Code

f6b76e5ded6c5b9f9d042cfca8d471d87a292ca8
[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("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         /* Call parent execute */
114         plugin::execute();
115     /* Do we need to flip is_account state? */
116     if (isset($_POST['modify_state'])){
117       $this->is_account= !$this->is_account;
118     }
120     /* Do we represent a valid terminal? */
121     if (!$this->is_account && $this->parent == NULL){
122       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
123         _("This 'dn' has no terminal features.")."</b>";
124       return ($display);
125     }
127     /* Show main page */
128     $smarty= get_smarty();
130     /* Arrays */ 
131     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
132           "XKbModels", "XKbLayouts", "XKbVariants",
133           "MouseTypes", "MousePorts") as $val){
134       $smarty->assign("$val", $this->$val);
135     }
136     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
137     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
138     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
139     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
141     /* Variables - select */
142     foreach(array(
143           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
144           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
145           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
147       $smarty->assign($val."_select", $this->$val);
148       $smarty->assign($val."ACL", chkacl($this->acl, $val));
149     }
151     /* Variables */
152     foreach(array("gotoXHsync", "gotoXVsync") as $val){
153       $smarty->assign($val, $this->$val);
154       $smarty->assign($val."ACL", chkacl($this->acl, $val));
155     }
156     $smarty->assign("staticAddress", "");
158     /* Checkboxes */
159     foreach(array("gotoScannerEnable") as $val){
160       if ($this->$val == TRUE) {
161         $smarty->assign("$val", "checked");
162       } else {
163         $smarty->assign("$val", "");
164       }
165     }
167     /* Phone stuff */
168     $smarty->assign ("goFonHardware", $this->goFonHardware);
169     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
170          _("Choose the phone located at the current terminal")."\" ".
171          chkacl($this->acl, "goFonHardware").">\n";
172     foreach ($this->hardware_list as $cn => $description){
173       if ($cn == $this->goFonHardware){
174         $selected= "selected";
175       } else {
176         $selected= "";
177       }
178       if (isset($this->used_hardware[$cn])){
179         $color= "style=\"color:#A0A0A0\"";
180       } else {
181         $color= "";
182       }
183       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
184     }
185     $hl.= "</select>\n";
186     $smarty->assign ("hardware_list", $hl);
187     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
189     /* Show main page */
190     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
191   }
193   function remove_from_parent()
194   {
195     /* This is not necessary, i think 
196      * Remove should be called from workGeneric ... 
197      */
198     /*$ldap= $this->config->get_ldap_link();
199     $ldap->rmdir($this->dn);
200     show_ldap_error($ldap->get_error());
201     $this->handle_post_events("remove");
202     */
203    
204     /* This only removes the attributes from this tab, 
205      * and not hte whole entry 
206      */ 
207     $ldap= $this->config->get_ldap_link();
208     plugin::remove_from_parent();
209     $ldap->cd($this->dn);
210     $ldap->modify($this->attrs);
211     show_ldap_error($ldap->get_error());}
214   /* Save data to object */
215   function save_object()
216   {
217     plugin::save_object();
219   }
222   /* Check supplied data */
223   function check()
224   {
225     $message= array();
227     /* Default entries can use blank hsync/vsync entries */
228     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
230       /* Check vsync for correct usage */
231       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
232       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
233           && chkacl ($this->acl, "gotoXVsync") == ""){
235         $message[]= _("Please specify a valid VSync range.");
236       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
237         list($v1,$v2)= split ("-", $val);
238         if ($v2 != ""){
239           if ($v1 > $v2){
240             $message[]= _("Please specify a valid VSync range.");
241           }
242         }
243       }
245       /* Check hsync for correct usage */
246       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
247       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
248           && chkacl ($this->acl, "gotoXHsync") == ""){
250         $message[]= _("Please specify a valid HSync range.");
251       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
252         list($v1,$v2)= split ("-", $val);
253         if ($v2 != ""){
254           if ($v1 > $v2){
255             $message[]= _("Please specify a valid HSync range.");
256           }
257         }
258       }
259     }
260     return ($message);
261   }
264   /* Save to LDAP */
265   function save()
266   {
267     plugin::save();
269     /* Strip out 'default' values */
270     foreach(array(
271           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
272           "gotoXKbModel", "gotoXKbLayout",
273           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
275       if ($this->attrs[$val] == "default"){
276         $this->attrs[$val]= array();
277       }
278     }
280     /* Write back to ldap */
281     $ldap= $this->config->get_ldap_link();
282     $ldap->cd($this->dn);
283     $ldap->modify($this->attrs);
284     show_ldap_error($ldap->get_error());
285     $this->handle_post_events("modify");
286   }
290 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
291 ?>