Exemplo n.º 1
0
 public static function updateTagOrdering()
 {
     $ids = $_POST['ids'];
     $response = new stdClass();
     if ($ids) {
         $strIds = implode(', ', $ids);
         $minOrder = DB::getInstance()->getValue("Select Min(ordering) From " . _DB_PREFIX_ . "ovic_custom_tags_tags Where id IN ({$strIds})");
         foreach ($ids as $i => $id) {
             DB::getInstance()->query("Update " . _DB_PREFIX_ . "ovic_custom_tags_tags Set ordering=" . ($minOrder + $i) . " Where id = " . $id);
         }
         $module = new OvicCustomTags();
         $module->clearCache();
         $response->status = 1;
         $response->msg = 'Update ordering success!';
     } else {
         $response->status = 0;
         $response->msg = 'Update ordering not success!';
     }
     die(Tools::jsonEncode($response));
 }
Exemplo n.º 2
0
 public static function saveTag()
 {
     $module = new OvicCustomTags();
     //$module->clearCache();
     $languages = $module->getAllLanguages();
     $shopId = Context::getContext()->shop->id;
     $db = DB::getInstance();
     $itemId = intval($_POST['tagId']);
     $titles = Tools::getValue('titles', array());
     $links = Tools::getValue('links', array());
     $groupId = intval($_POST['groupId']);
     $response = new stdClass();
     if ($itemId == 0) {
         $maxOrdering = (int) $db->getValue("Select MAX(ordering) From " . _DB_PREFIX_ . "ovic_custom_tags_tags Where groupId = " . $groupId);
         if ($maxOrdering) {
             $maxOrdering++;
         } else {
             $maxOrdering = 1;
         }
         if ($db->execute("Insert Into " . _DB_PREFIX_ . "ovic_custom_tags_tags (`groupId`, `status`, `ordering`) Values ('{$groupId}', '1', '{$maxOrdering}')")) {
             $insertId = $db->Insert_ID();
             if ($languages) {
                 $arrInsert = array();
                 foreach ($languages as $index => $language) {
                     $arrInsert[] = array('tagId' => $insertId, 'id_lang' => $language->id, 'id_shop' => $shopId, 'title' => $db->escape($titles[$index]), 'link' => $db->escape($links[$index]));
                 }
                 if ($arrInsert) {
                     $db->insert('ovic_custom_tags_tag_lang', $arrInsert);
                 }
             }
             $response->status = 1;
             $response->msg = $module->ajaxTranslate("Add new Tag Success!");
         } else {
             $response->status = 0;
             $response->msg = $module->ajaxTranslate("Add new Tag Not Success!");
         }
     } else {
         $arrInsert = array();
         foreach ($languages as $index => $language) {
             $check = $db->getValue("Select tagId From " . _DB_PREFIX_ . "ovic_custom_tags_tag_lang Where tagId = " . $itemId . " AND id_lang = " . $language->id . " AND id_shop = " . $shopId);
             if ($check) {
                 $db->execute("Update " . _DB_PREFIX_ . "ovic_custom_tags_tag_lang Set `title`='" . $db->escape($titles[$index]) . "', `link`='" . $links[$index] . "' Where `tagId` = '" . $itemId . "' AND `id_lang` = '" . $language->id . "' AND `id_shop` = '" . $shopId . "'");
             } else {
                 $arrInsert[] = array('tagId' => $itemId, 'id_lang' => $language->id, 'id_shop' => $shopId, 'title' => $db->escape($names[$index]), 'link' => $db->escape($links[$index]));
             }
         }
         if ($arrInsert) {
             $db->insert('ovic_custom_tags_tag_lang', $arrInsert);
         }
         $response->status = 1;
         $response->msg = $module->ajaxTranslate("Update Tag Success!");
     }
     die(Tools::jsonEncode($response));
 }