From 7f927098759cc390e94277e20401c95e75ed66d8 Mon Sep 17 00:00:00 2001 From: cajus Date: Wed, 16 Jan 2008 16:36:42 +0000 Subject: [PATCH] Added subdirectory git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8411 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../conference/class_divListConferences.inc | 317 ++++ .../class_phoneConferenceGeneric.inc | 789 ++++++++ .../class_phoneConferenceManagment.inc | 555 ++++++ gosa-plugins/gofon/conference/generic.tpl | 249 +++ gosa-plugins/gofon/conference/headpage.tpl | 45 + gosa-plugins/gofon/conference/main.inc | 56 + .../gofon/conference/paste_generic.tpl | 23 + gosa-plugins/gofon/conference/remove.tpl | 24 + .../gofon/conference/tabs_conference.inc | 41 + .../gofon/fonreports/class_fonreport.inc | 415 +++++ gosa-plugins/gofon/fonreports/contents.tpl | 59 + gosa-plugins/gofon/fonreports/main.inc | 21 + .../gofon/macro/class_divListMacros.inc | 298 +++ gosa-plugins/gofon/macro/class_gofonMacro.inc | 590 ++++++ .../macro/class_gofonMacroManagement.inc | 555 ++++++ .../macro/class_gofonMacroParameters.inc | 415 +++++ gosa-plugins/gofon/macro/generic.tpl | 83 + gosa-plugins/gofon/macro/headpage.tpl | 51 + gosa-plugins/gofon/macro/main.inc | 61 + gosa-plugins/gofon/macro/parameter.tpl | 28 + gosa-plugins/gofon/macro/paste_generic.tpl | 9 + gosa-plugins/gofon/macro/remove.tpl | 23 + gosa-plugins/gofon/macro/tabs_macros.inc | 40 + .../gofon/phoneaccount/class_phoneAccount.inc | 1644 +++++++++++++++++ gosa-plugins/gofon/phoneaccount/generic.tpl | 131 ++ gosa-plugins/gofon/phoneaccount/main.inc | 126 ++ .../gofon/phoneaccount/paste_generic.tpl | 55 + 27 files changed, 6703 insertions(+) create mode 100644 gosa-plugins/gofon/conference/class_divListConferences.inc create mode 100644 gosa-plugins/gofon/conference/class_phoneConferenceGeneric.inc create mode 100644 gosa-plugins/gofon/conference/class_phoneConferenceManagment.inc create mode 100644 gosa-plugins/gofon/conference/generic.tpl create mode 100644 gosa-plugins/gofon/conference/headpage.tpl create mode 100644 gosa-plugins/gofon/conference/main.inc create mode 100644 gosa-plugins/gofon/conference/paste_generic.tpl create mode 100644 gosa-plugins/gofon/conference/remove.tpl create mode 100644 gosa-plugins/gofon/conference/tabs_conference.inc create mode 100644 gosa-plugins/gofon/fonreports/class_fonreport.inc create mode 100644 gosa-plugins/gofon/fonreports/contents.tpl create mode 100644 gosa-plugins/gofon/fonreports/main.inc create mode 100644 gosa-plugins/gofon/macro/class_divListMacros.inc create mode 100644 gosa-plugins/gofon/macro/class_gofonMacro.inc create mode 100644 gosa-plugins/gofon/macro/class_gofonMacroManagement.inc create mode 100644 gosa-plugins/gofon/macro/class_gofonMacroParameters.inc create mode 100644 gosa-plugins/gofon/macro/generic.tpl create mode 100644 gosa-plugins/gofon/macro/headpage.tpl create mode 100644 gosa-plugins/gofon/macro/main.inc create mode 100644 gosa-plugins/gofon/macro/parameter.tpl create mode 100644 gosa-plugins/gofon/macro/paste_generic.tpl create mode 100644 gosa-plugins/gofon/macro/remove.tpl create mode 100644 gosa-plugins/gofon/macro/tabs_macros.inc create mode 100644 gosa-plugins/gofon/phoneaccount/class_phoneAccount.inc create mode 100644 gosa-plugins/gofon/phoneaccount/generic.tpl create mode 100644 gosa-plugins/gofon/phoneaccount/main.inc create mode 100644 gosa-plugins/gofon/phoneaccount/paste_generic.tpl diff --git a/gosa-plugins/gofon/conference/class_divListConferences.inc b/gosa-plugins/gofon/conference/class_divListConferences.inc new file mode 100644 index 000000000..cdcdcbc9d --- /dev/null +++ b/gosa-plugins/gofon/conference/class_divListConferences.inc @@ -0,0 +1,317 @@ +parent = $parent; + $this->ui = get_userinfo(); + + /* Set list strings */ + $this->SetTitle(_("List of conference rooms")); + $this->SetSummary(_("List of conference rooms")); + + /* Result page will look like a headpage */ + $this->SetHeadpageMode(); + $this->SetInformation(_("This menu allows you to create, delete and edit selected phone conferences. Having a large number of phone conferences, you might prefer the range selectors on top of the conferences list.")); + + $this->EnableAplhabet(true); + + /* Disable buttonsm */ + $this->EnableCloseButton(false); + $this->EnableSaveButton (false); + + /* Dynamic action col, depending on snapshot icons */ + $action_col_size = 100; + if($this->parent->snapshotEnabled()){ + $action_col_size += 20; + } + + /* Toggle all selected / deselected */ + $chk = ""; + + /* set Page header */ + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" =>_("Name - Number"), "attach" => "style=''")); + $this->AddHeader(array("string" => _("Owner"), "attach" => "style='width:200px;'")); + $this->AddHeader(array("string" => _("PIN"), "attach" => "style='width:50px;'")); + $this->AddHeader(array("string" =>_("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'")); + + /* Add Checkboxes / SubSearch checkbox */ + $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false); + + /* Name ,Text ,Default , Connect with alphabet */ + $this->AddRegex ("Regex", _("Regular expression for matching conference names"),"*" , true); + } + + + function GenHeader() + { + /* Prepare departments, + which are shown in the listbox on top of the listbox + */ + $options= ""; + + /* Get all departments within this subtree */ + $base = $this->config->current['BASE']; + + /* Add base */ + $tmp = array(); + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + $deps = array(); + foreach($tmp as $tm){ + $deps[$tm['dn']] = $tm['dn']; + } + + /* Load possible departments */ + $ui= get_userinfo(); + $tdeps= $ui->get_module_departments("gofonconference"); + $ids = $this->config->idepartments; + $first = ""; + $found = FALSE; + foreach($ids as $dep => $name){ + if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){ + + /* Keep first base dn in mind, we could need this + * info if no valid base was found + */ + if(empty($first)) { + $first = $dep['dn']; + } + + $value = $ids[$dep]; + if ($this->selectedBase == $dep){ + $found = TRUE; + $options.= ""; + } else { + $options.= ""; + } + } + } + + /* The currently used base is not visible with your acl setup. + * Set base to first useable base. + */ + if(!$found){ + $this->selectedBase = $first; + } + + /* Get acls */ + $acls = $ui->get_permissions($this->selectedBase,"gofonconference/conference"); + $acl_all = $ui->has_complete_category_acls($this->selectedBase,"gofonconference") ; + + /* Add default header */ + $listhead = MultiSelectWindow::get_default_header(); + + /* Add the rest (base select ....)*/ + $listhead .= _("Base")." ". + "  "; + + /* Create Layers menu */ + $s = ".|"._("Actions")."|\n"; + $s .= "..|". + " "._("Create")."|\n"; + + /* Append create options */ + if(preg_match("/(c.*w|w.*c)/",$acl_all)){ + $s.= "...|". + " "._("Conference")."|conference_new|\n"; + } + + /* Multiple options */ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Remove")."|"."remove_multiple|\n"; + + /* Add multiple copy & cut icons */ + if(is_object($this->parent->CopyPasteHandler)){ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Copy")."|"."multiple_copy_systems|\n"; + $s.= "..|". + " "._("Cut")."|"."multiple_cut_systems|\n"; + + if($this->parent->CopyPasteHandler->entries_queued()){ + $img = ""; + $s.="..|".$img." "._("Paste")."|editPaste|\n"; + }else{ + $img = ""; + $s.="..|".$img." "._("Paste")."\n"; + } + } + + /* Add snapshot icons */ + if(preg_match("/(c.*w|w.*c)/",$acls)){ + $s .= "..|---|\n"; + $s .= $this->get_snapshot_header(TRUE); + } + + $this->SetDropDownHeaderMenu($s); + $this->SetListHeader($listhead); + } + + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + } + + function setEntries($list) + { + $linkopen= "%s"; + + $userimg = "User"; + $editlink = "%s"; + + /* Dynamic action col, depending on snapshot icons */ + $action_col_size = 100; + if($this->parent->snapshotEnabled()){ + $action_col_size += 20; + } + + /* Insert conferneces*/ + foreach($list as $conferencekey => $conference ){ + + $acl = $this->ui->get_permissions($conference['dn'],"gofonconference/conference"); + $acl_all = $this->ui->has_complete_category_acls($conference['dn'],"gofonconference"); + + /* You will need at least read access for the + current conference informations to display it */ + if(!preg_match("/r/",$acl)){ + continue; + } + + $actions =""; + if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$acl_all)){ + $actions.= " "; + $actions.= " "; + } + + /* Add edit icon - This is allowed when we have at least read access. */ + $actions.= ""; + + /* Add snapshot icon - This is allowed when we have create and write access for the current entry */ + if(preg_match("/(c.*w|w.*c)/",$acl_all)){ + $actions.= $this->GetSnapShotActions($conference['dn']); + } + + /* Create delete link - Only if we are allowed to delete this entry */ + if(preg_match("/d/",$acl)){ + $actions.= ""; + } + + /* Display PIN icon, only if we are the owner of the given conference */ + $owner = $this->parent->ui->dn==$conference['goFonConferenceOwner'][0]; + $p_acl = $this->ui->get_permissions($conference['dn'],"gofonconference/conference","goFonPIN"); + if((isset($conference['goFonPIN'][0])) && $owner && preg_match("/r/",$p_acl)){ + $pin = "PIN"; + }else{ + $pin = " "; + } + + /* Display numer of the conference if we are allowed to view it */ + $n_acl = $this->ui->get_permissions($conference['dn'],"gofonconference/conference","telephoneNumber"); + if(isset($conference['telephoneNumber'][0]) && preg_match("/r/",$n_acl)){ + $number = " - ".$conference['telephoneNumber'][0]; + }else{ + $number = "  - ?"; + } + + /* Get conference owner name */ + $ldap= $this->parent->config->get_ldap_link(); + $ldap->cat($conference['goFonConferenceOwner'][0], array('cn')); + $data = $ldap->fetch(); + if(isset($data['cn'][0])){ + $cn = $data['cn'][0]; + }else{ + $cn = _("Unknown"); + } + + /* Create title */ + $title = " title='".preg_replace("/ /"," ",@LDAP::fix($data['dn']))."' "; + + /* Cutted objects should be displayed in light grey */ + $display = $conference['cn'][0].$number; + if($this->parent->CopyPasteHandler){ + foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){ + if($queue_data['dn'] == $conference['dn']) { + $display = "".$display.""; + break; + } + } + } + + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $a_field1 = array("string"=>sprintf($userimg,_("Conference")), "attach" => $title." style='text-align:center;width:20px;'"); + $a_field2 = array("string"=>sprintf($editlink,$conferencekey,$display), "attach" => $title." style=''"); + $a_field3 = array("string"=> $cn , "attach" => $title." style='width:200px;'"); + $a_field4 = array("string"=> $pin, "attach" => $title." style='width:50px;'"); + $a_field5 = array("string"=> preg_replace("/%KEY%/",$conferencekey,$actions), + "attach"=> $title."style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); + + $this->AddElement(array($field0,$a_field1,$a_field2,$a_field3,$a_field4,$a_field5)); + } + + /* Create summary string for list footer */ + $num_deps=0; + if(!$this->SubSearch){ + $num_deps = count($this->Added_Departments); + } + $num_objs = count($list); + + $num_obj_str = _("Number of listed conferences"); + $num_dep_str = _("Number of listed departments"); + + $str = "".$num_obj_str." ".$num_objs."    "; + $str.= "".$num_dep_str." ".$num_deps."    "; + + $this->set_List_Bottom_Info($str); + } + + function Save() + { + MultiSelectWindow :: Save(); + } + + function save_object() + { + /* Save automatic created POSTs like regex, checkboxes */ + MultiSelectWindow :: save_object(); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/conference/class_phoneConferenceGeneric.inc b/gosa-plugins/gofon/conference/class_phoneConferenceGeneric.inc new file mode 100644 index 000000000..cd6c84aa9 --- /dev/null +++ b/gosa-plugins/gofon/conference/class_phoneConferenceGeneric.inc @@ -0,0 +1,789 @@ +is_account = TRUE; + $this->ui = get_userinfo(); + $this->orig_dn = $dn; + + $this->languages= get_languages(TRUE,TRUE); + + + /* Check server configurations + * Load all server configuration in $this->goFonHomeServers if available + * and use first server as default if necessary. + */ + $a_SETUP= array(); + $config = session::get('config'); + if(isset($config->data['SERVERS']['FON']) && is_callable("mysql_connect")) { + + /* Set available server */ + $this->goFonHomeServers = $config->data['SERVERS']['FON']; + + /* Set default server */ + if($this->dn == "new"){ + $this->goFonHomeServer = $this->goFonHomeServers[0]['DN']; + } + + /* Remember inital home server, to be able to remove old entries */ + $this->init_HomeServer = $this->goFonHomeServer; + + /* get config */ + if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){ + print_red(sprintf(_("The specified home server '%s' is not available in GOsa server configuration. Saving this account will create a new entry on the server '%s'. Use cancel if you do not want to create a new entry while ignoring old accounts."),$this->goFonHomeServer, $this->goFonHomeServers[0]['DN'])); + + $this->goFonHomeServer = $this->goFonHomeServers[0]['DN']; + $this->init_HomeServer = $this->goFonHomeServers[0]['DN']; + } + $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer]; + } + + /* Set base */ + if ($this->dn == "new"){ + $ui= get_userinfo(); + if(session::is_set('CurrentMainBase')){ + $this->base = session::get('CurrentMainBase'); + }else{ + $this->base= dn2base($ui->dn); + } + } else { + + /* Get base */ + $this->base = preg_replace ("/^[^,]+,".normalizePreg(get_ou('conferenceou'))."/i","",$this->dn);; + } + + $this->goFonConferenceOwner=$this->ui->dn; + + /* Parse Options ... + * Parameter|Lifetime|number + */ + if($this->dn!="new"){ + $tmp1= split("\|",$this->attrs['goFonConferenceOption'][0]); + + for($i = 0 ; $i < strlen($tmp1[0]);$i++){ + $varname = "goFonConferenceOption_".$tmp1[0][$i]; + if($tmp1[0][$i]=="d"){ + $this->goFonConferenceOption_D = $tmp1[0][$i]; + }else{ + $this->$varname = $tmp1[0][$i]; + } + } + + $this->goFonConferenceOptionLifetime = $tmp1[1]; + if(isset($tmp1[2]) && isset($this->languages[$tmp1[2]])){ + $this->language = $tmp1[2]; + } + + $this->old_tele_number = $this->telephoneNumber; + } + $this->old_dn = $this->dn; + $this->old_cn = $this->cn; + $this->old_base = $this->base; + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Log last action */ + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","gofonconference/".get_class($this),$this->dn); + } + + $smarty= get_smarty(); + + $smarty->assign("bases" ,$this->config->idepartments); + $smarty->assign("base" ,$this->base); + + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){ + $once = false; + $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases()); + $this->dialog->setCurrentBase($this->base); + } + } + + /* Dialog handling */ + if(is_object($this->dialog)){ + /* Must be called before save_object */ + $this->dialog->save_object(); + + if($this->dialog->isClosed()){ + $this->dialog = false; + }elseif($this->dialog->isSelected()){ + $tmp = $this->get_allowed_bases(); + if(isset($tmp[$this->dialog->isSelected()])){ + $this->base = $this->dialog->isSelected(); + } + $this->dialog= false; + }else{ + return($this->dialog->execute()); + } + } + + foreach ($this->attributes as $val){ + $smarty->assign("$val", $this->$val); + if(!$this->$val){ + $smarty->assign($val."CHK", ""); + }else{ + $smarty->assign($val."CHK", " checked "); + } + } + + /* Create array with goFonHomeServer */ + $tmp = array(); + foreach($this->goFonHomeServers as $dn => $val){ + if(!is_numeric($dn)){ + $tmp[$dn] = $val['SERVER']; + } + } + $smarty->assign("language",$this->language); + $smarty->assign("languages",$this->languages); + $smarty->assign("goFonHomeServers",$tmp); + $smarty->assign("goFonConferenceOptions", array("D"=>"Conference ","d"=>"Conference without PIN")); + $smarty->assign("goFonConferenceOptionFormats", array("WAV"=>"Wave","GSM"=>"GSM","WAV49"=>"Wave49")); + $smarty->assign("goFonConferenceOption", $this->goFonConferenceOption_D); + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + if($this->acl_is_writeable("base")){ + $smarty->assign("baseSelect",true); + }else{ + $smarty->assign("baseSelect",false); + } + + $smarty->assign("bases" ,$this->get_allowed_bases()); + $smarty->assign("base_select" ,$this->base); + + + if(session::get('js')==1){ + if($this->goFonConferenceOption_P != "P"){ + $smarty->assign("goFonPINACL", $this->getacl("goFonPIN",TRUE)); + $smarty->assign("goFonPIN",""); + } + if($this->goFonConferenceOption_r != "r"){ + $smarty->assign("goFonConferenceOptionFormatACL", $this->getacl("goFonConferenceOptionr",TRUE)); + } + } + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); + } + + + function remove_from_parent() + { + /* Check if 'old' home server is available in gosa FON server configuration + * Try to remove this entry from database and display errors. + */ + if(isset($this->goFonHomeServers[$this->goFonHomeServer])){ + $str = $this->SQL_remove_me(true); + if($str){ + print_red($str); + return false; + } + }else{ + print_red(_("Could not remove the conference entry from database on home server (%s). Please check your asterisk database configuration.")); + return false; + } + + /* Remove ldap entry */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->recursive_remove(); + + new log("remove","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + + /* Optionally execute a command after we're done */ + $this->handle_post_events('remove'); + } + + + /* Save data to object */ + function save_object() + { + if(isset($_POST['phoneConferenceGeneric'])){ + + /* Get selected language */ + if(isset($_POST['language']) && isset($this->languages[get_post('language')])){ + $this->language = get_post('language'); + } + + /* Create a base backup and reset the + base directly after calling plugin::save_object(); + Base will be set seperatly a few lines below */ + $base_tmp = $this->base; + plugin::save_object(); + $this->base = $base_tmp; + + /* Save base, since this is no LDAP attribute */ + $tmp = $this->get_allowed_bases(); + if(isset($_POST['base'])){ + if(isset($tmp[$_POST['base']])){ + $this->base= $_POST['base']; + } + } + foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s", + "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){ + + /* Acl can't contain _ so we remove it here. */ + $acl_name = preg_replace("/_/","",$attrs); + + if($this->acl_is_writeable($acl_name)){ + + if(isset($_POST[$attrs])){ + $this->$attrs = $_POST[$attrs]; + }else{ + $this->$attrs = false; + } + } + } + } + } + + + function check_database_accessibility() + { + /* Check if mysql extension is available */ + if(!is_callable("mysql_pconnect")){ + return(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup.")); + } + + /******************** + * Check currently selected home server + ********************/ + + $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer]; + $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']); + if(!$r_current){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current)); + + return(sprintf(_("The MySQL home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."), + $cfg_Current['SERVER'],$cfg_Current['LOGIN'])); + } + $db_current = @mysql_select_db($cfg_Current['DB'],$r_current); + if(!$db_current){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_current)); + mysql_close($r_current); + return( sprintf(_("Can't select database '%s' on home server '%s'."),$cfg_Current['DB'],$cfg_Current['SERVER'])); + } + + /******************** + * Check init home server + ********************/ + + if($this->goFonHomeServers != $this->init_HomeServer){ + $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ; + $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']); + if(!$r_init){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init)); + + return(sprintf(_("The MySQL initial home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."), + $cfg_Init['SERVER'],$cfg_Init['LOGIN'])); + } + $db_init = @mysql_select_db($cfg_Init['DB'],$r_init); + if(!$db_init){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init)); + mysql_close($r_init); + return( sprintf(_("Can't select database '%s' on initial home server '%s'."),$cfg_Init['DB'],$cfg_Init['SERVER'])); + } + } + } + + /* Check values */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if($this->is_number_used()){ + $message[] = $this->is_number_used(); + } + + /* Check if previously selected server is still available */ + if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){ + $message[]= sprintf(_("The previously selected asterisk home server (%s) is no longer available."),preg_replace("/,/",", ",$this->goFonHomeServer)); + return($message); + } + + if((empty($this->goFonPIN))&&($this->goFonConferenceOption_P=="P")&&($this->goFonConferenceOption_D=="D")){ + $message[]= _("Please enter a PIN."); + } + + if(empty($this->cn)){ + $message[] =_("Please enter a name for the conference."); + } + + if(!is_numeric($this->telephoneNumber)){ + $message[] =_("Only numeric chars are allowed in Number field."); + } + + if(!((is_numeric($this->goFonConferenceOptionLifetime))||(empty($this->goFonConferenceOptionLifetime)))){ + $message[] =_("Only numbers are allowed in Lifetime."); + } + + /* Check if add could be successful */ + $str = $this->SQL_add_me(false); + if(!empty($str)){ + $message[] = $str; + } + + if($this->old_cn != $this->cn || $this->base != $this->old_base){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd(get_ou('conferenceou').$this->base); + $ldap->search("(&(objectClass=goFonConference)(cn=".$this->cn."))",array("cn")); + if($ldap->count()){ + $message[] =_("There is already a conference with this name in the current tree."); + } + } + return $message; + } + + + function SQL_add_me($save) + { + /* Check if there is at least on server configuration */ + if(!count($this->goFonHomeServers)){ + return( _("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.")); + } + + /******************** + * Get configuration and try to connect + ********************/ + + /* Check if databases are reachable, returns an error string if anything fails */ + $error_str = $this->check_database_accessibility(); + if($error_str){ + return($error_str); + } + + /* Remove old entries, returns an error string if anything fails */ + $error_str = $this->SQL_remove_me($save); + if($error_str){ + return($error_str); + } + + /* Connect to current database to be able to add new entries */ + $cfg_Current = $this->goFonHomeServers[$this->goFonHomeServer] ; + $res_cur = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']); + $db_cur = @mysql_select_db($cfg_Current['DB'],$res_cur); + + /******************** + * Remove entries that could cause trouble + ********************/ + + /* If the current home server is different to the initial home server, + * there may be already some entries with the given telephoneNumber and/or cn. + * We must remove those entries to avoid duplicate use of the same extension name. + */ + if($this->goFonHomeServer != $this->init_HomeServer){ + $query = "SELECT id FROM ".$cfg_Current['EXT_TABLE']." WHERE exten='".$this->telephoneNumber."' OR exten='".$this->cn."';"; + $res = @mysql_query($query,$res_cur); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(!$res){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur)); + return(_("Can not check if there are already some entries with given telephone number and/or cn in the destination home server."). + " "._("Please have a look a the gosa logfiles.")); + } + if($save && mysql_affected_rows($res_cur)) { + $SQL = "DELETE FROM ".$cfg_Current['EXT_TABLE']." + WHERE (exten='".$this->telephoneNumber."') + OR (exten='".$this->cn."')"; + + /* Query and ensure that everything went fine */ + $res = @mysql_query($SQL,$res_cur); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query"); + if(!$res){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($res_cur)); + return(_("Can not remove entries with some telephone number and/or cn from destination home server."). + " "._("Please have a look a the gosa logfiles.")); + } + } + } + + /******************** + * Add new conference entry + ********************/ + if((!empty($this->telephoneNumber))&&($save==true)){ + + /* Create string out of conference Flags */ + $parameter =""; + foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s", + "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D") as $attrs){ + $parameter .= $this->$attrs; + } + + $i=1; + $EXT=array(); + $context="GOsa"; + // Set Language to German + $EXT[$i]['exten'] =$this->telephoneNumber; + $EXT[$i]['context'] = $context; + $EXT[$i]['priority']= $i; + $EXT[$i]['app'] ="SetLanguage"; + $EXT[$i]['appdata'] =$this->language; + $i++; + + if($this->goFonConferenceOption_r == "r"){ + + // Recordingformat for conference + $EXT[$i]['exten'] =$this->telephoneNumber; + $EXT[$i]['context'] =$context; + $EXT[$i]['priority']= $i; + $EXT[$i]['app'] ="Setvar"; + $EXT[$i]['appdata'] ="MEETME_RECORDINGFORMAT=".$this->goFonConferenceOptionFormat; + $i++; + + } + + // Answer Call + $EXT[$i]['exten'] =$this->telephoneNumber; + $EXT[$i]['context'] =$context; + $EXT[$i]['priority']=$i; + $EXT[$i]['app'] ="answer"; + $EXT[$i]['appdata'] =""; + $i++; + + // Start Conference + $EXT[$i]['exten'] =$this->telephoneNumber; + $EXT[$i]['context'] =$context; + $EXT[$i]['priority']=$i; + $EXT[$i]['app'] ="MeetMe"; + + if(empty($this->goFonPIN)) { + $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter; + }else{ + $EXT[$i]['appdata'] =$this->telephoneNumber."|".$parameter."|".$this->goFonPIN; + } + $i++; + + // Start Conference + $EXT[$i]['exten'] =$this->cn; + $EXT[$i]['context'] =$context; + $EXT[$i]['priority']=1; + $EXT[$i]['app'] ="Goto"; + $EXT[$i]['appdata'] =$this->telephoneNumber."|1"; + $SQL=array(); + + foreach($EXT as $keytop => $valtop){ + $s_keys = ""; + $s_values = ""; + foreach($valtop as $key=>$val){ + $s_keys .="`".$key."`,"; + $s_values .="'".$val."',"; + } + $s_keys =preg_replace("/\,$/","",$s_keys); + $s_values =preg_replace("/\,$/","",$s_values); + $SQL[]="INSERT INTO ".$cfg_Current['EXT_TABLE']." (".$s_keys.") VALUES (".$s_values.");"; + } + foreach($SQL as $sqlsyn){ + mysql_query($sqlsyn,$res_cur); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$sqlsyn, "Database query"); + } + } + + @mysql_close($res_cur); + } + + + /* Remove initial entry from database + * This function checks if there is an entry in the + * initial home server that uses this->old_cn or $this->old_tele_number + * and removes this entries. + * This function is called from save and remove_from parent. + * + * The parameter '$save' is false if we just + * want to check if a remove is possible. + * And true if we realy want to remove the entries. + */ + function SQL_remove_me($save) + { + /* check database access */ + $str = $this->check_database_accessibility(); + if($str){ + return($str); + } + + /* Connect to old database */ + $cfg_Init = $this->goFonHomeServers[$this->init_HomeServer] ; + $r_init = @mysql_pconnect($cfg_Init['SERVER'],$cfg_Init['LOGIN'],$cfg_Init['PASSWORD']); + $db_init = @mysql_select_db($cfg_Init['DB'],$r_init); + + /* Check if there is an old entry */ + $query = "SELECT id FROM ".$cfg_Init['EXT_TABLE']." WHERE exten='".$this->old_tele_number."' OR exten='".$this->old_cn."';"; + $res = @mysql_query($query,$r_init); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(!$res){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init)); + return(_("Can not check if entry exists in old database. Please have a look a the gosa logfiles.")); + } + + /* There are entries using this cn and/or phone number */ + if($save && mysql_affected_rows($r_init)) { + $SQL = "DELETE FROM ".$cfg_Init['EXT_TABLE']." + WHERE (exten='".$this->old_tele_number."') + OR (exten='".$this->old_cn."')"; + + /* Query and ensure that everything went fine */ + $res = @mysql_query($SQL,$r_init); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$SQL, "Database query"); + if(!$res){ + new log("debug","gofonconference/".get_class($this),"",array(),@mysql_error($r_init)); + return(_("Can not remove old entries from initial home server. Please have a look a the gosa logfiles.")); + } + + }//ENDE old num availiable ... + @mysql_close($r_init); + return(false); + } + + + + /* This function checks if the given phonenumbers are available or already in use*/ + function is_number_used() + { + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid")); + while($attrs = $ldap->fetch()) { + unset($attrs['telephoneNumber']['count']); + foreach($attrs['telephoneNumber'] as $tele){ + if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn']; + if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn']; + $numbers[$tele]=$attrs; + } + } + + $num = $this->telephoneNumber; + if((isset($numbers[$num]))&&(($numbers[$num]['cn'][0]!=$this->old_cn))){ + if(isset($numbers[$num]['uid'][0])){ + return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]); + }else{ + return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]); + } + } + } + + + /* Save to LDAP */ + function save() + { + + if((!isset($this->attrs['goFonPIN']))){ + $pin_use = false; + }else{ + $pin_use = true; + } + + /* Unset PIN if this is a conference without PIN */ + if((!empty($this->goFonPIN)||($this->goFonConferenceOption_P=="P"))&&($this->goFonConferenceOption_D=="d")){ + $this->goFonPIN = ""; + } + + plugin::save(); + + if(empty($this->old_tele_number)){ + $this->old_tele_number= $this->telephoneNumber; + } + + $this->SQL_add_me(true); + + if(empty($this->goFonConferenceOption_P)){ + if($pin_use){ + $this->attrs['goFonPIN']=array(); + }else{ + unset($this->attrs['goFonPIN']); + } + } + $this->attrs['goFonConferenceOption']=""; + foreach(array("goFonConferenceOption_P","goFonConferenceOption_r","goFonConferenceOption_M","goFonConferenceOption_s", + "goFonConferenceOption_i","goFonConferenceOption_c","goFonConferenceOption_D","goFonConferenceOptionFormat") as $attrs){ + $this->attrs['goFonConferenceOption'] .= $this->$attrs; + unset($this->attrs[$attrs]); + } + + $this->attrs['goFonConferenceOption'].="|".$this->goFonConferenceOptionLifetime; + $this->attrs['goFonConferenceOption'].="|".$this->language; + unset($this->attrs['goFonConferenceOptionLifetime']); + + /* Write back to ldap */ + + unset($this->attrs['base']); + + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->cat($this->dn, array('dn')); + + if ($ldap->count()){ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + $this->handle_post_events('modify'); + } else { + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + $this->handle_post_events('add'); + } + + /* Log last action */ + if($this->initially_was_account){ + new log("modify","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + }else{ + new log("create","gofonconference/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + } + + show_ldap_error($ldap->get_error(), sprintf(_("Saving of goFonConference/generic with dn '%s' failed."),$this->dn)); + + /* Optionally execute a command after we're done */ + $this->postcreate(); + } + + + function getCopyDialog() + { + $smarty = get_smarty(); + $smarty->assign("cn" ,$this->cn); + $smarty->assign("telephoneNumber" ,$this->telephoneNumber); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } + if(isset($_POST['telephoneNumber'])){ + $this->telephoneNumber = $_POST['telephoneNumber']; + } + } + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source) ; + + $source_o = new conference($this->config,$source['dn']); + + foreach($this->attributes as $attr){ + $this->$attr = $source_o->$attr; + } + } + + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Conference"), + "plDescription" => _("Phone conference management"), + "plSelfModify" => TRUE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("addons" => _("Addons")), + "plCategory" => array("gofonconference" => array("description" => _("GOfon conference"), + "objectClass" => "gofonConference")), + + "plProvidedAcls" => array( + "cn" => _("Name"), + "base" => _("Base"), + "description" => _("Description"), + "goFonPIN" => _("Conference PIN"), + + "goFonHomeServer" => _("Home server"), + "goFonConferenceOptionP" => _("Preset PIN"), + "goFonConferenceOptionr" => _("Record conference"), + "goFonConferenceOptionM" => _("Play music on hold"), + "goFonConferenceOptions" => _("Activate menu"), + "goFonConferenceOptioni" => _("Announce user activity"), + "goFonConferenceOptionc" => _("Count user"), + "goFonConferenceOptionD" => _("Conference type"), + + "goFonConferenceOptionFormat" => _("Format"), + "goFonConferenceOptionLifetime" => _("Lifetime"), + "telephoneNumber" => _("Telephone number"), + "goFonConferenceOwner" => _("Owner")) + )); + } + + +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/conference/class_phoneConferenceManagment.inc b/gosa-plugins/gofon/conference/class_phoneConferenceManagment.inc new file mode 100644 index 000000000..50b4b241b --- /dev/null +++ b/gosa-plugins/gofon/conference/class_phoneConferenceManagment.inc @@ -0,0 +1,555 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $attributes = array(); + var $objectclasses = array(); + + var $conferences = array(); + var $conftab = false; + var $ui = NULL; + var $DivListConference = NULL; + + var $CopyPasteHandler = NULL; + var $start_pasting_copied_objects = FALSE; + + /* Initialise Class */ + function phoneConferenceManagment (&$config, $ui) + { + $this->ui = $ui; + $this->dn = ""; + $this->config = $config; + $this->DivListConference = new divListConference($this->config,$this); + + /* Copy & Paste enabled ?*/ + if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){ + $this->CopyPasteHandler = new CopyPasteHandler($this->config); + } + } + + + /* Execute class and display something */ + function execute() + { + /* Call parent execute */ + plugin::execute(); + + session::set('LOCK_VARS_TO_USE',array("/^id$/","/^act$/","/^conference_/","/^item_selected/","/^remove_multiple_conferences/")); + + /*************** + Variable initialisation + ***************/ + + /* Reload departments */ + $smarty = get_smarty(); + $display = ""; + $s_action = ""; // Will contain an action, like del or edit + $s_entry = ""; // The entry name for edit delete -... + + + /*************** + Check posts + ***************/ + + foreach($_POST as $key => $post){ + if(preg_match("/^conference_new.*/i",$key)){ + $s_action = "new"; + // Post for delete + }elseif(preg_match("/^conference_del.*/",$key)){ + $s_action = "del"; + $s_entry = preg_replace("/^conference_del_/i","",$key); + $s_entry = preg_replace("/_.*$/","",$s_entry); + // Post for edit + }elseif(preg_match("/conference_edit_.*/",$key)){ + $s_action="edit"; + $s_entry = preg_replace("/conference_edit_/i","",$key); + $s_entry = preg_replace("/_.*$/","",$s_entry); + }elseif(preg_match("/^remove_multiple_conferences/",$key)){ + $s_action="del_multiple"; + }elseif(preg_match("/^editPaste.*/i",$key)){ + $s_action="editPaste"; + }elseif(preg_match("/^copy_.*/",$key)){ + $s_action="copy"; + $s_entry = preg_replace("/^copy_/i","",$key); + $s_entry = preg_replace("/_.$/","",$s_entry); + }elseif(preg_match("/^cut_.*/",$key)){ + $s_action="cut"; + $s_entry = preg_replace("/^cut_/i","",$key); + $s_entry = preg_replace("/_.$/","",$s_entry); + }elseif(preg_match("/^multiple_copy_objects/",$key)){ + $s_action = "copy_multiple"; + }elseif(preg_match("/^multiple_cut_objects/",$key)){ + $s_action = "cut_multiple"; + } + } + + /* Edit Entry */ + if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){ + $s_action = "edit"; + $s_entry = $_GET['id']; + } + + /* handle C&P from layers menu */ + if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){ + $s_action = "copy_multiple"; + } + if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){ + $s_action = "cut_multiple"; + } + if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){ + $s_action = "editPaste"; + } + + /* Create options */ + if(isset($_POST['menu_action']) && $_POST['menu_action'] == "conference_new"){ + $s_action = "new"; + } + + /* handle remove from layers menu */ + if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){ + $s_action = "del_multiple"; + } + + + /*************** + Cancel dialogs + ***************/ + + /* Reset requested? */ + if (isset($_POST['edit_cancel'])){ + if (isset($this->conftab)){ + del_lock ($this->conftab->dn); + unset ($this->conftab); + } + $this->conftab= NULL; + $this->lognames= array();; + $this->cn= ""; + session::un_set('objectinfo'); + } + + + /******************** + Copy & Paste Handling ... + ********************/ + + /* Display the copy & paste dialog, if it is currently open */ + $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry); + if($ret){ + return($ret); + } + + + /******************** + Delete MULTIPLE entries requested, display confirm dialog + ********************/ + + if ($s_action=="del_multiple"){ + $ids = $this->list_get_selected_items(); + + if(count($ids)){ + + foreach($ids as $id){ + $dn = $this->conferences[$id]['dn']; + if (($user= get_lock($dn)) != ""){ + return(gen_locked_message ($user, $dn)); + } + $this->dns[$id] = $dn; + } + + $dns_names = "
";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="
"; + + /* Lock the current entry, so nobody will edit it during deletion */ + $smarty->assign("info", sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names))); + $smarty->assign("multiple", true); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + + /******************** + Delete MULTIPLE entries confirmed + ********************/ + + /* Confirmation for deletion has been passed. Users should be deleted. */ + if (isset($_POST['delete_multiple_conference_confirm'])){ + + /* Remove user by user and check acls before removeing them */ + foreach($this->dns as $key => $dn){ + $this->dn = $dn; + $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); + if(preg_match("/d/",$acl)){ + $this->remove_from_parent(); + } else { + print_red (_("You have no permission to remove this department.")); + } + /* Remove lock file after successfull deletion */ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /******************** + Delete MULTIPLE entries Canceled + ********************/ + + /* Remove lock */ + if(isset($_POST['delete_multiple_conference_cancel'])){ + foreach($this->dns as $key => $dn){ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /*************** + Delete + ***************/ + + /* Delete Entry if Posted action (s_action) == del + * The entry which will be deleted is defined in $s_entry + */ + if ($s_action =="del"){ + + $acl = $this->ui->get_permissions($this->conferences[$s_entry]['dn'],"gofonconference/conference"); + if(preg_match("/d/",$acl)){ + $this->dn= $this->conferences[$s_entry]['dn']; + + /* Check locking */ + if (($conf= get_lock($this->dn)) != ""){ + session::set('dn',$this->dn); + return(gen_locked_message($conf, $this->dn)); + } else { + add_lock ($this->dn, $this->ui->dn); + $smarty->assign("info", sprintf(_("You're about to delete the whole LDAP subtree placed under '%s'."), $this->dn)); + $smarty->assign("multiple", false); + $display.= $smarty->fetch (get_template_path('remove.tpl', TRUE)); + return ($display); + } + } + } + + + /*************** + Delete confirmed + ***************/ + + /* If department deletion is accepted ... + * Finally delete department + */ + if (isset($_POST['delete_department_confirm'])){ + $acl = $this->ui->get_permissions($this->dn,"gofonconference/conference"); + if(preg_match("/d/",$acl)){ + $this->remove_from_parent(); + } else { + print_red (_("You have no permission to remove this department.")); + } + } + + + /*************** + Edit + ***************/ + + /* Edit Entry if Posted action (s_action) == edit + * The entry which will be edited is defined in $s_entry + */ + if (($s_action=="edit") && (!isset($this->conftab->config))){ + + $this->dn= $this->conferences[$s_entry]['dn']; + + if (($conf= get_lock($this->dn)) != ""){ + return(gen_locked_message ($conf, $this->dn)); + } + + /* Lock the current entry, so everyone will get the above dialog */ + add_lock ($this->dn, $this->ui->dn); + + /* Register conftab to trigger edit dialog */ + $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference"); + $this->conftab->set_acl_base($this->dn); + session::set('objectinfo',$this->dn); + } + + + /*************** + Create new + ***************/ + + /* Insert new entry*/ + if($s_action == "new" ){ + + $dummy_dn = "cn=dummy,".get_ou('conferenceou').$this->DivListConference->selectedBase; + $acl = $this->ui->get_permissions($dummy_dn,"gofonconference/conference"); + if(preg_match("/c/",$acl)){ + /* Set up the users ACL's for this 'dn' */ + $this->dn= "new"; + $this->conftab= new conferencetabs($this->config,$this->config->data['TABS']['CONFERENCETABS'], $this->dn,"gofonconference"); + $this->conftab->set_acl_base($dummy_dn); + session::un_set('objectinfo'); + } + } + + + /*************** + Save entry + ***************/ + + /* Edit finished, check and save changes */ + if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->conftab->config))){ + /* Check tabs, will feed message array */ + $this->conftab->last= $this->conftab->current; + $this->conftab->save_object(); + $message= $this->conftab->check(); + + if (count($message) == 0){ + if($this->conftab->save() == 1){ + gosa_log ("goFonConference object '".$this->dn."' saving failed."); + return; + } + gosa_log ("goFonConference object '".$this->dn."' has been saved"); + + if (!isset($_POST['edit_apply'])){ + if ($this->dn != "new"){ + del_lock ($this->dn); + } + } + + del_lock ($this->conftab->dn);; + unset ($this->conftab); + $this->conftab= NULL; + session::un_set('objectinfo'); + } else { + show_errors($message); + } + } + + + /*************** + Display dialogs + ***************/ + + /* if edit or new, show dialog */ + if(($this->conftab) && (isset($this->conftab->config))){ + $display= $this->conftab->execute(); + + /* Don't show buttons if tab dialog requests this */ + if (!$this->conftab->by_object[$this->conftab->current]->dialog){ + $display.= "

\n"; + $display.= "\n"; + $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "

"; + } + return ($display); + } + + + /*************** + display divlist + ***************/ + + /* Check if there is a snapshot dialog open */ + $base = $this->DivListConference->selectedBase; + if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ + return($str); + } + + /* Return rendered main page */ + /* Display dialog with system list */ + $this->DivListConference->parent = $this; + $this->DivListConference->execute(); + + /* Add departments if subsearch is disabled */ + if(!$this->DivListConference->SubSearch){ + $this->DivListConference->AddDepartments($this->DivListConference->selectedBase,5,1); + } + $this->reload(); + $this->DivListConference->setEntries($this->conferences); + return($this->DivListConference->Draw()); + } + + + /* Return departments, that will be included within snapshot detection */ + function get_used_snapshot_bases() + { + return(array(get_ou('conferenceou').$this->DivListConference->selectedBase)); + } + + + /* Reload entries for divlist. + * reload all conferences for the current base, with the given regex + */ + function reload() + { + $Base = get_ou('conferenceou').$this->DivListConference->selectedBase; + $SubSearch = $this->DivListConference->SubSearch; + $Regex = $this->DivListConference->Regex; + $Flags = GL_SIZELIMIT ; + $Filter = "(&(|(cn=".$Regex.")(description=".$Regex."))(objectClass=goFonConference))"; + $Attrs = array("cn","goFonConferenceOwner","goFonPIN","telephoneNumber"); + + if($SubSearch){ + $Flags |= GL_SUBSEARCH; + } + + $this->conferences= get_list($Filter, "gofonconference", $Base, $Attrs, $Flags); + } + + function remove_from_parent() + { + /* Ehm what are we doinf here ? */ + + $cfg = new conference($this->config, $this->dn); + $cfg->set_acl_category("gofonconference"); + $cfg->set_acl_base($this->dn); + + $cfg->remove_from_parent(); + $ldap= $this->config->get_ldap_link(); + $ldap->cd ($this->dn); + $ldap->recursive_remove(); + + /* Optionally execute a command after we're done */ + $this->postremove(); + + /* Delete references to object groups */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn")); + while ($ldap->fetch()){ + $og= new conftab($this->config, $ldap->getDN()); + unset($og->member[$this->dn]); + $og->save (); + } + + } + + + function copyPasteHandling_from_queue($s_action,$s_entry) + { + /* Check if Copy & Paste is disabled */ + if(!is_object($this->CopyPasteHandler)){ + return(""); + } + + /* Add a single entry to queue */ + if($s_action == "cut" || $s_action == "copy"){ + + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + $dn = $this->conferences[$s_entry]['dn']; + $this->CopyPasteHandler->add_to_queue($dn,$s_action,"conferencetabs","CONFERENCETABS","gofonconference"); + } + + /* Add entries to queue */ + if($s_action == "copy_multiple" || $s_action == "cut_multiple"){ + + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + + /* Add new entries to CP queue */ + foreach($this->list_get_selected_items() as $id){ + $dn = $this->conferences[$id]['dn']; + + if($s_action == "copy_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"copy","conferencetabs","CONFERENCETABS","gofonconference"); + } + if($s_action == "cut_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"cut","conferencetabs","CONFERENCETABS","gofonconference"); + } + } + } + + /* Start pasting entries */ + if($s_action == "editPaste"){ + $this->start_pasting_copied_objects = TRUE; + } + /* Return C&P dialog */ + if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){ + + /* Load entry from queue and set base */ + $this->CopyPasteHandler->load_entry_from_queue(); + $this->CopyPasteHandler->SetVar("base",$this->DivListConference->selectedBase); + + /* Get dialog */ + $data = $this->CopyPasteHandler->execute(); + + /* Return dialog data */ + if(!empty($data)){ + return($data); + } + } + + /* Automatically disable status for pasting */ + if(!$this->CopyPasteHandler->entries_queued()){ + $this->start_pasting_copied_objects = FALSE; + } + return(""); + } + + + function save_object() + { + $this->DivListConference->save_object(); + } + + function remove_lock() + { + if (isset($this->dn)){ + del_lock ($this->dn); + } + } + + + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } + + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/conference/generic.tpl b/gosa-plugins/gofon/conference/generic.tpl new file mode 100644 index 000000000..63938a43c --- /dev/null +++ b/gosa-plugins/gofon/conference/generic.tpl @@ -0,0 +1,249 @@ + + + + + + + + + + + + + + + + + + + + +
+

