Code

Fixed Translation Strings.
[gosa.git] / plugins / admin / systems / class_goGlpiServer.inc
1 <?php
3 class goGlpiServer 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("goGlpiServer");
11   var $attributes       = array("goGlpiAdmin","goGlpiDatabase","goGlpiPassword");
12   var $StatusFlag       = "goGlpiServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goGlpiServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $cn               = "";
20   var $acl;
22   var $goGlpiServerStatus ="";
23   var $goGlpiAdmin        ="";
24   var $goGlpiDatabase     ="";
25   var $goGlpiPassword     ="";
26  
27  
28   function goGlpiServer($config,$dn)
29   {
30     plugin::plugin($config,$dn);
31     $this->DisplayName = _("Inventory database");
32   }
35   function execute()
36   { 
37     $smarty = get_smarty(); 
38     foreach($this->attributes as $attr){
39       $smarty->assign($attr,$this->$attr);
40       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
41     }
42     return($smarty->fetch(get_template_path("goGlpiServer.tpl",TRUE,dirname(__FILE__))));
43   }
46   function getListEntry()
47   {
48     $this->updateStatusState();
49     $flag = $this->StatusFlag;
50     $fields['Status']     = $this->$flag;
51     $fields['Message']    = _("Glpi management");
52     $fields['AllowStart'] = true;
53     $fields['AllowStop']  = true;
54     $fields['AllowRestart'] = true;
55     $fields['AllowRemove']= true;
56     $fields['AllowEdit']  = true;
57     return($fields);
58   }
61   function remove_from_parent()
62   {
63     plugin::remove_from_parent();
64     /* Check if this is a new entry ... add/modify */
65     $ldap = $this->config->get_ldap_link();
66     $ldap->cat($this->dn,array("objectClass"));
67     if($ldap->count()){
68       $ldap->cd($this->dn);
69       $ldap->modify($this->attrs);
70     }else{
71       $ldap->cd($this->dn);
72       $ldap->add($this->attrs);
73     }
74     show_ldap_error($ldap->get_error());
75     $this->handle_post_events("remove");
76   }
79   function save()
80   {
81     plugin::save();
82     /* Check if this is a new entry ... add/modify */
83     $ldap = $this->config->get_ldap_link();
84     $ldap->cat($this->dn,array("objectClass"));
85     if($ldap->count()){
86       $ldap->cd($this->dn);
87       $ldap->modify($this->attrs);
88     }else{
89       $ldap->cd($this->dn);
90       $ldap->add($this->attrs);
91     }
92     show_ldap_error($ldap->get_error());
93     if($this->initially_was_account){
94       $this->handle_post_events("modify");
95     }else{
96       $this->handle_post_events("add");
97     }
98   }
101   /* Directly save new status flag */
102   function setStatus($value)
103   {
104     if($value == "none") return;
105     if(!$this->initially_was_account) return;
106     $ldap = $this->config->get_ldap_link();
107     $ldap->cd($this->dn);
108     $ldap->cat($this->dn,array("objectClass"));
109     if($ldap->count()){
111       $tmp = $ldap->fetch();
112       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
113         $attrs['objectClass'][] = $tmp['objectClass'][$i];
114       }
115       $flag = $this->StatusFlag;
116       $attrs[$flag] = $value;
117       $this->$flag = $value;
118       $ldap->modify($attrs);
119       show_ldap_error($ldap->get_error());
120       $this->action_hook();
121     }
122   }
124   
125   function check()
126   { 
127     $message = plugin::check();
128     if(empty($this->goGlpiAdmin)){
129       $message[]= _("The attribute user is empty or contains invalid characters.");
130     }
131     if(empty($this->goGlpiDatabase)){
132       $message[]= _("The attribute database is empty or contains invalid characters.");
133     }
134     return($message);
135   }
136   
138   function save_object()
139   {
140     if(isset($_POST['goLogDBServerPosted'])){
141       plugin::save_object();
142     }
143   } 
145    function action_hook($add_attrs= array())
146   {
147     /* Find postcreate entries for this class */
148     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
149     if ($command == "" && isset($this->config->data['TABS'])){
150       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
151     }
152     if ($command != ""){
153       /* Walk through attribute list */
154       foreach ($this->attributes as $attr){
155         if (!is_array($this->$attr)){
156           $command= preg_replace("/%$attr/", $this->$attr, $command);
157         }
158       }
159       $command= preg_replace("/%dn/", $this->dn, $command);
160       /* Additional attributes */
161       foreach ($add_attrs as $name => $value){
162         $command= preg_replace("/%$name/", $value, $command);
163       }
165       /* If there are still some %.. in our command, try to fill these with some other class vars */
166       if(preg_match("/%/",$command)){
167         $attrs = get_object_vars($this);
168         foreach($attrs as $name => $value){
169           if(!is_string($value)) continue;
170           $command= preg_replace("/%$name/", $value, $command);
171         }
172       }
174       if (check_command($command)){
175         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
176             $command, "Execute");
178         exec($command);
179       } else {
180         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
181         print_red ($message);
182       }
183     }
184   }
187   /* Get updates for status flag */
188   function updateStatusState()
189   {
190     if(empty($this->StatusFlag)) return;
192     $attrs = array();
193     $flag = $this->StatusFlag;
194     $ldap = $this->config->get_ldap_link();
195     $ldap->cd($this->cn);
196     $ldap->cat($this->dn,array($flag));
197     if($ldap->count()){
198       $attrs = $ldap->fetch();
199     }
200     if(isset($attrs[$flag][0])){
201       $this->$flag = $attrs[$flag][0];
202     }
203   }
204  
206 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
207 ?>