PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/inc/page.php

https://bitbucket.org/ssimpledecision/simpledecision
PHP | 383 lines | 330 code | 38 blank | 15 comment | 63 complexity | 09392b677063bbebc220dbddfc79e2d4 MD5 | raw file
  1. <?
  2. ob_start();
  3. include "connect_db.php" ;
  4. include "vars.php" ;
  5. include "function.php" ;
  6. include "function.cms.php" ;
  7. include "class.phpmailer.php" ;
  8. // foreach ($_SERVER[ 'argv' ] as $key => $value) {
  9. // $lenarg +=strlen($value)+1;
  10. // }
  11. $href = substr ($_SERVER['REQUEST_URI'], 0, strlen($_SERVER['REQUEST_URI'])-$lenarg);
  12. $href=$home_root.$href;
  13. if (strlen($href)>1)
  14. while ($href[strlen($href)-1]=='?' || $href[strlen($href)-1]=='/')
  15. $href = substr ($href, 0, strlen($href)-1);
  16. $substr_count=substr_count($_SERVER[ 'REQUEST_URI' ],'/');
  17. $pt='';
  18. /*if ($substr_count>=2)
  19. {
  20. $substr_count-=2;
  21. for ($i=0;$i<=$substr_count;$i++)$pt.='../';
  22. }
  23. */
  24. $param = explode('&', $_SERVER[ 'argv' ][0]);
  25. foreach ($param as $key => $value) {
  26. $params = explode('=', $value);
  27. $arg[$params[0]]=$params[1];
  28. }
  29. // if (!empty($arg[0]))
  30. foreach ($arg as $key => $value) {
  31. if ($key!='p')
  32. $arg_no_p .= '&'.$key.'='.$value;
  33. }
  34. $arg_no_p = substr($arg_no_p, 1);
  35. $p_id = -1;
  36. $p_pid = 0;
  37. $p_title = 404;
  38. $p_description = '';
  39. $p_keyword = '';
  40. $p_name = 'Страница не найдена';
  41. $p_text = 'Ошибка 404. <br>К сожалению запрашиваемая вами страница не найдена';
  42. $p_type = 0;
  43. $p_href = '';
  44. $p_status = 0;
  45. $page = (!empty($_GET['p']))?$_GET['p']:1;
  46. $limit=12;
  47. $start=$page*$limit-$limit;
  48. $query = mysql_query("select * from {$pref}db_structure_alias where href='{$href}' limit 1");
  49. if ($query && mysql_num_rows($query)>0)
  50. {
  51. $res=mysql_fetch_array($query);
  52. $p_id_type=$res['id_type'];
  53. $p_id_el=$res['id_el'];
  54. $modul=getdb('db_modules',$res['id_type'],'table');
  55. $page=mysql_query("select * from {$pref}db_structure where id={$res['id_page']} and status=1");
  56. $content=mysql_query("select * from {$pref}{$modul} where id={$res['id_el']} and status=1");
  57. if ($page && mysql_num_rows($page)==0){
  58. $httperror=getdb('db_structure',$res['id_page'],'error');
  59. }
  60. if ($page && mysql_num_rows($page)>0 && $content && mysql_num_rows($content)>0){
  61. $page=mysql_fetch_array($page);
  62. $content=mysql_fetch_array($content);
  63. $p_access_admin = explode(',', $page['access_admin']);
  64. $p_access_moder = explode(',', $page['access_moder']);
  65. $p_access_user = explode(',', $page['access_user']);
  66. $p_access_notuser = $page['access_notuser'];
  67. $access=0;
  68. if (!empty($_SESSION['user_id'])){
  69. $ut = getUser($_SESSION['user_id'],'type');
  70. $ug = getUser($_SESSION['user_id'],'group');
  71. if ($ut==2){
  72. if (in_array($ug, $p_access_admin)) $access=1;
  73. } elseif ($ut==1){
  74. if (in_array($ug, $p_access_moder)) $access=1;
  75. } elseif ($ut==0){
  76. if (in_array($ug, $p_access_user)) $access=1;
  77. }
  78. } else {
  79. if ($p_access_notuser==1) $access=1;
  80. }
  81. if ($access==1) {
  82. $p_id = $page['id'];
  83. $p_pid = $page['pid'];
  84. $p_parent = $page['parent'];
  85. $p_name = $content['name'];
  86. $p_alias = $content['alias'];
  87. $p_anons = $content['anons'];
  88. $p_text = $content['text'];
  89. $p_type = $page['type'];
  90. $p_href = $page['href'];
  91. $p_status = $content['status'];
  92. $p_sort = $content['sort'];
  93. $p_title = $content['title'];
  94. $p_description = $content['description'];
  95. $p_keyword = $content['keyword'];
  96. $p_catalog = $page['catalog'];
  97. $p_catalog2 = $page['catalog2'];
  98. $p_materials = $page['materials'];
  99. $p_materials2 = $page['materials2'];
  100. $p_tpl = $page['tpl'];
  101. $p_menu = $page['menu'];
  102. $p_user = $content['user'];
  103. $p_date1 = $content['date1'];
  104. $p_date2 = $content['date2'];
  105. }
  106. elseif ($access==0) {
  107. $p_id1 = $page['id'];
  108. $p_id = -1;
  109. $p_pid = 0;
  110. $p_title = 403;
  111. $p_description = '';
  112. $p_keyword = '';
  113. $p_name = 'Страница недоступна';
  114. $p_text = 'Ошибка. <br>К сожалению запрашиваемая Вами страница недоступна';
  115. $p_type = 0;
  116. $p_href = '';
  117. $p_status = 0;
  118. $query = mysql_query("select * from {$pref}db_structure_alias where href='/error403'");
  119. if ($query && mysql_num_rows($query)>0)
  120. $id403=mysql_result($query,0, 'id_page');
  121. $query = mysql_query("select * from {$pref}db_structure where id='$id403'");
  122. if ($query && mysql_num_rows($query)>0){
  123. $res1=mysql_fetch_array($query);
  124. $p_id = $res1['id'];
  125. $p_pid = $res1['pid'];
  126. $p_parent = $res1['parent'];
  127. $p_name = $res1['name'];
  128. $p_alias = $res1['alias'];
  129. $p_anons = $res1['anons'];
  130. $p_text = $res1['text'];
  131. $p_type = $res1['type'];
  132. $p_href = $res1['href'];
  133. $p_status = $res1['status'];
  134. $p_sort = $res1['sort'];
  135. $p_title = $res1['title'];
  136. $p_description = $res1['description'];
  137. $p_keyword = $res1['keyword'];
  138. $p_catalog = $res1['catalog'];
  139. $p_catalog2 = $res1['catalog2'];
  140. $p_materials = $res1['materials'];
  141. $p_materials2 = $res1['materials2'];
  142. $p_tpl = $res1['tpl'];
  143. $p_menu = $res1['menu'];
  144. $p_user = $res1['user'];
  145. $p_date1 = $res1['date1'];
  146. $p_date2 = $res1['date2'];
  147. }
  148. header('HTTP/1.1 403 Forbidden');
  149. }
  150. } elseif (!empty($httperror)){
  151. $query = mysql_query("select * from {$pref}db_structure_alias where href='/error{$httperror}'");
  152. if ($query && mysql_num_rows($query)>0)
  153. $id404=mysql_result($query,0, 'id_page');
  154. $query = mysql_query("select * from {$pref}db_structure where id='$id404'");
  155. if ($query && mysql_num_rows($query)>0){
  156. $res1=mysql_fetch_array($query);
  157. $p_id = $res1['id'];
  158. $p_pid = $res1['pid'];
  159. $p_parent = $res1['parent'];
  160. $p_name = $res1['name'];
  161. $p_alias = $res1['alias'];
  162. $p_anons = $res1['anons'];
  163. $p_text = $res1['text'];
  164. $p_type = $res1['type'];
  165. $p_href = $res1['href'];
  166. $p_status = $res1['status'];
  167. $p_sort = $res1['sort'];
  168. $p_title = $res1['title'];
  169. $p_description = $res1['description'];
  170. $p_keyword = $res1['keyword'];
  171. $p_catalog = $res1['catalog'];
  172. $p_catalog2 = $res1['catalog2'];
  173. $p_materials = $res1['materials'];
  174. $p_materials2 = $res1['materials2'];
  175. $p_tpl = $res1['tpl'];
  176. $p_menu = $res1['menu'];
  177. $p_user = $res1['user'];
  178. $p_date1 = $res1['date1'];
  179. $p_date2 = $res1['date2'];
  180. }
  181. switch ($httperror) {
  182. case '402':
  183. header('HTTP/1.1 402 Payment Required');
  184. break;
  185. default:
  186. header('HTTP/1.1 404 Not Found');
  187. break;
  188. }
  189. } else{
  190. $query = mysql_query("select * from {$pref}db_structure_alias where href='/error404'");
  191. if ($query && mysql_num_rows($query)>0)
  192. $id404=mysql_result($query,0, 'id_page');
  193. $query = mysql_query("select * from {$pref}db_structure where id='$id404'");
  194. if ($query && mysql_num_rows($query)>0){
  195. $res1=mysql_fetch_array($query);
  196. $p_id = $res1['id'];
  197. $p_pid = $res1['pid'];
  198. $p_parent = $res1['parent'];
  199. $p_name = $res1['name'];
  200. $p_alias = $res1['alias'];
  201. $p_anons = $res1['anons'];
  202. $p_text = $res1['text'];
  203. $p_type = $res1['type'];
  204. $p_href = $res1['href'];
  205. $p_status = $res1['status'];
  206. $p_sort = $res1['sort'];
  207. $p_title = $res1['title'];
  208. $p_description = $res1['description'];
  209. $p_keyword = $res1['keyword'];
  210. $p_catalog = $res1['catalog'];
  211. $p_catalog2 = $res1['catalog2'];
  212. $p_materials = $res1['materials'];
  213. $p_materials2 = $res1['materials2'];
  214. $p_tpl = $res1['tpl'];
  215. $p_menu = $res1['menu'];
  216. $p_user = $res1['user'];
  217. $p_date1 = $res1['date1'];
  218. $p_date2 = $res1['date2'];
  219. }
  220. header('HTTP/1.1 404 Not Found');
  221. }
  222. } else {
  223. $query = mysql_query("select * from {$pref}db_structure_alias where href='/error404'");
  224. if ($query && mysql_num_rows($query)>0)
  225. $id404=mysql_result($query,0, 'id_page');
  226. $query = mysql_query("select * from {$pref}db_structure where id='$id404'");
  227. if ($query && mysql_num_rows($query)>0){
  228. $res1=mysql_fetch_array($query);
  229. $p_id = $res1['id'];
  230. $p_pid = $res1['pid'];
  231. $p_parent = $res1['parent'];
  232. $p_name = $res1['name'];
  233. $p_alias = $res1['alias'];
  234. $p_anons = $res1['anons'];
  235. $p_text = $res1['text'];
  236. $p_type = $res1['type'];
  237. $p_href = $res1['href'];
  238. $p_status = $res1['status'];
  239. $p_sort = $res1['sort'];
  240. $p_title = $res1['title'];
  241. $p_description = $res1['description'];
  242. $p_keyword = $res1['keyword'];
  243. $p_catalog = $res1['catalog'];
  244. $p_catalog2 = $res1['catalog2'];
  245. $p_materials = $res1['materials'];
  246. $p_materials2 = $res1['materials2'];
  247. $p_tpl = $res1['tpl'];
  248. $p_menu = $res1['menu'];
  249. $p_user = $res1['user'];
  250. $p_date1 = $res1['date1'];
  251. $p_date2 = $res1['date2'];
  252. }
  253. header('HTTP/1.1 404 Not Found');
  254. }
  255. $date_now = date('Y-m-d');
  256. $ip=$_SERVER['REMOTE_ADDR'];
  257. // echo $_SESSION['p_id'];
  258. //СЕССИЯ
  259. if (!empty($_COOKIE['user_unic']) && empty($_SESSION['user_id'])) {$_SESSION['user_id']=mysql_result(mysql_query("select * from {$pref}db_session where unic='{$_COOKIE['user_unic']}'"),0, 'user');$_SESSION['user_unic']=$_COOKIE['user_unic'];}
  260. if (!empty($_SESSION['user_id'])){
  261. $query=mysql_query("select * from {$pref}db_users where id='{$_SESSION['user_id']}' and type>=0 and status<3");
  262. if (mysql_num_rows($query)>0){
  263. $inf= mysql_fetch_array($query);
  264. if ($inf['status']==2)
  265. mysql_query("update {$pref}db_users set status=1 where id='{$_SESSION['user_id']}'");
  266. } else{
  267. session_unset();SetCookie("user_unic","", time() - 3600,'/');header("Location: /");die();
  268. }
  269. }
  270. // echo $_SESSION['user_unic'];
  271. // echo @$_COOKIE['user_unic'];
  272. if (!empty($_SESSION['user_id'])){
  273. $sql = "select * from {$pref}db_session where user='{$_SESSION['user_id']}'";
  274. if (mysql_num_rows(mysql_query($sql))==0)
  275. mysql_query("insert into {$pref}db_session set ip='{$ip}',user='{$_SESSION['user_id']}',unic='{$_SESSION['user_unic']}',date=NOW()");
  276. else
  277. mysql_query("update {$pref}db_session set ip='{$ip}',date=NOW(),unic='{$_SESSION['user_unic']}' where user='{$_SESSION['user_id']}'");
  278. mysql_query("delete from {$pref}db_session where user=0 and unic='{$_SESSION['user_unic']}'");
  279. if (!empty($_SESSION['user_remember']))
  280. SetCookie("user_unic","", time() - 3600,'/');
  281. } else{
  282. if (!empty($_COOKIE['user_unic'])) $_SESSION['user_unic']=@$_COOKIE['user_unic'];
  283. elseif (empty($_SESSION['user_unic'])) $_SESSION['user_unic']=md5(substr(md5(uniqid(rand(),true)),0,32).$ip.date('Y-m-d-H-i-s'));
  284. $sql = "select * from {$pref}db_session where ip='{$ip}' and user=0 and unic='{$_SESSION['user_unic']}'";
  285. if (mysql_num_rows(mysql_query($sql))==0) {
  286. mysql_query("insert into {$pref}db_session set ip='{$ip}',user='{$_SESSION['user_id']}',unic='{$_SESSION['user_unic']}',date=NOW()");
  287. SetCookie("user_unic",$_SESSION['user_unic'],time()+3600,'/');}
  288. else
  289. mysql_query("update {$pref}db_session set ip='{$ip}',user='{$_SESSION['user_id']}',date=NOW() where ip='{$ip}' and user=0 and unic='{$_SESSION['user_unic']}'");
  290. }
  291. if (!isset($_SESSION['basket'])){
  292. $sql="select * from {$pref}db_catalog_order_cat where unid='{$_SESSION['user_unic']}' and status=3 order by id desc limit 1";
  293. $query=mysql_query($sql);
  294. if ($query && mysql_num_rows($query)>0){
  295. $bid=mysql_result($query,0, 'id');
  296. $_SESSION['totalCount'] = mysql_result($query,0, 'count');
  297. $_SESSION['totalCost'] = mysql_result($query,0, 'price');
  298. $sql="select * from {$pref}db_catalog_order where pid='{$bid}'";
  299. $query=mysql_query($sql);
  300. if ($query && mysql_num_rows($query)>0)
  301. while ($res=mysql_fetch_array($query)) {
  302. $_SESSION['basket'][$res['catalog_id']]=$res['count'];
  303. }
  304. }
  305. }
  306. if (!empty($p_tpl)) $tpl_user='templates/tpl/'.$p_tpl;
  307. include $pt.$tpl_user."/page.tpl" ;
  308. $page = ob_get_contents();
  309. ob_end_clean();
  310. if (!empty($p_title))
  311. $page = str_replace("#title#", $p_title, $page);
  312. else
  313. $page = str_replace("#title#", $p_name.' | '.$s_title, $page);
  314. $page = str_replace("#advdescr#", $p_description, $page);
  315. $page = str_replace("#advkeyw#", $p_keyword, $page);
  316. if (strpos($page, '{^')) {
  317. $count = substr_count($page, '{^');
  318. for ($i=0; $i < $count; $i++) {
  319. $pagee=$page;
  320. $pos1 = strpos($pagee, '{^');
  321. $page1= mb_substr($pagee, 0,$pos1);
  322. $pos2 = strpos($pagee, '^}')+2;
  323. $page2= mb_substr($pagee, $pos2);
  324. $usl = mb_substr($pagee, $pos1+2,$pos2-$pos1-4);
  325. $page = $page1;
  326. if (file_exists($_SERVER['DOCUMENT_ROOT'].'/components/'.$usl.'.php')){
  327. $usl .= '.php';
  328. $page .= incude_comp($usl);
  329. }
  330. else {
  331. $sql = "select * from {$pref}db_components where name='{$usl}' and status=1 limit 1";
  332. $query = mysql_query($sql);
  333. if ($query && mysql_num_rows($query)>0){
  334. $usl = mysql_result($query,0, 'comp');
  335. if (file_exists($_SERVER['DOCUMENT_ROOT'].'/components/'.$usl.''))
  336. $page .= incude_comp($usl);
  337. }
  338. }
  339. $page .= $page2;
  340. }
  341. }
  342. $page = str_replace("^ptt^", '/'.$tpl_user.'/', $page);
  343. // $page = str_replace("{map}", qweqweqwe() , $page);
  344. echo $page;
  345. ?>