Example #1
0
function timeconditions_get_config($engine)
{
    global $ext;
    // is this the best way to pass this?
    global $conferences_conf;
    switch ($engine) {
        case "asterisk":
            $timelist = timeconditions_list(true);
            if (is_array($timelist)) {
                foreach ($timelist as $item) {
                    // add dialplan
                    // note we don't need to add 2nd optional option of true, gotoiftime will convert '|' to ',' for 1.6+
                    $times = timeconditions_timegroups_get_times($item['time']);
                    if (is_array($times)) {
                        foreach ($times as $time) {
                            $ext->add('timeconditions', $item['timeconditions_id'], '', new ext_gotoiftime($time[1], $item['truegoto']));
                        }
                    }
                    $ext->add('timeconditions', $item['timeconditions_id'], '', new ext_goto($item['falsegoto']));
                }
            }
            break;
    }
}
 /**
  * @verb GET
  * @returns - a list of timeconditions settings
  * @uri /timeconditions
  */
 function get_timeconditions($params)
 {
     $timeconditions = timeconditions_list();
     return $timeconditions ? $timeconditions : false;
 }
Example #3
0
        redirect_standard();
        break;
    case "delete":
        timeconditions_del($itemid);
        needreload();
        redirect_standard();
        break;
    case "edit":
        //just delete and re-add
        timeconditions_edit($itemid, $_POST);
        needreload();
        redirect_standard('itemid');
        break;
}
//get list of time conditions
$timeconditions = timeconditions_list();
?>

</div> <!-- end content div so we can display rnav properly-->

<!-- right side menu -->
<div class="rnav"><ul>
    <li><a id="<?php 
