function processView()
 {
     if (empty($_REQUEST['planid'])) {
         add_message('No plans selected for execution', 'error');
         return;
     }
     if (empty($_REQUEST['personid'])) {
         add_message('No persons selected for plan execution', 'error');
         return;
     }
     $plans = array();
     foreach ($_REQUEST['planid'] as $planid) {
         $plans[] = $GLOBALS['system']->getDBObject('action_plan', $planid);
     }
     $refdate = process_widget('plan_reference_date', array('type' => 'date'));
     foreach ($_REQUEST['personid'] as $personid) {
         foreach ($plans as $plan) {
             $plan->execute('person', (int) $personid, $refdate);
         }
     }
     foreach ($plans as $plan) {
         add_message('"' . $plan->getValue('name') . '" plan executed for ' . count($_REQUEST['personid']) . ' person(s)', 'success');
     }
     if (count($_REQUEST['personid']) == 1) {
         redirect('persons', array('personid' => (int) reset($_REQUEST['personid'])));
     }
 }
 function processView()
 {
     $this->_family =& $GLOBALS['system']->getDBObject('family', $_REQUEST['familyid']);
     $GLOBALS['system']->includeDBClass('person');
     $this->_person = new Person();
     if (array_get($_REQUEST, 'new_person_submitted')) {
         $GLOBALS['system']->doTransaction('begin');
         $this->_person = new Person();
         $this->_person->processForm();
         $this->_person->setValue('familyid', $this->_family->id);
         if ($this->_person->create()) {
             if (!empty($_POST['execute_plan'])) {
                 foreach ($_POST['execute_plan'] as $planid) {
                     $plan = $GLOBALS['system']->getDBObject('action_plan', $planid);
                     $plan->execute('person', $this->_person->id, process_widget('plan_reference_date', array('type' => 'date')));
                 }
             }
             $GLOBALS['system']->doTransaction('commit');
             add_message('New family member added');
             redirect('families', array('familyid' => $this->_family->id));
             // exits
         } else {
             $GLOBALS['system']->doTransaction('rollback');
         }
     } else {
         $this->_person->setValue('last_name', $this->_family->getValue('family_name'));
     }
 }
 function processView()
 {
     if (empty($_REQUEST['params_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->start_date = array_get($_SESSION['attendance'], 'start_date', date('Y-m-d', strtotime('-7 weeks')));
             $this->end_date = array_get($_SESSION['attendance'], 'end_date');
         } else {
             $this->start_date = date('Y-m-d', strtotime('-7 weeks'));
         }
     } else {
         $this->age_bracket = $_SESSION['attendance']['age_bracket'] = $_REQUEST['age_bracket'];
         if ($this->age_bracket != '') {
             $this->age_bracket = (int) $this->age_bracket;
         }
         if (!empty($_REQUEST['congregationid']) && is_array($_REQUEST['congregationid'])) {
             foreach ($_REQUEST['congregationid'] as $congid) {
                 $this->congregationids[] = (int) $congid;
             }
             $_SESSION['attendance']['congregationids'] = $this->congregationids;
         }
         $this->groupid = $_SESSION['attendance']['groupid'] = array_get($_REQUEST, 'groupid');
         $this->start_date = $_SESSION['attendance']['start_date'] = process_widget('start_date', array('type' => 'date'));
         $this->end_date = $_SESSION['attendance']['end_date'] = process_widget('end_date', array('type' => 'date'));
     }
     // Make sure there are no empty congregation IDs, except the first one
     for ($i = count($this->congregationids); $i > 0; $i--) {
         if (empty($this->congregationids[$i])) {
             unset($this->congregationids[$i]);
         }
     }
 }
 function processView()
 {
     $this->_start_date = process_widget('start_date', array('type' => 'date'));
     $this->_end_date = process_widget('end_date', array('type' => 'date'));
     if (is_null($this->_end_date)) {
         $this->_end_date = date('Y-m-d', strtotime(date('Y-m-01') . ' -1 day'));
     }
     if (is_null($this->_start_date)) {
         $this->_start_date = date('Y-m-d', strtotime($this->_start_date . '  -3 months'));
     }
 }
 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;
         }
     }
 }