+ {t}Properties{/t} +

+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + {$must} + +{render acl=$cnACL} + +{/render} +
+ + {$must} + +{render acl=$goFonConferenceOptionDACL} + +{/render} +
+
+
+ + {$must} + + +{render acl=$baseACL} + +{/render} + +{render acl=$baseACL disable_picture='images/folder_gray.png'} + +{/render} + +
{$must} +{render acl=$goFonHomeServerACL} + +{/render} +
{t}Language{/t} + + +
+
+   + + + + + + + + + + + + + + +
+ + +{render acl=$descriptionACL} + +{/render} +
+ {t}Lifetime (in days){/t} + +{render acl=$goFonConferenceOptionLifetimeACL} + +{/render} +
+ {t}Phone number{/t} + {$must} + +{render acl=$telephoneNumberACL} + +{/render} +
+ +
+

 

+
+

+ {t}Options{/t} +

+
+ + + + + + + + + + + + + + + + + +
+{render acl=$goFonConferenceOptionPACL} + +{/render} + + {t}Preset PIN{/t} +
+   + + {t}PIN{/t} +{render acl=$goFonPINACL} + +{/render} +
+{render acl=$goFonConferenceOptionrACL} + +{/render} + {t}Record conference{/t} +
+   + + {t}Sound file format{/t}  +{render acl=$goFonConferenceOptionFormatACL} + +{/render} +
+ +
+   + + + + + + + + + + + + + + + +
+{render acl=$goFonConferenceOptionMACL} + +{/render} + {t}Play music on hold{/t} +
+{render acl=$goFonConferenceOptionsACL} + +{/render} + {t}Activate session menu{/t} +
+{render acl=$goFonConferenceOptioniACL} + +{/render} + {t}Announce users joining or leaving the conference{/t} +
+{render acl=$goFonConferenceOptioncACL} + +{/render} + {t}Count users{/t} +
+ +
+ + + + + + diff --git a/gosa-plugins/gofon/conference/headpage.tpl b/gosa-plugins/gofon/conference/headpage.tpl new file mode 100644 index 000000000..5b5a95a89 --- /dev/null +++ b/gosa-plugins/gofon/conference/headpage.tpl @@ -0,0 +1,45 @@ + + + + + +
+
+

