Code

2d44350b4db414d95c2dac34cb4a46f30242fafa
[gosa.git] / plugins / gofon / conference / class_phoneConferenceGeneric.inc
1 <?php
2 /*
3   This code is part of GOsa (https://gosa.gonicus.de)
4   Copyright (C) 2003  Cajus Pollmeier
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2 of the License, or
9   (at your option) any later version.
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
21 class conference extends plugin
22 {
23   /* department attributes */
24   var $cn= "";
25   var $description= "";
26   var $base ="";
29   var $goFonPIN                            = "";
31   var $goFonConferenceOption_D = "";
32   var $goFonConferenceOption_r = "";
33   var $goFonConferenceOption_M = "";
34   var $goFonConferenceOption_s = "";
35   var $goFonConferenceOption_i = "";
36   var $goFonConferenceOption_c = "";
37   var $goFonConferenceOption_P = "";
39   var $goFonConferenceOptionFormat              = "";
40   var $goFonConferenceOptionLifetime    = "";
41   var $goFonConferenceOptionNumber              = "";
42         
43   /* Headpage attributes */
44   var $last_dep_sorting= "invalid";
45   var $departments= array();
47   /* attribute list for save action */
48   var $attributes= array("cn", "description", "goFonPIN","goFonConferenceOption_D","goFonConferenceOption_r",
49                                                  "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
50                                                  "goFonConferenceOption_P","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","goFonConferenceOptionNumber");
52   var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
54   function conference ($config, $dn)
55   {
56         plugin::plugin($config, $dn);
57         $this->is_account= TRUE;
58         $this->ui= get_userinfo();
59         $this->dn= $dn;
60         $this->orig_dn= $dn;
61         $this->config= $config;
63         /* Set base */
64     if ($this->dn == "new"){
65                 $ui= get_userinfo();
66                 if(isset($_SESSION['depfilter']['depselect'])){
67                         $this->base = $_SESSION['depfilter']['depselect'];
68                 }else{
69                         $this->base= dn2base($ui->dn);
70                 }
71         } else {
72                 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
73         }
74   }
76   function execute()
77   {
78         /* Reload departments */
79         $this->config->departments= get_departments($this->dn);
80         $this->config->make_idepartments();
81         $smarty= get_smarty();
83         $smarty->assign("goFonConferenceOptions",               array("P"=>"Conference ",""=>"Conference without PIN"));
84         $smarty->assign("goFonConferenceOptionFormats", array("P"=>"Conference ",""=>"Conference without PIN"));
85         $smarty->assign("goFonConferenceOption" ,$this->goFonConferenceOption_P);
86         
87         foreach ($this->attributes as $val){
88                 $smarty->assign("$val", $this->$val);
89                 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
90                 if($this->$val){
91                         $smarty->assign($val."CHK", "");
92                 }else{
93                         $smarty->assign($val."CHK", " checked ");
94                 }
95         }
96         $smarty->assign("bases", $this->config->idepartments);
97         $smarty->assign("base_select", $this->base);
98         return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
99   }
101   function clear_fields()
102   {
103         $this->dn= "";
104         $this->base= "";
105         $this->acl= "#none#";
107         foreach ($this->attributes as $val){
108                 $this->$val= "";
109         }
110   }
113   function remove_from_parent()
114   {
115         $ldap= $this->config->get_ldap_link();
116         $ldap->cd ($this->dn);
117         $ldap->recursive_remove();
119         /* Optionally execute a command after we're done */
120         $this->handle_post_events('remove');
121   }
124   /* Save data to object */
125   function save_object()
126   {
127         if (isset($_POST['base'])){
128                 plugin::save_object();
130                 /* Save base, since this is no LDAP attribute */
131                 if (chkacl($this->acl, "create") == ""){
132                         $this->base= $_POST['base'];
133                 }
134         }
135   }
138   /* Check values */
139   function check()
140   {
141         $message= array();
143         /* Permissions for that base? */
144         $this->dn= "ou=$this->ou,".$this->base;
145         $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
146         $acl= get_module_permission($acl, "department", $this->dn);
147         if (chkacl($acl, "create") != ""){
148                 $message[]= _("You have no permissions to create a department on this 'Base'.");
149         }
151         /* Check for presence of this department */
152         $ldap= $this->config->get_ldap_link();
153         $attrs= $ldap->cat ($this->dn);
154         if ($this->orig_dn == "new" && !($attrs === FALSE)){
155                 $message[]= _("Department with that 'Name' already exists.");
156         } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
157                 $message[]= _("Department with that 'Name' already exists.");
158         }
160         /* All required fields are set? */
161         if ($this->ou == ""){
162                 $message[]= _("Required field 'Name' is not set.");
163         }
164         if ($this->description == ""){
165                 $message[]= _("Required field 'Description' is not set.");
166         }
168         /* Validate and modify - or: spaghetti rules! */
169         if ($this->ou == "incoming"){
170                 $message[]= _("The field 'Name' contains the reserved word 'incoming'.".
171                                 " Please choose another name.");
172         }
173         if (preg_match ('/[,#+:=>\\\\]/', $this->ou)){
174                 $message[]= _("The field 'Name' contains invalid characters.");
175         }
176         if (!is_phone_nr($this->telephoneNumber)){
177                 $message[]= _("The field 'Phone' contains an invalid phone number.");
178         }
179         if (!is_phone_nr($this->facsimileTelephoneNumber)){
180                 $message[]= _("The field 'Fax' contains an invalid phone number.");
181         }
183         return $message;
184   }
187   /* Save to LDAP */
188   function save()
189   {
190         plugin::save();
192         /* Write back to ldap */
193         $ldap= $this->config->get_ldap_link();
194         $ldap->cat($this->dn);
195         $a= $ldap->fetch();
196         $ldap->cd($this->dn);
197         if (count($a)){
198                 $ldap->modify($this->attrs);
199                 $this->handle_post_events('modify');
200         } else {
201                 $ldap->add($this->attrs);
202                 $this->handle_post_events('add');
203         }
204         show_ldap_error($ldap->get_error());
206         /* Optionally execute a command after we're done */
207         $this->postcreate();
208   }
212 ?>