Subversion Repositories computer_asset_manager_v2

Rev

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

<?php
include_once (dirname(__FILE__) . '/../include/functions.php');
global $configuration;
$error         = '';
$message       = array();

$configuration = loadConfig();
if ( $configuration['error'] ) {
   print $configuration['error'];
   die;
}

$configFilename = $configuration['path'];
$configuration = $configuration['configuration'];


// 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' );
include_once( 'users_table.php' );

$configuration['customUsersFields'] = $customFields;

$message[]     = "Reading from " . $configuration['locations']['config_dir'];
$dbConnection = new DBQuery( $configuration['database']['dbserver'],$configuration['database']['dbusername'], $configuration['database']['dbpassword'], $configuration['database']['dbname'] );
if ( $dbConnection->connect_errno ) {
   $message[] = "Failed to connect to MySQL: (" . $dbConnection->connect_errno . ") " . $dbConnection->connect_error;
} else {
   // create a connection for the Users class
   global $connection;
   $connection = new usersPermissionsDataSourceMySQLi( 
         $dbConnection,
         $configuration['customUsersFields']
      );
   $databaseExists= $connection->test();
   if ( ! $databaseExists || (isset( $_REQUEST['approve'] ) && $_REQUEST['approve'] == 'Yes, Do It' ) ) {
      $initValues = array( 
         'users' => array( 
            'login' => 'admin', 
            'pass' => password_hash( 'admin', PASSWORD_DEFAULT ),
            'admin' => 1, 
         )
      );
      $connection->buildTable( );
      $connection->initTables( $initValues );
      foreach ( $permissions as $thisPermission ) {
         $connection->addPermission ( $thisPermission[0], $thisPermission[1], $thisPermission[2], $thisPermission[3] );
      }
      $connection->setUsersPermissions();
      if ( saveConfig( $configFilename, $configuration ) ) {
         $message[] = "Saved new copy of config to $configFilename";
      } else {
         print "Could not save configuration to $configFilename\nContents should be\n";
         print '<pre>' . yaml_emit( $configuration ) . '</pre>';
         die;
      }
      $dbConnection->buildAuditTable();
      $dbConnection->runSQLScript( file_get_contents( 'camp2.sql', true ) );
   }
}
?>
<html>
   <head>
   </head>
   <body>
      <div class='install'>
         <div class='messages'>
            <?php print implode("<br />\n", $message); ?>
         </div>
         <h1>Build Database</h1>
         <form method='post'>
            <?php if ($databaseExists) { ?>
               <H3>Warning, database already exists</H3>
               <p>It appears the database exists and has tables in it.</p>
               <p>If you initialize the database, it will overwrite everything with an empty database</p>
               <p>Data may be lost! If you really want to do this</p>
               <label>Enter the words <i>Yes, Do It</i> here
                  <input type='text' name='approve'>
               </label>
            <?php } else { ?>
               <input type='hidden' name='approve' value='I am aware I am destroying data'>
            <?php } ?>
            <p>Pressing the button below will initialize the database with a single admin user</p>
            <p>username: admin</p>
            <p>password: admin</p>
            <p>
               <input type='submit' name='initdb' value='Initialize Database'>
            </p>
         </form>
      </div>
   </body>
</html>