Code

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