示例#1
0
function deleteImg($shorten, $api_key)
{
    if (isUrlOwned($shorten, $api_key)) {
        deleteImage($shorten);
    } else {
        echo "Error";
    }
}
示例#2
0
 protected function _before_delete($option)
 {
     if (is_array($option['where']['id'])) {
         $this->error = '不支持批量删除';
         return FALSE;
     }
     $images = $this->field('brand_logo,big_brand_logo,mid_brand_logo,sm_brand_logo')->find($option['where']['id']);
     deleteImage($images);
 }
示例#3
0
function deleteAlbum($album_id)
{
    if (albumExists($album_id)) {
        $images = getAlbumImages($album_id);
        foreach ($images as $img) {
            $image_id = $img['ImageID'];
            deleteImage($image_id);
        }
        mysql_query("DELETE FROM `mbg_albums` WHERE `AlbumID` = '{$album_id}'");
        return true;
    }
    return false;
}
示例#4
0
function deleteNameFiles($nameId)
{
    global $dbConnect;
    $dbresult = $dbConnect->getLuasByNameId($nameId);
    while ($row = mysql_fetch_assoc($dbresult)) {
        deleteFilesByLuaId($row['Id']);
    }
    $dbresult = $dbConnect->getImagesByNameId($nameId);
    while ($row = mysql_fetch_assoc($dbresult)) {
        deleteImage($row['Id']);
    }
    //delete thumbnail
    unlink("thumbnails/" . $nameId);
}
示例#5
0
function product_update()
{
    $id = $_POST['id'];
    if (isset($_POST['update'])) {
        $data['product_object'] = model('product')->getOne($id);
        //var_dump($data);die;
        $data['template_file'] = 'product/update.php';
        render('layout.php', $data);
    }
    if (isset($_POST['saveUpdate'])) {
        unset($_POST['saveUpdate']);
        $postData = postData();
        if ($_FILES["fileImage"]['name'] != "") {
            $postData['image'] = uploadImage();
            deleteImage($_POST['image']);
        }
        if (model('product')->updateProduct($postData, $id)) {
            redirect('/index.php?c=product&m=list');
        }
    }
}
示例#6
0
<?php

include_once 'procedures.php';
deleteImage(intval($_POST['id']));
function delete_post($post_id)
{
    delete_tags_from_post($post_id);
    deleteImage($post_id);
    global $db;
    // vymažeme článok z tabuľky článkov
    $query = $db->prepare("DELETE FROM posts WHERE id = :id");
    $delete = $query->execute(array("id" => $post_id));
    if (!$delete) {
        add_message("Nepodarilo sa vymazať článok.");
        return false;
    }
    add_message("Článok bol vymazaný.");
    return true;
}
示例#8
0
    case "deleteCategory":
        deleteCategory($_GET['id']);
        break;
    case "edit":
        editBlogEntry($_GET['id']);
        break;
    case "finishEdit":
        finishEditBlogEntry($_POST['id'], $_POST['editBlogCategory'], $_POST['editBlogTitle'], $_POST['editBlogText'], $_POST['editBlogExtText']);
        break;
    case "delete":
        deleteBlogEntry($_GET['id']);
        break;
    case "upload":
        upload($_GET['id'], isset($_GET['error']) ? $_GET['error'] : "");
        break;
    case "finishUpload":
        finishUpload($_POST['blog_id'], $_POST['description'], $_FILES['image_file']['tmp_name'], $_FILES['image_file']['type'], $_FILES['image_file']['size'], $_FILES['image_file']['name']);
        break;
    case "editImage":
        editImage($_GET['id']);
        break;
    case "finishEditImage":
        finishEditImage($_POST['id'], $_POST['description'], $_POST['blog_id']);
        break;
    case "deleteImage":
        deleteImage($_GET['id'], $_GET['blog_id']);
        break;
    default:
        main(isset($_GET['PHP_SELF']) ? $_GET['PHP_SELF'] : "");
        break;
}
示例#9
0
    /**
     * Delete product images from database
     *
     * @return array Deletion result
     */
    public function deleteImages()
    {
        $result = Db::getInstance()->ExecuteS('
		SELECT `id_image`
		FROM `' . _DB_PREFIX_ . 'image`
		WHERE `id_product` = ' . (int) $this->id);
        foreach ($result as $row) {
            if (!deleteImage((int) $this->id, $row['id_image']) or !Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'image_lang` WHERE `id_image` = ' . (int) $row['id_image'])) {
                return false;
            }
        }
        return Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'image` WHERE `id_product` = ' . (int) $this->id);
    }
    public function delete()
    {
        if ($this->id == 1) {
            return false;
        }
        /* Get childs categories */
        $toDelete = array(intval($this->id));
        $this->recursiveDelete($toDelete, intval($this->id));
        $toDelete = array_unique($toDelete);
        /* Delete category and its child from database */
        $list = sizeof($toDelete) > 1 ? implode(',', $toDelete) : intval($this->id);
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category` WHERE `id_category` IN (' . $list . ')');
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_lang` WHERE `id_category` IN (' . $list . ')');
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_product` WHERE `id_category` IN (' . $list . ')');
        /* Delete categories images */
        foreach ($toDelete as $id_category) {
            deleteImage(intval($id_category));
        }
        /* Delete products which were\'t in others categories */
        $result = Db::getInstance()->ExecuteS('
		SELECT `id_product`
		FROM `' . _DB_PREFIX_ . 'product`
		WHERE `id_product` NOT IN (SELECT `id_product` FROM `' . _DB_PREFIX_ . 'category_product`)');
        foreach ($result as $p) {
            $product = new Product(intval($p['id_product']));
            if (Validate::isLoadedObject($product)) {
                $product->delete();
            }
        }
        /* Set category default to 1 where categorie no more exists */
        $result = Db::getInstance()->Execute('
		UPDATE `' . _DB_PREFIX_ . 'product`
		SET `id_category_default` = 1
		WHERE `id_category_default`
		NOT IN (SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category`)');
        return true;
    }
