PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/smartsection/admin/myblocksadmin2.php

https://github.com/severnaya99/Sg-2010
PHP | 347 lines | 273 code | 48 blank | 26 comment | 45 complexity | d39e4fc8550dafa5184b05ff3fff63a0 MD5 | raw file
Possible License(s): LGPL-2.1, AGPL-1.0, GPL-2.0
  1. <?php
  2. // ------------------------------------------------------------------------- //
  3. // myblocksadmin_for_2.2.php //
  4. // - XOOPS block admin for each modules - //
  5. // GIJOE <http://www.peak.ne.jp/> //
  6. // ------------------------------------------------------------------------- //
  7. if( ! defined( 'XOOPS_ROOT_PATH' ) ) exit ;
  8. include_once( '../../../include/cp_header.php' ) ;
  9. include_once( 'mygrouppermform.php' ) ;
  10. include_once( XOOPS_ROOT_PATH.'/class/xoopsblock.php' ) ;
  11. include_once "../include/gtickets.php" ;
  12. $xoops_system_path = XOOPS_ROOT_PATH . '/modules/system' ;
  13. // language files
  14. $language = $xoopsConfig['language'] ;
  15. if( ! file_exists( "$xoops_system_path/language/$language/admin/blocksadmin.php") ) $language = 'english' ;
  16. // to prevent from notice that constants already defined
  17. $error_reporting_level = error_reporting( 0 ) ;
  18. include_once( "$xoops_system_path/constants.php" ) ;
  19. include_once( "$xoops_system_path/language/$language/admin.php" ) ;
  20. include_once( "$xoops_system_path/language/$language/admin/blocksadmin.php" ) ;
  21. error_reporting( $error_reporting_level ) ;
  22. $group_defs = file( "$xoops_system_path/language/$language/admin/groups.php" ) ;
  23. foreach( $group_defs as $def ) {
  24. if( strstr( $def , '_AM_ACCESSRIGHTS' ) || strstr( $def , '_AM_ACTIVERIGHTS' ) ) eval( $def ) ;
  25. }
  26. // check $xoopsModule
  27. if( ! is_object( $xoopsModule ) ) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ;
  28. // set target_module if specified by $_GET['dirname']
  29. $module_handler =& xoops_gethandler('module');
  30. if( ! empty( $_GET['dirname'] ) ) {
  31. $target_module =& $module_handler->getByDirname($_GET['dirname']);
  32. }/* else if( ! empty( $_GET['mid'] ) ) {
  33. $target_module =& $module_handler->get( intval( $_GET['mid'] ) );
  34. }*/
  35. if( ! empty( $target_module ) && is_object( $target_module ) ) {
  36. // specified by dirname
  37. $target_mid = $target_module->getVar( 'mid' ) ;
  38. $target_mname = $target_module->getVar( 'name' ) . "&nbsp;" . sprintf( "(%2.2f)" , $target_module->getVar('version') / 100.0 ) ;
  39. $query4redirect = '?dirname='.urlencode(strip_tags($_GET['dirname'])) ;
  40. } else if( isset( $_GET['mid'] ) && $_GET['mid'] == 0 || $xoopsModule->getVar('dirname') == 'blocksadmin' ) {
  41. $target_mid = 0 ;
  42. $target_mname = '' ;
  43. $query4redirect = '?mid=0' ;
  44. } else {
  45. $target_mid = $xoopsModule->getVar( 'mid' ) ;
  46. $target_mname = $xoopsModule->getVar( 'name' ) ;
  47. $query4redirect = '' ;
  48. }
  49. // check access right (needs system_admin of BLOCK)
  50. $sysperm_handler =& xoops_gethandler('groupperm');
  51. if (!$sysperm_handler->checkRight('system_admin', XOOPS_SYSTEM_BLOCK, $xoopsUser->getGroups())) redirect_header( XOOPS_URL.'/user.php' , 1 , _NOPERM ) ;
  52. // get blocks owned by the module (Imported from xoopsblock.php then modified)
  53. $db =& Database::getInstance();
  54. $sql = "SELECT bid,name,show_func,func_file,template FROM ".$db->prefix("newblocks")." WHERE mid='$target_mid'";
  55. $result = $db->query($sql);
  56. $block_arr = array();
  57. while( list( $bid , $bname , $show_func , $func_file , $template ) = $db->fetchRow( $result ) ) {
  58. $block_arr[$bid] = array(
  59. 'name' => $bname ,
  60. 'show_func' => $show_func ,
  61. 'func_file' => $func_file ,
  62. 'template' => $template
  63. ) ;
  64. }
  65. // for 2.2
  66. function list_blockinstances()
  67. {
  68. global $query4redirect , $block_arr , $xoopsGTicket ;
  69. $myts =& MyTextSanitizer::getInstance() ;
  70. // cachetime options
  71. $cachetimes = array('0' => _NOCACHE, '30' => sprintf(_SECONDS, 30), '60' => _MINUTE, '300' => sprintf(_MINUTES, 5), '1800' => sprintf(_MINUTES, 30), '3600' => _HOUR, '18000' => sprintf(_HOURS, 5), '86400' => _DAY, '259200' => sprintf(_DAYS, 3), '604800' => _WEEK, '2592000' => _MONTH);
  72. // displaying TH
  73. echo "
  74. <form action='admin.php' name='blockadmin' method='post'>
  75. <table width='95%' class='outer' cellpadding='4' cellspacing='1'>
  76. <tr valign='middle'>
  77. <th>"._AM_TITLE."</th>
  78. <th align='center' nowrap='nowrap'>"._AM_SIDE."</th>
  79. <th align='center'>"._AM_WEIGHT."</th>
  80. <th align='center'>"._AM_VISIBLEIN."</th>
  81. <th align='center'>"._AM_BCACHETIME."</th>
  82. <th align='right'>"._AM_ACTION."</th>
  83. </tr>\n" ;
  84. // get block instances
  85. $crit = new Criteria("bid", "(".implode(",",array_keys($block_arr)).")", "IN");
  86. $criteria = new CriteriaCompo($crit);
  87. $criteria->setSort('visible DESC, side ASC, weight');
  88. $instance_handler =& xoops_gethandler('blockinstance');
  89. $instances =& $instance_handler->getObjects($criteria, true, true);
  90. //Get modules and pages for visible in
  91. $module_list[_AM_SYSTEMLEVEL]["0-2"] = _AM_ADMINBLOCK;
  92. $module_list[_AM_SYSTEMLEVEL]["0-1"] = _AM_TOPPAGE;
  93. $module_list[_AM_SYSTEMLEVEL]["0-0"] = _AM_ALLPAGES;
  94. $criteria = new CriteriaCompo(new Criteria('hasmain', 1));
  95. $criteria->add(new Criteria('isactive', 1));
  96. $module_handler =& xoops_gethandler('module');
  97. $module_main =& $module_handler->getObjects($criteria, true, true);
  98. if (count($module_main) > 0) {
  99. foreach (array_keys($module_main) as $mid) {
  100. $module_list[$module_main[$mid]->getVar('name')][$mid."-0"] = _AM_ALLMODULEPAGES;
  101. $pages = $module_main[$mid]->getInfo("pages");
  102. if ($pages == false) {
  103. $pages = $module_main[$mid]->getInfo("sub");
  104. }
  105. if (is_array($pages) && $pages != array()) {
  106. foreach ($pages as $id => $pageinfo) {
  107. $module_list[$module_main[$mid]->getVar('name')][$mid."-".$id] = $pageinfo['name'];
  108. }
  109. }
  110. }
  111. }
  112. // blocks displaying loop
  113. $class = 'even' ;
  114. $block_configs = get_block_configs() ;
  115. foreach( array_keys( $instances ) as $i ) {
  116. $sseln = $ssel0 = $ssel1 = $ssel2 = $ssel3 = $ssel4 = "";
  117. $scoln = $scol0 = $scol1 = $scol2 = $scol3 = $scol4 = "#FFFFFF";
  118. $weight = $instances[$i]->getVar("weight") ;
  119. $title = $instances[$i]->getVar("title") ;
  120. $bcachetime = $instances[$i]->getVar("bcachetime") ;
  121. $bid = $instances[$i]->getVar("bid") ;
  122. $name = $myts->makeTboxData4Edit( $block_arr[$bid]['name'] ) ;
  123. $visiblein = $instances[$i]->getVisibleIn();
  124. // visible and side
  125. if ( $instances[$i]->getVar("visible") != 1 ) {
  126. $sseln = " checked='checked'";
  127. $scoln = "#FF0000";
  128. } else switch( $instances[$i]->getVar("side") ) {
  129. default :
  130. case XOOPS_SIDEBLOCK_LEFT :
  131. $ssel0 = " checked='checked'";
  132. $scol0 = "#00FF00";
  133. break ;
  134. case XOOPS_SIDEBLOCK_RIGHT :
  135. $ssel1 = " checked='checked'";
  136. $scol1 = "#00FF00";
  137. break ;
  138. case XOOPS_CENTERBLOCK_LEFT :
  139. $ssel2 = " checked='checked'";
  140. $scol2 = "#00FF00";
  141. break ;
  142. case XOOPS_CENTERBLOCK_RIGHT :
  143. $ssel4 = " checked='checked'";
  144. $scol4 = "#00FF00";
  145. break ;
  146. case XOOPS_CENTERBLOCK_CENTER :
  147. $ssel3 = " checked='checked'";
  148. $scol3 = "#00FF00";
  149. break ;
  150. }
  151. // bcachetime
  152. $cachetime_options = '' ;
  153. foreach( $cachetimes as $cachetime => $cachetime_name ) {
  154. if( $bcachetime == $cachetime ) {
  155. $cachetime_options .= "<option value='$cachetime' selected='selected'>$cachetime_name</option>\n" ;
  156. } else {
  157. $cachetime_options .= "<option value='$cachetime'>$cachetime_name</option>\n" ;
  158. }
  159. }
  160. $module_options = '' ;
  161. foreach( $module_list as $mname => $module ) {
  162. $module_options .= "<optgroup label='$mname'>\n" ;
  163. foreach( $module as $mkey => $mval ) {
  164. if( in_array( $mkey , $visiblein ) ) {
  165. $module_options .= "<option value='$mkey' selected='selected'>$mval</option>\n" ;
  166. } else {
  167. $module_options .= "<option label='$mval' value='$mkey'>$mval</option>\n" ;
  168. }
  169. }
  170. $module_options .= "</optgroup>\n" ;
  171. }
  172. // delete link if it is cloned block
  173. $delete_link = "<br /><a href='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;op=delete&amp;id=$i&amp;selmod=$mid'>"._DELETE."</a>" ;
  174. // displaying part
  175. echo "
  176. <tr valign='middle'>
  177. <td class='$class'>
  178. $name
  179. <br />
  180. <input type='text' name='title[$i]' value='$title' size='20' />
  181. </td>
  182. <td class='$class' align='center' nowrap='nowrap' width='125px'>
  183. <div style='float:left;background-color:$scol0;'>
  184. <input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_LEFT."' style='background-color:$scol0;' $ssel0 />
  185. </div>
  186. <div style='float:left;'>-</div>
  187. <div style='float:left;background-color:$scol2;'>
  188. <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_LEFT."' style='background-color:$scol2;' $ssel2 />
  189. </div>
  190. <div style='float:left;background-color:$scol3;'>
  191. <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_CENTER."' style='background-color:$scol3;' $ssel3 />
  192. </div>
  193. <div style='float:left;background-color:$scol4;'>
  194. <input type='radio' name='side[$i]' value='".XOOPS_CENTERBLOCK_RIGHT."' style='background-color:$scol4;' $ssel4 />
  195. </div>
  196. <div style='float:left;'>-</div>
  197. <div style='float:left;background-color:$scol1;'>
  198. <input type='radio' name='side[$i]' value='".XOOPS_SIDEBLOCK_RIGHT."' style='background-color:$scol1;' $ssel1 />
  199. </div>
  200. <br />
  201. <br />
  202. <div style='float:left;width:40px;'>&nbsp;</div>
  203. <div style='float:left;background-color:$scoln;'>
  204. <input type='radio' name='side[$i]' value='-1' style='background-color:$scoln;' $sseln />
  205. </div>
  206. <div style='float:left;'>"._NONE."</div>
  207. </td>
  208. <td class='$class' align='center'>
  209. <input type='text' name=weight[$i] value='$weight' size='3' maxlength='5' style='text-align:right;' />
  210. </td>
  211. <td class='$class' align='center'>
  212. <select name='bmodule[$i][]' size='5' multiple='multiple'>
  213. $module_options
  214. </select>
  215. </td>
  216. <td class='$class' align='center'>
  217. <select name='bcachetime[$i]' size='1'>
  218. $cachetime_options
  219. </select>
  220. </td>
  221. <td class='$class' align='right'>
  222. <a href='".XOOPS_URL."/modules/system/admin.php?fct=blocksadmin&amp;op=edit&amp;id=$i'>"._EDIT."</a>{$delete_link}
  223. <input type='hidden' name='id[$i]' value='$i' />
  224. </td>
  225. </tr>\n" ;
  226. $class = ( $class == 'even' ) ? 'odd' : 'even' ;
  227. }
  228. // list block classes for add (not instances)
  229. foreach( $block_arr as $bid => $block ) {
  230. $description4show = '' ;
  231. foreach( $block_configs as $bconf ) {
  232. if( $block['show_func'] == $bconf['show_func'] && $block['func_file'] == $bconf['file'] && ( empty( $bconf['template'] ) || $block['template'] == $bconf['template'] ) ) {
  233. if( ! empty( $bconf['description'] ) ) $description4show = $myts->makeTboxData4Show( $bconf['description'] ) ;
  234. }
  235. }
  236. echo "
  237. <tr>
  238. <td class='$class' align='left'>
  239. ".$myts->makeTboxData4Edit($block['name'])."
  240. </td>
  241. <td class='$class' align='left' colspan='4'>
  242. $description4show
  243. </td>
  244. <td class='$class' align='center'>
  245. <input type='submit' name='addblock[$bid]' value='"._ADD."' />
  246. </td>
  247. </tr>
  248. \n" ;
  249. $class = ( $class == 'even' ) ? 'odd' : 'even' ;
  250. }
  251. echo "
  252. <tr>
  253. <td class='foot' align='center' colspan='6'>
  254. <input type='hidden' name='query4redirect' value='$query4redirect' />
  255. <input type='hidden' name='fct' value='blocksadmin' />
  256. <input type='hidden' name='op' value='order2' />
  257. ".$xoopsGTicket->getTicketHtml( __LINE__ , 1800 , 'myblocksadmin' )."
  258. <input type='submit' name='submit' value='"._SUBMIT."' />
  259. </td>
  260. </tr>
  261. </table>
  262. </form>\n" ;
  263. }
  264. // for 2.2
  265. function list_groups2()
  266. {
  267. global $target_mid , $target_mname , $xoopsDB ;
  268. $result = $xoopsDB->query( "SELECT i.instanceid,i.title FROM ".$xoopsDB->prefix("block_instance")." i LEFT JOIN ".$xoopsDB->prefix("newblocks")." b ON i.bid=b.bid WHERE b.mid='$target_mid'" ) ;
  269. $item_list = array() ;
  270. while( list( $iid , $title ) = $xoopsDB->fetchRow( $result ) ) {
  271. $item_list[ $iid ] = $title ;
  272. }
  273. $form = new MyXoopsGroupPermForm( _MD_AM_ADGS , 1 , 'block_read' , '' ) ;
  274. if( $target_mid > 1 ) {
  275. $form->addAppendix( 'module_admin' , $target_mid , $target_mname . ' ' . _AM_ACTIVERIGHTS ) ;
  276. $form->addAppendix( 'module_read' , $target_mid , $target_mname .' ' . _AM_ACCESSRIGHTS ) ;
  277. }
  278. foreach( $item_list as $item_id => $item_name) {
  279. $form->addItem( $item_id , $item_name ) ;
  280. }
  281. echo $form->render() ;
  282. }
  283. if( ! empty( $_POST['submit'] ) ) {
  284. if ( ! $xoopsGTicket->check( true , 'myblocksadmin' ) ) {
  285. redirect_header(XOOPS_URL.'/',3,$xoopsGTicket->getErrors());
  286. }
  287. include( "mygroupperm.php" ) ;
  288. redirect_header( XOOPS_URL."/modules/".$xoopsModule->dirname()."/admin/myblocksadmin.php$query4redirect" , 1 , _MD_AM_DBUPDATED );
  289. }
  290. xoops_cp_header() ;
  291. if( file_exists( './mymenu.php' ) ) include( './mymenu.php' ) ;
  292. echo "<h3 style='text-align:left;'>$target_mname</h3>\n" ;
  293. if( ! empty( $block_arr ) ) {
  294. echo "<h4 style='text-align:left;'>"._AM_BADMIN."</h4>\n" ;
  295. list_blockinstances() ;
  296. }
  297. list_groups2() ;
  298. xoops_cp_footer() ;
  299. ?>