Subversion Repositories computer_asset_manager_v2

Rev

Rev 45 | Rev 50 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php
   $VERSION='2.0a';
   $BUILD_DATE='20181118';
   $DB_REQUIRED_VERSION = '0.1';
   include_once( dirname(__FILE__) . '/include/functions.php');
   global $configuration;
   $error = '';

   $configStuff = loadConfig();
   if ( $configStuff['error'] ) {
      print $configStuff['error'];
      die;
   } else {
      $configuration = $configStuff['configuration'];
      $configPath = $configStuff['path'];
      unset( $configStuff );
   }
   
   // get include directories for libraries
   foreach ( $configuration['locations']['include_dirs'] as $key => $dir ) {
      ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $dir );
   }
   
   include_once( 'UsersPermissions.class.php' );
   include_once( 'UsersPermissionsDataSourceMySQLi.class.php' );
   include_once( 'DBQuery.class.php' );
   include_once( 'functions.php' );

   // since we are storing some user defined classes in the session, session
   // MUST be started after the class definitions are loaded
   session_start();

   // make the database connection
   $dbVersion = '';
   $dbConnection = new DBQuery( $configuration['database']['dbserver'],$configuration['database']['dbusername'], $configuration['database']['dbpassword'], $configuration['database']['dbname'] );
   if ( $dbConnection->connect_errno ) {
      $error = "Failed to connect to MySQL: (" . $dbConnection->connect_errno . ") " . $dbConnection->connect_error;
   } else {
      $dbVersion = $dbConnection->getOneDBValue( "select key_value from _system where group_name = 'database' and key_name = 'version'" );
   }

   //print "<pre>\nSession" . print_r($configuration,true) . '</pre>';
   

   // create a connection for the Users class
   global $connection;
   $connection = new usersPermissionsDataSourceMySQLi( 
         $dbConnection,
         $configuration['customUsersFields']
      );
   // if they are not logged in, set up for logging in
   if ( ! isset( $_SESSION['user'] ) ) {
      $_SESSION['user'] = new UsersPermissions( $configuration['customUsersFields'] );
   }
   
   
   // check if the user has request a log out.
   if ( isset( $_REQUEST['logout'] ) )
      $_SESSION['user']->logout();
   //Setup our HTML header here.
   if(!isset($page_title)) { $page_title = "Untitled"; }
   // set up our "here I am" variable
   $url = htmlentities($configuration['locations']['base_url'] . '/' . $configuration['locations']['main_script'] );
   $baseURL = htmlentities($configuration['locations']['base_url'] );

?>

<html>
   <head>
      <title><?php echo $page_title;?></title>
      <script language="javascript"> 
         function eToggle(anctag,darg) {
            var ele = document.getElementById(darg);
            var text = document.getElementById(anctag);
            if(ele.style.display == "block") {
               ele.style.display = "none";
               text.innerHTML = "Show " + darg;
            } else {
               ele.style.display = "block";
               text.innerHTML = "Hide " + darg;
            }
         } 
      </script>
     <link rel="stylesheet" type="text/css" href="camp.css">
   </head>
   <body>
      <div class="grid-container">
      <div class="titleimage">
         <h1>
            Computer Asset Management Program 
         </h1>
         <h2>
            Version <?php print "$VERSION, $BUILD_DATE"; ?>
         </h2>
      </div>
      <?php
         if ( $error ) {
            print "<h1>Serious Error encountered</h1><p>$error</p>";
            die($error);
         }
         if ( $dbVersion != $DB_REQUIRED_VERSION ) {
            print "<h1><b>Warning</b>: Database is version $dbVersion, but requires version $DB_REQUIRED_VERSION. Repair immediately</h1>";
            die;
         }
      ?>
      <?php
         if ( $_SESSION['user']->name() === null ) {
            /* 
             * we have to run this first since the last call, where name
             * is actually populated, returns an empty screen, but the
             * div still exists, so we check first, then if it is not
             * empty, do the div and page.
             */
            $page = $_SESSION['user']->HTML($connection);
            if ( $page ) {
               print "<div class='login'>\n$page\n</div>\n";
            }
         } elseif ( ! isset( $_SESSION['restrictions'] ) ) {
            // this must be new, so we have to build our where clause
            buildRestrictions();
         }
      ?>