setStatus($id, $status);
}
if ($task == 'set-cat-order') {
$categories = new Products_Categories();
if(isset($_POST['catrow']))
$categories->setCategoriesOrder($_POST['catrow']);
}
if ($task == 'addlevel') {
$cat_id = Tools_Http::Post('cat_id');
$start = Tools_Http::Post('start');
$end = Tools_Http::Post('end');
if($cat_id) {
$sql='INSERT INTO pricelevels (cat_id,start,end) VALUES ("'.$_POST['cat_id'].'","'.$_POST['start'].'","'.$_POST['end'].'") ';
$res=$this->db->Exec($sql);
echo mysql_insert_id();
}
}
if ($task == 'removelevel') {
$value = Tools_Http::Post('value');
$sql='DELETE FROM pricelevels WHERE level_id="'.$_POST['value'].'"';
$res=$this->db->Exec($sql);
if($res) echo $res;
}
if ($task=='addCar') {
$title = $DB->Escape(Tools_Http::Post('title'));
$id = Tools_Http::Post('catid',true);
if (!$title) {
array_push($errors,'title');
$err_msg = $L->Str('Ievadiet markas nosaukumu!');
}
$pic = $_FILES['imgfile'];
$pic_file='';
if ($pic['name'] && !sizeof($errors)) {
$hash = Tools_Text::getRandomHash();
$thumb_file = $hash.'.jpg';
$dest = WEBPATH.'images/cars/';
$upload = Tools_Filesystem::uploadFile ('imgfile', $dest, $thumb_file);
if (!$upload) {
array_push($errors,'pic');
$err_msg = $L->Str('Neizdevās ielādēt bildi.');
} else {
if (getimagesize($dest.$thumb_file)) {
Tools_Image:: imageResize ($dest.$thumb_file,$dest.$thumb_file,90,90,true,100);
chmod($dest.$thumb_file,0777);
if ($id) {
$cat_data = $DB -> getRow('goods_cars',$id);
if ($cat_data['icon']) {
unlink($dest.$cat_data['icon']);
}
$this->db->Exec("UPDATE goods_cars SET icon = '".$thumb_file."' WHERE id = ".$id);
}
$pic_file = $thumb_file;
} else {
unlink ($dest.$thumb_file);
array_push($errors, 'imgilfe');
$err_msg = $L->Str('Ielādētais fails nav bilde!');
}
}
}
if (!sizeof($errors)) {
$sql = ($id ? "UPDATE":"INSERT INTO")." goods_cars SET title = '".$title."' ".($id?" WHERE id = ".$id:", icon='".$pic_file."'");
$DB -> Exec($sql);
//echo 'OK|'.$L->Str('Marka pievienota.').'|document.location.href=document.location.href;window.opener.document.location.href=window.opener.document.location.href;';
?>
} else {
?>
}
}
if ($task == 'inplace') {
list($garbage, $id) = explode('-',Tools_Http::Post('element_id'));
$field = Tools_Http::Post('field');
$value = $DB -> Escape(Tools_Http::Post('update_value'));
if ($field == 'price' || $field == 'price_2' || $field == 'price_old' || $field == 'stock' ) {
$value = Tools_Common::formatPrice($value);
$array[$field]=$value;
$products = new Products();
$compare_fields = $products ->compareProduct($id,$array);
$log = new Common_Logs;
foreach($compare_fields as $f)
$log->addLog($id ,'goods_'.$f['field'],$f['new_data'],$f['saved_data']);
$sql= "UPDATE goods SET ".$field." = '".$value."' WHERE id = ".$id;
}
if($field == 'title') {
$sql = 'UPDATE languages_texts SET translation="'.$value.'" WHERE objectid='.$id.' AND col="title" AND type="goods" AND lang="'.$L->getCurrentLanguage().'" ';
if($L->getCurrentLanguage()=='ru')
$this->db->Exec("UPDATE goods SET ".$field." = '".$value."' WHERE id = ".$id);
}
$this->db->Exec($sql);
if($field == 'title')
$L->generateLanguageFiles();
echo $value;
}
if ($task == 'toggle-cat') {
$id = Tools_Http::Post('id',true);
$state = Tools_Http::Post('state');
$state = $state == 'true' ? 'active' : 'hidden';
$categories = new Products_Categories();
$categories -> setStatus ($id, $state);
}
if ($task == 'set-field') {
$id = Tools_Http::Post('id',true);
$field = Tools_Http::Post('field');
$value = $DB->Escape(Tools_Http::Post('value'));
$sql = "UPDATE goods SET ".$field." = '".$value."' WHERE id = ".$id;
$DB -> Exec($sql);
}
if ($task == 'addProduct') {
$title = $_POST['title'];
$descr = $_POST['descr'];
$code = $DB->Escape(Tools_Http::Post('code'));
$product_id = Tools_Http::Post('itemid', true);
$catid = Tools_Http::Post('catid', true);
$catid2 = Tools_Http::Post('catid2', true);
$catid3 = Tools_Http::Post('catid3', true);
$catid4 = Tools_Http::Post('catid4', true);
$catid5 = Tools_Http::Post('catid5', true);
$catid6 = Tools_Http::Post('catid6', true);
$status = Tools_Http::Post('status');
$sale = Tools_Http::Post('sale', true);
$new = Tools_Http::Post('new', true);
$clearance = Tools_Http::Post('clearance', true);
$stock = Tools_Http::Post('stock', true);
$car = Tools_Http::Post('car', true);
$price = floatval(Tools_Http::Post('price'));
$price_2 = floatval(Tools_Http::Post('price_2'));
$price_old = floatval(Tools_Http::Post('price_old'));
$pricelevels=isset($_POST['pricelevel']) ? $_POST['pricelevel'] : array();
$free_shipping = Tools_Http::Post('free_shipping', true);
$measure=(int) $_POST['measure'];
/* if (!$title) {
array_push($errors,'title');
$err_msg = $L->Str('Ievadiet produkta nosaukumu!');
} */
if (!$catid) {
array_push($errors,'catid');
$err_msg = $L->Str('Izvēlieties kategoriju!');
}
if (sizeof($errors)) {
?>
} else {
$products = new Products();
$compare_fields = $products ->compareProduct($product_id,$_POST);
$log = new Common_Logs;
foreach($compare_fields as $field)
$log->addLog($product_id,'goods_'.$field['field'],$field['new_data'],$field['saved_data']);
$result = $products -> editItem ($free_shipping, $title, $descr, $catid,$catid2,$catid3,$catid4,$catid5,$catid6, $code, $status, $sale, $new,$clearance, $price,$price_2,$price_old,$measure, $stock,$car, $product_id,$pricelevels);
$seo = new Seo();
foreach($_POST['seo'] as $key =>$value) {
$seo->addSeoMetadata('product',$result,$key,$value,$_POST['seokey'][$key]);
}
?>
}
exit;
}
if ($task == 'addGroup') {
$title = $DB->Escape(Tools_Http::Post('title'));
$group_id = Tools_Http::Post('group_id',true);
if (!$title) {
array_push($errors, 'title');
$err_msg = $L->Str('Ievadiet nosaukumu!');
}
if (empty($errors)) {
if ($group_id) {
$DB -> Exec("UPDATE properties_groups SET title = '".$title."' WHERE id = ".$group_id);
$id - $group_id;
} else {
$DB -> Exec("INSERT INTO properties_groups SET title = '".$title."' ");
$id = $DB->lastId();
}
$L->addText ('properties_groups', 'title', $id);
echo 'OK|'.$L->Str('Dati saglabāti').'|reloadPage(); window.opener.reloadPage();';
}
}
if ($task == 'addCat') {
$title = $_POST['title'];
$seo_description = $_POST['seo_description'];
$sef = $DB -> Escape(Tools_Http::Post('sef'));
$catid = Tools_Http::Post('catid', true);
$parentid = Tools_Http::Post('parentid', true);
$groupid = Tools_Http::Post('groupid', true);
$car = Tools_Http::Post('car', true);
$pic = $_FILES['imgfile'];
$start = isset($_POST['start']) ? $_POST['start'] : 0;
$end = isset($_POST['end']) ? $_POST['end'] : 0;
$level_id = isset($_POST['level_id']) ? $_POST['level_id'] : 0;
$sef = strtolower($sef ? $sef : Tools_Text::cleanString($title['ru']));
/* if (!$title) {
array_push($errors,'title');
$err_msg = $L->Str('Ievadiet kategorijas nosaukumu!');
} */
$sef_check = $DB -> GetRow('goods_categories', $sef, 'sef');
if (!empty($sef_check)) {
if ($sef_check['id'] != $catid) {
array_push($errors,'sef');
$err_msg = $L->Str('Kategorija ar šādu nosaukumu jau eksistē!');
}
}
if ($pic['name'] && !sizeof($errors)) {
if ($catid) {
$GoodsCategories = new Products_Categories();
$cat_data = $GoodsCategories -> getItem($catid);
$i_title = $cat_data['title'];
} else {
$i_title = $title;
}
$hash = strtolower(Tools_Text :: cleanString ($i_title).'_'.substr(Tools_Text::getRandomHash(), 0, 5));
$thumb_file = $hash.'.jpg';
$dest = WEBPATH.'images/category/';
$upload = Tools_Filesystem::uploadFile ('imgfile', $dest, $thumb_file);
if (!$upload) {
array_push($errors,'pic');
$err_msg = $L->Str('Neizdevās ielādēt bildi.');
} else {
if (getimagesize($dest.$thumb_file)) {
//Tools_Image:: imageResize ($dest.$thumb_file,$dest.$thumb_file,170,120,true,100);
chmod($dest.$thumb_file,0777);
if ($catid) {
if ($cat_data['image']) {
unlink($dest.$cat_data['image']);
}
echo 'Thumb'.$thumb_file;
$this->db->Exec("UPDATE goods_categories SET image = '".$thumb_file."' WHERE id = ".$catid);
}
$pic_file = $thumb_file;
} else {
unlink ($dest.$thumb_file);
array_push($errors, 'imgilfe');
$err_msg = $L->Str('Ielādētais fails nav bilde!');
}
}
}
if (sizeof($errors)) {
?>
} else {
$categories = new Products_Categories();
$result = $categories -> editCategory($title,$seo_description, $sef, $parentid,$groupid,$pic_file, $catid,$start,$end,$level_id);
$seo = new Seo();
foreach($_POST['seo'] as $key =>$value) {
$seo->addSeoMetadata('category',$result,$key,$value,$_POST['seokey'][$key]);
}
?>