Example #1
0
/**
 * Delete a set of selected widgets
 */
function delete_block()
{
    global $xoopsSecurity;
    if (!$xoopsSecurity->check()) {
        response(__('Session token expired!', 'rmcommon'), array(), 1, 0);
    }
    $block_id = rmc_server_var($_POST, 'id', 0);
    if ($block_id <= 0) {
        response(__('No block has been specified!', 'rmcommon'), array(), 1, 1);
    }
    $block = new RMInternalBlock($block_id);
    if ($block->isNew()) {
        response(__('Specified block does not exists!', 'rmcommon'), array(), 1, 1);
    }
    if (!$block->delete()) {
        response(sprintf(__('The block "%s" could not be deleted!', 'rmcommon'), $block->getVar('name')), array('error' => $block->errors()), 1, 1);
    } else {
        response(sprintf(__('The block "%s" was deleted successfully!', 'rmcommon'), $block->getVar('name')), array(), 0, 1);
    }
}
Example #2
0
 public function get_blocks($groupid, $mid = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight,b.wid', $isactive = 1, $subpage = '', $canvas = array())
 {
     $orderby = $orderby == '' ? 'b.weight,b.bid' : $orderby;
     // Get authorized blocks
     $db =& XoopsDatabaseFactory::getDatabaseConnection();
     $ret = array();
     $sql = "SELECT DISTINCT\n                    gperm_itemid\n                FROM\n                    " . $db->prefix('group_permission') . "\n                WHERE\n                    (gperm_name = 'rmblock_read')\n                AND\n                    gperm_modid = 1";
     if (is_array($groupid)) {
         $sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ',0)';
     } else {
         if (intval($groupid) > 0) {
             $sql .= ' AND gperm_groupid IN (0,' . $groupid . ')';
         }
     }
     $result = $db->query($sql);
     $blockids = array();
     while ($myrow = $db->fetchArray($result)) {
         $blockids[] = $myrow['gperm_itemid'];
     }
     if (!empty($blockids)) {
         $sql = 'SELECT b.* FROM ' . $db->prefix('mod_rmcommon_blocks') . ' b, ' . $db->prefix('mod_rmcommon_blocks_assignations') . ' m WHERE m.bid=b.bid';
         $sql .= ' AND b.isactive=' . $isactive;
         if (isset($visible)) {
             $sql .= ' AND b.visible=' . intval($visible);
         }
         $mid = intval($mid);
         if (!empty($mid)) {
             $sql .= ' AND m.mid IN (0,' . $mid;
             if ($toponlyblock) {
                 $sql .= ',1';
             }
             $sql .= ')';
         } else {
             /*   if ($toponlyblock) {*/
             $sql .= ' AND m.mid IN (0,1)';
             /*} else {
                   $sql .= ' AND m.app_id=0';
               }*/
         }
         $sql .= $subpage != '' ? " AND (m.page='{$subpage}' OR m.page='--')" : '';
         $sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')';
         if (is_array($canvas)) {
             $sql .= ' AND canvas IN (' . implode(',', $canvas) . ')';
         }
         $sql .= ' ORDER BY ' . $orderby;
         $result = $db->query($sql);
         while ($myrow = $db->fetchArray($result)) {
             $block = new RMInternalBlock();
             $block->assignVars($myrow);
             $ret[$myrow['bid']] = $block;
             unset($block);
         }
     }
     return $ret;
 }
 function getAllByGroupModule($groupid, $app_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight,b.bid', $isactive = 1, $subpage = '')
 {
     $orderby = $orderby == '' ? 'b.weight,b.bid' : $orderby;
     $db =& XoopsDatabaseFactory::getDatabaseConnection();
     $ret = array();
     $sql = "SELECT DISTINCT gperm_itemid FROM " . $db->prefix('group_permission') . " WHERE gperm_name = 'rmblock_read' AND gperm_modid = 1";
     if (is_array($groupid)) {
         $sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ',0)';
     } else {
         if (intval($groupid) > 0) {
             $sql .= ' AND gperm_groupid IN (0,' . $groupid . ')';
         }
     }
     $result = $db->query($sql);
     $blockids = array();
     while ($myrow = $db->fetchArray($result)) {
         $blockids[] = $myrow['gperm_itemid'];
     }
     if (!empty($blockids)) {
         $sql = 'SELECT b.* FROM ' . $db->prefix('rmc_blocks') . ' b, ' . $db->prefix('rmc_bkmod') . ' m WHERE m.bid=b.bid';
         $sql .= ' AND b.isactive=' . $isactive;
         if (isset($visible)) {
             $sql .= ' AND b.visible=' . intval($visible);
         }
         $app_id = intval($app_id);
         if (!empty($app_id)) {
             $sql .= ' AND m.app_id IN (0,' . $app_id;
             if ($toponlyblock) {
                 $sql .= ',1';
             }
             $sql .= ')';
         } else {
             /*   if ($toponlyblock) {*/
             $sql .= ' AND m.app_id IN (0,1)';
             /*} else {
                   $sql .= ' AND m.app_id=0';
               }*/
         }
         $sql .= $subpage != '' ? " AND (m.subpage='{$subpage}' OR m.subpage='--')" : '';
         $sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')';
         $sql .= ' ORDER BY ' . $orderby;
         $result = $db->query($sql);
         //echo $sql; die();
         while ($myrow = $db->fetchArray($result)) {
             $block = new RMInternalBlock();
             $block->assignVars($myrow);
             $ret[$myrow['bid']] =& $block;
             unset($block);
         }
     }
     return $ret;
 }
Example #4
0
function save_block_config()
{
    global $xoopsSecurity;
    foreach ($_POST as $k => $v) {
        ${$k} = $v;
    }
    if (!$xoopsSecurity->check($XOOPS_TOKEN_REQUEST)) {
        response(array('message' => __('Session token expired. Please try again.', 'rmcommon')), 1, 0);
        die;
    }
    if ($bid <= 0) {
        response(array('message' => __('You must provide a block ID!', 'rmcommon')), 1, 1);
        die;
    }
    $block = new RMInternalBlock($bid);
    if ($block->isNew()) {
        response(array('message' => __('Specified block does not exists!', 'rmcommon')), 1, 1);
        die;
    }
    if (isset($options)) {
        $block->setVar('options', serialize($options));
    }
    $block->setVar('name', $bk_name);
    $block->setVar('canvas', $bk_pos);
    $block->setVar('weight', $bk_weight);
    $block->setVar('visible', $bk_visible);
    $block->setVar('bcachetime', $bk_cache);
    if (isset($bk_content)) {
        $block->setVar('content', $bk_content);
        $block->setVar('content_type', $bk_ctype);
    }
    // Set modules
    $block->sections($bk_mod);
    // Set Groups
    $block->setReadGroups($bk_groups);
    if ($block->save()) {
        response(array('message' => __('Block updated successfully!', 'rmcommon')), 0, 1);
    }
    die;
}