Subversion Repositories computer_asset_manager_v2

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 rodolico 1
<?php
46 rodolico 2
   include_once( dirname(__FILE__) . '/../include/functions.php');
3
   global $configuration;
4
   $error = '';
5
   $message = array();
6
 
7
   $configStuff = loadConfig();
8
   $configuration = $configStuff['configuration'];
9
   $configPath = $configStuff['path'];
10
   unset( $configStuff );
11
   $message[] = "Reading from $configPath";
51 rodolico 12
   include_once( 'users_table.php' );
46 rodolico 13
 
14
   if ( ! $configuration ) {
15
      $configuration = array(
16
         'database'  => array(
17
            'dbserver'     => '127.0.0.1',
18
            'dbname'       => 'camp2',
19
            'dbusername'   => 'camp2',
20
            'dbpassword'   => 'camp2'
21
            ),
22
         'debug'     => 0,
23
         'locations' => array (
24
            'base_url'  => parentURL( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ),
25
            'main_script'  => 'index.php',
26
            'config_dir'   => '/var/www',
27
            'include_dirs' => array (
28
               'php_library_v2'  => findFile( $_SERVER['DOCUMENT_ROOT'], 'DBQuery.class.php'), #'/var/www/php72/php_library_v2',
29
               'php_users'       => findFile( $_SERVER['DOCUMENT_ROOT'], 'UsersPermissions.class.php'), #'/var/www/php72/php_users',
30
               'camp'            => realpath( __DIR__ . '/../include' )
31
            ),
45 rodolico 32
         ),
46 rodolico 33
         // fields for the Users class, adds where_clause, a TEXT object
34
         // and super_admin, a boolean
45 rodolico 35
      );
51 rodolico 36
      $configuration['customUsersFields'] = $customFields;      
46 rodolico 37
   } // if there was no configuration file
38
 
39
   if ( isset( $_REQUEST['writeconf'] ) ) {
40
      //print "Ready to update configuration";
41
      $configuration = updateConfig( $configuration );
42
      $message[] = writeConfig( $configuration['locations']['config_dir'] );
43
   }
44
 
45
   function parentURL( $url, $numRemove = 2 ) {
46
      $parts = explode( '/', $url );
47
      while ( $numRemove-- ) 
48
         array_pop( $parts ); // get rid of last one
49
      return implode( '/', $parts );
50
   }
51
 
52
   function updateConfig ( $configuration ) {
53
      foreach ( $configuration as $key => $value ) {
54
         //print "Updating $key<br />";
55
         if ( is_array( $value ) ) {
56
            $configuration[$key] = updateConfig( $value );
57
         } elseif ( is_scalar( $value ) && isset( $_REQUEST[$key] ) ) {
58
            $configuration[$key] = $_REQUEST[$key];
59
         }
60
      }
61
      return $configuration;
62
   }
63
 
64
 
65
   function writeConfig( $path ) {
66
      global $configuration;
67
 
68
      $path .= "/camp2_config.yaml";
69
      //print "Writing to $path<br />";
70
      if (yaml_emit_file( $path, $configuration ) ) {
71
         return "Configuration saved to $path";
72
      } else {
73
         return "Error saving configuration to $path, check permissions";
74
      }
75
   }
76
 
77
   function findFile( $root, $filename ) {
78
      $it = new RecursiveDirectoryIterator( $root );
79
      foreach ( new RecursiveIteratorIterator( $it ) as $file ) {
80
         if ( preg_match( "^/$filename$^", $file ) ) {
81
            return realpath( preg_replace( "^/$filename$^", '/', $file ) );;
82
         }
83
      }
84
   }
85
 
45 rodolico 86
?>
87
<html>
88
   <head>
89
   </head>
90
   <body>
91
      <div class='install'>
46 rodolico 92
         <div class='messages'>
93
            <pre><?php //print_r( $_REQUEST ); ?></pre>
94
            <?php print implode( "<br />\n", $message ); ?>
95
            <p><a href='installer.php'>Done with Configuration</a></p>
96
         </div>
45 rodolico 97
         <h1>Build/Edit Configuration</h1>
46 rodolico 98
         <form method='post'>
45 rodolico 99
               <h3>Database</h3>
100
            <p>
101
               <label>Database Name
46 rodolico 102
                  <input type='text' name='dbname' value='<?php print $configuration['database']['dbname']; ?>'>
45 rodolico 103
               </label>
104
            </p>
105
            <p>
106
               <label>Database Server
46 rodolico 107
                  <input type='text' name='dbserver' value='<?php print $configuration['database']['dbserver']; ?>'>
45 rodolico 108
               </label>
109
            </p>
110
            <p>
111
               <label>Database User
46 rodolico 112
                  <input type='text' name='dbusername' value='<?php print $configuration['database']['dbusername']; ?>'>
45 rodolico 113
               </label>
114
            </p>
115
            <p>
116
               <label>Database Password
46 rodolico 117
                  <input type='text' name='dbpassword' value='<?php print $configuration['database']['dbpassword']; ?>'>
45 rodolico 118
               </label>
119
            </p>
120
            <h3>Locations</h3>
121
            <p>
122
               <label>Base URL
46 rodolico 123
                  <input type='text' name='baseurl' value='<?php print $configuration['locations']['base_url']; ?>'>
45 rodolico 124
               </label>
125
            </p>
126
            <p>
127
               <label>Main Script Name
46 rodolico 128
                  <input type='text' name='main_script' value='<?php print $configuration['locations']['main_script']; ?>'>
45 rodolico 129
               </label>
130
            </p>
131
            <p>
132
               <label>Config Directory
46 rodolico 133
                  <input type='text' name='config_dir' value='<?php print $configuration['locations']['config_dir']; ?>'>
45 rodolico 134
               </label>
135
            </p>
136
            <p>
137
               <label>PHP Library v2
46 rodolico 138
                  <input type='text' name='php_library_v2' value='<?php print $configuration['locations']['include_dirs']['php_library_v2']; ?>'>
45 rodolico 139
               </label>
140
            </p>
141
            <p>
142
               <label>PHP Users
46 rodolico 143
                  <input type='text' name='php_users' value='<?php print $configuration['locations']['include_dirs']['php_users']; ?>'>
45 rodolico 144
               </label>
145
            </p>
146
            <h3>Other</h3>
147
            <p>
148
               <label>Debug Mode
46 rodolico 149
                  <input type='checkbox' name='debug' <?php if ( $configuration['debug'] ) print 'checked'; ?>>
45 rodolico 150
               </label>
151
            </p>
152
 
46 rodolico 153
            <input type='submit' name='writeconf' value='Save'>
45 rodolico 154
         </form>
155
      </div>
46 rodolico 156
      <pre>
157
         <?php //print_r( $configuration ); ?>
158
      </pre>
45 rodolico 159
   </body>
160
</html>