ACC SHELL

Path : /srv/www/vhosts/unitedsolution/admin/class/
File Upload :
Current File : /srv/www/vhosts/unitedsolution/admin/class/page.php

<?php

class category{	

	var $msg;
	
	function add($name){
		
		if(!empty($name)){
			
			$name = addslashes($name);
		
			$query = "INSERT INTO ".DBPREFIX."page_category (name) VALUES('$name')";
			
			if(mysql_query($query)){
				
				$this->msg = CATEGORY_CERATED;
			
			}
			else{
				
				$this->msg = SQL_ERROR.mysql_error();
			
			}
		
		}
		else{
			
			$this->msg = CATEGORY_NAME_EMPTY;
		
		}
	
	}
	
	var $id, $name;
	
	function show(){
		
		$query = "SELECT * FROM ".DBPREFIX."page_category ORDER BY name ASC";
		
		$sent = mysql_query($query);
		
		while($data = mysql_fetch_object($sent)){
			
			$this->id[] = $data->id;
			$this->name[] = stripslashes($data->name);
		
		}
	
	}
	
	function show_one($id){
		
		$query = "SELECT * FROM ".DBPREFIX."page_category WHERE id = '$id'";
		
		$sent = mysql_query($query);
		
		$data = mysql_fetch_object($sent);
		
		$this->id = $data->id;
		$this->name = stripslashes($data->name);
	
	}
	
	function delete($id){
	
		$query = "SELECT COUNT(*) AS pocet FROM ".DBPREFIX."page WHERE category = '$id'";
		
		$sent = mysql_query($query);
		
		$data = mysql_fetch_object($sent);
		
		if($data->pocet == 0){
		
			$query = "DELETE FROM ".DBPREFIX."page_category WHERE id = '$id'";
			
			if(mysql_query($query)){
				
				$this->msg = CATEGORY_DELETED;
			
			}
			else{
				
				$this->msg = SQL_ERROR.mysql_error();
			
			}
		}
		else{
			
			$this->msg = CATEGORY_NOT_EMPTY;
		
		}
		
	}
	
	function edit($id, $name){
		
		if(!empty($name)){
			
			$name = addslashes($name);
		
			$query = "UPDATE ".DBPREFIX."page_category SET name = '$name' WHERE id = '$id'";
			
			if(mysql_query($query)){
				
				$this->msg = CATEGORY_UPDATED;
			
			}
			else{
				
				$this->msg = SQL_ERROR.mysql_error();
			
			}
		
		}
		else{
			
			$this->msg = CATEGORY_NAME_EMPTY;
		
		}
	
	}
	
	function pocet(){
		
		$query = "SELECT COUNT(*) AS pocet FROM ".DBPREFIX."page_category";
		
		$sent = mysql_query($query);
		
		$data = mysql_fetch_object($sent);
		
		return $data->pocet;
	
	}

}

class page{
	
	var $msg, $template_id, $template_name;
	
	function select_templates(){
	
		$query = "SELECT * FROM ".DBPREFIX."template ORDER BY name ASC";
		
		$sent = mysql_query($query);
		
		while($data = mysql_fetch_object($sent)){
			
			$this->template_id[] = $data->id;
			$this->template_name[] = $data->name;
		
		}
	
	}

