<?php
function smarty_function_zakaz ($params, &$smarty)
{
extract($params);
$pre_link='/published/SC/html/scripts/index.php?did=89';
$disp='';
if($type==1){ //отображение формы во всплывающем окне
// if(isset($_SESSION['log'])==true)
// return '<h3 align="center">Ошибка! Опция доступна только зарегистрированным пользователям.</h3>';
if(!isset($_GET['pid']) || (int)$_GET['pid']<0)
return '<h3 align="center">Ошибка!</h3>';
if($_POST['uvedom']!='yes'){
$sql_t='select name_ru from SC_products where productID='.trim(htmlspecialchars($_GET['pid']));
if($r_t=mysql_query($sql_t))
$res_t=mysql_fetch_assoc($r_t);
$disp.='<div align="center" style="background-color:#FFFFFF;background-image:none; height:100%;">
<h3 style="padding:20px 20px 5px 20px; line-height:18px;">Введите ваши данные и мы сообщим, когда "'.$res_t['name_ru'].'" появится на складе!</h3>
<br />
<form method="post" action="">
<table width="220" cellpadding="8" cellspacing="8" border="0" class="cpt_product_details_request">
<tr>
<td width="40%">Ваше имя:</td>
<td style="padding-bottom:5px;"><input type="text" name="name" /></td>
</tr>
<tr>
<td width="40%">Ваш Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="" id="button_ok" style="margin-left:75px; margin-top:20px;" /></td>
</tr>
<input name="uvedom" value="yes" type="hidden" />
<input name="product" value="'.$_GET['pid'].'" type="hidden" />
</table></form>
</div>';
} else {
$user_name=trim(htmlspecialchars($_POST['name']));
$user_email=trim(htmlspecialchars($_POST['email']));
$sql='select id from uvedom where send=1 and product='.$_POST['product'].' and email="'.$user_email.'"';
if($r=mysql_query($sql))
$res=mysql_fetch_assoc($r);
if(isset($res['id']))
return $disp='<h3 align="center">Вы уже подписаны на этот товар.</h3><br /><br /><p align="center"><a href="javascript:void(0);" onclick="window.close();">Закрыть окно</a></p></div>';
$sql='SELECT `settings_value` as email FROM `SC_settings` WHERE `settings_constant_name`="CONF_ORDERS_EMAIL"';
if($r=mysql_query($sql))
$res=mysql_fetch_assoc($r);
$sql_t='select name_ru from SC_products where productID='.trim(htmlspecialchars($_POST['product']));
if($r_t=mysql_query($sql_t))
$res_t=mysql_fetch_assoc($r_t);
$heads = "Content-type: text/html; charset=utf-8"."\r\n"."From: =?utf-8?B?".base64_encode('"'.$user_name.'"')."?= <".$user_email.">\n";
$msg='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>';
$mess_=translate('mail_zakaz_admin');
$mess_=str_replace('{name}',$user_name,$mess_);
$mess_=str_replace('{email}',$user_email,$mess_);
$mess_=str_replace('{link}','<a href="http://'.$_SERVER['SERVER_NAME'].'/index.php?ukey=product&productID='.$_POST['product'].'">'.$res_t['name_ru'].'</a>',$mess_);
$mess_=str_replace('{date}',date("Y-m-d H:i:s"),$mess_);
$msg.=$mess_;
$msg.='</body>
</html>';
if( trim($user_name ) != "" && trim($user_email) != "" && !eregi("^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$", $user_email ) )
{
$send=mail($res['email'],'Уведомитель '.$res_t['name_ru'],$msg,$heads);
$sql='INSERT INTO `uvedom` ( `product` , `name`, `email`, `time` ,`send` )
VALUES ("'.$_POST['product'].'", "'.$user_name.'", "'.$user_email.'" , "'.date("Y-m-d H:i:s").'", "1")';
if(mysql_query($sql) )
$disp='<div style="padding:5px;"><h3 align="center">Спасибо!</h3><br /><h4 align="center">Как только '.$res_t['name_ru'].' появится на складе, Вы получите уведомление на email.</h4>';
else {
$disp='<h3 align="center">Произошла ошибка. Попробуйте еще раз.</h3>';
$disp.='<br /><br /><p align="center"><a href="javascript:void(0);" onclick="window.close();">Закрыть окно</a></p></div>';
}
}
else
{
$disp='<h3 align="center">Произошла ошибка. Не заполнены поля или неверный email.</h3>';
$disp.='<br /><br /><p align="center"><a href="javascript:void(0);" onclick="window.close();">Закрыть окно</a></p></div>';
}
}
} else if($type==2){ //Отображение списка подписок
if(isset($_GET['pid']) && (int)$_GET['pid']>0){
$sql2='SELECT * FROM SC_products WHERE productID="'.(int)$_GET['pid'].'" LIMIT 1';
if($res2=mysql_query($sql2))
$row2=mysql_fetch_assoc($res2);
$disp.='<h1>Продукт: <a href="/shop/product/'.$row2['productID'].'/" target="_blank">'.$row2['name_ru'].'</a></h1><br /><a href="'.$pre_link.'&act=zakaz">Назад</a>';
$disp.='<table width="100%" border="0" cellpadding="0" cellspacing="0" class="grid">';
$disp.='<tr class="gridsheader">';
$disp.='<td width="10%" align="center" valign="middle">#</td>';
$disp.='<td width="30%" align="left" valign="middle">Имя</td>';
$disp.='<td width="30%" align="left" valign="middle">Email</td>';
$disp.='<td width="30%" align="left" valign="middle">Время</td>';
$disp.='</tr>';
$sql='SELECT * FROM uvedom WHERE product="'.(int)$_GET['pid'].'" order by `time` DESC';
if($res=mysql_query($sql)){
$i=0;
while($row=mysql_fetch_assoc($res)){
$i++;
if($i%2==0)
$disp.='<tr class="gridline">';
else
$disp.='<tr class="gridline1">';
$disp.='<td width="10%" align="center" valign="middle">'.$i.'</td>';
$disp.='<td width="30%" align="left" valign="middle">'.$row['name'].'</td>';
$disp.='<td width="30%" align="left" valign="middle">'.$row['email'].'</td>';
$disp.='<td width="30%" align="left" valign="middle">'.$row['time'].'</td>';
$disp.='</tr>';
}
}
$disp.='</table>';
} else {
$disp.='<table width="100%" border="0" cellpadding="0" cellspacing="0" class="grid">';
$disp.='<tr class="gridsheader">';
$disp.='<td width="10%" align="center" valign="middle">#</td>
<td width="45%" align="center" valign="middle">Продукт</td>
<td width="45%" align="center" valign="middle">Кол-во подписавшихся</td>';
$disp.='</tr>';
$sql='SELECT *, count(`id`) as cid FROM uvedom group by product order by `cid` DESC';
if($res=mysql_query($sql)){
$i=0;
while($row=mysql_fetch_assoc($res)){
$i++;
$sql2='SELECT * FROM SC_products WHERE productID="'.$row['product'].'" LIMIT 1';
if($res2=mysql_query($sql2))
$row2=mysql_fetch_assoc($res2);
if($i%2==0)
$disp.='<tr class="gridline">';
else
$disp.='<tr class="gridline1">';
$disp.='<td width="10%" align="center" valign="middle">'.$i.'</td>
<td width="45%" align="left" valign="middle"><a href="/shop/product/'.$row2['productID'].'/" target="_blank">'.$row2['name_ru'].'</a></td>
<td width="45%" align="left" valign="middle"><a href="'.$pre_link.'&act=zakaz&pid='.$row2['productID'].'">'.$row['cid'].' — Просмотреть список</a></td>';
$disp.='</tr>';
}
}
$disp.='</table>';
}
} else if($type==3){ //Отображение кол-во подписок пользователя
if(isset($_GET['userID']) && (int)$_GET['userID']>0){
$sql='SELECT count(*) as cc FROM uvedom WHERE email in (SELECT Email FROM SC_customers WHERE customerID="'.(int)$_GET['userID'].'")';
if($res=mysql_query($sql)){
$row=mysql_fetch_assoc($res);
if($row['cc'])
echo $row['cc'];
else
echo 0;
}
}
} else{
extract($params);
if($product=='')
$product=$_GET['productID'];
$disp='<a href="javascript:void(0);" onclick="window.open(\'/shop/?zakaz=1&pid='.$product.'\',\'\',\'top=10%,left=20%,width=380,height=270,resizable=yes,scrollbars=no,status=no\');" >'.translate('zakaz').'</a>';
}
return $disp;
}
?>