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