function processView()
 {
     $GLOBALS['system']->setFriendlyErrors(TRUE);
     $this->_person =& $GLOBALS['system']->getDBObject('person', (int) $_REQUEST['personid']);
     if (!empty($_REQUEST['move_to'])) {
         if ($_REQUEST['move_to'] == 'new') {
             $family =& $GLOBALS['system']->getDBObject('family', (int) $this->_person->getValue('familyid'));
             $family->id = 0;
             $family->create();
             $this->_person->setValue('familyid', $family->id);
             $this->_person->save();
             add_message('New family created with same details as old family.  You should update the new family\'s details as required');
             redirect('_edit_family', array('familyid' => $family->id));
             // exits
         } else {
             if (empty($_REQUEST['familyid'])) {
                 trigger_error("You must select a new family to move to, or choose to create a new family");
                 return false;
             }
             $family =& $GLOBALS['system']->getDBObject('family', (int) $_REQUEST['familyid']);
             if ($family) {
                 $old_familyid = $this->_person->getValue('familyid');
                 $this->_person->setValue('familyid', (int) $_REQUEST['familyid']);
                 if ($this->_person->save()) {
                     add_message('Person moved to family "' . $family->toString() . '"');
                     $remaining_members = $GLOBALS['system']->getDBObjectData('person', array('familyid' => $old_familyid));
                     if (empty($remaining_members)) {
                         $old_family =& $GLOBALS['system']->getDBObject('family', $old_familyid);
                         if ($GLOBALS['user_system']->havePerm(PERM_EDITNOTE)) {
                             // add a note
                             $GLOBALS['system']->includeDBClass('family_note');
                             $note = new Family_Note();
                             $note->setValue('familyid', $old_familyid);
                             $note->setValue('subject', 'Archived by System');
                             $note->setValue('details', 'The system is archiving this family because its last member (' . $this->_person->toString() . ' #' . $this->_person->id . ') has been moved to another family (' . $family->toString() . ' #' . $family->id . ')');
                             $note->create();
                         }
                         // archive the family record
                         $old_family->setValue('status', 'archived');
                         $old_family->save();
                     }
                     redirect('persons', array('personid' => $this->_person->id));
                     // exits
                 }
             }
         }
     }
 }
 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');
         }
     }
 }