Code

The setStatus function expects that the service was already saved.
[gosa.git] / plugins / admin / systems / class_goImapServer.inc
1 <?php
3 class goImapServer extends plugin{
4         
5   var $cli_summary      = "This pluign is used within the ServerService Pluign \nand indicates that this server supports mailqueue listings and so on.";
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("goImapServer");
11   
12   /* This class can't be assigned twice so it conflicts with itsself */
13   var $conflicts        = array("goImapServer");
15   var $DisplayName      = "";
16   var $dn               = NULL;
17   var $StatusFlag       = "goImapServerStatus";
18   var $attributes       = array("goImapServerStatus",
19                                 "goImapName","goImapConnect","goImapAdmin","goImapPassword",
20                                 "goImapSieveServer","goImapSievePort",
21                                 "cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL");
23   var $cn;
25   var $goImapName           = "";
26   var $goImapConnect        = "";
27   var $goImapAdmin          = "";
28   var $goImapPassword       = "";
29   
30   var $goImapSieveServer    = "";
31   var $goImapSievePort      = "";
32   
33   var $goImapServerStatus   = "";
34   
35   var $cyrusImap            = false;
36   var $cyrusImapSSL         = false;
37   var $cyrusPop3            = false;
38   var $cyrusPop3SSL         = false;
39   var $is_account           = false;
41   var $acl; 
43   var $Actions              = array();
44  
45   function goImapServer($config,$dn)
46   {
47     plugin::plugin($config,$dn);
48   
49     $this->DisplayName = _("IMAP/POP3 service");
51     $this->Actions = array( SERVICE_STOPPED=>SERVICE_STOPPED,
52                             SERVICE_STARTED => SERVICE_STARTED,
53                             SERVICE_RESTARTED=>SERVICE_RESTARTED,
54                             "repair_database"=>_("Repair database"));
55     
56   }
58   function execute()
59   { 
60     $smarty = get_smarty();
61   
62     /* set new status */
63     if(isset($_POST['ExecAction'])){
64       if(isset($this->Actions[$_POST['action']])){
65         $this->setStatus($_POST['action']);
66       }
67     }
69     foreach($this->attributes as $attr){
70       $smarty->assign($attr,$this->$attr);  
71       $smarty->assign($attr."ACL",chkacl($this->acl,$attr));  
72     }
73     $smarty->assign("Actions",$this->Actions);
74     $smarty->assign("is_new",$this->dn);
75     $smarty->assign("is_acc",$this->initially_was_account);
76     return($smarty->fetch(get_template_path("goImapServer.tpl",TRUE,dirname(__FILE__))));
77   }
79   function getListEntry()
80   {
81     $flag = $this->StatusFlag;
82     $fields['Status']     = $this->$flag;
83     $fields['Message']    = _("Cyrus service");
84     $fields['AllowStart'] = true;
85     $fields['AllowStop']  = true;
86     $fields['AllowRestart'] = true;
87     $fields['AllowRemove']= true;
88     $fields['AllowEdit']  = true;
89     return($fields);
90   }
92   function remove_from_parent()
93   {
94     plugin::remove_from_parent();
95     /* Check if this is a new entry ... add/modify */
96     $ldap = $this->config->get_ldap_link();
97     $ldap->cat($this->dn,array("objectClass"));
98     if($ldap->count()){
99       $ldap->cd($this->dn);
100       $ldap->modify($this->attrs);
101     }else{
102       $ldap->cd($this->dn);
103       $ldap->add($this->attrs);
104     }
105     show_ldap_error($ldap->get_error());
106   }
108   function save()
109   {
110     $this->goImapSieveServer = $this->cn;
111     plugin::save();
112     /* Check if this is a new entry ... add/modify */
113     $ldap = $this->config->get_ldap_link();
114     $ldap->cat($this->dn,array("objectClass"));
115     if($ldap->count()){
116       $ldap->cd($this->dn);
117       $ldap->modify($this->attrs);
118     }else{
119       $ldap->cd($this->dn);
120       $ldap->add($this->attrs);
121     }
122     show_ldap_error($ldap->get_error());
123   }
126    /* Directly save new status flag */
127   function setStatus($value)
128   {
129     if($value == "none") return;
130     if(!$this->initially_was_account) return;
131     $ldap = $this->config->get_ldap_link();
132     $ldap->cd($this->dn);
133     $ldap->cat($this->dn,array("objectClass"));
134     if($ldap->count()){
136       $tmp = $ldap->fetch();
137       for($i = 0; $i < $tmp['objectClass']['count']; $i ++){
138         $attrs['objectClass'][] = $tmp['objectClass'][$i];
139       }
140       $flag = $this->StatusFlag;
141       $attrs[$flag] = $value;
142       $this->$flag = $value;
143       $ldap->modify($attrs);
144       show_ldap_error($ldap->get_error());
145     }
146   }
149   function check()
150   { 
151     $message = plugin::check();
152     if(empty($this->goImapName)){
153       $message[] =_("Please specify a server identifier.");
154     }  
155     if(empty($this->goImapConnect)){
156       $message[] =_("Please specify a connect url.");
157     }  
158     if(empty($this->goImapAdmin)){
159       $message[] =_("Please specify an admin user.");
160     }  
161     if(empty($this->goImapPassword)){
162       $message[] =_("Please specify a password for the admin user.");
163     } 
165     /* Check connect string */
166     if (!preg_match('/^\{[^:]+:[0-9]+.*\}$/', $this->goImapConnect)){
167       $message[]= sprintf(_("The imap connect string needs to be in the form '%s'."),
168           '{server-name:port/options}');
169     }
170     if (!preg_match('/^[0-9]+$/', $this->goImapSievePort)){
171       $message[]= _("The sieve port needs to be numeric.");
172     }
173  
174     return ($message);
175   }
178   function save_object()
179   {
180     if(isset($_POST['goImapServerPosted'])){
181       plugin::save_object(); 
183       foreach(array("cyrusImap","cyrusImapSSL","cyrusPop3","cyrusPop3SSL") as $checkbox) { 
184         if(!isset($_POST[$checkbox])){
185           $this->$checkbox = false;
186         }else{
187           $this->$checkbox = true;
188         }
189       }
190     }
191   }
193 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
194 ?>