Code

fixed problem with klicking apply more than once
[gosa.git] / plugins / admin / systems / class_goFaxServer.inc
1 <?php
3 class goFaxServer extends plugin{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports fax informations.";
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("goFaxServer");
11   var $attributes       = array("goFaxAdmin", "goFaxPassword");
12   var $StatusFlag       = "goFaxServerStatus";
13  
14   /* This class can't be assigned twice so it conflicts with itsself */
15   var $conflicts        = array("goFaxServer");
17   var $DisplayName      = "";
18   var $dn               = NULL;
19   var $acl;
21   var $goFaxAdmin         = "";
22   var $goFaxPassword      = "";
23   var $goFaxServerStatus  = "";
24   var $cn                 = "";
25  
26   function goFaxServer($config,$dn)
27   {
28     plugin::plugin($config,$dn);
29     $this->DisplayName = _("FAX service");
30   }
33   function execute()
34   { 
35     $smarty = get_smarty(); 
36     foreach($this->attributes as $attr){
37       $smarty->assign($attr,$this->$attr);
38       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
39     }
40     return($smarty->fetch(get_template_path("goFaxServer.tpl",TRUE,dirname(__FILE__))));
41   }
44   function getListEntry()
45   {
46     $this->updateStatusState();
47     $flag = $this->StatusFlag;
48     $fields['Status']      = $this->$flag;
49     $fields['Message']    = _("FAX database configuration");
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();
63     /* Remove status flag, it is not a memeber of 
64         this->attributes, so ensure that it is deleted too */
65     if(!empty($this->StatusFlag)){
66       $this->attrs[$this->StatusFlag] = array();
67     }
69     /* Check if this is a new entry ... add/modify */
70     $ldap = $this->config->get_ldap_link();
71     $ldap->cat($this->dn,array("objectClass"));
72     if($ldap->count()){
73       $ldap->cd($this->dn);
74       $ldap->modify($this->attrs);
75     }else{
76       $ldap->cd($this->dn);
77       $ldap->add($this->attrs);
78     }
79     show_ldap_error($ldap->get_error(), sprintf(_("Removing server services/gofax with dn '%s' failed."),$this->dn));
80     $this->handle_post_events("remove");
81   }
84   function save()
85   {
86     plugin::save();
87     /* Check if this is a new entry ... add/modify */
88     $ldap = $this->config->get_ldap_link();
89     $ldap->cat($this->dn,array("objectClass"));
90     if($ldap->count()){
91       $ldap->cd($this->dn);
92       $ldap->modify($this->attrs);
93     }else{
94       $ldap->cd($this->dn);
95       $ldap->add($this->attrs);
96     }
97     if($this->initially_was_account){
98       $this->handle_post_events("modify");
99     }else{
100       $this->handle_post_events("add");
101     }
102     show_ldap_error($ldap->get_error(), sprintf(_("Saving server services/gofax with dn '%s' failed."),$this->dn));
103   }
106   /* Directly save new status flag */
107   function setStatus($value)
108   {
109     if($value == "none") return;
110     if(!$this->initially_was_account) return;
111     $ldap = $this->config->get_ldap_link();
112     $ldap->cd($this->dn);
113     $ldap->cat($this->dn,array("objectClass"));
114     if($ldap->count()){
116       $tmp = $ldap->fetch();
117       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
118         $attrs['objectClass'][] = $tmp['objectClass'][$i];
119       }
120       $flag = $this->StatusFlag;
121       $attrs[$flag] = $value;
122       $this->$flag = $value;
123       $ldap->modify($attrs);
125       show_ldap_error($ldap->get_error(), sprintf(_("Set status flag for server services/gofax with dn '%s' failed."),$this->dn));
126       $this->action_hook();
127     }
128   }
130   
131   function check()
132   { 
133     $message = plugin::check();
134     if (empty($this->goFaxAdmin)){
135       $message[]= _("The attribute user is empty or contains invalid characters.");
136     }
137     if (empty($this->goFaxPassword)){
138       $message[]= _("The attribute password is empty or contains invalid characters.");
139     }
140     return($message);
141   }
142   
144   function save_object()
145   {
146     if(isset($_POST['goFaxServerPosted'])){
147       plugin::save_object();
148     }
149   } 
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       }
171       /* If there are still some %.. in our command, try to fill these with some other class vars */
172       if(preg_match("/%/",$command)){
173         $attrs = get_object_vars($this);
174         foreach($attrs as $name => $value){
175           if(!is_string($value)) continue;
176           $command= preg_replace("/%$name/", $value, $command);
177         }
178       }
180       if (check_command($command)){
181         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
182             $command, "Execute");
184         exec($command);
185       } else {
186         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
187         print_red ($message);
188       }
189     }
190   }
192   /* Get updates for status flag */
193   function updateStatusState()
194   {
195     if(empty($this->StatusFlag)) return;
197     $attrs = array();
198     $flag = $this->StatusFlag;
199     $ldap = $this->config->get_ldap_link();
200     $ldap->cd($this->cn);
201     $ldap->cat($this->dn,array($flag));
202     if($ldap->count()){
203       $attrs = $ldap->fetch();
204     }
205     if(isset($attrs[$flag][0])){
206       $this->$flag = $attrs[$flag][0];
207     }
208   }
211   /* Return plugin informations for acl handling */
212   function plInfo()
213   {
214     return (array(
215           "plShortName"   => _("Fax server"),
216           "plDescription" => _("Fax server service"),
217           "plSelfModify"  => FALSE,
218           "plDepends"     => array(),
219           "plPriority"    => 0,
220           "plSection"     => array("administration"),
221           "plCategory"    => array("server"),
223           "plProvidedAcls"=> array(
224              "goFaxAdmin"     => _("Login name"),
225              "goFaxPassword"  => _("Password"))
226           ));
227   }
229 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
230 ?>