| [ PHPXref.com ] | [ Generated: Sun Jul 20 19:13:40 2008 ] | [ osCommRes 1.2.0 ] |
| [ Index ] [ Variables ] [ Functions ] [ Classes ] [ Constants ] [ Statistics ] | ||
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 4 osCommerce, Open Source E-Commerce Solutions 5 http://www.oscommerce.com 6 7 Copyright (c) 2003 osCommerce 8 9 osCommRes, Services Online 10 http://www.oscommres.com 11 12 Copyright (c) 2005 osCommRes 13 14 Released under the GNU General Public License 15 */ 16 //// 17 // Return true if the events category has subcategories 18 // TABLES: events_categories 19 20 // use condition in all event status checking 21 define('EVENTS_CONDITION_STATUS'," and (e.events_status=1 or ( e.events_status=2 and e.sessions_start_date>=curdate()) or (e.events_status>=3 and e.sessions_end_date>=curdate())) and date_format(e.events_date_available,'%Y-%m-%d')<=curdate()"); 22 define('EVENTS_VIEW_CONDITION_STATUS'," and (e.events_status=1 or ( e.events_status=2 and e.sessions_start_date>curdate()) or (e.events_status>=3 and e.sessions_end_date>=curdate())) and date_format(e.events_date_available,'%Y-%m-%d')>curdate()"); 23 define('SUBSCRIPTION_CONDITION_STATUS'," and (su.subscription_status=1) and date_format(su.subscription_date_available,'%Y-%m-%d')<=curdate()"); 24 define('TEXT_COMPLETE_PAYMENT','Complete Payment'); 25 // check if an category has subcategories 26 function tep_has_events_category_subcategories($events_category_id) { 27 $child_events_category_query = tep_db_query("select count(*) as count from " . TABLE_EVENTS_CATEGORIES . " where parent_id = '" . (int)$events_category_id . "'"); 28 $child_events_category = tep_db_fetch_array($child_events_category_query); 29 30 if ($child_events_category['count'] > 0) { 31 return true; 32 } else { 33 return false; 34 } 35 } 36 37 //// 38 // Return the number of events in a category 39 // TABLES: events, events_to_events categories, categories 40 function tep_count_events_in_events_category($events_category_id, $include_inactive = false) { 41 $events_count = 0; 42 if ($include_inactive == true) { 43 $events_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " e2c where e.events_id = e2c.events_id and e2c.events_categories_id = '" . (int)$events_category_id . "'"); 44 } else { 45 $events_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS . " e, " . TABLE_EVENTS_TO_EVENTS_CATEGORIES . " e2c where e.events_id = e2c.events_id and e.events_status >= 1 and e2c.events_categories_id = '" . (int)$events_category_id . "'"); 46 } 47 $events = tep_db_fetch_array($events_query); 48 $events_count += $events['total']; 49 50 $child_events_categories_query = tep_db_query("select events_categories_id from " . TABLE_EVENTS_CATEGORIES . " where parent_id = '" . (int)$events_category_id . "'"); 51 if (tep_db_num_rows($child_events_categories_query)) { 52 while ($child_events_categories = tep_db_fetch_array($child_events_categories_query)) { 53 $events_count += tep_count_events_in_events_category($child_events_categories['events_categories_id'], $include_inactive); 54 } 55 } 56 57 return $events_count; 58 } 59 60 //// 61 // Parse and secure the ecPath parameter values 62 function tep_parse_events_category_path($ecPath) { 63 // make sure the category IDs are integers 64 $ecPath_array = array_map('tep_string_to_int', explode('_', $ecPath)); 65 66 // make sure no duplicate category IDs exist which could lock the server in a loop 67 $tmp_array = array(); 68 $n = sizeof($ecPath_array); 69 for ($i=0; $i<$n; $i++) { 70 if (!in_array($ecPath_array[$i], $tmp_array)) { 71 $tmp_array[] = $ecPath_array[$i]; 72 } 73 } 74 75 return $tmp_array; 76 } 77 78 79 //// 80 // Generate a path to events categories 81 function tep_get_events_path($current_events_category_id = '') { 82 global $ecPath_array; 83 84 if (tep_not_null($current_events_category_id)) { 85 $ecp_size = sizeof($ecPath_array); 86 if ($ecp_size == 0) { 87 $ecPath_new = $current_events_category_id; 88 } else { 89 $ecPath_new = ''; 90 $last_events_category_query = tep_db_query("select parent_id from " . TABLE_EVENTS_CATEGORIES . " where events_categories_id = '" . (int)$ecPath_array[($ecp_size-1)] . "'"); 91 $last_events_category = tep_db_fetch_array($last_events_category_query); 92 93 $current_events_category_query = tep_db_query("select parent_id from " . TABLE_EVENTS_CATEGORIES . " where events_categories_id = '" . (int)$current_events_category_id . "'"); 94 $current_events_category = tep_db_fetch_array($current_events_category_query); 95 96 if ($last_events_category['parent_id'] == $current_events_category['parent_id']) { 97 for ($i=0; $i<($ecp_size-1); $i++) { 98 $ecPath_new .= '_' . $ecPath_array[$i]; 99 } 100 } else { 101 for ($i=0; $i<$ecp_size; $i++) { 102 $ecPath_new .= '_' . $ecPath_array[$i]; 103 } 104 } 105 $ecPath_new .= '_' . $current_events_category_id; 106 107 if (substr($ecPath_new, 0, 1) == '_') { 108 $ecPath_new = substr($ecPath_new, 1); 109 } 110 } 111 } else { 112 $ecPath_new = implode('_', $ecPath_array); 113 } 114 115 return 'ecPath=' . $ecPath_new; 116 } 117 118 // prepare the events categories path for given category_id 119 function tep_find_events_category_path($category_id){ 120 $query=tep_db_query("SELECT parent_id,events_categories_id from " . TABLE_EVENTS_CATEGORIES . " where events_categories_id='" . $category_id . "'"); 121 122 if (tep_db_num_rows($query)<=0) return ""; 123 $result=tep_db_fetch_array($query); 124 if ($result["parent_id"]==0){ 125 return $category_id; 126 } else { 127 return tep_find_events_category_path($result["parent_id"]) . "_" . $category_id; 128 } 129 } 130 131 //// 132 // Return a event's name 133 // TABLES: events 134 function tep_get_events_name($event_id, $language = '') { 135 global $languages_id; 136 137 if (empty($language)) $language = $languages_id; 138 139 $event_query = tep_db_query("select events_name from " . TABLE_EVENTS_DESCRIPTION . " where events_id = '" . (int)$event_id . "' and language_id = '" . (int)$language . "'"); 140 $event = tep_db_fetch_array($event_query); 141 142 return $event['events_name']; 143 } 144 145 // Return a instructor name 146 function tep_get_instructor_name($id) { 147 $instructor_query = tep_db_query("select admin_firstname,admin_lastname from " . TABLE_ADMIN . " where admin_id='" . (int)$id . "'"); 148 if ($instructor=tep_db_fetch_array($instructor_query)) 149 return $instructor['admin_firstname'] . ' ' . $instructor['admin_lastname']; 150 } 151 152 // Get the session type single or recursive for an event 153 function tep_get_session_type($event_id) 154 { 155 $check_query=tep_db_query("select count(*) as total from " . TABLE_RECURSIVE_SESSIONS . " where events_id='" . $event_id . "'"); 156 if ($check_result=tep_db_fetch_array($check_query)){ 157 if ((int)$check_result['total']>0) 158 return 'R'; 159 $check_query=tep_db_query("select count(*) as total from " . TABLE_EVENTS_SESSIONS . " where events_id='" . $event_id . "' and sessions_type!=''"); 160 $check_result=tep_db_fetch_array($check_query); 161 if ((int)$check_result['total']>0) 162 return 'S'; 163 } 164 return ''; 165 } 166 // Get the session date for an session 167 function tep_get_session_date($session_id) 168 { 169 $check_query=tep_db_query("select start_date from " . TABLE_EVENTS_SESSIONS . " where sessions_id='" . $session_id . "'"); 170 $check_result=tep_db_fetch_array($check_query); 171 return $check_result["start_date"]; 172 } 173 174 // get the available free_sessions 175 function tep_get_free_sessions($start_id,$no_of_sessions,$events_type){ 176 // get event details with session id 177 global $session_array,$events_result,$customer_id; 178 179 $events_id=(int)$events_result['events_id']; 180 $start_date=tep_get_session_date($start_id); 181 $max_reserve=((int)$events_result['events_max_reserve']); 182 183 //iterate and find available session 184 if ($events_result['events_forward_period']=='Y'){ 185 $check_date=date('Y-m-d',tep_dateadd(time(),'day',(int)$events_result['events_forward_length'])); 186 $check_data=" and start_date<='" . $check_date . "' "; 187 } 188 $date_query=tep_db_query("select sessions_id,start_date,recursive_sessions_id from " . TABLE_EVENTS_SESSIONS . " where events_id='" . $events_id . "' and start_date>='" . $start_date . "' and sessions_type!='' and sessions_type!='P' " . $check_data ." order by start_date"); 189 190 //iterate all selected dates and find reserved,waitlist,no seats dates 191 $current_count=1; 192 193 $session_array_temp=array(); 194 while($date_result=tep_db_fetch_array($date_query)){ 195 $accept=false; 196 $session_type="R"; 197 if ($events_type=='R' || $events_type=='M'){ 198 199 // calculate total reservations using no of reserved users, no of renewal users, no of reservations in the cart 200 $total_reservations=tep_reserve_count($date_result["sessions_id"],$events_result)+1; 201 $total_reservations+=tep_get_renewal_users_count($events_result,$date_result['start_date']); 202 $total_reservations+=tep_count_cart($date_result["sessions_id"],"R"); 203 204 // check if total reservations exceed the maximum limits 205 if ($total_reservations<=$max_reserve){ 206 $accept=true; 207 } else { 208 // if session_gaps is not selected, continuous dates need to be selected 209 if ($events_result['session_gaps']!='Y' && sizeof($session_array_temp)>0){ 210 $session_array_temp=array(); 211 $current_count=1; 212 } 213 } 214 } 215 if ($accept==false){ 216 $session_type="W"; 217 if ($events_type=='W' || $events_type=='M'){ 218 // find the entry in any of the three waiting list groups 219 $find_group=tep_find_waitlist_group($events_id,$date_result['sessions_id'],$customer_id,$events_result); 220 221 if ($find_group!='E'){ 222 $accept=true; 223 } else { 224 if ($events_result['session_gaps']!='Y' && sizeof($session_array_temp)>0){ 225 $session_array_temp=array(); 226 $current_count=1; 227 } 228 } 229 } 230 } 231 if ($accept==true){ 232 // if the found date is not already selected add the temp list 233 if (!isset($session_array[$date_result['sessions_id']])){ 234 $session_array_temp[$date_result['sessions_id']]=array('date'=>$date_result['start_date'],'type'=>$session_type,'group'=>$find_group,'recursive_id'=>$date_result['recursive_sessions_id']); 235 $current_count++; 236 if ($current_count>$no_of_sessions) break; 237 } 238 } 239 } 240 // merge to final output list 241 if (sizeof($session_array_temp)>0) $session_array+=$session_array_temp; 242 } 243 244 // get the total no of reserved users 245 function tep_reserve_count($sessions_id,&$values) 246 { 247 $count=0; 248 $pending_option=""; 249 if ((int)$values['events_pending_period']>0){ 250 $pending_option=" and (o.orders_status>1 or date_add(o.date_purchased,interval '" . $values['events_pending_period'] . "' day)>=curdate())"; 251 } 252 $query=tep_db_query("select count(orders_products_id) as total_count from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op where o.orders_id=op.orders_id and op.products_type='E' and op.events_type='R' and op.products_id='" . $sessions_id ."' " . $pending_option); 253 $result=tep_db_fetch_array($query); 254 $count+=(int)$result['total_count']; 255 256 return $count; 257 } 258 259 // get the total no of waitlisted users 260 function tep_waitlist_count($sessions_id,&$values) 261 { 262 $count=0; 263 $pending_option=""; 264 if ((int)$values['events_pending_period']>0){ 265 $pending_option=" and (o.orders_status>1 or date_add(o.date_purchased,interval '" . $values['events_pending_period'] . "' day)>=curdate())"; 266 } 267 $query=tep_db_query("select count(orders_products_id) as total_count from " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op where o.orders_id=op.orders_id and op.products_type='E' and op.events_type='W' and op.products_id='" . $sessions_id ."' " . $pending_option); 268 $result=tep_db_fetch_array($query); 269 $count+=(int)$result['total_count']; 270 return $count; 271 } 272 273 // get the total no of users found in the cart 274 function tep_count_cart($session_id,$events_type,$waitlist_type=""){ 275 $cart_count=0; //count in shopping cart and edit orders table 276 277 // time elapsed of events_order_timeout 278 $expiry=strtotime("-" . ((int)EVENTS_ORDER_TIMEOUT) . " minutes"); 279 // get cart count by checking records within this expiry time 280 $query="SELECT count(*) as total from " . TABLE_CUSTOMERS_BASKET . " cb, " . TABLE_CUSTOMERS_BASKET_SESSIONS . " cs where cs.session_id='" . $session_id . "' and cs.products_id=cb.products_id " . 281 " and UNIX_TIMESTAMP(cb.customers_basket_date_added)>" . $expiry . " and cs.session_type='" . $events_type . "' and cs.session_group='" . $waitlist_type ."' and cb.products_type='E';"; 282 $result=tep_db_query($query); 283 $result_array=tep_db_fetch_array($result); 284 $cart_count+=(int)$result_array["total"]; 285 286 //get backend orders edit table count 287 $query="SELECT count(*) as total from " . TABLE_ORDERS_EDIT_PRODUCTS . " eo where eo.products_id='" . $session_id . 288 "' and UNIX_TIMESTAMP(eo.date_added)>" . $expiry . " and eo.events_type='" . $events_type . "' and eo.waitlist_type='" . $waitlist_type ."' and eo.products_type='E';"; 289 $result=tep_db_query($query); 290 $result_array=tep_db_fetch_array($result); 291 $cart_count+=(int)$result_array["total"]; 292 293 return $cart_count; 294 } 295 // get the admin groups name by providing the group id 296 function tep_get_group_name($group_id){ 297 $group_query=tep_db_query("SELECT admin_groups_name from " . TABLE_ADMIN_GROUPS . " where admin_groups_id='" . (int)$group_id . "'"); 298 if ($group_result=tep_db_fetch_array($group_query)){ 299 return $group_result['admin_groups_name']; 300 } 301 } 302 303 // get the html content for question input from user 304 function tep_get_question_input($type){ 305 $result=''; 306 $param="size=30 maxlength=100"; 307 //if the type is text or numeric, create a textbox 308 if ($type=='T' || $type=='N'){ 309 if ($type=='N') $param="size=15 maxlength=10"; 310 $result.=tep_draw_input_field('question_value_data','',$param); 311 } else if ($type=='D'){ 312 // if the type is a date, create a dropdownlist for month,day,year 313 314 $result.=tep_draw_hidden_field('question_value_data',''); 315 $month=array('','January','February','March','April','May','June','July','August','September','October','November','December'); 316 $date_query=tep_db_query("SELECT date_format(current_date,'%d') as day, date_format(current_date,'%m') as month, date_format(current_date,'%Y') as year"); 317 $date_result=tep_db_fetch_array($date_query); 318 $month_array=array(); 319 for($icnt=0;$icnt<=12;$icnt++) 320 $month_array[]=array('id'=>$icnt,'text'=>$month[$icnt]); 321 $result.=tep_draw_pull_down_menu('question_month',$month_array); 322 $day_array=array(); 323 for($icnt=0;$icnt<=31;$icnt++){ 324 $text=$icnt; 325 if ($icnt==0) $text=''; 326 $day_array[]=array('id'=>$icnt,'text'=>$text); 327 } 328 $result.=' ' . tep_draw_pull_down_menu('question_day',$day_array); 329 $year_array=array(); 330 $year_array[]=array('id'=>0,'text'=>''); 331 $year_array[]=array('id'=>$date_result['year'],'text'=>$date_result['year']); 332 $year_array[]=array('id'=>$date_result['year']+1,'text'=>$date_result['year']+1); 333 $result.=' ' . tep_draw_pull_down_menu('question_year',$year_array); 334 } 335 return $result . '<font color="red"> *</font>'; 336 } 337 338 // send single session email 339 function tep_send_event_email($process_id,$mail_type){ 340 global $currencies; 341 342 if ((int)EMAIL_ACTIVATE!=1 && (int)SMS_ACTIVATE!=1) return; 343 if ((int)$process_id<=0 || $mail_type=='') 344 return; 345 346 // fetch data 347 $process_query=tep_db_query("select c.customers_id,c.customers_firstname,c.customers_lastname,c.customers_dob,c.customers_telephone,c.customers_fax,c.customers_second_telephone,c.customers_second_email_address, 348 o.customers_street_address,c.customers_email_address,o.customers_suburb,o.customers_postcode,o.customers_city, 349 o.customers_state,o.customers_country,op.final_price,op.products_id,s.start_date,e.events_payment,op.products_tax,op.products_name, 350 e.events_id,e.events_instructor,e.events_renewal_start,e.events_renewal_end,time_format(e.events_start_time,'%h:%i %p') as events_start_time,time_format(e.events_end_time,'%h:%i %p') as events_end_time,e.events_location,e.events_fees,e.events_tax_class_id,o.orders_id,o.date_purchased,o.billing_name,o.billing_street_address,o.payment_method from " . 351 TABLE_CUSTOMERS . " c, " . TABLE_EVENTS_SESSIONS . " s, " . TABLE_ORDERS . " o, " . TABLE_ORDERS_PRODUCTS . " op, " . TABLE_EVENTS . " e " . 352 "where o.orders_id=op.orders_id and o.customers_id=c.customers_id and op.products_id=s.sessions_id and s.events_id=e.events_id and op.orders_products_id='" . $process_id . "'"); 353 354 if (tep_db_num_rows($process_query)<=0) return; 355 356 $process_result=tep_db_fetch_array($process_query); 357 358 //fetch mail template 359 $details=array(); 360 $details['type']=$mail_type; 361 $details['table']=TABLE_EVENTS_MESSAGES; 362 $details['events_id']=$process_result['events_id']; 363 364 tep_get_template($details); 365 366 if ($details['html_text']=="") return; 367 368 // get the renewal end date of this reservation 369 $renewal_array=tep_get_renewal_details($process_result,$process_result["customers_id"],true); 370 $renewal_end=""; 371 372 if (sizeof($renewal_array)>0) $renewal_end=$renewal_array["end_date"]; 373 374 $events_location=tep_get_locations_name($process_result['events_location']); 375 376 // prepare details for merge details 377 $replace_array=array( TEXT_FN=>$process_result['customers_firstname'], 378 TEXT_LN=>$process_result['customers_lastname'], 379 TEXT_DF=>format_date($process_result['customers_dob']), 380 TEXT_EM=>'<a href="mailto:' . $process_result['customers_email_address'] . '"><u>' . $process_result['customers_email_address'] .'</u></a>', 381 TEXT_TN=>$process_result['customers_telephone'], 382 TEXT_FX=>$process_result['customers_fax'], 383 TEXT_SA=>$process_result['customers_street_address'], 384 TEXT_SU=>$process_result['customers_suburb'], 385 TEXT_PC=>$process_result['customers_postcode'], 386 TEXT_CT=>$process_result['customers_city'], 387 TEXT_ST=>$process_result['customers_state'], 388 TEXT_CY=>$process_result['customers_country'], 389 390 TEXT_EN=>$process_result['products_name'], 391 TEXT_SI=>$process_result['events_start_time'], 392 TEXT_EI=>$process_result['events_end_time'], 393 TEXT_EF=>$currencies->format(tep_add_tax($process_result['events_fees'],tep_get_tax_rate($process_result['events_tax_class_id']))), 394 TEXT_IN=>tep_get_instructor_name($process_result['events_instructor']), 395 TEXT_EL=>$events_location, 396 TEXT_SD=>format_date($process_result['start_date']), 397 TEXT_IV=>'<a href="' . tep_href_link(