function processView() { if (empty($_POST['personid'])) { trigger_error("Cannot update persons, no person ID specified", E_USER_WARNING); return; } $customValues = array(); $customFields = $GLOBALS['system']->getDBObjectData('custom_field', array(), 'OR', 'rank'); $dummyField = new Custom_Field(); foreach ($customFields as $fieldid => $fieldDetails) { $dummyField->populate($fieldid, $fieldDetails); if ($val = $dummyField->processWidget()) { $customValues[$fieldid] = $val; } } foreach ($this->_allowedFields as $field) { if (array_get($_POST, $field, '') == '') { unset($_POST[$field]); } } if (empty($customValues) && count(array_intersect(array_keys($_POST), $this->_allowedFields)) == 0) { add_message("Cannot update; no new values were specified", 'error'); if (!empty($_REQUEST['backto'])) { parse_str($_REQUEST['backto'], $back); unset($back['backto']); redirect($back['view'], $back); } return; } $success = 0; $GLOBALS['system']->setFriendlyErrors(TRUE); foreach ((array) $_REQUEST['personid'] as $personid) { $this->_person = new Person((int) $personid); foreach ($this->_allowedFields as $field) { if (isset($_POST[$field])) { $this->_person->setValue($field, $_POST[$field]); } } foreach ($customValues as $fieldid => $val) { $this->_person->setCustomValue($fieldid, $val, array_get($_POST, 'custom_' . $fieldid . '_add', FALSE)); } if ($this->_person->validateFields() && $this->_person->save()) { $success++; } } if ($success == count($_REQUEST['personid'])) { add_message('Fields updated for ' . count($_REQUEST['personid']) . ' persons'); } else { if ($success > 0) { add_message("Fields updated for {$success} persons; some persons could not be updated"); } else { add_message('There was a problem updating the fields. Check your selected persons.'); } } if (!empty($_REQUEST['backto'])) { parse_str($_REQUEST['backto'], $back); unset($back['backto']); redirect($back['view'], $back); } }
function processForm() { parent::processForm(); $actions = array('notes' => array(), 'groups' => array(), 'groups_remove' => array(), 'dates' => array(), 'attendance' => NULL); $i = 0; while ($note = $this->_processNoteForm($i)) { $actions['notes'][] = $note; $i++; } $i = 0; while (isset($_POST['groups'][$i])) { if ($groupid = (int) $_POST['groups'][$i]) { $actions['groups'][] = $groupid; } $i++; } $i = 0; while (isset($_POST['groups_remove'][$i])) { if ($groupid = (int) $_POST['groups_remove'][$i]) { $actions['groups_remove'][] = $groupid; } $i++; } $addValue = array_get($_POST, 'fields_addvalue', array()); foreach (array_get($_POST, 'fields_enabled', array()) as $k => $v) { if (0 === strpos($k, 'custom_')) { $fieldID = substr($k, 7); $field = new Custom_Field($fieldID); if ($field->getValue('type') == 'date') { // FUture expansion: allow static dates here; for now we just support // the reference date, represented by magic number -1. $val = '-1===' . $_POST['custom_' . $fieldID . '_note']; } else { $val = $field->processWidget(); $val = reset($val); // it comes wrapped in an array } } else { $val = $_POST[$k]; } $actions['fields'][$k] = array('value' => $val, 'add' => array_get($addValue, $k, FALSE)); } $actions['attendance'] = $_POST['mark_present']; $this->setValue('actions', $actions); }