Skip to content

Instantly share code, notes, and snippets.

@kaspy003
Created August 4, 2016 12:20
Show Gist options
  • Save kaspy003/246e80ac7b48790da03845a2d6afe111 to your computer and use it in GitHub Desktop.
Save kaspy003/246e80ac7b48790da03845a2d6afe111 to your computer and use it in GitHub Desktop.
public static function updateItem($post){
$item = self::getItemByID($post['id']);
if(!empty($item)){
$deleteCatItems = self::deleteItemCatsByItem($post['id']);
$deleteCatItemsSimular = self::deleteItemSimularCatsByItem($post['id']);
if(query("UPDATE `store_items` SET
".(!empty($post['title']) ? "`title` = '".mysqli_real_escape_string(db(), $post['title'])."',":"")."
".(!empty($post['subtitle']) ? "`subtitle` = '".mysqli_real_escape_string(db(), $post['subtitle'])."',":"`subtitle` = '',")."
".(!empty($post['code']) ? "`code` = '".mysqli_real_escape_string(db(), $post['code'])."'," : "`code` = '',")."
".(!empty($item['url']) ? "`url` = '".mysqli_real_escape_string(db(), $item['url'])."',":"")."
".(!empty($item['cats']) ? "`cats` = '".mysqli_real_escape_string(db(), $item['cats'])."',":"")."
".(!empty($item['simular_cats']) ? "`simular_cats` = '".mysqli_real_escape_string(db(), $item['simular_cats'])."',":"")."
".(!empty($item['image']) ? "`image` = '".mysqli_real_escape_string(db(), $item['image'])."',":"")."
".(!empty($post['desc']) ? "`desc` = '".mysqli_real_escape_string(db(), $post['desc'])."'," : "`desc` = '',")."
".(!empty($post['desc_sec']) ? "`desc_sec` = '".mysqli_real_escape_string(db(), $post['desc_sec'])."'," : "`desc_sec` = '',")."
".(!empty($post['seo_desc']) ? "`seo_desc` = '".mysqli_real_escape_string(db(), $post['seo_desc'])."'," : "`seo_desc` = '',")."
".(!empty($post['tags']) ? "`tags` = '".mysqli_real_escape_string(db(), $post['tags'])."'," : "`tags` = '',")."
".(!empty($post['lang']) ? "`lang` = '".mysqli_real_escape_string(db(), $post['lang'])."'," : "`lang` = '',")."
".(!empty($post['price']) ? "`price` = '".mysqli_real_escape_string(db(), $post['price'])."'," : "`price` = '',")."
".(!empty($post['price_action']) ? "`price_action` = '".mysqli_real_escape_string(db(), $post['price_action'])."'," : "`price_action` = '',")."
".(!empty($post['price_valute']) ? "`price_valute` = '".mysqli_real_escape_string(db(), $post['price_valute'])."'," : "`price_valute` = '',")."
".(!empty($post['options']) ? "`options` = '".(int) $post['options']."'," : "`options` = '0',")."
".(!empty($post['pub']) ? "`pub` = '".(int) $post['pub']."'," : "")."
`uid` = '".(int) ID."',
`date` = NOW()
WHERE `id` = '".(int) $post['id']."'
") && mysqli_affected_rows(db())){
$tags = Search::addTags(30, $post['id'], $post['tags']);
if(!empty($post['cats'])){
$catSelected = $post['cats'];
$cats = '';
$count = 0;
foreach($catSelected AS $key=>$values){
$count++;
$cats .= $values.(count($catSelected) == $count ? '':',');
$addCat = self::addCatAndItem($post['id'], $values);
}
}
if(!empty($post['simular_cats'])){
$simSelected = $post['simular_cats'];
$simular = '';
$count = 0;
foreach($simSelected AS $key=>$values){
$count++;
$simular .= $values.(count($simSelected) == $count ? '':',');
$addSim = self::addSimularCatAndItem($post['id'], $values);
}
}
if(query("UPDATE `store_items` SET
".(!empty($cats) ? "`cats` = '".mysqli_real_escape_string(db(), $cats)."',":"")."
".(!empty($simular) ? "`simular_cats` = '".mysqli_real_escape_string(db(), $simular)."',":"")."
`date` = NOW()
WHERE `id` = '".(int) $post['id']."'
") && mysqli_affected_rows(db())){}
return $post['id'];
}else{
$_SESSION['error'] = mysqli_error(db());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment