Location: PHPKode > projects > MembersGear > membersgear/admin/admin_email_log_m.php
<?php
  require_once "../config/config.php";
  require_once INCLUDE_DIR."/users_class.php"; 
  require_once INCLUDE_DIR."/emaillog_class.php"; 
  $users=new users_class();
  
  if($_SERVER['REQUEST_METHOD']=="GET")
        $_SESSION[SESSION_PREFIX.'page_referrer']=$_SERVER['HTTP_REFERER'];
        
    if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view Email Log')==false)
    {
            Redirect('admin_nopermission.php',true);  
    }

    
    switch($_action)
    {
            case 'show_detail':
                   
                   if(!isset($_GET['ID']) or $_GET['ID'] == '' or !(is_numeric($_GET['ID'])))
                   {
                       Redirect('admin_email_log_v.php'); 
                   }
                   
                   $query = "select pel.id,pet.name,
                        case when pel.sendmessageto = 'Both' then 'Admin / User'
                             when pel.sendmessageto = 'Admin' then 'Admin'
                             when pel.sendmessageto = 'User' then 'User' end as `SendMessageTo`,
                        concat(pel.sender_name,'<br/>(',pel.sender_email,')') as `Sender`,
                        substring_index(pel.email_attachment,'/',-1) as `EmailAttachment`,
                        pel.email_message,
                        pel.admin_email_message,    
                        case when pel.sendmessageto = 'Both' then concat(pel.admin_email_format,' / ',pel.email_format)
                             when pel.sendmessageto = 'Admin' then concat(pel.admin_email_format)
                             when pel.sendmessageto = 'User' then concat(pel.email_format) end as `EmailFormat`,
                        from_unixtime(pel.createdon,'%Y-%m-%d<br/>%h:%i:%s') as `SendDate`,
                        case when pel.senttype = 1 then 'By Cron Job' else 'Manual' end as `SendType`,
                        pu.username as `UserName`

                        from ".TABLE_PREFIX."emails_log pel
                            join ".TABLE_PREFIX."email_templates pet on pet.id = pel.email_template_id
                            join ".TABLE_PREFIX."users pu on pu.id = pel.sentto_userid
                        WHERE pel.id = ".$_GET['ID'];
                        
                    $laResult = $users->View($query);
                    
                    //print_r($laResult[0]);
                    
                    //die;
                    
                    $smarty->assign('LogData',$laResult[0]);
                    $smarty->display('admin_email_log_m.tpl');    
                   
                    break;
            case 'delete_log':
                            if ($_SERVER['REQUEST_METHOD'] == 'POST')
                            {
                                $loEmailLog = new emaillog_class();
                                if((isset($_POST['chkDeleteItem']) and $_POST['chkDeleteItem'] != '') or isset($_POST['btnDeleteAll']))
                                {
                                    //print_r($_POST);die;
                                    $delete = (isset($_POST['btnDeleteSelected'])) ? $_POST['btnDeleteSelected'] : $_POST['btnDeleteAll'];
                                    switch($delete)
                                    {
                                        case 'Delete Selected':
                                                $deleteQuery = 'DELETE FROM '.TABLE_PREFIX.'emails_log WHERE id=?';
                                                foreach($_POST['chkDeleteItem'] as $k=>$val)
                                                {
                                                    $laDeleteID = array($val);
                                                    $qsueryResult = $loEmailLog->Delete($deleteQuery,$laDeleteID,null);         
                                                    unset($laDeleteID);
                                                }
                                                break;
                                        case 'Delete All':
                                                $deleteQuery = 'DELETE FROM '.TABLE_PREFIX.'emails_log';
                                                $qsueryResult = $loEmailLog->Delete($deleteQuery,null,null);         
                                                break;
                                    }
                                    $message->SetMessage('Email log deleted successfully.');
                                }
                                
                                 $quest="&";
                                if(isset($_GET) && !empty($_GET))
                                 {
                                     foreach($_GET as $keyname => $value) {
                                          $quest.=$keyname."=".$value."&";
                                        }     
                                 
                                 }
                                 
                         if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
                            Redirect($_SESSION[SESSION_PREFIX.'page_referrer'],true);
                         else  
                            Redirect("admin_email_log_v.php?$quest");
     
   
                            }
                    break;
            case 'search_log':
                    if ($_SERVER['REQUEST_METHOD'] == 'POST')
                    {
                            $EmailTemplateName = (isset($_POST['txtEmailTemplateName']) and $_POST['txtEmailTemplateName'] != '') ? $_POST['txtEmailTemplateName'] : null;
                            $Sender = (isset($_POST['txtSender']) and $_POST['txtSender']) ? $_POST['txtSender'] : null;
                            $MessageSentTo = (isset($_POST['ddlMessageSentTo']) and $_POST['ddlMessageSentTo']) ? $_POST['ddlMessageSentTo'] : null;
                            $EmailFormat= (isset($_POST['ddlEmailFormat']) and $_POST['ddlEmailFormat']) ? $_POST['ddlEmailFormat'] : null;
                            $EmailAttachment = (isset($_POST['txtEmailAttachment']) and $_POST['txtEmailAttachment']) ? $_POST['txtEmailAttachment'] : null;
                            $SentDate = (isset($_POST['txtSentDate']) and $_POST['txtSentDate']) ? strtotime($_POST['txtSentDate']) : null;
                            $SentType = (isset($_POST['ddlSentType']) and $_POST['ddlSentType']) ? $_POST['ddlSentType'] : null;
                            $SentTo = (isset($_POST['txtSentTo']) and $_POST['txtSentTo']) ? $_POST['txtSentTo'] : null;
                            
                            $LogFilter = '';
                            $seprator = '';
                            
                            if(isset($EmailTemplateName))
                            {
                                  $LogFilter .= 'pet.name='.$EmailTemplateName;
                                  $seprator   = ',';
                            }
                            
                            if(isset($Sender))
                            {
                                  $LogFilter .= $seprator.'pel.sender_name='.$Sender;
                                  $seprator   = ',';
                            }
                            
                            if(isset($MessageSentTo))
                            {
                                  $LogFilter .= $seprator.'pel.sendmessageto='.$MessageSentTo;
                                  $seprator   = ',';
                            }
                            
                            if(isset($EmailFormat))
                            {
                                  $LogFilter .= $seprator.'pel.email_format='.$EmailFormat;
                                  $seprator   = ',';
                            }
                            
                            if(isset($EmailAttachment))
                            {
                                  $LogFilter .= $seprator.'pel.email_attachment='.$EmailAttachment;
                                  $seprator   = ',';
                            }
                            
                            if(isset($SentDate))
                            {
                                  $LogFilter .= $seprator.'pel.createdon='.$SentDate;
                                  $seprator   = ',';
                            }
                            
                            if(isset($SentType))
                            {
                                  $LogFilter .= $seprator.'pel.senttype='.$SentType;
                                  $seprator   = ',';
                            }
                            
                            if(isset($SentTo))
                            {
                                  $LogFilter .= $seprator.'pu.username='.$SentTo;
                                  $seprator   = ',';
                            }
                        
                        $LogFilter = (isset($LogFilter) and $LogFilter != '') ? $LogFilter : null;    
                    }
                    if(isset($LogFilter))
                    {
                        Redirect('admin_email_log_v.php?filter='.$LogFilter);  
                    }
                    else
                    {
                        Redirect('admin_email_log_v.php');   
                    }
                    
                    break;
    }
?>
Return current item: MembersGear