/** * @desc Almacena toda la información referente a la sección **/ function saveSection($edit = 0, $ret = 0) { global $xoopsUser, $xoopsModuleConfig; foreach ($_POST as $k => $v) { ${$k} = $v; } //Verifica si se proporcionó una publicación para la sección if ($res <= 0) { redirect_header(RDURL, 1, __('Operation not allowed!', 'docs')); die; } //Verifica si la publicación existe $res = new RDResource($res); if ($res->isNew()) { redirect_header(RDURL, 1, __('Operation not allowed!', 'docs')); die; } //Verificamos si es una publicación aprobada if (!$res->getVar('approved')) { redirect_header(RDURL, 2, __('This Document has not been approved yet!', 'docs')); die; } // TODO: Crear el link correcto de retorno if ($xoopsModuleConfig['permalinks']) { $retlink = RDFunctions::url() . '/list/' . $res->getVar('nameid') . '/'; } else { $retlink = RDFunctions::url() . '?page=edit&action=list&res=' . $res->id(); } //Verificamos si el usuario tiene permisos de edicion if (!$xoopsUser->uid() == $res->getVar('owner') && !$res->isEditor($xoopsUser->uid()) && !$xoopsUser->isAdmin()) { redirect_header(RDURL, 2, __('You can not edit this content!', 'docs')); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); if ($edit) { //Verifica si la sección es válida if ($id == '') { redirect_header($retlink, 1, __('Specified section is not valid!', 'docs')); die; } //Comprueba si la sección es existente $sec = new RDSection($id); if ($sec->isNew()) { redirect_header($retlink, 1, __('Specified section does not exists!', 'docs')); 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='{$res}' AND id_sec<>" . $sec->id(); list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirect_header($sec->editlink(), 1, __('Already exists another section with same title!', 'docs')); die; } /** * Comprobamos si debemos almacenar las ediciones en la * tabla temporal o directamente en la tabla de secciones */ if (!$res->getVar('editor_approve') && !$xoopsUser->isAdmin()) { $sec = new RDEdit(null, $id_sec); } } 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='" . $res->id() . "'"; list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirect_header(ah_make_link('publish/' . $res->nameId() . '/'), 1, _MS_AH_ERRTITLE); die; } $sec = new RDSection(); } //Genera $nameid Nombre identificador if ($title != $sec->getVar('title')) { $found = false; $i = 0; do { $nameid = TextCleaner::getInstance()->sweetstring($title) . ($found ? $i : ''); $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_sections') . " WHERE nameid = '{$nameid}'"; list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { $found = true; $i++; } else { $found = false; } } while ($found == true); } if (!$res->getVar('editor_approve') && !$xoopsUser->isAdmin() && !($res->getVar('owner') == $xoopsUser->uid())) { $sec->setVar('id_sec', $id); } $sec->setVar('title', $title); $sec->setVar('content', $content); $sec->setVar('order', $order); $sec->setVar('id_res', $res->id()); isset($nameid) ? $sec->setVar('nameid', $nameid) : ''; $sec->setVar('parent', $parent); $sec->setVar('uid', $xoopsUser->uid()); $sec->setVar('uname', $xoopsUser->uname()); if ($edit) { $sec->setVar('modified', time()); } else { $sec->setVar('created', time()); $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()) { redirect_header($sec->editlink(), 3, __('Section could not be saved!', 'docs')); } else { if ($edit) { $sec = new RDSection($sec->getVar('id_sec')); } if ($return == 1) { redirect_header($sec->permalink(), 1, __('Database updated successfully!', 'docs')); } elseif ($return == 2) { redirect_header($sec->editlink(), 1, __('Database updated successfully!', 'docs')); } else { redirect_header($retlink, 1, __('Database 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); } } }