コード例 #1
0
function save_congregation_callback()
{
    // determine if this a save existing or save new situation
    $CongregationPIN = $_POST['PIN'];
    $Congregation = new Congregation();
    $saveType = $_POST['savetype'];
    // populate the object with the posted data
    $Congregation->PIN = $CongregationPIN;
    $Congregation->CongregationName = trim($_POST['CongregationName']);
    $Congregation->EIN = trim($_POST['EIN']);
    $Congregation->Address1 = trim($_POST['Address1']);
    $Congregation->Address2 = trim($_POST['Address2']);
    $Congregation->City = trim($_POST['City']);
    $Congregation->State = trim($_POST['State']);
    $Congregation->PostalCode = trim($_POST['PostalCode']);
    $Congregation->Phone = trim($_POST['Phone']);
    $Congregation->Email = trim($_POST['Email']);
    $Congregation->Website = trim($_POST['Website']);
    $Congregation->Region = trim($_POST['Region']);
    $Congregation->Latitude = trim($_POST['Latitude']);
    $Congregation->Longitude = trim($_POST['Longitude']);
    $Congregation->DoNotAutoUpdate = $_POST['DoNotAutoUpdate'];
    if ($saveType == 'existing') {
        $SavedResult = $Congregation->save_current_congregation();
    } else {
        $SavedResult = $Congregation->save_new_congregation();
    }
    $ResultResponse['result'] = $SavedResult;
    echo json_encode($ResultResponse);
    die;
}
コード例 #2
0
    function processView()
    {
        $GLOBALS['system']->includeDBClass('family');
        $GLOBALS['system']->includeDBClass('person');
        $GLOBALS['system']->includeDBClass('person_group');
        $GLOBALS['system']->includeDBClass('congregation');
        $GLOBALS['system']->includeDBClass('person_note');
        if (!empty($_REQUEST['done'])) {
            $this->_stage = 'done';
        } else {
            if (!empty($_POST['confirm_import'])) {
                ini_set('memory_limit', '256M');
                ini_set('max_execution_time', 60 * 10);
                ini_set('zlib.output_compression', 'Off');
                // read from session and create
                $GLOBALS['system']->doTransaction('BEGIN');
                $group = $GLOBALS['system']->getDBObject('person_group', $_SESSION['import']['groupid']);
                $this->_captureErrors();
                $done = 0;
                ?>
			<h1 style="position: absolute; text-align: center; top: 40%; color: #ccc; width: 100%">Importing...</h1>
			<div style="border: 1px solid; width: 50%; height: 30px; top: 50%; left: 25%; position: absolute"><div id="progress" style="background: blue; height: 30px; width: 2%; overflow: visible; line-height: 30px; text-align: center; color: white" /></div>
			<p style="text-align: center; color: #888">If this indicator stops making progress, your import may still be running in the background.<br />You should <a href="<?php 
                echo build_url(array('view' => 'persons__list_all'));
                ?>
">check your system for the imported persons</a> before running the import again.</p>
			<?php 
                foreach ($_SESSION['import']['families'] as $familydata) {
                    $members = $familydata['members'];
                    unset($familydata['members']);
                    $family = new Family();
                    $family->populate(0, $familydata);
                    if ($family->create()) {
                        foreach ($members as $persondata) {
                            $notetext = null;
                            if (!empty($persondata['note'])) {
                                $notetext = $persondata['note'];
                                unset($persondata['note']);
                            }
                            $person = new Person();
                            $person->populate(0, $persondata);
                            $person->setValue('familyid', $family->id);
                            if ($person->create()) {
                                $group->addMember($person->id);
                                if ($notetext) {
                                    $note = new Person_Note();
                                    $note->setValue('subject', 'Import note');
                                    $note->setvalue('details', $notetext);
                                    $note->setValue('personid', $person->id);
                                    $note->create();
                                    unset($note);
                                }
                                unset($person);
                            }
                        }
                        $done++;
                        if ($done % 20 == 0) {
                            ?>
<script>var d = document.getElementById('progress'); d.innerHTML = 'Importing family <?php 
                            echo $done . ' of ' . $_SESSION['import']['total_families'];
                            ?>
'; d.style.width = '<?php 
                            echo (int) ($done / $_SESSION['import']['total_families'] * 100);
                            ?>
%'</script><?php 
                            echo str_repeat('    ', 1024 * 4);
                        }
                        flush();
                        unset($family);
                    }
                }
                if ($errors = $this->_getErrors()) {
                    $msg = 'Errors during import - import aborted. <ul><li>' . implode('</li></li>', $errors) . '</li></ul>';
                    add_message($msg, 'failure', true);
                    $GLOBALS['system']->doTransaction('ROLLBACK');
                } else {
                    add_message('Import complete', 'success');
                    $GLOBALS['system']->doTransaction('COMMIT');
                }
                ?>
<script>document.location = '<?php 
                echo build_url(array());
                ?>
&done=1';</script>
			<?php 
                exit;
            } else {
                if (!empty($_FILES['import'])) {
                    if (empty($_REQUEST['groupid'])) {
                        add_message("You must choose a group first", 'error');
                        $this->stage = 'begin';
                        return;
                    }
                    if (empty($_FILES['import']) || empty($_FILES['import']['tmp_name'])) {
                        add_message("You must upload a file", 'error');
                        return;
                    }
                    $this->_dummy_family = new Family();
                    $this->_dummy_person = new Person();
                    // read the csv and save to session
                    $fp = fopen($_FILES['import']['tmp_name'], 'r');
                    if (!$fp) {
                        add_message("There was a problem reading your CSV file.  Please try again.", 'error');
                        $this->stage = 'begin';
                        return;
                    }
                    $map = fgetcsv($fp, 0, ",", '"');
                    $_SESSION['import']['groupid'] = (int) $_POST['groupid'];
                    $_SESSION['import']['families'] = array();
                    $_SESSION['import']['total_families'] = 0;
                    $_SESSION['import']['total_persons'] = 0;
                    $_SESSION['import']['total_notes'] = 0;
                    $row_errors = array();
                    $family = NULL;
                    $i = 1;
                    while ($rawrow = fgetcsv($fp, 0, ",", '"')) {
                        $row = array();
                        foreach ($map as $index => $fieldname) {
                            $row[$fieldname] = array_get($rawrow, $index);
                        }
                        if ($this->_isEmptyRow($row)) {
                            // Blank row = start a new family for the next row
                            unset($family);
                            continue;
                        }
                        if (!isset($family) || $this->_isNewFamily($row, $family)) {
                            // Add family
                            $this->_dummy_family->values = array();
                            $this->_dummy_family->setValue('status', 'current');
                            $this->_captureErrors();
                            $familyrow = $row;
                            unset($familyrow['status']);
                            $this->_dummy_family->fromCsvRow($familyrow);
                            if ($errors = $this->_getErrors()) {
                                $row_errors[$i] = $errors;
                            } else {
                                $_SESSION['import']['families'][] = $this->_dummy_family->values;
                                $family =& $_SESSION['import']['families'][count($_SESSION['import']['families']) - 1];
                                $_SESSION['import']['total_families']++;
                            }
                        } else {
                            // see if there's anything to update
                            // eg if the second family member has a home tel
                            foreach ($family as $fi => $fv) {
                                if ($family[$fi] === '' && $row[$fi] !== '') {
                                    $family[$fi] = $row[$fi];
                                }
                            }
                        }
                        $this->_captureErrors();
                        // Add a person and note
                        $this->_dummy_person->values = array();
                        $this->_dummy_person->setValue('familyid', '-1');
                        if (!empty($row['congregation'])) {
                            $row['congregationid'] = Congregation::findByName($row['congregation']);
                        }
                        $this->_dummy_person->fromCsvRow($row);
                        if ($errors = $this->_getErrors()) {
                            $row_errors[$i] = array_merge(array_get($row_errors, $i, array()), $errors);
                        } else {
                            $member = $this->_dummy_person->values + array('congregation' => $this->_dummy_person->getFormattedValue('congregationid'));
                            if (!empty($row['note'])) {
                                $member['note'] = $row['note'];
                                $_SESSION['import']['total_notes']++;
                            }
                            $family['members'][] = $member;
                            $_SESSION['import']['total_persons']++;
                        }
                        $i++;
                    }
                    if (!empty($row_errors)) {
                        $msg = 'Your import file is not valid.  Please correct the following errors and try again:<ul>';
                        foreach ($row_errors as $line => $errors) {
                            $msg .= '<li>Row ' . ($line + 1) . ': ' . implode('; ', $errors) . '</li>';
                        }
                        $msg .= '</ul>';
                        add_message($msg, 'failure', true);
                        $this->_stage = 'begin';
                    } else {
                        $this->_stage = 'confirm';
                    }
                }
            }
        }
    }
