<?php

class cmsClass extends MasterClass {
	
    ####################################################################################################################################################	
    ####################################################################################################################################################	

    //function to get page information
    public function getPageInfo($PageId){

        $info = array();

        if($this->checkRef()){
            
            if($PageId != ''){

                $this->dbConn();

                $this->query = "SELECT * FROM Pages WHERE page_nbr = '";
                $this->query .= $this->db->real_escape_string($PageId);
                $this->query .= "'";

               $getPage = $this->db->query($this->query);

                if($getPage->num_rows > 0){

                    $row = $getPage->fetch_assoc();

                    $info['Nbr'] = stripslashes($row['page_nbr']);
                    $info['Name'] = stripslashes($row['page_name']);
                    $info['Title_Tag'] = stripslashes($row['page_title_tag']);
                    $info['Keywords_Tag'] = stripslashes($row['page_keywords_tag']);
                    $info['Description_Tag'] = stripslashes($row['page_description_tag']);
                    $info['Content'] = stripslashes($row['page_content']);
                    $info['Date_Created'] = stripslashes($row['page_date_created']);
                    $info['Status'] = stripslashes($row['page_status']);
                    $info['Last_Updated'] = stripslashes($row['page_last_update']);

                }

                $this->dbClose();
                
            }

        }

        return $info;

    }

    ####################################################################################################################################################	
    ####################################################################################################################################################	

    //function to update page information
    public function updatePageInfo(){
        
        $result = array();
        
        if($this->checkRef()){
        
            $data = $this->cleanData();

            if($data['PageId'] != ''){

                $this->dbConn();
                
                $now = time();

                if(isset($data['PageContent'])){

                    $content = $data['PageContent'];

                }else{

                    $content = $data['Desc'];

                }
           
                $this->query = "UPDATE Pages SET page_title_tag = '";
                $this->query .= substr($data['Title_Tag'],0,65);
                $this->query .= "', page_keywords_tag = '";
                $this->query .= $data['Keywords_Tag'];
                $this->query .= "', page_description_tag = '";
                $this->query .= substr($data['Description_Tag'],0,155);
                $this->query .= "', page_content = '";
                $this->query .= $content;
                $this->query .= "', page_status = '";
                $this->query .= $data['Status'];
                $this->query .= "', page_last_update = '";
                $this->query .= $now;                
                $this->query .= "' WHERE page_nbr = '";
                $this->query .= $this->db->real_escape_string($data['PageId']);
                $this->query .= "'"; 

                $this->db->query($this->query);
               
                $this->dbClose();   
                    
                $result['Status'] = 1;
                $result['Class'] = 'success';
                $result['Msg'] = 'The page information has been successfully updated.';
                
            }else{

                $result['Status'] = 0;
                $result['Class'] = 'error';
                $result['Msg'] = 'No Page Id';            

            }
        
        }
        
        return $result;

    }

    ####################################################################################################################################################	
    ####################################################################################################################################################	

    //function to get pages
    public function getPages(){
        
        $info = array();
        
        if($this->checkRef()){
            
            $this->dbConn();
            
            $this->query = "SELECT * FROM Pages ORDER BY page_name ASC";
            
            $getInfo = $this->db->query($this->query);
            
            if($getInfo->num_rows > 0){
                
                $i=0;
                while($row = $getInfo->fetch_assoc()){
                    
                    $info[$i]['Nbr'] = stripslashes($row['page_nbr']);
                    $info[$i]['Name'] = stripslashes($row['page_name']);
                    $info[$i]['Title_Tag'] = stripslashes($row['page_title_tag']);
                    $info[$i]['Keywords_Tag'] = stripslashes($row['page_keywords_tag']);
                    $info[$i]['Description_Tag'] = stripslashes($row['page_description_tag']);
                    $info[$i]['Content'] = stripslashes($row['page_content']);
                    $info[$i]['Date_Created'] = stripslashes($row['page_date_created']);
                    $info[$i]['Status'] = stripslashes($row['page_status']);  
                    $info[$i]['Last_Updated'] = stripslashes($row['page_last_update']);  
                    $i++;
                    
                }
                
            }
            
            $this->dbClose();
            
        }
        
        return $info;
        
    }
 
    ####################################################################################################################################################	
    ####################################################################################################################################################	

    //function to delete content managed page
    function deleteCMP(){
        
        $result = array();
        
       if($this->checkRef()){
           
           $data = $this->cleanData();
           
           if($data['Id'] != ''){
               
               $this->dbConn();
               
               $this->query = "DELETE FROM Pages WHERE page_nbr = '";
               $this->query .= $this->db->real_escape_string($data['Id']);
               $this->query .= "'";
               
               $this->db->query($this->query);
               
               $this->dbClose();
               
               $result['Status'] = 1;
               $result['Msg'] = 'The content managed page has been successfully removed from the system.';
               $result['Class'] = 'success';
               
           }
           
       }
       
       return $result;
        
    }


    
}

?>