Location: PHPKode > projects > MembersGear > membersgear/includes/admin_autoemail.php
<?php
 //echo mktime(0,0,0,06,05,2009);die; 
 
  require_once "../config/config.php";
  require_once "users_class.php";
  require_once "product_class.php";
  require_once "cannedemail_class.php";
  require_once "autoresponder.php";
  
  /**************************************************************************************************/
  //                       For Send email when subscription about to expire                         //
  /**************************************************************************************************/
  function SendEmailWhenSubcriptionAboutToExpire()
  {
      //Fetch data for send email from prefix_product_users 
      
      $loUserClass = new users_class();
      $loProductClass = new product_class();
      $loCannedEmail = new cannedemail_class();
      
      $query = 'select * from '.TABLE_PREFIX.'product_users where islifetime = ?';
      $lsTempProductUsers = array(0);
      $laResult = $loUserClass->View($query,$lsTempProductUsers,null);
      
      foreach($laResult as $key=>$value)
      {
            //print_r($value)."<br/>";
            if($value != '')
            {
                
                if(EMAIL_SUBSCRIPTION_EXPIRED_DAYS > 0)
                {
                    $recorddate = date('Y/m/d',strtotime(date("Y/m/d",$value['uptodate'])." -".EMAIL_SUBSCRIPTION_EXPIRED_DAYS." day"));
                    $currentdate = date("Y/m/d");                                                                                   
                }
                elseif(EMAIL_SUBSCRIPTION_EXPIRED_DAYS < 0)
                {
                    $addDay = substr(EMAIL_SUBSCRIPTION_EXPIRED_DAYS,1);
                    $recorddate = date('Y/m/d',strtotime(date("Y/m/d",$value['uptodate'])." +".$addDay." day"));   
                    $currentdate = date("Y/m/d");
                }
                
                if($recorddate == $currentdate)
                {
                      //echo "send email to ".$value['id']." id number.<br/>";
                      if(EMAIL_SUBSCRIPTION_EXPIRED == 'true')
                      {
                          /*
                           $templateQuery = 'SELECT id,status FROM '.TABLE_PREFIX.'email_templates WHERE userid=? AND productid=?';
                           $lstemplateValues = array($value['userid'],$value['productid']);
                           $laTemplateData = $loCannedEmail->View($templateQuery,$lstemplateValues,null);
                     
                            if($laTemplateData != '')
                            {                                              
                                   $templateID = $laTemplateData['id'];
                            }
                            else
                            { */
                                    $templateQuery = 'SELECT id,status FROM '.TABLE_PREFIX.'email_templates WHERE name=\'Subscription about to expire\' AND productid=0';
                                    $laTemplateData = $loCannedEmail->View($templateQuery);
                                    
                            //}
                           
                           $userQuery = 'SELECT username,password,email,firstname,lastname,isunsubscribedfromemails FROM '.TABLE_PREFIX.'users WHERE id=?';
                           $lsUsersValues = array($value['userid']);
                           $laUserData = $loUserClass->View($userQuery,$lsUsersValues,null);
                           
                             if($laTemplateData[0]['status'] == 1 and $laUserData[0]['isunsubscribedfromemails'] == 1)
                             {
                                 SendCannedEmailsAutoresponse(EMAIL_SUBSCRIPTION_EXPIRED_TEMPLATE_ID,0,'','',$laUserData[0]['username'],$laUserData[0]['password'],$laUserData[0]['email'],$laUserData[0]['firstname'],$laUserData[0]['lastname']);
                             }

                           
                      }
                }
            }
           // echo "<br/><br/>";   
      }
      //print_r($laResult);
      unset($loUserClass);                
      unset($loProductClass);                
      unset($loCannedEmail);                
  }
  
  /**************************************************************************************************/
  //                       For Send email when subscription expired                                 //
  /**************************************************************************************************/
  function SendEmailWhenSubcriptionExpired()
  {
      //Fetch data for send email from prefix_product_users 
      
      $loUserClass = new users_class();
      $loProductClass = new product_class();
      $loCannedEmail = new cannedemail_class();
      
      $expiredDate = strtotime(date("Y/m/d")." -".EMAIL_SUBSCRIPTION_IS_EXPIRED_DAYS." day");
      
      $query = 'select * from '.TABLE_PREFIX.'product_users where uptodate = ? and islifetime = ?';
      $lsTempProductUsers = array($expiredDate,0);
      
      $laResult = $loUserClass->View($query,$lsTempProductUsers,null);
      
      foreach($laResult as $key=>$value)
      {
            //print_r($value)."<br/>";
            if($value != '')
            {
                
                
                
                    //echo "send email to ".$value['id']." id number.<br/>";
                      if(EMAIL_SUBSCRIPTION_IS_EXPIRED == 'true')
                      {
                          
                           $templateQuery = 'SELECT id,status FROM '.TABLE_PREFIX.'email_templates WHERE productid=? AND name=?';
                           $lstemplateValues = array($value['productid'],EMAIL_SUBSCRIPTION_IS_EXPIRED_TEMPLATE_NAME);
                           $laTemplateData = $loCannedEmail->View($templateQuery,$lstemplateValues,null);
                           $templateID = 0;
                            if($laTemplateData != '')
                            {
                                   $templateID = $laTemplateData[0]['id'];
                                   $productID  = $value['productid'];
                            }
                            else
                            { 
                                    $templateID = EMAIL_SUBSCRIPTION_IS_EXPIRED_TEMPLATE_ID;
                                    $productID  = 0;
                            }
                           
                           $userQuery = 'SELECT username,password,email,firstname,lastname,isunsubscribedfromemails FROM '.TABLE_PREFIX.'users WHERE id=?';
                           $lsUsersValues = array($value['userid']);
                           $laUserData = $loUserClass->View($userQuery,$lsUsersValues,null);
                           
                           $productTableQuery = 'SELECT expirationemail FROM '.TABLE_PREFIX.'products WHERE id=?';
                           $laProductValues = array($value['productid']+0);
                           $laProductData = $loProductClass->View($productTableQuery,$laProductValues,null);
                           
                             if($laUserData[0]['isunsubscribedfromemails'] == 1 and $laProductData[0]['expirationemail'] != 'DONOTSEND')
                             {
                                 SendCannedEmailsAutoresponse($templateID,$productID,'','',$laUserData[0]['username'],$laUserData[0]['password'],$laUserData[0]['email'],$laUserData[0]['firstname'],$laUserData[0]['lastname']);
                             }

                           
                      }
               
            }
           // echo "<br/><br/>";   
      }
      //print_r($laResult);
      unset($loUserClass);                
      unset($loProductClass);                
      unset($loCannedEmail);                
  }
  
  SendEmailWhenSubcriptionExpired();
  SendEmailWhenSubcriptionAboutToExpire();
  
?>
Return current item: MembersGear