function fbpromo_promoCodes($vars) { if (strstr($_SERVER['SCRIPT_NAME'], 'cart.php') && fbpromo_get_addon('promo_active')) { $txt = '<div style="text-align:center;background-color:#E7FFDA;border-radius:5px;padding:20px;font-size:16px;margin:20px 40px;">'; $txt .= html_entity_decode(fbpromo_get_addon('promo_text')); $txt .= '</div>'; return $txt; } }
function fbpromo_update_addon($setting, $value) { if (fbpromo_get_addon($setting) !== false) { $sql = "update `tbladdonmodules` set `value`='" . $value . "' where `module`='fbpromo' and `setting`='" . $setting . "'"; $rs = mysql_query($sql); } else { $sql = "insert into `tbladdonmodules` (`value`,`module`,`setting`) values ('" . $value . "','fbpromo','" . $setting . "')"; $rs = mysql_query($sql); } }
$i = 1; $promotions = array(); echo $vars['_lang']['liked'] . '<br />'; $sql = mysql_query("SELECT * FROM `tblpromotions` where `id` in (" . fbpromo_get_addon('promotions') . ") and (`expirationdate` = '0000-00-00' or `expirationdate` < '" . date('Y-m-d') . "') order by `code`"); if (mysql_num_rows($sql)) { while ($promotion = mysql_fetch_assoc($sql)) { echo '<strong>' . $promotion['code'] . '-' . $id . '-' . $hash . '</strong> <sup>(' . $i . ')</sup>' . '<br />'; $promotion['code'] .= '-' . $id . '-' . $hash; unset($promotion['id']); $promotion['uses'] = 0; $promotion['expirationdate'] = date('Y-m-d', time() + 60 * 60 * 24 * 30); $promotions[] = $promotion; $i++; } } echo '<br />' . fbpromo_get_addon('description') . '<br />'; foreach ($promotions as $promotion) { $values = $keys = ''; foreach ($promotion as $key => $value) { if ($values) { $values .= ","; } if ($keys) { $keys .= ","; } $values .= "'" . $value . "'"; $keys .= "`" . $key . "`"; } $sql = mysql_query("SELECT * FROM `tblpromotions` where `code`='" . $promotion['code'] . "'"); if (!mysql_num_rows($sql)) { $query = "INSERT INTO `tblpromotions` (" . $keys . ") VALUES (" . $values . ")";
function fbpromo_output($vars) { global $CONFIG; if (isset($_REQUEST['save-settings'])) { if (isset($_REQUEST['promotions'])) { $promotions = $_REQUEST['promotions']; fbpromo_update_addon('promotions', implode(',', $promotions)); } else { $promotions = array(); fbpromo_update_addon('promotions', ''); } if (isset($_REQUEST['description'])) { $description = $_REQUEST['description']; fbpromo_update_addon('description', $description); } else { fbpromo_update_addon('description', ''); } if (isset($_REQUEST['appid'])) { $appId = $_REQUEST['appid']; fbpromo_update_addon('appid', $appId); } else { fbpromo_update_addon('appid', ''); } if (isset($_REQUEST['appsecret'])) { $appSecret = $_REQUEST['appsecret']; fbpromo_update_addon('appsecret', $appSecret); } else { fbpromo_update_addon('appsecret', ''); } echo '<div class="infobox">' . $vars['_lang']['admin5'] . '</div>'; } else { $promotions = explode(',', fbpromo_get_addon('promotions')); $description = fbpromo_get_addon('description'); $appId = fbpromo_get_addon('appid'); $appSecret = fbpromo_get_addon('appsecret'); } echo '<form method="post" action="addonmodules.php?module=fbpromo">'; echo '<table class="form" width="100%" cellspacing="2" cellpadding="3" border="0">'; echo '<tr><td class="fieldlabel">' . $vars['_lang']['admin1'] . '</td><td class="fieldarea">' . $CONFIG['SystemURL'] . '/?m=fbpromo' . '</td></tr>'; echo '<tr><td class="fieldlabel">' . $vars['_lang']['admin8'] . '</td><td class="fieldarea"><input type="text" size="32" name="appid" value="' . $appId . '" /></td></tr>'; echo '<tr><td class="fieldlabel">' . $vars['_lang']['admin9'] . '</td><td class="fieldarea"><input type="text" size="32" name="appsecret" value="' . $appSecret . '" /></td></tr>'; $sql = mysql_query("SELECT * FROM `tblpromotions` where `expirationdate` = '0000-00-00' or `expirationdate` < '" . date('Y-m-d') . "' order by `code`"); if (mysql_num_rows($sql)) { echo '<tr>'; echo '<td class="fieldlabel">' . $vars['_lang']['admin4'] . '</td>'; echo '<td class="fieldarea">'; while ($promotion = mysql_fetch_assoc($sql)) { $tmp = explode('-', $promotion['code']); $hash = $id % 97; $c = count($tmp); if ($c >= 2) { $hash = $tmp[$c - 1]; $id = $tmp[$c - 2]; if ($hash == $id % 97) { continue; } } if (in_array($promotion['id'], $promotions)) { echo '<input type="checkbox" name="promotions[]" value="' . $promotion['id'] . '" checked="checked" />'; } else { echo '<input type="checkbox" name="promotions[]" value="' . $promotion['id'] . '" />'; } echo $promotion['code']; echo '<br />'; } echo '</td>'; echo '</tr>'; echo '<tr><td class="fieldlabel">' . $vars['_lang']['admin6'] . '</td>'; echo '<td class="fieldarea"><textarea cols="80" rows="10" name="description">' . $description . '</textarea></td>'; } else { echo '<tr><td class="fieldlabel">' . $vars['_lang']['admin3'] . '</td></tr>'; } echo '</table>'; echo '<p align="center"><input type="submit" name="save-settings" value="' . $vars['_lang']['admin2'] . '" /></p>'; echo '</form>'; echo '<hr /><p>' . $vars['_lang']['intro'] . '</p>'; }