Code

Updated template engine
[gosa.git] / gosa-plugins / goto / admin / systems / goto / Config / class_DeviceConfig.inc
1 <?php
3 class DeviceConfig extends plugin
4 {
5     private $TemplateEngine = NULL;
7     private $idToName = array();
9     function __construct(&$config, $dn)
10     {
11         $this->TemplateEngine = new TemplateEngine($config);
12         $this->config = $config;
14         $str = '{
15             "PuppetModule": {
16                 "options": {
17                     "dependency": {
18                         "description": "Modules that are needed to be installed for this module",
19                             "required": false,
20                             "value": [
22                                 ],
23                             "syntax": "^[a-zA-Z0-9_+\\\\./-]+(\\\\[[<=>]+[a-zA-Z0-9_+\\\\.-]+\\\\])?$",
24                             "type": "list",
25                             "display": "Module dependencies"
26                     },
27                         "version": {
28                             "description": "The version of the puppet module",
29                             "required": true,
30                             "value": "",
31                             "syntax": "^[a-zA-Z0-9_+.-]+$",
32                             "type": "string",
33                             "display": "Module  version"
34                         },
35                         "name": {
36                             "description": "The name of the puppet module",
37                             "required": true,
38                             "value": "",
39                             "syntax": "^[a-zA-Z0-9_+.-]+$",
40                             "type": "string",
41                             "display": "Module name"
42                         },
43                         "description": {
44                             "required": false,
45                             "type": "string",
46                             "display": "Module description",
47                             "value": "",
48                             "description": "Text       briefly describing the module contents"
49                         }
50                 },
51                     "container": [
52                         "PuppetManifest",
53                     "PuppetFile",
54                     "PuppetTemplate"
55                         ],
56                     "name": "Module",
57                     "description": "Puppet     module"
58             },
59                 "root": {
60                     "options": {
62                     },
63                     "container": [
64                         "PuppetModule"
65                         ],
66                     "name": "Root",
67                     "description": "The root item"
68                 }
69         }';        
71         $this->itemConfig = json_decode($str, TRUE);
72         $this->TemplateEngine->load($this->itemConfig);
73         
74         // Check for the root object
75         if(!isset($this->itemConfig['root'])){
76             echo 'No root!';
77         }
79         // Set current item to 'root'.
80         $this->currentItemDescriptor = &$this->itemConfig['root'];
81         $this->currentItemValues = array();
82         $this->currentItem = array();
84         $this->addItem('root','root',array());
85         $this->setCurrentItem('root');
86         $this->addItem('PuppetModule','test1',
87                 array(
88                     'version' => 1,
89                     'name'  => 'test1',
90                     'description' => 'Test Module')
91                 );
92         $this->addItem('PuppetModule','test2',
93                 array(
94                     'version' => 1,
95                     'name'  => 'test2',
96                     'description' => 'Test Module')
97                 );
98         $this->setCurrentItem('test1');
99         $this->addItem('PuppetTemplate','temp1',array('name' => 'temp1', 'file' => 'kekse.tpl'));
101         $this->setCurrentItem('root');
102     }
105     function renderNavigator($array = NULL)
106     {
107         $array = ($array == NULL)? $this->currentItemValues['root']: $array;
108         $str = "<ul>";
109         $plug = $_GET['plug'];
111         $id = array_search($array['name'],$this->idToName);
112         $str .= "<a href='?plug={$plug}&amp;item={$id}'>";
113         if($this->currentItemName == $array['name']){
114             $str .= "<b>".$array['name']."</b>";
115         }else{
116             $str .= $array['name'];
117         }
118         $str .= "</a>";
120         if(count($array['children'])){
121             foreach($array['children'] as $subItem){
122                 $str .= $this->renderNavigator($subItem);
123             } 
124         }
125         $str  .= "</ul>";
126         return($str);
127     }
129     function addItem($type,$name, $values)
130     {
131         $current = &$this->currentItem; 
132         $this->idToName[] = $name;
133         $new = array(
134                 'children' => array(),
135                 'type' => $type, 
136                 'name' => $name, 
137                 'values' => $values);
138         $this->currentItemValues[$name] = $new;
139         $current['children'][$name] = &$this->currentItemValues[$name];
140     }
142     function setCurrentItem($item)
143     {
144         $this->currentItemName = $item;
145         $this->currentItem = &$this->currentItemValues[$item];
146         $this->currentItemType = $this->currentItem['type'];
147         $this->currentItemDescriptor =&$this->itemConfig[$this->currentItem['type']];
148     }
151     function execute()
152     {
153         $smarty = get_smarty();
154         
155         // Assign possible sub-container objects.
156         $smarty->assign('subModule', $this->currentItemDescriptor['container']);
157         $smarty->assign('containerName', $this->currentItemDescriptor['name']);
158         $smarty->assign('containerDescription', $this->currentItemDescriptor['description']);
160         $smarty->assign('navigator', $this->renderNavigator());
161         
164         $this->TemplateEngine->setType($this->currentItemType);
165         $this->TemplateEngine->setValues($this->currentItem);
166         $this->TemplateEngine->setTemplate('puppet.tpl');
167         $smarty->assign('template',$this->TemplateEngine->render());
168         return($smarty->fetch(get_template_path('goto/Config/DeviceConfig.tpl', TRUE)));
169     }
171     function save_object()
172     {
173         if(isset($_POST['addSubModule']) && isset($_POST['subModule'])){
174             $sub = get_post('subModule');
175             if(in_array($sub, $this->currentItemDescriptor['container'])){
176                 
177             }
178         }
179     
180         if(isset($_GET['item'])){
181             $name = $this->idToName[$_GET['item']];
182             $this->setCurrentItem($name);
183         }
184     }
186 ?>