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
* Manage adding or editing forms associated with a trainer to the database.
26
* @author Luke Duncan <lduncan@intrahealth.org>
27
* @copyright Copyright © 2007, 2008 IntraHealth International, Inc.
33
* Page object to handle the adding or editing forms associated with a trainer to the database.
39
class iHRIS_PageFormParentTrainer extends I2CE_PageForm {
42
* Return the form name for this page.
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.
48
protected function getForm( $html=false ) { return $this->form_name; }
51
* @var integer The record id number of the object being edited.
55
* @var integer The recored if number of the parent of the object being edited
59
* The form name being edited by this page.
65
* The link used to access this form
66
* $var protected string $form_link
74
public function setFormLink($link) {
75
$this->form_link = $link;
81
* Create a new instance of this page.
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.
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);
97
$this->form_name = $form_name;
98
$this->form_link = $form_name ;
102
* Create and load data for the objects used for this form.
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.
108
protected function loadObjects() {
109
if ($this->isPost()) {
110
$primary = $this->factory->createContainer($this->getForm());
111
if (!$primary instanceof I2CE_Form) {
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;
123
$id = $this->getForm() . '|0';
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");
130
$primary->populate();
131
} elseif ( $this->get_exists('parent') ) {
132
$primary = $this->factory->createContainer($this->getForm());
133
if (!$primary instanceof I2CE_Form) {
136
$parent = $this->get('parent');
137
if (strpos($parent,'|')=== false) {
138
I2CE::raiseError("Deprecated use of parent variable");
139
$parent = 'trainer|' . $id;
141
$primary->setParent($parent);
143
if ($this->isGet()) {
144
$primary->load($this->get());
146
$trainer = $this->factory->createContainer( $primary->getParent());
147
if (!$trainer instanceof iHRIS_Trainer) {
148
I2CE::raiseError("Could not create trainer form from " . $primary->getParent());
151
$trainer->populate();
152
$this->setObject($primary);
153
$this->setObject($trainer,I2CE_PageForm::EDIT_PARENT);
154
//parent::loadObjects();
159
* Load the HTML template files for editing.
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", "trainer_form" );
169
* Set the data to be displayed for the page.
171
protected function setDisplayData() {
172
parent::setDisplayData();
173
$this->template->setDisplayData( "trainer_header", $this->getTitle() );
174
$this->template->setDisplayData( "trainer_form", $this->form_link);
179
* Save the objects to the database.
181
* Save the default object being edited and return to the view page.
184
protected function save() {
186
$this->setRedirect( "viewtrainer?id=" . $this->getPrimary()->getParent() );
194
# c-default-style: "bsd"
195
# indent-tabs-mode: nil