[ Index ]
 

Code source de e107 0.7.8

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

title

Body

[fermer]

/e107_plugins/calendar_menu/ -> subs_menu.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |     ©Steve Dun.an 2001-2002
   7  |     http://e107.org
   8  |     jali.@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  |     $Source: /cvsroot/e107/e107_0.7/e107_plugins/calendar_menu/subs_menu.php,v $
  14  |     $Revision: 1.5 $
  15  |     $Date: 2006/11/06 22:30:22 $
  16  |     $Author: e107coders $
  17  |
  18  | 09.07.06 - Mods by steved:
  19  |    General restructuring to use common routines
  20  |     Support for sending emails on previous day.
  21  |    Logging capability
  22  |     Debugging option
  23  |
  24  | 11.07.06 - Adjustment to logging messages
  25  | 12.07.06 - More adjustment to logging messages
  26  | 15.07.06 - Adjustment to 'tomorrow' query
  27  | 17.07.06 - More adjustment to 'tomorrow' query
  28  |
  29  | 04.10.06 - Mods to mailout to allow mix of voluntary and forced subs to the same event
  30  | 24.10.06 - Change DB names so works as a menu
  31  | 25.10.06 - Logging selectively disabled when run as menu
  32  | 27.10.06 - Update queries to new structure, don't email banned users
  33  | 31.10.06 - Attempt to optimise query better
  34  | 01.11.06 - More refinements on query
  35  | 05.11.06 - More refinement on query - ignores midnight at end of day.   **** BANG ****
  36  |
  37  +----------------------------------------------------------------------------+
  38  */
  39  
  40  if (!defined('e107_INIT')) { exit; }
  41  
  42  // This menu can be called from a cron job - see readme.rtf
  43  $run_from_menu = function_exists("parseheader");        // Use this to suppress logging in 'through' path
  44  $ec_dir = e_PLUGIN . "calendar_menu/";
  45  // Check if we are going to do the notify
  46  
  47  $debug_level = 0;            // Set to 1 or 2 to suppress actual sending of emails
  48  
  49  if (($debug_level > 0) && e_QUERY)
  50  {  // Run with query of ?dd-mm[-yy] to test specific date
  51    list($day,$month,$year) = explode("-",e_QUERY);
  52    if (!isset($year) || ($year == 0)) $year = date("Y");
  53    $cal_starttime = mktime(0,0,0,$month,$day,$year);
  54    echo "Debug run for {$day}-{$month}-{$year}<br />";
  55  }
  56  else
  57  {  // Normal operation
  58  $cal_starttime = mktime(0, 0, 0, date("n"), date("d"), date("Y"));
  59  }
  60  
  61  $log_requirement = 0;        // Logging required 0=none, 1=summary, 2=detailed
  62  if (isset($pref['eventpost_emaillog'])) $log_requirement = $pref['eventpost_emaillog'];
  63  if ($debug_level >= 2) $log_requirement = 2;    // Force full logging if debug
  64  
  65  if ($log_requirement > 0)
  66  {
  67    $log_filename = $ec_dir.'log/calendar_mail.txt';
  68    if (!$run_from_menu)
  69    {
  70      if (!($handle = fopen($log_filename, 'a'))) $log_requirement = 0;
  71      if (fwrite($handle,"\r\n\r\nMail subscriptions run started at ".date("D j M Y G:i:s")) === false)  $log_requirement = 0;
  72      fclose($handle);
  73    }
  74  }
  75  
  76  // Start with the 'in advance' emails
  77  $cal_args = "select * from #event left join #event_cat on event_category=event_cat_id where (event_cat_subs>0 OR event_cat_force_class != '') and 
  78  event_cat_last < " . intval($cal_starttime) . " and 
  79  event_cat_ahead > 0 and 
  80  event_start >= (" . intval($cal_starttime) . "+(86400*(event_cat_ahead))) and
  81  event_start <  (" . intval($cal_starttime) . "+(86400*(event_cat_ahead+1))) and
  82  find_in_set(event_cat_notify,'1,3,5,7')";
  83  
  84  send_mailshot($cal_args, 'Advance',1);
  85  
  86  
  87  
  88  // then for today
  89  //$cal_starttime = mktime(0, 0, 0, date("n"), date("d"), date("Y"));
  90  $cal_args = "select * from #event left join #event_cat on event_category=event_cat_id where (event_cat_subs>0 OR event_cat_force_class != '') and 
  91  event_cat_today < " . intval($cal_starttime) . " and 
  92  event_start >= (" . intval($cal_starttime) . ") and
  93  event_start <  (86400+" . intval($cal_starttime) . ") and
  94  find_in_set(event_cat_notify,'2,3,6,7')";
  95  
  96  send_mailshot($cal_args, 'today',2);
  97  
  98  
  99  // Finally do 'day before' emails
 100  $cal_args = "select * from #event left join #event_cat on event_category=event_cat_id where (event_cat_subs>0 OR event_cat_force_class != '') and 
 101  event_cat_today < " . intval($cal_starttime) . " and 
 102  event_start >= (" . intval($cal_starttime) ." + 86400 ) and
 103  event_start <  (" . intval($cal_starttime) ." + 172800) and
 104  find_in_set(event_cat_notify,'4,5,6,7')";
 105  
 106  send_mailshot($cal_args, 'tomorrow',2);
 107  
 108  
 109  if (($log_requirement > 0) && (!$run_from_menu))
 110  {
 111    if (!($handle = fopen($log_filename, 'a'))) $log_requirement = 0;
 112    if (fwrite($handle," .. completed at ".date("D j M Y G:i:s")."\r\n") === false) $log_requirement = 0;
 113    fclose($handle);
 114  }
 115  
 116  // Done
 117  
 118  
 119  /*
 120    Function to actually send a mailshot
 121  */
 122  function send_mailshot($cal_query, $shot_type, $msg_num)
 123  {
 124    global $sql, $sql2;
 125    global $log_requirement, $log_filename, $debug_level;
 126    global $pref;
 127    global $run_from_menu;
 128    
 129    if (($log_requirement > 1)  && (!$run_from_menu))
 130    {
 131      if (!$handle = fopen($log_filename, 'a')) $log_requirement = 0;
 132      if (fwrite($handle,"\r\n  Starting emails for ".$shot_type." at ".date("D j M Y G:i:s")) === false)  $log_requirement = 0;
 133      if ($debug_level >= 2)
 134      {
 135        if (fwrite($handle,"\r\n    Query is: ".$cal_query."\r\n") === false) $log_requirement = 0;
 136      }
 137    }
 138  
 139  if ($num_cat_proc = $sql->db_Select_gen($cal_query))
 140    {  // Got at least one event to process here
 141      if ($log_requirement > 1)
 142      {
 143        if ($run_from_menu) if (!($handle = fopen($log_filename, 'a'))) $log_requirement = 0;
 144        if (fwrite($handle," - ".$num_cat_proc." categories found to process\r\n") === false)  $log_requirement = 0;
 145      }
 146      require_once(e_HANDLER . "mail.php");
 147      while ($cal_row = $sql->db_Fetch())
 148      {  // Process one event at a time
 149        extract($cal_row);
 150          
 151        if ($log_requirement > 1)
 152        {
 153            if (fwrite($handle,"    Processing event: ".$event_title." \r\n") === false)  $log_requirement = 0;
 154        }
 155          
 156        if ($msg_num == 1)
 157          $sql2->db_Update("event_cat", "event_cat_last=" . time() . " where event_cat_id=" . intval($event_cat_id));
 158        else
 159          $sql2->db_Update("event_cat", "event_cat_today=" . time() . " where event_cat_id=" . intval($event_cat_id));
 160  
 161  
 162  // Start of next try on query
 163  // Four cases for the query:
 164  //    1. No forced mailshots - based on event_subs table only                                    Need INNER JOIN
 165  //    2. Forced mailshot to members - send to all users (don't care about subscriptions)        Don't need JOIN
 166  //     3. Forced mailshot to group of members - based on user table only                        Don't need JOIN
 167  //    4. Forced mailshot to group, plus optional subscriptions - use the lot!                    Need LEFT JOIN
 168  // (Always block sent to banned members)
 169        $manual_subs = (isset($pref['eventpost_asubs']) && ($pref['eventpost_asubs'] == '1'));
 170        $subs_fields = '';
 171        $subs_join = '';
 172        $where_clause = '';
 173        $group_clause = '';
 174        
 175        
 176        if ($event_cat_force_class != e_UC_MEMBER)
 177        {  // Cases 1, 3, 4 (basic query does for case 2)
 178        
 179          if ((!$event_cat_force_class) || ($manual_subs))
 180          {  // Cases 1 & 4 - need to join with event_subs database
 181            $subs_fields = ", es.* ";
 182            if ($event_cat_force_class) $subs_join = "LEFT"; else $subs_join = "INNER";
 183            $subs_join   .= " join #event_subs AS es on u.user_id=es.event_userid ";
 184            $where_clause = " es.event_cat='".intval($event_category)."' ";
 185            $group_clause = " GROUP BY u.user_id";
 186          }
 187  
 188          if ($event_cat_force_class)
 189          {  // cases 3 and 4 - ... and check for involuntary subscribers
 190              if ($where_clause) $where_clause .= " OR ";
 191              if ($event_cat_force_class == e_UC_ADMIN)
 192              {
 193                $where_clause .= "(u.user_admin = '1' )";
 194              }
 195              else
 196              {
 197                $where_clause .= "find_in_set('".intval($event_cat_force_class)."', u.user_class)";
 198              }
 199          }
 200  
 201          if ($where_clause) $where_clause = ' AND ('.$where_clause.' ) ';
 202        }   // End of cases 1, 3, 4
 203        
 204        $cal_emilargs = "SELECT u.user_id, u.user_class, u.user_email, u.user_name, u.user_ban, u.user_admin{$subs_fields}
 205            from #user AS u {$subs_join}
 206            WHERE u.user_ban = '0' {$where_clause} {$group_clause}";
 207            
 208  
 209          if ($debug_level >= 2)
 210          {
 211            if (fwrite($handle,"\r\n    Email selection query is: ".$cal_emilargs."\r\n") === false) $log_requirement = 0;
 212          }
 213          if ($num_shots = $sql2->db_Select_gen($cal_emilargs))
 214          {
 215              if ($log_requirement > 1)
 216              {
 217                if (fwrite($handle," - ".$num_shots." emails found to send\r\n") === false)  $log_requirement = 0;
 218              }
 219              while ($cal_emrow = $sql2->db_Fetch())
 220              {
 221                extract($cal_emrow);
 222                if ($msg_num == 1)
 223                  $cal_msg = $event_title . "\n\n" . $event_cat_msg1;
 224                else
 225                  $cal_msg = $event_title . "\n\n" . $event_cat_msg2;
 226                if ($debug_level == 0) $send_result = sendemail($user_email, $pref['eventpost_mailsubject'], $cal_msg, $user_name, $pref['eventpost_mailaddress'], $pref['eventpost_mailfrom']); 
 227                if ($log_requirement > 1)
 228                {
 229                  $log_string = "      Send to: ".$user_email." Name: ".$user_name;
 230                  if ($debug_level > 0) 
 231                    { $log_string .= " *DEBUG*
 232  ";                     } 
 233                  else 
 234                    { $log_string .= " Result = ".$send_result."
 235  ";                     }
 236                  if (fwrite($handle,$log_string) === false) $log_requirement = 0;
 237                }
 238              } 
 239          } 
 240      } // while    
 241      if ($log_requirement > 1)
 242      {
 243        if (fwrite($handle,"  Completed emails for ".$shot_type." at ".date("D j M Y G:i:s")."\r\n") === false)  $log_requirement = 0;
 244        fclose($handle);
 245      }
 246    }
 247  } 
 248  
 249  
 250  
 251  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7