Location: PHPKode > projects > MembersGear > membersgear/includes/system_get_set_options_class.php
<?php
 require_once "peardb_class.php";   
 class system_get_set_options_class extends peardb_class
 {   
      
        function View($pQuery, $pValues=false, $types=true, $pStart=0, $pEnd=0)
        {
            return $this->BaseView($pQuery,$pValues,$types,$pStart,$pEnd);
            
        }
        
        function Update($pQuery, $pValues=false, $types=true)
        { 
           
            return $this->BaseUpdate($pQuery, $pValues, $types);
        
        }

        
        function Insert($pQuery, $pValues=false, $types=true)
        { 
        
            return $this->BaseInsert($pQuery, $pValues, $types);
        
        }
        
        function Delete($pQuery, $pValues=false, $types=true)
        { 
        
            return $this->BaseDelete($pQuery, $pValues, $types);
        
        }
        
        function get_option($pOption_name)
        {
            $lsvalue='';  
            if(!isset($_SESSION[SESSION_PREFIX."system_options"]))
            {
                $lsvalue=array();
                $lsvalue[]=trim($pOption_name);
                $query="SELECT option_name,option_value from  ".TABLE_PREFIX."options ";
                $result=$this->View($query,$lsvalue,null);
                $option_arr=array();
                foreach($result as $val)
                {
                  $option_arr[$val[option_name]]=$val['option_value'];
                }
                $_SESSION[SESSION_PREFIX."system_options"]=$option_arr;
               
                if(array_key_exists($pOption_name,$_SESSION[SESSION_PREFIX."system_options"]))
                 {
                   $lsvalue=$_SESSION[SESSION_PREFIX."system_options"][$pOption_name];
                 } 
            }  
           else
            { 
               if(array_key_exists($pOption_name,$_SESSION[SESSION_PREFIX."system_options"]))
                 {
                   $lsvalue=$_SESSION[SESSION_PREFIX."system_options"][$pOption_name];
                 }
               else {
                     
                     $query="SELECT option_name,option_value from  ".TABLE_PREFIX."options WHERE option_name='".$pOption_name."';";
                     
                     $result=$this->View($query,$lsvalue,null);
                     
                     //print_r($result);
                     //die;
                     if(isset($result[0]['option_name']) && isset($result[0]['option_value']) ) {
                         
                         $_SESSION[SESSION_PREFIX."system_options"][$result[0]['option_name']] = $result[0]['option_value'];
                             
                     } 
                     
                     
                 }  
         
            }
            return $lsvalue;   
            
        }
        
        
        function set_option($pOption_name,$pOption_value)  
        {
           
            $lsValues[]=trim($pOption_name);
            $lsValues[]=trim($pOption_value);
            $lsValues[]="true";
          
             $query="INSERT INTO ".TABLE_PREFIX ."options 
                                          (option_name,option_value,autoload)VALUES (?,?,?)";      
             $lsInsertedrows = $this->BaseInsert($query,$lsValues,null);
             if($lsInsertedrows>0)
                return true;
             
        }


        function remove_option($pOption_name)  
        {
           
            $pQuery="delete from ".TABLE_PREFIX."options  where option_name=? "; 
            $pValues[]=$pOption_name; 
            return $this->BaseDelete($pQuery, $pValues, null); 
             
        }
        
            
        function update_option($pOption_name,$pOption_value)  
        {
                if ($pOption_name=='' or $pOption_name==null)
                 $pOption_name=' ';
                
                if(($pOption_value=='' or $pOption_value==null) and $pOption_value!=0 ) 
                  $pOption_value=' ';
                  
                $lsval=array();
                $lsval[]=trim($pOption_name);
                $query="SELECT * from  ".TABLE_PREFIX."options where option_name=?";
                $result=$this->View($query,$lsval,null);
                $lsvalue='';
                if(is_array($result) && sizeof($result)>0)
                 {
                        $lsValues[]=$pOption_value;
                        $lsValues[]=$pOption_name;
                      
                        
                        $query="update ".TABLE_PREFIX ."options set option_value=? where option_name=? ";      
                        $lsUpdatedrows = $this->BaseUpdate($query,$lsValues,null);
                  }
                 else
                  {
                  
                        $lsValues[]=$pOption_name;
                        $lsValues[]=$pOption_value;
                        $lsValues[]="true";
                      
                        $query="INSERT INTO ".TABLE_PREFIX ."options 
                                (option_name,option_value,autoload)VALUES (?,?,?)";      
                        $lsInsertedrows = $this->BaseInsert($query,$lsValues,null);
                       
                  
                  } 
             
        }
    
    
 }   
?>
Return current item: MembersGear