~kibsden/ihris-uganda/baylor-train

« back to all changes in this revision

Viewing changes to modules/Mentor/lib/iHRIS_PageFormParentPrivateFacility.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
 * Manage adding or editing forms associated with a person to the database.
 
22
 * 
 
23
 * @package iHRIS
 
24
 * @subpackage Common
 
25
 * @access public
 
26
 * @author Luke Duncan <lduncan@intrahealth.org>
 
27
 * @copyright Copyright &copy; 2007, 2008 IntraHealth International, Inc. 
 
28
 * @since v2.0.0
 
29
 * @version v2.0.0
 
30
 */
 
31
 
 
32
/**
 
33
 * Page object to handle the adding or editing forms associated with a person to the database.
 
34
 * 
 
35
 * @package iHRIS
 
36
 * @subpackage Common
 
37
 * @access public
 
38
 */
 
39
class iHRIS_PageFormParentPrivateFacility extends I2CE_PageForm {
 
40
        
 
41
    /**
 
42
     * Return the form name for this page.
 
43
     * 
 
44
     * It will be used for the default form template and php page for the form submission.
 
45
     * @param boolean $html Set to true if this is to be used for the html template page to load.
 
46
     * @return string
 
47
     */
 
48
    protected function getForm( $html=false ) { return $this->form_name; }
 
49
 
 
50
    /**
 
51
     * @var integer The record id number of the object being edited.
 
52
     */
 
53
    protected $id;
 
54
    /**
 
55
     * @var integer The recored if number of the parent of the object being edited
 
56
     */
 
57
    protected $parent_id;
 
58
    /**
 
59
     * The form name being edited by this page.
 
60
     * @var string
 
61
     */
 
62
    protected $form_name;
 
63
 
 
64
    /**
 
65
     * The link used to access this form
 
66
     * $var protected string $form_link
 
67
     */
 
68
    protected $form_link;
 
69
        
 
70
    /**
 
71
     * Sets the form link 
 
72
     * @param string $link
 
73
     */
 
74
    public function setFormLink($link) {
 
75
        $this->form_link = $link;
 
76
    }
 
77
        
 
78
 
 
79
 
 
80
    /**
 
81
     * Create a new instance of this page.
 
82
     * 
 
83
     * This will call the parent constructor and then setup the base
 
84
     * template pages for the {@link I2CE_Template template}.  It also sets up the values
 
85
     * for the member variables.
 
86
     * @param string $title The title for this page.
 
87
     * @param string $form_name The form name of the form being edited.
 
88
     * @param mixed $access The role required to access this page.
 
89
     * @param array $files The list of template files to load for this page.
 
90
     */
 
91
    public function __construct( $args,$request_remainder){
 
92
        parent::__construct($args,$request_remainder);
 
93
        $form_name = $args['page_form'];
 
94
        if(empty($form_name)) {
 
95
            I2CE::raiseError("No form name specified", E_USER_ERROR);
 
96
        }
 
97
        $this->form_name = $form_name;
 
98
        $this->form_link  = $form_name ;
 
99
    }
 
100
                
 
101
    /**
 
102
     * Create and load data for the objects used for this form.
 
103
     * 
 
104
     * Create the list object and if this is a form submission load
 
105
     * the data from the form data.  It determines the type based on the
 
106
     * {@link $type} member variable.
 
107
     */
 
108
    protected function loadObjects() {
 
109
        if ($this->isPost()) {
 
110
            $primary = $this->factory->createContainer($this->getForm());
 
111
            if (!$primary instanceof I2CE_Form) {
 
112
                return;
 
113
            }
 
114
            $primary->load($this->post);
 
115
        } elseif ( $this->get_exists('id') ) {
 
116
            if ($this->get_exists('id')) {
 
117
                $id = $this->get('id');
 
118
                if (strpos($id,'|')=== false) {
 
119
                    I2CE::raiseError("Deprecated use of id variable");
 
120
                    $id = $this->getForm() . '|' . $id;
 
121
                }
 
122
            } else {
 
123
                $id = $this->getForm() . '|0';
 
124
            }
 
125
            $primary = $this->factory->createContainer($id);
 
126
            if (!$primary instanceof I2CE_Form || $primary->getName() != $this->getForm()) {
 
127
                I2CE::raiseError("Could not create valid " . $this->getForm() . "form from id:$id");
 
128
                return;
 
129
            }
 
130
            $primary->populate();
 
131
        } elseif ( $this->get_exists('parent') ) {
 
132
            $primary = $this->factory->createContainer($this->getForm());
 
133
            if (!$primary instanceof I2CE_Form) {
 
134
                return;
 
135
            }
 
136
            $parent = $this->get('parent');
 
137
            if (strpos($parent,'|')=== false) {
 
138
                I2CE::raiseError("Deprecated use of parent variable");
 
139
                $parent =  'person|' . $id;            
 
140
            }
 
141
            $primary->setParent($parent);
 
142
        }
 
143
        if ($this->isGet()) {
 
144
            $primary->load($this->get());
 
145
        }
 
146
        $person = $this->factory->createContainer(  $primary->getParent());
 
147
        if (!$person instanceof iHRIS_PrivateFacility) {
 
148
            I2CE::raiseError("Could not create person form from " . $primary->getParent());
 
149
            return;
 
150
        }
 
151
        $person->populate();
 
152
        $this->setObject($primary);
 
153
        $this->setObject($person,I2CE_PageForm::EDIT_PARENT);        
 
154
        //parent::loadObjects();
 
155
    }
 
156
        
 
157
        
 
158
    /**
 
159
     * Load the HTML template files for editing.
 
160
     */
 
161
    protected function loadHTMLTemplates() {
 
162
        parent::loadHTMLTemplates();
 
163
        $this->template->appendFileById( "menu_view_link.html", "li", "navBarUL", true );
 
164
        $this->template->appendFileById( "form_" . $this->getForm( true ) . ".html", "tbody", "privatefacility_form" );
 
165
    }
 
166
 
 
167
 
 
168
    /**
 
169
     * Set the data to be displayed for the page.
 
170
     */
 
171
    protected function setDisplayData() {
 
172
        parent::setDisplayData();
 
173
        $this->template->setDisplayData( "priavtefacility_header", $this->getTitle());
 
174
        $this->template->setDisplayData( "privatefacility_form", $this->form_link);
 
175
    }
 
176
 
 
177
    /** 
 
178
     * Display the save or confirm buttons as needed.
 
179
     * 
 
180
     * If the page is a confirmation view then the save / edit button template will be displayed.  
 
181
     * Otherwise the confirm and return buttons will be shown.
 
182
     * @param boolean $save Flag to show the save button. (Defaults to false)
 
183
     * @param boolean $show_edit (defaults to true)
 
184
     * @global array
 
185
     */
 
186
    protected  function displayControls( $save = false, $show_edit = true ) {
 
187
        if ( $save ) {
 
188
            parent::displayControls( $save, $show_edit );
 
189
        }  else {       
 
190
            $this->template->addFile( 'button_facility_confirm_child.html' );
 
191
        }               
 
192
    }               
 
193
 
 
194
 
 
195
 
 
196
    /**
 
197
     * Save the objects to the database.
 
198
     * 
 
199
     * Save the default object being edited and return to the view page.
 
200
     * @global array
 
201
     */
 
202
    protected function save() {
 
203
        parent::save();
 
204
        $this->setRedirect(  "viewprivate?id=" . $this->getPrimary()->getParent() );
 
205
    }
 
206
                
 
207
}
 
208
 
 
209
 
 
210
# Local Variables:
 
211
# mode: php
 
212
# c-default-style: "bsd"
 
213
# indent-tabs-mode: nil
 
214
# c-basic-offset: 4
 
215
# End: