function processView()
{
$GLOBALS['system']->includeDBClass('service');
$this->_service_date = process_widget('service_date', array('type' => 'date'));
$this->_congregations = $GLOBALS['system']->getDBObjectData('congregation', array('!meeting_time' => ''));
if (empty($this->_congregations)) {
add_message("You need to set the 'code name' for some of your congregations before using this feature", 'failure');
$this->_congregations = NULL;
// mark that we neve had any even before processing
return;
}
$this->_dirs['populate'] = SERVICE_DOCS_TO_POPULATE_DIRS ? explode('|', SERVICE_DOCS_TO_POPULATE_DIRS) : '';
$this->_dirs['expand'] = SERVICE_DOCS_TO_EXPAND_DIRS ? explode('|', SERVICE_DOCS_TO_EXPAND_DIRS) : '';
if (empty($this->_dirs['populate']) && empty($this->_dirs['expand'])) {
add_message("You need to set a value for SERVICE_DOCS_TO_POPULATE_DIRS or SERVICE_DOCS_TO_EXPAND_DIRS in your system configuration before using this feature", 'failure');
$this->_dirs = NULL;
return;
}
// Convert relative path names to absolute, and warn of non-existent folders
$rootpath = DOCUMENTS_ROOT_PATH ? DOCUMENTS_ROOT_PATH : JETHRO_ROOT . '/files';
foreach (array('populate', 'expand') as $dirtype) {
foreach ($this->_dirs[$dirtype] as $i => &$dir) {
if (!is_dir($dir)) {
if (is_dir($rootpath . '/' . $dir)) {
$dir = $rootpath . '/' . $dir;
} else {
add_message("The folder " . $this->_cleanDirName($dir) . ' was not found and will not be used. Check your system config file.', 'warning');
unset($this->_dirs[$dirtype][$i]);
}
}
}
}
unset($dir);
// foreach by ref is dangerous.
if ($this->_service_date) {
switch (array_get($_REQUEST, 'action')) {
case 'initiate':
$this->processInitiate();
break;
case 'populate':
$this->processPopulate();
break;
case 'expand':
$this->processExpand();
break;
}
}
}
public function processView()
{
if (!count(self::getCongregations())) {
add_message("You need to set the 'code name' for some of your congregations before using this feature", 'failure');
return;
}
$this->_service_date = process_widget('date', array('type' => 'date'));
if (empty($this->_service_date)) {
add_message("No date supplied");
return;
}
if (!in_array(array_get($_REQUEST, 'action'), array('populate', 'expand'))) {
add_message("Invalid action specified");
return;
}
$this->_action = $_REQUEST['action'];
if (empty($_REQUEST['filename'])) {
add_message("no filename supplied");
return;
}
$this->_filename = self::resolveFilename($this->_action, $_REQUEST['filename']);
if (!$this->_filename) {
add_message("Unkown template " . $_REQUEST['filename']);
return;
}
if (!empty($_REQUEST['replacements'])) {
$method = '_process' . ucfirst($this->_action) . '';
$this->{$method}();
} else {
$this->loadReplacements();
}
}
function processView()
{
if (empty($_REQUEST['params_submitted']) && empty($_REQUEST['attendances_submitted'])) {
if (!empty($_SESSION['attendance'])) {
$this->_age_bracket = array_get($_SESSION['attendance'], 'age_bracket');
$this->_congregationids = array_get($_SESSION['attendance'], 'congregationids');
$this->_groupid = array_get($_SESSION['attendance'], 'groupid');
$this->_show_photos = array_get($_SESSION['attendance'], 'show_photos', FALSE);
}
// Default to last Sunday, unless today is Sunday
$this->_attendance_date = date('Y-m-d', date('D') == 'Sun' ? time() : strtotime('last Sunday'));
}
if (!empty($_REQUEST['params_submitted']) || !empty($_REQUEST['attendances_submitted'])) {
$this->_attendance_date = process_widget('attendance_date', array('type' => 'date'));
$this->_age_bracket = $_SESSION['attendance']['age_bracket'] = array_get($_REQUEST, 'age_bracket');
$this->_show_photos = $_SESSION['attendance']['show_photos'] = array_get($_REQUEST, 'show_photos', FALSE);
$status = NULL;
// TODO
if ($_REQUEST['for_type'] == 'congregationid') {
$cids = process_widget('congregationid', array('type' => 'reference', 'references' => 'congregation', 'multiple' => true));
foreach ($cids as $cid) {
if ($cid && !in_array($cid, $this->_congregationids)) {
$this->_congregationids[] = $cid;
$this->_record_sets[] = new Attendance_Record_Set($this->_attendance_date, $this->_age_bracket, $status, $cid, 0);
}
}
$_SESSION['attendance']['congregationids'] = $this->_congregationids;
$_SESSION['attendance']['groupid'] = null;
} else {
$this->_groupid = process_widget('groupid', array('type' => 'reference', 'references' => 'person_group', 'allow_empty' => false));
if ($this->_groupid) {
$this->_record_sets[] = new Attendance_Record_Set($this->_attendance_date, $this->_age_bracket, $status, NULL, $this->_groupid);
$_SESSION['attendance']['congregationids'] = array();
$_SESSION['attendance']['groupid'] = $this->_groupid;
}
}
if ($this->_show_photos) {
foreach ($this->_record_sets as $set) {
$set->show_photos = TRUE;
}
}
}
if (!empty($_REQUEST['attendances_submitted'])) {
// Process step 2
if ($_SESSION['enter_attendance_token'] == $_REQUEST['enter_attendance_token']) {
// Clear the token from the session on disk
$_SESSION['enter_attendance_token'] = NULL;
session_write_close();
session_start();
// Process the form
foreach ($this->_record_sets as $i => $set) {
if ($set->processForm($i)) {
$set->save();
if ((int) $set->congregationid) {
Headcount::save('congregation', $this->_attendance_date, $set->congregationid, $_REQUEST['headcount']['congregation'][$set->congregationid]);
} else {
Headcount::save('person_group', $this->_attendance_date, $set->groupid, $_REQUEST['headcount']['group'][$set->groupid]);
}
}
}
} else {
trigger_error('Could not save attendances - synchronizer token does not match. This probably means the request was duplicated somewhere along the line. If you see your changes below, they have been saved by the other request');
sleep(3);
// Give the other one time to finish before we load again
// Pretend we are back in step 2
$_POST['attendances_submitted'] = FALSE;
$_SESSION['enter_attendance_token'] = md5(time());
}
}
}
function processView()
{
if (empty($_POST['personid'])) {
trigger_error("Cannot update persons, no person ID specified", E_USER_WARNING);
return;
}
foreach ($this->_allowedFields as $field) {
if (array_get($_POST, $field, '') == '') {
unset($_POST[$field]);
}
}
if (empty($_POST['date_typeid']) && 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;
}
if (!is_array($_POST['personid'])) {
$_REQUEST['personid'] = array($_REQUEST['personid']);
}
$GLOBALS['system']->includeDBClass('person');
$success = 0;
$GLOBALS['system']->setFriendlyErrors(TRUE);
foreach ($_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]);
}
}
if (!empty($_POST['date_typeid'])) {
$params = Person::getDateSubfieldParams();
$dateval = process_widget('date_val', $params['date']);
if (!$dateval) {
trigger_error("Invalid date value; cannot set date field");
return;
}
$this->_person->addDate($dateval, $_POST['date_typeid'], $_POST['date_note']);
}
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);
}
}
/**
* Process an interface where an end user supplies a value for this custom field for a person record
* @return mixed
*/
public function processWidget()
{
$res = process_widget('custom_' . $this->id, $this->getWidgetParams());
if ($this->getValue('type') == 'date' && !empty($this->values['params']['allow_note'])) {
$notes = process_widget('custom_' . $this->id . '_note', array('type' => 'text'));
foreach ((array) $notes as $k => $v) {
if (!empty($res[$k])) {
$res[$k] .= ' ' . $v;
}
}
}
return $res;
}
/**
* Process an interface where an end user supplies a value for this custom field for a person record
* @return mixed
*/
public function processWidget()
{
$res = process_widget('custom_' . $this->id, $this->getWidgetParams(), NULL, TRUE);
if ($this->getValue('type') == 'date' && !empty($this->values['params']['allow_note'])) {
$notes = process_widget('custom_' . $this->id . '_note', array('type' => 'text'), NULL, TRUE);
foreach ((array) $notes as $k => $v) {
if (!empty($res[$k]) && strlen($v)) {
$res[$k] .= ' ' . $v;
}
}
}
if (is_array($res)) {
$res = array_remove_empties($res);
}
return $res;
}
请发表评论