Code

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