source: temp/test-xoops.ec-cube.net/html/modules/system/admin/blocksadmin/blocksadmin.php @ 405

Revision 405, 17.4 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: blocksadmin.php,v 1.4 2005/08/03 12:39:16 onokazu Exp $
3//  ------------------------------------------------------------------------ //
4//                XOOPS - PHP Content Management System                      //
5//                    Copyright (c) 2000 XOOPS.org                           //
6//                       <http://www.xoops.org/>                             //
7//  ------------------------------------------------------------------------ //
8//  This program is free software; you can redistribute it and/or modify     //
9//  it under the terms of the GNU General Public License as published by     //
10//  the Free Software Foundation; either version 2 of the License, or        //
11//  (at your option) any later version.                                      //
12//                                                                           //
13//  You may not change or alter any portion of this comment or credits       //
14//  of supporting developers from this source code or any supporting         //
15//  source code which is considered copyrighted (c) material of the          //
16//  original comment or credit authors.                                      //
17//                                                                           //
18//  This program is distributed in the hope that it will be useful,          //
19//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
20//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
21//  GNU General Public License for more details.                             //
22//                                                                           //
23//  You should have received a copy of the GNU General Public License        //
24//  along with this program; if not, write to the Free Software              //
25//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
26//  ------------------------------------------------------------------------ //
27// Author: Kazumi Ono (AKA onokazu)                                          //
28// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
29// Project: The XOOPS Project                                                //
30// ------------------------------------------------------------------------- //
31
32if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
33    exit("Access Denied");
34}
35// check if the user is authorised
36if ( $xoopsUser->isAdmin($xoopsModule->mid()) ) {
37    include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
38
39    function list_blocks()
40    {
41        global $xoopsUser, $xoopsConfig;
42        include_once XOOPS_ROOT_PATH.'/class/xoopslists.php';
43        //OpenTable();
44        $selmod = isset($_GET['selmod']) ? intval($_GET['selmod']) : 0;
45        $selvis = isset($_GET['selvis']) ? intval($_GET['selvis']) : 2;
46        $selgrp = isset($_GET['selgrp']) ? intval($_GET['selgrp']) : XOOPS_GROUP_USERS;
47        echo "
48        <h4 style='text-align:left;'>"._AM_BADMIN."</h4>";
49        echo '<form action="admin.php" method="get">';
50        $form = "<select size=\"1\" name=\"selmod\" onchange=\"location='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;selvis=$selvis&amp;selgrp=$selgrp&amp;selmod='+this.options[this.selectedIndex].value\">";
51        $module_handler =& xoops_gethandler('module');
52        $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
53        $criteria->add(new Criteria('isactive', 1));
54        $module_list =& $module_handler->getList($criteria);
55        $toponlyblock = false;
56        $module_list[-1] = _AM_TOPPAGE;
57        $selmod = isset($_GET['selmod']) ? intval($_GET['selmod']) : -1;
58        ksort($module_list);
59        foreach ($module_list as $k => $v) {
60            $sel = '';
61            if ($k == $selmod) {
62                $sel = ' selected="selected"';
63            }
64            $form .= '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
65        }
66        $form .= '</select>&nbsp;<input type="hidden" name="fct" value="blocksadmin" />';
67        printf(_AM_SVISIBLEIN, $form);
68        $member_handler =& xoops_gethandler('member');
69        $group_list =& $member_handler->getGroupList();
70        $group_sel = _AM_GROUP." <select size=\"1\" name=\"selgrp\" onchange=\"location='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;selvis=$selvis&amp;selmod=$selmod&amp;selgrp='+this.options[this.selectedIndex].value\">";
71        $group_list[0] = '#'._AM_UNASSIGNED; // fix for displaying blocks unassigned to any group
72        foreach ($group_list as $k => $v) {
73            $sel = '';
74            if ($k == $selgrp) {
75                $sel = ' selected="selected"';
76            }
77            $group_sel .= '<option value="'.$k.'"'.$sel.'>'.$v.'</option>';
78        }
79        $group_sel .= '</select> ';
80        echo $group_sel;
81        echo _AM_VISIBLE." <select size=\"1\" name=\"selvis\" onchange=\"location='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;selmod=$selmod&amp;selgrp=$selgrp&amp;selvis='+this.options[this.selectedIndex].value\">";
82        $selvis0 = $selvis1 = $selvis2 = "";
83        switch($selvis){
84        case 0:
85            $selvis0 = 'selected="selected"';
86            break;
87        case 1:
88            $selvis1 = 'selected="selected"';
89            break;
90        case 2:
91        default:
92            $selvis2 = 'selected="selected"';
93            break;
94        }
95        echo '<option value="0" '.$selvis0.'>'._NO.'</option>';
96        echo '<option value="1" '.$selvis1.'>'._YES.'</option>';
97        echo '<option value="2" '.$selvis2.'>'._ALL.'</option>';
98        echo '</select> <input type="submit" value="'._GO.'" name="selsubmit" />';
99        echo '</form>';
100        echo "<form action='admin.php' name='blockadmin' method='post'>
101        <table width='100%' class='outer' cellpadding='4' cellspacing='1'>
102        <tr valign='middle'><th width='20%'>"._AM_BLKDESC."</th><th>"._AM_TITLE."</th><th>"._AM_MODULE."</th><th align='center' nowrap='nowrap'>"._AM_SIDE."<br />"._LEFT."-"._CENTER."-"._RIGHT."</th><th align='center'>"._AM_WEIGHT."</th><th align='center'>"._AM_VISIBLE."</th><th align='right'>"._AM_ACTION."</th></tr>
103        ";
104        if ($selvis == 2) $selvis = null;
105        if ($selgrp == 0) {
106            // get blocks that are not assigned to any groups
107            $block_arr =& XoopsBlock::getNonGroupedBlocks($selmod, $toponlyblock, $selvis, 'b.side,b.weight,b.bid');
108        } else {
109            $block_arr =& XoopsBlock::getAllByGroupModule($selgrp, $selmod, $toponlyblock, $selvis, 'b.side,b.weight,b.bid');
110        }
111        $block_count = count($block_arr);
112        $class = 'even';
113        $module_list2 =& $module_handler->getList();
114        // for custom blocks
115        $module_list2[0] = '&nbsp;';
116        foreach (array_keys($block_arr) as $i) {
117            $sel0 = $sel1 = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = "";
118            if ( $block_arr[$i]->getVar("visible") == 1 ) {
119                $sel1 = " checked='checked'";
120            } else {
121                $sel0 = " checked='checked'";
122            }
123            if ( $block_arr[$i]->getVar("side") == XOOPS_SIDEBLOCK_LEFT){
124                $ssel0 = " checked='checked'";
125            } elseif ( $block_arr[$i]->getVar("side") == XOOPS_SIDEBLOCK_RIGHT ){
126                $ssel1 = " checked='checked'";
127            } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_LEFT ){
128                $ssel2 = " checked='checked'";
129            } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_RIGHT ){
130                $ssel4 = " checked='checked'";
131            } elseif ( $block_arr[$i]->getVar("side") == XOOPS_CENTERBLOCK_CENTER ){
132                $ssel3 = " checked='checked'";
133            }
134            if ( $block_arr[$i]->getVar("title") == "" ) {
135                $title = "&nbsp;";
136            } else {
137                $title = $block_arr[$i]->getVar("title");
138            }
139            $name = $block_arr[$i]->getVar("name");
140            echo "<tr valign='top'><td class='$class'>".$name."</td><td class='$class'>".$title."</td><td class='$class'>".$module_list2[$block_arr[$i]->getVar('mid')]."</td><td class='$class' align='center' nowrap='nowrap'><input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_LEFT."'$ssel0 />-<input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_LEFT."'$ssel2 /><input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_CENTER."'$ssel3 /><input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_RIGHT."'$ssel4 />-<input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_RIGHT."'$ssel1 /></td><td class='$class' align='center'><input type='text' name='weight[$i]' value='".$block_arr[$i]->getVar("weight")."' size='5' maxlength='5' /></td><td class='$class' align='center' nowrap='nowrap'><input type='radio' name='visible[$i]' value='1'$sel1 />"._YES."&nbsp;<input type='radio' name='visible[$i]' value='0'$sel0 />"._NO."</td><td class='$class' align='right'><a href='admin.php?fct=blocksadmin&amp;op=edit&amp;bid=".$block_arr[$i]->getVar("bid")."'>"._EDIT."</a>";
141            if ($block_arr[$i]->getVar('block_type') != 'S') {
142                echo "&nbsp;<a href='admin.php?fct=blocksadmin&amp;op=delete&amp;bid=".$block_arr[$i]->getVar("bid")."'>"._DELETE."</a>";
143            }
144            echo "
145            <input type='hidden' name='oldside[$i]' value='".$block_arr[$i]->getVar('side')."' />
146            <input type='hidden' name='oldweight[$i]' value='".$block_arr[$i]->getVar('weight')."' />
147            <input type='hidden' name='oldvisible[$i]' value='".$block_arr[$i]->getVar('visible')."' />
148            <input type='hidden' name='bid[$i]' value='".$i."' />
149            </td></tr>
150            ";
151            $class = ($class == 'even') ? 'odd' : 'even';
152        }
153        echo "<tr><td class='foot' align='center' colspan='7'>
154        <input type='hidden' name='fct' value='blocksadmin' />
155        <input type='hidden' name='op' value='order' />
156        <input type='submit' name='submit' value='"._SUBMIT."' />
157        </td></tr></table>
158        </form>
159        <br /><br />";
160
161        $block = array('form_title' => _AM_ADDBLOCK, 'side' => 0, 'weight' => 0, 'visible' => 1, 'title' => '', 'content' => '', 'modules' => array(-1), 'is_custom' => true, 'ctype' => 'H', 'cachetime' => 0, 'op' => 'save', 'edit_form' => false);
162        include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
163        $form->display();
164    }
165
166    function edit_block($bid)
167    {
168        $myblock = new XoopsBlock($bid);
169        $db =& Database::getInstance();
170        $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid);
171        $result = $db->query($sql);
172        $modules = array();
173        while ($row = $db->fetchArray($result)) {
174            $modules[] = intval($row['module_id']);
175        }
176        $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false;
177        $block = array('form_title' => _AM_EDITBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'title' => $myblock->getVar('title', 'E'), 'content' => $myblock->getVar('content', 'E'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'update', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'));
178        echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._AM_EDITBLOCK.'<br /><br />';
179        include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
180        $form->display();
181    }
182
183    function delete_block($bid)
184    {
185        $myblock = new XoopsBlock($bid);
186        if ( $myblock->getVar('block_type') == 'S' ) {
187            $message = _AM_SYSTEMCANT;
188            redirect_header('admin.php?fct=blocksadmin',4,$message);
189            exit();
190        } elseif ($myblock->getVar('block_type') == 'M') {
191            // Fix for duplicated blocks created in 2.0.9 module update
192            // A module block can be deleted if there is more than 1 that
193            // has the same func_num/show_func which is mostly likely
194            // be the one that was duplicated in 2.0.9
195            if (1 >= $count = XoopsBlock::countSimilarBlocks($myblock->getVar('mid'), $myblock->getVar('func_num'), $myblock->getVar('show_func'))) {
196                $message = _AM_MODULECANT;
197                redirect_header('admin.php?fct=blocksadmin',4,$message);
198                exit();
199            }
200        }
201        xoops_token_confirm(array('fct' => 'blocksadmin', 'op' => 'delete_ok', 'bid' => $myblock->getVar('bid')), 'admin.php', sprintf(_AM_RUSUREDEL,$myblock->getVar('title')));
202    }
203
204    function delete_block_ok($bid)
205    {
206        if(!xoops_confirm_validate())
207            die("Ticket Error");
208
209        $myblock = new XoopsBlock($bid);
210        $myblock->delete();
211        if ($myblock->getVar('template') != '') {
212            $tplfile_handler =& xoops_gethandler('tplfile');
213            $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
214            if (count($btemplate) > 0) {
215                $tplfile_handler->delete($btemplate[0]);
216            }
217        }
218        redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,_AM_DBUPDATED);
219        exit();
220    }
221
222    function order_block($bid, $weight, $visible, $side)
223    {
224        $myblock = new XoopsBlock($bid);
225        $myblock->setVar('weight', $weight);
226        $myblock->setVar('visible', $visible);
227        $myblock->setVar('side', $side);
228        $myblock->store();
229    }
230
231    function clone_block($bid)
232    {
233        global $xoopsConfig;
234        xoops_cp_header();
235        $myblock = new XoopsBlock($bid);
236        $db =& Database::getInstance();
237        $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid);
238        $result = $db->query($sql);
239        $modules = array();
240        while ($row = $db->fetchArray($result)) {
241            $modules[] = intval($row['module_id']);
242        }
243        $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false;
244        $block = array('form_title' => _AM_CLONEBLOCK, 'name' => $myblock->getVar('name'), 'side' => $myblock->getVar('side'), 'weight' => $myblock->getVar('weight'), 'visible' => $myblock->getVar('visible'), 'content' => $myblock->getVar('content', 'N'), 'modules' => $modules, 'is_custom' => $is_custom, 'ctype' => $myblock->getVar('c_type'), 'cachetime' => $myblock->getVar('bcachetime'), 'op' => 'clone_ok', 'bid' => $myblock->getVar('bid'), 'edit_form' => $myblock->getOptions(), 'template' => $myblock->getVar('template'), 'options' => $myblock->getVar('options'));
245        echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._AM_CLONEBLOCK.'<br /><br />';
246        include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
247        $form->display();
248        xoops_cp_footer();
249        exit();
250    }
251
252    function clone_block_ok($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options)
253    {
254        global $xoopsUser;
255        $block = new XoopsBlock($bid);
256        $clone =& $block->xoopsClone();
257        if (empty($bmodule)) {
258            xoops_cp_header();
259            xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
260            xoops_cp_footer();
261            exit();
262        }
263        $clone->setVar('side', $bside);
264        $clone->setVar('weight', $bweight);
265        $clone->setVar('visible', $bvisible);
266        $clone->setVar('content', $bcontent);
267        //$clone->setVar('title', $btitle);
268        $clone->setVar('bcachetime', $bcachetime);
269        if ( isset($options) && (count($options) > 0) ) {
270            $options = implode('|', $options);
271            $clone->setVar('options', $options);
272        }
273        $clone->setVar('bid', 0);
274        if ($block->getVar('block_type') == 'C' || $block->getVar('block_type') == 'E') {
275            $clone->setVar('block_type', 'E');
276        } else {
277            $clone->setVar('block_type', 'D');
278        }
279        $newid = $clone->store();
280        if (!$newid) {
281            xoops_cp_header();
282            $clone->getHtmlErrors();
283            xoops_cp_footer();
284            exit();
285        }
286        if ($clone->getVar('template') != '') {
287            $tplfile_handler =& xoops_gethandler('tplfile');
288            $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid);
289            if (count($btemplate) > 0) {
290                $tplclone =& $btemplate[0]->xoopsClone();
291                $tplclone->setVar('tpl_id', 0);
292                $tplclone->setVar('tpl_refid', $newid);
293                $tplman->insert($tplclone);
294            }
295        }
296        $db =& Database::getInstance();
297        foreach ($bmodule as $bmid) {
298            $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.$bmid.')';
299            $db->query($sql);
300        }
301        $groups =& $xoopsUser->getGroups();
302        $count = count($groups);
303        for ($i = 0; $i < $count; $i++) {
304            $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')";
305            $db->query($sql);
306        }
307        redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,_AM_DBUPDATED);
308    }
309} else {
310    echo "Access Denied";
311}
312?>
Note: See TracBrowser for help on using the repository browser.