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; }
function listadoForm($pDB, $smarty, $module_name, $local_templates_dir) { global $arrLang; $oDataForm = new paloSantoDataForm($pDB); // preguntando por el estado del filtro if (!isset($_POST['cbo_estado']) || $_POST['cbo_estado'] == "") { $_POST['cbo_estado'] = "A"; } $arrDataForm = $oDataForm->getFormularios(NULL, $_POST['cbo_estado']); $end = count($arrDataForm); $arrData = array(); if (is_array($arrDataForm)) { foreach ($arrDataForm as $DataForm) { $arrTmp = array(); $arrTmp[0] = $DataForm['nombre']; if (!isset($DataForm['descripcion']) || $DataForm['descripcion'] == "") { $DataForm['descripcion'] = " "; } $arrTmp[1] = $DataForm['descripcion']; if ($DataForm['estatus'] == 'I') { $arrTmp[2] = _tr('Inactive'); $arrTmp[3] = " <a href='?menu={$module_name}&action=preview&id=" . $DataForm['id'] . "'>" . _tr('Preview') . "</a>"; } else { $arrTmp[2] = _tr('Active'); $arrTmp[3] = " <a href='?menu={$module_name}&action=preview&id=" . $DataForm['id'] . "'>" . _tr('Preview') . "</a>"; } $arrData[] = $arrTmp; } } $url = construirUrl(array('menu' => $module_name), array('nav', 'start')); $arrGrid = array("title" => _tr("Form List"), "url" => $url, "icon" => "images/list.png", "width" => "99%", "start" => $end == 0 ? 0 : 1, "end" => $end, "total" => $end, "columns" => array(0 => array("name" => _tr("Form Name"), "property1" => ""), 1 => array("name" => _tr("Form Description"), "property1" => ""), 2 => array("name" => _tr("Status"), "property1" => ""), 3 => array("name" => _tr("Options"), "property1" => ""))); $estados = array("all" => _tr("All"), "A" => _tr("Active"), "I" => _tr("Inactive")); $combo_estados = "<select name='cbo_estado' id='cbo_estado' onChange='submit();'>" . combo($estados, $_POST['cbo_estado']) . "</select>"; $oGrid = new paloSantoGrid($smarty); $oGrid->showFilter("<table width='100%' border='0'><tr>" . "<td>" . _tr("Forms") . "</td>" . "<td class='letra12' align='right'><b>" . _tr("Status") . ":</b> {$combo_estados}</td>" . "</tr></table>"); $sContenido = $oGrid->fetchGrid($arrGrid, $arrData, $arrLang); if (strpos($sContenido, '<form') === FALSE) { $sContenido = "<form method=\"POST\" style=\"margin-bottom:0;\" action=\"{$url}\">{$sContenido}</form>"; } return $sContenido; }
function desactivar_formulario($id_formulario) { global $arrConf; $respuesta = new xajaxResponse(); $oDataForm = new paloSantoDataForm($arrConf["cadena_dsn"]); if ($oDataForm->eliminado_logico_formulario($id_formulario)) { header('?menu=hispana_form_designer'); } else { $respuesta->addAssign("mb_title", "innerHTML", _tr("Desactivate Error")); $respuesta->addAssign("mb_message", "innerHTML", _tr("Error when eliminating the form")); } return $respuesta; }
function preview_form($pDB, $smarty, $module_name, $local_templates_dir, $formCampos, $oForm, $arrConf, $arrValoresGestionAnterior) { require_once "/var/lib/asterisk/agi-bin/phpagi-asmanager.php"; $oForm->setViewMode(); // Esto es para activar el modo "preview" $pInterfazdeAgente = new paloSantoInterfazdeAgente($pDB); $iNumForm = $pInterfazdeAgente->getForm($_SESSION['id_campania']); $pDBsqlite = new paloDB("sqlite3:////var/www/db/acl.db"); $pInterfazdeAgenteSqlite = new paloSantoInterfazdeAgente($pDBsqlite); $extensionAgente = $pInterfazdeAgenteSqlite->getExtensionAgente($_SESSION['elastix_user']); if (isset($_GET['telefono'])) { // si el telefono viene en la barra de direccion $destinatario = $_GET['telefono']; } if (!isset($iNumForm) || !is_numeric($iNumForm)) { return false; } $oDataForm = new paloSantoDataForm($pDB); $arrDataForm = $oDataForm->getFormularios($iNumForm); if (is_array($arrValoresGestionAnterior)) { $arrFieldForm = $oDataForm->obtener_campos_formulario($iNumForm, NULL, $_SESSION['telefono'], $_SESSION, $arrValoresGestionAnterior); // envío arreglo $_GET } else { $arrFieldForm = $oDataForm->obtener_campos_formulario($iNumForm, NULL, $_SESSION['telefono'], $_SESSION); } $smarty->assign("id_formulario_actual", $iNumForm); $smarty->assign("style_field", "style='display:none;'"); $smarty->assign("formulario", $arrFieldForm); if (isset($destinatario) && $destinatario != "") { // si hay telefono seteado llamar al numero $astman = new AGI_AsteriskManager(); if (!$astman->connect($arrConf['asterisk_host'], $arrConf['asterisk_user'], $arrConf['asterisk_pass'])) { $smarty->assign("mb_title", _tr("Error")); $smarty->assign("mb_message", _tr("No es posible conectarse a la PBX.")); } else { $result = $astman->Originate("Local/{$extensionAgente}@from-internal", $extensionAgente, "hispana-callcenter", 1, null, null, null, null, "DEST={$destinatario}", null); } } $contenidoModulo = $oForm->fetchForm("{$local_templates_dir}/preview.tpl", _tr('Gestión de clientes')); // hay que pasar el arreglo return $contenidoModulo; }
function editar_campo_status($pDB, $smarty, $module_name, $local_templates_dir, $formCampos, $oForm) { $oDataForm = new paloSantoDataForm($pDB); if ($oDataForm->cambiar_status_field($_GET['id_field'], $_GET['status'])) { header("Location: ?menu={$module_name}&action=view&id=" . $_GET['id']); } else { $smarty->assign("mb_title", _tr('Changing Status Error')); $smarty->assign("mb_message", _tr('Error when Changing the form field status')); } }
function delete_form($pDB, $smarty, $module_name, $local_templates_dir, $formCampos, $oForm) { if (!isset($_POST['id_formulario']) || !is_numeric($_POST['id_formulario'])) { return false; } $oDataForm = new paloSantoDataForm($pDB); if ($oDataForm->delete_form($_POST['id_formulario'])) { if ($oDataForm->errMsg != "") { $smarty->assign("mb_title", _tr('Validation Error')); $smarty->assign("mb_message", $oDataForm->errMsg); } else { header("Location: ?menu=form_designer"); } } else { $msg_error = $oDataForm->errMsg != "" ? "<br>" . $oDataForm->errMsg : ""; $smarty->assign("mb_title", _tr('Delete Error')); $smarty->assign("mb_message", _tr('Error when deleting the Form') . $msg_error); } $sContenido = view_form($pDB, $smarty, $module_name, $local_templates_dir, $formCampos, $oForm); return $sContenido; }