Ejemplo n.º 6
0
 function processView()
 {
     $this->editing = !empty($_REQUEST['editing']) && $GLOBALS['user_system']->havePerm(PERM_EDITSERVICE);
     if (!empty($_REQUEST['congregationid'])) {
         $this->congregationid = (int) $_REQUEST['congregationid'];
     }
     $this->date = process_widget('date', array('type' => 'date'));
     if (empty($this->date) && !empty($_SESSION['service_date'])) {
         $this->date = $_SESSION['service_date'];
     }
     if (empty($this->congregationid) && !empty($_SESSION['service_congregationid'])) {
         $this->congregationid = $_SESSION['service_congregationid'];
     }
     if ($this->congregationid && $this->date) {
         $_SESSION['service_date'] = $this->date;
         $_SESSION['service_congregationid'] = $this->congregationid;
         $this->service = NULL;
         $serviceData = $GLOBALS['system']->getDBOBjectData('service', array('congregationid' => $this->congregationid, 'date' => $this->date), 'AND');
         if (!empty($serviceData)) {
             // SAVE RUN SHEET
             $this->service = $GLOBALS['system']->getDBObject('service', key($serviceData));
             if ($this->editing) {
                 $this->service->acquireLock('items');
             }
             if (!empty($_REQUEST['save_service']) && $GLOBALS['user_system']->havePerm(PERM_EDITSERVICE)) {
                 if (!$this->service->haveLock('items')) {
                     trigger_error("Your lock expired and your changes could not be saved");
                     return;
                 }
                 $newItems = array();
                 foreach (array_get($_POST, 'componentid', array()) as $rank => $compid) {
                     $newItem = array('componentid' => $compid, 'title' => $_POST['title'][$rank], 'personnel' => $_POST['personnel'][$rank], 'show_in_handout' => $_POST['show_in_handout'][$rank], 'length_mins' => $_POST['length_mins'][$rank], 'note' => trim($_POST['note'][$rank]), 'heading_text' => trim($_POST['heading_text'][$rank]));
                     $newItems[] = $newItem;
                 }
                 $this->service->saveItems($newItems);
                 $this->service->saveComments(process_widget('service_comments', array('type' => 'html')));
                 $this->service->releaseLock('items');
                 $this->editing = FALSE;
             }
         }
     } else {
         $this->date = date('Y-m-d', strtotime('Sunday'));
     }
 }
 function processView()
 {
     $this->_start_date = process_widget('start_date', array('type' => 'date'));
     if (is_null($this->_start_date)) {
         if (!empty($_SESSION['roster_start_date'])) {
             $this->_start_date = $_SESSION['roster_start_date'];
         } else {
             $this->_start_date = date('Y-m-d');
         }
     }
     $this->_end_date = process_widget('end_date', array('type' => 'date'));
     if (is_null($this->_end_date)) {
         if (!empty($_SESSION['roster_end_date'])) {
             $this->_end_date = $_SESSION['roster_end_date'];
         } else {
             $this->_end_date = date('Y-m-d', strtotime('+' . ROSTER_WEEKS_DEFAULT . ' weeks'));
         }
     }
     if (!empty($_REQUEST['viewid'])) {
         $this->_view = $GLOBALS['system']->getDBObject('roster_view', (int) $_REQUEST['viewid']);
     }
     $_SESSION['roster_start_date'] = $this->_start_date;
     $_SESSION['roster_end_date'] = $this->_end_date;
 }
