示例#1
0
文件: index.php 项目: hardikk/HNH
function saveNewMyExtension($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang, $extension, $isAdministrator)
{
    $pMyExtension = new paloSantoMyExtension($pDB);
    $arrFormMyExtension = createFieldForm($arrLang);
    $oForm = new paloForm($smarty, $arrFormMyExtension);
    $message = "";
    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);
    } else {
        $s = $_SESSION["my_extension"]["extension"];
        if (isset($_SESSION["my_extension"]["extension"])) {
            $extension = $_SESSION["my_extension"]["extension"];
            $enableDND = getParameter("do_not_disturb");
            //return on or off
            $enableCW = getParameter("call_waiting");
            //return on or off
            $enableCF = getParameter("call_forward");
            //return on or off
            $enableCFU = getParameter("call_forward_U");
            //return on or off
            $enableCFB = getParameter("call_forward_B");
            //return on or off
            $statusCW = $pMyExtension->setConfig_CallWaiting($enableCW, $extension);
            $statusDND = $pMyExtension->setConfig_DoNotDisturb($enableDND, $extension);
            $phoneNumberCF = trim(getParameter("phone_number_CF"));
            //is a number !!
            $phoneNumberCFU = trim(getParameter("phone_number_CFU"));
            $phoneNumberCFB = trim(getParameter("phone_number_CFB"));
            /*recordings*/
            $recordIncomingOption = getParameter("record_incoming");
            $recordOutgoingOption = getParameter("record_outgoing");
            /************/
            if ($enableCF == "on") {
                if (preg_match("/^[0-9]+\$/", $phoneNumberCF)) {
                    $statusCF = $pMyExtension->setConfig_CallForward($enableCF, $phoneNumberCF, $extension);
                } else {
                    $_SESSION["my_extension"]["enableCF"] = "on";
                    $_SESSION["my_extension"]["phoneNumberCF"] = $phoneNumberCF;
                    $message .= $arrLang["Please check your phone number for Call Forward"] . "<br />";
                    $smarty->assign("mb_title", $arrLang["Validation Error"]);
                    $smarty->assign("mb_message", $message);
                }
            } else {
                $statusCF = $pMyExtension->setConfig_CallForward($enableCF, "", $extension);
            }
            if ($enableCFU == "on") {
                if (preg_match("/^[0-9]+\$/", $phoneNumberCFU)) {
                    $statusCFU = $pMyExtension->setConfig_CallForwardOnUnavail($enableCFU, $phoneNumberCFU, $extension);
                } else {
                    $_SESSION["my_extension"]["enableCFU"] = "on";
                    $_SESSION["my_extension"]["phoneNumberCFU"] = $phoneNumberCFU;
                    $message .= $arrLang["Please check your phone number for Call Forward On Unavailable"] . "<br />";
                    $smarty->assign("mb_title", $arrLang["Validation Error"]);
                    $smarty->assign("mb_message", $message);
                }
            } else {
                $statusCFU = $pMyExtension->setConfig_CallForwardOnUnavail($enableCFU, "", $extension);
            }
            if ($enableCFB == "on") {
                if (preg_match("/^[0-9]+\$/", $phoneNumberCFB)) {
                    $statusCFB = $pMyExtension->setConfig_CallForwardOnBusy($enableCFB, $phoneNumberCFB, $extension);
                } else {
                    $_SESSION["my_extension"]["enableCFB"] = "on";
                    $_SESSION["my_extension"]["phoneNumberCFB"] = $phoneNumberCFB;
                    $message .= $arrLang["Please check your phone number for Call Forward On Busy"] . "<br />";
                    $smarty->assign("mb_title", $arrLang["Validation Error"]);
                    $smarty->assign("mb_message", $message);
                }
            } else {
                $statusCFB = $pMyExtension->setConfig_CallForwardOnBusy($enableCFB, "", $extension);
            }
            if (!$statusCW) {
                $message .= $arrLang["Error processing CallWaiting"] . "<br />";
            }
            if (!$statusDND) {
                $message .= $arrLang["Error processing Do Not Disturb"] . "<br />";
            }
            if (!$statusCF) {
                $message .= $arrLang["Error processing Call Forward"] . "<br />";
            }
            if (!$statusCFU) {
                $message .= $arrLang["Error processing Call Forward on Unavailable"] . "<br />";
            }
            if (!$statusCFB) {
                $message .= $arrLang["Error processing Call Forward on Busy"] . "<br />";
            }
            /*recordings*/
            $statusRecording = $pMyExtension->setRecordSettings($extension, $recordIncomingOption, $recordOutgoingOption);
            /************/
            if ($statusCW && $statusDND && $statusCF && $statusCFU && $statusCFB && $statusRecording) {
                $message = $arrLang["Your configuration has been saved correctly"] . "<br />";
            }
            $smarty->assign("mb_message", $message);
        } else {
            if ($isAdministrator) {
                $message = "<b>" . $arrLang["no_extension"] . "</b>";
            } else {
                $message = "<b>" . $arrLang["contact_admin"] . "</b>";
            }
            $smarty->assign("mb_message", $message);
        }
    }
    $content = viewFormMyExtension($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $arrLang, $extension);
    return $content;
}
示例#2
0
 /**
  * Functional point that sets the option call forward to the extension of the authenticated user
  *
  * @param   boolean     $callForward                         (optional) true will set a call forward, false will not
  * @param   integer     $phoneNumberCallForward              (optional) Number for the call forward
  * @param   boolean     $callForwardUnavailable              (optional) true will set a call forward on unavailable, false will not
  * @param   integer     $phoneNumberCallForwardUnavailable   (optional) Number for the call forward on unavailable
  * @param   boolean     $callForwardBusy                     (optional) true will set a call forward on busy, false will not
  * @param   integer     $phoneNumberCallForwardBusy          (optional) Number for the call forward on busy
  * @return  boolean     True if the call forward was set, or false if an error exists
  */
 public function setCallForward($callForward, $phoneNumberCallForward, $callForwardUnavailable, $phoneNumberCallForwardUnavailable, $callForwardBusy, $phoneNumberCallForwardBusy)
 {
     global $root;
     $extension = $this->_leerExtension();
     $pDB = new paloDB(generarDSNSistema('asteriskuser', 'asterisk', $root . "/"));
     $pMyExtension = new paloSantoMyExtension($pDB);
     $statusCF = $statusCFU = $statusCFB = true;
     if (is_null($extension)) {
         return false;
     }
     if (isset($callForward)) {
         if ($callForward) {
             if (isset($phoneNumberCallForward)) {
                 if (preg_match("/^[0-9]+\$/", $phoneNumberCallForward)) {
                     $statusCF = $pMyExtension->setConfig_CallForward("on", $phoneNumberCallForward, $extension);
                 }
             }
         } else {
             $statusCF = $pMyExtension->setConfig_CallForward("off", "", $extension);
         }
     }
     if (isset($callForwardUnavailable)) {
         if ($callForwardUnavailable) {
             if (isset($phoneNumberCallForwardUnavailable)) {
                 if (preg_match("/^[0-9]+\$/", $phoneNumberCallForwardUnavailable)) {
                     $statusCFU = $pMyExtension->setConfig_CallForwardOnUnavail("on", $phoneNumberCallForwardUnavailable, $extension);
                 }
             }
         } else {
             $statusCFU = $pMyExtension->setConfig_CallForwardOnUnavail("off", "", $extension);
         }
     }
     if (isset($callForwardBusy)) {
         if ($callForwardBusy) {
             if (isset($phoneNumberCallForwardBusy)) {
                 if (preg_match("/^[0-9]+\$/", $phoneNumberCallForwardBusy)) {
                     $statusCFB = $pMyExtension->setConfig_CallForwardOnBusy("on", $phoneNumberCallForwardBusy, $extension);
                 }
             }
         } else {
             $statusCFB = $pMyExtension->setConfig_CallForwardOnBusy("off", "", $extension);
         }
     }
     if (!$statusCF) {
         $this->errMsg["fc"] = 'ERROR';
         $this->errMsg["fm"] = 'Error Processing Call Forward';
         $this->errMsg["fd"] = 'The Call Forward could not be set';
         $this->errMsg["cn"] = get_class($this);
         return false;
     }
     if (!$statusCFU) {
         $this->errMsg["fc"] = 'ERROR';
         $this->errMsg["fm"] = 'Error Processing Call Forward on Unavailable';
         $this->errMsg["fd"] = 'The Call Forward on Unavailable could not be set';
         $this->errMsg["cn"] = get_class($this);
         return false;
     }
     if (!$statusCFB) {
         $this->errMsg["fc"] = 'ERROR';
         $this->errMsg["fm"] = 'Error Processing Call Forward on Busy';
         $this->errMsg["fd"] = 'The Call Forward on Busy could not be set';
         $this->errMsg["cn"] = get_class($this);
         return false;
     }
     return true;
 }