3
* © Copyright 2007 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 editing of all the list databases used for drop down menus.
23
* This page has the code for the {@link ListsPage} object and then it
24
* creates an instance of this page object and calls the {@link ListsPage::display() display}
29
* @author Luke Duncan <lduncan@intrahealth.org>
30
* @copyright Copyright © 2007 IntraHealth International, Inc.
36
* Page object to handle the management of all the list databases used for drop down menus.
38
* This page handles all the editing of the list database tables using the relevant
39
* {@link I2CE_Form} interface objects. The base page lists all the types of data
40
* that can be edited. From there you can add a new entry or edit an existing one.
42
* This object overrides the default {@link save()} and {@link action()} methods since there are many
43
* database objects to be edited.
48
class iHRIS_PageFormLists extends I2CE_PageForm {
51
* @var string The type of list object being edited.
55
* @var integer The record id number of the object being edited.
60
* Create a new instance of this page.
62
* This will call the parent constructor and then setup the base
63
* template pages for the {@link I2CE_Template template}. It also sets up the values
64
* for the member variables.
65
* @param string $title The title for this page.
66
* @param string $defaultHTMLFile The default HTML file for this page.
67
* @param mixed $access The role required to access this page.
68
* @param array $files The list of template files to load for this page.
70
public function __construct( $title, $defaultHTMLFile, $access = I2CE_ROLE_ADMIN, $files=array() ) {
71
parent::__construct( $title, $defaultHTMLFile, $access, $files );
74
if ( $this->isPost() ) {
75
$this->type = $this->post('type');
76
if ( $this->post_exists( 'id' ) ) {
77
$this->id = $this->post('id');
80
if ( $this->get_exists( 'type' ) ) {
81
$this->type = $this->get('type');
83
if ( $this->get_exists( 'id' ) ) {
84
$this->id = $this->get('id');
90
* Load the HTML template files for editing and confirming the list information.
92
* Since this page has special versions, this method is only called when a particular list object
93
* is being added or edited. All other pages are loaded within the {@link action} method.
95
protected function loadHTMLTemplates() {
96
$this->template->addHTMLFile( "lists_form_base.html" );
97
$this->template->addHTMLFile( $this->getPrimary()->getHTMLTemplate(), "tbody" );
98
if ( $this->showContact() ) $this->template->appendHTMLFileById( "lists_form_contact.html", "tbody", "list_fields" );
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
$factory = I2CE_FormFactory::instance();
110
switch( $this->type ) {
113
$obj = $factory->createForm( $this->type, $this->id );
114
if ( $this->getExtra( $this->type ) && !$this->id ) {
117
$this->setObject( $obj );
120
if ( $this->showContact() ) {
121
$contact = $factory->createForm( "contact" );
122
$contact->contact_type = $factory->getConst( "contact", "TYPE_FACILITY" );
123
$this->setObject( $contact, I2CE_PageForm::EDIT_CHILD );
125
parent::loadObjects();
129
* Display the save or confirm button templates as needed.
130
* @param boolean $save Flag to show the save button.
132
protected function loadButtons( $save = false ) {
134
$this->template->addHTMLFile( "button_save.html" );
136
$this->template->addHTMLFile( "button_confirm_admin.html" );
141
* Save the objects to the database.
143
* Save the list object being edited and return to the appropriate admin page.
145
protected function save() {
147
$this->setRedirect( "lists.php?type=" . $this->type );
152
* Perform the actions of the page.
154
* This handles some special actions because there are three versions of this page:
155
* - The list page of all objects that can be edited.
156
* - The add/update page for each list object.
157
* - The edit form for each list object.
159
* Only in the third case is the parent object action method called since that is the default setup
160
* for editing objects used in most other {@link PageForm} objects.
162
protected function action() {
163
if ( $this->type == "" ) {
164
$this->template->addHTMLFile( "lists.html" );
165
} elseif ( !$this->isPost() && !$this->get_exists('id') && !$this->get_exists('add') ) {
167
$this->loadObjects();
168
if ( $select_obj =& $this->getExtra( $this->type, true ) ) {
169
$this->template->addHTMLFile( "lists_" . $this->type . ".html" );
170
$select_obj->setFormLists( $this->template, true );
172
$this->template->addHTMLFile( "lists_type_" . $this->getPrimary()->getListType() . ".html" );
173
if ( $this->getPrimary()->getListType() == "list" ) {
174
$this->template->appendHTMLFileById( "lists_type_header.html", "th", "lists_header" );
175
$list = I2CE_List::getList( $this->type );
176
foreach( $list as $record => $value ) {
177
$imported_row =& $this->template->appendHTMLFileById( "lists_type_row.html", "tr", "lists_body" );
178
if ( ++$cnt % 2 == 1 ) $this->template->setNodeAttribute( "class", "even", $imported_row );
179
$this->template->setDisplayData( "add_lists_id", "id=" . $record . "&type=" . $this->type );
180
$this->template->setDisplayData( "lists_row_name", $value );
182
} elseif ( $this->getPrimary()->getListType() == "dual" ) {
183
$head = $this->template->appendHTMLFileById( "lists_type_header.html", "th", "lists_header" );
184
$this->template->setNodeAttribute( "colspan", "2", $head );
185
$list = $this->getPrimary()->getOptionsByLink();
187
$add_link_rows = array();
188
foreach( $list as $link => $options ) {
189
if ( $link_form == "" ) $link_form = I2CE_List::lookupFormName( $link );
190
$link_value = I2CE_List::lookup( $link, $link_form );
191
$add_link_rows[ $link_value ] = array();
192
foreach( $options as $record => $value ) {
193
$add_link_rows[ $link_value ][$record] = $value;
197
$link_rows = array_keys( $add_link_rows );
199
foreach( $link_rows as $link_value ) {
200
foreach( $add_link_rows[$link_value] as $record => $value ) {
201
$imported_row =& $this->template->appendHTMLFileById( "lists_type_dual_row.html", "tr", "lists_body" );
202
if ( ++$cnt % 2 == 1 ) $this->template->setNodeAttribute( "class", "even", $imported_row );
203
$this->template->setDisplayData( "add_lists_id", "id=" . $record . "&type=" . $this->type );
204
$this->template->setDisplayData( "lists_row_name", $value );
205
$this->template->setDisplayData( "lists_row_link", $link_value );
210
I2CE_List::listOptions( $this->template, "add_ids", $this->type );
213
$this->setDisplayData();
218
$this->template->setAttribute( "class", "active", "menuLists", "a[@href='lists.php']" );
222
* Check if this type has a special page to display for the edit selection lists.
224
* This will be needed if the object is linked to another form so the drop downs can be displayed.
225
* Optionally this method will return the object to use to populate the drop downs.
226
* @param string $type
227
* @param boolean $return_object
228
* @return mixed Boolean or the I2CE_Form object to populate the drop downs.
230
public function getExtra( $type, $return_object=false ) {
231
if ( $type == "region" || $type == "district" || $type == "county" ) {
232
if ( $return_object ) return new iHRIS_LocationSelect( $type );
240
* Check to see if the current type should display contact information when editing this list object.
243
public function showContact() {