3
* © Copyright 2009 IntraHealth International, Inc.
5
* This File is part of I2CE
7
* I2CE is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
* @author Carl Leitner <litlfred@ibiblio.org>
28
* Class iHRIS_Module_PersonContact
34
class iHRIS_Module_PersonContact extends I2CE_Module {
36
public static function getMethods() {
38
'iHRIS_PageView->action_person_contact_work' => 'action_person_contact_work',
39
'iHRIS_PageView->action_person_contact_personal' => 'action_person_contact_personal',
40
'iHRIS_PageView->action_person_contact_other' => 'action_person_contact_other',
41
'iHRIS_PageView->action_person_contact_emergency' => 'action_person_contact_emergency'
46
protected static $contacts = array("personal","work","emergency","other");
50
* Upgrades the modules
51
* @param string $old_vers
52
* @param string $new_vers
55
public function upgrade($old_vers,$new_vers) {
56
if (I2CE_Validate::checkVersion($old_vers,'<','3.2.6') || I2CE_Validate::checkVersion($old_vers,'=','3.2.10')) {
57
if (!$this->updateContacts()) {
64
public function post_update($old_vers,$new_vers) {
65
if (I2CE_Validate::checkVersion($old_vers,'=','0')) {
66
//this module is new to 3.2, we may need to update contacts from 3.1
67
//only fixup contact on a new installation
68
if (!$this->updateContacts()) {
75
protected function updateContacts() {
76
foreach (self::$contacts as $contact) {
77
I2CE::raiseError("Changing contact child form of type $contact of person to person_contact_$contact");
78
if (! iHRIS_Module_Contact::changeContactForm('person', "contact_type|$contact","person_contact_$contact",true,false)) {
79
I2CE::raiseError("Could not upgrade training funder contacts");
83
iHRIS_Module_Contact::removeContactForm('person');
93
public function action_person_contact_work($page) {
94
return $this->action_contact($page, 'work');
96
public function action_person_contact_personal($page) {
97
return $this->action_contact($page, 'personal');
99
public function action_person_contact_emergency($page) {
100
return $this->action_contact($page, 'emergency');
102
public function action_person_contact_other($page) {
103
return $this->action_contact($page, 'other');
108
protected function action_contact($page,$contact) {
109
if (!$page instanceof iHRIS_PageView) {
112
$person = $page->getPerson();
113
if (!$person instanceof iHRIS_Person) {
116
$page->addChildForms('person_contact_' . $contact);
117
$template = $page->getTemplate();
118
$contactObjs = $person->getChildren('person_contact_' . $contact);
119
if (count($contactObjs) == 1) {
121
} else if (count($contactObjs) > 1) {
122
I2CE::raiseError("Too many contacts of type " . $contact . " for " . $person->getId());
124
} else if ($page->hasPermission("task(person_can_edit_child_form_person_contact_$contact)")) {
125
$template->appendFileById("add_person_contact_" . $contact . ".html", 'span','contact_links');
135
# c-default-style: "bsd"
136
# indent-tabs-mode: nil