Subversion Repositories computer_asset_manager_v2

Rev

Rev 70 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php


class Admin {

   private $menu = array(
      'motd' => 'Edit MOTD',
      'devicetypes' => 'Edit Device Types',
      'dbconsistency' => 'Verify Database',
      'activitylog' => 'View Activity Log'
      );
   
   function run () {
      global $dbConnection;
      global $url;
      
      $action;
      
      if ( ! isset( $_REQUEST['action'] ) ) { // just show the menu
         return $this->menu( $url );
      } else {
         $action = $_REQUEST['action'];
      }
      if ( method_exists( $this, $action ) ) {
         return $this->$action($url, $dbConnection);
      } else {
         return "<p>Action '$action' is not implemented yet</p>";
      }
   }
   
   function menu ($url) {
      $return = array();
      foreach ( $this->menu as $action => $prompt ) {
         $return[] = "<a href='$url?module=admin&action=$action'>$prompt</a>\n";
      }
      return '<table><tr><td>' . join( "</tr></td>\n<tr><td>", $return ) . "</td>\n</tr></table>";
   }
   
   function motd( $url, $connection ) {
      $return = '';
      if ( isset( $_REQUEST['new_motd'] ) ) {
         $motd = $connection->real_escape_string( $_REQUEST['new_motd'] );
         $query = "update _system set key_value = '$motd' where group_name = 'program' and key_name = 'motd'";
         //print "<pre>$query</pre>"; die;
         $connection->doSQL( $query );
         $return = $this->menu($url);
      } else {
         $return = '<h3>Enter the Message of the Day</h3>';
         $return .= "<form action='$url' method='post'>\n";
         $return .= "<input type='hidden' name='module' value='admin'>\n";
         $return .= "<input type='hidden' name='action' value='motd'>\n";
         $return .= "<label MOTD><textarea name='new_motd'></textarea></label>\n";
         $return .= "<input type='submit' name='submit' value='Update'>\n";
         $return .= "</form>\n";
      }
      return $return;
   } // motd
   
   public function devicetypes( $url, $connection, $deviceType = null ) {
      require_once( 'devicetype.class.php' );
      
      if ( isset( $_REQUEST['id'] ) ) {
         $_SESSION['data']['DeviceType'] = new DeviceType( $_REQUEST['id']  );
         $_SESSION['data']['DeviceType']->edit( array( 'module' => 'admin', 'action' => 'devicetypes' ) );
      } else {
         return DeviceType::ShowSelectionList();
      }
      return '';
   }
      
} // class admin

?>