1 |
--- data.php.orig 2002-05-27 19:05:20.000000000 +0200 |
2 |
+++ data.php.patched 2002-10-21 12:33:59.000000000 +0200 |
3 |
@@ -20,6 +20,7 @@ |
4 |
} |
5 |
|
6 |
$error = false; |
7 |
+$errors_import = array(); |
8 |
$actionID = Horde::getFormData('actionID', NO_ACTION); |
9 |
|
10 |
if ($actionID == HORDE_IMPORT) { |
11 |
@@ -100,6 +101,12 @@ |
12 |
$hash = array(); |
13 |
reset($cfgSources[$dest]['map']); |
14 |
while (list($key, ) = each($cfgSources[$dest]['map'])) { |
15 |
+ // determine if appKey contains expression |
16 |
+ if ( isset($map[$key]) && substr($map[$key], 0, 6) == 'expr: ') { |
17 |
+ // patch "$row[$map[$key]]" |
18 |
+ $val = evaluateExpression(substr($map[$key], 6), $row); |
19 |
+ $row[$map[$key]] = $val; |
20 |
+ } |
21 |
if (isset($map[$key]) && !empty($row[$map[$key]])) { |
22 |
if ($attributes[$key]['type'] == 'date' || |
23 |
$attributes[$key]['type'] == 'time' || |
24 |
@@ -116,19 +123,59 @@ |
25 |
} elseif ($attributes[$key]['type'] == 'datetime') { |
26 |
$hash[$key] = mktime($dt_arr['hour'], $dt_arr['min'], $dt_arr['sec'], $dt_arr['month'], $dt_arr['mday'], $dt_arr['year']); |
27 |
} else { |
28 |
- $hash[$key] = $row[$map[$key]]; |
29 |
+ $hash[$key] = $row[$map[$key]]; |
30 |
} |
31 |
} |
32 |
} |
33 |
$hash['__owner'] = Auth::getAuth(); |
34 |
- if (!$driver->addObject($hash)) { |
35 |
+ |
36 |
+ $result = $driver->addObject($hash); |
37 |
+ // $driver->addObject may return a PEAR-Error-Object |
38 |
+ if ( is_object($result) && get_class($result) == 'pear_error' ) { |
39 |
+ $error_row = array( |
40 |
+ 'error_source' => 'PEAR', |
41 |
+ 'message' => $result->message, |
42 |
+ 'sourcedata_dump' => showvar($row), |
43 |
+ 'mapping_dump' => showvar($map), |
44 |
+ 'importhash_dump' => showvar($hash), |
45 |
+ ); |
46 |
+ array_push($errors_import, $error_row); |
47 |
$error = true; |
48 |
- } |
49 |
+ } |
50 |
+ |
51 |
+# if ($result == true) { |
52 |
+# $error = false; |
53 |
+# } |
54 |
} |
55 |
} |
56 |
|
57 |
if ($error) { |
58 |
- Horde::raiseMessage(_("There was an error importing the data."), HORDE_ERROR); |
59 |
+ $error_idx = 0; |
60 |
+ ?> |
61 |
+ <script language="javascript"> |
62 |
+ function toggleDetails(obj) { |
63 |
+ sel = obj.style.getAttribute('display'); |
64 |
+ if (sel == 'none') { |
65 |
+ obj.style.setAttribute('display', 'inline'); |
66 |
+ } else { |
67 |
+ obj.style.setAttribute('display', 'none'); |
68 |
+ } |
69 |
+ } |
70 |
+ </script> |
71 |
+ <? |
72 |
+ $msg_append = ''; |
73 |
+ foreach ($errors_import as $error_item) { |
74 |
+ $msg_append .= $error_item['message'] . " |
75 |
+<a href=\"javascript:toggleDetails(document.all.details$error_idx);\">details</a> |
76 |
+<span id=\"details$error_idx\" style=\"display:none; font-size:10px;\"> |
77 |
+<pre><blockquote> |
78 |
+sourcedata:<br>$error_item[sourcedata_dump]<br> |
79 |
+mapping:<br>$error_item[mapping_dump]<br> |
80 |
+import-hash:<br>$error_item[importhash_dump]<br> |
81 |
+</pre></blockquote></span><hr>"; |
82 |
+ $error_idx++; |
83 |
+ } |
84 |
+ Horde::raiseMessage(_("There was an error importing the data.<hr>" . $msg_append), HORDE_ERROR); |
85 |
} else { |
86 |
$import_type = Horde::getFormData('import_type'); |
87 |
switch ($import_type) { |
88 |
@@ -384,4 +431,65 @@ |
89 |
$registry->shutdown(); |
90 |
require TURBA_TEMPLATES . '/common-footer.inc'; |
91 |
|
92 |
+ |
93 |
+// dumps a variable |
94 |
+function showvar($var, $string = '$var') |
95 |
+{ |
96 |
+ $out = ""; |
97 |
+ // TRUE, FALSE, NULL and empty arrays: return this value |
98 |
+ if($var === true) { |
99 |
+ $out .= htmlentities($string . ' = TRUE;') . "\n"; |
100 |
+ } else if($var === false) { |
101 |
+ $out .= htmlentities($string . ' = FALSE;') . "\n"; |
102 |
+ } else if($var === null) { |
103 |
+ $out .= htmlentities($string . ' = NULL;') . "\n"; |
104 |
+ } else if($var === array()) { |
105 |
+ $out .= htmlentities($string . ' = array();') . "\n"; |
106 |
+ // array or object - foreach element of $var |
107 |
+ } else if ( is_array( $var ) || is_object($var) ) { |
108 |
+ foreach($var as $k=>$v) { |
109 |
+ // Format the string which stands next to the ' = '. |
110 |
+ // [] for arrays and -> for objects |
111 |
+ if(is_array($var)) { |
112 |
+ if(is_string($k)) { |
113 |
+ $k = "'" . str_replace('\"', '"', |
114 |
+ addslashes($k)) . "'"; |
115 |
+ } |
116 |
+ $new_string = $string . '[' . $k . ']'; |
117 |
+ } else if(is_object($var)) { |
118 |
+ $new_string = $string . '->' . $k; |
119 |
+ } |
120 |
+ // dive |
121 |
+ $out .= showvar($v, $new_string); |
122 |
+ } |
123 |
+ // not object, not array |
124 |
+ } else { |
125 |
+ // Format as a string if it is one |
126 |
+ if(is_string($var)) { |
127 |
+ $var = "'" . str_replace('\"', '"', |
128 |
+ addslashes($var)) . "'"; |
129 |
+ } |
130 |
+ $out .= htmlentities($string . ' = ' . $var) . ";\n"; |
131 |
+ } |
132 |
+ return $out; |
133 |
+} |
134 |
+ |
135 |
+ |
136 |
+// evaluates field-expression |
137 |
+function evaluateExpression($expr, $row) { |
138 |
+ $expr = str_replace('+', '.', $expr); |
139 |
+ preg_match_all("/{.+?}/", $expr, $matches); |
140 |
+ foreach ($matches[0] as $match_item) { |
141 |
+ $key = substr($match_item, 1, -1); |
142 |
+ $replacement = "''"; |
143 |
+ if (isset($row[$key])) { |
144 |
+ $replacement = "'" . $row[$key] . "'"; |
145 |
+ } |
146 |
+ $expr = str_replace($match_item, $replacement, $expr); |
147 |
+ } |
148 |
+ $expr_evalcmd = 'return ' . $expr . ';'; |
149 |
+ $expr_evalres = eval($expr_evalcmd); |
150 |
+ return $expr_evalres; |
151 |
+} |
152 |
+ |
153 |
?> |