Location: PHPKode > projects > TPEngine > tpengine-1.87beta/admin/index.php
<?php
/* $Id: index.php,v 1.0 drscream Exp $ */
/*
          TPEngine - PHP/MySQL Protocol System
        ==============================================
            (c) 2005 by
               Thomas Merkel      <hide@address.com>
               David Hoess	  <hide@address.com>
	       Uwe Schiber	  <hide@address.com>

          download the latest version:
            http://tpengine.sourceforge.net

          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.

        ==============================================

*/

include "common.inc.php";

$t = 1;

if( $action == "logout" ) {
  session_destroy();
  header("Location: index.php");
  exit;
}

tp_header();

/*
 * ==========================================
 *              <root>
 * ==========================================
 */
if( $action == "" )
{
	// try to determine version
	$current_version = '';
	
	print '<b>TPE - Administrative Center</b><br><br>';
	print 'Welcome '.$g_user.', to the administrative center of your TPE.
	       <br>Please keep in mind that tpe is still <u>beta software</u> and may sometimes not work as expected.<br>';

	print '<font color="darkblue">tpe version information</font><font size="1"><br>';
	print 'Your version: <b>'.$config['version'].'</b><br>';
	print '</font><br>';

	print '<font color="darkblue">System version information</font><font size="1"><br>
                PHP: <b>'.phpversion().'</b><br>
                MySQL: <b>'.mysql_get_server_info().'</b><br>
               </font><br>';
	$loadavg = @file('/proc/loadavg');
	if( $loadavg ) {
		$load = explode(' ', $loadavg[0]);
		print '<font color="darkblue">Average system load</font><font size="1"><br>
			Last minute: <b>'.$load[0].'</b><br>
			Last 5 minutes: <b>'.$load[1].'</b><br>
			Last 15 minutes: <b>'.$load[2].'</b><br>
		       </font>';
	}

	print '<br><br>Last 50 Admin-actions:<br><table width="50%" border="0" cellspacing="0" cellpadding="3">
		<tr>
		  <td><b>Date/Time</b></td>
		  <td><b>Logtype</b></td>
		  <td><b>Action</b></td>
		</tr>';
	$result = query( "SELECT logtype, logtime, logaction FROM ".$pref."adminlog ORDER BY logtime DESC limit 50" );
	while( $adminlog = mysql_fetch_array($result) )	{
		print "<tr>
    	                <td>".date('d.m.Y - H:i', $adminlog[logtime])."</td>
	                <td>$adminlog[logtype]</td>
    	                <td>$adminlog[logaction]</td>
	               </tr>";
	}
	print '</table>';
}


/*
 * ==========================================
 *              Settings
 * ==========================================
 */
elseif( $action == "EditSettings" )
{
  print '<b>Global Settings</b><br><br>';
  print '<form method="post" action="index.php">
          <table width="100%" border="0" cellspacing="0" cellpadding="4">';
	  
  // key/val
  $a_registry = array();
  $r_registry = query("SELECT keyname, keyvalue, keytype, keydescription, keydetails, keygroupid, keydisplayorder FROM $pref"."registry ORDER BY keydisplayorder ASC");
  
  //print(mysql_num_rows($r_registry));
  while( $registry = mysql_fetch_array($r_registry) ) {
    $a_registry[$registry['keygroupid']][] = $registry;
  }
	
  // groups
  $i = 0;
  $r_registrygroup = query("SELECT keygroupname, keygroupid, keygroupdisplayorder FROM $pref"."registrygroup 	ORDER BY keygroupdisplayorder ASC");

  //print(mysql_num_rows($r_registrygroup));
  while( $registrygroup = mysql_fetch_array($r_registrygroup) )	{
    print '<tr>
             <td colspan="2" bgcolor="#999999">
              <font size="2" color="white"><b>'.$registrygroup['keygroupname'].'</b></font>
             </td>
           </tr>';
			
    while( list(, $registry) = @each($a_registry[$registrygroup['keygroupid']]) ) {
	if( $registry['keygroupid'] == 0 ) // 0 -> hide
	  continue;
	
	print '<tr>
                 <td'.($i % 2 == 0 ? ' bgcolor="#eeeeee"' : '').' valign="top" width="50%"><b>'.$registry['keydescription'].'</b>';
	
	if( $registry['keydetails'] ) {
	  print '<font size="1"><br>'.$registry['keydetails'].'</font>';
	}
	print '</td>';
				
	print'<td'.($i % 2 == 0 ? ' bgcolor="#eeeeee"' : '').' valign="top" width="50%">';

	switch( $registry['keytype'] ) {
	  case 'boolean':
	    print '<input type="radio" name="Xconfig['.$registry['keyname'].']" value="1"' . ( $registry['keyvalue'] ? " checked" : "" ) . '> Yes 
                   <input type="radio" name="Xconfig['.$registry['keyname'].']" value="0"' . ( !$registry['keyvalue'] ? " checked" : "" ) . '> No';						
	    break;
	  case 'integer':
	    print '<input class="tbinput" type="text" size="6" name="Xconfig['.$registry['keyname'].']" value="'.intval($registry['keyvalue']).'">';
	    break;
	  case 'array':
	    print '<textarea class="tbinput" cols="60" rows="8" name="Xconfig['.$registry['keyname'].']">'.htmlspecialchars($registry['keyvalue']).'</textarea>';
	    break;
	  case 'string':
	    print '<input type="text" class="tbinput" name="Xconfig['.$registry['keyname'].']" value="'.htmlspecialchars($registry['keyvalue']).'">';
	    break;
	}
	  
      print '</td></tr>';
      $i++;
    }			
  }
	
  print '</table>
	  <br>
	  <center>
	    <input type="hidden" name="action" value="WriteSettings">
	    <input type="submit" name="update_settings" value="Save settings">
	  </center>
	</form>';
}



/*
 * ==========================================
 *              WriteSettings
 * ==========================================
 */
elseif( $action == "WriteSettings" )
{
	//var_dump($Xconfig);
	while( list($key, $value) = each($Xconfig) )
	{
		query("UPDATE $pref"."registry SET keyvalue='".addslashes($value)."' WHERE keyname='".$key."'");
	}
	print '<b>Settings saved</b><br><br>
	       Settings have been saved.';
}


tp_footer();
?>
Return current item: TPEngine