/inc/page.php
PHP | 383 lines | 330 code | 38 blank | 15 comment | 63 complexity | 09392b677063bbebc220dbddfc79e2d4 MD5 | raw file
- <?
- ob_start();
- include "connect_db.php" ;
- include "vars.php" ;
- include "function.php" ;
- include "function.cms.php" ;
- include "class.phpmailer.php" ;
- // foreach ($_SERVER[ 'argv' ] as $key => $value) {
- // $lenarg +=strlen($value)+1;
- // }
- $href = substr ($_SERVER['REQUEST_URI'], 0, strlen($_SERVER['REQUEST_URI'])-$lenarg);
- $href=$home_root.$href;
- if (strlen($href)>1)
- while ($href[strlen($href)-1]=='?' || $href[strlen($href)-1]=='/')
- $href = substr ($href, 0, strlen($href)-1);
- $substr_count=substr_count($_SERVER[ 'REQUEST_URI' ],'/');
- $pt='';
- /*if ($substr_count>=2)
- {
- $substr_count-=2;
- for ($i=0;$i<=$substr_count;$i++)$pt.='../';
- }
- */
- $param = explode('&', $_SERVER[ 'argv' ][0]);
- foreach ($param as $key => $value) {
- $params = explode('=', $value);
- $arg[$params[0]]=$params[1];
- }
- // if (!empty($arg[0]))
- foreach ($arg as $key => $value) {
- if ($key!='p')
- $arg_no_p .= '&'.$key.'='.$value;
- }
- $arg_no_p = substr($arg_no_p, 1);
- $p_id = -1;
- $p_pid = 0;
- $p_title = 404;
- $p_description = '';
- $p_keyword = '';
- $p_name = 'Страница не найдена';
- $p_text = 'Ошибка 404. <br>К сожалению запрашиваемая вами страница не найдена';
- $p_type = 0;
- $p_href = '';
- $p_status = 0;
- $page = (!empty($_GET['p']))?$_GET['p']:1;
- $limit=12;
- $start=$page*$limit-$limit;
- $query = mysql_query("select * from {$pref}db_structure_alias where href='{$href}' limit 1");
- if ($query && mysql_num_rows($query)>0)
- {
- $res=mysql_fetch_array($query);
- $p_id_type=$res['id_type'];
- $p_id_el=$res['id_el'];
- $modul=getdb('db_modules',$res['id_type'],'table');
- $page=mysql_query("select * from {$pref}db_structure where id={$res['id_page']} and status=1");
- $content=mysql_query("select * from {$pref}{$modul} where id={$res['id_el']} and status=1");
- if ($page && mysql_num_rows($page)==0){
- $httperror=getdb('db_structure',$res['id_page'],'error');
- }
- if ($page && mysql_num_rows($page)>0 && $content && mysql_num_rows($content)>0){
- $page=mysql_fetch_array($page);
- $content=mysql_fetch_array($content);
- $p_access_admin = explode(',', $page['access_admin']);
- $p_access_moder = explode(',', $page['access_moder']);
- $p_access_user = explode(',', $page['access_user']);
- $p_access_notuser = $page['access_notuser'];
- $access=0;
- if (!empty($_SESSION['user_id'])){
- $ut = getUser($_SESSION['user_id'],'type');
- $ug = getUser($_SESSION['user_id'],'group');
- if ($ut==2){
- if (in_array($ug, $p_access_admin)) $access=1;
- } elseif ($ut==1){
- if (in_array($ug, $p_access_moder)) $access=1;
- } elseif ($ut==0){
- if (in_array($ug, $p_access_user)) $access=1;
- }
- } else {
- if ($p_access_notuser==1) $access=1;
- }
- if ($access==1) {
- $p_id = $page['id'];
- $p_pid = $page['pid'];
- $p_parent = $page['parent'];
- $p_name = $content['name'];
- $p_alias = $content['alias'];
- $p_anons = $content['anons'];
- $p_text = $content['text'];
- $p_type = $page['type'];
- $p_href = $page['href'];
- $p_status = $content['status'];
- $p_sort = $content['sort'];
- $p_title = $content['title'];
- $p_description = $content['description'];
- $p_keyword = $content['keyword'];
- $p_catalog = $page['catalog'];
- $p_catalog2 = $page['catalog2'];
- $p_materials = $page['materials'];
- $p_materials2 = $page['materials2'];
- $p_tpl = $page['tpl'];
- $p_menu = $page['menu'];
- $p_user = $content['user'];
- $p_date1 = $content['date1'];
- $p_date2 = $content['date2'];
- }
- elseif ($access==0) {
- $p_id1 = $page['id'];
- $p_id = -1;
- $p_pid = 0;
- $p_title = 403;
- $p_description = '';
- $p_keyword = '';
- $p_name = 'Страница недоступна';
- $p_text = 'Ошибка. <br>К сожалению запрашиваемая Вами страница недоступна';
- $p_type = 0;
- $p_href = '';
- $p_status = 0;
-
- $query = mysql_query("select * from {$pref}db_structure_alias where href='/error403'");
- if ($query && mysql_num_rows($query)>0)
- $id403=mysql_result($query,0, 'id_page');
- $query = mysql_query("select * from {$pref}db_structure where id='$id403'");
- if ($query && mysql_num_rows($query)>0){
- $res1=mysql_fetch_array($query);
- $p_id = $res1['id'];
- $p_pid = $res1['pid'];
- $p_parent = $res1['parent'];
- $p_name = $res1['name'];
- $p_alias = $res1['alias'];
- $p_anons = $res1['anons'];
- $p_text = $res1['text'];
- $p_type = $res1['type'];
- $p_href = $res1['href'];
- $p_status = $res1['status'];
- $p_sort = $res1['sort'];
- $p_title = $res1['title'];
- $p_description = $res1['description'];
- $p_keyword = $res1['keyword'];
- $p_catalog = $res1['catalog'];
- $p_catalog2 = $res1['catalog2'];
- $p_materials = $res1['materials'];
- $p_materials2 = $res1['materials2'];
- $p_tpl = $res1['tpl'];
- $p_menu = $res1['menu'];
- $p_user = $res1['user'];
- $p_date1 = $res1['date1'];
- $p_date2 = $res1['date2'];
- }
- header('HTTP/1.1 403 Forbidden');
- }
- } elseif (!empty($httperror)){
- $query = mysql_query("select * from {$pref}db_structure_alias where href='/error{$httperror}'");
- if ($query && mysql_num_rows($query)>0)
- $id404=mysql_result($query,0, 'id_page');
- $query = mysql_query("select * from {$pref}db_structure where id='$id404'");
- if ($query && mysql_num_rows($query)>0){
- $res1=mysql_fetch_array($query);
- $p_id = $res1['id'];
- $p_pid = $res1['pid'];
- $p_parent = $res1['parent'];
- $p_name = $res1['name'];
- $p_alias = $res1['alias'];
- $p_anons = $res1['anons'];
- $p_text = $res1['text'];
- $p_type = $res1['type'];
- $p_href = $res1['href'];
- $p_status = $res1['status'];
- $p_sort = $res1['sort'];
- $p_title = $res1['title'];
- $p_description = $res1['description'];
- $p_keyword = $res1['keyword'];
- $p_catalog = $res1['catalog'];
- $p_catalog2 = $res1['catalog2'];
- $p_materials = $res1['materials'];
- $p_materials2 = $res1['materials2'];
- $p_tpl = $res1['tpl'];
- $p_menu = $res1['menu'];
- $p_user = $res1['user'];
- $p_date1 = $res1['date1'];
- $p_date2 = $res1['date2'];
- }
- switch ($httperror) {
- case '402':
- header('HTTP/1.1 402 Payment Required');
- break;
-
- default:
- header('HTTP/1.1 404 Not Found');
- break;
- }
- } else{
- $query = mysql_query("select * from {$pref}db_structure_alias where href='/error404'");
- if ($query && mysql_num_rows($query)>0)
- $id404=mysql_result($query,0, 'id_page');
- $query = mysql_query("select * from {$pref}db_structure where id='$id404'");
- if ($query && mysql_num_rows($query)>0){
- $res1=mysql_fetch_array($query);
- $p_id = $res1['id'];
- $p_pid = $res1['pid'];
- $p_parent = $res1['parent'];
- $p_name = $res1['name'];
- $p_alias = $res1['alias'];
- $p_anons = $res1['anons'];
- $p_text = $res1['text'];
- $p_type = $res1['type'];
- $p_href = $res1['href'];
- $p_status = $res1['status'];
- $p_sort = $res1['sort'];
- $p_title = $res1['title'];
- $p_description = $res1['description'];
- $p_keyword = $res1['keyword'];
- $p_catalog = $res1['catalog'];
- $p_catalog2 = $res1['catalog2'];
- $p_materials = $res1['materials'];
- $p_materials2 = $res1['materials2'];
- $p_tpl = $res1['tpl'];
- $p_menu = $res1['menu'];
- $p_user = $res1['user'];
- $p_date1 = $res1['date1'];
- $p_date2 = $res1['date2'];
- }
- header('HTTP/1.1 404 Not Found');
- }
- } else {
- $query = mysql_query("select * from {$pref}db_structure_alias where href='/error404'");
- if ($query && mysql_num_rows($query)>0)
- $id404=mysql_result($query,0, 'id_page');
- $query = mysql_query("select * from {$pref}db_structure where id='$id404'");
- if ($query && mysql_num_rows($query)>0){
- $res1=mysql_fetch_array($query);
- $p_id = $res1['id'];
- $p_pid = $res1['pid'];
- $p_parent = $res1['parent'];
- $p_name = $res1['name'];
- $p_alias = $res1['alias'];
- $p_anons = $res1['anons'];
- $p_text = $res1['text'];
- $p_type = $res1['type'];
- $p_href = $res1['href'];
- $p_status = $res1['status'];
- $p_sort = $res1['sort'];
- $p_title = $res1['title'];
- $p_description = $res1['description'];
- $p_keyword = $res1['keyword'];
- $p_catalog = $res1['catalog'];
- $p_catalog2 = $res1['catalog2'];
- $p_materials = $res1['materials'];
- $p_materials2 = $res1['materials2'];
- $p_tpl = $res1['tpl'];
- $p_menu = $res1['menu'];
- $p_user = $res1['user'];
- $p_date1 = $res1['date1'];
- $p_date2 = $res1['date2'];
- }
- header('HTTP/1.1 404 Not Found');
- }
- $date_now = date('Y-m-d');
- $ip=$_SERVER['REMOTE_ADDR'];
- // echo $_SESSION['p_id'];
- //СЕССИЯ
- 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'];}
- if (!empty($_SESSION['user_id'])){
- $query=mysql_query("select * from {$pref}db_users where id='{$_SESSION['user_id']}' and type>=0 and status<3");
- if (mysql_num_rows($query)>0){
- $inf= mysql_fetch_array($query);
- if ($inf['status']==2)
- mysql_query("update {$pref}db_users set status=1 where id='{$_SESSION['user_id']}'");
- } else{
- session_unset();SetCookie("user_unic","", time() - 3600,'/');header("Location: /");die();
- }
- }
- // echo $_SESSION['user_unic'];
- // echo @$_COOKIE['user_unic'];
- if (!empty($_SESSION['user_id'])){
- $sql = "select * from {$pref}db_session where user='{$_SESSION['user_id']}'";
- if (mysql_num_rows(mysql_query($sql))==0)
- mysql_query("insert into {$pref}db_session set ip='{$ip}',user='{$_SESSION['user_id']}',unic='{$_SESSION['user_unic']}',date=NOW()");
- else
- mysql_query("update {$pref}db_session set ip='{$ip}',date=NOW(),unic='{$_SESSION['user_unic']}' where user='{$_SESSION['user_id']}'");
- mysql_query("delete from {$pref}db_session where user=0 and unic='{$_SESSION['user_unic']}'");
- if (!empty($_SESSION['user_remember']))
- SetCookie("user_unic","", time() - 3600,'/');
- } else{
- if (!empty($_COOKIE['user_unic'])) $_SESSION['user_unic']=@$_COOKIE['user_unic'];
- elseif (empty($_SESSION['user_unic'])) $_SESSION['user_unic']=md5(substr(md5(uniqid(rand(),true)),0,32).$ip.date('Y-m-d-H-i-s'));
- $sql = "select * from {$pref}db_session where ip='{$ip}' and user=0 and unic='{$_SESSION['user_unic']}'";
- if (mysql_num_rows(mysql_query($sql))==0) {
- mysql_query("insert into {$pref}db_session set ip='{$ip}',user='{$_SESSION['user_id']}',unic='{$_SESSION['user_unic']}',date=NOW()");
- SetCookie("user_unic",$_SESSION['user_unic'],time()+3600,'/');}
- else
- 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']}'");
- }
- if (!isset($_SESSION['basket'])){
- $sql="select * from {$pref}db_catalog_order_cat where unid='{$_SESSION['user_unic']}' and status=3 order by id desc limit 1";
- $query=mysql_query($sql);
- if ($query && mysql_num_rows($query)>0){
- $bid=mysql_result($query,0, 'id');
- $_SESSION['totalCount'] = mysql_result($query,0, 'count');
- $_SESSION['totalCost'] = mysql_result($query,0, 'price');
- $sql="select * from {$pref}db_catalog_order where pid='{$bid}'";
- $query=mysql_query($sql);
- if ($query && mysql_num_rows($query)>0)
- while ($res=mysql_fetch_array($query)) {
- $_SESSION['basket'][$res['catalog_id']]=$res['count'];
- }
- }
- }
- if (!empty($p_tpl)) $tpl_user='templates/tpl/'.$p_tpl;
- include $pt.$tpl_user."/page.tpl" ;
- $page = ob_get_contents();
- ob_end_clean();
- if (!empty($p_title))
- $page = str_replace("#title#", $p_title, $page);
- else
- $page = str_replace("#title#", $p_name.' | '.$s_title, $page);
- $page = str_replace("#advdescr#", $p_description, $page);
- $page = str_replace("#advkeyw#", $p_keyword, $page);
- if (strpos($page, '{^')) {
- $count = substr_count($page, '{^');
- for ($i=0; $i < $count; $i++) {
- $pagee=$page;
- $pos1 = strpos($pagee, '{^');
- $page1= mb_substr($pagee, 0,$pos1);
- $pos2 = strpos($pagee, '^}')+2;
- $page2= mb_substr($pagee, $pos2);
- $usl = mb_substr($pagee, $pos1+2,$pos2-$pos1-4);
- $page = $page1;
- if (file_exists($_SERVER['DOCUMENT_ROOT'].'/components/'.$usl.'.php')){
- $usl .= '.php';
- $page .= incude_comp($usl);
- }
- else {
- $sql = "select * from {$pref}db_components where name='{$usl}' and status=1 limit 1";
- $query = mysql_query($sql);
- if ($query && mysql_num_rows($query)>0){
- $usl = mysql_result($query,0, 'comp');
- if (file_exists($_SERVER['DOCUMENT_ROOT'].'/components/'.$usl.''))
- $page .= incude_comp($usl);
- }
- }
- $page .= $page2;
- }
- }
- $page = str_replace("^ptt^", '/'.$tpl_user.'/', $page);
- // $page = str_replace("{map}", qweqweqwe() , $page);
- echo $page;
- ?>