sprintf(__("Time Condition: %s"),$thisexten['displayname']),
'edit_url' => 'config.php?display=timeconditions&itemid='.urlencode($exten),
);
}
} else {
return false;
}
}
// returns a associative arrays with keys 'destination' and 'description'
function timeconditions_destinations() {
//get the list of timeconditions
$results = timeconditions_list(true);
// return an associative array with destination and description
if (isset($results)) {
foreach($results as $result){
$extens[] = array('destination' => 'timeconditions,'.$result['timeconditions_id'].',1', 'description' => $result['displayname']);
}
return $extens;
} else {
return null;
}
}
/*
Generates dialplan for time conditions
We call this with retrieve_conf
*/
function timeconditions_get_config($engine) {
global $ext; // is this the best way to pass this?
global $conferences_conf;
global $amp_conf;
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;
$interval = isset($amp_conf['TCINTERVAL']) && ctype_digit($amp_conf['TCINTERVAL']) ? $amp_conf['TCINTERVAL'] : '60';
if ($amp_conf['TCMAINT']) {
$maint_context = 'tc-maint';
$ext->add($maint_context, 's', '', new ext_nocdr(''));
$ext->add($maint_context, 's', '', new ext_set("TCMAINT",'RETURN'));
}
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']);
$time_id = $item['timeconditions_id'];
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';
if ($amp_conf['USEDEVSTATE']) {
$ext->add($context, $time_id, $skip_dest, new ext_set("$DEVSTATE(Custom:TC$time_id)",'INUSE'));
$ext->add($context, $time_id, '', new ext_execif('$["${DB(TC/'.$time_id.')}" = "false_sticky"]','Set',$DEVSTATE.'(Custom:TCSTICKY${ARG1})=INUSE'));
$skip_dest = '';
}
$ext->add($context, $time_id, $skip_dest, new ext_gotoif('$["${TCMAINT}"!="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';
if ($amp_conf['USEDEVSTATE']) {
$ext->add($context, $time_id, $skip_dest, new ext_set("$DEVSTATE(Custom:TC$time_id)",'NOT_INUSE'));
$ext->add($context, $time_id, '', new ext_execif('$["${DB(TC/'.$time_id.')}" = "true_sticky"]','Set',$DEVSTATE.'(Custom:TCSTICKY${ARG1})=INUSE'));
$skip_dest = '';
}
$ext->add($context, $time_id, $skip_dest, new ext_gotoif('$["${TCMAINT}"!="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;
if ($amp_conf['USEDEVSTATE']) {
$ext->addHint($fc_context, $c, 'Custom:TC'.$time_id);
}
$ext->add($fc_context, $c, '', new ext_macro('user-callerid'));
$ext->add($fc_context, $c, '', new ext_macro('toggle-tc', $time_id));
$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;
if ($amp_conf['USEDEVSTATE']) {
$ext->add($maint_context, 's', '', new ext_gosub('1', $time_id, $context));
} else {
$ext->add($maint_context, 's', '', new ext_gosubif('$["${DB(TC/'.$time_id.')}" != ""]',"$context,$time_id,1"));
}
}
}
}
$fcc = new featurecode('timeconditions', 'toggle-mode-all');
$c = $fcc->getCodeActive();
unset($fcc);
if ($c) {
$ext->add($fc_context, $c, '', new ext_goto($fc_context.',${EXTEN}*${AMPUSER},1'));
$userFCs = array();
/*
if ($bmo && $bmo->Cos && $bmo->Cos->isLicensed()) {
$cos = $bmo->Cos;
} else if (function_exists('cos_islicenced') && cos_islicenced()) {
$cos = Cos::create();
}
if ($cos) {
$allCos = $cos->getAllCos();
foreach ($allCos as $cos_name) {
$all = $cos->getAll($cos_name);
foreach ($all['members'] as $key => $val) {
$userFCs[$key] = array_merge(($userFCs[$key] ? $userFCs[$key] : array()), $all['fcallow']);
}
}
}
*/
$users = core_users_list();
foreach ($users as $user) {
$exten = $user[0];
$indexes = '';
$hint = '';
foreach ($timelist as $item) {
$time_id = $item['timeconditions_id'];
if (count($userFCs) > 1 && (!isset($userFCs[$exten]) || !isset($userFCs[$exten]['toggle-mode-' . $time_id]))) {
continue;
}
$indexes.= '&' . $time_id;
$hint.= '&Custom:TC' . $time_id;
}
$indexes = ltrim($indexes, '&');
$hint = ltrim($hint, '&');
if ($amp_conf['USEDEVSTATE']) {
$ext->addHint($fc_context, $c . '*' . $exten, $hint);
}
if (strlen($indexes) == 0) {
$ext->add($fc_context, $c . '*' . $exten, '', new ext_hangup(''));
continue;
}
$ext->add($fc_context, $c . '*' . $exten, '', new ext_macro('toggle-tc', $indexes));
}
}
if ($amp_conf['TCMAINT']) {
// If we didn't have any maintenance to do, then don't reschedule the call file
//
if ($need_maint) {
$ext->add($maint_context, 's', '', new ext_system($amp_conf['ASTVARLIBDIR']."/bin/schedtc.php $interval ".$amp_conf['ASTSPOOLDIR'].'/outgoing ${CALLERID(number)}'));
}
$ext->add($maint_context, 's', '', new ext_answer());
$ext->add($maint_context, 's', '', new ext_hangup());
}
if ($got_code_autoreset) {
$ext->add($fc_context, 'h', '', new ext_hangup());
$ext->addInclude('from-internal-additional', $fc_context, _dgettext('timeconditions','Time Conditions')); // Add the include from from-internal
$m_context = 'macro-toggle-tc';
$ext->add($m_context, 's', '', new ext_setvar('INDEXES', '${ARG1}'));
$ext->add($m_context, 's', '', new ext_setvar('TCMAINT','RETURN'));
$ext->add($m_context, 's', '', new ext_setvar('TCSTATE', 'false'));
$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['TCMAINT']) {
$ext->add($m_context, 's', '', new ext_gotoif('$["${STAT(e,'.$amp_conf['ASTSPOOLDIR'].'/outgoing/schedtc.0.call)}"="1" | "${STAT(e,'.$amp_conf['ASTSPOOLDIR'].'/outgoing/schedtc.1.call)}"="1"]','playback'));
$ext->add($m_context, 's', '', new ext_system($amp_conf['ASTVARLIBDIR']."/bin/schedtc.php $interval ".$amp_conf['ASTSPOOLDIR'].'/outgoing 0'));
}
if ($amp_conf['FCBEEPONLY']) {
$ext->add($m_context, 's', 'playback', new ext_playback('beep'));
} else {
$ext->add($m_context, 's', 'playback', new ext_playback('beep&silence/1&time&${IF($["${TCSTATE}" = "true"]?de-activated:activated)}'));
}
}
if ($need_maint) {
/*
Now we have to make sure there is an active call file and if not kick one off.
Enabling the feature code will also do this, but this makes sure that if you
are using hints, that the hints are kept up. (Thus if not using hints, this is not
run until a feature code requires it).
If need_maint is false, then we don't have any updating to do so don't start
*/
if ($amp_conf['USEDEVSTATE'] && $amp_conf['TCMAINT']) {
$cf_0 = $amp_conf['ASTSPOOLDIR'].'/outgoing/schedtc.0.call';
$cf_1 = $amp_conf['ASTSPOOLDIR'].'/outgoing/schedtc.1.call';
if (!file_exists($cf_0) && !file_exists($cf_1)) {
exec($amp_conf['ASTVARLIBDIR'] . '/bin/schedtc.php 60 ' . $amp_conf['ASTSPOOLDIR'] . '/outgoing 0',$output,$ret_code);
if ($ret_code != 0) {
error(__("Unable to initiate Time Conditions call file with schedtc.php: $ret_code"));
}
}
}
}
}
break;
}
}
function timeconditions_check_destinations($dest=true) {
global $active_modules;
$destlist = array();
if (is_array($dest) && empty($dest)) {
return $destlist;
}
$sql = "SELECT timeconditions_id, displayname, truegoto, falsegoto FROM timeconditions ";
if ($dest !== true) {
$sql .= "WHERE (truegoto in ('".implode("','",$dest)."') ) OR (falsegoto in ('".implode("','",$dest)."') )";
}
$results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
$type = isset($active_modules['timeconditions']['type'])?$active_modules['timeconditions']['type']:'setup';
foreach ($results as $result) {
$thisdest = $result['truegoto'];
$thisid = $result['timeconditions_id'];
$description = sprintf(__("Time Condition: %s"),$result['displayname']);
$thisurl = 'config.php?display=timeconditions&itemid='.urlencode($thisid);
if ($dest === true || $dest[0] == $thisdest) {
$destlist[] = array(
'dest' => $thisdest,
'description' => $description . '('.__('true goto').')',
'edit_url' => $thisurl,
);
}
$thisdest = $result['falsegoto'];
if ($dest === true || $dest[0] == $thisdest) {
$destlist[] = array(
'dest' => $thisdest,
'description' => $description . '('.__('false goto').')',
'edit_url' => $thisurl,
);
}
}
return $destlist;
}
function timeconditions_change_destination($old_dest, $new_dest) {
$sql = 'UPDATE timeconditions SET truegoto = "' . $new_dest . '" WHERE truegoto = "' . $old_dest . '"';
sql($sql, "query");
$sql = 'UPDATE timeconditions SET falsegoto = "' . $new_dest . '" WHERE falsegoto = "' . $old_dest . '"';
sql($sql, "query");
}
function timeconditions_list($getall=false) {
$results = sql("SELECT * FROM timeconditions ORDER BY priority ASC","getAll",DB_FETCHMODE_ASSOC);
if(is_array($results)){
foreach($results as $result){
// check to see if we have a dept match for the current AMP User.
if ($getall || checkDept($result['deptname'])){
// return this item's dialplan destination, and the description
$allowed[] = $result;
}
}
}
if (isset($allowed)) {
return $allowed;
} else {
return null;
}
}
function timeconditions_get($id){
global $astman;
//get all the variables for the timecondition
$results = sql("SELECT * FROM timeconditions WHERE timeconditions_id = '$id'","getRow",DB_FETCHMODE_ASSOC);
$fcc = new featurecode('timeconditions', 'toggle-mode-'.$id);
$c = $fcc->getCodeActive();
$results['tcval'] = $fcc->getCode();
unset($fcc);
if ($c == '') {
$results['tcstate'] = false;
$results['tccode'] = false;
} else {
$results['tccode'] = $c;
if ($astman != null) {
$results['tcstate'] = timeconditions_get_state($id);
} else {
die_issabelpbx("No manager connection, can't get Time Condition State");
}
}
return $results;
}
function timeconditions_del($id){
global $astman,$amp_conf;
// remove all feature codes from the one deleted and anything above
$results = sql("SELECT timeconditions_id FROM timeconditions WHERE timeconditions_id>=\"$id\"","getAll",DB_FETCHMODE_ASSOC);
if(is_array($results)){
foreach($results as $result){
$subid = $result['timeconditions_id'];
$fcc = new featurecode('timeconditions', 'toggle-mode-'.$subid);
$fcc->delete();
unset($fcc);
if ($astman != null) {
$astman->database_del("TC",$subid);
}
}
}
// remove actual db entry
$results = sql("DELETE FROM timeconditions WHERE timeconditions_id = \"$id\"","query");
// reindex after deletion on DB entry
$results = sql("UPDATE timeconditions SET timeconditions_id=timeconditions_id-1 WHERE timeconditions_id>\"$id\"","query");
// recreate feature codes
$autoincrement=1;
$results = sql("SELECT timeconditions_id,displayname FROM timeconditions","getAll",DB_FETCHMODE_ASSOC);
if(is_array($results)){
foreach($results as $result){
$autoincrement++;
$id = $result['timeconditions_id'];
$name = $result['displayname'];
$fcc = new featurecode('timeconditions', 'toggle-mode-'.$id);
$fcc->delete();
unset($fcc);
if ($astman != null) {
$astman->database_del("TC",$id);
}
timeconditions_create_fc($id, $name);
}
}
// set autoincrement
if(preg_match("/qlite/",$amp_conf["AMPDBENGINE"])) {
$autoincrement--;
$results = sql("UPDATE sqlite_sequence SET seq=$autoincrement WHERE name='timeconditions'");
} else {
$results = sql("ALTER TABLE timeconditions AUTO_INCREMENT=$autoincrement");
}
}
//obsolete handled in timegroups module
function timeconditions_get_time( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish) {
//----- Time Hour Interval proccess ----
//
if ($minute_start == '-') {
$time_minute_start = "*";
} else {
$time_minute_start = sprintf("%02d",$minute_start);
}
if ($minute_finish == '-') {
$time_minute_finish = "*";
} else {
$time_minute_finish = sprintf("%02d",$minute_finish);
}
if ($hour_start == '-') {
$time_hour_start = '*';
} else {
$time_hour_start = sprintf("%02d",$hour_start) . ':' . $time_minute_start;
}
if ($hour_finish == '-') {
$time_hour_finish = '*';
} else {
$time_hour_finish = sprintf("%02d",$hour_finish) . ':' . $time_minute_finish;
}
if ($time_hour_start == $time_hour_finish) {
$time_hour = $time_hour_start;
} else {
$time_hour = $time_hour_start . '-' . $time_hour_finish;
}
//----- Time Week Day Interval proccess -----
//
if ($wday_start == '-') {
$time_wday_start = '*';
} else {
$time_wday_start = $wday_start;
}
if ($wday_finish == '-') {
$time_wday_finish = '*';
} else {
$time_wday_finish = $wday_finish;
}
if ($time_wday_start == $time_wday_finish) {
$time_wday = $time_wday_start;
} else {
$time_wday = $time_wday_start . '-' . $time_wday_finish;
}
//----- Time Month Day Interval proccess -----
//
if ($mday_start == '-') {
$time_mday_start = '*';
} else {
$time_mday_start = $mday_start;
}
if ($mday_finish == '-') {
$time_mday_finish = '*';
} else {
$time_mday_finish = $mday_finish;
}
if ($time_mday_start == $time_mday_finish) {
$time_mday = $time_mday_start;
} else {
$time_mday = $time_mday_start . '-' . $time_mday_finish;
}
//----- Time Month Interval proccess -----
//
if ($month_start == '-') {
$time_month_start = '*';
} else {
$time_month_start = $month_start;
}
if ($month_finish == '-') {
$time_month_finish = '*';
} else {
$time_month_finish = $month_finish;
}
if ($time_month_start == $time_month_finish) {
$time_month = $time_month_start;
} else {
$time_month = $time_month_start . '-' . $time_month_finish;
}
$time = $time_hour . '|' . $time_wday . '|' . $time_mday . '|' . $time_month;
return $time;
}
function timeconditions_get_state($id) {
global $astman;
return $astman->database_get("TC", $id);
}
function timeconditions_set_state($id, $state) {
global $astman;
global $amp_conf;
if ($astman != null) {
switch ($state) {
case 'auto':
case '':
$state = '';
$blf = 'NOT_INUSE';
$sticky = 'NOT_INUSE';
break;
case 'true':
$blf = 'NOT_INUSE';
$sticky = 'NOT_INUSE';
break;
case 'true_sticky':
$blf = 'NOT_INUSE';
$sticky = 'INUSE';
break;
case 'false':
$blf = 'INUSE';
$sticky = 'NOT_INUSE';
break;
case 'false_sticky':
$blf = 'INUSE';
$sticky = 'INUSE';
break;
default:
$state = false;
break;
}
if ($state !== false) {
$astman->database_put("TC", $id, $state);
$DEVSTATE = $amp_conf['AST_FUNC_DEVICE_STATE'];
if ($DEVSTATE) {
$astman->set_global($DEVSTATE . "(Custom:TC" . $id . ")", $blf);
$astman->set_global($DEVSTATE . "(Custom:TCSTICKY" . $id . ")", $sticky);
}
}
} else {
die_issabelpbx("No manager connection, can't update Time Condition State");
}
}
/*
*/
function timeconditions_create_fc($id, $displayname='') {
$fcc = new featurecode('timeconditions', 'toggle-mode-'.$id);
if ($displayname) {
$fcc->setDescription("$id: $displayname");
} else {
$fcc->setDescription($id.__(": Time Condition Override"));
}
$fcc->setDefault('*27'.$id);
$fcc->setProvideDest();
$fcc->update();
unset($fcc);
timeconditions_set_state($id, '');
}
function timeconditions_add($post){
global $db;
global $amp_conf;
$displayname = $db->escapeSimple($post['displayname']);
$time = $db->escapeSimple($post['time']);
$falsegoto = $db->escapeSimple($post[$post['goto1']]);
$truegoto = $db->escapeSimple($post[$post['goto0']]);
$deptname = $db->escapeSimple($post['deptname']);
$generate_hint = '1';
if($displayname == '') {
$displayname = "unnamed";
}
$results = sql("INSERT INTO timeconditions (displayname,time,truegoto,falsegoto,deptname,generate_hint) values (\"$displayname\",\"$time\",\"$truegoto\",\"$falsegoto\",\"$deptname\",\"$generate_hint\")");
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);
}
timeconditions_create_fc($id, $displayname);
return $id;
}
function timeconditions_edit($id,$post){
global $db;
$id = $db->escapeSimple($id);
$displayname = $db->escapeSimple($post['displayname']);
$time = $db->escapeSimple($post['time']);
$falsegoto = $db->escapeSimple($post[$post['goto1']]);
$truegoto = $db->escapeSimple($post[$post['goto0']]);
$deptname = $db->escapeSimple($post['deptname']);
$generate_hint = '1';
if(empty($displayname)) {
$displayname = "unnamed";
}
$results = sql("UPDATE timeconditions SET displayname = \"$displayname\", time = \"$time\", truegoto = \"$truegoto\", falsegoto = \"$falsegoto\", deptname = \"$deptname\", generate_hint = \"$generate_hint\" WHERE timeconditions_id = \"$id\"");
if (isset($post['tcstate_new']) && $post['tcstate_new'] != 'unchanged') {
timeconditions_set_state($id, $post['tcstate_new']);
}
$fcc = new featurecode('timeconditions', 'toggle-mode-'.$id);
if ($displayname) {
$fcc->setDescription("$id: $displayname");
} else {
$fcc->setDescription($id.__(": Time Condition Override"));
}
$fcc->update();
unset($fcc);
}
function timeconditions_timegroups_usage($group_id) {
$results = sql("SELECT timeconditions_id, displayname FROM timeconditions WHERE time = '$group_id'","getAll",DB_FETCHMODE_ASSOC);
if (empty($results)) {
return array();
} else {
foreach ($results as $result) {
$usage_arr[] = array(
"url_query" => "display=timeconditions&extdisplay=".$result['timeconditions_id'],
"description" => $result['displayname'],
);
}
return $usage_arr;
}
}
function timeconditions_timegroups_list_usage($timegroup_id) {
global $active_modules;
$full_usage_arr = array();
foreach(array_keys($active_modules) as $mod) {
$function = $mod."_timegroups_usage";
if (function_exists($function)) {
$timegroup_usage = $function($timegroup_id);
if (!empty($timegroup_usage)) {
$full_usage_arr = array_merge($full_usage_arr, $timegroup_usage);
}
}
}
return $full_usage_arr;
}
/*
The following functions are available to other modules.
function timeconditions_timegroups_add_group($description,$times=null) return the inserted id
expects an array of times, each an associative array
Array ( [0] => Array ( [hour_start] => - [minute_start] => - [hour_finish] => -
[minute_finish] => - [wday_start] => - [wday_finish] => - [mday_start] => -
[mday_finish] => - [month_start] => - [month_finish] => - ) )
function timeconditions_timegroups_add_group_timestrings($description,$times=null) return the inserted id
alternative to above. expects an array of time strings instead of associative array of hours minutes etc.
function timeconditions_timegroups_list_groups()
returns an array of id and descriptions for any time groups defined by the user
the array contains inidces 0 and 1 for the rnav and associative value and text for select boxes
function timeconditions_timegroups_get_times($timegroup)
returns an array of id and time string of the users time selections for the selected timegroup
function timeconditions_timegroups_buildtime( $hour_start, $minute_start, $hour_finish, $minute_finish, $wday_start, $wday_finish, $mday_start, $mday_finish, $month_start, $month_finish)
should never be needed by another module, as this module should be the only place creating the time string, as it returns the string to other modules.
function timeconditions_timegroups_drawtimeselects($name, $time, $displayname)
should never be needed by another module, as this module should be the only place drawing the time selects
*/
//lists any time groups defined by the user
function timeconditions_timegroups_list_groups() {
global $db;
$tmparray = array();
$sql = "SELECT id, description FROM timegroups_groups ORDER BY description";
$results = $db->getAll($sql);
if(DB::IsError($results)) {
$results = null;
}
foreach ($results as $val) {
$tmparray[] = array($val[0], $val[1], "value" => $val[0], "text" => $val[1]);
}
return $tmparray;
}
//---------------------------------------------
//timegroups page helper
//we are using gui styles so there is very little on the page
//the timegroups page is used to create time string
//to be used by other modules for gotoif or includes or IFTIME func
function timeconditions_timegroups_configpageinit($dispnum) {
global $currentcomponent;
switch ($dispnum) {
case 'timegroups':
$currentcomponent->addguifunc('timeconditions_timegroups_configpageload');
$currentcomponent->addprocessfunc('timeconditions_timegroups_configprocess', 5);
break;
}
}
//actually render the timegroups page
function timeconditions_timegroups_configpageload() {
global $currentcomponent;
$helptext = __("Creates a group of different date/times that can be used to match on a specific time condition");
$help = '
?'.$helptext.'
';
$descerr = __("Description must be alpha-numeric, and may not be left blank");
$extdisplay = isset($_REQUEST['extdisplay'])?$_REQUEST['extdisplay']:null;
$action= isset($_REQUEST['action'])?$_REQUEST['action']:null;
if ($action == 'del') {
$currentcomponent->addguielem('_top', new gui_pageheading('title', __("Time Group").": $extdisplay".__(" deleted!"), false), 0);
unset($extdisplay);
}
//need to get page name/type dynamically
$query = ($_SERVER['QUERY_STRING'])?$_SERVER['QUERY_STRING']:'type=setup&display=timegroups&extdisplay='.$extdisplay;
$delURL = $_SERVER['PHP_SELF'].'?'.$query.'&action=del';
$info = '';
if (!$extdisplay) {
$currentcomponent->addguielem('_top', new gui_pageheading('title', __("Add Time Group"), false, $help), 0);
$currentcomponent->addguielem(__("Time Group"), new gui_textbox('description', '', __("Description"), __("This will display as the name of this Time Group."), '!isAlphanumeric() || isWhitespace()', $descerr, false), 3);
} else {
$langparts = preg_split("/_/",$_COOKIE['lang']);
$curlang = strtolower($langparts[0]);
$countries=array();
if(($fp = fopen("countries.csv","r",TRUE)) !== FALSE) {
while (($data = fgetcsv($fp, 1000, ",")) !== FALSE) {
if($data[0]=='Name') { continue; }
$iso = $curlang.".".strtolower($data[1]);
$countries[]=array('value'=>$iso,'text'=>$data[0]);
}
fclose($fp);
}
$savedtimegroup= timeconditions_timegroups_get_group($extdisplay);
$timegroup = $savedtimegroup[0];
$description = $savedtimegroup[1];
$currentcomponent->addguielem('_top', new gui_hidden('extdisplay', $extdisplay));
$currentcomponent->addguielem('_top', new gui_pageheading('title', __("Edit Time Group").": $description", false, $help), 0);
//$tlabel = sprintf(__("Delete Time Group %s"),$extdisplay);
//$label = ' '.$tlabel.'';
//$currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
$usage_list = timeconditions_timegroups_list_usage($extdisplay);
$count = 0;
$alllinks = '';
foreach ($usage_list as $link) {
$label = ''.$link['description'].'';
$timegroup_link = $_SERVER['PHP_SELF'].'?'.$link['url_query'];
$currentcomponent->addguielem(__("Used By"), new gui_link('link'.$count++, $label, $timegroup_link, true, false), 4);
}
$fill = new gui_selectbox('countries', $countries, '', __('Country'), __('Select country to retrieve holiday information.'), false, '', false, 'componentSelectSearch');
$filltext = "
".__('Country')."
".$fill->html_input."
";
$filltext .= '
';
$currentcomponent->addguielem(__('Autofill Holiday'), new guielement('test0', $filltext, ''),3);
$currentcomponent->addguielem(__("Time Group"), new gui_textbox('description', $description, __("Description"), __("This will display as the name of this Time Group."), '', '', false), 4);
$timelist = timeconditions_timegroups_get_times($extdisplay);
foreach ($timelist as $val) {
$timehtml = timeconditions_timegroups_drawtimeselects('times['.$val[0].']',$val[1],$val[2]);
$timehtml = '