echo $itemid == '' ? 'current' : '';
?>
" href="config.php?display=<?php 
echo urlencode($dispnum);
?>
"><?php 
echo _("Add Time Condition");
?>
function daynight_checkadd_timecondition()
{
    global $db;
    $sql = "SELECT ext FROM daynight WHERE dmode IN ('timeday', 'timenight') AND dest = 'add'";
    $res = $db->getAll($sql, DB_FETCHMODE_ASSOC);
    if (DB::IsError($res)) {
        return null;
    }
    // If we find anything, then we get the highest timeconditions_id which should be the last one inserted
    //
    if (!empty($res)) {
        $timeconditions_arr = timeconditions_list();
        foreach ($timeconditions_arr as $item) {
            $timeconditions_ids[] = $item['timeconditions_id'];
        }
        rsort($timeconditions_ids);
        $viewing_itemid = $timeconditions_ids[0];
        $sql = "UPDATE `daynight` SET `dest` = '{$viewing_itemid}' WHERE `dest` = 'add'";
        sql($sql);
    }
}
function timeconditions_get_config($engine)
{
    global $ext;
    // is this the best way to pass this?
    global $conferences_conf;
    global $amp_conf;
    global $astman;
    switch ($engine) {
        case "asterisk":
            $DEVSTATE = $amp_conf['AST_FUNC_DEVICE_STATE'];
            $timelist = timeconditions_list(true);
            if (is_array($timelist)) {
                $context = 'timeconditions';
                $fc_context = 'timeconditions-toggles';
                $got_code_autoreset = false;
                $need_maint = false;
                foreach ($timelist as $item) {
                    // add dialplan
                    // note we don't need to add 2nd optional option of true, gotoiftime will convert '|' to ',' for 1.6+
                    $times = timeconditions_timegroups_get_times($item['time'], null, $item['timeconditions_id']);
                    $time_id = $item['timeconditions_id'];
                    $invert_hint = isset($item['invert_hint']) && $item['invert_hint'] == '1' ? true : false;
                    $fcc_password = isset($item['fcc_password']) ? trim($item['fcc_password']) : '';
                    $ext->add($context, $time_id, '', new ext_set("DB(TC/" . $time_id . "/INUSESTATE)", $invert_hint ? "NOT_INUSE" : "INUSE"));
                    $ext->add($context, $time_id, '', new ext_set("DB(TC/" . $time_id . "/NOT_INUSESTATE)", $invert_hint ? "INUSE" : "NOT_INUSE"));
                    if (is_array($times)) {
                        foreach ($times as $time) {
                            $ext->add($context, $time_id, '', new ext_gotoiftime($time[1], 'truestate'));
                        }
                    }
                    $ext->add($context, $time_id, 'falsestate', new ext_gotoif('$["${DB(TC/' . $time_id . '):0:4}" = "true"]', 'truegoto'));
                    $ext->add($context, $time_id, '', new ext_execif('$["${DB(TC/' . $time_id . ')}" = "false"]', 'Set', "DB(TC/{$time_id})="));
                    $skip_dest = 'falsegoto';
                    //Formerly part of USEDEVSTATE
                    //Modifications by namezero111111 follow (FREEPBX-6415)
                    $ext->add($context, $time_id, $skip_dest, new ext_set("{$DEVSTATE}(Custom:TC{$time_id})", $invert_hint ? "NOT_INUSE" : "INUSE"));
                    //End USEDEVSTATE case
                    //end modifications by namezero111111
                    $ext->add($context, $time_id, '', new ext_execif('$["${DB(TC/' . $time_id . ')}" = "false_sticky"]', 'Set', $DEVSTATE . '(Custom:TCSTICKY${ARG1})=' . ($invert_hint ? "NOT_INUSE" : "INUSE")));
                    $ext->add($context, $time_id, '', new ext_gotoif('$["${TCRETURN}"!="RETURN"]', $item['falsegoto']));
                    $ext->add($context, $time_id, '', new ext_set("TCSTATE", 'false'));
                    $ext->add($context, $time_id, '', new ext_set("TCOVERRIDE", '${IF($["${DB(TC/' . $time_id . '):0:5}" = "false"]?true:false)}'));
                    $ext->add($context, $time_id, '', new ext_return(''));
                    $ext->add($context, $time_id, 'truestate', new ext_gotoif('$["${DB(TC/' . $time_id . '):0:5}" = "false"]', 'falsegoto'));
                    $ext->add($context, $time_id, '', new ext_execif('$["${DB(TC/' . $time_id . ')}" = "true"]', 'Set', "DB(TC/{$time_id})="));
                    $skip_dest = 'truegoto';
                    //Formerly part of USEDEVSTATE
                    //Modifications by namezero111111 follow (FREEPBX-6415)
                    $ext->add($context, $time_id, $skip_dest, new ext_set("{$DEVSTATE}(Custom:TC{$time_id})", $invert_hint ? "INUSE" : "NOT_INUSE"));
                    //End USEDEVSTATE case
                    //end modifications by namezero111111
                    $ext->add($context, $time_id, '', new ext_execif('$["${DB(TC/' . $time_id . ')}" = "true_sticky"]', 'Set', $DEVSTATE . '(Custom:TCSTICKY${ARG1})=' . ($invert_hint ? "NOT_INUSE" : "INUSE")));
                    $ext->add($context, $time_id, '', new ext_gotoif('$["${TCRETURN}"!="RETURN"]', $item['truegoto']));
                    $ext->add($context, $time_id, '', new ext_set("TCSTATE", 'true'));
                    $ext->add($context, $time_id, '', new ext_set("TCOVERRIDE", '${IF($["${DB(TC/' . $time_id . '):0:4}" = "true"]?true:false)}'));
                    $ext->add($context, $time_id, '', new ext_return(''));
                    $fcc = new featurecode('timeconditions', 'toggle-mode-' . $time_id);
                    $c = $fcc->getCodeActive();
                    unset($fcc);
                    if ($c != '') {
                        $got_code_autoreset = true;
                        //Formerly part of USEDEVSTATE
                        $ext->addHint($fc_context, $c, 'Custom:TC' . $time_id);
                        //End USEDEVSTATE
                        //Modifications by namezero111111 follow (FREEPBX-6415)
                        $fcccode_macro_call = !empty($fcc_password) ? ',' . $fcc_password : '';
                        $ext->add($fc_context, $c, '', new ext_macro('user-callerid'));
                        $ext->add($fc_context, $c, '', new ext_macro('toggle-tc', $time_id . $fcccode_macro_call));
                        //end modifications by namezero111111
                        $ext->add($fc_context, $c, '', new ext_hangup());
                        // If using hints then we want to keep the current, if not, then we only need to update if it is
                        // currently overridden
                        //
                        // If there are no times then this is purely manual and does not need to be updated
                        //
                        if ($amp_conf['TCMAINT'] && is_array($times) && count($times)) {
                            $need_maint = true;
                        }
                    }
                }
                $fcc = new featurecode('timeconditions', 'toggle-mode-all');
                $c = $fcc->getCodeActive();
                unset($fcc);
                if ($c) {
                    $ext->add($fc_context, $c, '', new ext_macro('user-callerid'));
                    $ext->add($fc_context, $c, '', new ext_goto($fc_context . ',${EXTEN}*${AMPUSER},1'));
                    //TODO: technically a hint could be here
                }
                if ($got_code_autoreset) {
                    $ext->add($fc_context, 'h', '', new ext_hangup());
                    $ext->addInclude('from-internal-additional', $fc_context);
                    // Add the include from from-internal
                    $m_context = 'macro-toggle-tc';
                    // for i18n playback in multiple languages
                    $ext->add($m_context, 'lang-playback', '', new ext_gosubif('$[${DIALPLAN_EXISTS(' . $m_context . ',${CHANNEL(language)})}]', $m_context . ',${CHANNEL(language)},${ARG1}', $m_context . ',en,${ARG1}'));
                    $ext->add($m_context, 'lang-playback', '', new ext_return());
                    $ext->add($m_context, 's', '', new ext_gotoif('$[${ARG2} > 0]', 'hasauth', 'toggle'));
                    $ext->add($m_context, 's', 'hasauth', new ext_authenticate('${ARG2}'));
                    $ext->add($m_context, 's', 'toggle', new ext_setvar('INDEXES', '${ARG1}'));
                    $ext->add($m_context, 's', '', new ext_setvar('TCRETURN', 'RETURN'));
                    $ext->add($m_context, 's', '', new ext_setvar('TCSTATE', 'false'));
                    $ext->add($m_context, 's', '', new ext_set("TCINUSE", '${DB(TC/${ARG1}/INUSESTATE)}'));
                    $ext->add($m_context, 's', '', new ext_set("TCNOTINUSE", '${DB(TC/${ARG1}/NOT_INUSESTATE)}'));
                    $ext->add($m_context, 's', '', new ext_setvar('LOOPCNT', '${FIELDQTY(INDEXES,&)}'));
                    $ext->add($m_context, 's', '', new ext_setvar('ITER', '1'));
                    $ext->add($m_context, 's', 'begin1', new ext_setvar('INDEX', '${CUT(INDEXES,&,${ITER})}'));
                    $ext->add($m_context, 's', '', new ext_gosub('1', '${INDEX}', $context));
                    $ext->add($m_context, 's', '', new ext_setvar('TCSTATE_${INDEX}', '${TCSTATE}'));
                    $ext->add($m_context, 's', '', new ext_execif('$["${TCOVERRIDE}" = "true"]', 'Set', 'OVERRIDE=true'));
                    $ext->add($m_context, 's', 'end1', new ext_setvar('ITER', '$[${ITER} + 1]'));
                    $ext->add($m_context, 's', '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin1'));
                    $ext->add($m_context, 's', '', new ext_setvar('LOOPCNT', '${FIELDQTY(INDEXES,&)}'));
                    $ext->add($m_context, 's', '', new ext_setvar('ITER', '1'));
                    $ext->add($m_context, 's', 'begin2', new ext_setvar('INDEX', '${CUT(INDEXES,&,${ITER})}'));
                    $ext->add($m_context, 's', '', new ext_set('DB(TC/${INDEX})', '${IF($["${OVERRIDE}" = "true"]?:${IF($["${TCSTATE_${INDEX}}" == "true"]?false:true)})}'));
                    $ext->add($m_context, 's', '', new ext_gosub('1', '${INDEX}', $context));
                    $ext->add($m_context, 's', 'end2', new ext_setvar('ITER', '$[${ITER} + 1]'));
                    $ext->add($m_context, 's', '', new ext_gotoif('$[${ITER} <= ${LOOPCNT}]', 'begin2'));
                    if ($amp_conf['FCBEEPONLY']) {
                        $ext->add($m_context, 's', 'playback', new ext_playback('beep'));
                    } else {
                        $ext->add($m_context, 's', 'playback', new ext_gosub('1', 'lang-playback', $m_context, 'hook_0'));
                    }
                    $lang = 'en';
                    //English
                    $ext->add($m_context, $lang, 'hook_0', new ext_playback('beep&silence/1&time&${IF($["${TCSTATE}" = "true"]?de-activated:activated)}'));
                    $lang = 'ja';
                    //Japanese
                    $ext->add($m_context, $lang, 'hook_0', new ext_playback('beep&silence/1&time-change&${IF($["${TCSTATE}" = "true"]?de-activated:activated)}'));
                }
                \FreePBX::Timeconditions()->updateCron();
            }
            break;
    }
}