Example #1
0
function sendNewSendFax($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf)
{
    global $arrCredentials;
    $pSendFax = new paloSantoSendFax($pDB);
    $pFaxList = new paloFax($pDB);
    $ruta_archivo = "";
    //obtenemos el fax del usuario
    //para eso necesitamos el numero de extension del usuario
    $faxexten = $pSendFax->getFaxExtensionUser($arrCredentials['idUser']);
    if ($faxexten === false || $faxexten == '') {
        $smarty->assign("mb_title", _tr('ERROR'));
        $smarty->assign("mb_message", "An error has ocurred to retrieved fax info. " . $faxexten->errMsg);
        return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    $faxes = $pFaxList->getFaxList(array('organization_domain' => $arrCredentials['domain'], 'exten' => $faxexten));
    if ($faxes == false) {
        $smarty->assign("mb_title", _tr('ERROR'));
        $smarty->assign("mb_message", _tr("An error has ocurred to retrieved fax info"));
        return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
    $faxDev = "ttyIAX" . $faxes[0]['dev_id'];
    $smarty->assign("FAX_DEV", $faxDev);
    $arrFormSendFax = createFieldForm();
    $oForm = new paloForm($smarty, $arrFormSendFax);
    if (!$oForm->validateForm($_POST)) {
        // Validation basic, not empty and VALIDATION_TYPE
        $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} [{$v['mensaje']}], ";
            }
        }
        $smarty->assign("mb_message", $strErrorMsg);
        return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    } else {
        $destine = getParameter("to");
        //$faxDev     = getParameter("from");
        $data_content = getParameter("body");
        /*if($faxDev == "none"){
              $smarty->assign("mb_title", _tr("Validation Error"));
              $smarty->assign("mb_message", _tr("Please, select a valid Fax Device"));
              return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
          }*/
        if (getParameter("option_fax") == "by_file") {
            if (is_uploaded_file($_FILES['file_record']['tmp_name'])) {
                $ruta_archivo = $_FILES['file_record']['tmp_name'];
            } else {
                $smarty->assign("mb_title", _tr("Validation Error"));
                $smarty->assign("mb_message", _tr("File to upload is empty"));
                return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
            }
        } else {
            if (!empty($data_content)) {
                /* Las siguientes operaciones son necesarias para lidiar con el
                 * bug Elastix #446. El programa sendfax es incapaz de detectar
                 * un archivo como un archivo de texto si contiene caracteres 
                 * fuera del rango ASCII. */
                $ruta_archivo = $pSendFax->generarArchivoTextoPS($data_content);
                if (is_null($ruta_archivo)) {
                    $smarty->assign(array('mb_title' => _tr('Validation Error'), 'mb_message' => _tr('Failed to convert text')));
                    return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
                }
            } else {
                $smarty->assign("mb_title", _tr("Validation Error"));
                $smarty->assign("mb_message", _tr("Text to send is empty"));
                return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
            }
        }
        $jobid = $pSendFax->sendFax($faxDev, $destine, $ruta_archivo);
        if (is_null($jobid)) {
            $smarty->assign("mb_title", _tr('Validation Error'));
            $smarty->assign("mb_message", _tr('Failed to submit job') . ': ' . $pSendFax->errMsg);
        } else {
            $smarty->assign("SEND_FAX_SUCCESS", _tr('Fax has been sent correctly'));
            $smarty->assign("SENDING_FAX", _tr('Sending Fax...'));
            $smarty->assign('JOBID', $jobid);
        }
        if (file_exists($ruta_archivo)) {
            unlink($ruta_archivo);
        }
        return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf);
    }
}
Example #2
0
function sendNewSendFax($smarty, $module_name, $local_templates_dir, &$pDB, $arrConf, $arrLang)
{
    $pSendFax = new paloSantoSendFax($pDB);
    $pFaxList = new paloFax($pDB);
    $ruta_archivo = "";
    $faxes = $pFaxList->getFaxList();
    $arrFaxList = array("none" => '-- ' . $arrLang["Select a Fax Device"] . ' --');
    foreach ($faxes as $values) {
        $arrFaxList["ttyIAX" . $values['dev_id']] = $values['clid_name'] . " / " . $values['extension'];
    }
    $arrFormSendFax = createFieldForm($arrLang, $arrFaxList);
    $oForm = new paloForm($smarty, $arrFormSendFax);
    if (!$oForm->validateForm($_POST)) {
        // Validation basic, not empty and VALIDATION_TYPE
        $smarty->assign("mb_title", $arrLang["Validation Error"]);
        $arrErrores = $oForm->arrErroresValidacion;
        $strErrorMsg = "<b>{$arrLang['The following fields contain errors']}:</b><br/>";
        if (is_array($arrErrores) && count($arrErrores) > 0) {
            foreach ($arrErrores as $k => $v) {
                $strErrorMsg .= "{$k}, ";
            }
        }
        $smarty->assign("mb_message", $strErrorMsg);
        return $content = viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang);
    } else {
        $destine = getParameter("to");
        $faxexten = getParameter("from");
        $data_content = getParameter("body");
        if ($faxexten == "none") {
            $smarty->assign("mb_title", $arrLang["Validation Error"]);
            $smarty->assign("mb_message", $arrLang["Please, select a valid Fax Device"]);
            return $content = viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang);
        }
        if (getParameter("option_fax") == "by_file") {
            if (is_uploaded_file($_FILES['file_record']['tmp_name'])) {
                $ruta_archivo = $_FILES['file_record']['tmp_name'];
            } else {
                $smarty->assign("mb_title", $arrLang["Validation Error"]);
                $smarty->assign("mb_message", $arrLang["File to upload is empty"]);
                return $content = viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang);
            }
        } else {
            if (!empty($data_content)) {
                /* Las siguientes operaciones son necesarias para lidiar con el
                 * bug Elastix #446. El programa sendfax es incapaz de detectar
                 * un archivo como un archivo de texto si contiene caracteres 
                 * fuera del rango ASCII. */
                $ruta_archivo = $pSendFax->generarArchivoTextoPS($data_content);
                if (is_null($ruta_archivo)) {
                    $smarty->assign(array('mb_title' => _tr('Validation Error'), 'mb_message' => _tr('Failed to convert text')));
                    return viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang);
                }
            } else {
                $smarty->assign("mb_title", $arrLang["Validation Error"]);
                $smarty->assign("mb_message", $arrLang["Text to send is empty"]);
                return $content = viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang);
            }
        }
        $jobid = $pSendFax->sendFax($faxexten, $destine, $ruta_archivo);
        if (is_null($jobid)) {
            $smarty->assign("mb_title", _tr('Validation Error'));
            $smarty->assign("mb_message", _tr('Failed to submit job') . ': ' . $pSendFax->errMsg);
        } else {
            $smarty->assign("SEND_FAX_SUCCESS", _tr('Fax has been sent correctly'));
            $smarty->assign("SENDING_FAX", _tr('Sending Fax...'));
            $smarty->assign('JOBID', $jobid);
        }
        if (file_exists($ruta_archivo)) {
            unlink($ruta_archivo);
        }
        return $content = viewFormSendFax($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang);
    }
}