Code

Added missing error msgs
[gosa.git] / plugins / admin / systems / class_goLogDBServer.inc
1 <?php
3 class goLogDBServer 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("goLogDBServer");
11   var $attributes       = array("goLogAdmin", "goLogPassword");
12   var $StatusFlag       = "goLogDBServerStatus";
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goLogDBServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
20   var $cn                   = "";
21   var $goLogDBServerStatus  = "";
22   var $goLogAdmin           = "";
23   var $goLogPassword        = "";  
26   function goLogDBServer($config,$dn)
27   {
28     plugin::plugin($config,$dn);
29     $this->DisplayName = _("Logging database");
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("goLogDBServer.tpl",TRUE,dirname(__FILE__))));
41   }
44   function getListEntry()
45   {
46     $this->updateStatusState();
47     $flag = $this->StatusFlag;
48     $fields['Status']     = $this->$flag;
49     $fields['Message']    = _("Logging database");
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();
63     /* Remove status flag, it is not a memeber of 
64         this->attributes, so ensure that it is deleted too */
65     if(!empty($this->StatusFlag)){
66       $this->attrs[$this->StatusFlag] = array();
67     }
69     /* Check if this is a new entry ... add/modify */
70     $ldap = $this->config->get_ldap_link();
71     $ldap->cat($this->dn,array("objectClass"));
72     if($ldap->count()){
73       $ldap->cd($this->dn);
74       $ldap->modify($this->attrs);
75     }else{
76       $ldap->cd($this->dn);
77       $ldap->add($this->attrs);
78     }
79     show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/goLogDB with dn '%s' failed."),$this->dn));
80     $this->handle_post_events("remove");
81   }
84   function save()
85   {
86     plugin::save();
87     /* Check if this is a new entry ... add/modify */
88     $ldap = $this->config->get_ldap_link();
89     $ldap->cat($this->dn,array("objectClass"));
90     if($ldap->count()){
91       $ldap->cd($this->dn);
92       $ldap->modify($this->attrs);
93     }else{
94       $ldap->cd($this->dn);
95       $ldap->add($this->attrs);
96     }
97     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/goLogDB with dn '%s' failed."),$this->dn));
98     if($this->initially_was_account){
99       $this->handle_post_events("modify");
100     }else{
101       $this->handle_post_events("add");
102     }
103   }
106   /* Directly save new status flag */
107   function setStatus($value)
108   {
109     if($value == "none") return;
110     if(!$this->initially_was_account) return;
111     $ldap = $this->config->get_ldap_link();
112     $ldap->cd($this->dn);
113     $ldap->cat($this->dn,array("objectClass"));
114     if($ldap->count()){
116       $tmp = $ldap->fetch();
117       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
118         $attrs['objectClass'][] = $tmp['objectClass'][$i];
119       }
120       $flag = $this->StatusFlag;
121       $attrs[$flag] = $value;
122       $this->$flag = $value;
123       $ldap->modify($attrs);
124       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/goLogDB with dn '%s' failed."),$this->dn));
125       $this->action_hook();
126     }
127   }
130   function check()
131   { 
132     $message = plugin::check();
133     if (empty($this->goLogAdmin)){
134       $message[]= sprintf_("The attribute user is empty or contains invalid characters.");
135     }
136     if (empty($this->goLogPassword)){
137       $message[]= sprintf_("The attribute password is empty or contains invalid characters.");
138     }
139     return($message);
140   }
143   function save_object()
144   {
145     if(isset($_POST['goLogDBServerPosted'])){
146       plugin::save_object();
147     }
148   } 
150   function action_hook($add_attrs= array())
151   {
152     /* Find postcreate entries for this class */
153     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
154     if ($command == "" && isset($this->config->data['TABS'])){
155       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
156     }
157     if ($command != ""){
158       /* Walk through attribute list */
159       foreach ($this->attributes as $attr){
160         if (!is_array($this->$attr)){
161           $command= preg_replace("/%$attr/", $this->$attr, $command);
162         }
163       }
164       $command= preg_replace("/%dn/", $this->dn, $command);
165       /* Additional attributes */
166       foreach ($add_attrs as $name => $value){
167         $command= preg_replace("/%$name/", $value, $command);
168       }
170       /* If there are still some %.. in our command, try to fill these with some other class vars */
171       if(preg_match("/%/",$command)){
172         $attrs = get_object_vars($this);
173         foreach($attrs as $name => $value){
174           if(!is_string($value)) continue;
175           $command= preg_replace("/%$name/", $value, $command);
176         }
177       }
179       if (check_command($command)){
180         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
181             $command, "Execute");
183         exec($command);
184       } else {
185         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
186         print_red ($message);
187       }
188     }
189   }
192   /* Get updates for status flag */
193   function updateStatusState()
194   {
195     if(empty($this->StatusFlag)) return;
197     $attrs = array();
198     $flag = $this->StatusFlag;
199     $ldap = $this->config->get_ldap_link();
200     $ldap->cd($this->cn);
201     $ldap->cat($this->dn,array($flag));
202     if($ldap->count()){
203       $attrs = $ldap->fetch();
204     }
205     if(isset($attrs[$flag][0])){
206       $this->$flag = $attrs[$flag][0];
207     }
208   }
209   
211 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
212 ?>