source: temp/test-xoops.ec-cube.net/html/modules/tinyd0/admin/myblocksadmin2.php @ 405

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