public function install()
 {
     $sql = "CREATE TABLE IF NOT EXISTS miscapps (miscapps_id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, ext VARCHAR( 50 ) , description VARCHAR( 50 ) , dest VARCHAR( 255 ))";
     $q = $this->db->prepare($sql);
     $q = $q->execute();
     unset($sql);
     unset($q);
     //Migration... Is this still needed
     global $db;
     $results = array();
     $sql = "SELECT miscapps_id, dest FROM miscapps";
     $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
     if (!\DB::IsError($results)) {
         // error - table must not be there
         foreach ($results as $result) {
             $old_dest = $result['dest'];
             $this->id = $result['miscapps_id'];
             $new_dest = merge_ext_followme(trim($old_dest));
             if ($new_dest != $old_dest) {
                 $sql = "UPDATE miscapps SET dest = '{$new_dest}' WHERE miscapps_id = {$miscapps_id}  AND dest = '{$old_dest}'";
                 $results = $db->query($sql);
                 if (DB::IsError($results)) {
                     die_freepbx($results->getMessage());
                 }
             }
         }
     }
 }
/** parking_save
 * Short insert or update parking settings
 * Long takes array of settings to update, missing settings will
 * get default values, if id not present it will insert a new row.
 * Returns the id of the current or newly inserted record or
 * boolean false upon a failure.
 *
 * @author Philippe Lindheimer
 * @param array $parms
 * @return mixed
 */
