[ PHPXref.com ] [ Generated: Sun Jul 20 19:13:40 2008 ] [ osCommRes 1.2.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/functions/ -> subscription_general.php (source)

   1  <?php
   2  /*

   3  

   4    osCommRes, Services Online

   5    http://www.oscommres.com

   6  

   7    Copyright (c) 2005 osCommRes

   8  

   9    Released under the GNU General Public License

  10  */
  11    
  12  // Generate a path to subscription categories

  13    function tep_get_subscription_path($current_subscription_category_id = '') {
  14      global $sucPath_array;
  15  
  16      if (tep_not_null($current_subscription_category_id)) {
  17        $ecp_size = sizeof($sucPath_array);
  18        if ($ecp_size == 0) {
  19          $sucPath_new = $current_subscription_category_id;
  20        } else {
  21          $sucPath_new = '';
  22          $last_subscription_category_query = tep_db_query("select parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " where subscription_categories_id = '" . (int)$sucPath_array[($sucp_size-1)] . "'");
  23          $last_subscription_category = tep_db_fetch_array($last_subscription_category_query);
  24  
  25          $current_subscription_category_query = tep_db_query("select parent_id from " . TABLE_SUBSCRIPTION_CATEGORIES . " where subscription_categories_id = '" . (int)$current_subscription_category_id . "'");
  26          $current_subscription_category = tep_db_fetch_array($current_subscription_category_query);
  27  
  28          if ($last_subscription_category['parent_id'] == $current_subscription_category['parent_id']) {
  29            for ($i=0; $i<($sucp_size-1); $i++) {
  30              $sucPath_new .= '_' . $sucPath_array[$i];
  31            }
  32          } else {
  33            for ($i=0; $i<$sucp_size; $i++) {
  34              $sucPath_new .= '_' . $sucPath_array[$i];
  35            }
  36          }
  37          $sucPath_new .= '_' . $current_subscription_category_id;
  38  
  39          if (substr($sucPath_new, 0, 1) == '_') {
  40            $sucPath_new = substr($sucPath_new, 1);
  41          }
  42        }
  43      } else {
  44        $sucPath_new = implode('_', $sucPath_array);
  45      }
  46  
  47      return 'sucPath=' . $sucPath_new;
  48    }
  49  
  50  
  51  ////

  52  // Parse and secure the sucPath parameter values

  53    function tep_parse_subscription_category_path($sucPath) {
  54  // make sure the category IDs are integers

  55      $sucPath_array = array_map('tep_string_to_int', explode('_', $sucPath));
  56  
  57  // make sure no duplicate category IDs exist which could lock the server in a loop

  58      $tmp_array = array();
  59      $n = sizeof($sucPath_array);
  60      for ($i=0; $i<$n; $i++) {
  61        if (!in_array($sucPath_array[$i], $tmp_array)) {
  62          $tmp_array[] = $sucPath_array[$i];
  63        }
  64      }
  65  
  66      return $tmp_array;
  67    }
  68    
  69    function tep_get_subscription_name($subscription_id, $language_id = 0) {
  70      global $languages_id;
  71  
  72      if ($language_id == 0) $language_id = $languages_id;
  73      $subscription_query = tep_db_query("select subscription_name from " . TABLE_SUBSCRIPTIONS_DESCRIPTION . " where subscription_id = '" . (int)$subscription_id . "' and language_id = '" . (int)$language_id . "'");
  74      $subscription = tep_db_fetch_array($subscription_query);
  75  
  76      return $subscription['subscription_name'];
  77    }
  78    
  79  // send subscription order email

  80  function tep_send_subscription_order_email($i){
  81      global $currencies,$order,$customer_id,$insert_id;
  82  
  83      if ((int)EMAIL_ACTIVATE!=1) return;
  84  
  85      // get subscription details    

  86      $subscription_query=tep_db_query("SELECT su.subscription_id,su.subscription_period,su.subscription_renewal_end,su.subscription_costs,su.subscription_tax_class_id from " . 
  87                                 TABLE_SUBSCRIPTIONS . " su " . " where su.subscription_id='" . (int)$order->products[$i]['id'] . "'");
  88      if (tep_db_num_rows($subscription_query)<=0) return;    
  89      $subscription_result=tep_db_fetch_array($subscription_query);
  90      
  91      // get mail template details

  92      $details_r=array();
  93      $details_r['type']='RCF';
  94      $details_r['table']=TABLE_SUBSCRIPTION_MESSAGES;
  95      $details_r['subscription_id']=$subscription_result['subscription_id'];
  96      tep_get_template($details_r);
  97      
  98      if ($details_r['html_text']=="") return;
  99  
 100      // get the renewal end date of this reservation

 101      $renewal_date=date('Y-m-d',tep_dateadd(strtotime(getServerDate()),"day",$subscription_result["subscription_period"]-$subscription_result["subscription_renewal_end"]));
 102      
 103      // get some customer information 

 104      $order_query=tep_db_query("SELECT customers_fax,customers_dob from " . TABLE_CUSTOMERS . " where customers_id='" . (int)$customer_id . "'");
 105      $order_result=tep_db_fetch_array($order_query);
 106   
 107        $replace_array=array(    TEXT_FN=>$order->customer['firstname'],
 108                              TEXT_LN=>$order->customer['lastname'],
 109                              TEXT_DF=>format_date($order_result['customers_dob']),
 110                              TEXT_EM=>'<a href="mailto:' . $order->customer['email_address'] . '"><u>' . $order->customer['email_address'] .'</u></a>',
 111                              TEXT_TN=>$order->customer['telephone'],
 112                              TEXT_FX=>$order_result['customers_fax'],
 113                              TEXT_SA=>$order->customer['street_address'],
 114                              TEXT_SU=>$order->customer['suburb'],
 115                              TEXT_PC=>$order->customer['postcode'],
 116                              TEXT_CT=>$order->customer['city'],
 117                              TEXT_ST=>$order->customer['state'],
 118                              TEXT_CY=>$order->customer['country']['title'],
 119                              
 120                              TEXT_SUB_NA=>$order->products[$i]['name'],
 121                              TEXT_SUB_CO=>$currencies->format(tep_add_tax($subscription_result['subscription_costs'],tep_get_tax_rate($subscription_result['subscription_tax_class_id']))),
 122                              TEXT_SUB_PE=>$subscription_result["subscription_period"],
 123                              TEXT_IV=>'<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_INVITE_FRIEND,'R=1&path=ACC&suID=' . $subscription_result['subscription_id'],'NONSSL',false) . '">' . TEST_MAIL_SUB_IV . '</a>',
 124                              TEXT_UN=>'<a href="' . tep_href_link(FILENAME_SUBSCRIPTION_UNSUBSCRIBE,'R=1&cID=' . $customer_id,'NONSSL',false) . '">' . TEST_MAIL_SUB_UN . '</a>',
 125                              TEXT_SUB_RL=>'<a href="' . tep_href_link(FILENAME_ACCOUNT,'R=1','NONSSL',false) . '">' . TEST_MAIL_SUB_RL . '</a>',
 126                              TEXT_IL=>'<a href="' . tep_href_link(FILENAME_ACCOUNT_HISTORY_INFO,'R=1&order_id=' . $insert_id,'NONSSL',false) . '">' . TEST_MAIL_SUB_IL . '</a>',
 127                              TEXT_RE=>format_date($renewal_date),
 128                              
 129                              TEXT_ON=>$insert_id,
 130                              TEXT_OC=>$order->info['comments'],
 131                              TEXT_OD=>date(EVENTS_DATE_FORMAT),
 132                              TEXT_BT=>$order->billing['firstname'] . ' ' . $order->billing['lastname'],
 133                              TEXT_BA=>$order->billing['street_address'],
 134                              TEXT_PY=>$order->info['payment_method'],
 135                              TEXT_TX=>$currencies->format(tep_calculate_tax($order->products[$i]['final_price'],$order->products[$i]['tax'])*$order->products[$i]['qty']),
 136                              TEXT_SB=>$currencies->format($order->products[$i]['final_price']*$order->products[$i]['qty']),
 137                              TEXT_TL=>$currencies->format(tep_add_tax($order->products[$i]['final_price'],$order->products[$i]['tax'])*$order->products[$i]['qty'])
 138                              );
 139  
 140      $sql_array=array(    'orders_id'=>$insert_id,
 141                          'subscription_id'=>$subscription_result['subscription_id'],
 142                          'customers_id'=>$customer_id,
 143                          'message_type'=>'RCF',
 144                          'message_mode'=>'E',
 145                          'email_address'=>$order->customer['email_address'],
 146                          'send_date'=>'now()'
 147                      );
 148      tep_replace_template($details_r,$replace_array);
 149      tep_strip_html($details_r);
 150      // form the address array to send

 151      $details_r['to_name']=$order->customer['firstname'] . ' ' . $order->customer['lastname'];
 152      $details_r['to_email']=$order->customer['email_address'];
 153      $details_r['from_name']=STORE_OWNER;
 154      $details_r['from_email']=STORE_OWNER_EMAIL_ADDRESS;
 155      tep_send_email($details_r);
 156      tep_db_perform(TABLE_SUBSCRIPTION_MESSAGES_HISTORY,$sql_array);
 157  }
 158  
 159  // send invite email to selected friends email address

 160  function tep_send_subscription_invite_email(&$send_details){
 161      global $currencies,$languages_id;
 162  
 163      if (!is_array($send_details)) return;
 164  
 165      // fetch the subscription details

 166      $subscription_query=tep_db_query("select su.subscription_id,sud.subscription_name,su.subscription_period,su.subscription_costs,su.subscription_tax_class_id from " . 
 167                                  TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION .  " sud " .
 168                                  "where su.subscription_id='" . $send_details['subscription_id'] . "' and su.subscription_id=sud.subscription_id and sud.language_id='" . $languages_id . "'");
 169  
 170      if (tep_db_num_rows($subscription_query)<=0) return;
 171  
 172      $subscription_result=tep_db_fetch_array($subscription_query);
 173  
 174      $tax_rate=tep_get_tax_rate($subscription_result['subscription_tax_class_id']);
 175  
 176      // fetch the customer details

 177      $customer_query=tep_db_query("select customers_firstname,customers_lastname,customers_email_address from " . TABLE_CUSTOMERS . " where customers_id='" . $send_details['customers_id'] . "'");
 178      if (tep_db_num_rows($customer_query)<=0) return;
 179      $customer_result=tep_db_fetch_array($customer_query);
 180  
 181      $details=array();
 182      $details['type']=$send_details['mail_type'];
 183      $details['table']=TABLE_SUBSCRIPTION_MESSAGES;
 184      $details['subscription_id']=$send_details['subscription_id'];
 185      
 186      tep_get_template($details);
 187      
 188      $replace_array=array(     TEXT_SUB_NA=>$subscription_result['subscription_name'],
 189                              TEXT_SUB_CO=>$currencies->format(tep_add_tax($subscription_result['subscription_costs'],$tax_rate)),
 190                              TEXT_SUB_PE=>$subscription_result["subscription_period"],
 191                              TEXT_SUB_RL=>'<a href="' . tep_href_link(FILENAME_ACCOUNT,'R=1','NONSSL',false) . '">' . TEST_MAIL_SUB_RL . '</a>',
 192                              TEXT_CF=>$customer_result['customers_firstname'],
 193                              TEXT_CL=>$customer_result['customers_lastname'],
 194                              TEXT_IC=>$send_details['comments'],
 195                              TEXT_IF=>'<a href="mailto:' . $customer_result['customers_email_address'] . '"><u>' . $customer_result['customers_email_address'] .'</u></a>'
 196                              );
 197      //replace template

 198      tep_replace_template($details,$replace_array);
 199      tep_strip_html($details);
 200      $email_array=&$send_details["address"];
 201      $name_array=&$send_details["name"];
 202  
 203      // send email

 204      $message = new email(array('X-Mailer: osCommres'));
 205      for ($icnt=0;$icnt<sizeof($email_array);$icnt++){
 206          $mes_content=$details['html_text'];
 207          $mes_text=eregi_replace("%%" . TEXT_FE . "%%",$name_array[$icnt] . "",$mes_content);
 208          
 209          $text=strip_tags($mes_text,'<br>');
 210          $text=str_replace('<br>',chr(13). chr(10),$text);
 211          $text=str_replace('<BR>',chr(13). chr(10),$text);
 212  
 213          if ($mes_text!='' && $email_array[$icnt]!=''){
 214  
 215              if ($mail_data_result['message_format'] != 'T') {
 216                  $message->add_html($mes_text, $text);
 217              } else {
 218                  $message->add_text($text);
 219              }
 220              $message->build_message();
 221              //echo $email_array[$icnt] . '-->' . $mes_text . '<br>';

 222              $message->send($name_array[$icnt], $email_array[$icnt], $customer_result['customers_firstname'] . ' ' . $customer_result['customers_lastname'], $customer_result['customers_email_address'], $details['subject']);
 223          }
 224      }
 225  }
 226  
 227  // replace the invite email content

 228  function tep_replace_subscription_invite_mail_content($send_details){
 229  global $currencies,$languages_id;
 230      if (!is_array($send_details)) return;
 231  
 232      // fetch the subscription details

 233      $subscription_query=tep_db_query("select su.subscription_id,sud.subscription_name,su.subscription_period,su.subscription_costs,su.subscription_tax_class_id from " . 
 234                                  TABLE_SUBSCRIPTIONS . " su, " . TABLE_SUBSCRIPTIONS_DESCRIPTION .  " sud " .
 235                                  "where su.subscription_id='" . $send_details['subscription_id'] . "' and su.subscription_id=sud.subscription_id and sud.language_id='" . $languages_id . "'");
 236      
 237      if (tep_db_num_rows($subscription_query)<=0) return;
 238      
 239      $subscription_result=tep_db_fetch_array($subscription_query);
 240      
 241      $tax_rate=tep_get_tax_rate($subscription_result['subscription_tax_class_id']);
 242      
 243      // fetch the customer detail

 244      $customer_query=tep_db_query("select customers_firstname,customers_lastname,customers_email_address from " . TABLE_CUSTOMERS . " where customers_id='" . $send_details['cID'] . "'");
 245      if (tep_db_num_rows($customer_query)<=0) return;
 246      $customer_result=tep_db_fetch_array($customer_query);
 247  
 248      
 249      // prepare the merge array

 250      $replace_array=array(     TEXT_SUB_NA=>$subscription_result['subscription_name'],
 251                              TEXT_SUB_CO=>$currencies->format(tep_add_tax($subscription_result['subscription_costs'],$tax_rate)),
 252                              TEXT_SUB_PE=>$subscription_result["susbcription_period"],
 253                              TEXT_SUB_RL=>'<a href="' . tep_href_link(FILENAME_ACCOUNT,'R=1','NONSSL',false) . '">' . TEST_MAIL_SUB_RL . '</a>',
 254                              TEXT_CF=>$customer_result['customers_firstname'],
 255                              TEXT_CL=>$customer_result['customers_lastname'],
 256                              TEXT_IC=>$send_details['comments'],
 257                              TEXT_FE=>TEST_MAIL_FE,
 258                              TEXT_IC=>TEST_MAIL_IC,
 259                              TEXT_IF=>'<a href="mailto:' . $customer_result['customers_email_address'] . '"><u>' . $customer_result['customers_email_address'] .'</u></a>'
 260                              );
 261  
 262      $mes_content=$send_details['text'];
 263  
 264      // replace the merge details

 265      while (list($key, $value) = each($replace_array))
 266          $mes_content=eregi_replace("%%" . $key  . "%%",$value . "",$mes_content);
 267  
 268      return $mes_content;    
 269  }
 270  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]