예제 #1
0
function fn_update_page($page_data, $page_id = 0, $lang_code = CART_LANGUAGE)
{
    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']) ? '' : implode(',', $page_data['usergroup_ids']);
    }
    $_data = $page_data;
    if (isset($page_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($page_data['timestamp']);
    }
    if (isset($_data['localization'])) {
        $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    fn_set_company_id($_data);
    if (empty($page_id)) {
        // page title required
        if (empty($page_data['page'])) {
            return false;
        }
        // add new page
        $_data['page_id'] = $page_id = db_query('INSERT INTO ?:pages ?e', $_data);
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query('INSERT INTO ?:page_descriptions ?e', $_data);
        }
        // now we need to update 'id_path' field, as we know $page_id
        /* Generate id_path for page */
        $parent_id = intval($_data['parent_id']);
        if ($parent_id == 0) {
            $id_path = $page_id;
        } else {
            $id_path = db_get_row("SELECT id_path FROM ?:pages WHERE page_id = ?i", $parent_id);
            $id_path = $id_path['id_path'] . '/' . $page_id;
        }
        db_query('UPDATE ?:pages SET ?u WHERE page_id = ?i', array('id_path' => $id_path), $page_id);
    } else {
        if (!fn_check_company_id('pages', 'page_id', $page_id)) {
            fn_company_access_denied_notification();
            return false;
        }
        $old_company_id = fn_get_company_id('pages', 'page_id', $page_id);
        if ($_data['company_id'] != $old_company_id) {
            fn_change_page_company($page_id, $_data['company_id']);
        }
        // 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', $_data, $page_id);
        db_query('UPDATE ?:page_descriptions SET ?u WHERE page_id = ?i AND lang_code = ?s', $_data, $page_id, $lang_code);
        // regenerate id_path for child pages
        if (isset($page_data['parent_id'])) {
            fn_change_page_parent($page_id, $page_data['parent_id']);
        }
    }
    if (!empty($page_data['block_id'])) {
        fn_add_items_to_block($page_data['block_id'], $page_data['add_items'], $page_id, 'pages');
    }
    fn_set_hook('update_page', $page_data, $page_id, $lang_code);
    return $page_id;
}
예제 #2
0
function fn_update_news($news_id, $news_data, $lang_code = CART_LANGUAGE)
{
    // news title required
    if (empty($news_data['news'])) {
        return false;
    }
    $_data = $news_data;
    $_data['date'] = fn_parse_date($news_data['date']);
    if (isset($_data['localization'])) {
        $_data['localization'] = empty($_data['localization']) ? '' : fn_implode_localizations($_data['localization']);
    }
    if (empty($news_id)) {
        $create = true;
        $news_id = $_data['news_id'] = db_query("REPLACE INTO ?:news ?e", $_data);
        if (empty($news_id)) {
            return false;
        }
        // Adding descriptions
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:news_descriptions ?e", $_data);
        }
    } else {
        if (!empty($news_data['block_id'])) {
            fn_add_items_to_block($news_data['block_id'], $news_data['add_items'], $news_id, 'news');
        }
        db_query("UPDATE ?:news SET ?u WHERE news_id = ?i", $_data, $news_id);
        // update news descriptions
        $_data = $news_data;
        db_query("UPDATE ?:news_descriptions SET ?u WHERE news_id = ?i AND lang_code = ?s", $_data, $news_id, $lang_code);
    }
    // Log news update/add
    fn_log_event('news', !empty($create) ? 'create' : 'update', array('news_id' => $news_id));
    fn_set_hook('update_news', $news_data, $news_id, $lang_code);
    return $news_id;
}
예제 #3
0
     $suffix = "&selected_section={$_REQUEST['add_selected_section']}";
 }
 if ($mode == 'enable_disable' && !empty($_REQUEST['block_id'])) {
     fn_assign_block($_REQUEST);
     exit;
 }
 if ($mode == 'update') {
     fn_update_block($_REQUEST['block'], $_REQUEST['block']['location'], $_REQUEST['redirect_location']);
     $suffix .= "&selected_section={$_REQUEST['redirect_location']}";
 }
 if ($mode == 'update_location') {
     fn_update_location($_REQUEST['block']);
     $suffix .= "&selected_section=" . $_REQUEST['block']['location'];
 }
 if ($mode == 'add_items') {
     fn_add_items_to_block($_REQUEST['block_id'], !empty($_REQUEST['block_items']) ? $_REQUEST['block_items'] : '', !empty($_REQUEST['object_id']) ? $_REQUEST['object_id'] : 0, $_REQUEST['block_location'], empty($_REQUEST['is_manage']), !empty($_REQUEST['page']) ? $_REQUEST['page'] : 0);
     $suffix .= "&selected_section={$_REQUEST['redirect_location']}";
 }
 if ($mode == 'save_layout') {
     $positions = $_REQUEST['block_positions'];
     if (empty($_REQUEST['object_id']) && empty($_REQUEST['user_choice'])) {
         foreach ($positions as $_group) {
             if (!empty($_group)) {
                 $block_ids = split(',', $_group);
                 $custom_positions = db_get_array("SELECT position FROM ?:block_positions WHERE object_id != '0' AND location = ?s AND (block_id IN(?n) OR text_id IN(?a))", $_REQUEST['add_selected_section'], $block_ids, $block_ids);
                 if (!empty($custom_positions)) {
                     $ajax->assign('confirm_text', fn_get_lang_var('text_position_overwrite'));
                     exit;
                 }
             }
         }
예제 #4
0
function fn_update_category($category_data, $category_id = 0, $lang_code = CART_LANGUAGE)
{
    // category title required
    if (empty($category_data['category'])) {
        //return false; // FIXME: management page doesn't have category name
    }
    if (isset($category_data['localization'])) {
        $category_data['localization'] = empty($category_data['localization']) ? '' : fn_implode_localizations($category_data['localization']);
    }
    if (isset($category_data['usergroup_ids'])) {
        $category_data['usergroup_ids'] = empty($category_data['usergroup_ids']) ? '' : implode(',', $category_data['usergroup_ids']);
    }
    $_data = $category_data;
    if (isset($category_data['timestamp'])) {
        $_data['timestamp'] = fn_parse_date($category_data['timestamp']);
    }
    if (empty($_data['position']) && isset($_data['parent_id'])) {
        $_data['position'] = db_get_field("SELECT max(position) FROM ?:categories WHERE parent_id = ?i", $_data['parent_id']);
        $_data['position'] = $_data['position'] + 10;
    }
    if (!empty($_data['selected_layouts'])) {
        $_data['selected_layouts'] = serialize($_data['selected_layouts']);
    }
    if (isset($_data['use_custom_templates']) && $_data['use_custom_templates'] == 'N') {
        // Clear the layout settings if the category custom templates were disabled
        $_data['product_columns'] = $_data['selected_layouts'] = $_data['default_layout'] = '';
    }
    // create new category
    if (empty($category_id)) {
        $create = true;
        $category_id = db_query("INSERT INTO ?:categories ?e", $_data);
        if (empty($category_id)) {
            return false;
        }
        // now we need to update 'id_path' field, as we know $category_id
        /* Generate id_path for category */
        $parent_id = intval($_data['parent_id']);
        if ($parent_id == 0) {
            $id_path = $category_id;
        } else {
            $id_path = db_get_row("SELECT id_path FROM ?:categories WHERE category_id = ?i", $parent_id);
            $id_path = $id_path['id_path'] . '/' . $category_id;
        }
        db_query('UPDATE ?:categories SET ?u WHERE category_id = ?i', array('id_path' => $id_path), $category_id);
        //
        // Adding same category descriptions for all cart languages
        //
        $_data = $category_data;
        $_data['category_id'] = $category_id;
        foreach ((array) Registry::get('languages') as $_data['lang_code'] => $v) {
            db_query("INSERT INTO ?:category_descriptions ?e", $_data);
        }
        // update existing category
    } else {
        /* regenerate id_path for all child categories of the updated category */
        if (isset($category_data['parent_id'])) {
            fn_change_category_parent($category_id, intval($category_data['parent_id']));
        }
        db_query("UPDATE ?:categories SET ?u WHERE category_id = ?i", $_data, $category_id);
        $_data = $category_data;
        db_query("UPDATE ?:category_descriptions SET ?u WHERE category_id = ?i AND lang_code = ?s", $_data, $category_id, $lang_code);
    }
    // Log category add/update
    fn_log_event('categories', !empty($create) ? 'create' : 'update', array('category_id' => $category_id));
    // Assign usergroup to all subcategories
    if (!empty($category_data['usergroup_to_subcats']) && $category_data['usergroup_to_subcats'] == 'Y') {
        $id_path = db_get_field("SELECT id_path FROM ?:categories WHERE category_id = ?i", $category_id);
        db_query("UPDATE ?:categories SET usergroup_ids = ?s WHERE id_path LIKE ?l", $category_data['usergroup_ids'], "{$id_path}/%");
    }
    if (!empty($category_data['block_id'])) {
        fn_add_items_to_block($category_data['block_id'], $category_data['add_items'], $category_id, 'categories');
    }
    fn_set_hook('update_category', $category_data, $category_id, $lang_code);
    return $category_id;
}