示例#11
0
            $select_sql_string = 'SELECT albums.id, albums.name FROM imagesToAlbums, albums WHERE imagesToAlbums.imageId=' . mysql_real_escape_string($imageId) . ' AND imagesToAlbums.albumId=albums.id';
            $result = $db->query($select_sql_string);
            if (isset($_POST["Delete"])) {
                $albums = $_POST['album'];
                if (!empty($albums)) {
                    foreach ($albums as $albumId) {
                        $query_for_album = "SELECT parentAlbumId, id, ownerId, name FROM albums WHERE id='" . mysql_real_escape_string($albumId) . "'";
                        $album_data = mysql_fetch_array($db->query($query_for_album));
                        if (!empty($album_data)) {
                            if ($album_data['ownerId'] == $currentUser['id']) {
                                $delete_sql_string = 'DELETE FROM imagesToAlbums WHERE albumId="' . mysql_real_escape_string($albumId) . '" AND imageId ="' . $imageId . '"';
                                $db->query($delete_sql_string);
                            }
                        }
                    }
                    deleteImage($currentUser['id'], $db, $imageId);
                }
                if (!$phpunit['isTest']) {
                    header('Location: ./index.html?id=' . $_GET['albumId']);
                    exit;
                }
            }
        }
        if (!$phpunit['isTest']) {
            if ($error) {
                print $message;
            } else {
                $select_sql_string = 'SELECT albums.id, albums.name FROM imagesToAlbums, albums WHERE imagesToAlbums.imageId=' . mysql_real_escape_string($imageId) . ' AND imagesToAlbums.albumId=albums.id';
                $result = $db->query($select_sql_string);
                ?>
示例#12
0
 protected function _before_delete($option)
 {
     if (is_array($option['where']['id'])) {
         $this->error = '不支持批量删除';
         return FALSE;
     }
     $images = $this->field('goods_ori,goods_thumb')->find($option['where']['id']);
     deleteImage($images);
     /*********** 先删除商品的其他信息 ***************/
     // 扩展分类
     $model = M('GoodsCat');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     // 会员价格
     $model = M('MemberPirce');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     //商品属性
     $model = M('Goods_attr');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     //商品库存量
     $model = M('GoodsNumber');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     //商品相册图片
     $model = M('GoodsPics');
     //想取出图片的路径
     $pics = $model->where()->select();
     foreach ($pics as $p) {
         deleteImage($p);
     }
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
 }
示例#13
0
function delete_ads_files($ad_id)
{
    $sql = "select * from form_fields where form_id=1 ";
    $result = mysql_query($sql) or die(mysql_error());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $field_id = $row['field_id'];
        $field_type = $row['field_type'];
        if ($field_type == "FILE") {
            deleteFile("ads", "ad_id", $ad_id, $field_id);
        }
        if ($field_type == "IMAGE") {
            deleteImage("ads", "ad_id", $ad_id, $field_id);
        }
    }
}
    print "something went wrong ...\n";
    exit;
}
if (encodeImageFile($image, "test.jpg", 80, "")) {
    print "image written all fine.\n";
} else {
    print "something went wrong writing the image ...\n";
    exit;
}
# advanced use, use in memory locations
$image_bits = `cat testsuite/tif/5.1.13.tif`;
if (decodeImage($image, $image_bits)) {
    print "image read from RAM.\n";
} else {
    print "something went wrong decoding the RAM\n";
    exit;
}
# image properties
print "Width: " . imageWidth($image) . "\n";
print "Height: " . imageHeight($image) . "\n";
print "Xres: " . imageXres($image) . "\n";
print "Yres: " . imageYres($image) . "\n";
print "Channels: " . imageChannels($image) . "\n";
print "Channel depth: " . imageChannelDepth($image) . "\n";
# setable as well
imageSetXres($image, 144);
imageSetYres($image, 144);
print "Xres: " . imageXres($image) . "\n";
print "Yres: " . imageYres($image) . "\n";
deleteImage($image);
示例#15
0
function get_sql_update_values($form_id, $table_name, $object_name, $object_id, $user_id)
{
    $sql = "SELECT * FROM form_fields WHERE form_id='{$form_id}' AND field_type != 'SEPERATOR' AND field_type != 'BLANK' AND field_type != 'NOTE'  ";
    $result = mysql_query($sql) or die(mysql_error());
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $tmp = '';
        $comma = '';
        switch ($row['field_type']) {
            case "IMAGE":
                if ($_FILES[$row['field_id']]['name'] != '') {
                    //echo "Image:<b>***$table_name, $object_name, $object_id, $user_id</b>";
                    $file_name = saveImage($row['field_id']);
                    $_REQUEST[$row['field_id']] = $file_name;
                    // delete the old image
                    if ($object_id != '') {
                        deleteImage($table_name, $object_name, $object_id, $row[field_id]);
                    }
                    $str .= ", `" . $row['field_id'] . "` = '" . $file_name . "' ";
                }
                break;
            case "FILE":
                if ($_FILES[$row['field_id']]['name'] != '') {
                    $file_name = saveFile($row['field_id']);
                    $mime_type = $_FILES[$row['field_id']]['type'];
                    //$_REQUEST[$row[field_id]] = $file_name;
                    // delete the old image
                    if ($object_id != '') {
                        deleteFile($table_name, $object_name, $object_id, $row['field_id']);
                    }
                    //$str .= ", `".$row['field_id']."` = '".$file_name."' , `".$row[field_id]."9193` = '".$mime_type."'";
                    $str .= ", `" . $row['field_id'] . "` = '" . $file_name . "' ";
                }
                break;
            case "DATE":
                $day = $_REQUEST[$row['field_id'] . "d"];
                $month = $_REQUEST[$row['field_id'] . "m"];
                $year = $_REQUEST[$row['field_id'] . "y"];
                $_REQUEST[$row['field_id']] = $year . "-" . $month . "-" . $day;
                $str .= ", `" . $row['field_id'] . "` = '" . $_REQUEST[$row['field_id']] . "' ";
                break;
            case "DATE_CAL":
                $temp_time = strtotime($_REQUEST[$row['field_id']] . " GMT");
                $day = date('d', $temp_time);
                $month = date('m', $temp_time);
                $year = date('y', $temp_time);
                $str .= ", `" . $row['field_id'] . "` = '" . $year . "-" . $month . "-" . $day . "' ";
                break;
            case "CHECK":
                $selected_codes = array();
                $selected_codes = $_REQUEST[$row['field_id']];
                // the field comes in as an array
                for ($i = 0; $i < sizeof($selected_codes); $i++) {
                    if ($i > 0) {
                        $comma = ',';
                    }
                    $tmp .= $comma . $selected_codes[$i] . "";
                }
                $_REQUEST[$row['field_id']] = $tmp;
                $str .= ", `" . $row['field_id'] . "` = '" . $_REQUEST[$row['field_id']] . "' ";
                break;
            case "MSELECT":
                $selected_codes = array();
                $selected_codes = $_REQUEST[$row['field_id']];
                // the field comes in as an array
                for ($i = 0; $i < sizeof($selected_codes); $i++) {
                    if ($i > 0) {
                        $comma = ',';
                    }
                    $tmp .= $comma . $selected_codes[$i] . "";
                }
                $_REQUEST[$row['field_id']] = $tmp;
                $str .= ", `" . $row['field_id'] . "` = '" . $_REQUEST[$row['field_id']] . "' ";
                break;
            case "SKILL_MATRIX":
                save_skill_matrix_data($row['field_id'], $object_id, $user_id);
                $str .= ", `" . $row['field_id'] . "` = '" . $_REQUEST[$row['field_id']] . "' ";
                break;
            case "TEXT":
                $str .= ", `" . $row['field_id'] . "` = '" . html_entity_decode($_REQUEST[$row['field_id']]) . "' ";
                break;
            default:
                $str .= ", `" . $row['field_id'] . "` = '" . $_REQUEST[$row['field_id']] . "' ";
                break;
        }
    }
    //echo "$str<br>";
    return $str;
}
示例#16
0
    public function delete()
    {
        if ((int) $this->id === 0 or (int) $this->id === 1) {
            return false;
        }
        $this->clearCache();
        /* Get childs categories */
        $toDelete = array((int) $this->id);
        $this->recursiveDelete($toDelete, (int) $this->id);
        $toDelete = array_unique($toDelete);
        /* Delete category and its child from database */
        $list = sizeof($toDelete) > 1 ? implode(',', array_map('intval', $toDelete)) : (int) $this->id;
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category` WHERE `id_category` IN (' . $list . ')');
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_lang` WHERE `id_category` IN (' . $list . ')');
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_product` WHERE `id_category` IN (' . $list . ')');
        Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_category` IN (' . $list . ')');
        self::cleanPositions($this->id_parent);
        /* Delete categories images */
        require_once _PS_ROOT_DIR_ . '/images.inc.php';
        foreach ($toDelete as $id_category) {
            deleteImage((int) $id_category);
        }
        /* Delete products which were not in others categories */
        $result = Db::getInstance()->ExecuteS('
		SELECT `id_product`
		FROM `' . _DB_PREFIX_ . 'product`
		WHERE `id_product` NOT IN (SELECT `id_product` FROM `' . _DB_PREFIX_ . 'category_product`)');
        foreach ($result as $p) {
            $product = new Product((int) $p['id_product']);
            if (Validate::isLoadedObject($product)) {
                $product->delete();
            }
        }
        /* Set category default to 1 where categorie no more exists */
        $result = Db::getInstance()->Execute('
		UPDATE `' . _DB_PREFIX_ . 'product`
		SET `id_category_default` = 1
		WHERE `id_category_default`
		NOT IN (SELECT `id_category` FROM `' . _DB_PREFIX_ . 'category`)');
        /* Rebuild the nested tree */
        if (!isset($this->doNotRegenerateNTree) or !$this->doNotRegenerateNTree) {
            self::regenerateEntireNtree();
        }
        Module::hookExec('categoryDeletion', array('category' => $this));
        return true;
    }
示例#17
0
    if ($res) {
        Header("Location: " . $_SERVER['PHP_SELF']);
    }
}
function deleteImage($id)
{
    global $dbi;
    sql_query("DELETE FROM jones_binarydata WHERE id='{$id}'", $dbi);
    Header("Location: " . $_SERVER['PHP_SELF']);
}
set_error_handler("myErrorHandler");
if (isset($_GET['cmd'])) {
    $cmd = $_GET['cmd'];
} else {
    if (isset($_POST['cmd'])) {
        $cmd = $_POST['cmd'];
    } else {
        $cmd = "";
    }
}
switch ($cmd) {
    case "finishUpload":
        finishUpload($_FILES['image_file']['tmp_name'], $_FILES['image_file']['type'], $_FILES['image_file']['size'], $_FILES['image_file']['name']);
        break;
    case "deleteImage":
        deleteImage($_GET['id']);
        break;
    default:
        main(isset($_GET['error']) ? $_GET['error'] : "");
        break;
}
示例#18
0
 function deleteAlbumChild($currentUserId, $db, $albumId)
 {
     $query_for_parent_album = "SELECT parentAlbumId, id, ownerId, name FROM albums WHERE id='" . mysql_real_escape_string($albumId) . "'";
     $parent_album = mysql_fetch_assoc($db->query($query_for_parent_album));
     if (!empty($parent_album)) {
         if ($parent_album['ownerId'] == $currentUserId) {
             $albumsChild = $db->query('SELECT * FROM albums WHERE parentAlbumId="' . $albumId . ' "');
             if (!empty($albumsChild)) {
                 while ($childAlbum = mysql_fetch_array($albumsChild)) {
                     $images = $db->query('SELECT * FROM imagestoalbums WHERE albumId=' . $childAlbum['id']);
                     if (!empty($images)) {
                         while ($image = mysql_fetch_array($images)) {
                             $delete_sql_string = 'DELETE FROM imagestoalbums WHERE imageId="' . $image['imageId'] . '" AND albumId="' . $childAlbum['id'] . '"';
                             $db->query($delete_sql_string);
                             deleteImage($currentUserId, $db, $image['imageId']);
                         }
                     }
                     deleteAlbumChild($currentUserId, $db, $childAlbum['id']);
                     $delete_sql_string = 'DELETE FROM albums WHERE id="' . $childAlbum['id'] . '" ';
                     $db->query($delete_sql_string);
                 }
             }
         }
     }
 }
    /**
     * postProcess handle every checks before saving products information
     *
     * @param mixed $token
     * @return void
     */
    public function postProcess($token = NULL)
    {
        global $cookie, $currentIndex;
        /* Add a new product */
        if (Tools::isSubmit('submitAddproduct') or Tools::isSubmit('submitAddproductAndStay') or Tools::isSubmit('submitAddProductAndPreview')) {
            if (Tools::getValue('id_product') and $this->tabAccess['edit'] === '1' or $this->tabAccess['add'] === '1' and !Tools::isSubmit('id_product')) {
                $this->submitAddproduct($token);
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add here.');
            }
        }
        /* Delete a product in the download folder */
        if (Tools::getValue('deleteVirtualProduct')) {
            if ($this->tabAccess['delete'] === '1') {
                $this->deleteVirtualProduct();
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::isSubmit('submitAddAttachments')) {
            if ($this->tabAccess['add'] === '1') {
                $languages = Language::getLanguages(false);
                $is_attachment_name_valid = false;
                foreach ($languages as $language) {
                    $attachment_name_lang = Tools::getValue('attachment_name_' . (int) $language['id_lang']);
                    if (strlen($attachment_name_lang) > 0) {
                        $is_attachment_name_valid = true;
                    }
                    if (!Validate::isGenericName(Tools::getValue('attachment_name_' . (int) $language['id_lang']))) {
                        $this->_errors[] = Tools::displayError('Invalid Name');
                    } elseif (Tools::strlen(Tools::getValue('attachment_name_' . (int) $language['id_lang'])) > 32) {
                        $this->_errors[] = Tools::displayError('Name is too long');
                    }
                    if (!Validate::isCleanHtml(Tools::getValue('attachment_description_' . (int) $language['id_lang']))) {
                        $this->_errors[] = Tools::displayError('Invalid description');
                    }
                }
                if (!$is_attachment_name_valid) {
                    $this->_errors[] = Tools::displayError('Attachment Name Required');
                }
                if (empty($this->_errors)) {
                    if (isset($_FILES['attachment_file']) and is_uploaded_file($_FILES['attachment_file']['tmp_name'])) {
                        if ($_FILES['attachment_file']['size'] > Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) {
                            $this->_errors[] = $this->l('File too large, maximum size allowed:') . ' ' . Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 . ' ' . $this->l('kb') . '. ' . $this->l('File size you\'re trying to upload is:') . number_format($_FILES['attachment_file']['size'] / 1024, 2, '.', '') . $this->l('kb');
                        } else {
                            do {
                                $uniqid = sha1(microtime());
                            } while (file_exists(_PS_DOWNLOAD_DIR_ . $uniqid));
                            if (!copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_ . $uniqid)) {
                                $this->_errors[] = $this->l('File copy failed');
                            }
                            @unlink($_FILES['attachment_file']['tmp_name']);
                        }
                    } else {
                        if ((int) $_FILES['attachment_file']['error'] === 1) {
                            $max_upload = (int) ini_get('upload_max_filesize');
                            $max_post = (int) ini_get('post_max_size');
                            $upload_mb = min($max_upload, $max_post);
                            $this->_errors[] = $this->l('the File') . ' <b>' . $_FILES['attachment_file']['name'] . '</b> ' . $this->l('exceeds the size allowed by the server, this limit is set to') . ' <b>' . $upload_mb . $this->l('Mb') . '</b>';
                        }
                    }
                    if (empty($this->_errors) && isset($uniqid)) {
                        $attachment = new Attachment();
                        foreach ($languages as $language) {
                            if (isset($_POST['attachment_name_' . (int) $language['id_lang']])) {
                                $attachment->name[(int) $language['id_lang']] = pSQL($_POST['attachment_name_' . (int) $language['id_lang']]);
                            }
                            if (isset($_POST['attachment_description_' . (int) $language['id_lang']])) {
                                $attachment->description[(int) $language['id_lang']] = pSQL($_POST['attachment_description_' . (int) $language['id_lang']]);
                            }
                        }
                        $attachment->file = $uniqid;
                        $attachment->mime = $_FILES['attachment_file']['type'];
                        $attachment->file_name = pSQL($_FILES['attachment_file']['name']);
                        if (empty($attachment->mime) or Tools::strlen($attachment->mime) > 64) {
                            $this->_errors[] = Tools::displayError('Invalid file extension');
                        }
                        if (!Validate::isGenericName($attachment->file_name)) {
                            $this->_errors[] = Tools::displayError('Invalid file name');
                        }
                        if (Tools::strlen($attachment->file_name) > 128) {
                            $this->_errors[] = Tools::displayError('File name too long');
                        }
                        if (!sizeof($this->_errors)) {
                            $attachment->add();
                            Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue($this->identifier) . '&id_category=' . (int) Tools::getValue('id_category') . '&addproduct&conf=4&tabs=6&token=' . ($token ? $token : $this->token));
                        } else {
                            $this->_errors[] = Tools::displayError('Invalid file');
                        }
                    }
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add here.');
            }
        } elseif (Tools::isSubmit('submitAttachments')) {
            if ($this->tabAccess['edit'] === '1') {
                if ($id = (int) Tools::getValue($this->identifier)) {
                    if (Attachment::attachToProduct($id, $_POST['attachments'])) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $id . (isset($_POST['id_category']) ? '&id_category=' . (int) $_POST['id_category'] : '') . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token));
                    }
                }
            }
        } elseif (isset($_GET['duplicate' . $this->table])) {
            if ($this->tabAccess['add'] === '1') {
                if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
                    $id_product_old = $product->id;
                    unset($product->id);
                    unset($product->id_product);
                    $product->indexed = 0;
                    $product->active = 0;
                    if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateSpecificPrices($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id) and Product::duplicateDownload($id_product_old, $product->id)) {
                        if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) {
                            $this->_errors[] = Tools::displayError('An error occurred while copying images.');
                        } else {
                            Hook::addProduct($product);
                            Search::indexation(false);
                            Tools::redirectAdmin($currentIndex . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&conf=19&token=' . ($token ? $token : $this->token));
                        }
                    } else {
                        $this->_errors[] = Tools::displayError('An error occurred while creating object.');
                    }
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add here.');
            }
        } elseif (isset($_GET['status']) and Tools::getValue($this->identifier)) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($object = $this->loadObject())) {
                    if ($object->toggleStatus()) {
                        Tools::redirectAdmin($currentIndex . '&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1' and Tools::getValue('id_product')) ? '&id_category=' . $id_category : '') . '&token=' . $token);
                    } else {
                        $this->_errors[] = Tools::displayError('An error occurred while updating status.');
                    }
                } else {
                    $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        } elseif (isset($_GET['delete' . $this->table])) {
            if ($this->tabAccess['delete'] === '1') {
                if (Validate::isLoadedObject($object = $this->loadObject()) and isset($this->fieldImageSettings)) {
                    // check if request at least one object with noZeroObject
                    if (isset($object->noZeroObject) and sizeof($taxes = call_user_func(array($this->className, $object->noZeroObject))) <= 1) {
                        $this->_errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.');
                    } else {
                        $id_category = Tools::getValue('id_category');
                        $category_url = empty($id_category) ? '' : '&id_category=' . $id_category;
                        if ($this->table == 'product') {
                            $product = new Product($object->id);
                            $product->deleteImages();
                        } else {
                            $this->deleteImage($object->id);
                        }
                        if ($this->deleted) {
                            $object->deleted = 1;
                            if ($object->update()) {
                                Tools::redirectAdmin($currentIndex . '&conf=1&token=' . ($token ? $token : $this->token) . $category_url);
                            }
                        } elseif ($object->delete()) {
                            Tools::redirectAdmin($currentIndex . '&conf=1&token=' . ($token ? $token : $this->token) . $category_url);
                        }
                        $this->_errors[] = Tools::displayError('An error occurred during deletion.');
                    }
                } else {
                    $this->_errors[] = Tools::displayError('An error occurred while deleting object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::getValue('submitDel' . $this->table)) {
            if ($this->tabAccess['delete'] === '1') {
                if (isset($_POST[$this->table . 'Box'])) {
                    $object = new $this->className();
                    if (isset($object->noZeroObject) and (sizeof(call_user_func(array($this->className, $object->noZeroObject))) <= 1 or sizeof($_POST[$this->table . 'Box']) == sizeof(call_user_func(array($this->className, $object->noZeroObject))))) {
                        $this->_errors[] = Tools::displayError('You need at least one object.') . ' <b>' . $this->table . '</b><br />' . Tools::displayError('You cannot delete all of the items.');
                    } else {
                        $result = true;
                        if ($this->deleted) {
                            foreach (Tools::getValue($this->table . 'Box') as $id) {
                                $toDelete = new $this->className($id);
                                $toDelete->deleted = 1;
                                $result = $result and $toDelete->update();
                            }
                        } else {
                            $result = $object->deleteSelection(Tools::getValue($this->table . 'Box'));
                        }
                        if ($result) {
                            $id_category = Tools::getValue('id_category');
                            $category_url = empty($id_category) ? '' : '&id_category=' . $id_category;
                            Tools::redirectAdmin($currentIndex . '&conf=2&token=' . $token . $category_url);
                        }
                        $this->_errors[] = Tools::displayError('An error occurred while deleting selection.');
                    }
                } else {
                    $this->_errors[] = Tools::displayError('You must select at least one element to delete.');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif ($id_image = (int) Tools::getValue('id_image') and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) {
            if ($this->tabAccess['edit'] === '1') {
                /* Delete product image */
                if (isset($_GET['deleteImage'])) {
                    $image->delete();
                    deleteImage($image->id_product, $image->id);
                    if (!Image::getCover($image->id_product)) {
                        $first_img = Db::getInstance()->getRow('
						SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image`
						WHERE `id_product` = ' . (int) $image->id_product);
                        Db::getInstance()->Execute('
						UPDATE `' . _DB_PREFIX_ . 'image`
						SET `cover` = 1
						WHERE `id_image` = ' . (int) $first_img['id_image']);
                    }
                    @unlink(_PS_TMP_IMG_DIR_ . '/product_' . $image->id_product . '.jpg');
                    @unlink(_PS_TMP_IMG_DIR_ . '/product_mini_' . $image->id_product . '.jpg');
                    Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token));
                } elseif (isset($_GET['editImage'])) {
                    if ($image->cover) {
                        $_POST['cover'] = 1;
                    }
                    $languages = Language::getLanguages(false);
                    foreach ($languages as $language) {
                        if (isset($image->legend[$language['id_lang']])) {
                            $_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']];
                        }
                    }
                    $_POST['id_image'] = $image->id;
                    $this->displayForm();
                } elseif (isset($_GET['coverImage'])) {
                    Image::deleteCover($image->id_product);
                    $image->cover = 1;
                    if (!$image->update()) {
                        $this->_errors[] = Tools::displayError('Cannot change the product cover');
                    } else {
                        $productId = (int) Tools::getValue('id_product');
                        @unlink(_PS_TMP_IMG_DIR_ . '/product_' . $productId . '.jpg');
                        @unlink(_PS_TMP_IMG_DIR_ . '/product_mini_' . $productId . '.jpg');
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token));
                    }
                } elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) {
                    $image->positionImage((int) Tools::getValue('imgPosition'), (int) Tools::getValue('imgDirection'));
                    Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token));
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        } elseif (Tools::isSubmit('submitProductAttribute')) {
            if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
                if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) {
                    $this->_errors[] = Tools::displayError('Attribute price required.');
                }
                if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) {
                    $this->_errors[] = Tools::displayError('You must add at least one attribute.');
                }
                if (!sizeof($this->_errors)) {
                    if (!isset($_POST['attribute_wholesale_price'])) {
                        $_POST['attribute_wholesale_price'] = 0;
                    }
                    if (!isset($_POST['attribute_price_impact'])) {
                        $_POST['attribute_price_impact'] = 0;
                    }
                    if (!isset($_POST['attribute_weight_impact'])) {
                        $_POST['attribute_weight_impact'] = 0;
                    }
                    if (!isset($_POST['attribute_ecotax'])) {
                        $_POST['attribute_ecotax'] = 0;
                    }
                    if (Tools::getValue('attribute_default')) {
                        $product->deleteDefaultAttributes();
                    }
                    // Change existing one
                    if ($id_product_attribute = (int) Tools::getValue('id_product_attribute')) {
                        if ($this->tabAccess['edit'] === '1') {
                            if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) {
                                $this->_errors[] = Tools::displayError('This attribute already exists.');
                            } else {
                                $product->updateProductAttribute($id_product_attribute, Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), false, Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'), Tools::getValue('minimal_quantity'));
                                if ($id_reason = (int) Tools::getValue('id_mvt_reason') and (int) Tools::getValue('attribute_mvt_quantity') > 0 and $id_reason > 0) {
                                    $reason = new StockMvtReason((int) $id_reason);
                                    $qty = Tools::getValue('attribute_mvt_quantity') * $reason->sign;
                                    if (!$product->addStockMvt($qty, $id_reason, (int) $id_product_attribute, NULL, $cookie->id_employee)) {
                                        $this->_errors[] = Tools::displayError('An error occurred while updating qty.');
                                    }
                                }
                                Hook::updateProductAttribute((int) $id_product_attribute);
                            }
                        } else {
                            $this->_errors[] = Tools::displayError('You do not have permission to add here.');
                        }
                    } else {
                        if ($this->tabAccess['add'] === '1') {
                            if ($product->productAttributeExists($_POST['attribute_combinaison_list'])) {
                                $this->_errors[] = Tools::displayError('This combination already exists.');
                            } else {
                                $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_unity') * Tools::getValue('attribute_unit_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'), Tools::getValue('attribute_upc'));
                            }
                        } else {
                            $this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('Edit here.');
                        }
                    }
                    if (!sizeof($this->_errors)) {
                        $product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list'));
                        $product->checkDefaultAttributes();
                    }
                    if (!sizeof($this->_errors)) {
                        if (!$product->cache_default_attribute) {
                            $product->cache_default_attribute = 1;
                            $product->update();
                        }
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token));
                    }
                }
            }
        } elseif (Tools::isSubmit('deleteProductAttribute')) {
            if ($this->tabAccess['delete'] === '1') {
                if ($id_product = (int) Tools::getValue('id_product') and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) {
                    $product->deleteAttributeCombinaison((int) Tools::getValue('id_product_attribute'));
                    $product->checkDefaultAttributes();
                    $product->updateQuantityProductWithAttributeQuantity();
                    if (!$product->hasAttributes()) {
                        $product->cache_default_attribute = 0;
                        $product->update();
                    }
                    Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token));
                } else {
                    $this->_errors[] = Tools::displayError('Cannot delete attribute');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::isSubmit('deleteAllProductAttributes')) {
            if ($this->tabAccess['delete'] === '1') {
                if ($id_product = (int) Tools::getValue('id_product') and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) {
                    $product->deleteProductAttributes();
                    $product->updateQuantityProductWithAttributeQuantity();
                    if ($product->cache_default_attribute) {
                        $product->cache_default_attribute = 0;
                        $product->update();
                    }
                    Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token));
                } else {
                    $this->_errors[] = Tools::displayError('Cannot delete attributes');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::isSubmit('defaultProductAttribute')) {
            if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
                $product->deleteDefaultAttributes();
                $product->setDefaultAttribute((int) Tools::getValue('id_product_attribute'));
                Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&tabs=3&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token));
            } else {
                $this->_errors[] = Tools::displayError('Cannot make default attribute');
            }
        } elseif (Tools::isSubmit('submitProductFeature')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
                    // delete all objects
                    $product->deleteFeatures();
                    // add new objects
                    $languages = Language::getLanguages(false);
                    foreach ($_POST as $key => $val) {
                        if (preg_match('/^feature_([0-9]+)_value/i', $key, $match)) {
                            if ($val) {
                                $product->addFeaturesToDB($match[1], $val);
                            } else {
                                if ($default_value = $this->checkFeatures($languages, $match[1])) {
                                    $id_value = $product->addFeaturesToDB($match[1], 0, 1, (int) $language['id_lang']);
                                    foreach ($languages as $language) {
                                        if ($cust = Tools::getValue('custom_' . $match[1] . '_' . (int) $language['id_lang'])) {
                                            $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $cust);
                                        } else {
                                            $product->addFeaturesCustomToDB($id_value, (int) $language['id_lang'], $default_value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . (int) $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=4&conf=4&token=' . ($token ? $token : $this->token));
                    }
                } else {
                    $this->_errors[] = Tools::displayError('Product must be created before adding features.');
                }
            }
            $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
        } elseif (Tools::isSubmit('submitPricesModification')) {
            $_POST['tabs'] = 5;
            if ($this->tabAccess['edit'] === '1') {
                $id_specific_prices = Tools::getValue('spm_id_specific_price');
                $id_shops = Tools::getValue('spm_id_shop');
                $id_currencies = Tools::getValue('spm_id_currency');
                $id_countries = Tools::getValue('spm_id_country');
                $id_groups = Tools::getValue('spm_id_group');
                $prices = Tools::getValue('spm_price');
                $from_quantities = Tools::getValue('spm_from_quantity');
                $reductions = Tools::getValue('spm_reduction');
                $reduction_types = Tools::getValue('spm_reduction_type');
                $froms = Tools::getValue('spm_from');
                $tos = Tools::getValue('spm_to');
                foreach ($id_specific_prices as $key => $id_specific_price) {
                    if ($this->_validateSpecificPrice($id_shops[$key], $id_currencies[$key], $id_countries[$key], $id_groups[$key], $prices[$key], $from_quantities[$key], $reductions[$key], $reduction_types[$key], $froms[$key], $tos[$key])) {
                        $specificPrice = new SpecificPrice((int) $id_specific_price);
                        $specificPrice->id_shop = (int) $id_shops[$key];
                        $specificPrice->id_currency = (int) $id_currencies[$key];
                        $specificPrice->id_country = (int) $id_countries[$key];
                        $specificPrice->id_group = (int) $id_groups[$key];
                        $specificPrice->price = (double) $prices[$key];
                        $specificPrice->from_quantity = (int) $from_quantities[$key];
                        $specificPrice->reduction = (double) ($reduction_types[$key] == 'percentage' ? $reductions[$key] / 100 : $reductions[$key]);
                        $specificPrice->reduction_type = !$reductions[$key] ? 'amount' : $reduction_types[$key];
                        $specificPrice->from = !$froms[$key] ? '0000-00-00 00:00:00' : $froms[$key];
                        $specificPrice->to = !$tos[$key] ? '0000-00-00 00:00:00' : $tos[$key];
                        if (!$specificPrice->update()) {
                            $this->_errors = Tools::displayError('An error occurred while updating the specific price.');
                        }
                    }
                }
                if (!sizeof($this->_errors)) {
                    Tools::redirectAdmin($currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&update' . $this->table . '&tabs=2&token=' . ($token ? $token : $this->token));
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add here.');
            }
        } elseif (Tools::isSubmit('submitPriceAddition')) {
            if ($this->tabAccess['add'] === '1') {
                $id_product = (int) Tools::getValue('id_product');
                $id_shop = Tools::getValue('sp_id_shop');
                $id_currency = Tools::getValue('sp_id_currency');
                $id_country = Tools::getValue('sp_id_country');
                $id_group = Tools::getValue('sp_id_group');
                $price = Tools::getValue('sp_price');
                $from_quantity = Tools::getValue('sp_from_quantity');
                $reduction = (double) Tools::getValue('sp_reduction');
                $reduction_type = !$reduction ? 'amount' : Tools::getValue('sp_reduction_type');
                $from = Tools::getValue('sp_from');
                $to = Tools::getValue('sp_to');
                if ($this->_validateSpecificPrice($id_shop, $id_currency, $id_country, $id_group, $price, $from_quantity, $reduction, $reduction_type, $from, $to)) {
                    $specificPrice = new SpecificPrice();
                    $specificPrice->id_product = $id_product;
                    $specificPrice->id_shop = (int) $id_shop;
                    $specificPrice->id_currency = (int) $id_currency;
                    $specificPrice->id_country = (int) $id_country;
                    $specificPrice->id_group = (int) $id_group;
                    $specificPrice->price = (double) $price;
                    $specificPrice->from_quantity = (int) $from_quantity;
                    $specificPrice->reduction = (double) ($reduction_type == 'percentage' ? $reduction / 100 : $reduction);
                    $specificPrice->reduction_type = $reduction_type;
                    $specificPrice->from = !$from ? '0000-00-00 00:00:00' : $from;
                    $specificPrice->to = !$to ? '0000-00-00 00:00:00' : $to;
                    if (!$specificPrice->add()) {
                        $this->_errors = Tools::displayError('An error occurred while updating the specific price.');
                    } else {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $id_product . '&add' . $this->table . '&tabs=2&conf=3&token=' . ($token ? $token : $this->token));
                    }
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add here.');
            }
        } elseif (Tools::isSubmit('deleteSpecificPrice')) {
            if ($this->tabAccess['delete'] === '1') {
                if (!($obj = $this->loadObject())) {
                    return;
                }
                if (!($id_specific_price = Tools::getValue('id_specific_price')) or !Validate::isUnsignedId($id_specific_price)) {
                    $this->_errors[] = Tools::displayError('Invalid specific price ID');
                } else {
                    $specificPrice = new SpecificPrice((int) $id_specific_price);
                    if (!$specificPrice->delete()) {
                        $this->_errors[] = Tools::displayError('An error occurred while deleting the specific price');
                    } else {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=1&token=' . ($token ? $token : $this->token));
                    }
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::isSubmit('submitSpecificPricePriorities')) {
            if (!($obj = $this->loadObject())) {
                return;
            }
            if (!($priorities = Tools::getValue('specificPricePriority'))) {
                $this->_errors[] = Tools::displayError('Please specify priorities');
            } elseif (Tools::isSubmit('specificPricePriorityToAll')) {
                if (!SpecificPrice::setPriorities($priorities)) {
                    $this->_errors[] = Tools::displayError('An error occurred while updating priorities.');
                } else {
                    Tools::redirectAdmin($currentIndex . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=4&token=' . ($token ? $token : $this->token));
                }
            } elseif (!SpecificPrice::setSpecificPriority((int) $obj->id, $priorities)) {
                $this->_errors[] = Tools::displayError('An error occurred while setting priorities.');
            } else {
                Tools::redirectAdmin($currentIndex . '&id_product=' . $obj->id . '&add' . $this->table . '&tabs=2&conf=4&token=' . ($token ? $token : $this->token));
            }
        } elseif (Tools::isSubmit('submitCustomizationConfiguration')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
                    if (!$product->createLabels((int) $_POST['uploadable_files'] - (int) $product->uploadable_files, (int) $_POST['text_fields'] - (int) $product->text_fields)) {
                        $this->_errors[] = Tools::displayError('An error occurred while creating customization fields.');
                    }
                    if (!sizeof($this->_errors) and !$product->updateLabels()) {
                        $this->_errors[] = Tools::displayError('An error occurred while updating customization.');
                    }
                    $product->uploadable_files = (int) $_POST['uploadable_files'];
                    $product->text_fields = (int) $_POST['text_fields'];
                    $product->customizable = ((int) $_POST['uploadable_files'] > 0 or (int) $_POST['text_fields'] > 0) ? 1 : 0;
                    if (!sizeof($this->_errors) and !$product->update()) {
                        $this->_errors[] = Tools::displayError('An error occurred while updating customization configuration.');
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=5&token=' . ($token ? $token : $this->token));
                    }
                } else {
                    $this->_errors[] = Tools::displayError('Product must be created before adding customization possibilities.');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        } elseif (Tools::isSubmit('submitProductCustomization')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($product = new Product((int) Tools::getValue('id_product')))) {
                    foreach ($_POST as $field => $value) {
                        if (strncmp($field, 'label_', 6) == 0 and !Validate::isLabel($value)) {
                            $this->_errors[] = Tools::displayError('Label fields are invalid');
                        }
                    }
                    if (!sizeof($this->_errors) and !$product->updateLabels()) {
                        $this->_errors[] = Tools::displayError('An error occurred while updating customization.');
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . (!empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') . '&add' . $this->table . '&tabs=5&token=' . ($token ? $token : $this->token));
                    }
                } else {
                    $this->_errors[] = Tools::displayError('Product must be created before adding customization possibilities.');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
            }
        } elseif (isset($_GET['position'])) {
            if ($this->tabAccess['edit'] !== '1') {
                $this->_errors[] = Tools::displayError('You do not have permission to edit here.');
            } elseif (!Validate::isLoadedObject($object = $this->loadObject())) {
                $this->_errors[] = Tools::displayError('An error occurred while updating status for object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)');
            }
            if (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) {
                $this->_errors[] = Tools::displayError('Failed to update the position.');
            } else {
                Tools::redirectAdmin($currentIndex . '&' . $this->table . 'Orderby=position&' . $this->table . 'Orderway=asc&conf=5' . (($id_category = !empty($_REQUEST['id_category']) ? $_REQUEST['id_category'] : '1') ? '&id_category=' . $id_category : '') . '&token=' . Tools::getAdminTokenLite('AdminCatalog'));
            }
        } else {
            parent::postProcess(true);
        }
    }
示例#20
0
 function atualizar($id = 0)
 {
     $data = array();
     $dados = array();
     $file_existente = (bool) $this->input->post('file_existente');
     if ($file_existente) {
         $_POST['arquivo'] = $this->input->post('file_select');
     }
     if (!$id) {
         redirect('admin');
         die;
     }
     $prod = $this->product->getProductById($id);
     if ($_FILES['userfile']['name'] and !$_FILES['userfile']['error']) {
         deleteImage($prod['image']);
         $data += array('image_data' => $this->enviaImagem());
     }
     if (!$file_existente) {
         if ($_FILES['arquivo']['name'] and !$_FILES['arquivo']['error']) {
             $data += array('file_data' => $this->enviaArquivo());
             $_POST['arquivo'] = $data['file_data']['file_name'] ? $data['file_data']['file_name'] : $prod['arquivo'];
         } else {
             $_POST['arquivo'] = $_FILES['arquivo']['name'] ? $_FILES['arquivo']['name'] : $prod['arquivo'];
         }
     }
     $_POST['userfile'] = $_FILES['userfile']['name'] ? $_FILES['userfile']['name'] : $prod['image'];
     $data += $this->_getDataEdit($id);
     //caso a validação esteja ok
     if ($this->validation->run()) {
         $dados += array('nome' => $this->input->post('nome'), 'preco' => $this->input->post('preco'), 'descricao' => $this->input->post('descricao'), 'image' => $this->input->post('userfile'), 'arquivo' => $this->input->post('arquivo'));
         $dados = $this->input->xss_clean($dados);
         if ($id) {
             $this->product->updateProduct(array('id_produto' => $id), $dados);
         }
         $msg = sprintf('Produto <span>"%s"</span> foi atualizado com sucesso!', $dados['nome']);
         $this->messages->add($msg, 'done');
     }
     $this->load->view('admin-produto', $data);
     //redirect('produto/editar/'.$id); die();
 }
示例#21
0
 protected function _before_delete($option)
 {
     if (is_array($option['where']['id'])) {
         $this->error = '不支持批量删除';
         return FALSE;
     }
     $images = $this->field('logo,sm_logo')->find($option['where']['id']);
     deleteImage($images);
     /****************************** 先删除商品的其他的信息 ********************************/
     // 扩展分类
     $model = M('GoodsCat');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     // 会员价格
     $model = M('MemberPrice');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     // 商品属性
     $model = M('GoodsAttr');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     // 商品库存量
     $model = M('GoodsNumber');
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
     // 商品图片
     $model = M('GoodsPics');
     // 先取出图片的路径
     $pics = $model->field('pic,sm_pic')->where(array('goods_id' => array('eq', $option['where']['id'])))->select();
     // 循环每个图片进行删除
     foreach ($pics as $p) {
         deleteImage($p);
     }
     $model->where(array('goods_id' => array('eq', $option['where']['id'])))->delete();
 }
示例#22
0
 protected function uninstallImage()
 {
     $logo = Db::getInstance()->executeS('SELECT logo FROM `' . _DB_PREFIX_ . 'hometabfeatures`');
     $image = Db::getInstance()->executeS('SELECT image FROM `' . _DB_PREFIX_ . 'hometabfeatures`');
     foreach ($logo as $log) {
         deleteImage($log);
     }
     foreach ($image as $img) {
         deleteImage($img);
     }
 }
            break;
        case 'resize':
            $width = isset($_REQUEST["width"]) ? intval($_REQUEST["width"]) : 0;
            $height = isset($_REQUEST["height"]) ? intval($_REQUEST["height"]) : 0;
            $imageSrc = isset($_REQUEST["image"]) ? $_REQUEST["image"] : '';
            print_r(json_encode(resizeImage($imagesPath, $imagesThumbsPath, $imagesUrl, $imageSrc, $width, $height)));
            break;
        case 'imagesList':
            $limit = isset($_REQUEST["limit"]) ? intval($_REQUEST["limit"]) : 10;
            $start = isset($_REQUEST["start"]) ? intval($_REQUEST["start"]) : 0;
            $query = isset($_REQUEST["query"]) ? $_REQUEST["query"] : 0;
            print_r(json_encode(getImages($imagesPath, $imagesUrl, $imagesTumbsUrl, $imagesThumbsPath, $allowedFormats, $start, $limit, $query)));
            break;
        case 'delete':
            $image = isset($_REQUEST["image"]) ? stripslashes($_REQUEST["image"]) : "";
            print_r(json_encode(deleteImage($imagesPath, $imagesThumbsPath, $image)));
            break;
    }
}
function checkAllowedFormats($imageName, $allowedFormats)
{
    // quitamos caracteres extraños
    $imageName = preg_replace('/[^(\\x20-\\x7F)]*/', '', $imageName);
    // extensión del archivo
    $ext = strtolower(substr($imageName, strpos($imageName, '.') + 1, strlen($imageName) - 1));
    if (!in_array($ext, explode(',', $allowedFormats))) {
        return false;
    } else {
        return true;
    }
}
示例#24
0
$post = get_post($post_id, false);
// ak sme nezískali žiadne dáta, článok neexistuje a zobrazíme 404 stránku
if (!$post) {
    show_404();
}
// ak prihlásený užívateľ nie je majteľom článku, zobrazíme 404 stránku
if (!is_owner($post)) {
    show_404();
}
// ak bol na túto stránku odoslaný formulár...
if (is_post()) {
    // ... vymažeme článok ...
    if (edit_post($post_id)) {
        // ... a ak sa úspešne aktualizoval skúsime pridať alebo odstrániť obrázok...
        if ($post["has_image"] && isset($_POST["delete_image"])) {
            deleteImage($post_id);
        } else {
            addImage($post_id);
        }
        // ... a nakoniec presmerujeme na článok
        redirect("clanok/" . $post_id);
    }
}
$tags = get_tags($post["id"]);
include_header(array("title" => "Úprava článku"));
?>

    <h1 class="text-center">Úprava článku</h1>

    <form method="post" enctype="multipart/form-data">
示例#25
0
 protected function _before_delete($option)
 {
     if (is_array($option['where']['id'])) {
         $this->error = '不支持批量删除';
         return FALSE;
     }
     $images = $this->field('device_img,sm_img')->find($option['where']['id']);
     deleteImage($images);
     /****************************** 先删除设备的其他的信息 ********************************/
     // 扩展分类
     $model = M('DeviceCat');
     $model->where(array('device_id' => array('eq', $option['where']['id'])))->delete();
     // 设备属性
     $model = M('DeviceAttr');
     $model->where(array('device_id' => array('eq', $option['where']['id'])))->delete();
     $model->where(array('device_id' => array('eq', $option['where']['id'])))->delete();
 }
 public function ajaxDelImage()
 {
     $picId = I('get.pic_id');
     $gpModel = M('GoodsPics');
     // 先取出图片的路径
     $pic = $gpModel->field('pic,sm_pic')->find($picId);
     // 把图片从硬盘上删除
     deleteImage($pic);
     // 再从数据库中把图片的数据也删除掉
     $gpModel->delete($picId);
 }
示例#27
0
        $back_delta = 0;
        break;
    case "home":
    default:
        $back_src = "connection_" . $_SESSION['language'] . ".php?type=login";
        $back_delta = -1;
        break;
}
function formIsValid()
{
    $string = isset($_POST['n_caver_check']) ? $_POST['n_caver_check'] : '';
    $user_check = isset($_SESSION['userCheck']) ? $_SESSION['userCheck'] : '';
    $check = md5(getIp() . strtolower($string)) == $user_check;
    return $check;
}
deleteImage();
?>
    <script type="text/javascript" src="../scripts/classeGCTest.js"></script>
    <script type="text/javascript">
    <?php 
echo getCDataTag(true);
switch ($type) {
    case "login":
        ?>
    function loginSubmit(event) {
      var oForm = document.login_user;
      oForm.l_caver_password.value = c(oForm.l_caver_password.value, oForm.l_key.value);
      return true;
    }
    
    function loginBeforeLoad(failed) {
示例#28
0
// Change Order of Albums
if ($_GET['albums_new_order'] && $_GET['order_string']) {
    $order_string = $_GET['order_string'];
    $ids = explode(",", $order_string);
    foreach ($ids as $id_str) {
        $order_row = explode("=", $id_str);
        $order_id = $order_row[0];
        $album_id = $order_row[1];
        mysql_query("UPDATE `mbg_albums` SET `OrderID` = '{$order_id}' WHERE `AlbumID` = '{$album_id}'");
    }
    @mysql_close($connect);
    exit;
}
// Delete Image from Album
if ($image_id = $_GET['deleteimageid']) {
    deleteImage($image_id);
    @mysql_close($connect);
    exit;
}
// Change Image Name
if (isset($_POST['change_img_name'])) {
    $image_id = $_POST['image_id'];
    $name = $_POST['name'];
    if ($image_id) {
        setImageName($image_id, $name);
        define("_SUCCESS_", "Image name has been saved");
    }
}
// Edit Album Info
if (isset($_POST['edit_album'])) {
    $album_id = $_GET['id'];
    public function postProcess($token = NULL)
    {
        global $currentIndex;
        /* Add a new product */
        if (Tools::isSubmit('submitAddproduct') or Tools::isSubmit('submitAddproductAndStay')) {
            if ($this->tabAccess['add'] === '1') {
                $this->submitAddproduct($token);
            } elseif (Tools::getValue('id_product') and $this->tabAccess['edit'] === '1') {
                $this->submitAddproduct($token);
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add anything here.');
            }
        }
        /* Delete a product in the download folder */
        if (Tools::getValue('deleteVirtualProduct')) {
            if ($this->tabAccess['delete'] === '1') {
                $this->deleteVirtualProduct();
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete anything here.');
            }
        } elseif (Tools::isSubmit('submitAttachments')) {
            if ($this->tabAccess['edit'] === '1') {
                if ($id = intval(Tools::getValue($this->identifier))) {
                    if (Attachment::attachToProduct($id, $_POST['attachments'])) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $id . '&conf=4&add' . $this->table . '&tabs=6&token=' . ($token ? $token : $this->token));
                    }
                }
            }
        } elseif (isset($_GET['duplicate' . $this->table])) {
            if ($this->tabAccess['add'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    $id_product_old = $product->id;
                    unset($product->id);
                    unset($product->id_product);
                    $product->indexed = 0;
                    if ($product->add() and Category::duplicateProductCategories($id_product_old, $product->id) and ($combinationImages = Product::duplicateAttributes($id_product_old, $product->id)) !== false and Product::duplicateAccessories($id_product_old, $product->id) and Product::duplicateFeatures($id_product_old, $product->id) and Product::duplicateQuantityDiscount($id_product_old, $product->id) and Pack::duplicate($id_product_old, $product->id) and Product::duplicateCustomizationFields($id_product_old, $product->id) and Product::duplicateTags($id_product_old, $product->id)) {
                        if (!Tools::getValue('noimage') and !Image::duplicateProductImages($id_product_old, $product->id, $combinationImages)) {
                            $this->_errors[] = Tools::displayError('an error occurred while copying images');
                        } else {
                            Hook::addProduct($product);
                            Search::indexation(false);
                            Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=19&token=' . ($token ? $token : $this->token));
                        }
                    } else {
                        $this->_errors[] = Tools::displayError('an error occurred while creating object');
                    }
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add anything here.');
            }
        } elseif ($id_image = intval(Tools::getValue('id_image')) and Validate::isUnsignedId($id_image) and Validate::isLoadedObject($image = new Image($id_image))) {
            if ($this->tabAccess['edit'] === '1') {
                /* Delete product image */
                if (isset($_GET['deleteImage'])) {
                    $image->delete();
                    deleteImage($image->id_product, $image->id);
                    if (!Image::getCover($image->id_product)) {
                        $first_img = Db::getInstance()->getRow('
						SELECT `id_image` FROM `' . _DB_PREFIX_ . 'image`
						WHERE `id_product` = ' . intval($image->id_product));
                        Db::getInstance()->Execute('
						UPDATE `' . _DB_PREFIX_ . 'image`
						SET `cover` = 1
						WHERE `id_image` = ' . intval($first_img['id_image']));
                    }
                    @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $image->id_product . '.jpg');
                    @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $image->id_product . '.jpg');
                    Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1' . '&token=' . ($token ? $token : $this->token));
                } elseif (isset($_GET['editImage'])) {
                    if ($image->cover) {
                        $_POST['cover'] = 1;
                    }
                    $languages = Language::getLanguages();
                    foreach ($languages as $language) {
                        if (isset($image->legend[$language['id_lang']])) {
                            $_POST['legend_' . $language['id_lang']] = $image->legend[$language['id_lang']];
                        }
                    }
                    $_POST['id_image'] = $image->id;
                    $this->displayForm($token ? $token : $this->token);
                } elseif (isset($_GET['coverImage'])) {
                    Image::deleteCover($image->id_product);
                    $image->cover = 1;
                    if (!$image->update()) {
                        $this->_errors[] = Tools::displayError('Impossible to change the product cover');
                    } else {
                        $productId = intval(Tools::getValue('id_product'));
                        @unlink(dirname(__FILE__) . '/../../img/tmp/product_' . $productId . '.jpg');
                        @unlink(dirname(__FILE__) . '/../../img/tmp/product_mini_' . $productId . '.jpg');
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&addproduct&tabs=1' . '&token=' . ($token ? $token : $this->token));
                    }
                } elseif (isset($_GET['imgPosition']) and isset($_GET['imgDirection'])) {
                    $image->positionImage(intval(Tools::getValue('imgPosition')), intval(Tools::getValue('imgDirection')));
                    Tools::redirectAdmin($currentIndex . '&id_product=' . $image->id_product . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=1&token=' . ($token ? $token : $this->token));
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.');
            }
        } elseif (Tools::isSubmit('submitProductAttribute')) {
            if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                if (!isset($_POST['attribute_quantity']) or $_POST['attribute_quantity'] == NULL) {
                    $this->_errors[] = Tools::displayError('attribute quantity is required');
                }
                if (!isset($_POST['attribute_price']) or $_POST['attribute_price'] == NULL) {
                    $this->_errors[] = Tools::displayError('attribute price is required');
                }
                if (!isset($_POST['attribute_combinaison_list']) or !sizeof($_POST['attribute_combinaison_list'])) {
                    $this->_errors[] = Tools::displayError('you must add at least one attribute');
                }
                if (!sizeof($this->_errors)) {
                    if (!isset($_POST['attribute_wholesale_price'])) {
                        $_POST['attribute_wholesale_price'] = 0;
                    }
                    if (!isset($_POST['attribute_price_impact'])) {
                        $_POST['attribute_price_impact'] = 0;
                    }
                    if (!isset($_POST['attribute_weight_impact'])) {
                        $_POST['attribute_weight_impact'] = 0;
                    }
                    if (!isset($_POST['attribute_ecotax'])) {
                        $_POST['attribute_ecotax'] = 0;
                    }
                    if (Tools::getValue('attribute_default')) {
                        $product->deleteDefaultAttributes();
                    }
                    // Change existing one
                    if ($id_product_attribute = intval(Tools::getValue('id_product_attribute'))) {
                        if ($this->tabAccess['edit'] === '1') {
                            if ($product->productAttributeExists($_POST['attribute_combinaison_list'], $id_product_attribute)) {
                                $this->_errors[] = Tools::displayError('This attribute already exists.');
                            } else {
                                $product->updateProductAttribute($id_product_attribute, Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'));
                            }
                        } else {
                            $this->_errors[] = Tools::displayError('You do not have permission to add anything here.');
                        }
                    } else {
                        if ($this->tabAccess['add'] === '1') {
                            if ($product->productAttributeExists($_POST['attribute_combinaison_list'])) {
                                $this->_errors[] = Tools::displayError('This combination already exists.');
                            } else {
                                $id_product_attribute = $product->addCombinationEntity(Tools::getValue('attribute_wholesale_price'), Tools::getValue('attribute_price') * Tools::getValue('attribute_price_impact'), Tools::getValue('attribute_weight') * Tools::getValue('attribute_weight_impact'), Tools::getValue('attribute_ecotax'), Tools::getValue('attribute_quantity'), Tools::getValue('id_image_attr'), Tools::getValue('attribute_reference'), Tools::getValue('attribute_supplier_reference'), Tools::getValue('attribute_ean13'), Tools::getValue('attribute_default'), Tools::getValue('attribute_location'));
                            }
                        } else {
                            $this->_errors[] = Tools::displayError('You do not have permission to') . '<hr>' . Tools::displayError('edit something here.');
                        }
                    }
                    if (!sizeof($this->_errors)) {
                        $product->addAttributeCombinaison($id_product_attribute, Tools::getValue('attribute_combinaison_list'));
                        $product->checkDefaultAttributes();
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=2&token=' . ($token ? $token : $this->token));
                    }
                }
            }
        } elseif (isset($_GET['deleteProductAttribute'])) {
            if ($this->tabAccess['delete'] === '1') {
                if ($id_product = intval(Tools::getValue('id_product')) and Validate::isUnsignedId($id_product) and Validate::isLoadedObject($product = new Product($id_product))) {
                    $product->deleteAttributeCombinaison(intval(Tools::getValue('id_product_attribute')));
                    $product->checkDefaultAttributes();
                    Tools::redirectAdmin($currentIndex . '&add' . $this->table . '&id_category=' . intval(Tools::getValue('id_category')) . '&tabs=2&id_product=' . $product->id . '&token=' . ($token ? $token : $this->token));
                } else {
                    $this->_errors[] = Tools::displayError('impossible to delete attribute');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::isSubmit('submitProductFeature')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    // delete all objects
                    $product->deleteFeatures();
                    // add new objects
                    $languages = Language::getLanguages();
                    foreach ($_POST as $key => $val) {
                        if (preg_match("/^feature_([0-9]+)_value/i", $key, $match)) {
                            if ($val) {
                                $product->addFeaturesToDB($match[1], $val);
                            } else {
                                if ($default_value = $this->checkFeatures($languages, $match[1])) {
                                    $id_value = $product->addFeaturesToDB($match[1], 0, 1, $language['id_lang']);
                                    foreach ($languages as $language) {
                                        if ($cust = Tools::getValue('custom_' . $match[1] . '_' . $language['id_lang'])) {
                                            $product->addFeaturesCustomToDB($id_value, $language['id_lang'], $cust);
                                        } else {
                                            $product->addFeaturesCustomToDB($id_value, $language['id_lang'], $default_value);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=3&token=' . ($token ? $token : $this->token));
                    }
                } else {
                    $this->_errors[] = Tools::displayError('product must be created before adding features');
                }
            }
            $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.');
        } elseif (Tools::isSubmit('submitQuantityDiscount')) {
            $_POST['tabs'] = 5;
            if ($this->tabAccess['add'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    if (!($id_discount_type = intval(Tools::getValue('id_discount_type')))) {
                        $this->_errors[] = Tools::displayError('discount type not selected');
                    } else {
                        if (!($quantity_discount = intval(Tools::getValue('quantity_discount')))) {
                            $this->_errors[] = Tools::displayError('quantity is required');
                        } else {
                            if (!($value_discount = floatval(Tools::getValue('value_discount')))) {
                                $this->_errors[] = Tools::displayError('value is required');
                            } else {
                                $qD = new QuantityDiscount();
                                $qD->id_product = $product->id;
                                $qD->id_discount_type = $id_discount_type;
                                $qD->quantity = $quantity_discount;
                                $qD->value = $value_discount;
                                if ($qD->add() and !sizeof($this->_errors) and $qD->validateFields()) {
                                    Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=5&conf=3&token=' . ($token ? $token : $this->token));
                                }
                                $this->_errors[] = Tools::displayError('an error occurred while creating object');
                            }
                        }
                    }
                } else {
                    $this->_errors[] = Tools::displayError('product must be created before adding quantity discounts');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to add anything here.');
            }
        } elseif (isset($_GET['deleteQuantityDiscount'])) {
            if ($this->tabAccess['delete'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    if (Validate::isLoadedObject($qD = new QuantityDiscount(intval(Tools::getValue('id_quantity_discount'))))) {
                        $qD->delete();
                        if (!sizeof($this->_errors)) {
                            Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=5&conf=1&token=' . ($token ? $token : $this->token));
                        }
                    } else {
                        $this->_errors[] = Tools::displayError('not a valid quantity discount');
                    }
                } else {
                    $this->_errors[] = Tools::displayError('product must be created before delete quantity discounts');
                }
                $qD = new QuantityDiscount();
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } elseif (Tools::isSubmit('submitCustomizationConfiguration')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    if (!$product->createLabels(intval($_POST['uploadable_files']) - intval($product->uploadable_files), intval($_POST['text_fields']) - intval($product->text_fields))) {
                        $this->_errors[] = Tools::displayError('an error occured while creating customization fields');
                    }
                    if (!sizeof($this->_errors) and !$product->updateLabels()) {
                        $this->_errors[] = Tools::displayError('an error occured while updating customization');
                    }
                    $product->uploadable_files = intval($_POST['uploadable_files']);
                    $product->text_fields = intval($_POST['text_fields']);
                    $product->customizable = (intval($_POST['uploadable_files']) > 0 or intval($_POST['text_fields']) > 0) ? 1 : 0;
                    if (!sizeof($this->_errors) and !$product->update()) {
                        $this->_errors[] = Tools::displayError('an error occured while updating customization configuration');
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=4&token=' . ($token ? $token : $this->token));
                    }
                } else {
                    $this->_errors[] = Tools::displayError('product must be created before adding customization possibilities');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.');
            }
        } elseif (Tools::isSubmit('submitProductCustomization')) {
            if ($this->tabAccess['edit'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    foreach ($_POST as $field => $value) {
                        if (strncmp($field, 'label_', 6) == 0 and !Validate::isLabel($value)) {
                            $this->_errors[] = Tools::displayError('label fields are invalid');
                        }
                    }
                    if (!sizeof($this->_errors) and !$product->updateLabels()) {
                        $this->_errors[] = Tools::displayError('an error occured while updating customization');
                    }
                    if (!sizeof($this->_errors)) {
                        Tools::redirectAdmin($currentIndex . '&id_product=' . $product->id . '&id_category=' . intval(Tools::getValue('id_category')) . '&add' . $this->table . '&tabs=4&token=' . ($token ? $token : $this->token));
                    }
                } else {
                    $this->_errors[] = Tools::displayError('product must be created before adding customization possibilities');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to edit anything here.');
            }
        } elseif (isset($_GET['delete' . $this->table])) {
            if ($this->tabAccess['delete'] === '1') {
                if (Validate::isLoadedObject($product = new Product(intval(Tools::getValue('id_product'))))) {
                    if (!$this->deleteImage($product->id)) {
                        $this->_errors[] = Tools::displayError('an error occurred during product image deletion');
                    }
                    if ($product->delete()) {
                        Tools::redirectAdmin($currentIndex . '&id_category=' . intval(Tools::getValue('id_category')) . '&conf=1&token=' . ($token ? $token : $this->token));
                    }
                    $this->_errors[] = Tools::displayError('an error occurred during product deletion');
                }
            } else {
                $this->_errors[] = Tools::displayError('You do not have permission to delete here.');
            }
        } else {
            parent::postProcess(true);
        }
    }
<?php

require "../settings.php";
$items = scandir(MEDIA_DIR);
$result = array();
$target = $_GET["id"];
foreach ($items as $i) {
    if (substr($i, 0, 1) != ".") {
        if ($i === $target) {
            deleteImage($i);
            break;
        }
    }
}
function deleteImage($imageId)
{
    $imageDir = MEDIA_DIR . DIRECTORY_SEPARATOR . $imageId;
    $files = scandir($imageDir);
    foreach ($files as $i) {
        if (substr($i, 0, 1) === ".") {
            continue;
        }
        unlink($imageDir . DIRECTORY_SEPARATOR . $i);
    }
    rmdir($imageDir);
}
header("Content-Type: application/json");
echo json_encode(["success" => true]);