Subversion Repositories computer_asset_manager_v2

Rev

Rev 51 | Rev 63 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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

   $configStuff = loadConfig();
   $configuration = $configStuff['configuration'];
   $configPath = $configStuff['path'];
   unset( $configStuff );
   $message[] = "Reading from $configPath";
   include_once( 'users_table.php' );

   if ( ! $configuration ) {
      $configuration = array(
         'database'  => array(
            'dbserver'     => '127.0.0.1',
            'dbname'       => 'camp2',
            'dbusername'   => 'camp2',
            'dbpassword'   => 'camp2'
            ),
         'debug'     => 0,
         'session' => array(
            'save_path'=> '/var/www/sessions',
            'gc_maxlifetime'=> 57600,
            'cookie_lifetime'=> 57600,
            'cache_expire'=> 960,
            'name'=> 'camp2'
         ),
         'locations' => array (
            'base_url'  => parentURL( $_SERVER['REQUEST_SCHEME'] . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF'] ),
            'main_script'  => 'index.php',
            'config_dir'   => '/var/www',
            'include_dirs' => array (
               'php_library_v2'  => findFile( $_SERVER['DOCUMENT_ROOT'], 'DBQuery.class.php'), #'/var/www/php72/php_library_v2',
               'php_users'       => findFile( $_SERVER['DOCUMENT_ROOT'], 'UsersPermissions.class.php'), #'/var/www/php72/php_users',
               'camp'            => realpath( __DIR__ . '/../include' )
            ),
         ),
         // fields for the Users class, adds where_clause, a TEXT object
         // and super_admin, a boolean
      );
      $configuration['customUsersFields'] = $customFields;      
   } // if there was no configuration file
   
   if ( isset( $_REQUEST['writeconf'] ) ) {
      //print "Ready to update configuration";
      $configuration = updateConfig( $configuration );
      $message[] = writeConfig( $configuration['locations']['config_dir'] );
   }
   
   function parentURL( $url, $numRemove = 2 ) {
      $parts = explode( '/', $url );
      while ( $numRemove-- ) 
         array_pop( $parts ); // get rid of last one
      return implode( '/', $parts );
   }
   
   function updateConfig ( $configuration ) {
      foreach ( $configuration as $key => $value ) {
         //print "Updating $key<br />";
         if ( is_array( $value ) ) {
            $configuration[$key] = updateConfig( $value );
         } elseif ( is_scalar( $value ) && isset( $_REQUEST[$key] ) ) {
            $configuration[$key] = $_REQUEST[$key];
         }
      }
      return $configuration;
   }
            
            
   function writeConfig( $path ) {
      global $configuration;
      
      $path .= "/camp2_config.yaml";
      //print "Writing to $path<br />";
      if (yaml_emit_file( $path, $configuration ) ) {
         return "Configuration saved to $path";
      } else {
         return "Error saving configuration to $path, check permissions";
      }
   }
   
   function findFile( $root, $filename ) {
      $it = new RecursiveDirectoryIterator( $root );
      foreach ( new RecursiveIteratorIterator( $it ) as $file ) {
         if ( preg_match( "^/$filename$^", $file ) ) {
            return realpath( preg_replace( "^/$filename$^", '/', $file ) );;
         }
      }
   }
   
?>
<html>
   <head>
   </head>
   <body>
      <div class='install'>
         <div class='messages'>
            <pre><?php //print_r( $_REQUEST ); ?></pre>
            <?php print implode( "<br />\n", $message ); ?>
            <p><a href='installer.php'>Done with Configuration</a></p>
         </div>
         <h1>Build/Edit Configuration</h1>
         <form method='post'>
               <h3>Database</h3>
            <p>
               <label>Database Name
                  <input type='text' name='dbname' value='<?php print $configuration['database']['dbname']; ?>'>
               </label>
            </p>
            <p>
               <label>Database Server
                  <input type='text' name='dbserver' value='<?php print $configuration['database']['dbserver']; ?>'>
               </label>
            </p>
            <p>
               <label>Database User
                  <input type='text' name='dbusername' value='<?php print $configuration['database']['dbusername']; ?>'>
               </label>
            </p>
            <p>
               <label>Database Password
                  <input type='text' name='dbpassword' value='<?php print $configuration['database']['dbpassword']; ?>'>
               </label>
            </p>
            <h3>Session Control</h3>
            <p>
               <label>Session Path
                  <input type='text' name='save_path' value='<?php print $configuration['sessions']['save_path']; ?>'>
               </label>
            </p>
            <p>
               <label>gc_maxlifetime
                  <input type='text' name='gc_maxlifetime' value='<?php print $configuration['sessions']['gc_maxlifetime']; ?>'>
               </label>
            </p>
            <p>
               <label>Cookie Lifetime (seconds)
                  <input type='text' name='cookie_lifetime' value='<?php print $configuration['sessions']['cookie_lifetime']; ?>'>
               </label>
            </p>
            <p>
               <label>Cache Expire (minutes)
                  <input type='text' name='cache_expire' value='<?php print $configuration['sessions']['cache_expire']; ?>'>
               </label>
            </p>
            <p>
               <label>Session Name
                  <input type='text' name='name' value='<?php print $configuration['sessions']['name']; ?>'>
               </label>
            </p>
            <h3>Locations</h3>
            <p>
               <label>Base URL
                  <input type='text' name='baseurl' value='<?php print $configuration['locations']['base_url']; ?>'>
               </label>
            </p>
            <p>
               <label>Main Script Name
                  <input type='text' name='main_script' value='<?php print $configuration['locations']['main_script']; ?>'>
               </label>
            </p>
            <p>
               <label>Config Directory
                  <input type='text' name='config_dir' value='<?php print $configuration['locations']['config_dir']; ?>'>
               </label>
            </p>
            <p>
               <label>PHP Library v2
                  <input type='text' name='php_library_v2' value='<?php print $configuration['locations']['include_dirs']['php_library_v2']; ?>'>
               </label>
            </p>
            <p>
               <label>PHP Users
                  <input type='text' name='php_users' value='<?php print $configuration['locations']['include_dirs']['php_users']; ?>'>
               </label>
            </p>
            <h3>Other</h3>
            <p>
               <label>Debug Mode
                  <input type='checkbox' name='debug' <?php if ( $configuration['debug'] ) print 'checked'; ?>>
               </label>
            </p>
            
            <input type='submit' name='writeconf' value='Save'>
         </form>
      </div>
      <pre>
         <?php //print_r( $configuration ); ?>
      </pre>
   </body>
</html>