Guest User

Untitled

a guest
Aug 15th, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.12 KB | None | 0 0
  1. <?php
  2.     include_once ("sql.php");
  3.     $db = new DB();
  4.  
  5.     if( isset($name) ) {
  6.         define('query','?'.$_SERVER['QUERY_STRING']);
  7.         $menuPage = $db->alone_data_where("menu","name",$name);
  8.         $file = $menuPage->file;
  9.         if(isset($_POST["action"])){
  10.             $table = $_POST["table"];
  11.             $action = $_POST["action"];
  12.             unset($_POST["table"]);
  13.             unset($_POST["action"]);
  14.             switch ($action) {
  15.                 case 'add':
  16.                     if($file == 'config'){
  17.                         $_POST["file"] = 'content';
  18.                         $_POST["name"] = 'none';
  19.                     }
  20.                     $sql = "INSERT INTO `".dbPrefix."$table`(";
  21.                         foreach($_POST as $key=>$get){
  22.                             $sql.= "`".$key."`,";
  23.                         }
  24.                     $sql.= "`title`) VALUES (";
  25.                         foreach($_POST as $key=>$get){
  26.                             $sql.= "'".$get."',";
  27.                         }
  28.                     $sql.= "'None');";
  29.                     if($db->execute_sql($sql)){
  30.                         $success = "Thêm thành công !";
  31.                     }else{
  32.                         echo $sql;
  33.                     }
  34.                     break;
  35.                
  36.                 case 'del':
  37.                     $value = $_POST["value"];
  38.                     $sql = "";
  39.                     $sql.= "DELETE FROM `".dbPrefix."$table` WHERE `id` = '$value'; ";
  40.                     switch ($table) {
  41.                         case 'menu':
  42.                             $allListMenuChild = array();
  43.                             $allListMenuChild = $db->allListMenuChild($value,$allListMenuChild);
  44.                             foreach($allListMenuChild as $menu){
  45.                                 if($menu->id !== 0 && $menu->id !== '0' && $menu->id !== ''){
  46.                                     $sql.="DELETE FROM `".dbPrefix."menu` WHERE `menu_parent` = '$menu->id'; ";
  47.                                     $sql.="DELETE FROM `".dbPrefix."data` WHERE `menu` = '$menu->id'; ";
  48.                                 }
  49.                             }
  50.                             break;
  51.                         case 'data':
  52.                             $sql.="DELETE FROM `".dbPrefix."data` WHERE `data_parent` = '$value'; ";
  53.                             break;
  54.                     }
  55.                     if($db->execute_sql($sql)){
  56.                         $success = "Xóa thành công !";
  57.                     }else{
  58.                         echo $sql;
  59.                     }
  60.                     break;
  61.             }
  62.         }else if(count($_POST)){
  63.             $timeNow = '-'.renameTitle(timeNow());
  64.             if(isset($id)){
  65.                 $idPost = $id;
  66.             }else if(isset($idList)){
  67.                 $idPost = $idList;
  68.             }else{
  69.                 $idPost = $menuPage->id;
  70.             }
  71.             $target_dir = "../upload/";
  72.             switch ($file) {
  73.                 case 'config':
  74.                     if(isset($_POST["listMenu"]) && count($_POST["listMenu"])){
  75.                         $sql = "";
  76.                         foreach($_POST["listMenu"] as $key=>$menu){
  77.                             $menu["name"] = renameTitle($menu["title"]);
  78.                            
  79.                             $db->updateRow('menu',$menu,'id',$key);
  80.                         }
  81.                     }
  82.  
  83.                     $check = $array = [];
  84.                     $dataPage = $db->list_data('page');
  85.                     foreach($dataPage as $data){
  86.                         $check[$data->name] = $data->content;
  87.                     }
  88.                     foreach($_POST as $key=>$post){
  89.                         if(isset($check[$key])){
  90.                             $array[$key] = $post;
  91.                         }
  92.                     }
  93.                     if(isset($_FILES)){
  94.                         foreach($_FILES as $key=>$f){
  95.                             if(($f["name"]) !== "" ){
  96.                                 $vlFile = explode(".",$f["name"]);
  97.                                 $vl = renameTitle($vlFile[0]).$timeNow.".".$vlFile[1];
  98.                                 $array[$key] = $vl;
  99.                                 move_uploaded_file($f["tmp_name"],$target_dir.$vl);
  100.                             }
  101.                         }
  102.                     }
  103.                     if($db->updateTable('page',$array,'content','name')){
  104.                         $success = "Lưu thành công !";
  105.                     }
  106.                     break;
  107.                
  108.                
  109.                
  110.                 /*case 'show-news':
  111.                 case 'show-products':*/
  112.                 case 'post':
  113.                 case 'design':
  114.                     $array = array();
  115.                     foreach ($_POST as $key=>$post) {
  116.                         $array[$key] = $post;
  117.                     }
  118.                     if(count($array)){
  119.                         $array["time"] = timeNow();
  120.                         if($db->insertData('data',$array)){
  121.                             $success = "Gửi yêu cầu thành công !";
  122.                         }
  123.                     }
  124.                     break;
  125.             }
  126.  
  127.             if(isset($id)){
  128.                 $_POST["time"] = timeNow();
  129.             }
  130.            
  131.             if(isset($_FILES["img"])){
  132.                 $f = $_FILES["img"];
  133.                 $vlFile = explode(".",$f["name"]);
  134.                 if(count($vlFile) > 1){
  135.                     $vl = renameTitle($vlFile[0]).$timeNow.".".$vlFile[1];
  136.                     if(move_uploaded_file($f["tmp_name"], $target_dir.$vl)){
  137.                         $_POST["img"] = $vl;
  138.                     }
  139.                 }
  140.                
  141.             }
  142.             if(isset($_FILES["file"])){
  143.                 $f = $_FILES["file"];
  144.                 $vlFile = explode(".",$f["name"]);
  145.                 if(count($vlFile) > 1){
  146.                     $vl = renameTitle($vlFile[0]).$timeNow.".".$vlFile[1];
  147.                     if(move_uploaded_file($f["tmp_name"], $target_dir.$vl)){
  148.                         $_POST["file"] = $vl;
  149.                     }
  150.                 }
  151.                
  152.             }
  153.             if(isset($_POST["listData"])){
  154.                 $sql = "";
  155.                 foreach($_POST["listData"] as $key=>$data){
  156.                     $db->updateRow('data',$data,'id',$key);
  157.                 }
  158.             }
  159.             if(isset($_FILES["listData"])){
  160.  
  161.                 foreach($_FILES["listData"]["name"] as $key=>$f){
  162.                     if($_FILES["listData"]["name"][$key] !== '' ){
  163.                         $vlFile = explode(".",$_FILES["listData"]["name"][$key]);
  164.                         if(count($vlFile) > 1){
  165.                             $vl = renameTitle($vlFile[0]).$timeNow.".".$vlFile[1];
  166.                             if(move_uploaded_file($_FILES["listData"]["tmp_name"][$key], $target_dir.$vl)){
  167.                                 $data["img"] = $vl;
  168.                                 $db->updateRow('data',$data,'id',$key);
  169.                             }
  170.                         }
  171.                     }
  172.                 }
  173.             }
  174.             if( (isset($menuPage) && isset($_POST["content"]) && !isset($idList) && !isset($id)) || (isset($_POST['content']) && $idList == $menuPage->id)){
  175.                 if($db->updateRow("menu",$_POST,'id',$menuPage->id)){
  176.                     $success = "Lưu thành công !";
  177.                 }
  178.             }
  179.             if(isset($_POST["table"])){
  180.                 if($db->updateRow($_POST["table"],$_POST,'id',$_POST["id"])){
  181.                     $success = "Lưu thành công !";
  182.                 }
  183.             }
  184.             if(isset($_POST["images"][0]) && count($_POST["images"])){
  185.                 foreach($_POST["images"] as $images){
  186.                     $type = $images;
  187.                     if(isset($_FILES[$type])){
  188.                         foreach($_FILES[$type]["name"] as $key=>$vl){
  189.                             if($vl !== ""){
  190.                                 $vlFile = explode(".",$vl);
  191.                                 $vl = renameTitle($vlFile[0]).$timeNow.".".$vlFile[1];
  192.                                 if(move_uploaded_file($_FILES[$type]["tmp_name"][$key], $target_dir.$vl)){
  193.                                     $db->insertImage($idPost,$type,$vl);
  194.                                 }
  195.                             }                  
  196.                         }
  197.                     }
  198.                 }
  199.             }
  200.             if(isset($_FILES["slideData"])){
  201.                 foreach($_FILES["slideData"]["name"] as $key=>$vl){
  202.                     if($vl !== ""){
  203.                         $vlFile = explode(".",$vl);
  204.                         $vl = renameTitle($vlFile[0]).$timeNow.".".$vlFile[1];
  205.                         if(move_uploaded_file($_FILES["slideData"]["tmp_name"][$key], $target_dir.$vl)){
  206.                             $db->insertImageData($idPost,'slide',$vl);
  207.                         }
  208.                     }                  
  209.                 }
  210.             }
  211.         }
  212.        
  213.         $menuPage = $db->alone_data_where("menu","name",$name);
  214.  
  215.         if (isset($id)) {
  216.             $page = $db->alone_data_where("data","id",$id);
  217.             $update["view"] = $page->view + 1;
  218.             $db->updateRow("data",$update,'id',$id);
  219.             $idMenu = $page->menu;
  220.         }else if(isset($idList)){
  221.             $page = $db->alone_data_where("menu","id",$idList);
  222.             $idMenu = $page->id;
  223.         }else{
  224.             $idMenu = $menuPage->id;
  225.         }
  226.     }
  227.  
  228.     $password = $db->alone_data_where("page","name","password");
  229.     $password = $password->content;
  230.  
  231.     $listMenu = $db->list_data_where_where_order("menu","menu_parent",0,'hide',0,'pos','ASC');
  232.     $listMenuAdmin = $db->list_data_where_order("menu","menu_parent",0,'pos','ASC');
  233.     $listPage = $db->list_data("page");
  234.  
  235.     $infoPage = new stdClass();
  236.     foreach ($listPage as $vl) {
  237.         $key = $vl->name;
  238.         $infoPage->$key = $vl->content;
  239.     }
  240.  
  241.     if(isset($page)){
  242.         $title = $page->title;
  243.         $image = $page->img;
  244.         $des = $infoPage->des;
  245.         if(isset($page->price)){
  246.             $des = $page->price;
  247.         }
  248.     }else if(isset($menuPage)){
  249.         $title = $menuPage->title;
  250.         if($menuPage->file == 'home'){
  251.             $title = $infoPage->title;
  252.         }
  253.         $image = $infoPage->logo;
  254.         $des = $infoPage->des;
  255.     }
  256.  
  257.     $menuShop = $db->alone_data_where("menu","file","shop");
  258.     $menuMap = $db->alone_data_where("menu","file","map");
  259.     $menuHome = $db->alone_data_where("menu","file","home");
  260.     $menuSearch = $db->alone_data_where("menu","file","search");
  261.     $menuPost = $db->alone_data_where("menu","file","post");
  262.     $menuProduct = $db->alone_data_where("menu","file","show-products");
  263.     $menuNews = $db->alone_data_where("menu","name","tin-tuc");
  264.     $menuDesign = $db->alone_data_where("menu","file","design");
  265.     $menuUser = $db->alone_data_where("menu","file","user");
  266.     $menuContact = $db->alone_data_where("menu","file","contact");
  267.  
  268.     $list = new stdClass;
  269.    
  270.     foreach($config->showListImageAdmin as $key=>$listImage){
  271.         $list->$key = $db->list_data_where_where_order("data","menu",$menuHome->id,'type',$key,'pos','ASC');
  272.     }
  273.    
  274.     if(isset($menuPage)){
  275.         $menuFile = $menuPage->file;
  276.         if(isset($config->showIdListAdmin->$menuFile)){
  277.             $configMenu = $config->showIdListAdmin->$menuFile;
  278.         }
  279.     }
  280. ?>
Add Comment
Please, Sign In to add comment