    function makeSeoUrl($url) {
    static $tbl = array("\xc3\xa1"=>"a","\xc3\xa4"=>"a","\xc4\x8d"=>"c","\xc4\x8f"=>"d","\xc3\xa9"=>"e","\xc4\x9b"=>"e","\xc3\xad"=>"i","\xc4\xbe"=>"l","\xc4\xba"=>"l","\xc5\x88"=>"n","\xc3\xb3"=>"o","\xc3\xb6"=>"o","\xc5\x91"=>"o","\xc3\xb4"=>"o","\xc5\x99"=>"r","\xc5\x95"=>"r","\xc5\xa1"=>"s","\xc5\xa5"=>"t","\xc3\xba"=>"u","\xc5\xaf"=>"u","\xc3\xbc"=>"u","\xc5\xb1"=>"u","\xc3\xbd"=>"y","\xc5\xbe"=>"z","\xc3\x81"=>"A","\xc3\x84"=>"A","\xc4\x8c"=>"C","\xc4\x8e"=>"D","\xc3\x89"=>"E","\xc4\x9a"=>"E","\xc3\x8d"=>"I","\xc4\xbd"=>"L","\xc4\xb9"=>"L","\xc5\x87"=>"N","\xc3\x93"=>"O","\xc3\x96"=>"O","\xc5\x90"=>"O","\xc3\x94"=>"O","\xc5\x98"=>"R","\xc5\x94"=>"R","\xc5\xa0"=>"S","\xc5\xa4"=>"T","\xc3\x9a"=>"U","\xc5\xae"=>"U","\xc3\x9c"=>"U","\xc5\xb0"=>"U","\xc3\x9d"=>"Y","\xc5\xbd"=>"Z"," "=>"-");
	 $seo_url = strtr($url, $tbl);
	 $seo_url = str_replace('\"','qt',$seo_url);
	 $seo_url = str_replace('\'','qt',$seo_url);	
	 $seo_url = strtolower($seo_url);
	 $seo_url = preg_replace('~[^-a-z0-9_]+~', '', $seo_url);
	
	return $seo_url; 
	
    }

	
	function add($name, $page, $footer, $category, $home,$title, $keywords, $description, $lang, $template, $img=''){
		
		$seo_url = $this->makeSeoUrl($name);
		$page = addslashes($page);
		$name = addslashes($name);
		$title = addslashes($title);
		$keywords = addslashes($keywords);
		$description = addslashes($description);
		$page = str_replace('</textarea>','{/textarea}',$page);
			
		if(empty($footer)) $footer = 0;
		
		if(empty($home)) $home = 0;
		
		if(!empty($name) && !empty($page)){
			
			/*$seo_url = strtr($seo_url, "áäčďéěëíňóöřą»úůüýžÁÄČĎÉĚËÍŇÓÖŘ©«ÚŮÜÝ® ", "aacdeeeinoorstuuuyzAACDEEEINOORSTUUUYZ-");
			$seo_url = str_replace('\"','qt',$seo_url);
			$seo_url = str_replace('\'','qt',$seo_url);*/
		
			$query = "SELECT COUNT(*) AS pocet FROM ".DBPREFIX."page WHERE name = '$name'";
			
			$sent = mysql_query($query);
			
			$data = mysql_fetch_object($sent);
			
			if($data->pocet == 0){

					$query = "INSERT INTO ".DBPREFIX."page (name, page, footer, home, category, seo_url,title, keywords, description, lang, template, img) 
							  VALUES('$name','$page','$footer','$home','$category', '$seo_url', '$title', '$keywords', '$description', '$lang', '$template','$img')";
					
					if(mysql_query($query)){
						
						$this->msg = PAGE_ADDED;
					
					}
					else{
						
						$this->msg = SQL_ERR0R.mysql_error();
					
					}
					
			}
			else{
				
				$this->msg = PAGE_NAME_EXIST;
			
			}

		}
		else{
			
			$this->msg = FORM_EMPTY;
		
		}
			
	}
	
	var $id, $name, $page, $footer, $category, $home, $title, $keywords, $description, $seo_url;
	
	function select($category){
		
		if(empty($category)) $category = 0;
		
		if($category == 0){
			
			$query = 	"SELECT r.id AS id, r.name AS name, footer, home, rc.name AS cname, t.name AS temp_name
						 FROM ".DBPREFIX."page r, ".DBPREFIX."page_category rc, ".DBPREFIX."template t
						 WHERE category = rc.id AND r.template = t.id
						 ORDER BY r.name ASC";
		
		}
		else{
			
			$query = 	"SELECT r.id AS id, r.name AS name, footer, home, rc.name AS cname, t.name AS temp_name
						 FROM ".DBPREFIX."page r, ".DBPREFIX."page_category rc, ".DBPREFIX."template t
					  	 WHERE category = '$category' AND category = rc.id AND r.template = t.id
						 ORDER BY r.name ASC";
		
		}
			
		$sent = mysql_query($query);
	
		while($data = mysql_fetch_object($sent)){
			
			$this->id[] = $data->id;
			$this->name[] = stripslashes($data->name);
			$this->footer[] = $data->footer;
			$this->category[] = stripslashes($data->cname);
			$this->home[] = stripslashes($data->home);
			$this->template[] = $data->temp_name;
		
		}
	
	}
	
	function select_one($id){
		
		$query = "SELECT * FROM ".DBPREFIX."page WHERE id = '$id'";
		
		$sent = mysql_query($query);
		
		$data = mysql_fetch_object($sent);
		
		$this->id = $data->id;
		$this->name = stripslashes($data->name);
		$this->page = stripslashes($data->page);
		$this->footer = $data->footer;
		$this->category = $data->category;
		$this->home = $data->home;
		$this->title = stripslashes($data->title);
		$this->keywords = stripslashes($data->keywords);
		$this->description = stripslashes($data->description);
		$this->lang = $data->lang;
		$this->template = $data->template;
		$this->foto = $data->img;
                $this->seo_url = $data->seo_url;
	
	}
	
