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

Revision 405, 12.1 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: main.php,v 1.5 2006/05/01 02:37:29 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}
35include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
36
37$op = "list";
38
39if ( isset($_GET['op']) ) {
40    if ($_GET['op'] == "edit" || $_GET['op'] == "delete" || $_GET['op'] == "delete_ok" || $_GET['op'] == "clone") {
41        $op = $_GET['op'];
42        $bid = isset($_GET['bid']) ? intval($_GET['bid']) : 0;
43    }
44} elseif (!empty($_POST['op'])) {
45    $op = $_POST['op'];
46}
47
48if (isset($_POST['previewblock'])) {
49    if (!XoopsMultiTokenHandler::quickValidate('block')) {
50        redirect_header("admin.php?fct=blocksadmin");
51        exit();
52    }
53    xoops_cp_header();
54    include_once XOOPS_ROOT_PATH.'/class/template.php';
55    $xoopsTpl = new XoopsTpl();
56    $xoopsTpl->xoops_setCaching(0);
57    $bid = !empty($_POST['bid']) ? intval($_POST['bid']) : 0;
58    if (!empty($bid)) {
59        $block['bid'] = $bid;
60        $block['form_title'] = _AM_EDITBLOCK;
61        $myblock = new XoopsBlock($bid);
62        $block['name'] = $myblock->getVar('name');
63    } else {
64        if ($op == 'save') {
65            $block['form_title'] = _AM_ADDBLOCK;
66        } else {
67            $block['form_title'] = _AM_CLONEBLOCK;
68        }
69        $myblock = new XoopsBlock();
70        $myblock->setVar('block_type', 'C');
71    }
72    $myts =& MyTextSanitizer::getInstance();
73    $myblock->setVar('title', $myts->stripSlashesGPC($_POST['btitle']));
74    $myblock->setVar('content', $myts->stripSlashesGPC($_POST['bcontent']));
75    $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.htmlspecialchars($xoopsConfig['sitename']).'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'" /></head><body><table><tr><th>'.$myblock->getVar('title').'</th></tr><tr><td>'.$myblock->getContent('S', $_POST['bctype']).'</td></tr></table></body></html>';
76
77    $block['edit_form'] = false;
78    $block['template'] = '';
79    $block['op'] = $op;
80    $block['side'] = $_POST['bside'];
81    $block['weight'] = $_POST['bweight'];
82    $block['visible'] = $_POST['bvisible'];
83    $block['title'] = $myblock->getVar('title', 'E');
84    $block['content'] = $myblock->getVar('content', 'E');
85    $block['modules'] =& $_POST['bmodule'];
86    $block['ctype'] = isset($_POST['bctype']) ? $_POST['bctype'] : $myblock->getVar('c_type');
87    $block['is_custom'] = true;
88    $block['cachetime'] = intval($_POST['bcachetime']);
89    echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$block['form_title'].'<br /><br />';
90    include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
91    $form->display();
92    xoops_cp_footer();
93    echo '<script type="text/javascript">
94    <!--//
95    win = openWithSelfMain("", "xoops_system_block_preview", 250, 200, true);
96    ';
97    $lines = preg_split("/(\r\n|\r|\n)( *)/", $dummyhtml);
98    foreach ($lines as $line) {
99        echo 'win.document.writeln("'.str_replace('"', '\"', $line).'");';
100    }
101    echo '
102    win.document.close();
103    //-->
104    </script>';
105    exit();
106}
107
108if ( $op == "list" ) {
109    require_once XOOPS_ROOT_PATH."/modules/system/admin/blocksadmin/blocksadmin.php";
110    xoops_cp_header();
111    list_blocks();
112    xoops_cp_footer();
113    exit();
114}
115
116if ( $op == "order" ) {
117    if (is_array($_POST['bid'])) {
118        require_once XOOPS_ROOT_PATH."/modules/system/admin/blocksadmin/blocksadmin.php";
119        foreach (array_keys($_POST['bid']) as $i) {
120            if ($_POST['oldweight'][$i] != $_POST['weight'][$i] || $_POST['oldvisible'][$i] != $_POST['visible'][$i] || $_POST['oldside'][$i] != $_POST['side'][$i])
121            order_block($_POST['bid'][$i], $_POST['weight'][$i], $_POST['visible'][$i], $_POST['side'][$i]);
122        }
123    }
124    redirect_header("admin.php?fct=blocksadmin",1,_AM_DBUPDATED);
125    exit();
126}
127
128if ( $op == "save" ) {
129    if (empty($_POST['bmodule']) || !XoopsMultiTokenHandler::quickValidate('block')) {
130        xoops_cp_header();
131        xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
132        xoops_cp_footer();
133        exit();
134    }
135    $myblock = new XoopsBlock();
136    $myblock->setVar('side', $_POST['bside']);
137    $myblock->setVar('weight', $_POST['bweight']);
138    $myblock->setVar('visible', $_POST['bvisible']);
139    $myblock->setVar('weight', $_POST['bweight']);
140    $myblock->setVar('title', $_POST['btitle']);
141    $myblock->setVar('content', $_POST['bcontent']);
142    $myblock->setVar('c_type', $_POST['bctype']);
143    $myblock->setVar('block_type', 'C');
144    $myblock->setVar('bcachetime', $_POST['bcachetime']);
145    switch ($_POST['bctype']) {
146    case 'H':
147        $name = _AM_CUSTOMHTML;
148        break;
149    case 'P':
150        $name = _AM_CUSTOMPHP;
151        break;
152    case 'S':
153        $name = _AM_CUSTOMSMILE;
154        break;
155    default:
156        $name = _AM_CUSTOMNOSMILE;
157        break;
158    }
159    $myblock->setVar('name', $name);
160    $newid = $myblock->store();
161    if (!$newid) {
162        xoops_cp_header();
163        $myblock->getHtmlErrors();
164        xoops_cp_footer();
165        exit();
166    }
167    $db =& Database::getInstance();
168    foreach ($_POST['bmodule'] as $bmid) {
169        $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.intval($bmid).')';
170            $db->query($sql);
171    }
172    $groups = $xoopsUser->getGroups();
173    $count = count($groups);
174    for ($i = 0; $i < $count; $i++) {
175        $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_name, gperm_modid) VALUES (".$groups[$i].", ".$newid.", 'block_read', 1)";
176        $db->query($sql);
177    }
178    redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,_AM_DBUPDATED);
179    exit();
180}
181
182if ( $op == "update" ) {
183    $bid = !empty($_POST['bid']) ? intval($_POST['bid']) : 0;
184    if ($bid <= 0) {
185        exit();
186    }
187    $bcachetime = isset($_POST['bcachetime']) ? intval($_POST['bcachetime']) : 0;
188    $options = isset($_POST['options']) ? $_POST['options'] : array();
189    $bcontent = isset($_POST['bcontent']) ? $_POST['bcontent'] : '';
190    $bctype = isset($_POST['bctype']) ? $_POST['bctype'] : '';
191    if (empty($_POST['bmodule']) || !XoopsMultiTokenHandler::quickValidate('block')) {
192        xoops_cp_header();
193        xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN));
194        xoops_cp_footer();
195        exit();
196    }
197    $myblock = new XoopsBlock($bid);
198    $myblock->setVar('side', $_POST['bside']);
199    $myblock->setVar('weight', $_POST['bweight']);
200    $myblock->setVar('visible', $_POST['bvisible']);
201    $myblock->setVar('title', $_POST['btitle']);
202    $myblock->setVar('content', $bcontent);
203    $myblock->setVar('bcachetime', $bcachetime);
204    $options_count = count($options);
205    if ($options_count > 0) {
206        //Convert array values to comma-separated
207        for ( $i = 0; $i < $options_count; $i++ ) {
208            if (is_array($options[$i])) {
209                $options[$i] = implode(',', $options[$i]);
210            }
211        }
212        $options = implode('|', $options);
213        $myblock->setVar('options', $options);
214    }
215    if ($myblock->getVar('block_type') == 'C') {
216        switch ($bctype) {
217        case 'H':
218            $name = _AM_CUSTOMHTML;
219            break;
220        case 'P':
221            $name = _AM_CUSTOMPHP;
222            break;
223        case 'S':
224            $name = _AM_CUSTOMSMILE;
225            break;
226        default:
227            $name = _AM_CUSTOMNOSMILE;
228            break;
229        }
230        $myblock->setVar('name', $name);
231        $myblock->setVar('c_type', $bctype);
232    } else {
233        $myblock->setVar('c_type', 'H');
234    }
235    $msg = _AM_DBUPDATED;
236    if ($myblock->store() != false) {
237        $db =& Database::getInstance();
238        $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $db->prefix('block_module_link'), $bid);
239        $db->query($sql);
240        foreach ($_POST['bmodule'] as $bmid) {
241            $sql = sprintf("INSERT INTO %s (block_id, module_id) VALUES (%u, %d)", $db->prefix('block_module_link'), $bid, intval($bmid));
242            $db->query($sql);
243        }
244        include_once XOOPS_ROOT_PATH.'/class/template.php';
245        $xoopsTpl = new XoopsTpl();
246        $xoopsTpl->xoops_setCaching(2);
247        if ($myblock->getVar('template') != '') {
248            if ($xoopsTpl->is_cached('db:'.$myblock->getVar('template'), 'blk_'.$myblock->getVar('bid'))) {
249                if (!$xoopsTpl->clear_cache('db:'.$myblock->getVar('template'), 'blk_'.$myblock->getVar('bid'))) {
250                    $msg = 'Unable to clear cache for block ID '.$bid;
251                }
252            }
253        } else {
254            if ($xoopsTpl->is_cached('db:system_dummy.html', 'blk_'.$bid)) {
255                if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'blk_'.$bid)) {
256                    $msg = 'Unable to clear cache for block ID '.$bid;
257                }
258            }
259        }
260    } else {
261        $msg = 'Failed update of block. ID:'.$bid;
262    }
263    redirect_header('admin.php?fct=blocksadmin&amp;t='.time(),1,$msg);
264    exit();
265}
266
267
268if ( $op == "delete_ok" ) {
269    $bid = !empty($_POST['bid']) ? intval($_POST['bid']) : 0;
270    if ($bid > 0) {
271        require_once XOOPS_ROOT_PATH."/modules/system/admin/blocksadmin/blocksadmin.php";
272        delete_block_ok($bid);
273    }
274    exit();
275}
276
277if ( $op == "delete" ) {
278    xoops_cp_header();
279    if ($bid > 0) {
280        require_once XOOPS_ROOT_PATH."/modules/system/admin/blocksadmin/blocksadmin.php";
281        delete_block($bid);
282    }
283    xoops_cp_footer();
284    exit();
285}
286
287if ( $op == "edit" ) {
288    xoops_cp_header();
289    if ($bid > 0) {
290        require_once XOOPS_ROOT_PATH."/modules/system/admin/blocksadmin/blocksadmin.php";
291        edit_block($bid);
292    }
293    xoops_cp_footer();
294    exit();
295}
296/*
297if ($op == 'clone') {
298    clone_block($bid);
299}
300
301if ($op == 'clone_ok') {
302    clone_block_ok($bid, $bside, $bweight, $bvisible, $bcachetime, $bmodule, $options);
303}
304*/
305?>
Note: See TracBrowser for help on using the repository browser.