Code

Added workservice to ogorup tabs
[gosa.git] / plugins / admin / systems / class_workstationService.inc
1 <?php
3 class workservice extends plugin
4 {
5   /* CLI vars */
6   var $cli_summary= "Manage terminal service aspects";
7   var $cli_description= "Some longer text\nfor help";
8   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10   var $gotoScannerEnable;
11   /* Generic terminal attributes */
12   var $gotoXMonitor= "";
13   var $gotoXDriver= "";
14   var $gotoXResolution= "";
15   var $gotoXColordepth= "";
16   var $gotoXHsync= "";
17   var $gotoXVsync= "";
18   var $gotoXKbModel= "";
19   var $gotoXKbLayout= "";
20   var $gotoXKbVariant= "";
21   var $gotoXMouseType= "";
22   var $gotoXMouseport= "";
23   var $gotoScannerClients= "";
24   var $gotoScannerBackend= "";
25   var $goFonHardware= "automatic";
27   /* Needed values and lists */
28   var $ignore_account= TRUE;
29   var $base= "";
30   var $cn= "";
31   var $orig_dn= "";
32   var $XMethods= array();
33   var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
34       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
35       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
36       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga");
37   var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
38       "1400x1050", "1600x1200");
39   var $XColordepths= array("default", "8", "15", "16", "24");
40   var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
41       "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
42       "logiinetnav", "logiinternet", "macintosh", "microsoft",
43       "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
44       "pc105", "rapidaccess", "rapidaccess2", "winbook");
45   var $XKbLayouts= array ("default", "de", "intl", "us");
46   var $XKbVariants= array ("default", "nodeadkeys", "basic");
47   var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
48   var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
49   var $hardware_list= array();
50   var $used_hardware= array();
53   /* attribute list for save action */
54   var $attributes= array("cn","gotoXMonitor",
55       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
56       "gotoXHsync", "gotoXVsync",
57       "gotoScannerEnable", "gotoScannerClients",
58       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
59       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
60   var $objectclasses= array("GOhard");
63   function workservice ($config, $dn= NULL)
64   {
65     plugin::plugin ($config, $dn);
67     /* Initialize methods */
68     $this->XMethods["default"]= _("default");
69     $this->XMethods["indirect"]= _("show chooser");
70     $this->XMethods["query"]= _("direct");
71 #$this->XMethods["squery"]= _("direct via ssh");
72 #$this->XMethods["nquery"]= _("direct via nx");
73     $this->XMethods["load"]= _("load balanced");
74 #$this->XMethods["sload"]= _("load balanced via ssh");
75 #$this->XMethods["nload"]= _("load balanced via nx");
76     $this->XMethods["rdp"]= _("Windows RDP");
77     $this->XMethods["citrix"]= _("ICA client");
79     $this->orig_dn= $this->dn;
81     /* Load hardware list */
82     $ldap= $this->config->get_ldap_link();
83     $ldap->cd($this->config->current['BASE']);
84     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
85     while ($attrs= $ldap->fetch()){
86       $cn= $attrs['cn'][0];
87       if (isset($attrs['description'])){
88         $description= " - ".$attrs['description'][0];
89       } else {
90         $description= "";
91       }
92       $this->hardware_list[$cn]= "$cn$description";
93     }
95     /* Eventually colorize phones */
96     $ldap->cd($this->config->current['BASE']);
97     foreach ($this->hardware_list as $cn => $desc){
98       $ldap->search("(goFonHardware=$cn)", array('cn'));
99       if ($ldap->count() > 0){
100         $ldap->fetch();
101         if ($ldap->getDN() != $this->dn){
102           $this->used_hardware[$cn]= $ldap->getDN();
103         }
104       }
105     }
107     $this->hardware_list["automatic"]= _("automatic");
108     ksort($this->hardware_list);
109   }
111   function execute()
112   {
113     /* Do we need to flip is_account state? */
114     if (isset($_POST['modify_state'])){
115       $this->is_account= !$this->is_account;
116     }
118     /* Do we represent a valid terminal? */
119     if (!$this->is_account && $this->parent == NULL){
120       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
121         _("This 'dn' has no terminal features.")."</b>";
122       return ($display);
123     }
125     /* Show main page */
126     $smarty= get_smarty();
128     /* Arrays */ 
129     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
130           "XKbModels", "XKbLayouts", "XKbVariants",
131           "MouseTypes", "MousePorts") as $val){
132       $smarty->assign("$val", $this->$val);
133     }
134     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
135     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
136     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
137     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
139     /* Variables - select */
140     foreach(array(
141           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
142           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
143           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
145       $smarty->assign($val."_select", $this->$val);
146       $smarty->assign($val."ACL", chkacl($this->acl, $val));
147     }
149     /* Variables */
150     foreach(array("gotoXHsync", "gotoXVsync") as $val){
151       $smarty->assign($val, $this->$val);
152       $smarty->assign($val."ACL", chkacl($this->acl, $val));
153     }
154     $smarty->assign("staticAddress", "");
156     /* Checkboxes */
157     foreach(array("gotoScannerEnable") as $val){
158       if ($this->$val == TRUE) {
159         $smarty->assign("$val", "checked");
160       } else {
161         $smarty->assign("$val", "");
162       }
163     }
165     /* Phone stuff */
166     $smarty->assign ("goFonHardware", $this->goFonHardware);
167     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
168          _("Choose the phone located at the current terminal")."\" ".
169          chkacl($this->acl, "goFonHardware").">\n";
170     foreach ($this->hardware_list as $cn => $description){
171       if ($cn == $this->goFonHardware){
172         $selected= "selected";
173       } else {
174         $selected= "";
175       }
176       if (isset($this->used_hardware[$cn])){
177         $color= "style=\"color:#A0A0A0\"";
178       } else {
179         $color= "";
180       }
181       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
182     }
183     $hl.= "</select>\n";
184     $smarty->assign ("hardware_list", $hl);
185     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
187     /* Show main page */
188     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
189   }
191   function remove_from_parent()
192   {
193     $ldap= $this->config->get_ldap_link();
194     $ldap->rmdir($this->dn);
195     show_ldap_error($ldap->get_error());
196     $this->handle_post_events("remove");
197   }
200   /* Save data to object */
201   function save_object()
202   {
203     plugin::save_object();
205   }
208   /* Check supplied data */
209   function check()
210   {
211     $message= array();
213     /* Default entries can use blank hsync/vsync entries */
214     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
216       /* Check vsync for correct usage */
217       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
218       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
219           && chkacl ($this->acl, "gotoXVsync") == ""){
221         $message[]= _("Please specify a valid VSync range.");
222       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
223         list($v1,$v2)= split ("-", $val);
224         if ($v2 != ""){
225           if ($v1 > $v2){
226             $message[]= _("Please specify a valid VSync range.");
227           }
228         }
229       }
231       /* Check hsync for correct usage */
232       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
233       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
234           && chkacl ($this->acl, "gotoXHsync") == ""){
236         $message[]= _("Please specify a valid HSync range.");
237       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
238         list($v1,$v2)= split ("-", $val);
239         if ($v2 != ""){
240           if ($v1 > $v2){
241             $message[]= _("Please specify a valid HSync range.");
242           }
243         }
244       }
245     }
246     return ($message);
247   }
250   /* Save to LDAP */
251   function save()
252   {
253     plugin::save();
255     /* Strip out 'default' values */
256     foreach(array(
257           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
258           "gotoXKbModel", "gotoXKbLayout",
259           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
261       if ($this->attrs[$val] == "default"){
262         $this->attrs[$val]= array();
263       }
264     }
266     /* Write back to ldap */
267     $ldap= $this->config->get_ldap_link();
268     $ldap->cd($this->dn);
269     $ldap->modify($this->attrs);
270     show_ldap_error($ldap->get_error());
271     $this->handle_post_events("modify");
272   }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
277 ?>