Code

9129d1411c096aacbe062399d27992079eb314ec
[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     $flag = $this->StatusFlag;
49     $fields['Status']     = $this->$flag;
50     $fields['Message']    = _("Glpi management");
51     $fields['AllowStart'] = true;
52     $fields['AllowStop']  = true;
53     $fields['AllowRestart'] = true;
54     $fields['AllowRemove']= true;
55     $fields['AllowEdit']  = true;
56     return($fields);
57   }
60   function remove_from_parent()
61   {
62     plugin::remove_from_parent();
63     /* Check if this is a new entry ... add/modify */
64     $ldap = $this->config->get_ldap_link();
65     $ldap->cat($this->dn,array("objectClass"));
66     if($ldap->count()){
67       $ldap->cd($this->dn);
68       $ldap->modify($this->attrs);
69     }else{
70       $ldap->cd($this->dn);
71       $ldap->add($this->attrs);
72     }
73     show_ldap_error($ldap->get_error());
74     $this->handle_post_events("remove");
75   }
78   function save()
79   {
80     plugin::save();
81     /* Check if this is a new entry ... add/modify */
82     $ldap = $this->config->get_ldap_link();
83     $ldap->cat($this->dn,array("objectClass"));
84     if($ldap->count()){
85       $ldap->cd($this->dn);
86       $ldap->modify($this->attrs);
87     }else{
88       $ldap->cd($this->dn);
89       $ldap->add($this->attrs);
90     }
91     show_ldap_error($ldap->get_error());
92     if($this->initially_was_account){
93       $this->handle_post_events("modify");
94     }else{
95       $this->handle_post_events("add");
96     }
97   }
100   /* Directly save new status flag */
101   function setStatus($value)
102   {
103     if($value == "none") return;
104     if(!$this->initially_was_account) return;
105     $ldap = $this->config->get_ldap_link();
106     $ldap->cd($this->dn);
107     $ldap->cat($this->dn,array("objectClass"));
108     if($ldap->count()){
110       $tmp = $ldap->fetch();
111       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
112         $attrs['objectClass'][] = $tmp['objectClass'][$i];
113       }
114       $flag = $this->StatusFlag;
115       $attrs[$flag] = $value;
116       $this->$flag = $value;
117       $ldap->modify($attrs);
118       show_ldap_error($ldap->get_error());
119       $this->action_hook();
120     }
121   }
123   
124   function check()
125   { 
126     $message = plugin::check();
127     if(empty($this->goGlpiAdmin)){
128       $message[]= _("The attribute user is empty or contains invalid characters.");
129     }
130     if(empty($this->goGlpiDatabase)){
131       $message[]= _("The attribute database is empty or contains invalid characters.");
132     }
133     return($message);
134   }
135   
137   function save_object()
138   {
139     if(isset($_POST['goLogDBServerPosted'])){
140       plugin::save_object();
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       }
164       /* If there are still some %.. in our command, try to fill these with some other class vars */
165       if(preg_match("/%/",$command)){
166         $attrs = get_object_vars($this);
167         foreach($attrs as $name => $value){
168           if(!is_string($value)) continue;
169           $command= preg_replace("/%$name/", $value, $command);
170         }
171       }
173       if (check_command($command)){
174         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
175             $command, "Execute");
177         exec($command);
178       } else {
179         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
180         print_red ($message);
181       }
182     }
183   }
184  
186 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
187 ?>