Example #1
0
function fn_update_product_filter($filter_data, $filter_id, $lang_code = DESCR_SL)
{
    if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
        if (!empty($filter_id) && !fn_check_company_id('product_filters', 'filter_id', $filter_id)) {
            fn_company_access_denied_notification();
            return false;
        }
        if (!empty($filter_id)) {
            unset($filter_data['company_id']);
        }
    }
    // Parse filter type
    if (strpos($filter_data['filter_type'], 'FF-') === 0 || strpos($filter_data['filter_type'], 'RF-') === 0 || strpos($filter_data['filter_type'], 'DF-') === 0) {
        $filter_data['feature_id'] = str_replace(array('RF-', 'FF-', 'DF-'), '', $filter_data['filter_type']);
        $filter_data['feature_type'] = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $filter_data['feature_id']);
    } else {
        $filter_data['field_type'] = str_replace(array('R-', 'B-'), '', $filter_data['filter_type']);
        $filter_fields = fn_get_product_filter_fields();
    }
    if (!empty($filter_id)) {
        db_query('UPDATE ?:product_filters SET ?u WHERE filter_id = ?i', $filter_data, $filter_id);
        db_query('UPDATE ?:product_filter_descriptions SET ?u WHERE filter_id = ?i AND lang_code = ?s', $filter_data, $filter_id, $lang_code);
    } else {
        $filter_data['filter_id'] = $filter_id = db_query('INSERT INTO ?:product_filters ?e', $filter_data);
        foreach (fn_get_translation_languages() as $filter_data['lang_code'] => $_d) {
            db_query("INSERT INTO ?:product_filter_descriptions ?e", $filter_data);
        }
    }
    fn_set_hook('update_product_filter', $filter_data, $filter_id, $lang_code);
    return $filter_id;
}
function fn_update_product_filter($filter_data, $filter_id, $lang_code = DESCR_SL)
{
    if (fn_allowed_for('ULTIMATE') && Registry::get('runtime.company_id')) {
        if (!empty($filter_id) && !fn_check_company_id('product_filters', 'filter_id', $filter_id)) {
            fn_company_access_denied_notification();
            return false;
        }
        if (!empty($filter_id)) {
            unset($filter_data['company_id']);
        }
    }
    // Parse filter type
    if (strpos($filter_data['filter_type'], 'FF-') === 0 || strpos($filter_data['filter_type'], 'RF-') === 0 || strpos($filter_data['filter_type'], 'DF-') === 0) {
        $filter_data['feature_id'] = str_replace(array('RF-', 'FF-', 'DF-'), '', $filter_data['filter_type']);
        $filter_data['feature_type'] = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $filter_data['feature_id']);
    } else {
        $filter_data['field_type'] = str_replace(array('R-', 'B-'), '', $filter_data['filter_type']);
        $filter_fields = fn_get_product_filter_fields();
    }
    if (isset($filter_data['display_more_count']) && isset($filter_data['display_count']) && $filter_data['display_more_count'] < $filter_data['display_count']) {
        $filter_data['display_more_count'] = $filter_data['display_count'];
    }
    if (!empty($filter_id)) {
        db_query('UPDATE ?:product_filters SET ?u WHERE filter_id = ?i', $filter_data, $filter_id);
        db_query('UPDATE ?:product_filter_descriptions SET ?u WHERE filter_id = ?i AND lang_code = ?s', $filter_data, $filter_id, $lang_code);
    } else {
        $filter_data['filter_id'] = $filter_id = db_query('INSERT INTO ?:product_filters ?e', $filter_data);
        foreach (fn_get_translation_languages() as $filter_data['lang_code'] => $_d) {
            db_query("INSERT INTO ?:product_filter_descriptions ?e", $filter_data);
        }
    }
    $delete_all_ranges = false;
    // if filter has ranges
    if (!empty($filter_data['feature_type']) && strpos('ODN', $filter_data['feature_type']) !== false || !empty($filter_data['field_type']) && !empty($filter_fields[$filter_data['field_type']]['is_range'])) {
        $range_ids = array();
        foreach ($filter_data['ranges'] as $k => $range) {
            if (!empty($filter_data['feature_type']) && $filter_data['feature_type'] == 'D') {
                $range['to'] = fn_parse_date($filter_data['dates_ranges'][$k]['to']);
                $range['from'] = fn_parse_date($filter_data['dates_ranges'][$k]['from']);
            }
            $range['filter_id'] = $filter_id;
            if (!empty($filter_data['feature_id'])) {
                $range['feature_id'] = $filter_data['feature_id'];
            }
            if (!empty($range['range_id'])) {
                db_query("UPDATE ?:product_filter_ranges SET ?u WHERE range_id = ?i", $range, $range['range_id']);
                db_query('UPDATE ?:product_filter_ranges_descriptions SET ?u WHERE range_id = ?i AND lang_code = ?s', $range, $range['range_id'], $lang_code);
            } elseif ((!empty($range['from']) || !empty($range['to'])) && !empty($range['range_name'])) {
                $range['range_id'] = db_query("INSERT INTO ?:product_filter_ranges ?e", $range);
                foreach (fn_get_translation_languages() as $range['lang_code'] => $_d) {
                    db_query("INSERT INTO ?:product_filter_ranges_descriptions ?e", $range);
                }
            }
            if (!empty($range['range_id'])) {
                $range_ids[] = $range['range_id'];
            }
        }
        if (!empty($range_ids)) {
            $deleted_ranges = db_get_fields("SELECT range_id FROM ?:product_filter_ranges WHERE filter_id = ?i AND range_id NOT IN (?n)", $filter_id, $range_ids);
            if (!empty($deleted_ranges)) {
                db_query("DELETE FROM ?:product_filter_ranges WHERE range_id IN (?n)", $deleted_ranges);
                db_query("DELETE FROM ?:product_filter_ranges_descriptions WHERE range_id IN (?n)", $deleted_ranges);
            }
        } else {
            $delete_all_ranges = true;
        }
    } else {
        $delete_all_ranges = true;
    }
    if ($delete_all_ranges) {
        $deleted_ranges = db_get_fields("SELECT range_id FROM ?:product_filter_ranges WHERE filter_id = ?i", $filter_id);
        db_query("DELETE FROM ?:product_filter_ranges WHERE filter_id = ?i", $filter_id);
        db_query("DELETE FROM ?:product_filter_ranges_descriptions WHERE range_id IN (?n)", $deleted_ranges);
    }
    fn_set_hook('update_product_filter', $filter_data, $filter_id, $lang_code);
    return $filter_id;
}
function fn_company_products_check($product_ids, $notify = false)
{
    if (!empty($product_ids)) {
        $c = db_get_field("SELECT count(*) FROM ?:products WHERE product_id IN (?n) ?p", $product_ids, fn_get_company_condition('?:products.company_id'));
        if (count((array) $product_ids) == $c) {
            return true;
        } else {
            if ($notify) {
                fn_company_access_denied_notification();
            }
            return false;
        }
    }
    return true;
}
Example #4
0
/**
 * Updates page data by id or create new
 *
 * @param array $page_data Page data
 * @param int $page_id Page idetifier, if equals zero new page will be created
 * @param string $lang_code 2 letters language code
 * @return int Page identifier on success, false otherwise
 */
