db = &$db;
$this->tpl = &$tpl;
$this->error = &$error;
$this->cache = &$cache;
}
function trim (&$data)
{
foreach ($data as $key => $value)
{
if (is_array ($value))
$this->trim ($value);
else
$data[$key] = stripslashes (trim ($value));
}
}
function valid ($data, $upload = null)
{
if (isset ($data['name']))
{
if (! preg_match ("/.{1,100}/i", $data['name']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Íàçâàíèÿ.";
}
if (isset ($data['about_min']))
{
if (! preg_match ("/.+/is", $data['about_min']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Êðàòêîå îïèñàíèå.";
}
/*
* if(isset($data['text'])){
* if( !preg_match("/.+/is",$data['text']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Ïîëíîå îïèñàíèå.";
* }
*/
/*
* if(isset($data['cine'])){
* if( !preg_match("/[0-9]+/",$data['cine']) ) $this->error[] = "Îøèáêà ââîäà ïîëÿ Öåíà, òîëüêî öèôðû.";
* }
*/
if (isset ($upload['pic']['name']) && $upload['pic']['tmp_name'])
{
$type = substr (strrchr ($upload['pic']['name'], "."), 1);
if (! preg_match ("/^(jpeg|jpg|gif|png|bmp)$/i", $type))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Èçîáðàæåíèÿ, òîëüêî jpg,png,gif.";
}
if (isset ($upload['file']['name']))
{
if (! preg_match ("/\.csv$/i", $upload['file']['name']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ CSV ôàéë, òîëüêî csv.";
}
if (isset ($data['order_name']))
{
if (! preg_match ("/.{1,100}/i", $data['order_name']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
}
if (isset ($data['order_adress']))
{
if (! preg_match ("/.{1,200}/i", $data['order_adress']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Àäðåñ (Ìàêñèìóì 200 ñèìâîëîâ).";
}
if (isset ($data['order_phone2']) && strlen ($data['order_phone2']) > 0)
{
if (! preg_match ("/.{1,20}/i", $data['order_phone2']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Òåëåôîí (Ìàêñèìóì 70 ñèìâîëîâ).";
}
if (isset ($data['order_phone']))
{
if (trim ($data['order_phone']) == "")
$this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX).";
if (strlen (trim ($data['order_phone'])) < 5)
$this->error[] = "Îøèáêà ââîäà ïîëÿ Ìîáèëüíûé òåëåôîí (ôîðìàò: (0XX) XXX-XXXX).";
}
if (isset ($data['delivery']) && $data['delivery'] == 0)
{
$this->error[] = "Îøèáêà ââîäà ïîëÿ Äîñòàâêà.";
}
if (isset ($data['user_name']))
{
if (! preg_match ("/.{1,100}/i", $data['user_name']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Èìÿ (Ìàêñèìóì 100 ñèìâîëîâ).";
}
if (isset ($data['order_city']))
{
if (! preg_match ("/.{1,100}/i", $data['order_city']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Ãîðîä (Ìàêñèìóì 100 ñèìâîëîâ).";
}
if (isset ($data['user_email']))
{
if (! preg_match ("/.{1,80}/i", $data['user_email']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø e-mail (Ìàêñèìóì 80 ñèìâîëîâ).";
}
if (isset ($data['user_login']))
{
if (! preg_match ("/.{1,100}/i", $data['user_login']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ëîãèí (Ìàêñèìóì 100 ñèìâîëîâ).";
elseif ($this->isLoginUser ($data['user_login']))
$this->error[] = "Îøèáêà òàêîé Ëîãèí óæå åñòü!";
}
if (isset ($data['you_login']))
{
if (! $this->isLoginUser ($data['you_login']))
$this->error[] = "Òàêîãî ËÎÃÈÍÀ íåò â áàçå äàííûõ ñàéòà!";
}
if (isset ($data['user_psw']))
{
if (! preg_match ("/.{1,100}/i", $data['user_psw']))
$this->error[] = "Îøèáêà ââîäà ïîëÿ Âàø ïàðîëü (Ìàêñèìóì 100 ñèìâîëîâ).";
}
return (count ($this->error)) ? true : false;
}
function deleteRubric ($id, $field = "id")
{
$sql = "select pic,id,parent_id from catalogs_rubrics where $field=?";
$res = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
foreach ($res as $row)
{
@unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/rubrics/{$row['pic']}");
$sql = "delete from catalogs_rubrics where id=?";
$this->db->query ($sql, array (
$row['id']
));
$this->deleteFiltersRubric_id ($row['id']);
$this->deleteFiltersRubric_id2 ($row['id']);
$this->deleteYearsRubric_id ($row['id']);
$this->deleteProductsRubric ($row['id']);
$this->deleteRubric ($row['id'], "parent_id");
}
}
function deleteProductPics ($id, $pics = array('pic_big','pic','pic2'))
{
$sql = "select pic_big,pic,pic2 from catalogs_products where id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
// if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/big/{$row['pic_big']}");
if (in_array ('pic', $pics))
@unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/{$row['pic']}");
if (in_array ('pic2', $pics))
@unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/2/{$row['pic2']}");
}
function deleteProduct ($id)
{
$this->deleteProductPics ($id);
$sql = "delete from catalogs_products where id=?";
$this->db->query ($sql, array (
$id
));
$this->delete_keysProductsFilters ($id);
$this->delete_keysProductsFilters2 ($id);
$this->delete_keysProductsAkcii ($id);
$this->delete_keysProductsYears ($id);
$this->delete_keysProductsCities ($id);
$this->deleteProductModifications ($id);
}
function deleteProductsRubric ($id)
{
$res = $this->db->getAll ("select id from catalogs_products where rubric_id=?", array (
$id
), DB_FETCHMODE_ASSOC);
foreach ($res as $row)
{
$this->deleteProduct ($row['id']);
$this->deleteGalleryProduct ($row['id']);
}
}
function PhotosCheck ($id_s, $check_s = array())
{
$sql = "UPDATE gallery SET active = ? WHERE id =?";
foreach ($id_s as $id)
{
$this->db->query ($sql, array (
0,
$id
));
}
if (count ($check_s))
{
foreach ($check_s as $id)
{
$this->db->query ($sql, array (
1,
$id
));
}
}
}
function viewRubrics ($id = 0, $parent_id = 0)
{ // print $parent_id."
";
global $rubrics;
// if(!$this->cache->cacheLife("cache_sql_rubrics")){
// $sql = "select a.*,(select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1) as r_pid from catalogs_rubrics a where a.parent_id=? group by a.id order by a.sort asc";
$sql = "
select
a.name,
a.name_ukr,
a.id,
a.parent_id,
a.level,
a.sort,
a.sort_cost,
a.list_name,
a.list_name_ukr,
a.translit,
a.pic,
a.top,
(
select b.translit from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1
) as r_pid2, (
select b.id from catalogs_rubrics b where b.parent_id=a.id order by b.sort limit 1
) as r_pid
from catalogs_rubrics a
where a.parent_id=?
group by a.id
order by a.sort asc
";
$res = $this->db->query ($sql, array (
$id
));
while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC))
{
$rubrics[] = $row; // print $row['id']."
";
if (in_array ($row['id'], $this->getParentIdRubric ($parent_id)))
{
$this->viewRubrics ($row['id']);
}
// if($row['level']==0){$this->viewRubrics($row['id']);}
}
// $this->cache->cacheSave($rubrics,130);
// }else $count = $this->cache->sql_result;
$this->tpl->assign ("rubrics", $rubrics);
}
function getParentIdRubric ($id)
{
// $ids = array();
global $ids;
if (! count ($ids))
$ids = array ();
while ($id > 0)
{
$row = $this->db->getRow ('select id,parent_id from catalogs_rubrics where id=?', array (
$id
), DB_FETCHMODE_ASSOC);
// if(isset($row['id']))
$ids[] = $row['id'];
$id = $row['parent_id'];
} // print_r($ids);
// sort($ids);
return $ids;
}
function viewRubricsAll ($id = 0)
{
global $rubrics;
$sql = "
SELECT
a.name,
a.name_ukr,
a.id,
a.parent_id,
a.level,
a.sort,
a.sort_cost,
a.list_name,
a.list_name_ukr,
a.translit,
a.pic,
a.top
FROM catalogs_rubrics a
WHERE parent_id=?
ORDER BY sort asc
";
$res = $this->db->query ($sql, array (
$id
));
while ($res->fetchInto ($row, DB_FETCHMODE_ASSOC))
{
$rubrics[] = $row;
$this->viewRubricsAll ($row['id']);
}
$this->tpl->assign ("rubrics", $rubrics);
}
function viewRubrics_begin ($item = 'parents', $lang = 'ru')
{
// if(!$this->cache->cacheLife("cache_sql_rubrics_$item"."_".$lang)){
$sql = "
SELECT
a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,
a.id,
a.parent_id,
a.level,
a.sort,
a.sort_cost,
a.list_name,
a.list_name_ukr,
a.translit,
a.pic,
a.top,
(
SELECT b.id
FROM catalogs_rubrics b
WHERE b.parent_id = a.id
ORDER BY b.sort
LIMIT 1
) as r_pid
FROM catalogs_rubrics a
WHERE a.parent_id=?
ORDER BY a.sort asc
";
$row = $this->db->getAll ($sql, array (
0
), DB_FETCHMODE_ASSOC);
foreach ($row as $key => $value)
{
if ($item == 'parents')
{
$row[$key]['parents'] = $this->db->getAll ("
SELECT
a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,
a.id,
a.parent_id,
a.level,
a.sort,
a.sort_cost,
a.list_name,
a.list_name_ukr,
a.translit,
a.pic,
a.top
FROM catalogs_rubrics a
WHERE parent_id=?
ORDER BY sort asc
", array (
$value['id']
), DB_FETCHMODE_ASSOC);
}
else if ($item == 'brends')
{
$row[$key]['brends'] = $this->db->getAll ("
SELECT *
FROM catalogs_brends
WHERE rubric_id in (
SELECT id
FROM catalogs_rubrics
WHERE parent_id=? or id=?
)
GROUP BY name
", array (
$value['id'],
$value['id']
), DB_FETCHMODE_ASSOC);
}
}
$this->tpl->assign ("catalogs_rubrics_begin", $row);
}
// ==== CACHE viewRubrics begin ====
function getFilenameCacheVRB ($item = 'parents', $lang = 'ru')
{
return $_SERVER['DOCUMENT_ROOT'] . '/cache/menu/menu-' . $item . '-' . $lang . '.php';
}
function isFreshCacheVRB ($item = 'parents', $lang = 'ru')
{
$filename = $this->getFilenameCacheVRB ($item, $lang);
$time = 60 * 60 * 24;
if (is_file ($filename) && (filemtime ($filename) + $time) > time ())
{
return true;
}
return false;
}
function saveCacheVRB ($item = 'parents', $lang = 'ru')
{
$filename = $this->getFilenameCacheVRB ($item, $lang);
ob_start ();
var_export ($this->tpl->get_template_vars ('catalogs_rubrics_begin'));
// $row - êàñòûëü çàòî÷êà ïîä "catalogs_rubrics_begin", $row
file_put_contents ($filename, 'getFilenameCacheVRB ($item, $lang);
if (! isset ($this->zlofound))
{
$this->tpl->assign ("catalogs_rubrics_begin", $row);
$this->zlofound = true;
unset ($row);
}
}
function viewRubrics_parent ($parent_id = 0)
{
$sql = "
SELECT
a.name,
a.name_ukr,
a.id,
a.parent_id,
a.level,
a.sort,
a.sort_cost,
a.list_name,
a.list_name_ukr,
a.translit,
a.pic,
a.top
FROM catalogs_rubrics a
WHERE parent_id=?
ORDER BY sort asc
";
$row = $this->db->getAll ($sql, array (
$parent_id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("catalogs_rubrics_parent", $row);
}
function viewRubrics_parent2 ($rub_id, $lang = 'ru')
{
$parent_id = $this->getRubricParent ($rub_id);
if ($parent_id == 0)
{
$parent_id = $rub_id;
}
$sql = "
SELECT
a.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,
a.id,
a.parent_id,
a.level,
a.sort,
a.sort_cost,
a.list_name,
a.list_name_ukr,
a.translit,
a.pic,
a.top
FROM catalogs_rubrics a
WHERE parent_id=?
ORDER BY sort asc
";
$row = $this->db->getAll ($sql, array (
$parent_id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("catalogs_rubrics_parent2", $row);
}
function viewRubricOne ($id, &$row, $lang = 'ru')
{
if ($lang == 'ukr')
$sql = "select *,name_ukr as name,name_h1_ukr as name_h1,top_text_ukr as top_text,seo_text_ukr as seo_text,
meta_title_ukr as meta_title,meta_description_ukr as meta_description,meta_keywords_ukr as meta_keywords,meta_about_ukr as meta_about,
filter2_ukr as filter2, filter_ukr as filter, list_name_ukr as list_name from catalogs_rubrics where id=?";
else
$sql = "select * from catalogs_rubrics where id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('rubric', $row);
}
function getRubricName ($id, $lang = 'ru')
{
$sql = "select name" . ($lang == 'ukr' ? '_ukr' : '') . " from catalogs_rubrics where id=?";
return $this->db->getOne ($sql, array (
$id
));
}
function getRubricParent ($id)
{
$sql = "select parent_id from catalogs_rubrics where id=?";
return $this->db->getOne ($sql, array (
$id
));
}
function activeRubricTop ($id, $top)
{
$table_name = "catalogs_rubrics";
$fields_values = array (
'top' => $top
);
$this->db->autoExecute ($table_name, $fields_values, DB_AUTOQUERY_UPDATE, "id=$id");
}
function SaveRubric ($data, $upload)
{
$table_name = "catalogs_rubrics";
if (trim ($data['translit']) == '')
$data['translit'] = translit ($data['name']);
$DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$parent_id = (isset ($data['parent_id']) ? $data['parent_id'] : 0);
$fields_values = array (
'parent_id' => $parent_id,
"level" => ($this->getLevelRubric ($parent_id) + 1),
'sort' => $data['sort'],
'name' => $data['name'],
'name_ukr' => $data['name_ukr'],
'list_name' => $data['list_name'],
'list_name_ukr' => $data['list_name_ukr'],
'name_h1' => $data['name_h1'],
'name_h1_ukr' => $data['name_h1_ukr'],
'seo_text' => $data['seo_text'],
'seo_text_ukr' => $data['seo_text_ukr'],
'top_text' => $data['top_text'],
'top_text_ukr' => $data['top_text_ukr'],
'filter' => $data['filter'],
'filter_ukr' => $data['filter_ukr'],
'filter2' => $data['filter2'],
'filter2_ukr' => $data['filter2_ukr'],
'filter_products' => $data['filter_products'],
'sort_cost' => $data['sort_cost'],
'meta_title' => $data['meta_title'],
'meta_title_ukr' => $data['meta_title_ukr'],
'meta_description' => $data['meta_description'],
'meta_description_ukr' => $data['meta_description_ukr'],
'meta_keywords' => $data['meta_keywords'],
'meta_keywords_ukr' => $data['meta_keywords_ukr'],
'meta_about' => $data['meta_about'],
'meta_about_ukr' => $data['meta_about_ukr'],
'translit' => $data['translit']
);
if (isset ($data['literal']))
$fields_values['literal'] = 1;
else
$fields_values['literal'] = 0;
if (isset ($data['if_filter_mod']))
$fields_values['if_filter_mod'] = 1;
else
$fields_values['if_filter_mod'] = 0;
if (isset ($data['is_usd']))
$fields_values['is_usd'] = 1;
else
$fields_values['is_usd'] = 0;
if (isset ($data['is_xml']))
$fields_values['is_xml'] = 1;
else
$fields_values['is_xml'] = 0;
if (isset ($data['is_xml2']))
$fields_values['is_xml2'] = 1;
else
$fields_values['is_xml2'] = 0;
if (isset ($data['is_width']))
$fields_values['is_width'] = 1;
else
$fields_values['is_width'] = 0;
/*
* if($upload['pic']['tmp_name']){
* $fields_values['pic'] = upload_ImageResize($upload['pic'],array('width'=>"180",'height'=>"180",'upload_path'=>"./uploaded/pic/catalogs/rubrics/"));
* }
*/
if ($upload['pic']['tmp_name'])
{
if ($data['update_id'] > 0)
$this->deletePicRubric ($data['update_id']);
$uploadfile = "./uploaded/pic/catalogs/rubrics/";
$type = substr (strrchr ($upload['pic']['name'], "."), 1);
$uploadname = mktime () . "." . $type;
if (! move_uploaded_file ($_FILES['pic']['tmp_name'], $uploadfile . $uploadname))
print "Îøèáêà ïðè çàêà÷êå ôàéëà!";
$fields_values['pic'] = $uploadname;
}
// print_r($fields_values);exit;
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
}
function deletePicRubric ($id)
{
$sql = "select pic from catalogs_rubrics where id=?";
$rub = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
@unlink ("./uploaded/pic/catalogs/rubrics/{$rub['pic']}");
}
function getLevelRubric ($id)
{
$level = $this->db->getOne ("select level from catalogs_rubrics where id=?", array (
$id
));
return ($level == null) ? - 1 : $level;
}
function saveUser ($data)
{
$table_name = "catalogs_users";
$DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array (
'name' => $data['user_name'],
'email' => $data['user_email'],
'login' => $data['user_login'],
'psw' => $data['user_psw'],
'about' => $data['user_about'],
'mktime' => mktime ()
);
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
}
function updateUser ($data)
{
$table_name = "catalogs_users";
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$fields_values = array (
'name' => $data['user_name'],
'email' => $data['user_email'],
'login' => $data['user_login'],
'psw' => $data['user_psw'],
'about' => $data['user_about'],
'discount' => $data['user_discount']
);
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
}
function updateUserID ($data, $id)
{
$table_name = "catalogs_users";
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$fields_values = array (
'name' => $data['user_name'],
'email' => $data['user_email'],
'psw' => $data['user_psw'],
'about' => $data['user_about'],
'phone' => $data['user_phone'],
'phonemob' => $data['user_phonemob'],
'adress' => $data['user_adress']
);
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$id}");
}
function deleteUser ($id)
{
$this->db->query ("delete from catalogs_users where id=?", array (
$id
));
$res_order_id = $this->db->getRow ("select id from catalogs_orders where user_id=?", array (
$id
), DB_FETCHMODE_ASSOC);
if (count ($res_order_id))
{
foreach ($res_order_id as $_id)
{
$this->db->query ("delete from catalogs_orders where id=?", array (
$_id
));
$this->db->query ("delete from catalogs_orders_products where order_id=?", array (
$_id
));
}
}
}
function isLoginUser ($login)
{
return $this->db->getOne ("select id from catalogs_users where login=?", array (
$login
));
}
function sendLoginInfo ($login)
{
$user = $this->db->getRow ("select * from catalogs_users where login=?", array (
$login
), DB_FETCHMODE_ASSOC);
$mail = new PHPMailer ();
$mail->CharSet = "windows-1251";
$mail->From = "shop@eltrade.com.ua";
$mail->FromName = "shop@eltrade.com.ua";
$mail->AddAddress ($user['email'], $user['name']);
$mail->Subject = "Àêêàóíò ýêñòðèì";
$msg = "";
$msg .= "Çäðàâñòâóéòå: " . $user['name'];
$msg .= "
";
$msg .= "Âàø ëîãèí: " . $user['login'];
$msg .= "
";
$msg .= "Âàø ïàðîëü: " . $user['psw'];
$msg .= "
";
$msg .= "Ñ óâàæåíèåì, shop@eltrade.com.ua";
$mail->MsgHTML ($msg);
if (! $mail->Send ())
{
echo "There has been a mail error sending to
";
return false;
}
$mail->ClearAddresses ();
$mail->ClearAttachments ();
}
function isUser ($login, $psw)
{
$row = $this->db->getRow ("select * from catalogs_users where login=? AND psw=?", array (
$login,
$psw
), DB_FETCHMODE_ASSOC);
// print $login .' - '.$psw;
$this->tpl->assign ('user_service', $row);
return $row['id'];
}
function viewUser ($id)
{
$sql = "select * from catalogs_users where id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('user', $row);
}
function getUserDiscount ($id)
{
return $this->db->getOne ("select discount from catalogs_users where id=?", array (
$id
));
}
function viewUsers ()
{
$sql = "SELECT catalogs_users. *, COUNT(catalogs_orders.user_id) as count_orders
FROM catalogs_users LEFT JOIN catalogs_orders ON catalogs_orders.user_id=catalogs_users.id
GROUP BY catalogs_users.id
ORDER BY catalogs_users.mktime DESC";
$pagerOptions = Array (
'mode' => 'Sliding',
'delta' => 6,
'perPage' => 10,
'linkClass' => "link_class",
'curPageLinkClassName' => "link_class_active",
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
$this->tpl->assign ('usersData', $res);
}
// ======================
// ==== MODIFICATION ====
// ======================
function viewModifications ($product_id)
{
$sql = "select * from catalogs_modifications where product_id=? order by id desc";
$row = $this->db->getAll ($sql, array (
$product_id
), DB_FETCHMODE_ASSOC);
if (trim ($_REQUEST['test2']) == '1')
print_r ($row);
$this->tpl->assign ('modifications', $row);
}
function viewModificationsProduct ($product_id)
{
$sql = "select a1.* from catalogs_modifications a1 where a1.product_id=? and a1.active>0 order by a1.id asc";
// $sql = "select m.* from catalogs_keys_products_cities k left join catalogs_modifications m on m.code=k.mod_code where k.product_id=? and k.count>0 order by k.mod_code desc";
$row = $this->db->getAll ($sql, array (
$product_id
), DB_FETCHMODE_ASSOC);
for ($i = 0; $i < count ($row); $i ++)
{
$row2 = $this->db->getRow ("SELECT * FROM catalogs_keys_products_cities WHERE product_id='" . $product_id . "' AND mod_code='" . @$row[$i]['code'] . "' LIMIT 1;", array (), DB_FETCHMODE_ASSOC);
// if($row2['city_id']==25){ unset($row[$i]); }
}
$new_row = array ();
// if($_GET['test']=='18') print_r($row);
foreach ($row as $key => $value)
{
// $new_row[] = $value;
}
// if($_GET['test']=='18') print_r($new_row);
$this->tpl->assign ('modifications', $row);
return $row;
}
function viewModificationOne ($id)
{
$sql = "select * from catalogs_modifications where id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('modification', $row);
return $row;
}
function getModificationProduct_id ($code)
{
return $this->db->getOne ("select product_id from catalogs_modifications where code=?", array (
$code
));
}
function getModification ($product_id, $code)
{
return $this->db->getOne ("
SELECT id
FROM catalogs_modifications
WHERE product_id=?
AND code=?", array (
$product_id,
$code
));
}
function SaveModification ($data, $upload)
{
$table_name = "catalogs_modifications";
$DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array (
'product_id' => $data['product_id'],
'code' => $data['code'],
'size' => $data['size'],
'color' => $data['color'],
'active' => $data['active']
);
if (isset ($data['color2']))
{
$fields_values['color2'] = $data['color2'];
}
if (isset ($data['rost']))
{
$fields_values['rost'] = $data['rost'];
}
if (isset ($data['delete_pic']))
{
if ($data['update_id'] > 0)
{
$this->deleteModificationPics ($data['update_id']);
}
$fields_values['pic'] = null;
$fields_values['pic_big'] = null;
}
if ($upload['pic']['tmp_name'])
{
if ($data['update_id'] > 0)
{
$delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array (
'pic'
) : array (
'pic',
'pic_big'
);
$this->deleteModificationPics ($data['update_id'], $delete_pics);
}
$fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
'width' => "144",
'height' => "144",
'upload_path' => "./uploaded/pic/catalogs/modifications/"
));
$fields_values['pic_big'] = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? $upload['pic']['name'] : upload_ImageResize ($upload['pic'], array (
'width' => "1000",
'height' => "1000",
'upload_path' => "./uploaded/pic/catalogs/modifications/big/"
));
}
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='{$data['update_id']}'");
return $id;
}
function deleteModification ($id)
{
$this->deleteModificationPics ($id);
$this->db->query ("delete from catalogs_modifications where id=?", array (
$id
));
}
function deleteProductModifications ($product_id, $nopic = false)
{
IF ($nopic == false)
{
$sql = "
select *
from catalogs_modifications
where product_id=?";
$res = $this->db->getAll ($sql, array (
$product_id
), DB_FETCHMODE_ASSOC);
foreach ($res as $row)
{
$this->deleteModificationPics ($row['id']);
}
}
$this->db->query ("
delete from catalogs_modifications
where product_id=?", array (
$product_id
));
}
function deleteModificationPics ($id, $pics = array('pic_big','pic'))
{
$sql = "select pic,pic_big from catalogs_modifications where id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
if (in_array ('pic', $pics))
{
@unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/{$row['pic']}");
}
// if(in_array('pic_big',$pics))@unlink("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/modifications/big/{$row['pic_big']}");
}
// =================
// ==== PRODUCT ====
// =================
function ProductClick ($id)
{
$this->db->query ("update catalogs_products set click=click+1 where id='$id'");
}
function SaveProduct ($data, $upload)
{
$table_name = "catalogs_products";
if (trim (@$data['translit']) == "")
$data['translit'] = translit ($data['name']);
$DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$id = ($data['update_id'] > 0) ? $data['update_id'] : $this->db->nextId ('mySequence_' . $table_name);
$fields_values = array (
'id' => $id,
'rubric_id' => $data['rubric_id'],
'rubric_parent_id' => $this->getRubricParent ($data['rubric_id']),
'brend_id' => $data['brend_id'],
'name' => $data['name'],
'about' => $data['about'],
'text' => $data['text'],
'update_text' => (int) $data['update_text'],
'strnumber' => $data['strnumber'],
'cine' => $data['cine'],
'cine_last' => $data['cine_last'],
'mktime' => mktime (),
'meta_title' => $data['meta_title'],
'meta_description' => $data['meta_description'],
'meta_keywords' => $data['meta_keywords'],
'meta_about' => $data['meta_about'],
'active' => $data['active'],
'translit' => $data['translit']
);
if (isset ($data['is_cost2']))
$fields_values['is_cost2'] = 1;
else
$fields_values['is_cost2'] = 0;
if (isset ($data['cine2']))
$fields_values['cine2'] = $data['cine2'];
if (isset ($data['params']))
$this->saveProductParams ($id, $data['params']);
if (isset ($data['doc']))
$fields_values['doc'] = $data['doc'];
if (isset ($data['update_text']))
$fields_values['update_text'] = $data['update_text'];
if (isset ($data['video_code']))
$fields_values['video_code'] = $data['video_code'];
if (isset ($data['akcii_id']))
$fields_values['akcii_id'] = $data['akcii_id'];
if (isset ($data['translit']))
$fields_values['translit'] = $data['translit'];
if ($upload['pic']['tmp_name'])
{
$delete_pics = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? array (
'pic',
'pic2'
) : array (
'pic',
'pic2',
'pic_big'
);
$this->deleteProductPics ($id, $delete_pics);
$fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
'width' => "144",
'height' => "144",
'upload_path' => "./uploaded/pic/catalogs/products/"
));
$fields_values['pic2'] = upload_ImageResize ($upload['pic'], array (
'width' => "244",
'height' => "244",
'upload_path' => "./uploaded/pic/catalogs/products/2/"
));
$fields_values['pic_big'] = (isset ($upload['pic']['big']) && $upload['pic']['big'] == true) ? $upload['pic']['name'] : upload_ImageResize ($upload['pic'], array (
'width' => "1000",
'height' => "1000",
'upload_path' => "./uploaded/pic/catalogs/products/big/"
));
}
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id='$id'");
$this->save_keysProductsFilters ($id, $data);
$this->save_keysProductsFilters2 ($id, $data);
$this->save_keysProductsYears ($id, $data);
// $this->save_keysProductsCities($id,$data);
$this->save_keysProductsAkcii ($id, $data);
$this->save_keysProductsSex ($id, $data);
return $id;
}
function save_keysProductsSex ($id, $data)
{
$this->delete_keysProductsSex ($id);
if (! isset ($data['sex']))
return false;
$table_name = "catalogs_keys_products_sex";
foreach ($data['sex'] as $sex)
{
$this->db->autoExecute ($table_name, array (
'product_id' => $id,
'sex' => $sex,
'rubric_id' => $data['rubric_id']
), DB_AUTOQUERY_INSERT);
}
}
function delete_keysProductsSex ($id)
{
$this->db->query ("delete from catalogs_keys_products_sex where product_id=?", array (
$id
));
}
function save_keysProductsFilters2 ($id, $data)
{
$this->delete_keysProductsFilters2 ($id);
if (! isset ($data['filter2']))
return false;
$table_name = "catalogs_keys_products_filters2";
foreach ($data['filter2'] as $filter_id)
{
$this->db->autoExecute ($table_name, array (
'product_id' => $id,
'filter_id' => $filter_id,
'rubric_id' => $data['rubric_id']
), DB_AUTOQUERY_INSERT);
}
}
function delete_keysProductsFilters2 ($id)
{
$this->db->query ("delete from catalogs_keys_products_filters2 where product_id=?", array (
$id
));
}
function save_keysProductsFilters ($id, $data)
{
$this->delete_keysProductsFilters ($id);
if (! isset ($data['filter']))
return false;
$table_name = "catalogs_keys_products_filters";
foreach ($data['filter'] as $filter_id)
{
$this->db->autoExecute ($table_name, array (
'product_id' => $id,
'filter_id' => $filter_id,
'rubric_id' => $data['rubric_id']
), DB_AUTOQUERY_INSERT);
}
}
function delete_keysProductsFilters ($id)
{
$this->db->query ("delete from catalogs_keys_products_filters where product_id=?", array (
$id
));
}
function save_keysProductsYears ($id, $data)
{
$this->delete_keysProductsYears ($id);
if (! isset ($data['years']))
return false;
$table_name = "catalogs_keys_products_years";
foreach ($data['years'] as $filter_id)
{
$this->db->autoExecute ($table_name, array (
'product_id' => $id,
'year_id' => $filter_id,
'rubric_id' => $data['rubric_id']
), DB_AUTOQUERY_INSERT);
}
}
function delete_keysProductsYears ($id)
{
$this->db->query ("delete from catalogs_keys_products_years where product_id=?", array (
$id
));
}
function save_keysProductsCities ($id, $data)
{
$this->delete_keysProductsCities ($id);
if (! isset ($data['city']))
return false;
$table_name = "catalogs_keys_products_cities";
foreach ($data['city'] as $city_id)
{
$this->db->autoExecute ($table_name, array (
'product_id' => $id,
'city_id' => $city_id
), DB_AUTOQUERY_INSERT);
}
}
function delete_keysProductsAkcii ($id)
{
$this->db->query ("delete from catalogs_keys_products_akcii where product_id=?", array (
$id
));
}
function save_keysProductsAkcii ($id, $data)
{
$this->delete_keysProductsAkcii ($id);
if (! isset ($data['akcii']))
return false;
$table_name = "catalogs_keys_products_akcii";
foreach ($data['akcii'] as $rubric_id)
{
$this->db->autoExecute ($table_name, array (
'product_id' => $id,
'rubric_id' => $rubric_id
), DB_AUTOQUERY_INSERT);
}
}
function delete_keysProductsCities ($id)
{
$this->db->query ("delete from catalogs_keys_products_cities where product_id=?", array (
$id
));
}
function saveProductSizeCine ($id, $data)
{
$this->db->query ("delete from catalogs_products_cine where product_id=?", array (
$id
));
foreach ($data['size'] as $key => $size)
{
$this->db->autoExecute ("catalogs_products_cine", array (
'product_id' => $id,
'size' => $size,
'cine' => $data['cine'][$key],
'metka' => $data['size_metka'][$key],
'n' => $key
), DB_AUTOQUERY_INSERT);
}
}
function productsIsHits ($products, $hits, $tops, $akcii)
{
$sql = "update catalogs_products set active=?,top=?,akcii_id=? where id=?";
foreach ($products as $id)
{
if (@in_array ($id, $hits))
$hit = true;
else
$hit = false;
if (@in_array ($id, $tops))
$top = true;
else
$top = false;
if (@in_array ($id, $akcii))
$akcii = true;
else
$akcii = false;
$this->db->query ($sql, array (
$hit,
$top,
$akcii,
$id
));
}
}
function productsIsHits2 ($data, $hits)
{
$sql = "update catalogs_products set hit=?,hit_sort=? where id=?";
foreach ($data['product_id'] as $key => $id)
{
if (@in_array ($id, $hits))
$hit = true;
else
$hit = false;
$this->db->query ($sql, array (
$hit,
$data['hit_sort'][$key],
$id
));
}
}
function viewProductsRubrics ($rubrics, $limit = 20)
{
$data = array ();
foreach ($rubrics as $key => $rubric_id)
{
$data[$key]['rubric']['name'] = $this->getRubricName ($rubric_id);
$data[$key]['rubric']['id'] = $rubric_id;
$count = $this->db->getOne ("select count(*) from catalogs_products WHERE count_modifications>0 and rubric_id=?", array (
$rubric_id
));
$limit = 5;
$round = ($count > $limit) ? rand (0, ($count - $limit)) : $limit;
$sql = "select * from catalogs_products where count_modifications>0 and rubric_id=? order by id " . ((rand (1, 1000) % 2) ? "asc" : "desc") . " limit $round,$limit";
$data[$key]['products'] = $this->db->getAll ($sql, array (
$rubric_id
), DB_FETCHMODE_ASSOC);
}
/*
* print"
";
* print_r($data);
* print"
";
*/
$this->tpl->assign ('products', $data);
}
function seralizeFilter ($str)
{
$array = explode (';', iconv ('UTF-8', 'CP1251', $str));
$filter = array ();
foreach ($array as $key => $value)
{
$filter[substr ($value, 0, 1)][] = "'" . substr (str_replace (".", ",", $value), 1, strpos ($value, "_") - 1) . "'";
}
// print_r($filter);
return $filter;
}
function seralizeSex ($str)
{
$sex = array ();
$sex_num = array (
'male' => 1,
'female' => 2,
'child' => 3,
'unisex' => 4
);
$sex_row = explode (';', $str);
foreach ($sex_row as $row)
{
$sex[] = $sex_num[$row];
}
return $sex;
}
// =================
// ==== FILTER =====
// =================
/**
* Ôèëüòðàöèÿ òîâàðîâ ïî êðèòåðèÿåì
* Ìîæíî èñïîëüçîâàòü â êà÷åñòâå âûâîäà ñïèñêà ñâîéñòâ ôèëüòðîâ
* @param array $setting
* @return array òîâàðû/ñïèñêà ñâîéñòâ ôèëüòðîâ
*/
function queryBuild (array $setting = array ())
{
Tools::ifNotExist ($setting, array (
'akcii' => true,
'sex' => true,
));
$SQL = new SqlQuery();
$SQL->select('
catalogs_products.*, catalogs_products.name.as name,
catalogs_brends.name as brend_name,
catalogs_rubrics.list_name' . ($lang == 'ukr' ? '_ukr' : '') . ' as list_name,
catalogs_rubrics.translit as rubric_translit,
catalogs_keys_products_filters.*,
catalogs_keys_products_filters2.*,
catalogs_modifications.*
');
$SQL->from('catalogs_products');
$SQL->innerJoin(
'catalogs_brends', NULL,
'catalogs_brends.id = catalogs_products.brend_id'
);
$SQL->innerJoin(
'catalogs_rubrics', NULL,
'catalogs_rubrics.id=catalogs_products.rubric_id'
);
$SQL->innerJoin(
'catalogs_keys_products_filters', NULL,
'catalogs_keys_products_filters.product_id = catalogs_products.id'
);
$SQL->innerJoin(
'catalogs_keys_products_filters2', NULL,
'catalogs_keys_products_filters2.product_id = catalogs_products.id'
);
$SQL->innerJoin(
'catalogs_modifications', NULL,
'catalogs_modifications.product_id = catalogs_products.id
AND catalogs_modifications.active = 1'
);
// àêöèè
if ($setting['akcii'])
{
$SQL->select('catalogs_keys_products_akcii.*');
$SQL->innerJoin(
'catalogs_keys_products_akcii', NULL,
'catalogs_keys_products_akcii.product_id = catalogs_products.id'
);
}
// ïîë
if ($setting['sex'])
{
$SQL->select('sex.*');
$SQL->innerJoin(
'catalogs_keys_products_sex', 'sex',
'catalogs_keys_products_sex.product_id = catalogs_products.id
AND sex.sex_id > 0'
);
}
$SQL->where('catalogs_products.count_modifications > 0');
// ===========================
// ==== ðàçáîð ïàðàìåòðîâ ====
// ===========================
if (isset ($params['filter']) && count ($params['filter']) > 0)
{
// LIMIT
if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100)
{
$perPage = $_GET['perPage'];
}
else
{
$perPage = 20;
}
$SQL->limit($perPage);
// ÏÎÈÑÊ
if (isset ($params['search_str']) && strlen ($params['search_str']) > 0)
{
$array_string = explode (' ', trim ($params['search_str']));
foreach ($array_string as $word)
{
$SQL->where('(
catalogs_products.name LIKE "%'.$word.'%"
OR catalogs_products.text LIKE "%'.$word.'%"
OR catalogs_rubrics.name LIKE "%'.$word.'%"
OR catalogs_brends.name LIKE "%'.$word.'%"
OR catalogs_modifications.code = "'.$word.'"
)');
}
}
// PARAM
if (isset ($params['brendID']) && $params['brendID'] > 0)
{
$SQL->where( sprintf ("catalogs_products.brend_id='%d'", $params['brendID']));
}
if (isset ($params['akciiID']) && $params['akciiID'] > 0)
{
$SQL->where( sprintf ("catalogs_products.akcii_id>'%d'", 0));
}
if (isset ($params['new']) && $params['new'] > 0)
{
$SQL->where( sprintf ("catalogs_products.active='%d'", $params['new']));
}
if (isset ($params['top']) && $params['top'] > 0)
{
$SQL->where( sprintf ("catalogs_products.top='%d'", $params['top']));
}
if (isset ($params['brend']) && strlen ($params['brend']) > 0)
{
$SQL->where( "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")");
}
if (isset ($params['sex']) && strlen ($params['sex']) > 0)
{
$sex = $this->seralizeSex ($params['sex']);
$SQL->where( "s.sex IN (" . implode (",", $sex) . ")");
}
// ÕÇ
if ($count_modf == true)
{
$SQL->where( "catalogs_products.count_modifications>0");
}
if (isset ($params['rubID']) && $params['rubID'] > 0
&& ! isset ($params['filter_products'])
&& ! isset ($params['what']))
{
$SQL->where( ($rubricsP == true) ? sprintf ("(catalogs_products.rubric_id='%d')", $params['rubID']) : sprintf ("
(
catalogs_products.rubric_parent_id='%d' ||
catalogs_products.rubric_id='%d' ||
catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') ||
catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d')
)",
$params['rubID'],
$params['rubID'],
$params['rubID'],
$params['rubID']
));
}
$filter = $this->seralizeFilter ($params['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$SQL->where( "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")");
}
elseif (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($params['what']))
{
$SQL->where( "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")");
}
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$SQL->where( "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")");
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$SQL->where( "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")");
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$SQL->where( "m2.rost in (" . implode (",", $filter['r']) . ")");
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$SQL->where( "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")");
}
// ==== SORT ====
if (isset ($params['sort']))
{
switch ($params['sort'])
{
case 'cine' :
$SQL->orderBy('catalogs_products.cine '. ($_GET['order'] == 'asc' ? 'ASC' : 'DESC'));
break;
case 'click' :
$SQL->orderBy('catalogs_products.click' . ($_GET['order'] == 'asc' ? 'ASC' : 'DESC'));
break;
case 'rating' :
$SQL->orderBy('catalogs_products.rating' . ($_GET['order'] == 'asc' ? 'ASC' : 'DESC'));
break;
case 'hit' :
$SQL->orderBy('catalogs_products.hit_sort ASC');
break;
default :
$SQL->orderBy('catalogs_products.mktime DESC');
}
}
else
{
$SQL->orderBy(! empty ($params['top']) ? 'catalogs_rubrics.top DESC' : 'catalogs_products.rating DESC');
}
// ==== GROUP ====
$SQL->groupBy('catalogs_products.id');
}
return $this->db->getAll ($SQL->__toSting(), array (), DB_FETCHMODE_ASSOC);
}
function viewProducts ($params, $rubricsP = false, $count_modf = true, $lang = 'ru')
{
// exit;
// print $params['filter_products'];
if (isset ($params['filter']) && count ($params['filter']) > 0)
$filter = $this->seralizeFilter ($params['filter']);
$search = array ();
if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100)
$perPage = $_GET['perPage'];
else
$perPage = 20;
if (isset ($params['search_str']) && strlen ($params['search_str']) > 0)
{
$array_string = explode (" ", trim ($params['search_str']));
foreach ($array_string as $row)
{
$search[] = "(catalogs_products.name LIKE '%" . $row . "%' OR catalogs_products.text LIKE '%" . $row . "%' OR catalogs_rubrics.name LIKE '%" . $row . "%' OR catalogs_brends.name LIKE '%" . $row . "%' OR catalogs_modifications.code='" . $row . "%')";
}
$search_string = array ();
// $search_string[] = "catalogs_products.name like '%".mysql_real_escape_string($params['search_str'])."%'";
// $search_string[] = "catalogs_products.text like '%".mysql_real_escape_string($params['search_str'])."%'";
/*
* foreach($array_string as $str){
* $search_string[] = "catalogs_products.name like '$str'";
* $search_string[] = "catalogs_products.name like'% $str %'";
* $search_string[] = "catalogs_products.name like'%$str %'";
* $search_string[] = "catalogs_products.name like'% $str%'";
*
* $search_string[] = "catalogs_products.text like '$str'";
* $search_string[] = "catalogs_products.text like'% $str %'";
* $search_string[] = "catalogs_products.text like'%$str %'";
* $search_string[] = "catalogs_products.text like'% $str%'";
* }
*/
// $search[] = "((" . implode(" OR ",$search_string) . ") OR ". sprintf("catalogs_modifications.code='%s'", mysql_real_escape_string($params['search_str'])).")";
}
// print_r($params);
if (isset ($params['brendID']) && $params['brendID'] > 0)
$search[] = sprintf ("catalogs_products.brend_id='%d'", $params['brendID']);
if (isset ($params['akciiID']) && $params['akciiID'] > 0)
$search[] = sprintf ("catalogs_products.akcii_id>'%d'", 0);
if (isset ($params['new']) && $params['new'] > 0)
$search[] = sprintf ("catalogs_products.active='%d'", $params['new']);
if (isset ($params['top']) && $params['top'] > 0)
$search[] = sprintf ("catalogs_products.top='%d'", $params['top']);
if (isset ($params['brend']) && strlen ($params['brend']) > 0)
$search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")";
if (isset ($params['sex']) && strlen ($params['sex']) > 0)
{
$sex = $this->seralizeSex ($params['sex']);
// print_r($sex);
// $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
$search[] = "s.sex IN (" . implode (",", $sex) . ")";
}
// if(isset($params['akcii']) && $params['akcii']>0)$search[] = sprintf("catalogs_products.hit='%d'",$params['akcii']);
if ($count_modf == true)
$search[] = "catalogs_products.count_modifications>0";
if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']) && ! isset ($params['what']))
{
$search[] = ($rubricsP == true) ? sprintf ("(catalogs_products.rubric_id='%d')", $params['rubID']) : sprintf ("
(catalogs_products.rubric_parent_id='%d' ||
catalogs_products.rubric_id='%d' ||
catalogs_products.rubric_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d') ||
catalogs_products.rubric_parent_id=(SELECT id FROM catalogs_rubrics WHERE translit='%d'))", $params['rubID'], $params['rubID'], $params['rubID'], $params['rubID']);
}
/*
* if(isset($params['filterID'])){
* //$search[] = sprintf("catalogs_keys_products_filters.filter_id='%d'", $params['filterID']);
* $search[] = "catalogs_keys_products_filters.filter_id in (".implode(",",$params['filterID']).")";
* }
*/
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
elseif (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($params['what']))
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
}
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
/*
* if(isset($params['yearID']) && $params['yearID']>0){
* //$search[] = sprintf("catalogs_keys_products_years.year_id='%d'", $params['yearID']);
* $search[] = "catalogs_keys_products_years.year_id in (".implode(",",$params['yearID']).")";
* }
*/
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
$sql = "
SELECT catalogs_rubrics.translit as rubric_translit,catalogs_products.*,catalogs_products.name" . ($lang == 'ukr' ? '' : '') . " as name,catalogs_brends.name as brend_name,catalogs_rubrics.list_name" . ($lang == 'ukr' ? '_ukr' : '') . " as list_name
FROM catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id
RIGHT JOIN catalogs_keys_products_akcii ON catalogs_keys_products_akcii.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id
AND catalogs_modifications.active=1
LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id
WHERE 1=1
";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
// if(isset($params['akcii']) && $params['akcii']>0){$sql .= " GROUP BY catalogs_keys_products_akcii.product_id ";}
// if(isset($params['search_str']) && strlen($params['search_str'])>0){}
$sql .= " GROUP BY catalogs_products.id ";
$sql .= "order by ";
if (isset ($params['sort']))
{
switch ($params['sort'])
{
case 'cine' :
$sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'click' :
$sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'rating' :
$sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'hit' :
$sql .= " catalogs_products.hit_sort asc";
break;
default :
$sql .= " catalogs_products.mktime desc";
}
}
else
$sql .= (! empty ($params['top'])) ? " catalogs_rubrics.top desc" : " catalogs_products.rating desc";
$pagerOptions = Array (
'mode' => 'Sliding',
'delta' => 5,
'perPage' => $perPage,
'linkClass' => "link_class",
'curPageLinkClassName' => "link_class_active",
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
// echo $sql;
// $sql="";
$res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
if (! empty ($res))
{
// if($_GET['test']=='1')
for ($i = 0; $i < count ($res['data']); $i ++)
{
$res['data'][$i]['mod'] = $this->db->getRow ('select * from catalogs_modifications where product_id=? and active=1 Order By id Asc', array (
$res['data'][$i]['id']
), DB_FETCHMODE_ASSOC);
$res['data'][$i]['ph1'] = $this->getFilterPh1 ($res['data'][$i]['id'], $lang);
$res['data'][$i]['rating2'] = $res['data'][$i]['rating'];
if (@$res['data'][$i]['rating'])
$res['data'][$i]['rating'] = round ((@$res['data'][$i]['rating'] / @$res['data'][$i]['vote_num']), 0);
else
$res['data'][$i]['rating'] = 0;
$res['data'][$i]['rating'] = @$res['data'][$i]['rating'] * 17;
}
}
$this->tpl->assign ('productsData', $res);
return $res;
}
function getFilterPh1 ($product_id, $lang = 'ru')
{
$sql = "select ph1" . ($lang == 'ukr' ? '_ukr' : '') . " as ph1 from catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where k.product_id=? AND f.ph1" . ($lang == 'ukr' ? '_ukr' : '') . "<>''";
return $this->db->getOne ($sql, array (
$product_id
));
}
function getCineCurs ($type_curs, $cine)
{
$curs = array ();
$uah = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
'uah'
));
$uah_bank = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
'uah_bank'
));
$usd = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
'usd'
));
switch ($type_curs)
{
case 'uah' :
$curs['uah'] = round ($cine, 2);
$curs['uah_bank'] = round (($cine / $usd) * $uah_bank, 2);
$curs['usd'] = round ($cine / $usd, 2);
break;
case 'uah_bank' :
$curs['uah'] = round (($cine / $uah_bank) * $uah, 2);
$curs['uah_bank'] = round ($cine, 2);
$curs['usd'] = round ($cine / $uah_bank, 2);
break;
case 'usd' :
$curs['uah'] = round ($cine * $uah, 2);
$curs['uah_bank'] = round ($cine * $uah_bank, 2);
$curs['usd'] = round ($cine, 2);
break;
}
return $curs;
}
function viewProductsAkcii ($rubric_id, $limit = 8)
{
// $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
// LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
// LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
// WHERE catalogs_products.top=? and catalogs_products.count_modifications>0 ";
// if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
// $sql .= "order by RAND() LIMIT $limit";
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
/*
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "catalogs_products.sex IN (" . implode (",", $sex) . ")";
}
/*
* $sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_keys_products_akcii
* left join catalogs_products on catalogs_products.id=catalogs_keys_products_akcii.product_id
* LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
* LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
*/
$sql = "
SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit
FROM catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
WHERE catalogs_products.count_modifications>0
AND catalogs_products.akcii_id>0
";
if ($rubric_id > 0)
$sql .= "and catalogs_products.rubric_id='$rubric_id' ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "order by RAND()";
if ($rubric_id == 0)
{
$sql .= " limit 8";
}
$res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
// print_r($res);
for ($i = 0; $i < count ($res); $i ++)
{
$res[$i]['rating2'] = $res[$i]['rating'];
if (@$res[$i]['rating'])
$res[$i]['rating'] = round ((@$res[$i]['rating'] / @$res[$i]['vote_num']), 0);
else
$res[$i]['rating'] = 0;
$res[$i]['rating'] = @$res[$i]['rating'] * 17;
}
$this->tpl->assign ('products_akcii', $res);
}
function getProductsAkcii ($limit = 6)
{
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id ";
// $sql .= "where catalogs_keys_products_akcii.rubric_id=? ";
$sql .= "where catalogs_products.count_modifications>0 and catalogs_products.akcii_id>0 ";
// if(count($search))$sql .= "AND " . implode(" AND ",$search) . " ";
$sql .= "order by RAND() limit $limit";
return $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
}
function viewProductsHitsAll2 ()
{
if (isset ($_GET['perPage']) && $_GET['perPage'] > 0 && $_GET['perPage'] <= 100)
$perPage = $_GET['perPage'];
else
$perPage = 20;
$sql = "select * from catalogs_products where hit=?";
$pagerOptions = Array (
'mode' => 'Sliding',
'delta' => 6,
'perPage' => $perPage,
'linkClass' => "link_class",
'curPageLinkClassName' => "link_class_active",
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array (
true
));
$this->tpl->assign ('productsData', $res);
}
function viewProductsActiveAll ($params, $limit = 4, $curs = null)
{
$search = array ();
$sql = "
SELECT * FROM (
select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.active=? and catalogs_products.count_modifications>0 ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "ORDER BY RAND()) as T ";
$sql .= "Group By rubric_id ORDER BY RAND() LIMIT $limit";
$res = $this->db->getAll ($sql, array (
true
), DB_FETCHMODE_ASSOC);
// print_r($res);
$this->tpl->assign ('products_active', $res);
}
function viewProductsActive ($params, $limit = 4, $curs = null)
{
$search = array ();
if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']))
$search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']);
if (isset ($params['filter']) && count ($params['filter']) > 0)
$filter = $this->seralizeFilter ($params['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
}
if (isset ($params['brend']) && strlen ($params['brend']) > 0)
$search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")";
/*
* if(isset($params['sex']) && strlen($params['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "s.sex IN (" . implode (",", $sex) . ")";
}
$sql = "
SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit
FROM catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id
WHERE catalogs_products.active=?
AND catalogs_products.count_modifications>0
";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "order by RAND() LIMIT $limit";
$res = $this->db->getAll ($sql, array (
true
), DB_FETCHMODE_ASSOC);
// print_r($res);
$this->tpl->assign ('products_active', $res);
}
function viewProductsHits ($params, $limit = 4, $curs = null)
{
$search = array ();
if (isset ($params['rubID']) && $params['rubID'] > 0)
$search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']);
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.hit=? and catalogs_products.count_modifications>0 ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "order by ";
if (isset ($params['sort']))
{
switch ($params['sort'])
{
case 'cine' :
$sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'click' :
$sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'rating' :
$sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'hit' :
$sql .= " catalogs_products.hit_sort asc";
break;
default :
$sql .= " RAND()";
}
}
else
$sql .= " RAND()";
$sql .= " LIMIT $limit";
$res = $this->db->getAll ($sql, array (
true
), DB_FETCHMODE_ASSOC);
// print_r($res);
$this->tpl->assign ('products_hits', $res);
}
function viewProductsTops ($params, $limit = 4, $curs = null)
{
$search = array ();
if (isset ($params['rubID']) && $params['rubID'] > 0 && ! isset ($params['filter_products']))
$search[] = sprintf ("catalogs_products.rubric_id=%d", $params['rubID']);
if (isset ($params['filter']) && count ($params['filter']) > 0)
$filter = $this->seralizeFilter ($params['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
}
if (isset ($params['brend']) && strlen ($params['brend']) > 0)
$search[] = "catalogs_products.brend_id in(" . implode (",", $this->getBrendIDs_name ($params['brend'])) . ")";
/*
* if(isset($params['sex']) && strlen($params['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("catalogs_products.sex='%d'",$sex[$params['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "catalogs_products.sex IN (" . implode (",", $sex) . ")";
}
$sql = "
SELECT catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit
FROM catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
WHERE catalogs_products.top=?
AND catalogs_products.count_modifications>0
";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
// $sql .= "order by RAND()";
$sql .= "order by ";
if (isset ($params['sort']))
{
switch ($params['sort'])
{
case 'cine' :
$sql .= " catalogs_products.cine " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'click' :
$sql .= " catalogs_products.click " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'rating' :
$sql .= " catalogs_products.rating " . (($_GET['order'] == 'asc') ? "asc" : "desc");
break;
case 'hit' :
$sql .= " catalogs_products.hit_sort asc";
break;
default :
$sql .= " r.top desc";
}
}
else
$sql .= " r.top desc";
$sql .= " LIMIT $limit";
// print $sql;
$res = $this->db->getAll ($sql, array (
true
), DB_FETCHMODE_ASSOC);
// print_r($res);
$this->tpl->assign ('products_top', $res);
}
function viewProductsTopOne ()
{
$count = $this->db->getOne ("select count(*) from catalogs_products WHERE catalogs_products.header=?", array (
true
));
$limit = 1;
$round = rand (0, ($count - $limit));
$res = $this->db->getRow ("select * from catalogs_products WHERE catalogs_products.header=? order by id " . ((rand (1, 1000) % 2) ? "asc" : "desc") . " LIMIT $round,$limit", array (
true
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('products_top_one', $res);
}
function viewProductsLast ($limit = 1)
{
$search = array ();
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE catalogs_products.active=? ";
$sql .= "order by catalogs_products.mktime desc LIMIT $limit";
$res = $this->db->getAll ($sql, array (
true
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('products_last', $res);
}
function viewProductsHitsAll ($limit = 4)
{
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name from catalogs_products LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id WHERE hit=? ";
$sql .= "order by mktime desc LIMIT $limit";
$products_hits = $this->db->getAll ($sql, array (
true
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('products_hits_all', $products_hits);
}
function activeNull ($rubric_id)
{
$sql = "update catalogs_products set active=? where rubric_id=?";
$this->db->query ($sql, array (
0,
$rubric_id
));
}
function viewProductOne ($id, &$row)
{
// $sql = "select p.*,b.name as brend_name,b.text as brend_text,b.pic_s as brend_pic_s from catalogs_products p left join catalogs_brends b2 ON b2.id=p.brend_id left join catalogs_brends b ON b.name=b2.name and b.active=1 where p.id=?";
$sql = "select p.*,b.name as brend_name,b.text as brend_text,b.pic_s as brend_pic_s from catalogs_products p left join catalogs_brends b ON b.id=p.brend_id where p.id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$row['ph1'] = $this->getFilterPh1 ($row['id']);
$row['rating2'] = $row['rating'];
if (@$row['rating'])
$row['rating'] = round ((@$row['rating'] / @$row['vote_num']), 0);
else
$row['rating'] = 0;
$row['rating'] = @$row['rating'] * 17;
// print_r($row);
$this->tpl->assign ('product', $row);
}
function deleteCompareProduct (&$compare, $id)
{
foreach ($compare as $key => $_id)
{
if ($_id == $id)
unset ($compare[$key]);
}
}
function viewCompareProducts ($compare)
{
$products = array ();
$i = 0;
foreach ($compare as $id)
{
$sql = "select p.* from catalogs_products p where p.id=?";
$products[$i] = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$products[$i]['params'] = $this->getProductParams ($id);
$i ++;
} // print_r($products);
$this->tpl->assign ('products', $products);
}
function viewProductNembers ($str_n)
{
$arr_id = explode (",", $str_n);
$products = array ();
foreach ($arr_id as $id)
{
$count = $this->db->getOne ("select count(*) from catalogs_keys_products_filters where filter_id=?", array (
trim ($id)
));
$limit = 1;
$round = rand (0, ($count - $limit)); // " LIMIT 0,$limit"
$sql = "select catalogs_rubrics.translit as rubric_translit,catalogs_rubrics.name as rubric, catalogs_products.*,catalogs_keys_products_filters.filter_id as prd from catalogs_keys_products_filters Left Join catalogs_products ON catalogs_products.id=catalogs_keys_products_filters.product_id Left Join catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id where catalogs_keys_products_filters.filter_id=? and catalogs_products.count_modifications>0 order by catalogs_keys_products_filters.product_id " . ((rand (1, 1000) % 2) ? "asc" : "desc"); // . " LIMIT $round,$limit";
$row = $this->db->getRow ($sql, array (
trim ($id)
), DB_FETCHMODE_ASSOC);
if (count ($row) > 0)
$products[] = $row;
}
// $products = $this->db->getAll("select catalogs_rubrics.translit as translit2,catalogs_products.*,catalogs_keys_products_filters.filter_id as prd from catalogs_keys_products_filters Left Join catalogs_products ON catalogs_products.id=catalogs_keys_products_filters.product_id Left Join catalogs_rubrics ON catalogs_rubrics.id=catalogs_products.rubric_id where catalogs_keys_products_filters.filter_id in(".implode(',',$arr_id).") and catalogs_products.count_modifications>0 Group By catalogs_keys_products_filters.filter_id order by catalogs_keys_products_filters.product_id " . ((rand(1,1000)%2) ? "asc" : "desc") ,array(),DB_FETCHMODE_ASSOC);
$this->tpl->assign ('products_parent', $products);
}
function getProductSizeCine ($id, &$products)
{
$res = $this->db->getAll ("select * from catalogs_products_cine where product_id=?", array (
$id
), DB_FETCHMODE_ASSOC);
$i = 0;
foreach ($res as $row)
{
$products['size_' . $row['n']] = $row['size'];
$products['cine_' . $row['n']] = $row['cine'];
$products['metka_' . $row['n']] = $row['metka'];
$products['id_cine_' . $row['n']] = $row['id'];
$i ++;
} // print_r($products);
}
/*
* function getProductCine($id,$curs = null){
* $sql = "select cine from catalogs_products where id=?";
* $row = $this->db->getOne($sql,array($id));
* return $row;
* }
*/
function getProductCine ($id)
{
$sql = "select IF( catalogs_products.is_cost2 <1, catalogs_products.cine, catalogs_products.cine2 ) AS cine from catalogs_modifications left join catalogs_products on catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?";
return $this->db->getOne ($sql, array (
$id
));
}
function viewProductCine ($id)
{
$row = $this->db->getAll ("select * from catalogs_products_cine where product_id=? and cine>0 Order By n ASC", array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('product_cines', $row);
}
function viewCatalogsCurs ()
{
$uah = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
'uah'
));
$this->tpl->assign ('curs_uah', $uah);
$uah_bank = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
'uah_bank'
));
$this->tpl->assign ('curs_uah_bank', $uah_bank);
$usd = $this->db->getOne ("select curs from catalogs_curs where type=?", array (
'usd'
));
$this->tpl->assign ('curs_usd', $usd);
}
function saveCurs ($data)
{
$table_name = "catalogs_curs";
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
foreach ($data as $key => $value)
{
$this->db->autoExecute ($table_name, array (
'curs' => $value
), $DB_AUTOQUERY, "type='$key'");
}
}
function viewVarCurs ($curs)
{
$this->tpl->assign ('curs', $curs);
}
function viewBasketProducts ($session_basket, $curs = null, $discount = 0)
{
$products = array ();
$i = 0;
$cineAll = 0;
// $sql = "select catalogs_products.* from catalogs_products where catalogs_products.id=?";
// $sql = "select catalogs_modifications.id,IF(catalogs_products.is_cost2<1,catalogs_products.cine,catalogs_products.cine2) as cine,catalogs_products.name,catalogs_modifications.code,catalogs_modifications.size,catalogs_modifications.color,catalogs_modifications.pic,catalogs_modifications.pic_big from catalogs_modifications Left Join catalogs_products On catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?";
$sql = "select catalogs_modifications.id,catalogs_modifications.sale,IF(catalogs_modifications.cine>0,catalogs_modifications.cine,catalogs_products.cine) as cine,catalogs_products.name,catalogs_modifications.code,catalogs_modifications.size,catalogs_modifications.color,catalogs_modifications.pic,catalogs_modifications.pic_big from catalogs_modifications Left Join catalogs_products On catalogs_products.id=catalogs_modifications.product_id where catalogs_modifications.id=?";
foreach ($session_basket as $id)
{
$products_count = 1;
if (count ($products))
{
foreach ($products as $key => $value)
{
if ($value['id'] == $id)
{
$products_count = $products[$key]['products_count'] + $products_count;
$products[$key]['products_count'] = $products_count;
$products[$key]['products_cine_all'] = $products[$key]['cine'] * $products_count;
$cineAll = $cineAll + $products[$key]['cine'];
}
}
}
if ($products_count == 1)
{
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$products[$i] = $row;
$products[$i]['cine'] = round ($products[$i]['cine'] - ($products[$i]['cine'] * $products[$i]['sale'] / 100));
$products[$i]['products_count'] = $products_count;
$products[$i]['products_cine_all'] = $products[$i]['cine'] * $products_count;
$cineAll = $cineAll + $products[$i]['products_cine_all'];
$i ++;
}
}
/*
* print"";
* print_r($products);
* print"
";
*/
$this->tpl->assign ('cineAll', $cineAll);
$this->tpl->assign ('cineAll_discount', $cineAll - (($cineAll * $discount) / 100));
$this->tpl->assign ('basket_products', $products); // print_r($products);
}
function BasketUpload (&$session_basket, $proructs_count)
{
// ========== ZLODEYEV ============
foreach ($proructs_count as $key => $value)
{
// ==== îáíîâëÿåì ====
// Âûáèðàåì èíôî î òîâàðå
$sql4 = "SELECT * FROM catalogs_modifications as m
LEFT JOIN catalogs_products as p
ON p.id=m.product_id
WHERE m.id='" . $key . "' ";
$result4 = mysql_query ($sql4) or die (mysql_error ());
if (mysql_affected_rows () != 0)
{
$item = mysql_fetch_assoc ($result4);
}
$f = 0;
if (isset ($_SESSION['shopcart']))
{
foreach ($_SESSION['shopcart'] as $i => $cart)
{
if ($cart['code'] != '' && $cart['code'] == $key)
{
$f = 1;
$_SESSION['shopcart'][$i]['count'] = $value;
$_SESSION['shopcart'][$i]['total'] = $value * $_SESSION['shopcart'][$i]['price'];
if ($_SESSION['shopcart'][$i]['total'] == 0)
{
unset ($_SESSION['shopcart'][$i]);
}
break;
}
}
}
}
// ========== ZLODEYEV ============
$session_basket = array ();
foreach ($proructs_count as $key => $value)
{
for ($i = 0; $i < $value; $i ++)
{
$session_basket[] = $key;
}
}
}
function sendOrder ($data)
{
$mail = new PHPMailer ();
$mail->CharSet = "windows-1251";
$mail->From = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
$mail->FromName = $data['order_name'];
$mail->AddAddress ("shop@eltrade.com.ua", "shop");
$mail->Subject = "Îôîðìèòü çàêàç ñ ÝêñòðèìÑòèëü";
$title = Mail::str_rus ("Îôîðìèòü çàêàç");
$msg = "";
foreach ($data['product_id'] as $key => $value)
{
$msg .= "ID: " . $value . " ";
$msg .= "Íàçâàíèå: " . $data['product_name'][$key] . " ";
$msg .= "Öåíà çà îäèí: " . $data['product_cine'][$key] . " ";
$msg .= "Êîëè÷åñòâî: " . $data['product_count'][$key] . " ";
$msg .= "Çà âåñü òîâàð: " . $data['product_cine_all'][$key] . " ";
$msg .= "
";
}
$msg .= "Îáùàÿ ñóìà: " . $data['cineAll'];
$msg .= "
";
/*
* $msg .= "Ñêèäêà: ".$data['discount']." %";
* $msg .= "
";
*/
$msg .= "Èòîãî ê îïëàòå: " . $data['cineAll_discount'];
$msg .= "
";
$msg .= "Êîíòàêòíûå äàííûå:";
$msg .= "
";
$msg .= "Èìÿ: " . $data['order_name'];
$msg .= "
";
$msg .= "Àäðåñ: " . $data['order_adress'];
$msg .= "
";
$msg .= "E-mail: " . $data['order_email'];
$msg .= "
";
$msg .= "Êîíòàêòíûé òåëåôîí: " . $data['order_phone'];
// $msg .= "
";
// $msg .= "Ìîáèëüíûé òåëåôîí: ".$data['order_phonemob'];
$msg .= "
";
$msg .= "Êîììåíòàðèé: " . $data['order_comment'];
// $order_email = (strlen($data['order_email'])>0) ? $data['order_email'] : "vapila@vapila.kiev.ua";
// Mail::send("borisenko.pavel@gmail.com",$data['order_email'],$title,Mail::str_rus($msg));
$mail->MsgHTML ($msg);
if (! $mail->Send ())
{
echo "There has been a mail error sending to
";
return false;
}
$mail->ClearAddresses ();
$mail->ClearAttachments ();
$this->sendOrderXML ($data);
}
function sendOrderXML ($data)
{
$data['order_phone'] = str_replace ("-", "", $data['order_phone']);
$data['order_phone'] = str_replace (")", "", $data['order_phone']);
$data['order_phone'] = str_replace ("(", "", $data['order_phone']);
$data['order_phone'] = str_replace (" ", "", $data['order_phone']);
$ffffffff = substr ($data['order_phone'], 0, 3);
if ($ffffffff != "380")
$data['order_phone'] = "+38" . $data['order_phone'];
$mail = new PHPMailer ();
$mail->CharSet = "windows-1251";
$mail->From = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
$mail->FromName = $data['order_name'];
$mail->AddAddress ("extremshop@portal.myoffice.biz.ua", "extremshop");
$mail->Subject = "xml çàêàç ñ ÝêñòðèìÑòèëü";
$order_email = (strlen ($data['order_email']) > 0) ? $data['order_email'] : "shopextremstyle2@gmail.com";
$xml = '';
$xml .= '';
foreach ($data['product_id'] as $key => $value)
{
$xml .= "";
$xml .= "" . $data['product_name2'][$key] . "";
$xml .= "" . $data['product_size'][$key] . "";
$xml .= "" . $data['product_color'][$key] . "";
$xml .= "" . $data['product_price'][$key] . "";
$xml .= "" . $data['product_count'][$key] . "";
$xml .= "";
}
$xml .= '';
$xml .= '' . $data['order_name'] . '';
$xml .= '' . $data['order_phone'] . '';
$xml .= '' . $data['order_email'] . '';
$xml .= '';
$xml .= '';
$xml .= 'Óêðàèíà';
$xml .= '' . $data['order_adress'] . '';
$xml .= 'Äîñòàâêà';
$xml .= '';
$xml .= '' . $data['order_comment'] . '';
$xml .= '';
$tmpfname = tempnam ("tmp", "FOO");
$handle = fopen ($tmpfname, "w");
fwrite ($handle, $xml);
$mail->AddAttachment ($tmpfname, 'order.xml');
if (! $mail->Send ())
{
echo "There has been a mail error sending to
";
return false;
}
fclose ($handle);
unlink ($tmpfname);
$mail->ClearAddresses ();
$mail->ClearAttachments ();
// Mail::send("borisenko.pavel@gmail.com",$order_email,"Order",Mail::str_rus($xml));
// Mail::send("andrey.belyy@gmail.com",$order_email,"Order",Mail::str_rus($xml));
}
function saveOrder ($data, $userID = 0)
{
$table_name = "catalogs_orders";
if (isset ($data['update_id']) && $data['update_id'] > 0)
{
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$id = $data['update_id'];
$where = sprintf ("id='%d'", $id);
}
else
{
$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
$id = $this->db->nextId ('mySequence_' . $table_name);
$where = null;
}
$fields_values = array (
'id' => $id,
'user_id' => $userID,
'name' => $data['order_name'],
'email' => $data['order_email'],
'adress' => $data['order_adress'],
// 'phone' => phone_mobil($data['order_phone']),
'phone' => $data['order_phone'],
'comment' => $data['order_comment'],
'delivery' => $data['delivery'],
'total' => $_SESSION['cart']['total'],
'status' => '1',
'mktime' => mktime ()
);
$DB_AUTOQUERY;
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, $where);
if (isset ($data['product_id']))
{
$i = - 1;
foreach ($data['product_id'] as $key => $value)
{
$i ++;
$this->db->autoExecute ("catalogs_orders_products", array (
'order_id' => $id,
'product_id' => $value,
'product_cine_id' => $_SESSION['cart'][$i]['price'],
'count' => $data['product_count'][$key]
), DB_AUTOQUERY_INSERT);
}
}
}
function deleteOrder ($id)
{
$this->db->query ("delete from catalogs_orders where id=?", array (
$id
));
$this->db->query ("delete from catalogs_orders_products where order_id=?", array (
$id
));
}
function updateOrder ($data)
{
$table_name = "catalogs_orders";
$fields_values = array (
'name' => $data['order_name'],
'email' => $data['order_email'],
'adress' => $data['order_adress'],
'phone' => $data['order_phone'],
'comment' => $data['order_comment'],
'mktime' => mktime ()
);
if (isset ($data['order_active']))
$fields_values['active'] = 1;
else
$fields_values['active'] = 0;
$this->db->autoExecute ($table_name, $fields_values, DB_AUTOQUERY_UPDATE, sprintf ("id='%d'", $data['update_id']));
}
function updateOrderProducts ($data)
{
foreach ($data['product_id'] as $key => $value)
{
if ($data['product_count'][$value] < 1)
{
$this->db->query ("delete from catalogs_orders_products where order_id='{$data['order_id']}' AND product_id='$value'");
}
else
{
$this->db->autoExecute ("catalogs_orders_products", array (
'count' => $data['product_count'][$value]
), DB_AUTOQUERY_UPDATE, "order_id='{$data['order_id']}' AND product_id='$value'");
}
}
}
function viewOrder ($id)
{
$row = $this->db->getRow ("select * from catalogs_orders where id=?", array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('order', $row);
}
function viewOrderProducts ($order_id)
{
$res = $this->db->getAll ("select p.*,op.*,pr.name,pr.pic,pr.pic_big from catalogs_orders_products op Left join catalogs_products_cine p On p.id=op.product_id Left join catalogs_products pr On pr.id=p.product_id where order_id=?", array (
$order_id
), DB_FETCHMODE_ASSOC);
$sum = 0;
foreach ($res as $key => $row)
{
$sum = $sum + ($row['cine'] * $row['count']);
$res[$key]['cine_all'] = ($row['cine'] * $row['count']);
}
$discount = $this->db->getOne ('select catalogs_users.discount from catalogs_orders Left join catalogs_users on catalogs_users.id=user_id where catalogs_orders.id=?', array (
$order_id
));
$this->tpl->assign ('cine', array (
'sum' => $sum,
'discount' => $discount,
'sum_discount' => ($sum - (($sum * $discount) / 100))
));
$this->tpl->assign ('basket_products', $res);
}
function viewOrders ($params = array())
{
$search = array ();
if (isset ($params['userID']) && $params['userID'] > 0)
$search[] = sprintf ("catalogs_orders.user_id='%d'", $params['userID']);
$sql = "select catalogs_orders.*,catalogs_users.login as user_login,catalogs_users.discount from catalogs_orders Left join catalogs_users on catalogs_users.id=user_id WHERE 1=1 ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= " order by mktime desc";
$pagerOptions = Array (
'mode' => 'Sliding',
'delta' => 16,
'perPage' => 50,
'linkClass' => "link_class",
'curPageLinkClassName' => "link_class_active",
'spacesBeforeSeparator' => 1,
'spacesAfterSeparator' => 1
);
$res = Pager_Wrapper_DB ($this->db, $sql, $pagerOptions, false, DB_FETCHMODE_ASSOC, array ());
foreach ($res['data'] as $key => $value)
{
$res['data'][$key]['sum'] = $this->getOrderProductsSum ($value['id']);
$res['data'][$key]['sum_discount'] = $res['data'][$key]['sum'] - (($res['data'][$key]['sum'] * $value['discount']) / 100);
}
$this->tpl->assign ('ordersData', $res);
}
function getOrderProductsSum ($order_id)
{
$res = $this->db->getAll ("select op.*,p.cine from catalogs_orders_products op Left join catalogs_products_cine p On p.id=op.product_id where op.order_id=?", array (
$order_id
), DB_FETCHMODE_ASSOC);
// print_r($res);
$sum = 0;
foreach ($res as $row)
{
$sum = $sum + ($row['cine'] * $row['count']);
}
return $sum;
}
function SaveBrend ($data, $upload)
{
$table_name = "catalogs_brends";
$DB_AUTOQUERY = ($data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array (
'rubric_id' => $data['rubric_id'],
'name' => $data['brend'],
'email' => $data['email'],
'text' => $data['text_setka'],
'youtube' => $data['youtube'],
'seo' => $data['seo_text'],
'sort' => $data['sort'],
'meta_title' => $data['meta_title'],
'meta_description' => $data['meta_description'],
'meta_keywords' => $data['meta_keywords'],
'active' => $data['active'],
'about' => $data['about'],
'link' => $data['link'],
'teh' => $data['teh']
);
if (isset ($data['delete_video']) && $data['delete_video'] == 1)
{
$this->deleteBrendPic ($data['update_id']);
$fields_values['pic'] = null;
}
if ($upload['pic']['tmp_name'])
{
if ($data['update_id'] > 0)
$this->deleteBrendPic ($data['update_id'], array (
'pic'
));
$name_pic = mktime () . "." . substr (strrchr ($_FILES['pic']['name'], "."), 1);
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/$name_pic";
move_uploaded_file ($_FILES["pic"]["tmp_name"], $file_name);
chmod ($file_name, "0777");
$fields_values['pic'] = $name_pic;
}
if (isset ($data['delete_pic_s']) && $data['delete_pic_s'] == 1)
{
$this->deleteBrendPic ($data['update_id'], array (
'pic_s'
));
$fields_values['pic_s'] = null;
}
if ($upload['pic_s']['tmp_name'])
{
if ($data['update_id'] > 0)
$this->deleteBrendPic ($data['update_id'], array (
'pic_s'
));
$name_pic = mktime () . "." . substr (strrchr ($_FILES['pic_s']['name'], "."), 1);
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/$name_pic";
move_uploaded_file ($_FILES["pic_s"]["tmp_name"], $file_name);
chmod ($file_name, "0777");
$fields_values['pic_s'] = $name_pic;
}
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
}
function deleteBrendPic ($id, $pics = array('pic','pic_s'))
{
$sql = "select " . implode (',', $pics) . " from catalogs_brends where id=?";
$row = $this->db->getRow ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
if (isset ($row['pic']))
{
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/{$row['pic']}";
@unlink ($file_name);
}
if (isset ($row['pic_s']))
{
$file_name = "{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/brends/s/{$row['pic_s']}";
@unlink ($file_name);
}
}
function viewBrends ($type = false)
{
$sql = "select b.*,r.name as rubric from catalogs_brends b left join catalogs_rubrics r On r.id=b.rubric_id ";
if ($type != false)
$sql .= "where b.type='$type'";
$sql .= " Order by b.name Asc";
$row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('brends', $row);
}
function viewBrendsGroup ($params = array())
{
$search = array ();
if (isset ($params['filter']) && count ($params['filter']) > 0)
$filter = $this->seralizeFilter ($params['filter']);
if (isset ($params['filter_products']) && strlen ($params['filter_products']) > 0 && ! isset ($filter['f']))
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . $params['filter_products'] . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("catalogs_products.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("catalogs_products.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("catalogs_products.akcii_id>'%d'", 0);
/*
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("catalogs_products.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "s.sex IN (" . implode (",", $sex) . ")";
}
// ==== catalogs_products ====
$sql[] = "
SELECT *
FROM catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=catalogs_products.id
LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=catalogs_products.id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=catalogs_products.id and catalogs_modifications.active=1
LEFT JOIN catalogs_modifications m2 ON m2.product_id=catalogs_products.id and m2.active=1
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=catalogs_products.id
WHERE catalogs_products.count_modifications > 0
AND catalogs_brends.id > 0
";
if (count ($search))
{
$sql[] = "AND " . implode (" AND ", $search) . " ";
}
if (isset ($params['rubID']) && ! isset ($params['filter_products']))
{
$rubric_id = $params['rubID']; // $this->getRubricParent($params['rubID']);
$rubric_id = ($rubric_id == 0) ? $params['rubID'] : $rubric_id;
$sql[] = "and catalogs_products.rubric_id='" . $rubric_id . "'";
}
$sql[] = " Group by catalogs_brends.name Order by catalogs_brends.name Asc";
if (count ($sql) > 4)
{
$row = $this->db->getAll (implode (' ', $sql), array (), DB_FETCHMODE_ASSOC);
}
else
{
// çíà÷èò ñòðàíèöà
$row = array ();
}
$this->tpl->assign ('brends', $row);
}
// =====
function viewBrendsActive ()
{
$sql = "select * from catalogs_brends where active=1 ";
$sql .= " Order by name Asc";
$row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('brends_a', $row);
}
function SaveCity ($data)
{
$table_name = "catalogs_cities";
$DB_AUTOQUERY = (isset ($data['update_id']) && $data['update_id'] > 0) ? DB_AUTOQUERY_UPDATE : DB_AUTOQUERY_INSERT;
$fields_values = array (
'name' => $data['name']
);
$this->db->autoExecute ($table_name, $fields_values, $DB_AUTOQUERY, "id={$data['update_id']}");
return mysql_insert_id ();
}
function is_city ($name)
{
return $this->db->getOne ('select id from catalogs_cities where name=?', array (
$name
));
}
function viewCityMod ($code)
{
$sql = "select c.name from catalogs_keys_products_cities k left join catalogs_cities c on c.id=k.city_id where k.mod_code=? and k.count>0";
$row = $this->db->getCol ($sql, "name", array (
$code
));
if (! count ($row))
return "";
if (count ($row) == 1 && trim ($row[0]) == '')
{
return "";
}
foreach ($row as $key => $value)
{
if ($value == "Èíòåðíåò ìàãàçèí" or $value == "Êèåâ(Îëèìïèéñêèé)" or $value == "Ëüâîâ" or trim ($value) == "")
unset ($row[$key]);
}
$row2 = array ();
foreach ($row as $key => $value)
if (trim ($value) != '')
$row2[] = $value;
$row = $row2;
$l = array ();
for ($i = 0; $i < count ($row); $i ++)
{
$key = 0;
for ($i2 = 0; $i2 < count ($l); $i2 ++)
if ($l[$i2] == $row[$i])
$key = 1;
if ($key == 0)
$l[] = $row[$i];
}
if (trim ($_REQUEST['test2']) != '1')
{
return implode (', ', $l);
}
return implode (', ', $row);
}
function viewCitiesProductID ($id)
{
$sql = "select city_id from catalogs_keys_products_cities where product_id=?";
$row = $this->db->getCol ($sql, "city_id", array (
$id
));
$this->tpl->assign ('product_cities', $row);
}
function viewCities ($type = false)
{
$sql = "select * from catalogs_cities ";
$sql .= " Order by name Asc";
$row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('cities', $row);
}
function viewCitiesProduct ($id)
{
$sql = "select catalogs_cities.* from catalogs_keys_products_cities left join catalogs_cities on catalogs_cities.id=catalogs_keys_products_cities.city_id Where catalogs_keys_products_cities.product_id=?";
$row = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('cities', $row);
}
function viewCity ($id)
{
$row = $this->db->getRow ("select * from catalogs_cities where id=?", array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('city', $row);
}
function deleteCity ($id)
{
$this->db->query ("delete from catalogs_cities where id=?", array (
$id
));
$this->delete_keysCitiesProduct ($id);
}
function delete_keysCitiesProduct ($id)
{
$sql = "delete from catalogs_keys_products_cities where city_id=?";
$this->db->query ($sql, array (
$id
));
}
function SaveYears ($data)
{
$table_name = "catalogs_years";
foreach ($data['filter'] as $key => $name)
{
if (strlen ($name) > 0)
{
if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0)
{
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$where = "id='{$data['update_id'][$key]}'";
}
else
{
$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
$where = "";
}
$this->db->autoExecute ($table_name, array (
'name' => $name,
'rubric_id' => $data['rubric_id']
), $DB_AUTOQUERY, $where);
}
}
}
function viewYearsProduct ($id)
{
$sql = "select y.* from catalogs_keys_products_years k LEFT JOIN catalogs_years y ON y.id=k.year_id where k.product_id=?";
$row = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('product_years', $row);
}
function viewYearsProductID ($id)
{
$sql = "select year_id from catalogs_keys_products_years where product_id=?";
$row = $this->db->getCol ($sql, "year_id", array (
$id
));
$this->tpl->assign ('product_years', $row);
}
function viewYears ($rubric_id, $filters = null)
{
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("p.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("p.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("p.akcii_id>'%d'", 0);
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
/**
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "s.sex IN (" . implode (",", $sex) . ")";
}
if (strlen ($filters) > 0 && ! isset ($filter['f']))
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")";
}
$sql = "
SELECT y.*
FROM catalogs_products p, catalogs_keys_products_years k
LEFT JOIN catalogs_years y ON y.id=k.year_id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1
LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id
WHERE p.id=k.product_id
AND p.count_modifications>0
";
if ($filters == null)
$sql .= " and p.rubric_id='" . $rubric_id . "' ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= " GROUP BY k.year_id order by y.name desc";
// print $sql;
$row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('years', $row);
}
function viewYearsAll ($rubric_id)
{
$sql = "SELECT * FROM catalogs_years WHERE rubric_id=? ORDER BY id asc ";
$row = $this->db->getAll ($sql, array (
$rubric_id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('years', $row);
}
function viewSexProduct ($id)
{
$sql = "select * from catalogs_keys_products_sex where product_id=?";
$row = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('product_sex', $row);
}
function viewSexProductID ($id)
{
$sql = "select sex from catalogs_keys_products_sex where product_id=?";
$row = $this->db->getCol ($sql, "sex", array (
$id
));
$this->tpl->assign ('product_sex', $row);
}
function viewSex ($rubric_id, $filters = null, $lang = 'rus')
{
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("p.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("p.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("p.akcii_id>'%d'", 0);
if (strlen ($filters) > 0 && ! isset ($filter['f']))
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . $filters . ")";
}
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
$sql = "
SELECT s.sex
FROM catalogs_products p
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=p.id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=p.id and catalogs_modifications.active=1
LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
WHERE p.count_modifications>0
AND s.sex < 4
AND p.sex > 0
";
if ($filters == null)
$sql .= " and p.rubric_id='" . $rubric_id . "' ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= " GROUP BY s.sex";
// print $sql;
$res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
// print_r($res);
$sex = array ();
if ($lang == 'ukr')
$arr = array (
1 => array (
'name' => "×îëîâ³÷èé",
'link' => 'male'
),
2 => array (
'name' => "Ƴíî÷èé",
'link' => 'female'
),
3 => array (
'name' => "Äèòÿ÷èé",
'link' => 'child'
)
);
// 4=>array('name'=>"Óí³ñåêñ",'link'=>'unisex')
else
$arr = array (
1 => array (
'name' => "Ìóæñêîé",
'link' => 'male'
),
2 => array (
'name' => "Æåíñêèé",
'link' => 'female'
),
3 => array (
'name' => "Äåòñêèé",
'link' => 'child'
)
);
// 4=>array('name'=>"Óíèñåêñ",'link'=>'unisex')
foreach ($res as $row)
{
$sex[] = $arr[$row['sex']];
}
if (isset ($_GET['s']))
print_r ($sex);
$this->tpl->assign ('sex', $sex);
}
function getYearsName_IDs ($ids)
{
// $sql = "select name from catalogs_years where id in (".implode(",",$ids).") order by name";
// $row = $this->db->getCol($sql,"name",array());
// return implode(", ",$row);
$name = array ();
foreach ($ids as $id)
{
$name[] = $this->db->getOne ("select name from catalogs_years where id=$id", array ());
}
return implode (", ", $name);
}
function deleteYearsRubric_id ($id)
{
$this->db->query ("delete from catalogs_years where rubric_id=?", array (
$id
));
$this->delete_keysYearsRubric ($id);
}
function delete_keysYearsRubric ($id)
{
$sql = "delete from catalogs_keys_products_years where rubric_id=?";
$this->db->query ($sql, array (
$id
));
}
function deleteYear ($id)
{
$this->db->query ("delete from catalogs_years where id=?", array (
$id
));
$this->delete_keysYearsProduct ($id);
}
function delete_keysYearsProduct ($id)
{
$sql = "delete from catalogs_keys_products_years where year_id=?";
$this->db->query ($sql, array (
$id
));
}
function SaveFilters ($data)
{
$table_name = "catalogs_filters";
foreach ($data['filter'] as $key => $name)
{
if (strlen ($name) > 0)
{
if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0)
{
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$where = "id='{$data['update_id'][$key]}'";
}
else
{
$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
$where = "";
}
$active = (isset ($data['active'][$key])) ? 1 : 0;
$fields = array (
'name' => $name,
"name_ukr" => $data['filter_ukr'][$key],
'prefix' => encodestring ($name),
'rubric_id' => $data['rubric_id'],
"ph1" => $data['ph1'][$key],
"ph1_ukr" => $data['ph1_ukr'][$key],
"sort" => $data['sort'][$key],
"active" => $active
);
if (isset ($data['cat'][$key]))
{
$fields['cat'] = $data['cat'][$key];
}
$this->db->autoExecute ($table_name, $fields, $DB_AUTOQUERY, $where);
}
}
}
function viewFilterProduct ($id)
{
$sql = "select f.* from catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where f.active='0' and k.product_id=?";
$row = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('product_filters', $row);
return $row;
}
function viewFilterProductID ($id)
{
$sql = "select filter_id from catalogs_keys_products_filters where product_id=?";
$row = $this->db->getCol ($sql, "filter_id", array (
$id
));
$this->tpl->assign ('product_filters', $row);
}
function deleteFilter ($id)
{
$this->db->query ("delete from catalogs_filters where id=?", array (
$id
));
$this->delete_keysFilterProduct ($id);
}
function deleteFiltersRubric_id ($rubric_id)
{
$this->db->query ("delete from catalogs_filters where rubric_id=?", array (
$rubric_id
));
$this->delete_keysFilterRubric ($rubric_id);
}
function delete_keysFilterProduct ($id)
{
$sql = "delete from catalogs_keys_products_filters where filter_id=?";
$this->db->query ($sql, array (
$id
));
}
function delete_keysFilterRubric ($id)
{
$sql = "delete from catalogs_keys_products_filters where rubric_id=?";
$this->db->query ($sql, array (
$id
));
}
function viewFilters ($rubric_id, $all = false, $lang = 'ru')
{
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['g']) && count ($filter['g']) > 0)
{
$search[] = "catalogs_keys_products_filters2.filter_id in (" . implode (",", $filter['g']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("p.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("p.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("p.akcii_id>'%d'", 0);
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
/*
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "s.sex IN (" . implode (",", $sex) . ")";
}
$sql = "
SELECT f.*,f.name" . ($lang == 'ukr' ? '_ukr' : '') . " as name,f.h1" . ($lang == 'ukr' ? '_ukr' : '') . " as h1
FROM catalogs_products p, catalogs_keys_products_filters k
LEFT JOIN catalogs_filters f ON f.id=k.filter_id
LEFT JOIN catalogs_keys_products_filters2 ON catalogs_keys_products_filters2.product_id=k.product_id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1
LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id
WHERE p.id=k.product_id
AND p.count_modifications>0
";
// $sql = "select * from catalogs_filters where 1=1 ";
if ($all == false)
$sql .= "and f.active='0' ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc";
// print $sql;
$row = $this->db->getAll ($sql, array (
$rubric_id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('filters', $row);
}
function viewFiltersAll ($rubric_id)
{
$row = $this->db->getAll ("select * from catalogs_filters where rubric_id=? order by sort", array (
$rubric_id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('filters', $row);
}
function getFiltersName_IDs ($ids, $lang)
{
// $sql = "select name from catalogs_filters where id in (".implode(",",$ids).")";
// $row = $this->db->getCol($sql,"name",array());
$name = array ();
foreach ($ids as $id)
{
$row = $this->db->getRow ("select h1" . ($lang == 'ukr' ? '_ukr' : '') . " as h1 from catalogs_filters where id=$id", array (), DB_FETCHMODE_ASSOC);
$name[] = ((strlen ($row['h1']) > 0) ? $row['h1'] : $row['name']);
}
return implode (", ", $name);
}
function getFilters2Name_IDs ($ids)
{
// $sql = "select name from catalogs_filters where id in (".implode(",",$ids).")";
// $row = $this->db->getCol($sql,"name",array());
$name = array ();
foreach ($ids as $id)
{
$row = $this->db->getRow ("select h1,name from catalogs_filters2 where id=$id", array (), DB_FETCHMODE_ASSOC);
$name[] = ((strlen ($row['h1']) > 0) ? $row['h1'] : $row['name']);
}
// print_r($name);
return implode (", ", $name);
}
function SaveFilters2 ($data)
{
$table_name = "catalogs_filters2";
foreach ($data['filter2'] as $key => $name)
{
if (strlen ($name) > 0)
{
if (isset ($data['update_id'][$key]) && $data['update_id'][$key] > 0)
{
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$where = "id='{$data['update_id'][$key]}'";
}
else
{
$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
$where = "";
}
$active = (isset ($data['active'][$key])) ? 1 : 0;
$this->db->autoExecute ($table_name, array (
'name' => $name,
"name_ukr" => $data['filter_ukr'][$key],
'prefix' => encodestring ($name),
'rubric_id' => $data['rubric_id'],
"sort" => $data['sort'][$key],
"active" => $active
), $DB_AUTOQUERY, $where);
}
}
}
function viewFilterProductID2 ($id)
{
$sql = "select filter_id from catalogs_keys_products_filters2 where product_id=?";
$row = $this->db->getCol ($sql, "filter_id", array (
$id
));
$this->tpl->assign ('product_filters2', $row);
}
function deleteFilter2 ($id)
{
$this->db->query ("delete from catalogs_filters2 where id=?", array (
$id
));
$this->delete_keysFilterProduct2 ($id);
}
function delete_keysFilterProduct2 ($id)
{
$sql = "delete from catalogs_keys_products_filters2 where filter_id=?";
$this->db->query ($sql, array (
$id
));
}
function deleteFiltersRubric_id2 ($rubric_id)
{
$this->db->query ("delete from catalogs_filters2 where rubric_id=?", array (
$rubric_id
));
$this->delete_keysFilterRubric2 ($rubric_id);
}
function delete_keysFilterRubric2 ($id)
{
$sql = "delete from catalogs_keys_products_filters2 where rubric_id=?";
$this->db->query ($sql, array (
$id
));
}
function viewFilters2 ($rubric_id, $lang = 'ru')
{
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($filter['s']) && count ($filter['s']) > 0)
{
$search[] = "catalogs_modifications.size in (" . implode (",", $filter['s']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("p.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("p.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("p.akcii_id>'%d'", 0);
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
/*
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "s.sex IN (" . implode (",", $sex) . ")";
}
$sql = "
SELECT f.*,f.name" . ($lang == 'ukr' ? '_ukr' : '') . " as name
FROM catalogs_products p, catalogs_keys_products_filters2 k
LEFT JOIN catalogs_filters2 f ON f.id=k.filter_id
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=k.product_id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=k.product_id
LEFT JOIN catalogs_modifications ON catalogs_modifications.product_id=k.product_id and catalogs_modifications.active=1
LEFT JOIN catalogs_modifications m2 ON m2.product_id=k.product_id and m2.active=1
LEFT JOIN catalogs_keys_products_sex s ON s.product_id=k.product_id
WHERE p.id=k.product_id
AND p.count_modifications>0
";
// $sql = "select * from catalogs_filters where 1=1 ";
if ($all == false)
$sql .= "and f.active='0' ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "and f.rubric_id=? GROUP BY k.filter_id order by f.sort asc";
// print $sql;
$row = $this->db->getAll ($sql, array (
$rubric_id
), DB_FETCHMODE_ASSOC);
// $row = $this->db->getAll("select *,f.name".($lang=='ukr'?'_ukr':'')." as name from catalogs_filters2 f where f.active='0' and f.rubric_id=? order by sort",array($rubric_id),DB_FETCHMODE_ASSOC);
$this->tpl->assign ('filters2', $row);
}
function getFiltersMod_IDs ($ids)
{
$name = array ();
foreach ($ids as $id)
{
$name[] = $this->db->getOne ("select size from catalogs_modifications where size=$id", array ());
}
return implode (", ", $name);
}
function viewFiltersMod ($rubric_id)
{
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($filter['r']) && count ($filter['r']) > 0)
{
$search[] = "m2.rost in (" . implode (",", $filter['r']) . ")";
}
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
/*
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "p.sex IN (" . implode (",", $sex) . ")";
}
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("p.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("p.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("p.akcii_id>'%d'", 0);
$sql = "
SELECT m.*
FROM catalogs_modifications m,catalogs_products p
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id
LEFT JOIN catalogs_modifications m2 ON m2.product_id=p.id and m2.active=1
WHERE m.size<>''
";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= "
and m.product_id=p.id
and m.active=1
and p.rubric_id=?
and p.count_modifications>0
and m.size > 0
GROUP BY m.size";
$row = $this->db->getAll ($sql, array (
$rubric_id
), DB_FETCHMODE_ASSOC);
if ($_GET['t'] == 1)
{
print "";
print_r ($row);
print "
";
}
$this->tpl->assign ('size', $row);
}
function viewFiltersRost ($rubric_id)
{
$search = array ();
if (isset ($_GET['filter']) && count ($_GET['filter']) > 0)
$filter = $this->seralizeFilter ($_GET['filter']);
if (isset ($filter['f']) && count ($filter['f']) > 0)
{
$search[] = "catalogs_keys_products_filters.filter_id in (" . implode (",", $filter['f']) . ")";
}
if (isset ($filter['y']) && $filter['y'] > 0)
{
$search[] = "catalogs_keys_products_years.year_id in (" . implode (",", $filter['y']) . ")";
}
if (isset ($_GET['brend']) && strlen ($_GET['brend']) > 0)
$search[] = "p.brend_id in(" . implode (",", $this->getBrendIDs_name ($_GET['brend'])) . ")";
/*
* if(isset($_GET['sex']) && strlen($_GET['sex'])>0){
* $sex = array('male'=>1,'female'=>2,'child'=>3,'unisex'=>4);
* $search[] = sprintf("p.sex='%d'",$sex[$_GET['sex']]);
* }
*/
if (isset ($_GET['sex']) && strlen ($_GET['sex']) > 0)
{
$sex = $this->seralizeSex ($_GET['sex']);
$search[] = "p.sex IN (" . implode (",", $sex) . ")";
}
$sql = "
SELECT m.*
FROM catalogs_modifications m, catalogs_products p
LEFT JOIN catalogs_keys_products_filters ON catalogs_keys_products_filters.product_id=p.id
LEFT JOIN catalogs_keys_products_years ON catalogs_keys_products_years.product_id=p.id
WHERE m.rost > 0";
if (count ($search))
{
$sql .= "AND " . implode (" AND ", $search) . " ";
}
$sql .= "
AND m.product_id=p.id
AND m.active=1
AND p.rubric_id=?
AND p.count_modifications>0
GROUP BY m.rost
";
$row = $this->db->getAll ($sql, array (
$rubric_id
), DB_FETCHMODE_ASSOC);
if ($_GET['t'] == 1)
{
print "";
print_r ($row);
print "
";
}
$this->tpl->assign ('rost', $row);
}
function viewRostProduct ($id)
{
$sql = "select m.* from catalogs_modifications m where m.product_id=? GROUP BY m.rost";
$row = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('product_rost', $row);
}
function viewFiltersInProducts ($filter_products, $lang = 'ru')
{
$search = array ();
if (isset ($_GET['new']) && $_GET['new'] > 0)
$search[] = sprintf ("p.active='%d'", $_GET['new']);
if (isset ($_GET['top']) && $_GET['top'] > 0)
$search[] = sprintf ("p.top='%d'", $_GET['top']);
if (isset ($_GET['akciiID']) && $_GET['akciiID'] > 0)
$search[] = sprintf ("p.akcii_id>'%d'", 0);
$sql = "select f.*,f.name" . ($lang == 'ukr' ? '_ukr' : '') . " as name from catalogs_products p, catalogs_keys_products_filters k LEFT JOIN catalogs_filters f ON f.id=k.filter_id where p.id=k.product_id AND f.id IN (" . $filter_products . ") and f.active='0' ";
if (count ($search))
$sql .= "AND " . implode (" AND ", $search) . " ";
$sql .= 'GROUP BY k.filter_id order by f.sort';
// print $sql;
$row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('filters', $row);
}
function viewBrend ($id)
{
$row = $this->db->getRow ("select * from catalogs_brends where id=?", array (
$id
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('brend', $row);
}
function viewBrendName ($name)
{
$name = iconv ("utf-8", "windows-1251", $name);
$sql = "select * from catalogs_brends where name=? limit 1";
$row = $this->db->getRow ($sql, array (
$name
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('brend_seo', $row);
return $row;
}
function getBrendIDs_name ($name)
{
$n = array ();
$name_arr = explode (";", $name);
foreach ($name_arr as $row)
{
$n[] = "'" . $row . "'";
}
// $name = iconv("utf-8", "windows-1251", $name);
$sql = "select id from catalogs_brends where name in (" . implode (",", $n) . ")";
// print $sql;
return $this->db->getCol ($sql, "id", array ());
}
function viewBrendRubrics ($name, $lang = 'ru')
{
$name = iconv ("utf-8", "windows-1251", $name);
$sql = "
SELECT r.name" . (($lang == 'ukr') ? '_ukr' : '') . " as name,r.parent_id,r.translit,count(p.id) as c
FROM catalogs_brends b
LEFT JOIN catalogs_rubrics r On r.id=b.rubric_id
LEFT JOIN catalogs_products p On p.brend_id=b.id AND p.count_modifications>0
WHERE b.name=?
AND r.name<>''
GROUP BY p.brend_id
";
$res = $this->db->getAll ($sql, array (
$name
), DB_FETCHMODE_ASSOC);
$rubrics = array ();
foreach ($res as $row)
{
if ($row['c'] > 0)
{
$rubrics[$this->getRubricName ($row['parent_id'], $lang)][] = $row;
}
}
// print"";
// print_r($rubrics);
// print"
";
$this->tpl->assign ('brend_rubrics', $rubrics);
}
function deleteBrend ($id)
{
$this->db->query ("delete from catalogs_brends where id=?", array (
$id
));
}
function viewAkciiProductID ($id)
{
$sql = "select rubric_id from catalogs_keys_products_akcii where product_id=?";
$row = $this->db->getCol ($sql, "rubric_id", array (
$id
));
$this->tpl->assign ('product_akcii', $row);
}
function import_saveRubric ($name, $parent_id)
{
$id = $this->db->getOne ("select id from catalogs_rubrics where name=? and parent_id=?", array (
$name,
$parent_id
));
if (! $id)
{
$this->db->autoExecute ("catalogs_rubrics", array (
'name' => $name,
'translit' => translit ($name),
'parent_id' => $parent_id,
"level" => ($this->getLevelRubric ($parent_id) + 1)
), DB_AUTOQUERY_INSERT);
return mysql_insert_id ();
}
return $id;
}
function import_saveBrend ($name, $rubric_id)
{
// getRubricParent();
$id = $this->db->getOne ("select id from catalogs_brends where name=? and rubric_id=?", array (
$name,
$rubric_id
));
if (! $id)
{
$this->db->autoExecute ("catalogs_brends", array (
'rubric_id' => $rubric_id,
'name' => $name
), DB_AUTOQUERY_INSERT);
return mysql_insert_id ();
}
return $id;
}
function import_saveFilters2 ($rubric_id, $str)
{
if (! $str)
return array ();
$row_str = explode (",", trim ($str));
$arr_id = array ();
foreach ($row_str as $str)
{
$name = trim ($str);
$name_r = explode ('=', $name);
$name = $name_r[0];
$active = (isset ($name_r[1])) ? 1 : 0;
$id = $this->db->getOne ("select id from catalogs_filters2 where rubric_id=? and name=?", array (
$rubric_id,
$name
));
if (! $id)
{
$this->db->autoExecute ("catalogs_filters2", array (
'rubric_id' => $rubric_id,
'name' => $name,
'prefix' => encodestring ($name),
'active' => $active
), DB_AUTOQUERY_INSERT);
$id = mysql_insert_id ();
}
else
{
$this->db->autoExecute ("catalogs_filters2", array (
'rubric_id' => $rubric_id,
'name' => $name,
'prefix' => encodestring ($name),
'active' => $active
), DB_AUTOQUERY_UPDATE, "id=$id");
}
$arr_id[] = $id;
}
return $arr_id;
}
function import_saveFilters ($rubric_id, $str)
{
if (! $str)
return array ();
$row_str = explode (",", trim ($str));
$arr_id = array ();
foreach ($row_str as $str)
{
$name = trim ($str);
$name_r = explode ('=', $name);
$name = $name_r[0];
$active = (isset ($name_r[1])) ? 1 : 0;
$id = $this->db->getOne ("select id from catalogs_filters where rubric_id=? and name=?", array (
$rubric_id,
$name
));
if (! $id)
{
$this->db->autoExecute ("catalogs_filters", array (
'rubric_id' => $rubric_id,
'name' => $name,
'prefix' => encodestring ($name),
'active' => $active
), DB_AUTOQUERY_INSERT);
$id = mysql_insert_id ();
}
else
{
$this->db->autoExecute ("catalogs_filters", array (
'rubric_id' => $rubric_id,
'name' => $name,
'prefix' => encodestring ($name),
'active' => $active
), DB_AUTOQUERY_UPDATE, "id=$id");
}
$arr_id[] = $id;
}
return $arr_id;
}
function import_saveYear ($rubric_id, $name)
{
if (! $name)
return false;
$id = $this->db->getOne ("select id from catalogs_years where rubric_id=? and name=?", array (
$rubric_id,
$name
));
if (! $id)
{
$this->db->autoExecute ("catalogs_years", array (
'rubric_id' => $rubric_id,
'name' => $name
), DB_AUTOQUERY_INSERT);
$id = mysql_insert_id ();
}
return ($id) ? array (
$id
) : array ();
}
function import_updateProductCine ($product_id, $row, $line = '', $mktime = 0)
{ // print"";print_r($row);print"
";
IF ($product_id > 0)
{
IF ($row[3] > 0)
{
if ($row[2] < 1)
{
$cine = $row[1];
$cine_last = 0;
}
else
{
$cine = $row[2];
$cine_last = (($row[1] > 0) ? $row[1] : $row[2]);
}
$this->db->autoExecute ("catalogs_products", array (
'cine' => $cine,
'cine_last' => $cine_last
), DB_AUTOQUERY_UPDATE, "id='$product_id'");
}
$city = trim ($row[4]);
if (! $city)
$city = "Èíòåðíåò ìàãàçèí";
// echo "OK(1) -
";
if (strlen ($city) > 0)
{ // print $city;
$city_id = $this->is_city ($city);
// echo "OK(2) -
";
if (! $city_id)
{
$city_id = $this->SaveCity (array (
'name' => $city
));
}
$this->db->query ("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime", array (
$product_id,
$row[0],
$mktime
));
if ($row[3] == 0)
{
}
else
{
// $this->db->query("delete from catalogs_keys_products_cities where product_id=? and mod_code=? and mktime", array($product_id,$row[0],$mktime));
// echo "OK(3) -
";
if ($this->getKeysModificationCity ($row[0], $city_id))
{
$DB_AUTOQUERY = DB_AUTOQUERY_UPDATE;
$where = "mod_code='" . $row[0] . "' and city_id='" . $city_id . "'";
}
else
{
$DB_AUTOQUERY = DB_AUTOQUERY_INSERT;
$where = null;
}
// if($this->getKeysModificationCityMktime_count($row[0], $city_id, $mktime)>0){$row[3]=1;}
// print $city_id .'--'.$where."
";
$fields = array (
'count' => $row[3],
'product_id' => $product_id,
'mod_code' => $row[0],
'city_id' => $city_id,
'mktime' => $mktime
);
$s = $this->db->autoExecute ("catalogs_keys_products_cities", $fields, $DB_AUTOQUERY, $where);
if (PEAR::isError ($s))
die ($s->getMessage ());
}
}
// echo "OK(4) -
";
$active = $this->db->getOne ("select count(*) from catalogs_keys_products_cities where mod_code=? and count>0", array (
$row[0]
));
// $active = true;
if ($this->db->getOne ("select count(*) from catalogs_modifications where code=?", array (
$row[0]
)) > 0)
{
$this->db->autoExecute ("catalogs_modifications", array (
'active' => $active,
'is_update' => 1,
'prefix' => $row[4]
), DB_AUTOQUERY_UPDATE, "code='" . $row[0] . "'");
// echo "OK(5) -
";
}
else
{
// echo "OK(6) -
";
$this->saveCsvMod ($line);
}
}
}
function saveCsvMod ($line)
{
echo "OK1 -
";
$tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/tmp/noDB_mod.csv";
$handle = @fopen ($tmpfname, "a");
// $row = explode(";",$line);
// File_FGetCSV::fputcsv($handle,$row,';');
echo "OK2 -
";
echo $line;
echo "OK3 -
";
fwrite ($handle, $line);
fclose ($handle);
}
function getKeysModificationCity ($code, $city_id)
{
return $this->db->getOne ("select count(*) from catalogs_keys_products_cities where mod_code=? and city_id=?", array (
$code,
$city_id
));
}
function getKeysModificationCity_count ($code, $city_id)
{
return $this->db->getOne ("select count from catalogs_keys_products_cities where mod_code=? and city_id=?", array (
$code,
$city_id
));
}
function getKeysModificationCityMktime_count ($code, $city_id, $mktime)
{
$r = $this->db->getOne ("select count from catalogs_keys_products_cities where mod_code=? and city_id=? and mktime=?", array (
$code,
$city_id,
$mktime
));
return $r;
}
function getProductID ($name)
{
$id = $this->db->getOne ("select id from catalogs_products where name=?", array (
$name
));
return $id;
}
function getProductID_R ($name, $rubric_parent_id)
{
$id = $this->db->getOne ("select id from catalogs_products where name=? and rubric_id=?", array (
$name,
$rubric_parent_id
));
return $id;
}
function getModificationActive ($code)
{
return $this->db->getOne ("select active from catalogs_modifications where code=?", array (
$code
));
}
function updateProduct_countModification ($product_id, $count)
{
$this->db->autoExecute ("catalogs_products", array (
'count_modifications' => $count
), DB_AUTOQUERY_UPDATE, "id='$product_id'");
}
function updateProductModificationCountPrefix ($product_id, $prefix = "+")
{
// print $product_id;
$sql = "UPDATE catalogs_products SET count_modifications = count_modifications $prefix 1 WHERE id =?";
$this->db->query ($sql, array (
$product_id
));
}
function exportCSV ()
{
$tmpfname = "tmp/price.csv";
$handle = fopen ($tmpfname, "w");
// fwrite($handle, $xml);
$res = $this->db->getAll ('select p.id,p.rubric_id,r2.name,r.name,b.name as brend,p.name,p.about,p.text,null,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big,null from catalogs_products p left join catalogs_rubrics r on r.id=p.rubric_id left join catalogs_rubrics r2 on r2.id=p.rubric_parent_id left join catalogs_brends b on b.id=p.brend_id', array ());
foreach ($res as $key => $row)
{
$list = $row;
$mod_res = $this->db->getAll ('select code,size,color,pic_big,active from catalogs_modifications where product_id=? Order by id', array (
$row[0]
));
foreach ($mod_res as $mod_row)
{
$list[] = implode ('=', $mod_row);
}
$f_row = $this->db->getCol ("select f.name from catalogs_keys_products_filters k Left Join catalogs_filters f ON f.id=k.filter_id where k.product_id=?", 'name', array (
$list[0]
));
$list[8] = implode (',', $f_row);
$f_row = $this->db->getCol ("select f.name from catalogs_keys_products_filters2 k Left Join catalogs_filters2 f ON f.id=k.filter_id where k.product_id=?", 'name', array (
$list[0]
));
$list[9] = implode (',', $f_row);
switch ($list[10])
{
case 1 :
$list[10] = 'ìóæñêîé';
break;
case 2 :
$list[10] = 'æåíñêèé';
break;
case 3 :
$list[10] = 'äåòñêèé';
break;
case 4 :
$list[10] = 'óíèñåêñ';
break;
default :
$list[10] = 'ìóæñêîé';
break;
}
$y_row = $this->db->getCol ("select y.name from catalogs_keys_products_years k Left Join catalogs_years y ON y.id=k.year_id where k.product_id=?", 'name', array (
$list[0]
));
$list[11] = implode (',', $y_row);
$p_row = $this->db->getCol ("select pic_big from catalogs_gallery where product_id=?", 'pic_big', array (
$list[0]
));
$list[20] = implode (',', $p_row);
// print_r($list);exit;
$p_res = $this->db->getAll ("select name,size,metka from catalogs_products_params where product_id=? order by id asc", array (
$list[0]
));
$param = array ();
foreach ($p_res as $row_p)
{
$param[] = implode ('*', $row_p);
}
$list[17] = implode ('=', $param);
unset ($list[0]);
unset ($list[1]);
File_FGetCSV::fputcsv ($handle, $list, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'price.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportCSVaktual ()
{
$tmpfname = "tmp/price.csv";
$handle = fopen ($tmpfname, "w");
// fwrite($handle, $xml);
$res = $this->db->getAll ('select p.id,p.rubric_id,r2.name,r.name,b.name as brend,p.name,p.about,p.text,null,null,p.sex,null,p.cine,p.cine_last,p.akcii_id,p.strnumber,p.active,null,p.video_code,p.pic_big,null from catalogs_products p left join catalogs_rubrics r on r.id=p.rubric_id left join catalogs_rubrics r2 on r2.id=p.rubric_parent_id left join catalogs_brends b on b.id=p.brend_id WHERE p.count_modifications>0', array ());
foreach ($res as $key => $row)
{
$list = $row;
$mod_res = $this->db->getAll ('select code,size,rost,color,pic_big,active from catalogs_modifications where product_id=? Order by id', array (
$row[0]
));
foreach ($mod_res as $mod_row)
{
if (strlen ($mod_row[2]) > 0)
$mod_row[1] = $mod_row[1] . '*' . $mod_row[2];
unset ($mod_row[2]);
$list[] = implode ('=', $mod_row);
}
$f_row = $this->db->getCol ("select f.name from catalogs_keys_products_filters k Left Join catalogs_filters f ON f.id=k.filter_id where k.product_id=?", 'name', array (
$list[0]
));
$list[8] = implode (',', $f_row);
$f_row = $this->db->getCol ("select f.name from catalogs_keys_products_filters2 k Left Join catalogs_filters2 f ON f.id=k.filter_id where k.product_id=?", 'name', array (
$list[0]
));
$list[9] = implode (',', $f_row);
switch ($list[10])
{
case 1 :
$list[10] = 'ìóæñêîé';
break;
case 2 :
$list[10] = 'æåíñêèé';
break;
case 3 :
$list[10] = 'äåòñêèé';
break;
case 4 :
$list[10] = 'óíèñåêñ';
break;
default :
$list[10] = 'ìóæñêîé';
break;
}
$y_row = $this->db->getCol ("select y.name from catalogs_keys_products_years k Left Join catalogs_years y ON y.id=k.year_id where k.product_id=?", 'name', array (
$list[0]
));
$list[11] = implode (',', $y_row);
$p_row = $this->db->getCol ("select pic_big from catalogs_gallery where product_id=?", 'pic_big', array (
$list[0]
));
$list[20] = implode (',', $p_row);
// print_r($list);exit;
$p_res = $this->db->getAll ("select name,size,metka from catalogs_products_params where product_id=? order by id asc", array (
$list[0]
));
$param = array ();
foreach ($p_res as $row_p)
{
$param[] = implode ('*', $row_p);
}
$list[17] = implode ('=', $param);
unset ($list[0]);
unset ($list[1]);
File_FGetCSV::fputcsv ($handle, $list, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'price.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportModCSV ()
{
$tmpfname = "tmp/price_mod.csv";
$handle = fopen ($tmpfname, "w");
$res = $this->db->getAll ('select m.code,p.cine,p.cine_last,m.active,null,m.prefix,m.is_update From catalogs_modifications m Left join catalogs_products p on p.id=m.product_id Order by m.id');
foreach ($res as $key => $row)
{
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'file_1.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
$this->db->autoExecute ("catalogs_modifications", array (
'is_update' => 0
), DB_AUTOQUERY_UPDATE);
}
/**
* Ýêñïîðò ñ ðàçáèâêîé íà ÷àñòè
*/
function exportUsersCSV ()
{
set_time_limit(3000);
ini_set('memory_limit', '256M');
$param = array (
'parts' => 1,
'count' => 0,
'start' => 0,
'end' => 0,
'limit' => 0,
'folder' => $_SERVER['DOCUMENT_ROOT'].'/tmp',
'files' => array(),
'zip_name' => 'users.zip',
);
$total = $this->db->getOne ('
SELECT count(id) as total
FROM zlo_users
');
$param['limit'] = round ($total / $param['parts']);
for ($i = 0; $i < $param['parts']; $i++)
{
$param['files'][] = $param['folder'].'/user-'.$i.'.csv';
$param['count'] = $i;
$param['start'] = $i * $param['limit'];
$this->exportUsersFiles ($param);
}
// ==== ZIP ====
$zip = new ZipArchive();
if ($zip->open($param['zip_name'], ZIPARCHIVE::CREATE) === TRUE)
{
foreach ($param['files'] as $i => $file)
{
$content = file_get_contents($file);
$zip->addFromString(pathinfo ($file, PATHINFO_FILENAME).'.csv', $content);
unlink ($file);
}
$zip->close();
if (file_exists ($param['zip_name']))
{
// îòäà¸ì ôàéë íà ñêà÷èâàíèå
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.$param['zip_name'].'"');
readfile($param['zip_name']);
// óäàëÿåì zip ôàéë åñëè îí ñóùåñòâóåò
unlink ($param['zip_name']);
}
}
}
function exportUsersFiles ($param)
{
$tmpfname = $param['files'][$param['count']];
$handle = fopen ($tmpfname, "w");
$sql = '
SELECT
u.id,
u.username,
u.tel,
u.city,
u.email,
g.name,
u.registered,
summary,
u.birthday,
c.card
FROM zlo_users AS u
LEFT JOIN card c ON c.user_id = u.id
LEFT JOIN zlo_users_group AS g ON u.group = g.id
LEFT JOIN (
SELECT user_id AS order_user_id, sum( `total` ) AS `summary`
FROM catalogs_orders
GROUP BY user_id
) o ON u.id = o.order_user_id
LIMIT '.$param['start'].', '.$param['limit'].'
';
$res = $this->db->getAll ($sql);
foreach ($res as $key => $row)
{
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
}
function exportUsersBirdthCSV ()
{
$tmpfname = "tmp/usersBirdth.csv";
$handle = fopen ($tmpfname, "w");
$sql = "SELECT u.id,u.username,u.tel,u.city,u.email,g.name,u.registered,u.birthday,c.card
FROM zlo_users AS u
LEFT JOIN card c ON c.user_id = u.id
LEFT JOIN zlo_users_group AS g ON u.group = g.id
WHERE DAYOFMONTH(u.birthday) >= '19' AND DAYOFMONTH(u.birthday) <= '28' and MONTH(u.birthday) = '10'
";
$res = $this->db->getAll ($sql);
foreach ($res as $key => $row)
{
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'users.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportSeoF1CSV ()
{
$tmpfname = "tmp/seo_f1.csv";
$handle = fopen ($tmpfname, "w");
$res = $this->db->getAll ("select id,name,translit,name_h1 from catalogs_rubrics");
foreach ($res as $key => $row)
{
// $res_b = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
// foreach($res_b as $row_b){
$list = array ();
$f_res = $this->db->getAll ("select id,prefix,name from catalogs_filters where rubric_id=?", array (
$row[0]
));
foreach ($f_res as $f_row)
{
$list[0] = $row[0];
$list[1] = (strlen ($row[3]) > 0) ? $row[3] : $row[1];
$list[2] = $f_row[2];
$list[3] = "http://extremstyle.ua/" . $row[2] . "-catalogs/filter;filter=f" . $f_row[0] . "_" . $f_row[1] . "/";
// $list[4] = $row_b[0];
File_FGetCSV::fputcsv ($handle, $list, ';');
}
// }
}
$res = $this->db->getAll ("select id,name,translit,name_h1 from catalogs_rubrics");
foreach ($res as $key => $row)
{
// $res_b = $this->db->getAll("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id",array($row[0]));
// foreach($res_b as $row_b){
$list = array ();
$f_res = $this->db->getAll ("select b.name from catalogs_products p left join catalogs_brends b on b.id=p.brend_id where p.rubric_id=? group by p.brend_id", array (
$row[0]
));
foreach ($f_res as $f_row)
{
if (! strlen ($f_row[0]))
continue;
$list[0] = $row[0];
$list[1] = (strlen ($row[3]) > 0) ? $row[3] : $row[1];
$list[2] = $f_row[0];
$list[3] = "http://extremstyle.ua/" . $row[2] . "-catalogs/filter;brend=" . $f_row[0] . "/";
// $list[4] = $row_b[0];
File_FGetCSV::fputcsv ($handle, $list, ';');
}
// }
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'seo_f1.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportSeoCSV ()
{
$tmpfname = "tmp/seo.csv";
$handle = fopen ($tmpfname, "w");
$res = $this->db->getAll ('select p.id,p.rubric_id,r.name_h1,null,r.list_name,b.name,p.name,null,p.cine, r.translit,p.translit,r.name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id');
foreach ($res as $key => $row)
{
$row[3] = $this->getFilterPh1 ($row[0]);
if (! strlen ($row[2]))
$row[2] = $row[11];
$row[7] = "http://extremstyle.ua/" . $row[9] . "-catalogs/" . $row[10] . "-" . $row[0] . "/";
unset ($row[9]);
unset ($row[10]);
unset ($row[11]);
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'seo.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportProductsSeoCSV ()
{
$tmpfname = "tmp/products_seo.csv";
$handle = fopen ($tmpfname, "w");
$res = $this->db->getAll ('select r.id,r.name,p.id,p.name,p.cine,r.translit,p.translit,r.list_name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id where b.name=?', array (
'Dakine'
));
foreach ($res as $key => $row)
{
$vowels = array (
"'05",
"'06",
"'07",
"'08",
"'09",
"'10",
"'11",
"'12",
"'13",
"'14",
"'15",
"'16",
"2005",
"2006",
"2007",
"2008",
"2009",
"2010",
"2011",
"2012",
"2013",
"2014",
"2015",
"2016"
);
$row[3] = $this->getFilterPh1 ($row[2]) . ' ' . str_replace ($vowels, "", $row[3]);
$row[8] = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/";
unset ($row[6]);
unset ($row[7]);
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'products_seo.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportProducts2SeoCSV ()
{
$tmpfname = $_SERVER['DOCUMENT_ROOT'] . "/cron/products_seo.csv";
$handle = fopen ($tmpfname, "w");
$sql = 'select r.id,r.name,p.id,p.name,p.cine,r.translit,p.translit,r.list_name From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id LEFT JOIN catalogs_keys_products_years ky ON ky.product_id=p.id LEFT JOIN catalogs_years y ON y.id=ky.year_id where p.count_modifications>0 and b.name=? and y.name in ("2013","2014","2015","2014-2015")';
$res = $this->db->getAll ($sql, array (
'Dakine'
));
foreach ($res as $key => $row)
{
$vowels = array (
"'05",
"'06",
"'07",
"'08",
"'09",
"'10",
"'11",
"'12",
"'13",
"'14",
"'15",
"'16",
"2005",
"2006",
"2007",
"2008",
"2009",
"2010",
"2011",
"2012",
"2013",
"2014",
"2015",
"2016"
);
$row[3] = $this->getFilterPh1 ($row[2]) . ' ' . str_replace ($vowels, "", $row[3]);
$row[8] = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/";
unset ($row[5]);
unset ($row[6]);
unset ($row[7]);
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
}
function exportProductsFeed ()
{
$tmpfname = "tmp/products_feed.csv";
$handle = fopen ($tmpfname, "w");
$sql = 'select r.id,r.name,p.id,p.name,p.cine_last,r.translit,p.translit,r.list_name,p.pic,b.name,p.about,p.cine From catalogs_products p Left join catalogs_rubrics r on r.id=p.rubric_id Left join catalogs_brends b on b.id=p.brend_id where p.count_modifications>0 and p.cine>0';
$res = $this->db->getAll ($sql, array ());
$list = array (
'ID',
'ID2',
'Item title',
'Destination URL',
'Image URL',
'Item subtitle',
'Item description',
'Item category',
'Price',
'Sale price',
'Contextual keywords',
'Item address'
);
File_FGetCSV::fputcsv ($handle, $list, ',');
foreach ($res as $key => $row)
{
$url = "http://extremstyle.ua/" . $row[5] . "-catalogs/" . $row[6] . "-" . $row[2] . "/";
$image = "http://extremstyle.ua/uploaded/pic/catalogs/products/" . $row[8];
$subtitle = $row[1] . ' ' . $row[9];
$list = array (
$row[2],
$row[2] . 'S',
substr ($row[3], 0, 12),
$url,
$image,
substr ($subtitle, 0, 12),
"Ãàðàíòèÿ êà÷åñòâà",
$row[1],
round ($row[11]) . ' UAH',
round ($row[4]) . ' UAH',
$row[1] . ' ' . $row[9]
);
// print_r($list);
unset ($row[5]);
unset ($row[6]);
unset ($row[7]);
File_FGetCSV::fputcsv ($handle, $list, ',');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'products_feed.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function exportOrdersCSV ()
{
$tmpfname = "tmp/orders.csv";
$handle = fopen ($tmpfname, "w");
$res = $this->db->getAll ('select o.id,o.name,o.email,o.adress,o.phone,o.total From catalogs_orders o LEFT JOIN zlo_users u ON u.id=o.user_id WHERE u.`group`=2 order by o.id desc');
foreach ($res as $key => $row)
{
$products = $this->db->getAll ("select p.* from catalogs_orders_products op
LEFT JOIN catalogs_modifications m ON m.code=op.code
LEFT JOIN catalogs_products p ON p.id=m.product_id
where op.order_id=? GROUP BY p.id", array (
$row[0]
), DB_FETCHMODE_ASSOC);
$arr_products = array ();
foreach ($products as $p)
{
$arr_products[] = $p['name'];
}
$row[6] = implode (', ', $arr_products);
File_FGetCSV::fputcsv ($handle, $row, ';');
}
fclose ($handle);
$params = array (
'file' => $tmpfname,
'contenttype' => 'application/xls',
'contentdisposition' => array (
HTTP_DOWNLOAD_ATTACHMENT,
'orders.csv'
),
'cache' => false
);
$error = HTTP_Download::staticSend ($params, false); // îòäà¸ì ôàéë
if ($error === true)
{
// åñëè ôàéë çàãðóæåí óñïåøíî, îáíîâëÿåì äàòó ïîñëåäíåé çàêà÷êè
}
unlink ($tmpfname);
}
function deleteProductParams ($product_id)
{
$sql = "delete from catalogs_products_params where product_id=?";
$this->db->query ($sql, array (
$product_id
));
}
function saveProductParams ($product_id, $pruduct_params)
{
$this->deleteProductParams ($product_id);
$array_params = explode ("=", $pruduct_params);
foreach ($array_params as $row)
{
$arr = explode ('*', $row);
$this->db->autoExecute ("catalogs_products_params", array (
'product_id' => $product_id,
'name' => $arr[0],
'size' => $arr[1],
'metka' => $arr[2]
), DB_AUTOQUERY_INSERT);
}
}
function getProductParams ($product_id)
{
$sql = "select * from catalogs_products_params where product_id=? order by id";
$row = $this->db->getAll ($sql, array (
$product_id
), DB_FETCHMODE_ASSOC);
return $row;
}
function viewProductParams ($product_id)
{
$this->tpl->assign ('params', $this->getProductParams ($product_id));
}
/**
* íóæíî äëÿ ïðîñìîòðà ïîâòîðåíèå ñòðîê â ôàéëå èìïîðòà
*/
function saveTmpProduct ($row, $product_id)
{
if ($product_id > 0)
{
$this->db->autoExecute ("catalogs_tmp_products", array (
'name' => $row[3],
'product_id' => $product_id
), DB_AUTOQUERY_INSERT);
}
}
function clearTmpProduct ()
{
$sql = "TRUNCATE TABLE catalogs_tmp_products";
$this->db->query ($sql, array ());
}
function viewTmpProducts ()
{
$sql = "
SELECT count( name ) AS cn, name
FROM catalogs_tmp_products
GROUP BY name
ORDER BY name";
$row = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ('list', $row);
$this->tpl->assign ('list_total', $this->db->getOne ("
select count(*)
from catalogs_tmp_products
"));
}
function deleteGalleryProduct ($id)
{
$sql = "select * from catalogs_gallery where product_id=?";
$res = $this->db->getAll ($sql, array (
$id
), DB_FETCHMODE_ASSOC);
foreach ($res as $row)
{
@unlink ("{$_SERVER['DOCUMENT_ROOT']}/uploaded/pic/catalogs/products/gallery/{$row['pic']}");
$this->db->query ("delete from catalogs_gallery where id=?", array (
$row['id']
));
}
}
function saveGalleryPics ($product_id, $pruduct_gallery_pics)
{
$this->deleteGalleryProduct ($product_id);
if (strlen ($pruduct_gallery_pics) > 0)
{
$arr = explode (",", $pruduct_gallery_pics);
foreach ($arr as $pic)
{
$pic = trim ($pic);
$id = $this->db->nextId ('mySequence_catalogs_gallery');
$fields_values = array (
'id' => $id,
'name' => $pic,
'product_id' => $product_id
);
$upload['pic'] = array (
'tmp_name' => "./uploaded/pic/catalogs/products/big/$pic",
'name' => $pic
);
$fields_values['pic'] = upload_ImageResize ($upload['pic'], array (
'width' => "100",
'height' => "100",
'upload_path' => "./uploaded/pic/catalogs/products/gallery/"
));
$fields_values['pic_big'] = $pic;
$this->db->autoExecute ("catalogs_gallery", $fields_values, DB_AUTOQUERY_INSERT);
}
}
}
function importCSV ($upload)
{
error_reporting (0);
if ($upload['file']['name'] == "file_1.csv")
{
print "Îøèáêà! Ôàéë öåí!";
exit ();
}
// $arr_line = file($upload['file']['tmp_name']);
$f = fopen ($upload['file']['tmp_name'], "r") or die ("Îøèáêà!");
// print"";
$this->clearTmpProduct ();
for ($i = 0; $row_line = File_FGetCSV::fgetcsv ($f, 15000, ";"); $i ++)
{
// foreach($arr_line as $line){
// $row_line = fgetcsv(";",$line);
$rubric_id = $this->import_saveRubric ($row_line[0], 0);
$rubric_parent_id = $this->import_saveRubric ($row_line[1], $rubric_id);
$brend_id = $this->import_saveBrend ($row_line[2], $rubric_parent_id);
$pruduct_name = trim ($row_line[3]);
$pruduct_about = trim ($row_line[4]);
$pruduct_text = trim ($row_line[5]);
$sex = explode (',', $row_line[8]);
$pruduct_sex = array ();
foreach ($sex as $s)
{
switch (trim ($s))
{
case 'ìóæñêîé' :
$pruduct_sex[] = 1;
break;
case 'æåíñêèé' :
$pruduct_sex[] = 2;
break;
case 'äåòñêèé' :
$pruduct_sex[] = 3;
break;
case 'óíèñåêñ' :
$pruduct_sex[] = 4;
break;
default :
$pruduct_sex[] = array ();
break;
}
}
$pruduct_date = trim ($row_line[9]);
$pruduct_cine = trim ($row_line[10]);
$pruduct_cine_last = trim ($row_line[11]);
if ($pruduct_cine < 1)
{
$pruduct_cine = $pruduct_cine_last;
$pruduct_cine_last = 0;
}
$pruduct_akcii_id = trim ($row_line[12]);
$pruduct_strnumber = trim ($row_line[13]);
$pruduct_active = trim ($row_line[14]);
$pruduct_params = trim ($row_line[15]);
$pruduct_pic_tmp = trim ($row_line[17]);
$pruduct_gallery_pics = trim ($row_line[18]);
$pruduct_video = trim ($row_line[16]);
$pruduct_update_id = $this->getProductID_R ($pruduct_name, $rubric_parent_id);
if ($pruduct_update_id > 0)
{
$row_product = $this->db->getRow ('
select update_text, about, text
from catalogs_products
where id=?', array (
$pruduct_update_id
), DB_FETCHMODE_ASSOC);
// íå îáíîâëÿòü ïðè èìïîðòå?
// 0 - îáíîâëÿòü
// 1 - íå îáíîâëÿòü
if ($row_product['update_text'] == 1)
{
// about - ukr
$pruduct_about = $row_product['about'];
// text - ru
$pruduct_text = $row_product['text'];
}
}
$upload_pruduct = (strlen ($pruduct_pic_tmp) > 0 && is_file ("./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp")) ? array (
'pic' => array (
'tmp_name' => "./uploaded/pic/catalogs/products/big/$pruduct_pic_tmp",
'name' => $pruduct_pic_tmp,
'big' => true
)
) : null;
$product_id = $this->saveProduct (array (
'rubric_id' => $rubric_parent_id,
'rubric_parent_id' => $rubric_parent_id,
'brend_id' => $brend_id,
'name' => $pruduct_name,
'about' => $pruduct_about,
'update_text' => isset ($row_product['update_text']) ? $row_product['update_text'] : 0,
'text' => $pruduct_text,
'video_code' => $pruduct_video,
'sex' => $pruduct_sex,
'date' => $pruduct_date,
'cine' => $pruduct_cine,
'cine_last' => $pruduct_cine_last,
'akcii_id' => $pruduct_akcii_id,
'strnumber' => $pruduct_strnumber,
'active' => $pruduct_active,
'meta_title' => $pruduct_name,
'meta_description' => $pruduct_name,
'meta_keywords' => $pruduct_name,
'meta_about' => $pruduct_name,
'filter' => $this->import_saveFilters ($rubric_parent_id, $row_line[6]),
'filter2' => $this->import_saveFilters2 ($rubric_parent_id, $row_line[7]),
'years' => $this->import_saveYear ($rubric_parent_id, $pruduct_date),
'akcii' => array (),
'update_id' => $pruduct_update_id
), $upload_pruduct);
// print $pruduct_update_id;exit;
$this->saveProductParams ($product_id, $pruduct_params);
$this->saveGalleryPics ($product_id, $pruduct_gallery_pics);
// íå óäàëÿåì !
// $this->deleteProductModifications ($product_id, true);
$m_i = 0;
for ($i = 19; $i < count ($row_line); $i ++)
{
$arr_mod = trim ($row_line[$i]);
if (strlen ($arr_mod) > 0)
{
$row_mod = explode ("=", $arr_mod);
$upload_mod = (strlen ($row_mod[3]) > 0 && is_file ("./uploaded/pic/catalogs/modifications/big/" . $row_mod[3])) ? array (
'pic' => array (
'tmp_name' => "./uploaded/pic/catalogs/modifications/big/" . $row_mod[3],
'name' => $row_mod[3],
'big' => true
)
) : null;
$size_mod = explode ("*", $row_mod[1]);
$rost = (isset ($size_mod[1])) ? $size_mod[1] : '';
// íàõîäèì modifications_id
$modifications_id = $this->getModification ($product_id, $row_mod[0]);
// ñîõðàíÿåì
$this->SaveModification (array (
'product_id' => $product_id,
'code' => $row_mod[0],
'size' => $size_mod[0],
'rost' => $rost,
'color' => $row_mod[2],
'active' => $row_mod[4],
'update_id' => (int) $modifications_id
), $upload_mod);
if ($row_mod[4] > 0)
{
$m_i ++;
}
}
}
$this->updateProduct_countModification ($product_id, $m_i);
// $this->import_saveFilters($product_id,$rubric_parent_id,$row_line[6]);
// $strnumber = $this->getProductID($row_line[3]); $this->save_keysProductsFilters($id,$data);
// print_r($row_line);
$this->saveTmpProduct ($row_line, $product_id);
if (($i % 30) == 0)
{
sleep (1);
}
}
// print"
";
}
function importCSV_cine ($upload)
{
if ($upload['file']['name'] != "file_1.csv")
{
print "Îøèáêà! Òîëüêî file_1.csv";
exit ();
}
$arr_line = file ($upload['file']['tmp_name']);
// print"";
$i = 0;
$mktime = mktime ();
foreach ($arr_line as $line)
{
$row_line = explode (";", $line);
$this->import_updateProductCine ($this->getModificationProduct_id ($row_line[0]), $row_line, $line, $mktime);
if (($i % 30) == 0)
{
sleep (1);
}
$i ++;
}
}
function loadCSV_cine ($upload)
{
if ($upload['file']['name'] != "file_1.csv")
{
print "Îøèáêà! Òîëüêî file_1.csv";
exit ();
}
$file = $_SERVER['DOCUMENT_ROOT'] . "/cron/file_1.csv";
// echo $file;
// exit;
move_uploaded_file ($upload['file']['tmp_name'], $file);
}
function is_loadCSV_cine ()
{
$is = is_file ($_SERVER['DOCUMENT_ROOT'] . '/cron/file_1.csv');
$this->tpl->assign ('is', $is);
}
function CronImportCSV_cine ($upload)
{
$this->importCSV_cine ($upload);
}
function updateCountModificationProducts ()
{
$res = $this->db->getAll ("
select id
from catalogs_products
", array (), DB_FETCHMODE_ASSOC);
$i = 0;
foreach ($res as $row)
{
$count = $this->db->getOne ("
select count(*)
from catalogs_modifications
where product_id=? and active>0", array (
$row['id']
));
$this->db->autoExecute ("catalogs_products", array (
'count_modifications' => $count
), DB_AUTOQUERY_UPDATE, "id='" . $row['id'] . "'");
$i ++;
}
}
function config_update ($id, $value)
{
$this->db->autoExecute ("catalogs_config", array (
'value' => $value
), DB_AUTOQUERY_UPDATE, "id='" . $id . "'");
}
function view_config_value ($id)
{
$r = $this->db->getOne ("select value from catalogs_config where id=?", $id);
$this->tpl->assign ("config", $r);
return $r;
}
function addViewProduct ($product_id)
{
$i = 0;
foreach ($_SESSION['view_product'] as $id)
{
if ($product_id == $id)
$i ++;
}
if ($i == 0)
$_SESSION['view_product'][] = $product_id;
}
function viewUserProducts ($limit = "all")
{ // unset($_SESSION['view_product']);
if (isset ($_SESSION['view_product']) && count ($_SESSION['view_product']) > 0)
{
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.id IN (" . implode (",", $_SESSION['view_product']) . ") ";
if ($limit != "all")
$sql .= "LIMIT " . $limit;
$res = $this->db->getAll ($sql, array (), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("products_view", $res);
}
}
function viewSimilarProducts ($product_id, $brend, $rubric_id, $mods)
{
IF ($brend == 'Dakine')
{
$rub_arr = array (
14071,
14069,
14070,
14072
);
unset ($rub_arr[array_search ('rubric_id', $rub_arr)]);
if (count ($mods) > 1)
{
$r = array ();
foreach ($mods as $key => $mod)
{
$r[$key]['color'] = $mod['color'];
$row = $this->db->getRow ("select * from catalogs_products where id=?", array (
$product_id
), DB_FETCHMODE_ASSOC);
$sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine and catalogs_brends.name=? and m.color=? and m.active=1 Order by catalogs_products.cine DESC LIMIT 5";
$r[$key]["products_similar_prev"] = $this->db->getAll ($sql, array (
$row['cine'],
$brend,
$mod['color']
), DB_FETCHMODE_ASSOC);
$sql = "select catalogs_products.*,m.pic,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
LEFT JOIN catalogs_modifications m ON m.product_id=catalogs_products.id
WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine>? and catalogs_brends.name=? and m.color=? and m.active=1 Order by catalogs_products.cine DESC LIMIT 5";
$r[$key]["products_similar_next"] = $this->db->getAll ($sql, array (
$row['cine'],
$brend,
$mod['color']
), DB_FETCHMODE_ASSOC);
}
// print_r($r);
$this->tpl->assign ("products_similar", $r);
}
else
{
$row = $this->db->getRow ("select * from catalogs_products where id=?", array (
$product_id
), DB_FETCHMODE_ASSOC);
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine and catalogs_brends.name=? Order by catalogs_products.cine DESC LIMIT 5";
$res = $this->db->getAll ($sql, array (
$row['cine'],
$brend
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("products_similar_prev", $res);
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.rubric_id IN (" . implode (',', $rub_arr) . ") and catalogs_products.count_modifications>0 and catalogs_products.cine>? and catalogs_brends.name=? Order by catalogs_products.cine DESC LIMIT 5";
$res = $this->db->getAll ($sql, array (
$row['cine'],
$brend
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("products_similar_next", $res);
}
}
else
{
$row = $this->db->getRow ("select * from catalogs_products where id=?", array (
$product_id
), DB_FETCHMODE_ASSOC);
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine Order by catalogs_products.cine DESC LIMIT 5";
$res = $this->db->getAll ($sql, array (
$row['rubric_id'],
$row['cine']
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("products_similar_prev", $res);
$sql = "select catalogs_products.*,catalogs_brends.name as brend_name,r.translit as rubric_translit from catalogs_products
LEFT JOIN catalogs_brends ON catalogs_brends.id=catalogs_products.brend_id
LEFT JOIN catalogs_rubrics r ON r.id=catalogs_products.rubric_id
WHERE catalogs_products.rubric_id=? and catalogs_products.count_modifications>0 and catalogs_products.cine>? Order by catalogs_products.cine DESC LIMIT 5";
$res = $this->db->getAll ($sql, array (
$row['rubric_id'],
$row['cine']
), DB_FETCHMODE_ASSOC);
$this->tpl->assign ("products_similar_next", $res);
}
}
function displayCatalogsCurs ()
{
$this->tpl->assign ("tpl", 'catalogs_curs.tpl');
}
function displayCatalogs ()
{
$this->tpl->assign ("tpl", 'catalogs.tpl');
}
function displayProducts ()
{
$this->tpl->assign ("tpl", 'catalogs_product-list.tpl');
}
function displayProductsTops ()
{
$this->tpl->assign ("tpl", 'catalogs_products_tops.tpl');
}
function displayProductsHits ()
{
$this->tpl->assign ("tpl", 'catalogs_products_hits.tpl');
}
function displayProductsHitsAll ()
{
$this->tpl->assign ("tpl", 'catalogs_products_hits_all.tpl');
}
function displayBasket ($count_products, $cine_products, $cine_products_discount, $discount)
{
$this->tpl->assign ("count_products", $count_products);
$this->tpl->assign ("cine_products", $cine_products);
$this->tpl->assign ("cine_products_discount", $cine_products_discount);
$this->tpl->assign ("discount", $discount);
$this->tpl->display ('basket.tpl');
}
function displayProduct ()
{
$this->tpl->assign ("tpl", 'catalogs_product.tpl');
}
function displayProductBasket ()
{
$this->tpl->assign ("tpl", 'catalogs_basket.tpl');
}
function displayBrends ()
{
$this->tpl->assign ("tpl", 'catalogs_brends.tpl');
}
function displayBrend ()
{
$this->tpl->assign ("tpl", 'catalogs_brend.tpl');
}
function displayCities ()
{
$this->tpl->assign ("tpl", 'catalogs_cities.tpl');
}
function displayProductBasketSend ()
{
$this->tpl->assign ("tpl", 'catalogs_basket_send.tpl');
}
function displayReg ()
{
$this->tpl->assign ("tpl", 'catalogs_reg.tpl');
}
function displayEditUser ()
{
$this->tpl->assign ("tpl", 'catalogs_user_edit.tpl');
}
function displayNoPsw ()
{
$this->tpl->assign ("tpl", 'catalogs_nopsw.tpl');
}
function displayOrders ()
{
$this->tpl->assign ("tpl", 'catalogs_orders.tpl');
}
function displayOrder ()
{
$this->tpl->assign ("tpl", 'catalogs_order.tpl');
}
function displayUsers ()
{
$this->tpl->assign ("tpl", 'catalogs_users.tpl');
}
function displayUser ()
{
$this->tpl->assign ("tpl", 'catalogs_user.tpl');
}
function displayFilters ()
{
$this->tpl->assign ("tpl", 'catalogs_filters.tpl');
}
function displayFilters2 ()
{
$this->tpl->assign ("tpl", 'catalogs_filters2.tpl');
}
function displayYears ()
{
$this->tpl->assign ("tpl", 'catalogs_years.tpl');
}
function displayWinProducts ()
{
$this->tpl->display ('catalogs_win_products.tpl');
}
function displayModifications ()
{
$this->tpl->assign ("tpl", 'catalogs_modifications.tpl');
}
function displayImport ()
{
$this->tpl->assign ("tpl", 'catalogs_import.tpl');
}
function displayImportCine ()
{
$this->tpl->assign ("tpl", 'catalogs_import_cine.tpl');
}
function displayAkcii ()
{
$this->tpl->assign ("tpl", 'catalogs_akcii.tpl');
}
function displayCompare ()
{
$this->tpl->assign ("tpl", 'catalogs_compare.tpl');
}
function displayTmpProducts ()
{
$this->tpl->assign ("tpl", 'catalogs_tmp_products.tpl');
}
}