Code

Added Inherit all button to Workstation Servive - testing.
[gosa.git] / plugins / admin / systems / class_workstationService.inc
1 <?php
3 class workservice extends plugin
4 {
5   var $gotoScannerEnable;
6   /* Generic terminal attributes */
7   var $gotoXMonitor= "";
8   var $gotoXDriver= "";
9   var $gotoXResolution= "";
10   var $gotoXColordepth= "";
11   var $gotoXHsync= "";
12   var $gotoXVsync= "";
13   var $AutoSync = false;
14   var $gotoXKbModel= "";
15   var $gotoXKbLayout= "";
16   var $gotoXKbVariant= "";
17   var $gotoXMouseType= "";
18   var $gotoXMouseport= "";
19   var $gotoScannerClients= "";
20   var $gotoScannerBackend= "";
21   var $goFonHardware= "automatic";
23   /* Needed values and lists */
24   var $ignore_account= TRUE;
25   var $base= "";
26   var $cn= "";
27   var $orig_dn= "";
28   var $XMethods= array();
29   var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
30       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
31       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
32       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
34   var $XResolutions = array();
36   var $MouseTypes= array();
37   var $MousePorts= array();
38   var $hardware_list= array();
39   var $used_hardware= array();
42   /* attribute list for save action */
43   var $attributes= array("gotoXMonitor",
44       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
45       "gotoXHsync", "gotoXVsync",
46       "gotoScannerEnable", "gotoScannerClients",
47       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
48       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
49   var $objectclasses= array("GOhard");
51   var $XColordepths     =array();
52   var $XKbModels        =array();
53   var $XKbLayouts       =array();
54   var $XKbVariants      =array();
56   var $member_of_ogroup = FALSE;
58   function workservice ($config, $dn= NULL, $parent= NULL)
59   {
60     plugin::plugin ($config, $dn, $parent);
63     $ldap = $this->config->get_ldap_link();
64     $ldap->cd ($this->config->current['BASE']);
65     $ldap->search("(&(objectClass=gosaGroupOfNames)(member=".$this->dn."))",array("cn"));
66     $this->member_of_ogroup = $ldap->count() >= 1;
68     $this->XResolutions= array( 
69         "640x480"   =>  "640x480",
70         "800x600"   =>  "800x600",
71         "1024x768"  =>  "1024x768",
72         "1152x864"  =>  "1152x864", 
73         "1280x1024" =>  "1280x1024",
74         "1400x1050" =>  "1400x1050", 
75         "1600x1200" =>  "1600x1200");
77     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
78       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
80       if(is_readable($file)){
81         $str = file_get_contents($file);
82         $lines = split("\n",$str);
83         foreach($lines as $line){
84           $line = trim($line);
85           if(!empty($line)){
86             $this->XResolutions[$line]=$line;
87           }
88         }
89         //natcasesort($this->gotoXResolutions);
90       }else{
91         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
92       }
93     }
95     array_unshift($this->XDrivers, "["._("unknown")."]");
96  
97     $this->XColordepths= array( 
98         "8"        => "8 " ._("bit"), 
99         "15"       => "15 "._("bit"),      
100         "16"       => "16 "._("bit"),   
101         "24"       => "24 "._("bit"));
103     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
104           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
105           "logiinetnav", "logiinternet", "macintosh", "microsoft",
106           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
107           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
108       $this->XKbModels[$type] = $type;
109     }
111     $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft", 
112                               "Logitech" => "Logitech");
114     $this->MousePorts= array("/dev/ttyS0"  =>"/dev/ttyS0", 
115                              "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
116                              "/dev/input/mice"  => "/dev/input/mice");
118     /* Additional values will be extracted from CONFIG_DIR/gosa/keyboardLayouts */
119     $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
120     $this->XKbVariants= array ("basic"=>"basic", "nodeadkeys"=>"nodeadkeys");
122     /* try to read additional keyboard layouts 
123      */
124     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
125       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
126         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
127         $tmp = split("\n",$str);
128         foreach($tmp as $entry){
129           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
130             $entry = trim($entry);
131             $tmp2 = split ("\:",$entry);
132             $la =   trim($tmp2[0]);   // What would be saved to ldap
133             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
134             $this->XKbLayouts [ $la] = $da;  
135           } 
136         }
137       }
138     }
140     /* Initialize methods */
141     $this->XMethods["indirect"]= _("show chooser");
142     $this->XMethods["query"]= _("direct");
143     #$this->XMethods["squery"]= _("direct via ssh");
144     #$this->XMethods["nquery"]= _("direct via nx");
145     $this->XMethods["load"]= _("load balanced");
146     #$this->XMethods["sload"]= _("load balanced via ssh");
147     #$this->XMethods["nload"]= _("load balanced via nx");
148     $this->XMethods["rdp"]= _("Windows RDP");
149     $this->XMethods["citrix"]= _("ICA client");
151     $this->orig_dn= $this->dn;
153     /* Load hardware list */
154     $ldap= $this->config->get_ldap_link();
155     $ldap->cd($this->config->current['BASE']);
156     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
157     while ($attrs= $ldap->fetch()){
158       $cn= $attrs['cn'][0];
159       if (isset($attrs['description'])){
160         $description= " - ".$attrs['description'][0];
161       } else {
162         $description= "";
163       }
164       $this->hardware_list[$cn]= "$cn$description";
165     }
167     /* Eventually colorize phones */
168     $ldap->cd($this->config->current['BASE']);
169     foreach ($this->hardware_list as $cn => $desc){
170       $ldap->search("(goFonHardware=$cn)", array('cn'));
171       if ($ldap->count() > 0){
172         $ldap->fetch();
173         if ($ldap->getDN() != $this->dn){
174           $this->used_hardware[$cn]= $ldap->getDN();
175         }
176       }
177     }
179     if(preg_match("/\+/",$this->gotoXHsync)){
180       $this->AutoSync = true;
181       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
182       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
183     }
185     $this->hardware_list["automatic"]= _("automatic");
186     ksort($this->hardware_list);
188     /* Load hardware list */
189     $ldap= $this->config->get_ldap_link();
190     $ldap->cd($this->config->current['BASE']);
191     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
192     if ($ldap->count() == 1){
193       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
194                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
195       $attrs= $ldap->fetch();
197       foreach ($map as $name){
198         if (!isset($attrs[$name][0])){
199           continue;
200         }
201         
202         switch ($name){
203           case 'gotoXResolution':
204             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
205             break;
206           case 'gotoXColordepth':
207             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
208             break;
209           case 'gotoXKbModel':
210             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
211             break;
212           case 'gotoXKbLayout':
213             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
214             break;
215           case 'gotoXKbVariant':
216             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
217             break;
218           case 'gotoXMouseType':
219             $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
220             break;
221           case 'gotoXMouseport':
222             $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
223             break;
224         }
226       }
228     }
230     /* Workaround to fill in inherited values if we've specified an objectclass */
231     if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
232       $this->XResolutions= array('default' => _("inherited"));
233       $this->XColordepths= array('default' => _("inherited"));
234       $this->XKbModels= array('default' => _("inherited"));
235       $this->XKbLayouts= array('default' => _("inherited"));
236       $this->XKbVariants= array('default' => _("inherited"));
237       $this->MouseTypes= array('AUTO' => _("inherited"));
238       $this->MousePorts= array('AUTO' => _("inherited"));
239     }
240   }
242   function execute()
243   {
244     /* Call parent execute */
245     plugin::execute();
247     /* Do we need to flip is_account state? */
248     if (isset($_POST['modify_state'])){
249       $this->is_account= !$this->is_account;
250     }
252     /* Do we represent a valid terminal? */
253     if (!$this->is_account && $this->parent == NULL){
254       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
255         _("This 'dn' has no terminal features.")."</b>";
256       return ($display);
257     }
259     /* Show main page */
260     $smarty= get_smarty();
262     /* Arrays */ 
263     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
264           "XKbModels", "XKbVariants",
265           "MouseTypes", "MousePorts") as $val){
266       $smarty->assign("$val", $this->$val);
267     }
268     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
269     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
271     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
272     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
273     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
274     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
276     /* Variables - select */
277     foreach(array(
278           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
279           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
280           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
282       $smarty->assign($val."_select", $this->$val);
283       $smarty->assign($val."ACL", chkacl($this->acl, $val));
284     }
286     /* Variables */
287     foreach(array("gotoXHsync", "gotoXVsync") as $val){
288       $smarty->assign($val, $this->$val);
289       $smarty->assign($val."ACL", chkacl($this->acl, $val));
290     }
291     $smarty->assign("staticAddress", "");
293     /* Checkboxes */
294     foreach(array("gotoScannerEnable") as $val){
295       if ($this->$val == TRUE) {
296         $smarty->assign("$val", "checked");
297       } else {
298         $smarty->assign("$val", "");
299       }
300     }
302     /* Phone stuff */
303     $smarty->assign ("goFonHardware", $this->goFonHardware);
304     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
305       _("Choose the phone located at the current terminal")."\" ".
306       chkacl($this->acl, "goFonHardware").">\n";
307     foreach ($this->hardware_list as $cn => $description){
308       if ($cn == $this->goFonHardware){
309         $selected= "selected";
310       } else {
311         $selected= "";
312       }
313       if (isset($this->used_hardware[$cn])){
314         $color= "style=\"color:#A0A0A0\"";
315       } else {
316         $color= "";
317       }
318       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
319     }
320     $hl.= "</select>\n";
321     $smarty->assign ("hardware_list", $hl);
322     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
323     $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
325     if($this->AutoSync){
326       $smarty->assign("AutoSyncCHK"," checked ");
327       $smarty->assign("hiddenState"," disabled ");
328     }else{
329       $smarty->assign("AutoSyncCHK"," ");
330       $smarty->assign("hiddenState","");
331     }
333     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
335     /* Show main page */
336     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
337   }
339   function remove_from_parent()
340   {
341     $this->handle_post_events("remove");
342   }
344   /* Save data to object */
345   function save_object()
346   {
347     plugin::save_object();
349     if(isset($_POST["inheritAll"])){
350       $this->set_everything_to_inherited();
351     }
353     if(isset($_POST['gotoXDriver']) && chkacl($this->acl,"AutoSync") == ""){
354       if(isset($_POST['AutoSync'])){
355         $this->AutoSync = true;
356       }else{
357         $this->AutoSync = false;
358       }
359     }
360   }
362   /* Check supplied data */
363   function check()
364   {
365     /* Call common method to give check the hook */
366     $message= plugin::check();
368     /* Default entries can use blank hsync/vsync entries */
369     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
371       /* But only if no auto sync is enabled... */
372       if (!$this->AutoSync){
374         /* Check vsync for correct usage */
375         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
376         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
377             && chkacl ($this->acl, "gotoXVsync") == ""){
379           $message[]= _("Please specify a valid VSync range.");
380         } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
381           list($v1,$v2)= preg_split ("/[-+]/", $val);
382           if ($v2 != ""){
383             if ($v1 > $v2){
384               $message[]= _("Please specify a valid VSync range.");
385             }
386           }
387         }
389         /* Check hsync for correct usage */
390         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
391         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
392             && chkacl ($this->acl, "gotoXHsync") == ""){
394           $message[]= _("Please specify a valid HSync range.");
395         } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
396           list($v1,$v2)= preg_split ("/[-+]/", $val);
397           if ($v2 != ""){
398             if ($v1 > $v2){
399               $message[]= _("Please specify a valid HSync range.");
400             }
401           }
402         }
403       }
404     }
406     return ($message);
407   }
410   /* Save to LDAP */
411   function save()
412   {
413     /* remove objectclass GOhard if this is an ogroup tab */
414     if(isset($this->parent->by_object['ogroup'])){
415       $this->objectclasses = array();
416     }
418     plugin::save();
420     /* Strip out 'default' values */
421     foreach(array(
422           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
423           "gotoXKbModel", "gotoXKbLayout",
424           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
426       if ($this->attrs[$val] == "default"){
427         $this->attrs[$val]= array();
428       }
429     }
431     if($this->AutoSync){
432       $this->attrs['gotoXHsync'] = "30+55";
433       $this->attrs['gotoXVsync'] = "50+70";
434     }
436     /* Write back to ldap */
437     $ldap= $this->config->get_ldap_link();
438     $ldap->cd($this->dn);
439     $this->cleanup();
440     $ldap->modify ($this->attrs); 
442     show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
443     $this->handle_post_events("modify");
444   }
446   
447   function set_everything_to_inherited()
448   {
449       $this->gotoXKbLayout = "default";
450       $this->gotoXKbModel = "default";
451       $this->gotoXKbVariant = "default";      
453       $this->gotoXDriver ="default";
454       $this->gotoXResolution ="default";
455       $this->gotoXColordepth ="default";
456       $this->gotoXMouseType ="default";
457       $this->gotoXMouseport ="default";
458   }
461 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
462 ?>