Code

Fixed Translation Strings.
[gosa.git] / plugins / admin / systems / class_goTerminalServer.inc
1 <?php
3 class goTerminalServer extends plugin{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports asterisk management.";
6   var $cli_description  = "Some longer text\nfor help";
7   var $cli_parameters   = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
9   /* This plugin only writes its objectClass */
10   var $objectclasses    = array("goTerminalServer");
11   var $attributes       = array("goXdmcpIsEnabled", "goFontPath");
12   var $StatusFlag       = "goTerminalServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goTerminalServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
20   var $cn                      = "";
21   var $goTerminalServerStatus  = "";
22   var $goXdmcpIsEnabled        = false;  
23   var $goFontPath              = "";
26   function goTerminalServer($config,$dn)
27   {
28     plugin::plugin($config,$dn);
29     $this->DisplayName = _("Terminal service");
30   }
33   function execute()
34   { 
35     $smarty = get_smarty(); 
36     foreach($this->attributes as $attr){
37       $smarty->assign($attr,$this->$attr);
38       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
39     }
40     return($smarty->fetch(get_template_path("goTerminalServer.tpl",TRUE,dirname(__FILE__))));
41   }
44   function getListEntry()
45   {
46     $this->updateStatusState();
47     $flag = $this->StatusFlag;
48     $fields['Status']     = $this->$flag;
49     $fields['Message']    = _("Terminal service");
50     $fields['AllowStart'] = true;
51     $fields['AllowStop']  = true;
52     $fields['AllowRestart'] = true;
53     $fields['AllowRemove']= true;
54     $fields['AllowEdit']  = true;
55     return($fields);
56   }
59   function remove_from_parent()
60   {
61     plugin::remove_from_parent();
62     /* Check if this is a new entry ... add/modify */
63     $ldap = $this->config->get_ldap_link();
64     $ldap->cat($this->dn,array("objectClass"));
65     if($ldap->count()){
66       $ldap->cd($this->dn);
67       $ldap->modify($this->attrs);
68     }else{
69       $ldap->cd($this->dn);
70       $ldap->add($this->attrs);
71     }
72     show_ldap_error($ldap->get_error());
73     $this->handle_post_events("remove");
74   }
77   function save()
78   {
79     plugin::save();
81     if(!$this->goXdmcpIsEnabled){
82       $this->attrs['goXdmcpIsEnabled'] = "0";
83     }
85     /* Check if this is a new entry ... add/modify */
86     $ldap = $this->config->get_ldap_link();
87     $ldap->cat($this->dn,array("objectClass"));
88     if($ldap->count()){
89       $ldap->cd($this->dn);
90       $ldap->modify($this->attrs);
91     }else{
92       $ldap->cd($this->dn);
93       $ldap->add($this->attrs);
94     }
95     show_ldap_error($ldap->get_error());
96     if($this->initially_was_account){
97       $this->handle_post_events("modify");
98     }else{
99       $this->handle_post_events("add");
100     }
101   }
104   /* Directly save new status flag */
105   function setStatus($value)
106   {
107     if($value == "none") return;
108     if(!$this->initially_was_account) return;
109     $ldap = $this->config->get_ldap_link();
110     $ldap->cd($this->dn);
111     $ldap->cat($this->dn,array("objectClass"));
112     if($ldap->count()){
114       $tmp = $ldap->fetch();
115       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
116         $attrs['objectClass'][] = $tmp['objectClass'][$i];
117       }
118       $flag = $this->StatusFlag;
119       $attrs[$flag] = $value;
120       $this->$flag = $value;
121       $ldap->modify($attrs);
122       show_ldap_error($ldap->get_error());
123       $this->action_hook();
124     }
125   }
128   function check()
129   { 
130     $message = plugin::check();
131     if(empty($this->goFontPath)){
132       $message[]=_("Terminal server, must have fontpath specified.");
133     }
135     return($message);
136   }
139   function save_object()
140   {
141     if(isset($_POST['goTerminalServerPosted'])){
142       plugin::save_object();
143       if(isset($_POST['goXdmcpIsEnabled'])){
144         $this->goXdmcpIsEnabled = true;
145       }else{
146         $this->goXdmcpIsEnabled = false;
147       }
148     }
149   } 
151   function action_hook($add_attrs= array())
152   {
153     /* Find postcreate entries for this class */
154     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
155     if ($command == "" && isset($this->config->data['TABS'])){
156       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
157     }
158     if ($command != ""){
159       /* Walk through attribute list */
160       foreach ($this->attributes as $attr){
161         if (!is_array($this->$attr)){
162           $command= preg_replace("/%$attr/", $this->$attr, $command);
163         }
164       }
165       $command= preg_replace("/%dn/", $this->dn, $command);
166       /* Additional attributes */
167       foreach ($add_attrs as $name => $value){
168         $command= preg_replace("/%$name/", $value, $command);
169       }
171       /* If there are still some %.. in our command, try to fill these with some other class vars */
172       if(preg_match("/%/",$command)){
173         $attrs = get_object_vars($this);
174         foreach($attrs as $name => $value){
175           if(!is_string($value)) continue;
176           $command= preg_replace("/%$name/", $value, $command);
177         }
178       }
180       if (check_command($command)){
181         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
182             $command, "Execute");
184         exec($command);
185       } else {
186         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
187         print_red ($message);
188       }
189     }
190   }
193   /* Get updates for status flag */
194   function updateStatusState()
195   {
196     if(empty($this->StatusFlag)) return;
198     $attrs = array();
199     $flag = $this->StatusFlag;
200     $ldap = $this->config->get_ldap_link();
201     $ldap->cd($this->cn);
202     $ldap->cat($this->dn,array($flag));
203     if($ldap->count()){
204       $attrs = $ldap->fetch();
205     }
206     if(isset($attrs[$flag][0])){
207       $this->$flag = $attrs[$flag][0];
208     }
209   }
212 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
213 ?>