protected function _getChanges() { $res = parent::_getChanges(); if (!empty($this->_old_custom_values)) { $customFields = $this->getCustomFields(); $dummyField = new Custom_Field(); foreach ($this->_old_custom_values as $fieldid => $oldVal) { $dummyField->populate($fieldid, $customFields[$fieldid]); $res[] = $dummyField->getValue('name') . ' changed from "' . $dummyField->formatValue($oldVal) . '" to "' . $dummyField->formatValue($this->_custom_values[$fieldid]) . '"'; } } return $res; }
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); }
<?php $dummy = new Person(); foreach (array('congregationid', 'status', 'age_bracket') as $field) { $dummy->fields[$field]['allow_empty'] = TRUE; $dummy->fields[$field]['empty_text'] = '(No change)'; $dummy->setValue($field, NULL); echo '<tr><td>Set ' . $dummy->getFieldLabel($field) . ' to: </td><td>'; $dummy->printFieldInterface($field); echo '</td></tr>'; } $customFields = $GLOBALS['system']->getDBObjectData('custom_field', array(), 'OR', 'rank'); $dummy = new Custom_Field(); $addParams = array('type' => 'select', 'options' => array('Replacing existing values ', 'Adding to existing values')); foreach ($customFields as $fieldid => $fieldDetails) { $dummy->populate($fieldid, $fieldDetails); echo '<tr><td>Set ' . ents($dummy->getValue('name')) . ' to: </td><td>'; $dummy->printWidget(''); if ($dummy->getValue('allow_multiple')) { echo '</td><td>'; print_widget('custom_' . $fieldid . '_add', $addParams, 0); } echo '</td></tr>'; } ?> </table> <input type="submit" class="btn" onclick="return confirm('Are you sure you want to bulk-update these persons?')" value="Go" data-set-form-action="<?php echo BASE_URL; ?> ?view=_persons_bulk_update&backto=<?php echo urlencode(http_build_query($_GET)); ?>
function printView() { if (is_null($this->fields)) { return; } if (empty($this->fields)) { ?> <p><i>No custom fields have been set up in the system yet.</i></p> <?php } $field = new Custom_Field(); $this->fields['_new_'] = $field; ?> <form method="post"> <table id="custom-fields-editor" class="table table-auto-width expandable valign-top"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Type</th> <th>Multi?</th> <th>Divider?</th> <th>Heading?</th> <th>Parameters</th> <th><i class="icon-trash"></i></th> </tr> </thead> <tbody> <?php $i = 0; foreach ($this->fields as $field) { $prefix = 'fields_' . $i . '_'; $class = $field->getValue('divider_before') ? 'class="divider-before"' : ''; ?> <tr <?php echo $class; ?> > <td class="cursor-move"> <?php echo $field->id; print_hidden_field($prefix . 'id', $field->id); print_hidden_field('index[]', $i); ?> </td> <td class="name"> <?php $field->printFieldInterface('heading_before', $prefix); ?> <?php $field->printFieldInterface('name', $prefix); ?> </td> <td> <?php if ($field->id) { $field->printFieldValue('type'); } else { $field->printFieldInterface('type', $prefix); } ?> </td> <td class="center"> <?php $field->printFieldInterface('allow_multiple', $prefix); ?> </td> <td class="center toggle-divider"> <?php $field->printFieldInterface('divider_before', $prefix); ?> </td> <td class="center toggle-heading"> <?php $field->printFieldInterface('heading_before_toggle', $prefix); ?> </td> <td> <?php $field->printFieldInterface('params', $prefix); ?> </td> <td class="center"> <?php if ($field->id) { ?> <input type="checkbox" name="<?php echo $prefix; ?> delete" value="1" data-toggle="strikethrough" data-target="row" title="Click to delete this field" /> <?php } ?> </td> </tr> <?php $i++; } ?> </tbody> </table> <input type="submit" class="btn" value="Save" /> </form> <?php }