/include/blocksadmin.inc.php

https://gitlab.com/VoyaTrax/vtforum · PHP · 613 lines · 363 code · 62 blank · 188 comment · 134 complexity · dbd861b8e2c52324b976c9fe5916d74b MD5 · raw file

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