Subversion Repositories computer_asset_manager_v2

Rev

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

<?php
   include_once( 'DatabaseDefinition.php' );
   global $LOGFILE;
   $LOGFILE='/tmp/camp.log';
   define( 'VERSION', '2.0b' );
   define( 'BUILD_DATE', '20130527');
   
   function loadConfig() {
      // Search through directories looking for a config file
      $return = array(
         'error' => '',
         'path'  => '',
         'configuration' => array()
      );
      $configFileName = 'camp2_config.yaml';
      $searchDirectories = array( 
         // one level up from document root
         $_SERVER['DOCUMENT_ROOT'] . "/../$configFileName",
         // directory private one level up from document root
         $_SERVER['DOCUMENT_ROOT'] . "/../private/$configFileName",
         // the current directory
         "./$configFileName",
      );
      foreach ( $searchDirectories as $search ) {
         if ( file_exists( realpath( $search ) ) ) {
            $return['path'] = realpath( $search );
            $return['configuration'] = yaml_parse_file( $return['path'] );
            $return['error'] = '';
            return $return;
         } // if
      } // for
      $return['error'] = "No configuration found in<br />" . implode( '<br />', $searchDirectories );
      return $return;
   }
   
   function saveConfig( $filename, $configuration ) {
      return yaml_emit_file( $filename, $configuration );
   }
   
   function insertValuesIntoQuery( $query, $values ) {
      foreach ( $values as $name => $value ) {
         $query = search_replace_string($query, "<$name>", $value );
      }
      return $query;
   }

   function search_replace_string($string, $searchFor, $replaceWith ) {
      $string = str_replace ( $searchFor, $replaceWith, $string );
      return $string;
   }
   
   /**
    * uses $_REQUEST to decide what to display
    * 
    * @param string[] $request The contents for $_REQUEST
    * 
    * @returns string HTML to be inserted into page
    */
   function displayHTML( $request ) {
      global $connection;

      if ( isset( $_REQUEST['doAdmin'] ) ) {
         $return = $_SESSION['user']->admin($connection) .  $_SESSION['user']->errors();
         $_SESSION['user']->clearErrors();
      } elseif ( isset( $_REQUEST['searchfor'] ) ) {
         $return = print_r( doSearch( $_REQUEST['searchfor'] ), true );
      } else { // default to this if nothing else works
         //$return = '<pre>' . print_r( $_SESSION, true ) . '</pre>';
         $return = "<h3 align='center'>Content goes here</h3>";
      } // else
      return $return;
   }
   
   function buildRestrictions() {
      global $dbConnection;
      if ( empty( $_SESSION['user']->restrictions ) || $_SESSION['user']->restrictions == '1=1' ) {
         // give full access
         $_SESSION['restrictions']['owner'] = '1=1';
         $_SESSION['restrictions']['location'] = '1=1';
         $_SESSION['restrictions']['device'] = '1=1';
      } else {
         $rules = explode( "\n", $_SESSION['user']->restrictions );
         //print '<pre>' . print_r( $rules, true ) . '</pre>' ; die;
         $temp = array();
         $workingOn = '';
         foreach ( $rules as $thisOne ) {
            //print "<pre>Working on $thisOne\n</pre>";
            if ( preg_match( '/\[([^\[\]]+)\]/', $thisOne, $match ) ) {
               //print "Adding as category\n<br />";
               $workingOn = $match[1];
            } else {
               //print "Adding as a value in $workingOn\n<br />";
               $temp[$workingOn][] = "'" . $dbConnection->real_escape_string(trim($thisOne)) . "'";
            }
         } // foreach
         //print '<pre>' . print_r( $temp, true ) . '</pre>' ; die;
         $_SESSION['restrictions']['owner'] = implode( ',', $temp['owner'] );
         $_SESSION['restrictions']['location'] = implode( ',', $temp['location'] );
         $_SESSION['restrictions']['device'] = implode( ',', $temp['device'] );
      } // else
   }
         

      
      
      
   
?>