| 1 | <?php |
|---|
| 2 | // $Id: main.php,v 1.12 2004/01/06 09:36:20 okazu 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 | |
|---|
| 32 | if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) { |
|---|
| 33 | exit('Access Denied'); |
|---|
| 34 | } |
|---|
| 35 | include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php'; |
|---|
| 36 | include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blocksadmin.php'; |
|---|
| 37 | |
|---|
| 38 | $op = 'list'; |
|---|
| 39 | |
|---|
| 40 | if ( !empty($_POST['op']) ) { $op = $_POST['op']; } |
|---|
| 41 | if ( !empty($_POST['bid']) ) { $bid = intval($_POST['bid']); } |
|---|
| 42 | |
|---|
| 43 | if ( isset($_GET['op']) ) { |
|---|
| 44 | if ($_GET['op'] == 'edit' || $_GET['op'] == 'delete' || $_GET['op'] == 'delete_ok' || $_GET['op'] == 'clone' /* || $_GET['op'] == 'previewpopup'*/) { |
|---|
| 45 | $op = $_GET['op']; |
|---|
| 46 | $bid = isset($_GET['bid']) ? intval($_GET['bid']) : 0; |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | $dirname4disp = preg_replace( '[^a-zA-Z0-9_.-]' , '' , @$_GET['dirname'] ) ; |
|---|
| 50 | |
|---|
| 51 | |
|---|
| 52 | if (isset($_POST['previewblock'])) { |
|---|
| 53 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
|---|
| 54 | // exit('Invalid Referer'); |
|---|
| 55 | //} |
|---|
| 56 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 57 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | if( empty( $bid ) ) die( 'Invalid bid.' ) ; |
|---|
| 61 | |
|---|
| 62 | if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
|---|
| 63 | if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
|---|
| 64 | if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
|---|
| 65 | if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); } |
|---|
| 66 | if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; } |
|---|
| 67 | if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; } |
|---|
| 68 | if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; } |
|---|
| 69 | if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
|---|
| 70 | |
|---|
| 71 | xoops_cp_header(); |
|---|
| 72 | include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 73 | $xoopsTpl = new XoopsTpl(); |
|---|
| 74 | $xoopsTpl->xoops_setCaching(0); |
|---|
| 75 | $block['bid'] = $bid; |
|---|
| 76 | |
|---|
| 77 | if ($op == 'clone_ok') { |
|---|
| 78 | $block['form_title'] = _AM_CLONEBLOCK; |
|---|
| 79 | $block['submit_button'] = _CLONE; |
|---|
| 80 | $myblock = new XoopsBlock(); |
|---|
| 81 | $myblock->setVar('block_type', 'C'); |
|---|
| 82 | } else { |
|---|
| 83 | $op = 'update' ; |
|---|
| 84 | $block['form_title'] = _AM_EDITBLOCK; |
|---|
| 85 | $block['submit_button'] = _SUBMIT; |
|---|
| 86 | $myblock = new XoopsBlock($bid); |
|---|
| 87 | $block['name'] = $myblock->getVar('name'); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 91 | $myblock->setVar('title', $myts->stripSlashesGPC($btitle)); |
|---|
| 92 | $myblock->setVar('content', $myts->stripSlashesGPC($bcontent)); |
|---|
| 93 | // $dummyhtml = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.$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', $bctype).'</td></tr></table></body></html>'; |
|---|
| 94 | |
|---|
| 95 | /* $dummyfile = '_dummyfile_'.time().'.html'; |
|---|
| 96 | $fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w'); |
|---|
| 97 | fwrite($fp, $dummyhtml); |
|---|
| 98 | fclose($fp);*/ |
|---|
| 99 | $block['edit_form'] = false; |
|---|
| 100 | $block['template'] = ''; |
|---|
| 101 | $block['op'] = $op; |
|---|
| 102 | $block['side'] = $bside; |
|---|
| 103 | $block['weight'] = $bweight; |
|---|
| 104 | $block['visible'] = $bvisible; |
|---|
| 105 | $block['title'] = $myblock->getVar('title', 'E'); |
|---|
| 106 | $block['content'] = $myblock->getVar('content','n'); |
|---|
| 107 | $block['modules'] =& $bmodule; |
|---|
| 108 | $block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type'); |
|---|
| 109 | $block['is_custom'] = true; |
|---|
| 110 | $block['cachetime'] = intval($bcachetime); |
|---|
| 111 | echo '<a href="myblocksadmin.php?dirname='.$dirname4disp.'">'. _AM_BADMIN .'</a> <span style="font-weight:bold;">»»</span> '.$block['form_title'].'<br /><br />'; |
|---|
| 112 | include dirname(__FILE__).'/../admin/myblockform.php'; //GIJ |
|---|
| 113 | //echo '<a href="admin.php?fct=blocksadmin">'. _AM_BADMIN .'</a> <span style="font-weight:bold;">»»</span> '.$block['form_title'].'<br /><br />'; |
|---|
| 114 | //include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php'; |
|---|
| 115 | $xoopsGTicket->addTicketXoopsFormElement( $form , __LINE__ , 1800 , 'myblocksadmin' ) ; //GIJ |
|---|
| 116 | $form->display(); |
|---|
| 117 | |
|---|
| 118 | $original_level = error_reporting( E_ALL ) ; |
|---|
| 119 | echo " |
|---|
| 120 | <table width='100%' class='outer' cellspacing='1'> |
|---|
| 121 | <tr> |
|---|
| 122 | <th>".$myblock->getVar('title')."</th> |
|---|
| 123 | </tr> |
|---|
| 124 | <tr> |
|---|
| 125 | <td class='odd'>".$myblock->getContent('S', $bctype)."</td> |
|---|
| 126 | </tr> |
|---|
| 127 | </table>\n" ; |
|---|
| 128 | error_reporting( $original_level ) ; |
|---|
| 129 | |
|---|
| 130 | xoops_cp_footer(); |
|---|
| 131 | /* echo '<script type="text/javascript"> |
|---|
| 132 | preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file='.$dummyfile.'", "popup", 250, 200); |
|---|
| 133 | </script>';*/ |
|---|
| 134 | |
|---|
| 135 | exit(); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | /* if ($op == 'previewpopup') { |
|---|
| 139 | if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
|---|
| 140 | exit('Invalid Referer'); |
|---|
| 141 | } |
|---|
| 142 | $file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($_GET['file'])); |
|---|
| 143 | if (file_exists($file)) { |
|---|
| 144 | include $file; |
|---|
| 145 | @unlink($file); |
|---|
| 146 | } |
|---|
| 147 | exit(); |
|---|
| 148 | } */ |
|---|
| 149 | |
|---|
| 150 | /* if ( $op == "list" ) { |
|---|
| 151 | xoops_cp_header(); |
|---|
| 152 | list_blocks(); |
|---|
| 153 | xoops_cp_footer(); |
|---|
| 154 | exit(); |
|---|
| 155 | } */ |
|---|
| 156 | |
|---|
| 157 | if ( $op == 'order' ) { |
|---|
| 158 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
|---|
| 159 | // exit('Invalid Referer'); |
|---|
| 160 | //} |
|---|
| 161 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 162 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 163 | } |
|---|
| 164 | if ( !empty($_POST['side']) ) { $side = $_POST['side']; } |
|---|
| 165 | // if ( !empty($_POST['weight']) ) { $weight = $_POST['weight']; } |
|---|
| 166 | if ( !empty($_POST['visible']) ) { $visible = $_POST['visible']; } |
|---|
| 167 | // if ( !empty($_POST['oldside']) ) { $oldside = $_POST['oldside']; } |
|---|
| 168 | // if ( !empty($_POST['oldweight']) ) { $oldweight = $_POST['oldweight']; } |
|---|
| 169 | // if ( !empty($_POST['oldvisible']) ) { $oldvisible = $_POST['oldvisible']; } |
|---|
| 170 | if ( !empty($_POST['bid']) ) { $bid = $_POST['bid']; } else { $bid = array(); } |
|---|
| 171 | // GIJ start |
|---|
| 172 | foreach (array_keys($bid) as $i) { |
|---|
| 173 | if( $side[$i] < 0 ) { |
|---|
| 174 | $visible[$i] = 0 ; |
|---|
| 175 | $side[$i] = -1 ; |
|---|
| 176 | } else { |
|---|
| 177 | $visible[$i] = 1 ; |
|---|
| 178 | } |
|---|
| 179 | |
|---|
| 180 | $bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1) ; |
|---|
| 181 | |
|---|
| 182 | myblocksadmin_update_block($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null , null , $_POST['bcachetime'][$i], $bmodule, array()); |
|---|
| 183 | |
|---|
| 184 | // if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] ) |
|---|
| 185 | // order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]); |
|---|
| 186 | } |
|---|
| 187 | redirect_header("myblocksadmin.php?dirname=$dirname4disp",1,_AM_DBUPDATED); |
|---|
| 188 | // GIJ end |
|---|
| 189 | exit(); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | |
|---|
| 193 | if ( $op == 'order2' ) { |
|---|
| 194 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 195 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | if( isset( $_POST['addblock'] ) && is_array( $_POST['addblock'] ) ) { |
|---|
| 199 | |
|---|
| 200 | // addblock |
|---|
| 201 | foreach( $_POST['addblock'] as $bid => $val ) { |
|---|
| 202 | myblocksadmin_update_blockinstance( 0, 0, 0, 0, '', null , null , 0, array(), array(), intval( $bid ) ); |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | } else { |
|---|
| 206 | |
|---|
| 207 | // else change order |
|---|
| 208 | if ( !empty($_POST['side']) ) { $side = $_POST['side']; } |
|---|
| 209 | if ( !empty($_POST['visible']) ) { $visible = $_POST['visible']; } |
|---|
| 210 | if ( !empty($_POST['id']) ) { $id = $_POST['id']; } else { $id = array(); } |
|---|
| 211 | |
|---|
| 212 | foreach (array_keys($id) as $i) { |
|---|
| 213 | // separate side and visible |
|---|
| 214 | if( $side[$i] < 0 ) { |
|---|
| 215 | $visible[$i] = 0 ; |
|---|
| 216 | $side[$i] = -1 ; // for not to destroy the original position |
|---|
| 217 | } else { |
|---|
| 218 | $visible[$i] = 1 ; |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | $bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1) ; |
|---|
| 222 | |
|---|
| 223 | myblocksadmin_update_blockinstance($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null , null , $_POST['bcachetime'][$i], $bmodule, array()); |
|---|
| 224 | |
|---|
| 225 | } |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | redirect_header("myblocksadmin.php?dirname=$dirname4disp",1,_MD_AM_DBUPDATED); |
|---|
| 229 | exit; |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | /* if ( $op == 'save' ) { |
|---|
| 233 | if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
|---|
| 234 | exit('Invalid Referer'); |
|---|
| 235 | } |
|---|
| 236 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 237 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 238 | } |
|---|
| 239 | if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
|---|
| 240 | if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
|---|
| 241 | if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
|---|
| 242 | if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); } |
|---|
| 243 | if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; } |
|---|
| 244 | if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; } |
|---|
| 245 | if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; } |
|---|
| 246 | if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
|---|
| 247 | save_block($bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bmodule, $bcachetime); |
|---|
| 248 | exit(); |
|---|
| 249 | } */ |
|---|
| 250 | |
|---|
| 251 | if ( $op == 'update' ) { |
|---|
| 252 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
|---|
| 253 | // exit('Invalid Referer'); |
|---|
| 254 | //} |
|---|
| 255 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 256 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 257 | } |
|---|
| 258 | /* if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; } |
|---|
| 259 | if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; } |
|---|
| 260 | if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; } |
|---|
| 261 | if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; } |
|---|
| 262 | if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; } |
|---|
| 263 | if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; } |
|---|
| 264 | if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; } |
|---|
| 265 | if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); } |
|---|
| 266 | if ( !empty($_POST['options']) ) { $options = $_POST['options']; } else { $options = array(); } |
|---|
| 267 | update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options);*/ |
|---|
| 268 | |
|---|
| 269 | $bcachetime = isset($_POST['bcachetime']) ? intval($_POST['bcachetime']) : 0; |
|---|
| 270 | $options = isset($_POST['options']) ? $_POST['options'] : array(); |
|---|
| 271 | $bcontent = isset($_POST['bcontent']) ? $_POST['bcontent'] : ''; |
|---|
| 272 | $bctype = isset($_POST['bctype']) ? $_POST['bctype'] : ''; |
|---|
| 273 | $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1) ; // GIJ + |
|---|
| 274 | $msg = myblocksadmin_update_block($_POST['bid'], $_POST['bside'], $_POST['bweight'], $_POST['bvisible'], $_POST['btitle'], $bcontent, $bctype, $bcachetime, $bmodule, $options); // GIJ ! |
|---|
| 275 | redirect_header("myblocksadmin.php?dirname=$dirname4disp",1,$msg); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | if ( $op == 'delete_ok' ) { |
|---|
| 280 | //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) { |
|---|
| 281 | // exit('Invalid Referer'); |
|---|
| 282 | //} |
|---|
| 283 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 284 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 285 | } |
|---|
| 286 | // delete_block_ok($bid); GIJ imported from blocksadmin.php |
|---|
| 287 | $myblock = new XoopsBlock($bid); |
|---|
| 288 | if ( $myblock->getVar('block_type') != 'D' && $myblock->getVar('block_type') != 'C' ) { |
|---|
| 289 | redirect_header('myblocksadmin.php',4,'Invalid block'); |
|---|
| 290 | exit(); |
|---|
| 291 | } |
|---|
| 292 | $myblock->delete(); |
|---|
| 293 | if ($myblock->getVar('template') != '' && ! defined('XOOPS_ORETEKI') ) { |
|---|
| 294 | $tplfile_handler =& xoops_gethandler('tplfile'); |
|---|
| 295 | $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
|---|
| 296 | if (count($btemplate) > 0) { |
|---|
| 297 | $tplman->delete($btemplate[0]); |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | redirect_header("myblocksadmin.php?dirname=$dirname4disp",1,_AM_DBUPDATED); |
|---|
| 301 | exit(); |
|---|
| 302 | // end of delete_block_ok() GIJ |
|---|
| 303 | exit(); |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | if ( $op == 'delete' ) { |
|---|
| 307 | xoops_cp_header(); |
|---|
| 308 | // delete_block($bid); GIJ imported from blocksadmin.php |
|---|
| 309 | $myblock = new XoopsBlock($bid); |
|---|
| 310 | if ( $myblock->getVar('block_type') == 'S' ) { |
|---|
| 311 | $message = _AM_SYSTEMCANT; |
|---|
| 312 | redirect_header('admin.php?fct=blocksadmin',4,$message); |
|---|
| 313 | exit(); |
|---|
| 314 | } elseif ($myblock->getVar('block_type') == 'M') { |
|---|
| 315 | $message = _AM_MODULECANT; |
|---|
| 316 | redirect_header('admin.php?fct=blocksadmin',4,$message); |
|---|
| 317 | exit(); |
|---|
| 318 | } else { |
|---|
| 319 | xoops_confirm(array('fct' => 'blocksadmin', 'op' => 'delete_ok', 'bid' => $myblock->getVar('bid')) + $xoopsGTicket->getTicketArray( __LINE__ , 1800 , 'myblocksadmin' ) , "admin.php?dirname=$dirname4disp", sprintf(_AM_RUSUREDEL,$myblock->getVar('title'))); |
|---|
| 320 | } |
|---|
| 321 | // end of delete_block() GIJ |
|---|
| 322 | xoops_cp_footer(); |
|---|
| 323 | exit(); |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | if ( $op == 'edit' ) { |
|---|
| 327 | |
|---|
| 328 | xoops_cp_header(); |
|---|
| 329 | // edit_block($bid); GIJ imported from blocksadmin.php |
|---|
| 330 | $myblock = new XoopsBlock($bid); |
|---|
| 331 | |
|---|
| 332 | $db =& Database::getInstance(); |
|---|
| 333 | $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid); |
|---|
| 334 | $result = $db->query($sql); |
|---|
| 335 | $modules = array(); |
|---|
| 336 | while ($row = $db->fetchArray($result)) { |
|---|
| 337 | $modules[] = intval($row['module_id']); |
|---|
| 338 | } |
|---|
| 339 | $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false; |
|---|
| 340 | $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','n'), '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'), 'submit_button' => _SUBMIT); |
|---|
| 341 | |
|---|
| 342 | echo '<a href="myblocksadmin.php?dirname='.$dirname4disp.'">'. _AM_BADMIN .'</a> <span style="font-weight:bold;">»»</span> '._AM_EDITBLOCK.'<br /><br />'; |
|---|
| 343 | include dirname(__FILE__).'/../admin/myblockform.php'; //GIJ |
|---|
| 344 | $xoopsGTicket->addTicketXoopsFormElement( $form , __LINE__ , 1800 , 'myblocksadmin' ) ; //GIJ |
|---|
| 345 | $form->display(); |
|---|
| 346 | // end of edit_block() GIJ |
|---|
| 347 | xoops_cp_footer(); |
|---|
| 348 | exit(); |
|---|
| 349 | } |
|---|
| 350 | |
|---|
| 351 | |
|---|
| 352 | if ($op == 'clone') { |
|---|
| 353 | xoops_cp_header(); |
|---|
| 354 | $myblock = new XoopsBlock($bid); |
|---|
| 355 | |
|---|
| 356 | $db =& Database::getInstance(); |
|---|
| 357 | $sql = 'SELECT module_id FROM '.$db->prefix('block_module_link').' WHERE block_id='.intval($bid); |
|---|
| 358 | $result = $db->query($sql); |
|---|
| 359 | $modules = array(); |
|---|
| 360 | while ($row = $db->fetchArray($result)) { |
|---|
| 361 | $modules[] = intval($row['module_id']); |
|---|
| 362 | } |
|---|
| 363 | $is_custom = ($myblock->getVar('block_type') == 'C' || $myblock->getVar('block_type') == 'E') ? true : false; |
|---|
| 364 | $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'), 'title' => $myblock->getVar('title','E'), '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'), 'submit_button' => _CLONE); |
|---|
| 365 | echo '<a href="myblocksadmin.php?dirname='.$dirname4disp.'">'. _AM_BADMIN .'</a> <span style="font-weight:bold;">»»</span> '._AM_CLONEBLOCK.'<br /><br />'; |
|---|
| 366 | include dirname(__FILE__).'/../admin/myblockform.php'; |
|---|
| 367 | $xoopsGTicket->addTicketXoopsFormElement( $form , __LINE__ , 1800 , 'myblocksadmin' ) ; //GIJ |
|---|
| 368 | $form->display(); |
|---|
| 369 | xoops_cp_footer(); |
|---|
| 370 | exit(); |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | if ($op == 'clone_ok') { |
|---|
| 375 | // Ticket Check |
|---|
| 376 | if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) { |
|---|
| 377 | redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors()); |
|---|
| 378 | } |
|---|
| 379 | |
|---|
| 380 | $block = new XoopsBlock($bid); |
|---|
| 381 | |
|---|
| 382 | // block type check |
|---|
| 383 | $block_type = $block->getVar('block_type') ; |
|---|
| 384 | if( $block_type != 'C' && $block_type != 'M' && $block_type != 'D' ) { |
|---|
| 385 | redirect_header('myblocksadmin.php',4,'Invalid block'); |
|---|
| 386 | } |
|---|
| 387 | |
|---|
| 388 | if( empty( $_POST['options'] ) ) $options = array() ; |
|---|
| 389 | else if( is_array( $_POST['options'] ) ) $options = $_POST['options'] ; |
|---|
| 390 | else $options = explode( '|' , $_POST['options'] ) ; |
|---|
| 391 | |
|---|
| 392 | // for backward compatibility |
|---|
| 393 | // $cblock =& $block->clone(); or $cblock =& $block->xoopsClone(); |
|---|
| 394 | $cblock = new XoopsBlock() ; |
|---|
| 395 | foreach( $block->vars as $k => $v ) { |
|---|
| 396 | $cblock->assignVar( $k , $v['value'] ) ; |
|---|
| 397 | } |
|---|
| 398 | $cblock->setNew(); |
|---|
| 399 | |
|---|
| 400 | $myts =& MyTextSanitizer::getInstance(); |
|---|
| 401 | $cblock->setVar('side', $_POST['bside']); |
|---|
| 402 | $cblock->setVar('weight', $_POST['bweight']); |
|---|
| 403 | $cblock->setVar('visible', $_POST['bvisible']); |
|---|
| 404 | $cblock->setVar('title', $_POST['btitle']); |
|---|
| 405 | $cblock->setVar('content', @$_POST['bcontent']); |
|---|
| 406 | $cblock->setVar('c_type', @$_POST['bctype']); |
|---|
| 407 | $cblock->setVar('bcachetime', $_POST['bcachetime']); |
|---|
| 408 | if ( isset($options) && (count($options) > 0) ) { |
|---|
| 409 | $options = implode('|', $options); |
|---|
| 410 | $cblock->setVar('options', $options); |
|---|
| 411 | } |
|---|
| 412 | $cblock->setVar('bid', 0); |
|---|
| 413 | $cblock->setVar('block_type', $block_type == 'C' ? 'C' : 'D' ); |
|---|
| 414 | $cblock->setVar('func_num', 255); |
|---|
| 415 | $newid = $cblock->store(); |
|---|
| 416 | if (!$newid) { |
|---|
| 417 | xoops_cp_header(); |
|---|
| 418 | $cblock->getHtmlErrors(); |
|---|
| 419 | xoops_cp_footer(); |
|---|
| 420 | exit(); |
|---|
| 421 | } |
|---|
| 422 | /* if ($cblock->getVar('template') != '') { |
|---|
| 423 | $tplfile_handler =& xoops_gethandler('tplfile'); |
|---|
| 424 | $btemplate =& $tplfile_handler->find($GLOBALS['xoopsConfig']['template_set'], 'block', $bid); |
|---|
| 425 | if (count($btemplate) > 0) { |
|---|
| 426 | $tplclone =& $btemplate[0]->clone(); |
|---|
| 427 | $tplclone->setVar('tpl_id', 0); |
|---|
| 428 | $tplclone->setVar('tpl_refid', $newid); |
|---|
| 429 | $tplman->insert($tplclone); |
|---|
| 430 | } |
|---|
| 431 | } */ |
|---|
| 432 | $db =& Database::getInstance(); |
|---|
| 433 | $bmodule = (isset($_POST['bmodule']) && is_array($_POST['bmodule'])) ? $_POST['bmodule'] : array(-1) ; // GIJ + |
|---|
| 434 | foreach( $bmodule as $bmid ) { |
|---|
| 435 | $sql = 'INSERT INTO '.$db->prefix('block_module_link').' (block_id, module_id) VALUES ('.$newid.', '.$bmid.')'; |
|---|
| 436 | $db->query($sql); |
|---|
| 437 | } |
|---|
| 438 | |
|---|
| 439 | /* global $xoopsUser; |
|---|
| 440 | $groups =& $xoopsUser->getGroups(); |
|---|
| 441 | $count = count($groups); |
|---|
| 442 | for ($i = 0; $i < $count; $i++) { |
|---|
| 443 | $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES (".$groups[$i].", ".$newid.", 1, 'block_read')"; |
|---|
| 444 | $db->query($sql); |
|---|
| 445 | } |
|---|
| 446 | */ |
|---|
| 447 | |
|---|
| 448 | $sql = "SELECT gperm_groupid FROM ".$db->prefix('group_permission')." WHERE gperm_name='block_read' AND gperm_modid='1' AND gperm_itemid='$bid'" ; |
|---|
| 449 | $result = $db->query($sql); |
|---|
| 450 | while( list( $gid ) = $db->fetchRow( $result ) ) { |
|---|
| 451 | $sql = "INSERT INTO ".$db->prefix('group_permission')." (gperm_groupid, gperm_itemid, gperm_modid, gperm_name) VALUES ($gid, $newid, 1, 'block_read')"; |
|---|
| 452 | $db->query($sql); |
|---|
| 453 | } |
|---|
| 454 | |
|---|
| 455 | redirect_header("myblocksadmin.php?dirname=$dirname4disp",1,_AM_DBUPDATED); |
|---|
| 456 | } |
|---|
| 457 | |
|---|
| 458 | // import from modules/system/admin/blocksadmin/blocksadmin.php |
|---|
| 459 | function myblocksadmin_update_block($bid, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options=array()) |
|---|
| 460 | { |
|---|
| 461 | global $xoopsConfig; |
|---|
| 462 | /* if (empty($bmodule)) { |
|---|
| 463 | xoops_cp_header(); |
|---|
| 464 | xoops_error(sprintf(_AM_NOTSELNG, _AM_VISIBLEIN)); |
|---|
| 465 | xoops_cp_footer(); |
|---|
| 466 | exit(); |
|---|
| 467 | } */ |
|---|
| 468 | $myblock = new XoopsBlock($bid); |
|---|
| 469 | // $myblock->setVar('side', $bside); GIJ - |
|---|
| 470 | if( $bside >= 0 ) $myblock->setVar('side', $bside); // GIJ + |
|---|
| 471 | $myblock->setVar('weight', $bweight); |
|---|
| 472 | $myblock->setVar('visible', $bvisible); |
|---|
| 473 | $myblock->setVar('title', $btitle); |
|---|
| 474 | if( isset( $bcontent ) ) $myblock->setVar('content', $bcontent); |
|---|
| 475 | if( isset( $bctype ) ) $myblock->setVar('c_type', $bctype); |
|---|
| 476 | $myblock->setVar('bcachetime', $bcachetime); |
|---|
| 477 | if ( isset($options) && (count($options) > 0) ) { |
|---|
| 478 | $options = implode('|', $options); |
|---|
| 479 | $myblock->setVar('options', $options); |
|---|
| 480 | } |
|---|
| 481 | if ( $myblock->getVar('block_type') == 'C') { |
|---|
| 482 | switch ( $myblock->getVar('c_type') ) { |
|---|
| 483 | case 'H': |
|---|
| 484 | $name = _AM_CUSTOMHTML; |
|---|
| 485 | break; |
|---|
| 486 | case 'P': |
|---|
| 487 | $name = _AM_CUSTOMPHP; |
|---|
| 488 | break; |
|---|
| 489 | case 'S': |
|---|
| 490 | $name = _AM_CUSTOMSMILE; |
|---|
| 491 | break; |
|---|
| 492 | default: |
|---|
| 493 | $name = _AM_CUSTOMNOSMILE; |
|---|
| 494 | break; |
|---|
| 495 | } |
|---|
| 496 | $myblock->setVar('name', $name); |
|---|
| 497 | } |
|---|
| 498 | $msg = _AM_DBUPDATED; |
|---|
| 499 | if ($myblock->store() != false) { |
|---|
| 500 | $db =& Database::getInstance(); |
|---|
| 501 | $sql = sprintf("DELETE FROM %s WHERE block_id = %u", $db->prefix('block_module_link'), $bid); |
|---|
| 502 | $db->query($sql); |
|---|
| 503 | foreach ($bmodule as $bmid) { |
|---|
| 504 | $sql = sprintf("INSERT INTO %s (block_id, module_id) VALUES (%u, %d)", $db->prefix('block_module_link'), $bid, intval($bmid)); |
|---|
| 505 | $db->query($sql); |
|---|
| 506 | } |
|---|
| 507 | include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 508 | $xoopsTpl = new XoopsTpl(); |
|---|
| 509 | $xoopsTpl->xoops_setCaching(2); |
|---|
| 510 | if ($myblock->getVar('template') != '') { |
|---|
| 511 | if ($xoopsTpl->is_cached('db:'.$myblock->getVar('template'))) { |
|---|
| 512 | if (!$xoopsTpl->clear_cache('db:'.$myblock->getVar('template'))) { |
|---|
| 513 | $msg = 'Unable to clear cache for block ID'.$bid; |
|---|
| 514 | } |
|---|
| 515 | } |
|---|
| 516 | } else { |
|---|
| 517 | if ($xoopsTpl->is_cached('db:system_dummy.html', 'block'.$bid)) { |
|---|
| 518 | if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block'.$bid)) { |
|---|
| 519 | $msg = 'Unable to clear cache for block ID'.$bid; |
|---|
| 520 | } |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | } else { |
|---|
| 524 | $msg = 'Failed update of block. ID:'.$bid; |
|---|
| 525 | } |
|---|
| 526 | // redirect_header('admin.php?fct=blocksadmin&t='.time(),1,$msg); |
|---|
| 527 | // exit(); GIJ - |
|---|
| 528 | return $msg ; // GIJ + |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | |
|---|
| 532 | // update block instance for 2.2 |
|---|
| 533 | function myblocksadmin_update_blockinstance($id, $bside, $bweight, $bvisible, $btitle, $bcontent, $bctype, $bcachetime, $bmodule, $options=array(), $bid=null) |
|---|
| 534 | { |
|---|
| 535 | global $xoopsDB ; |
|---|
| 536 | |
|---|
| 537 | $instance_handler =& xoops_gethandler('blockinstance'); |
|---|
| 538 | $block_handler =& xoops_gethandler('block') ; |
|---|
| 539 | if ($id > 0) { |
|---|
| 540 | // update |
|---|
| 541 | $instance =& $instance_handler->get($id); |
|---|
| 542 | if( $bside >= 0 ) $instance->setVar('side', $bside); |
|---|
| 543 | if( ! empty($options) ) $instance->setVar('options', $options); |
|---|
| 544 | } else { |
|---|
| 545 | // insert |
|---|
| 546 | $instance =& $instance_handler->create(); |
|---|
| 547 | $instance->setVar( 'bid' , $bid ) ; |
|---|
| 548 | $instance->setVar('side', $bside); |
|---|
| 549 | $block = $block_handler->get( $bid ) ; |
|---|
| 550 | $instance->setVar('options', $block->getVar("options") ); |
|---|
| 551 | if( empty( $btitle ) ) $btitle = $block->getVar("name") ; |
|---|
| 552 | } |
|---|
| 553 | $instance->setVar('weight', $bweight); |
|---|
| 554 | $instance->setVar('visible', $bvisible); |
|---|
| 555 | $instance->setVar('title', $btitle); |
|---|
| 556 | // if( isset( $bcontent ) ) $instance->setVar('content', $bcontent); |
|---|
| 557 | // if( isset( $bctype ) ) $instance->setVar('c_type', $bctype); |
|---|
| 558 | $instance->setVar('bcachetime', $bcachetime); |
|---|
| 559 | |
|---|
| 560 | if ($instance_handler->insert($instance)) { |
|---|
| 561 | $GLOBALS['xoopsDB']->query("DELETE FROM ".$GLOBALS['xoopsDB']->prefix('block_module_link')." WHERE block_id=".$instance->getVar('instanceid')); |
|---|
| 562 | foreach ($bmodule as $mid) { |
|---|
| 563 | $page = explode('-', $mid); |
|---|
| 564 | $mid = $page[0]; |
|---|
| 565 | $pageid = $page[1]; |
|---|
| 566 | $GLOBALS['xoopsDB']->query("INSERT INTO ".$GLOBALS['xoopsDB']->prefix('block_module_link')." VALUES (".$instance->getVar('instanceid').", ".intval($mid).", ".intval($pageid).")"); |
|---|
| 567 | } |
|---|
| 568 | return _MD_AM_DBUPDATED; |
|---|
| 569 | } |
|---|
| 570 | return 'Failed update of block instance. ID:'.$id; |
|---|
| 571 | |
|---|
| 572 | /* // NAME for CUSTOM BLOCK |
|---|
| 573 | if ( $instance->getVar('block_type') == 'C') { |
|---|
| 574 | switch ( $instance->getVar('c_type') ) { |
|---|
| 575 | case 'H': |
|---|
| 576 | $name = _AM_CUSTOMHTML; |
|---|
| 577 | break; |
|---|
| 578 | case 'P': |
|---|
| 579 | $name = _AM_CUSTOMPHP; |
|---|
| 580 | break; |
|---|
| 581 | case 'S': |
|---|
| 582 | $name = _AM_CUSTOMSMILE; |
|---|
| 583 | break; |
|---|
| 584 | default: |
|---|
| 585 | $name = _AM_CUSTOMNOSMILE; |
|---|
| 586 | break; |
|---|
| 587 | } |
|---|
| 588 | $instance->setVar('name', $name); |
|---|
| 589 | } |
|---|
| 590 | */ |
|---|
| 591 | /* // CLEAR TEMPLATE CACHE |
|---|
| 592 | include_once XOOPS_ROOT_PATH.'/class/template.php'; |
|---|
| 593 | $xoopsTpl = new XoopsTpl(); |
|---|
| 594 | $xoopsTpl->xoops_setCaching(2); |
|---|
| 595 | if ($instance->getVar('template') != '') { |
|---|
| 596 | if ($xoopsTpl->is_cached('db:'.$instance->getVar('template'))) { |
|---|
| 597 | if (!$xoopsTpl->clear_cache('db:'.$instance->getVar('template'))) { |
|---|
| 598 | $msg = 'Unable to clear cache for block ID'.$bid; |
|---|
| 599 | } |
|---|
| 600 | } |
|---|
| 601 | } else { |
|---|
| 602 | if ($xoopsTpl->is_cached('db:system_dummy.html', 'block'.$bid)) { |
|---|
| 603 | if (!$xoopsTpl->clear_cache('db:system_dummy.html', 'block'.$bid)) { |
|---|
| 604 | $msg = 'Unable to clear cache for block ID'.$bid; |
|---|
| 605 | } |
|---|
| 606 | } |
|---|
| 607 | } |
|---|
| 608 | */ |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | // TODO edit2, delete2, customblocks |
|---|
| 612 | |
|---|
| 613 | ?> |
|---|