Пример #1
0
/**
* Save the current positions
*/
function save_position($edit = 0)
{
    global $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        redirectMsg('blocks.php', __('You are not allowed to do this action!', 'rmcommon'), 1);
        die;
    }
    $name = rmc_server_var($_POST, 'posname', '');
    $tag = rmc_server_var($_POST, 'postag', '');
    if ($name == '') {
        redirectMsg('blocks.php', __('Please provide a name and tag for this new position!', 'rmcommon'), RMMSG_ERROR);
        die;
    }
    if ($tag == '') {
        $tag = str_replace("-", "_", TextCleaner::getInstance()->sweetstring($name));
    }
    if ($edit) {
        $id = rmc_server_var($_POST, 'id', '');
        if ($id <= 0) {
            redirectMsg('blocks.php', __('You must specify a valid position ID!', 'rmcommon'), 1);
        }
        $pos = new RMBlockPosition($id);
        if ($pos->isNew()) {
            redirectMsg('blocks.php', __('Specified position does not exists!', 'rmcommon'), 1);
        }
    } else {
        $pos = new RMBlockPosition();
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $pos->setVar('name', $name);
    $pos->setVar('tag', $tag);
    $pos->setVar('active', 1);
    $sql = "SELECT COUNT(*) FROM " . $db->prefix("mod_rmcommon_blocks_positions") . " WHERE name='{$name}' OR tag='{$tag}'";
    if ($edit) {
        $sql .= " AND id_position<>{$id}";
    }
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        redirectMsg('blocks.php', __('Already exists another position with same name or same tag!', 'rmcommon'), 1);
    }
    if ($pos->save()) {
        redirectMsg('blocks.php?from=positions', __('Database updated successfully!', 'rmcommon'));
    } else {
        redirectMsg('blocks.php', __('Errors ocurred while trying to save data', 'rmcommon') . '<br />' . $pos->errors());
    }
}
Пример #2
0
function save_block_position()
{
    global $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        response(__('Session token expired. Please try again.', 'rmcommon'), array(), 1, 0);
    }
    $id = rmc_server_var($_POST, 'id', 0);
    $name = rmc_server_var($_POST, 'name', '');
    $tag = rmc_server_var($_POST, 'tag', '');
    $active = rmc_server_var($_POST, 'active', 1);
    if ($id <= 0) {
        response(__('Specified position is not valid!', 'rmcommon'), array(), 1, 1);
    }
    if ($name == '' || $tag == '') {
        response(__('You must fill name and tag input fields!', 'rmcommon'), array(), 1, 1);
    }
    $pos = new RMBlockPosition($id);
    if ($pos->isNew()) {
        response(__('Specified blocks position does not exists!', 'rmcommon'), array(), 1, 1);
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $sql = "SELECT COUNT(*) FROM " . $db->prefix("mod_rmcommon_blocks_positions") . " WHERE (name='{$name}' OR tag='{$tag}') AND id_position<>{$id}";
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        response(__('Already exists another blocks position with same name or tag!', 'rmcommon'), array(), 1, 1);
    }
    $pos->setVar('name', $name);
    $pos->setVar('tag', $tag);
    $pos->setVar('active', $active);
    if ($pos->save()) {
        response(sprintf(__('Position "%s" was saved successfylly!', 'rmcommon'), $pos->getVar('name')), array(), 0, 1);
    } else {
        response(sprintf(__('Position "%s" could not be saved!', 'rmcommon'), $pos->getVar('name')), array('error' => $pos->errors()), 1, 1);
    }
}