Subversion Repositories php_library

Rev

Rev 55 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 55 Rev 58
Line 11... Line 11...
11
   Revision 10 - 20090115 - R. W. Rodolico
11
   Revision 10 - 20090115 - R. W. Rodolico
12
   Modified editData routine to grab display query from table definition if key field not defined in complex join definition
12
   Modified editData routine to grab display query from table definition if key field not defined in complex join definition
13
 
13
 
14
*/
14
*/
15
 
15
 
16
   define('REVISION', '2.18');
16
   const REVISION = '2.18';
17
   define( 'HTML_QUOTE_CHAR', '"' );
17
   const HTML_QUOTE_CHAR = '"' ;
18
   define( 'CONSTANT_NO_VALUE_DROPDOWN', '--------' );
18
   const CONSTANT_NO_VALUE_DROPDOWN = '--------' ;
-
 
19
 
-
 
20
 
-
 
21
   // following field types are numeric (with length)
-
 
22
   const NUMERICS = [
-
 
23
         'BIT'=> 16,
-
 
24
         'TINYINT'=> 1,
-
 
25
         'BOOL'=> 1,
-
 
26
         'SMALLINT'=> 2,
-
 
27
         'MEDIUMINT'=> 9,
-
 
28
         'INTEGER'=> 3,
-
 
29
         'BIGINT'=> 8,
-
 
30
         'SERIAL'=> 8,
-
 
31
         'FLOAT'=> 4,
-
 
32
         'DOUBLE'=> 5,
-
 
33
         'DECIMAL'=> 246,
-
 
34
         'NUMERIC'=> 246,
-
 
35
         'FIXED'=> 246
-
 
36
      ];
-
 
37
   // the following are the type names which are dates (with length)
-
 
38
   const DATES = [
-
 
39
         'DATE'=> 10,
-
 
40
         'DATETIME'=> 12,
-
 
41
         'TIMESTAMP'=> 7,
-
 
42
         'TIME'=> 11,
-
 
43
         'YEAR'=> 13
-
 
44
      ];
-
 
45
 
19
 
46
 
20
   $LOGIN_PAGE = 'login.html';
47
   $LOGIN_PAGE = 'login.html';
21
   
48
   
22
   function getParameter( $parameterName, $default = '' ) {
49
   function getParameter( $parameterName, $default = '' ) {
23
      if (isset($_POST[$parameterName])) {
50
      if (isset($_POST[$parameterName])) {
Line 84... Line 111...
84
         return false;
111
         return false;
85
      }
112
      }
86
   }
113
   }
