Example #1
0
function didAssign($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    $pDID = new paloDidPBX($pDB);
    $domain = getParameter('domain');
    $prop['country'] = getParameter('country');
    $prop['city'] = getParameter('city');
    if ($credentials['userlevel'] != "superadmin") {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("You are not authorized to perform this action"));
        return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    //validamos que sea un dominio valido
    if (!preg_match("/^(([[:alnum:]-]+)\\.)+([[:alnum:]])+\$/", $domain)) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Invalid domain format"));
        return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    if (getParameter('save_did')) {
        //procedemos a guardar los cambios
        $selectDID = getParameter("listDIDOrg");
        if (!empty($selectDID)) {
            $listDIDOrg = explode(",", $selectDID);
            if ($pDID->assignDIDs($listDIDOrg, $domain)) {
                $smarty->assign("mb_title", _tr("Message"));
                if (writeDHADIDidFile($error)) {
                    $smarty->assign("mb_message", _tr("DID was assigned successfully"));
                } else {
                    $smarty->assign("mb_message", _tr("DID was assigned") . $error);
                }
            } else {
                $smarty->assign("mb_title", _tr("ERROR"));
                $smarty->assign("mb_message", $pDID->errMsg);
            }
            return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        } else {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("You must select at least one DID"));
        }
    } else {
        //obtenemos la lista de los DID filtrado por el dominio
        $listDID = $pDID->getDIDFree(array('country' => null, 'city' => null));
        if ($listDID === false) {
            $smarty->assign("mb_title", _tr("ERROR"));
            $smarty->assign("mb_message", _tr("An error has ocurred to retrieve DID data"));
            return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
        }
        $country = array("0" => _tr("--Select a Country--"));
        $city = array("0" => _tr("--Select a City--"));
        $arrDID = $listDIDOrg = array();
        foreach ($listDID as $value) {
            $arrDID[] = array('id' => $value['id'], 'did' => $value['did'], 'country_code' => $value['country_code'], 'area_code' => $value['area_code']);
            $country[$value['country']] = $value['country'];
            $city[$value['city']] = $value['city'];
        }
    }
    global $arrPermission;
    if (in_array('edit_DID', $arrPermission)) {
        $smarty->assign('EDIT_DID', TRUE);
    }
    $smarty->assign("SEARCH", "<input name='search_did' type='button' class='button' onclick='filer_did()' value='" . _tr('Search') . "'>");
    $smarty->assign("DID_FREE", $arrDID);
    $smarty->assign("CANCEL", _tr("Cancel"));
    $smarty->assign("SAVE", _tr("Save"));
    $smarty->assign("DIDLIST_LABEL", _tr('Available DID'));
    $smarty->assign("DIDORG_LABEL", _tr('DID to assign to') . " " . $domain);
    $smarty->assign("LEYENDDRAG", _tr("Drag and Drop DIDs into 'DID to assign' Area"));
    $smarty->assign("listDIDOrg", '');
    $smarty->assign("domain", $domain);
    $arrForm = createDidForn($country, $city);
    $oForm = new paloForm($smarty, $arrForm);
    $htmlForm = $oForm->fetchForm("{$local_templates_dir}/organization_did.tpl", _tr("Organization DID"), $prop);
    $content = "<form  method='POST' style='margin-bottom:0;' action='?menu={$module_name}'>" . $htmlForm . "</form>";
    return $content;
}