/** * Create/Update sitemap links * * @param array $links_data Links update data * @param int $section_id Section identifier */ function fn_update_sitemap_links($links_data, $section_id) { $link_ids = array(); foreach ($links_data as $link_data) { if (!empty($link_data['link'])) { fn_set_hook('sitemap_update_object', $link_data); if (empty($link_data['link_id'])) { $link_data['section_id'] = $section_id; $link_id = db_query("INSERT INTO ?:sitemap_links ?e", $link_data); $link_ids[] = $link_id; if (!empty($link_id)) { $_data = array(); foreach (fn_get_translation_languages() as $lang_code => $_lang_data) { $_data[] = array('object' => $link_data['link'], 'object_id' => $link_id, 'object_holder' => 'sitemap_links', 'lang_code' => $lang_code); } db_query("INSERT INTO ?:common_descriptions ?m", $_data); } } else { $link_data['section_id'] = $section_id; $link_ids[] = $link_data['link_id']; db_query("UPDATE ?:sitemap_links SET ?u WHERE link_id = ?i", $link_data, $link_data['link_id']); db_query("UPDATE ?:common_descriptions SET object=?s WHERE object_id = ?i AND lang_code = ?s AND object_holder = 'sitemap_links'", $link_data['link'], $link_data['link_id'], DESCR_SL); } } } $obsolete_ids = db_get_fields("SELECT link_id FROM ?:sitemap_links WHERE section_id = ?i AND link_id NOT IN (?n)", $section_id, $link_ids); if (!empty($obsolete_ids)) { fn_delete_sitemap_links($obsolete_ids); } }
$section = db_get_row("SELECT s.*, c.object as section FROM ?:sitemap_sections as s LEFT JOIN ?:common_descriptions as c ON c.object_id = s.section_id AND object_holder = ?s AND lang_code = ?s WHERE s.section_id = ?i", 'affiliate_plans', DESCR_SL, $_REQUEST['section_id']); $view->assign('section', $section); $links = db_get_array("SELECT link_id, link_href, section_id, status, position, link_type, description, object as link FROM ?:sitemap_links LEFT JOIN ?:common_descriptions ON ?:common_descriptions.object_id = ?:sitemap_links.link_id AND ?:common_descriptions.object_holder = 'sitemap_links' AND ?:common_descriptions.lang_code = ?s WHERE section_id = ?i ORDER BY position, link", DESCR_SL, $section_id); $view->assign('links', $links); fn_add_breadcrumb(fn_get_lang_var('sitemap'), "sitemap.manage"); // Show all section methods } elseif ($mode == 'manage') { $view->assign('sitemap_sections', db_get_array("SELECT *, object as section FROM ?:sitemap_sections LEFT JOIN ?:common_descriptions ON ?:common_descriptions.object_id = ?:sitemap_sections.section_id AND ?:common_descriptions.object_holder = 'sitemap_sections' AND ?:common_descriptions.lang_code = ?s ORDER BY position, section", DESCR_SL)); } elseif ($mode == 'delete_sitemap_section') { if (!empty($_REQUEST['section_id'])) { fn_delete_sitemap_sections((array) $_REQUEST['section_id']); } return array(CONTROLLER_STATUS_REDIRECT, "sitemap.manage"); } elseif ($mode == 'delete_link') { if (!empty($_REQUEST['link_id'])) { fn_delete_sitemap_links((array) $_REQUEST['link_id']); } return array(CONTROLLER_STATUS_REDIRECT, "sitemap.update?section_id={$section_id}"); } /** /Body **/ function fn_delete_sitemap_links($link_ids) { db_query("DELETE FROM ?:sitemap_links WHERE link_id IN (?n)", $link_ids); db_query("DELETE FROM ?:common_descriptions WHERE object_holder = 'sitemap_links' AND object_id IN (?n)", $link_ids); } function fn_delete_sitemap_sections($section_ids) { db_query("DELETE FROM ?:sitemap_sections WHERE section_id IN (?n)", $section_ids); db_query("DELETE FROM ?:common_descriptions WHERE object_holder = 'sitemap_sections' AND object_id IN (?n)", $section_ids); $links = db_get_fields("SELECT link_id FROM ?:sitemap_links WHERE section_id IN (?n)", $section_ids); if (!empty($links)) {