parse("subscribe", "subscribe"); } $tpl->parse("main", "main"); function subscribe(&$tpl, $addr) { global $rootweb, $from_email; $MAIL = array(); read_mail_arrays($MAIL); $tpl->set("mcountry", make_select($MAIL['country'], $_GET['country'], '')); $tpl->set("mcity_turk", make_select($MAIL['city_turk'], $_GET['city'], '')); $tpl->set("mcity_cypr", make_select($MAIL['city_cypr'], $_GET['city'], '')); $tpl->set("mocc", make_select($MAIL['occ'], $_GET['mocc'], '')); $tpl->set("mage", make_select($MAIL['age'], $_GET['mage'], '')); if ($addr == '') return; $err = ''; if (!preg_match('|^[A-Za-z0-9_.+]+@[A-Za-z0-9.-]+$|', $addr)) $err .= $tpl->translate("Please, enter a valid E-Mail")."
"; if (trim($_GET['name']) == '') $err .= $tpl->translate("Please, enter Your name")."
"; if (trim($_GET['surname']) == '') $err .= $tpl->translate("Please, enter Your surname")."
"; if (trim($_GET['city']) == '') $err .= $tpl->translate("Please, enter Your city")."
"; if (trim($_GET['country']) == '') $err .= $tpl->translate("Please, select Your country")."
"; if (trim($_GET['occ']) == '') $err .= $tpl->translate("Please, select Your occupation")."
"; if (trim($_GET['age']) == '') $err .= $tpl->translate("Please, select Your age group")."
"; if ($err != '') { $tpl->set('addr', $addr, 'name', $_GET['name'], 'surname', $_GET['surname'], 'subscribe_errors', $err); $tpl->set('city', $_GET['city'], 'country', $_GET['country']); $tpl->parse("subscribe", "subscribe"); return -2; } $tpl->set('addr', $addr); $res = @mysql_query("SELECT COUNT(*) FROM mail WHERE maddr='".mysql_escape_string($addr)."'"); list($cnt) = @mysql_fetch_row($res); @mysql_free_result($res); if ($cnt > 0) { $tpl->parse('subscribe_already', "subscribe"); return -1; } $code = mt_rand(1, 0x7fffffff); @mysql_query("INSERT INTO mail SET maddr='".strtolower(mysql_escape_string($addr))."', mcode=$code, mstate=0, mdt=NOW()". ", mname='".mysql_escape_string($_GET['name'])."', msurname='".mysql_escape_string($_GET['surname'])."'". ", mcity='".mysql_escape_string($_GET['city'])."', mcountry='".mysql_escape_string($_GET['country'])."'". ", mocc='".mysql_escape_string($_GET['occ'])."', mage='".mysql_escape_string($_GET['age'])."'" ); if (@mysql_errno() == 0) { $tpl->set('code', $code); $tpl->parse('subscribe_ok', "subscribe"); @mail($addr, "Subscription on $rootweb", $tpl->parse('subscribe_mail', ''), "From: $from_email\r\n"); } else { $tpl->parse('subscribe_err', "subscribe"); } return @mysql_insert_id(); } function confirm(&$tpl, $addr, $code) { global $rootweb, $from_email; $tpl->set('addr', $addr); $res = @mysql_query("SELECT mid, mcode, mstate FROM mail WHERE maddr='".strtolower(mysql_escape_string($addr))."'"); $row = @mysql_fetch_array($res); @mysql_free_result($res); if (!$row['mid'] || $row['mcode'] != $code) { $tpl->parse('confirm_err', "subscribe"); return -1; } if ($row['mstate'] > 0) { $tpl->parse('subscribe_already', "subscribe"); return -2; } @mysql_query("UPDATE mail SET mstate=1 WHERE mid=".$row['mid']); if (@mysql_errno() == 0) { $tpl->set('code', $code); $tpl->parse('confirm_ok', "subscribe"); @mail($addr, "Subscription on $rootweb", $tpl->parse('confirm_mail', ''), "From: $from_email\r\n"); } else { $tpl->parse('db_error', "subscribe"); } return $row['mid']; } function unsubscribe(&$tpl, $addr, $code) { global $rootweb, $from_email; $tpl->set('addr', $addr); $res = @mysql_query("SELECT mid, mcode FROM mail WHERE maddr='".strtolower(mysql_escape_string($addr))."'"); $row = @mysql_fetch_array($res); @mysql_free_result($res); if (!$row['mid'] || $row['mcode'] != $code) { $tpl->parse('unsubscribe_err', "subscribe"); return -1; } //@mysql_query("DELETE FROM mail WHERE mid=".$row['mid']); @mysql_query("UPDATE mail SET mstate=-1 WHERE mid=".$row['mid']); if (@mysql_errno() == 0) { $tpl->parse('unsubscribe_ok', "subscribe"); } else { $tpl->parse('db_error', "subscribe"); } return $row['mid']; } function subscribe_edit(&$tpl) { $step = 2; if (trim($_GET['addr']) == '' || trim($_GET['code']) == '') $step = 1; else { $res = @mysql_query("SELECT * FROM mail WHERE maddr='".strtolower(mysql_escape_string($_GET['addr']))."'"); $row = @mysql_fetch_array($res); @mysql_free_result($res); if (!$row['mid'] || $row['mcode'] != $_GET['code']) { $tpl->set('addr', $_GET['addr']); $tpl->parse('confirm_err', 'subscribe_errors'); $step = 1; } } if ($step == 1) { $tpl->set('addr', $_GET['addr'], 'code', $_GET['code']); $tpl->parse('subscribe_edit1', 'subscribe'); return; } if ($_POST['mode'] == 'edit') { @mysql_query("UPDATE mail SET mname='".mysql_escape_string($_POST['name'])."', msurname='".mysql_escape_string($_POST['surname'])."'". ", mcity='".mysql_escape_string($_POST['city'])."', mcountry='".mysql_escape_string($_POST['country'])."'". ", mocc='".mysql_escape_string($_POST['occ'])."', mage='".mysql_escape_string($_POST['age'])."'". " WHERE mid=".$row['mid']); if (@mysql_errno() == 0) { $res = @mysql_query("SELECT * FROM mail WHERE mid=".$row['mid']); $row = @mysql_fetch_array($res); @mysql_free_result($res); $tpl->set('subscribe_errors', $tpl->translate("Your data have been successfully updated")); } else { $tpl->parse('db_error', "subscribe_errors"); } } $tpl->set($row); $MAIL = array(); read_mail_arrays($MAIL); $tpl->set("mcountry", make_select($MAIL['country'], $row['mcountry'], '')); $tpl->set("mcity_turk", make_select($MAIL['city_turk'], $row['mcity'], '')); $tpl->set("mcity_cypr", make_select($MAIL['city_cypr'], $row['mcity'], '')); $tpl->set("mocc", make_select($MAIL['occ'], $row['mocc'], '')); $tpl->set("mage", make_select($MAIL['age'], $row['mage'], '')); $tpl->parse('subscribe_edit2', 'subscribe'); } ?> CYPRUS MIRROR Daily News |