+ {t}List of conference rooms{/t} {$hint} +

+
+
+ {$conferencehead} +
+
+
+ {$conferences} + +
+
+
+

[i]{t}Information{/t}

+
+
+

+ {t}This menu allows you to create, delete and edit selected phone conferences. Having a large number of phone conferences, you might prefer the range selectors on top of the conferences list.{/t} +

+
+
+
+

[F]{t}Filters{/t}

+
+
+ + {$alphabet} +
+ +
+ {$apply} +
+ + +
+ + diff --git a/gosa-plugins/gofon/conference/main.inc b/gosa-plugins/gofon/conference/main.inc new file mode 100644 index 000000000..063624509 --- /dev/null +++ b/gosa-plugins/gofon/conference/main.inc @@ -0,0 +1,56 @@ +remove_lock(); + del_lock ($ui->dn); + session::un_set ('conference'); + } +} else { + /* Create usermanagement object on demand */ + if (!session::is_set('conference') || (isset($_GET['reset']) && $_GET['reset'] == 1)){ + session::set("conference",new phoneConferenceManagment($config, $ui)); + } + $conference = session::get('conference'); + $conference->save_object(); + $output= $conference->execute(); + + /* Page header*/ + if (session::is_set('objectinfo')){ + $display= print_header(get_template_path('images/conference.png'), _("Conference management"), "\"\" ".@LDAP::fix(session::get('objectinfo'))); + } else { + $display= print_header(get_template_path('images/conference.png'), _("Conference management")); + } + + /* Reset requested? */ + if (isset($_GET['reset']) && $_GET['reset'] == 1){ + del_lock ($ui->dn); + session::un_set ('conference'); + } + + /* Show and save dialog */ + $conference->save_object(); + $display.= $output; + session::set('conference',$conference); +} + +?> diff --git a/gosa-plugins/gofon/conference/paste_generic.tpl b/gosa-plugins/gofon/conference/paste_generic.tpl new file mode 100644 index 000000000..fa72f3f24 --- /dev/null +++ b/gosa-plugins/gofon/conference/paste_generic.tpl @@ -0,0 +1,23 @@ + + + + + + + + + +
+ + {$must} + + +
+ {t}Phone number{/t} + {$must} + + +
+ diff --git a/gosa-plugins/gofon/conference/remove.tpl b/gosa-plugins/gofon/conference/remove.tpl new file mode 100644 index 000000000..970abd4be --- /dev/null +++ b/gosa-plugins/gofon/conference/remove.tpl @@ -0,0 +1,24 @@ +
+  {t}Warning{/t} +
+ {$info} +

+ {t}This includes 'all' accounts, systems, etc. in this subtree. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+ +

+ {t}Best thing to do before performing this action would be to save the current contents of your LDAP tree in a file. So - if you've done so - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+{if $multiple} + +   + +{else} + +   + +{/if} +

+ diff --git a/gosa-plugins/gofon/conference/tabs_conference.inc b/gosa-plugins/gofon/conference/tabs_conference.inc new file mode 100644 index 000000000..6b0c545e0 --- /dev/null +++ b/gosa-plugins/gofon/conference/tabs_conference.inc @@ -0,0 +1,41 @@ +base= $this->by_object['conference']->base; + + /* Add references/acls/snapshots */ + $this->addSpecialTabs(); + } + + function check($ignore_account= FALSE) + { + return (tabs::check(TRUE)); + } + + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['conference']; + $new_dn= 'cn='.$baseobject->cn.','.get_ou('conferenceou').$baseobject->base; + + if(strtolower($this->dn)==strtolower($new_dn)){ + $this->dn=$new_dn; + } + + if($this->dn != $new_dn){ + $baseobject->recursive_move($this->dn, $new_dn); + } + $this->dn= $new_dn; + + tabs::save(TRUE); + } + +} + +?> diff --git a/gosa-plugins/gofon/fonreports/class_fonreport.inc b/gosa-plugins/gofon/fonreports/class_fonreport.inc new file mode 100644 index 000000000..0c256bbeb --- /dev/null +++ b/gosa-plugins/gofon/fonreports/class_fonreport.inc @@ -0,0 +1,415 @@ +config = $config; + $this->ui = $ui; + $this->search_base= get_base_from_people($ui->dn); + + $this->month = date("m"); + $this->year = date("Y"); + + /* Use filter settings if we have already searched */ + if (!session::is_set("fonfilter")){ + $fonfilter = array(); + foreach($this->attributes_SO as $name){ + $fonfilter[$name]=$this->$name; + } + session::set("fonfilter", $fonfilter); + }else{ + $fonfilter = session::get("fonfilter"); + foreach($this->attributes_SO as $name){ + $this->$name = $fonfilter[$name]; + } + } + } + + + /* Save ui interactions and store results in session, + to remember settings */ + function save_object() + { + $fonfilter= session::get("fonfilter"); + if(isset($_POST['EntryPerPage'])){ + $this->range = $_POST['EntryPerPage']; + } + if (isset($_GET['start'])){ + $this->start= (int)$_GET['start']; + } + foreach( array("year", "month", "search_for", "search_base") as $type){ + if (isset($_POST[$type])){ + $this->$type= $_POST[$type]; + } + } + + /* Adapt sorting */ + if (isset($_GET['sort'])){ + if ($this->sort == (int)$_GET['sort']){ + if ($this->sort_direction == "down"){ + $this->sort_direction= "up"; + } else { + $this->sort_direction= "down"; + } + } + $this->sort= (int)$_GET['sort']; + if ($this->sort < 0 || $this->sort > 6){ + $this->sort= 0; + } + } + + /* remove unwanted tags */ + $this->search_for = stripslashes(preg_replace("/[^0-9a-z\*\+ \-]/i","",$this->search_for)); + + foreach($this->attributes_SO as $name){ + $fonfilter[$name] = $this->$name; + } + session::set("fonfilter", $fonfilter); + } + + + /* Search & display results */ + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* GVet template engine */ + $smarty= get_smarty(); + + /* Log view */ + if(!$this->view_logged){ + $this->view_logged = TRUE; + new log("view","gofon/".get_class($this),$this->dn); + } + + /***************** + Variable Init + *****************/ + + $fields_str = ""; + + $months= array(); + for($i = 1 ; $i <= 12 ; $i ++ ){ + $months[$i] = _(date("F",gmmktime(0,0,0,$i))); + } + + /* Prepare template */ + $current= date("Y"); + $years= array(); + for ($y= $current - 5; $y<=$current; $y++){ + $years[$y]= $y; + } + + /***************** + Smarty + *****************/ + $bases = array(); + $cat_bases = $this->ui->get_module_departments("gofon"); + foreach($this->config->idepartments as $dn => $name){ + if(in_array_ics($dn,$cat_bases)){ + $bases[$dn] = $name; + } + } + + if(!isset($bases[$this->search_base])){ + $this->search_base = key($bases); + } + + $smarty->assign("plug", "?plug=".validate($_GET['plug'])); + $smarty->assign("launchimage", get_template_path('images/launch.png')); + $smarty->assign("search_image", get_template_path('images/search.png')); + $smarty->assign("search_for", $this->search_for); + $smarty->assign("bases", $bases); + $smarty->assign("base_select", $this->search_base); + $smarty->assign("months", $months); + $smarty->assign("month_select", $this->month); + $smarty->assign("years", $years); + $smarty->assign("year_select", $this->year); + $smarty->assign("search_result", ""); + + + /***************** + Check Database , Table , Connection + *****************/ + + /* Connecting, selecting database */ + if (!isset($this->config->data['SERVERS']['FON'][0])){ + print_red(_("Can't connect to phone database, no reports can be shown!")); + return($smarty->fetch(get_template_path('contents.tpl', TRUE))); + }elseif(!is_callable("mysql_connect")){ + print_red(_("There is no mysql extension available, please check your php setup.")); + return($smarty->fetch(get_template_path('contents.tpl', TRUE))); + }else{ + + $cfg= $this->config->data['SERVERS']['FON'][0]; + $link = @mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD']); + if ($link === FALSE){ + print_red(_("Can't connect to phone database, no reports can be shown!")); + return($smarty->fetch(get_template_path('contents.tpl', TRUE))); + } + if (! @mysql_select_db("gophone")){ + print_red(_("Can't select phone database for report generation!")); + return($smarty->fetch(get_template_path('contents.tpl', TRUE))); + } + } + + + /***************** + Get Query String && Search + *****************/ + + $query = $this->CreateQuerySyntax(); + $cfg = $this->config->data['SERVERS']['FON'][0]; + $link = @mysql_pconnect($cfg['SERVER'], $cfg['LOGIN'], $cfg['PASSWORD']); + + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + + $result = @mysql_query($query); + if ($result === false){ + print_red(_("Query for phone database failed!")); + return($smarty->fetch(get_template_path('contents.tpl', TRUE))); + } + + /***************** + Fetch results + *****************/ + + $report_list= array(); + + /* Restricted attributes will not be displayed, this will be displayed instead */ + $no_acl = ""._("Insufficient permissions").""; + + $no_acl = " "; + + while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { + + foreach($line as $attr => $value){ + + if($attr == "duration") continue; + + $acl = $this->ui->get_permissions($this->search_base,"gofon/fonreport",$attr); + if(!preg_match("/r/",$acl)){ + $line[$attr] = $no_acl; + } + } + + if($this->ui->get_permissions($this->search_base,"gofon/fonreport","calldate")){ + $hour= substr($line["calldate"], 11, 2); + $minute=substr($line["calldate"], 14, 2); + $format= _("Y-M-D"); + $date= preg_replace("/Y/", substr($line["calldate"], 0, 4), $format); + $date= preg_replace("/M/", substr($line["calldate"], 5, 2), $date); + $date= preg_replace("/D/", substr($line["calldate"], 8, 2), $date); + $date_str = $date." ".$hour.":".$minute; + }else{ + $date_str = $no_acl; + } + + $append_str = ""; + $append_str .= "".$date_str.""; + + foreach(array("src","dst","channel","lastapp","disposition") as $atr){ + if(isset($line[$atr])){ + $append_str .= "".$line[$atr].""; + } + } + + if($this->ui->get_permissions($this->search_base,"gofon/fonreport","duration")){ + $append_str .= "".$this->gen_duration($line["duration"]).""; + }else{ + $append_str .= "".$no_acl.""; + } + $report_list[] = $append_str; + } + + $this->report_list= $report_list; + @mysql_close($link); + + + /***************** + Create list of results + *****************/ + + /* Generate output */ + $mod = 0; + $output = ""; + if(count($this->report_list) < $this->start){ + $this->start = 0; + } + foreach($this->report_list as $val){ + if ($mod < $this->start) { + $mod++; + continue; + } + if ($mod >= ($this->start + $this->range)){ + $mod++; + break; + } + if ( ($mod++) & 1){ + $col= "background-color: #ECECEC;"; + } else { + $col= "background-color: #F5F5F5;"; + } + $output.= "$val"; + } + + /***************** + Tell smarty what we have found + *****************/ + + if ($output != ""){ + $smarty->assign("search_result", $output); + $smarty->assign("range_selector", range_selector(count($this->report_list), $this->start,$this->range,"EntryPerPage")); + } else { + $smarty->assign("search_result", ""); + } + + /* Show main page */ + for($i= 0; $i<7; $i++){ + $smarty->assign("mode$i", ""); + } + $smarty->assign("mode".$this->sort, "\"\"sort_direction.".png\" border=0 align=middle>"); + + return($smarty->fetch(get_template_path('contents.tpl', TRUE))); + } + + + /* Create duration string 12'11" */ + function gen_duration($seconds) + { + if ($seconds / 60 > 1){ + $minutes= (int)($seconds / 60); + $seconds= $seconds % 60; + return ("$minutes’$seconds”"); + } + return ("$seconds”"); + } + + + /* Create WHERE part for our mysql serach */ + function GetUidMatchingFilter() + { + $ldap = $this->config->get_ldap_link(); + $ldap->cd ($this->search_base); + $s = $this->search_for; + + $s = preg_replace("/\%/","",$s); + $s2 = preg_replace("/\*/","%",$s); + + $filter = "(&(objectClass=gosaAccount)(!(objectClass=gosaUserTemplate))". + "(|(uid=$s)(l=$s)(homePhone=$s)(telephoneNumber=$s)(facsimileTelephoneNumber=$s)(mobile=$s)". + "(pager=$s)(cn=$s)(givenName=$s)(sn=$s)(personalTitle=$s)(title=$s)))"; + + $attrs = array("uid"); + $res = get_list($filter,"users",$this->search_base,$attrs); + + $str = " AND ("; + $fields = array("dstchannel","channel"); + if(count($res)){ + foreach($res as $attrs){ + $uid = $attrs["uid"][0]; + foreach($fields as $name){ + $str .= $name." like '%".$uid."%' OR "; + } + } + } + $str .= " channel like '%".$s."%' OR + dstchannel like '%".$s."%' OR + dst like '".$s2."' OR + src like '".$s2."' OR + lastapp like '".$s2."')"; + return($str); + } + + + /* Create query string */ + function CreateQuerySyntax() + { + /* Get extended search filter which contain uids and so on */ + $uidstring = $this->GetUidMatchingFilter(); + + /* Create string with all fields seperated by ,*/ + $fields_str =""; + foreach($this->fields as $field){ + if($field == "calldate") { + continue; + } + $fields_str .= $field.", "; + } + $fields_str = preg_replace("/, $/","",$fields_str); + + /* Create Sort tag */ + if ($this->sort_direction == "down"){ + $desc= "DESC"; + } else { + $desc= "ASC"; + } + /* Create times */ + $start= date ("YmdHis", mktime(0,0,0,$this->month,1,$this->year)); + $end= date ("YmdHis", mktime(23,59,59,($this->month +1),0,$this->year)); + $query = "SELECT ".$fields_str.",calldate FROM cdr ". + "WHERE + calldate <= $end + AND + calldate >= $start + ". $uidstring." + ORDER BY ".$this->fields[$this->sort]." $desc;"; + return($query); + } + + + /* Return plugin informations for acl handling + #FIXME You can only read attributes within this report plugin */ + static function plInfo() + { + return (array( + "plShortName" => _("Phone reports"), + "plDescription" => _("Phone reports")." "._("All entries are readonly")."", + "plSelfModify" => TRUE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plCategory" => array("fonreport"), + + "plProvidedAcls" => array( + "calldate" =>_("Date"), + "src" =>_("Source"), + "dst" =>_("Destination"), + "channel" =>_("Channel"), + "lastapp" =>_("Application called"), + "disposition" =>_("Disposition"), + "duration" =>_("Duration")) + )); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/fonreports/contents.tpl b/gosa-plugins/gofon/fonreports/contents.tpl new file mode 100644 index 000000000..d8cf0a47f --- /dev/null +++ b/gosa-plugins/gofon/fonreports/contents.tpl @@ -0,0 +1,59 @@ +
+

[F]{t}Filter{/t}

+
+
+

+  {t}Search for{/t} + + {t}in{/t} + + {t}during{/t} + + {t}in{/t} + +   + +

+
+ +
+ +{if $search_result } + + + + + + + + + + + {$search_result} +
{t}Date{/t} {$mode0}{t}Source{/t} {$mode1}{t}Destination{/t} {$mode2}{t}Channel{/t} {$mode3}{t}Application{/t} {$mode4}{t}Status{/t} {$mode5}{t}Duration{/t} {$mode6}
+ + + + + +
{$range_selector}
+ +

+   +

