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");
49
* Return the array of hooks available in this module.
52
public static function getHooks() {
54
foreach ( self::$contacts as $type ) {
55
$hooks["validate_form_person_contact_${type}_field_email"] = "validate_form_contact_field_email";
61
* Validate the email field for contact forms.
62
* @param I2CE_FormField $formfield
64
public function validate_form_contact_field_email( $formfield ) {
65
$value = $formfield->getValue();
66
if ( I2CE_Validate::checkString( $value )
67
&& !I2CE_Validate::checkEmail( $value ) ) {
68
$formfield->setInvalid( "Please enter a valid email address." );
73
* Upgrades the modules
74
* @param string $old_vers
75
* @param string $new_vers
78
public function upgrade($old_vers,$new_vers) {
79
if (I2CE_Validate::checkVersion($old_vers,'<','3.2.6') || I2CE_Validate::checkVersion($old_vers,'=','3.2.10')) {
80
if (!$this->updateContacts()) {
87
public function post_update($old_vers,$new_vers) {
88
if (I2CE_Validate::checkVersion($old_vers,'=','0')) {
89
//this module is new to 3.2, we may need to update contacts from 3.1
90
//only fixup contact on a new installation
91
if (!$this->updateContacts()) {
98
protected function updateContacts() {
99
foreach (self::$contacts as $contact) {
100
I2CE::raiseError("Changing contact child form of type $contact of person to person_contact_$contact");
101
if (! iHRIS_Module_Contact::changeContactForm('person', "contact_type|$contact","person_contact_$contact",true,false)) {
102
I2CE::raiseError("Could not upgrade training funder contacts");
106
iHRIS_Module_Contact::removeContactForm('person');
116
public function action_person_contact_work($page) {
117
return $this->action_contact($page, 'work');
119
public function action_person_contact_personal($page) {
120
return $this->action_contact($page, 'personal');
122
public function action_person_contact_emergency($page) {
123
return $this->action_contact($page, 'emergency');
125
public function action_person_contact_other($page) {
126
return $this->action_contact($page, 'other');
131
protected function action_contact($page,$contact) {
132
if (!$page instanceof iHRIS_PageView) {
135
$person = $page->getPerson();
136
if (!$person instanceof iHRIS_Person) {
139
$page->addChildForms('person_contact_' . $contact);
140
$template = $page->getTemplate();
141
$contactObjs = $person->getChildren('person_contact_' . $contact);
142
if (count($contactObjs) == 1) {
144
} else if (count($contactObjs) > 1) {
145
I2CE::raiseError("Too many contacts of type " . $contact . " for " . $person->getId());
147
} else if ($page->hasPermission("task(person_can_edit_child_form_person_contact_$contact)")) {
148
$template->appendFileById("add_person_contact_" . $contact . ".html", 'span','contact_links');
158
# c-default-style: "bsd"
159
# indent-tabs-mode: nil