Code

queue parameter modifcated
[gosa.git] / plugins / admin / systems / class_terminalService.inc
1 <?php
3 class termservice 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   /* Generic terminal attributes */
11   var $gotoLpdEnable= FALSE;
12   var $gotoXMonitor= "";
13   var $gotoXMethod= "";
14   var $gotoXdmcpServer= "";
15   var $gotoFontPath= "";
16   var $gotoXDriver= "";
17   var $gotoXResolution= "";
18   var $gotoXColordepth= "";
19   var $gotoXHsync= "";
20   var $gotoXVsync= "";
21   var $gotoXKbModel= "";
22   var $gotoXKbLayout= "";
23   var $gotoXKbVariant= "";
24   var $gotoXMouseType= "";
25   var $gotoXMouseport= "";
26   var $gotoLpdServer= "";
27   var $gotoScannerEnable= "";
28   var $gotoScannerModel= "";
29   var $gotoScannerClients= "";
30   var $gotoScannerBackend= "";
31   var $goFonHardware= "automatic";
33   /* Needed values and lists */
34   var $ignore_account= TRUE;
35   var $base= "";
36   var $cn= "";
37   var $orig_dn= "";
38   var $XMethods= array();
39   var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
40       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
41       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
42       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga");
43   var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
44       "1400x1050", "1600x1200");
45   var $XColordepths= array("default", "8", "15", "16", "24");
46   var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
47       "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
48       "logiinetnav", "logiinternet", "macintosh", "microsoft",
49       "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
50       "pc105", "rapidaccess", "rapidaccess2", "winbook");
51   var $XKbLayouts= array ("default", "de", "intl", "us");
52   var $XKbVariants= array ("default", "nodeadkeys", "basic");
53   var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
54   var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
55   var $gotoScannerModels= array();
56   var $hardware_list= array();
57   var $used_hardware= array();
60   /* attribute list for save action */
61   var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
62       "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
63       "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
64       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
65       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
66       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
67   var $objectclasses= array("GOhard");
70   function termservice ($config, $dn= NULL)
71   {
72     plugin::plugin ($config, $dn);
74     /* Load scanner models */
75     $fcontents = file ($this->config->basedir."/include/scanner.inc");
76     while (list ($line_num, $line) = each ($fcontents)) {
77       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
78       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
79     }
80     ksort ($this->gotoScannerModels);
82     /* Initialize methods */
83     $this->XMethods["default"]= _("default");
84     $this->XMethods["indirect"]= _("show chooser");
85     $this->XMethods["query"]= _("direct");
86 #$this->XMethods["squery"]= _("direct via ssh");
87 #$this->XMethods["nquery"]= _("direct via nx");
88     $this->XMethods["load"]= _("load balanced");
89 #$this->XMethods["sload"]= _("load balanced via ssh");
90 #$this->XMethods["nload"]= _("load balanced via nx");
91     $this->XMethods["rdp"]= _("Windows RDP");
92     $this->XMethods["citrix"]= _("ICA client");
94     $this->orig_dn= $this->dn;
96     /* Load hardware list */
97     $ldap= $this->config->get_ldap_link();
98     $ldap->cd($this->config->current['BASE']);
99     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
100     while ($attrs= $ldap->fetch()){
101       $cn= $attrs['cn'][0];
102       if (isset($attrs['description'])){
103         $description= " - ".$attrs['description'][0];
104       } else {
105         $description= "";
106       }
107       $this->hardware_list[$cn]= "$cn$description";
108     }
110     /* Eventually colorize phones */
111     $ldap->cd($this->config->current['BASE']);
112     foreach ($this->hardware_list as $cn => $desc){
113       $ldap->search("(goFonHardware=$cn)", array('cn'));
114       if ($ldap->count() > 0){
115         $ldap->fetch();
116         if ($ldap->getDN() != $this->dn){
117           $this->used_hardware[$cn]= $ldap->getDN();
118         }
119       }
120     }
122     $this->hardware_list["automatic"]= _("automatic");
123     ksort($this->hardware_list);
124   }
126   function execute()
127   {
128     /* Do we need to flip is_account state? */
129     if (isset($_POST['modify_state'])){
130       $this->is_account= !$this->is_account;
131     }
133     /* Do we represent a valid terminal? */
134     if (!$this->is_account && $this->parent == NULL){
135       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
136         _("This 'dn' has no terminal features.")."</b>";
137       return ($display);
138     }
140     /* Show main page */
141     $smarty= get_smarty();
143     /* Arrays */ 
144     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
145           "gotoScannerModels", "XKbModels", "XKbLayouts", "XKbVariants",
146           "MouseTypes", "MousePorts") as $val){
147       $smarty->assign("$val", $this->$val);
148     }
149     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
150     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
151     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
152     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
154     /* Variables - select */
155     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
156           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
157           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
158           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
160       $smarty->assign($val."_select", $this->$val);
161       $smarty->assign($val."ACL", chkacl($this->acl, $val));
162     }
164     /* Variables */
165     foreach(array("gotoXHsync", "gotoXVsync") as $val){
166       $smarty->assign($val, $this->$val);
167       $smarty->assign($val."ACL", chkacl($this->acl, $val));
168     }
169     $smarty->assign("staticAddress", "");
171     /* Checkboxes */
172     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
173       if ($this->$val == TRUE) {
174         $smarty->assign("$val", "checked");
175       } else {
176         $smarty->assign("$val", "");
177       }
178       $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
179     }
181     /* Phone stuff */
182     $smarty->assign ("goFonHardware", $this->goFonHardware);
183     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
184          _("Choose the phone located at the current terminal")."\" ".
185          chkacl($this->acl, "goFonHardware").">\n";
186     foreach ($this->hardware_list as $cn => $description){
187       if ($cn == $this->goFonHardware){
188         $selected= "selected";
189       } else {
190         $selected= "";
191       }
192       if (isset($this->used_hardware[$cn])){
193         $color= "style=\"color:#A0A0A0\"";
194       } else {
195         $color= "";
196       }
197       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
198     }
199     $hl.= "</select>\n";
200     $smarty->assign ("hardware_list", $hl);
201     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
203     /* Show main page */
204     return($smarty->fetch (get_template_path('service.tpl', TRUE)));
205   }
207   function remove_from_parent()
208   {
209     $ldap= $this->config->get_ldap_link();
210     $ldap->rmdir($this->dn);
211     show_ldap_error($ldap->get_error());
212     $this->handle_post_events("remove");
213   }
216   /* Save data to object */
217   function save_object()
218   {
219     plugin::save_object();
221     /* Save checkbox state */
222     if (isset ($_POST['gotoXMethod'])){
223       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
225         if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
226           $this->$val= FALSE;
227         } else {
228           $this->$val= TRUE;
229         }
230       }
231     }
232   }
235   /* Check supplied data */
236   function check()
237   {
238     $message= array();
240     /* Default entries can use blank hsync/vsync entries */
241     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
243       /* Check vsync for correct usage */
244       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
245       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
246           && chkacl ($this->acl, "gotoXVsync") == ""){
248         $message[]= _("Please specify a valid VSync range.");
249       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
250         list($v1,$v2)= split ("-", $val);
251         if ($v2 != ""){
252           if ($v1 > $v2){
253             $message[]= _("Please specify a valid VSync range.");
254           }
255         }
256       }
258       /* Check hsync for correct usage */
259       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
260       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
261           && chkacl ($this->acl, "gotoXHsync") == ""){
263         $message[]= _("Please specify a valid HSync range.");
264       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
265         list($v1,$v2)= split ("-", $val);
266         if ($v2 != ""){
267           if ($v1 > $v2){
268             $message[]= _("Please specify a valid HSync range.");
269           }
270         }
271       }
272     }
273     return ($message);
274   }
277   /* Save to LDAP */
278   function save()
279   {
280     plugin::save();
282     /* Strip out 'default' values */
283     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
284           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
285           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
286           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
288       if ($this->attrs[$val] == "default"){
289         $this->attrs[$val]= array();
290       }
291     }
293     /* Write back to ldap */
294     $ldap= $this->config->get_ldap_link();
295     $ldap->cd($this->dn);
296     $ldap->modify($this->attrs);
297     show_ldap_error($ldap->get_error());
298     $this->handle_post_events("modify");
299   }
303 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
304 ?>