function fn_update_page($page_data, $page_id = 0, $lang_code = CART_LANGUAGE)
{
    /**
     * Actions before all checks and initializations
     *
     * @param array  $page_data Page data
     * @param int    $page_id   Page idetifier, if equals zero new page will be created
     * @param string $lang_code 2 letters language code
     */
    fn_set_hook('update_page_pre', $page_data, $page_id, $lang_code);
    if (!empty($page_id) && !fn_check_company_id('pages', 'page_id', $page_id)) {
        fn_company_access_denied_notification();
        return false;
    }
    if (!empty($page_data)) {
        SecurityHelper::sanitizeObjectData('page', $page_data);
        if (!empty($page_data['avail_from_timestamp'])) {
            $page_data['avail_from_timestamp'] = fn_parse_date($page_data['avail_from_timestamp']);
        } else {
            $page_data['avail_from_timestamp'] = 0;
        }
        if (!empty($page_data['avail_till_timestamp'])) {
            $page_data['avail_till_timestamp'] = fn_parse_date($page_data['avail_till_timestamp']) + 86399;
        } else {
            $page_data['avail_till_timestamp'] = 0;
        }
        if (isset($page_data['usergroup_ids'])) {
            $page_data['usergroup_ids'] = empty($page_data['usergroup_ids']) ? '0' : implode(',', $page_data['usergroup_ids']);
        }
        $page_data['add_items'] = empty($page_data['add_items']) ? array() : $page_data['add_items'];
        if (isset($page_data['timestamp'])) {
            $page_data['timestamp'] = fn_parse_date($page_data['timestamp']);
        }
        if (isset($page_data['localization'])) {
            $page_data['localization'] = empty($page_data['localization']) ? '' : fn_implode_localizations($page_data['localization']);
        }
        $old_page_data = array();
        /**
         * Actions after all checks and initializations and before update page
         *
         * @param array $page_data Page data
         * @param int $page_id Page idetifier, if equals zero new page will be created
         * @param string $lang_code 2 letters language code
         */
        fn_set_hook('update_page_before', $page_data, $page_id, $lang_code);
        $parent_id = isset($page_data['parent_id']) ? $page_data['parent_id'] : null;
        unset($page_data['parent_id']);
        if (empty($page_id)) {
            // page title required
            if (empty($page_data['page'])) {
                return false;
            }
            // add new page
            $create = true;
            $page_data['page_id'] = $page_id = db_query('INSERT INTO ?:pages ?e', $page_data);
            foreach (fn_get_translation_languages() as $page_data['lang_code'] => $v) {
                db_query('INSERT INTO ?:page_descriptions ?e', $page_data);
            }
        } else {
            $old_page_data = fn_get_page_data($page_id, $lang_code);
            $create = false;
            // page title is not updated
            if (empty($page_data['page'])) {
                unset($page_data['page']);
            }
            // update existing page
            db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', $page_data, $page_id);
            db_query('UPDATE ?:page_descriptions SET ?u WHERE page_id = ?i AND lang_code = ?s', $page_data, $page_id, $lang_code);
        }
        $page_data['parent_id'] = $parent_id;
        // regenerate id_path for child pages
        if (isset($page_data['parent_id'])) {
            fn_change_page_parent($page_id, intval($page_data['parent_id']));
        }
    }
    /**
     * Actions after page update
     *
     * @param array  $page_data     Page data
     * @param int    $page_id       Page idetifier, if equals zero new page will be created
     * @param string $lang_code     2 letters language code
     * @param bool   $create        True if page was created, falce otherwise
     * @param array  $old_page_data Page data before update
     */
    fn_set_hook('update_page_post', $page_data, $page_id, $lang_code, $create, $old_page_data);
    return $page_id;
}
Example #5
0
****************************************************************************/
use Tygh\Registry;
if (!defined('BOOTSTRAP')) {
    die('Access denied');
}
$_REQUEST['category_id'] = empty($_REQUEST['category_id']) ? 0 : $_REQUEST['category_id'];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Define trusted variables that shouldn't be stripped
    fn_trusted_vars('category_data', 'categories_data');
    //
    // Create/update category
    //
    if ($mode == 'update') {
        if (fn_allowed_for('ULTIMATE')) {
            if (!empty($_REQUEST['category_id']) && !fn_check_company_id('categories', 'category_id', $_REQUEST['category_id'])) {
                fn_company_access_denied_notification();
                return array(CONTROLLER_STATUS_OK, 'categories.update?category_id=' . $_REQUEST['category_id']);
            }
        }
        $category_id = fn_update_category($_REQUEST['category_data'], $_REQUEST['category_id'], DESCR_SL);
        if (!empty($category_id)) {
            fn_attach_image_pairs('category_main', 'category', $category_id, DESCR_SL);
            $suffix = ".update?category_id={$category_id}" . (!empty($_REQUEST['category_data']['block_id']) ? "&selected_block_id=" . $_REQUEST['category_data']['block_id'] : "");
        } else {
            $suffix = '.manage';
        }
    }
    //
    // Processing mulitple addition of new category elements
    //
    if ($mode == 'm_add') {
Example #6
0
/**
* Deletes news by its ID
*
* @param int $news_id - News Identifier
*/
function fn_delete_news($news_id)
{
    $news_deleted = false;
    if (!empty($news_id)) {
        if (fn_check_company_id('news', 'news_id', $news_id)) {
            // Log news deletion
            fn_log_event('news', 'delete', array('news_id' => $news_id));
            Block::instance()->removeDynamicObjectData('news', $news_id);
            $affected_rows = db_query("DELETE FROM ?:news WHERE news_id = ?i", $news_id);
            db_query("DELETE FROM ?:news_descriptions WHERE news_id = ?i", $news_id);
            if ($affected_rows != 0) {
                $news_deleted = true;
            } else {
                fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('news'))), '', '404');
            }
            fn_set_hook('delete_news', $news_id);
        } else {
            fn_company_access_denied_notification();
        }
    }
    return $news_deleted;
}
Example #7
0
function fn_clone_page($page_id)
{
    if (!fn_check_company_id('pages', 'page_id', $page_id)) {
        fn_company_access_denied_notification(false);
        return false;
    }
    // Clone main data
    $data = db_get_row("SELECT * FROM ?:pages WHERE page_id = ?i", $page_id);
    unset($data['page_id']);
    $data['status'] = 'D';
    $new_page_id = db_query("INSERT INTO ?:pages ?e", $data);
    // Update parent-child deps
    $id_path = explode('/', $data['id_path']);
    array_pop($id_path);
    $id_path[] = $new_page_id;
    db_query("UPDATE ?:pages SET id_path = ?s WHERE page_id = ?i", implode('/', $id_path), $new_page_id);
    // Clone descriptions
    $data = db_get_array("SELECT * FROM ?:page_descriptions WHERE page_id = ?i", $page_id);
    foreach ($data as $v) {
        $v['page_id'] = $new_page_id;
        if ($v['lang_code'] == CART_LANGUAGE) {
            $orig_name = $v['page'];
            $new_name = $v['page'] . ' [CLONE]';
        }
        $v['page'] .= ' [CLONE]';
        db_query("INSERT INTO ?:page_descriptions ?e", $v);
    }
    fn_clone_block_links('pages', $page_id, $new_page_id);
    fn_set_hook('clone_page', $page_id, $new_page_id);
    return array('page_id' => $new_page_id, 'orig_name' => $orig_name, 'page' => $new_name);
}
/**
 * Removes product feature
 *
 * @param int $feature_id Feature identifier
 * @return boolean Always true
 */