Ejemplo n.º 8
0
 static function processDatesInterface($prefix)
 {
     $res = NULL;
     if (!empty($_POST[$prefix . 'date'])) {
         $res = array();
         $date_params = array('type' => 'date', 'allow_blank_year' => true);
         foreach ($_POST[$prefix . 'date'] as $i => $d) {
             $d['date'] = process_widget($prefix . 'dateval[' . $i . ']', $date_params);
             if (empty($d['date'])) {
                 continue;
             }
             if (empty($d['typeid'])) {
                 $d['typeid'] = NULL;
             }
             if (empty($d['typeid']) && !strlen($d['note'])) {
                 add_message('The date "' . format_date($d['date']) . '" was not saved because no type or note was specified for it');
             } else {
                 // we only save each dateval+type combo once.  entries with notes win.
                 $res[] = $d;
             }
         }
     }
     return $res;
 }
Ejemplo n.º 9
0
 public function processFieldInterface($name, $prefix = '')
 {
     if (!$this->id || $this->haveLock()) {
         $value = process_widget($prefix . $name, $this->fields[$name]);
         if (!is_null($value)) {
             $this->setValue($name, $value);
         }
     }
 }
Ejemplo n.º 10
0
function process_widget($name, $params, $index = NULL, $preserveEmpties = FALSE)
{
    $testVal = $rawVal = array_get($_REQUEST, $name);
    if (empty($testVal) && $params['type'] == 'date') {
        $testVal = array_get($_REQUEST, $name . '_d');
    }
    if (is_array($testVal) && $params['type'] != 'bitmask' && array_get($params, 'allow_multiple', 0) == 0) {
        if (!is_null($index)) {
            $rawVal = $rawVal[$index];
        } else {
            $res = array();
            foreach ($testVal as $i => $v) {
                $x = process_widget($name, $params, $i);
                if ($preserveEmpties || strlen($x)) {
                    $res[] = $x;
                }
            }
            return $res;
        }
    }
    $value = null;
    switch ($params['type']) {
        case 'phone':
            if (array_get($params, 'allow_empty', TRUE) && empty($rawVal)) {
                $value = '';
            } else {
                if (!is_valid_phone_number($rawVal, $params['formats'])) {
                    trigger_error('The phone number "' . $rawVal . '" is not valid and has not been set', E_USER_NOTICE);
                    $value = NULL;
                } else {
                    $value = clean_phone_number($rawVal);
                }
            }
            break;
        case 'date':
            if (isset($rawVal)) {
                // might have an ISO8601 date
                if (preg_match('/^(\\d\\d\\d\\d-\\d\\d-\\d\\d)$/', $rawVal)) {
                    return $rawVal;
                }
            }
            if (FALSE === strpos($name, '[')) {
                $subindex = NULL;
            } else {
                $subindex = substr($name, strpos($name, '[') + 1, strpos($name, ']') - strpos($name, '[') - 1);
                $name = substr($name, 0, strpos($name, '['));
            }
            if (!isset($_REQUEST[$name . '_d'])) {
                return NULL;
            }
            if (!is_null($subindex) && !isset($_REQUEST[$name . '_d'][$subindex])) {
                return NULL;
            }
            foreach (array('y', 'm', 'd') as $comp) {
                $comp_vals[$comp] = array_get($_REQUEST, $name . '_' . $comp, 0);
                if (!is_null($index)) {
                    $comp_vals[$comp] = $comp_vals[$comp][$index];
                }
                if (!is_null($subindex)) {
                    $comp_vals[$comp] = $comp_vals[$comp][$subindex];
                }
            }
            $value = sprintf('%04d-%02d-%02d', $comp_vals['y'], $comp_vals['m'], $comp_vals['d']);
            if ($value == '0000-00-00') {
                return NULL;
            }
            if ($value == '0000-01-00') {
                return NULL;
            }
            if (array_get($params, 'allow_blank_year') && !(int) $comp_vals['y']) {
                $value = substr($value, 4);
                if (date('-m-d', strtotime('2000' . $value)) != $value) {
                    trigger_error('The date "' . $value . '" is not valid and has not been set', E_USER_NOTICE);
                    $value = NULL;
                }
            } else {
                if (date('Y-m-d', strtotime($value)) != $value) {
                    trigger_error('The date "' . $value . '" is not valid and has not been set', E_USER_NOTICE);
                    $value = NULL;
                }
            }
            break;
        case 'bibleref':
            if (!empty($rawVal)) {
                require_once 'bible_ref.class.php';
                $br = new bible_ref($rawVal);
                if ($br->book) {
                    $value = $br->toCode();
                }
            }
            break;
        case 'bitmask':
            // value is the bitwise-or of all submitted values
            $value = 0;
            if (isset($rawVal)) {
                foreach ((array) $rawVal as $i) {
                    $value = $value | (int) $i;
                }
            }
            break;
        case 'html':
            if (isset($rawVal)) {
                require_once 'htmLawed.php';
                $value = htmLawed($rawVal, array('deny_attribute' => '* -href', 'safe' => 1));
            }
            break;
        default:
            $value = $rawVal;
            if (!empty($params['regex']) && !empty($value) && !preg_match('/' . trim($params['regex'], '/') . '/i', $value)) {
                trigger_error($value . ' is not a valid value for ' . array_get($params, 'label', ucfirst($name)));
                $value = NULL;
            }
            break;
    }
    return $value;
}
Ejemplo n.º 11
0
 function _processRuleDetails($field)
 {
     $res = array();
     switch ($this->_field_details[$field]['type']) {
         case 'datetime':
             $res['from'] = process_widget('params_' . str_replace('.', '_', $field) . '_from', array('type' => 'date'));
             $res['to'] = process_widget('params_' . str_replace('.', '_', $field) . '_to', array('type' => 'date'));
             break;
         case 'select':
         case 'reference':
             $res = $this->_removeEmpties(array_get($_POST, 'params_' . str_replace('.', '_', $field), array()));
             break;
         default:
             $res = array_get($_POST, 'params_' . str_replace('.', '_', $field));
             break;
     }
     return $res;
 }