	function delete($id){
	
		$query = "DELETE FROM ".DBPREFIX."page WHERE id = '$id'";
		
		if(mysql_query($query)){
			
			$this->msg = PAGE_DELETED;
		
		}
		else{
			
			$this->msg = SQL_ERROR.mysql_error();
		
		}
	
	}
	
	function edit($id, $name, $page, $footer, $category, $home, $title, $keywords, $description, $lang, $template, $img=''){
		
		$seo_url = $this->makeSeoUrl($name);
		$page = addslashes($page);
		$name = addslashes($name);
		$title = addslashes($title);
		$keywords = addslashes($keywords);
		$description = addslashes($description);
		$page = str_replace('</textarea>','{/textarea}',$page);
		
		if(empty($footer)) $footer = 0;
		
		if(empty($home)) $home = 0;
		
		if(!empty($name) && !empty($page)){
		
			$query = "SELECT COUNT(*) AS pocet FROM ".DBPREFIX."page WHERE id != $id AND name = '$name'";
			
			$sent = mysql_query($query);
			
			$data = mysql_fetch_object($sent);
			
			if($data->pocet == 0){
				
    /*$seo_url = strtr($seo_url, "áäčďéěëíňóöřą»úůüýžÁÄČĎÉĚËÍŇÓÖŘ©«ÚŮÜÝ® ", "aacdeeeinoorstuuuyzAACDEEEINOORSTUUUYZ-");
				$seo_url = str_replace('\"','qt',$seo_url);
				$seo_url = str_replace('\'','qt',$seo_url);*/
	
				$query = "	UPDATE ".DBPREFIX."page 
							SET name = '$name', page = '$page', footer = '$footer', home = '$home', category = '$category', seo_url = '$seo_url',
								title = '$title', keywords = '$keywords', description = '$description', lang = '$lang', template = '$template', img = '$img'
							WHERE id = '$id'";
				
				if(mysql_query($query)){
					
					$this->msg = PAGE_EDITED;
				
				}
				else{
					
					$this->msg = SQL_ERROR.mysql_error();
				
				}
			}
			else{
				
				$this->msg = PAGE_NAME_EXIST;
			
			}
			
		}
		else{
		
			$this->msg = FORM_EMPTY;
		
		}
	
	}

 function edit_page_picture() {
  $id = $_GET["id"];
  if( $id > 0 ){
   global $_FILES;
   if(!isset($_FILES)) return false;

   $ok_type = array("image/jpeg","image/tiff","image/gif","image/png","image/bmp");

   if(is_uploaded_file($_FILES['foto']['tmp_name'])){     
    //je-li mensi jak 8 MB
    if($_FILES['foto']['size'] > 8388608)
     $this->msg = USER_IMAGE_SIZE;
    elseif(!in_array($_FILES['foto']['type'], $ok_type ))
     $this->msg = USER_IMAGE_FORM;
    else{
     // jmeno  
     $type = substr($_FILES['foto']['type'], strpos($_FILES['foto']['type'], '/')+1 );       
     $file_name = "img_page_".$id.".".$type;
     //echo "=".$file_name;
     // cesta
     $path = "../images_page/".$file_name; 
     if(move_uploaded_file($_FILES['foto']['tmp_name'], $path)){
      //sql
      $query = " UPDATE ".DBPREFIX."page "
             . " SET `img` = '$file_name' "
             . " WHERE `id` = '$id' ";                   
      //echo $query;
      if(mysql_query($query)) {			
       $this->msg = USER_IMAGE_EDITED;		
      }
      else {			
       $this->msg = SQL_ERROR.mysql_error();	
       // smazat uploadovany soubor
       unlink($path);	
      }        
     } 
     else{
      $this->msg = USER_IMAGE_SAVE;
     }  
    } 
   } 
   else{
    $this->msg = USER_IMAGE_NONE;
   }
  }
  else{
   $this->msg = STAT_ID_FALSE;
  }        
 }

 // smazani fotky
 function delete_picture() {
  $id = $_GET["id"];
  if( $id > 0 ){
   //sql
   $query = " UPDATE ".DBPREFIX."page " 
          . " SET `img` = '' "
          . " WHERE `id` = '$id' ";                   
   //echo $query;
   if(mysql_query($query)){			
    $this->msg = USER_IMAGE_DEL;		
   }
   else{			
    $this->msg = SQL_ERROR.mysql_error();	
   } 
  }
  else{
   $this->msg = STAT_ID_FALSE;
  }   
 }

}
?>

ACC SHELL 2018