File: //home/bk/__backup/ajax/wishlist.php
<?php
if(!empty($_SERVER['HTTP_USER_AGENT'])){
session_name(md5($_SERVER['HTTP_USER_AGENT']));
}
session_start();
require_once('../api/Mgc.php');
define('IS_CLIENT', true);
$mgc = new Mgc();
$limit = 500;
$id = $mgc->request->get('id', 'integer');
/*Создаем массив с товрами в списке избранного*/
if(!empty($_COOKIE['wished_products'])) {
$products_ids = explode(',', $_COOKIE['wished_products']);
$products_ids = array_reverse($products_ids);
} else {
$products_ids = array();
}
/*Действия над товаром в списке избранного*/
if($mgc->request->get('action', 'string') == 'delete') {
$key = array_search($id, $products_ids);
unset($products_ids[$key]);
} else {
array_push($products_ids, $id);
$products_ids = array_unique($products_ids);
}
$products_ids = array_slice($products_ids, 0, $limit);
$products_ids = array_reverse($products_ids);
/*Записываем список избранного в куки*/
if(!count($products_ids)) {
unset($_COOKIE['wished_products']);
setcookie('wished_products', '', time()-3600, '/');
} else {
setcookie('wished_products', implode(',', $products_ids), time()+30*24*3600, '/');
}
$mgc->design->assign('wished_products', $products_ids);
/*Определяем язык*/
$language = $mgc->languages->get_language($mgc->languages->lang_id());
$mgc->design->assign('language', $language);
$mgc->design->assign('lang_link', $mgc->languages->get_lang_link());
$mgc->design->assign('lang', $mgc->translations->get_translations(array('lang'=>$language->label)));
header("Content-type: text/html; charset=UTF-8");
header("Cache-Control: must-revalidate");
header("Pragma: no-cache");
header("Expires: -1");
$result['info'] = $mgc->design->fetch('wishlist_informer.tpl');
$result['cnt'] = count($products_ids);
print json_encode($result);