source: temp/test-xoops.ec-cube.net/html/include/cp_functions.php @ 405

Revision 405, 21.9 KB checked in by root, 20 years ago (diff)
Line 
1<?php
2// $Id: cp_functions.php,v 1.5 2006/05/01 02:37:26 onokazu 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//  ------------------------------------------------------------------------ //
27define('XOOPS_CPFUNC_LOADED', 1);
28
29function xoops_cp_header()
30{
31    global $xoopsConfig, $xoopsUser;
32    if ($xoopsConfig['gzip_compression'] == 1) {
33        ob_start("ob_gzhandler");
34    } else {
35        ob_start();
36    }
37    if (!headers_sent()) {
38        header ('Content-Type:text/html; charset='._CHARSET);
39        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
40        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
41        header('Cache-Control: no-store, no-cache, must-revalidate');
42        header("Cache-Control: post-check=0, pre-check=0", false);
43        header("Pragma: no-cache");
44        }
45    echo "<!DOCTYPE html PUBLIC '//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
46    echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._LANGCODE.'" lang="'._LANGCODE.'">
47    <head>
48    <meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />
49    <meta http-equiv="content-language" content="'._LANGCODE.'" />
50    <title>'.htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES).' Administration</title>
51    <script type="text/javascript" src="'.XOOPS_URL.'/include/xoops.js"></script>
52    ';
53    echo '<link rel="stylesheet" type="text/css" media="all" href="'.XOOPS_URL.'/xoops.css" />';
54        echo '<link rel="stylesheet" type="text/css" media="all" href="'.XOOPS_URL.'/modules/system/style.css" />';
55        include_once XOOPS_CACHE_PATH.'/adminmenu.php';
56        $moduleperm_handler =& xoops_gethandler('groupperm');
57        $admin_mids = $moduleperm_handler->getItemIds('module_admin', $xoopsUser->getGroups());
58
59        $module_handler =& xoops_gethandler('module');
60        $modules =& $module_handler->getObjects(new
61Criteria('mid', "(".implode(',', $admin_mids).")", 'IN'), true);
62        $admin_mids = array_keys($modules);
63
64?>
65
66<script type='text/javascript'>
67<!--
68var thresholdY = 15; // in pixels; threshold for vertical repositioning of a layer
69var ordinata_margin = 20; // to start the layer a bit above the mouse vertical coordinate
70// -->
71</script>
72
73<script type='text/javascript' src='<?php echo XOOPS_URL."/include/layersmenu.js";?>'></script>
74
75<script type='text/javascript'>
76<!--
77<?php
78        echo $xoops_admin_menu_js;
79?>
80function moveLayers() {
81<?php
82        foreach ( $admin_mids as $adm ) {
83            if (isset($xoops_admin_menu_ml[$adm])) {
84                echo $xoops_admin_menu_ml[$adm];
85            }
86        }
87?>
88}
89function shutdown() {
90<?php
91        foreach ( $admin_mids as $adm ) {
92            if (isset($xoops_admin_menu_sd[$adm])) {
93                echo $xoops_admin_menu_sd[$adm];
94            }
95        }
96?>
97}
98if (NS4) {
99document.onmousedown = function() { shutdown(); }
100} else {
101document.onclick = function() { shutdown(); }
102}
103// -->
104</script>
105
106<?php
107        $logo = file_exists(XOOPS_THEME_URL."/".getTheme()."/images/logo.gif") ? XOOPS_THEME_URL."/".getTheme()."/images/logo.gif" : XOOPS_URL."/images/logo.gif";
108        echo "</head>
109        <body>
110        <table border='0' width='100%' cellspacing='0' cellpadding='0'>
111          <tr>
112            <td bgcolor='#2F5376'><a href='http://xoopscube.org/' target='_blank'><img src='".XOOPS_URL."/modules/system/images/logo.gif' alt='".htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES)."' /></a></td>
113            <td align='right' bgcolor='#2F5376' colspan='2'><img src='".XOOPS_URL."/modules/system/images/xoops2.gif' alt='' /></td>
114          </tr>
115          <tr>
116            <td align='left' colspan='3' class='bg5'>
117              <table border='0' width='100%' cellspacing='0' cellpadding='0'>
118                <tr>
119                  <td width='1%'><img src='".XOOPS_URL."/modules/system/images/hbar_left.gif' width='10' height='23' /></td>
120                  <td background='".XOOPS_URL."/modules/system/images/hbar_middle.gif'>&nbsp;<a href='".XOOPS_URL."/admin.php'>"._CPHOME."</a><!--//&nbsp;|&nbsp;<a href='".XOOPS_URL."/admin.php?xoopsorgnews=1'>XOOPS News</a>//--></td>
121                  <td background='".XOOPS_URL."/modules/system/images/hbar_middle.gif' align='right'><a href='".XOOPS_URL."/user.php?op=logout'>"._LOGOUT."</a>&nbsp;|&nbsp;<a href='".XOOPS_URL."/'>"._YOURHOME."</a> &nbsp;</td>
122                  <td width='1%'><img src='".XOOPS_URL."/modules/system/images/hbar_right.gif' width='10' height='23' /></td>
123                </tr>
124              </table>
125            </td>
126          </tr>
127        </table>
128        <table border='0' cellpadding='0' cellspacing='0' width='100%'>
129          <tr>
130            <td width='2%' valign='top' class='bg5'  background='".XOOPS_URL."/modules/system/images/bg_menu.gif' align='center'></td>
131            <td width='15%' valign='top' class='bg5' align='center'><img src='".XOOPS_URL."/modules/system/images/menu.gif' /><br />
132              <table border='0' cellpadding='4' cellspacing='0' width='100%'>";
133        foreach ( $admin_mids as $adm ) {
134            if ( !empty($xoops_admin_menu_ft[$adm]) ) {
135                echo "<tr><td align='center'>".$xoops_admin_menu_ft[$adm]."</td></tr>";
136            }
137        }
138        echo "
139              </table>
140              <br />
141            </td>
142            <td align='left' valign='top' width='82%'>
143              <div class='content'><br />\n";
144}
145
146function xoops_cp_footer()
147{
148    global $xoopsConfig, $xoopsLogger;
149    echo"
150              </div><br />
151            </td>
152            <td width='1%' background='".XOOPS_URL."/modules/system/images/bg_content.gif'></td>
153          </tr>
154          <tr>
155            <td align='center' colspan='4' class='bg5' height='15'>
156              <table border='0' width='100%' cellspacing='0' cellpadding='0'>
157                <tr>
158                  <td width='1%'><img src='".XOOPS_URL."/modules/system/images/hbar_left.gif' width='10' height='23' /></td>
159                  <td width='98%' background='".XOOPS_URL."/modules/system/images/hbar_middle.gif' align='center'><div class='fontSmall'>Powered by&nbsp;".XOOPS_VERSION." &copy; 2001-2005 <a href='http://xoopscube.org/' target='_blank'>The XOOPS Cube Project</a></div></td><td width='1%'><img src='".XOOPS_URL."/modules/system/images/hbar_right.gif' width='10' height='23' /></td>
160                </tr>
161              </table>
162            </td>
163          </tr>
164        </table>";
165    include XOOPS_CACHE_PATH.'/adminmenu.php';
166    echo $xoops_admin_menu_dv;
167    echo "
168        </body>
169      </html>
170    ";
171    if ($xoopsConfig['debug_mode'] == 2) {
172        echo '<script type="text/javascript">
173        <!--//
174        debug_window = openWithSelfMain("", "popup", 680, 450, true);
175        ';
176        $content = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.htmlspecialchars($xoopsConfig['sitename']).'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($xoopsConfig['theme_set']).'" /></head><body>'.$xoopsLogger->dumpAll().'<div style="text-align:center;"><input class="formButton" value="'._CLOSE.'" type="button" onclick="javascript:window.close();" /></div></body></html>';
177        $lines = preg_split("/(\r\n|\r|\n)( *)/", $content);
178        foreach ($lines as $line) {
179            echo 'debug_window.document.writeln("'.str_replace('"', '\"', $line).'");';
180        }
181        echo '
182        debug_window.document.close();
183        //-->
184        </script>';
185    }
186    ob_end_flush();
187}
188
189// We need these because theme files will not be included
190function OpenTable()
191{
192    echo "<table width='100%' border='0' cellspacing='1' cellpadding='8' style='border: 2px solid #2F5376;'><tr class='bg4'><td valign='top'>\n";
193}
194
195function CloseTable()
196{
197    echo '</td></tr></table>';
198}
199
200function themecenterposts($title, $content)
201{
202    echo '<table cellpadding="4" cellspacing="1" width="98%" class="outer"><tr><td class="head">'.$title.'</td></tr><tr><td><br />'.$content.'<br /></td></tr></table>';
203}
204
205function myTextForm($url , $value)
206{
207    return '<form action="'.$url.'" method="post"><input type="submit" value="'.$value.'" /></form>';
208}
209
210function xoopsfwrite()
211{
212    if ($_SERVER['REQUEST_METHOD'] != 'POST') {
213        return false;
214    } else {
215
216    }
217    if (!xoops_refcheck()) {
218        return false;
219    } else {
220
221    }
222    return true;
223}
224
225function xoops_module_get_admin_menu()
226{
227    /************************************************************
228    * Based on:
229    * - PHP Layers Menu 1.0.7(c)2001,2002 Marco Pratesi <[email protected]>
230    * - TreeMenu 1.1 - Bjorge Dijkstra <[email protected]>
231    ************************************************************/
232    $abscissa_step = 90;        // step for the left boundaries of layers
233    $abscissa_offset = 15;        // to choose the horizontal coordinate start offset for the layers
234    $rightarrow = "";
235    // the following is to support browsers not detecting the mouse position
236    $ordinata_step = 15;        // estimated value of the number of pixels between links on a layer
237    $ordinata[1] = 150-$ordinata_step;// to choose the vertical coordinate start offset for the layers
238    $moveLayers = array();
239    $shutdown = array();
240    $firstleveltable = array();
241
242    /*********************************************/
243    /* read file to $tree array                  */
244    /* tree[x][0] -> tree level                  */
245    /* tree[x][1] -> item text                   */
246    /* tree[x][2] -> item link                   */
247    /* tree[x][3] -> link target                 */
248    /* tree[x][4] -> module id                   */
249    /*********************************************/
250
251    $js = "";
252    $maxlevel = 0;
253    $cnt = 1;
254    $module_handler =& xoops_gethandler('module');
255    $criteria = new CriteriaCompo();
256    $criteria->add(new Criteria('hasadmin', 1));
257    $criteria->add(new Criteria('isactive', 1));
258    $criteria->setSort('mid');
259    $mods =& $module_handler->getObjects($criteria);
260    foreach ($mods as $mod) {
261        // RMV-NOTIFY:
262        // Why need 'adminindex' defined??  Should just be for ALL modules
263        // because sometimes comments, notification gives options but
264        // module may have no other admin functions...
265        /*if ($mod->getInfo('adminindex') && trim($mod->getInfo('adminindex')) != '') {*/
266            $tree[$cnt][0] = 1;
267            $tree[$cnt][5] = "<img src='\".XOOPS_URL.\"/modules/".$mod->getVar('dirname')."/".$mod->getInfo('image')."' alt='' />";
268            $tree[$cnt][1] = $mod->getVar('name');
269            $tree[$cnt][2] = "\".XOOPS_URL.\"/modules/".$mod->getVar('dirname')."/".trim($mod->getInfo('adminindex'));
270            $tree[$cnt][3] = "";
271            $tree[$cnt][4] = $mod->getVar('mid');
272            $tree[$cnt][6] = "<b>\"._VERSION.\":</b> ".round($mod->getVar('version')/100 , 2)."<br /><b>\"._DESCRIPTION.\":</b> ".$mod->getInfo('description');
273            $layer_label[$cnt] = "L" . $cnt;
274            if ( $tree[$cnt][0] > $maxlevel ) {
275                $maxlevel = $tree[$cnt][0];
276            }
277            $cnt++;
278            $adminmenu = $mod->getAdminMenu();
279            if ($mod->getVar('hasnotification') || ($mod->getInfo('config') && is_array($mod->getInfo('config'))) || ($mod->getInfo('comments') && is_array($mod->getInfo('comments')))) {
280                $adminmenu[] = array('link' => '".XOOPS_URL."/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod='.$mod->getVar('mid'), 'title' => _PREFERENCES, 'absolute' => true);
281            }
282            if (!empty($adminmenu)) {
283                foreach ( $adminmenu as $menuitem ) {
284                    $menuitem['link'] = trim($menuitem['link']);
285                    $menuitem['target'] = isset($menuitem['target']) ? trim($menuitem['target']) : '';
286                    $tree[$cnt][0] = 2;
287                    $tree[$cnt][1] = trim($menuitem['title']);
288                    if (isset($menuitem['absolute']) && $menuitem['absolute']) {
289                        $tree[$cnt][2] = (empty($menuitem['link'])) ? "#" : $menuitem['link'];
290                    } else {
291                        $tree[$cnt][2] = (empty($menuitem['link'])) ? "#" : "\".XOOPS_URL.\"/modules/".$mod->getVar('dirname')."/".$menuitem['link'];
292                    }
293                    $tree[$cnt][3] = (empty($menuitem['target'])) ? "" : $menuitem['target'];
294                    $tree[$cnt][4] = $mod->getVar('mid');
295                    $layer_label[$cnt] = "L" . $cnt;
296                    if ($tree[$cnt][0] > $maxlevel) {
297                        $maxlevel = $tree[$cnt][0];
298                    }
299                    $cnt++;
300                }
301            }
302        /*
303        }*/
304    }
305    $tmpcount = count($tree);
306    $tree[$tmpcount+1][0] = 0;
307    for ( $i = 0; $i < $maxlevel; $i++) {
308        $abscissa[$i] = $i * $abscissa_step + $abscissa_offset;
309    }
310    for ( $cnt = 1; $cnt <= $tmpcount; $cnt++) {        // this counter scans all nodes
311        // assign the layers name to the current hierarchical level,
312        // to keep trace of the route leading to the current node on the tree
313        $layername[$tree[$cnt][0]] = $layer_label[$cnt];
314
315        // assign the starting vertical coordinates for all sublevels
316        for ( $i = $tree[$cnt][0] + 1; $i < $maxlevel; $i++) {
317            $ordinata[$i] = $ordinata[$i-1] + 1.5*$ordinata_step;
318        }
319        // increment the starting vertical coordinate for the current sublevel
320        if ($tree[$cnt][0] < $maxlevel) {
321            $ordinata[$tree[$cnt][0]] += $ordinata_step;
322        }
323        if ($tree[$cnt+1][0]>$tree[$cnt][0] && $cnt<$tmpcount) {                        // the node is not a leaf, hence it has at least a child
324            // initialize the corresponding layer content trought a void string
325            $layer[$layer_label[$cnt]] = "";
326            // prepare the popUp function related to the children
327            $js .= "function popUp" . $layer_label[$cnt] . "() {\n" . "shutdown();\n";
328            for ($i=1; $i<=$tree[$cnt][0]; $i++) {
329                $js .= "popUp(\\\"" . $layername[$i] . "\\\",true);\n";
330            }
331            $js .= "}\n";
332
333            // geometrical parameters are assigned to the new layer, related to the above mentioned children
334            if (!isset($moveLayers[$tree[$cnt][4]])) {
335                $moveLayers[$tree[$cnt][4]] = "setleft('" . $layer_label[$cnt] . "'," . $abscissa[$tree[$cnt][0]] . ");\n";
336            } else {
337                $moveLayers[$tree[$cnt][4]] .= "setleft('" . $layer_label[$cnt] . "'," . $abscissa[$tree[$cnt][0]] . ");\n";
338                }
339                if (!isset($moveLayers[$tree[$cnt][4]])) {
340                    $moveLayers[$tree[$cnt][4]] = "settop('" . $layer_label[$cnt] . "'," . $ordinata[$tree[$cnt][0]] . ");\n";
341                } else {
342                    $moveLayers[$tree[$cnt][4]] .= "settop('" . $layer_label[$cnt] . "'," . $ordinata[$tree[$cnt][0]] . ");\n";
343                }
344                //$moveLayers[$tree[$cnt][4]] .= "setwidth('" . $layer_label[$cnt] . "'," . $abscissa_step . ");\n";
345
346                // the new layer is accounted for in the shutdown() function
347                if (!isset($shutdown[$tree[$cnt][4]])) {
348                    $shutdown[$tree[$cnt][4]] = "popUp('" . $layer_label[$cnt] . "',false);\n";
349                } else {
350                    $shutdown[$tree[$cnt][4]] .= "popUp('" . $layer_label[$cnt] . "',false);\n";
351                }
352            }
353            if ($tree[$cnt+1][0]>$tree[$cnt][0] && $cnt<$tmpcount) {
354                // not a leaf
355                $currentarrow = $rightarrow;
356            } else {
357                // a leaf
358                $currentarrow = "";
359            }
360            /* */
361            $currentlink = $tree[$cnt][2];
362            /* */
363            /*
364            if ( $tree[$cnt+1][0] > $tree[$cnt][0] && $cnt < $tmpcount) {
365                // not a leaf
366                $currentlink = "#";
367            } else {
368                // a leaf
369                $currentlink = $tree[$cnt][2];
370            }
371            */
372            if ($tree[$cnt][3] != "") {
373                $currenttarget = " target='" . $tree[$cnt][3] . "'";
374            } else {
375                $currenttarget = "";
376            }
377            if ($tree[$cnt][0] > 1) {
378                // the hierarchical level is > 1, hence the current node is not a child of the root node
379                // handle accordingly the corresponding link, distinguishing if the current node is a leaf or not
380                if ( $tree[$cnt+1][0] > $tree[$cnt][0] && $cnt < $tmpcount ) {        // not a leaf
381                    $onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY) ; popUp" . $layer_label[$cnt] . "();";
382                    $onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY, event) ; popUp" . $layer_label[$cnt] . "();";
383                } else {        // a leaf
384                    $onmouseover = " onmouseover='popUp" . $layername[$tree[$cnt][0]-1] . "();";
385                }
386                $layer[$layername[$tree[$cnt][0]-1]] .= "<img src='\".XOOPS_URL.\"/images/pointer.gif' width='8' height='8' alt='' />&nbsp;<a href='" . $currentlink . "'" . $onmouseover . "'" . $currenttarget . ">" .$tree[$cnt][1]. "</a>" . $currentarrow . "<br />\n";
387            } elseif ($tree[$cnt][0] == 1) {
388                // the hierarchical level is = 1, hence the current node is a child of the root node
389                // handle accordingly the corresponding link, distinguishing if the current node is a leaf or not
390                if ($tree[$cnt+1][0]>$tree[$cnt][0] && $cnt<$tmpcount) {
391                    // not a leaf
392                    $onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY) ; popUp" . $layer_label[$cnt] . "();";
393                    $onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY,event) ; popUp" . $layer_label[$cnt] . "();";
394                } else {
395                    // a leaf
396                   $onmouseover = " onmouseover='shutdown();";
397                }
398                if (!isset($firstleveltable[$tree[$cnt][4]])) {
399                    $firstleveltable[$tree[$cnt][4]] = "<a href='" . $currentlink . "'" . $onmouseover . "'" . $currenttarget . ">" . $tree[$cnt][5] . "</a>" . $currentarrow . "<br />\n";
400                } else {
401                    $firstleveltable[$tree[$cnt][4]] .= "<a href='" . $currentlink . "'" . $onmouseover . "'" . $currenttarget . ">" . $tree[$cnt][5] . "</a>" . $currentarrow . "<br />\n";
402                }
403            }
404        }        // end of the "for" cycle scanning all nodes
405
406        $cellpadding = 10;
407        $width = $abscissa_step - $cellpadding;
408        $menu_layers = "";
409        for ( $cnt = 1; $cnt <= $tmpcount; $cnt++ ) {
410            if (!($tree[$cnt+1][0]<=$tree[$cnt][0])) {
411                $menu_layers .= "<div id='".$layer_label[$cnt]."' style='position: absolute; visibility: hidden; z-index:1000;'><table class='outer' width='150' cellspacing='1'><tr><th nowrap='nowrap'>".$tree[$cnt][1]."</th></tr><tr><td class='even' nowrap='nowrap'>".$layer[$layer_label[$cnt]]."<div style='margin-top: 5px; font-size: smaller; text-align: right;'><a href='#' onmouseover='shutdown();'>["._CLOSE."]</a></div></td></tr><tr><th style='font-size: smaller; text-align: left;'>".$tree[$cnt][5]."<br />".$tree[$cnt][6]."</th></tr></table></div>\n";
412            }
413        }
414        $menu_layers .= "<script language='JavaScript'>\n<!--\nmoveLayers();\nloaded = 1;\n// -->\n</script>\n";
415        $content = "<"."?php\n";
416        $content .= "\$xoops_admin_menu_js = \"".$js."\";\n";
417        foreach ( $moveLayers as $k => $v ){
418            $content .= "\$xoops_admin_menu_ml[$k] = \"".$v."\";\n";
419        }
420        foreach ( $shutdown as $k => $v ){
421            $content .= "\$xoops_admin_menu_sd[$k] = \"".$v."\";\n";
422    }
423    foreach ( $firstleveltable as $k => $v ){
424        $content .= "\$xoops_admin_menu_ft[$k] = \"".$v."\";\n";
425    }
426    $content .= "\$xoops_admin_menu_dv = \"".$menu_layers."\";\n";
427    $content .= "\n?".">";
428    return $content;
429}
430
431function xoops_module_write_admin_menu($content)
432{
433    if (!xoopsfwrite()) {
434        return false;
435    }
436    $filename = XOOPS_CACHE_PATH.'/adminmenu.php';
437    if ( !$file = fopen($filename, "w") ) {
438        echo 'failed open file';
439        return false;
440    }
441    if ( fwrite($file, $content) == -1 ) {
442        echo 'failed write file';
443        return false;
444    }
445    fclose($file);
446    return true;
447}
448?>
Note: See TracBrowser for help on using the repository browser.