Code

Added posts to service tabs
[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("goFaxServerStatus","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  
25   function goFaxServer($config,$dn)
26   {
27     plugin::plugin($config,$dn);
28     $this->DisplayName = _("FAX service");
29   }
32   function execute()
33   { 
34     $smarty = get_smarty(); 
35     foreach($this->attributes as $attr){
36       $smarty->assign($attr,$this->$attr);
37       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));
38     }
39     return($smarty->fetch(get_template_path("goFaxServer.tpl",TRUE,dirname(__FILE__))));
40   }
43   function getListEntry()
44   {
45     $flag = $this->StatusFlag;
46     $fields['Status']      = $this->$flag;
47     $fields['Message']    = _("FAX database configuration");
48     $fields['AllowStart'] = true;
49     $fields['AllowStop']  = true;
50     $fields['AllowRestart'] = true;
51     $fields['AllowRemove']= true;
52     $fields['AllowEdit']  = true;
53     return($fields);
54   }
57   function remove_from_parent()
58   {
59     plugin::remove_from_parent();
60     /* Check if this is a new entry ... add/modify */
61     $ldap = $this->config->get_ldap_link();
62     $ldap->cat($this->dn,array("objectClass"));
63     if($ldap->count()){
64       $ldap->cd($this->dn);
65       $ldap->modify($this->attrs);
66     }else{
67       $ldap->cd($this->dn);
68       $ldap->add($this->attrs);
69     }
70     show_ldap_error($ldap->get_error());
71     $this->handle_post_events("remove");
72   }
75   function save()
76   {
77     plugin::save();
78     /* Check if this is a new entry ... add/modify */
79     $ldap = $this->config->get_ldap_link();
80     $ldap->cat($this->dn,array("objectClass"));
81     if($ldap->count()){
82       $ldap->cd($this->dn);
83       $ldap->modify($this->attrs);
84     }else{
85       $ldap->cd($this->dn);
86       $ldap->add($this->attrs);
87     }
88     if($this->initially_was_account){
89       $this->handle_post_events("modify");
90     }else{
91       $this->handle_post_events("add");
92     }
93     show_ldap_error($ldap->get_error());
94   }
97   /* Directly save new status flag */
98   function setStatus($value)
99   {
100     if($value == "none") return;
101     if(!$this->initially_was_account) return;
102     $ldap = $this->config->get_ldap_link();
103     $ldap->cd($this->dn);
104     $ldap->cat($this->dn,array("objectClass"));
105     if($ldap->count()){
107       $tmp = $ldap->fetch();
108       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
109         $attrs['objectClass'][] = $tmp['objectClass'][$i];
110       }
111       $flag = $this->StatusFlag;
112       $attrs[$flag] = $value;
113       $this->$flag = $value;
114       $ldap->modify($attrs);
115       show_ldap_error($ldap->get_error());
116       $this->action_hook();
117     }
118   }
120   
121   function check()
122   { 
123     $message = plugin::check();
124     if (empty($this->goFaxAdmin)){
125       $message[]= _("The attribute user is empty or contains invalid characters.");
126     }
127     if (empty($this->goFaxPassword)){
128       $message[]= _("The attribute password is empty or contains invalid characters.");
129     }
130     return($message);
131   }
132   
134   function save_object()
135   {
136     if(isset($_POST['goFaxServerPosted'])){
137       plugin::save_object();
138     }
139   } 
141    function action_hook($add_attrs= array())
142   {
143     /* Find postcreate entries for this class */
144     $command= search_config($this->config->data['MENU'], get_class($this), "ACTION_HOOK");
145     if ($command == "" && isset($this->config->data['TABS'])){
146       $command= search_config($this->config->data['TABS'], get_class($this), "ACTION_HOOK");
147     }
148     if ($command != ""){
149       /* Walk through attribute list */
150       foreach ($this->attributes as $attr){
151         if (!is_array($this->$attr)){
152           $command= preg_replace("/%$attr/", $this->$attr, $command);
153         }
154       }
155       $command= preg_replace("/%dn/", $this->dn, $command);
156       /* Additional attributes */
157       foreach ($add_attrs as $name => $value){
158         $command= preg_replace("/%$name/", $value, $command);
159       }
160       if (check_command($command)){
161         @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
162             $command, "Execute");
164         exec($command);
165       } else {
166         $message= sprintf(_("Command '%s', specified as ACTION_HOOK for plugin '%s' doesn't seem to exist."), $command, get_class($this));
167         print_red ($message);
168       }
169     }
170   }
171  
173 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
174 ?>