Location: PHPKode > projects > Astrocytes > htdocs/include/cp_functions.php
<?php

//  ------------------------------------------------------------------------ //
//                                                                           //
//            Astrocytes - Medical Managment Systems                         //
//              Copyright (c) 2005 astrocytes.org                            //
//              <http://www.astrocytes.org/>                                 //
//              <http://sourceforge.net/projects/astroarm/>                  //
//              BY YAZID JIBREL                                              //
//              hide@address.com                                       //
//              Based on XOOPS CMS <xoops.org>                               //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software <gnu.org>    //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
//  ------------------------------------------------------------------------ //
//  ------------------------------------------------------------------------ //
// Authors: author name (hide@address.com),                      //
// URL: http://www.astrocytes.org                                            //
// Package: Package name                                                     //
// Project: Astrocytes                                                       //
// version: 1.1                                                              //
// ------------------------------------------------------------------------- //
define('ASTRO_CPFUNC_LOADED', 1);

function astro_cp_header()
{
    global $astroConfig, $astroUser;
	if ($astroConfig['gzip_compression'] == 1) {
		ob_start("ob_gzhandler");
	} else {
		ob_start();
	}
	if (!headers_sent()) {
		header('Content-Type:text/html; charset='._CHARSET);
		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
		header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
		header('Cache-Control: no-store, no-cache, must-revalidate');
		header("Cache-Control: post-check=0, pre-check=0", false);
		header("Pragma: no-cache");
    }
	echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
	echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="'._LANGCODE.'" lang="'._LANGCODE.'">
	<head>
	<meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" />
	<meta http-equiv="content-language" content="'._LANGCODE.'" />
	<title>'.htmlspecialchars($astroConfig['sitename'], ENT_QUOTES).' Administration</title>
	<script type="text/javascript" src="'.ASTRO_URL.'/include/astro.js"></script>
	';
	echo '<link rel="stylesheet" type="text/css" media="all" href="'.ASTRO_URL.'/astro.css" />';
        echo '<link rel="stylesheet" type="text/css" media="all" href="'.ASTRO_URL.'/modules/system/style.css" />';
        include_once ASTRO_CACHE_PATH.'/adminmenu.php';
        $moduleperm_handler =& astro_gethandler('groupperm');
        $admin_mids =& $moduleperm_handler->getItemIds('module_admin', $astroUser->getGroups());
?>

<script type='text/javascript'>
<!--
var thresholdY = 15; // in pixels; threshold for vertical repositioning of a layer
var ordinata_margin = 20; // to start the layer a bit above the mouse vertical coordinate
// -->
</script>

<script type='text/javascript' src='<?php echo ASTRO_URL."/include/layersmenu.js";?>'></script>

<script type='text/javascript'>
<!--
<?php
		echo $astro_admin_menu_js;
?>
function moveLayers() {
<?php
		foreach ( $admin_mids as $adm ) {
			if (isset($astro_admin_menu_ml[$adm])) {
				echo $astro_admin_menu_ml[$adm];
			}
		}
?>
}
function shutdown() {
<?php
		foreach ( $admin_mids as $adm ) {
			if (isset($astro_admin_menu_sd[$adm])) {
				echo $astro_admin_menu_sd[$adm];
			}
		}
?>
}
if (NS4) {
document.onmousedown = function() { shutdown(); }
} else {
document.onclick = function() { shutdown(); }
}
// -->
</script>

<?php
        $logo = file_exists(ASTRO_THEME_URL."/".getTheme()."/images/logo.gif") ? ASTRO_THEME_URL."/".getTheme()."/images/logo.gif" : ASTRO_URL."/images/logo.gif";
        echo "</head>
        <body>
        <table border='0' width='100%' cellspacing='0' cellpadding='0'>
          <tr>
            <td bgcolor='#FFFFFF'><img src='".ASTRO_URL."/modules/system/images/logo.gif' alt='".$astroConfig['sitename']."' /></td>            
          </tr>
          <tr>
            <td align='left' colspan='3' class='bg5'>
              <table border='0' width='100%' cellspacing='0' cellpadding='0'>
                <tr>
                  <td width='1%'><a href='".ASTRO_URL."/'><img src='".ASTRO_URL."/modules/system/images/hbar_left.gif' width='102' height='30' /></a></td>
                  <td background='".ASTRO_URL."/modules/system/images/hbar_middle.gif'>&nbsp;<a href='".ASTRO_URL."/admin.php'>
				  <img src='".ASTRO_URL."/modules/system/images/control_panel.gif' />&nbsp;Control Panel</a>
				  &nbsp;<a href='".ASTRO_URL."/user.php?op=logout'><img src='".ASTRO_URL."/modules/system/images/logout.gif' />&nbsp;Logout</a>
				  &nbsp;<img src='".ASTRO_URL."/modules/system/images/rss.png' /><a href='".ASTRO_URL."/admin.php?astroorgnews=1'>&nbsp;astrocytes news & updates</a></td>
                     </tr>
              </table>
            </td>
          </tr>
        </table>
        <table border='0' cellpadding='0' cellspacing='0' width='100%'>
          <tr>
            <td width='15%' valign='top' class='bg5' align='center'><img src='".ASTRO_URL."/modules/system/images/menu.gif' /><br />
              <table style='border-right: 1px solid #AAAAAA;' border='0' cellpadding='4' cellspacing='0' width='100%'>";
        foreach ( array_keys($astro_admin_menu_ft) as $adm ) {
            if ( in_array($adm, $admin_mids) ) {
                echo "<tr><td align='center'>".$astro_admin_menu_ft[$adm]."</td></tr>";
            }
        }
        echo "
              </table>
              <br />
            </td>
            <td align='left' valign='top' width='82%'>
              <div class='content'><br />\n";
}

