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

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