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/>.
25
* @author Carl Leitner <litlfred@ibiblio.org>
26
* @copyright Copyright © 2007, 2008 IntraHealth International, Inc.
27
* This file is part of I2CE. I2CE is free software; you can redistribute it and/or modify it under
28
* the terms of the GNU General Public License as published by the Free Software Foundation; either
29
* version 3 of the License, or (at your option) any later version. I2CE is distributed in the hope
30
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
31
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have
32
* received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
37
class I2CE_Page_MagicDataBrowser extends I2CE_Page {
42
* @var protected array $config_path array of strings. the configuration path requested for this page.
44
protected $config_path;
47
* @var I2CE_MagicData protected The magic data pointed to by the config path
52
* Constructor -- called from page wrangler for URL of form admin/(module_name)/action/arg1/arg2
53
* @param string $shortname A module name to show the admin page for. Defaults to null to mean no module.
54
* @param string $action The action this pages is to perform
55
* @param array $args an array of strings
56
* @param string $message. A message to display on the page. Defaults to null
58
public function __construct($args,$request_remainder) {
59
parent::__construct($args,$request_remainder);
60
$this->config_path = $request_remainder;
61
$this->config = I2CE::getConfig()->__traverse('/'.implode('/',$this->config_path),false,false);
62
if (!$this->config instanceof I2CE_MagicDataNode ) {
63
I2CE::raiseError("Invalid Path:'/".implode('/',$this->config_path));
64
$this->config = I2CE::getConfig(); //just in case
71
* Perform the actions for this page
73
protected function action() {
75
switch($this->page()) {
77
$name = $this->config->__getName();
78
$parent = $this->config->__parent;
79
I2CE::raiseError("Parent: " . $parent->__getPath(false) . "\n child=$name");
80
if ($this->config->__getPath() != $this->config->__top->__getPath()) { //don't allow an erase of the top level node
81
$this->config->__erase($name);
83
$this->config = $parent;
84
$this->setRedirect($this->module() .'/show/' . $parent->__getPath(false));
87
$this->actionDisplayConfig();
90
$this->setRedirect($this->module() .'/show/' . implode('/',$this->request_remainder));
97
function displayConfig($config,$magicNode,$full) {
98
$keys = $config->getKeys();
99
if (count($keys) > 0) {
100
foreach ($keys as $key) {
101
if($config->__checkType($key,'parent')) {
102
$path = 'magicDataBrowser/show/' . $config->__getPath(false);
103
$node = $this->template->loadFile("browser_node.html",'li');
104
$magicNode->appendChild($node);
105
$subNode = $this->template->query( ".//*[@name='magic_data_list']",$node);
106
$this->template->setDisplayDataImmediate('browser_magic_data_key_path',$path.'/'.$key,$node);
107
$this->template->setDisplayDataImmediate('browser_magic_data_key',$key,$node);
108
if ($full && $subNode->length > 0) {
109
$this->displayConfig($config->$key,$subNode->item(0),$full);
111
$valueNode = $this->template->getElementById('browser_magic_data_value',$node);
112
if (!$valueNode instanceof DOMElement) {
115
if ($this->hasAjax()) {
116
$replacementNode = $this->template->createElement('span',
117
array('class'=>'clickable',
118
'id'=>"magic_data_list_$path/$key"
122
$this->addAjaxUpdate("magic_data_list_$path/$key",
123
"magic_data_list_$path/$key",
128
$this->addAjaxUpdateFunctionComplete("magic_data_list_$path/$key",
129
"$('magic_data_list_$path/$key').removeClass('clickable')"
132
$replacementNode = $this->template->createTextNode('*******');
134
$valueNode->parentNode->replaceChild($replacementNode,$valueNode);
136
} else if($config->__checkType($key,'value')) {
137
//just display the value
138
$valueNode = $this->template->loadFile("browser_value_node.html",'li');
139
$magicNode->appendChild($valueNode);
140
$this->template->setDisplayDataImmediate('browser_magic_data_key',$key,$valueNode);
141
$this->template->setDisplayDataImmediate('browser_magic_data_value',$config->$key,$valueNode);
142
$this->template->setDisplayDataImmediate('erase_link','magicDataBrowser/erase/'. $config->__getPath(false) . "/$key",$valueNode);
143
} else if( $config->__checkType($key,'indeterminate')) {
144
$valueNode = $this->template->loadFile("browser_value_node_notset.html",'li');
145
$magicNode->appendChild($valueNode);
146
$this->template->setDisplayDataImmediate('browser_magic_data_key',$key,$valueNode);
147
$this->template->setDisplayDataImmediate('erase_link','magicDataBrowser/erase/'. $config->__getPath(false) . "/$key",$valueNode);
154
protected function actionDisplayConfig() {
155
$this->template->setBodyId( "magicDataBrowserPage" );
156
$this->template->addHeaderLink("MagicDataBrowser.css");
157
if ($this->hasAjax() === true) {
158
$this->template->addHeaderLink("mootools.js");
160
$path = $this->config->__getPath(false);
161
$magicNode = $this->template->addFile( "browser.html", "div" );
162
$this->template->setAttribute( "class", "active", "menuConfigure", "a[@href='configure']" );
163
$this->template->appendFileById( "menu_configure.html", "ul", "menuConfigure" );
164
$this->template->setAttribute( "class", "active", "menuBrowseMagicData", "a[@href='magicDataBrowser/show']" );
165
$this->template->addFile( "magicdata_export_controls.html", "div" );
167
$this->template->addFormWorm('magicdata_export_form');
169
$this->template->setDisplayDataImmediate('config_path_display', $path, $magicNode);
170
if (!$this->get_exists('full')) {
171
$this->template->setDisplayDataImmediate('full_view','magicDataBrowser/show' . $path .'?full' , $magicNode);
172
$this->template->setDisplayDataImmediate('compressed_view','');
174
$this->template->setDisplayDataImmediate('compressed_view','magicDataBrowser/show' . $path , $magicNode);
175
$this->template->setDisplayDataImmediate('full_view','');
177
if (strlen($path) > 1) {
178
$this->template->setDisplayDataImmediate('parent_config','magicDataBrowser/show' . $path . '/../', $magicNode);
180
$this->template->setDisplayDataImmediate('parent_config','', $magicNode);
182
if ($path !== $this->config->__top->__getPath(false)) {
183
$actionNodeList = $this->template->query("//*[@id='magicdata_erase']");
184
for ($i=0; $i < $actionNodeList->length; $i++) {
185
$actionNodeList->item($i)->setAttribute('action','magicDataBrowser/erase/' . $path);
188
$this->template->removeNodeById('magicdata_erase');
190
$actionNodeList = $this->template->query("//*[@id='magicdata_export']");
191
for ($i=0; $i < $actionNodeList->length; $i++) {
192
$actionNodeList->item($i)->setAttribute('action','magicDataExport/export/' . $path);
194
$magicListNode =$this->template->query( ".//*[@name='magic_data_list']",$magicNode);
195
if ($magicListNode->length > 0) {
196
$this->displayConfig($this->config,$magicListNode->item(0) ,$this->get_exists('full'));
207
# c-default-style: "bsd"
208
# indent-tabs-mode: nil