Init
This commit is contained in:
52
simpla/ajax/add_order_product.php
Normal file
52
simpla/ajax/add_order_product.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
if(!$simpla->managers->access('orders'))
|
||||
return false;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT p.id, p.name, i.filename as image FROM __products p
|
||||
LEFT JOIN __images i ON i.product_id=p.id AND i.position=(SELECT MIN(position) FROM __images WHERE product_id=p.id LIMIT 1)
|
||||
LEFT JOIN __variants pv ON pv.product_id=p.id AND (pv.stock IS NULL OR pv.stock>0) AND pv.price>0
|
||||
WHERE p.name LIKE "%'.mysql_real_escape_string($keyword).'%"
|
||||
ORDER BY p.name LIMIT ?', $limit);
|
||||
$products = array();
|
||||
foreach($simpla->db->results() as $product)
|
||||
$products[$product->id] = $product;
|
||||
|
||||
$simpla->db->query('SELECT v.id, v.name, v.price, IFNULL(v.stock, ?) as stock, (v.stock IS NULL) as infinity, v.product_id FROM __variants v WHERE v.product_id in(?@) AND (v.stock IS NULL OR v.stock>0) AND v.price>0 ORDER BY v.position', $simpla->settings->max_order_amount, array_keys($products));
|
||||
$variants = $simpla->db->results();
|
||||
|
||||
foreach($variants as $variant)
|
||||
if(isset($products[$variant->product_id]))
|
||||
$products[$variant->product_id]->variants[] = $variant;
|
||||
|
||||
|
||||
foreach($products as $product)
|
||||
{
|
||||
if(!empty($product->variants))
|
||||
{
|
||||
if(!empty($product->image))
|
||||
{
|
||||
$product->image = $simpla->design->resize_modifier($product->image, 35, 35);
|
||||
$products_names[] = $product->name;
|
||||
}
|
||||
else
|
||||
$products_names[] = $product->name;
|
||||
|
||||
$products_data[] = $product;
|
||||
}
|
||||
}
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $products_names;
|
||||
$res->data = $products_data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
186
simpla/ajax/export.php
Normal file
186
simpla/ajax/export.php
Normal file
@@ -0,0 +1,186 @@
|
||||
<?php
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
class ExportAjax extends Simpla
|
||||
{
|
||||
private $columns_names = array(
|
||||
'category'=> 'Êàòåãîðèÿ',
|
||||
'name'=> 'Òîâàð',
|
||||
'price'=> 'Öåíà',
|
||||
'url'=> 'Àäðåñ',
|
||||
'visible'=> 'Âèäèì',
|
||||
'featured'=> 'Ðåêîìåíäóåìûé',
|
||||
'brand'=> 'Áðåíä',
|
||||
'variant'=> 'Âàðèàíò',
|
||||
'compare_price'=> 'Ñòàðàÿ öåíà',
|
||||
'sku'=> 'Àðòèêóë',
|
||||
'stock'=> 'Ñêëàä',
|
||||
'meta_title'=> 'Çàãîëîâîê ñòðàíèöû',
|
||||
'meta_keywords'=> 'Êëþ÷åâûå ñëîâà',
|
||||
'meta_description'=> 'Îïèñàíèå ñòðàíèöû',
|
||||
'annotation'=> 'Àííîòàöèÿ',
|
||||
'body'=> 'Îïèñàíèå',
|
||||
'images'=> 'Èçîáðàæåíèÿ'
|
||||
);
|
||||
|
||||
private $column_delimiter = ';';
|
||||
private $subcategory_delimiter = '/';
|
||||
private $products_count = 5;
|
||||
private $export_files_dir = 'simpla/files/export/';
|
||||
private $filename = 'export.csv';
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
|
||||
if(!$this->managers->access('export'))
|
||||
return false;
|
||||
|
||||
// Ýêñåëü êóøàåò òîëüêî 1251
|
||||
setlocale(LC_ALL, 'ru_RU.1251');
|
||||
$this->db->query('SET NAMES cp1251');
|
||||
|
||||
// Ñòðàíèöà, êîòîðóþ ýêñïîðòèðóåì
|
||||
$page = $this->request->get('page');
|
||||
if(empty($page) || $page==1)
|
||||
{
|
||||
$page = 1;
|
||||
// Åñëè íà÷àëè ñíà÷àëà - óäàëèì ñòàðûé ôàéë ýêñïîðòà
|
||||
if(is_writable($this->export_files_dir.$this->filename))
|
||||
unlink($this->export_files_dir.$this->filename);
|
||||
}
|
||||
|
||||
// Îòêðûâàåì ôàéë ýêñïîðòà íà äîáàâëåíèå
|
||||
$f = fopen($this->export_files_dir.$this->filename, 'ab');
|
||||
|
||||
// Äîáàâèì â ñïèñîê êîëîíîê ñâîéñòâà òîâàðîâ
|
||||
$features = $this->features->get_features();
|
||||
foreach($features as $feature)
|
||||
$this->columns_names[$feature->name] = $feature->name;
|
||||
|
||||
// Åñëè íà÷àëè ñíà÷àëà - äîáàâèì â ïåðâóþ ñòðîêó íàçâàíèÿ êîëîíîê
|
||||
if($page == 1)
|
||||
{
|
||||
fputcsv($f, $this->columns_names, $this->column_delimiter);
|
||||
}
|
||||
|
||||
// Âñå òîâàðû
|
||||
$products = array();
|
||||
foreach($this->products->get_products(array('page'=>$page, 'limit'=>$this->products_count)) as $p)
|
||||
{
|
||||
$products[$p->id] = (array)$p;
|
||||
|
||||
// Ñâîéñòâà òîâàðîâ
|
||||
$options = $this->features->get_product_options($p->id);
|
||||
foreach($options as $option)
|
||||
{
|
||||
if(!isset($products[$option->product_id][$option->name]))
|
||||
$products[$option->product_id][$option->name] = $option->value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(empty($products))
|
||||
return false;
|
||||
|
||||
// Êàòåãîðèè òîâàðîâ
|
||||
foreach($products as $p_id=>&$product)
|
||||
{
|
||||
$categories = array();
|
||||
$cats = $this->categories->get_product_categories($p_id);
|
||||
foreach($cats as $category)
|
||||
{
|
||||
$path = array();
|
||||
$cat = $this->categories->get_category((int)$category->category_id);
|
||||
if(!empty($cat))
|
||||
{
|
||||
// Âû÷èñëÿåì ñîñòàâëÿþùèå êàòåãîðèè
|
||||
foreach($cat->path as $p)
|
||||
$path[] = str_replace($this->subcategory_delimiter, '\\'.$this->subcategory_delimiter, $p->name);
|
||||
// Äîáàâëÿåì êàòåãîðèþ ê òîâàðó
|
||||
$categories[] = implode('/', $path);
|
||||
}
|
||||
}
|
||||
$product['category'] = implode(', ', $categories);
|
||||
}
|
||||
|
||||
// Èçîáðàæåíèÿ òîâàðîâ
|
||||
$images = $this->products->get_images(array('product_id'=>array_keys($products)));
|
||||
foreach($images as $image)
|
||||
{
|
||||
// Äîáàâëÿåì èçîáðàæåíèÿ ê òîâàðó ÷åçåð çàïÿòóþ
|
||||
if(empty($products[$image->product_id]['images']))
|
||||
$products[$image->product_id]['images'] = $image->filename;
|
||||
else
|
||||
$products[$image->product_id]['images'] .= ', '.$image->filename;
|
||||
}
|
||||
|
||||
$variants = $this->variants->get_variants(array('product_id'=>array_keys($products)));
|
||||
|
||||
foreach($variants as $variant)
|
||||
{
|
||||
if(isset($products[$variant->product_id]))
|
||||
{
|
||||
$v = array();
|
||||
$v['variant'] = $variant->name;
|
||||
$v['price'] = $variant->price;
|
||||
$v['compare_price'] = $variant->compare_price;
|
||||
$v['sku'] = $variant->sku;
|
||||
$v['stock'] = $variant->stock;
|
||||
if($variant->infinity)
|
||||
$v['stock'] = '';
|
||||
$products[$variant->product_id]['variants'][] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
foreach($products as &$product)
|
||||
{
|
||||
$variants = $product['variants'];
|
||||
unset($product['variants']);
|
||||
|
||||
if(isset($variants))
|
||||
foreach($variants as $variant)
|
||||
{
|
||||
$result = array();
|
||||
$result = $product;
|
||||
foreach($variant as $name=>$value)
|
||||
$result[$name]=$value;
|
||||
|
||||
foreach($this->columns_names as $internal_name=>$column_name)
|
||||
{
|
||||
if(isset($result[$internal_name]))
|
||||
$res[$internal_name] = $result[$internal_name];
|
||||
else
|
||||
$res[$internal_name] = '';
|
||||
}
|
||||
fputcsv($f, $res, $this->column_delimiter);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$total_products = $this->products->count_products();
|
||||
|
||||
if($this->products_count*$page < $total_products)
|
||||
return array('end'=>false, 'page'=>$page, 'totalpages'=>$total_products/$this->products_count);
|
||||
else
|
||||
return array('end'=>true, 'page'=>$page, 'totalpages'=>$total_products/$this->products_count);
|
||||
|
||||
fclose($f);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$export_ajax = new ExportAjax();
|
||||
$data = $export_ajax->fetch();
|
||||
if($data)
|
||||
{
|
||||
header("Content-type: application/json; charset=utf-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
$json = json_encode($data);
|
||||
print $json;
|
||||
}
|
||||
89
simpla/ajax/export_users.php
Normal file
89
simpla/ajax/export_users.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
class ExportAjax extends Simpla
|
||||
{
|
||||
private $columns_names = array(
|
||||
'name'=> 'Èìÿ',
|
||||
'email'=> 'Email',
|
||||
'group_name'=> 'Ãðóïïà',
|
||||
'discount'=> 'Ñêèäêà',
|
||||
'enabled'=> 'Àêòèâåí',
|
||||
'created'=> 'Äàòà',
|
||||
'last_ip'=> 'Ïîñëåäíèé IP'
|
||||
);
|
||||
|
||||
private $column_delimiter = ';';
|
||||
private $users_count = 5;
|
||||
private $export_files_dir = 'simpla/files/export_users/';
|
||||
private $filename = 'users.csv';
|
||||
|
||||
public function fetch()
|
||||
{
|
||||
if(!$this->managers->access('users'))
|
||||
return false;
|
||||
|
||||
// Ýêñåëü êóøàåò òîëüêî 1251
|
||||
setlocale(LC_ALL, 'ru_RU.1251');
|
||||
$this->db->query('SET NAMES cp1251');
|
||||
|
||||
// Ñòðàíèöà, êîòîðóþ ýêñïîðòèðóåì
|
||||
$page = $this->request->get('page');
|
||||
if(empty($page) || $page==1)
|
||||
{
|
||||
$page = 1;
|
||||
// Åñëè íà÷àëè ñíà÷àëà - óäàëèì ñòàðûé ôàéë ýêñïîðòà
|
||||
if(is_writable($this->export_files_dir.$this->filename))
|
||||
unlink($this->export_files_dir.$this->filename);
|
||||
}
|
||||
|
||||
// Îòêðûâàåì ôàéë ýêñïîðòà íà äîáàâëåíèå
|
||||
$f = fopen($this->export_files_dir.$this->filename, 'ab');
|
||||
|
||||
// Åñëè íà÷àëè ñíà÷àëà - äîáàâèì â ïåðâóþ ñòðîêó íàçâàíèÿ êîëîíîê
|
||||
if($page == 1)
|
||||
{
|
||||
fputcsv($f, $this->columns_names, $this->column_delimiter);
|
||||
}
|
||||
|
||||
$filter = array();
|
||||
$filter['page'] = $page;
|
||||
$filter['limit'] = $this->users_count;
|
||||
if($this->request->get('group_id'))
|
||||
$filter['group_id'] = intval($this->request->get('group_id'));
|
||||
$filter['sort'] = $this->request->get('sort');
|
||||
$filter['keyword'] = $this->request->get('keyword');
|
||||
|
||||
// Âûáèðàåì ïîëüçîâàòåëåé
|
||||
$users = array();
|
||||
foreach($this->users->get_users($filter) as $u)
|
||||
{
|
||||
$str = array();
|
||||
foreach($this->columns_names as $n=>$c)
|
||||
$str[] = $u->$n;
|
||||
|
||||
fputcsv($f, $str, $this->column_delimiter);
|
||||
}
|
||||
|
||||
$total_users = $this->users->count_users();
|
||||
|
||||
if($this->users_count*$page < $total_users)
|
||||
return array('end'=>false, 'page'=>$page, 'totalpages'=>$total_users/$this->users_count);
|
||||
else
|
||||
return array('end'=>true, 'page'=>$page, 'totalpages'=>$total_users/$this->users_count);
|
||||
|
||||
fclose($f);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$export_ajax = new ExportAjax();
|
||||
$json = json_encode($export_ajax->fetch());
|
||||
header("Content-type: application/json; charset=utf-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print $json;
|
||||
38
simpla/ajax/file.php
Normal file
38
simpla/ajax/file.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'remove'){
|
||||
$simpla->db->query("DELETE FROM __article_photo WHERE id=" . (int)$_POST['id']);
|
||||
die;
|
||||
}
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'reorder'){
|
||||
foreach($_POST['ids'] as $pos => $id){
|
||||
$simpla->db->query("UPDATE __article_photo SET position='$pos' WHERE id='" . (int)$id ."' " );
|
||||
}
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$ext = mb_strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1), 'UTF-8');
|
||||
$name = $_POST['article_id'] . '_' . md5( uniqid( $_POST['article_id'] . rand(1, 10000), true) ) . '.' . $ext;
|
||||
|
||||
|
||||
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/files/article_photo/' . $name);
|
||||
|
||||
|
||||
|
||||
$simpla->db->query("INSERT INTO __article_photo SET article_id='" . (int)$_POST['article_id'] ."', img='$name', position=999 " );
|
||||
|
||||
echo $simpla->db->insert_id();
|
||||
|
||||
//print_r($_POST); print_r($_FILES);
|
||||
//echo 3;
|
||||
|
||||
//echo json_encode(array('id'=>44, 'img'=>'test'));
|
||||
38
simpla/ajax/file_action.php
Normal file
38
simpla/ajax/file_action.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'remove'){
|
||||
$simpla->db->query("DELETE FROM __action_photo WHERE id=" . (int)$_POST['id']);
|
||||
die;
|
||||
}
|
||||
|
||||
if(isset($_POST['action']) && $_POST['action'] == 'reorder'){
|
||||
foreach($_POST['ids'] as $pos => $id){
|
||||
$simpla->db->query("UPDATE __action_photo SET position='$pos' WHERE id='" . (int)$id ."' " );
|
||||
}
|
||||
die;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$ext = mb_strtolower(substr(strrchr($_FILES['file']['name'], '.'), 1), 'UTF-8');
|
||||
$name = $_POST['article_id'] . '_' . md5( uniqid( $_POST['article_id'] . rand(1, 10000), true) ) . '.' . $ext;
|
||||
|
||||
|
||||
|
||||
move_uploaded_file($_FILES['file']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . '/files/post/' . $name);
|
||||
|
||||
|
||||
|
||||
$simpla->db->query("INSERT INTO __action_photo SET action_id='" . (int)$_POST['article_id'] ."', img='$name', position=999 " );
|
||||
|
||||
echo $simpla->db->insert_id();
|
||||
|
||||
//print_r($_POST); print_r($_FILES);
|
||||
//echo 3;
|
||||
|
||||
//echo json_encode(array('id'=>44, 'img'=>'test'));
|
||||
46
simpla/ajax/get_images.php
Normal file
46
simpla/ajax/get_images.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
$use_curl = true; // Использовать CURL
|
||||
|
||||
$keyword = $_GET['keyword'];
|
||||
$keyword = str_replace(' ', '+', $keyword);
|
||||
|
||||
$start=0;
|
||||
if(isset($_GET['start']))
|
||||
$start = intval($_GET['start']);
|
||||
|
||||
$url = 'http://ajax.googleapis.com/ajax/services/search/images?v=1.0&q='.urlencode($keyword).'&start='.$start.'&rsz=8';
|
||||
if($use_curl && function_exists('curl_init'))
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
//curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_REFERER, 'http://google.com');
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.51");
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
||||
|
||||
// Для использования прокси используйте строки:
|
||||
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
|
||||
//curl_setopt($ch, CURLOPT_PROXY, '88.85.108.16:8080');
|
||||
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
|
||||
|
||||
$page = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = file_get_contents($url);
|
||||
}
|
||||
$data = json_decode($page);
|
||||
$images = array();
|
||||
if($data)
|
||||
foreach ($data->responseData->results as $result)
|
||||
$images[] = urldecode(str_replace('%2520', '%20', $result->url));
|
||||
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
|
||||
print(json_encode($images));
|
||||
101
simpla/ajax/get_info.php
Normal file
101
simpla/ajax/get_info.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
$use_curl = true; // Использовать CURL
|
||||
|
||||
// Ключевое слово для поиска
|
||||
$keyword = $_GET['keyword'];
|
||||
$keyword = str_replace(' ', '+', $keyword);
|
||||
|
||||
// Адрес страницы с результатами поиска
|
||||
$url = "http://market.yandex.ru/search.xml?text=$keyword&nopreciser=1";
|
||||
|
||||
// Выбираем результаты поиска
|
||||
$page = get_page($url);
|
||||
|
||||
// Находим ссылку на описание товара
|
||||
if(preg_match_all('/<h3 class="b-offers__title"><a href="(.*?)" class="b-offers__name">/ui', $page, $matches))
|
||||
$product_url = 'http://market.yandex.ru'.reset($matches[1]);
|
||||
else
|
||||
return false;
|
||||
|
||||
$page = get_page($product_url);
|
||||
|
||||
if(preg_match_all('/<ul class="b-vlist b-vlist_type_mdash b-vlist_type_friendly">(.*?)/ui', $page, $matches))
|
||||
{
|
||||
// Описание товара
|
||||
$description = '<ul>'.reset($matches[1]).'</ul>';
|
||||
$result->description = $description;
|
||||
|
||||
// Страница характеристик
|
||||
if(preg_match_all('/<p class="b-model-friendly__title"><a href="(.*?)">все характеристики<\/a><\/p>/ui', $page, $matches))
|
||||
{
|
||||
$options_url = 'http://market.yandex.ru'.reset($matches[1]);
|
||||
|
||||
$options_page = get_page($options_url);
|
||||
preg_match_all('/<th class="b-properties__label b-properties__label-title"><span>(.*?)<\/span><\/th><td class="b-properties__value">(.*?)<\/td>/ui', $options_page, $matches, PREG_SET_ORDER);
|
||||
|
||||
$options = array();
|
||||
foreach($matches as $m)
|
||||
{
|
||||
$option = null;
|
||||
$option->name = $m[1];
|
||||
$option->value = $m[2];
|
||||
$options[] = $option;
|
||||
}
|
||||
$result->options = $options;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
|
||||
print(json_encode($result));
|
||||
|
||||
|
||||
function get_page($url, $use_curl=true)
|
||||
{
|
||||
if($use_curl && function_exists('curl_init'))
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 1);
|
||||
curl_setopt($ch, CURLOPT_REFERER, 'http://google.com');
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, "Opera/9.80 (Windows NT 5.1; U; ru) Presto/2.9.168 Version/11.51");
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
// Для использования прокси используйте строки:
|
||||
//curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
|
||||
//curl_setopt($ch, CURLOPT_PROXY, '88.85.108.16:8080');
|
||||
//curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'user:password');
|
||||
|
||||
// Яндекс может нас отправить в редирект, так что нужно следовать за редиректом
|
||||
do{
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
$header = curl_exec($ch);
|
||||
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
if($code == 301 || $code == 302)
|
||||
{
|
||||
preg_match('/Location:(.*?)\n/', $header, $matches);
|
||||
$url = trim(array_pop($matches));
|
||||
}
|
||||
else
|
||||
$code = 0;
|
||||
}while($code);
|
||||
|
||||
$page = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
}
|
||||
else
|
||||
{
|
||||
$page = file_get_contents($url);
|
||||
}
|
||||
return $page;
|
||||
}
|
||||
14
simpla/ajax/get_service_brands.php
Normal file
14
simpla/ajax/get_service_brands.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$results = $simpla->services->get_brands_pages($simpla->request->get('id', 'integer'));
|
||||
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($results);
|
||||
396
simpla/ajax/import.php
Normal file
396
simpla/ajax/import.php
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
class ImportAjax extends Simpla
|
||||
{
|
||||
// Соответствие полей в базе и имён колонок в файле
|
||||
private $columns_names = array(
|
||||
'name'=> array('product', 'name', 'товар', 'название', 'наименование'),
|
||||
'url'=> array('url', 'адрес'),
|
||||
'visible'=> array('visible', 'published', 'видим'),
|
||||
'featured'=> array('featured', 'hit', 'хит', 'рекомендуемый'),
|
||||
'category'=> array('category', 'категория'),
|
||||
'brand'=> array('brand', 'бренд'),
|
||||
'variant'=> array('variant', 'вариант'),
|
||||
'price'=> array('price', 'цена'),
|
||||
'compare_price'=> array('compare price', 'старая цена'),
|
||||
'sku'=> array('sku', 'артикул'),
|
||||
'stock'=> array('stock', 'склад', 'на складе'),
|
||||
'meta_title'=> array('meta title', 'заголовок страницы'),
|
||||
'meta_keywords'=> array('meta keywords', 'ключевые слова'),
|
||||
'meta_description'=> array('meta description', 'описание страницы'),
|
||||
'annotation'=> array('annotation', 'аннотация', 'краткое описание'),
|
||||
'description'=> array('description', 'описание'),
|
||||
'images'=> array('images', 'изображения')
|
||||
);
|
||||
|
||||
// Соответствие имени колонки и поля в базе
|
||||
private $internal_columns_names = array();
|
||||
|
||||
private $import_files_dir = 'simpla/files/import/'; // Временная папка
|
||||
private $import_file = 'import.csv'; // Временный файл
|
||||
private $category_delimiter = ','; // Разделитель каегорий в файле
|
||||
private $subcategory_delimiter = '/'; // Разделитель подкаегорий в файле
|
||||
private $column_delimiter = ';';
|
||||
private $products_count = 10;
|
||||
private $columns = array();
|
||||
|
||||
public function import()
|
||||
{
|
||||
if(!$this->managers->access('import'))
|
||||
return false;
|
||||
|
||||
// Для корректной работы установим локаль UTF-8
|
||||
setlocale(LC_ALL, 'ru_RU.UTF-8');
|
||||
|
||||
// Определяем колонки из первой строки файла
|
||||
$f = fopen($this->import_files_dir.$this->import_file, 'r');
|
||||
$this->columns = fgetcsv($f, null, $this->column_delimiter);
|
||||
|
||||
// Заменяем имена колонок из файла на внутренние имена колонок
|
||||
foreach($this->columns as &$column)
|
||||
{
|
||||
if($internal_name = $this->internal_column_name($column))
|
||||
{
|
||||
$this->internal_columns_names[$column] = $internal_name;
|
||||
$column = $internal_name;
|
||||
}
|
||||
}
|
||||
|
||||
// Если нет названия товара - не будем импортировать
|
||||
if(!in_array('name', $this->columns) && !in_array('sku', $this->columns))
|
||||
return false;
|
||||
|
||||
// Переходим на заданную позицию, если импортируем не сначала
|
||||
if($from = $this->request->get('from'))
|
||||
fseek($f, $from);
|
||||
|
||||
// Массив импортированных товаров
|
||||
$imported_items = array();
|
||||
|
||||
// Проходимся по строкам, пока не конец файла
|
||||
// или пока не импортировано достаточно строк для одного запроса
|
||||
for($k=0; !feof($f) && $k<$this->products_count; $k++)
|
||||
{
|
||||
// Читаем строку
|
||||
$line = fgetcsv($f, 0, $this->column_delimiter);
|
||||
|
||||
$product = null;
|
||||
|
||||
if(is_array($line))
|
||||
// Проходимся по колонкам строки
|
||||
foreach($this->columns as $i=>$col)
|
||||
{
|
||||
// Создаем массив item[название_колонки]=значение
|
||||
if(isset($line[$i]) && !empty($line) && !empty($col))
|
||||
$product[$col] = $line[$i];
|
||||
}
|
||||
|
||||
// Импортируем этот товар
|
||||
if($imported_item = $this->import_item($product))
|
||||
$imported_items[] = $imported_item;
|
||||
}
|
||||
|
||||
/*
|
||||
if(count($variants_ids)>0)
|
||||
{
|
||||
// Для отчета выбираем импортированные товары
|
||||
$variants = (array)$this->variants->get_variants(array('id'=>$variants_ids));
|
||||
$products_ids = array();
|
||||
|
||||
foreach($variants as $v)
|
||||
$products_ids[] = $v->product_id;
|
||||
|
||||
$products = array();
|
||||
foreach($this->products->get_products(array('id'=>$products_ids)) as $p)
|
||||
$products[$p->id] = $p;
|
||||
|
||||
|
||||
foreach($variants as $v)
|
||||
{
|
||||
$imported_items[$v->id]->variant_id = $v->id;
|
||||
$imported_items[$v->id]->product_id = $v->product_id;
|
||||
$imported_items[$v->id]->variant_name = $v->name;
|
||||
$imported_items[$v->id]->product_name = $products[$v->product_id]->name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$imported_items = null;
|
||||
}
|
||||
*/
|
||||
|
||||
// Запоминаем на каком месте закончили импорт
|
||||
$from = ftell($f);
|
||||
|
||||
// И закончили ли полностью весь файл
|
||||
$result->end = feof($f);
|
||||
|
||||
fclose($f);
|
||||
$size = filesize($this->import_files_dir.$this->import_file);
|
||||
|
||||
// Создаем объект результата
|
||||
$result->from = $from; // На каком месте остановились
|
||||
$result->totalsize = $size; // Размер всего файла
|
||||
$result->items = $imported_items; // Импортированные товары
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
// Импорт одного товара $item[column_name] = value;
|
||||
private function import_item($item)
|
||||
{
|
||||
// Проверим не пустое ли название и артинкул (должно быть хоть что-то из них)
|
||||
if(empty($item['name']) && empty($item['sku']))
|
||||
return false;
|
||||
|
||||
// Подготовим товар для добавления в базу
|
||||
if(isset($item['name']))
|
||||
$product['name'] = trim($item['name']);
|
||||
|
||||
if(isset($item['meta_title']))
|
||||
$product['meta_title'] = trim($item['meta_title']);
|
||||
|
||||
if(isset($item['meta_keywords']))
|
||||
$product['meta_keywords'] = trim($item['meta_keywords']);
|
||||
|
||||
if(isset($item['meta_description']))
|
||||
$product['meta_description'] = trim($item['meta_description']);
|
||||
|
||||
if(isset($item['annotation']))
|
||||
$product['annotation'] = trim($item['annotation']);
|
||||
|
||||
if(isset($item['description']))
|
||||
$product['body'] = trim($item['description']);
|
||||
|
||||
if(isset($item['visible']))
|
||||
$product['visible'] = intval($item['visible']);
|
||||
|
||||
if(isset($item['featured']))
|
||||
$product['featured'] = intval($item['featured']);
|
||||
|
||||
if(isset($item['url']))
|
||||
$product['url'] = trim($item['url']);
|
||||
elseif(isset($item['name']))
|
||||
$product['url'] = $this->translit($item['name']);
|
||||
|
||||
// Если задан бренд
|
||||
if(!empty($item['brand']))
|
||||
{
|
||||
$item['brand'] = trim($item['brand']);
|
||||
// Найдем его по имени
|
||||
$this->db->query('SELECT id FROM __brands WHERE name=?', $item['brand']);
|
||||
if(!$product['brand_id'] = $this->db->result('id'))
|
||||
// Создадим, если не найден
|
||||
$product['brand_id'] = $this->brands->add_brand(array('name'=>$item['brand'], 'meta_title'=>$item['brand'], 'meta_keywords'=>$item['brand'], 'meta_description'=>$item['brand']));
|
||||
}
|
||||
|
||||
// Если задана категория
|
||||
$category_id = null;
|
||||
$categories_ids = array();
|
||||
if(isset($item['category']))
|
||||
{
|
||||
foreach(explode($this->category_delimiter, $item['category']) as $c)
|
||||
$categories_ids[] = $this->import_category($c);
|
||||
$category_id = reset($categories_ids);
|
||||
}
|
||||
|
||||
// Подготовим вариант товара
|
||||
if(isset($item['variant']))
|
||||
$variant['name'] = trim($item['variant']);
|
||||
|
||||
if(isset($item['price']))
|
||||
$variant['price'] = str_replace(',', '.', trim($item['price']));
|
||||
|
||||
if(isset($item['compare_price']))
|
||||
$variant['compare_price'] = trim($item['compare_price']);
|
||||
|
||||
if(isset($item['stock']))
|
||||
if($item['stock'] == '')
|
||||
$variant['stock'] = null;
|
||||
else
|
||||
$variant['stock'] = trim($item['stock']);
|
||||
|
||||
if(isset($item['sku']))
|
||||
$variant['sku'] = trim($item['sku']);
|
||||
|
||||
// Если задан артикул варианта, найдем этот вариант и соответствующий товар
|
||||
if(!empty($variant['sku']))
|
||||
{
|
||||
$this->db->query('SELECT id as variant_id, product_id FROM __variants WHERE sku=? LIMIT 1', $variant['sku']);
|
||||
$result = $this->db->result();
|
||||
if($result)
|
||||
{
|
||||
// и обновим товар
|
||||
if(!empty($product))
|
||||
$this->products->update_product($result->product_id, $product);
|
||||
// и вариант
|
||||
if(!empty($variant))
|
||||
$this->variants->update_variant($result->variant_id, $variant);
|
||||
|
||||
$product_id = $result->product_id;
|
||||
$variant_id = $result->variant_id;
|
||||
// Обновлен
|
||||
$imported_item->status = 'updated';
|
||||
}
|
||||
}
|
||||
|
||||
// Если на прошлом шаге товар не нашелся, и задано хотя бы название товара
|
||||
if((empty($product_id) || empty($variant_id)) && isset($item['name']))
|
||||
{
|
||||
if(!empty($variant['sku']) && empty($variant['name']))
|
||||
$this->db->query('SELECT v.id as variant_id, p.id as product_id FROM __products p LEFT JOIN __variants v ON v.product_id=p.id WHERE v.sku=? LIMIT 1', $variant['sku']);
|
||||
elseif(isset($item['variant']))
|
||||
$this->db->query('SELECT v.id as variant_id, p.id as product_id FROM __products p LEFT JOIN __variants v ON v.product_id=p.id AND v.name=? WHERE p.name=? LIMIT 1', $item['variant'], $item['name']);
|
||||
else
|
||||
$this->db->query('SELECT v.id as variant_id, p.id as product_id FROM __products p LEFT JOIN __variants v ON v.product_id=p.id WHERE p.name=? LIMIT 1', $item['name']);
|
||||
|
||||
$r = $this->db->result();
|
||||
if($r)
|
||||
{
|
||||
$product_id = $r->product_id;
|
||||
$variant_id = $r->variant_id;
|
||||
}
|
||||
// Если товар найден - обноаляем,
|
||||
if(!empty($variant_id))
|
||||
{
|
||||
$this->variants->update_variant($variant_id, $variant);
|
||||
$this->products->update_product($product_id, $product);
|
||||
$imported_item->status = 'updated';
|
||||
}
|
||||
// Иначе - добавляем
|
||||
elseif(empty($variant_id))
|
||||
{
|
||||
if(empty($product_id))
|
||||
$product_id = $this->products->add_product($product);
|
||||
$variant['product_id'] = $product_id;
|
||||
$variant_id = $this->variants->add_variant($variant);
|
||||
$imported_item->status = 'added';
|
||||
}
|
||||
}
|
||||
|
||||
// Нужно вернуть обновленный товар
|
||||
$imported_item->variant = $this->variants->get_variant(intval($variant_id));
|
||||
$imported_item->product = $this->products->get_product(intval($product_id));
|
||||
|
||||
// Добавляем категории к товару
|
||||
if(!empty($categories_ids))
|
||||
foreach($categories_ids as $c_id)
|
||||
$this->categories->add_product_category($product_id, $c_id);
|
||||
|
||||
// Изображения товаров
|
||||
if(isset($item['images']))
|
||||
{
|
||||
// Изображений может быть несколько, через запятую
|
||||
$images = explode(',', $item['images']);
|
||||
foreach($images as $image)
|
||||
{
|
||||
$image = trim($image);
|
||||
if(!empty($image))
|
||||
{
|
||||
// Имя файла
|
||||
$image_filename = pathinfo($image, PATHINFO_BASENAME);
|
||||
|
||||
// Добавляем изображение только если такого еще нет в этом товаре
|
||||
$this->db->query('SELECT filename FROM __images WHERE product_id=? AND (filename=? OR filename=?) LIMIT 1', $product_id, $image_filename, $image);
|
||||
if(!$this->db->result('filename'))
|
||||
{
|
||||
$this->products->add_image($product_id, $image);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Характеристики товаров
|
||||
foreach($item as $feature_name=>$feature_value)
|
||||
{
|
||||
// Если нет такого названия колонки, значит это название свойства
|
||||
if(!in_array($feature_name, $this->internal_columns_names))
|
||||
{
|
||||
// Свойство добавляем только если для товара указана категория
|
||||
if($category_id)
|
||||
{
|
||||
$this->db->query('SELECT f.id FROM __features f WHERE f.name=? LIMIT 1', $feature_name);
|
||||
if(!$feature_id = $this->db->result('id'))
|
||||
$feature_id = $this->features->add_feature(array('name'=>$feature_name));
|
||||
|
||||
$this->features->add_feature_category($feature_id, $category_id);
|
||||
$this->features->update_option($product_id, $feature_id, $feature_value);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return $imported_item;
|
||||
}
|
||||
|
||||
|
||||
// Отдельная функция для импорта категории
|
||||
private function import_category($category)
|
||||
{
|
||||
// Поле "категория" может состоять из нескольких имен, разделенных subcategory_delimiter-ом
|
||||
// Только неэкранированный subcategory_delimiter может разделять категории
|
||||
$delimiter = $this->subcategory_delimiter;
|
||||
$regex = "/\\DELIMITER((?:[^\\\\\DELIMITER]|\\\\.)*)/";
|
||||
$regex = str_replace('DELIMITER', $delimiter, $regex);
|
||||
$names = preg_split($regex, $category, 0, PREG_SPLIT_DELIM_CAPTURE);
|
||||
$id = null;
|
||||
$parent = 0;
|
||||
|
||||
// Для каждой категории
|
||||
foreach($names as $name)
|
||||
{
|
||||
// Заменяем \/ на /
|
||||
$name = trim(str_replace("\\$delimiter", $delimiter, $name));
|
||||
if(!empty($name))
|
||||
{
|
||||
// Найдем категорию по имени
|
||||
$this->db->query('SELECT id FROM __categories WHERE name=? AND parent_id=?', $name, $parent);
|
||||
$id = $this->db->result('id');
|
||||
|
||||
// Если не найдена - добавим ее
|
||||
if(empty($id))
|
||||
$id = $this->categories->add_category(array('name'=>$name, 'parent_id'=>$parent, 'meta_title'=>$name, 'meta_keywords'=>$name, 'meta_description'=>$name, 'url'=>$this->translit($name)));
|
||||
|
||||
$parent = $id;
|
||||
}
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
private function translit($text)
|
||||
{
|
||||
$ru = explode('-', "А-а-Б-б-В-в-Ґ-ґ-Г-г-Д-д-Е-е-Ё-ё-Є-є-Ж-ж-З-з-И-и-І-і-Ї-ї-Й-й-К-к-Л-л-М-м-Н-н-О-о-П-п-Р-р-С-с-Т-т-У-у-Ф-ф-Х-х-Ц-ц-Ч-ч-Ш-ш-Щ-щ-Ъ-ъ-Ы-ы-Ь-ь-Э-э-Ю-ю-Я-я");
|
||||
$en = explode('-', "A-a-B-b-V-v-G-g-G-g-D-d-E-e-E-e-E-e-ZH-zh-Z-z-I-i-I-i-I-i-J-j-K-k-L-l-M-m-N-n-O-o-P-p-R-r-S-s-T-t-U-u-F-f-H-h-TS-ts-CH-ch-SH-sh-SCH-sch---Y-y---E-e-YU-yu-YA-ya");
|
||||
|
||||
$res = str_replace($ru, $en, $text);
|
||||
$res = preg_replace("/[\s]+/ui", '-', $res);
|
||||
$res = preg_replace('/[^\p{L}\p{Nd}\d-]/ui', '', $res);
|
||||
$res = strtolower($res);
|
||||
return $res;
|
||||
}
|
||||
|
||||
// Фозвращает внутреннее название колонки по названию колонки в файле
|
||||
private function internal_column_name($name)
|
||||
{
|
||||
$name = trim($name);
|
||||
$name = str_replace('/', '', $name);
|
||||
$name = str_replace('\/', '', $name);
|
||||
foreach($this->columns_names as $i=>$names)
|
||||
{
|
||||
foreach($names as $n)
|
||||
if(!empty($name) && preg_match("/^".preg_quote($name)."$/ui", $n))
|
||||
return $i;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$import_ajax = new ImportAjax();
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
|
||||
$json = json_encode($import_ajax->import());
|
||||
print $json;
|
||||
24
simpla/ajax/options_autocomplete.php
Normal file
24
simpla/ajax/options_autocomplete.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
$feature_id = $simpla->request->get('feature_id', 'string');
|
||||
|
||||
$query = $simpla->db->placehold('SELECT DISTINCT po.value FROM __options po
|
||||
WHERE value LIKE "'.mysql_real_escape_string($keyword).'%" AND feature_id=? ORDER BY po.value LIMIT ?', $feature_id, $limit);
|
||||
|
||||
$simpla->db->query($query);
|
||||
|
||||
$options = $simpla->db->results('value');
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $options;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
36
simpla/ajax/save_style.php
Normal file
36
simpla/ajax/save_style.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
$simpla = new Simpla();
|
||||
|
||||
if(!$simpla->managers->access('design'))
|
||||
return false;
|
||||
|
||||
// Проверка сессии для защиты от xss
|
||||
if(!$simpla->request->check_session())
|
||||
{
|
||||
trigger_error('Session expired', E_USER_WARNING);
|
||||
exit();
|
||||
}
|
||||
$content = $simpla->request->post('content');
|
||||
$style = $simpla->request->post('style');
|
||||
$theme = $simpla->request->post('theme', 'string');
|
||||
|
||||
if(pathinfo($style, PATHINFO_EXTENSION) != 'css')
|
||||
exit();
|
||||
|
||||
$file = $simpla->config->root_dir.'design/'.$theme.'/css/'.$style;
|
||||
if(is_file($file) && is_writable($file) && !is_file($simpla->config->root_dir.'design/'.$theme.'/locked'))
|
||||
file_put_contents($file, $content);
|
||||
|
||||
$result= true;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
$json = json_encode($result);
|
||||
print $json;
|
||||
36
simpla/ajax/save_template.php
Normal file
36
simpla/ajax/save_template.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
$simpla = new Simpla();
|
||||
|
||||
if(!$simpla->managers->access('design'))
|
||||
return false;
|
||||
|
||||
// Проверка сессии для защиты от xss
|
||||
if(!$simpla->request->check_session())
|
||||
{
|
||||
trigger_error('Session expired', E_USER_WARNING);
|
||||
exit();
|
||||
}
|
||||
$content = $simpla->request->post('content');
|
||||
$template = $simpla->request->post('template');
|
||||
$theme = $simpla->request->post('theme', 'string');
|
||||
|
||||
if(pathinfo($template, PATHINFO_EXTENSION) != 'tpl')
|
||||
exit();
|
||||
|
||||
$file = $simpla->config->root_dir.'design/'.$theme.'/html/'.$template;
|
||||
if(is_file($file) && is_writable($file) && !is_file($simpla->config->root_dir.'design/'.$theme.'/locked'))
|
||||
file_put_contents($file, $content);
|
||||
|
||||
$result= true;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
$json = json_encode($result);
|
||||
print $json;
|
||||
27
simpla/ajax/search_articles.php
Normal file
27
simpla/ajax/search_articles.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT id, name FROM __articles
|
||||
WHERE name LIKE "%'.mysql_real_escape_string($keyword).'%" ORDER BY name LIMIT ?', $limit);
|
||||
$products = $simpla->db->results();
|
||||
|
||||
foreach($products as $product)
|
||||
{
|
||||
$products_names[] = $product->name;
|
||||
|
||||
$products_data[] = $product;
|
||||
}
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $products_names;
|
||||
$res->data = $products_data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
27
simpla/ajax/search_markas.php
Normal file
27
simpla/ajax/search_markas.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT id, name FROM __marka
|
||||
WHERE name LIKE "%'.mysql_real_escape_string($keyword).'%" ORDER BY name LIMIT ?', $limit);
|
||||
$products = $simpla->db->results();
|
||||
|
||||
foreach($products as $product)
|
||||
{
|
||||
$products_names[] = $product->name;
|
||||
|
||||
$products_data[] = $product;
|
||||
}
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $products_names;
|
||||
$res->data = $products_data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
41
simpla/ajax/search_models.php
Normal file
41
simpla/ajax/search_models.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT id, name, marka_id FROM __model
|
||||
WHERE name LIKE "%'.mysql_real_escape_string($keyword).'%" ORDER BY name LIMIT ?', $limit);
|
||||
$products = $simpla->db->results();
|
||||
|
||||
foreach($products as $product)
|
||||
{
|
||||
$marka = $simpla->model->getMarka($product->marka_id);
|
||||
$product->name = $marka ? $marka->name . ' - ' . $product->name : $product->name;
|
||||
//$products_names[] = $product->name;
|
||||
|
||||
$products_data[] = $product;
|
||||
}
|
||||
|
||||
usort($products_data, 'sortNamesUsort');
|
||||
|
||||
$products_names = array();
|
||||
foreach($products_data as $row) $products_names[] = $row->name;
|
||||
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $products_names;
|
||||
$res->data = $products_data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
echo json_encode($res);
|
||||
|
||||
|
||||
function sortNamesUsort($a, $b){
|
||||
if($a->name < $b->name) return -1;
|
||||
return $a->name > $b->name ? 1 : 0;
|
||||
}
|
||||
18
simpla/ajax/search_orders.php
Normal file
18
simpla/ajax/search_orders.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('keyword', 'string');
|
||||
if($simpla->request->get('limit', 'integer'))
|
||||
$limit = $simpla->request->get('limit', 'integer');
|
||||
|
||||
$orders = array_values($simpla->orders->get_orders(array('keyword'=>$keyword, 'limit'=>$limit)));
|
||||
|
||||
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($orders);
|
||||
27
simpla/ajax/search_pages.php
Normal file
27
simpla/ajax/search_pages.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT id, name FROM __pages
|
||||
WHERE name LIKE "%'.mysql_real_escape_string($keyword).'%" AND menu_id=3 ORDER BY name LIMIT ?', $limit);
|
||||
$products = $simpla->db->results();
|
||||
|
||||
foreach($products as $product)
|
||||
{
|
||||
$products_names[] = $product->name;
|
||||
|
||||
$products_data[] = $product;
|
||||
}
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $products_names;
|
||||
$res->data = $products_data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
35
simpla/ajax/search_products.php
Normal file
35
simpla/ajax/search_products.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT p.id, p.name,p.visible, i.filename as image FROM __products p
|
||||
LEFT JOIN __images i ON i.product_id=p.id AND i.position=(SELECT MIN(position) FROM __images WHERE product_id=p.id LIMIT 1)
|
||||
WHERE p.name LIKE "%'.mysql_real_escape_string($keyword).'%" ORDER BY p.name LIMIT ?', $limit);
|
||||
$products = $simpla->db->results();
|
||||
|
||||
foreach($products as $product)
|
||||
{
|
||||
if($product->visible == 0) continue;
|
||||
if(!empty($product->image))
|
||||
{
|
||||
$product->image = $simpla->design->resize_modifier($product->image, 35, 35);
|
||||
$products_names[] = $product->name;
|
||||
}
|
||||
else
|
||||
$products_names[] = $product->name;
|
||||
|
||||
$products_data[] = $product;
|
||||
}
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $products_names;
|
||||
$res->data = $products_data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
63
simpla/ajax/search_services.php
Normal file
63
simpla/ajax/search_services.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
function showRes($res)
|
||||
{
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
|
||||
//function buildFlatServiceTree($serviceId, $main = true)
|
||||
//{
|
||||
// global $simpla;
|
||||
// $simpla->db->query("SELECT * FROM __pages WHERE parent = ? ORDER BY name", $serviceId);
|
||||
// $services = $simpla->db->results();
|
||||
// $res = [];
|
||||
// foreach ($services as $service) {
|
||||
//// $res = array_merge($res, buildFlatServiceTree($service->id));
|
||||
// if ($main && $service->show_service != 1) continue;
|
||||
// $res[] = [
|
||||
// 'id' => $service->id,
|
||||
// 'name' => $service->name,
|
||||
// ];
|
||||
// }
|
||||
// return $res;
|
||||
//}
|
||||
|
||||
$simpla->db->query("SELECT * FROM __pages WHERE show_service = 1 ORDER BY name");
|
||||
$services = $simpla->db->results();
|
||||
|
||||
|
||||
//$services = buildFlatServiceTree(28);
|
||||
|
||||
if ($keyword) {
|
||||
$services = array_filter($services, function ($service) use ($keyword) {
|
||||
return strpos(mb_strtolower($service->name), mb_strtolower($keyword)) !== false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
foreach ($services as $service) {
|
||||
$service_name[] = $service->name;
|
||||
|
||||
$services_data[] = $service;
|
||||
}
|
||||
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $service_name;
|
||||
$res->data = $services_data;
|
||||
|
||||
showRes($res);
|
||||
25
simpla/ajax/search_users.php
Normal file
25
simpla/ajax/search_users.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$limit = 100;
|
||||
|
||||
$keyword = $simpla->request->get('query', 'string');
|
||||
|
||||
$simpla->db->query('SELECT u.id, u.name, u.email FROM __users u WHERE u.name LIKE "%'.mysql_real_escape_string($keyword).'%" OR u.email LIKE "%'.mysql_real_escape_string($keyword).'%"ORDER BY u.name LIMIT ?', $limit);
|
||||
$users = $simpla->db->results();
|
||||
|
||||
foreach($users as $user)
|
||||
{
|
||||
$names[] = $user->name." ($user->email)";
|
||||
$data[] = $user;
|
||||
}
|
||||
|
||||
$res->query = $keyword;
|
||||
$res->suggestions = $names;
|
||||
$res->data = $data;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
34
simpla/ajax/stat/stat.php
Normal file
34
simpla/ajax/stat/stat.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
chdir('../../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
class StatAjax extends Simpla
|
||||
{
|
||||
public function fetch()
|
||||
{
|
||||
$query = $this->db->placehold('SELECT SUM( o.total_price ) AS total_price, DAY(date) AS day, MONTH(date) as month, YEAR(date) as year FROM __orders o WHERE o.closed AND date > DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY DATE( o.date ) DESC LIMIT 30');
|
||||
$this->db->query($query);
|
||||
$data = $this->db->results();
|
||||
|
||||
$results = array();
|
||||
foreach($data as $d)
|
||||
{
|
||||
$result['day'] = $d->day;
|
||||
$result['month'] = $d->month;
|
||||
$result['year'] = $d->year;
|
||||
$result['y'] = $d->total_price;
|
||||
$results[] = $result;
|
||||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$stat_ajax = new StatAjax();
|
||||
header("Content-type: application/json; charset=utf-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
$json = json_encode($stat_ajax->fetch());
|
||||
print $json;
|
||||
120
simpla/ajax/update_object.php
Normal file
120
simpla/ajax/update_object.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
|
||||
$simpla = new Simpla();
|
||||
|
||||
// Проверка сессии для защиты от xss
|
||||
if(!$simpla->request->check_session())
|
||||
{
|
||||
trigger_error('Session expired', E_USER_WARNING);
|
||||
exit();
|
||||
}
|
||||
|
||||
$id = intval($simpla->request->post('id'));
|
||||
$object = $simpla->request->post('object');
|
||||
$values = $simpla->request->post('values');
|
||||
|
||||
switch ($object)
|
||||
{
|
||||
case 'product':
|
||||
if($simpla->managers->access('products'))
|
||||
$result = $simpla->products->update_product($id, $values);
|
||||
break;
|
||||
case 'category':
|
||||
if($simpla->managers->access('categories'))
|
||||
$result = $simpla->categories->update_category($id, $values);
|
||||
break;
|
||||
case 'categoryview':
|
||||
if($simpla->managers->access('categories'))
|
||||
$result = $simpla->categories->update_category($id, $values);
|
||||
break;
|
||||
|
||||
case 'article_category':
|
||||
|
||||
//if($simpla->managers->access('articles_category'))
|
||||
$result = $simpla->articles->update_category($id, $values);
|
||||
|
||||
break;
|
||||
|
||||
case 'banner':
|
||||
$result = $simpla->banners->update_banner($id, $values);
|
||||
break;
|
||||
|
||||
case 'brands':
|
||||
$result = $simpla->brands->update_brand($id, $values);
|
||||
break;
|
||||
|
||||
case 'marka':
|
||||
$result = $simpla->marka->update_brand($id, $values);
|
||||
break;
|
||||
|
||||
case 'model':
|
||||
$result = $simpla->model->update_model($id, $values);
|
||||
break;
|
||||
case 'feature':
|
||||
if($simpla->managers->access('features'))
|
||||
$result = $simpla->features->update_feature($id, $values);
|
||||
break;
|
||||
case 'page':
|
||||
if($simpla->managers->access('pages')) {
|
||||
$action = $simpla->request->post('action','string');
|
||||
if('move' === $action) {
|
||||
$result = $simpla->services->move($id, $values);
|
||||
} elseif('enable' === $action){
|
||||
$simpla->services->set_visible($id, $values['visible']);
|
||||
} else
|
||||
$result = $simpla->pages->update_page($id, $values);
|
||||
}
|
||||
break;
|
||||
case 'blog':
|
||||
if($simpla->managers->access('blog'))
|
||||
$result = $simpla->blog->update_post($id, $values);
|
||||
break;
|
||||
case 'actions':
|
||||
if($simpla->managers->access('actions'))
|
||||
$result = $simpla->actions->update_post($id, $values);
|
||||
break;
|
||||
|
||||
case 'articles':
|
||||
|
||||
if($simpla->managers->access('articles'))
|
||||
|
||||
$result = $simpla->articles->update_article($id, $values);
|
||||
|
||||
break;
|
||||
case 'delivery':
|
||||
if($simpla->managers->access('delivery'))
|
||||
$result = $simpla->delivery->update_delivery($id, $values);
|
||||
break;
|
||||
case 'payment':
|
||||
if($simpla->managers->access('payment'))
|
||||
$result = $simpla->payment->update_payment_method($id, $values);
|
||||
break;
|
||||
case 'currency':
|
||||
if($simpla->managers->access('currency'))
|
||||
$result = $simpla->money->update_currency($id, $values);
|
||||
break;
|
||||
case 'comment':
|
||||
if($simpla->managers->access('comments'))
|
||||
$result = $simpla->comments->update_comment($id, $values);
|
||||
break;
|
||||
case 'user':
|
||||
if($simpla->managers->access('users'))
|
||||
$result = $simpla->users->update_user($id, $values);
|
||||
break;
|
||||
case 'label':
|
||||
if($simpla->managers->access('labels'))
|
||||
$result = $simpla->orders->update_label($id, $values);
|
||||
break;
|
||||
}
|
||||
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
$json = json_encode($result);
|
||||
print $json;
|
||||
37
simpla/ajax/ym.php
Normal file
37
simpla/ajax/ym.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
chdir('../..');
|
||||
require_once('api/Simpla.php');
|
||||
$simpla = new Simpla();
|
||||
$object = $simpla->request->get('type');
|
||||
$yms = $simpla->request->post('ym');
|
||||
//print_r($yms);
|
||||
$res = array();
|
||||
switch ($object)
|
||||
{
|
||||
case 'prod':
|
||||
foreach($yms AS $id=>$val)
|
||||
$result = $simpla->products->update_product($id, array('ym'=>$val));
|
||||
|
||||
|
||||
break;
|
||||
case 'cat':
|
||||
foreach($yms AS $id=>$val){
|
||||
$result = $simpla->categories->update_category($id, array('ym'=>$val));
|
||||
$results = $simpla->products->get_products(array('category_id'=>$id));
|
||||
foreach($results AS $p)
|
||||
$result = $simpla->products->update_product($p->id, array('ym'=>$val));
|
||||
/*$ids[] = $p->id;
|
||||
|
||||
if($val==0)
|
||||
print_r($ids);*/
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
//print_r($yms);
|
||||
//$res = $yms;
|
||||
header("Content-type: application/json; charset=UTF-8");
|
||||
header("Cache-Control: must-revalidate");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: -1");
|
||||
print json_encode($res);
|
||||
Reference in New Issue
Block a user