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 $old_cn = "";
31 var $goFonConferenceOption = "";
32 var $goFonConferenceOption_P = ""; // Set PIN
33 var $goFonConferenceOption_r = ""; // record Conference
34 var $goFonConferenceOption_M = ""; // Play Music opn hold
35 var $goFonConferenceOption_s = ""; // activate menu
36 var $goFonConferenceOption_i = ""; // announce new and leaving user
37 var $goFonConferenceOption_c = ""; // Count User
38 var $goFonConferenceOption_D = ""; // Conference Type, no PIN/PIN
40 var $goFonConferenceOwner = "";
42 var $error_shown = false;
44 var $goFonConferenceOptionFormat = "";
45 var $goFonConferenceOptionLifetime = "";
46 var $telephoneNumber = "";
48 var $old_tele_number = false;
49 var $generate_error = "";
51 var $old_dn;
53 /* Headpage attributes */
54 var $last_dep_sorting= "invalid";
55 var $departments= array();
57 /* attribute list for save action */
58 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r",
59 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c",
60 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
62 var $objectclasses= array("top", "goFonConference");
64 function conference ($config, $dn)
65 {
66 plugin::plugin($config, $dn);
67 $this->is_account = TRUE;
68 $this->ui = get_userinfo();
69 $this->dn = $dn;
70 $this->orig_dn = $dn;
71 $this->config = $config;
73 /* Set base */
74 if ($this->dn == "new"){
75 $ui= get_userinfo();
76 if(isset($_SESSION['CurrentMainBase'])){
77 $this->base = $_SESSION['CurrentMainBase'];
78 }else{
79 $this->base= dn2base($ui->dn);
80 }
81 } else {
82 $this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
83 }
85 $ui= get_userinfo();
86 $acl= get_permissions ($ui->dn, $this->ui->subtreeACL);
87 $this->acl= get_module_permission($acl, "conference", $ui->dn);
88 $this->goFonConferenceOwner=$this->ui->dn;
90 /* Parse Options ...
91 * Parameter|Lifetime|number
92 */
93 if($this->dn!="new"){
94 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
96 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
97 $varname = "goFonConferenceOption_".$tmp1[0][$i];
98 if($tmp1[0][$i]=="d"){
99 $this->goFonConferenceOption_D = $tmp1[0][$i];
100 }else{
101 $this->$varname = $tmp1[0][$i];
102 }
103 }
105 $this->goFonConferenceOptionLifetime = $tmp1[1];
106 $this->old_tele_number = $this->telephoneNumber;
107 }
108 $this->old_dn = $this->dn;
109 $this->old_cn = $this->cn;
110 }
112 function execute()
113 {
114 /* Call parent execute */
115 plugin::execute();
117 $smarty= get_smarty();
119 $smarty->assign("bases" ,$this->config->idepartments);
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 $this->SQL_remove_me(true);
152 $ldap= $this->config->get_ldap_link();
153 $ldap->cd ($this->dn);
154 $ldap->recursive_remove();
156 /* Optionally execute a command after we're done */
157 $this->handle_post_events('remove');
158 }
161 /* Save data to object */
162 function save_object()
163 {
164 plugin::save_object();
165 if(isset($_POST['cn'])){
166 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
167 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonPIN") as $attrs){
168 if(isset($_POST[$attrs])){
169 $this->$attrs = $_POST[$attrs];
170 }else{
171 $this->$attrs = false;
172 }
173 }
174 }
175 }
178 /* Check values */
179 function check()
180 {
181 /* Call common method to give check the hook */
182 $message= plugin::check();
184 if($this->is_number_used()){
185 $message[] = $this->is_number_used();
186 }
188 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
189 $message[] =_("You have specified a conference 'without PIN' ... please leave the PIN fields empty.");
190 }
192 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
193 $message[]= _("Please enter a PIN.");
194 }
196 if(empty($this->cn)){
197 $message[] =_("Please enter a name for the conference.");
198 }
200 if(!is_numeric($this->telephoneNumber)){
201 $message[] =_("Only numeric chars are allowed in Number field.");
202 }
204 if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
205 $message[] =_("Only numbers are allowed in Lifetime.");
206 }
208 $this->SQL_remove_me(false);
209 $this->SQL_add_me(false);
211 if(!empty($this->generate_error)){
212 $message[]=$this->generate_error;
213 $this->generate_error="";
214 }
216 return $message;
217 }
220 function SQL_add_me($save){
222 if(!isset($_SESSION['config']->data['SERVERS']['FON'])){
223 $this->generate_error = _("There is currently no asterisk server defined. Possibly you are missing a server that handles the asterisk management (goFonServer). Your settings can't be saved to asterisk database.");
224 return(false);
225 }
227 // Get Configuration for Mysql database Server
228 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
230 // Connect to DB server
231 $r_con = false;
233 if(!is_callable("mysql_pconnect")){
234 if(!$this->error_shown){
235 print_red(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
236 $this->error_shown = true;
237 }
238 return(true);
239 }
240 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
242 // Check if we are connected correctly
243 if(!$r_con){
244 $this->generate_error = sprintf(_("The MySQL server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
245 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
246 gosa_log(mysql_error());
247 return false;
248 }
250 // Select database for Extensions
251 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
253 // Test if we have the database selected correctly
254 if(!$db){
255 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
256 gosa_log(mysql_error());
257 return false;
258 }
260 if((!empty($this->telephoneNumber))&&($save==true)){
262 $EXT=array();
264 $parameter ="";
265 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
266 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
267 $parameter .= $this->$attrs;
268 }
270 $i=1;
271 $context="GOsa";
272 // Set Language to German
273 $EXT[$i]['exten'] =$this->telephoneNumber;
274 $EXT[$i]['context'] = $context;
275 $EXT[$i]['priority']= $i;
276 $EXT[$i]['app'] ="SetLanguage";
277 $EXT[$i]['appdata'] ="de";
278 $i++;
280 if($this->goFonConferenceOption_r == "r"){
282 // Recordingformat for conference
283 $EXT[$i]['exten'] =$this->telephoneNumber;
284 $EXT[$i]['context'] =$context;
285 $EXT[$i]['priority']= $i;
286 $EXT[$i]['app'] ="Setvar";
287 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
288 $i++;
290 }
292 // Answer Call
293 $EXT[$i]['exten'] =$this->telephoneNumber;
294 $EXT[$i]['context'] =$context;
295 $EXT[$i]['priority']=$i;
296 $EXT[$i]['app'] ="answer";
297 $EXT[$i]['appdata'] ="";
298 $i++;
300 // Start Conference
301 $EXT[$i]['exten'] =$this->telephoneNumber;
302 $EXT[$i]['context'] =$context;
303 $EXT[$i]['priority']=$i;
304 $EXT[$i]['app'] ="MeetMe";
306 if(empty($this->goFonPIN)) {
307 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
308 }else{
309 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
310 }
311 $i++;
313 // Start Conference
314 $EXT[$i]['exten'] =$this->cn;
315 $EXT[$i]['context'] =$context;
316 $EXT[$i]['priority']=1;
317 $EXT[$i]['app'] ="Goto";
318 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
319 $SQL=array();
321 foreach($EXT as $keytop => $valtop){
322 $s_keys = "";
323 $s_values = "";
324 foreach($valtop as $key=>$val){
325 $s_keys .="`".$key."`,";
326 $s_values .="'".$val."',";
327 }
328 $s_keys =preg_replace("/\,$/","",$s_keys);
329 $s_values =preg_replace("/\,$/","",$s_values);
330 $SQL[]="INSERT INTO ".$a_SETUP['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
331 }
332 foreach($SQL as $sqlsyn){
333 mysql_query($sqlsyn);
334 }
335 }
338 @mysql_close($r_con);
339 return(true);
340 }
342 function SQL_remove_me($save){
343 if(!is_callable("mysql_pconnect")){
344 if(!$this->error_shown){
345 print_red(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup."));
346 $this->error_shown = true;
347 }
348 return(true);
349 }
351 if($this->old_tele_number){
352 // Get Configuration for Mysql database Server
353 $a_SETUP = $_SESSION['config']->data['SERVERS']['FON'];
355 // Connect to DB server
356 $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']);
358 // Check if we are connected correctly
359 if(!$r_con){
360 $this->generate_error = sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."),
361 $a_SETUP['SERVER'],$a_SETUP['LOGIN']);
362 gosa_log(mysql_error());
363 return false;
364 }
366 // Select database for Extensions
367 $db = @mysql_select_db($a_SETUP['DB'],$r_con);
369 // Test if we have the database selected correctly
370 if(!$db){
371 $this->generate_error = sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER']);
372 gosa_log(mysql_error());
373 return false;
374 }
376 $SQL = "DELETE FROM ".$a_SETUP['EXT_TABLE']."
377 WHERE (exten='".$this->old_tele_number."')
378 OR (exten='".$this->telephoneNumber."')
379 OR (exten='".$this->cn."')
380 OR (exten='".$this->old_cn."')";
382 if($save){
383 @mysql_query($SQL);
384 }
386 }//ENDE old num availiable ...
387 @mysql_close($r_con);
388 return(true);
389 }
393 /* This function checks if the given phonenumbers are available or already in use*/
394 function is_number_used()
395 {
396 $ldap= $this->config->get_ldap_link();
397 $ldap->cd($this->config->current['BASE']);
398 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
399 while($attrs = $ldap->fetch()) {
400 unset($attrs['telephoneNumber']['count']);
401 foreach($attrs['telephoneNumber'] as $tele){
402 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
403 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
404 $numbers[$tele]=$attrs;
405 }
406 }
408 $num = $this->telephoneNumber;
409 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
410 if(isset($numbers[$num]['uid'][0])){
411 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]);
412 }else{
413 return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]);
414 }
415 }
416 }
422 /* Save to LDAP */
423 function save()
424 {
426 if((!isset($this->attrs['goFonPIN']))){
427 $pin_use = false;
428 }else{
429 $pin_use = true;
430 }
432 plugin::save();
434 if(empty($this->old_tele_number)){
435 $this->old_tele_number= $this->telephoneNumber;
436 }
438 $this->SQL_remove_me(true);
439 $this->SQL_add_me(true);
441 if(empty($this->goFonConferenceOption_P)){
442 if($pin_use){
443 $this->attrs['goFonPIN']=array();
444 }else{
445 unset($this->attrs['goFonPIN']);
446 }
447 }
448 $this->attrs['goFonConferenceOption']="";
449 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
450 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
451 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
452 unset($this->attrs[$attrs]);
453 }
455 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
456 unset($this->attrs['goFonConferenceOptionLifetime']);
458 /* Write back to ldap */
460 unset($this->attrs['base']);
462 foreach($this->attributes as $atr){
463 if(chkacl($this->acl, $atr)!=""){
464 unset($this->attrs[$atr]);
465 }
466 }
468 $ldap= $this->config->get_ldap_link();
470 $ldap->cat($this->dn);
471 $a= $ldap->fetch();
472 $ldap->cd($this->dn);
473 if (count($a)){
474 $this->cleanup();
475 $ldap->modify ($this->attrs);
477 $this->handle_post_events('modify');
478 } else {
479 $ldap->add($this->attrs);
480 $this->handle_post_events('add');
481 }
482 show_ldap_error($ldap->get_error());
484 /* Optionally execute a command after we're done */
485 $this->postcreate();
486 }
488 }
490 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
491 ?>