示例#1
0
function AJsubmitEditRequest()
{
    global $user;
    $requestid = getContinuationVar('requestid');
    $openend = getContinuationVar('openend');
    $allownousercheck = getContinuationVar('nousercheck');
    $modifystart = getContinuationVar('modifystart');
    $startdays = getContinuationVar('startdays');
    $lengths = getContinuationVar('lengths');
    $maxextend = getContinuationVar('maxextend');
    $allowindefiniteend = getContinuationVar('allowindefiniteend');
    $request = getRequestInfo($requestid, 1);
    if (is_null($request)) {
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        sendJSON(array('status' => 'norequest', 'html' => i('The selected reservation no longer exists.') . '<br><br>', 'cont' => $cont));
        return;
    }
    if ($modifystart) {
        $day = processInputVar('day', ARG_NUMERIC, 0);
        if (!in_array($day, $startdays)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i('Invalid start day submitted'), 'cont' => $cont));
            return;
        }
        $starttime = processInputVar('starttime', ARG_STRING);
        if (!preg_match('/^(([01][0-9])|(2[0-3]))([0-5][0-9])$/', $starttime, $matches)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid start time submitted"), 'cont' => $cont));
            return;
        }
        preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})$/', $day, $tmp);
        $startdt = "{$tmp[1]}-{$tmp[2]}-{$tmp[3]} {$matches[1]}:{$matches[4]}:00";
        $startts = datetimeToUnix($startdt);
    } else {
        $startdt = $request['start'];
        $startts = datetimeToUnix($startdt);
    }
    $endmode = processInputVar('endmode', ARG_STRING);
    if ($endmode == 'length') {
        $length = processInputVar('length', ARG_NUMERIC);
        if (!in_array($length, $lengths)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid duration submitted"), 'cont' => $cont));
            return;
        }
        if ($modifystart) {
            $endts = $startts + $length * 60;
        } else {
            $tmp = datetimeToUnix($request['end']);
            $endts = $tmp + $length * 60;
        }
        $enddt = unixToDatetime($endts);
    } elseif ($endmode == 'ending') {
        $ending = processInputVar('ending', ARG_NUMERIC);
        if (!preg_match('/^([0-9]{4})([0-9]{2})([0-9]{2})(([01][0-9])|(2[0-3]))([0-5][0-9])$/', $ending, $tmp) || !checkdate($tmp[2], $tmp[3], $tmp[1])) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid end date/time submitted"), 'cont' => $cont));
            return;
        }
        $enddt = "{$tmp[1]}-{$tmp[2]}-{$tmp[3]} {$tmp[4]}:{$tmp[7]}:00";
        $endts = datetimeToUnix($enddt);
    } elseif ($allowindefiniteend && $endmode == 'indefinite') {
        $endts = datetimeToUnix('2038-01-01 00:00:00');
        $enddt = unixToDatetime($endts);
    } else {
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        sendJSON(array('status' => 'error', 'errmsg' => i("Invalid data submitted"), 'cont' => $cont));
        return;
    }
    $updategroups = 0;
    $updateservername = 0;
    if ($request['serverrequest']) {
        if ($user['showallgroups']) {
            $groups = getUserGroups(0);
        } else {
            $groups = getUserGroups(0, $user['affiliationid']);
        }
        $admingroupid = processInputVar('admingroupid', ARG_NUMERIC);
        $logingroupid = processInputVar('logingroupid', ARG_NUMERIC);
        if ($admingroupid != 0 && !array_key_exists($admingroupid, $groups) && $admingroupid != $request['admingroupid'] || $logingroupid != 0 && !array_key_exists($logingroupid, $groups) && $logingroupid != $request['logingroupid']) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("Invalid user group submitted"), 'cont' => $cont));
            return;
        }
        $testadmingroupid = $admingroupid;
        if ($admingroupid == 0) {
            $testadmingroupid = '';
        }
        $testlogingroupid = $logingroupid;
        if ($logingroupid == 0) {
            $testlogingroupid = '';
        }
        if ($testadmingroupid != $request['admingroupid'] || $testlogingroupid != $request['logingroupid']) {
            $updategroups = 1;
        }
        $servername = processInputVar('servername', ARG_STRING);
        if (!preg_match('/^([-a-zA-Z0-9\\.\\(\\)_ ]){3,255}$/', $servername)) {
            $cdata = getContinuationVar();
            $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
            sendJSON(array('status' => 'error', 'errmsg' => i("The name can only contain letters, numbers, spaces, dashes(-), and periods(.) and can be from 3 to 255 characters long"), 'cont' => $cont));
            return;
        }
        if ($servername != $request['servername']) {
            $servername = mysql_real_escape_string($servername);
            $updateservername = 1;
        }
    }
    $h = '';
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $endts, $max, $requestid)) {
        if ($max == 0) {
            $m = i("The time you requested overlaps with another reservation you currently have. You are only allowed to have a single reservation at any given time. Please select another time for the reservation.");
            $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        } else {
            $m = sprintf(i("The time you requested overlaps with another reservation you currently have. You are allowed to have %s overlapping reservations at any given time. Please select another time for the reservation."), $max);
            $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        }
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        sendJSON(array('status' => 'error', 'errmsg' => $h, 'cont' => $cont));
        return;
    }
    if ($request['serverrequest'] && (!empty($request['fixedIP']) || !empty($request['fixedMAC']))) {
        $ip = $request['fixedIP'];
        $mac = $request['fixedMAC'];
    } else {
        $ip = '';
        $mac = '';
    }
    $imageid = $request['reservations'][0]['imageid'];
    $images = getImages();
    $revisions = array();
    foreach ($request['reservations'] as $key => $res) {
        $revisions[$res['imageid']][$key] = $res['imagerevisionid'];
    }
    $rc = isAvailable($images, $imageid, $revisions, $startts, $endts, 1, $requestid, 0, 0, 0, $ip, $mac);
    $data = array();
    if ($rc < 1) {
        $cdata = array('now' => 0, 'start' => $startts, 'end' => $endts, 'server' => $allowindefiniteend, 'imageid' => $imageid, 'requestid' => $requestid);
        if (!$modifystart) {
            $cdata['extendonly'] = 1;
        }
        $sugcont = addContinuationsEntry('AJshowRequestSuggestedTimes', $cdata);
        if (array_key_exists('subimages', $images[$imageid]) && count($images[$imageid]['subimages'])) {
            $data['sugcont'] = 'cluster';
        } else {
            $data['sugcont'] = $sugcont;
        }
        addChangeLogEntry($request["logid"], NULL, $enddt, $startdt, NULL, NULL, 0);
    }
    if ($rc == -3) {
        $msgip = '';
        $msgmac = '';
        if (!empty($ip)) {
            $msgip = " ({$ip})";
        }
        if (!empty($mac)) {
            $msgmac = " ({$mac})";
        }
        $h .= sprintf(i("The reserved IP (%s) or MAC address (%s) conflicts with another reservation using the same IP or MAC address. Please select a different time to use the image."), $msgip, $msgmac);
        $h = preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $h);
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
        return;
    } elseif ($rc == -2) {
        $m = i("The time you requested overlaps with a maintenance window. Please select a different time to use the image.");
        $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
        return;
    } elseif ($rc == -1) {
        $m = i("The reservation you are modifying is for an environment limited in the number of concurrent reservations that can be made. The time or duration you have requested overlaps with too many other reservations for the same image. Please select another time or duration for the reservation.");
        $h .= preg_replace("/(.{1,60}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
        return;
    } elseif ($rc > 0) {
        updateRequest($requestid);
        $serversets = array();
        $reqsets = array();
        if ($updategroups && $request['laststateid'] != 24) {
            if ($admingroupid == 0) {
                $admingroupid = 'NULL';
            }
            if ($logingroupid == 0) {
                $logingroupid = 'NULL';
            }
            $serversets[] = "admingroupid = {$admingroupid}";
            $serversets[] = "logingroupid = {$logingroupid}";
            addChangeLogEntryOther($request['logid'], "event:usergroups|admingroupid:{$admingroupid}|logingroupid:{$logingroupid}");
            $reqsets[] = "stateid = 29";
        }
        if ($updateservername) {
            $serversets[] = "name = '{$servername}'";
        }
        if ($allownousercheck) {
            $newnousercheck = processInputVar('newnousercheck', ARG_NUMERIC);
            if (($newnousercheck == 1 || $newnousercheck == 0) && $newnousercheck == $request['checkuser']) {
                $reqsets[] = "checkuser = (1 - checkuser)";
            }
        }
        if (count($serversets)) {
            $sets = implode(',', $serversets);
            $query = "UPDATE serverrequest " . "SET {$sets} " . "WHERE requestid = {$requestid}";
            doQuery($query);
        }
        if (count($reqsets)) {
            $sets = implode(',', $reqsets);
            $query = "UPDATE request " . "SET {$sets} " . "WHERE id = {$requestid}";
            doQuery($query);
        }
        sendJSON(array('status' => 'success'));
        cleanSemaphore();
        return;
    } else {
        $m = i("The time period you have requested is not available. Please select a different time.");
        $h .= preg_replace("/(.{1,55}([ \n]|\$))/", '\\1<br>', $m) . "<br>";
        $cdata = getContinuationVar();
        $cont = addContinuationsEntry('AJsubmitEditRequest', $cdata, SECINDAY, 1, 0);
        $data['status'] = 'conflict';
        $data['errmsg'] = $h;
        $data['cont'] = $cont;
        sendJSON($data);
    }
}
示例#2
0
function submitEditRequest()
{
    global $user, $submitErr, $viewmode, $mode;
    $data = getContinuationVar();
    $request = getRequestInfo($data["requestid"]);
    print "<H2>Modify Reservation</H2>\n";
    $hour = $data["hour"];
    if ($data["hour"] == 12) {
        if ($data["meridian"] == "am") {
            $hour = 0;
        }
    } elseif ($data["meridian"] == "pm") {
        $hour = $data["hour"] + 12;
    }
    $tmp = explode('/', $data["day"]);
    $start = mktime($hour, $data["minute"], "0", $tmp[0], $tmp[1], $tmp[2]);
    if ($data['openend'] && $data['ending'] == 'date') {
        $end = datetimeToUnix($data['enddate']);
    } else {
        if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
            $end = $start + $data["length"] * 60 + 900;
        } else {
            $end = $start + $data["length"] * 60;
        }
    }
    // get semaphore lock
    if (!semLock()) {
        abort(3);
    }
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($start, $end, $max, $data["requestid"])) {
        if ($max == 0) {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are only allowed ";
            print "to have a single reservation at any given time. Please select ";
            print "another time to use the application.</font><br><br>\n";
        } else {
            print "<font color=\"#ff0000\">The time you requested overlaps with ";
            print "another reservation you currently have.  You are allowed ";
            print "to have {$max} overlapping reservations at any given time. ";
            print "Please select another time to use the application.</font><br>";
            print "<br>\n";
        }
        $submitErr = 1;
        editRequest();
        return;
    }
    $rc = isAvailable(getImages(), $data["imageid"], $start, $end, $data["os"], $data["requestid"]);
    if ($rc == -1) {
        print "You have requested an environment that is limited in the number ";
        print "of concurrent reservations that can be made. No further ";
        print "reservations for the environment can be made for the time you ";
        print "have selected. Please select another time to use the ";
        print "environment.<br>";
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), unixToDatetime($start), NULL, NULL, 0);
    } elseif ($rc > 0) {
        updateRequest($data["requestid"]);
        if ($data["started"]) {
            if ($data['openend'] && $data['ending'] == 'date') {
                print "Your request to change the ending of your reservation for <b>";
                print "{$data["prettyimage"]}</b> to {$data['enddate']} ";
                print "has been accepted.<br><br>\n";
            } else {
                $remaining = ($end - time()) / 60;
                print "Your request to extend your reservation for <b>";
                print "{$data["prettyimage"]}</b> by " . prettyLength($data["extend"]);
                print " has been accepted.<br><br>\n";
                print "You now have " . prettyLength($remaining) . " remaining for ";
                print "your reservation<br>\n";
            }
        } else {
            print "Your request to use <b>" . $data["prettyimage"] . "</b> on ";
            if (datetimeToUnix($request["start"]) < datetimeToUnix($request["daterequested"])) {
                print prettyDatetime($request["daterequested"]);
            } else {
                print prettyDatetime($start);
            }
            if ($data['openend'] && $data['ending'] == 'date') {
                print " until " . prettyDatetime($end);
            } else {
                print " for " . prettyLength($data["length"]);
            }
            print " has been accepted.<br>\n";
        }
    } else {
        $cdata = array('imageid' => $data['imageid'], 'length' => $data['length'], 'requestid' => $data['requestid']);
        $cont = addContinuationsEntry('selectTimeTable', $cdata);
        print "The time you have requested is not available. You may ";
        print "<a href=\"" . BASEURL . SCRIPT . "?continuation={$cont}\">";
        print "view a timetable</a> of free and reserved times to find ";
        print "a time that will work for you.<br>\n";
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), unixToDatetime($start), NULL, NULL, 0);
    }
}
示例#3
0
<?php

