Example #1
0
function removeDID($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials)
{
    $pORGZ = new paloSantoOrganization($pDB);
    $pDID = new paloDidPBX($pDB);
    $domain = getParameter('domain');
    if ($credentials['userlevel'] != "superadmin") {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("You are not authorized to perform this action"));
        return reportOrganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    $listDID = $_POST["dids"];
    $arrDIDs = array();
    if (is_array($listDID)) {
        foreach ($listDID as $value) {
            if (preg_match('/^[[:digit:]]+$/', $value)) {
                $arrDIDs[] = $value;
            }
        }
    }
    if (count($arrDIDs) == 0) {
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("You must select at least one item."));
        return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
    $error = "";
    $pDB->beginTransaction();
    if ($pDID->removeAsignation($arrDIDs, $domain)) {
        $pDB->commit();
        $smarty->assign("mb_title", _tr("Message"));
        if (writeDHADIDidFile($error)) {
            $smarty->assign("mb_message", _tr("DID was removed successfully"));
        } else {
            $smarty->assign("mb_message", _tr("DID was removed") . $error);
        }
        return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    } else {
        $pDB->rollBack();
        $smarty->assign("mb_title", _tr("ERROR"));
        $smarty->assign("mb_message", _tr("Changes couldn't be applied."));
        return reportDIDorganization($smarty, $module_name, $local_templates_dir, $pDB, $arrConf, $credentials);
    }
}