| [ 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 // Sets the status of a banner 18 function tep_set_banner_status($banners_id, $status) { 19 if ($status == '1') { 20 return tep_db_query("update " . TABLE_BANNERS . " set status = '1', date_status_change = now(), date_scheduled = NULL where banners_id = '" . (int)$banners_id . "'"); 21 } elseif ($status == '0') { 22 return tep_db_query("update " . TABLE_BANNERS . " set status = '0', date_status_change = now() where banners_id = '" . (int)$banners_id . "'"); 23 } else { 24 return -1; 25 } 26 } 27 28 //// 29 // Auto activate banners 30 function tep_activate_banners() { 31 $banners_query = tep_db_query("select banners_id, date_scheduled from " . TABLE_BANNERS . " where date_scheduled != ''"); 32 if (tep_db_num_rows($banners_query)) { 33 while ($banners = tep_db_fetch_array($banners_query)) { 34 if (date('Y-m-d H:i:s') >= $banners['date_scheduled']) { 35 tep_set_banner_status($banners['banners_id'], '1'); 36 } 37 } 38 } 39 } 40 41 //// 42 // Auto expire banners 43 function tep_expire_banners() { 44 $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"); 45 if (tep_db_num_rows($banners_query)) { 46 while ($banners = tep_db_fetch_array($banners_query)) { 47 if (tep_not_null($banners['expires_date'])) { 48 if (date('Y-m-d H:i:s') >= $banners['expires_date']) { 49 tep_set_banner_status($banners['banners_id'], '0'); 50 } 51 } elseif (tep_not_null($banners['expires_impressions'])) { 52 if ( ($banners['expires_impressions'] > 0) && ($banners['banners_shown'] >= $banners['expires_impressions']) ) { 53 tep_set_banner_status($banners['banners_id'], '0'); 54 } 55 } 56 } 57 } 58 } 59 60 //// 61 // Display a banner from the specified group or banner id ($identifier) 62 function tep_display_banner($action, $identifier) { 63 if ($action == 'dynamic') { 64 $banners_query = tep_db_query("select count(*) as count from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'"); 65 $banners = tep_db_fetch_array($banners_query); 66 if ($banners['count'] > 0) { 67 $banner = tep_random_select("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'"); 68 } else { 69 return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> No banners with group \'' . $identifier . '\' found!</b>'; 70 } 71 } elseif ($action == 'static') { 72 if (is_array($identifier)) { 73 $banner = $identifier; 74 } else { 75 $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 . "'"); 76 if (tep_db_num_rows($banner_query)) { 77 $banner = tep_db_fetch_array($banner_query); 78 } else { 79 return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> Banner with ID \'' . $identifier . '\' not found, or status inactive</b>'; 80 } 81 } 82 } else { 83 return '<b>TEP ERROR! (tep_display_banner(' . $action . ', ' . $identifier . ') -> Unknown $action parameter value - it must be either \'dynamic\' or \'static\'</b>'; 84 } 85 86 if (tep_not_null($banner['banners_html_text'])) { 87 $banner_string = $banner['banners_html_text']; 88 } else { 89 $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>'; 90 } 91 92 tep_update_banner_display_count($banner['banners_id']); 93 94 return $banner_string; 95 } 96 97 //// 98 // Check to see if a banner exists 99 function tep_banner_exists($action, $identifier) { 100 if ($action == 'dynamic') { 101 return tep_random_select("select banners_id, banners_title, banners_image, banners_html_text from " . TABLE_BANNERS . " where status = '1' and banners_group = '" . $identifier . "'"); 102 } elseif ($action == 'static') { 103 $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 . "'"); 104 return tep_db_fetch_array($banner_query); 105 } else { 106 return false; 107 } 108 } 109 110 //// 111 // Update the banner display statistics 112 function tep_update_banner_display_count($banner_id) { 113 $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')"); 114 $banner_check = tep_db_fetch_array($banner_check_query); 115 116 if ($banner_check['count'] > 0) { 117 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')"); 118 } else { 119 tep_db_query("insert into " . TABLE_BANNERS_HISTORY . " (banners_id, banners_shown, banners_history_date) values ('" . (int)$banner_id . "', 1, now())"); 120 } 121 } 122 123 //// 124 // Update the banner click statistics 125 function tep_update_banner_click_count($banner_id) { 126 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')"); 127 } 128 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| [ Powered by PHPXref - Served by Debian GNU/Linux ] |