case 'staticpage':
         case 'staticpopup':
         case 'html':
             if (isset($content_section_content) && strlen($content_section_content) > 0 && !empty($contentsection_id)) {
                 $data = array('content' => htmlspecialchars_decode(trim($content_section_content)));
                 if ($current_language == $config['default_customer_language']) {
                     cw_array2update('cms', $data, "contentsection_id = '" . $contentsection_id . "'");
                 }
                 cw_array2update('cms_alt_languages', $data, "contentsection_id = '" . $contentsection_id . "' AND code = '" . $current_language . "'");
             }
             // no break here because 'html' type needs image processing as well
         // no break here because 'html' type needs image processing as well
         case 'image':
             if (!empty($contentsection_id) && !empty($file_upload_data) && is_array($file_upload_data)) {
                 $is_image_uploaded_and_saved = false;
                 if (cw_image_check_posted($file_upload_data['cms_images'])) {
                     if (cw_image_save($file_upload_data['cms_images'], array('id' => $contentsection_id, 'code' => $current_language))) {
                         $is_image_uploaded_and_saved = true;
                     }
                 }
                 if (!$is_image_uploaded_and_saved) {
                     cw_add_top_message(cw_get_langvar_by_name('msg_ab_err_banner_image_not_uploaded_or_saved'), 'E');
                     cw_header_location('index.php?target=cms&mode=add');
                 }
             }
             break;
     }
     cw_event('on_cms_update', array($contentsection_id, $content_section));
     $presaved_content_section = array();
     cw_header_location('index.php?target=cms&mode=update&contentsection_id=' . $contentsection_id);
 }
    $to_update = array('manufacturer' => $manufacturer_update['manufacturer'], 'url' => $manufacturer_update['url'], 'descr' => $manufacturer_update['descr'], 'featured' => $manufacturer_update['featured'], 'avail' => $manufacturer_update['avail'], 'orderby' => $manufacturer_update['orderby'], 'show_image' => $manufacturer_update['show_image']);
    $to_update_lng = array('manufacturer_id' => $manufacturer_id, 'code' => $edited_language, 'descr' => $manufacturer_update['descr'], 'manufacturer' => $manufacturer_update['manufacturer']);
    if ($edited_language != $config['default_admin_language'] && $manufacturer_id) {
        cw_unset($to_update, 'manufacturer', 'descr');
    }
    if (!$manufacturer_id) {
        $top_message['content'] = cw_get_langvar_by_name("msg_adm_err_manufacturer_add");
        $manufacturer_id = cw_array2insert('manufacturers', $to_update);
        $to_update_lng['manufacturer_id'] = $manufacturer_id;
    } else {
        $top_message['content'] = cw_get_langvar_by_name("msg_adm_err_manufacturer_upd");
    }
    cw_array2update('manufacturers', $to_update, "manufacturer_id='{$manufacturer_id}' " . $warehouse_condition);
    cw_array2insert('manufacturers_lng', $to_update_lng, true);
    cw_call('cw_attributes_save', array('item_id' => $manufacturer_id, 'item_type' => 'M', 'attributes' => $attributes, 'language' => $edited_language));
    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');
 $update_fields = array('category', 'description', 'featured', 'order_by', 'short_list');
 array_push($update_fields, 'meta_descr', 'meta_keywords');
 if ($edited_language != $config['default_admin_language']) {
     cw_unset($update_fields, 'category', 'description');
 }
 cw_array2update('categories', $category_update, "category_id='{$cat}'", $update_fields);
 cw_category_update_status($cat, $category_update['status']);
 cw_category_update_path($cat);
 cw_membership_update('categories', $cat, $category_update['membership_ids'], 'category_id');
 $category_lng = array();
 $category_lng['code'] = $edited_language;
 $category_lng['category_id'] = $cat;
 $category_lng['category'] = $category_update['category'];
 $category_lng['description'] = $category_update['description'];
 cw_array2insert('categories_lng', $category_lng, true, array('code', 'category_id', 'category', 'description'));
 if (cw_image_check_posted($file_upload_data['categories_images_thumb'])) {
     cw_image_save($file_upload_data['categories_images_thumb']);
 }
 $parent_categories = cw_category_get_path($cat);
 if (is_array($parent_categories)) {
     cw_recalc_subcat_count($parent_categories);
 }
 cw_func_call('cw_items_attribute_classes_save', array('item_id' => $cat, 'attribute_class_ids' => $category_update['attribute_class_ids'], 'item_type' => 'C'));
 if ($replicate_attribute_classes == "Y") {
     $child_subcategories = cw_func_call('cw_category_get_subcategory_ids', array('cat' => $cat));
     if (is_array($child_subcategories)) {
         foreach ($child_subcategories as $subcatid) {
             cw_func_call('cw_items_attribute_classes_save', array('item_id' => $subcatid, 'attribute_class_ids' => $category_update['attribute_class_ids'], 'item_type' => 'C'));
         }
     }
 }
             cw_array2insert("clean_urls_custom_facet_urls_options", array('url_id' => $custom_facet_url_id, 'attribute_value_ids' => $attribute_value_ids_by_options[$o_idx], 'clean_urls' => $cu_v));
         }
         $top_message = array('content' => cw_get_langvar_by_name("txt_custom_facet_url_updated"), 'type' => 'I');
     } else {
         $custom_facet_url_id = cw_array2insert("clean_urls_custom_facet_urls", array('custom_facet_url' => $custom_facet_url, 'description' => addslashes($description), 'title' => addslashes($title)));
         db_query("delete from {$tables['clean_urls_custom_facet_urls_options']} where url_id = {$custom_facet_url_id}");
         $clean_urls_by_options = explode('###', $clean_urls);
         $attribute_value_ids_by_options = explode('###', $attribute_value_ids);
         foreach ($clean_urls_by_options as $o_idx => $cu_v) {
             cw_array2insert("clean_urls_custom_facet_urls_options", array('url_id' => $custom_facet_url_id, 'attribute_value_ids' => $attribute_value_ids_by_options[$o_idx], 'clean_urls' => $cu_v));
         }
         $top_message = array('content' => cw_get_langvar_by_name("txt_custom_facet_url_added"), 'type' => 'I');
     }
     if (!empty($custom_facet_url_id) && !empty($file_upload_data) && is_array($file_upload_data)) {
         $is_image_uploaded_and_saved = false;
         if (cw_image_check_posted($file_upload_data['facet_categories_images'])) {
             if (cw_image_save($file_upload_data['facet_categories_images'], array('id' => $custom_facet_url_id))) {
                 $is_image_uploaded_and_saved = true;
             }
         }
         if (!$is_image_uploaded_and_saved) {
             cw_add_top_message('Image cannot be saved', 'E');
         }
     }
 } else {
     $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');
<?php

require_once $app_main_dir . '/addons/detailed_product_images/func.php';
cw_image_clear(array('products_detailed_images'));
global $file_upload_data, $product_id, $top_message, $image, $iids, $action, $image_id, $ge_id, $fields;
if ($action == 'product_images' && is_array($file_upload_data['products_detailed_images'])) {
    foreach ($file_upload_data['products_detailed_images'] as $image) {
        $image_posted = cw_image_check_posted($image);
        if ($image_posted) {
            $image_id = cw_image_save($image, array('alt' => $alt, 'id' => $product_id));
            if ($ge_id && $fields['new_d_image']) {
                $data = cw_query_first("select * from {$tables['products_detailed_images']} where id = '{$product_id}' AND image_id = '{$image_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, 'products_detailed_images', true);
                    }
                    $data['id'] = $pid;
                    cw_array2insert("products_detailed_images", $data);
                }
            }
        }
    }
    $top_message = array('content' => cw_get_langvar_by_name('msg_adm_product_images_add'), 'type' => 'I');
    cw_dpi_refresh($product_id, 'dpi');
}
$image = $_POST['image'];
if ($action == 'update_availability' && !empty($image)) {
    foreach ($image as $key => $value) {
function ps_modify_details($offer_id)
{
    global $tables, $available_fields, $optional_fields, $skip_striptags_fields, $date_fields;
    /*if (empty($offer_id)) {
          return array(false, 'Offer Id was not provided');
      }*/
    global $offer_data;
    if (empty($offer_data) || !is_array($offer_data)) {
        return array(true, null);
    }
    $error = null;
    $data = array();
    $excl_from_base_list = array('offer_id');
    foreach ($excl_from_base_list as $field) {
        if (isset($available_fields[$field])) {
            unset($available_fields[$field]);
        }
    }
    $additional_lang_data = array();
    foreach ($date_fields as $field) {
        if (isset($offer_data[$field]) && !empty($offer_data[$field])) {
            $offer_data[$field] = cw_core_strtotime($offer_data[$field]);
        }
    }
    foreach ($available_fields as $field => $field_type) {
        if (isset($offer_data[$field])) {
            $result = settype($offer_data[$field], $field_type);
            if ($result === false) {
                $error = 'msg_ps_incorrect_field_type';
                $additional_lang_data = array('field_name' => $field);
                break;
            }
            if ($field == 'description') {
                if ($offer_data[$field] == '<p>&#160;</p>') {
                    $offer_data[$field] = null;
                }
            }
            if (empty($offer_data[$field])) {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_ps_empty_fields';
                    break;
                }
            } else {
                if ($field_type == 'string' && !in_array($field, $skip_striptags_fields)) {
                    $offer_data[$field] = cw_strip_tags($offer_data[$field]);
                }
                $data[$field] =& $offer_data[$field];
            }
        } else {
            if ($field_type == 'bool') {
                $data[$field] = 0;
            } else {
                if (in_array($field, $optional_fields)) {
                    $data[$field] = null;
                } else {
                    $error = 'msg_ps_empty_fields';
                    break;
                }
            }
        }
    }
    $sess_offer_data =& cw_session_register('_offer_data');
    $GLOBALS['_offer_data'] =& $offer_data;
    cw_session_register('_offer_data');
    if (!empty($error)) {
        return array(false, cw_get_langvar_by_name($error, $additional_lang_data));
    }
    global $attributes;
    $data['attributes'] = $attributes;
    $error = cw_error_check($data, array(), PS_ATTR_ITEM_TYPE);
    //cw_attributes_check($array_to_check['attribute_class_id'], $array_to_check['attributes'], $attributes_type, $index)
    if (!empty($error)) {
        return array(false, $error);
    }
    global $file_upload_data;
    if (empty($offer_id)) {
        if (empty($data)) {
            return array(false, null);
        }
        $offer_id = cw_array2insert($tables['ps_offers'], cw_addslashes($data));
        $is_image = false;
        if (!empty($file_upload_data) && isset($file_upload_data[PS_IMG_TYPE]) && is_array($file_upload_data[PS_IMG_TYPE])) {
            $is_image = true;
            if (isset($sess_offer_data['image']) && !empty($sess_offer_data['image'])) {
                $file_upload_data[PS_IMG_TYPE]['is_redirect'] = false;
            }
            $GLOBALS['_offer_data']['image'] = $file_upload_data[PS_IMG_TYPE];
            $file_upload_data[PS_IMG_TYPE]['is_redirect'] = false;
        }
        if (!empty($offer_id)) {
            if ($is_image == true) {
                $image_posted = cw_image_check_posted($file_upload_data[PS_IMG_TYPE]);
                if ($image_posted) {
                    $image_id = cw_image_save($file_upload_data[PS_IMG_TYPE], array('alt' => $data['title'], 'id' => $offer_id));
                }
            }
        }
    } else {
        $image_id = 0;
        if (!empty($file_upload_data) && isset($file_upload_data[PS_IMG_TYPE]) && is_array($file_upload_data[PS_IMG_TYPE])) {
            $image_posted = cw_image_check_posted($file_upload_data[PS_IMG_TYPE]);
            if ($image_posted) {
                $image_id = cw_image_save($file_upload_data[PS_IMG_TYPE], array('alt' => $data['title'], 'id' => $offer_id));
            }
        }
        if (empty($data) && empty($image_id)) {
            $error = 'msg_ps_nothing_to_update';
            return array(false, cw_get_langvar_by_name($error, $additional_lang_data));
        }
        cw_array2update($tables['ps_offers'], cw_addslashes($data), 'offer_id = \'' . $offer_id . '\'');
    }
    cw_call('cw_attributes_save', array('item_id' => $offer_id, 'item_type' => PS_ATTR_ITEM_TYPE, 'attributes' => $attributes));
    cw_session_unregister('_offer_data');
    return array($offer_id, null);
}
                 }
                 cw_array2update('product_variants', $query_data, "variant_id = '{$vid}'");
                 cw_price_lists_replace_price($pid, $v['price'], $vid, false, $v['is_manual_price']);
                 if ($def_variant == $k) {
                     cw_array2update('product_variants', array('def' => ''), "product_id = '{$pid}'");
                     cw_array2update('product_variants', array('def' => 'Y'), "product_id = '{$pid}' and variant_id='{$vid}'");
                 }
             }
         }
     }
 }
 if (!empty($def_variant)) {
     cw_array2update('product_variants', array('def' => ''), "product_id = '{$product_id}'");
     cw_array2update('product_variants', array("def" => 'Y'), "product_id = '{$product_id}' and variant_id='{$def_variant}'");
 }
 if (is_array($vids) && cw_image_check_posted($file_upload_data['products_images_var'])) {
     $vids = array_keys($vids);
     $vid = array_shift($vids);
     $image_id = cw_image_save($file_upload_data['products_images_var'], array('id' => $vid));
     $res = cw_addslashes(cw_query_first("select * from {$tables['products_images_var']} where image_id = '{$image_id}' limit 1"));
     unset($res['image_id']);
     if ($res) {
         foreach ($vids as $vid) {
             $res['id'] = $vid;
             cw_image_delete($vid, 'products_images_var');
             cw_array2insert('products_images_var', $res);
         }
     }
     if ($ge_id && $fields['variants']) {
         while ($pid = cw_ge_each($ge_id, 1, $product_id)) {
             $res['id'] = cw_variants_get_same($v, $pid);
function cw_check_image_storage_perms($file_upload_data, $type = 'T', $get_message = true)
{
    global $config, $app_dir;
    if (!cw_image_check_posted($file_upload_data[$type])) {
        return true;
    }
    return cw_check_image_perms($type, $get_message);
}
<?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']);
     }
     if (cw_image_check_posted($file_upload_data['products_images_det'])) {
         cw_image_save($file_upload_data['products_images_det'], array('id' => $product_id));
     }
 } else {
     if ($pdf_file_name != 'none' && $pdf_file_name != "") {
         $destination = $var_dirs['pdf'] . '/' . $pdf_file_name;
         $path = cw_move_uploaded_file('pdf_file', $destination);
         if ($path) {
             $product_data['pdf_link'] = $var_dirs_web['pdf'] . '/' . $pdf_file_name;
         }
     }
     if (cw_image_check_posted($file_upload_data['products_images_thumb'])) {
         cw_image_save($file_upload_data['products_images_thumb'], array('id' => $product_id));
     }
     if (cw_image_check_posted($file_upload_data['products_images_det'])) {
         cw_image_save($file_upload_data['products_images_det'], array('id' => $product_id));
     }
     if ($fields['thumbnail']) {
         cw_group_edit_copy($ge_id, 'products_images_thumb', 'id', $product_id);
     }
     if ($fields['product_image']) {
         cw_group_edit_copy($ge_id, 'products_images_det', 'id', $product_id);
     }
 }
 if ($config['Appearance']['categories_in_products'] == '1') {
     if ($product_info) {
         $old_product_categories = cw_query_column("SELECT category_id FROM {$tables['products_categories']} WHERE product_id='{$product_id}'");
     }
     db_query("update {$tables['products_categories']} set main=0 where product_id = '{$product_id}'");
     $query_data_cat = array('category_id' => $product_data['category_id'], 'product_id' => $product_id, 'main' => 1, 'orderby' => cw_query_first_cell("select orderby from {$tables['products_categories']} where category_id = '{$product_data['category_id']}' and product_id = '{$product_id}' and main = 1"));