+{else} + {t}Search returned no results...{/t} +{/if} + + + diff --git a/gosa-plugins/gofon/fonreports/main.inc b/gosa-plugins/gofon/fonreports/main.inc new file mode 100644 index 000000000..0b3d25f5e --- /dev/null +++ b/gosa-plugins/gofon/fonreports/main.inc @@ -0,0 +1,21 @@ +save_object(); + $display= $fonreport->execute (); + $display.= "\n"; + + /* Page header*/ + $display= print_header(get_template_path('images/phonereport.png'), _("Phone reports")).$display; + + /* Store changes in session */ + session::set('fonreport',$fonreport); +} +?> diff --git a/gosa-plugins/gofon/macro/class_divListMacros.inc b/gosa-plugins/gofon/macro/class_divListMacros.inc new file mode 100644 index 000000000..de822bb54 --- /dev/null +++ b/gosa-plugins/gofon/macro/class_divListMacros.inc @@ -0,0 +1,298 @@ +parent = $parent; + $this->ui = get_userinfo(); + + /* Set list strings */ + $this->SetTitle(_("List of macros")); + $this->SetSummary(_("List of macros")); + + /* Result page will look like a headpage */ + $this->SetHeadpageMode(); + $this->SetInformation(_("This menu allows you to add, edit and remove selected macros. You may want to use the range selector on top of the macro listbox, when working with a large number of macros.")); + + $this->EnableAplhabet (true); + + /* Disable buttonsm */ + $this->EnableCloseButton(false); + $this->EnableSaveButton (false); + + /* Dynamic action col, depending on snapshot icons */ + $action_col_size = 100; + if($this->parent->snapshotEnabled()){ + $action_col_size += 20; + } + + /* Toggle all selected / deselected */ + $chk = ""; + + /* set Page header */ + $this->AddHeader(array("string"=> $chk, "attach"=>"style='width:20px;'")); + $this->AddHeader(array("string" => " ", "attach" => "style='text-align:center;width:20px;'")); + $this->AddHeader(array("string" => _("Macro name")." / "._("Department"), "attach" => "style=''")); + $this->AddHeader(array("string" => _("Visible"), "attach" => "style='width:50px;'")); + $this->AddHeader(array("string" => _("Actions"), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'" )); + + /* Add Checkboxes / SubSearch checkbox */ + $this->AddCheckBox("SubSearch", _("Select to search within subtrees"), _("Search in subtrees"), false); + + /* Name ,Text ,Default , Connect with alphabet */ + $this->AddRegex ("Regex", _("Regular expression for matching macro names"),"*" , true); + } + + function GenHeader() + { + /* Prepare departments, + which are shown in the listbox on top of the listbox + */ + $options= ""; + + /* Get all departments within this subtree */ + $base = $this->config->current['BASE']; + $first = ""; + $found = FALSE; + + /* Add base */ + $tmp = array(); + $tmp[] = array("dn"=>$this->config->current['BASE']); + $tmp= array_merge($tmp,get_list("(&(|(ou=*)(description=*))(objectClass=gosaDepartment))", $this->module, $base, + array("ou", "description"), GL_SIZELIMIT | GL_SUBSEARCH)); + + $deps = array(); + foreach($tmp as $tm){ + $deps[$tm['dn']] = $tm['dn']; + } + + /* Load possible departments */ + $ui= get_userinfo(); + $tdeps= $ui->get_module_departments("gofonmacro"); + $ids = $this->config->idepartments; + $first = ""; + $found = FALSE; + foreach($ids as $dep => $name){ + if(isset($deps[$dep]) && in_array_ics($dep, $tdeps)){ + + /* Keep first base dn in mind, we could need this + * info if no valid base was found + */ + if(empty($first)) { + $first = $dep['dn']; + } + + $value = $ids[$dep]; + if ($this->selectedBase == $dep){ + $found = TRUE; + $options.= ""; + } else { + $options.= ""; + } + } + } + + /* The currently used base is not visible with your acl setup. + * Set base to first useable base. + */ + if(!$found){ + $this->selectedBase = $first; + } + + $acls = $ui->get_permissions($this->selectedBase,"gofonmacro/macro"); + + /* Add default header */ + $listhead = MultiSelectWindow::get_default_header(); + $listhead .= _("Base")." ". + "  "; + + /* Create Layers menu */ + $s = ".|"._("Actions")."|\n"; + $s .= "..|". + " "._("Create")."|\n"; + + /* Append create options */ + if(preg_match("/c/",$acls)){ + $s.= "...|". + " "._("Macro")."|goFonMacro_new|\n"; + } + + /* Multiple options */ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Remove")."|"."remove_multiple|\n"; + + /* Add multiple copy & cut icons */ + if(preg_match("/(c.*w|w.*c)/",$acls) && is_object( $this->parent->CopyPasteHandler)){ + $s.= "..|---|\n"; + $s.= "..|". + " "._("Copy")."|"."multiple_copy_systems|\n"; + $s.= "..|". + " "._("Cut")."|"."multiple_cut_systems|\n"; + + if($this->parent->CopyPasteHandler->entries_queued()){ + $img = ""; + $s.="..|".$img." "._("Paste")."|editPaste|\n"; + }else{ + $img = ""; + $s.="..|".$img." "._("Paste")."\n"; + } + } + + /* Add snapshot icons */ + if(preg_match("/(c.*w|w.*c)/",$acls)){ + $s .= "..|---|\n"; + $s .= $this->get_snapshot_header(TRUE); + } + + $this->SetDropDownHeaderMenu($s); + + + + + $this->SetListHeader($listhead); + } + + function execute() + { + $this->ClearElementsList(); + $this->GenHeader(); + } + + function setEntries($list) + { + + $empty = ""; + $macroimg = ""._("Macro").""; + $visible = ""._("yes").""; + $invisible = ""._("no").""; + $editlink = "%s"; + + /* Dynamic action col, depending on snapshot icons */ + $action_col_size = 100; + if($this->parent->snapshotEnabled()){ + $action_col_size += 20; + } + + $ui = get_userinfo(); + + foreach($list as $key => $val){ + + $sacl = $ui->get_permissions($val['dn'],"gofonmacro/macro"); + + $action = ""; + if(!preg_match("/r/",$sacl)){ + continue; + } + + if(($this->parent->CopyPasteHandler) && preg_match("/(c.*w|w.*c)/",$sacl)){ + $action.= " "; + $action.= " "; + } + + $action.= ""; + + if(preg_match("/c/",$sacl) && preg_match("/w/",$sacl)){ + $action.= $this->GetSnapShotActions($val['dn']); + } + + if(preg_match("/d/",$sacl)){ + $action.= ""; + } + + if(isset($val['goFonMacroVisible']['0'])&&($val['goFonMacroVisible']['0'] == "1")){ + $pic1 = $visible; + }else{ + $pic1 = $invisible; + } + + $display= $val["displayName"][0]." (".$val["cn"][0].")"; + if(isset($val['description'][0])){ + + $desc = $val['description'][0]; + if(strlen($desc) > 55){ + $desc = substr($desc,0,52)."..."; + } + + $display .= " [".$desc."]"; + } + + /* Cutted objects should be displayed in light grey */ + if($this->parent->CopyPasteHandler){ + foreach($this->parent->CopyPasteHandler->queue as $queue_key => $queue_data){ + if($queue_data['dn'] == $val['dn']) { + $display = "".$display.""; + break; + } + } + } + + /* Create each field */ + $field0 = array("string" => "" , + "attach" => "style='width:20px;'"); + $field1 = array("string" => sprintf($macroimg,$val['dn']), "attach" => "style='text-align:center;width:20px;'"); + $field2 = array("string" => sprintf($editlink,$key,$display), "attach" => "style='' title='".preg_replace('/ /', ' ', @LDAP::fix($val['dn']))."'"); + $field3 = array("string" => $pic1, "attach" => "style='width:50px;'"); + $field4 = array("string" => preg_replace("/%KEY%/", "$key", $action), "attach" => "style='width:".$action_col_size."px;border-right:0px;text-align:right;'"); + + $this->AddElement(array($field0,$field1,$field2,$field3,$field4)); + } + + /* Create summary string for list footer */ + $num_deps=0; + if(!$this->SubSearch){ + $num_deps = count($this->Added_Departments); + } + $num_objs = count($list); + + $num_obj_str = _("Number of listed macros"); + $num_dep_str = _("Number of listed departments"); + + $str = "".$num_obj_str." ".$num_objs."    "; + $str.= "".$num_dep_str." ".$num_deps."    "; + + $this->set_List_Bottom_Info($str); + } + + function Save() + { + MultiSelectWindow :: Save(); + } + + function save_object() + { + /* Save automatic created POSTs like regex, checkboxes */ + MultiSelectWindow :: save_object(); + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/macro/class_gofonMacro.inc b/gosa-plugins/gofon/macro/class_gofonMacro.inc new file mode 100644 index 000000000..07e10f0aa --- /dev/null +++ b/gosa-plugins/gofon/macro/class_gofonMacro.inc @@ -0,0 +1,590 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /*! Macro attributes, */ + var $generate_error= ""; + + /*! The name of the Macro in the openldap drirectory */ + var $cn = ""; + + /*! Display error once */ + var $error_shown = false; + + /*! This ist the variable that contains the description of the macro*/ + var $description = ""; + + /*! The base of the macro, is used to save the macro in the correct directory tree */ + var $base = ""; + + /*! This is the name of the macro which the enduser will see, instead of the cn */ + var $displayName = ""; + + /*! Here is the macro content, the real macroscript */ + var $goFonMacroContent= ""; + + /*! To allow user to use this macro this var must be true, else false */ + var $goFonMacroVisible= 0; + + /*! attribute list for save action */ + var $attributes = array("cn","base", "description","displayName","goFonMacroContent","goFonMacroVisible"); + var $view_logged = FALSE; + var $orig_cn = ""; + /*! Objectclasses that this calls handles */ + var $objectclasses = array("top", "goFonMacro"); + + var $goFonHomeServers = array(); // Contains all available asterisk database server + + //! The Konstructor + /*! Konstructor, load class with attributes of the given dn*/ + function macro (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + /* This is always an account */ + $this->is_account= TRUE; + + /* Edit or new one ?*/ + if ($this->dn == "new"){ + if(session::is_set('CurrentMainBase')){ + $this->base = session::get('CurrentMainBase'); + }else{ + $ui= get_userinfo(); + $this->base= dn2base($ui->dn); + } + } else { + $this->orig_cn=$this->cn; + $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,[^,]+,[^,]+,/", "", $this->dn); + } + + /* Check server configurations + * Load all server configuration in $this->goFonHomeServers if available + */ + $a_SETUP= array(); + if(isset($config->data['SERVERS']['FON'])){ + + /* Set available server */ + $this->goFonHomeServers = $config->data['SERVERS']['FON']; + + /* Remove default entry, not necessary here */ + if(isset($this->goFonHomeServers[0])){ + unset($this->goFonHomeServers[0]); + } + } + } + + + /*! Execute this plugin */ + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Log view */ + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","gofonmacro/".get_class($this),$this->dn); + } + + /* Variables */ + $vars = ""; + $tmp = array(); + $number = 0; + + /* Base select dialog */ + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^chooseBase/",$name) && $once){ + $once = false; + $this->dialog = new baseSelectDialog($this->config,$this,$this->allowedBasesToMoveTo()); + $this->dialog->setCurrentBase($this->base); + } + } + + /* Dialog handling */ + if(is_object($this->dialog)){ + /* Must be called before save_object */ + $this->dialog->save_object(); + + if($this->dialog->isClosed()){ + $this->dialog = false; + }elseif($this->dialog->isSelected()){ + + /* A new base was selected, check if it is a valid one */ + $tmp = $this->get_allowed_bases(); + if(isset($tmp[$this->dialog->isSelected()])){ + $this->base = $this->dialog->isSelected(); + } + + $this->dialog= false; + }else{ + return($this->dialog->execute()); + } + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + $smarty->assign("bases", $this->get_allowed_bases()); + + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + if($this->acl_is_writeable("base")){ + $smarty->assign("baseSelect",true); + }else{ + $smarty->assign("baseSelect",false); + } + + + /* Assign all vars to Smarty */ + foreach($this->attributes as $ar){ + $smarty->assign($ar, $this->$ar); + } + /* Checkboxes */ + $smarty->assign("base_select", $this->base); + $smarty->assign("vars", $vars); + + if($this->goFonMacroVisible){ + $smarty->assign("goFonMacroVisibleChecked"," checked "); + }else{ + $smarty->assign("goFonMacroVisibleChecked",""); + } + + $smarty->assign("cnACL",$this->getacl("cn",$this->initially_was_account)); + $smarty->assign("cn",$this->cn); + + /* Ensure that macro content is displayed correctly encoded */ + $smarty->assign("goFonMacroContent",htmlentities(utf8_decode ($this->goFonMacroContent))); + + /* Show main page */ + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); + } + + + /* This method check if all databases are reachable. + * Returns with error message or an empty string on success. + * + * - Is mysql extension available + * - Is every server reachable + * - Does the database exists/is accessible + */ + function check_database_accessibility() + { + /* Check if mysql extension is available */ + if(!is_callable("mysql_pconnect")){ + return(_("Can't save any changes to asterisk database, there is currently no mysql extension available in your php setup.")); + } + + /******************** + * Check all home server + ********************/ + foreach($this->goFonHomeServers as $goFonHomeServer => $cfg_Current){ + $r_current = @mysql_pconnect($cfg_Current['SERVER'],$cfg_Current['LOGIN'],$cfg_Current['PASSWORD']); + if(!$r_current){ + new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current)); + return(sprintf(_("The MySQL home server '%s' isn't reachable as user '%s', check GOsa log for mysql error."), + $cfg_Current['SERVER'],$cfg_Current['LOGIN'])); + } + $db_current = @mysql_select_db($cfg_Current['DB'],$r_current); + if(!$db_current){ + new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current)); + mysql_close($r_current); + return( sprintf(_("Can't select database '%s' on home server '%s'."),$cfg_Current['DB'],$cfg_Current['SERVER'])); + } + } + } + + + /* Remove current macro from all asterisk server. + * First of all check if we have access to all databases. + * - Remove old entries + */ + function remove_from_database($save) + { + /* Check if all databases are reachable */ + $str = $this->check_database_accessibility(); + if($str){ + return($str); + } + + /* Create query string */ + $context = addslashes("macro-".$this->cn); + + /* Remove current macro from each server available */ + if($save){ + foreach($this->goFonHomeServers as $dn => $Server){ + $query = "DELETE FROM ".$Server['EXT_TABLE']." WHERE context='".$context."';"; + $r_current = @mysql_pconnect($Server['SERVER'],$Server['LOGIN'],$Server['PASSWORD']); + $db_current = @mysql_select_db($Server['DB'],$r_current); + $res = @mysql_query($query,$r_current); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(!$res){ + new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_current)); + return(sprintf(_("Removing macro from '%s' failed. Check GOsa log for mysql error."),$Server['SERVER'])); + } + @mysql_close($r_current); + } + } + } + + + /* Add current macro to all asterisk server. + * First of all check if we have access to all databases. + * - Remove old entries + * - Add new entries + */ + function add_to_database($save) + { + /* Check if all databases are reachable */ + $str = $this->check_database_accessibility(); + if($str){ + return($str); + } + + /* Remove old entries first. Else we got duplicated entries */ + $str = $this->remove_from_database($save); + if($str){ + return($str); + } + + /* Create query string */ + $context = "macro-".$this->cn; + + /************ + * Parse Macro content + ************/ + $sql = + "INSERT INTO %TABLENAME% ". + " (context,exten,priority,app,appdata) ". + " VALUES "; + + $a_contentLines = split("\n",$this->goFonMacroContent); + foreach($a_contentLines as $i_linenum => $s_linestr){ + + /* Remove the 'exten => ' string in front of the macro content line + * example line 'exten => s,2,GotoIf(${ARG3}?3:5)' + * Remove comments introduced by ; + * Skip empty lines + */ + $s_linestr = trim($s_linestr); + $s_linestr = preg_replace("/;.*$/","",$s_linestr) ; + $s_linestr = preg_replace ("/^.*=\> /","",$s_linestr); + + if(empty($s_linestr)){ + continue; + } + + /* A line that passes the check above should look like this + * s,1,SetLanguage(de) + * 3 parts seperated by , + * If there are more or less parts, abort. + * The preg_replace exclude parameters from split .. + */ + $tmp = split(",", $s_linestr,3); + + /* Check if there are exactly 2 , */ +# if(substr_count($s_linestr,",") !=2){ +# return(sprintf(_("More than two ',' given in line : '%s'. Remember that parameters are seperated by '|'."),$i_linenum)); +# } + /* Multiple () are not supproted currently ... */ + if(substr_count($s_linestr,"(") >1 ){ + return(sprintf(_("More than one '(' is currently not supported. Line : '%s'."),$i_linenum)); + } + if(substr_count($s_linestr,")") >1 ){ + return(sprintf(_("More than one ')' is currently not supported. Line : '%s'."),$i_linenum)); + } + /* Check if there is an application given */ + if(empty($tmp[1])){ + return(sprintf(_("There is no application given in line : '%s'."),$i_linenum)); + } + /* Check if there is an extension given */ + if(empty($tmp[0])){ + return(sprintf(_("There is no extension type given in line : '%s'."),$i_linenum)); + } + + /* Create extension entry for current line + * and add this line to an array that will be inserted + * to each database. + */ + $exten = addslashes($tmp[0]); + $prio = addslashes($tmp[1]); + $app = addslashes(preg_replace("/\(.*\).*$/","",$tmp[2])); + $para = addslashes(preg_replace("/^.*\(/","",$tmp[2])); + $para = preg_replace("/\).*$/","",$para); + $sql.= " ('".$context."','".$exten."','".$prio."','".$app."','".$para."'),"; + } + + /* Remove last , from query string */ + $sql = preg_replace("/,$/","",$sql); + + /* Save current changes to the database */ + if($save){ + + /* Macro are spread to each asterisk server */ + foreach($this->goFonHomeServers as $dn => $cfg){ + $r_con = @mysql_pconnect($cfg['SERVER'],$cfg['LOGIN'],$cfg['PASSWORD']); + $db = @mysql_select_db($cfg['DB'],$r_con); + $query = preg_replace("/%TABLENAME%/",$cfg['EXT_TABLE'],$sql); + $res = @mysql_query($query,$r_con); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(!$res){ + new log("debug","gofonmacro/".get_class($this),"",array(),@mysql_error($r_con)); + return(sprintf(_("Insert of new macro failed for server '%s'."),$cfg['SERVER'])); + } + @mysql_close($r_con); + } + } + } + + + function save_object() + { + if (isset($_POST['gofonMacroGenericPosted'])){ + + $old_cn = $this->cn; + $old_visible = $this->goFonMacroVisible; + + /* Create a base backup and reset the + base directly after calling plugin::save_object(); + Base will be set seperatly a few lines below */ + $base_tmp = $this->base; + plugin::save_object(); + $this->base = $base_tmp; + + /* Save base, since this is no LDAP attribute */ + $tmp = $this->get_allowed_bases(); + if(isset($_POST['base'])){ + if(isset($tmp[$_POST['base']])){ + $this->base= $_POST['base']; + } + } + + /* Restore old cn if we have insuficient acls to change cn ... */ + if(!$this->acl_is_writeable("cn",$this->initially_was_account)){ + $this->cn = $old_cn; + } + + /* check if we are allowed to toggle visibility */ + if($this->acl_is_writeable("goFonMacroVisible")) { + + /* Checkbox selected ? */ + if(isset($_POST['goFonMacroVisible'])) { + $this->goFonMacroVisible= 1 ; + }else { + if(isset($_POST['displayName'])){ + $this->goFonMacroVisible= 0 ; + } + } + }else{ + $this->goFonMacroVisible = $old_visible; + } + } + } + + + /*! Check values */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(!count($this->goFonHomeServers)){ + $message[] = _("There must be at least one server with an asterisk database to save this phone macro."); + } + + /* Check if insert/replace is possible and all servers are available */ + $str = $this->add_to_database(false); + if($str){ + $message[] = $str; + } + + /* Check if cn is already used */ + if(($this->dn=="new")||($this->orig_cn!=$this->cn)){ + $ldap = $this->config->get_ldap_link(); + $ldap->search("(&(objectClass=goFonMacro)(cn=".$this->cn."))",array("cn")); + if($ldap->count()>0){ + $message[]=sprintf(_("The given cn '%s' already exists."),$this->cn); + } + } + + /* Check if display name is set */ + if(empty($this->displayName)){ + $message[] = _("You must specify the 'Display Name' in order to save this macro"); + } + /* CN is restricted to 20 chars */ + if(strlen("Makro-".$this->cn)>20 ){ + $message[]=_("The given cn is too long, to create a Makro entry, maximum 20 chars."); + } + + /* If this macro is still in use we should not change the visible for user flag to invisible */ + if(!$this->goFonMacroVisible){ + $ldap = $this->config->get_ldap_link(); + $res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro")); + while ($val = $ldap->fetch()){ + if(strstr($val['goFonMacro'][0],$this->dn)){ + $message[] = _("This macro is still in use. It is necessary to mark this macro as visible for users."); + return($message); + } + } + } + + /* Macro content must be smaller than 100 lines */ + if(count(split("\n",$this->goFonMacroContent))>100){ + $message[] = _("Makro length must be lower than 100 lines"); + } + + /* Macro content must be smaller than 100 lines */ + if(empty($this->goFonMacroContent)){ + $message[] = _("You can't save an empty macro."); + } + return $message; + } + + + /*! Remove makro from all given databases + * and ldap too. + */ + function remove_from_parent() + { + $ldap= $this->config->get_ldap_link(); + + /* Skip remove if this macro is still in use */ + $res = $ldap->search("(&(objectClass=goFonAccount)(objectClass=gosaAccount)(goFonMacro=*))", array("goFonMacro")); + while ($val = $ldap->fetch()){ + if(strstr($val['goFonMacro'][0],$this->dn)){ + print_red(_("This macro is still in use. To delete this Macro ensure that nobody has selected it.")); + return false; + } + } + + /* Try to remove from database */ + if(count($this->goFonHomeServers)){ + $str = $this->remove_from_database(true); + if($str){ + print_red($str); + return false; + } + }else{ + print_red(_("Could not remove the macro entry from asterisk databases. Please check your asterisk database configurations.")); + return false; + } + + /* Remove phone macro */ + $ldap->rmDir($this->dn); + new log("remove","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of goFonMacro/generic account with dn '%s' failed."),$this->dn)); + + /* Delete references to object groups */ + $ldap->cd ($this->config->current['BASE']); + $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn")); + while ($ldap->fetch()){ + $og= new ogroup($this->config, $ldap->getDN()); + unset($og->member[$this->dn]); + $og->save (); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of goFonMacro/generic account with dn '%s' failed."),$this->dn)); + } + } + + + /*! Save to LDAP */ + function save() + { + plugin::save(); + unset($this->attrs['base']); + + /* Try to add entries to databases */ + $str = $this->add_to_database(true); + if($str){ + print_red($str); + }else{ + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('dn')); + $a= $ldap->fetch(); + + if (count($a)){ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + $this->handle_post_events("modify"); + } else { + $ldap->cd($this->config->current['BASE']); + $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn)); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + $this->handle_post_events("add"); + } + show_ldap_error($ldap->get_error(), sprintf(_("Saving of goFonMacro/generic account with dn '%s' failed."),$this->dn)); + + /* Log last action */ + if($this->initially_was_account){ + new log("modify","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + }else{ + new log("create","gofonmacro/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + } + } + } + + + function getCopyDialog() + { + $smarty = get_smarty(); + $smarty->assign("cn" ,$this->cn); + $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE)); + $ret = array(); + $ret['string'] = $str; + $ret['status'] = ""; + return($ret); + } + + + function saveCopyDialog() + { + if(isset($_POST['cn'])){ + $this->cn = $_POST['cn']; + } + } + + + static function plInfo() + { + return (array( + "plShortName" => _("Generic"), + "plDescription" => _("Asterisk macro management"), + "plSelfModify" => FALSE, + "plDepends" => array(), + "plPriority" => 0, + "plSection" => array("administration"), + "plCategory" => array("gofonmacro" => array("description" => _("GOfon macro"), + "objectClass" => "gofonMacro")), + + "plProvidedAcls" => array( + "cn" => _("Macro name"), + "base" => _("Base"), + "description" => _("Description"), + "displayName" => _("Display name"), + "goFonMacroContent" => _("Macro content and parameter"), + "goFonMacroVisible" => _("Visibility flag")) + )); + } + +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/macro/class_gofonMacroManagement.inc b/gosa-plugins/gofon/macro/class_gofonMacroManagement.inc new file mode 100644 index 000000000..9d552be2a --- /dev/null +++ b/gosa-plugins/gofon/macro/class_gofonMacroManagement.inc @@ -0,0 +1,555 @@ +config= $config; + $this->ui= $ui; + + $this->DivListMacro = new divListMacro($this->config,$this); + + /* Copy & Paste enabled ?*/ + if((isset($this->config->data['MAIN']['ENABLECOPYPASTE']))&&(preg_match("/true/i",$this->config->data['MAIN']['ENABLECOPYPASTE']))){ + $this->CopyPasteHandler = new CopyPasteHandler($this->config); + } + } + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + session::set('LOCK_VARS_TO_USE',array("/^goFonMacro_/","/^act$/","/^id$/","/^item_selected/","/^remove_multiple_macros/")); + + /***************** + Variable initialisation + *****************/ + + $s_action = ""; // Contains the action to proceed + $s_entry = ""; // The value for s_action + $base_back = ""; // The Link for Backbutton + $smarty= get_smarty(); + + + /***************** + Check Posts + *****************/ + + /* Test Posts */ + foreach($_POST as $key => $val){ + // Post for delete + if(preg_match("/^goFonMacro_del/",$key)){ + $s_action = "del"; + $s_entry = preg_replace("/^goFonMacro_del_/i","",$key); + // Post for edit + }elseif(preg_match("/^goFonMacro_edit_/",$key)){ + $s_action="edit"; + $s_entry = preg_replace("/^goFonMacro_edit_/i","",$key); + // Post for new + }elseif(preg_match("/^goFonMacro_new/",$key)){ + $s_action="new"; + }elseif(preg_match("/^remove_multiple_macros/",$key)){ + $s_action="del_multiple"; + }elseif(preg_match("/^editPaste.*/i",$key)){ + $s_action="editPaste"; + }elseif(preg_match("/^copy_.*/",$key)){ + $s_action="copy"; + $s_entry = preg_replace("/^copy_/i","",$key); + }elseif(preg_match("/^cut_.*/",$key)){ + $s_action="cut"; + $s_entry = preg_replace("/^cut_/i","",$key); + }elseif(preg_match("/^multiple_copy_objects/",$key)){ + $s_action = "copy_multiple"; + }elseif(preg_match("/^multiple_cut_objects/",$key)){ + $s_action = "cut_multiple"; + } + } + if((isset($_GET['act']))&&($_GET['act']=="edit_entry")){ + $s_action ="edit"; + $s_entry = $_GET['id']; + } + $s_entry = preg_replace("/_.$/","",$s_entry); + + + /******************** + Copy & Paste Handling ... + ********************/ + + + /* handle C&P from layers menu */ + if(isset($_POST['menu_action']) && preg_match("/^multiple_copy_systems/",$_POST['menu_action'])){ + $s_action = "copy_multiple"; + } + if(isset($_POST['menu_action']) && preg_match("/^multiple_cut_systems/",$_POST['menu_action'])){ + $s_action = "cut_multiple"; + } + if(isset($_POST['menu_action']) && preg_match("/^editPaste/",$_POST['menu_action'])){ + $s_action = "editPaste"; + } + + /* Create options */ + if(isset($_POST['menu_action']) && $_POST['menu_action'] == "goFonMacro_new"){ + $s_action = "new"; + } + + /* handle remove from layers menu */ + if(isset($_POST['menu_action']) && preg_match("/^remove_multiple/",$_POST['menu_action'])){ + $s_action = "del_multiple"; + } + + /* Display the copy & paste dialog, if it is currently open */ + $ret = $this->copyPasteHandling_from_queue($s_action,$s_entry); + if($ret){ + return($ret); + } + + + /***************** + Create a new Macro + *****************/ + + /* New macro? */ + if ($s_action=="new"){ + + /* By default we set 'dn' to 'new', all relevant plugins will + react on this. */ + $this->dn= "new"; + + /* Create new usertab object */ + $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn,"gofonmacro"); + $this->macrotabs->set_acl_base($this->DivListMacro->selectedBase); + } + + /***************** + Edit || Password canceled + *****************/ + + /* Cancel dialogs */ + if (isset($_POST['edit_cancel'])){ + del_lock ($this->macrotabs->dn); + unset ($this->macrotabs); + $this->macrotabs= NULL; + session::un_set('objectinfo'); + } + + + /***************** + Edit finised + *****************/ + + /* Finish mac edit is triggered by the tabulator dialog, so + the user wants to save edited data. Check and save at this + point. */ + if ((isset($_POST['edit_finish']) || isset($_POST['edit_apply'])) && (isset($this->macrotabs->config))){ + + /* Check tabs, will feed message array */ + $this->macrotabs->last= $this->macrotabs->current; + $this->macrotabs->save_object(); + $message= $this->macrotabs->check(); + + /* Save, or display error message? */ + if (count($message) == 0){ + + /* Save data data to ldap */ + $this->macrotabs->save(); + + if (!isset($_POST['edit_apply'])){ + /* macro has been saved successfully, remove lock from + LDAP. */ + if ($this->dn != "new"){ + del_lock ($this->dn); + } + + unset ($this->macrotabs); + $this->macrotabs= NULL; + session::un_set('objectinfo'); + } + } else { + /* Ok. There seem to be errors regarding to the tab data, + show message and continue as usual. */ + show_errors($message); + } + } + + + /***************** + Edit macro + *****************/ + + /* User wants to edit data */ + if (($s_action=="edit") && (!isset($this->macrotabs->config))){ + + $dn = $this->macros[$s_entry]['dn']; + $acl = $this->ui->get_permissions($dn,"gofonmacro/macro"); + if(preg_match("/r/",$acl)){ + $this->dn = $dn; + + /* Check locking, save current plugin in 'back_plugin', so + the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return(gen_locked_message ($user, $this->dn)); + } + + /* Lock the current entry, so everyone will get the + above dialog */ + add_lock ($this->dn, $this->ui->dn); + /* Register macrotabs to trigger edit dialog */ + $this->macrotabs= new macrotabs($this->config, + $this->config->data['TABS']['MACROTABS'], $this->dn,"gofonmacro"); + session::set('objectinfo',$this->dn); + } + } + + + + /******************** + Delete MULTIPLE entries requested, display confirm dialog + ********************/ + + if ($s_action=="del_multiple"){ + $ids = $this->list_get_selected_items(); + + if(count($ids)){ + + foreach($ids as $id){ + $dn = $this->macros[$id]['dn']; + if (($user= get_lock($dn)) != ""){ + return(gen_locked_message ($user, $dn)); + } + $this->dns[$id] = $dn; + } + + $dns_names = "
";
+        foreach($this->dns as $dn){
+          add_lock ($dn, $this->ui->dn);
+          $dns_names .= $dn."\n";
+        }
+        $dns_names .="
"; + + /* Lock the current entry, so nobody will edit it during deletion */ + $smarty->assign("intro", sprintf(_("You're about to delete the following user(s) %s"), @LDAP::fix($dns_names))); + $smarty->assign("multiple", true); + return($smarty->fetch(get_template_path('remove.tpl', TRUE))); + } + } + + + /******************** + Delete MULTIPLE entries confirmed + ********************/ + + /* Confirmation for deletion has been passed. Users should be deleted. */ + if (isset($_POST['delete_multiple_macro_confirm'])){ + + /* Remove user by user and check acls before removeing them */ + foreach($this->dns as $key => $dn){ + + $acl = $this->ui->get_permissions($dn,"gofonmacro/macro"); + if(preg_match("/d/",$acl)){ + + /* Delete request is permitted, perform LDAP action */ + $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $dn,"gofonmacro"); + $this->macrotabs->delete (); + unset ($this->macrotabs); + $this->macrotabs= NULL; + + } else { + print_red (_("You are not allowed to delete this macro!")); + } + + /* Remove lock file after successfull deletion */ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /******************** + Delete MULTIPLE entries Canceled + ********************/ + + /* Remove lock */ + if(isset($_POST['delete_multiple_macro_cancel'])){ + foreach($this->dns as $key => $dn){ + del_lock ($dn); + unset($this->dns[$key]); + } + } + + + /***************** + Remove macro + *****************/ + + /* Remove user was requested */ + if ($s_action=="del"){ + + /* Get 'dn' from posted 'uid' */ + $dn = $this->macros[$s_entry]['dn']; + $acl = $this->ui->get_permissions($dn,"gofonmacro/macro"); + + if(preg_match("/d/",$acl)){ + + $this->dn = $dn; + + /* Check locking, save current plugin in 'back_plugin', so + the dialog knows where to return. */ + if (($user= get_lock($this->dn)) != ""){ + return (gen_locked_message ($user, $this->dn)); + } + + /* Lock the current entry, so nobody will edit it during deletion */ + add_lock ($this->dn, $this->ui->dn); + $smarty= get_smarty(); + $smarty->assign("intro", sprintf(_("You're about to delete the macro '%s'."), $this->dn)); + $smarty->assign("multiple", false); + return($smarty->fetch (get_template_path('remove.tpl', TRUE))); + } else { + + /* Obviously the user isn't allowed to delete. Show message and + clean session. */ + print_red (_("You are not allowed to delete this macro!")); + } + } + + + /***************** + Remove macro + *****************/ + + /* Confirmation for deletion has been passed. Macro should be deleted. */ + if (isset($_POST['delete_macro_confirm'])){ + + $acl = $this->ui->get_permissions($this->dn,"gofonmacro/macro"); + + if(preg_match("/r/",$acl)){ + + /* Delete request is permitted, perform LDAP action */ + $this->macrotabs= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->dn,"gofonmacro"); + $this->macrotabs->delete (); + unset ($this->macrotabs); + $this->macrotabs= NULL; + } else { + /* Normally this shouldn't be reached, send some extra + logs to notify the administrator */ + print_red (_("You are not allowed to delete this macro!")); + new log("security","gofonmacro/".get_class($this),$this->dn,array(),"Tried to trick deletion."); + } + /* Remove lock file after successfull deletion */ + del_lock ($this->dn); + } + + + /***************** + Display open dialogs + *****************/ + + /* Show tab dialog if object is present */ + if (($this->macrotabs) && (isset($this->macrotabs->config))){ + $display= $this->macrotabs->execute(); + + /* Don't show buttons if tab dialog requests this */ + if (!$this->macrotabs->by_object[$this->macrotabs->current]->dialog){ + $display.= "

