Code

a074429e75d3451fdb31693b8e1bb2a4387bf85b
[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     /* 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     /* This is not necessary, i think 
194      * Remove should be called from workGeneric ... 
195      */
196     /*$ldap= $this->config->get_ldap_link();
197     $ldap->rmdir($this->dn);
198     show_ldap_error($ldap->get_error());
199     $this->handle_post_events("remove");
200     */
201     
202     $ldap= $this->config->get_ldap_link();
203     plugin::remove_from_parent();
204     $ldap->cd($this->dn);
205     $ldap->modify($this->attrs);
206     show_ldap_error($ldap->get_error());}
209   /* Save data to object */
210   function save_object()
211   {
212     plugin::save_object();
214   }
217   /* Check supplied data */
218   function check()
219   {
220     $message= array();
222     /* Default entries can use blank hsync/vsync entries */
223     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
225       /* Check vsync for correct usage */
226       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
227       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
228           && chkacl ($this->acl, "gotoXVsync") == ""){
230         $message[]= _("Please specify a valid VSync range.");
231       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
232         list($v1,$v2)= split ("-", $val);
233         if ($v2 != ""){
234           if ($v1 > $v2){
235             $message[]= _("Please specify a valid VSync range.");
236           }
237         }
238       }
240       /* Check hsync for correct usage */
241       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
242       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
243           && chkacl ($this->acl, "gotoXHsync") == ""){
245         $message[]= _("Please specify a valid HSync range.");
246       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
247         list($v1,$v2)= split ("-", $val);
248         if ($v2 != ""){
249           if ($v1 > $v2){
250             $message[]= _("Please specify a valid HSync range.");
251           }
252         }
253       }
254     }
255     return ($message);
256   }
259   /* Save to LDAP */
260   function save()
261   {
262     plugin::save();
264     /* Strip out 'default' values */
265     foreach(array(
266           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
267           "gotoXKbModel", "gotoXKbLayout",
268           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
270       if ($this->attrs[$val] == "default"){
271         $this->attrs[$val]= array();
272       }
273     }
275     /* Write back to ldap */
276     $ldap= $this->config->get_ldap_link();
277     $ldap->cd($this->dn);
278     $ldap->modify($this->attrs);
279     show_ldap_error($ldap->get_error());
280     $this->handle_post_events("modify");
281   }
285 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
286 ?>