function parking_save($parms = array())
{
    global $db, $amp_conf;
    if (!empty($parms['id'])) {
        $var['id'] = $db->escapeSimple($parms['id']);
    }
    if (!function_exists('parkpro_get')) {
        $var['id'] = 1;
    }
    $var['name'] = "Parking Lot";
    $var['type'] = 'public';
    $var['parkext'] = '';
    $var['parkpos'] = '';
    $var['numslots'] = 4;
    $var['parkingtime'] = 45;
    $var['parkedmusicclass'] = 'default';
    $var['generatehints'] = 'yes';
    $var['generatefc'] = 'yes';
    $var['findslot'] = 'first';
    $var['parkedplay'] = 'both';
    $var['parkedcalltransfers'] = 'caller';
    $var['parkedcallreparking'] = 'caller';
    $var['alertinfo'] = '';
    $var['cidpp'] = '';
    $var['autocidpp'] = 'none';
    $var['announcement_id'] = null;
    $var['comebacktoorigin'] = 'yes';
    $var['dest'] = '';
    foreach ($var as $k => $v) {
        if (isset($parms[$k])) {
            $var[$k] = $db->escapeSimple($parms[$k]);
        }
    }
    $var['defaultlot'] = isset($var['id']) && $var['id'] == 1 ? 'yes' : 'no';
    $fields = "name, type, parkext, parkpos, numslots, parkingtime, parkedmusicclass, generatehints, generatefc, findslot, parkedplay,\n\t\tparkedcalltransfers, parkedcallreparking, alertinfo, cidpp, autocidpp, announcement_id, comebacktoorigin, dest, defaultlot";
    $holders = "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?";
    if (empty($var['id'])) {
        $sql = "INSERT INTO parkplus ({$fields}) VALUES ({$holders})";
    } else {
        $sql = "REPLACE INTO parkplus (id, {$fields}) VALUES (?,{$holders})";
    }
    $res = $db->query($sql, array_values($var));
    if (DB::IsError($res)) {
        $id = false;
        // TODO log error
    } elseif (empty($var['id'])) {
        if (method_exists($db, 'insert_id')) {
            $id = $db->insert_id();
        } else {
            $id = $amp_conf["AMPDBENGINE"] == "sqlite3" ? sqlite_last_insert_rowid($db->connection) : mysql_insert_id($db->connection);
        }
        needreload();
    } else {
        $id = $var['id'];
        needreload();
    }
    return $id;
}
Example #3
0
function setcid_edit($cid_id, $description, $cid_name, $cid_num, $dest)
{
    global $db;
    $sql = "UPDATE setcid SET " . "description = '" . $db->escapeSimple($description) . "', " . "cid_name = '" . $db->escapeSimple($cid_name) . "', " . "cid_num = '" . $db->escapeSimple($cid_num) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE cid_id = " . $db->escapeSimple($cid_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
function contactdir_get_all_server_types()
{
    global $db;
    $sql = "select * from contactdir_server_types";
    $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        die_freepbx($result->getDebugInfo());
    }
    return $results;
}
Example #5
0
function legacy_extensions_del($context, $exten)
{
    global $db;
    $sql = "DELETE FROM extensions WHERE context = '" . $db->escapeSimple($context) . "' AND `extension` = '" . $db->escapeSimple($exten) . "'";
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($sql . "<br>\n" . $result->getMessage());
    }
    return $result;
}
function ttsengines_get_all_engines()
{
    global $db;
    $sql = "select * from ttsengines";
    $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        die_freepbx($result->getDebugInfo());
    }
    return $results;
}
Example #7
0
function restart_get_devices($grp)
{
    global $db;
    $sql = "SELECT * FROM devices";
    $results = $db->getAll($sql);
    if (DB::IsError($results)) {
        $results = null;
    }
    foreach ($results as $val) {
        $tmparray[] = $val[0];
    }
    return $tmparray;
}
Example #8
0
function _timeconditions_timegroups_get_times($timegroup)
{
    global $db;
    $sql = "select id, time from timegroups_details where timegroupid = {$timegroup}";
    $results = $db->getAll($sql);
    if (DB::IsError($results)) {
        $results = null;
    }
    foreach ($results as $val) {
        $tmparray[] = array($val[0], $val[1]);
    }
    return $tmparray;
}
function getZap_sib($searchext)
{
    global $db;
    zapexists();
    $sql = "SELECT id,data FROM zap WHERE keyword = 'callerid' AND data LIKE '%" . $searchext . "%' ORDER BY id";
    $results = $db->getAll($sql);
    if (DB::IsError($results)) {
        $results = null;
    }
    foreach ($results as $result) {
        $result[] = 'zap';
        $zap[] = $result;
    }
    return $zap;
}
Example #10
0
function execSQL($file)
{
    global $db;
    $data = null;
    // run sql script
    $fd = fopen($file, "r");
    while (!feof($fd)) {
        $data .= fread($fd, 1024);
    }
    fclose($fd);
    preg_match_all("/((SELECT|INSERT|UPDATE|DELETE|CREATE|DROP).*);\\s*\n/Us", $data, $matches);
    foreach ($matches[1] as $sql) {
        $result = $db->query($sql);
        if (DB::IsError($result)) {
            return false;
        }
    }
    return true;
}
Example #11
0
function get_dial_string($extnum)
{
    global $db;
    $ds = '';
    $sql = "SELECT value FROM globals WHERE variable = 'E{$extnum}'";
    $result = $db->getAll($sql);
    if (DB::IsError($result)) {
        die($result->getMessage());
    }
    if (count($result) > 0) {
        $exttech = $result[0][0];
        switch ($exttech) {
            case "SIP":
                $ds = "SIP/" . $extnum;
                break;
            case "IAX2":
                $ds = "IAX2/" . $extnum;
                break;
            case "ZAP":
                $sql = "SELECT value FROM globals WHERE variable = 'ZAPCHAN_{$extnum}'";
                $zapres = $db->getAll($sql);
                if (DB::IsError($zapres)) {
                    die($zapres->getMessage());
                }
                if (count($zapres) > 0) {
                    $zapchannel = $result[0][0];
                }
                $ds = "Zap/" . $zapchannel;
                break;
            default:
                outn($exttech . "...");
                break;
        }
    }
    return $ds;
}
Example #12
0
if (DB::IsError($results)) {
    die($results->getMessage());
}
// get all call groups
$sql = "select extension, args from extensions where args LIKE 'GROUP=%';";
$results = $db->getAll($sql);
if (DB::IsError($results)) {
    die($results->getMessage());
}
out(count($results) . " to check...");
if (count($results) > 0) {
    // yes, there are ring groups defined
    foreach ($results as $key => $value) {
        // replace * that are not at the beginning of an extension
        $new_extensions = preg_replace("/([0-9*#]+)\\*([0-9#]+)/", "\$1\$2#", $value[1]);
        // only replace if changed
        if ($new_extensions != $value[1]) {
            out("Changing " . $value[1] . " to " . $new_extensions);
            $sql = sprintf("update extensions set args = '%s' WHERE extension = '%s' ", $new_extensions, $value['0']) . "AND args LIKE 'GROUP=%'";
            // debug("sql = ". $sql);
            $update_results = $db->query($sql);
            if (DB::IsError($update_results)) {
                die($update_results->getMessage());
            }
        }
    }
}
out("OK");
?>

