[ Index ] |
PHP Cross Reference of osCMax 2.0.4 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 $Id: banner.php 3 2006-05-27 04:59:07Z user $ 4 5 osCMax Power E-Commerce 6 http://oscdox.com 7 8 Copyright 2006 osCMax 9 10 Released under the GNU General Public License 11 */ 12 13 //// 14 // Sets the status of a banner 15 function tep_set_banner_status($banners_id, $status) { 16 if ($status == '1') { 17 return tep_db_query("update " . TABLE_BANNERS . " set status = '1', date_status_change = now(), date_scheduled = NULL where banners_id = '" . (int)$banners_id . "'"); 18 } elseif ($status == '0') { 19 return tep_db_query("update " . TABLE_BANNERS . " set status = '0', date_status_change = now() where banners_id = '" . (int)$banners_id . "'"); 20 } else { 21 return -1; 22 } 23 } 24 25 //// 26 // Auto activate banners 27 function tep_activate_banners() { 28 $banners_query = tep_db_query("select banners_id, date_scheduled from " . TABLE_BANNERS . " where date_scheduled != ''"); 29 if (tep_db_num_rows($banners_query)) { 30 while ($banners = tep_db_fetch_array($banners_query)) { 31 if (date('Y-m-d H:i:s') >= $banners['date_scheduled']) { 32 tep_set_banner_status($banners['banners_id'], '1'); 33 } 34 } 35 } 36 } 37 38 //// 39 // Auto expire banners 40 function tep_expire_banners() { 41 $banners_query = tep_db_query("select b.banners_id, b.expires_date, b.expires_impressions, sum(bh.banners_shown) as banners_shown from " . TABLE_BANNERS . " b, " . TABLE_BANNERS_HISTORY . " bh where b.status = '1' and b.banners_id = bh.banners_id group by b.banners_id"); 42 if (tep_db_num_rows($banners_query)) { 43 while ($banners = tep_db_fetch_array($banners_query)) { 44 if (tep_not_null($banners['expires_date'])) { 45 if (date('Y-m-d H:i:s') >= $banners['expires_date']) { 46 tep_set_banner_status($banners['banners_id'], '0'); 47 } 48 } elseif (tep_not_null($banners['expires_impressions'])) { 49 if ( ($banners['expires_impressions'] > 0) && ($banners['banners_shown'] >= $banners['expires_impressions']) ) { 50 tep_set_banner_status($banners['banners_id'], '0'); 51 } 52 } 53 } 54 } 55 } 56 57 //// 58 // Display a banner from the specified group or banner id ($identifier) 59 function tep_display_banner($action, $identifier) { 60 if ($action == 'dynamic') { 61 $banners_query = tep_db_query("select count(*) as count from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'"); 62 $banners = tep_db_fetch_array($banners_query); 63 if ($banners['count'] > 0) { 64 $banner = tep_random_select("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'"); 65 } else { 66 return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> No banners with group \'' . $identifier . '\' found!</b>'; 67 } 68 } elseif ($action == 'static') { 69 if (is_array($identifier)) { 70 $banner = $identifier; 71 } else { 72 $banner_query = tep_db_query("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_id = '" . (int)$identifier . "'"); 73 if (tep_db_num_rows($banner_query)) { 74 $banner = tep_db_fetch_array($banner_query); 75 } else { 76 return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> Banner with ID \'' . $identifier . '\' not found, or status inactive</b>'; 77 } 78 } 79 } else { 80 return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> Unknown $action parameter value - it must be either \'dynamic\' or \'static\'</b>'; 81 } 82 83 if (tep_not_null($banner['banners_html_text'])) { 84 $banner_string = $banner['banners_html_text']; 85 } else { 86 $banner_string = '<a href="' . tep_href_link(FILENAME_REDIRECT, 'action=banner&goto=' . $banner['banners_id']) . '" target="_blank">' . tep_image(DIR_WS_IMAGES . $banner['banners_image'], $banner['banners_title']) . '</a>'; 87 } 88 89 tep_update_banner_display_count($banner['banners_id']); 90 91 return $banner_string; 92 } 93 94 //// 95 // Check to see if a banner exists 96 function tep_banner_exists($action, $identifier) { 97 if ($action == 'dynamic') { 98 return tep_random_select("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'"); 99 } elseif ($action == 'static') { 100 $banner_query = tep_db_query("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_id = '" . (int)$identifier . "'"); 101 return tep_db_fetch_array($banner_query); 102 } else { 103 return false; 104 } 105 } 106 107 //// 108 // Update the banner display statistics 109 function tep_update_banner_display_count($banner_id) { 110 $banner_check_query = tep_db_query("select count(*) as count from " . TABLE_BANNERS_HISTORY . " where banners_id = '" . (int)$banner_id . "' and date_format(banners_history_date, '%Y%m%d') = date_format(now(), '%Y%m%d')"); 111 $banner_check = tep_db_fetch_array($banner_check_query); 112 113 if ($banner_check['count'] > 0) { 114 tep_db_query("update " . TABLE_BANNERS_HISTORY . " set banners_shown = banners_shown + 1 where banners_id = '" . (int)$banner_id . "' and date_format(banners_history_date, '%Y%m%d') = date_format(now(), '%Y%m%d')"); 115 } else { 116 tep_db_query("insert into " . TABLE_BANNERS_HISTORY . " (banners_id, banners_shown, banners_history_date) values ('" . (int)$banner_id . "', 1, now())"); 117 } 118 } 119 120 //// 121 // Update the banner click statistics 122 function tep_update_banner_click_count($banner_id) { 123 tep_db_query("update " . TABLE_BANNERS_HISTORY . " set banners_clicked = banners_clicked + 1 where banners_id = '" . (int)$banner_id . "' and date_format(banners_history_date, '%Y%m%d') = date_format(now(), '%Y%m%d')"); 124 } 125 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Jan 1 13:43:16 2010 | Cross-referenced by PHPXref 0.7 |