function fn_delete_feature($feature_id)
{
    $feature_deleted = true;
    if (fn_allowed_for('ULTIMATE')) {
        if (!fn_check_company_id('product_features', 'feature_id', $feature_id)) {
            fn_company_access_denied_notification();
            return false;
        }
    }
    /**
     * Adds additional actions before product feature deleting
     *
     * @param int $feature_id Feature identifier
     */
    fn_set_hook('delete_feature_pre', $feature_id);
    $feature_type = db_get_field("SELECT feature_type FROM ?:product_features WHERE feature_id = ?i", $feature_id);
    fn_set_hook('delete_product_feature', $feature_id, $feature_type);
    if ($feature_type == 'G') {
        $fids = db_get_fields("SELECT feature_id FROM ?:product_features WHERE parent_id = ?i", $feature_id);
        if (!empty($fids)) {
            foreach ($fids as $fid) {
                fn_delete_feature($fid);
            }
        }
    }
    $affected_rows = db_query("DELETE FROM ?:product_features WHERE feature_id = ?i", $feature_id);
    db_query("DELETE FROM ?:product_features_descriptions WHERE feature_id = ?i", $feature_id);
    if ($affected_rows == 0) {
        fn_set_notification('E', __('error'), __('object_not_found', array('[object]' => __('feature'))), '', '404');
        $feature_deleted = false;
    }
    $variant_ids = fn_delete_product_feature_variants($feature_id);
    if (!fn_allowed_for('ULTIMATE:FREE')) {
        $filter_ids = db_get_fields("SELECT filter_id FROM ?:product_filters WHERE feature_id = ?i", $feature_id);
        foreach ($filter_ids as $_filter_id) {
            fn_delete_product_filter($_filter_id);
        }
    }
    /**
     * Adds additional actions after product feature deleting
     *
     * @param int   $feature_id  Deleted feature identifier
     * @param array $variant_ids Deleted feature variants
     */
    fn_set_hook('delete_feature_post', $feature_id, $variant_ids);
    return $feature_deleted;
}
Example #9
0
/**
 * Function delete order
 *
 * @param int $order_id
 * @return int
 */
