function save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime, $bgroups) { global $xoopsUser; if (empty($bmodule)) { xoops_cp_header(); xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); xoops_cp_footer(); exit; } $myblock = new XoopsBlock(); $myblock->setVar('side', $bside); $myblock->setVar('weight', $bweight); $myblock->setVar('visible', $bvisible); $myblock->setVar('weight', $bweight); $myblock->setVar('title', $btitle); $myblock->setVar('content', $bcontent); $myblock->setVar('c_type', $bctype); $myblock->setVar('block_type', 'C'); $myblock->setVar('bcachetime', $bcachetime); switch ($bctype) { case 'H': $name = _AM_CUSTOMHTML; break; case 'P': $name = _AM_CUSTOMPHP; break; case 'S': $name = _AM_CUSTOMSMILE; break; default: $name = _AM_CUSTOMNOSMILE; break; } $myblock->setVar('name', $name); $newid = $myblock->store(); if (!$newid) { xoops_cp_header(); $myblock->getHtmlErrors(); xoops_cp_footer(); exit; } $db =& Database::getInstance(); foreach ($bmodule as $bmid) { $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . intval($bmid) . ')'; $db->query($sql); } $groupperm_handler =& xoops_gethandler('groupperm'); $groups_with_access =& $groupperm_handler->getGroupIds("block_read", $newid); $removed_groups = array_diff($groups_with_access, $bgroups); if (count($removed_groups) > 0) { foreach ($removed_groups as $groupid) { $criteria = new CriteriaCompo(new Criteria('gperm_name', 'block_read')); $criteria->add(new Criteria('gperm_groupid', $groupid)); $criteria->add(new Criteria('gperm_itemid', $newid)); $criteria->add(new Criteria('gperm_modid', 1)); $perm = $groupperm_handler->getObjects($criteria); if (isset($perm[0]) && is_object($perm[0])) { $groupperm_handler->delete($perm[0]); } } } $new_groups = array_diff($bgroups, $groups_with_access); if (count($new_groups) > 0) { foreach ($new_groups as $groupid) { $groupperm_handler->addRight("block_read", $newid, $groupid); } } redirect_header('admin.php?fct=blocksadmin&selgen=0&t=' . time(), 1, _AM_DBUPDATED); exit; }
function save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime) { global $xoopsUser; if (empty($bmodule)) { xoops_cp_header(); xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); xoops_cp_footer(); exit; } $myblock = new XoopsBlock(); $myblock->setVar('side', $bside); $myblock->setVar('weight', $bweight); $myblock->setVar('visible', $bvisible); $myblock->setVar('weight', $bweight); $myblock->setVar('title', $btitle); $myblock->setVar('content', $bcontent); $myblock->setVar('c_type', $bctype); $myblock->setVar('block_type', 'C'); $myblock->setVar('bcachetime', $bcachetime); switch ($bctype) { case 'H': $name = _AM_CUSTOMHTML; break; case 'P': $name = _AM_CUSTOMPHP; break; case 'S': $name = _AM_CUSTOMSMILE; break; default: $name = _AM_CUSTOMNOSMILE; break; } $myblock->setVar('name', $name); $newid = $myblock->store(); if (!$newid) { xoops_cp_header(); $myblock->getHtmlErrors(); xoops_cp_footer(); exit; } $db =& Database::getInstance(); foreach ($bmodule as $bmid) { $sql = 'INSERT INTO ' . $db->prefix('block_module_link') . ' (block_id, module_id) VALUES (' . $newid . ', ' . intval($bmid) . ')'; $db->query($sql); } $groups =& $xoopsUser->getGroups(); $count = count($groups); for ($i = 0; $i < $count; $i++) { $sql = "INSERT INTO " . $db->prefix('group_permission') . " (gperm_groupid, gperm_itemid, gperm_name, gperm_modid) VALUES (" . $groups[$i] . ", " . $newid . ", 'block_read', 1)"; $db->query($sql); } redirect_header('admin.php?fct=blocksadmin&t=' . time(), 1, _AM_DBUPDATED); exit; }
$cblock->setVar('visible', $_POST['bvisible']); $cblock->setVar('title', $_POST['btitle']); $cblock->setVar('content', @$_POST['bcontent']); $cblock->setVar('c_type', @$_POST['bctype']); $cblock->setVar('bcachetime', $_POST['bcachetime']); if (isset($options) && count($options) > 0) { $options = implode('|', $options); $cblock->setVar('options', $options); } $cblock->setVar('bid', 0); $cblock->setVar('block_type', $block_type == 'C' ? 'C' : 'D'); $cblock->setVar('func_num', 255); $newid = $cblock->store(); if (!$newid) { xoops_cp_header(); $cblock->getHtmlErrors(); xoops_cp_footer(); exit; } /* if ($cblock->getVar('template') != '') { $tplfile_handler =& xoops_gethandler('tplfile'); $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); if (count($btemplate) > 0) { $tplclone =& $btemplate[0]->clone(); $tplclone->setVar('tpl_id', 0); $tplclone->setVar('tpl_refid', $newid); $tplman->insert($tplclone); } } */ $db =& Database::getInstance(); $bmodule = isset($_POST['bmodule']) && is_array($_POST['bmodule']) ? $_POST['bmodule'] : array(-1);
function do_clone($bid) { $bid = intval($bid); $request = $this->fetchRequest4Block($bid); $block = new XoopsBlock($bid); if (!$block->getVar('bid')) { die('Invalid bid'); } if (!$this->canClone($block)) { die('Invalid block_type'); } if (empty($_POST['options'])) { $options = array(); } else { if (is_array($_POST['options'])) { $options = $_POST['options']; } else { $options = explode('|', $_POST['options']); } } // for backward compatibility // $cblock =& $block->clone(); or $cblock =& $block->xoopsClone(); $cblock = new XoopsBlock(); foreach ($block->vars as $k => $v) { $cblock->assignVar($k, $v['value']); } $cblock->setNew(); $cblock->setVar('bid', 0); $cblock->setVar('block_type', $block->getVar('block_type') == 'C' ? 'C' : 'D'); $cblock->setVar('func_num', $this->find_func_num_vacancy($block->getVar('mid'))); // store the block into DB as a new one $newbid = $cblock->store(); if (!$newbid) { return $cblock->getHtmlErrors(); } // update the block by the request $this->update_block($newbid, $request['side'], $request['weight'], $request['visible'], $request['title'], $request['content'], $request['ctype'], $request['bcachetime'], is_array(@$_POST['options']) ? $_POST['options'] : array()); // block_module_link update $this->updateBlockModuleLink($newbid, $request['bmodule']); // group_permission update $this->updateBlockReadGroupPerm($newbid, $request['bgroup']); return _MD_A_MYBLOCKSADMIN_DBUPDATED; }