Code

Fixed "Undefined index: �z"
[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     $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   }
124   function check()
125   { 
126     $message = plugin::check();
127     if (empty($this->goFonAdmin)){
128       $message[]= sprintf(_("The attribute DB user is empty or contains invalid characters."), $attr);
129     }
130     if (empty($this->goFonPassword)){
131       $message[]= sprintf(_("The attribute password is empty or contains invalid characters."), $attr);
132     }
133     if (empty($this->goFonAreaCode)){
134       $message[]= sprintf(_("The attribute local dial prefix is empty or contains invalid characters."), $attr);
135     }
136     if (empty($this->goFonCountryCode)){
137       $message[]= sprintf(_("The attribute country dial prefix is empty or contains invalid characters."), $attr);
138     }
139     return($message);
140   }
141   
143   function save_object()
144   {
145     if(isset($_POST['goFonServerPosted'])){
146       plugin::save_object();
147     }
148   } 
150   
151    function action_hook($add_attrs= array())
152   {
153     /* Find postcreate entries for this class */
154     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
155     if ($command == "" && isset($this->config->data['TABS'])){
156       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
157     }
158     if ($command != ""){
159       /* Walk through attribute list */
160       foreach ($this->attributes as $attr){
161         if (!is_array($this->$attr)){
162           $command= preg_replace("/%$attr/", $this->$attr, $command);
163         }
164       }
165       $command= preg_replace("/%dn/", $this->dn, $command);
166       /* Additional attributes */
167       foreach ($add_attrs as $name => $value){
168         $command= preg_replace("/%$name/", $value, $command);
169       }
170       if (check_command($command)){
171         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
172             $command, "Execute");
174         exec($command);
175       } else {
176         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
177         print_red ($message);
178       }
179     }
180   }
181  
183 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
184 ?>