Location: PHPKode > projects > MembersGear > membersgear/admin/admin_email_log_v.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();
   $lsmanageemaillog=true;   
   
  if(isset($_SESSION[SESSION_PREFIX.'page_referrer']))
      unset($_SESSION[SESSION_PREFIX.'page_referrer']);
      
   if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can view Email Log')==false)
   {
        Redirect('admin_nopermission.php',true);  
      
   }
   if($users->IsAdminhavePermission($_SESSION[SESSION_PREFIX.'Admin_UserID'],'Can manage Email Log')==false)
   {
       $lsmanageemaillog=false; 
      
   }
   
   require_once INCLUDE_DIR."/datepicker/class/class.oCalendarPicker.php";

     $aMonthNames=array(
         "FR"=>array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"),
         "EN"=>array("January","February","March","April","May","June","July","August","September","October","November","December")
     );
     $aDaysNames=array(
         "FR"=>array("Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi", "Dimanche"),
         "EN"=>array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
    );
     $sDateFormat=array(
         "FR"=>"m/d/Y",
         //"EN"=>"m/d/Y"
         "EN"=>"Y-m-d"
    );
    
    $sDate=(!empty($_GET['sDate']))?$_GET['sDate']:date("Ymd");
   
      /*
        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.');
            }
            Redirect('admin_email_log_v.php');
            exit(); 
        }
        */
 
 //for display the header.php
 
          echo($smarty->fetch('admin_header.php'));
          //echo PrintABCDPaging();
          //phpinfo();
           
            echo "<div id=\"content\" class=\"setdiv\"> ";
           
            if($message->IsMessageExists())
            {    
                $lsmsg=$message->GetMessage();
                echo "<div class=\"succmsg\" style=\"width:200px\">$lsmsg</div>";
            }
            echo "
                    <script language=\"JavaScript\">
                        function CheckAll(elementID)
                        {
                            var CheckSelect = document.getElementById('chkSelectAll');
                            var LabelCheckSelect = document.getElementById('lblSelect');
                            var AllCheckBox = document.getElementsByName('chkDeleteItem[]');
                            //alert(CheckSelect.checked);
                            //alert(AllCheckBox.length);
                            
                            switch(elementID)
                            {
                                case 'chkSelectAll':
                                        if(CheckSelect.checked)
                                        {
                                             //alert(AllCheckBox.length);
                                             LabelCheckSelect.innerHTML = 'Uncheck All';
                                            for(i=0;i<AllCheckBox.length;i++)
                                            {
                                                AllCheckBox[i].checked = 'true';
                                            }
                                        }
                                        else
                                        {
                                            LabelCheckSelect.innerHTML = 'Check All';
                                            for(i=0;i<AllCheckBox.length;i++)
                                            {
                                                AllCheckBox[i].checked = '';
                                            }
                                        }
                                        break;
                                case 'ckhDeleteItem':
                                        var flag = 1;
                                        for(i=0;i<AllCheckBox.length;i++)
                                        {
                                            if(!AllCheckBox[i].checked)
                                            {
                                                  flag = 0;
                                            }
                                        }
                                        
                                        if(flag == 0)
                                        {
                                             LabelCheckSelect.innerHTML = 'Check All';
                                             CheckSelect.checked = '';
                                        }
                                        else
                                        {
                                             LabelCheckSelect.innerHTML = 'Uncheck All';
                                             CheckSelect.checked = 'true';
                                        }
                            }
            
                        }
                        
                        function ValidateCheckbox(str)
                        {
                              var AllCheckBox = document.getElementsByName('chkDeleteItem[]');
                              var flag = 0;  
                                for(i=0;i<AllCheckBox.length;i++)
                                {
                                        if(AllCheckBox[i].checked)
                                        {
                                                  flag = 1;
                                        }
                                }
                                
                                if(flag == 0 && str == 'selected')
                                {
                                    alert('Please select atleast one record to delete!');
                                    return false;
                                }
                                else
                                {
                                    return confirm('Are you sure to delete '+str+' Email logs?');
                                    //return true;
                                }
                        }
                        
                        function ValidateSearchForm()
                        {
                            var EmailTemplateName = document.getElementById('txtEmailTemplateName');
                            var Sender = document.getElementById('txtSender');
                            var MessageSentTo = document.getElementById('ddlMessageSentTo');
                            var EmailFormat= document.getElementById('ddlEmailFormat');
                            var EmailAttachment = document.getElementById('txtEmailAttachment');
                            var SentDate = document.getElementById('txtSentDate');
                            var SentType = document.getElementById('ddlSentType');
                            var SentTo = document.getElementById('txtSentTo');
                            
                            var flag = 1;
                            
                            if(EmailTemplateName.value == '' && Sender.value == '' && MessageSentTo.options[MessageSentTo.selectedIndex].value == '' && EmailFormat.options[EmailFormat.selectedIndex].value == '' && EmailAttachment.value == '' && SentDate.value == '' && SentType.options[SentType.selectedIndex].value == '' && SentTo.value == '')
                            {
                                    flag = 0;
                            }
                            
                            if(flag == 0)
                            {
                                //alert('Please enter atleast one field for search?');
                                return true;
                            }
                            else
                            {
                                return true;
                            }
                            
                        }
                    </script>
                
                 ";
                 
                 /**************************** Filter Log *********************************/     
                 if(isset($_GET['filter']))
                 {
                     $SearchFor = explode(',',$_GET['filter']);
                     $FilterString = array();
                     $ControlValue = array();
                     foreach($SearchFor as $key=>$searchvalue)
                     {
                         $tempKey = explode('=',$searchvalue);
                         if($tempKey[0] == 'pel.createdon')
                         {
                              $FilterString[$tempKey[0]] = "from_unixtime(pel.createdon,\"%Y-%m-%d\") = from_unixtime(".$tempKey[1].",\"%Y-%m-%d\")";
                              $ControlValue[$tempKey[0]] = $tempKey[1];
                         }
                         elseif($tempKey[0] == 'pel.email_format')
                         {
                             if($ControlValue['pel.sendmessageto'] == 'Admin')
                             {
                                  $searchvalue = 'pel.admin_email_format='.$tempKey[1];
                                  $FilterString[$tempKey[0]] = str_replace('=',' like \'%',$searchvalue)."%'";
                             }
                             elseif($ControlValue['pel.sendmessageto'] == 'User')
                             {
                                   $searchvalue = 'pel.email_format='.$tempKey[1];
                                   $FilterString[$tempKey[0]] = str_replace('=',' like \'%',$searchvalue)."%'";
                             }
                             else
                             {
                                    $searchvalue = 'pel.email_format='.$tempKey[1];
                                    $FilterString[$tempKey[0]] = str_replace('=',' like \'%',$searchvalue)."%'";
                             
                                    $searchvalue = 'pel.admin_email_format='.$tempKey[1];
                                    $FilterString[] = str_replace('=',' like \'%',$searchvalue)."%'";
                             }
                             
                             $ControlValue[$tempKey[0]] = $tempKey[1]; 
                         }
                         else
                         {
                              $FilterString[$tempKey[0]] = str_replace('=',' like \'%',$searchvalue)."%'";
                              $ControlValue[$tempKey[0]] = $tempKey[1];
                         } 
                         //echo $searchvalue." ".$key."<br>";
                     }
                     $SearchFor = implode(' AND ',$FilterString);
                     //echo $SearchFor;
                     //die;
                     //echo str_replace(',',' OR ',$_GET['filter']);die;
                 } 
            /*****************************************************************************/
            
            echo "<div id=\"full-contentdiv\">";
            echo "<div class=\"righttop\">";
            echo "<h2 align=\"center\">";
            echo "Email Log List";
            echo "</h2>";
            echo "</div>";
            echo "<div class=\"whole-page clear\">";   
            echo "
                    <div style='width:925px;margin-bottom:10px' class='formformat'>
                            <form action='admin_email_log_m.php?action=search_log' method='POST' name='frmSearchLog' id='frmSearchLog'>
                                    <table cellspacing='0' cellpadding='0' border='0'>
                                           <tr>
                                                <td class='right-side-text' style='width:150px'>
                                                    <label>Email Template :</label>
                                                </td>
                                                <td class='left-side-text' style='width:150px'>
                                                    <input type='text' id='txtEmailTemplateName' name='txtEmailTemplateName' class='txtcss' value='".$ControlValue['pet.name']."'>
                                                </td>
                                                
                                                <td class='right-side-text' style='width:150px'> 
                                                    <label>Sender :</label>
                                                </td>
                                                <td class='left-side-text' style='width:150px'>
                                                    <input type='text' id='txtSender' name='txtSender' class='txtcss' value='".$ControlValue['pel.sender_name']."'>
                                                </td>
                                                
                                                <td class='right-side-text' style='width:150px'>
                                                    <label>Message sent to :</label>
                                                </td>
                                                <td class='left-side-text' style='width:150px'>
                                                    <select id='ddlMessageSentTo' name='ddlMessageSentTo' class='selectcss' style='width:125px'>
                                                             <option value=''>Select</option>
                                                             <option value='Both' ";
                                                             if($ControlValue['pel.sendmessageto'] == 'Both')
                                                                    echo "selected='selected'>Both</option>";
                                                             else
                                                                    echo ">Both</option>";
                                                             echo "
                                                             
                                                             <option value='Admin' ";
                                                             
                                                             if($ControlValue['pel.sendmessageto'] == 'Admin')
                                                                    echo "selected='selected'>Admin</option>";
                                                             else
                                                                    echo ">Admin</option>";
                                                             
                                                             echo "
                                                             
                                                             <option value='User'";
                                                             
                                                             if($ControlValue['pel.sendmessageto'] == 'User')
                                                                    echo "selected='selected'>User</option>";
                                                             else
                                                                    echo ">User</option>";
                                                             
                                                             echo "
                                                             
                                                    </select>
                                                </td>
                                           </tr>
                                           
                                           <tr>
                                                <td class='right-side-text'>
                                                    <label>Email Format :</label>
                                                </td>
                                                <td class='left-side-text'>
                                                    <select id='ddlEmailFormat' name='ddlEmailFormat' class='selectcss' style='width:125px;'>
                                                             <option value=''>Select</option>
                                                             <option value='HTML'";
                                                             if($ControlValue['pel.email_format'] == 'HTML')
                                                                    echo "selected='selected'>HTML</option>";
                                                             else
                                                                    echo ">HTML</option>";
                                                                    
                                                             echo "<option value='Text'";
                                                             if($ControlValue['pel.email_format'] == 'Text')
                                                                    echo "selected='selected'>TEXT</option>";
                                                             else
                                                                    echo ">TEXT</option>";
                                                             
                                                             echo"
                                                    </select>
                                                    
                                                </td>
                                                
                                                <td class='right-side-text'>
                                                    <label>Email Attachment :</label>
                                                </td>
                                                <td class='left-side-text'>
                                                    <input type='text' id='txtEmailAttachment' name='txtEmailAttachment' class='txtcss' value='".$ControlValue['pel.email_attachment']."'>
                                                </td>
                                                
                                                 <td class='right-side-text'>
                                                    <label>Sent Type :</label>
                                                </td>
                                                <td class='left-side-text'>
                                                    <select id='ddlSentType' name='ddlSentType' class='selectcss' style='width:125px'>
                                                             <option value=''>Select</option>
                                                             <option value='1' ";
                                                             
                                                             if($ControlValue['pel.senttype'] == 1)
                                                                    echo "selected='selected'>By Cron Job</option>";
                                                             else
                                                                    echo ">By Cron Job</option>";
                                                              
                                                             
                                                            echo " <option value='2' ";
                                                            
                                                            if($ControlValue['pel.senttype'] == 2)
                                                                    echo "selected='selected'>Manual</option>";
                                                             else
                                                                    echo ">Manual</option>";
                                                            
                                                            echo "
                                                    </select>
                                                    
                                                </td>
                                                
                                                
                                           </tr>
                                           
                                           <tr>
                                               
                                                <td class='right-side-text'>
                                                    <label>Sent To :</label>
                                                </td>
                                                <td class='left-side-text'>
                                                    <input type='text' id='txtSentTo' name='txtSentTo' class='txtcss' value='".$ControlValue['pu.username']."'>
                                                </td>
                                                <td class='right-side-text'>
                                                    <label>Sent Date :</label>
                                                </td>
                                                <td class='left-side-text'>
                                                    <input type='text' id='txtSentDate' readonly='readonly' name='txtSentDate' class='txtcss' style='width:95px' value='";
                                                    if($ControlValue['pel.createdon'] != '')
                                                        echo date("Y-m-d",$ControlValue['pel.createdon']);
                                                    echo "'>";
                                                    echo "<input type='button' value='' style='background:url(".ADMIN_IMAGE_DIR."/calendar1.gif) no-repeat;height:20px;width:21px;border:0px;'   onclick=\"displayCalendar(document.forms[0].txtSentDate,'yyyy-mm-dd',this)\">";    
                                                  
                                                   /* $aCalendarParams=array(
                                                     "sIconPath"     =>  ADMIN_IMAGE_DIR."/calendar1.gif",
                                                     "iAction"       =>  1,   //0=>reloadCurrentPage with get param sDate, 1=>fill field sFieldName
                                                     "sFieldName"    =>  "txtSentDate",
                                                     "iStyle"        =>  1,   //0=>display calendar, 1=>display div on icon click
                                                     "aMonthNames"   =>  $aMonthNames["EN"],
                                                     "aDaysNames"    =>  $aDaysNames["EN"],
                                                     "sDateFormat"   =>  $sDateFormat["EN"]

                                                     );          
                                                     new oCalendarPicker("calFixe1",$sDate,$aCalendarParams);   */
                   echo"                             </td>
                                                
                                                <td class='right-side-text' colspan='2'>
                                                    <label>&nbsp;</label>
                                                </td>
                                                
                                           </tr>
                                           
                                           <tr>
                                                <td colspan='6' class='buttontd' style='text-align:center;'>
                                                    <input type='submit' id='FilterSubmit' name='FilterSubmit' value='Search Email Log' style='width:150px' class='btncss' onclick='return ValidateSearchForm();'>
                                                </td>
                                           </tr>
                                    </table>
                            </form>
                    </div>   
            ";    
             $quest="&";
                if(isset($_GET) && !empty($_GET))
                 {
                     foreach($_GET as $keyname => $value) {
                          $quest.=$keyname."=".$value."&";
                        }     
                 
                 }
            echo "<form name=\"frmDeleteLog\" action=\"admin_email_log_m.php?action=delete_log$quest\" method=\"POST\">"; 
            /****************************************************************************
            * Updated By Jayesh : for display character based paging
            *****************************************************************************/
            echo "<div class=\"divABCDPaging\">";
            echo PrintABCDPaging();
             echo "</div>";
            echo "<div style=\"text-align:center;margin:2px;overflow:hidden;clear:both;height:30px\">";  
            echo "<div style=\"margin-left:3px;margin-top:3px;text-align:left;font-weight:bold !important;float:left;width:120px;\">"; 
            if($lsmanageemaillog==true)
            {
               echo "<input type=\"checkbox\" class=\"chkcss\" id=\"chkSelectAll\" name=\"chkSelectAll\" onclick=\"return CheckAll(this.id)\"> <label id=\"lblSelect\" for=\"chkSelectAll\">Check All</label>";              
            }
            
             echo "</div>";
             echo "</div>";
              
            
             if(isset($_GET['letter']) and $_GET['letter'] != 'all')
             {
                    $lsSearchLetter = $_GET['letter'];
             }
             else
             {
                    $lsSearchLetter = '';   
             }
         
         
            
          //echo $res;
                /*$sql = 'SELECT *,CASE WHEN bantype = 1 THEN \'IP Address\' WHEN bantype = 2 THEN  \'Hostname\' WHEN bantype = 3 THEN \'Range\' END AS `BanType`,CASE WHEN `isactive` = 1 THEN \'Active\' WHEN `isactive` = 0 THEN \'InActive\' END AS `Status` FROM '.TABLE_PREFIX.'banlist';*/
                
                $sql = "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`,
                        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`,
                        concat('<input type=\"checkbox\" id=\"ckhDeleteItem\" name=\"chkDeleteItem[]\" onclick=\"return CheckAll(this.id)\" value=\"',pel.id,'\" />') as `CheckToDelete`,
                        concat('<a href=\"#\" onclick=\"window.open(\'admin_email_log_m.php?action=show_detail&ID=',pel.id,'\',\'\',\'dependent=1,scrollbars=1,diretories=0,height=600px,width=800px,location=0\');return false;\">More Detail</a>') as `More`

                        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";
                       
                       $queryCondition = '';
                       
                       if(isset($lsSearchLetter) and $lsSearchLetter != '')
                       {     
                                $sql .= " WHERE pet.name like '$lsSearchLetter%'";
                                $queryCondition = ' AND ';
                       }
                       
                        if(isset($SearchFor))
                        {
                            if($queryCondition != '')
                                    $sql .= $queryCondition."(".$SearchFor.")";   
                            else
                                    $sql .= ' WHERE '.$SearchFor;
                        }
                        
                        
                       //echo $sql;die;
                # execute the sql query
                $db->execute($sql);
                $totalrowcount=$db->rowCount(); 
             

                # creates a new phpSortColumn object for ID´s 
                //$col_0 = new phpSortColumn("id", "ID");
                
                #creates a new phpSortcolunm objects for name
                if($lsmanageemaillog==true)
                    $col_0 = new phpSortColumn("CheckToDelete","");
                
                $col_1 = new phpSortColumn("name", "Email Template");
                
                # creates a new phpSortColumn object for Tile
                $col_2 = new phpSortColumn("Sender", "Sender");

                # creates a new phpSortColumn object for Field Type
                $col_3 = new phpSortColumn("SendMessageTo", "Message sent to");
                
                $col_4 = new phpSortColumn("EmailFormat","Email Format<br/>(Admin / User)");
                
                $col_5 = new phpSortColumn("EmailAttachment","Email Attachment");
                
                $col_6 = new phpSortColumn("SendDate","Sent Date");
                
                $col_7 = new phpSortColumn("SendType","Sent Type");
                
                $col_8 = new phpSortColumn("UserName","Sent To");
                
                $col_9 = new phpSortColumn("More","");

                
                # add the columns to an array 
                if($lsmanageemaillog==true)
                    $columns = array(0=>$col_0, 1=>$col_1, 2=>$col_2, 3=>$col_3, 4=>$col_4, 5=>$col_5, 6=>$col_6, 7=>$col_7, 8=>$col_8, 9=>$col_9);
                else
                    $columns = array(1=>$col_1, 2=>$col_2, 3=>$col_3, 4=>$col_4, 5=>$col_5, 6=>$col_6, 7=>$col_7, 8=>$col_8, 9=>$col_9); 
                # create a new phpSortable object with the abstracted db object
                # and the array of column object
                $sortable = new phpSortable($db, $columns);

                # define the table format: cellpadding, cellspacing, border
                $sortable->setTableFormat ("2", "2", "0");

                # define the table title
                $sortable->tableTitle = "";

                # Encrypt Edit and Delete Link
                $sortable->encryptlink = false;
                
                # define the key name to be attached to links
                $sortable->urlKeyName = "id";

                # define the column name of to be attached to links as key value
                $sortable->tableKeyName = "id";

                # define the message to be diplayed if there are no results found
                $sortable->emptyMsg = "No Email Logs Found.";
                
                

                #define the deafult row number to be displayed
                $sortable->defaultRowsNum = "10";

                #define the path for the css file
                $sortable->cssFilePath = ADMIN_CSS_DIR."/phpSortable.css";

                #define the path for of the images directory
                $sortable->imgFilePath = ADMIN_IMAGE_DIR."/phpgrid/"; 

                # print the table            
                $sortable->printTable();
             if($lsmanageemaillog==true)
             {        
               echo '<input style="margin:5px;" type="submit" value="Delete Selected" name="btnDeleteSelected" id="btnDeleteSelected" class="btncss" onclick="return ValidateCheckbox(\'selected\');"/>';
               echo '<input style="margin:5px;width:108px" type="submit" value="Delete All" name="btnDeleteAll" id="btnDeleteAll" class="btncss" onclick="return ValidateCheckbox(\'all\');"/>';
              
             }
                if($totalrowcount<=0 && $lsmanageemaillog==true)
               {
                 echo "<script>";
                 echo "document.getElementById('chkSelectAll').style.display='none';";
                 echo "document.getElementById('lblSelect').style.display='none';";
                 echo "document.getElementById('btnDeleteSelected').style.display='none';";
                 echo "document.getElementById('btnDeleteAll').style.display='none';";
                 echo "</script>";
               }
              echo "</form>";
              echo "</div>";
              echo "</div>";
              echo "</div>";
                
              //For display footer.php
              echo($smarty->fetch('admin_footer.php'));   
 
?>
Return current item: MembersGear