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 = "";
27 var $ou = "";
28 var $goFonPIN = "";
29 var $acl = "";
30 var $old_cn = "";
32 var $goFonConferenceOption = "";
33 var $goFonConferenceOption_P = ""; // Set PIN
34 var $goFonConferenceOption_r = ""; // record Conference
35 var $goFonConferenceOption_M = ""; // Play Music opn hold
36 var $goFonConferenceOption_s = ""; // activate menu
37 var $goFonConferenceOption_i = ""; // announce new and leaving user
38 var $goFonConferenceOption_c = ""; // Count User
39 var $goFonConferenceOption_D = ""; // Conference Type, no PIN/PIN
41 var $goFonConferenceOwner = "";
43 var $goFonConferenceOptionFormat = "";
44 var $goFonConferenceOptionLifetime = "";
45 var $telephoneNumber = "";
47 var $old_tele_number = false;
48 var $generate_error = "";
50 var $old_dn;
52 /* Headpage attributes */
53 var $last_dep_sorting= "invalid";
54 var $departments= array();
56 /* attribute list for save action */
57 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
58 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
59 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
61 var $objectclasses= array("top", "goFonConference");
63 function conference ($config, $dn)
64 {
65 plugin::plugin($config, $dn);
66 $this->is_account = TRUE;
67 $this->ui = get_userinfo();
68 $this->dn = $dn;
69 $this->orig_dn = $dn;
70 $this->config = $config;
72 /* Set base */
73 if ($this->dn == "new"){
74 $ui= get_userinfo();
75 if(isset($_SESSION['conferencefilter']['depselect'])){
76 $this->base = $_SESSION['conferencefilter']['depselect'];
77 }else{
78 $this->base= dn2base($ui->dn);
79 }
80 } else {
81 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
82 }
84 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
85 $this->acl= get_module_permission($acl, "goFonConference", $this->dn);
86 $this->goFonConferenceOwner=$this->ui->dn;
88 /* Parse Options ...
89 * Parameter|Lifetime|number
90 */
91 if($this->dn!="new"){
92 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
94 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
95 $varname = "goFonConferenceOption_".$tmp1[0][$i];
96 if($tmp1[0][$i]=="d"){
97 $this->goFonConferenceOption_D = $tmp1[0][$i];
98 }else{
99 $this->$varname = $tmp1[0][$i];
100 }
101 }
103 $this->goFonConferenceOptionLifetime = $tmp1[1];
104 $this->old_tele_number = $this->telephoneNumber;
105 }
106 $this->old_dn = $this->dn;
107 $this->old_cn = $this->cn;
108 }
110 function execute()
111 {
112 $acl= get_permissions ($this->dn, $this->ui->subtreeACL);
113 $this->acl= get_module_permission($acl, "goFonConference", $this->dn);
115 $this->config->departments = get_departments($this->dn);
116 $this->config->make_idepartments();
117 $smarty= get_smarty();
119 $smarty->assign("bases" ,array_flip($this->config->departments));
120 $smarty->assign("base" ,$this->base);
122 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
123 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
124 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
126 foreach ($this->attributes as $val){
127 $smarty->assign("$val", $this->$val);
128 $smarty->assign("$val"."ACL", chkacl($this->acl, "$val"));
129 if(!$this->$val){
130 $smarty->assign($val."CHK", "");
131 }else{
132 $smarty->assign($val."CHK", " checked ");
133 }
134 }
136 if($_SESSION['js']==1){
137 if($this->goFonConferenceOption_P != "P"){
138 $smarty->assign("goFonPINACL"," disabled ");
139 $smarty->assign("goFonPIN","");
140 }
141 if($this->goFonConferenceOption_r != "r"){
142 $smarty->assign("goFonConferenceOptionFormatACL"," disabled ");
143 }
144 }
145 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
146 }
148 function remove_from_parent()
149 {
150 $ldap= $this->config->get_ldap_link();
151 $ldap->cd ($this->dn);
152 $ldap->recursive_remove();
154 /* Optionally execute a command after we're done */
155 $this->handle_post_events('remove');
156 }
159 /* Save data to object */
160 function save_object()
161 {
162 plugin::save_object();
163 if(isset($_POST['cn'])){
164 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
165 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
166 if(isset($_POST[$attrs])){
167 $this->$attrs = $_POST[$attrs];
168 }else{
169 $this->$attrs = false;
170 }
171 }
172 }
173 }
176 /* Check values */
177 function check()
178 {
179 $message= array();
181 if($this->is_number_used()){
182 $message[] = $this->is_number_used();
183 }
185 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
186 $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
187 }
189 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
190 $message[]= _("Please enter a PIN.");
191 }
193 if(empty($this->cn)){
194 $message[] =_("Please enter a name for the conference.");
195 }
197 if(!is_numeric($this->telephoneNumber)){
198 $message[] =_("Only numeric chars are allowed in Number field.");
199 }
201 if(!is_numeric($this->goFonConferenceOptionLifetime)){
202 $message[] =_("Only numbers are allowed in Lifetime.");
203 }
205 $this->SQL_remove_me(false);
206 $this->SQL_add_me(false);
208 if(!empty($this->generate_error)){
209 $message[]=$this->generate_error;
210 $this->generate_error="";
211 }
213 return $message;
214 }
217 function SQL_add_me($save){
218 // Get Configuration for Mysql database Server
219 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
221 // Connect to DB server
222 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
224 // Check if we are connected correctly
225 if(!$r_con){
226 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
227 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
228 gosa_log(mysql_error());
229 return false;
230 }
232 // Select database for Extensions
233 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
235 // Test if we have the database selected correctly
236 if(!$db){
237 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
238 gosa_log(mysql_error());
239 return false;
240 }
242 if((!empty($this->telephoneNumber))&&($save==true)){
244 $EXT=array();
246 $parameter ="";
247 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
248 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
249 $parameter .= $this->$attrs;
250 }
252 $i=1;
253 $context="GOsa";
254 // Set Language to German
255 $EXT[$i]['exten'] =$this->telephoneNumber;
256 $EXT[$i]['context'] = $context;
257 $EXT[$i]['priority']= $i;
258 $EXT[$i]['app'] ="SetLanguage";
259 $EXT[$i]['appdata'] ="de";
260 $i++;
262 if($this->goFonConferenceOption_r == "r"){
264 // Recordingformat for conference
265 $EXT[$i]['exten'] =$this->telephoneNumber;
266 $EXT[$i]['context'] =$context;
267 $EXT[$i]['priority']= $i;
268 $EXT[$i]['app'] ="Setvar";
269 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
270 $i++;
272 }
274 // Answer Call
275 $EXT[$i]['exten'] =$this->telephoneNumber;
276 $EXT[$i]['context'] =$context;
277 $EXT[$i]['priority']=$i;
278 $EXT[$i]['app'] ="answer";
279 $EXT[$i]['appdata'] ="";
280 $i++;
282 // Start Conference
283 $EXT[$i]['exten'] =$this->telephoneNumber;
284 $EXT[$i]['context'] =$context;
285 $EXT[$i]['priority']=$i;
286 $EXT[$i]['app'] ="MeetMe";
288 if(empty($this->goFonPIN)) {
289 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
290 }else{
291 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
292 }
293 $i++;
295 // Start Conference
296 $EXT[$i]['exten'] =$this->cn;
297 $EXT[$i]['context'] =$context;
298 $EXT[$i]['priority']=1;
299 $EXT[$i]['app'] ="Goto";
300 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
301 $SQL=array();
303 foreach($EXT as $keytop => $valtop){
304 $s_keys = "";
305 $s_values = "";
306 foreach($valtop as $key=>$val){
307 $s_keys .="`".$key."`,";
308 $s_values .="'".$val."',";
309 }
310 $s_keys =preg_replace("/\,$/","",$s_keys);
311 $s_values =preg_replace("/\,$/","",$s_values);
312 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
313 }
314 foreach($SQL as $sqlsyn){
315 mysql_query($sqlsyn);
316 }
317 }
321 return(true);
322 }
324 function SQL_remove_me($save){
326 if($this->old_tele_number){
327 // Get Configuration for Mysql database Server
328 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
330 // Connect to DB server
331 $r_con = @mysql_connect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
333 // Check if we are connected correctly
334 if(!$r_con){
335 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
336 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
337 gosa_log(mysql_error());
338 return false;
339 }
341 // Select database for Extensions
342 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
344 // Test if we have the database selected correctly
345 if(!$db){
346 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
347 gosa_log(mysql_error());
348 return false;
349 }
351 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE (exten= '".$this->old_tele_number."')
352 OR (exten='".$this->telephoneNumber."')
353 OR (exten='".$this->cn."')";
355 if($save){
356 @mysql_query($SQL);
357 }
359 }//ENDE old num availiable ...
360 return(true);
361 }
365 /* This function checks if the given phonenumbers are available or already in use*/
366 function is_number_used()
367 {
368 $ldap= $this->config->get_ldap_link();
369 $ldap->cd($this->config->current['BASE']);
370 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
371 while($attrs = $ldap->fetch()) {
372 unset($attrs['telephoneNumber']['count']);
373 foreach($attrs['telephoneNumber'] as $tele){
374 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
375 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
376 $numbers[$tele]=$attrs;
377 }
378 }
380 $num = $this->telephoneNumber;
381 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
382 if(isset($numbers[$num]['uid'][0])){
383 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
384 }else{
385 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
386 }
387 }
388 }
394 /* Save to LDAP */
395 function save()
396 {
397 plugin::save();
399 $this->SQL_remove_me(true);
400 $this->SQL_add_me(true);
402 if(empty($this->goFonConferenceOption_P)){
403 $this->attrs['goFonPIN']=array();
404 }
405 $this->attrs['goFonConferenceOption']="";
406 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
407 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
408 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
409 unset($this->attrs[$attrs]);
410 }
412 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
413 unset($this->attrs['goFonConferenceOptionLifetime']);
415 /* Write back to ldap */
417 unset($this->attrs['base']);
419 foreach($this->attributes as $atr){
420 if(chkacl($this->acl, $atr)!=""){
421 unset($this->attrs[$atr]);
422 }
423 }
425 $ldap= $this->config->get_ldap_link();
427 $ldap->cat($this->dn);
428 $a= $ldap->fetch();
429 $ldap->cd($this->dn);
430 if (count($a)){
431 $ldap->modify($this->attrs);
432 $this->handle_post_events('modify');
433 } else {
434 $ldap->add($this->attrs);
435 $this->handle_post_events('add');
436 }
437 show_ldap_error($ldap->get_error());
439 /* Optionally execute a command after we're done */
440 $this->postcreate();
441 }
443 }
445 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
446 ?>