function getTrunksBillFiltrado(&$oDB, &$oTrunk, $arrConfig, &$arrTrunks, &$arrTrunksBill) { $arrTrunks = getTrunks($oDB); $arrTrunksBill = $oTrunk->getTrunksBill(); $oTrunk->getExtendedTrunksBill($grupos, $arrConfig['ASTETCDIR']['valor'] . '/chan_dahdi.conf'); // Sólo los puertos no-DAHDI y los grupos de puertos DAHDI son elegibles para tener un precio $t = array(); if (is_array($arrTrunks)) { foreach ($arrTrunks as $tupla) { if (substr($tupla[1], 0, 3) != 'DAHDI' || $tupla[1][4] == 'g') { $t[] = $tupla; } } $arrTrunks = $t; } }
function formEditCampaign($pDB, $smarty, $module_name, $local_templates_dir, $id_campaign = NULL) { include_once "libs/paloSantoQueue.class.php"; include_once "modules/form_designer/libs/paloSantoDataForm.class.php"; // Si se ha indicado cancelar, volver a listado sin hacer nada más if (isset($_POST['cancel'])) { Header("Location: ?menu={$module_name}"); return ''; } $smarty->assign('FRAMEWORK_TIENE_TITULO_MODULO', existeSoporteTituloFramework()); // Leer los datos de la campaña, si es necesario $arrCampaign = NULL; $oCamp = new paloSantoCampaignCC($pDB); if (!is_null($id_campaign)) { $arrCampaign = $oCamp->getCampaigns(null, null, $id_campaign); if (!is_array($arrCampaign) || count($arrCampaign) == 0) { $smarty->assign("mb_title", 'Unable to read campaign'); $smarty->assign("mb_message", 'Cannot read campaign - ' . $oCamp->errMsg); return ''; } } // Obtener y conectarse a base de datos de FreePBX $pConfig = new paloConfig("/etc", "amportal.conf", "=", "[[:space:]]*=[[:space:]]*"); $arrConfig = $pConfig->leer_configuracion(false); $dsn = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asterisk"; $oDB = new paloDB($dsn); // Leer las troncales que se han definido en FreePBX $arrDataTrunks = array('' => '(' . _tr('By Dialplan') . ')'); $arrTrunks = getTrunks($oDB); //obtener la lista de trunks if (is_array($arrTrunks)) { foreach ($arrTrunks as $trunk) { $arrDataTrunks[$trunk[1]] = $trunk[1]; } } // Leer las colas que se han definido en FreePBX, y quitar las usadas // en campañas entrantes. $arrDataQueues = array(); $oQueue = new paloQueue($oDB); $arrQueues = $oQueue->getQueue(); // Todas las colas, entrantes y salientes if (is_array($arrQueues)) { $query_call_entry = "SELECT queue FROM queue_call_entry WHERE estatus = 'A'"; $arr_call_entry = $pDB->fetchTable($query_call_entry); // Las colas entrantes $colasEntrantes = array(); foreach ($arr_call_entry as $row) { $colasEntrantes[] = $row[0]; } foreach ($arrQueues as $rowQueue) { if (!in_array($rowQueue[0], $colasEntrantes)) { $arrDataQueues[$rowQueue[0]] = $rowQueue[1]; } } } $arrUrlsExternos = array('' => _tr('(No external URL)')) + $oCamp->getExternalUrls(); // Cargar la información de todos los formularios creados y activos $oDataForm = new paloSantoDataForm($pDB); $arrDataForm = $oDataForm->getFormularios(NULL, 'A'); // Impedir mostrar el formulario si no se han definido colas o no // quedan colas libres para usar en campañas salientes. if (count($arrQueues) <= 0) { $formCampos = getFormCampaign($arrDataTrunks, $arrDataQueues, NULL, NULL, NULL); $oForm = new paloForm($smarty, $formCampos); $smarty->assign('no_queues', 1); } elseif (count($arrDataQueues) <= 0) { $formCampos = getFormCampaign($arrDataTrunks, $arrDataQueues, NULL, NULL, NULL); $oForm = new paloForm($smarty, $formCampos); $smarty->assign('no_outgoing_queues', 1); } elseif (count($arrDataForm) <= 0) { $formCampos = getFormCampaign($arrDataTrunks, $arrDataQueues, NULL, NULL, NULL); $oForm = new paloForm($smarty, $formCampos); $smarty->assign('no_forms', 1); } else { $smarty->assign('label_manage_trunks', _tr('Manage Trunks')); $smarty->assign('label_manage_queues', _tr('Manage Queues')); $smarty->assign('label_manage_forms', _tr('Manage Forms')); $smarty->assign('label_manage_external_url', _tr('Manage External URLs')); // Definición del formulario de nueva campaña $smarty->assign("REQUIRED_FIELD", _tr("Required field")); $smarty->assign("CANCEL", _tr("Cancel")); $smarty->assign("SAVE", _tr("Save")); $smarty->assign("APPLY_CHANGES", _tr("Apply changes")); $smarty->assign('LABEL_CALL_FILE', _tr('Call File')); // Valores por omisión para primera carga $arrNoElegidos = array(); // Lista de selección de formularios elegibles $arrElegidos = array(); // Lista de selección de formularios ya elegidos $values_form = NULL; // Selección hecha en el formulario if (is_null($id_campaign)) { if (!isset($_POST['nombre'])) { $_POST['nombre'] = ''; } if (!isset($_POST["context"]) || $_POST["context"] == "") { $_POST["context"] = "from-internal"; } if (!isset($_POST['max_canales']) || $_POST['max_canales'] == '') { $_POST['max_canales'] = 23; } if (!isset($_POST['reintentos']) || $_POST['reintentos'] == '') { $_POST['reintentos'] = 5; } if (!isset($_POST['rte_script'])) { $_POST['rte_script'] = ''; } if (!isset($_POST['values_form'])) { $_POST['values_form'] = ''; } //$_POST['formulario']= explode(",", $_POST['values_form']); $values_form = explode(",", $_POST['values_form']); } else { if (!isset($_POST['nombre'])) { $_POST['nombre'] = $arrCampaign[0]['name']; } if (!isset($_POST['fecha_ini'])) { $_POST['fecha_ini'] = date('d M Y', strtotime($arrCampaign[0]['datetime_init'])); } if (!isset($_POST['fecha_fin'])) { $_POST['fecha_fin'] = date('d M Y', strtotime($arrCampaign[0]['datetime_end'])); } $arrDateTimeInit = explode(":", $arrCampaign[0]['daytime_init']); $arrDateTimeEnd = explode(":", $arrCampaign[0]['daytime_end']); if (!isset($_POST['hora_ini_HH'])) { $_POST['hora_ini_HH'] = isset($arrDateTimeInit[0]) ? $arrDateTimeInit[0] : "00"; } if (!isset($_POST['hora_ini_MM'])) { $_POST['hora_ini_MM'] = isset($arrDateTimeInit[1]) ? $arrDateTimeInit[1] : "00"; } if (!isset($_POST['hora_fin_HH'])) { $_POST['hora_fin_HH'] = isset($arrDateTimeEnd[0]) ? $arrDateTimeEnd[0] : "00"; } if (!isset($_POST['hora_fin_MM'])) { $_POST['hora_fin_MM'] = isset($arrDateTimeEnd[1]) ? $arrDateTimeEnd[1] : "00"; } if (!isset($_POST['reintentos'])) { $_POST['reintentos'] = $arrCampaign[0]['retries']; } if (!isset($_POST['trunk'])) { $_POST['trunk'] = $arrCampaign[0]['trunk']; } if (!isset($_POST['queue'])) { $_POST['queue'] = $arrCampaign[0]['queue']; } if (!isset($_POST['context'])) { $_POST['context'] = $arrCampaign[0]['context']; } if (!isset($_POST['max_canales'])) { $_POST['max_canales'] = $arrCampaign[0]['max_canales']; } //$_POST['script'] = ""; if (!isset($_POST['rte_script'])) { $_POST['rte_script'] = $arrCampaign[0]['script']; } //if (!isset($_POST['formulario'])) $_POST['formulario'] = ""; //if (!isset($_POST['formularios_elegidos'])) $_POST['formularios_elegidos'] = ""; if (!isset($_POST['values_form'])) { $values_form = $oCamp->obtenerCampaignForm($id_campaign); } else { $values_form = explode(",", $_POST['values_form']); } if (!isset($_POST['external_url'])) { $_POST['external_url'] = $arrCampaign[0]['id_url']; } } // rte_script es un HTML complejo que debe de construirse con Javascript. $smarty->assign("rte_script", adaptar_formato_rte($_POST['rte_script'])); // Clasificar los formularios elegidos y no elegidos foreach ($arrDataForm as $key => $form) { if (in_array($form['id'], $values_form)) { $arrElegidos[$form['id']] = $form['nombre']; } else { $arrNoElegidos[$form['id']] = $form['nombre']; } } // Generación del objeto de formulario $formCampos = getFormCampaign($arrDataTrunks, $arrDataQueues, $arrNoElegidos, $arrElegidos, $arrUrlsExternos); $oForm = new paloForm($smarty, $formCampos); if (!is_null($id_campaign)) { $oForm->setEditMode(); $smarty->assign('id_campaign', $id_campaign); } // En esta implementación el formulario trabaja exclusivamente en modo 'input' // y por lo tanto proporciona el botón 'save' $bDoCreate = isset($_POST['save']); $bDoUpdate = isset($_POST['apply_changes']); if ($bDoCreate || $bDoUpdate) { if (!$oForm->validateForm($_POST) || (!isset($_POST['rte_script']) || $_POST['rte_script'] == '')) { // Falla la validación básica del formulario $smarty->assign("mb_title", _tr("Validation Error")); $arrErrores = $oForm->arrErroresValidacion; $strErrorMsg = "<b>" . _tr('The following fields contain errors') . ":</b><br/>"; if (is_array($arrErrores) && count($arrErrores) > 0) { foreach ($arrErrores as $k => $v) { $strErrorMsg .= "{$k}, "; } } if (!isset($_POST['rte_script']) || $_POST['rte_script'] == '') { $strErrorMsg .= _tr("Script"); } $strErrorMsg .= ""; $smarty->assign("mb_message", $strErrorMsg); } elseif ($_POST['max_canales'] <= 0) { $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", _tr('At least 1 used channel must be allowed.')); } elseif ((int) $_POST['reintentos'] <= 0) { $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", _tr('Campaign must allow at least one call retry')); } elseif ($bDoCreate && !in_array($_POST['encoding'], mb_list_encodings())) { $smarty->assign("mb_title", _tr('Validation Error')); $smarty->assign("mb_message", _tr('Invalid character encoding')); } elseif ($bDoCreate && empty($_FILES['phonefile']['tmp_name'])) { $smarty->assign("mb_title", _tr('Validation Error')); $smarty->assign("mb_message", _tr('Call file not specified or failed to be uploaded')); } else { $time_ini = $_POST['hora_ini_HH'] . ":" . $_POST['hora_ini_MM']; $time_fin = $_POST['hora_fin_HH'] . ":" . $_POST['hora_fin_MM']; $iFechaIni = strtotime($_POST['fecha_ini']); $iFechaFin = strtotime($_POST['fecha_fin']); $iHoraIni = strtotime($time_ini); $iHoraFin = strtotime($time_fin); if ($iFechaIni == -1 || $iFechaIni === FALSE) { $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", _tr('Unable to parse start date specification')); } elseif ($iFechaFin == -1 || $iFechaFin === FALSE) { $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", _tr('Unable to parse end date specification')); } elseif ($iHoraIni == -1 || $iHoraIni === FALSE) { $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", _tr('Unable to parse start time specification')); } elseif ($iHoraFin == -1 || $iHoraFin === FALSE) { $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", _tr('Unable to parse end time specification')); } else { if (!$pDB->genQuery("SET AUTOCOMMIT=0")) { $smarty->assign("mb_message", $pDB->errMsg); } else { $bExito = TRUE; if ($bDoCreate) { $id_campaign = $oCamp->createEmptyCampaign($_POST['nombre'], $_POST['max_canales'], $_POST['reintentos'], $_POST['trunk'], $_POST['context'], $_POST['queue'], date('Y-m-d', $iFechaIni), date('Y-m-d', $iFechaFin), $time_ini, $time_fin, $_POST['rte_script'], $_POST['external_url'] == '' ? NULL : (int) $_POST['external_url']); if (is_null($id_campaign)) { $bExito = FALSE; } } elseif ($bDoUpdate) { $bExito = $oCamp->updateCampaign($id_campaign, $_POST['nombre'], $_POST['max_canales'], $_POST['reintentos'], $_POST['trunk'], $_POST['context'], $_POST['queue'], date('Y-m-d', $iFechaIni), date('Y-m-d', $iFechaFin), $time_ini, $time_fin, $_POST['rte_script'], $_POST['external_url'] == '' ? NULL : (int) $_POST['external_url']); } // Introducir o actualizar formularios if ($bExito && isset($_POST['values_form'])) { if ($bDoCreate) { $bExito = $oCamp->addCampaignForm($id_campaign, $_POST['values_form']); } elseif ($bDoUpdate) { $bExito = $oCamp->updateCampaignForm($id_campaign, $_POST['values_form']); } } // Para creación, se introduce lista de valores CSV if ($bExito && !empty($_FILES['phonefile']['tmp_name'])) { // Se puede tardar mucho tiempo en la inserción ini_set('max_execution_time', 3600); $sEncoding = $_POST['encoding']; $bExito = $oCamp->addCampaignNumbersFromFile($id_campaign, $_FILES['phonefile']['tmp_name'], $sEncoding); if ($bExito && $bDoUpdate && $arrCampaign[0]['estatus'] == 'T') { // Agregar números a una campaña terminada debe volverla a activar $oCamp->activar_campaign($id_campaign, 'A'); } } // Confirmar o deshacer la transacción según sea apropiado if ($bExito) { $pDB->genQuery("COMMIT"); header("Location: ?menu={$module_name}"); } else { $pDB->genQuery("ROLLBACK"); $smarty->assign("mb_title", _tr("Validation Error")); $smarty->assign("mb_message", $oCamp->errMsg); } } $pDB->genQuery("SET AUTOCOMMIT=1"); } } } } $smarty->assign('icon', 'images/kfaxview.png'); $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/new.tpl", is_null($id_campaign) ? _tr("New Campaign") : _tr("Edit Campaign") . ' "' . $_POST['nombre'] . '"', $_POST); return $contenidoModulo; }
private function _loadStaticDataFromDatabase_bak() { // Recoger todas las extensiones, con todas las tecnologías $recordset = $this->_db->fetchTable('SELECT dial AS channel, tech, id AS extension, description FROM devices ORDER BY dial', TRUE); if (is_array($recordset)) { foreach ($recordset as $tupla) { $phonestate = array('channel' => $tupla['channel'], 'tech' => $tupla['tech'], 'extension' => $tupla['extension'], 'description' => $tupla['description'], 'current_area' => 'Extension', 'mailbox' => $tupla['extension'] . '@default', 'UrgMessages' => 0, 'NewMessages' => 0, 'OldMessages' => 0, 'ip' => NULL, 'registered' => FALSE, 'active' => array()); // Leer estado actual del voicemail $r = $this->_ami->MailboxCount($phonestate['mailbox'], $this->_actionid); if ($r['Response'] == 'Success') { foreach (array('UrgMessages', 'NewMessages', 'OldMessages') as $k) { if (isset($r[$k])) { $phonestate[$k] = (int) $r[$k]; } } } $this->_internalState['phones'][$tupla['channel']] = $phonestate; } } // Leer y clasificar todas las colas conocidas $recordset = $this->_db->fetchTable('SELECT extension, descr AS description FROM queues_config ORDER BY extension', TRUE); if (is_array($recordset)) { foreach ($recordset as $tupla) { $this->_internalState['queues'][$tupla['extension']] = array('extension' => $tupla['extension'], 'description' => $tupla['description'], 'members' => array(), 'callers' => array()); } } // Leer y clasificar todas las conferencias Meetme conocidas $recordset = $this->_db->fetchTable('SELECT exten AS extension, description FROM meetme ORDER BY exten', TRUE); if (is_array($recordset)) { foreach ($recordset as $tupla) { $this->_internalState['conferences'][$tupla['extension']] = array('extension' => $tupla['extension'], 'description' => $tupla['description'], 'callers' => array()); } } // Generar todas las extensiones disponibles para parqueo de llamadas $parkpos = NULL; $numslots = 0; $tupla = $this->_db->getFirstRowQuery('SHOW TABLES LIKE "parkplus"'); if (count($tupla)) { // FreePBX 2.11 o superior $tupla = $this->_db->getFirstRowQuery('SELECT parkpos, numslots FROM parkplus ORDER BY id LIMIT 0,1', TRUE); if (is_array($tupla)) { $parkpos = $tupla['parkpos']; $numslots = (int) $tupla['numslots']; } } else { // FreePBX 2.8 $recordset = $this->_db->fetchTable('SELECT keyword, data FROM parkinglot', TRUE); if (is_array($recordset)) { foreach ($recordset as $tupla) { if ($tupla['keyword'] == 'parkext') { $parkpos = $tupla['data'] + 1; } if ($tupla['keyword'] == 'numslots') { $numslots = (int) $tupla['data']; } } } } if (!is_null($parkpos)) { for ($i = 0; $i < $numslots; $i++) { $k = $parkpos + $i; $this->_internalState['parkinglots'][$k] = array('extension' => $k, 'Channel' => NULL, 'Since' => NULL, 'Timeout' => NULL); } } // Leer y clasificar todas las troncales distintas de DAHDI // FIXME: trunks.disabled está en 'off' para troncales desactivadas $trunks = getTrunks($this->_db); if (is_array($trunks)) { foreach ($trunks as $t) { $trunk = $t[1]; if (strpos($trunk, 'DAHDI/') !== 0) { $regs = NULL; $tech = ''; if (preg_match('|^(\\w+)/|', $trunk, $regs)) { $tech = $regs[1]; } $this->_internalState['iptrunks'][$trunk] = array('channel' => $trunk, 'tech' => $tech, 'ip' => NULL, 'registered' => FALSE, 'active' => array()); } } } /* Mostrar todos los canales DAHDI disponibles. Para cada canal, se * clasificará dentro de su span correspondiente. */ $r = $this->_ami->Command('dahdi show channels'); if (isset($r['data'])) { foreach (explode("\n", $r['data']) as $s) { $regs = NULL; if (preg_match('/^\\s*(\\d+)/', $s, $regs)) { $chan = (int) $regs[1]; $r = $this->_ami->Command('dahdi show channel ' . $chan); if (isset($r['data'])) { foreach (explode("\n", $r['data']) as $l) { if (preg_match('/^Span: (\\d+)/', $l, $regs)) { $span = (int) $regs[1]; $this->_internalState['dahdi']['chan2span'][$chan] = $span; if (!isset($this->_internalState['dahdi']['spans'][$span])) { $this->_internalState['dahdi']['spans'][$span] = array('active' => array(), 'chan' => array()); } $this->_internalState['dahdi']['spans'][$span]['chan'][$chan] = array('active' => array(), 'Alarm' => 'No Alarm'); } } } } } } }
function _getAll_Trunk() { $dsn = generarDSNSistema('asteriskuser', 'asterisk'); $pDBTrunk = new paloDB($dsn); $arrTrunks = getTrunks($pDBTrunk); $trunks = array(); if (empty($arrTrunks)) { return $trunks; } if (is_array($arrTrunks) & count($arrTrunks) > 0) { foreach ($arrTrunks as $key => $trunk) { $tmp = explode("/", $trunk[1]); $trunks[] = $tmp[1]; } } return $trunks; }
function getSIPTrunksARRAY() { $result = getTrunks($this->_DB1); if ($result == FALSE) { $this->errMsg = $this->_DB1->errMsg; return array(); } $arrTrunk = array(); $arrTmp = array(); foreach ($result as $key => $value) { $arrTmp[$value[0]] = $value[1]; } foreach ($arrTmp as $key => $value) { $trunk = explode("/", $value); if ($trunk[0] != "DAHDI") { $arrTrunk[] = $value; } } foreach ($arrTrunk as $key => $value) { $tmp = explode("/", $value); $arrTrunk[$key] = array(); $arrTrunk[$key]['name'] = $value; $arrTrunk[$key]['status'] = "off"; if ($tmp[0] == "SIP") { $arrTrunk[$key]['status'] = $this->getTrunkStatus($value, "SIP"); } elseif ($tmp[0] == "IAX2") { $arrTrunk[$key]['status'] = $this->getTrunkStatus($value, "IAX2"); } } return $arrTrunk; }
function loadTrunks($pDB_ext) { include_once "libs/paloSantoTrunk.class.php"; $arrTrunksTemp = getTrunks($pDB_ext); $arrTrunk = array(); foreach ($arrTrunksTemp as $key => $arr) { $arrTrunk[$arr[1]] = $arr[1]; } return $arrTrunk; }
function getTrunksAll($arrConfig) { include_once "libs/paloSantoTrunk.class.php"; $pDB = new paloDB("sqlite3:////var/www/db/trunk.db"); $oTrunk = new paloTrunk($pDB); $arrTrunks = array(); $result = ""; $dsn = $arrConfig['AMPDBENGINE']['valor'] . "://" . $arrConfig['AMPDBUSER']['valor'] . ":" . $arrConfig['AMPDBPASS']['valor'] . "@" . $arrConfig['AMPDBHOST']['valor'] . "/asterisk"; $pDB = new paloDB($dsn); $arrTrunks = getTrunks($pDB); if (is_array($arrTrunks)) { foreach ($arrTrunks as $tupla) { if (substr($tupla[1], 0, 3) != 'DAHDI' || $tupla[1][4] == 'g') { $t[] = $tupla; } } $arrTrunks = $t; } return $arrTrunks; }
function obtener_nuevas_trunks($pDB, $pDB_asterisk) { $listaTrunks = array('' => _tr('(All)')); $trunks = getTrunks($pDB_asterisk); foreach ($trunks as $tuplaTrunk) { $listaTrunks[$tuplaTrunk[1]] = $tuplaTrunk[1]; } return $listaTrunks; }