Code

Fixed save_object
[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("goLogDBServerStatus","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;
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     $flag = $this->StatusFlag;
47     $fields['Status']     = $this->$flag;
48     $fields['Message']    = _("Logging database");
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();
78     /* Check if this is a new entry ... add/modify */
79     $ldap = $this->config->get_ldap_link();
80     $ldap->cat($this->dn,array("objectClass"));
81     if($ldap->count()){
82       $ldap->cd($this->dn);
83       $ldap->modify($this->attrs);
84     }else{
85       $ldap->cd($this->dn);
86       $ldap->add($this->attrs);
87     }
88     show_ldap_error($ldap->get_error());
89   }
92   /* Directly save new status flag */
93   function setStatus($value)
94   {
95     if($value == "none") return;
96     if(!$this->initially_was_account) return;
97     $ldap = $this->config->get_ldap_link();
98     $ldap->cd($this->dn);
99     $ldap->cat($this->dn,array("objectClass"));
100     if($ldap->count()){
102       $tmp = $ldap->fetch();
103       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
104         $attrs['objectClass'][] = $tmp['objectClass'][$i];
105       }
106       $flag = $this->StatusFlag;
107       $attrs[$flag] = $value;
108       $this->$flag = $value;
109       $ldap->modify($attrs);
110       show_ldap_error($ldap->get_error());
111       $this->action_hook();
112     }
113   }
116   function check()
117   { 
118     $message = plugin::check();
119     if (empty($this->goLogAdmin)){
120       $message[]= sprintf_("The attribute user is empty or contains invalid characters.");
121     }
122     if (empty($this->goLogPassword)){
123       $message[]= sprintf_("The attribute password is empty or contains invalid characters.");
124     }
125     return($message);
126   }
129   function save_object()
130   {
131     if(isset($_POST['goLogDBServerPosted'])){
132       plugin::save_object();
133     }
134   } 
136   function action_hook($add_attrs= array())
137   {
138     /* Find postcreate entries for this class */
139     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
140     if ($command == "" && isset($this->config->data['TABS'])){
141       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
142     }
143     if ($command != ""){
144       /* Walk through attribute list */
145       foreach ($this->attributes as $attr){
146         if (!is_array($this->$attr)){
147           $command= preg_replace("/%$attr/", $this->$attr, $command);
148         }
149       }
150       $command= preg_replace("/%dn/", $this->dn, $command);
151       /* Additional attributes */
152       foreach ($add_attrs as $name => $value){
153         $command= preg_replace("/%$name/", $value, $command);
154       }
155       if (check_command($command)){
156         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
157             $command, "Execute");
159         exec($command);
160       } else {
161         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
162         print_red ($message);
163       }
164     }
165   }
168 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
169 ?>