~oh-dev/openhealth/phit-tools

« back to all changes in this revision

Viewing changes to ihris-suite/lib/i2ce/modules/MagicDataBrowser/I2CE_Page_MagicDataBrowser.php

  • Committer: litlfred at ibiblio
  • Date: 2009-10-23 12:59:28 UTC
  • Revision ID: litlfred@ibiblio.org-20091023125928-u5lkafz0urm9t8eq
updated ihris-suite to 4.0.1-prerelease -- not debugged

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
 
 * Default Admin Page
22
 
 *
23
 
 * @package I2CE
24
 
 * @subpackage Core
25
 
 * @author Carl Leitner <litlfred@ibiblio.org>
26
 
 * @copyright Copyright &copy; 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/>.
33
 
 * @version 2.1
34
 
 * @access public
35
 
 */
36
 
 
37
 
class I2CE_Page_MagicDataBrowser extends I2CE_Page {
38
 
 
39
 
        
40
 
 
41
 
    /*
42
 
     * @var protected array $config_path array of strings.  the configuration path requested for this page.
43
 
     */
44
 
    protected $config_path;
45
 
 
46
 
    /*
47
 
     * @var I2CE_MagicData protected The magic data pointed to by the config path
48
 
     */
49
 
    protected $config;
50
 
    
51
 
    /**
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
57
 
     */
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
65
 
        }
66
 
 
67
 
    }
68
 
 
69
 
 
70
 
    /*
71
 
     * Perform the actions for this page
72
 
     */
73
 
    protected function action() {
74
 
        parent::action();
75
 
        switch($this->page()) {
76
 
        case 'erase':
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);            
82
 
            }
83
 
            $this->config = $parent;
84
 
            $this->setRedirect($this->module() .'/show/' . $parent->__getPath(false));
85
 
            break;
86
 
        case 'show':
87
 
            $this->actionDisplayConfig();
88
 
            break;
89
 
        default:
90
 
            $this->setRedirect($this->module() .'/show/' . implode('/',$this->request_remainder));
91
 
        }
92
 
    }
93
 
 
94
 
 
95
 
        
96
 
 
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); 
110
 
                    } else {
111
 
                        $valueNode = $this->template->getElementById('browser_magic_data_value',$node);
112
 
                        if (!$valueNode instanceof DOMElement) {
113
 
                            continue;
114
 
                        }
115
 
                        if ($this->hasAjax()) {
116
 
                            $replacementNode = $this->template->createElement('span',
117
 
                                                                              array('class'=>'clickable',
118
 
                                                                                    'id'=>"magic_data_list_$path/$key"
119
 
                                                                                  ), 
120
 
                                                                              'show values' 
121
 
                                ); 
122
 
                            $this->addAjaxUpdate("magic_data_list_$path/$key",
123
 
                                                 "magic_data_list_$path/$key",
124
 
                                                 'click',
125
 
                                                 "$path/$key",
126
 
                                                 'magic_data_list'
127
 
                                );
128
 
                            $this->addAjaxUpdateFunctionComplete("magic_data_list_$path/$key",
129
 
                                                                 "$('magic_data_list_$path/$key').removeClass('clickable')"
130
 
                                );
131
 
                        } else {
132
 
                            $replacementNode = $this->template->createTextNode('*******');
133
 
                        }
134
 
                        $valueNode->parentNode->replaceChild($replacementNode,$valueNode);
135
 
                    }
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);
148
 
                }
149
 
            }
150
 
        }
151
 
    }
152
 
 
153
 
 
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");
159
 
        }
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" );
166
 
 
167
 
        $this->template->addFormWorm('magicdata_export_form');
168
 
                
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','');
173
 
        } else {
174
 
            $this->template->setDisplayDataImmediate('compressed_view','magicDataBrowser/show' . $path , $magicNode); 
175
 
            $this->template->setDisplayDataImmediate('full_view','');
176
 
        }
177
 
        if (strlen($path) > 1) {
178
 
            $this->template->setDisplayDataImmediate('parent_config','magicDataBrowser/show' . $path . '/../', $magicNode);
179
 
        }  else {
180
 
            $this->template->setDisplayDataImmediate('parent_config','', $magicNode);
181
 
        }
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);
186
 
            }
187
 
        } else {
188
 
            $this->template->removeNodeById('magicdata_erase');
189
 
        }
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);
193
 
        }
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'));  
197
 
        }
198
 
 
199
 
    }
200
 
 
201
 
 
202
 
 
203
 
}
204
 
 
205
 
# Local Variables:
206
 
# mode: php
207
 
# c-default-style: "bsd"
208
 
# indent-tabs-mode: nil
209
 
# c-basic-offset: 4
210
 
# End: