/[debian]/quickappoint/branches/upstream/current/lib/dbedit.php
ViewVC logotype

Contents of /quickappoint/branches/upstream/current/lib/dbedit.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 140 - (show annotations)
Sat Feb 25 17:48:32 2006 UTC (15 years, 5 months ago) by gregoa
File size: 2731 byte(s)
[svn-inject] Installing original source of quickappoint
1 <?php
2 // require_once(dirname(__FILE__) . '/prepend.php');
3 // require_once(dirname(__FILE__) . '/db.php');
4
5
6 // Takes a hash "$request" and extracts all key/value pairs where the keys begin with :
7 // The leading : is removed within the keys.
8 // If $remove is true, the extracted entries are deleted from the request
9 // Example:
10 // :tablename
11
12 function decodeRequestMetaData(&$request, $remove = FALSE) {
13 $result = array();
14 foreach($request as $key => $value) {
15 if (substr($key, 0, 1) == ':') {
16 $result[substr($key, 1)] = $value;
17 if ($remove) unset($request[$key]);
18 }
19 }
20 return $result;
21 }
22
23
24 // Takes the hash "$request". The keys of its entries $key => $value are supposed
25 // to have the following form
26 // [functionname@]fieldname[:])
27 // If the fieldname is followed by the (optional) : this field is handled as
28 // one of database key field names.
29 // If the fieldname as preceded by functionname@, this function should be applied
30 // to the corresponding value (but this is not done within this function).
31 //
32 // Return hashes:
33 // $key_field_value_map:
34 // Contains key => value pairs for database keys fields
35 // The database key fields are freed from the : at the end and the optional
36 // functionname@ at the beginning.
37 // $field_value_map: The rest of the fields.
38 // The fields are freed from the optional
39 // functionname@ at the beginning.
40 // $key_function_map: A hash with all keys that have functionnames
41 // The functionnames are freed from the @ at the end
42 //
43 // Example:
44 // $request = array('id:' => 7, 'name' => 'hugo', 'md5@password' => 'abc');
45 // // result:
46 // $key_field_value_map == array('id' => 7)
47 // $field_value_map == array('name' => 'hugo', 'password' => 'abc')
48 // $key_function_map == array('password' => 'md5');
49
50 function decodeRequest($request, &$key_field_value_map, &$field_value_map, &$key_function_map) {
51 // Begin with empty results
52 $key_field_value_map = array();
53 $field_value_map = array();
54 $key_function_map = array();
55
56 foreach ($request as $key => $value) {
57 // Split $key in $functionname $fieldname $isdbkey
58 // - Init
59 $functionname = NULL;
60 $fieldname = '';
61 $isdbkey = FALSE;
62 // - functionname
63 $functionname_keyname = explode('@', $key);
64 if (count($functionname_keyname) == 2) {
65 $key = $functionname_keyname[1];
66 $functionname = $functionname_keyname[0];
67 }
68 // - isdbkey
69 if (substr($key, -1) == ':') {
70 $key = substr($key, 0, -1);
71 $isdbkey = TRUE;
72 }
73 // - fieldname
74 $fieldname = $key;
75
76 // Insert in the corresponding hashes
77 if ($isdbkey) $key_field_value_map[$fieldname] = $value;
78 else $field_value_map[$fieldname] = $value;
79 if (!is_null($functionname)) $key_function_map[$fieldname] = $functionname;
80 }
81 }
82
83
84
85 ?>

  ViewVC Help
Powered by ViewVC 1.1.26