Code

Fixed "Undefined index: �z"
[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("goGlpiServerStatus","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 $acl;
21   var $goGlpiServerStatus ="";
22   var $goGlpiAdmin        ="";
23   var $goGlpiDatabase     ="";
24   var $goGlpiPassword     ="";
25  
26  
27   function goGlpiServer($config,$dn)
28   {
29     plugin::plugin($config,$dn);
30     $this->DisplayName = _("Inventory database");
31   }
34   function execute()
35   { 
36     $smarty = get_smarty(); 
37     foreach($this->attributes as $attr){
38       $smarty->assign($attr,$this->$attr);
39       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
40     }
41     return($smarty->fetch(get_template_path("goGlpiServer.tpl",TRUE,dirname(__FILE__))));
42   }
45   function getListEntry()
46   {
47     $flag = $this->StatusFlag;
48     $fields['Status']     = $this->$flag;
49     $fields['Message']    = _("Glpi management");
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();
62     /* Check if this is a new entry ... add/modify */
63     $ldap = $this->config->get_ldap_link();
64     $ldap->cat($this->dn,array("objectClass"));
65     if($ldap->count()){
66       $ldap->cd($this->dn);
67       $ldap->modify($this->attrs);
68     }else{
69       $ldap->cd($this->dn);
70       $ldap->add($this->attrs);
71     }
72     show_ldap_error($ldap->get_error());
73     $this->handle_post_events("remove");
74   }
77   function save()
78   {
79     plugin::save();
80     /* Check if this is a new entry ... add/modify */
81     $ldap = $this->config->get_ldap_link();
82     $ldap->cat($this->dn,array("objectClass"));
83     if($ldap->count()){
84       $ldap->cd($this->dn);
85       $ldap->modify($this->attrs);
86     }else{
87       $ldap->cd($this->dn);
88       $ldap->add($this->attrs);
89     }
90     show_ldap_error($ldap->get_error());
91     if($this->initially_was_account){
92       $this->handle_post_events("modify");
93     }else{
94       $this->handle_post_events("add");
95     }
96   }
99   /* Directly save new status flag */
100   function setStatus($value)
101   {
102     if($value == "none") return;
103     if(!$this->initially_was_account) return;
104     $ldap = $this->config->get_ldap_link();
105     $ldap->cd($this->dn);
106     $ldap->cat($this->dn,array("objectClass"));
107     if($ldap->count()){
109       $tmp = $ldap->fetch();
110       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
111         $attrs['objectClass'][] = $tmp['objectClass'][$i];
112       }
113       $flag = $this->StatusFlag;
114       $attrs[$flag] = $value;
115       $this->$flag = $value;
116       $ldap->modify($attrs);
117       show_ldap_error($ldap->get_error());
118       $this->action_hook();
119     }
120   }
122   
123   function check()
124   { 
125     $message = plugin::check();
126     if(empty($this->goGlpiAdmin)){
127       $message[]= _("The attribute user is empty or contains invalid characters.");
128     }
129     if(empty($this->goGlpiDatabase)){
130       $message[]= _("The attribute database is empty or contains invalid characters.");
131     }
132     return($message);
133   }
134   
136   function save_object()
137   {
138     if(isset($_POST['goLogDBServerPosted'])){
139       plugin::save_object();
140     }
141   } 
143    function action_hook($add_attrs= array())
144   {
145     /* Find postcreate entries for this class */
146     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
147     if ($command == "" && isset($this->config->data['TABS'])){
148       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
149     }
150     if ($command != ""){
151       /* Walk through attribute list */
152       foreach ($this->attributes as $attr){
153         if (!is_array($this->$attr)){
154           $command= preg_replace("/%$attr/", $this->$attr, $command);
155         }
156       }
157       $command= preg_replace("/%dn/", $this->dn, $command);
158       /* Additional attributes */
159       foreach ($add_attrs as $name => $value){
160         $command= preg_replace("/%$name/", $value, $command);
161       }
162       if (check_command($command)){
163         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
164             $command, "Execute");
166         exec($command);
167       } else {
168         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
169         print_red ($message);
170       }
171     }
172   }
173  
175 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
176 ?>