예제 #1
0
/**
* @desc Almacena los camobios realizados en el orden de las categorías
**/
function updateOrderCatego()
{
    global $xoopsSecurity;
    $orders = isset($_POST['orders']) ? $_POST['orders'] : array();
    if (!$xoopsSecurity->check()) {
        RMUris::redirect_with_message(__('Token session expired. Try again.', 'bxpress'), 'categories.php', RMMSG_ERROR);
    }
    $errors = '';
    foreach ($orders as $k => $v) {
        //Verificamos que la categoría sea válida
        if ($k <= 0) {
            $errors .= sprintf(__('Category ID is not valid: %s', 'bxpress'), $k);
            continue;
        }
        //Verificamos que categoría exista
        $cat = new bXCategory($k);
        if ($cat->isNew()) {
            $errors .= sprintf(__('Category with ID %u does not exists.', 'bxpress'), $k);
            continue;
        }
        //Actualizamos el orden
        $cat->setOrder($v);
        if (!$cat->save()) {
            $errors .= sprintf(__('Category %s could not be saved.', 'bxpress'), $k);
        }
    }
    if ($errors != '') {
        RMUris::redirect_with_message(__('Errors ocurred while trying to update categories order', 'bxpress') . $errors, './categories.php', RMMSG_ERROR);
    } else {
        RMUris::redirect_with_message(__('Database updated successfully!', 'bxpress'), './categories.php', RMMSG_SUCCESS);
    }
}
예제 #2
0
    $response->prepare_ajax_response();
    $result = RMNotifications::get()->subscribe();
    if (FALSE === $result) {
        $response->ajax_response(__('Sorry, your request could not be processed.', 'rmcommon'), 1, 0);
    }
    $message = 'subscribed' == $result->status ? __('Subscribed', 'rmcommon') : __('Subscription cancelled', 'rmcommon');
    $response->ajax_response($message, 0, 0, $event);
} elseif ('cu-notification-list' == $page) {
    // Show subscriptions list
    global $xoopsUser, $cuSettings;
    if (!$xoopsUser) {
        RMUris::redirect_with_message(__('You need to register/login to view this page.', 'rmcommon'), XOOPS_URL, RMMSG_WARN);
    }
    $subscriptions = RMNotifications::get()->subscriptions();
    if (empty($subscriptions)) {
        RMUris::redirect_with_message(__('You are not subscribed to any notification event.', 'rmcommon'), XOOPS_URL, RMMSG_WARN);
    }
    $elements = array();
    $items = array();
    $tf = new RMTimeFormatter(0, __('%M% %d%, %Y%', 'rmcommon'));
    $crypt = new Crypt(null, $cuSettings->secretkey);
    foreach ($subscriptions as $item) {
        $class = ucfirst($item->element . '_Notifications');
        if (!class_exists($class)) {
            // Include controller file
            if ('plugin' == $event->type) {
                $file = XOOPS_ROOT_PATH . '/modules/rmcommon/plugins/' . $item->element . '/class/' . strtolower($item->element) . '.notifications.class.php';
            } elseif ('theme' == $event->type) {
                $file = XOOPS_ROOT_PATH . '/themes/' . $item->element . '/class/' . strtolower($item->element) . '.notifications.class.php';
            } else {
                $file = XOOPS_ROOT_PATH . '/modules/' . $item->element . '/class/' . strtolower($item->element) . '.notifications.class.php';
예제 #3
0
function activate_position($status)
{
    global $xoopsSecurity, $xoopsDB;
    if (!$xoopsSecurity->check()) {
        RMUris::redirect_with_message(__('Session token is not valid!', 'rmcommon'), 'blocks.php', RMMSG_ERROR);
    }
    $ids = RMHttpRequest::post('ids', 'array', array());
    if (!is_array($ids) || empty($ids)) {
        RMUris::redirect_with_message(__('No position id has been provided', 'rmcommon'), 'blocks.php', RMMSG_WARN);
    }
    $sql = "UPDATE " . $xoopsDB->prefix("mod_rmcommon_blocks_positions") . " SET active = " . ($status == 'active' ? 1 : 0) . "\n            WHERE id_position IN (" . implode(',', $ids) . ")";
    if ($xoopsDB->queryF($sql)) {
        RMUris::redirect_with_message(__('Database updated successully!', 'rmcommon'), 'blocks.php', RMMSG_SUCCESS);
    } else {
        RMUris::redirect_with_message(__('Errors ocurrs while trying to update data:', 'rmcommon') . $xoopsDB->error(), 'blocks.php', RMMSG_ERROR);
    }
}
예제 #4
0
파일: forum.php 프로젝트: petitours/bxpress
    redirect_header(BB_URL, 2, __('Specified forum does not exists!', 'bxpress'));
    die;
}
/**
 * Check if module is inactive
 */
$isModerator = $xoopsUser && ($xoopsUser->isAdmin() || $forum->isModerator($xoopsUser->uid()));
if (!$forum->active && !$isModerator) {
    RMUris::redirect_with_message(__('This forum is closed and you don\'t have permissions to view it', 'bxpress'), BX_URL, RMMSG_WARN);
}
/**
* Comprobamos que el usuario actual tenga permisos
* de acceso al foro
*/
if (!$forum->isAllowed($xoopsUser ? $xoopsUser->getGroups() : array(0, XOOPS_GROUP_ANONYMOUS), BXPRESS_PERM_VIEW)) {
    RMUris::redirect_with_message(__('You are not allowed to view this forum!', 'bxpress'), BX_URL, RMMSG_WARN);
    die;
}
/**
* Cargamos los temas
*/
$tbl1 = $db->prefix("mod_bxpress_topics");
$tbl2 = $db->prefix("mod_bxpress_forumtopics");
$sql = "SELECT COUNT(*) FROM {$tbl1} WHERE id_forum='" . $forum->id() . "' AND approved='1'";
list($num) = $db->fetchRow($db->queryF($sql));
$page = isset($_REQUEST['pag']) ? $_REQUEST['pag'] : '';
$limit = $xoopsModuleConfig['topicperpage'] > 0 ? $xoopsModuleConfig['topicperpage'] : 15;
if ($page > 0) {
    $page -= 1;
}
$start = $page * $limit;
예제 #5
0
<?php

// $Id: submit.php 824 2011-12-08 23:50:30Z i.bitcero $
// --------------------------------------------------------------
// MyWords
// Blogging System
// Author: Eduardo Cortés <*****@*****.**>
// Email: i.bitcero@gmail.com
// License: GPL 2.0
// --------------------------------------------------------------
require '../../mainfile.php';
global $xoopsUser, $xoopsOption, $xoopsModuleConfig, $xoopsConfig, $rmTpl, $xoopsSecurity;
if (!$xoopsModuleConfig['submit']) {
    RMUris::redirect_with_message(__('Posts submission is currently disabled', 'mywords'), XOOPS_URL, RMMSG_INFO);
}
if (!$xoopsUser) {
    redirect_header(MWFunctions::get_url(), 1, __('You are not allowed to do this action!', 'mywords'));
    die;
}
// Check if user is a editor
$author = new MWEditor();
if (!$author->from_user($xoopsUser->uid()) && !$xoopsUser->isAdmin()) {
    redirect_header(MWFunctions::get_url(), 1, __('You are not allowed to do this action!', 'mywords'));
    die;
}
RMTemplate::get()->add_jquery();
$edit = isset($edit) ? $edit : 0;
if ($edit > 0) {
    $id = $edit;
    if ($id <= 0) {
        redirect_header(MWFunctions::get_url(), __('Please, specify a valid post ID', 'mywords'), 1);
예제 #6
0
 public function eventCoreIncludeFunctionsRedirectheaderStart($params)
 {
     global $xoopsModule;
     global $cuSettings;
     //if ( $xoopsModule &&  !$xoopsModule->getInfo('rmnative') && $cuSettings->gui_disable )
     //    return;
     // 0 = URL
     // 1 = Time
     // 2 = Message
     // 3 = Add redirect
     // 4 = Allow external link
     RMEvents::get()->run_event('rmcommon.redirect.header', $params[0], $params[1], $params[2], $params[3], $params[4]);
     //if(!defined('XOOPS_CPFUNC_LOADED')) return;
     RMUris::redirect_with_message($params[2], $params[0], RMMSG_INFO);
     die;
 }
예제 #7
0
 private function response($method)
 {
     if ($method == 'ajax') {
         self::prepare_ajax_response();
         self::ajax_response(__('You don\'t have required rights to do this action!', 'rmcommon'), 1, 0, array('goto' => XOOPS_URL));
     } else {
         RMUris::redirect_with_message(__('You don\'t have required rights to do this action!', 'rmcommon'), XOOPS_URL, RMMSG_WARN, 'fa fa-warning');
     }
 }
예제 #8
0
        $xoopsMailer->setToGroups($group);
        $xoopsMailer->setFromEmail($mailConfig['from']);
        $xoopsMailer->setFromName($mailConfig['fromname']);
        $xoopsMailer->setSubject(sprintf(__('New comment sent in %s', 'rmcommon'), $xoopsConfig['sitename']));
        if (isset($controller)) {
            $item = array('name' => $controller->get_item($params, $comment), 'url' => $uri);
        } else {
            $item = array('name' => $xoopsConfig['sitename'], 'url' => $uri);
        }
        ob_start();
        include RMTemplate::get()->get_template('mail/rmc-comment-notify.php');
        $body = ob_get_clean();
        $xoopsMailer->setBody($body);
        $xoopsMailer->send();
    }
    RMUris::redirect_with_message(__('Comment posted successfully!', 'rmcommon'), $uri . '#comment-' . $comment->id(), RMMSG_SUCCESS);
} elseif ($action == 'edit') {
    if (rmc_server_var($_GET, 'ret', '') == '') {
        redirect_header(XOOPS_URL, 2, __('Invalid operation', 'rmcommon'));
        die;
    }
    // Check if user is allowed to edit this comment
    if (!$xoopsUser) {
        redirect_header(rmc_server_var($_REQUEST, 'comment_url', XOOPS_URL), 1, __('You are not allowed to edit this comment!', 'rmcommon'));
        die;
    }
    $id = rmc_server_var($_GET, 'id', 0);
    if ($id <= 0) {
        redirect_header(rmc_server_var($_REQUEST, 'ret', XOOPS_URL), 1, __('Please specify a comment', 'rmcommon'));
        die;
    }
예제 #9
0
/**
* @desc Activa o desactiva un foro
*/
function bx_activate_forums($status = 1)
{
    global $xoopsDB, $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        RMUris::redirect_with_message(__('Session token expired! Try again.', 'bxpress'), 'forums.php', RMMSG_ERROR);
    }
    $forums = RMHttpRequest::post('ids', 'array', null);
    if (!is_array($forums) || empty($forums)) {
        RMUris::redirect_with_message(__('No forum has been selected.', 'bxpress'), 'forums.php', RMMSG_ERROR);
    }
    $sql = "UPDATE " . $xoopsDB->prefix("mod_bxpress_forums") . " SET active='{$status}' WHERE ";
    $sql1 = '';
    foreach ($forums as $k => $v) {
        $sql1 .= $sql1 == '' ? "id_forum='{$v}' " : "OR id_forum='{$v}' ";
    }
    $xoopsDB->queryF($sql . $sql1);
    RMUris::redirect_with_message(__('Database updated successfully!', 'bxpress'), 'forums.php', RMMSG_INFO);
}
예제 #10
0
/**
* Save user data
*
* @param bool Indicates when is a edit
*/
function save_data($edit = false)
{
    global $xoopsSecurity, $xoopsDB;
    $q = '';
    // Query String
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
        if ($k == 'XOOPS_TOKEN_REQUEST' || $k == 'sbt' || $k == 'action' || $k == 'password' || $k == 'passwordc') {
            continue;
        }
        $q .= $q == '' ? "{$k}=" . urlencode($v) : "&{$k}=" . urlencode($v);
    }
    if (!$xoopsSecurity->check()) {
        redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Sorry, you don\'t have permission to add users.', 'rmcommon'), 1);
        die;
    }
    if ($edit) {
        if ($uid <= 0) {
            redirectMsg('users.php', __('The specified user is not valid!', 'rmcommon'), 1);
            die;
        }
        $user = new RMUser($uid);
        if ($user->isNew()) {
            redirectMsg('users.php', __('The specified user does not exists!', 'rmcommon'), 1);
            die;
        }
    } else {
        $user = new RMUser();
    }
    // Check uname, password and passwordc
    if ($uname == '' || $email == '' || !$edit && ($password == '' || $passwordc == '')) {
        redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Please fill all required fields and try again!', 'rmcommon'), 1);
        die;
    }
    // Check passwords
    if ($password != $passwordc) {
        redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('Passwords doesn\'t match. Please chek them.', 'rmcommon'), 1);
        die;
    }
    // Check if user exists
    $sql = "SELECT COUNT(*) FROM " . $xoopsDB->prefix("users") . " WHERE (uname = '{$uname}' OR email = '{$email}')" . ($edit ? " AND uid != " . $user->uid : '');
    list($exists) = $xoopsDB->fetchRow($xoopsDB->query($sql));
    if ($exists > 0) {
        RMUris::redirect_with_message(__('Another user with same username or email already exists!', 'rmcommon'), 'users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, RMMSG_ERROR);
    }
    // Save user data
    $user->setVar('name', $name);
    $user->setVar('uname', $uname);
    $user->setVar('display_name', $display_name);
    $user->setVar('email', $email);
    if (!$edit) {
        $user->assignVar('user_regdate', time());
    }
    if ($password != '') {
        $user->assignVar('pass', md5($password));
    }
    $user->setVar('level', 1);
    $user->setVar('timezone_offset', $timezone);
    $user->setVar('url', $url);
    /**
     * If "All" has been selected then we need to get all
     * groups ID's
     */
    if (in_array(0, $groups)) {
        $groups = array();
        $result = $xoopsDB->query("SELECT groupid FROm " . $xoopsDB->prefix("groups"));
        while ($row = $xoopsDB->fetchArray($result)) {
            $groups[] = $row['groupid'];
        }
        unset($result);
    }
    /**
     * If no group has been selected, then we add user to
     * Anonymous group
     */
    if (empty($groups)) {
        $groups = array(XOOPS_GROUP_ANONYMOUS);
    }
    $user->setGroups($groups);
    // Plugins and modules can save metadata.
    // Metadata are generated by other dynamical fields
    $user = RMEvents::get()->run_event('rmcommon.add.usermeta.4save', $user);
    if ($user->save()) {
        $user = RMEvents::get()->run_event($edit ? 'rmcommon.user.edited' : 'rmcommon.user.created', $user);
        redirectMsg('users.php', __('Database updated successfully!', 'rmcommon'), 0);
    } else {
        redirectMsg('users.php?action=' . ($edit ? 'edit' : 'new') . '&' . $q, __('The users could not be saved. Please try again!', 'rmcommon') . '<br />' . $user->errors(), 1);
    }
}
예제 #11
0
/**
* Stores data for new categories
*/
function save_category($edit = 0)
{
    global $xoopsDB, $xoopsModuleConfig, $xoopsModule;
    $q = 'images.php?action=' . ($edit ? 'editcat' : 'newcat');
    foreach ($_POST as $k => $v) {
        if ($k == 'action' || $k == 'XOOPS_TOKEN_REQUEST') {
            continue;
        }
        if (is_array($v)) {
            $q .= '&' . RMFunctions::urlencode_array($v, $k);
        } else {
            $q .= '&' . $k . '=' . urlencode($v);
        }
    }
    extract($_POST);
    if ($edit) {
        if ($id <= 0) {
            redirectMsg('images.php?action=showcats', __('Specify a valid category id', 'rmcommon'), 1);
            die;
        }
        $cat = new RMImageCategory($id);
        if ($cat->isNew()) {
            redirectMsg('images.php?action=showcats', __('Specified category does not exists!', 'rmcommon'), 1);
            die;
        }
    } else {
        $cat = new RMImageCategory();
    }
    if ($name == '') {
        redirectMsg($q, __('Please specify a category name', 'rmcommon'), 1);
        die;
    }
    if (empty($read)) {
        $read = array(0);
    }
    if (empty($write)) {
        $write = array(0);
    }
    // Check if resize data is correct
    $schecked = array();
    foreach ($sizes as $size) {
        if (trim($size['name']) == '') {
            continue;
        }
        if ($size['type'] != 'none' && $size['width'] <= 0 && $size['height'] <= 0) {
            continue;
        }
        $schecked[] = $size;
    }
    if (empty($schecked)) {
        redirectMsg($q, __('You must create one size for this category at least!', 'rmcommon'), 1);
        die;
    }
    // Check if there are a category with same name
    $num = RMFunctions::get_num_records('mod_rmcommon_images_categories', "name='{$name}'" . ($edit ? " AND id_cat<>'" . $cat->id() . "'" : ''));
    if ($num > 0) {
        redirectMsg($q, __('There is already a category with the same name!', 'rmcommon'), 1);
        die;
    }
    $cat->setVar('name', $name);
    $cat->setVar('status', $status);
    $cat->setVar('groups', array('write' => $write, 'read' => $read));
    $cat->setVar('sizes', $schecked);
    $cat->setVar('filesize', $filesize <= 0 ? '50' : $filesize);
    $cat->setVar('sizeunit', $sizeunit <= 0 ? '1024' : $sizeunit);
    if ($cat->save()) {
        RMUris::redirect_with_message(__($edit ? 'Category updated successfully!' : 'Category saved successfully!', 'rmcommon'), 'images.php?action=showcats', RMMSG_SUCCESS);
    } else {
        RMUris::redirect_with_message(__('There were some erros while trying to save this category.', 'rmcommon') . '<br />' . $cat->errors(), $q, RMMSG_ERROR);
    }
}
 protected function logged()
 {
     global $xoopsUser;
     if ($xoopsUser) {
         return true;
     }
     RMUris::redirect_with_message(__('This area requires user login!', 'rmcommon'), XOOPS_URL . '/user.php', RMMSG_INFO);
     return null;
 }