\n"; + $display.= "\n"; + $display.= " \n"; + if ($this->dn != "new"){ + $display.= "\n"; + $display.= " \n"; + } + $display.= "\n"; + $display.= "

"; + } + return ($display); + } + + + /***************** + Display entry list + *****************/ + + /* Check if there is a snapshot dialog open */ + $base = $this->DivListMacro->selectedBase; + if($str = $this->showSnapshotDialog($base,$this->get_used_snapshot_bases())){ + return($str); + } + + /* Return rendered main page */ + /* Display dialog with system list */ + $this->DivListMacro->parent = $this; + $this->DivListMacro->execute(); + + /* Add departments if subsearch is disabled */ + if(!$this->DivListMacro->SubSearch){ + $this->DivListMacro->AddDepartments($this->DivListMacro->selectedBase,4,1); + } + $this->reload(); + $this->DivListMacro->setEntries($this->macros); + return($this->DivListMacro->Draw()); + } + + + function copyPasteHandling_from_queue($s_action,$s_entry) + { + /* Check if Copy & Paste is disabled */ + if(!is_object($this->CopyPasteHandler)){ + return(""); + } + + /* Add a single entry to queue */ + if($s_action == "cut" || $s_action == "copy"){ + + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + $dn = $this->macros[$s_entry]['dn']; + $this->CopyPasteHandler->add_to_queue($dn,$s_action,"macrotabs","MACROTABS","gofonmacro"); + } + + /* Add entries to queue */ + if($s_action == "copy_multiple" || $s_action == "cut_multiple"){ + + /* Cleanup object queue */ + $this->CopyPasteHandler->cleanup_queue(); + + /* Add new entries to CP queue */ + foreach($this->list_get_selected_items() as $id){ + $dn = $this->macros[$id]['dn']; + + if($s_action == "copy_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"copy","macrotabs","MACROTABS","gofonmacro"); + } + if($s_action == "cut_multiple"){ + $this->CopyPasteHandler->add_to_queue($dn,"cut","macrotabs","MACROTABS","gofonmacro"); + } + } + } + + /* Start pasting entries */ + if($s_action == "editPaste"){ + $this->start_pasting_copied_objects = TRUE; + } + + /* Return C&P dialog */ + if($this->start_pasting_copied_objects && $this->CopyPasteHandler->entries_queued()){ + + /* Load entry from queue and set base */ + $this->CopyPasteHandler->load_entry_from_queue(); + $this->CopyPasteHandler->SetVar("base",$this->DivListMacro->selectedBase); + + /* Get dialog */ + $data = $this->CopyPasteHandler->execute(); + + /* Return dialog data */ + if(!empty($data)){ + return($data); + } + } + + /* Automatically disable status for pasting */ + if(!$this->CopyPasteHandler->entries_queued()){ + $this->start_pasting_copied_objects = FALSE; + } + return(""); + } + + + + /* Return departments, that will be included within snapshot detection */ + function get_used_snapshot_bases() + { + return(array(get_ou('macroou').$this->DivListMacro->selectedBase)); + } + + + function reload() + { + /* Set base for all searches */ + $base = $this->DivListMacro->selectedBase; + $SubSearch = $this->DivListMacro->SubSearch; + $Regex = $this->DivListMacro->Regex; + $Filter = "(&(cn=".$Regex.")(objectClass=goFonMacro))"; + $Flags = GL_SIZELIMIT; + $Attrs = array("cn","description","displayName","goFonMacroVisible"); + + /* Prepare for ls or search*/ + if($SubSearch){ + $Flags |= GL_SUBSEARCH; + }else{ + $base = get_ou('macroou').$base; + } + + /* Generate macro list */ + $res= get_list($Filter, "gofonmacro", $base, $Attrs, $Flags); + + $tmp=array(); + foreach($res as $tkey => $val ){ + $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val; + } + ksort($tmp); + $this->macros=array(); + foreach($tmp as $val){ + $this->macros[]=$val; + } + + reset ($this->macros); + } + + + /* Save data to object */ + function save_object() + { + $this->DivListMacro->save_object(); + } + + + function list_get_selected_items() + { + $ids = array(); + foreach($_POST as $name => $value){ + if(preg_match("/^item_selected_[0-9]*$/",$name)){ + $id = preg_replace("/^item_selected_/","",$name); + $ids[$id] = $id; + } + } + return($ids); + } + + + function adapt_from_template($dn) { } + function check() { } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/macro/class_gofonMacroParameters.inc b/gosa-plugins/gofon/macro/class_gofonMacroParameters.inc new file mode 100644 index 000000000..935321e0f --- /dev/null +++ b/gosa-plugins/gofon/macro/class_gofonMacroParameters.inc @@ -0,0 +1,415 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* Parameter Count*/ + var $para_count = 0 ; + /*! macro base */ + var $base= ""; + + /*! This array contains all Parameter defined for the macro*/ + var $goFonMacroParameter =array(); + + /*! This are the available types for a macro */ + var $type_shortcut= array("string" => array("selected", "", ""), + "combo" => array("", "selected", ""), + "bool" => array("", "", "selected")); + + /*! attribute list for save action */ + var $attributes= array("base","goFonMacroParameter"); + + /*! Objectclasses needed by the class*/ + var $objectclasses= array("top", "goFonMacro"); + var $ui; + + //! The konstructor of macroParameter + /*! The konstructor of macroParameter... + - reads goFonMacroParameter and parses them to an array + - Set attributes from openldap (edit) + - Set attributes from default (new) + */ + function macroParameter (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + $tmp = array(); // temporary Var + $tmp2 = array(); // temporary Var ... + $tmp3 = ""; + $ldap= $config->get_ldap_link(); + + $this->dn = $dn; + + /* This is always an account */ + $this->is_account= TRUE; + + /* Edit or new one ?*/ + if ($this->dn == "new"){ + $ui= get_userinfo(); + $this->base= dn2base($ui->dn); + } else { + $this->base= dn2base($this->dn); + } + + /* initialising macro parameter */ + if(isset($this->attrs['goFonMacroParameter']) && + isset($this->attrs['goFonMacroParameter']['count'])){ + unset($this->attrs['goFonMacroParameter']['count']); + } + + /* Set Parameters, or a new array if ther are no parameters */ + if(isset($this->attrs['goFonMacroParameter'])){ + $this->goFonMacroParameter = $this->attrs['goFonMacroParameter']; + }else{ + $this->goFonMacroParameter =array(); + } + + /* Create an array for parameters if not given yet */ + if(!is_array($this->goFonMacroParameter)){ + $tmp3 = $this->goFonMacroParameter; + $this->goFonMacroParameter =array(); + if(!empty($tmp3)) { + $this->goFonMacroParameter[] = $tmp3; + } + } + + /* Load parametersettings*/ + foreach($this->goFonMacroParameter as $para){ + $tmp = split("!",$para); + $num = $tmp[0]; + $tmp2[$num]['name'] = base64_decode($tmp[1]); + $tmp2[$num]['type'] = $tmp[2]; + $tmp2[$num]['default'] = $tmp[3]; + $tmp2[$num]['var'] = "var".$num; + } + + + /* Assign this array */ + $this->goFonMacroParameter = $tmp2; + + $this->para_count = count ($tmp2); + + $this->ui= get_userinfo(); + } + + //! Perform Parameter check + /*! + Compares the given parameters (goFonMacroParameters) with the parameters defined in goFonContent\n + -> Decide which attrs are new and which are unused\n + -> Sort result array (containing both parameters 'goFonMacroParameters/goFonContent' and new / unused info)\n + \param $content The given goFonContent for this macro\n + \param $goFonMacroParameter Array with the already given parameters \n + */ + function check_paras($content,$goFonMacroParameter) + { + /* Check contents for parameters */ + preg_match_all("/[$]\{ARG[0-9]*\}/",$content,$res,PREG_OFFSET_CAPTURE); + + $new = array(); + + /* Detect parameters with positions */ + foreach($res[0] as $val){ + $num = preg_replace("/[^0-9]/","",$val[0]); + $new[$num]['val'] = $val[0]; + $new[$num]['num'] = $num; + } + + /* Compare content parameter and macro parameter */ + foreach($goFonMacroParameter as $gokey => $goval){ + foreach($new as $nkey => $nval){ + if($gokey == $nval['num']){ + /* sign this as OK */ + $goFonMacroParameter[$gokey]['check']= true; + } + } + } + + /* Now check if there is new parameter in the content, which is not assigned yet */ + foreach($new as $key => $val){ + /* Assign std values */ + $goFonMacroParameter[$key]['var']="var".$key; + $goFonMacroParameter[$key]['check']= true; + + /* If this is a new Parameter, name it ${ARG#} by default*/ + if((!isset($goFonMacroParameter[$key]['name']))||(empty($goFonMacroParameter[$key]['name']))){ + $goFonMacroParameter[$key]['name']="\${ARG".$key."}"; + } + } + + foreach($goFonMacroParameter as $key => $val){ + /* All attributes with check == false, are unneeded so mark them with ['check']= false */ + if(!isset($goFonMacroParameter[$key]['check'])){ + $goFonMacroParameter[$key]['check']= false; + } + /* Ah no default given assign ="" to prevent unsigned index */ + if(!isset($goFonMacroParameter[$key]['default'])){ + $goFonMacroParameter[$key]['default'] = ""; + } + } + + /* Sort output for better reading */ + asort($goFonMacroParameter); + return($goFonMacroParameter); + + } + + //! Execute this Plugin + /*! + Perform Parameter check \n + Draw paramter table\n + Show tpl \n + */ + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Variables */ + $vars = ""; + $tmp = array(); + $number = 0; + + /* Get acls for this tab, + there is only one attribute to write, + so we use the acls from gofon/marco */ + $ACLs = $this->ui->get_permissions($this->dn,"gofonmacro/macro","goFonMarcoContent"); + + /* get current content */ + $macroManagment = session::get('macroManagment') ; + $content = $macroManagment->macrotabs->by_object['macro']->goFonMacroContent; + + if(strstr($content,"ARG")){ + $vorpos = strpos($content,"ARG"); + $rest = substr($content,$vorpos, strlen($content)); + } + + /* Do we represent a valid group? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + _("This 'dn' is no phone macro.").""; + return ($display); + } + + /* Fill templating stuff */ + $smarty= get_smarty(); + + /* Add an empty Parameter */ + if(isset($_POST['addvar']) && preg_match("/w/",$ACLs)){ + if(!is_array($this->goFonMacroParameter)){ + $vars = $this->goFonMacroParameter; + $this->goFonMacroParameter = array(); + $this->goFonMacroParameter[]= $vars; + } + $number= count($this->goFonMacroParameter); + $number++; + $this->goFonMacroParameter[]=array("var"=>"var","name"=>"new","type"=>"string","default"=>"test"); + } + + /*generate Table which shows als parameters */ + $FonParas = $this->check_paras($content,$this->goFonMacroParameter); + + /* Sort by Parameterid, and keep keys */ + ksort($FonParas); + + + + if(!preg_match("/r/",$ACLs)){ + $smarty->assign("readable",false); + }else{ + $smarty->assign("readable",true); + foreach($FonParas as $key=>$para) { + + /* Select correct item of combobox */ + if(isset($para['type'])){ + list($sel1, $sel2, $sel3)= $this->type_shortcut[$para['type']]; + }else{ + list($sel1, $sel2, $sel3)= array("", "", ""); + } + + /* Disable all input fields if we are not allowed to change the parameters */ + $disabled = ""; + if(!preg_match("/w/",$ACLs)){ + $key = ""; + $disabled = " disabled "; + } + + /* Assemble output table */ + $vars .=" + + + ARG".$key." + + + + + + +  "; + if($para['check']==false) { + $vars.=""; + } + + $vars.=" "; + } + } + + /* Checkboxes */ + $smarty->assign("base_select", $this->base); + $smarty->assign("vars", $vars); + + /* Show main page */ + return($smarty->fetch (get_template_path('parameter.tpl', TRUE))); + } + + //! Unused here + /*! + Unused here because goFonMacro will remove this Macro\n + */ + function remove_from_parent() + { + } + + //! Save our data + /*! + Save POST data to object \n + This gives us the possibility to leave a tab, without losing our typed informations\n + \n + Read the POST fields for the parameters and saves their info the the class\n + */ + function save_object() + { + if (isset($_POST['phoneparameters'])){ + plugin::save_object(); + } + /* read out post data, and assign it to the parameters */ + /* And or delete */ + foreach($_POST as $name=>$value){ + + /* Test if there is a variable begining with "del" */ + if(preg_match("/del/",$name)){ + + /* Extract entry id to delete */ + $nr = str_replace("del","",$name) ; + + /* unset entry */ + unset($this->goFonMacroParameter[$nr]); + + }elseif(preg_match("/number/",$name)){ + + /* Set Post vars */ + $key = $_POST[$name]; + + $this->goFonMacroParameter[$key]['var'] = $_POST["var".$key]; + $this->goFonMacroParameter[$key]['name'] = $_POST["varname".$key]; + $this->goFonMacroParameter[$key]['type'] = $_POST["vartype".$key]; + $this->goFonMacroParameter[$key]['default']= $_POST["default".$key]; + } + } + + } + + + //! Checks given values + /*! + Check values\n + If a user enters an invalid value, then this function will output an error msg\n + (In better words :prepare the errormessages that will be put out )\n + */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + foreach($this->goFonMacroParameter as $key=>$val){ + if((strstr($val['default'],"!"))||(strstr($val['default'],"#"))) { + $message[] = sprintf(_("The parameter %s contains invalid char. '!,#' is used as delimiter"),$val['name']); + } + switch($val['type']){ + case 'bool' : $possible = array("","0","1"); + if(!in_array($val['default'],$possible)) { + $message[] = sprintf(_("The parameter %s has incorrect value for type bool."),$val['name']); + };break; + case 'string' : + case 'combo' : + default : ; + + } + } + return $message; + } + + //! Save changes to openldap + /*! + Save to LDAP + This function saves given attributes to the ldap + */ + function save() + { + /* Post checks */ + + plugin::save(); + + $this->attrs['goFonMacroParameter']=array(); + + foreach($this->goFonMacroParameter as $key=>$fonpara){ + $this->attrs['goFonMacroParameter'][]=$key."!".base64_encode($fonpara['name'])."!".$fonpara['type']."!".$fonpara['default']; + } + + if($this->para_count != count($this->attrs['goFonMacroParameter'])){ + print_red(_("Parameter count of the macro changed, you must update each user which are using this macro '%s'."),$this->dn); + } + + unset($this->attrs['base']); + + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($this->dn, array('dn')); + $a= $ldap->fetch(); + + if (count($a)){ + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + $this->handle_post_events("modify"); + } else { + if(count($this->attrs['goFonMacroParameter']==0)){ + unset($this->attrs['goFonMacroParameter']); + } + $ldap->cd($this->dn); + $ldap->create_missing_trees( $this->dn); + $ldap->cd($this->dn); + $ldap->add($this->attrs); + $this->handle_post_events("add"); + } + show_ldap_error($ldap->get_error(), sprintf(_("Removing of goFonMacro/generic account with dn '%s' failed."),$this->dn)); + } + + function PrepareForCopyPaste($source) + { + plugin::PrepareForCopyPaste($source); + + $source_o = new macroParameter($this->config,$source['dn']); + $this->goFonMacroParameter = $source_o-> goFonMacroParameter; + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/macro/generic.tpl b/gosa-plugins/gofon/macro/generic.tpl new file mode 100644 index 000000000..7bedc5219 --- /dev/null +++ b/gosa-plugins/gofon/macro/generic.tpl @@ -0,0 +1,83 @@ + + + + + + +
+ + + + + + + + + + + + + + + + +
{$must} +{render acl=$cnACL} + +{/render} +
{$must} +{render acl=$displayNameACL} + +{/render} +
+
{$must} + {render acl=$baseACL} + + {/render} + + {render acl=$baseACL disable_picture='images/folder_gray.png'} + + {/render} + +
+
+   + + + + + + + + + +
+{render acl=$descriptionACL} + +{/render} +
+{render acl=$goFonMacroVisibleACL} + {t}Visible for user{/t} +{/render} +
+
+

 