function astro_cp_footer()
{
	global $astroConfig, $astroLogger;
	echo"
              </div><br />
            </td>
          </tr>
          <tr>
            <td align='center' colspan='4' class='bg5' height='15'>
            </td>
          </tr>
        </table>";
    include ASTRO_CACHE_PATH.'/adminmenu.php';
	echo $astro_admin_menu_dv;
	echo "
        </body>
      </html>
    ";
	if ($astroConfig['debug_mode'] == 2) {
		echo '<script type="text/javascript">
		<!--//
		debug_window = openWithSelfMain("", "popup", 680, 450, true);
		debug_window.document.clear();
		';
		$content = '<html><head><meta http-equiv="content-type" content="text/html; charset='._CHARSET.'" /><meta http-equiv="content-language" content="'._LANGCODE.'" /><title>'.$astroConfig['sitename'].'</title><link rel="stylesheet" type="text/css" media="all" href="'.getcss($astroConfig['theme_set']).'" /></head><body>'.$astroLogger->dumpAll().'<div style="text-align:center;"><input class="formButton" value="'._CLOSE.'" type="button" onclick="javascript:window.close();" /></div></body></html>';
		$lines = preg_split("/(\r\n|\r|\n)( *)/", $content);
		foreach ($lines as $line) {
			echo 'debug_window.document.writeln("'.str_replace('"', '\"', $line).'");';
		}
		echo '
		debug_window.focus();
		debug_window.document.close();
		//-->
		</script>';
	}
	ob_end_flush();
}

// We need these because theme files will not be included
function OpenTable()
{
	echo "<table width='100%' border='0' cellspacing='1' cellpadding='8' style='border: 2px solid #2F5376;'><tr class='bg4'><td valign='top'>\n";
}

function CloseTable()
{
	echo '</td></tr></table>';
}

function themecenterposts($title, $content)
{
	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>';
}

function myTextForm($url , $value)
{
	return '<form action="'.$url.'" method="post"><input type="submit" value="'.$value.'" /></form>';
}

function astrofwrite()
{
	if ($_SERVER['REQUEST_METHOD'] != 'POST') {
		return false;
	} else {

    }
	if (!astro_refcheck()) {
		return false;
	} else {

	}
    return true;
}

