예제 #1
0
<?php

//	License for all code of this FreePBX module can be found in the license file inside the module directory
//	Copyright 2015 Sangoma Technologies.
//
extract($request, EXTR_SKIP);
if ($extdisplay) {
    $savedtimegroup = timeconditions_timegroups_get_group($extdisplay);
    $timegroup = $savedtimegroup[0];
    $description = $savedtimegroup[1];
    $delURL = '?display=timegroups&action=del&extdisplay=' . $extdisplay;
    $timelist = timeconditions_timegroups_get_times($extdisplay);
    $usage = timeconditions_timegroups_list_usage($extdisplay);
}
$timehtml = '';
if (!empty($timelist)) {
    foreach ($timelist as $val) {
        $timehtml .= timeconditions_timegroups_drawtimeselects('times[' . $val[0] . ']', $val[1]);
    }
} else {
    $timehtml = timeconditions_timegroups_drawtimeselects('times[0]', null);
}
if (isset($usage) && !empty($usage)) {
    echo '<script>$(document).ready(function(){$("#delete").attr("disabled",true);});</script>';
    echo '<div class="alert alert-warning">';
    echo '<strong>' . _("This time group is currently in use and cannot be deleted") . '</strong><br/>';
    echo '<table class="table">';
    foreach ($usage as $key => $value) {
        echo '<tr><td><a href="' . $value['url_query'] . '">' . $value['description'] . '</a></td></tr>';
    }
    echo '</table>';
 public function doConfigPageInit($page)
 {
     $request = $_REQUEST;
     switch ($page) {
         case "timeconditions":
             isset($request['action']) ? $action = $request['action'] : ($action = '');
             isset($request['itemid']) ? $itemid = $request['itemid'] : ($itemid = '');
             isset($request['view']) ? $view = $request['view'] : ($view = '');
             $invert_hint = isset($request['invert_hint']) ? $request['invert_hint'] : '0';
             $fcc_password = isset($request['fcc_password']) ? $request['fcc_password'] : '';
             //if submitting form, update database
             switch ($action) {
                 case "add":
                     $itemid = $this->addTimeCondition($request);
                     $_REQUEST['extdisplay'] = $itemid;
                     \needreload();
                     break;
                 case "delete":
                     $this->delTimeCondition($itemid);
                     $_REQUEST['extdisplay'] = NULL;
                     \needreload();
                     break;
                 case "edit":
                     //just delete and re-add
                     $this->editTimeCondition($itemid, $request);
                     \needreload();
                     break;
             }
             break;
         case "timegroups":
             $action = isset($request['action']) ? $request['action'] : null;
             $timegroup = isset($request['extdisplay']) ? $request['extdisplay'] : null;
             $description = isset($request['description']) ? $request['description'] : null;
             $times = isset($request['times']) ? $request['times'] : null;
             switch ($action) {
                 case 'add':
                     $this->addTimeGroup($description, $times);
                     unset($_REQUEST['view']);
                     break;
                 case 'edit':
                     $this->editTimeGroup($timegroup, $description);
                     $this->editTimes($timegroup, $times);
                     unset($_REQUEST['view']);
                     break;
                 case 'del':
                     $usage = timeconditions_timegroups_list_usage($timegroup);
                     if (isset($usage) && sizeof($usage) >= 1) {
                         $this->errormsg = _("Could not delete time group as it is in use");
                         return;
                     }
                     $this->delTimeGroup($timegroup);
                     unset($_REQUEST['view']);
                     break;
                 case 'getJSON':
                     header('Content-Type: application/json');
                     switch ($request['jdata']) {
                         case 'grid':
                             $timegroupslist = timeconditions_timegroups_list_groups();
                             $rdata = array();
                             foreach ($timegroupslist as $tg) {
                                 $rdata[] = array('text' => $tg['text'], 'value' => $tg['value'], 'link' => array($tg['text'], $tg['value']));
                             }
                             echo json_encode($rdata);
                             exit;
                             break;
                         default:
                             echo json_encode(array("error" => "Unknown Request"));
                             exit;
                             break;
                     }
                     break;
             }
             break;
     }
 }
예제 #3
0
function timeconditions_timegroups_configpageload()
{
    global $currentcomponent;
    $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), 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 {
        $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), 0);
        $tlabel = sprintf(_("Delete Time Group %s"), $extdisplay);
        $label = '<span><img width="16" height="16" border="0" title="' . $tlabel . '" alt="" src="images/core_delete.png"/>&nbsp;' . $tlabel . '</span>';
        $currentcomponent->addguielem('_top', new gui_link('del', $label, $delURL, true, false), 0);
        $usage_list = timeconditions_timegroups_list_usage($extdisplay);
        $count = 0;
        foreach ($usage_list as $link) {
            $label = '<span><img width="16" height="16" border="0" title="' . $link['description'] . '" alt="" src="images/time_link.png"/>&nbsp;' . $link['description'] . '</span>';
            $timegroup_link = $_SERVER['PHP_SELF'] . '?' . $link['url_query'];
            $currentcomponent->addguielem(_("Used By"), new gui_link('link' . $count++, $label, $timegroup_link, true, false), 4);
        }
        $currentcomponent->addguielem(_("Time Group"), new gui_textbox('description', $description, _("Description"), _("This will display as the name of this Time Group."), '', '', false), 3);
        $timelist = timeconditions_timegroups_get_times($extdisplay);
        foreach ($timelist as $val) {
            $timehtml = timeconditions_timegroups_drawtimeselects('times[' . $val[0] . ']', $val[1]);
            $timehtml = '<tr><td colspan="2"><table>' . $timehtml . '</table></td></tr>';
            $currentcomponent->addguielem($val[1], new guielement('dest0', $timehtml, ''), 5);
        }
    }
    $timehtml = timeconditions_timegroups_drawtimeselects('times[new]', null);
    $timehtml = '<tr><td colspan="2"><table>' . $timehtml . '</table></td></tr>';
    $currentcomponent->addguielem(_("New Time"), new guielement('dest0', $timehtml, ''), 6);
    $currentcomponent->addguielem('_top', new gui_hidden('action', $extdisplay ? 'edit' : 'add'));
}