Location: PHPKode > projects > MembersGear > membersgear/admin/admin_send_email.php
<?php
require_once "../config/config.php";
require_once INCLUDE_DIR."/autoresponder.php"; 
require_once INCLUDE_DIR."/users_class.php";  
$users = new users_class();

  
if(isset($_POST['chkDeleteItem']))
{}
else
{             
     if($_action=="senduser")
     { 
            Redirect('admin_users_v.php',true);
     }
     else if($_action=="sendgp")
     {
             Redirect('admin_product_v.php',true); 
     } 
     
}   

    
  if($_action!='sendmail')
  {
    if(isset($_SERVER['HTTP_REFERER']))
    {
        $_SESSION[SESSION_PREFIX.'Email_Referer_url']=$_SERVER['HTTP_REFERER'];                
    }
      $query="SELECT * FROM ".TABLE_PREFIX."email_templates WHERE productid=0  and status = 1 order by `name`";
      $laresult=$users->View($query);
      $lsemailmsg='';
      $lstmpid='';
       if(is_array($laresult) && sizeof($laresult))
       {
           $smarty->assign('latemplate',$laresult);     
           foreach($laresult as $key=>$value)
           {
                 if($laresult[$key]['name']=='Default')
                 {
                    $lsemailmsg=$laresult[$key]['email_message'];
                    $lstmpid=$laresult[$key]['id']; 
                    break;
                 }    
           } 
             $smarty->assign('email_msg',$lsemailmsg);
             $smarty->assign('tmpid',$lstmpid);     
       }  
  }
    
  switch($_action)
{
    case 'sendgp':
    
         // print_r($_POST);
       //   die; 
         $lsproductid=implode(",",$_POST['chkDeleteItem']);
         $lsstatus='';
         if($_POST['rdlemail']=="1")
         {
            if(isset($_POST['chkactive']))
            {    $lschkactive=$_POST['chkactive'];
                $lsstatus.="'".$lschkactive."'";
            }
            else
                $lschkactive='';
            if(isset($_POST['chkinactive']))
            {
                $lschkinactive=$_POST['chkinactive'];
                if(strlen($lsstatus)>0)
                   $lsstatus.=",'".$lschkinactive."'";
                else
                   $lsstatus.="'".$lschkinactive."'";  
               
            }
            else
               $lschkinactive='';      
            if(isset($_POST['chkpending']))
            {
               
                $lschkpending=$_POST['chkpending'];
                if(strlen($lsstatus)>0)
                   $lsstatus.=",'".$lschkpending."'";
                else
                   $lsstatus.="'".$lschkpending."'"; 
            
            }
            else
               $lschkpending=''; 
             if(isset($_POST['chkexpire']))
             {
                $lschkexpire=$_POST['chkexpire'];
                 if(strlen($lsstatus)>0)
                   $lsstatus.=",'".$lschkexpire."'";
                else
                   $lsstatus.="'".$lschkexpire."'"; 
            
             }
             else
               $lschkexpire='';  
                 
             
          
             $query="select id, Email from ".TABLE_PREFIX."users where id  in 
                        (SELECT userid FROM ".TABLE_PREFIX."product_users p
                            join ".TABLE_PREFIX."master_values mv on mv.id = p.productmembershipstatusid
                            join ".TABLE_PREFIX."master m on m.id = mv.masterid  and mv.value in ($lsstatus)   
                        where m.name = 'productmembershipstatus'
                        and productid in ($lsproductid))";
 
         } 
         else
         {
             /*$query="SELECT  u.Email,userid as userid ,productid FROM ".TABLE_PREFIX."product_users
                po join ".TABLE_PREFIX."users u on po.userid=u.id where productid not in ($lsproductid)";  */
             /*$query=" select id, email from ".TABLE_PREFIX."users where id not in 
                            (select userid from ".TABLE_PREFIX."product_users
                                    where productid  in ($lsproductid))"; */
              $query="select   u.id as id,u.username as username,u.Email as email
                     from  ".TABLE_PREFIX."users u join
                            ".TABLE_PREFIX."users_in_roles ur on u.id=ur.userid and
                           ur.roleid =(select id from   ".TABLE_PREFIX."roles where name='customer')
                           where  u.id not in
                            (select userid from  ".TABLE_PREFIX."product_users
                                    where productid  in ($lsproductid))";                      
             
                
         }   
         
   
                
         $laresult=$users->view($query);
         $lsuserid='';
         $lsuseremail='';
         $msg='';
         if(is_array($laresult) && sizeof($laresult)>0)
         {
             $lauseremail=array();
             $lauserid=array();
             foreach($laresult as $key=>$value)
             {
               $lauseremail[$key]=$laresult[$key]['email'];
               $lauserid[$key]=$laresult[$key]['id'];
                 
             } 
             $lsuseremail=implode(",\n",$lauseremail);
             $lsuserid=implode(",",$lauserid);   
         
         } 
         else
         {
           //$msg="Selected Group not have  Users to Send Email."; 
           $msg="No users found in selected group";    
           $smarty->assign('lsnodata','Yes');  
         }   
         
        
        $sendtype='sendgp';
        $smarty->assign('msg',$msg);
        $smarty->assign('userid',$lsuserid);
        $smarty->assign('email',$lsuseremail);
        $smarty->assign('showfg',$sendtype);  
        $smarty->display('admin_send_email.tpl'); 
        break;
        
    case 'senduser':
         $lsuserid=implode(",",$_POST['chkDeleteItem']);
         $query="SELECT  Email,id from ".TABLE_PREFIX."users where id in ($lsuserid)";
         $laresult=$users->view($query);
         $lsuserid='';
         $lsuseremail='';
         $msg='';
          if(is_array($laresult) && sizeof($laresult)>0)
         {
             $lauseremail=array();
             $lauserid=array(); 
             foreach($laresult as $key=>$value)
             {
               $lauseremail[$key]=$laresult[$key]['email'];
               $lauserid[$key]=$laresult[$key]['id'];    
             }   
            $lsuseremail=implode(",\n",$lauseremail);
            $lsuserid=implode(",",$lauserid); 
         }
         else
         {
            $msg="No users found";    
            $smarty->assign('lsnodata','Yes');   
             
         }    
         
         $sendtype='senduser';  
         $smarty->assign('userid',$lsuserid);
        $smarty->assign('email',$lsuseremail);
        $smarty->assign('showfg',$sendtype);  
        $smarty->display('admin_send_email.tpl'); 
        break; 
    
    case 'sendmail':
        $lsuserid=($_POST['hdn_uid']);
        $lsTemplateID=$_POST['hdn_tmp_id'];
        $lsContent=$_POST['txtContent'];
        $lssubject=$_POST['txtsubject'];
        
        $query = 'SELECT * FROM '.TABLE_PREFIX.'email_templates WHERE id='.$lsTemplateID.' AND productid=0 AND status = 1';
        
     //   $lsValues = array($lsTemplateID,0);
        $latmpres=$users->View($query);
        if(is_array($latmpres) && sizeof($latmpres)>0)
        {
                $pEmaildata= $latmpres;  
        }
        
        //if(trim($_POST['hdn_sendtype'])=="senduser")
        {
             
                                            
                $userQuery = 'SELECT id,username,password,email,firstname,lastname,isunsubscribedfromemails FROM '.TABLE_PREFIX.'users WHERE id in ('.$lsuserid.')';
                $laUserData = $users->View($userQuery);
                                               
            
               foreach($laUserData as $key=>$value)
               { 
                   
                   SendEmailsAutoresponse($lsTemplateID,$pEmaildata,$lsContent,'',$laUserData[$key]['id'],$lssubject,'','',null,0,'test','','',$laUserData[$key]['username'],$laUserData[$key]['password'],$laUserData[$key]['email'],$laUserData[$key]['firstname'],$laUserData[$key]['lastname']);    
                  
               }
               if(trim($_POST['hdn_sendtype'])=="senduser")
                { 
                   $lareturnurl='';
                   if(isset($_SESSION[SESSION_PREFIX.'Email_Referer_url']))
                   {
                       $lareturnurl=trim($_SESSION[SESSION_PREFIX.'Email_Referer_url']);
                       if(strpos($lareturnurl,'admin_users_v.php')>0)
                       {
                             $message->SetMessage('Email is successfully sent to selected users');
                             Redirect('./admin_users_v.php');
                       }
                       else
                       {
                             $message->SetMessage('Email is successfully sent to selected users');
                             Redirect('./admin_search_user.php?action=search');
                       }  
                       unset($_SESSION[SESSION_PREFIX.'Email_Referer_url']);    
                   }  
                   else
                   { 
                        $message->SetMessage('Email is successfully sent to selected users');
                        Redirect('./admin_users_v.php');
                   }
                }
                else
                {
                  $message->SetMessage('Email is successfully sent to selected group');
                  Redirect('./admin_product_v.php');  
                    
                }    
            
        }
    
        
            
         break;   
    default:
    
    $smarty->display('admin_send_email.tpl');
    
}    
?>
Return current item: MembersGear