function cw_category_delete($cat, $is_show_process = false)
{
    global $tables;
    // can't delete root category
    if ($cat == 1) {
        return 1;
    }
    $path = cw_category_get_path($cat);
    $parent_category_id = cw_query_first_cell("select parent_id from {$tables['categories']} where category_id='{$cat}'");
    # Delete products from subcategories
    $prods = db_query("select {$tables['products_categories']}.product_id from {$tables['products_categories']}, {$tables['categories_parents']} where ({$tables['categories_parents']}.parent_id ='{$cat}' or {$tables['categories_parents']}.category_id = '{$cat}') and {$tables['products_categories']}.category_id={$tables['categories_parents']}.category_id and {$tables['products_categories']}.main=1");
    cw_load('image', 'attributes', 'product');
    $index = 0;
    if ($prods) {
        while ($prod = db_fetch_array($prods)) {
            cw_call('cw_delete_product', array('product_id' => $prod['product_id'], 'update_categories' => false));
            if ($index++ % 10 == 0) {
                cw_flush('.');
            }
            if ($index % 1000 == 0) {
                cw_flush('<br/>');
            }
        }
    }
    db_free_result($prods);
    # Delete subcategories
    $subcats = cw_category_get_subcategory_ids($cat);
    $subcats[] = $cat;
    if (is_array($subcats)) {
        db_exec("DELETE FROM {$tables['categories']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['categories_stats']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['products_categories']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['categories_subcount']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['featured_products']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['categories_lng']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['categories_memberships']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['categories_parents']} WHERE category_id IN (?)", array($subcats));
        db_exec("DELETE FROM {$tables['categories_parents']} WHERE parent_id IN (?)", array($subcats));
        cw_image_delete($subcats, 'categories_images_thumb');
        cw_call('cw_attributes_cleanup', array($subcats, 'C'));
        if ($index++ % 10 == 0) {
            cw_flush('.');
        }
        if ($index % 1000 == 0) {
            cw_flush('<br/>');
        }
    }
    cw_recalc_subcat_count($path, $is_show_process);
    return $parent_category_id;
}
    if (cw_image_check_posted($file_upload_data['manufacturer_images'])) {
        cw_image_save($file_upload_data['manufacturer_images'], array('id' => $manufacturer_id));
    }
    cw_cache_clean('manufacturers_all');
    cw_header_location("index.php?target={$target}&manufacturer_id={$manufacturer_id}&page={$page}");
}
if ($action == "delete" and !empty($to_delete) && is_array($to_delete)) {
    foreach ($to_delete as $manufacturer_id => $tmp) {
        cw_call('cw_manufacturer_delete', array($manufacturer_id));
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_manufacturer_del");
    cw_cache_clean('manufacturers_all');
    cw_header_location("index.php?target={$target}&page={$page}");
}
if ($action == 'delete_image' && $manufacturer_id) {
    cw_image_delete($manufacturer_id, 'manufacturer_images');
    cw_header_location("index.php?target={$target}&manufacturer_id={$manufacturer_id}");
}
if ($action == "update") {
    if (is_array($records)) {
        foreach ($records as $k => $v) {
            $v['avail'] = $v['avail'] ? 1 : 0;
            $v['featured'] = $v['featured'] ? 1 : 0;
            db_query($sql = "UPDATE {$tables['manufacturers']} SET avail='{$v['avail']}', orderby='{$v['orderby']}', featured='{$v['featured']}' WHERE manufacturer_id='{$k}' {$warehouse_condition}");
        }
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_manufacturers_upd");
    cw_header_location("index.php?target={$target}&manufacturer_id={$manufacturer_id}&page={$page}");
}
if ($manufacturer_id) {
    $manufacturer_data = cw_func_call('cw_manufacturer_get', array('manufacturer_id' => $manufacturer_id));
            unset($data['image_id']);
            $data = cw_array_map("addslashes", $data);
            while ($pid = cw_group_edit_each($ge_id, 1, $product_id)) {
                $id = cw_query_first_cell("SELECT image_id FROM {$tables['products_detailed_images']} WHERE id = '{$pid}' AND md5 = '{$data['md5']}'");
                if (!empty($id)) {
                    cw_image_delete($id, "D", true);
                }
                $data['id'] = $pid;
                cw_array2insert("products_detailed_images", $data);
            }
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_images_upd'), 'type' => 'I');
    cw_dpi_refresh($product_id, 'dpi');
}
if ($action == 'product_images_delete' && is_array($iids)) {
    foreach ($iids as $image_id => $tmp) {
        $md5 = cw_query_first_cell("SELECT md5 FROM {$tables['products_detailed_images']} WHERE image_id = '{$image_id}'");
        cw_image_delete($image_id, 'products_detailed_images', true);
        if ($ge_id && $fields['d_image'][$image_id]) {
            while ($pid = cw_group_edit_each($ge_id, 1, $product_id)) {
                $id = cw_query_first_cell("SELECT image_id FROM {$tables['products_detailed_images']} WHERE id = '{$pid}' AND md5 = '{$md5}'");
                if (!empty($id)) {
                    cw_image_delete($id, "D", true);
                }
            }
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_images_del'), 'type' => 'I');
    cw_dpi_refresh($product_id, 'dpi');
}
         $replace = $result['type'] == 1 ? 'Custom clean url' : 'Clean urls combination';
         $content = str_replace('{{paramname}}', $replace, cw_get_langvar_by_name("lbl_error_param_unique", null, false, true));
         $custom_facet_url_name = cw_clean_url_get_custom_facet_url_name($result['id']);
         $replaced = "<a href='index.php?target=custom_facet_urls&mode=details&custom_facet_url_id=" . $result['id'] . "'>" . $custom_facet_url_name . "</a>";
         $content = str_replace('{{entrylink}}', $replaced, $content);
         $top_message = array('content' => $content, 'type' => 'E');
     }
     $custom_facet_url_data['attribute_value_ids'] = $attribute_value_ids;
     $custom_facet_url_data['custom_facet_url'] = $custom_facet_url;
     $custom_facet_url_data['description'] = $description;
     $custom_facet_url_data['title'] = $title;
     $param = !empty($custom_facet_url_id) ? 'details&custom_facet_url_id=' . $custom_facet_url_id : 'add';
     cw_header_location('index.php?target=custom_facet_urls&mode=' . $param);
 }
 if ($action == 'delete_image' && $custom_facet_url_id) {
     cw_image_delete($custom_facet_url_id, 'facet_categories_images');
     cw_header_location("index.php?target={$target}&mode={$mode}&custom_facet_url_id={$custom_facet_url_id}");
 }
 $custom_facet_url = "";
 if (!empty($custom_facet_url_id)) {
     $result = cw_query_first("\n\t\t\tSELECT *\n\t\t\tFROM {$tables['clean_urls_custom_facet_urls']}\n\t\t\tWHERE url_id = '{$custom_facet_url_id}'\n\t\t");
     $custom_facet_url = $result['custom_facet_url'];
     $description = $result['description'];
     $title = $result['title'];
     $attribute_value_ids_list = cw_query("select attribute_value_ids from {$tables['clean_urls_custom_facet_urls_options']} where url_id='{$custom_facet_url_id}'");
     $attribute_value_ids_data = array();
     foreach ($attribute_value_ids_list as $avi_v) {
         $attribute_value_ids_data = array_merge($attribute_value_ids_data, explode(',', $avi_v['attribute_value_ids']));
     }
 } else {
     $attribute_value_ids_data = explode(',', str_replace('###', ',', $custom_facet_url_data['attribute_value_ids']));
/**
 * Delete product or all products
 * 
 * @param int $product_id
 * @param bool $update_categories - flag to update categories statistic
 * @param bool $delete_all - flag to delete all products, $product_id ignored
 * 
 * @return bool
 */
function cw_delete_product($product_id = 0, $update_categories = true, $delete_all = false)
{
    global $tables, $addons;
    cw_load('category', 'image', 'sections', 'attributes', 'tags');
    if ($delete_all === true) {
        $tables_to_clear = array('products', 'products_stats', 'products_prices', 'products_warehouses_amount', 'featured_products', 'products', 'attributes_values', 'products_categories', 'products_votes', 'products_reviews', 'products_lng', 'download_keys', 'discount_coupons', 'products_bookmarks', 'products_memberships');
        foreach ($tables_to_clear as $table) {
            db_query("delete from " . $tables[$table]);
        }
        cw_delete_sections($product_id);
        cw_image_delete('products_images_thumb');
        cw_image_delete('products_images_det');
        cw_image_delete('products_detailed_images');
        /*
        # kornev, TOFIX
        * TODO: move to addon hook
                # magnifier addon
                if (cw_query_first_cell("SELECT addon_name FROM $tables[addons] WHERE addon_name='magnifier'")) {
                    if (!isset($tables['magnifier_images']))
                        include_once $app_main_dir.'/addons/magnifier/config.php';
        
                    db_query("DELETE FROM $tables[magnifier_images]");
                    $dir_z = cw_image_dir("Z");
                    if (is_dir($dir_z) && file_exists($dir_z))
                        cw_rm_dir($dir_z);
                }
        */
        if ($update_categories) {
            $res = db_query("SELECT category_id FROM {$tables['categories']}");
            cw_recalc_subcat_count($res);
        }
        db_query("DELETE FROM {$tables['products_flat']}");
        // TODO: move to addon
        if ($addons['faq']) {
            cw_load('faq');
            cw_faq_delete_products();
        }
        return true;
    }
    $product_categories = cw_query_column("select {$tables['categories_parents']}.parent_id from {$tables['categories_parents']}, {$tables['products_categories']} where {$tables['categories_parents']}.category_id = {$tables['products_categories']}.category_id and {$tables['products_categories']}.product_id='{$product_id}' group by {$tables['categories_parents']}.parent_id");
    // TODO: move to addon
    if ($addons['faq']) {
        cw_load('faq');
        cw_faq_delete_product($product_id);
    }
    cw_delete_section_product($product_id);
    db_query("DELETE FROM {$tables['products_stats']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_prices']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_warehouses_amount']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['featured_products']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_shipping']} WHERE product_id='{$product_id}'");
    cw_call('cw_attributes_cleanup', array($product_id, 'P'));
    db_query("DELETE FROM {$tables['products_memberships']} WHERE product_id='{$product_id}'");
    cw_image_delete($product_id, 'products_images_thumb');
    cw_image_delete($product_id, 'products_images_det');
    Product\delete($product_id);
    // associate your event handlers with on_product_delete event triggered in this method
    # Product options addon
    /*
    # kornev, TOFIX
    * TODO: move to addon hook
        # magnifier addon
        if (cw_query_first_cell("SELECT addon_name FROM $tables[addons] WHERE addon_name='magnifier'")) {
            if (!isset($tables['magnifier_images'])) {
                include_once $app_main_dir."/addons/magnifier/config.php";
            }
    
            db_query("DELETE FROM $tables[magnifier_images] WHERE id = '$product_id'");
            $dir_z = cw_image_dir("Z").DIRECTORY_SEPARATOR.$product_id;
            if (is_dir($dir_z) && file_exists($dir_z))
                cw_rm_dir($dir_z);
        }
    */
    db_query("DELETE FROM {$tables['products_votes']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_reviews']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_lng']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['download_keys']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['discount_coupons']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_bookmarks']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['products_system_info']} WHERE product_id='{$product_id}'");
    #
    # Update product count for categories
    #
    if ($update_categories && !empty($product_categories)) {
        cw_recalc_subcat_count($product_categories);
    }
    db_query("DELETE FROM {$tables['products_flat']} WHERE product_id = '{$product_id}'");
    cw_tags_clear_product_tags($product_id);
    return true;
}
function ps_delete_image($offer_id)
{
    global $top_message;
    $_action = 'details';
    $_js_tab = 'ps_offer_details';
    $offer_id = (int) $offer_id;
    if (empty($offer_id)) {
        ps_redirect();
    }
    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
        ps_redirect($offer_id, $_action, $_js_tab);
    }
    cw_image_delete($offer_id, PS_IMG_TYPE);
    $top_message = array('content' => cw_get_langvar_by_name('msg_ps_updated_succes'), 'type' => 'I');
    ps_redirect($offer_id, $_action, $_js_tab);
}
}
if ($mode == 'list') {
    $contentsections_filter = array();
}
$redirect_link = 'index.php?target=cms' . (empty($mode) ? '' : '&mode=' . $mode) . (empty($page) ? '' : '&page=' . $page) . (empty($cs_type) ? '' : '&cs_type=' . $cs_type);
if ($REQUEST_METHOD == 'POST') {
    switch ($action) {
        case 'delete_contentsections':
            if (!empty($delete_contentsections) && is_array($delete_contentsections)) {
                $delete_contentsections = array_keys($delete_contentsections);
                db_query("DELETE FROM {$tables['cms']} WHERE contentsection_id IN ('" . implode("','", $delete_contentsections) . "')");
                db_query("DELETE FROM {$tables['cms_restrictions']} WHERE contentsection_id IN ('" . implode("','", $delete_contentsections) . "')");
                db_query("DELETE FROM {$tables['cms_user_counters']} WHERE contentsection_id IN ('" . implode("','", $delete_contentsections) . "')");
                db_query("DELETE FROM {$tables['cms_alt_languages']} WHERE contentsection_id IN ('" . implode("','", $delete_contentsections) . "')");
                foreach ($delete_contentsections as $contentsection_id) {
                    cw_image_delete($contentsection_id, 'cms_images');
                    cw_call('cw_attributes_cleanup', array($contentsection_id, 'AB'));
                }
            }
            break;
        case 'update_filters':
            if (!empty($filter) && is_array($filter)) {
                $date_fields = array(0 => array('start_filter_date' => 0, 'end_filter_date' => 1));
                cw_core_process_date_fields($filter, $date_fields);
                $contentsections_filter = array('type' => $filter['type'], 'name' => stripslashes($filter['name']), 'target' => $filter['target'], 'url' => stripslashes($filter['url']), 'skin' => $filter['skin'], 'service_code' => stripslashes($filter['service_code']), 'start_date' => intval($filter['start_filter_date']), 'end_date' => intval($filter['end_filter_date']), 'sort_field' => 'service_code', 'sort_direction' => 0, 'attributes' => $attributes, 'offers' => $content_section['offers']);
                if (!empty($content_section_clean_urls) && is_array($content_section_clean_urls)) {
                    $contentsections_filter['clean_urls'] = array();
                    foreach ($content_section_clean_urls as $cs_filter_cu) {
                        $filter_clean_url = trim($cs_filter_cu['value']);
                        if (!empty($filter_clean_url)) {
                            $contentsections_filter['clean_urls'][] = $filter_clean_url;
Ejemplo n.º 8
0
function cw_ps_offer_delete($offer_id)
{
    global $tables;
    $offer_id = intval($offer_id);
    $ps_tables = array('ps_bonus_details', 'ps_bonuses', 'ps_cond_details', 'ps_cond_details', 'ps_offers');
    foreach ($ps_tables as $t) {
        if (!empty($tables[$t])) {
            db_query('DELETE FROM ' . $tables[$t] . ' WHERE offer_id="' . $offer_id . '"');
        }
    }
    cw_load('image');
    cw_image_delete($offer_id, 'ps_offer_images');
}
    }
    cw_header_location('index.php?target=' . $target);
}
if ($action == 'images') {
    foreach ($file_upload_data['attributes_images'] as $image) {
        $image_posted = cw_image_check_posted($image);
        if ($image_posted) {
            cw_image_save($image, array('alt' => $alt, 'id' => $attribute_id));
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('lbl_att_images_add'), 'type' => 'I');
    cw_header_location('index.php?target=' . $target . '&mode=att&attribute_id=' . $attribute_id);
}
if ($action == 'images_delete' && is_array($iids)) {
    foreach ($iids as $image_id => $tmp) {
        cw_image_delete($image_id, 'attributes_images', true);
    }
    cw_header_location('index.php?target=' . $target . '&mode=att&attribute_id=' . $attribute_id);
}
if ($action == 'images_update' && !empty($image)) {
    foreach ($image as $key => $value) {
        cw_array2update('attributes_images', $value, "image_id = '{$key}'");
    }
    cw_header_location('index.php?target=' . $target . '&mode=att&attribute_id=' . $attribute_id);
}
if ($mode == 'att' && isset($attribute_id)) {
    $attribute = array();
    if ($attribute_id) {
        $attribute = cw_func_call('cw_attributes_get_attribute', array('attribute_id' => $attribute_id, 'language' => $edited_language));
    }
    if ($attribute_modified_data) {
    cw_load('magnifier');
    foreach ($file_upload_data['magnifier_images'] as $image) {
        $image_posted = cw_image_check_posted($image);
        if ($image_posted) {
            $image_id = cw_image_save($image, array('id' => $product_id));
            $image = cw_image_get('magnifier_images', $image_id);
            $dir_name = cw_magnifier_create($image['image_path'], $image_id);
            db_query("update {$tables['magnifier_images']} set image_path='{$dir_name}/TileGroup0/0-0-0.jpg' where image_id='{$image_id}'");
        }
    }
    $top_message['content'] = cw_get_langvar_by_name('msg_adm_images_added_4zoomer');
    cw_refresh($product_id, 'zoomer');
}
if ($action == "zoomer_update_availability" && !empty($zoomer_image)) {
    # Update images
    foreach ($zoomer_image as $key => $value) {
        db_query("UPDATE {$tables['magnifier_images']} SET orderby='" . $value['orderby'] . "', avail='" . $value['avail'] . "' WHERE image_id='{$key}'");
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_images_updated_4zoomer");
    cw_refresh($product_id, 'zoomer');
}
if ($action == "product_zoomer_delete") {
    if (!empty($iids)) {
        foreach ($iids as $image_id => $tmp) {
            cw_image_delete($image_id, 'magnifier_images');
        }
    }
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_images_deleted_4zoomer");
    cw_refresh($product_id, 'zoomer');
}
$smarty->assign('zoomer_images', cw_image_get_list('magnifier_images', $product_id));
function cw_image_save(&$image_posted, $added_data = array(), $_image_id = NULL)
{
    global $tables, $available_images, $skip_image, $config;
    $type = $image_posted['type'];
    $image_data = cw_image_prepare($image_posted);
    if ($available_images[$type]['max_width']) {
        cw_image_resize($image_data, $available_images[$type]['max_width']);
    } elseif ($config['Appearance']['size_user_avatar'] && $type == 'customers_images') {
        cw_image_resize($image_data, $config['Appearance']['size_user_avatar']);
    }
    if (!empty($added_data)) {
        $image_data = cw_array_merge($image_data, $added_data);
    }
    if (!$image_data || !$image_data['id']) {
        return false;
    }
    if ($skip_image[$type] == 'Y') {
        if (!empty($image_posted['is_copied'])) {
            @unlink($image_posted['file_path']);
        }
        unset($image_posted);
        return false;
    }
    $image_data['date'] = cw_core_get_time();
    $image_data = cw_addslashes($image_data);
    unset($image_posted);
    $_table = $tables[$type];
    if ($available_images[$type]['type'] == 'U') {
        cw_image_delete($image_data['id'], $type);
    }
    return cw_array2insert($type, $image_data);
}
function cw_product_options_delete_product($product_id = 0, $update_categories = true, $delete_all = false)
{
    global $tables;
    if ($delete_all === true) {
        db_query("DELETE FROM {$tables['product_options']}");
        db_query("DELETE FROM {$tables['product_options_values']}");
        db_query("DELETE FROM {$tables['product_options_values_lng']}");
        db_query("DELETE FROM {$tables['products_options_ex']}");
        db_query("DELETE FROM {$tables['product_options_js']}");
        db_query("DELETE FROM {$tables['product_variant_items']}");
        db_query("DELETE FROM {$tables['product_variants']}");
        return true;
    }
    $options = cw_query_column("SELECT product_option_id FROM {$tables['product_options']} WHERE product_id='{$product_id}'");
    db_query("DELETE FROM {$tables['product_options']} where product_id='{$product_id}'");
    if (!empty($options)) {
        $values = cw_query_column("SELECT option_id FROM {$tables['product_options_values']} where product_option_id IN ('" . implode("','", $options) . "')");
        db_query("DELETE FROM {$tables['product_options_lng']} where product_option_id IN ('" . implode("','", $options) . "')");
        if (!empty($values)) {
            db_query("DELETE FROM {$tables['product_options_values']} where product_option_id IN ('" . implode("','", $options) . "')");
            db_query("DELETE FROM {$tables['product_options_values_lng']} WHERE option_id IN ('" . implode("','", $values) . "')");
            db_query("DELETE FROM {$tables['products_options_ex']} WHERE option_id IN ('" . implode("','", $values) . "')");
            db_query("DELETE FROM {$tables['product_variant_items']} WHERE option_id IN ('" . implode("','", $values) . "')");
        }
    }
    db_query("DELETE FROM {$tables['product_options_js']} WHERE product_id='{$product_id}'");
    $vids = db_query("SELECT variant_id FROM {$tables['product_variants']} WHERE product_id='{$product_id}'");
    if ($vids) {
        while ($row = db_fetch_array($vids)) {
            cw_image_delete($row['variant_id'], 'products_images_var');
        }
        db_free_result($vids);
    }
    db_query("delete from {$tables['product_variants']} WHERE product_id='{$product_id}'");
}
<?php

cw_load('in_images');
$file_upload_data =& cw_session_register('file_upload_data');
cw_image_clear(array('webmaster_images'));
if ($action) {
    list($action, $id) = explode('_', $action, 2);
}
if ($action == 'delete') {
    cw_image_delete($id, 'webmaster_images');
    cw_header_location('index.php?target=' . $target);
}
if ($action == 'update') {
    if (is_array($file_upload_data['webmaster_images'])) {
        foreach ($file_upload_data['webmaster_images'] as $image) {
            if (cw_image_check_posted($image)) {
                cw_image_save($image);
            }
        }
    }
    if (is_array($image_data)) {
        foreach ($image_data as $key => $val) {
            cw_array2update('webmaster_images', $val, "id='{$key}'");
        }
    }
    cw_header_location('index.php?target=' . $target);
}
$images_to_upload = cw_in_images_get_list();
foreach ($images_to_upload as $key => $val) {
    $image_id = cw_in_images_get_id($key);
    $in_images[$val['name']] = cw_in_images_get_image_info($image_id, $val['name']);
Ejemplo n.º 14
0
<?php

global $action, $mode, $current_area;
cw_load('image');
$file_upload_data =& cw_session_register('file_upload_data');
cw_image_clear(array('customers_images'));
if ($action == 'delete_photos' && !empty($user_image_id)) {
    cw_image_delete($user_image_id, 'customers_images');
}
if ($action == 'customer_images') {
    if (cw_image_check_posted($file_upload_data['customers_images'])) {
        $images = cw_image_get_list('customers_images', $user);
        if (is_array($images)) {
            foreach ($images as $image) {
                cw_image_delete($image['image_id'], 'customers_images');
            }
        }
        cw_image_save($file_upload_data['customers_images'], array('id' => $user));
    }
}
if ($current_area == 'C') {
    cw_header_location("index.php?target={$target}");
} else {
    cw_header_location("index.php?target={$target}&mode=modify&user={$user}");
}
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_variants_upd'), 'type' => 'I');
    $refresh = $rebuild_quick = true;
} elseif ($action == 'product_variants_rebuild' && AREA_TYPE == 'A') {
    cw_rebuild_variants($product_id, true);
    $top_message['content'] = cw_get_langvar_by_name("msg_adm_product_variants_rebuilded");
    $top_message['type'] = "I";
    $refresh = $rebuild_quick = true;
} elseif ($action == "variants_delete_image" && !empty($vids) and AREA_TYPE == 'A') {
    foreach ($vids as $k => $v) {
        cw_image_delete($k, 'products_images_var');
        # Delete variants image (Group editing of products functionality)
        if ($ge_id && $fields['variants'][$k]) {
            while ($pid = cw_ge_each($ge_id, 1, $product_id)) {
                $vid = cw_variants_get_same($k, $pid);
                if (!empty($vid)) {
                    cw_image_delete($vid, 'products_images_var');
                }
            }
        }
    }
    $refresh = $rebuild_quick = true;
} elseif ($action == 'product_variants_search') {
    $search_variants[$product_id] = empty($search) ? array() : $search;
    $refresh = true;
}
if ($rebuild_quick) {
    cw_func_call('cw_product_build_flat', array('product_id' => $product_id));
    if ($ge_id) {
        while ($pid = cw_group_edit_each($ge_id, 100)) {
            cw_func_call('cw_product_build_flat', array('product_id' => $pid));
        }
Ejemplo n.º 16
0
                foreach ($subcats as $scat_id) {
                    cw_category_update_path($scat_id);
                }
            }
            $path = array($parent_id, $cat_location);
            cw_recalc_subcat_count($path);
        }
        $top_message = array('content' => cw_get_langvar_by_name('msg_adm_category_move'), 'type' => 'I');
        cw_header_location("index.php?target={$target}&mode=edit&cat={$cat}&ge_id={$ge_id}");
    }
}
if ($action == "delete_icon" && !empty($cat)) {
    cw_image_delete($cat, 'categories_images_thumb');
    if ($ge_id && $fields['image']) {
        while ($id = cw_group_edit_each($ge_id, 100, $cat)) {
            cw_image_delete($id, 'categories_images_thumb');
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_category_icon_del'), 'type' => 'I');
    cw_header_location("index.php?target={$target}&mode={$mode}&cat={$cat}&ge_id={$ge_id}");
}
$smarty->assign('memberships', cw_user_get_memberships(array('C', 'R')));
$current_category = cw_func_call('cw_category_get', array('cat' => $cat, 'from_category' => 0, 'location_target' => '', 'lang' => $edited_language));
if ($mode == 'add') {
    $current_category['category'] = '';
    $current_category['image'] = array();
}
if ($saved_category) {
    if (!is_array($current_category)) {
        $current_category = array();
    }
function cw_manufacturer_delete($manufacturer_id)
{
    global $tables;
    db_query("delete from {$tables['manufacturers']} where manufacturer_id='{$manufacturer_id}'");
    db_query("delete from {$tables['manufacturers_lng']} where manufacturer_id='{$manufacturer_id}'");
    $id = cw_call('cw_attributes_get_attribute_by_field', array('field' => 'manufacturer_id'));
    db_query("delete from {$tables['attributes_values']} where attribute_id='{$id}' and value='{$manufacturer_id}'");
    cw_call('cw_attributes_cleanup', array($manufacturer_id, 'M'));
    cw_image_delete($manufacturer_id, 'manufacturer_images');
    cw_event('on_manufacturer_delete', array($manufacturer_id));
}
Ejemplo n.º 18
0
function cw_dod_generate()
{
    global $tables, $config, $current_language;
    $generator = cw_query_first("select * from {$tables['dod_generators']} where active=1 and startdate<='" . time() . "' and enddate>'" . time() . "'  and dod_interval<>0 order by position asc, generator_id asc");
    if (!empty($generator)) {
        //check last generation date
        $last_gen_date = $generator['current_offer_date'];
        $hrs_since_last_generation = intval((time() - $last_gen_date) / 3600);
        $generate_again = false;
        if ($generator['dod_interval_type'] == 'D') {
            $generate_again = $hrs_since_last_generation >= $generator['dod_interval'] * 24;
            $offer_enddate = min($generator['enddate'], time() + $generator['dod_interval'] * 24 * 3600);
        } elseif ($generator['dod_interval_type'] == 'T') {
            $dod_period_hrs = intval(($generator['enddate'] - $generator['startdate']) / 3600);
            $hrs_interval = intval($dod_period_hrs / $generator['dod_interval']);
            $generate_again = $hrs_since_last_generation >= $hrs_interval;
            $offer_enddate = min($generator['enddate'], time() + $dod_period_hrs / $generator['dod_interval'] * 3600);
        }
        if ($generate_again || $_GET['force_generate']) {
            if (!empty($generator['used_pids'])) {
                $used_pids = explode(';', $generator['used_pids']);
            } else {
                $used_pids = array();
            }
            $dod_products = cw_query_column("select dbd.object_id from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_PRODS . "'");
            $dod_categories = cw_query_column("select dbd.object_id from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_CATS . "'");
            $dod_manufacturers = cw_query_column("select dbd.object_id from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_MANS . "'");
            $dod_attributes = cw_query("select dbd.*  from {$tables['dod_bonus_details']} dbd inner join {$tables['dod_bonuses']} db on db.generator_id=dbd.generator_id and db.bonus_id=dbd.bonus_id and db.type='" . DOD_DISCOUNT . "' where dbd.generator_id='{$generator['generator_id']}' and dbd.object_type='" . DOD_OBJ_TYPE_ATTR . "'");
            //select products by dod conditions
            $data = array();
            $dod_data_where_pids = '';
            if ($dod_products) {
                $dod_data_where_pids = "{$tables['products']}.product_id in ('" . implode("','", $dod_products) . "')";
            }
            if ($dod_categories) {
                $data['search_in_subcategories'] = 1;
                $data['category_ids'] = $dod_categories;
            }
            if ($dod_manufacturers) {
                $manufacturer_id_attribute = cw_query_first_cell("select attribute_id from {$tables['attributes']} where field='manufacturer_id' and addon='manufacturers'");
                if ($manufacturer_id_attribute) {
                    if (!isset($ret_params)) {
                        $ret_params = array();
                    }
                    if (!isset($ret_params['query_joins'])) {
                        $ret_params['query_joins'] = array();
                    }
                    $ret_params['query_joins']['atv_manufacturer'] = array('tblname' => 'attributes_values', 'on' => "{$tables['products']}.product_id=atv_manufacturer.item_id and atv_manufacturer.item_type='P' and atv_manufacturer.attribute_id = '{$manufacturer_id_attribute}' and atv_manufacturer.code in ('{$current_language}', '') and atv_manufacturer.value in ('" . implode("','", $dod_manufacturers) . "')", 'is_inner' => 1);
                }
            }
            if ($dod_attributes) {
                $param2_sql = array('eq' => '=', 'lt' => '<', 'le' => '<=', 'gt' => '>', 'ge' => '=>');
                foreach ($dod_attributes as $attr_data_k => $attr_data) {
                    $is_def_values = cw_query_first("select * from {$tables['attributes_default']} where attribute_value_id='{$attr_data['param1']}' and attribute_id='{$attr_data['object_id']}'");
                    //print_r($is_def_values);print("<br><br>");
                    $sql_operation = $param2_sql[$attr_data['param2']];
                    if (empty($sql_operation)) {
                        continue;
                    }
                    if (!isset($ret_params)) {
                        $ret_params = array();
                    }
                    if (!isset($ret_params['query_joins'])) {
                        $ret_params['query_joins'] = array();
                    }
                    if ($is_def_values) {
                        $ret_params['query_joins']['atv_dod_' . $attr_data_k] = array('tblname' => 'attributes_values', 'on' => "{$tables['products']}.product_id=atv_dod_{$attr_data_k}.item_id and atv_dod_{$attr_data_k}.item_type='P' and atv_dod_{$attr_data_k}.attribute_id = '{$attr_data['object_id']}' and atv_dod_{$attr_data_k}.code in ('{$current_language}', '')", 'is_inner' => 1);
                        $ret_params['query_joins']['atd_dod_' . $attr_data_k] = array('tblname' => 'attributes_default', 'on' => "atd_dod_{$attr_data_k}.attribute_value_id=atv_dod_{$attr_data_k}.value and atv_dod_{$attr_data_k}.attribute_id=atd_dod_{$attr_data_k}.attribute_id and atd_dod_{$attr_data_k}.value{$sql_operation}'" . addslashes($is_def_values['value']) . "'", 'is_inner' => 1);
                    } else {
                        $ret_params['query_joins']['atv_dod_' . $attr_data_k] = array('tblname' => 'attributes_values', 'on' => "{$tables['products']}.product_id=atv_dod_{$attr_data_k}.item_id and atv_dod_{$attr_data_k}.item_type='P' and atv_dod_{$attr_data_k}.attribute_id = '{$attr_data['object_id']}' and atv_dod_{$attr_data_k}.code in ('{$current_language}', '') and atv_dod_{$attr_data_k}.value{$sql_operation}'{$attr_data['param1']}'", 'is_inner' => 1);
                    }
                }
            }
            global $user_account, $current_area, $items_per_page_targets, $target;
            $items_per_page_targets[$target] = 1;
            $new_pid = 0;
            $safety_cnt = 1000;
            while (!$new_pid && $safety_cnt > 0) {
                if (!empty($data) || !empty($dod_data_where_pids)) {
                    $data['sort_field'] = 'rand';
                    $data['flat_search'] = 1;
                    $dod_data_where = array();
                    if (!empty($dod_data_where_pids)) {
                        $dod_data_where[] = $dod_data_where_pids;
                    }
                    if (!empty($used_pids)) {
                        $dod_data_where[] = "{$tables['products']}.product_id not in ('" . implode("','", $used_pids) . "')";
                    }
                    $data['where'] = implode(' and ', $dod_data_where);
                    list($products, $nav, $product_filter) = cw_func_call('cw_product_search', array('data' => $data, 'user_account' => $user_account, 'current_area' => $current_area, 'info_type' => 8, 'product_id_only' => 1), $ret_params);
                }
                $product = reset($products);
                //print_r(array('product'=>$product));print("<br><br>");
                $new_pid = $product['product_id'];
                if (!$new_pid) {
                    if ($generator['no_item_repeat']) {
                        break;
                    } else {
                        if (!empty($used_pids)) {
                            array_shift($used_pids);
                        } else {
                            break;
                        }
                    }
                }
                $safety_cnt--;
            }
            //die;
            if ($new_pid) {
                $used_pids[] = $new_pid;
            }
            $generator['used_pids'] = implode(';', $used_pids);
            $regenerate_offer = true;
            if ($regenerate_offer) {
                //regenerate offer
                if (!empty($generator['current_offer_id'])) {
                    $offer_ids = array($generator['current_offer_id']);
                    $offer_ids_query = implode("', '", $offer_ids);
                    db_query("DELETE FROM {$tables['ps_offers']} WHERE offer_id IN ('" . $offer_ids_query . "')");
                    db_query("DELETE FROM {$tables['ps_bonuses']} WHERE offer_id IN ('" . $offer_ids_query . "')");
                    db_query("DELETE FROM {$tables['ps_bonus_details']} WHERE offer_id IN ('" . $offer_ids_query . "')");
                    db_query("DELETE FROM {$tables['ps_conditions']} WHERE offer_id IN ('" . $offer_ids_query . "')");
                    db_query("DELETE FROM {$tables['ps_cond_details']} WHERE offer_id IN ('" . $offer_ids_query . "')");
                    db_query("DELETE FROM {$tables['attributes_values']} WHERE item_id IN ('" . $offer_ids_query . "') and item_type='PS'");
                    foreach ($offer_ids as $offer_id) {
                        cw_image_delete($offer_id, PS_IMG_TYPE);
                    }
                    cw_attributes_cleanup($offer_ids, PS_ATTR_ITEM_TYPE);
                    cw_cache_clean('shipping_rates');
                }
                if ($new_pid) {
                    cw_log_add('dod_generator', array('new DOD product selected' => $new_pid));
                    $new_offer_id = cw_array2insert('ps_offers', array('title' => 'Deal Of The Day', 'description' => $generator['description'], 'startdate' => time(), 'enddate' => $offer_enddate, 'active' => 1));
                }
                $current_offer_id = 0;
                if ($new_offer_id) {
                    $mdm_attribute_id = cw_query_first_cell("select attribute_id from {$tables['attributes']} where addon='multi_domains' and item_type='PS'");
                    if ($mdm_attribute_id) {
                        cw_array2insert('attributes_values', array('item_id' => $new_offer_id, 'attribute_id' => $mdm_attribute_id, 'value' => 0, 'code' => '', 'item_type' => 'PS'));
                    }
                    //copy bonus and bonus details
                    $dod_bonuses = cw_query("select * from {$tables['dod_bonuses']} where generator_id='{$generator['generator_id']}' and unused=0");
                    foreach ($dod_bonuses as $dod_bonus) {
                        $_dod_bonus = $dod_bonus;
                        unset($_dod_bonus['generator_id']);
                        $_dod_bonus['offer_id'] = $new_offer_id;
                        $new_bonus_id = cw_array2insert('ps_bonuses', $_dod_bonus);
                        if ($_dod_bonus['type'] == 'D' && $_dod_bonus['apply'] == 3) {
                            cw_array2insert('ps_bonus_details', array('bonus_id' => $new_bonus_id, 'offer_id' => $new_offer_id, 'object_id' => $new_pid, 'quantity' => 1, 'object_type' => DOD_OBJ_TYPE_PRODS));
                        } else {
                            $dod_bonus_details = cw_query("select * from {$tables['dod_bonus_details']} where generator_id='{$generator['generator_id']}' and bonus_id='{$dod_bonus['bonus_id']}'");
                            if (!empty($dod_bonus_details)) {
                                foreach ($dod_bonus_details as $dod_bonus_detail) {
                                    $_dod_bonus_detail = $dod_bonus_detail;
                                    unset($_dod_bonus_detail['generator_id']);
                                    $_dod_bonus_detail['offer_id'] = $new_offer_id;
                                    $_dod_bonus_detail['bonus_id'] = $new_bonus_id;
                                    cw_array2insert('ps_bonus_details', $_dod_bonus_detail);
                                }
                            }
                        }
                    }
                    $new_cond_id = cw_array2insert('ps_conditions', array('type' => 'P', 'total' => '0.00', 'offer_id' => $new_offer_id));
                    if ($new_cond_id) {
                        cw_array2insert('ps_cond_details', array('cond_id' => $new_cond_id, 'offer_id' => $new_offer_id, 'object_id' => $new_pid, 'quantity' => 1, 'object_type' => DOD_OBJ_TYPE_PRODS));
                    }
                    $current_offer_id = $new_offer_id;
                }
            }
            //update dod_generator fields
            cw_array2update('dod_generators', array('current_offer_id' => $current_offer_id, 'used_pids' => $generator['used_pids'], 'current_offer_date' => $current_offer_id ? time() : 0), "generator_id='{$generator['generator_id']}'");
            if ($current_offer_id && !empty($config['deal_of_day']['dod_news_template']) && $config['deal_of_day']['dod_newslist']) {
                $newslist = cw_query_first("select * from {$tables['newslists']} where list_id='" . $config['deal_of_day']['dod_newslist'] . "' and avail=1");
                if (!empty($newslist)) {
                    //create message
                    global $smarty;
                    $smarty->assign('promotion', $generator);
                    $smarty->assign('product_id', $new_pid);
                    $product_info = cw_func_call('cw_product_get', array('id' => $new_pid, 'user_account' => $user_account, 'info_type' => 65535));
                    $smarty->assign('product', $product_info);
                    $smarty->assign('news_message', $config['deal_of_day']['dod_news_template']);
                    $message = cw_display("addons/deal_of_day/admin/generate_news.tpl", $smarty, false, $newslist['lngcode']);
                    $smarty->assign('news_message', $config['deal_of_day']['dod_news_template_subject']);
                    $message_subject = cw_display("addons/deal_of_day/admin/generate_news.tpl", $smarty, false, $newslist['lngcode']);
                    //                    $message = $smarty->display('addons/deal_of_day/admin/generate_news.tpl');
                    print $message_subject . "<hr />" . $message;
                    if (!empty($message)) {
                        cw_array2insert('newsletter', array('subject' => $message_subject, 'body' => $message, 'created_date' => time(), 'send_date' => time(), 'updated_date' => time(), 'status' => 'N', 'list_id' => $config['deal_of_day']['dod_newslist'], 'show_as_news' => 1, 'allow_html' => 1));
                    }
                }
            }
        }
    }
    return $new_pid;
}
Ejemplo n.º 19
0
$warehouses = cw_get_warehouses();
$smarty->assign('warehouses', $warehouses);
if (AREA_TYPE == 'A' && $action == "delete_thumbnail" && !empty($product_id)) {
    cw_image_delete($product_id, 'products_images_thumb');
    if ($ge_id && $fields['thumbnail']) {
        while ($pid = cw_group_edit_each($ge_id, 100, $product_id)) {
            cw_image_delete($pid, 'products_images_thumb');
        }
    }
    cw_refresh($product_id);
}
if (AREA_TYPE == 'A' && $action == 'delete_product_image' && !empty($product_id)) {
    cw_image_delete($product_id, 'products_images_det');
    if ($ge_id && $fields['product_image']) {
        while ($pid = cw_group_edit_each($ge_id, 100, $product_id)) {
            cw_image_delete($pid, 'products_images_det');
        }
    }
    cw_refresh($product_id);
}
if ($product_id) {
    $smarty->assign('main', 'product_modify');
} else {
    $smarty->assign('main', 'product_add');
}
if ($REQUEST_METHOD == "POST" && ($action == "product_modify" || $action == 'add') && (AREA_TYPE == 'A' || AREA_TYPE == 'V')) {
    $is_variant = false;
    # kornev, TOFIX
    if ($product_id && $addons['product_options']) {
        $is_variant = cw_product_has_variants($product_id);
    }