예제 #13
0
/**
* Install specified theme
*/
function xt_install_theme()
{
    global $xoopsConfig, $xtFunctions, $xtAssembler;
    $current = $xtAssembler->theme()->getInfo('dir');
    $dir = RMHttpRequest::get('dir', 'string', '');
    if ($dir == '') {
        redirectMsg('themes.php', __('No theme has been specified!', 'xthemes'), RMMSG_ERROR);
    }
    $theme_dir = XOOPS_THEME_PATH . '/' . $dir;
    if (!is_file($theme_dir . '/theme.html')) {
        redirectMsg('themes.php', __('Specified directory does not contain a valid theme!', 'xthemes'), RMMSG_WARN);
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    if (is_file($theme_dir . '/assemble/' . $dir . '.theme.php')) {
        // Install a xThemes Theme
        include_once $theme_dir . '/assemble/' . $dir . '.theme.php';
        $class = ucfirst($dir);
        if (!class_exists($class)) {
            redirectMsg('themes.php', __('Specified theme is not a valid xThemes theme!', 'xthemes'), RMMSG_WARN);
        }
        $theme = new $class();
        $theme->setVar('date', time());
        if (!$theme->on_install()) {
            RMUris::redirect_with_message(__('Theme could not be activated!', 'xthemes') . '<br>' . implode('<br>', $theme->errors()), 'themes.php', RMMSG_ERROR);
        }
        if (!$theme->save() && $theme->isNew()) {
            redirectMsg('themes.php', __('Sorry, theme could not be installed!', 'xthemes') . $theme->errors(), RMMSG_ERROR);
        }
        // Notify to current theme
        $xtFunctions->notify_deactivation($current);
        // Configuration options
        if (!$xtFunctions->insertOptions($theme)) {
            redirectMsg('themes.php', __('Sorry, theme could not be installed!', 'xthemes') . $theme->errors(), RMMSG_ERROR);
        }
        // Create blocks positions
        if (!$xtFunctions->insertPositions($theme)) {
            showMessage(__('The blocks positions could not be installed.', 'xthemes'), 'themes.php', RMMSG_WARN);
        }
    }
    $sql = "UPDATE " . $db->prefix("config") . " SET conf_value='{$dir}' WHERE conf_modid=0 AND conf_catid=1 AND conf_name='theme_set'";
    if (!$db->queryF($sql)) {
        redirectMsg('themes.php', __('Theme could not be activated', 'xthemes') . $db->getError(), RMMSG_ERROR);
    }
    $sql = "UPDATE " . $db->prefix("config") . " SET conf_value='" . serialize(array($dir)) . "' WHERE conf_modid=0 AND conf_catid=1 AND conf_name='theme_set_allowed'";
    $db->queryF($sql);
    redirectMsg('themes.php', __('Theme installed and activated successfully!', 'xthemes'), RMMSG_SUCCESS);
}
예제 #14
0
/**
 * @deprecated
 * @param string $url Pgina en la que se mostrar el error
 * @param string $msg Mensaje de Error
 * @param int $level Indicates the level of the message (error, info, warn, etc.) You can use the constants RMMSG_INFO, RMMSG_WARN... or you can specify your own level number
 * @param string $icon URL for an icon to show in message. This value is used by templates.
 */
function redirectMsg($url, $msg = '', $level = 5, $icon = '')
{
    RMUris::redirect_with_message($msg, $url, $level, $icon);
}
예제 #15
0
파일: post.php 프로젝트: petitours/bxpress
     $event = $events->event('newtopic')->parameters($forum->id())->permissions(array('users' => $forum->moderators(), 'groups' => array(XOOPS_GROUP_ADMIN)));
     // Notificar cuando se crea un tema
     if ($create) {
         $notifications->notify($event, array('forum' => $forum, 'topic' => $topic, 'post' => $post));
     }
     // Notificar cuando se envía un mensaje en el foro
     $event = $events->event('forum-newpost')->parameters($forum->id())->permissions(array('users' => $forum->moderators(), 'groups' => array(XOOPS_GROUP_ADMIN)));
     if (!$create) {
         $notifications->notify($event, array('forum' => $forum, 'topic' => $topic, 'post' => $post));
     }
     // Notificar cuando una respuesta es enviada en un tema
     $permissions = $forum->permissions();
     $event = $events->event('reply')->parameters($topic->id())->permissions(array('groups' => in_array(0, $permissions['view']) ? array() : $permissions['view']));
     $notifications->notify($event, array('forum' => $forum, 'topic' => $topic, 'post' => $post));
     // Redirect to topic
     RMUris::redirect_with_message($errors == '' ? __('Your posts has been sent!', 'bxpress') : __('Message posted, however some errors ocurred while sending!', 'bxpress'), 'topic.php?pid=' . $post->id() . '#p' . $post->id(), $errors == '' ? RMMSG_SUCCESS : RMMSG_ERROR);
     break;
 default:
     $xoopsOption['template_main'] = "bxpress-postform.tpl";
     $xoopsOption['module_subpage'] = "post";
     include 'header.php';
     bXFunctions::makeHeader();
     $form = new RMForm($tid > 0 ? __('Reply', 'bxpress') : __('Create New Topic', 'bxpress'), 'frmTopic', 'post.php');
     $form->addElement(new RMFormSubTitle(__('Write your post and send it', 'bxpress'), 1, 'even'));
     if (!$xoopsUser) {
         $form->addElement(new RMFormText(__('Your name:', 'bxpress'), 'name', 50, 255), true);
         $form->addElement(new RMFormText(__('Your email:', 'bxpress'), 'email', 50, 255), true, 'email');
     }
     if ($create) {
         $form->addElement(new RMFormText(__('Topic subject:', 'bxpress'), 'subject', 50, 255, $tid > 0 ? $topic->title() : ''), true);
     }
예제 #16
0
/**
 * Save module settings
 */
function save_module_settings()
{
    global $xoopsSecurity, $xoopsDB;
    $mod = RMHttpRequest::post('mod', 'string', '');
    $via_ajax = RMHttpRequest::post('via_ajax', 'integer', 0);
    if ($via_ajax) {
        $ajax = new AjaxResponse();
        $ajax->prepare_ajax_response();
    }
    if ($mod == '') {
        RMUris::redirect_with_message(__('A module has not been specified!', 'rmcommon'), 'settings.php', RMMSG_ERROR);
    }
    //echo RMHttpRequest::request('CUTOKEN_REQUEST', 'string', '') . ' ' . print_r($_SESSION['CUTOKEN_SESSION'], true); die();
    if (!$xoopsSecurity->check(true, false, $via_ajax ? 'CUTOKEN' : 'XOOPS_TOKEN')) {
        if ($via_ajax) {
            $ajax->ajax_response(__('Session token expired. Please try again.', 'rmcommon'), 1, 0);
        } else {
            RMUris::redirect_with_message(__('Session token expired. Please try again.', 'rmcommon'), 'settings.php', RMMSG_WARN);
        }
    }
    $module = RMModules::load_module($mod);
    if (!$module) {
        if ($via_ajax) {
            $ajax->ajax_response(__('The specified module does not exists.', 'rmcommon'), 1, 1);
        } else {
            RMUris::redirect_with_message(__('The specified module does not exists.', 'rmcommon'), 'settings.php', RMMSG_ERROR);
        }
    }
    $current_settings = (array) RMSettings::module_settings($module->getVar('dirname'));
    $new_settings = RMHttpRequest::post(ucfirst($module->getVar('dirname')), 'array', array());
    $configs = $module->getInfo('config');
    $fields = array();
    // Container for all fields and values
    foreach ($configs as $option) {
        $id = $option['name'];
        $field = new stdClass();
        $field->id = $id;
        $field->value = isset($values->{$id}) ? $values->{$id} : $option['default'];
        $field->caption = defined($option['title']) ? constant($option['title']) : $option['title'];
        $field->description = defined($option['description']) ? constant($option['description']) : $option['description'];
        $field->field = $option['formtype'];
        $field->type = $option['valuetype'];
        $field->options = isset($option['options']) ? $option['options'] : null;
        $category = isset($option['category']) ? $option['category'] : 'all';
        $fields[$id] = $field;
    }
    /**
     * This keys already exists in database
     */
    $to_save = array_intersect_key($new_settings, $current_settings);
    /**
     * This settings will be added to database beacause don't exists in table
     */
    $to_add = array_diff_key($new_settings, $current_settings);
    /**
     * This keys has been removed from xoops_version.php file and then
     * must be removed from table
     */
    $to_delete = array_diff_key($current_settings, $new_settings);
    $errors = '';
    // Errors ocurred while saving
    /**
     * First for all, remove unused items
     */
    $keys = array_keys($to_delete);
    if (!empty($keys)) {
        $sql = "DELETE FROM " . $xoopsDB->prefix("config") . " WHERE conf_modid = " . $module->mid() . " AND (conf_name = '" . implode("' OR conf_name='", $keys) . "')";
        if (!$xoopsDB->queryF($sql)) {
            $errors .= $xoopsDB->error() . '<br>';
        }
    }
    /**
     * Save existing items
     */
    if (!empty($to_save)) {
        foreach ($to_save as $name => $value) {
            $item = new Rmcommon_Config_Item($name, $module->mid());
            if (isset($fields[$name])) {
                $item->setVar('conf_valuetype', $fields[$name]->type);
                $item->setVar('conf_title', $fields[$name]->caption);
                $item->setVar('conf_desc', $fields[$name]->description);
                $item->setVar('conf_formtype', $fields[$name]->field);
            }
            $item->set_value($value, $item->getVar('conf_valuetype'));
            $item->save();
        }
    }
    /**
     * Add new items
     */
    if (!empty($to_add)) {
        foreach ($to_add as $name => $value) {
            $item = new Rmcommon_Config_Item($name, $module->mid());
            if (isset($fields[$name])) {
                $item->setVar('conf_modid', $module->mid());
                $item->setVar('conf_name', $name);
                $item->setVar('conf_valuetype', $fields[$name]->type);
                $item->setVar('conf_title', $fields[$name]->caption);
                $item->setVar('conf_desc', $fields[$name]->description);
                $item->setVar('conf_formtype', $fields[$name]->field);
            }
            $item->set_value($value, $item->getVar('conf_valuetype'));
            $item->save();
        }
    }
    /**
     * Notify to system events
     */
    RMEvents::get()->trigger('rmcommon.saved.settings', $module->dirname(), $to_save, $to_add, $to_delete);
    if ($module->getInfo('hasAdmin')) {
        $goto = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/' . $module->getInfo('adminindex');
    } else {
        $goto = 'settings.php';
    }
    if ($via_ajax) {
        $ajax->ajax_response(__('Settings saved successfully!', 'rmcommon'), 0, 1, array('closeWindow' => '#cu-settings-form', 'notify' => array('icon' => 'svg-rmcommon-ok-circle', 'type' => 'alert-success')));
    } else {
        RMUris::redirect_with_message(__('Settings saved successfully!', 'rmcommon'), $goto, RMMSG_SUCCESS, 'fa fa-check');
    }
}