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 $old_base = "";
28 var $ou = "";
29 var $goFonPIN = "";
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 = "";
42 var $goFonHomeServer = "0"; // Home server of the conference
43 var $init_HomeServer = "0"; // Initial home server of the conference
44 var $goFonHomeServers = array(); // All available home servers
46 var $goFonConferenceOptionFormat = "";
47 var $goFonConferenceOptionLifetime = "";
48 var $telephoneNumber = "";
50 var $old_tele_number = false;
51 var $old_dn;
53 /* Headpage attributes */
54 var $last_dep_sorting= "invalid";
55 var $departments= array();
56 var $view_logged = FALSE;
57 var $dialog ;
59 /* attribute list for save action */
60 var $attributes= array("cn","base", "description", "goFonPIN","goFonConferenceOption_P","goFonConferenceOption_r","goFonHomeServer",
61 "goFonConferenceOption_M","goFonConferenceOption_s","goFonConferenceOption_i","goFonConferenceOption_c","goFonHomeServer",
62 "goFonConferenceOption_D","goFonConferenceOptionFormat","goFonConferenceOptionLifetime","telephoneNumber","goFonConferenceOwner");
64 var $language = "de";
65 var $languages = array();
67 var $objectclasses= array("top", "goFonConference");
69 var $orig_dn ="";
70 var $orig_base = "";
72 function conference (&$config, $dn, $plugin= NULL)
73 {
74 plugin::plugin($config, $dn, $plugin);
75 $this->is_account = TRUE;
76 $this->ui = get_userinfo();
77 $this->orig_dn = $dn;
79 $this->languages= get_languages(TRUE,TRUE);
82 /* Check server configurations
83 * Load all server configuration in $this->goFonHomeServers if available
84 * and use first server as default if necessary.
85 */
86 $a_SETUP= array();
87 $config = session::get('config');
88 if(isset($config->data['SERVERS']['FON']) && is_callable("mysql_connect")) {
90 /* Set available server */
91 $this->goFonHomeServers = $config->data['SERVERS']['FON'];
93 /* Set default server */
94 if($this->dn == "new"){
95 $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
96 }
98 /* Remember inital home server, to be able to remove old entries */
99 $this->init_HomeServer = $this->goFonHomeServer;
101 /* get config */
102 if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){
103 msg_dialog::display(_("Obsolete entry"), sprintf(_("The current home server is not available anymore. It will be moved to '%s' if you save this entry!"), preg_replace("/,/",", ",$this->goFonHomeServers[0]['DN'])), ERROR_DIALOG);
105 $this->goFonHomeServer = $this->goFonHomeServers[0]['DN'];
106 $this->init_HomeServer = $this->goFonHomeServers[0]['DN'];
107 }
108 $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer];
109 }
111 /* Set base */
112 if ($this->dn == "new"){
113 $ui= get_userinfo();
114 if(session::is_set('CurrentMainBase')){
115 $this->base = session::get('CurrentMainBase');
116 }else{
117 $this->base= dn2base($ui->dn);
118 }
119 } else {
121 /* Get base */
122 $this->base = preg_replace ("/^[^,]+,".normalizePreg(get_ou('conferenceou'))."/i","",$this->dn);;
123 }
125 $this->goFonConferenceOwner=$this->ui->dn;
127 /* Parse Options ...
128 * Parameter|Lifetime|number
129 */
130 if($this->dn!="new"){
131 $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]);
133 for($i = 0 ; $i < strlen($tmp1[0]);$i++){
134 $varname = "goFonConferenceOption_".$tmp1[0][$i];
135 if($tmp1[0][$i]=="d"){
136 $this->goFonConferenceOption_D = $tmp1[0][$i];
137 }else{
138 $this->$varname = $tmp1[0][$i];
139 }
140 }
142 $this->goFonConferenceOptionLifetime = $tmp1[1];
143 if(isset($tmp1[2]) && isset($this->languages[$tmp1[2]])){
144 $this->language = $tmp1[2];
145 }
147 $this->old_tele_number = $this->telephoneNumber;
148 }
149 $this->old_dn = $this->dn;
150 $this->old_cn = $this->cn;
151 $this->old_base = $this->base;
152 $this->orig_base = $this->base;
153 $this->orig_dn = $this->dn;
155 }
158 function execute()
159 {
160 /* Call parent execute */
161 plugin::execute();
163 /* Log last action */
164 if($this->is_account && !$this->view_logged){
165 $this->view_logged = TRUE;
166 new log("view","gofonconference/".get_class($this),$this->dn);
167 }
169 $smarty= get_smarty();
171 $smarty->assign("bases" ,$this->config->idepartments);
172 $smarty->assign("base" ,$this->base);
174 $once = true;
175 foreach($_POST as $name => $value){
176 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
177 $once = false;
178 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
179 $this->dialog->setCurrentBase($this->base);
180 }
181 }
183 /* Dialog handling */
184 if(is_object($this->dialog)){
185 /* Must be called before save_object */
186 $this->dialog->save_object();
188 if($this->dialog->isClosed()){
189 $this->dialog = false;
190 }elseif($this->dialog->isSelected()){
191 $tmp = $this->get_allowed_bases();
192 if(isset($tmp[$this->dialog->isSelected()])){
193 $this->base = $this->dialog->isSelected();
194 }
195 $this->dialog= false;
196 }else{
197 return($this->dialog->execute());
198 }
199 }
201 foreach ($this->attributes as $val){
202 $smarty->assign("$val", $this->$val);
203 if(!$this->$val){
204 $smarty->assign($val."CHK", "");
205 }else{
206 $smarty->assign($val."CHK", " checked ");
207 }
208 }
210 /* Create array with goFonHomeServer */
211 $tmp = array();
212 foreach($this->goFonHomeServers as $dn => $val){
213 if(!is_numeric($dn)){
214 $tmp[$dn] = $val['SERVER'];
215 }
216 }
217 $smarty->assign("language",$this->language);
218 $smarty->assign("languages",$this->languages);
219 $smarty->assign("goFonHomeServers",$tmp);
220 $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN"));
221 $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49"));
222 $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D);
224 $tmp = $this->plInfo();
225 foreach($tmp['plProvidedAcls'] as $name => $translation){
226 $smarty->assign($name."ACL",$this->getacl($name));
227 }
229 if($this->acl_is_writeable("base")){
230 $smarty->assign("baseSelect",true);
231 }else{
232 $smarty->assign("baseSelect",false);
233 }
235 $smarty->assign("bases" ,$this->get_allowed_bases());
236 $smarty->assign("base_select" ,$this->base);
239 if(session::get('js')==1){
240 if($this->goFonConferenceOption_P != "P"){
241 $smarty->assign("goFonPINACL", $this->getacl("goFonPIN",TRUE));
242 $smarty->assign("goFonPIN","");
243 }
244 if($this->goFonConferenceOption_r != "r"){
245 $smarty->assign("goFonConferenceOptionFormatACL", $this->getacl("goFonConferenceOptionr",TRUE));
246 }
247 }
248 return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
249 }
252 function remove_from_parent()
253 {
254 /* Check if 'old' home server is available in gosa FON server configuration
255 * Try to remove this entry from database and display errors.
256 */
257 if(isset($this->goFonHomeServers[$this->goFonHomeServer])){
258 $str = $this->SQL_remove_me(true);
259 if($str){
260 msg_dialog::display(_("Error"), $str, ERROR_DIALOG);
261 return false;
262 }
263 }else{
264 msg_dialog::display(_("Error"), sprintf(_("Cannot delete entry from server '%s' because it seems to be removed!"), preg_replace("/,/",", ",$this->goFonHomeServer)), ERROR_DIALOG);
265 return false;
266 }
268 /* Remove ldap entry */
269 $ldap= $this->config->get_ldap_link();
270 $ldap->cd ($this->dn);
271 $ldap->recursive_remove();
273 new log("remove","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
275 /* Optionally execute a command after we're done */
276 $this->handle_post_events('remove');
277 }
280 /* Save data to object */
281 function save_object()
282 {
283 if(isset($_POST['phoneConferenceGeneric'])){
285 /* Get selected language */
286 if(isset($_POST['language']) && isset($this->languages[get_post('language')])){
287 $this->language = get_post('language');
288 }
290 /* Create a base backup and reset the
291 base directly after calling plugin::save_object();
292 Base will be set seperatly a few lines below */
293 $base_tmp = $this->base;
294 plugin::save_object();
295 $this->base = $base_tmp;
297 /* Save base, since this is no LDAP attribute */
298 $tmp = $this->get_allowed_bases();
299 if(isset($_POST['base'])){
300 if(isset($tmp[$_POST['base']])){
301 $this->base= $_POST['base'];
302 }
303 }
304 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
305 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
307 /* Acl can't contain _ so we remove it here. */
308 $acl_name = preg_replace("/_/","",$attrs);
310 if($this->acl_is_writeable($acl_name)){
312 if(isset($_POST[$attrs])){
313 $this->$attrs = $_POST[$attrs];
314 }else{
315 $this->$attrs = false;
316 }
317 }
318 }
319 }
320 }
323 function check_database_accessibility()
324 {
325 /* Check if mysql extension is available */
326 if(!is_callable("mysql_pconnect")){
327 return(msgPool::missingext("php-mysql"));
328 }
330 /********************
331 * Check currently selected home server
332 ********************/
334 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer];
335 $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
336 if(!$r_current){
337 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
338 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Current['SERVER']));
339 }
340 $db_current = @mysql_select_db($cfg_Current['DB'],$r_current);
341 if(!$db_current){
342 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current));
343 mysql_close($r_current);
344 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Current['DB']));
345 }
347 /********************
348 * Check init home server
349 ********************/
351 if($this->goFonHomeServers != $this->init_HomeServer){
352 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
353 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
354 if(!$r_init){
355 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
356 return(msgPool::dbconnect("GOfon",@mysql_error($r_current), $cfg_Init['SERVER']));
357 }
358 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
359 if(!$db_init){
360 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
361 mysql_close($r_init);
362 return(msgPool::dbselect("GOfon",@mysql_error($r_current), $cfg_Init['DB']));
363 }
364 }
365 }
367 /* Check values */
368 function check()
369 {
370 /* Call common method to give check the hook */
371 $message= plugin::check();
373 if($this->is_number_used()){
374 $message[] = $this->is_number_used();
375 }
377 /* Check if previously selected server is still available */
378 if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){
379 $message[]= sprintf(_("The previously selected asterisk home server '%s' is no longer available!"),preg_replace("/,/",", ",$this->goFonHomeServer));
380 return($message);
381 }
383 if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){
384 $message[]= msgPool::required(_("PIN"));
385 }
387 if(empty($this->cn)){
388 $message[] = msgPool::required(_("Name"));
389 }
391 if(!is_numeric($this->telephoneNumber)){
392 $message[] = msgPool::invalid(_("Number"),$this->telephoneNumber,"/[0-9]/");
393 }
395 if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){
396 $message[] = msgPool::invalid(_("Lifetime"),$this->goFonConferenceOptionLifetime,"/[0-9]/");
397 }
399 /* Check if add could be successful */
400 $str = $this->SQL_add_me(false);
401 if(!empty($str)){
402 $message[] = $str;
403 }
405 if($this->old_cn != $this->cn || $this->base != $this->old_base){
406 $ldap = $this->config->get_ldap_link();
407 $ldap->cd(get_ou('conferenceou').$this->base);
408 $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn"));
409 if($ldap->count()){
410 $message[] = msgPool::duplicated(_("Name"));
411 }
412 }
414 /* Check if we are allowed to create or move this object
415 */
416 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
417 $message[] = msgPool::permCreate();
418 }elseif($this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
419 $message[] = msgPool::permMove();
420 }
422 return $message;
423 }
426 function SQL_add_me($save)
427 {
428 /* Check if there is at least on server configuration */
429 if(!count($this->goFonHomeServers)){
430 return(msgPool::noserver(_("GOfon")));
431 }
433 /********************
434 * Get configuration and try to connect
435 ********************/
437 /* Check if databases are reachable, returns an error string if anything fails */
438 $error_str = $this->check_database_accessibility();
439 if($error_str){
440 return($error_str);
441 }
443 /* Remove old entries, returns an error string if anything fails */
444 $error_str = $this->SQL_remove_me($save);
445 if($error_str){
446 return($error_str);
447 }
449 /* Connect to current database to be able to add new entries */
450 $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ;
451 $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']);
452 $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur);
454 /********************
455 * Remove entries that could cause trouble
456 ********************/
458 /* If the current home server is different to the initial home server,
459 * there may be already some entries with the given telephoneNumber and/or cn.
460 * We must remove those entries to avoid duplicate use of the same extension name.
461 */
462 if($this->goFonHomeServer != $this->init_HomeServer){
463 $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';";
464 $res = @mysql_query($query,$res_cur);
465 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
466 if(!$res){
467 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
468 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
469 }
470 if($save && mysql_affected_rows($res_cur)) {
471 $SQL = "DELETE FROM ".$cfg_Current['EXT_TABLE']."
472 WHERE (exten='".$this->telephoneNumber."')
473 OR (exten='".$this->cn."')";
475 /* Query and ensure that everything went fine */
476 $res = @mysql_query($SQL,$res_cur);
477 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
478 if(!$res){
479 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur));
480 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Current['SERVER']));
481 }
482 }
483 }
485 /********************
486 * Add new conference entry
487 ********************/
488 if((!empty($this->telephoneNumber))&&($save==true)){
490 /* Create string out of conference Flags */
491 $parameter ="";
492 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
493 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){
494 $parameter .= $this->$attrs;
495 }
497 $i=1;
498 $EXT=array();
499 $context="GOsa";
500 // Set Language to German
501 $EXT[$i]['exten'] =$this->telephoneNumber;
502 $EXT[$i]['context'] = $context;
503 $EXT[$i]['priority']= $i;
504 $EXT[$i]['app'] ="SetLanguage";
505 $EXT[$i]['appdata'] =$this->language;
506 $i++;
508 if($this->goFonConferenceOption_r == "r"){
510 // Recordingformat for conference
511 $EXT[$i]['exten'] =$this->telephoneNumber;
512 $EXT[$i]['context'] =$context;
513 $EXT[$i]['priority']= $i;
514 $EXT[$i]['app'] ="Setvar";
515 $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat;
516 $i++;
518 }
520 // Answer Call
521 $EXT[$i]['exten'] =$this->telephoneNumber;
522 $EXT[$i]['context'] =$context;
523 $EXT[$i]['priority']=$i;
524 $EXT[$i]['app'] ="answer";
525 $EXT[$i]['appdata'] ="";
526 $i++;
528 // Start Conference
529 $EXT[$i]['exten'] =$this->telephoneNumber;
530 $EXT[$i]['context'] =$context;
531 $EXT[$i]['priority']=$i;
532 $EXT[$i]['app'] ="MeetMe";
534 if(empty($this->goFonPIN)) {
535 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter;
536 }else{
537 $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN;
538 }
539 $i++;
541 // Start Conference
542 $EXT[$i]['exten'] =$this->cn;
543 $EXT[$i]['context'] =$context;
544 $EXT[$i]['priority']=1;
545 $EXT[$i]['app'] ="Goto";
546 $EXT[$i]['appdata'] =$this->telephoneNumber."|1";
547 $SQL=array();
549 foreach($EXT as $keytop => $valtop){
550 $s_keys = "";
551 $s_values = "";
552 foreach($valtop as $key=>$val){
553 $s_keys .="`".$key."`,";
554 $s_values .="'".$val."',";
555 }
556 $s_keys =preg_replace("/\,$/","",$s_keys);
557 $s_values =preg_replace("/\,$/","",$s_values);
558 $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");";
559 }
560 foreach($SQL as $sqlsyn){
561 mysql_query($sqlsyn,$res_cur);
562 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$sqlsyn, "Database query");
563 }
564 }
566 @mysql_close($res_cur);
567 }
570 /* Remove initial entry from database
571 * This function checks if there is an entry in the
572 * initial home server that uses this->old_cn or $this->old_tele_number
573 * and removes this entries.
574 * This function is called from save and remove_from parent.
575 *
576 * The parameter '$save' is false if we just
577 * want to check if a remove is possible.
578 * And true if we realy want to remove the entries.
579 */
580 function SQL_remove_me($save)
581 {
582 /* check database access */
583 $str = $this->check_database_accessibility();
584 if($str){
585 return($str);
586 }
588 /* Connect to old database */
589 $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ;
590 $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']);
591 $db_init = @mysql_select_db($cfg_Init['DB'],$r_init);
593 /* Check if there is an old entry */
594 $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';";
595 $res = @mysql_query($query,$r_init);
596 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query");
597 if(!$res){
598 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
599 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
600 }
602 /* There are entries using this cn and/or phone number */
603 if($save && mysql_affected_rows($r_init)) {
604 $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']."
605 WHERE (exten='".$this->old_tele_number."')
606 OR (exten='".$this->old_cn."')";
608 /* Query and ensure that everything went fine */
609 $res = @mysql_query($SQL,$r_init);
610 @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query");
611 if(!$res){
612 new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init));
613 return(msgPool::dbquery("GOfon", @mysql_error($res_cur),$cfg_Init['SERVER']));
614 }
616 }//ENDE old num availiable ...
617 @mysql_close($r_init);
618 return(false);
619 }
623 /* This function checks if the given phonenumbers are available or already in use*/
624 function is_number_used()
625 {
626 $ldap= $this->config->get_ldap_link();
627 $ldap->cd($this->config->current['BASE']);
628 $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid"));
629 while($attrs = $ldap->fetch()) {
630 unset($attrs['telephoneNumber']['count']);
631 foreach($attrs['telephoneNumber'] as $tele){
632 if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn'];
633 if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn'];
634 $numbers[$tele]=$attrs;
635 }
636 }
638 $num = $this->telephoneNumber;
639 if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){
640 if(isset($numbers[$num]['uid'][0])){
641 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['uid'][0]);
642 }else{
643 return sprintf(_("'%s' is already assigned to '%s'!"),$num,$numbers[$num]['cn'][0]);
644 }
645 }
646 }
649 /* Save to LDAP */
650 function save()
651 {
653 if((!isset($this->attrs['goFonPIN']))){
654 $pin_use = false;
655 }else{
656 $pin_use = true;
657 }
659 /* Unset PIN if this is a conference without PIN */
660 if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){
661 $this->goFonPIN = "";
662 }
664 plugin::save();
666 if(empty($this->old_tele_number)){
667 $this->old_tele_number= $this->telephoneNumber;
668 }
670 $this->SQL_add_me(true);
672 if(empty($this->goFonConferenceOption_P)){
673 if($pin_use){
674 $this->attrs['goFonPIN']=array();
675 }else{
676 unset($this->attrs['goFonPIN']);
677 }
678 }
679 $this->attrs['goFonConferenceOption']="";
680 foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s",
681 "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){
682 $this->attrs['goFonConferenceOption'] .= $this->$attrs;
683 unset($this->attrs[$attrs]);
684 }
686 $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime;
687 $this->attrs['goFonConferenceOption'].="|".$this->language;
688 unset($this->attrs['goFonConferenceOptionLifetime']);
690 /* Write back to ldap */
692 unset($this->attrs['base']);
694 $ldap= $this->config->get_ldap_link();
695 $ldap->cd($this->config->current['BASE']);
696 $ldap->cat($this->dn, array('dn'));
698 if ($ldap->count()){
699 $ldap->cd($this->dn);
700 $this->cleanup();
701 $ldap->modify ($this->attrs);
702 $this->handle_post_events('modify');
703 } else {
704 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
705 $ldap->cd($this->dn);
706 $ldap->add($this->attrs);
707 $this->handle_post_events('add');
708 }
710 /* Log last action */
711 if($this->initially_was_account){
712 new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
713 }else{
714 new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
715 }
717 if (!$ldap->success()){
718 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
719 }
721 /* Optionally execute a command after we're done */
722 $this->postcreate();
723 }
726 function getCopyDialog()
727 {
728 $smarty = get_smarty();
729 $smarty->assign("cn" ,$this->cn);
730 $smarty->assign("telephoneNumber" ,$this->telephoneNumber);
731 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
732 $ret = array();
733 $ret['string'] = $str;
734 $ret['status'] = "";
735 return($ret);
736 }
739 function saveCopyDialog()
740 {
741 if(isset($_POST['cn'])){
742 $this->cn = $_POST['cn'];
743 }
744 if(isset($_POST['telephoneNumber'])){
745 $this->telephoneNumber = $_POST['telephoneNumber'];
746 }
747 }
749 function PrepareForCopyPaste($source)
750 {
751 plugin::PrepareForCopyPaste($source) ;
753 $source_o = new conference($this->config,$source['dn']);
755 foreach($this->attributes as $attr){
756 $this->$attr = $source_o->$attr;
757 }
758 }
761 /* Return plugin informations for acl handling */
762 static function plInfo()
763 {
764 return (array(
765 "plShortName" => _("Conference"),
766 "plDescription" => _("Phone conference management"),
767 "plSelfModify" => TRUE,
768 "plDepends" => array(),
769 "plPriority" => 0,
770 "plSection" => array("addons" => _("Addons")),
771 "plCategory" => array("gofonconference" => array("description" => _("GOfon conference"),
772 "objectClass" => "gofonConference")),
774 "plProvidedAcls" => array(
775 "cn" => _("Name"),
776 "base" => _("Base"),
777 "description" => _("Description"),
778 "goFonPIN" => _("Conference PIN"),
780 "goFonHomeServer" => _("Home server"),
781 "goFonConferenceOptionP" => _("Preset PIN"),
782 "goFonConferenceOptionr" => _("Record conference"),
783 "goFonConferenceOptionM" => _("Play music on hold"),
784 "goFonConferenceOptions" => _("Activate menu"),
785 "goFonConferenceOptioni" => _("Announce user activity"),
786 "goFonConferenceOptionc" => _("Count user"),
787 "goFonConferenceOptionD" => _("Conference type"),
789 "goFonConferenceOptionFormat" => _("Format"),
790 "goFonConferenceOptionLifetime" => _("Lifetime"),
791 "telephoneNumber" => _("Telephone number"),
792 "goFonConferenceOwner" => _("Owner"))
793 ));
794 }
797 }
799 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
800 ?>