3
* © Copyright 2007, 2008 IntraHealth International, Inc.
5
* This File is part of iHRIS
7
* iHRIS 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/>.
21
* View a person's record.
25
* @author Luke Duncan <lduncan@intrahealth.org>
26
* @copyright Copyright © 2007, 2008 IntraHealth International, Inc.
32
* The page class for displaying the a person's record.
37
class iHRIS_PageView extends I2CE_Page{
41
* Perform the main actions of the page.
43
protected function action() {
45
if (!$this->hasPermission("task(person_can_view)")) {
46
$this->userMessage("You do not have permission to view this person");
49
$this->template->addHeaderLink("view.js");
50
$this->template->appendFileById( "menu_view.html", "li", "navBarUL", true );
51
$this->template->appendFileById( "menu_view_trainer.html", "ul", "menuView" );
52
$factory = I2CE_FormFactory::instance();
53
if (!$this->request_exists('id')) {
54
$this->userMessage("Invalid Person Requested");
57
if ($this->request_exists('id')) {
58
$id = $this->request('id');
59
if (strpos($id,'|')=== false) {
60
I2CE::raiseError("Deprecated use of id variable");
61
$id = 'trainer|' . $id;
66
$person = $factory->createContainer( $id);
67
if (!$person instanceof iHRIS_Trainer) {
71
$this->person = $person;
72
$this->person->populate();
73
$this->template->setForm( $this->person );
74
$child_forms = $this->person->getChildForms();
75
foreach($child_forms as $form) {
76
if (!$this->hasPermission("task(person_can_view_child_forms|person_can_view_child_form_{$form})")) {
79
$method = 'action_' . $form;
80
if ($this->_hasMethod($method)) {
81
if (!$this->$method()) {
82
I2CE::raiseError("Could not do action for $form");
89
public function getPerson() {
93
public function hasChildForm($form, $populate = false) {
95
$this->person->populateChildren($form);
97
return (array_key_exists($form,$this->person->children) && is_array($this->person->children[$form]) && count($this->person->children[$form]) > 0);
100
public function addChildForms($form, $set_on_node = null , $template = false, $tag = 'div', $append_node = null) {
101
$this->person->populateChildren($form);
102
return $this->appendChildTemplate($form,$set_on_node,$template,$tag, $append_node );
106
public function addLastChildForm($form, $field, $set_on_node = null, $template = false, $tag = 'div', $append_node = null) {
107
$this->person->populateLast(array($form=> $field));
108
return $this->appendChildTemplate($form,$set_on_node,$template,$tag, $append_node );
114
public function appendChildTemplate($form,$set_on_node = null, $template = false, $tag = 'div', $appendNode = null) {
115
if (!array_key_exists($form,$this->person->children) || !is_array($this->person->children[$form])) {
118
if (!is_string($template)) {
119
$template = 'view_' . $form . '.html';
121
if ($appendNode === null) {
124
if (is_string($appendNode)) {
125
$appendNode = $this->template->getElementById($appendNode);
127
if (! $appendNode instanceof DOMNode) {
128
I2CE::raiseError("Do not know where to add child form $form ");
131
foreach ($this->person->children[$form] as $child) {
132
I2CE_ModuleFactory::callHooks( 'pre_add_child_form_' . $form,
133
array( 'form' => $child,
134
'page' => $this, 'set_on_node' => $set_on_node,
135
'append_node' => $appendNode ) );
136
$node = $this->template->appendFileByNode($template, $tag, $appendNode );
137
if (!$node instanceof DOMNode) {
138
I2CE::raiseError("Could not find template $template for child form $form of person");
141
$this->template->setForm($child,$node);
142
if ($set_on_node !== null) {
143
$this->template->setForm($child,$set_on_node);
145
I2CE_ModuleFactory::callHooks( 'post_add_child_form_' . $form,
146
array( 'form' => $child, 'node' => $node,
147
'page' => $this, 'set_on_node' => $set_on_node,
148
'append_node' => $appendNode ) );
160
# c-default-style: "bsd"
161
# indent-tabs-mode: nil