function fn_delete_order($order_id)
{
    if (Registry::get('runtime.company_id') && !fn_allowed_for('ULTIMATE')) {
        fn_company_access_denied_notification();
        return false;
    }
    // Log order deletion
    fn_log_event('orders', 'delete', array('order_id' => $order_id));
    fn_change_order_status($order_id, STATUS_INCOMPLETED_ORDER, '', fn_get_notification_rules(array(), false));
    // incomplete to increase inventory
    fn_set_hook('delete_order', $order_id);
    db_query("DELETE FROM ?:new_orders WHERE order_id = ?i", $order_id);
    db_query("DELETE FROM ?:order_data WHERE order_id = ?i", $order_id);
    db_query("DELETE FROM ?:order_details WHERE order_id = ?i", $order_id);
    $result = db_query("DELETE FROM ?:orders WHERE order_id = ?i", $order_id);
    db_query("DELETE FROM ?:product_file_ekeys WHERE order_id = ?i", $order_id);
    db_query("DELETE FROM ?:profile_fields_data WHERE object_id = ?i AND object_type='O'", $order_id);
    db_query("DELETE FROM ?:order_docs WHERE order_id = ?i", $order_id);
    // Delete shipments
    $shipment_ids = db_get_fields('SELECT shipment_id FROM ?:shipment_items WHERE order_id = ?i GROUP BY shipment_id', $order_id);
    if (!empty($shipment_ids)) {
        db_query('DELETE FROM ?:shipments WHERE shipment_id IN (?a)', $shipment_ids);
        db_query('DELETE FROM ?:shipment_items WHERE order_id = ?i', $order_id);
    }
    return $result;
}
Example #10
0
function fn_mve_clone_page_pre(&$page_id, &$data)
{
    if (!fn_check_company_id('pages', 'page_id', $page_id)) {
        fn_company_access_denied_notification();
        unset($data);
    }
}