~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Mentor/lib/iHRIS_PageViewPrivateFacility.php

  • Committer: Dennis Kibiye
  • Date: 2012-08-15 12:39:06 UTC
  • Revision ID: kibsden@gmail.com-20120815123906-ckmfgnpgi8xqiz9o
First Initialisation of In Service Baylor Training System Based on iHRIS Manage

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 * © Copyright 2007, 2008 IntraHealth International, Inc.
 
4
 * 
 
5
 * This File is part of iHRIS
 
6
 * 
 
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.
 
11
 * 
 
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.
 
16
 * 
 
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/>.
 
19
 */
 
20
/**
 
21
 * View a privatefacility's record.
 
22
 * @package iHRIS
 
23
 * @subpackage Qualify
 
24
 * @access public
 
25
 * @author Luke Duncan <lduncan@intrahealth.org>
 
26
 * @copyright Copyright &copy; 2007, 2008 IntraHealth International, Inc. 
 
27
 * @since v2.0.0
 
28
 * @version v2.0.0
 
29
 */
 
30
 
 
31
/**
 
32
 * The page class for displaying the a privatefacility's record.
 
33
 * @package iHRIS
 
34
 * @subpackage Qualify
 
35
 * @access public
 
36
 */
 
37
class iHRIS_PageViewPrivateFacility extends I2CE_Page{ 
 
38
    protected $privatefacility;
 
39
 
 
40
    /**
 
41
     * Perform the main actions of the page.
 
42
     */
 
43
    protected function action() {
 
44
        parent::action();
 
45
        if (!$this->hasPermission("task(person_can_view)")) {
 
46
            $this->userMessage("You do not have permission to view this person");
 
47
            return false;
 
48
        }
 
49
        $this->template->addHeaderLink("view.js");
 
50
        $this->template->appendFileById( "menu_view.html", "li", "navBarUL", true );
 
51
        $this->template->appendFileById( "menu_view_privatefacility.html", "ul", "menuView" );
 
52
        $factory = I2CE_FormFactory::instance();
 
53
        if (!$this->request_exists('id')) {
 
54
            $this->userMessage("Invalid Private Health Unit Requested");
 
55
            return false;
 
56
        }
 
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 = 'privatefacility|' . $id;
 
62
            }
 
63
        } else {
 
64
            $id = 'privatefacility|0';
 
65
        }
 
66
        $privatefacility = $factory->createContainer( $id);
 
67
        if (!$privatefacility instanceof iHRIS_PrivateFacility) {
 
68
            return false;
 
69
        }
 
70
 
 
71
        $this->privatefacility = $privatefacility;
 
72
        $this->privatefacility->populate();
 
73
        $this->privatefacility->getField("supervisor")->setHref("view?id=");
 
74
        $this->template->setForm( $this->privatefacility );
 
75
        $child_forms = $this->privatefacility->getChildForms();
 
76
        foreach($child_forms as $form) {
 
77
            if (!$this->hasPermission("task(person_can_view_child_forms|person_can_view_child_form_{$form})")) {
 
78
                continue;
 
79
            }
 
80
            $method = 'action_' . $form;
 
81
            if ($this->_hasMethod($method)) {
 
82
                if (!$this->$method()) {
 
83
                    I2CE::raiseError("Could not do action for $form");
 
84
                }
 
85
            }
 
86
        }
 
87
 
 
88
        return true;
 
89
    }
 
90
    
 
91
    public function getFacility() {
 
92
        return $this->privatefacility;
 
93
    }
 
94
 
 
95
    public function hasChildForm($form, $populate = false) {
 
96
        if ($populate) {
 
97
            $this->privatefacility->populateChildren($form);
 
98
        }
 
99
        return (array_key_exists($form,$this->privatefacility->children) && is_array($this->privatefacility->children[$form]) && count($this->privatefacility->children[$form]) > 0);
 
100
    }
 
101
 
 
102
    public function addChildForms($form, $set_on_node = null , $template = false, $tag = 'div', $append_node = null) {
 
103
        $this->privatefacility->populateChildren($form);
 
104
        return $this->appendChildTemplate($form,$set_on_node,$template,$tag, $append_node );
 
105
    }
 
106
 
 
107
 
 
108
    public function addLastChildForm($form, $field,  $set_on_node = null,  $template = false, $tag = 'div', $append_node = null) {
 
109
        $this->privatefacility->populateLast(array($form=> $field));
 
110
        return $this->appendChildTemplate($form,$set_on_node,$template,$tag, $append_node );
 
111
    }
 
112
 
 
113
 
 
114
 
 
115
 
 
116
    public function appendChildTemplate($form,$set_on_node = null, $template = false, $tag = 'div', $appendNode = null) {
 
117
        if (!array_key_exists($form,$this->privatefacility->children) || !is_array($this->privatefacility->children[$form])) {
 
118
            return true;
 
119
        }
 
120
        if (!is_string($template)) {
 
121
            $template = 'view_' . $form . '.html';
 
122
        }
 
123
        if ($appendNode === null) {
 
124
            $appendNode = $form;
 
125
        }
 
126
        if (is_string($appendNode)) {
 
127
            $appendNode = $this->template->getElementById($appendNode);
 
128
        }        
 
129
        if (! $appendNode instanceof DOMNode) {
 
130
            I2CE::raiseError("Do not know where to add child form $form ");
 
131
            return false;
 
132
        }
 
133
        foreach ($this->privatefacility->children[$form] as $child) {
 
134
            I2CE_ModuleFactory::callHooks( 'pre_add_child_form_' . $form, 
 
135
                    array( 'form' => $child, 
 
136
                        'page' => $this, 'set_on_node' => $set_on_node, 
 
137
                        'append_node' => $appendNode ) );
 
138
            $node = $this->template->appendFileByNode($template, $tag,  $appendNode );
 
139
            if (!$node instanceof DOMNode) {
 
140
                I2CE::raiseError("Could not find template $template for child form $form of privatefacility");
 
141
                return false;
 
142
            }
 
143
            $this->template->setForm($child,$node);
 
144
            if ($set_on_node !== null) {
 
145
                $this->template->setForm($child,$set_on_node);
 
146
            }
 
147
            I2CE_ModuleFactory::callHooks( 'post_add_child_form_' . $form, 
 
148
                    array( 'form' => $child, 'node' => $node,
 
149
                        'page' => $this, 'set_on_node' => $set_on_node, 
 
150
                        'append_node' => $appendNode ) );
 
151
        }
 
152
        return true;
 
153
    }
 
154
 
 
155
 
 
156
  }
 
157
 
 
158
 
 
159
 
 
160
# Local Variables:
 
161
# mode: php
 
162
# c-default-style: "bsd"
 
163
# indent-tabs-mode: nil
 
164
# c-basic-offset: 4
 
165
# End: