/** * Agregamos nuevos editores a la base de datos */ function save_editor($edit = false) { global $xoopsConfig, $xoopsSecurity; $page = rmc_server_var($_POST, 'page', 1); if (!$xoopsSecurity->check()) { redirectMsg('editors.php?page=' . $page, __('Operation not allowed!', 'mywords'), 1); die; } if ($edit) { $id = rmc_server_var($_POST, 'id', 0); if ($id <= 0) { redirectMsg('editors.php?page=' . $page, __('Editor ID has not been provided!', 'mywords'), 1); die; } $editor = new MWEditor($id); if ($editor->isNew()) { redirectMsg('editors.php?page=' . $page, __('Editor has not been found!', 'mywords'), 1); die; } } else { $editor = new MWEditor(); } $name = rmc_server_var($_POST, 'name', ''); $bio = rmc_server_var($_POST, 'bio', ''); $uid = rmc_server_var($_POST, 'new_user', 0); $perms = rmc_server_var($_POST, 'perms', array()); $short = rmc_server_var($_POST, 'short', ''); if (trim($name) == '') { redirectMsg('editors.php?page=' . $page, __('You must provide a display name for this editor!', 'mywords'), 1); die; } if ($uid <= 0) { redirectMsg('editors.php?page=' . $page, __('You must specify a registered user ID for this editor!', 'mywords'), 1); die; } // Check if XoopsUser is already register $db = XoopsDatabaseFactory::getDatabaseConnection(); $sql = "SELECT COUNT(*) FROM " . $db->prefix("mw_editors") . " WHERE uid={$uid}"; if ($edit) { $sql .= " AND id_editor<>" . $editor->id(); } list($num) = $db->fetchRow($db->query($sql)); if ($num > 0) { redirectMsg('editors.php?page=' . $page, __('This user has been registered as editor before.', 'mywords'), 1); die; } $editor->setVar('name', $name); $editor->setVar('shortname', TextCleaner::sweetstring($short != '' ? $short : $name)); $editor->setVar('bio', $bio); $editor->setVar('uid', $uid); $editor->setVar('privileges', $perms); if (!$editor->save()) { redirectMsg('editors.php?page=' . $page, __('Errors occurs while trying to save editor data', 'mywords') . '<br />' . $editor->errors(), 1); die; } else { redirectMsg('editors.php?page=' . $page, __('Database updated succesfully!', 'mywords'), 0); die; } }
if (!isset($categories) || empty($categories)) { $categories = array(MWFunctions::get()->default_category_id()); } // Check publish options if ($visibility == 'password' && $vis_password == '') { return_error(__('You must provide a password for this post or select another visibility option', 'mywords'), true); die; } $time = explode("-", $schedule); $schedule = mktime($time[3], $time[4], 0, $time[1], $time[0], $time[2]); if ($schedule <= time()) { $schedule = 0; } $editor = new MWEditor($xoopsUser->uid(), 'user'); if ($editor->isNew()) { $editor->setVar('uid', $xoopsUser->uid()); $editor->setVar('shortname', $xoopsUser->getVar('uname')); $editor->setVar('name', $xoopsUser->getVar('name')); $editor->setVar('bio', $xoopsUser->getVar('bio')); $editor->setVar('active', 0); $editor->save(); } // Add Data $post->setVar('title', $title); $post->setVar('shortname', $shortname); $post->setVar('content', $content); if ($editor->isNew() && !$xoopsUser->isAdmin()) { $status = 'pending'; } else { if ($xoopsUser->isAdmin()) { $status = $status;