Code

Added action hook
[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("goTerminalServerStatus","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;
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     $flag = $this->StatusFlag;
47     $fields['Status']     = $this->$flag;
48     $fields['Message']    = _("Terminal service");
49     $fields['AllowStart'] = true;
50     $fields['AllowStop']  = true;
51     $fields['AllowRestart'] = true;
52     $fields['AllowRemove']= true;
53     $fields['AllowEdit']  = true;
54     return($fields);
55   }
58   function remove_from_parent()
59   {
60     plugin::remove_from_parent();
61     /* Check if this is a new entry ... add/modify */
62     $ldap = $this->config->get_ldap_link();
63     $ldap->cat($this->dn,array("objectClass"));
64     if($ldap->count()){
65       $ldap->cd($this->dn);
66       $ldap->modify($this->attrs);
67     }else{
68       $ldap->cd($this->dn);
69       $ldap->add($this->attrs);
70     }
71     show_ldap_error($ldap->get_error());
72   }
75   function save()
76   {
77     plugin::save();
79     if(!$this->goXdmcpIsEnabled){
80       $this->attrs['goXdmcpIsEnabled'] = "0";
81     }
83     /* Check if this is a new entry ... add/modify */
84     $ldap = $this->config->get_ldap_link();
85     $ldap->cat($this->dn,array("objectClass"));
86     if($ldap->count()){
87       $ldap->cd($this->dn);
88       $ldap->modify($this->attrs);
89     }else{
90       $ldap->cd($this->dn);
91       $ldap->add($this->attrs);
92     }
93     show_ldap_error($ldap->get_error());
94   }
97   /* Directly save new status flag */
98   function setStatus($value)
99   {
100     if($value == "none") return;
101     if(!$this->initially_was_account) return;
102     $ldap = $this->config->get_ldap_link();
103     $ldap->cd($this->dn);
104     $ldap->cat($this->dn,array("objectClass"));
105     if($ldap->count()){
107       $tmp = $ldap->fetch();
108       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
109         $attrs['objectClass'][] = $tmp['objectClass'][$i];
110       }
111       $flag = $this->StatusFlag;
112       $attrs[$flag] = $value;
113       $this->$flag = $value;
114       $ldap->modify($attrs);
115       show_ldap_error($ldap->get_error());
116       $this->action_hook();
117     }
118   }
121   function check()
122   { 
123     $message = plugin::check();
124     if(empty($this->goFontPath)){
125       $message[]=_("Terminal server, must have fontpath specified.");
126     }
128     return($message);
129   }
132   function save_object()
133   {
134     if(isset($_POST['goTerminalServerPosted'])){
135       plugin::save_object();
136       if(isset($_POST['goXdmcpIsEnabled'])){
137         $this->goXdmcpIsEnabled = true;
138       }else{
139         $this->goXdmcpIsEnabled = false;
140       }
141     }
142   } 
144   function action_hook($add_attrs= array())
145   {
146     /* Find postcreate entries for this class */
147     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
148     if ($command == "" && isset($this->config->data['TABS'])){
149       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
150     }
151     if ($command != ""){
152       /* Walk through attribute list */
153       foreach ($this->attributes as $attr){
154         if (!is_array($this->$attr)){
155           $command= preg_replace("/%$attr/", $this->$attr, $command);
156         }
157       }
158       $command= preg_replace("/%dn/", $this->dn, $command);
159       /* Additional attributes */
160       foreach ($add_attrs as $name => $value){
161         $command= preg_replace("/%$name/", $value, $command);
162       }
163       if (check_command($command)){
164         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
165             $command, "Execute");
167         exec($command);
168       } else {
169         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
170         print_red ($message);
171       }
172     }
173   }
176 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
177 ?>