function astro_module_get_admin_menu()
{
    /************************************************************
	* Based on:
	* - PHP Layers Menu 1.0.7(c)2001,2002 Marco Pratesi <hide@address.com>
	* - TreeMenu 1.1 - Bjorge Dijkstra <hide@address.com>
	************************************************************/
	$abscissa_step = 90;        // step for the left boundaries of layers
	$abscissa_offset = 15;        // to choose the horizontal coordinate start offset for the layers
	$rightarrow = "";
	// the following is to support browsers not detecting the mouse position
	$ordinata_step = 15;        // estimated value of the number of pixels between links on a layer
	$ordinata[1] = 150-$ordinata_step;// to choose the vertical coordinate start offset for the layers
    $moveLayers = array();
	$shutdown = array();
	$firstleveltable = array();

    /*********************************************/
	/* read file to $tree array                  */
	/* tree[x][0] -> tree level                  */
	/* tree[x][1] -> item text                   */
	/* tree[x][2] -> item link                   */
	/* tree[x][3] -> link target                 */
	/* tree[x][4] -> module id                   */
	/*********************************************/

    $js = "";
	$maxlevel = 0;
	$cnt = 1;
	$module_handler =& astro_gethandler('module');
	$criteria = new CriteriaCompo();
	$criteria->add(new Criteria('hasadmin', 1));
	$criteria->add(new Criteria('isactive', 1));
	$criteria->setSort('mid');
	$mods =& $module_handler->getObjects($criteria);
	foreach ($mods as $mod) {
		// RMV-NOTIFY:
		// Why need 'adminindex' defined??  Should just be for ALL modules
		// because sometimes comments, notification gives options but
		// module may have no other admin functions...
		/*if ($mod->getInfo('adminindex') && trim($mod->getInfo('adminindex')) != '') {*/
			$tree[$cnt][0] = 1;
			$tree[$cnt][5] = "<img src='\".ASTRO_URL.\"/modules/".$mod->getVar('dirname')."/".$mod->getInfo('image')."' alt='' />";
			$tree[$cnt][1] = $mod->getVar('name');
			$tree[$cnt][2] = "\".ASTRO_URL.\"/modules/".$mod->getVar('dirname')."/".trim($mod->getInfo('adminindex'));
			$tree[$cnt][3] = "";
			$tree[$cnt][4] = $mod->getVar('mid');
			$tree[$cnt][6] = "<b>\"._VERSION.\":</b> ".round($mod->getVar('version')/100 , 2)."<br /><b>\"._DESCRIPTION.\":</b> ".$mod->getInfo('description');
			$layer_label[$cnt] = "L" . $cnt;
			if ( $tree[$cnt][0] > $maxlevel ) {
				$maxlevel = $tree[$cnt][0];
			}
			$cnt++;
			$adminmenu = $mod->getAdminMenu();
			if ($mod->getVar('hasnotification') || ($mod->getInfo('config') && is_array($mod->getInfo('config'))) || ($mod->getInfo('comments') && is_array($mod->getInfo('comments')))) {
				$adminmenu[] = array('link' => '".ASTRO_URL."/modules/system/admin.php?fct=preferences&amp;op=showmod&amp;mod='.$mod->getVar('mid'), 'title' => _PREFERENCES, 'absolute' => true);
			}
			if (!empty($adminmenu)) {
				foreach ( $adminmenu as $menuitem ) {
					$menuitem['link'] = trim($menuitem['link']);
					$menuitem['target'] = isset($menuitem['target']) ? trim($menuitem['target']) : '';
					$tree[$cnt][0] = 2;
					$tree[$cnt][1] = trim($menuitem['title']);
					if (isset($menuitem['absolute']) && $menuitem['absolute']) {
						$tree[$cnt][2] = (empty($menuitem['link'])) ? "#" : $menuitem['link'];
					} else {
						$tree[$cnt][2] = (empty($menuitem['link'])) ? "#" : "\".ASTRO_URL.\"/modules/".$mod->getVar('dirname')."/".$menuitem['link'];
					}
					$tree[$cnt][3] = (empty($menuitem['target'])) ? "" : $menuitem['target'];
					$tree[$cnt][4] = $mod->getVar('mid');
					$layer_label[$cnt] = "L" . $cnt;
					if ($tree[$cnt][0] > $maxlevel) {
						$maxlevel = $tree[$cnt][0];
					}
					$cnt++;
				}
			}
		/*
		}*/
	}
	$tmpcount = count($tree);
	$tree[$tmpcount+1][0] = 0;
	for ( $i = 0; $i < $maxlevel; $i++) {
		$abscissa[$i] = $i * $abscissa_step + $abscissa_offset;
	}
	for ( $cnt = 1; $cnt <= $tmpcount; $cnt++) {        // this counter scans all nodes
        // assign the layers name to the current hierarchical level,
        // to keep trace of the route leading to the current node on the tree
		$layername[$tree[$cnt][0]] = $layer_label[$cnt];

        // assign the starting vertical coordinates for all sublevels
		for ( $i = $tree[$cnt][0] + 1; $i < $maxlevel; $i++) {
			$ordinata[$i] = $ordinata[$i-1] + 1.5*$ordinata_step;
		}
		// increment the starting vertical coordinate for the current sublevel
		if ($tree[$cnt][0] < $maxlevel) {
			$ordinata[$tree[$cnt][0]] += $ordinata_step;
		}
		if ($tree[$cnt+1][0]>$tree[$cnt][0] && $cnt<$tmpcount) {                        // the node is not a leaf, hence it has at least a child
            // initialize the corresponding layer content trought a void string
			$layer[$layer_label[$cnt]] = "";
			// prepare the popUp function related to the children
			$js .= "function popUp" . $layer_label[$cnt] . "() {\n" . "shutdown();\n";
			for ($i=1; $i<=$tree[$cnt][0]; $i++) {
				$js .= "popUp(\\\"" . $layername[$i] . "\\\",true);\n";
			}
            $js .= "}\n";

            // geometrical parameters are assigned to the new layer, related to the above mentioned children
            if (!isset($moveLayers[$tree[$cnt][4]])) {
                $moveLayers[$tree[$cnt][4]] = "setleft('" . $layer_label[$cnt] . "'," . $abscissa[$tree[$cnt][0]] . ");\n";
            } else {
                $moveLayers[$tree[$cnt][4]] .= "setleft('" . $layer_label[$cnt] . "'," . $abscissa[$tree[$cnt][0]] . ");\n";
                }
                if (!isset($moveLayers[$tree[$cnt][4]])) {
                    $moveLayers[$tree[$cnt][4]] = "settop('" . $layer_label[$cnt] . "'," . $ordinata[$tree[$cnt][0]] . ");\n";
                } else {
                    $moveLayers[$tree[$cnt][4]] .= "settop('" . $layer_label[$cnt] . "'," . $ordinata[$tree[$cnt][0]] . ");\n";
                }
                //$moveLayers[$tree[$cnt][4]] .= "setwidth('" . $layer_label[$cnt] . "'," . $abscissa_step . ");\n";

                // the new layer is accounted for in the shutdown() function
                if (!isset($shutdown[$tree[$cnt][4]])) {
                    $shutdown[$tree[$cnt][4]] = "popUp('" . $layer_label[$cnt] . "',false);\n";
                } else {
                    $shutdown[$tree[$cnt][4]] .= "popUp('" . $layer_label[$cnt] . "',false);\n";
                }
            }
            if ($tree[$cnt+1][0]>$tree[$cnt][0] && $cnt<$tmpcount) {
                // not a leaf
                $currentarrow = $rightarrow;
            } else {
                // a leaf
                $currentarrow = "";
            }
            /* */
            $currentlink = $tree[$cnt][2];
            /* */
            /*
            if ( $tree[$cnt+1][0] > $tree[$cnt][0] && $cnt < $tmpcount) {
                // not a leaf
                $currentlink = "#";
            } else {
                // a leaf
                $currentlink = $tree[$cnt][2];
            }
            */
            if ($tree[$cnt][3] != "") {
                $currenttarget = " target='" . $tree[$cnt][3] . "'";
            } else {
                $currenttarget = "";
            }
            if ($tree[$cnt][0] > 1) {
                // the hierarchical level is > 1, hence the current node is not a child of the root node
                // handle accordingly the corresponding link, distinguishing if the current node is a leaf or not
                if ( $tree[$cnt+1][0] > $tree[$cnt][0] && $cnt < $tmpcount ) {        // not a leaf
                    $onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY) ; popUp" . $layer_label[$cnt] . "();";
					$onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY, event) ; popUp" . $layer_label[$cnt] . "();";
                } else {        // a leaf
                    $onmouseover = " onmouseover='popUp" . $layername[$tree[$cnt][0]-1] . "();";
                }
                $layer[$layername[$tree[$cnt][0]-1]] .= "<img src='\".ASTRO_URL.\"/images/pointer.gif' width='8' height='8' alt='' />&nbsp;<a href='" . $currentlink . "'" . $onmouseover . "'" . $currenttarget . ">" .$tree[$cnt][1]. "</a>" . $currentarrow . "<br />\n";
            } elseif ($tree[$cnt][0] == 1) {
                // the hierarchical level is = 1, hence the current node is a child of the root node
                // handle accordingly the corresponding link, distinguishing if the current node is a leaf or not
                if ($tree[$cnt+1][0]>$tree[$cnt][0] && $cnt<$tmpcount) {
                    // not a leaf
                    $onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY) ; popUp" . $layer_label[$cnt] . "();";
					$onmouseover = " onmouseover='moveLayerY(\\\"" . $layer_label[$cnt] . "\\\", currentY,event) ; popUp" . $layer_label[$cnt] . "();";
                } else {
                    // a leaf
                   $onmouseover = " onmouseover='shutdown();";
                }
                if (!isset($firstleveltable[$tree[$cnt][4]])) {
                    $firstleveltable[$tree[$cnt][4]] = "<a href='" . $currentlink . "'" . $onmouseover . "'" . $currenttarget . ">" . $tree[$cnt][5] . "</a>" . $currentarrow . "<br />\n";
                } else {
                    $firstleveltable[$tree[$cnt][4]] .= "<a href='" . $currentlink . "'" . $onmouseover . "'" . $currenttarget . ">" . $tree[$cnt][5] . "</a>" . $currentarrow . "<br />\n";
                }
            }
        }        // end of the "for" cycle scanning all nodes

        $cellpadding = 10;
        $width = $abscissa_step - $cellpadding;
        $menu_layers = "";
        for ( $cnt = 1; $cnt <= $tmpcount; $cnt++ ) {
            if (!($tree[$cnt+1][0]<=$tree[$cnt][0])) {
                $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";
            }
        }
        $menu_layers .= "<script language='JavaScript'>\n<!--\nmoveLayers();\nloaded = 1;\n// -->\n</script>\n";
        $content = "<"."?php\n";
        $content .= "\$astro_admin_menu_js = \"".$js."\";\n";
        foreach ( $moveLayers as $k => $v ){
            $content .= "\$astro_admin_menu_ml[$k] = \"".$v."\";\n";
        }
        foreach ( $shutdown as $k => $v ){
            $content .= "\$astro_admin_menu_sd[$k] = \"".$v."\";\n";
    }
    foreach ( $firstleveltable as $k => $v ){
        $content .= "\$astro_admin_menu_ft[$k] = \"".$v."\";\n";
    }
    $content .= "\$astro_admin_menu_dv = \"".$menu_layers."\";\n";
    $content .= "\n?".">";
    return $content;
}

function astro_module_write_admin_menu($content)
{
    if (!astrofwrite()) {
        return false;
    }
    $filename = ASTRO_CACHE_PATH.'/adminmenu.php';
    if ( !$file = fopen($filename, "w") ) {
        echo 'failed open file';
        return false;
    }
    if ( fwrite($file, $content) == -1 ) {
        echo 'failed write file';
        return false;
    }
    fclose($file);
    return true;
}
?>
Return current item: Astrocytes