Example #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());
    }
}
Example #2
0
/**
* Save blocks orders
*/
function save_block_order()
{
    global $xoopsSecurity;
    $blocks = rmc_server_var($_POST, 'blocks', '');
    $pos_id = rmc_server_var($_POST, 'position', '');
    if (!$xoopsSecurity->check(false, false)) {
        response(__('Blocks order could not be saved!', 'rmcommon'), array('error' => __('Session token expired!', 'rmcommon')), 1, 0);
    }
    if ($pos_id <= 0) {
        response(__('Position not specified!', 'rmcommon'), array('error' => ''), 1, 0);
    }
    $blocks = json_decode($blocks, true);
    if (empty($blocks)) {
        response('', array('position' => $pos_id), 0, 0);
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $ids = array();
    $sql = "UPDATE " . $db->prefix("mod_rmcommon_blocks") . " SET canvas = {$pos_id}, weight = CASE bid\n";
    foreach ($blocks as $i => $block) {
        $sql .= "WHEN {$block['id']} THEN {$i}\n";
        $ids[] = $block['id'];
    }
    $sql .= "END\n WHERE bid IN (" . implode(",", $ids) . ");";
    $pos = new RMBlockPosition($pos_id);
    if ($db->queryF($sql)) {
        response(sprintf(__('Blocks order for position "%s" saved successfully!', 'rmcommon'), $pos->getVar('name')), array('position' => $pos_id), 0, 0);
    } else {
        response(sprintf(__('Blocks order for position "%s" could not be saved!', 'rmcommon'), $pos->getVar('name')), array('position' => $pos_id, 'error' => $db->error()), 1, 0);
    }
}
Example #3
0
 public function notify_deactivation($dir)
 {
     $theme = self::load_theme($dir);
     if (!is_a($theme, 'StandardTheme')) {
         $theme->status('inactive');
         // Disable blocks positions assigned to this theme
         $positions = $theme->blocks_positions();
         foreach ($positions as $tag => $name) {
             $pos = new RMBlockPosition($tag);
             if (!$pos->isNew()) {
                 $pos->setVar('active', 0);
                 $pos->save();
             }
         }
     }
 }
Example #4
0
function xt_activate_theme()
{
    global $xtAssembler;
    $dir = RMHttpRequest::get('dir', 'string', '');
    if ($dir == '') {
        RMUris::redirect_with_message(__('No theme has been specified!', 'xthemes'), 'themes.php', RMMSG_ERROR);
    }
    $theme_dir = XOOPS_THEME_PATH . '/' . $dir;
    if (!is_file($theme_dir . '/theme.html')) {
        RMUris::redirect_with_message(__('Specified directory does not contain a valid theme!', 'xthemes'), 'themes.php', RMMSG_WARN);
    }
    /**
     * Notify to current theme that will be disabled
     */
    $theme = $xtAssembler->theme();
    if ($xtAssembler->isSupported() && $theme_dir != $theme->getInfo('dir')) {
        $theme->status('inactive');
        // Disable blocks positions assigned to this theme
        $positions = $theme->blocks_positions();
        foreach ($positions as $tag => $name) {
            $pos = new RMBlockPosition($tag);
            if (!$pos->isNew()) {
                $pos->setVar('active', 0);
                $pos->save();
            }
        }
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $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)) {
        RMUris::redirect_with_message(__('Theme could not be activated', 'xthemes') . $db->getError(), 'themes.php', 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);
    /**
     * Notify to new theme that was activated
     */
    $xtAssembler->loadTheme($dir);
    $theme = $xtAssembler->theme();
    if ($xtAssembler->isSupported() && $dir == $theme->getInfo('dir')) {
        $theme->status('active');
        // Disable blocks positions assigned to this theme
        $positions = $theme->blocks_positions();
        foreach ($positions as $tag => $name) {
            $pos = new RMBlockPosition($tag);
            if (!$pos->isNew()) {
                $pos->setVar('active', 1);
                $pos->save();
            }
        }
    }
    RMUris::redirect_with_message(__('Theme activated successfully!', 'xthemes'), 'themes.php', RMMSG_SUCCESS);
}
Example #5
0
function save_block_position()
{
    global $xoopsSecurity;
    if (!$xoopsSecurity->check($XOOPS_TOKEN_REQUEST)) {
        response(array('message' => __('Session token expired. Please try again.', 'rmcommon')), 1, 0);
        die;
    }
    $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(array('message' => __('Specified position is not valid!', 'rmcommon')), 1, 1);
        die;
    }
    if ($name == '' || $tag == '') {
        response(array('message' => __('You must fill name and tag input fields!', 'rmcommon')), 1, 1);
        die;
    }
    $pos = new RMBlockPosition($id);
    if ($pos->isNew()) {
        response(array('message' => __('Specified block position does not exists!', 'rmcommon')), 1, 1);
        die;
    }
    $db = XoopsDatabaseFactory::getDatabaseConnection();
    $sql = "SELECT COUNT(*) FROM " . $db->prefix("rmc_blocks_positions") . " WHERE (name='{$name}' OR tag='{$tag}') AND id_position<>{$id}";
    list($num) = $db->fetchRow($db->query($sql));
    if ($num > 0) {
        response(array('message' => __('Already exists another block position with same name or tag!', 'rmcommon')), 1, 1);
        die;
    }
    $pos->setVar('name', $name);
    $pos->setVar('tag', $tag);
    $pos->setVar('active', $active);
    if ($pos->save()) {
        response(array('message' => __('Changes saved successfully!', 'rmcommon')), 0, 1);
        die;
    } else {
        response(array('message' => __('Changes could not be saved!', 'rmcommon')), 1, 1);
        die;
    }
}