Code

Fixed save_object
[gosa.git] / plugins / admin / systems / class_goFonServer.inc
1 <?php
3 class goFonServer 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("goFonServer");
11   var $attributes       = array("goFonServerStatus","goFonAdmin", "goFonPassword","goFonAreaCode", "goFonCountryCode");
12   var $StatusFlag       = "goFonServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goFonServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
21   var $goFonServerStatus  = "";
22   var $goFonPassword      = "";
23   var $goFonAdmin         = "";
24   var $goFonAreaCode      = "";
25   var $goFonCountryCode   = "";
26    
27  
28   function goFonServer($config,$dn)
29   {
30     plugin::plugin($config,$dn);
31     $this->DisplayName = _("VoIP service");
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("goFonServer.tpl",TRUE,dirname(__FILE__))));
43   }
46   function getListEntry()
47   {
48     $flag = $this->StatusFlag;
49     $fields['Status']     = $this->$flag;
50     $fields['Message']    = _("Asterisk 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   }
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   }
94   /* Directly save new status flag */
95   function setStatus($value)
96   {
97     if($value == "none") return;
98     if(!$this->initially_was_account) return;
99     $ldap = $this->config->get_ldap_link();
100     $ldap->cd($this->dn);
101     $ldap->cat($this->dn,array("objectClass"));
102     if($ldap->count()){
104       $tmp = $ldap->fetch();
105       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
106         $attrs['objectClass'][] = $tmp['objectClass'][$i];
107       }
108       $flag = $this->StatusFlag;
109       $attrs[$flag] = $value;
110       $this->$flag = $value;
111       $ldap->modify($attrs);
112       show_ldap_error($ldap->get_error());
113       $this->action_hook();
114     }
115   }
118   function check()
119   { 
120     $message = plugin::check();
121     if (empty($this->goFonAdmin)){
122       $message[]= sprintf(_("The attribute DB user is empty or contains invalid characters."), $attr);
123     }
124     if (empty($this->goFonPassword)){
125       $message[]= sprintf(_("The attribute password is empty or contains invalid characters."), $attr);
126     }
127     if (empty($this->goFonAreaCode)){
128       $message[]= sprintf(_("The attribute local dial prefix is empty or contains invalid characters."), $attr);
129     }
130     if (empty($this->goFonCountryCode)){
131       $message[]= sprintf(_("The attribute country dial prefix is empty or contains invalid characters."), $attr);
132     }
133     return($message);
134   }
135   
137   function save_object()
138   {
139     if(isset($_POST['goFonServerPosted'])){
140       plugin::save_object();
141     }
142   } 
144   
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       }
164       if (check_command($command)){
165         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
166             $command, "Execute");
168         exec($command);
169       } else {
170         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
171         print_red ($message);
172       }
173     }
174   }
175  
177 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
178 ?>