Location: PHPKode > projects > MembersGear > membersgear/admin/admin_export.php
<?php
  require_once "../config/config.php";
  require_once INCLUDE_DIR."/users_class.php";
  require_once INCLUDE_DIR."/product_class.php";
  require_once INCLUDE_DIR."/export_class.php";
   
  $users = new users_class();   
  $loProductClass = new product_class();
  $loExportClass = new export_class();
  
  if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can run export')==false)
  {
    Redirect('admin_nopermission.php',true);  
  }
  
    switch($_action)
    {
        case 'generateCSV':
                $query = '';
                $condition = '';
                $query = 'SELECT ';
                
                if($_POST['ddlMemberFields'] == null and $_POST['ddlSubFields'] == null)
                {
                        $message->SetMessage('Please select atleast one field for export.');
                        Redirect('admin_export.php');
                        break;  
                }
                
                $laMemberFields  = ($_POST['ddlMemberFields'] != null) ? $_POST['ddlMemberFields'] : '';
                if($laMemberFields != '')
                {
                    $query = $loExportClass->SetMemberFields($query,$laMemberFields);
                }
                
                $laProductFields = ($_POST['ddlSubFields'] != null) ? $_POST['ddlSubFields'] : '';
                if($laProductFields != '')
                {
                    $query = $loExportClass->SetSubscriptionFields($query,$laProductFields);
                }
                
                $query .= 'FROM '.TABLE_PREFIX.'users pu, '.TABLE_PREFIX.'product_users tpu';
                $query = str_replace(', FROM ',' FROM ',$query);
                $query .= ' WHERE pu.id = tpu.userid'; 
                
                $laRecordSelect = ($_POST['ddlRecordSelect'] != null) ? $_POST['ddlRecordSelect'] : '';
                if($laRecordSelect != '')
                {
                    $query = $loExportClass->SetRecordSelections($query,$laRecordSelect);
                    $condition = ' AND ';   
                }
                else
                {
                    $condition = ' AND ';   
                }
                
                $_POST['date_check'] = ($_POST['date_check'] != '') ? 'true' : 'false';
                $liBeginDate = strtotime(($_POST['txtBeginDate'] != '') ? $_POST['txtBeginDate'] : 0) ;
                $liEndDate = strtotime(($_POST['txtEndDate'] != '') ? $_POST['txtEndDate'] : 0 );
                                            
                if($liBeginDate > 0 and $liEndDate > 0 and $_POST['date_check'] == 'false')
                {
                    $query .= $condition;
                    $query = $loExportClass->SetDateRange($query,$liBeginDate,$liEndDate);
                    $condition = ' AND ';   
                }
                
                $laProductList = ($_POST['ddlProductList'] != null) ? $_POST['ddlProductList'] : '';
                if($laProductList != null)
                {
                    $query .= $condition;
                    $query = $loExportClass->SetProductList($query,$laProductList);
                    $condition = ' AND ';
                }
                
                
                //$laMultipleSubscription = ($_POST['ddlMultipleSub'] != null) ? $_POST['ddlMultipleSub'] : '';
                //Commented by Pankaj
                //$query .= ')';
                              
                
                
                //Chaneg by Pankaj
                //$query = str_replace('OR )','',$query);
                $query = str_replace('OR )',')',$query);
                
                
                $_POST['txtDelim'] = ($_POST['txtDelim'] != '' and ($_POST['txtDelim'] == ',' or $_POST['txtDelim'] == ';')) ? $_POST['txtDelim'] : ',';
                $_POST['chkquote'] = ($_POST['chkquote'] != '') ? '"' : '';
                $_POST['chksend_file'] = ($_POST['chksend_file'] != '') ? $_POST['chksend_file'] : 0;
                
                $filename = 'membersite-'.date("Ymd").'.csv';
                $Result = $loExportClass->exportMysqlToCsv($query,$filename,$_POST['txtDelim'],$_POST['chkquote'],$_POST['chksend_file']); 
                //print_r($Result);
                //echo $ShowData;
                //die;
                
                if($_POST['chksend_file'] == 0)
                {
                    
                     $count = 0;
                        $ShowData = ' 
                                        <table cellpadding=0 cellspacing=0 border=0>';
                        foreach($Result as $key=>$value)
                        {
                            //echo $value.'<br/>';
                            $explodeData = explode(',',$value);
                                  $ShowData .= '<tr>';
                            foreach($explodeData as $key1=>$value1)
                            {
                                  $ShowData .= '<td class="right-side-text">';
                                  $ShowData .= ($value1 != '') ? ($count ==0 ? '<strong>'.$value1.'</strong>' : $value1) : '&nbsp;'; 
                                  $ShowData .= '</td>'; 
                            }
                                  $ShowData .= '</tr>';
                                  $count = 1;
                        }
                        
                        $ShowData .= '  </table>';
                        
                    
                     //echo $Result;
                     $Result = str_replace("\n","<br/>",$Result);
                     $smarty->assign('ShowResult',$ShowData);
                     $smarty->assign('ShowContent','true');
                     $smarty->display('admin_export.tpl');
                }
                //echo $query."<br/>";
                //echo $filename;
                //die;
                break;
        
        default:
                
                $query = 'SELECT * FROM '.TABLE_PREFIX.'products WHERE IsApproved = 1 AND (IsDeleted =0 OR IsDeleted is null) AND (isprohibited = 0 OR isprohibited is null) AND islinkedwithpaygear = 1;';
                
                $laProductList = $loProductClass->View($query);
                
                if($message->IsMessageExists())
                {    
                    $lsmsg=$message->GetMessage();
                    $smarty->assign('msg',$lsmsg);
                }
                
                $smarty->assign('ProductList',$laProductList);
                $smarty->display('admin_export.tpl');
        
    }
?>
Return current item: MembersGear