include '../../settings.php';
include '../../inc/login_functions.php';
include '../../inc/helper.php';
include 'functions.php';
$logedIn = access($mysqli);
if (isset($_GET['request'])) {
    $request = trim(htmlentities($_GET['request'], ENT_QUOTES, "UTF-8"));
    $request = $mysqli->real_escape_string($request);
    $result = updateRequest($mysqli, $request, $_SESSION['userId']);
    $requestData = getRequestData($mysqli, $request, $_SESSION['userId']);
}
/* direkt zum thank You direkten */
if ($result === 1) {
    header("Location: ../Request/thankYou.php");
    exit;
}
$placeholder = "Hi advilist, \nich bin auf der Suche nach einem neuen Multimedia Notebook. Ich würde gerne Blu Rays darauf schauen und das Notebook an meinen Fernseher anschließen können. Außerdem wäre es super, wenn neue PC-Spiele darauf laufen würden... \n\nViele Grüße Martin";
include "../../inc/head.php";
?>

<section id="Content" role="main">
      <div class="container">

          <!-- SECTION EMPHASIS 1 -->
          <!-- FULL WIDTH -->
      </div><!-- !container -->
      <div class="full-width section-emphasis-1 page-header">
          <div class="container">
              <header class="row">
示例#4
0
function XMLRPCsetRequestEnding($requestid, $end)
{
    global $user;
    $requestid = processInputData($requestid, ARG_NUMERIC);
    $userRequests = getUserRequests('all', $user['id']);
    $found = 0;
    foreach ($userRequests as $req) {
        if ($req['id'] == $requestid) {
            $request = getRequestInfo($requestid);
            $found = 1;
            break;
        }
    }
    if (!$found) {
        return array('status' => 'error', 'errorcode' => 1, 'errormsg' => 'unknown requestid');
    }
    // make sure user is a member of the 'Specify End Time' group
    $groupid = getUserGroupID('Specify End Time');
    $members = getUserGroupMembers($groupid);
    if (!$request['serverrequest'] && !array_key_exists($user['id'], $members)) {
        return array('status' => 'error', 'errorcode' => 35, 'errormsg' => "access denied to specify end time");
    }
    $end = processInputData($end, ARG_NUMERIC);
    $maxend = datetimeToUnix("2038-01-01 00:00:00");
    if ($end < 0 || $end > $maxend) {
        return array('status' => 'error', 'errorcode' => 36, 'errormsg' => "received invalid input for end");
    }
    $startts = datetimeToUnix($request['start']);
    if ($end % (15 * 60)) {
        $end = unixFloor15($end) + 15 * 60;
    }
    // check that reservation has started
    if ($startts > time()) {
        return array('status' => 'error', 'errorcode' => 38, 'errormsg' => 'reservation has not started');
    }
    // check for overlap
    $max = getMaxOverlap($user['id']);
    if (checkOverlap($startts, $end, $max, $requestid)) {
        return array('status' => 'error', 'errorcode' => 41, 'errormsg' => 'overlapping reservation restriction', 'maxoverlap' => $max);
    }
    // check for computer being available for extended time?
    $timeToNext = timeToNextReservation($request);
    $movedall = 1;
    if ($timeToNext > -1) {
        $lockedall = 1;
        if (count($request['reservations']) > 1) {
            # get semaphore on each existing node in cluster so that nothing
            # can get moved to the nodes during this process
            $unixend = datetimeToUnix($request['end']);
            $checkend = unixToDatetime($unixend + 900);
            $resources = getUserResources(array("imageAdmin", "imageCheckOut"));
            $tmp = array_keys($resources['image']);
            $semimageid = $tmp[0];
            $semrevid = getProductionRevisionid($semimageid);
            foreach ($request["reservations"] as $res) {
                if (!retryGetSemaphore($semimageid, $semrevid, $res['managementnodeid'], $res['computerid'], $request['start'], $checkend, $requestid)) {
                    $lockedall = 0;
                    break;
                }
            }
        }
        if ($lockedall) {
            foreach ($request["reservations"] as $res) {
                if (!moveReservationsOffComputer($res["computerid"])) {
                    $movedall = 0;
                    break;
                }
            }
        } else {
            cleanSemaphore();
            return array('status' => 'error', 'errorcode' => 42, 'errormsg' => 'cannot extend due to another reservation immediately after this one');
        }
        cleanSemaphore();
    }
    if (!$movedall) {
        $timeToNext = timeToNextReservation($request);
        if ($timeToNext >= 15) {
            $timeToNext -= 15;
        }
        $oldendts = datetimeToUnix($request['end']);
        // reservation immediately after this one, cannot extend
        if ($timeToNext < 15) {
            return array('status' => 'error', 'errorcode' => 42, 'errormsg' => 'cannot extend due to another reservation immediately after this one');
        } elseif (($end - $oldendts) / 60 > $timeToNext) {
            $maxend = $oldendts + $timeToNext * 60;
            return array('status' => 'error', 'errorcode' => 43, 'errormsg' => 'cannot extend by requested amount due to another reservation', 'maxend' => $maxend);
        }
    }
    $rc = isAvailable(getImages(), $request['reservations'][0]["imageid"], $request['reservations'][0]['imagerevisionid'], $startts, $end, 1, $requestid);
    // conflicts with scheduled maintenance
    if ($rc == -2) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 46, 'errormsg' => 'requested time is during a maintenance window');
    } elseif ($rc == -1) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 44, 'errormsg' => 'concurrent license restriction');
    } elseif ($rc == 0) {
        addChangeLogEntry($request["logid"], NULL, unixToDatetime($end), $request['start'], NULL, NULL, 0);
        return array('status' => 'error', 'errorcode' => 45, 'errormsg' => 'cannot extend at this time');
    }
    // success
    updateRequest($requestid);
    cleanSemaphore();
    return array('status' => 'success');
}