Subversion Repositories computer_asset_manager_v2

Rev

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

Rev Author Line No. Line
1 rodolico 1
<?php
20 rodolico 2
   include_once( 'DatabaseDefinition.php' );
1 rodolico 3
   global $LOGFILE;
4
   $LOGFILE='/tmp/camp.log';
5
   define( 'VERSION', '2.0b' );
6
   define( 'BUILD_DATE', '20130527');
7
 
45 rodolico 8
   function loadConfig() {
9
      // Search through directories looking for a config file
10
      $return = array(
11
         'error' => '',
12
         'path'  => '',
13
         'configuration' => array()
14
      );
15
      $configFileName = 'camp2_config.yaml';
16
      $searchDirectories = array( 
17
         // one level up from document root
18
         $_SERVER['DOCUMENT_ROOT'] . "/../$configFileName",
19
         // directory private one level up from document root
20
         $_SERVER['DOCUMENT_ROOT'] . "/../private/$configFileName",
21
         // the current directory
22
         "./$configFileName",
23
      );
24
      foreach ( $searchDirectories as $search ) {
25
         if ( file_exists( realpath( $search ) ) ) {
26
            $return['path'] = realpath( $search );
27
            $return['configuration'] = yaml_parse_file( $return['path'] );
28
            $return['error'] = '';
29
            return $return;
30
         } // if
31
      } // for
32
      $return['error'] = "No configuration found in<br />" . implode( '<br />', $searchDirectories );
33
      return $return;
34
   }
35
 
1 rodolico 36
   function insertValuesIntoQuery( $query, $values ) {
37
      foreach ( $values as $name => $value ) {
38
         $query = search_replace_string($query, "<$name>", $value );
39
      }
40
      return $query;
41
   }
42
 
43
   function search_replace_string($string, $searchFor, $replaceWith ) {
44
      $string = str_replace ( $searchFor, $replaceWith, $string );
45
      return $string;
46
   }
45 rodolico 47
 
48
   /**
49
    * uses $_REQUEST to decide what to display
50
    * 
51
    * @param string[] $request The contents for $_REQUEST
52
    * 
53
    * @returns string HTML to be inserted into page
54
    */
55
   function displayHTML( $request ) {
56
      global $connection;
20 rodolico 57
 
45 rodolico 58
      if ( isset( $_REQUEST['doAdmin'] ) ) {
59
         $return = $_SESSION['user']->admin($connection) .  $_SESSION['user']->errors();
60
         $_SESSION['user']->clearErrors();
61
      } elseif ( isset( $_REQUEST['searchfor'] ) ) {
62
         $return = print_r( doSearch( $_REQUEST['searchfor'] ), true );
63
      } else { // default to this if nothing else works
64
         $return = '<form method="POST" enctype="multipart/form-data" name="search">
65
               <table border="1" cellpadding="2" align="center">
66
                  <tbody>
67
                     <tr>
68
                        <td align = "center" colspan="2">
69
                           Enter search phrase to find device<br />
70
                           Precede search phrase with <b>site:</b> or <b>client:</b><br />
71
                           to search for site or client<br />
72
                           This is a substring search!
73
                        </td>
74
                     </tr>
75
                     <tr>
76
                        <td>
77
                           Search
78
                        </td>
79
                        <td title="Enter substring to search for">
80
                           <input type="text" name="searchfor" value="">
81
                        </td>
82
                     </tr>
83
                     <tr>
84
                        <td colspan="2" align="center">
85
                           <input type="submit" name="search" value="Search">
86
                        </td>
87
                     </tr>
88
                  </tbody>
89
               </table>
90
            </form>';
91
      } // else
92
      return $return;
93
   }
94
 
95
 
22 rodolico 96
 
45 rodolico 97
 
98
 
1 rodolico 99
 
100
?>