/** * @desc Almacena información perteneciente a una publicación **/ function savePublish() { global $xoopsSecurity, $xoopsModuleConfig, $xoopsUser, $xoopsConfig; $config_handler =& xoops_gethandler('config'); $xconfig = $config_handler->getConfigsByCat(XOOPS_CONF_MAILER); foreach ($_POST as $k => $v) { ${$k} = $v; } if ($xoopsModuleConfig['permalinks']) { $purl = RDFunctions::url() . '/publish/'; } else { $purl = RDFunctions::url() . '?page=publish&action=publish'; } if (!$xoopsSecurity->check()) { redirect_header($prul, 1, __('Session token expired!', 'docs')); die; } $db = XoopsDatabaseFactory::getDatabaseConnection(); //Comprueba que el título de publicación no exista $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_resources') . " WHERE title='{$title}' "; list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { redirect_header($purl, 1, __('Already exists a Document with same name!', 'docs')); die; } $res = new RDResource(); //Genera $nameid Nombre identificador $found = false; $i = 0; do { $nameid = TextCleaner::getInstance()->sweetstring($title) . ($found ? $i : ''); $sql = "SELECT COUNT(*) FROM " . $db->prefix('rd_resources') . " WHERE nameid = '{$nameid}'"; list($num) = $db->fetchRow($db->queryF($sql)); if ($num > 0) { $found = true; $i++; } else { $found = false; } } while ($found == true); $res->setVar('title', $title); $res->setVar('description', $desc); $res->setVar('created', time()); $res->setVar('modified', time()); $res->setVar('editors', $editors); $res->setVar('groups', $groups); $res->setVar('public', 1); $res->setVar('quick', $quick); $res->setVar('nameid', $nameid); $res->setVar('owner', $xoopsUser->uid()); $res->setVar('owname', $xoopsUser->uname()); $res->setVar('approved', $xoopsModuleConfig['approved']); $res->setVar('single', $single); if (!$res->save()) { redirect_header($prul, 1, __('Document could not be created!', 'docs')); } else { //Si no se aprobó la publicación enviamos correo al administrador if (!$xoopsModuleConfig['approved']) { $mailer = new RMMailer('text/plain'); $mailer->add_user($xconfig['from'], $xconfig['fromname'], 'to'); $mailer->set_subject(__('New Document created at RapidDocs is waiting for approval', 'rmcommon')); $mailer->assign('to_name', $xconfig['fromname']); $mailer->assign('link_to_resource', XOOPS_URL . '/modules/docs/admin/resources.php?action=edit&id=' . $res->id()); $mailer->template(RMTemplate::get()->get_template('mail/resource_for_approval.php', 'module', 'docs')); if (!$mailer->send()) { redirect_header(RDFunctions::url(), 1, __('Your Document has been created, however the email to administrator could no be sent.', 'docs')); die; } redirect_header(RDFunctions::url(), 1, __('Your Document has been created and is pending for approval. We will sent an email when you can access to it and add content.', 'docs')); die; } if ($xoopsModuleConfig['permalinks']) { $purl = RDFunctions::url() . '/list/' . $res->id() . '/'; } else { $purl = RDFunctions::url() . '?page=edit&action=list&id=' . $res->id(); } redirect_header($purl, 1, __('Document created successfully!', 'docs')); die; } }
/** * @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); } } }
/** * @desc Permite aprobar o no una publicación **/ function approved_resources($app = 0) { global $xoopsSecurity, $xoopsConfig, $xoopsModuleConfig; $resources = rmc_server_var($_POST, 'ids', array()); $page = rmc_server_var($_POST, 'page', 1); if (!$xoopsSecurity->check()) { redirectMsg('./resources.php?page=' . $page, __('Session token expired!', 'docs'), 1); die; } //Verifica que se haya proporcionado una publicación if (!is_array($resources) || empty($resources)) { redirectMsg('./resources.php?page=' . $page, __('Select at least a Document!', 'docs'), 1); die; } $errors = ''; foreach ($resources as $k) { //Comprueba si la publicación es válida if ($k <= 0) { $errors .= sprintf(__('Document ID "%s" is not valid!', 'docs'), $k); continue; } //Comprueba si la publicación existe $res = new RDResource($k); if ($res->isNew()) { $errors .= sprintf(__('Document with ID "%s" does not exists!', 'docs'), $k); continue; } $approved = $res->getVar('approved'); $res->setVar('approved', $app); if (!$res->save()) { $errors .= sprintf(__('Resoource "%s" could not be saved!', 'docs'), $k); } else { if ($app && !$approved) { $errors .= RDFunctions::mail_approved($res) != true ? __('Notification email could not be sent!', 'docs') . '<br />' : ''; } } } if ($errors != '') { redirectMsg('./resources.php?page=' . $page, __('Errors ocurred while trying to update resources.') . '<br />' . $errors, 1); } else { redirectMsg('./resources.php?page=' . $page, __('Documents updated successfully!', 'docs'), 0); } }