Location: PHPKode > projects > MembersGear > membersgear/admin/admin_fields_m.php
<?php
  
  require_once "../config/config.php"; 

  require_once "../includes/fields_class.php";
  
   require_once INCLUDE_DIR."/users_class.php"; 
   $users=new users_class();
   if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view  fields')==false)
   {
        Redirect('admin_nopermission.php',true);  
      
   } 
   if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can manage fields')==false)
   {
        Redirect('admin_nopermission.php',true);  
      
   } 
  
    if($_SERVER['REQUEST_METHOD']=="GET")
        $_SESSION[SESSION_PREFIX.'page_referrer']=$_SERVER['HTTP_REFERER'];
        
   $loManageFields = new fields_class();
  
switch($_action)
{
    case 'insert':
           //Insert
           $lTypes=null;
           $getDataQuery = 'SELECT * FROM '.TABLE_PREFIX.'singupformfields WHERE name =?';
           $lsNameValues = array(TABLE_FIELD_PREFIX.$_POST['txtFieldName']);
           
           $dataIsExist = $loManageFields->View($getDataQuery,$lsNameValues,null);
           
           if($dataIsExist != null)
           {
                $message->SetMessage('Record with "'.$_POST['txtFieldName'].'" field name is alredy exist.');
                  
                  if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                      Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
                    else  
                       Redirect('admin_fields_v.php'); 
                  
             
                break;
           
           }
              
           $query = 'INSERT INTO '.TABLE_PREFIX.'singupformfields
                    (name, label, description, displaytype, datatype, property, defaultvalue, signupformvisibility, profileformvisibility, validationfurnction, sortorder, createdon, createdby, createdipaddress)
                    VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)';
                    //VALUES('user4','user4','hide@address.com','address1','1950-12-12 00:00:00',1,1)'
                    
           $lsValues = array();         
           
           $lsValues[0] = TABLE_FIELD_PREFIX.$_POST['txtFieldName'];
           $lsValues[1] = $_POST['txtFieldTitle'];
           $lsValues[2] = $_POST['txtFieldDescription'];
           $lsValues[3] = $_POST['rdDisplayType'];
           $lsValues[4] = 'BLOB';//$_POST['ddlSQLFieldType'];
                
                switch($_POST['rdDisplayType'])
                {
                        case 'text':
                                $lsValues[5] = 'maxlength='.$_POST['size'].' size=20';
                                break;
                        case 'textarea':
                                $lsValues[5] = 'cols='.$_POST['cols'].' rows='.$_POST['rows'];
                                break;
                        case 'select':
                        case 'multi_select':
                                $lsValues[5] = $_POST['values'].' size='.$_POST['size'];
                                break;
                        case 'radio':
                        case 'checkbox':
                                $lsValues[5] = $_POST['values'];
                                break;   
                        case 'checkbox(unchecked)':
                        case 'checkbox(checked)':
                                $lsValues[5]=' ';
                                break;
                        case  'label':
                                $lsValues[5]=' ';
                                break;        
                                         
                }
                
           $lsValues[6] = $_POST['default']!=''?$_POST['default']:' ';
           $lsValues[7] = $_POST['ddlDisplaySignup'];
           $lsValues[8] = $_POST['ddlDisplayProfile'];
           $lsValues[9] = $_POST['ddlValidateFunction'];
           $lsValues[10] = $_POST['txtSortOrder'];
           $lsValues[11] = mktime();
           $lsValues[12] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
           $lsValues[13] = $_SERVER['REMOTE_ADDR'];
           
            
           $lsInsertedrows = $loManageFields->Insert($query,$lsValues,$lTypes);

           $message->SetMessage('Field is Insert Successfully.');
                  
                  
          if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                 Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
           else  
               Redirect('admin_fields_v.php');
           
           break;
    case 'update':                     
           //Update           
          
           $lTypes=null;
           
           $getDataQuery = 'SELECT * FROM '.TABLE_PREFIX.'singupformfields WHERE name =?';
           $lsNameValues = array(TABLE_FIELD_PREFIX.$_POST['txtFieldName']);
           
           $dataIsExist = $loManageFields->View($getDataQuery,$lsNameValues,null);
           
           if($dataIsExist != null and $dataIsExist[0]['id'] != $_POST['hiddID'])
           {
                $message->SetMessage('Record with "'.$_POST['txtFieldName'].'" field name is alredy exist.');
                  
                if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                      Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
                    else  
                       Redirect('admin_fields_v.php');
                break;
           
           }
           
           $query = 'UPDATE '.TABLE_PREFIX.'singupformfields SET name=?, label=?, description=?, displaytype=?, datatype=?, property=?, defaultvalue=?, signupformvisibility=?, profileformvisibility=?, validationfurnction=?, sortorder=?, modifiedon=?, modifiedby=?, modifiedipaddress=? WHERE id=?';
           
           $lsValues = array();         
           
           $lsValues[0] = TABLE_FIELD_PREFIX.$_POST['txtFieldName'];
           $lsValues[1] = $_POST['txtFieldTitle'];
           $lsValues[2] = $_POST['txtFieldDescription'];
           $lsValues[3] = $_POST['rdDisplayType'];
           $lsValues[4] = 'BLOB';//$_POST['ddlSQLFieldType'];
           
                switch($_POST['rdDisplayType'])
                {
                        case 'text':
                                $lsValues[5] = 'maxlength="'.$_POST['size'].'" size="20"';
                                break;
                        case 'textarea':
                                $lsValues[5] = 'cols="'.$_POST['cols'].'" rows="'.$_POST['rows'].'"';
                                break;
                        case 'select':
                        case 'multi_select':
                                $lsValues[5] = $_POST['values'].' size='.$_POST['size'];
                                break;
                        case 'radio':
                        case 'checkbox':
                                $lsValues[5] = $_POST['values'];
                                break;
                        case 'checkbox(unchecked)':
                        case 'checkbox(checked)':
                                $lsValues[5]=' ';
                                break;
                        case  'label':
                                $lsValues[5]=' ';
                                break;         
                }
           //$lsValues[5] = $_POST['txtFieldProperty'];
           $lsValues[6] = (isset($_POST['default']) and $_POST['default'] != null) ? $_POST['default'] : ' ';
           $lsValues[7] = $_POST['ddlDisplaySignup'];
           $lsValues[8] = $_POST['ddlDisplayProfile'];
           $lsValues[9] = $_POST['ddlValidateFunction'];
           $lsValues[10] = $_POST['txtSortOrder'];
           $lsValues[11] = mktime();
           $lsValues[12] = $_SESSION[SESSION_PREFIX.'Admin_UserID'];
           $lsValues[13] = $_SERVER['REMOTE_ADDR'];
           $lsValues[14] = $_POST['hiddID'];
           
          $lsUpdatedrows = $loManageFields->Update($query,$lsValues,$lTypes);
            
            $message->SetMessage('Field is Update Successfully.');
                  
           if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                      Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
            else  
                Redirect('admin_fields_v.php');
           break;
    
    case 'edit':
             $lTypes=null;
             $lsValues = array($_GET['id']);
             $query = "SELECT * FROM ".TABLE_PREFIX."singupformfields WHERE id=?";
             
             $result = $loManageFields->View($query,$lsValues,null);
             
             $removePrefix = explode(TABLE_FIELD_PREFIX,$result[0]['name']);
             
                    $result[0]['name'] = $removePrefix[1];
                    switch($result[0]['displaytype'])
                    {
                          case 'label':
                                 break;  
                          case 'text':
                                    $lsTextBoxProperty = str_replace("\"",'',$result[0]['property']);
                                    $lsTextBoxProperty = explode(' ',$lsTextBoxProperty);
                                    $lsTextBoxProperty = explode('=',$lsTextBoxProperty[0]);
                                    //$lsTextBoxProperty = explode('""',$lsTextBoxProperty[1]);
                                    $smarty->assign('size',$lsTextBoxProperty[1]);
                                    break;
                            
                            case 'textarea':   
                                    $lsTextAreaProperty = explode(' ',$result[0]['property']);
                                    $lsTextAreaCols = explode('=',$lsTextAreaProperty[0]);
                                    $lsTextAreaRows = explode('=',$lsTextAreaProperty[1]);
                                    
                                    $smarty->assign('cols',str_replace('"','',$lsTextAreaCols[1]));
                                    $smarty->assign('rows',str_replace('"','',$lsTextAreaRows[1]));                   
                                    break;
                            
                            case 'select':
                            case 'multi_select':
                                    $lsSelectProperty = explode('size=',$result[0]['property']);
                                    $smarty->assign('size',$lsSelectProperty[1]);
                                    $smarty->assign('value',$lsSelectProperty[0]);
                                    break;
                            
                            case 'radio':
                            case 'checkbox':
                                    $smarty->assign('value', $result[0]['property']);
                                    break;
                   }
                    
             
            // print_r($result);
            // die;
             $smarty->assign('data',$result);
             
             $smarty->assign('IsEdit','yes');
               $smarty->display('admin_fields_m.tpl'); 
            break;
    case 'delete':
            if(isset($_GET['id']) and $_GET['id'] != '')
            {
                $lTypes = null;
                $query = 'DELETE FROM '.TABLE_PREFIX.'singupformfields WHERE id=?';
                $lsValues = array($_GET['id']);
                
                $lsDeletedrow = $loManageFields->Delete($query,$lsValues,null);
                
                if($lsDeletedrow > 0)
                {
                    $message->SetMessage('Field is deleted successfully.');
                }   
            }
            
            $quest="&";
            if(isset($_GET) && !empty($_GET))
             {
                 foreach($_GET as $keyname => $value) {
                      if(strtoupper($keyname)!='ACTION')
                         $quest.=$keyname."=".$value."&";
                    }     
             
             }
            
            if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
             else  
                 Redirect("admin_fields_v.php?$quest"); 
        
            break;
            
    default:       
           ////Parameterized View
         /*  $lsValues = array();
           
           $lTypes=null;
           
           $result = $loManageFields->View('SELECT * FROM '.TABLE_PREFIX.'singupformfields');
  
           $smarty->assign('data',$result);
           
           //$smarty->display('admin_fields_m.tpl');  */
          // require_once "../templates/admin_header.php";
         
            $smarty->display('admin_fields_m.tpl');              
}

       
 
?>
Return current item: MembersGear