+
+{t}Macro text{/t} +
+{render acl=$goFonMacroContentACL} + +{/render} + + + + + diff --git a/gosa-plugins/gofon/macro/headpage.tpl b/gosa-plugins/gofon/macro/headpage.tpl new file mode 100644 index 000000000..79a6fa289 --- /dev/null +++ b/gosa-plugins/gofon/macro/headpage.tpl @@ -0,0 +1,51 @@ + + + + + +
+
+

+ {t}List of macros{/t} {$hint} +

+
+
+ {$macroshead} +
+
+
+ {$macros} + +
+
+
+

[i]{t}Information{/t}

+
+
+

+ {t}This menu allows you to add, edit and remove selected macros. You may want to use the range selector on top of the macro listbox, when working with a large number of macros.{/t} +

+
+
+
+

[F]{t}Filters{/t}

+
+
+ + {$alphabet} +
+ + + + + +
+ {t}Display macros matching{/t} + + +
+ {$apply} +
+
+ + diff --git a/gosa-plugins/gofon/macro/main.inc b/gosa-plugins/gofon/macro/main.inc new file mode 100644 index 000000000..4d438b211 --- /dev/null +++ b/gosa-plugins/gofon/macro/main.inc @@ -0,0 +1,61 @@ +remove_lock(); + del_lock ($ui->dn); + session::un_set ('macroManagment'); + } +} else { + + /* Create macroManagment object on demand */ + if (!session::is_set('macroManagment') || (isset($_GET['reset']) && $_GET['reset'] == 1)){ + session::set('macroManagment',new goFonMacro ($config, $ui)); + } + + /* Get object */ + $macroManagment = session::get('macroManagment'); + $macroManagment->save_object(); + $output= $macroManagment->execute(); + + /* Page header*/ + if (session::is_set('objectinfo')){ + $display= print_header( get_template_path('images/macros.png'), + _("Phone macro management"), + "\"\" + ".@LDAP::fix(session::get('objectinfo'))); + } else { + $display= print_header(get_template_path('images/macros.png'), _("Phone macro management")); + } + + /* Reset requested? */ + if (isset($_GET['reset']) && $_GET['reset'] == 1){ + del_lock ($ui->dn); + session::un_set ('macroManagment'); + } + + /* Show and save dialog */ + $display.= $output; + session::set('macroManagment',$macroManagment); +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/macro/parameter.tpl b/gosa-plugins/gofon/macro/parameter.tpl new file mode 100644 index 000000000..48e99cd82 --- /dev/null +++ b/gosa-plugins/gofon/macro/parameter.tpl @@ -0,0 +1,28 @@ +{if $readable} + + + + + + + + + {$vars} +
{t}Argument{/t} + {t}Name{/t} + {t}type{/t} + {t}Default value{/t} + +   +
+{else} +

{t}You are not allowed to view the macro parameter settings{/t}

+{/if} + + + + diff --git a/gosa-plugins/gofon/macro/paste_generic.tpl b/gosa-plugins/gofon/macro/paste_generic.tpl new file mode 100644 index 000000000..0f5acf467 --- /dev/null +++ b/gosa-plugins/gofon/macro/paste_generic.tpl @@ -0,0 +1,9 @@ + + + + + +
+ {$must} + +
diff --git a/gosa-plugins/gofon/macro/remove.tpl b/gosa-plugins/gofon/macro/remove.tpl new file mode 100644 index 000000000..4dbd248c5 --- /dev/null +++ b/gosa-plugins/gofon/macro/remove.tpl @@ -0,0 +1,23 @@ +
+  {t}Warning{/t} +
+

+ {$intro} + {t}This may be used by several groups. Please double check if your really want to do this since there is no way for GOsa to get your data back.{/t} +

+

+ {t}So - if you're sure - press 'Delete' to continue or 'Cancel' to abort.{/t} +

+ +

+ {if $multiple} + +   + + {else} + +   + + {/if} +

+ diff --git a/gosa-plugins/gofon/macro/tabs_macros.inc b/gosa-plugins/gofon/macro/tabs_macros.inc new file mode 100644 index 000000000..b2003f86e --- /dev/null +++ b/gosa-plugins/gofon/macro/tabs_macros.inc @@ -0,0 +1,40 @@ +addSpecialTabs(); + } + + function save($ignore_account= FALSE) + { + $baseobject= $this->by_object['macro']; + + /* Check for new 'dn', in order to propagate the + 'dn' to all plugins */ + $new_dn= "cn=".$baseobject->cn.",".get_ou('macroou').$baseobject->base; + + /* Move group? */ + if ($this->dn != $new_dn){ + + /* Write entry on new 'dn' */ + if ($this->dn != "new"){ + $baseobject->move($this->dn, $new_dn); + $this->by_object['macro']= $baseobject; + } + + /* Happen to use the new one */ + $this->dn= $new_dn; + } + + tabs::save(); + } + +} + +?> diff --git a/gosa-plugins/gofon/phoneaccount/class_phoneAccount.inc b/gosa-plugins/gofon/phoneaccount/class_phoneAccount.inc new file mode 100644 index 000000000..a247dec96 --- /dev/null +++ b/gosa-plugins/gofon/phoneaccount/class_phoneAccount.inc @@ -0,0 +1,1644 @@ + "Eins ist toll", "zwei" => "Zwei ist noch besser"); + + /* attribute list for save action */ + var $CopyPasteVars = array("phoneNumbers","macroarray","macrostillavailable"/*"phoneNumbers" -Reset- */, + "hardware_list","used_hardware"); + + var $attributes = array("goFonDeliveryMode", "goFonFormat","cn","goFonHomeServer", + "goFonHardware","goFonPIN","goFonVoicemailPIN","telephoneNumber", "goFonMacro","macro"); + var $objectclasses= array("goFonAccount"); + + var $uid; + + var $view_logged = FALSE; + var $multiple_support = TRUE; + + function phoneAccount (&$config, $dn= NULL, $parent= NULL) + { + plugin::plugin ($config, $dn, $parent); + + /* Assemble phone numbers */ + if (isset($this->attrs['telephoneNumber'])){ + for ($i= 0; $i<$this->attrs['telephoneNumber']['count']; $i++){ + $number= $this->attrs['telephoneNumber'][$i]; + $this->phoneNumbers[$number]= $number; + } + } + + /* Set up has_mailAccount */ + if (isset($this->attrs['objectClass'])){ + if (in_array("gosaMailAccount", $this->attrs['objectClass'])){ + $this->has_mailAccount= TRUE; + } + } + + /* Set uid */ + if((isset($this->parent->by_object['user']->uid))&&(!empty($this->parent->by_object['user']->uid))){ + $this->uid = $this->parent->by_object['user']->uid; + } + if((isset($this->parent->by_object['user']->cn))&&(!empty($this->parent->by_object['user']->cn))){ + $this->cn = $this->parent->by_object['user']->cn; + } + + /* Check server configurations + * Load all server configuration in $this->goFonHomeServers if available + * and first server as default if necessary. + * Check if connection is successfull for the selected server $this->goFonHomeServer + */ + + + /* Set available server */ + $config = session::get('config'); + if(isset($config->data['SERVERS']['FON'])){ + $this->goFonHomeServers = $config->data['SERVERS']['FON']; + } + + $a_SETUP= array(); + if($this->is_account && isset($config->data['SERVERS']['FON']) && + array_key_exists('FON',$config->data['SERVERS']) && + is_callable("mysql_connect") + ) { + + /* Servers defined? Watch here... */ + if (count($this->goFonHomeServers)){ + + /* Set default server */ + if(empty($this->goFonHomeServer) || $this->goFonHomeServer == "0"){ + $this->goFonHomeServer= $this->goFonHomeServers[0]['DN']; + } + + /* Remember inital home server, to be able to remove old entries */ + $this->init_HomeServer = $this->goFonHomeServer; + + /* Get config */ + if(!isset($this->goFonHomeServers[$this->goFonHomeServer])){ + print_red(sprintf(_("The specified goFonHomeServer '%s' is not available in GOsa server configuration. Saving this account will create a new entry on the server '%s'. Use cancel if you do not want to create a new entry ignoring old accounts."),$this->goFonHomeServer, $this->goFonHomeServers[0]['DN'])); + + $this->goFonHomeServer = $this->goFonHomeServers[0]['DN']; + $this->init_HomeServer = $this->goFonHomeServers[0]['DN']; + } + $cur_cfg = $this->goFonHomeServers[$this->goFonHomeServer]; + + $r_con = @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']); + if(!$r_con){ +# print_red( sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."), +# $cur_cfg['SERVER'],$cur_cfg['LOGIN'])); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); + } + $db = @mysql_select_db($cur_cfg['DB'],$r_con); + if(!$db){ +# print_red(sprintf(_("Can't select database %s on %s."),$cur_cfg['DB'],$cur_cfg['SERVER'])); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); + } + + $first = false; + foreach($this->phoneNumbers as $key => $val){ + if(!$first){ + $first = $key; + } + } + } + } + + /* Get available phone hardware + * Search for all available phone hardware + */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(objectClass=goFonHardware)", array('cn', 'description')); + while ($attrs= $ldap->fetch()){ + $cn= $attrs['cn'][0]; + if (isset($attrs['description'])){ + $description= " - ".$attrs['description'][0]; + } else { + $description= ""; + } + $this->hardware_list[$cn]= "$cn$description"; + } + + + /* Get available Macros + * Search for all Marcos that are visible and create + * an array with name and parameters + */ + $ldap->search("(&(objectClass=goFonMacro)(goFonMacroVisible=1))", array("*")); + + /* Add none for no macro*/ + $this->macros['none']=_("no macro"); + $this->macro ="none"; + + /* Fetch all Macros*/ + while ($attrs= $ldap->fetch()){ + + /* unset Count, we don't need that here */ + unset($attrs['displayName']['count']); + + /* Parse macro data, unset count for parameterarrays */ + if (isset($attrs['goFonMacroParameter']['count'])){ + unset($attrs['goFonMacroParameter']['count']); + } + + /* fill Selectfield variable with Macros */ + if(isset($attrs['displayName'][0])){ + $this->macros[$attrs['dn']] = $attrs['displayName'][0]." (".$attrs['cn'][0].")"; + }else{ + $this->macros[$attrs['dn']] = _("undefined"); + } + + /* Go through available parameters and parse all attributes, like parametername, type, default ...*/ + if((isset($attrs['goFonMacroParameter']))&&(is_array($attrs['goFonMacroParameter']))){ + + foreach($attrs['goFonMacroParameter'] as $pkey=>$pval){ + /* Split Data in readable values, by delimiter ! */ + $data = split("!",$attrs['goFonMacroParameter'][$pkey]); + + /* Set all attrs */ + $id = $data[0]; + $this->macroarray[$attrs['dn']][$id]['var'] ="var".$id; + $this->macroarray[$attrs['dn']][$id]['choosen']=$data[3]; + $this->macroarray[$attrs['dn']][$id]['id'] =$id; + $this->macroarray[$attrs['dn']][$id]['name'] =$data[1]; + $this->macroarray[$attrs['dn']][$id]['type'] =$data[2]; + $this->macroarray[$attrs['dn']][$id]['default']=$data[3]; + if($data[2] == "bool"){ + $this->macroarray[$attrs['dn']][$id]['choosen']=$data[3]; + } + }//foreach + }//is_array + }//while + + + /* Parse used Macro + * If we have a macro selected, parse it and set values + * in $this->macroarray[$this->macro]. + */ + $tmp = split("!",$this->goFonMacro); + if(is_array($tmp)){ + + /* First value is the macroname */ + $this->macro = $tmp[0]; + + /* Macroname saved, delete that index */ + unset($tmp[0]); + + /* Check if makro has been removed */ + if(!isset($this->macros[$this->macro])){ + $this->macrostillavailable = false; + }else{ + $this->macrostillavailable = true; + } + + /* for each parametervalues ( parameterID#value like 25#twentyfive) */ + foreach($tmp as $var){ + + /* Split this, so we have $varar[0] = parameterID $varar[1] = SelectedValue */ + $varar = split("#",$var); + + /* Only insert if the parameter still exists */ + if(isset($this->macroarray[$this->macro][$varar[0]])){ + /* Assign value */ + $this->macroarray[$this->macro][$varar[0]]['choosen']=$varar[1]; + } + } + } + + + /* Colorize phones + * Used phones will be colored in grey, + * so we must detect which phones are currently in use. + */ + $ldap->cd($this->config->current['BASE']); + $ldap->search("(goFonHardware=*)",array('cn','dn','goFonHardware')); + while($attrs = $ldap->fetch()){ + $cn = $attrs['goFonHardware'][0]; + if(isset($this->hardware_list[$cn])){ + $this->used_hardware[$cn]= $cn; + } + } + $this->hardware_list["automatic"]= _("automatic"); + ksort($this->hardware_list); + $this->a_old_telenums = $this->phoneNumbers; + + /* Get voicemail PIN from MySQL DB + * Because every user can change his PIN directly from the phone + * without any update to the ldap + * This means, the PIN in the DB is up to date + */ + // Connect to DB server + if((is_callable("mysql_pconnect"))&&(isset($cur_cfg))&&(isset($cur_cfg['SERVER']))&&(isset($cur_cfg['LOGIN']))&&(isset($cur_cfg['PASSWORD']))){ + $r_con = @mysql_pconnect($cur_cfg['SERVER'],$cur_cfg['LOGIN'],$cur_cfg['PASSWORD']); + if($r_con){ + $r_db = @mysql_select_db($cur_cfg['DB'],$r_con); + + $query_tmp = "SELECT ".$cur_cfg['VOICE_TABLE'].".password FROM ".$cur_cfg['VOICE_TABLE'].", ". + $cur_cfg['SIP_TABLE']." WHERE customer_id = sip_users.mailbox AND name='".$this->uid."'"; + + $vp = mysql_fetch_row(mysql_query($query_tmp)); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query_tmp, "Database query"); + if((isset($vp[0]))&&(!empty($vp[0]))){ + $this->goFonPINVoice = $vp[0]; + } + } + } + $this->lastmacro=$this->macro; + + if(is_callable("mysql_close")&&(isset($r_con))&&($r_con)){ + @mysql_close($r_con) ; + } + } + + + /* This function generates the Database entries. + * The Parameter 'save' could be true or false. + * false - means only testing no database transactions. + * true - write database entries. + * + * 'sip_users','voice_mail' and 'extensions' table entries will be created. + * + * If the phone hardware is 'automatic' the table entries will only be removed + * and not added. + */ + function generate_mysql_entension_entries($save = false) + { + /* Check if there is at least one server available + * If not, return and tell the user that saving failed + */ + if(!count($this->goFonHomeServers)){ + if($save){ + print_red(_("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.")); + } + return(true); + } + + /* Check if Mysql extension is available */ + if(!is_callable("mysql_pconnect")){ + if($save) + print_red(_("Can't save any changes to asterisk database, there is no mysql extension available.")); + return(true); + } + + /********************** + * Attribute Initialisation + **********************/ + + $old_connection = false; + + // Get Configuration for Mysql database Server + $s_parameter = ""; // Contains paramter for selected Macro + $r_con = false; // DB connection + $r_db = false; // Selected DB + $r_res = false; // Result resource + $a_ldap_attrs = array(); // + + $s_ip = NULL; // Contains ip for Sip entry + $s_host = NULL; // Contains host for Sip entry + $s_qualify = "yes"; // Qualify entry + $s_pin = NULL; // Entry for secret + $s_type = NULL; // Entry for phone type (friend , peer ..) + + $sip_data_array = array(); // Contains complete sip entry, to generate SQL syntax + $i_old_key = false; // Contains index for first old phonenumber, to delete old entries corectly + $i_new_key = false; // Contains index for first new phonenumber, to generate new entries corectly + + $s_sip_values = ""; // Contains string with all values for given attributes in SQL syntax + $s_sip_keys = ""; // Contains all needed attributes to generate sip entry in DB + + $s_sip_key = ""; // Key for SIP entry index + $s_sip_val = ""; // Value for SIP entry index + + $b_first_deleted= false; // Only delete first entry, + $s_telenums = ""; // for each value variable + + $i_is_accounted = false; // Ensure that extension entry, for name to number is only once in table + + restore_error_handler(); + + /* Prepare some basic attributes */ + foreach($this->a_old_telenums as $tele){ + $oldnums[]= preg_replace("/[^0-9]/","",$tele); + } + foreach($this->phoneNumbers as $tele){ + $newnums[]= preg_replace("/[^0-9]/","",$tele); + } + + /* If deletion starts from userslist, cn uid are not set */ + if((isset($this->parent->by_object['user']->uid))&&(!empty($this->parent->by_object['user']->uid))){ + $this->uid = $this->parent->by_object['user']->uid; + } + if((isset($this->parent->by_object['user']->cn))&&(!empty($this->parent->by_object['user']->cn))){ + $this->cn = $this->parent->by_object['user']->cn; + } + /* Create voicemail entry + */ + if((!isset($this->cn))||(empty($this->cn))){ + $CNname= $this->uid; + }else{ + $CNname= $this->cn; + } + + if((isset($this->parent))&&(isset($this->parent->by_object['mailAccount']))&&($this->parent->by_object['mailAccount']->is_account==true)){ + $s_mail = $this->parent->by_object['mailAccount']->mail; + }else{ + $s_mail = ""; + } + /* Get phonehardware to setup sip entry */ + $ldap = $this->config->get_ldap_link(); + $r_res = $ldap->search("(&(objectClass=goFonHardware)(cn=".$this->goFonHardware."))", array('*')); + $a_ldap_attrs = $ldap->fetch(); + + /* Check selected phone hardware, is a default IP set? */ + if(((isset($a_ldap_attrs['goFonDefaultIP'][0]))&&($a_ldap_attrs['goFonDefaultIP'][0] != "dynamic"))){ + $s_ip = $a_ldap_attrs['goFonDefaultIP'][0]; + $s_host = $s_ip; + }else{ + $s_ip = NULL; + $s_host = "dynamic"; + } + + // Attribute GoFonQualify set ? + if(isset($a_ldap_attrs['goFonQualify'])){ + $s_qualify = $a_ldap_attrs['goFonQualify'][0]; + } + + // Attribute GoFonPIN set ? + if(isset($this->goFonPIN)){ + $s_pin = $this->goFonPIN; + } + + // Attribute GoFonType set ? + if(isset($a_ldap_attrs['goFonType'])){ + $s_type = $a_ldap_attrs['goFonType'][0]; + } + + if(isset($a_ldap_attrs['goFonDmtfMode'][0])){ + $sip_data_array['dtmfmode'] = $a_ldap_attrs['goFonDmtfMode'][0]; + }else{ + $sip_data_array['dtmfmode'] ="rfc2833"; + } + + /* Check if phone number is used */ + if($this->is_number_used()){ + $this->generate_error = $this->is_number_used(); + return false; + } + + + + /********************** + * Check Server Connection Information + **********************/ + + /* Create Mysql handle for the current goFonHomeServer, if possible + * Get configuration to old asterisk home server + */ + $a_New = $this->goFonHomeServers[$this->goFonHomeServer]; // DB Configuration + $new_connection = @mysql_pconnect($a_New['SERVER'],$a_New['LOGIN'],$a_New['PASSWORD']); + if(!$new_connection){ + $this->generate_error = sprintf( + _("The MySQL Server '%s' isn't reachable as user '%s'. Abort saving entries to keep the database consistent, check GOsa log for mysql error."), + $a_New['SERVER'],$a_New['LOGIN']); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($new_connection)); + return false; + } + $new_database = @mysql_select_db($a_New['DB'],$new_connection); + if(!$new_database){ + $this->generate_error = sprintf( + _("Can't select database %s on %s. Abort saving entries to keep the database consistent, check GOsa log for mysql error."), + $a_New['DB'],$a_New['SERVER']); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($new_connection)); + return false; + } + + /* If the home server has changed, we must remove entries from old + * server and add new entries in new server. + */ + if($this->init_HomeServer != $this->goFonHomeServer){ + + /* Get configuration to old asterisk home server */ + $a_Remove = $this->goFonHomeServers[$this->init_HomeServer]; // DB Configuration + + /* Create connection to the database that contains the old entry. + */ + $old_connection = @mysql_pconnect($a_Remove['SERVER'],$a_Remove['LOGIN'],$a_Remove['PASSWORD']); + if(!$old_connection){ + $this->generate_error = sprintf( + _("The old MySQL home server '%s' isn't reachable as user '%s'. Abort saving entries to keep the database consistent, check GOsa log for mysql error."), + $a_Remove['SERVER'],$a_Remove['LOGIN']); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($old_connection)); + return false; + } + $old_database = @mysql_select_db($a_Remove['DB'],$old_connection); + if(!$old_database){ + $this->generate_error = sprintf( + _("Can't select database %s on %s. Abort saving entries to keep the database consistent, check GOsa log for mysql error."), + $a_Remove['DB'],$a_Remove['SERVER']); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error($old_connection)); + return false; + } + } + + /* Save means that we must save changes, not only test */ + if($save == true){ + + /********************** + * Remove entries from old home server + **********************/ + + /* Check if there is an old entry + * If there is an old entry, get callerid and remove voicemail and extensions + */ + if($old_connection){ + $query = "SELECT id,name,callerid FROM ".$a_Remove['SIP_TABLE']." WHERE name='".$this->uid."';"; + $rid = mysql_query($query,$old_connection); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + + /* Old entry found, remove it */ + $query_a = array(); + if(mysql_affected_rows($old_connection)){ + $result = mysql_fetch_assoc($rid); + $query_a[]= "DELETE FROM ".$a_Remove['SIP_TABLE']." WHERE name='".$this->uid."';"; + $query_a[]= "DELETE FROM ".$a_Remove['VOICE_TABLE']." WHERE customer_id='".$result['callerid']."';"; + $query_a[]= "DELETE FROM ".$a_Remove['EXT_TABLE']." WHERE exten='".$this->uid."';"; + foreach($oldnums as $s_telenums) { + $query_a[]= "DELETE FROM ".$a_Remove['EXT_TABLE']." WHERE exten='".$s_telenums."';"; + } + + foreach($query_a as $qry){ + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$qry, "Database query"); + if(!mysql_query($qry,$old_connection)){ + echo mysql_error($old_connection); + } + } + } + } + + /********************** + * Update / Insert sip_users entry + **********************/ + + /* Set the first given phone number as callerid */ + reset($newnums); + $i_new_key = key($newnums); + $sip_data_array['callerid'] =$newnums[$i_new_key]; + $sip_data_array['mailbox'] =$newnums[$i_new_key]; + + /* Check if there is already an entry in sip_users for this uid */ + $SQL_query_array = array(); + $query = "SELECT * FROM ".$a_New['SIP_TABLE']." WHERE name='".$this->uid."';\n"; + $rid = mysql_query($query,$new_connection); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(mysql_affected_rows($new_connection)){ + + /********************** + * Update sip_users entry + **********************/ + $result = mysql_fetch_assoc($rid); + $sip_data_array['host'] = $s_host; + $sip_data_array['qualify'] = $s_qualify; + $sip_data_array['secret'] = $this->goFonPIN; + $sip_data_array['type'] = $s_type ; + $sip_data_array['username'] = $this->uid; + $sip_data_array['ipaddr'] = $s_ip; + + /* Remove not changed attributes, to avoid updating table with same values */ + foreach($sip_data_array as $name => $value){ + if($result[$name] == $value){ + unset($sip_data_array[$name]); + } + } + /* Only update entry if there is something to uopdate */ + if(count($sip_data_array)){ + $query = "UPDATE ".$a_New['SIP_TABLE']." SET "; + foreach($sip_data_array as $key => $val){ + $query.= "".$key."='".$val."',"; + } + $query = preg_replace("/,$/","",$query); + $query.= " WHERE name='".$this->uid."';"; + $SQL_query_array[] = $query; + } + } else { + + /********************** + * Insert sip_users entry + **********************/ + //generate SIP entry + $sip_data_array['id'] = ""; + $sip_data_array['name'] = $this->uid; + $sip_data_array['accountcode'] = NULL; + $sip_data_array['amaflags'] = NULL; + $sip_data_array['callgroup'] = NULL; + $sip_data_array['canreinvite'] = "no"; + $sip_data_array['context'] = "default"; + $sip_data_array['defaultip'] = NULL; + $sip_data_array['fromuser'] = NULL; + $sip_data_array['fromdomain'] = NULL; + $sip_data_array['host'] = $s_host; + $sip_data_array['insecure'] = NULL; + $sip_data_array['language'] = NULL; + $sip_data_array['mailbox'] = $newnums[$i_new_key]; + $sip_data_array['md5secret'] = NULL; + $sip_data_array['nat'] = "no"; + $sip_data_array['permit'] = NULL; + $sip_data_array['deny'] = NULL; + $sip_data_array['mask'] = NULL; + $sip_data_array['pickupgroup'] = NULL; + $sip_data_array['port'] = NULL; + $sip_data_array['qualify'] = $s_qualify; + $sip_data_array['restrictcid'] = "n"; + $sip_data_array['rtptimeout'] = NULL; + $sip_data_array['rtpholdtimeout']=NULL; + $sip_data_array['secret'] = $this->goFonPIN; + $sip_data_array['type'] = $s_type ; + $sip_data_array['username'] = $this->uid; + $sip_data_array['disallow'] = NULL; + $sip_data_array['allow'] = NULL; + $sip_data_array['musiconhold'] = NULL; + $sip_data_array['regseconds'] = NULL; + $sip_data_array['ipaddr'] = $s_ip; + $sip_data_array['regexten'] = NULL; + $sip_data_array['cancallforward']=NULL; + + /* There is currently no entry for this user in the sip_users table. + * We should create one i + */ + foreach($sip_data_array as $s_sip_key=>$s_sip_val){ + if($s_sip_val === NULL) continue; + $s_sip_values.="'".$s_sip_val."',"; + $s_sip_keys .="`".$s_sip_key."`,"; + } + $s_sip_values = preg_replace("/,$/","",$s_sip_values); + $s_sip_keys = preg_replace("/,$/","",$s_sip_keys); + + /* Add sip entries to mysql queries */ + $SQL_query_array[] ="INSERT INTO ".$a_New['SIP_TABLE']." (".$s_sip_keys.") VALUES (".$s_sip_values.");"; + } + + + /********************** + * Update / Insert Voice mail entry + **********************/ + + $customer_id = $newnums[$i_new_key]; + + $voice_data_array = array( + "customer_id" => $customer_id, + "mailbox" => $customer_id, + "password" => $this->goFonVoicemailPIN, + "fullname" => $CNname, + "email" => $s_mail); + + /* Set pager number if available */ + if(isset($this->parent->by_object['user']->pager)){ + $voice_data_array['pager'] = $this->parent->by_object['user']->pager; + } + + /* Check if there is already an entry in sip_users for this uid */ + $query_tmp = "SELECT * FROM ".$a_New['VOICE_TABLE']." WHERE customer_id='".$customer_id."';\n"; + $rid = mysql_query($query_tmp,$new_connection); + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query_tmp, "Database query"); + if(mysql_affected_rows($new_connection)){ + + /********************** + * Update Voice mail entry + **********************/ + $result = mysql_fetch_assoc($rid) ; + + foreach($voice_data_array as $name => $value){ + if($result[$name] == $value){ + unset($voice_data_array[$name]); + } + } + + /* Only update entry if there is something to uopdate */ + if(count($voice_data_array)){ + $query = "UPDATE ".$a_New['VOICE_TABLE']." SET "; + foreach($voice_data_array as $key => $val){ + $query.= "".$key."='".$val."',"; + } + $query = preg_replace("/,$/","",$query); + $query.= " WHERE customer_id='".$customer_id."';"; + $SQL_query_array[] = $query; + } + }else{ + + /********************** + * Insert Voice mail entry + **********************/ + $voice_data_array['context'] = "default"; + + /* There is currently no voice mail entry for this user. + * We should create one + */ + $s_voi_values = $s_voi_keys = ""; + foreach($voice_data_array as $s_voi_key=>$s_voi_val){ + if($s_voi_val === NULL) continue; + $s_voi_values.="'".$s_voi_val."',"; + $s_voi_keys .="`".$s_voi_key."`,"; + } + $s_voi_values = preg_replace("/,$/","",$s_voi_values); + $s_voi_keys = preg_replace("/,$/","",$s_voi_keys); + + /* Add sip entries to mysql queries */ + $SQL_query_array[] ="INSERT INTO ".$a_New['VOICE_TABLE']." (".$s_voi_keys.") VALUES (".$s_voi_values.");"; + } + + + /********************** + * Remove/Insert extension entries + **********************/ + + /* Remove old entries */ + $query = array(); + $query[]= "DELETE FROM ".$a_New['EXT_TABLE']." WHERE exten=\"".$this->uid."\";"; + foreach($oldnums as $s_telenums){ + $query[]= "DELETE FROM ".$a_New['EXT_TABLE']." WHERE exten=\"".$s_telenums."\";"; + } + foreach($newnums as $s_telenums){ + $query[]= "DELETE FROM ".$a_New['EXT_TABLE']." WHERE exten=\"".$s_telenums."\";"; + } + foreach($query as $qry){ + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$qry, "Database query"); + if(!mysql_query($qry,$new_connection)){ + echo mysql_error($new_connection); + } + } + + /********************** + * Insert extension entries + **********************/ + + // Get selected Macro Parameter and create parameter entry + if(isset($this->macroarray[$this->macro])){ + foreach($this->macroarray[$this->macro] as $key => $val ){ + $s_parameter .= $val['choosen']."|"; + } + $s_parameter = preg_replace("/\|$/","",$s_parameter); + } + + $i = 0; + $EXT = array(); + if(!is_numeric($this->uid)){ + $EXT[$i]['context'] = 'GOsa'; + $EXT[$i]['exten'] = $this->uid; + $EXT[$i]['priority']= 1; + $EXT[$i]['app'] = "Goto"; + $EXT[$i]['appdata'] = $newnums[$i_new_key]."|1"; + $i ++; + } + + // Entension entries Hint / Dial / Goto + foreach($newnums as $s_telenums){ + + /* Hint Entry */ + $EXT[$i]['context'] = 'GOsa'; + $EXT[$i]['exten'] = $s_telenums; + $EXT[$i]['priority']= "Hint"; + $EXT[$i]['app'] = 'SIP/'.$this->uid; + $i ++; + /* SetCID */ + //$EXT[$i]['context'] = 'GOsa'; + //$EXT[$i]['exten'] = $s_telenums; + //$EXT[$i]['priority']= 1; + //$EXT[$i]['app'] = "SetCIDName"; + //$EXT[$i]['appdata'] = $CNname; + //$i ++; + + // If no macro is selected use Dial + if($this->macro!="none"){ + $macroname = preg_replace("/,.*$/","",$this->macro); + $macroname = preg_replace("/^.*=/","",$macroname); + $s_app = "Macro";$macroname; + $s_par = $macroname."|".$s_parameter; + }else{ + $s_app = "Dial"; + $s_par = 'SIP/'.$this->uid."|20|r"; + } + + $EXT[$i]['context'] = 'GOsa'; + $EXT[$i]['exten'] = $s_telenums; + $EXT[$i]['priority']= 1; + $EXT[$i]['app'] = $s_app; + $EXT[$i]['appdata'] = $s_par; + $i ++; + } + + // Append all these Entries + foreach($EXT as $entr){ + $SQL_syn = "INSERT INTO ".$a_New['EXT_TABLE']." ("; + foreach($entr as $key2 => $val2){ + $SQL_syn.= "`".$key2."`,"; + } + $SQL_syn = preg_replace("/,$/","",$SQL_syn); + $SQL_syn .= ") VALUES ("; + foreach($entr as $key2 => $val2){ + $SQL_syn .= "'".$val2."',"; + } + $SQL_syn = preg_replace("/,$/","",$SQL_syn); + $SQL_syn .=");\n"; + + $SQL_query_array[] =$SQL_syn; + $SQL_syn =""; + } + + // Perform queries ... + if($this->goFonHardware != "automatic"){ + foreach($SQL_query_array as $query){ + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(!@mysql_query($query,$new_connection)){ + print_red(_("Error while performing query:")." ".mysql_error()); + return false; + } + } + } + } + @mysql_close($new_connection); + return true; + } + + + function execute() + { + /* Call parent execute */ + plugin::execute(); + + /* Log view */ + if($this->is_account && !$this->view_logged){ + $this->view_logged = TRUE; + new log("view","users/".get_class($this),$this->dn); + } + + $display = ""; + $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit'); + if(empty($this->macro)&&(!empty($this->goFonMacro))){ + + /* Go through already saved values, for a parameter */ + $tmp = split("!",$this->goFonMacro); + + /* it is possible that nothing has been saved yet */ + if(is_array($tmp)){ + + /* First value is the macroname */ + $this->macro = $tmp[0]; + + /* Macroname saved, delete that index */ + unset($tmp[0]); + + /* Check if macro has been removed */ + if(!isset($this->macroarray[$this->macro])){ + $this->macrostillavailable = false; + }else{ + $this->macrostillavailable = true; + } + + /* for each parametervalues ( parameterID#value like 25#twentyfive) */ + foreach($tmp as $var){ + + /* Split this, so we have $varar[0] = parameterID $varar[1] = SelectedValue */ + $varar = split("#",$var); + + /* Only insert if the parameter still exists */ + if(isset($this->macroarray[$this->macro][$varar[0]])){ + /* Assign value */ + $this->macroarray[$this->macro][$varar[0]]['choosen']=$varar[1]; + } + } + } + } + + /* Do we represent a valid account? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + _("This account has no phone extensions.").""; + $display.= back_to_main(); + return ($display); + } + + /* Do we need to flip is_account state? */ + if (isset($_POST['modify_state'])){ + $this->is_account= !$this->is_account; + } + + /* Do we represent a valid account? */ + if (!$this->is_account && $this->parent === NULL){ + $display= "\"\" ". + _("This account has no phone extensions.").""; + $display.= back_to_main(); + return($display); + } + + $display= ""; + + /* Show tab dialog headers */ + + if (!$this->multiple_support_active && $this->parent !== NULL){ + if ($this->is_account){ + $display= $this->show_disable_header(_("Remove phone account"), + _("This account has phone features enabled. You can disable them by clicking below.")); + } else { + if(empty($this->uid)){ + $display= $this->show_enable_header(_("Create phone account"), + _("This account has phone features disabled. You can't enable them while no uid is set."),TRUE,TRUE); + }else{ + $display= $this->show_enable_header(_("Create phone account"), + _("This account has phone features disabled. You can enable them by clicking below.")); + } + return ($display); + } + } + /* Select no macro if, state is empty, this is the case, if the selected macro is no longer available */ + if(empty($this->macro)){ + $this->macro ="none"; + } + + /* Prepare templating */ + $smarty= get_smarty(); + + /* tell user that the selected plugin is no longer available */ + if((!$this->macrostillavailable)&&($this->macro!="none")){ + print_red(_("The macro you selected, is no longer available for you, please choose another one.")); + } + + /* Assing macroselectbox values */ + $smarty->assign("macros",$this->macros); + $smarty->assign("macro", $this->macro); + + /* check if there is a FON server created */ + if(!count($this->goFonHomeServer)){ + print_red(_("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.")); + } + + /* Create html parameter table for selected macro parameters + * skip if no parameters given + */ + if(!isset($this->macroarray[$this->macro])){ + $macrotab=""; + }else{ + + $macrotab =""; + /* for every single parameter-> display textfile,combo, or true false switch*/ + + foreach($this->phoneNumbers as $phonenum){ + $tmp[] = $phonenum; + } + + if($this->macro != $this->lastmacro){ + /* Go through all params */ + foreach($this->macroarray[$this->macro] as $key => $paras){ + + $string = $paras['default']; + + $string=preg_replace("/%uid/i",$this->uid,$string); + + if(isset($this->cn)){ + $string=preg_replace("/%cn/i",$this->cn,$string); + } + + for($i = 0 ; $i < 10; $i++){ + if(isset($tmp[$i])){ + $string = preg_replace("/%telephoneNumber_".($i+1)."/i",$tmp[$i],$string); + } + } + if(isset($tmp[0])){ + $string = preg_replace("/%telephoneNumber/i",$tmp[0],$string); + } + $this->macroarray[$this->macro][$key]['choosen']=$string; + } + } + + foreach($this->macroarray[$this->macro] as $paras){ + + /* get al vars */ + $var = $paras['var']; + $name = $paras['name']; + $default = $paras['default']; + $type = $paras['type']; + $choosen = $paras['choosen'] ; + $str = $default; + + $dis = ""; + if(!$this->acl_is_writeable("goFonMacro",$SkipWrite)){ + $dis = " disabled "; + } + + /* in case of a combo box display a combobox with selected attr */ + $macrotab.= ""; + switch ($type){ + + case "combo": + $str= ""; + $macrotab.= ""; + + } + $macrotab.="
".base64_decode($name)."$str"; + break; + + case "bool": + if(!$choosen){ + $str="\n"; + }else{ + $str="\n"; + } + $macrotab.= "$str ".base64_decode($name).""; + break; + + case "string": + $str=""; + $macrotab.= "".base64_decode($name)."$str"; + break; + + } + $macrotab.= "
"; + }//is_array() + + /* Give smarty the table */ + $smarty->assign("macrotab",$macrotab); + + + /* Add phone number */ + if (isset($_POST["add_phonenumber"]) && $_POST['phonenumber']){ + if (tests::is_phone_nr($_POST['phonenumber'])){ + $number= $_POST["phonenumber"]; + $this->phoneNumbers[$number]= $number; + $this->is_modified= TRUE; + } else { + print_red(_("Please enter a valid phone number!")); + } + } + + /* Remove phone number */ + if (isset($_POST["delete_phonenumber"]) && isset($_POST["phonenumber_list"])){ + foreach ($_POST['phonenumber_list'] as $number){ + unset($this->phoneNumbers[$number]); + $this->is_modified= TRUE; + } + } + + /* Assign acls */ + $tmp = $this->plInfo(); + foreach($tmp['plProvidedAcls'] as $name => $translation){ + $smarty->assign($name."ACL",$this->getacl($name)); + } + + /* Transfer ACL's */ + foreach($this->attributes as $val){ + if(isset($this->$val)){ + $smarty->assign($val,$this->$val); + }else{ + $smarty->assign($val,""); + } + } + + /* Create home server array */ + $tmp = array(); + foreach($this->goFonHomeServers as $dn => $attrs){ + if(!is_numeric($dn)){ + $tmp[$dn] = $attrs['SERVER']; + } + } + $smarty->assign("goFonHomeServers",$tmp); + + /* Fill arrays */ + $smarty->assign ("goFonHardware", $this->goFonHardware); + if (!count($this->phoneNumbers)){ + $smarty->assign ("phoneNumbers", array()); + } else { + $smarty->assign ("phoneNumbers", $this->phoneNumbers); + } + + $dis = ""; + if(!$this->acl_is_writeable("goFonHardware",$SkipWrite)){ + $dis= " disabled "; + } + $hl= "\n"; + $smarty->assign ("hardware_list", $hl); + + + foreach($this->attributes as $attr){ + if(in_array($attr,$this->multi_boxes)){ + $smarty->assign("use_".$attr,TRUE); + }else{ + $smarty->assign("use_".$attr,FALSE); + } + } + + /* Show main page */ + $this->lastmacro = $this->macro; + $smarty->assign("multiple_support",$this->multiple_support_active); + $display.= $smarty->fetch(get_template_path('generic.tpl', TRUE, dirname(__FILE__))); + return($display); + } + + + function save_object() + { + $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit'); + if (isset($_POST["phoneTab"])){ + + plugin::save_object(); + + /* Save checkbox */ + $tmp = preg_replace("/[^a-z]/i","",$this->goFonDeliveryMode); + if($this->acl_is_writeable("goFonDeliveryMode",$SkipWrite)){ + if(isset($_POST['fon_to_mail']) && !preg_match("/M/",$this->goFonDeliveryMode)){ + $tmp .= "M"; + }elseif(!isset($_POST['fon_to_mail']) && preg_match("/M/",$this->goFonDeliveryMode)){ + $tmp = preg_replace ("/M/","",$tmp); + } + } + $this->goFonDeliveryMode= "[".$tmp."]"; + + + /* Every macro in the select box are available */ + if((isset($_POST['macro']))){ + $this->macrostillavailable=true; + } + + if(isset($_POST['macro']) && $_POST['macro'] != $this->macro){ + $this->is_modified =true; + } + + if(is_array($this->phoneNumbers)){ + foreach($this->phoneNumbers as $telenumms) { + $nummsinorder[]=$telenumms; + } + }else{ + $nummsinorder=array(""); + } + + + /* get all Postvars */ + if(isset($this->macroarray[$this->macro])){ + + if($this->acl_is_writeable("goFonMarco",$SkipWrite)){ + foreach($this->macroarray[$this->macro] as $key => $paras){ + + $backup = $this->macroarray[$this->macro][$key]; + + if(isset($_POST[$paras['var']])){ + $this->macroarray[$this->macro][$key]['choosen'] = $_POST[$paras['var']]; + } + + /* Checkboxes are special, they are not Posted if they are not selected, so the won't be changed with the above code + We need this code below to read and save checkboxes correct + */ + + if(isset($_POST['post_success'])){ + if($this->macroarray[$this->macro][$key]['type']=="bool"){ + if(isset($_POST[$this->macroarray[$this->macro][$key]['var']])) { + $this->macroarray[$this->macro][$key]['choosen']=$_POST[$paras['var']]; + }else{ + $this->macroarray[$this->macro][$key]['choosen']=false; + } + } + } + } + if(count(array_diff($this->macroarray[$this->macro][$key],$backup))){ + $this->modified = TRUE; + } + } + } + } + } + + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); + + if(!count($this->goFonHomeServers)){ + $message[] = _("There must be at least one server with an asterisk database to create a phone account."); + } + + if(empty($this->goFonHomeServer)){ + $message[] = _("Please select a valid goFonHomeServer."); + } + + if((strlen($this->goFonVoicemailPIN)==0)||(strlen($this->goFonVoicemailPIN)>4)){ + $message[]=(_("Voicemail PIN must be between 1-4 characters.")); + }else{ + if(preg_match("/[^0-9]/",$this->goFonVoicemailPIN)){ + $message[]=(_("The specified Voicemail PIN contains invalid characters, only numeric values are allowed here.")); + } + } + + if(preg_match("/[^0-9a-z]/i",$this->goFonPIN)){ + $message[]=(_("The specified phone PIN contains invalid characters, only aphanumeric values are allowed here.")); + } + + if ($this->initially_was_account != $this->is_account || $this->is_modified){ + if(!$this->generate_mysql_entension_entries()){ + $message[] = $this->generate_error; + } + } + + /* We need at least one phone number */ + if (count($this->phoneNumbers) == 0){ + $message[]= sprintf(_("You need to specify at least one phone number!")); + } + + /* check for ! in any parameter setting*/ + if(isset($this->macroarray[$this->macro])){ + foreach($this->macroarray[$this->macro] as $val){ + if((strstr($val['choosen'],"!"))||(strstr($val['choosen'],"#"))){ + $message[] = sprintf(_("The parameter %s contains invalid char. '!,#' is used as delimiter"),$val['name']); + } + } + } + return ($message); + } + + + + function save() + { + plugin::save(); + + /* Force saving macro again + * This ensures that + * - the macro is available on the destiantion server. + * - the macro saved is up to date on the destination server. + */ + if(!empty($this->macro) && $this->macro != "none") { + $macro_tab= new macrotabs($this->config,$this->config->data['TABS']['MACROTABS'], $this->macro,"gofonmacro"); + $macro_tab -> save(); + } + + /* Save arrays */ + $tmp_numbers = array(); + foreach ($this->phoneNumbers as $number){ + $tmp_numbers[] = $number; + } + + /* Save settings, or remove goFonMacro attribute*/ + if($this->macro!="none"){ + $this->attrs['goFonMacro']=$this->macro; + if(isset($this->macroarray[$this->macro])){ + foreach($this->macroarray[$this->macro] as $paras) { + $this->attrs['goFonMacro'].="!".$paras['id']."#".$paras['choosen']; + } + } + }else{ + $this->attrs['goFonMacro']=array(); + } + unset($this->attrs['macro']) ; + + $this->attrs['goFonForwarding']=array(); + + if ($this->initially_was_account != $this->is_account || $this->is_modified){ + $str = $this->generate_mysql_entension_entries(true); + if(empty($str)){ + print_red($str); + } + } + + if($this->attrs['goFonMacro']==""){ + $this->attrs['goFonMacro']=array(); + } + + unset($this->attrs['cn']); + + /* Write back to ldap */ + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->dn); + $this->cleanup(); + + /* Force saving numbers, else it will be overwriten by user account. */ + $this->attrs['telephoneNumber'] =$tmp_numbers; + $ldap->modify ($this->attrs); + + /* Log last action */ + if($this->initially_was_account){ + new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + }else{ + new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + } + + show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/phone account with dn '%s' failed."),$this->dn)); + + /* Optionally execute a command after we're done */ + + if ($this->initially_was_account == $this->is_account){ + if ($this->is_modified){ + $this->handle_post_events("modify",array("uid" => $this->uid)); + } + } else { + $this->handle_post_events("add",array("uid" => $this->uid)); + } + + } + + + function adapt_from_template($dn) + { + plugin::adapt_from_template($dn); + + /* Assemble phone numbers */ + if (isset($this->attrs['telephoneNumber'])){ + for ($i= 0; $i<$this->attrs['telephoneNumber']['count']; $i++){ + $number= $this->attrs['telephoneNumber'][$i]; + $this->phoneNumbers[$number]= $number; + } + } + } + + + function remove_from_parent() + { + if(!$this->initially_was_account) return; + + foreach($this->attributes as $key=>$val){ + if(in_array($val,array("uid","cn"))){ + unset($this->attributes[$key]); + unset($this->$val); + } + } + if(count($this->goFonHomeServers) && !empty($this->init_HomeServer) && is_callable("mysql_pconnect")){ + + // Get Configuration for initial Mysql database Server + $a_SETUP = $this->goFonHomeServers[$this->init_HomeServer]; + $s_parameter =""; + + // Connect to DB server + $r_con = @mysql_pconnect($a_SETUP['SERVER'],$a_SETUP['LOGIN'],$a_SETUP['PASSWORD']); + + // Check if we are connected correctly + if(!$r_con){ + print_red(sprintf(_("The MySQL Server '%s' isn't reachable as user '%s', check GOsa log for mysql error."), + $a_SETUP['SERVER'],$a_SETUP['LOGIN'])); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); + return false; + } + + // Select database for Extensions + $db = @mysql_select_db($a_SETUP['DB'],$r_con); + + // Test if we have the database selected correctly + if(!$db){ + print_red(sprintf(_("Can't select database %s on %s."),$a_SETUP['DB'],$a_SETUP['SERVER'])); + new log("debug","gofonreport/".get_class($this),"",array(),@mysql_error()); + return false; + } + + $SQL=""; + + /* If deletion starts from userslist, cn uid are not set */ + if((isset($this->parent->by_object['user']->uid))&&(!empty($this->parent->by_object['user']->uid))){ + $this->uid = $this->parent->by_object['user']->uid; + } + + if((isset($this->parent->by_object['user']->cn))&&(!empty($this->parent->by_object['user']->cn))){ + $this->cn = $this->parent->by_object['user']->cn; + } + + $first_num = false; + // Delete old entries + foreach($this->a_old_telenums as $s_telenums){ + if(!$first_num){ + $first_num = $s_telenums; + } + $SQL[] = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$s_telenums."';\n"; + } + + $SQL[] = "DELETE FROM ".$a_SETUP['VOICE_TABLE']." WHERE customer_id='".$first_num."';"; + $SQL[] = "DELETE FROM ".$a_SETUP['EXT_TABLE']." WHERE exten='".$this->uid."';\n"; + $SQL[] = "DELETE FROM ".$a_SETUP['SIP_TABLE']." WHERE name='".$this->uid."';\n"; + + foreach($SQL as $query){ + @DEBUG (DEBUG_MYSQL, __LINE__, __FUNCTION__, __FILE__,$query, "Database query"); + if(!@mysql_query($query,$r_con)){ + print_red(_("Stop".mysql_error())); + return false; + } + } + }else{ + print_red(_("Can't remove phone account, the mysql extension is not present in php configuration.")); + return false; + } + + /* unset macro attr, it will cause an error */ + $tmp = array_flip($this->attributes); + unset($tmp['macro']); + $this->attributes=array_flip($tmp); + + /* Cancel if there's nothing to do here */ + if (!$this->initially_was_account){ + return; + } + + plugin::remove_from_parent(); + + /* Just keep one phone number */ + if (count($this->telephoneNumber) && $this->telephoneNumber != ""){ + $this->attrs['telephoneNumber']= $this->telephoneNumber; + } else { + $this->attrs['telephoneNumber']= array(); + } + + + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(&(objectClass=goFonQueue)(member=*))", array("member")); + while($attr = $ldap->fetch()){ + if(in_array($this->dn,$attr['member'])){ + $new =new ogrouptabs($this->config, $this->config->data['TABS']['OGROUPTABS'],$attr['dn']); + unset($new->by_object['ogroup']->memberList[$this->dn]); + unset($new->by_object['ogroup']->member[$this->dn]); + $new->save(); + print_red(sprintf(_("Removed user '%s' from phone queue '%s'."),$this->uid,$new->by_object['ogroup']->cn)); + } + } + $ldap->cd($this->dn); + $this->cleanup(); + $ldap->modify ($this->attrs); + + new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); + show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/phone account with dn '%s' failed."),$this->dn)); + + /* Optionally execute a command after we're done */ + @mysql_close($r_con); + $this->handle_post_events('remove',array("uid"=> $this->uid)); + } + + + + /* This function checks if the given phonenumbers are available or already in use*/ + function is_number_used() + { + $ldap= $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->search("(|(objectClass=goFonAccount)(objectClass=goFonQueue)(objectClass=goFonConference))", array("telephoneNumber","cn","uid")); + while($attrs = $ldap->fetch()) { + unset($attrs['telephoneNumber']['count']); + foreach($attrs['telephoneNumber'] as $tele){ + if(!isset($attrs['cn'][0])) $attrs['cn'][0]=$attrs['dn']; + if(!isset($attrs['uid'][0])) $attrs['uid'][0]=$attrs['dn']; + $numbers[$tele]=$attrs; + } + } + + foreach($this->phoneNumbers as $num){ + if(!isset($this->cn)) $this->cn = ""; + + if((isset($numbers[$num]))&&(($numbers[$num]['uid'][0]!=$this->uid))){ + if(isset($numbers[$num]['uid'][0])){ + return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['uid'][0]); + }else{ + return sprintf(_("The specified telephonenumber '%s' is already assigned to '%s'."),$num,$numbers[$num]['cn'][0]); + } + } + } + } + + + /* Create phoneAccount part of copy & paste dialog */ + function getCopyDialog() + { + if(!$this->is_account) return(""); + $smarty = get_smarty(); + if (!count($this->phoneNumbers)){ + $smarty->assign ("phoneNumbers", array("")); + } else { + $smarty->assign ("phoneNumbers", $this->phoneNumbers); + } + + $smarty->assign("goFonVoicemailPIN",$this->goFonVoicemailPIN); + $smarty->assign("goFonPIN",$this->goFonPIN); + + $display= $smarty->fetch(get_template_path('paste_generic.tpl', TRUE, dirname(__FILE__))); + $ret =array(); + $ret['string'] = $display; + $ret['status'] = ""; + return($ret); + } + + /* Save posts from copy & paste dialog dialog */ + function saveCopyDialog() + { + if(!$this->is_account) return; + $this->execute(); + if(isset($_POST['goFonVoicemailPIN'])) { + $this->goFonVoicemailPIN = $_POST['goFonVoicemailPIN']; + } + if(isset($_POST['goFonPIN'])){ + $this->goFonPIN = $_POST['goFonPIN']; + } + } + + + function allow_remove() + { + /* Check if previously selected server is still available */ + if($this->initially_was_account && !isset($this->goFonHomeServers[$this->goFonHomeServer])){ + return sprintf(_("The previously selected asterisk home server (%s) is no longer available. Remove aborted."),preg_replace("/,/",", ",$this->goFonHomeServer)); + } + } + + /* Return plugin informations for acl handling */ + static function plInfo() + { + return (array( + "plShortName" => _("Phone"), + "plDescription" => _("Phone account settings"), + "plSelfModify" => TRUE, + "plDepends" => array("user"), + "plPriority" => 7, // Position in tabs + "plSection" => "personal", // This belongs to personal + "plCategory" => array("gofonreport" => array("description" => _("GOfon reports"), + "objectClass" => "")), + + "plOptions" => array(), + + "plProvidedAcls" => array( + "telephoneNumber" => _("Telephone number"), + "goFonHomeServer" => _("Home server"), + "goFonMacro" => _("Macro settings"), + "goFonHardware" => _("Phone hardware"), + "goFonPIN" => _("Telephone pin"), + "goFonVoicemailPIN" => _("Voicemail pin")) + )); + } + + + + function multiple_execute() + { + plugin::multiple_execute(); + return($this->execute()); + } + + function get_multi_init_values() + { + $ret = plugin::get_multi_init_values(); + $ret['phoneNumbers'] = array(); + foreach($this->phoneNumbers as $number){ + $ret['phoneNumbers'][] = $number." [".$this->attrs['cn'][0]."]"; + } + $ret['phoneNumbers']['count'] = count($ret['phoneNumbers']); + return($ret); + } + + function init_multiple_support($attrs,$all) + { + plugin::init_multiple_support($attrs,$all); + + $this->phoneNumbers = array(); + if(isset($all['phoneNumbers'])){ + for($i = 0 ; $i < $all['phoneNumbers']['count'] ; $i++){ + $this->phoneNumbers[$all['phoneNumbers'][$i]] = $all['phoneNumbers'][$i]; + } + } + } + + function multiple_save_object() + { + /* Simply call parents save_object */ + if (isset($_POST["phoneTab"])){ + + plugin::save_object(); + plugin::multiple_save_object(); + + /* Every macro in the select box are available */ + if((isset($_POST['macro']))){ + $this->macrostillavailable=true; + } + + if(isset($_POST['macro']) && $_POST['macro'] != $this->macro){ + $this->is_modified =true; + } + + /* get all Postvars */ + if(isset($this->macroarray[$this->macro])){ + foreach($this->macroarray[$this->macro] as $key => $paras){ + $backup = $this->macroarray[$this->macro][$key]; + if(isset($_POST[$paras['var']])){ + $this->macroarray[$this->macro][$key]['choosen'] = $_POST[$paras['var']]; + } + if(isset($_POST['post_success'])){ + if($this->macroarray[$this->macro][$key]['type']=="bool"){ + if(isset($_POST[$this->macroarray[$this->macro][$key]['var']])) { + $this->macroarray[$this->macro][$key]['choosen']=$_POST[$paras['var']]; + }else{ + $this->macroarray[$this->macro][$key]['choosen']=false; + } + } + } + } + if(count(array_diff($this->macroarray[$this->macro][$key],$backup))){ + $this->modified = TRUE; + } + } + } + } + + function multiple_check() + { + $message = plugin::multiple_check(); + + if(!count($this->goFonHomeServers) && in_array("goFonHomeServers",$this->multi_boxes)){ + $message[] = _("There must be at least one server with an asterisk database to create a phone account."); + } + + if(empty($this->goFonHomeServer) && in_array("goFonHomeServers",$this->multi_boxes)){ + $message[] = _("Please select a valid goFonHomeServer."); + } + + if(in_array("goFonVoicemailPIN",$this->multi_boxes) && + ( (strlen($this->goFonVoicemailPIN)==0)|| + (strlen($this->goFonVoicemailPIN)>4))){ + $message[]=(_("Voicemail PIN must be between 1-4 characters.")); + }else{ + if(preg_match("/[^0-9]/",$this->goFonVoicemailPIN) && in_array("goFonVoicemailPIN",$this->multi_boxes) ){ + $message[]=(_("The specified Voicemail PIN contains invalid characters, only numeric values are allowed here.")); + } + } + + if(preg_match("/[^0-9a-z]/i",$this->goFonPIN) && in_array("goFonPIN",$this->multi_boxes)){ + $message[]=(_("The specified phone PIN contains invalid characters, only aphanumeric values are allowed here.")); + } + + /* check for ! in any parameter setting*/ + if(isset($this->macroarray[$this->macro]) && in_array("macro",$this->multi_boxes)){ + foreach($this->macroarray[$this->macro] as $val){ + if((strstr($val['choosen'],"!"))||(strstr($val['choosen'],"#"))){ + $message[] = sprintf(_("The parameter %s contains invalid char. '!,#' is used as delimiter"),$val['name']); + } + } + } + + return($message); + } + + function get_multi_edit_values() + { + $ret = plugin::get_multi_edit_values(); + if(in_array("macro",$this->multi_boxes)){ + $ret['macro'] = $this->macro; + $ret['macroarray'] = $this->macroarray; + $ret['macros'] = $this->macros; + } + return($ret); + } +} + +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?> diff --git a/gosa-plugins/gofon/phoneaccount/generic.tpl b/gosa-plugins/gofon/phoneaccount/generic.tpl new file mode 100644 index 000000000..9680c9308 --- /dev/null +++ b/gosa-plugins/gofon/phoneaccount/generic.tpl @@ -0,0 +1,131 @@ + + + + + + + + + + + + +
+

+ +  {t}Phone numbers{/t} +

+ +{if $multiple_support} + + + +{else} + +{render acl=$telephoneNumberACL} + +{/render} +
+{render acl=$telephoneNumberACL} + +{/render} +{render acl=$telephoneNumberACL} +   +{/render} +{render acl=$telephoneNumberACL} + +{/render} + +{/if} +
+ + + + + +
+

 {t}Telephone hardware{/t}

+ + + {if !$multiple_support} + + + + + {/if} + + + + + + + + + + + + +
+ {t}Telephone{/t} + + {$hardware_list} +
{t}Home server{/t}{$must} + +{render acl=$goFonHomeServerACL checkbox=$multiple_support checked=$use_goFonHomeServer} + +{/render} +
+ + +{render acl=$goFonVoicemailPINACL checkbox=$multiple_support checked=$use_goFonVoicemailPIN} + +{/render} +
+ + +{render acl=$goFonPINACL checkbox=$multiple_support checked=$use_goFonPIN} + +{/render} +
+
+
 
+

+ +  {t}Phone macro{/t} +

+ + + + +
+{render acl=$goFonMacroACL checkbox=$multiple_support checked=$use_macro} + +{/render} + {if $javascript eq 'false'} +{render acl=$goFonMacroACL} + +{/render} + {/if} +
+
+ {$macrotab} +
+ + + + diff --git a/gosa-plugins/gofon/phoneaccount/main.inc b/gosa-plugins/gofon/phoneaccount/main.inc new file mode 100644 index 000000000..b8cc5ac60 --- /dev/null +++ b/gosa-plugins/gofon/phoneaccount/main.inc @@ -0,0 +1,126 @@ +dn); + session::un_set ('edit'); + session::un_set ('phoneAccount'); + } + + /* Create phoneAccount object on demand */ + if (!session::is_set('phoneAccount') || (isset($_GET['reset']) && $_GET['reset'] == 1)){ + $phoneAccount= new phoneAccount ($config, $ui->dn); + $phoneAccount->set_acl_base($ui->dn); + $phoneAccount->set_acl_category("users"); + session::set('phoneAccount',$phoneAccount); + } + $phoneAccount = session::get('phoneAccount'); + + /* save changes back to object */ + if (session::is_set('edit')){ + $phoneAccount->save_object (); + } + + /* Enter edit mode? */ + if (isset($_POST['edit'])){ + + /* Check locking */ + if (($username= get_lock($ui->dn)) != ""){ + session::set('back_plugin',$plug); + session::set('LOCK_VARS_TO_USE',array("/^edit$/","/^plug$/")); + $lock_msg = gen_locked_message ($username, $ui->dn); + + }else{ + + /* Lock the current entry */ + add_lock ($ui->dn, $ui->dn); + session::set('dn',$ui->dn); + session::set('edit',TRUE); + } + + } + + /* save changes to LDAP and disable edit mode */ + if (isset($_POST['edit_finish'])){ + + /* Perform checks */ + $message= $phoneAccount->check (); + + /* No errors, save object */ + if (count ($message) == 0){ + $phoneAccount->save (); + + del_lock ($ui->dn); + session::un_set ('edit'); + + /* Write back to session */ + session::set('phoneAccount',$phoneAccount); + } else { + /* Errors found, show message */ + show_errors ($message); + } + } + + /* Execute formular */ + if($lock_msg){ + $display.= $lock_msg; + }else{ + $display.= $phoneAccount->execute (); + } + + /* Store changes in session */ + if (session::is_set('edit')){ + session::set('phoneAccount',$phoneAccount); + } + + $info= ""; + if ($phoneAccount->is_account && empty($lock_msg)){ + $display.= "

"; + + /* Are we in edit mode? */ + if (session::is_set('edit')){ + $display.= "\n"; + $display.= " "; + $display.= "\n"; + $info= "\"\" ".$ui->dn." "; + } else { + $info= "\"\" ".$ui->dn." "; + + if(preg_match("/w/",$ui->get_permissions($ui->dn,"users/phoneAccount"))){ + $info.= "\"\""._("Click the 'Edit' button below to change informations in this dialog"); + $display.= "\n"; + } + $display.= "\n"; + } + $display.= "

\n"; + $display.= "\n"; + } + + /* Page header*/ + $display= print_header(get_template_path('images/phone.png'), _("Phone settings"), $info).$display; + +} +?> diff --git a/gosa-plugins/gofon/phoneaccount/paste_generic.tpl b/gosa-plugins/gofon/phoneaccount/paste_generic.tpl new file mode 100644 index 000000000..d643e9f69 --- /dev/null +++ b/gosa-plugins/gofon/phoneaccount/paste_generic.tpl @@ -0,0 +1,55 @@ +

{t}Phone settings{/t}

+ + + + + + + + +
+

+  {t}Phone numbers{/t} +

+
+ +
+ + + +
+ + + + +
+

+ +  {t}Telephone hardware{/t} +

+ + + + + + + + + +
+ + + +
+ + + +
+
+
+ +
+
-- 2.30.2