| 1 |
<?php |
<?php |
| 2 |
// $Id: mailhandler.module,v 1.87.2.8 2008/05/02 15:06:45 weitzman Exp $ |
// $Id: mailhandler.module,v 1.87.2.9 2008/05/02 17:32:18 weitzman Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Retrieve all msgs from a given mailbox and process them. |
* Retrieve all msgs from a given mailbox and process them. |
| 151 |
list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox); |
list($fromaddress, $fromname) = mailhandler_get_fromaddress($header, $mailbox); |
| 152 |
|
|
| 153 |
//dprint_r($node); //DEBUG |
//dprint_r($node); //DEBUG |
| 154 |
|
|
| 155 |
|
// Drupal 5.x & 6.x don't support multiple validations: each node_validate() |
| 156 |
|
// call will ADD error messages to previous ones, so if some validation error |
| 157 |
|
// occours in one message it will be reported in all messages after it. |
| 158 |
|
// Since there is no way to reset form errors, the only method to avoid this |
| 159 |
|
// problem is working with $_SESSION['messages'], used by form_set_error(). |
| 160 |
|
// See http://drupal.org/node/271975 for more info. |
| 161 |
|
// Warning: with this method, if the same error message is reported for 2+ different |
| 162 |
|
// fields it will be detected only for the last one. |
| 163 |
|
|
| 164 |
|
if (!isset($_SESSION['messages'])) { |
| 165 |
|
$_SESSION['messages'] = array(); |
| 166 |
|
} |
| 167 |
|
$saved_errors = is_array($_SESSION['messages']['error']) ? $_SESSION['messages']['error'] : array(); |
| 168 |
|
$_SESSION['messages']['error'] = array(); |
| 169 |
node_validate($node); |
node_validate($node); |
| 170 |
$error = form_get_errors(); |
$error = array(); |
| 171 |
|
if (count($_SESSION['messages']['error'])) { |
| 172 |
|
$allerrors = form_get_errors(); |
| 173 |
|
foreach ($_SESSION['messages']['error'] as $message) { |
| 174 |
|
$keys = array_keys($allerrors, $message); |
| 175 |
|
if (!$keys || !count($keys)) { |
| 176 |
|
// Not a validation error (but an error, i'll print it) |
| 177 |
|
$saved_errors[] = $message; |
| 178 |
|
} else { |
| 179 |
|
// This is a validation error, i take the last field with it (previous fields |
| 180 |
|
// should be about previous validations) |
| 181 |
|
$error[$keys[count($keys) - 1]] = $message; |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
|
} |
| 185 |
|
$_SESSION['messages']['error'] = $saved_errors; |
| 186 |
|
|
| 187 |
if (!$error) { |
if (!$error) { |
| 188 |
// Prepare the node for save and allow modules make changes |
// Prepare the node for save and allow modules make changes |
| 189 |
$node = node_submit($node); |
$node = node_submit($node); |