Example #13
0
function callrecording_edit($callrecording_id, $description, $callrecording_mode, $dest)
{
    global $db;
    $sql = "UPDATE callrecording SET " . "description = '" . $db->escapeSimple($description) . "', " . "callrecording_mode = '" . $db->escapeSimple($callrecording_mode) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE callrecording_id = " . $db->escapeSimple($callrecording_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
		$rule_match = array('status'=>false,'number'=>false);
	}
	if((!$rule_match['status']) || (!$rule_match['number'])){
		if($debug)
		{
			print "Searching Superfecta Cache ... ";
		}
		
		//clear old cache
		$sql = "DELETE FROM superfectacache WHERE dateentered < DATE_SUB(NOW(),INTERVAL ".(isset($run_param['Cache_Timeout'])?$run_param['Cache_Timeout']:$source_param['Cache_Timeout']['default'])." DAY)";
		$db->query($sql);
		
		//query cache
		$sql = "SELECT callerid FROM superfectacache WHERE number = '$thenumber'";
		$sres = $db->getOne($sql);
		if (DB::IsError($sres))
		{
			die_freepbx( "Error: " . $sres->getMessage() .  "<br>");
		}
		
		//check to see if there is a valid return and that it's not numeric
		if(($sres != '') && !is_numeric($sres))
		{
			$caller_id = $sres;
			$cache_found = true;
		}
		else if($debug)
		{
			print "not found<br>\n";
		}
	}elseif($debug){
Example #15
0
function __core_routing_getroutetrunks($route)
{
    global $db;
    $sql = "SELECT DISTINCT args FROM extensions WHERE context = 'outrt-" . $route . "' AND (args LIKE 'dialout-trunk,%' OR args LIKE 'dialout-enum,%' OR args LIKE 'dialout-dundi,%') ORDER BY CAST(priority as UNSIGNED) ";
    $results = $db->getAll($sql);
    if (DB::IsError($results)) {
        die_freepbx($results->getMessage());
    }
    $trunks = array();
    foreach ($results as $row) {
        if (preg_match('/^dialout-trunk,(\\d+)/', $row[0], $matches)) {
            // check in_array -- even though we did distinct
            // we still might get ${EXTEN} and ${EXTEN:1} if they used | to split a pattern
            if (!in_array("OUT_" . $matches[1], $trunks)) {
                $trunks[] = "OUT_" . $matches[1];
            }
        } else {
            if (preg_match('/^dialout-enum,(\\d+)/', $row[0], $matches)) {
                if (!in_array("OUT_" . $matches[1], $trunks)) {
                    $trunks[] = "OUT_" . $matches[1];
                }
            } else {
                if (preg_match('/^dialout-dundi,(\\d+)/', $row[0], $matches)) {
                    if (!in_array("OUT_" . $matches[1], $trunks)) {
                        $trunks[] = "OUT_" . $matches[1];
                    }
                }
            }
        }
    }
    return $trunks;
}
Example #16
0
/**
 * This function will get the MySQL field size of the specified fieldname
 * It's useful for finding out the limit of certain fields in MySQL so that
 * we can do validation checks on strings to make sure they aren't too long.
 * This will help prevent MySQL from needing to do auto chopping on lengthy strings
 * which causes problems with multibyte characters getting cut off abruptly.
 * The third argument defaultsize is just to futureproof in case someone decides
 * to change things in MySQL in the future that would otherwise just pass null back
 * and cause a bug.
 * @param  string $tablename   The table name
 * @param  string $fieldname   The fieldname
 * @param  string $defaultsize Default Size of the field
 * @return string              The default size
 */
function module_get_field_size($tablename, $fieldname, $defaultsize)
{
    global $db;
    $sql = "SELECT character_maximum_length FROM information_schema.columns WHERE table_name = ? AND column_name = ?";
    $results = $db->getAll($sql, array($tablename, $fieldname));
    if (DB::IsError($results)) {
        $results = null;
    }
    return isset($results) ? $results[0][0] : $defaultsize;
}
Example #17
0
        echo $text . "<br />";
    }
}
if (!function_exists("outn")) {
    function outn($text)
    {
        echo $text;
    }
}
$autoincrement = $amp_conf["AMPDBENGINE"] == "sqlite" || $amp_conf["AMPDBENGINE"] == "sqlite3" ? "AUTOINCREMENT" : "AUTO_INCREMENT";
$sql = "CREATE TABLE IF NOT EXISTS manager (\n\t`manager_id` INTEGER NOT NULL PRIMARY KEY {$autoincrement},\n\t`name` VARCHAR( 15 ) NOT NULL ,\n\t`secret` VARCHAR( 50 ) ,\n\t`deny` VARCHAR( 255 ) ,\n\t`permit` VARCHAR( 255 ) ,\n\t`read` VARCHAR( 255 ) ,\n\t`write` VARCHAR( 255 )\n)";
$check = $db->query($sql);
if (DB::IsError($check)) {
    die_freepbx("Can not create `manager` table" . $check->getMessage() . "\n");
}
outn(_("Increasing read field size if needed.."));
$sql = "ALTER TABLE `manager` CHANGE `read` `read` VARCHAR( 255 )";
$result = $db->query($sql);
if (DB::IsError($check)) {
    out(_("error encountered, not altered"));
} else {
    out(_("ok"));
}
outn(_("Increasing write field size if needed.."));
$sql = "ALTER TABLE `manager` CHANGE `write` `write` VARCHAR( 255 )";
$result = $db->query($sql);
if (DB::IsError($check)) {
    out(_("error encountered, not altered"));
} else {
    out(_("ok"));
}
Example #18
0
function fax_get_destinations()
{
    global $db;
    $sql = "SELECT fax_users.user,fax_users.faxemail,fax_users.faxattachformat FROM fax_users where fax_users.faxenabled = 'true' ORDER BY fax_users.user";
    $results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        die_freepbx($results->getMessage() . "<br><br>Error selecting from fax");
    }
    $final = array();
    $warning = array();
    foreach ($results as $res) {
        $o = \FreePBX::Userman()->getUserByID($res['user']);
        if (!empty($o)) {
            if (empty($o['email'])) {
                $warning[] = $o['username'];
                continue;
            }
            $res['uname'] = $o['username'];
            $res['name'] = !empty($o['displayname']) ? $o['displayname'] : $o['fname'] . " " . $o['lname'];
            $res['name'] = trim($res['name']);
            $res['name'] = !empty($res['name']) ? $res['name'] : $o['username'];
            $final[] = $res;
        }
    }
    $nt = \notifications::create();
    if (!empty($warning)) {
        $nt->add_warning("fax", "invalid_email", _("Invalid Email for Inbound Fax"), sprintf(_("User Manager users '%s' have the ability to receive faxes but have no email address defined so they will not be able to receive faxes."), implode(",", $warning)), "", true, true);
    } else {
        $nt->delete("fax", "invalid_email");
    }
    return $final;
}
Example #19
0
    for ($i = 0; $i < 4; $i++) {
        $interval[] = process_interval($_REQUEST['ora_inizio'][$i], $_REQUEST['minuti_inizio'][$i], $_REQUEST['giorno_inizio'][$i], $_REQUEST['mese_inizio'][$i], $_REQUEST['ora_fine'][$i], $_REQUEST['minuti_fine'][$i], $_REQUEST['giorno_fine'][$i], $_REQUEST['mese_fine'][$i], $_REQUEST['ore_tutti'][$i], $_REQUEST['giorni_tutti'][$i], $_REQUEST['mesi_tutti'][$i]);
    }
    $globalfields = array(array($_REQUEST['INCOMING'], 'INCOMING_1'), array($interval[0][0], 'REGTIME_1'), array($interval[0][1], 'REGDAYS_1'), array($interval[0][2], 'REGMONTHS_1'), array($interval[1][0], 'REGTIME2_1'), array($interval[1][1], 'REGDAYS2_1'), array($interval[1][2], 'REGMONTHS2_1'), array($interval[2][0], 'REGTIME3_1'), array($interval[2][1], 'REGDAYS3_1'), array($interval[2][2], 'REGMONTHS3_1'), array($interval[3][0], 'REGTIME4_1'), array($interval[3][1], 'REGDAYS4_1'), array($interval[3][2], 'REGMONTHS4_1'), array($_REQUEST['INCOMING_DESC'], 'INCOMING_DESC_1'), array($_REQUEST['AFTER_INCOMING'], 'AFTER_INCOMING_1'), array($_REQUEST['HOLIDAY_INCOMING'], 'HOLIDAY_INCOMING_1'), array($_REQUEST['IN_OVERRIDE'], 'IN_OVERRIDE_1'));
    $compiled = $db->prepare('UPDATE globals SET value = ? WHERE variable = ?');
    $result = $db->executeMultiple($compiled, $globalfields);
    if (DB::IsError($result)) {
        echo $action . '<br>';
        die($result->getMessage());
    }
    exec($wScript);
    needreload();
}
$sql = "SELECT * FROM globals";
$globals = $db->getAll($sql);
if (DB::IsError($globals)) {
    die($globals->getMessage());
}
foreach ($globals as $global) {
    ${trim($global[0])} = $global[1];
}
$ReadForceIncomingHours = ReadForceIncomingHours(2);
if ($ReadForceIncomingHours != "none") {
    $WarningMsg = "This Incoming Call is in conflict with the Special Estension *60.<br>Please don't use both at the same time. SUBMIT CHANGES is Disabled.";
} else {
    $WarningMsg = "&nbsp;";
}
$unique_aas = getaas();
$extens = getextens();
$gresults = getgroups();
$queues = getqueues();
 /** Internal use only */
 function _setenabled($modulename, $enabled)
 {
     global $db;
     $sql = 'UPDATE modules SET enabled = ' . ($enabled ? '1' : '0') . ' WHERE modulename = "' . $db->escapeSimple($modulename) . '"';
     $results = $db->query($sql);
     if (DB::IsError($results)) {
         die_freepbx($sql . "<br>\n" . $results->getMessage());
     }
     $modulelist =& modulelist::create($db);
     $modulelist->invalidate();
 }