コード例 #3
0
 function initInitialEntities()
 {
     foreach ($_POST['congregation_name'] as $cname) {
         if (empty($cname)) {
             continue;
         }
         $c = new Congregation();
         $c->setValue('name', $cname);
         $c->setValue('long_name', $cname);
         $this->congregations[] = $c;
         if (!$c->validateFields()) {
             return FALSE;
         }
     }
     $this->user = new Staff_Member();
     foreach ($this->initial_person_fields as $field) {
         $this->user->processFieldInterface($field, 'install_');
     }
     $this->user->setValue('status', 0);
     $this->user->setValue('permissions', PERM_SYSADMIN);
     if (!$this->user->validateFields()) {
         return FALSE;
     }
     $this->family = new Family();
     $this->family->setValue('family_name', $this->user->getValue('last_name'));
     $this->family->setValue('creator', 0);
     if (!$this->family->validateFields()) {
         return FALSE;
     }
     return TRUE;
 }
コード例 #4
0
function update_congregation_rows($KeyArray, $RawDataFile)
{
    $UpdateResults['errors'] = 0;
    $UpdateResults['updates'] = 0;
    $UpdateResults['ignored'] = 0;
    $UpdateResults['deleted'] = 0;
    while (!feof($RawDataFile)) {
        $newRow = fgetcsv($RawDataFile);
        // loop through the arrays to create a new
        // associative array
        $newArray = array();
        $LoopCount = count($KeyArray);
        for ($loop = 0; $loop < $LoopCount; $loop++) {
            $newArray = array_push_assoc($newArray, $KeyArray[$loop], $newRow[$loop]);
        }
        // create the congregation class
        $UpdateCongregation = new Congregation();
        // check to see if we need to delete it first
        if (strtolower($newArray['updatecode']) == 'd') {
            // check to see if it even exists, otherwise, ignore it.
            if ($UpdateCongregation->get_congregation_by_PIN($newArray['pin'])) {
                // check to see if it has been flagged for no auto updates
                if ($UpdateCongregation->DoNotAutoUpdate) {
                    // marked to not update - log it and stop.
                    add_congregation_search_update_log('INFO', 'Congregation ' . $newArray['pin'] . ' is locked to not allow updates. Delete request ignored.');
                    $UpdateResults['ignored']++;
                } elseif (delete_congregation($newArray['pin'])) {
                    add_congregation_search_update_log('DELETE', 'Congregation ' . $newArray['pin'] . ' was deleted.');
                    $UpdateResults['deleted']++;
                } else {
                    add_congregation_search_update_log('ERROR', 'Congregation ' . $newArray['pin'] . ' could not be deleted.');
                    $UpdateResults['errors']++;
                }
            }
        } else {
            // first see if the congregation exists and make certain we d
            if (!$UpdateCongregation->get_congregation_by_PIN($newArray['pin'])) {
                // if false, this is a new congregation - lets create it
                $UpdateCongregation->PIN = $newArray['pin'];
                $UpdateCongregation->CongregationName = $newArray['congregationname'];
                $UpdateCongregation->EIN = $newArray['ein'];
                $UpdateCongregation->Address1 = $newArray['address1'];
                $UpdateCongregation->Address2 = $newArray['address2'];
                $UpdateCongregation->City = $newArray['city'];
                $UpdateCongregation->State = $newArray['state'];
                $UpdateCongregation->PostalCode = $newArray['postalcode'];
                $UpdateCongregation->Phone = $newArray['phone'];
                $UpdateCongregation->Email = $newArray['email'];
                $UpdateCongregation->Website = $newArray['website'];
                $UpdateCongregation->Region = $newArray['region'];
                if (array_key_exists('latitude', $newArray) && array_key_exists('longitude', $newArray)) {
                    // if latitude and longitude were provided then add them
                    $UpdateCongregation->Latitude = $newArray['latitude'];
                    $UpdateCongregation->Longitude = $newArray['longitude'];
                } else {
                    if ($UpdateCongregation->Address1 != '' && $UpdateCongregation->City != '' && $UpdateCongregation->State != '') {
                        //geocode the address and add it to the record
                        $newLatLong = get_congregation_city_state_latlong($UpdateCongregation->Address1 . ', ' . $UpdateCongregation->City . ', ' . $UpdateCongregation->State);
                        if ($newLatLong != null) {
                            $UpdateCongregation->Latitude = $newLatLong['location']['lat'];
                            $UpdateCongregation->Longitude = $newLatLong['location']['long'];
                            add_congregation_search_update_log('GEOCODE_SUCCESS', 'Congregation ' . $newArray['pin'] . ' was successfully geocoded.');
                        } else {
                            add_congregation_search_update_log('GEOCODE_FAILURE', 'Congregation ' . $newArray['pin'] . ' could not be geocoded.');
                        }
                    }
                }
                // save and log the result
                $SavedCongregationResults = $UpdateCongregation->save_new_congregation();
                if ($SavedCongregationResults) {
                    add_congregation_search_update_log('ADDED', 'Congregation ' . $newArray['pin'] . ' was added.');
                    $UpdateResults['updates']++;
                } else {
                    add_congregation_search_update_log('ERROR', 'Congregation ' . $newArray['pin'] . ' could not be added: ' . $SavedCongregationResults);
                    $UpdateResults['errors']++;
                }
            } else {
                // first checked to see if it's been flagged to not update,
                // then check to see if the updated data is more recent
                // than the current data in the database
                // We do this because update file contain updated for the last 7 days,
                // in case a previous update execution created an error that
                // precented some data from being updated.
                // check for no auto updates to this congregation
                if ($UpdateCongregation->DoNotAutoUpdate) {
                    add_congregation_search_update_log('INFO', 'Congregation ' . $newArray['pin'] . ' is locked to not allow updated. Update request ignored.');
                    $UpdateResults['ignored']++;
                } elseif (strtotime($UpdateCongregation->DateUpdated) < strtotime($newArray['lastupdated'])) {
                    $UpdateCongregation->CongregationName = $newArray['congregationname'];
                    $UpdateCongregation->EIN = $newArray['ein'];
                    $UpdateCongregation->Address1 = $newArray['address1'];
                    $UpdateCongregation->Address2 = $newArray['address2'];
                    $UpdateCongregation->City = $newArray['city'];
                    $UpdateCongregation->State = $newArray['state'];
                    $UpdateCongregation->PostalCode = $newArray['postalcode'];
                    $UpdateCongregation->Phone = $newArray['phone'];
                    $UpdateCongregation->Email = $newArray['email'];
                    $UpdateCongregation->Website = $newArray['website'];
                    $UpdateCongregation->Region = $newArray['region'];
                    if (array_key_exists('latitude', $newArray) && array_key_exists('longitude', $newArray)) {
                        // now check to see if they exist in the database. If not, don't overwrite the data
                        // as site-side lat/long data might be overwritten
                        if ($newArray['latitude'] != '' && $newArray['longitude'] != '') {
                            $UpdateCongregation->Latitude = $newArray['latitude'];
                            $UpdateCongregation->Longitude = $newArray['longitude'];
                        }
                    } else {
                        if ($UpdateCongregation->Latitude == 0.0 || $UpdateCongregation->Longitude == 0.0) {
                            //geocode the address and add it to the record
                            $newLatLong = get_congregation_city_state_latlong($UpdateCongregation->Address1 . ', ' . $UpdateCongregation->City . ', ' . $UpdateCongregation->State);
                            if ($newLatLong != null) {
                                $UpdateCongregation->Latitude = $newLatLong['location']['lat'];
                                $UpdateCongregation->Longitude = $newLatLong['location']['long'];
                                add_congregation_search_update_log('GEOCODE_SUCCESS', 'Congregation ' . $newArray['pin'] . ' was successfully geocoded.');
                            } else {
                                add_congregation_search_update_log('GEOCODE_FAILURE', 'Congregation ' . $newArray['pin'] . ' could not be geocoded.');
                            }
                        }
                    }
                    $UpdateCongregationResults = $UpdateCongregation->save_current_congregation();
                    if ($UpdateCongregationResults) {
                        add_congregation_search_update_log('UPDATED', 'Congregation ' . $newArray['pin'] . ' was updated.');
                        $UpdateResults['updates']++;
                    } else {
                        add_congregation_search_update_log('ERROR', 'Congregation ' . $newArray['pin'] . ' could not be updated:' . $UpdateCongregationResults);
                        $UpdateResults['errors']++;
                    }
                }
            }
        }
    }
    // end while
    // close the data file
    fclose($RawDataFile);
    return $UpdateResults;
}
コード例 #5
0
 /**
  * Return a congregation by ID.
  *
  * @param integer $id The ID of the congregation.
  *
  * @return Congregation A congregation if found, otherwise null.
  */
 public static function getCongregation($id)
 {
     Log::info('Get congregation.', compact('id'));
     return Congregation::find($id);
 }