PageRenderTime 81ms CodeModel.GetById 17ms app.highlight 57ms RepoModel.GetById 2ms app.codeStats 0ms

/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
 32if ( !is_object($xoopsUser) || !is_object($xoopsModule) || !$xoopsUser->isAdmin($xoopsModule->mid()) ) {
 33  exit('Access Denied');
 34}
 35include_once XOOPS_ROOT_PATH.'/class/xoopsblock.php';
 36include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blocksadmin.php';
 37
 38$op = 'list';
 39
 40if ( !empty($_POST['op']) ) { $op = $_POST['op']; }
 41if ( !empty($_POST['bid']) ) { $bid = intval($_POST['bid']); }
 42
 43if ( 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
 50if (isset($_POST['previewblock'])) {
 51  //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
 52  //  exit('Invalid Referer');
 53  //}
 54  if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) {
 55    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
 56  }
 57
 58  if( empty( $bid ) ) die( 'Invalid bid.' ) ;
 59
 60  if ( !empty($_POST['bside']) ) { $bside = intval($_POST['bside']); } else { $bside = 0; }
 61  if ( !empty($_POST['bweight']) ) { $bweight = intval($_POST['bweight']); } else { $bweight = 0; }
 62  if ( !empty($_POST['bvisible']) ) { $bvisible = intval($_POST['bvisible']); } else { $bvisible = 0; }
 63  if ( !empty($_POST['bmodule']) ) { $bmodule = $_POST['bmodule']; } else { $bmodule = array(); }
 64  if ( !empty($_POST['btitle']) ) { $btitle = $_POST['btitle']; } else { $btitle = ""; }
 65  if ( !empty($_POST['bcontent']) ) { $bcontent = $_POST['bcontent']; } else { $bcontent = ""; }
 66  if ( !empty($_POST['bctype']) ) { $bctype = $_POST['bctype']; } else { $bctype = ""; }
 67  if ( !empty($_POST['bcachetime']) ) { $bcachetime = intval($_POST['bcachetime']); } else { $bcachetime = 0; }
 68  
 69  xoops_cp_header();
 70  include_once XOOPS_ROOT_PATH.'/class/template.php';
 71  $xoopsTpl = new XoopsTpl();
 72  $xoopsTpl->xoops_setCaching(0);
 73  $block['bid'] = $bid;
 74
 75  if ($op == 'clone_ok') {
 76    $block['form_title'] = _AM_CLONEBLOCK;
 77    $block['submit_button'] = _CLONE;
 78    $myblock = new XoopsBlock();
 79    $myblock->setVar('block_type', 'C');
 80  } else {
 81    $op = 'update' ;
 82    $block['form_title'] = _AM_EDITBLOCK;
 83    $block['submit_button'] = _SUBMIT;
 84    $myblock = new XoopsBlock($bid);
 85    $block['name'] = $myblock->getVar('name');
 86  }
 87
 88  $myts =& MyTextSanitizer::getInstance();
 89  $myblock->setVar('title', $myts->stripSlashesGPC($btitle));
 90  $myblock->setVar('content', $myts->stripSlashesGPC($bcontent));
 91//  $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>';
 92
 93  /* $dummyfile = '_dummyfile_'.time().'.html';
 94  $fp = fopen(XOOPS_CACHE_PATH.'/'.$dummyfile, 'w');
 95  fwrite($fp, $dummyhtml);
 96  fclose($fp);*/
 97  $block['edit_form'] = false;
 98  $block['template'] = '';
 99  $block['op'] = $op;
100  $block['side'] = $bside;
101  $block['weight'] = $bweight;
102  $block['visible'] = $bvisible;
103  $block['title'] = $myblock->getVar('title', 'E');
104  $block['content'] = $myblock->getVar('content','n');
105  $block['modules'] =& $bmodule;
106  $block['ctype'] = isset($bctype) ? $bctype : $myblock->getVar('c_type');
107  $block['is_custom'] = true;
108  $block['cachetime'] = intval($bcachetime);
109  echo '<a href="myblocksadmin.php">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'.$block['form_title'].'<br /><br />';
110  include dirname(__FILE__).'/../admin/myblockform.php'; //GIJ
111  //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 />';
112  //include XOOPS_ROOT_PATH.'/modules/system/admin/blocksadmin/blockform.php';
113  $xoopsGTicket->addTicketXoopsFormElement( $form , __LINE__ , 1800 , 'myblocksadmin' ) ; //GIJ
114  $form->display();
115
116  $original_level = error_reporting( E_ALL ) ;
117  echo "
118    <table width='100%' class='outer' cellspacing='1'>
119      <tr>
120        <th>".$myblock->getVar('title')."</th>
121      </tr>
122      <tr>
123        <td class='odd'>".$myblock->getContent('S', $bctype)."</td>
124      </tr>
125    </table>\n" ;
126  error_reporting( $original_level ) ;
127
128  xoops_cp_footer();
129  /* echo '<script type="text/javascript">
130  preview_window = openWithSelfMain("'.XOOPS_URL.'/modules/system/admin.php?fct=blocksadmin&op=previewpopup&file='.$dummyfile.'", "popup", 250, 200);
131  </script>';*/
132
133  exit();
134}
135
136/* if ($op == 'previewpopup') {
137  if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
138    exit('Invalid Referer');
139  }
140  $file = str_replace('..', '', XOOPS_CACHE_PATH.'/'.trim($_GET['file']));
141  if (file_exists($file)) {
142    include $file;
143    @unlink($file);
144  }
145  exit();
146} */
147
148/* if ( $op == "list" ) {
149  xoops_cp_header();
150  list_blocks();
151  xoops_cp_footer();
152  exit();
153} */
154
155if ( $op == 'order' ) {
156  //if ( !admin_refcheck("/modules/$admin_mydirname/admin/") ) {
157  //  exit('Invalid Referer');
158  //}
159  if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) {
160    redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
161  }
162  if ( !empty($_POST['side']) ) { $side = $_POST['side']; }
163//  if ( !empty($_POST['weight']) ) { $weight = $_POST['weight']; }
164  if ( !empty($_POST['visible']) ) { $visible = $_POST['visible']; }
165//  if ( !empty($_POST['oldside']) ) { $oldside = $_POST['oldside']; }
166//  if ( !empty($_POST['oldweight']) ) { $oldweight = $_POST['oldweight']; }
167//  if ( !empty($_POST['oldvisible']) ) { $oldvisible = $_POST['oldvisible']; }
168  if ( !empty($_POST['bid']) ) { $bid = $_POST['bid']; } else { $bid = array(); }
169  // GIJ start
170  foreach (array_keys($bid) as $i) {
171		if( $side[$i] < 0 ) {
172			$visible[$i] = 0 ;
173			$side[$i] = -1 ;
174		} else {
175			$visible[$i] = 1 ;
176		}
177
178		$bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1) ;
179
180		myblocksadmin_update_block($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null , null , $_POST['bcachetime'][$i], $bmodule, array());
181
182//    if ( $oldweight[$i] != $weight[$i] || $oldvisible[$i] != $visible[$i] || $oldside[$i] != $side[$i] )
183//    order_block($bid[$i], $weight[$i], $visible[$i], $side[$i]);
184  }
185  $query4redirect = '?dirname=' . urlencode( strip_tags( substr( $_POST['query4redirect'] , 9 ) ) ) ;
186  redirect_header("myblocksadmin.php$query4redirect",1,_AM_DBUPDATED);
187  // GIJ end
188  exit();
189}
190
191
192if ( $op == 'order2' ) {
193	if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) {
194		redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
195	}
196
197	if( isset( $_POST['addblock'] ) && is_array( $_POST['addblock'] ) ) {
198
199		// addblock
200		foreach( $_POST['addblock'] as $bid => $val ) {
201			myblocksadmin_update_blockinstance( 0, 0, 0, 0, '', null , null , 0, array(), array(), intval( $bid ) );
202		}
203
204	} else {
205
206		// else change order
207		if ( !empty($_POST['side']) ) { $side = $_POST['side']; }
208		if ( !empty($_POST['visible']) ) { $visible = $_POST['visible']; }
209		if ( !empty($_POST['id']) ) { $id = $_POST['id']; } else { $id = array(); }
210
211		foreach (array_keys($id) as $i) {
212			// separate side and visible
213			if( $side[$i] < 0 ) {
214				$visible[$i] = 0 ;
215				$side[$i] = -1 ;  // for not to destroy the original position
216			} else {
217				$visible[$i] = 1 ;
218			}
219
220			$bmodule = (isset($_POST['bmodule'][$i]) && is_array($_POST['bmodule'][$i])) ? $_POST['bmodule'][$i] : array(-1) ;
221	
222			myblocksadmin_update_blockinstance($i, $side[$i], $_POST['weight'][$i], $visible[$i], $_POST['title'][$i], null , null , $_POST['bcachetime'][$i], $bmodule, array());
223
224		}
225	}
226
227	$query4redirect = '?dirname=' . urlencode( strip_tags( substr( $_POST['query4redirect'] , 9 ) ) ) ;
228	redirect_header("myblocksadmin.php$query4redirect",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
251if ( $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',1,$msg);
276}
277
278
279if ( $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',1,_AM_DBUPDATED);
301		exit();
302  // end of delete_block_ok() GIJ
303  exit();
304}
305
306if ( $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', sprintf(_AM_RUSUREDEL,$myblock->getVar('title')));
320		}
321  // end of delete_block() GIJ
322  xoops_cp_footer();
323  exit();
324}
325
326if ( $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">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._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
352if ($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">'. _AM_BADMIN .'</a>&nbsp;<span style="font-weight:bold;">&raquo;&raquo;</span>&nbsp;'._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
374if ($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',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&amp;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?>