[ Index ]
 

Code source de vtiger CRM 5.0.2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/ -> SendReminder.php (source)

   1  <?php
   2  ////////////////////////////////////////////////////
   3  // PHPMailer - PHP email class
   4  //
   5  // Class for sending email using either
   6  // sendmail, PHP mail(), or SMTP.  Methods are
   7  // based upon the standard AspEmail(tm) classes.
   8  //
   9  // Copyright (C) 2001 - 2003  Brent R. Matzelle
  10  //
  11  // License: LGPL, see LICENSE
  12  ////////////////////////////////////////////////////
  13  
  14  /**
  15   * PHPMailer - PHP email transport class
  16   * @package PHPMailer
  17   * @author Brent R. Matzelle
  18   * @copyright 2001 - 2003 Brent R. Matzelle
  19   */
  20  
  21  
  22  //file modified by richie
  23  require_once ('include/utils/utils.php');
  24  require ("modules/Emails/class.phpmailer.php");
  25  require_once ("include/database/PearDatabase.php");
  26  require_once ('include/logging.php');
  27  require ("config.php");
  28  
  29  // Get the list of activity for which reminder needs to be sent
  30  
  31  global $adb;
  32  global $log;
  33  $log =& LoggerManager::getLogger('SendReminder');
  34  $log->debug(" invoked SendReminder ");
  35  
  36  //modified query for recurring events -Jag
  37       $query="select vtiger_crmentity.crmid,vtiger_seactivityrel.crmid as setype,vtiger_activity.*,vtiger_activity_reminder.reminder_time,vtiger_activity_reminder.reminder_sent,vtiger_activity_reminder.recurringid,vtiger_recurringevents.recurringdate from vtiger_activity inner join vtiger_crmentity on vtiger_crmentity.crmid=vtiger_activity.activityid inner join vtiger_activity_reminder on vtiger_activity.activityid=vtiger_activity_reminder.activity_id left outer join vtiger_recurringevents on vtiger_activity.activityid=vtiger_recurringevents.activityid left outer join vtiger_seactivityrel on vtiger_seactivityrel.activityid = vtiger_activity.activityid where DATE_FORMAT(vtiger_activity.date_start,'%Y-%m-%d, %H:%i:%s') >= '".date('Y-m-d')."' and vtiger_crmentity.crmid != 0 and vtiger_activity.eventstatus = 'Planned' and vtiger_activity_reminder.reminder_sent = 0 group by vtiger_activity.activityid,vtiger_recurringevents.recurringid";
  38  
  39  $result = $adb->query($query);
  40  
  41  if($adb->num_rows($result) >= 1)
  42  {
  43      while($result_set = $adb->fetch_array($result))
  44      {
  45          $date_start = $result_set['date_start'];
  46          $time_start = $result_set['time_start'];
  47          $reminder_time = $result_set['reminder_time'];
  48              $curr_time = strtotime(date("Y-m-d H:i"))/60;
  49          $activity_id = $result_set['activityid'];
  50          $activitymode = ($result_set['activitytype'] == "Task")?"Task":"Events";
  51          $parent_type = $result_set['setype']; 
  52          $activity_sub = $result_set['subject'];
  53          $to_addr='';
  54              
  55          if($parent_type!='')
  56          $parent_content = getParentInfo($parent_type)."\n";
  57          else
  58          $parent_content = "";
  59          //code included for recurring events by jaguar starts    
  60          $recur_id = $result_set['recurringid'];
  61          $current_date=date('Y-m-d');
  62          if($recur_id == 0)
  63          {
  64              $date_start = $result_set['date_start'];
  65          }
  66          else
  67          {
  68              $date_start = $result_set['recurringdate'];
  69          }
  70          //code included for recurring events by jaguar ends    
  71  
  72              $activity_time = strtotime(date("$date_start $time_start"))/60;
  73  
  74          if (($activity_time - $curr_time) > 0 && ($activity_time - $curr_time) == $reminder_time)
  75          {
  76              $log->debug(" InSide  REMINDER");
  77              $query_user="SELECT vtiger_users.email1,vtiger_salesmanactivityrel.smid FROM vtiger_salesmanactivityrel inner join vtiger_users on vtiger_users.id=vtiger_salesmanactivityrel.smid where vtiger_salesmanactivityrel.activityid =".$activity_id." and vtiger_users.deleted=0"; 
  78              $user_result = $adb->query($query_user);        
  79              if($adb->num_rows($user_result)>=1)
  80              {
  81                  while($user_result_row = $adb->fetch_array($user_result))
  82                  {
  83                      if($user_result_row['email1']!='' || $user_result_row['email1'] !=NULL)
  84                      {
  85                          $to_addr[] = $user_result_row['email1'];
  86                      }
  87                  }
  88              }
  89          
  90                  // Set the preferred email id
  91              $from ="reminders@localserver.com";
  92              
  93              // Retriving the Subject and message from reminder table        
  94              $sql = "select active,notificationsubject,notificationbody from vtiger_notificationscheduler where schedulednotificationid=7";
  95              $result_main = $adb->query($sql);
  96  
  97              $subject = "[Reminder:".$result_set['activitytype']." @ ".$result_set['date_start']." ".$result_set['time_start']."] ".$adb->query_result($result_main,0,'notificationsubject');
  98  
  99              //Set the mail body/contents here
 100              $contents = nl2br($adb->query_result($result_main,0,'notificationbody')) ."\n\n Subject : ".$activity_sub."\n ". $parent_content ." Date & Time : ".$date_start." ".$time_start."\n\n Kindly visit the link for more details on the activity <a href='".$site_URL."/index.php?action=DetailView&module=Calendar&record=".$activity_id."&activity_mode=".$activitymode."'>Click here</a>";
 101  
 102              if(count($to_addr) >=1)
 103              {
 104                  send_mail($to_addr,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password);
 105                  $upd_query = "UPDATE vtiger_activity_reminder SET reminder_sent=1 where activity_id=".$activity_id;
 106  
 107                  if($recur_id!=0)
 108                  {
 109                      $upd_query.=" and recurringid =".$recur_id;
 110                  }
 111  
 112                  $adb->query($upd_query);
 113  
 114                  
 115                  
 116              }
 117          }
 118      }
 119  }
 120  
 121  /**
 122   This function is used to assign parameters to the mail object and send it.
 123   It takes the following as parameters.
 124      $to as string - to address
 125      $from as string - from address
 126      $subject as string - subject if the mail
 127      $contents as text - content of the mail
 128      $mail_server as string - sendmail server name 
 129      $mail_server_username as string - sendmail server username 
 130      $mail_server_password as string - sendmail server password
 131  
 132  */
 133  function send_mail($to,$from,$subject,$contents,$mail_server,$mail_server_username,$mail_server_password)
 134  {
 135      global $adb;
 136       global $log;
 137          $log->info("This is send_mail function in SendReminder.php(vtiger home).");
 138      global $root_directory;
 139  
 140      $mail = new PHPMailer();
 141  
 142  
 143      $mail->Subject = $subject;
 144      $mail->Body    = nl2br($contents);//"This is the HTML message body <b>in bold!</b>";
 145  
 146  
 147      $mail->IsSMTP();                                      // set mailer to use SMTP
 148  
 149      if($mail_server=='')
 150      {
 151          $mailserverresult=$adb->query("select * from vtiger_systems where server_type='email'");
 152          $mail_server = $adb->query_result($mailserverresult,0,'server');
 153          $mail_server_username = $adb->query_result($mailserverresult,0,'server_username');
 154          $mail_server_password = $adb->query_result($mailserverresult,0,'server_password');
 155          $smtp_auth = $adb->query_result($mailserverresult,0,'smtp_auth');
 156  
 157          $_REQUEST['server']=$mail_server;
 158          $log->info("Mail Server Details => '".$mail_server."','".$mail_server_username."','".$mail_server_password."'");
 159  
 160      }    
 161  
 162      $mail->Host = $mail_server;            // specify main and backup server
 163      $mail->SMTPAuth = $smtp_auth;            // turn on SMTP authentication
 164      $mail->Username = $mail_server_username ;    // SMTP username
 165      $mail->Password = $mail_server_password ;    // SMTP password
 166      $mail->From = $from;
 167      $mail->FromName = $initialfrom;
 168      $log->info("Mail sending process : From Name & email id => '".$initialfrom."','".$from."'");
 169      foreach($to as $pos=>$addr)
 170      {
 171          $mail->AddAddress($addr);                  // name is optional
 172          $log->info("Mail sending process : To Email id = '".$addr."' (set in the mail object)");
 173  
 174      }
 175      $mail->WordWrap = 50;                                 // set word wrap to 50 characters
 176  
 177      $mail->IsHTML(true);                                  // set email format to HTML
 178      
 179      $mail->AltBody = "This is the body in plain text for non-HTML mail clients";
 180  
 181      $flag = MailSend($mail);
 182      $log->info("After executing the mail->Send() function.");
 183  }
 184  
 185  /**
 186   This function is used to ensure mail has been sent sucessfully with out error.
 187   It takes the mail object as the input and returns true if sucess else an error messaget. 
 188  */
 189  function MailSend($mail)
 190  {
 191      global $log;
 192          if(!$mail->Send())
 193          {
 194          $log->info("Error in Mail Sending : Error log = '".$mail->ErrorInfo."'");
 195             $msg = $mail->ErrorInfo;
 196          }
 197      else
 198             {    
 199          $log->info("Mail has been sent from the vtigerCRM system : Status : '".$mail->ErrorInfo."'");
 200          return true;
 201      }        
 202  }
 203  
 204  /**
 205   This function is used to get the Parent mail id
 206   It takes the input returnmodule as string and parentid as integer, returns the parent mailid as string. 
 207  */
 208  function getParentMailId($returnmodule,$parentid)
 209  {
 210      global $adb;
 211          if($returnmodule == 'Leads')
 212          {
 213                  $tablename = 'vtiger_leaddetails';
 214                  $idname = 'leadid';
 215          }
 216          if($returnmodule == 'Contacts' || $returnmodule == 'HelpDesk')
 217          {
 218          if($returnmodule == 'HelpDesk')
 219              $parentid = $_REQUEST['contact_id'];
 220                  $tablename = 'vtiger_contactdetails';
 221                  $idname = 'contactid';
 222          }
 223      if($parentid != '')
 224      {
 225              $query = 'select * from '.$tablename.' where '.$idname.' = '.$parentid;
 226              $mailid = $adb->query_result($adb->query($query),0,'email');
 227      }
 228          if($mailid == '' && $returnmodule =='Contacts')
 229          {
 230                  $mailid = $adb->query_result($adb->query($query),0,'otheremail');
 231                  if($mailid == '')
 232                          $mailid = $adb->query_result($adb->query($query),0,'yahooid');
 233          }
 234      return $mailid;
 235  }
 236  
 237  /**
 238   This function is used to get the Parent type and its Name
 239   It takes the input integer - crmid and returns the parent type and its name as string. 
 240  */
 241  function getParentInfo($value)
 242  {
 243      global $adb;
 244       $parent_module = getSalesEntityType($value);
 245      if($parent_module == "Leads")
 246      {
 247          $sql = "select * from vtiger_leaddetails where leadid=".$value;
 248          $result = $adb->query($sql);
 249          $first_name = $adb->query_result($result,0,"firstname");
 250          $last_name = $adb->query_result($result,0,"lastname");
 251  
 252          $parent_name = $last_name.' '.$first_name;
 253      }
 254      elseif($parent_module == "Accounts")
 255      {
 256          $sql = "select * from  vtiger_account where accountid=".$value;
 257          $result = $adb->query($sql);
 258          $account_name = $adb->query_result($result,0,"accountname");
 259  
 260          $parent_name =$account_name;
 261      }
 262      elseif($parent_module == "Potentials")
 263      {
 264          $sql = "select * from  vtiger_potential where potentialid=".$value;
 265          $result = $adb->query($sql);
 266          $potentialname = $adb->query_result($result,0,"potentialname");
 267  
 268          $parent_name =$potentialname;
 269      }
 270        return $parent_module ." : ".$parent_name;
 271  }
 272  ?>


Généré le : Sun Feb 25 10:22:19 2007 par Balluche grâce à PHPXref 0.7