Ejemplo n.º 12
0
 /**
  * Process the interface for POPULATING fields within this note template
  * (used when adding a note to a person)
  */
 public function processNoteFieldWidgets()
 {
     $fields = $GLOBALS['system']->getDBObjectData('note_template_field', array('templateid' => $this->id), 'OR', 'rank');
     foreach ($fields as $id => $details) {
         if ($details['customfieldid']) {
             $cf = $GLOBALS['system']->getDBObject('custom_field', $details['customfieldid']);
             $this->_field_values[$id] = $cf->processWidget();
         } else {
             $params = unserialize($details['params']);
             $params['type'] = $details['type'];
             $this->_field_values[$id] = process_widget('template_field_' . $id, $params);
         }
     }
 }
 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);
     }
 }
Ejemplo n.º 16
0
 /**
  * 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;
 }
Ejemplo n.º 17
0
 function processView()
 {
     if (empty($this->_rootpath)) {
         $this->_rootpath = JETHRO_ROOT . '/files';
     }
     if (!is_dir($this->_rootpath)) {
         trigger_error("Documents root path " . $this->_rootpath . ' does not exist, please check your config file', E_USER_ERROR);
         // exits
     }
     $this->_realdir = $this->_rootpath;
     $this->_messages = array();
     if (!empty($_REQUEST['dir'])) {
         $this->_realdir = $this->_validateDirPath($_REQUEST['dir']);
     }
     if ($GLOBALS['user_system']->havePerm(PERM_EDITDOC)) {
         if (!empty($_POST['deletefolder'])) {
             if (rmdir($this->_realdir)) {
                 $this->_addMessage('Folder "' . basename($this->_realdir) . '" deleted');
                 $this->_realdir = dirname($this->_realdir);
             }
         }
         if (!empty($_POST['renamefolder'])) {
             if ($newname = $this->_validateDirName($_POST['renamefolder'])) {
                 $newdir = dirname($this->_realdir) . '/' . $newname;
                 if (rename($this->_realdir, $newdir)) {
                     $this->_addMessage('Folder "' . basename($this->_realdir) . '" renamed to "' . $newname . '"');
                     $this->_realdir = $newdir;
                 }
             }
         }
         if (!empty($_POST['newfolder'])) {
             if ($newname = $this->_validateDirName($_POST['newfolder'])) {
                 $newdir = $this->_realdir . '/' . $newname;
                 if (is_dir($newdir) || mkdir($newdir)) {
                     if ($p = fileperms(DOCUMENTS_ROOT_PATH)) {
                         chmod($newdir, $p);
                     }
                     $this->_addMessage('Folder "' . $newname . '" created');
                     $this->_realdir = $newdir;
                 }
             }
         }
         if (!empty($_FILES['newfile'])) {
             foreach ($_FILES['newfile']['error'] as $key => $error) {
                 if ($error == UPLOAD_ERR_OK) {
                     $tmp_name = $_FILES["newfile"]["tmp_name"][$key];
                     if ($name = $this->_validateFileName($_FILES["newfile"]["name"][$key])) {
                         if (move_uploaded_file($tmp_name, $this->_realdir . '/' . $name)) {
                             if ($p = fileperms(DOCUMENTS_ROOT_PATH)) {
                                 chmod($this->_realdir . '/' . $name, $p);
                             }
                             $this->_addMessage('File "' . $name . '" saved');
                         }
                     }
                 } else {
                     trigger_error("There was an error ({$error}) uploading a file");
                 }
             }
         }
         if (!empty($_FILES['replacefile'])) {
             foreach ($_FILES['replacefile']['error'] as $origname => $error) {
                 if ($error == UPLOAD_ERR_OK && ($origname = $this->_validateFileName($origname))) {
                     $tmp_name = $_FILES["replacefile"]["tmp_name"][$origname];
                     if (file_exists($this->_realdir . '/' . $origname)) {
                         if (move_uploaded_file($tmp_name, $this->_realdir . '/' . $origname)) {
                             if ($p = fileperms(DOCUMENTS_ROOT_PATH)) {
                                 chmod($this->_realdir . '/' . $origname, $p);
                             }
                             $this->_addMessage('File "' . $origname . '" replaced');
                         }
                     }
                 }
             }
         }
         if (!empty($_POST['deletefile'])) {
             foreach ($_POST['deletefile'] as $delname) {
                 if ($delname = $this->_validateFileName($delname)) {
                     if (file_exists($this->_realdir . '/' . $delname) && unlink($this->_realdir . '/' . $delname)) {
                         $this->_addMessage('File "' . $delname . '" deleted');
                     }
                 }
             }
         }
         if (!empty($_POST['renamefile'])) {
             foreach ($_POST['renamefile'] as $origname => $newname) {
                 if (($newname = $this->_validateFileName($newname)) && ($origname = $this->_validateFileName($origname))) {
                     if (file_exists($this->_realdir . '/' . $origname) && rename($this->_realdir . '/' . $origname, $this->_realdir . '/' . $newname)) {
                         $this->_addMessage("{$origname} renamed to {$newname}");
                     }
                 }
             }
         }
         if (!empty($_POST['movefile'])) {
             foreach ($_POST['movefile'] as $filename => $newdir) {
                 if (($filename = $this->_validateFileName($filename)) && ($fulldir = $this->_validateDirPath($newdir))) {
                     if (rename($this->_realdir . '/' . $filename, $fulldir . '/' . $filename)) {
                         $this->_addMessage("\"{$filename}\" moved to folder \"{$newdir}\"");
                     }
                 }
             }
         }
         if (!empty($_REQUEST['editfile'])) {
             if ($_REQUEST['editfile'] == '_new_') {
                 $this->_editfile = '_new_';
             } else {
                 $this->_editfile = $this->_validateFileName($_REQUEST['editfile']);
             }
         }
         if (!empty($_POST['savefile'])) {
             if ($filename = $this->_validateFileName($_POST['savefile'])) {
                 if (!$this->_isHTML($filename)) {
                     trigger_error($this->_getExtension($filename) . " - Only HTML files can be saved", E_USER_ERROR);
                     // exits
                 }
                 if (!empty($_POST['isnew']) && file_exists($this->_realdir . '/' . $filename)) {
                     trigger_error("{$filename} already exists in this folder.  Please choose another name.");
                     $this->_editfile = $filename;
                 } else {
                     if (file_put_contents($this->_realdir . '/' . $filename, process_widget('contents', array('type' => 'html')))) {
                         if ($p = fileperms(DOCUMENTS_ROOT_PATH)) {
                             chmod($this->_realdir . '/' . $filename, $p);
                         }
                         $this->_addMessage("\"{$filename}\" saved");
                     }
                 }
             }
         }
     }
 }
 private function _handleProgramSave()
 {
     // Update and/or create services on existing dates
     $dummy = new Service();
     foreach ($this->_grouped_services as $date => $date_services) {
         foreach ($this->_congregations as $congid) {
             if (isset($date_services[$congid])) {
                 // update the existing service
                 $dummy->populate($date_services[$congid]['id'], $date_services[$congid]);
                 if ($dummy->acquireLock()) {
                     $this->_processServiceCell($congid, $date, $dummy);
                     $dummy->save();
                     $dummy->releaseLock();
                 } else {
                     trigger_error("Could not acquire lock on individual service for {$congid} on {$date} - didn't save");
                 }
             } else {
                 if (!empty($_POST['topic_title'][$congid][$date]) || !empty($_POST['format_title'][$congid][$date]) || !empty($_POST['bible_ref0'][$congid][$date])) {
                     // create a new service
                     $service = new Service();
                     $service->setValue('date', $date);
                     $service->setValue('congregationid', $congid);
                     $this->_processServiceCell($congid, $date, $service);
                     $service->create();
                 }
             }
         }
     }
     // Add services on new dates
     $i = 0;
     while (isset($_POST['new_service_date_d'][$i])) {
         foreach ($this->_congregations as $congid) {
             if (!empty($_POST['topic_title'][$congid]['new_' . $i]) || !empty($_POST['format_title'][$congid]['new_' . $i]) || !empty($_POST['bible_refs'][$congid]['new_' . $i][0]) || !empty($_POST['bible_refs'][$congid]['new_' . $i][1])) {
                 // we need to create a service here
                 $service = new Service();
                 $service->setValue('date', process_widget('new_service_date[' . $i . ']', array('type' => 'date')));
                 $service->setValue('congregationid', $congid);
                 $this->_processServiceCell($congid, 'new_' . $i, $service);
                 $service->create();
             }
         }
         $i++;
     }
     $shifted = FALSE;
     // Process the "delete" commands if necessary
     if (!empty($_POST['delete_single'])) {
         $service = $GLOBALS['system']->getDBOBject('service', (int) $_POST['delete_single']);
         if ($service) {
             $service->delete();
             if (!empty($_POST['shift_after_delete'])) {
                 Service::shiftServices(array($service->getValue('congregationid')), $service->getValue('date'), '-7');
                 $shifted = TRUE;
             }
         }
     }
     if (!empty($_POST['delete_all_date'])) {
         $services = $GLOBALS['system']->getDBObjectData('service', array('date' => $_POST['delete_all_date'], 'congregationid' => $this->_congregations), 'AND');
         $dummy = new Service();
         foreach ($services as $id => $details) {
             $dummy->populate($id, $details);
             $dummy->delete();
             $shifted = TRUE;
         }
         if (!empty($_POST['shift_after_delete'])) {
             Service::shiftServices($this->_congregations, $_POST['delete_all_date'], '-7');
             $shifted = TRUE;
         }
     }
     // Process the "insert" commands if necessary
     if (!empty($_POST['insert_all_date'])) {
         Service::shiftServices($this->_congregations, $_POST['insert_all_date'], '7');
         $shifted = TRUE;
     }
     if (!empty($_POST['insert_single_date'])) {
         foreach ($_POST['insert_single_date'] as $congid => $date) {
             Service::shiftServices(array($congid), $date, '7');
             $shifted = TRUE;
         }
     }
     if (!$shifted) {
         foreach ($this->_congregations as $id) {
             $cong = $GLOBALS['system']->getDBObject('congregation', $id);
             $cong->releaseLock('services');
         }
         add_message("Services saved");
         redirect($_REQUEST['view'], array('editing' => NULL));
     }
     $this->_loadServices();
 }
Ejemplo n.º 19
0
 /**
  * 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;
 }
 function processView()
 {
     if (isset($_REQUEST['cohortids'])) {
         foreach ($_REQUEST['cohortids'] as $id) {
             if ($id) {
                 $this->_cohortids[] = $id;
             }
         }
         $_SESSION['attendance']['cohortids'] = $this->_cohortids;
     }
     $this->_attendance_date = process_widget('attendance_date', array('type' => 'date'));
     if (empty($this->_attendance_date)) {
         // Default to last Sunday, unless today is Sunday
         $default_day = defined('ATTENDANCE_DEFAULT_DAY') ? ATTENDANCE_DEFAULT_DAY : 'Sunday';
         $this->_attendance_date = date('Y-m-d', date('l') == $default_day ? time() : strtotime('last ' . $default_day));
     }
     if (empty($_REQUEST['params_submitted']) && empty($_REQUEST['attendances_submitted'])) {
         if (!empty($_SESSION['attendance'])) {
             $this->_age_brackets = array_get($_SESSION['attendance'], 'age_brackets');
             $this->_statuses = array_get($_SESSION['attendance'], 'statuses');
             $this->_cohortids = array_get($_SESSION['attendance'], 'cohortids');
             $this->_show_photos = array_get($_SESSION['attendance'], 'show_photos', FALSE);
             $this->_parallel_mode = array_get($_SESSION['attendance'], 'parallel_mode', FALSE);
         }
     }
     if (!empty($_REQUEST['params_submitted']) || !empty($_REQUEST['attendances_submitted'])) {
         if (!empty($_REQUEST['age_brackets_all'])) {
             unset($_REQUEST['age_brackets']);
         }
         if (!empty($_REQUEST['statuses_all'])) {
             unset($_REQUEST['statuses']);
         }
         $this->_age_brackets = $_SESSION['attendance']['age_brackets'] = array_get($_REQUEST, 'age_brackets');
         $this->_statuses = $_SESSION['attendance']['statuses'] = array_get($_REQUEST, 'statuses');
         $this->_show_photos = $_SESSION['attendance']['show_photos'] = array_get($_REQUEST, 'show_photos', FALSE);
         $this->_parallel_mode = $_SESSION['attendance']['parallel_mode'] = array_get($_REQUEST, 'parallel_mode', FALSE);
     }
     foreach ($this->_cohortids as $id) {
         $this->_record_sets[$id] = new Attendance_Record_set($this->_attendance_date, $id, $this->_age_brackets, $this->_statuses);
         if ($this->_show_photos) {
             $this->_record_sets[$id]->show_photos = TRUE;
         }
     }
     if (!empty($_REQUEST['release'])) {
         foreach ($this->_record_sets as $set) {
             $set->releaseLock();
         }
     } else {
         if (!empty($_REQUEST['params_submitted'])) {
             foreach ($this->_record_sets as $cohortid => $set) {
                 if (!$set->checkAllowedDate()) {
                     add_message(_('"Attendance for "') . $set->getCohortName() . _('" cannot be recorded on a "') . date('l', strtotime($this->_attendance_date)), 'error');
                     unset($this->_record_sets[$cohortid]);
                     $this->_cohortids = array_diff($this->_cohortids, array($cohortid));
                     continue;
                 }
                 if (!$set->acquireLock()) {
                     add_message(_('"Another user is currently recording attendance for "') . $set->getCohortName() . _('".  Please wait until they finish then try again."'), 'error');
                     unset($this->_record_sets[$cohortid]);
                     $this->_cohortids = array_diff($this->_cohortids, array($cohortid));
                 }
             }
         }
     }
     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->haveLock() && !$set->acquireLock()) {
                     add_message("Unfortunately your lock on '" . $set->getCohortName() . "' has expired and been acquired by another user.  Please wait until they finish and try again.", 'error');
                 } else {
                     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]);
                         }
                         $set->releaseLock();
                     }
                 }
             }
         } 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()
 {
     $GLOBALS['system']->includeDBClass('family');
     $this->_family = new Family();
     if (array_get($_REQUEST, 'new_family_submitted')) {
         // some initial checks
         $i = 0;
         $found_member = FALSE;
         while (isset($_POST['members_' . $i . '_first_name'])) {
             if (!empty($_POST['members_' . $i . '_first_name'])) {
                 $found_member = TRUE;
             }
             $i++;
         }
         if (!$found_member) {
             add_message('New family must have at least one member', 'failure');
             return FALSE;
         }
         if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) {
             if (REQUIRE_INITIAL_NOTE && empty($_POST['initial_note_subject'])) {
                 add_message("A subject must be supplied for the initial family note", 'failure');
                 return FALSE;
             }
         }
         $GLOBALS['system']->doTransaction('begin');
         // Create the family record itself
         $this->_family->processForm();
         $success = $this->_family->create();
         if ($success) {
             // Add members
             $i = 0;
             $members = array();
             $GLOBALS['system']->includeDBClass('person');
             while (isset($_POST['members_' . $i . '_first_name'])) {
                 if (!empty($_POST['members_' . $i . '_first_name'])) {
                     $member = new Person();
                     $member->setValue('familyid', $this->_family->id);
                     $member->processForm('members_' . $i . '_');
                     if (!$member->create()) {
                         $success = FALSE;
                         break;
                     }
                     $members[] =& $member;
                 }
                 $i++;
             }
         }
         if ($success) {
             if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) {
                 if (REQUIRE_INITIAL_NOTE || !empty($_POST['initial_note_subject'])) {
                     // Add note
                     if (count($members) > 1) {
                         $GLOBALS['system']->includeDBClass('family_note');
                         $note = new Family_Note();
                         $note->setValue('familyid', $this->_family->id);
                     } else {
                         $GLOBALS['system']->includeDBClass('person_note');
                         $note = new Person_Note();
                         $note->setValue('personid', $members[0]->id);
                     }
                     $note->processForm('initial_note_');
                     $success = $note->create();
                 }
             }
             if (!empty($_POST['execute_plan'])) {
                 foreach ($_POST['execute_plan'] as $planid) {
                     $plan = $GLOBALS['system']->getDBObject('action_plan', $planid);
                     $plan->execute('family', $this->_family->id, process_widget('plan_reference_date', array('type' => 'date')));
                 }
             }
         }
         // Before committing, check for duplicates
         if (empty($_REQUEST['override_dup_check'])) {
             $this->_similar_families = $this->_family->findSimilarFamilies();
             if (!empty($this->_similar_families)) {
                 $GLOBALS['system']->doTransaction('rollback');
                 return;
             }
         }
         if ($success) {
             $GLOBALS['system']->doTransaction('commit');
             add_message('Family Created');
             redirect('families', array('familyid' => $this->_family->id));
         } else {
             $GLOBALS['system']->doTransaction('rollback');
             $this->_family->id = 0;
             add_message('Error during family creation, family not created', 'failure');
         }
     }
 }