/** * @desc Modifica el orden de las secciones **/ function changeOrderSections() { global $xoopsSecurity, $xoopsModuleConfig; $orders = rmc_server_var($_POST, 'orders', array()); $id = rmc_server_var($_POST, 'id', 0); if ($xoopsModuleConfig['permalinks']) { $url_ret = RDfunctions::url() . '/list/' . $id . '/'; } else { $url_ret = RDFunctions::url() . '?page=edit&action=list&id=' . $id; } if (!$xoopsSecurity->check()) { redirect_header($url_ret, 0, __('Session token expired!', 'docs')); die; } if (!is_array($orders) || empty($orders)) { redirect_header($url_ret, 1, __('Sorry, the data provided contains some errors!', 'docs'), 1); die; } $errors = ''; foreach ($orders as $k => $v) { if ($k <= 0) { continue; } //Comprueba si la sección es existente $sec = new RDSection($k); if ($sec->isNew()) { continue; } $sec->setVar('order', $v); if (!$sec->save()) { $errors .= sprintf(__('Order could not be saved for section %s', 'docs'), $sec->getVar('title')) . '<br />'; } } if ($errors != '') { redirect_header($url_ret, 1, __('Errors ocurred while trying to update orders') . '<br />' . $errors); } else { redirect_header($url_ret, 0, __('Sections updated successfully!', 'docs')); } }
/** * @desc Almacena información de las secciones **/ function rd_save_sections($edit = 0) { global $xoopsUser, $xoopsSecurity; foreach ($_POST as $k => $v) { ${$k} = $v; } if (!$xoopsSecurity->check()) { redirectMsg('./sections.php?op=new&id=' . $id, __('Session token expired!', 'docs'), 1); die; } if ($id <= 0) { redirectMsg('resources.php', __('A Document was not specified!', 'docs'), 1); die; } $res = new RDResource($id); if ($res->isNew()) { redirectMsg('resources.php', __('Specified Document does not exists!', 'docs'), 1); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); if ($edit) { //Verifica si la sección es válida if ($id_sec <= 0) { redirectMsg('./sections.php?id=' . $id, __('No section has been specified', 'docs'), 1); die; } //Comprueba si la sección es existente $sec = new RDSection($id_sec); if ($sec->isNew()) { redirectMsg('./sections.php?id=' . $id, __('Section does not exists!', 'docs'), 1); die; } //Comprueba que el título de la sección no exista $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE title='{$title}' AND id_res='{$id}' AND id_sec<>{$id_sec}"; list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirectMsg('./sections.php?op=new&id=' . $id, __('Already exists another section with same title!', 'docs'), 1); die; } } else { //Comprueba que el título de la sección no exista $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE title='{$title}' AND id_res='{$id}'"; list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirectMsg('./sections.php?op=new&id=' . $id, __('Already exists another section with same title!', 'docs'), 1); die; } $sec = new RDSection(); } //Genera $nameid Nombre identificador $nameid = !isset($nameid) || $nameid == '' ? TextCleaner::getInstance()->sweetstring($title) : $nameid; $sec->setVar('title', $title); $sec->setVar('content', $content); $sec->setVar('order', $order); $sec->setVar('id_res', $id); $sec->setVar('nameid', $nameid); $sec->setVar('parent', $parent); if (!isset($uid)) { $sec->setVar('uid', $xoopsUser->uid()); $sec->setVar('uname', $xoopsUser->uname()); } else { $xu = new XoopsUser($uid); if ($xu->isNew()) { $sec->setVar('uid', $xoopsUser->uid()); $sec->setVar('uname', $xoopsUser->uname()); } else { $sec->setVar('uid', $uid); $sec->setVar('uname', $xu->uname()); } } if ($sec->isNew()) { $sec->setVar('created', time()); $sec->setVar('modified', time()); } else { $sec->setVar('modified', time()); } // Metas if ($edit) { $sec->clear_metas(); } // Clear all metas // Initialize metas array if not exists if (!isset($metas)) { $metas = array(); } // Get meta key if "select" is visible if (isset($meta_name_sel) && $meta_name_sel != '') { $meta_name = $meta_name_sel; } // Add meta to metas array if (isset($meta_name) && $meta_name != '') { array_push($metas, array('key' => $meta_name, 'value' => $meta_value)); } // Assign metas foreach ($metas as $value) { $sec->add_meta($value['key'], $value['value']); } RMEvents::get()->run_event('docs.saving.section', $sec); if (!$sec->save()) { if ($sec->isNew()) { redirectMsg('./sections.php?action=new&id=' . $id, __('Database could not be updated!', 'docs') . "<br />" . $sec->errors(), 1); die; } else { redirectMsg('./sections.php?action=edit&id=' . $id . '&sec=' . $id_sec, __('Sections has been saved but some errors ocurred', 'docs') . "<br />" . $sec->errors(), 1); die; } } else { $res->setVar('modified', time()); $res->save(); RMEvents::get()->run_event('docs.section.saved', $sec); if ($return) { redirectMsg('./sections.php?action=edit&sec=' . $sec->id() . '&id=' . $id, __('Database updated successfully!', 'docs'), 0); } else { redirectMsg('./sections.php?id=' . $id, __('Database updated successfully!', 'docs'), 0); } } }