function languages_edit($language_id, $description, $lang_code, $dest)
{
    global $db;
    $sql = "UPDATE languages SET " . "description = '" . $db->escapeSimple($description) . "', " . "lang_code = '" . $db->escapeSimple($lang_code) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE language_id = " . $db->escapeSimple($language_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
Example #22
0
function paging_get_pagingconfig($grp)
{
    global $db;
    // Just in case someone's trying to be smart with a SQL injection.
    $grp = $db->escapeSimple($grp);
    $sql = "SELECT * FROM paging_config WHERE page_group='{$grp}'";
    $results = $db->getRow($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($results)) {
        $results = null;
    }
    $sql = "SELECT * FROM admin WHERE variable='default_page_grp' AND value='{$grp}'";
    $default_group = $db->getRow($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($default_group)) {
        $results['default_group'] = 0;
    } else {
        $results['default_group'] = empty($default_group) ? 0 : $default_group['value'];
    }
    return $results;
}
Example #23
0
function announcement_edit($announcement_id, $description, $recording_id, $allow_skip, $post_dest, $return_ivr, $noanswer, $repeat_msg)
{
    global $db;
    $sql = "UPDATE announcement SET " . "description = '" . $db->escapeSimple($description) . "', " . "recording_id = '" . $recording_id . "', " . "allow_skip = '" . ($allow_skip ? 1 : 0) . "', " . "post_dest = '" . $db->escapeSimple($post_dest) . "', " . "return_ivr = '" . ($return_ivr ? 1 : 0) . "', " . "noanswer = '" . ($noanswer ? 1 : 0) . "', " . "repeat_msg = '" . $db->escapeSimple($repeat_msg) . "' " . "WHERE announcement_id = " . $db->escapeSimple($announcement_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}
Example #24
0
function __migrate_trunks_to_table()
{
    global $db;
    global $amp_conf;
    $sql = "\n\tCREATE TABLE `trunks` \n\t( \n\t\t`trunkid` INTEGER,\n\t\t`name` VARCHAR( 50 ) NOT NULL DEFAULT '', \n\t\t`tech` VARCHAR( 20 ) NOT NULL , \n\t\t`outcid` VARCHAR( 40 ) NOT NULL DEFAULT '', \n\t\t`keepcid` VARCHAR( 4 ) DEFAULT 'off',\n\t\t`maxchans` VARCHAR( 6 ) DEFAULT '',\n\t\t`failscript` VARCHAR( 255 ) NOT NULL DEFAULT '', \n\t\t`dialoutprefix` VARCHAR( 255 ) NOT NULL DEFAULT '', \n\t\t`channelid` VARCHAR( 255 ) NOT NULL DEFAULT '', \n\t\t`usercontext` VARCHAR( 255 ) NULL, \n\t\t`provider` VARCHAR( 40 ) NULL, \n\t\t`disabled` VARCHAR( 4 ) DEFAULT 'off',\n\t\n\t\tPRIMARY KEY  (`trunkid`, `tech`, `channelid`) \n\t) \n\t";
    $check = $db->query($sql);
    if (DB::IsError($check)) {
        if ($check->getCode() == DB_ERROR_ALREADY_EXISTS) {
            //echo ("already exists\n");
            return false;
        } else {
            die_freepbx($check->getDebugInfo());
        }
    }
    // sqlite doesn't support the syntax required for the SQL so we have to do it the hard way
    if ($amp_conf["AMPDBENGINE"] == "sqlite3") {
        $sqlstr = "SELECT variable, value FROM globals WHERE variable LIKE 'OUT\\_%' ESCAPE '\\'";
        $my_unique_trunks = sql($sqlstr, "getAll", DB_FETCHMODE_ASSOC);
        $sqlstr = "SELECT variable, value FROM globals WHERE variable LIKE 'OUTDISABLE\\_%' ESCAPE '\\'";
        $disable_states = sql($sqlstr, "getAll", DB_FETCHMODE_ASSOC);
        foreach ($disable_states as $arr) {
            $disable_states_assoc[$arr['variable']] = $arr['value'];
        }
        global $unique_trunks;
        $unique_trunks = array();
        foreach ($my_unique_trunks as $this_trunk) {
            $trunk_num = substr($this_trunk['variable'], 4);
            $this_state = isset($disable_states_assoc['OUTDISABLE_' . $trunk_num]) ? $disable_states_assoc['OUTDISABLE_' . $trunk_num] : 'off';
            $unique_trunks[] = array($this_trunk['variable'], $this_trunk['value'], $this_state);
        }
        // sort this array using a custom function __sort_trunks(), defined above
        uksort($unique_trunks, "__sort_trunks");
        // re-index the newly sorted array
        foreach ($unique_trunks as $arr) {
            $unique_trunks_t[] = array($arr[0], $arr[1], $arr[2]);
        }
        $unique_trunks = $unique_trunks_t;
    } else {
        $sqlstr = "SELECT t.variable, t.value, d.value state FROM `globals` t ";
        $sqlstr .= "JOIN (SELECT x.variable, x.value FROM globals x WHERE x.variable LIKE 'OUTDISABLE\\_%') d ";
        $sqlstr .= "ON substring(t.variable,5) = substring(d.variable,12) WHERE t.variable LIKE 'OUT\\_%' ";
        $sqlstr .= "UNION ALL ";
        $sqlstr .= "SELECT v.variable, v.value, concat(substring(v.value,1,0),'off') state  FROM `globals` v ";
        $sqlstr .= "WHERE v.variable LIKE 'OUT\\_%' AND concat('OUTDISABLE_',substring(v.variable,5)) NOT IN ";
        $sqlstr .= " ( SELECT variable from globals WHERE variable LIKE 'OUTDISABLE\\_%' ) ";
        $sqlstr .= "ORDER BY variable";
        $unique_trunks = sql($sqlstr, "getAll");
    }
    $trunkinfo = array();
    foreach ($unique_trunks as $trunk) {
        list($tech, $name) = explode('/', $trunk[1]);
        $trunkid = ltrim($trunk[0], 'OUT_');
        $sqlstr = "\n\t\t\tSELECT `variable`, `value` FROM `globals` WHERE `variable` IN (\n\t\t\t\t'OUTCID_{$trunkid}', 'OUTFAIL_{$trunkid}', 'OUTKEEPCID_{$trunkid}',\n\t\t\t\t'OUTMAXCHANS_{$trunkid}', 'OUTPREFIX_{$trunkid}')\n\t\t";
        $trunk_attribs = sql($sqlstr, 'getAll', DB_FETCHMODE_ASSOC);
        $trunk_attrib_hash = array();
        foreach ($trunk_attribs as $attribs) {
            $trunk_attrib_hash[$attribs['variable']] = $attribs['value'];
        }
        switch ($tech) {
            case 'SIP':
                $tech = 'sip';
                $user = sql("SELECT `data` FROM `sip` WHERE `id` = '99999{$trunkid}' AND `keyword` = 'account'", 'getOne');
                break;
            case 'IAX':
            case 'IAX2':
                $tech = 'iax';
                $user = sql("SELECT `data` FROM `iax` WHERE `id` = '99999{$trunkid}' AND `keyword` = 'account'", 'getOne');
                break;
            case 'ZAP':
            case 'DUNDI':
            case 'ENUM':
                $tech = strtolower($tech);
                $user = '';
                break;
            default:
                if (substr($tech, 0, 4) == 'AMP:') {
                    $tech = 'custom';
                    $name = substr($trunk[1], 4);
                } else {
                    $tech = strtolower($tech);
                }
                $user = '';
        }
        $trunkinfo[] = array('trunkid' => $trunkid, 'tech' => $tech, 'outcid' => $trunk_attrib_hash['OUTCID_' . $trunkid], 'keepcid' => $trunk_attrib_hash['OUTKEEPCID_' . $trunkid], 'maxchans' => $trunk_attrib_hash['OUTMAXCHANS_' . $trunkid], 'failscript' => $trunk_attrib_hash['OUTFAIL_' . $trunkid], 'dialoutprefix' => $trunk_attrib_hash['OUTPREFIX_' . $trunkid], 'channelid' => $name, 'usercontext' => $user, 'disabled' => $trunk[2]);
        $sqlstr = "INSERT INTO `trunks` \n\t\t\t( trunkid, tech, outcid, keepcid, maxchans, failscript, dialoutprefix, channelid, usercontext, disabled) \n\t\t\tVALUES (\n\t\t\t\t'" . $db->escapeSimple($trunkid) . "',\n\t\t\t\t'" . $db->escapeSimple($tech) . "',\n\t\t\t\t'" . $db->escapeSimple($trunk_attrib_hash['OUTCID_' . $trunkid]) . "',\n\t\t\t\t'" . $db->escapeSimple($trunk_attrib_hash['OUTKEEPCID_' . $trunkid]) . "',\n\t\t\t\t'" . $db->escapeSimple($trunk_attrib_hash['OUTMAXCHANS_' . $trunkid]) . "',\n\t\t\t\t'" . $db->escapeSimple($trunk_attrib_hash['OUTFAIL_' . $trunkid]) . "',\n\t\t\t\t'" . $db->escapeSimple($trunk_attrib_hash['OUTPREFIX_' . $trunkid]) . "',\n\t\t\t\t'" . $db->escapeSimple($name) . "',\n\t\t\t\t'" . $db->escapeSimple($user) . "',\n\t\t\t\t'" . $db->escapeSimple($trunk[2]) . "'\n\t\t  )\n\t\t";
        sql($sqlstr);
    }
    return $trunkinfo;
}
Example #25
0
 /** Remove all settings with the indicated module ownership, used
  * during functions like uninstalling modules.
  *
  * @param  array  array of settings to be removed
  */
 function remove_module_settings($module)
 {
     global $db;
     $sql = "DELETE FROM freepbx_settings WHERE module = '{$module}'";
     $result = $db->query($sql);
     if (\DB::IsError($result)) {
         die_freepbx(_('fatal error deleting rows from freepbx_settings, sql query: %s') . $sql);
     }
 }
Example #26
0
function miscapps_edit($miscapps_id, $description, $ext, $dest, $enabled = true)
{
    global $db;
    $sql = "UPDATE miscapps SET " . "description = '" . $db->escapeSimple($description) . "', " . "ext = '" . $db->escapeSimple($ext) . "', " . "dest = '" . $db->escapeSimple($dest) . "' " . "WHERE miscapps_id = " . $db->escapeSimple($miscapps_id);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
    $fc = new featurecode('miscapps', 'miscapp_' . $miscapps_id);
    $fc->setDescription($description);
    $fc->setDefault($ext, true);
    $fc->setEnabled($enabled);
    $fc->update();
}
    public function install()
    {
        global $db;
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_groups` (
		 `id` int(11) NOT NULL AUTO_INCREMENT,
		 `owner` int(11) NOT NULL,
		 `name` varchar(80) NOT NULL,
		 `type` varchar(25) NOT NULL,
		 PRIMARY KEY (`id`)
		);';
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_group_entries` (
		 `id` int(11) NOT NULL AUTO_INCREMENT,
		 `groupid` int(11) NOT NULL,
		 `user` int(11) NOT NULL,
		 `displayname` varchar(100) default NULL,
		 `fname` varchar(100) default NULL,
		 `lname` varchar(100) default NULL,
		 `title` varchar(100) default NULL,
		 `company` varchar(100) default NULL,
		 `address` varchar(200) default NULL,
		 PRIMARY KEY (`id`)
		);';
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_numbers` (
		 `id` int(11) NOT NULL AUTO_INCREMENT,
		 `entryid` int(11) NOT NULL,
		 `number` varchar(100) default NULL,
		 `extension` varchar(100) default NULL,
		 `type` varchar(100),
		 `flags` varchar(100),
		 PRIMARY KEY (`id`)
		);';
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_images` (
		 `entryid` int(11) NOT NULL,
		 `image` LONGBLOB,
		 `format` VARCHAR(45) NOT NULL,
		 `gravatar` tinyint(4) NOT NULL DEFAULT "0",
		 PRIMARY KEY (`entryid`)
	 );';
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_xmpps` (
		 `id` int(11) NOT NULL AUTO_INCREMENT,
		 `entryid` int(11) NOT NULL,
		 `xmpp` varchar(100) default NULL,
		 PRIMARY KEY (`id`)
		);';
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_emails` (
		 `id` int(11) NOT NULL AUTO_INCREMENT,
		 `entryid` int(11) NOT NULL,
		 `email` varchar(100) default NULL,
		 PRIMARY KEY (`id`)
		);';
        $sql[] = 'CREATE TABLE IF NOT EXISTS `contactmanager_entry_websites` (
		 `id` int(11) NOT NULL AUTO_INCREMENT,
		 `entryid` int(11) NOT NULL,
		 `website` varchar(100) default NULL,
		 PRIMARY KEY (`id`)
		);';
        foreach ($sql as $statement) {
            $check = $db->query($statement);
            if (\DB::IsError($check)) {
                die_freepbx("Can not execute {$statement} : " . $check->getMessage() . "\n");
            }
        }
        outn(_("checking for title field.."));
        $sql = "SELECT `title` FROM contactmanager_group_entries";
        $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
        if (\DB::IsError($check)) {
            // add new field
            $sql = "ALTER TABLE contactmanager_group_entries ADD `title` varchar(100), ADD `company` varchar(100)";
            $result = $db->query($sql);
            if (\DB::IsError($result)) {
                out(_("ERROR failed to update title field"));
            } else {
                out(_("OK"));
            }
        } else {
            out(_("already exists"));
        }
        outn(_("checking for displayname field.."));
        $sql = "SELECT `displayname` FROM contactmanager_group_entries";
        $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
        if (\DB::IsError($check)) {
            // add new field
            $sql = "ALTER TABLE contactmanager_group_entries ADD `displayname` varchar(100)";
            $result = $db->query($sql);
            if (\DB::IsError($result)) {
                out(_("ERROR failed to update displayname field"));
            } else {
                out(_("OK"));
            }
        } else {
            out(_("already exists"));
        }
        outn(_("checking for address field.."));
        $sql = "SELECT `address` FROM contactmanager_group_entries";
        $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
        if (\DB::IsError($check)) {
            // add new field
            $sql = "ALTER TABLE contactmanager_group_entries ADD `address` varchar(200)";
            $result = $db->query($sql);
            if (\DB::IsError($result)) {
                out(_("ERROR failed to update address field"));
            } else {
                out(_("OK"));
            }
        } else {
            out(_("already exists"));
        }
        outn(_("checking for extension field.."));
        $sql = "SELECT `extension` FROM contactmanager_entry_numbers";
        $check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
        if (\DB::IsError($check)) {
            // add new field
            $sql = "ALTER TABLE contactmanager_entry_numbers ADD `extension` varchar(100)";
            $result = $db->query($sql);
            if (\DB::IsError($result)) {
                out(_("ERROR failed to update extension field"));
            } else {
                out(_("OK"));
            }
        } else {
            out(_("already exists"));
        }
        $sql = "SELECT * FROM contactmanager_groups WHERE type = 'userman'";
        $sth = $this->db->prepare($sql);
        $sth->execute();
        $grps = $sth->fetchAll(\PDO::FETCH_ASSOC);
        if (empty($grps)) {
            $ret = $this->addGroup(_("User Manager Group"), "userman");
            $id = $this->freepbx->Userman->getAutoGroup();
            $id = !empty($id) ? $id : 1;
            $this->freepbx->Userman->setModuleSettingByGID($id, 'contactmanager', 'groups', array("*"));
        }
    }
Example #28
0
    $scheme_name_array[0] = $scheme_name_request;
}
if (empty($trunk_info['callerid']) && !is_int($trunk_info['callerid'])) {
    if (!$cli) {
        die('Invalid Number');
    } else {
        echo base64_encode(serialize(array('message' => 'Invalid Number')));
    }
}
foreach ($scheme_name_array as $list) {
    $scheme_name = $list;
    //Get Scheme Params
    $param = array();
    $query = "SELECT * FROM superfectaconfig";
    $res = $db->query($query);
    if (DB::IsError($res)) {
        die("Unable to load scheme parameters: " . $res->getMessage() . "<br>");
    }
    while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC)) {
        $param[$row['source']][$row['field']] = $row['value'];
    }
    if (!array_key_exists($scheme_name, $param)) {
        die('Scheme Does not Exist!');
    }
    $scheme_param = $param[$scheme_name];
    require_once dirname(__FILE__) . '/superfecta_base.php';
    $options = array('db' => $db, 'amp_conf' => $amp_conf, 'astman' => $astman, 'debug' => $debug, 'scheme_name' => $scheme_name, 'scheme_parameters' => $scheme_param, 'path_location' => dirname(dirname(__FILE__)) . '/sources', 'trunk_info' => $trunk_info);
    switch ($scheme_param['processor']) {
        case 'superfecta_multi.php':
            require_once dirname(__FILE__) . '/processors/superfecta_multi.php';
            $options['multifecta_id'] = isset($multifecta_id) ? $multifecta_id : null;
Example #29
0
        die_freepbx($result->getDebugInfo());
    } else {
        out(_("added"));
    }
} else {
    out(_("not needed"));
}
outn(_("Checking for retvm.."));
$sql = "SELECT retvm FROM ivr";
$check = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if (DB::IsError($check)) {
    //  Add retvm field
    //
    $sql = "ALTER TABLE ivr ADD retvm VARCHAR(8);";
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        out(_("fatal error"));
        die_freepbx($result->getDebugInfo());
    } else {
        out(_("added"));
    }
} else {
    out(_("not needed"));
}
$count = sql('SELECT COUNT(*) FROM `ivr` WHERE `enable_directory` = "CHECKED"', 'getOne');
if ($count) {
    global $db;
    $notifications =& notifications::create($db);
    $extext = sprintf(_("There are %s IVRs that have the legacy Directory dialing enabled. This has been deprecated and will be removed from future releases. You should convert your IVRs to use the Directory module for this functionality and assign an IVR destination to a desired Directory. You can install the Directory module from the Online Module Repository"), $count);
    $notifications->add_notice('ivr', 'DIRECTORY_DEPRECATED', sprintf(_('Deprecated Directory used by %s IVRs'), $count), $extext, '', true, true);
    out(_("posting notice about deprecated functionality"));
Example #30
0
function customappsreg_customextens_edit($old_custom_exten, $custom_exten, $description, $notes)
{
    global $db;
    $sql = "UPDATE custom_extensions SET " . "custom_exten = " . sql_formattext($custom_exten) . ", " . "description = " . sql_formattext($description) . ", " . "notes = " . sql_formattext($notes) . " " . "WHERE custom_exten = " . sql_formattext($old_custom_exten);
    $result = $db->query($sql);
    if (DB::IsError($result)) {
        die_freepbx($result->getMessage() . $sql);
    }
}