Ejemplo n.º 1
0
 function save($update_family = TRUE)
 {
     $GLOBALS['system']->doTransaction('BEGIN');
     $msg = '';
     if ($update_family && $GLOBALS['user_system']->havePerm(PERM_EDITPERSON)) {
         // We do this perm check because someone might
         // be updating themselves but saving the family will fail
         if (!empty($this->_old_values['status']) || !empty($this->_old_values['last_name'])) {
             $family =& $GLOBALS['system']->getDBObject('family', $this->getValue('familyid'));
             $members = $family->getMemberData();
             if (!empty($this->_old_values['status']) && $this->getValue('status') == 'archived') {
                 // status has just been changed to 'archived' so archive family if no live members
                 $found_live_member = false;
                 foreach ($members as $id => $details) {
                     if ($id == $this->id) {
                         continue;
                     }
                     if ($details['status'] != 'archived') {
                         $found_live_member = true;
                         break;
                     }
                 }
                 if (!$found_live_member) {
                     if ($family->canAcquireLock()) {
                         $family->acquireLock();
                         $family->setValue('status', 'archived');
                         $family->save(FALSE);
                         $family->releaseLock();
                         $msg = 'All members of the "' . $family->getValue('family_name') . '" family are now archived, the family itself has been archived also';
                     } else {
                         $msg = 'All members of the "' . $family->getValue('family_name') . '" family are now archived.  However the family itself could not be archived because another user holds the lock.';
                     }
                 }
             }
             if (array_get($this->_old_values, 'status') == 'archived' && $this->getValue('status') != 'archived') {
                 // We have just been de-archived so de-archive family too
                 if ($family->getValue('status') == 'archived') {
                     if ($family->canAcquireLock()) {
                         $family->acquireLock();
                         $family->setValue('status', 'current');
                         $family->save(FALSE);
                         $family->releaseLock();
                         $msg = '"' . $this->toString() . '" has been de-archived, so the "' . $family->getValue('family_name') . '" family has also been de-archived';
                     } else {
                         $msg = $msg = '"' . $this->toString() . '" has been de-archived, so the "' . $family->getValue('family_name') . '" family should also be de-archived, however this could not be completed because the lock on the family could not be acquried.';
                     }
                 }
             }
             if (!empty($this->_old_values['last_name'])) {
                 // last name has changed - update the family name if only one member
                 if (count($members) == 1) {
                     if ($family->canAcquireLock()) {
                         $family->acquireLock();
                         $family->setValue('family_name', $this->getValue('last_name'));
                         $family->save(FALSE);
                         $family->releaseLock();
                         $msg = 'Since "' . $this->toString() . '" is the only member of family #' . $family->id . ', it has been renamed to the  "' . $family->getValue('family_name') . '" family';
                     } else {
                         $msg = 'Since "' . $this->toString() . '" is the only member of family #' . $family->id . ', it should be renamed to the  "' . $family->getValue('family_name') . '" family. However this could not be completed because the lock on the family could not be acquired.';
                     }
                 }
             }
         }
     }
     $res = parent::save();
     if ($res) {
         $this->_savePhoto();
         $this->_saveCustomValues();
         $GLOBALS['system']->doTransaction('COMMIT');
     } else {
         $GLOBALS['system']->doTransaction('ROLLBACK');
     }
     if ($msg) {
         add_message($msg);
     }
     return $res;
 }
Ejemplo n.º 2
0
 function save()
 {
     // If the subject or details is updated, set the 'editor' and 'edited' fields
     if (isset($this->_old_values['subject']) || isset($this->_old_values['details'])) {
         $this->setValue('edited', 'CURRENT_TIMESTAMP');
         $this->setValue('editor', $GLOBALS['user_system']->getCurrentUser('id'));
     }
     return parent::save();
 }
Ejemplo n.º 3
0
 function save()
 {
     if ($this->id == 'TEMP') {
         $_SESSION['saved_query'] = serialize($this);
         return TRUE;
     } else {
         return parent::save();
     }
 }
Ejemplo n.º 4
0
 function save()
 {
     $this->setValue('modified', date('Y-m-d H:i:s'));
     $this->setValue('modifier', $GLOBALS['user_system']->getCurrentUser('id'));
     return parent::save();
 }