87
*/
114
*/
88
   function makeSafeSQLValue ( $value, $type='S' ) {
115
   function makeSafeSQLValue ( $value, $type='S' ) {
-
 
116
      global $databaseConnection;
89
      if (strlen($value) == 0) { // simply set any empty values to null
117
      if (strlen($value) == 0) { // simply set any empty values to null
90
         return 'null';
118
         return 'null';
91
      }
119
      }
92
      if(get_magic_quotes_gpc()) {
120
      //if(get_magic_quotes_gpc()) {
93
           $value = stripslashes($value);
121
      //     $value = stripslashes($value);
94
       }
122
      // }
95
      $value = mysql_real_escape_string( $value );
123
      $value = mysqli_real_escape_string( $databaseConnection,$value );
96
      if (($type == 'S') and strlen($value)  > 0) { // put quotes around strings
124
      if (($type == 'S') and strlen($value)  > 0) { // put quotes around strings
97
         $value = "'" . $value . "'";
125
         $value = "'" . $value . "'";
98
      } elseif ($type == 'D') {
126
      } elseif ($type == 'D') {
99
         if ( $result = strtotime( $value ) ) {
127
         if ( $result = strtotime( $value ) ) {
100
            $value = Date( 'Y-m-d', $result);
128
            $value = Date( 'Y-m-d', $result);
Line 118... Line 146...
118
   creates audit trail of modifications to the database
146
   creates audit trail of modifications to the database
119
*/ 
147
*/ 
120
   function audit ($sql ) {
148
   function audit ($sql ) {
121
      return ;
149
      return ;
122
      $query = 'insert into _audit (_audit.user_id,_audit.sql) values ( ' . $_SESSION['worker_id'] . ', ' . makeSafeSQLValue($sql) . ')';
150
      $query = 'insert into _audit (_audit.user_id,_audit.sql) values ( ' . $_SESSION['worker_id'] . ', ' . makeSafeSQLValue($sql) . ')';
-
 
151
      doSQL( $query );
123
      mysql_query( $query );
152
      #mysql_query( $query );
124
      if( mysql_errno() ) {
153
      #if( mysql_errno() ) {
125
         $error = 'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$query</VAR>";
154
      #   $error = 'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$query</VAR>";
126
         echo($error);
155
      #   echo($error);
127
      }
156
      #}
128
   }
157
   }
129
 
158
 
130
 
159
 
131
   /*
160
   /*
132
      Taken from comments at http://www.php.net/manual/en/function.mysql-query.php
161
      Taken from comments at http://www.php.net/manual/en/function.mysql-query.php
Line 151... Line 180...
151
               'length' maximum width of the column FOR THIS QUERY
180
               'length' maximum width of the column FOR THIS QUERY
152
               'numeric'true if the column is numeric
181
               'numeric'true if the column is numeric
153
               'type'   type of the column (database dependant)
182
               'type'   type of the column (database dependant)
154
 
183
 
155
   */
184
   */
-
 
185
   
-
 
186
   /* Modified for mysqli. Uses a global variable, $databaseConnection, which must exist */
156
 
187
 
157
      function queryDatabaseExtended($query,$assoc=1,$showErrors=true) {
188
   function queryDatabaseExtended($query,$assoc=1,$showErrors=true) {
-
 
189
      global $databaseConnection;
158
      // print "<pre>In Query database\n---------------------\n$query\n---------------------\n</pre>";
190
      // print "<pre>In Query database\n---------------------\n$query\n---------------------\n</pre>";
159
      printLog( $query );
191
      printLog( $query );
160
      // we use the @ symbol to suppress warnings and errors when calling mysql_query
192
      // we use the @ symbol to suppress warnings and errors when calling mysql_query
161
      $r = @mysql_query($query);
193
      $r = @mysqli_query($databaseConnection,$query);
162
      if( mysql_errno() ) {
194
      if( mysqli_errno($databaseConnection) ) {
163
         $error = 'MYSQL ERROR #'.mysql_errno().' : <small>' . mysql_error(). "</small><br><VAR>$query</VAR>";
195
         $error = 'MYSQL ERROR #'.mysqli_errno($databaseConnection).' : <small>' . mysqli_error($databaseConnection). "</small><br><VAR>$query</VAR>";
164
         if ( $showErrors ) echo($error);
196
         if ( $showErrors ) echo($error);
165
         return FALSE;
197
         return FALSE;
166
      }
198
      }
167
      if( ! preg_match ( '/^\s*select/i', $query ) ) {
199
      if( ! preg_match ( '/^\s*select/i', $query ) ) {
168
         $f = array( 'affected_rows' => mysql_affected_rows(),'insert_id' => mysql_insert_id());
200
         $f = array( 'affected_rows' => mysqli_affected_rows($databaseConnection),'insert_id' => mysqli_insert_id($databaseConnection));
169
         // create audit trail
201
         // create audit trail
170
         audit($query);
202
         audit($query);
171
         return $f;
203
         return $f;
172
      }
204
      }
173
      $count = @mysql_num_rows($r);
205
      $count = @mysqli_num_rows($r);
174
      $fieldMeta = array();
206
      $fieldMeta = array();
-
 
207
      $i = 0;
175
      while ($i++ < mysql_num_fields($r)) {
208
      while ($i++ < mysqli_num_fields($r)) {
176
         $meta = mysql_fetch_field ( $r );
209
         $meta = mysqli_fetch_field ( $r );
177
         //objectDebugScreen($meta);
210
         //objectDebugScreen($meta);
178
         $fieldMeta[] = array('name' => $meta->name, 'length' => $meta->max_length, 'numeric' => $meta->numeric, 'type' => $meta->type );
211
         $fieldMeta[] = array('name' => $meta->name, 'length' => $meta->max_length, 'numeric' => array_key_exists( $meta->type, NUMERICS ), 'date' => array_key_exists( $meta->type, DATES ), 'type' => $meta->type );
179
      }
212
      }
180
      if( ! $count ) return '';
213
      if( ! $count ) return '';
181
      $all = array();
214
      $all = array();
182
      for( $i = 0; $i < $count; $i++ ) {
215
      for( $i = 0; $i < $count; $i++ ) {
183
        if( $assoc ) $f = mysql_fetch_assoc($r);
216
        if( $assoc ) $f = mysqli_fetch_assoc($r);
184
        else $f = mysql_fetch_row($r);
217
        else $f = mysqli_fetch_row($r);
185
        $all[] = $f;
218
        $all[] = $f;
186
      }
219
      }
187
      mysql_free_result($r);
220
      mysqli_free_result($r);
188
      return array( 'meta' => $fieldMeta, 'data' => $all, 'count' => $count);
221
      return array( 'meta' => $fieldMeta, 'data' => $all, 'count' => $count);
189
   } // function queryDatabaseExtended
222
   } // function queryDatabaseExtended
190
 
223
 
191
 
224
 
192
   // function returns the first column of the first row of data returned from query
225
   // function returns the first column of the first row of data returned from query