Esta es la FUNCION que procesa la sucripcion:
Código PHP:
<?php
require_once(dirname(dirname(dirname(__FILE__))) . '/app.php');
need_manager();
need_auth('market');
$like = strval($_GET['like']);
$cs = strval($_GET['cs']);
/* build condition */
$condition = array();
if ($like) {
$condition[] = "email like '%".mysql_escape_string($like)."%'";
}
if ( $cs ) {
$cscity = DB::LimitQuery('category', array(
'condition' => array(
'zone' => 'city',
'name' => $cs,
),
'one' => true,
));
if ($cscity) $condition['city_id'] = $cscity['id'];
else $cs = null;
}
/* end */
$count = Table::Count('subscribe', $condition);
list($pagesize, $offset, $pagestring) = pagestring($count, 50);
$subscribes = DB::LimitQuery('subscribe', array(
'condition' => $condition,
'order' => 'ORDER BY id DESC',
'size' => $pagesize,
'offset' => $offset,
));
$city_ids = Utility::GetColumn($subscribes, 'city_id');
$cities = Table::Fetch('category', $city_ids);
include template('manage_misc_subscribe');
Código PHP:
<?php
class ZSubscribe
{
static public function Create($email, $city_id, $nombre)
{
if (!Utility::ValidEmail($email, true)) return;
$secret = md5($email . $city_id);
$table = new Table('subscribe', array(
'email' => $email,
'nombre' => $nombre,
'city_id' => $city_id,
'secret' => $secret,
));
Table::Delete('subscribe', $email, 'email', $nombre, 'nombre');
return $table->insert(array('email', 'nombre','city_id', 'secret'));
}
static public function Unsubscribe($subscribe) {
Table::Delete('subscribe', $subscribe['email'], 'email', $subscribe['nombre'], 'nombre' );
}
}