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