Code

Added title tag
[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 $cn               ="";
20   var $acl;
22   var $goFonServerStatus  = "";
23   var $goFonPassword      = "";
24   var $goFonAdmin         = "";
25   var $goFonAreaCode      = "";
26   var $goFonCountryCode   = "";
27    
28  
29   function goFonServer($config,$dn)
30   {
31     plugin::plugin($config,$dn);
32     $this->DisplayName = _("VoIP service");
33   }
36   function execute()
37   { 
38     $smarty = get_smarty(); 
39     foreach($this->attributes as $attr){
40       $smarty->assign($attr,$this->$attr);
41       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
42     }
43     return($smarty->fetch(get_template_path("goFonServer.tpl",TRUE,dirname(__FILE__))));
44   }
47   function getListEntry()
48   {
49     $flag = $this->StatusFlag;
50     $fields['Status']     = $this->$flag;
51     $fields['Message']    = _("Asterisk management");
52     $fields['AllowStart'] = true;
53     $fields['AllowStop']  = true;
54     $fields['AllowRestart'] = true;
55     $fields['AllowRemove']= true;
56     $fields['AllowEdit']  = true;
57     return($fields);
58   }
61   function remove_from_parent()
62   {
63     plugin::remove_from_parent();
64     /* Check if this is a new entry ... add/modify */
65     $ldap = $this->config->get_ldap_link();
66     $ldap->cat($this->dn,array("objectClass"));
67     if($ldap->count()){
68       $ldap->cd($this->dn);
69       $ldap->modify($this->attrs);
70     }else{
71       $ldap->cd($this->dn);
72       $ldap->add($this->attrs);
73     }
74     show_ldap_error($ldap->get_error());
75     $this->handle_post_events("remove");
76   }
79   function save()
80   {
81     plugin::save();
82     /* Check if this is a new entry ... add/modify */
83     $ldap = $this->config->get_ldap_link();
84     $ldap->cat($this->dn,array("objectClass"));
85     if($ldap->count()){
86       $ldap->cd($this->dn);
87       $ldap->modify($this->attrs);
88     }else{
89       $ldap->cd($this->dn);
90       $ldap->add($this->attrs);
91     }
92     show_ldap_error($ldap->get_error());
93     if($this->initially_was_account){
94       $this->handle_post_events("modify");
95     }else{
96       $this->handle_post_events("add");
97     }
98   }
101   /* Directly save new status flag */
102   function setStatus($value)
103   {
104     if($value == "none") return;
105     if(!$this->initially_was_account) return;
106     $ldap = $this->config->get_ldap_link();
107     $ldap->cd($this->dn);
108     $ldap->cat($this->dn,array("objectClass"));
109     if($ldap->count()){
111       $tmp = $ldap->fetch();
112       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
113         $attrs['objectClass'][] = $tmp['objectClass'][$i];
114       }
115       $flag = $this->StatusFlag;
116       $attrs[$flag] = $value;
117       $this->$flag = $value;
118       $ldap->modify($attrs);
119       show_ldap_error($ldap->get_error());
120       $this->action_hook();
121     }
122   }
125   function check()
126   { 
127     $message = plugin::check();
128     if (empty($this->goFonAdmin)){
129       $message[]= sprintf(_("The attribute DB user is empty or contains invalid characters."), $attr);
130     }
131     if (empty($this->goFonPassword)){
132       $message[]= sprintf(_("The attribute password is empty or contains invalid characters."), $attr);
133     }
134     if (empty($this->goFonAreaCode)){
135       $message[]= sprintf(_("The attribute local dial prefix is empty or contains invalid characters."), $attr);
136     }
137     if (empty($this->goFonCountryCode)){
138       $message[]= sprintf(_("The attribute country dial prefix is empty or contains invalid characters."), $attr);
139     }
140     return($message);
141   }
142   
144   function save_object()
145   {
146     if(isset($_POST['goFonServerPosted'])){
147       plugin::save_object();
148     }
149   } 
151   
152    function action_hook($add_attrs= array())
153   {
154     /* Find postcreate entries for this class */
155     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
156     if ($command == "" && isset($this->config->data['TABS'])){
157       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
158     }
159     if ($command != ""){
160       /* Walk through attribute list */
161       foreach ($this->attributes as $attr){
162         if (!is_array($this->$attr)){
163           $command= preg_replace("/%$attr/", $this->$attr, $command);
164         }
165       }
166       $command= preg_replace("/%dn/", $this->dn, $command);
167       /* Additional attributes */
168       foreach ($add_attrs as $name => $value){
169         $command= preg_replace("/%$name/", $value, $command);
170       }
172       /* If there are still some %.. in our command, try to fill these with some other class vars */
173       if(preg_match("/%/",$command)){
174         $attrs = get_object_vars($this);
175         foreach($attrs as $name => $value){
176           if(!is_string($value)) continue;
177           $command= preg_replace("/%$name/", $value, $command);
178         }
179       }
181       if (check_command($command)){
182         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
183             $command, "Execute");
185         exec($command);
186       } else {
187         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
188         print_red ($message);
189       }
190     }
191   }
192  
194 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
195 ?>