Subversion Repositories computer_asset_manager_v2

Rev

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

Rev Author Line No. Line
46 rodolico 1
<?php
2
include_once (dirname(__FILE__) . '/../include/functions.php');
3
global $configuration;
4
$error         = '';
5
$message       = array();
6
 
7
$configuration = loadConfig();
8
if ( $configuration['error'] ) {
9
   print $configuration['error'];
10
   die;
11
}
12
 
13
$configFilename = $configuration['path'];
14
$configuration = $configuration['configuration'];
15
 
16
 
17
// get include directories for libraries
18
foreach ( $configuration['locations']['include_dirs'] as $key => $dir ) {
19
   ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $dir );
20
}
21
 
22
include_once( 'UsersPermissions.class.php' );
23
include_once( 'UsersPermissionsDataSourceMySQLi.class.php' );
24
include_once( 'DBQuery.class.php' );
25
include_once( 'functions.php' );
26
include_once( 'users_table.php' );
27
 
28
$configuration['customUsersFields'] = $customFields;
29
 
30
$message[]     = "Reading from " . $configuration['locations']['config_dir'];
31
$dbConnection = new DBQuery( $configuration['database']['dbserver'],$configuration['database']['dbusername'], $configuration['database']['dbpassword'], $configuration['database']['dbname'] );
32
if ( $dbConnection->connect_errno ) {
33
   $message[] = "Failed to connect to MySQL: (" . $dbConnection->connect_errno . ") " . $dbConnection->connect_error;
34
} else {
35
   // create a connection for the Users class
36
   global $connection;
37
   $connection = new usersPermissionsDataSourceMySQLi( 
38
         $dbConnection,
39
         $configuration['customUsersFields']
40
      );
41
   $databaseExists= $connection->test();
42
   if ( ! $databaseExists || (isset( $_REQUEST['approve'] ) && $_REQUEST['approve'] == 'Yes, Do It' ) ) {
43
      $initValues = array( 
44
         'users' => array( 
45
            'login' => 'admin', 
46
            'pass' => password_hash( 'admin', PASSWORD_DEFAULT ),
47
            'admin' => 1, 
48
         )
49
      );
50
      $connection->buildTable( );
51
      $connection->initTables( $initValues );
52
      foreach ( $permissions as $thisPermission ) {
53
         $connection->addPermission ( $thisPermission[0], $thisPermission[1], $thisPermission[2], $thisPermission[3] );
54
      }
55
      $connection->setUsersPermissions();
56
      if ( saveConfig( $configFilename, $configuration ) ) {
57
         $message[] = "Saved new copy of config to $configFilename";
58
      } else {
59
         print "Could not save configuration to $configFilename\nContents should be\n";
60
         print '<pre>' . yaml_emit( $configuration ) . '</pre>';
61
         die;
62
      }
63
      $dbConnection->buildAuditTable();
64
      $dbConnection->runSQLScript( file_get_contents( 'camp2.sql', true ) );
65
   }
66
}
67
?>
68
<html>
69
   <head>
70
   </head>
71
   <body>
72
      <div class='install'>
73
         <div class='messages'>
74
            <?php print implode("<br />\n", $message); ?>
75
         </div>
76
         <h1>Build Database</h1>
77
         <form method='post'>
78
            <?php if ($databaseExists) { ?>
79
               <H3>Warning, database already exists</H3>
80
               <p>It appears the database exists and has tables in it.</p>
81
               <p>If you initialize the database, it will overwrite everything with an empty database</p>
82
               <p>Data may be lost! If you really want to do this</p>
83
               <label>Enter the words <i>Yes, Do It</i> here
84
                  <input type='text' name='approve'>
85
               </label>
86
            <?php } else { ?>
87
               <input type='hidden' name='approve' value='I am aware I am destroying data'>
88
            <?php } ?>
89
            <p>Pressing the button below will initialize the database with a single admin user</p>
90
            <p>username: admin</p>
91
            <p>password: admin</p>
92
            <p>
93
               <input type='submit' name='initdb' value='Initialize Database'>
94
            </p>
95
         </form>
96
      </div>
97
   </body>
98
</html>