Location: PHPKode > projects > MembersGear > membersgear/cronjobs/email_subscriptions_status_protectfolders.php
<?php
// echo mktime(0,0,0,06,14,2009)."<br/>";die;
// echo strtotime(date("Y/m/d")." -1 day");
//die; 
 
  require_once "../config/config.php";
  require_once INCLUDE_DIR."/users_class.php";
  require_once INCLUDE_DIR."/product_class.php";
  require_once INCLUDE_DIR."/product_protection_class.php";
  require_once INCLUDE_DIR."/cannedemail_class.php";
  require_once INCLUDE_DIR."/autoresponder.php";
  require_once INCLUDE_DIR."/master_class.php"; 
  require_once  INCLUDE_DIR."/folderProtection.php";
  require_once INCLUDE_DIR."/passgen.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);
      
      if(is_array($laResult) and sizeof($laResult) > 0)
      {
              foreach($laResult as $key=>$value)
              {
                    //print_r($value)."<br/>";
                    if($value != '')
                    {
                        
                        if(EMAIL_SUBSCRIPTION_ABOUT_TO_EXPIRED_DAYS >= 0)
                        {
                            $recorddate = date('Y/m/d',strtotime(date("Y/m/d",$value['uptodate'])." +".EMAIL_SUBSCRIPTION_ABOUT_TO_EXPIRED_DAYS." day"));
                            $currentdate = date("Y/m/d");                                                                                   
                        }
                        elseif(EMAIL_SUBSCRIPTION_ABOUT_TO_EXPIRED_DAYS < 0)
                        {
                            $addDay = substr(EMAIL_SUBSCRIPTION_ABOUT_TO_EXPIRED_DAYS,1);
                            $recorddate = date('Y/m/d',strtotime(date("Y/m/d",$value['uptodate'])." -".$addDay." day"));   
                            $currentdate = date("Y/m/d");
                        }
                        if(isset($recorddate) and isset($currentdate))
                        {
                                if($recorddate == $currentdate)
                                {
                                      //echo "send email to ".$value['id']." id number.<br/>";
                                      if(EMAIL_SUBSCRIPTION_ABOUT_TO_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);
                                           
                                           $productTableQuery = 'SELECT name,protectedurl FROM '.TABLE_PREFIX.'products WHERE id=?';
                                           $laProductValues = array($value['productid']+0);
                                           $laProductData = $loProductClass->View($productTableQuery,$laProductValues,null);
                                           
                                           if($laTemplateData[0]['status'] == 1 and $laUserData[0]['isunsubscribedfromemails'] == 0)
                                           {
                                                 SendCannedEmailsAutoresponse(EMAIL_SUBSCRIPTION_ABOUT_TO_EXPIRED_TEMPLATE_ID,0,EMAIL_SUBSCRIPTION_ABOUT_TO_EXPIRED_TEMPLATE_NAME,$laProductData[0]['name'],$laProductData[0]['protectedurl'],$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);
      
      if(is_array($laResult) and sizeof($laResult) > 0)
      {
              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 name,protectedurl,expirationemail FROM '.TABLE_PREFIX.'products WHERE id=?';
                                   $laProductValues = array($value['productid']+0);
                                   $laProductData = $loProductClass->View($productTableQuery,$laProductValues,null);
                                   
                                     if($laUserData[0]['isunsubscribedfromemails'] == 0 and $laProductData[0]['expirationemail'] != 'DONOTSEND')
                                     {
                                         SendCannedEmailsAutoresponse($templateID,$productID,EMAIL_SUBSCRIPTION_IS_EXPIRED_TEMPLATE_NAME,$laProductData[0]['name'],$laProductData[0]['protectedurl'],$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