function parseInputs($user) { if (isset($_POST['func'])) { $func = $_POST['func']; // getters =============================== if ($func === "getGoals") { echo json_encode(getGoals($user)); } if ($func === "getIndustries") { echo json_encode(getIndustries($user)); } if ($func === "getLocations") { echo json_encode(getLocations($user)); } if ($func === "getPostings") { getPostings($user); } if ($func === "getContacts") { echo json_encode(getContacts($user)); } if ($func === "getSchedules") { echo json_encode(getSchedules($user)); } if ($func === "getCompanies") { echo getCompanies($user); } if ($func === "getBlogId") { echo json_encode(getBlogId($user, $_POST['title'], $_POST['text'])); } if ($func === "getBlog") { echo json_encode(getBlog($user)); } if ($func === "getNotesOnPosting") { $postingId = $_POST['postingId']; echo json_encode(getNotesOnPosting($user, $postingId)); } // inserters =============================== if ($func === "insertGoal") { if (isset($_POST["goal"]) && $_POST["goal"] !== '') { echo json_encode(insertGoal($user, $_POST["goal"])); } } if ($func === "insertIndustry") { if (isset($_POST["industry"]) && $_POST["industry"] !== '') { echo json_encode(insertIndustry($user, $_POST["industry"])); } } if ($func === "insertCompany") { $url = urldecode($_POST["url"]); $companyName = $_POST["company"]; insertCompany($user, $companyName); } if ($func === "insertLocation") { if (isset($_POST["location"]) && $_POST["location"] !== '') { echo json_encode(insertLocation($user, $_POST["location"])); } } if ($func === "insertPosting") { echo json_encode(insertPosting($user)); } if ($func === "insertContact") { // more complex. will be responsible for getting $_POST echo json_encode(insertContact($user)); } if ($func === "insertSchedule") { // more complex. will be responsible for getting $_POST // echo json_encode(insertSchedule($user)); echo insertSchedule($user); } if ($func === "addSchedule") { // more complex. will be responsible for getting $_POST // echo json_encode(insertSchedule($user)); // echo "adding ZSchecdule"; $name = $_POST["name"]; $description = $_POST["description"]; $contact = $_POST["contact"]; $start = $_POST["start"]; $end = $_POST["end"]; // addSchedule($name,$description,$contact,$start,$end) if (addSchedule($name, $description, $contact, $start, $end)) { $scheduleId = getScheduleId($name, $description, $contact, $start, $end); if ($scheduleId > 0) { // echo $scheduleId; // insert schedule id and user id to user_schedule $query = "insert into user_schedule "; $query .= "(user,schedule) "; $query .= "values ( {$user}, "; $query .= "{$scheduleId} ) "; //return $query; echo booleanEcho($query); } else { echo "error getting schedule id."; } } else { echo "error inserting schedule."; } } if ($func === "insertBlog") { echo json_encode(insertBlog($user)); } if ($func === "insertNotesPostingUser") { // insertBlog, then insertNotesPostingUser $noteId = insertBlog($user); // $noteId = $_POST["noteId"]; $postingId = $_POST["postingId"]; echo json_encode(insertNotesPostingUser($noteId, $postingId, $user)); } // removers =============================== if ($func === "removeGoal") { // url is the id for user_goals if (isset($_POST["url"]) && $_POST["url"] !== '') { echo json_encode(removeGoal($user, $_POST["url"])); } } if ($func === "removeIndustry") { // url is the id for user_industries if (isset($_POST["url"]) && $_POST["url"] !== '') { echo json_encode(removeIndustry($user, $_POST["url"])); } } if ($func === "removeLocation") { // url is the id for locations if (isset($_POST["url"]) && $_POST["url"] !== '') { echo json_encode(removeLocation($user, $_POST["url"])); } } if ($func === "removeContact") { // url is the id for user_contacts if (isset($_POST["url"]) && $_POST["url"] !== '') { echo json_encode(removeUserContact($user, $_POST["url"])); } } if ($func === "removePosting") { if (isset($_POST["url"]) && $_POST["url"] !== '') { removePosting($user, $_POST["url"]); } } if ($func === "removeCompany") { $companyId = $_POST["url"]; // companyID is stored here removeCompany($user, $companyId); } if ($func === "removeSchedule") { $scheduleId = $_POST["url"]; // scheduleID is stored here echo json_encode(removeSchedule($user, $scheduleId)); } if ($func === "removeBlog") { $userNoteId = $_POST["url"]; // need to get noteId from userNoteId $noteId = getNoteIdFromUserNoteId($userNoteId); if (removeNoteUser($user, $userNoteId) === true) { if (removeNote($noteId) === true) { echo json_encode(true); } else { echo json_encode("Error removing from notes."); } } else { echo json_encode("Error removing from NoteUser."); } } // updaters =============================== if ($func === "updateGoal") { echo json_encode(updateGoal($user)); } if ($func === "updateIndustry") { echo json_encode(updateIndustry($user)); } if ($func === "updatePosting") { updatePosting($user); // returns on its own } if ($func === "updateContact") { echo json_encode(updateContact($user)); } } }
function validateResourceData() { global $user; $return = array('error' => 0); $return['rscid'] = getContinuationVar('rscid', 0); $return['name'] = processInputVar('name', ARG_STRING); $return['startnum'] = processInputVar('startnum', ARG_NUMERIC); $return['endnum'] = processInputVar('endnum', ARG_NUMERIC); $return['owner'] = processInputVar('owner', ARG_STRING, "{$user['unityid']}@{$user['affiliation']}"); $return['type'] = processInputVar('type', ARG_STRING); $return['IPaddress'] = processInputVar('ipaddress', ARG_STRING); $return['privateIPaddress'] = processInputVar('privateipaddress', ARG_STRING); $return['eth0macaddress'] = processInputVar('privatemac', ARG_STRING); $return['eth1macaddress'] = processInputVar('publicmac', ARG_STRING); $return['startpubipaddress'] = processInputVar('startpubipaddress', ARG_STRING); $return['endpubipaddress'] = processInputVar('endpubipaddress', ARG_STRING); $return['startprivipaddress'] = processInputVar('startprivipaddress', ARG_STRING); $return['endprivipaddress'] = processInputVar('endprivipaddress', ARG_STRING); $return['startmac'] = processInputVar('startmac', ARG_STRING); $return['provisioningid'] = processInputVar('provisioningid', ARG_NUMERIC); $return['stateid'] = processInputVar('stateid', ARG_NUMERIC); $return['notes'] = processInputVar('notes', ARG_STRING); $return['vmprofileid'] = processInputVar('vmprofileid', ARG_NUMERIC); $return['platformid'] = processInputVar('platformid', ARG_NUMERIC); $return['scheduleid'] = processInputVar('scheduleid', ARG_NUMERIC); $return['ram'] = processInputVar('ram', ARG_NUMERIC); $return['cores'] = processInputVar('cores', ARG_NUMERIC); $return['procspeed'] = processInputVar('procspeed', ARG_NUMERIC); $return['network'] = processInputVar('network', ARG_NUMERIC); $return['predictivemoduleid'] = processInputVar('predictivemoduleid', ARG_NUMERIC); $return['natenabled'] = processInputVar('natenabled', ARG_NUMERIC); $return['nathostid'] = processInputVar('nathostid', ARG_NUMERIC); $return['nathostenabled'] = processInputVar('nathostenabled', ARG_NUMERIC); $return['natpublicIPaddress'] = processInputVar('natpublicipaddress', ARG_STRING); $return['natinternalIPaddress'] = processInputVar('natinternalipaddress', ARG_STRING); $return['location'] = processInputVar('location', ARG_STRING); $addmode = processInputVar('addmode', ARG_STRING); if (!is_null($addmode) && $addmode != 'single' && $addmode != 'multiple') { $return['error'] = 1; $return['errormsg'] = "Invalid Add mode submitted"; return $return; } $olddata = getContinuationVar('olddata'); if ($return['rscid'] == 0) { $return['mode'] = 'add'; } else { $return['mode'] = 'edit'; } $errormsg = array(); # hostname $hostreg = '/^[a-zA-Z0-9_][-a-zA-Z0-9_\\.]{1,49}$/'; if ($return['mode'] == 'add' && $addmode == 'multiple') { $hostreg = '/^[a-zA-Z0-9_%][-a-zA-Z0-9_\\.%]{1,49}$/'; } if (!preg_match($hostreg, $return['name'])) { $return['error'] = 1; $errormsg[] = "Hostname can only contain letters, numbers, dashes(-), periods(.), and underscores(_). It can be from 1 to 50 characters long"; } elseif ($this->checkForHostname($return['name'], $return['rscid'])) { $return['error'] = 1; $errormsg[] = "A computer already exists with this hostname."; } # add multiple if ($return['mode'] == 'add' && $addmode == 'multiple') { # startnum/endnum if ($return['startnum'] < 0 || $return['startnum'] > 255) { $return['error'] = 1; $errormsg[] = "Start must be from 0 to 255"; } if ($return['endnum'] < 0 || $return['endnum'] > 255) { $return['error'] = 1; $errormsg[] = "End must be from 0 to 255"; } if ($return['startnum'] >= 0 && $return['startnum'] <= 255 && $return['endnum'] >= 0 && $return['endnum'] <= 255 && $return['startnum'] > $return['endnum']) { $return['error'] = 1; $errormsg[] = "Start must be >= End"; } $checkhosts = array(); for ($i = $return['startnum']; $i <= $return['endnum']; $i++) { $checkhosts[] = str_replace('%', $i, $return['name']); } $allhosts = implode("','", $checkhosts); $query = "SELECT hostname FROM computer " . "WHERE hostname IN ('{$allhosts}') AND " . "deleted = 0"; $qh = doQuery($query); $exists = array(); while ($row = mysql_fetch_assoc($qh)) { $exists[] = $row['hostname']; } if (count($exists)) { $hosts = implode(', ', $exists); $return['error'] = 1; $errormsg[] = "There are already computers with these hostnames: {$hosts}"; } } else { $return['startnum'] = 0; $return['endnum'] = 0; } # owner if (!validateUserid($return['owner'])) { $return['error'] = 1; $errormsg[] = "Submitted owner is not valid"; } # type if (!preg_match('/^(blade|lab|virtualmachine)$/', $return['type'])) { $return['error'] = 1; $errormsg[] = "Submitted type is not valid"; } # edit or add single if ($return['rscid'] || $return['mode'] == 'add' && $addmode == 'single') { # ipaddress if (!validateIPv4addr($return['IPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } # private ipaddress if (strlen($return['privateIPaddress']) && !validateIPv4addr($return['privateIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Private IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } # eth0macaddress if (strlen($return['eth0macaddress'])) { if (!preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["eth0macaddress"])) { $return['error'] = 1; $errormsg[] = "Invalid Private MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif ($this->checkForMACaddress($return['eth0macaddress'], 0, $return['rscid'])) { $return['error'] = 1; $errormsg[] = "There is already a computer with this Private MAC address."; } } # eth1macaddress if (strlen($return['eth1macaddress'])) { if (!preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return["eth1macaddress"])) { $return['error'] = 1; $errormsg[] = "Invalid Public MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif ($this->checkForMACaddress($return['eth1macaddress'], 1, $return['rscid'])) { $return['error'] = 1; $errormsg[] = "There is already a computer with this Public MAC address."; } } } else { $return['IPaddress'] = ''; $return['privateIPaddress'] = ''; $return['eth0macaddress'] = ''; $return['eth1macaddress'] = ''; } # add multiple if ($return['mode'] == 'add' && $addmode == 'multiple') { if (!validateIPv4addr($return['startpubipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Start Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if (!validateIPv4addr($return['endpubipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid End Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if (!validateIPv4addr($return['startprivipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid Start Private IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } if (!validateIPv4addr($return['endprivipaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid End Private IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; } $startpubiplong = ip2long($return['startpubipaddress']); $endpubiplong = ip2long($return['endpubipaddress']); if ($startpubiplong > $endpubiplong) { $return['error'] = 1; $errormsg[] = "Start Public IP Address must be lower or equal to End Public IP Address"; } elseif ($endpubiplong - $startpubiplong != $return['endnum'] - $return['startnum']) { $return['error'] = 1; $errormsg[] = "Public IP Address range does not equal Start/End range"; } $startpriviplong = ip2long($return['startprivipaddress']); $endpriviplong = ip2long($return['endprivipaddress']); if ($startpriviplong > $endpriviplong) { $return['error'] = 1; $errormsg[] = "Start Private IP Address must be lower or equal to End Private IP Address"; } elseif ($endpriviplong - $startpriviplong != $return['endnum'] - $return['startnum']) { $return['error'] = 1; $errormsg[] = "Private IP Address range does not equal Start/End range"; } $return['startpubiplong'] = $startpubiplong; $return['endpubiplong'] = $endpubiplong; $return['startpriviplong'] = $startpriviplong; $return['endpriviplong'] = $endpriviplong; $cnt = $endpubiplong - $startpubiplong + 1; if ($return['startmac'] != '') { if (!preg_match('/^(([A-Fa-f0-9]){2}:){5}([A-Fa-f0-9]){2}$/', $return['startmac'])) { $return['error'] = 1; $errormsg[] = "Invalid Start MAC address. Must be XX:XX:XX:XX:XX:XX " . "with each pair of XX being from 00 to FF (inclusive)"; } elseif ($this->checkMultiAddMacs($return['startmac'], $cnt, $msg, $macs)) { $return['error'] = 1; $errormsg[] = $msg; } $return['macs'] = $macs; } else { $return['macs'] = array(); } } else { $return['startpubipaddress'] = ''; $return['endpubipaddress'] = ''; $return['startprivipaddress'] = ''; $return['endprivipaddress'] = ''; $return['startmac'] = ''; } # provisioningid $provisioning = getProvisioning(); if (!array_key_exists($return['provisioningid'], $provisioning)) { $return['error'] = 1; $errormsg[] = "Invalid Provisioning Engine selected"; } else { $return['provisioning'] = $provisioning[$return['provisioningid']]['name']; } # stateid 2 - available, 10 - maintenance, 20 - vmhostinuse if (!preg_match('/^(2|10|20)$/', $return['stateid']) && ($return['mode'] == 'add' || $return['stateid'] != $olddata['stateid'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for State"; } # validate type/provisioning combinations $provtypes = getProvisioningTypes(); if (($return['mode'] == 'add' || $olddata['provisioningid'] != $return['provisioningid']) && !array_key_exists($return['provisioningid'], $provtypes[$return['type']])) { $return['error'] = 1; $errormsg[] = "Invalid Provisioning Engine selected for computer type"; } # validate type/provisioning/state combinations if ($return['mode'] == 'add' || $olddata['stateid'] != $return['stateid']) { if ($return['type'] == 'lab') { if ($return['stateid'] != 2 && $return['stateid'] != 10) { $return['error'] = 1; $errormsg[] = "Invalid state submitted for computer type Lab"; } } elseif ($return['type'] == 'virtualmachine') { if ($return['stateid'] != 10 && ($return['mode'] == 'add' || !is_numeric($olddata['vmhostid']) || $return['stateid'] != 2)) { $return['error'] = 1; $errormsg[] = "Invalid state submitted for computer type Virtual Machine"; } } elseif ($return['type'] == 'blade') { if ($provisioning[$return['provisioningid']]['name'] == 'none' && $return['stateid'] != 10 && $return['stateid'] != 20) { $return['error'] = 1; $errormsg[] = "Invalid state submitted for computer type Bare Metal"; } } } # notes if ($return['stateid'] == 10) { if (!preg_match('/^([-a-zA-Z0-9_\\. ,#\\(\\)=\\+:;]{0,5000})$/', $return['notes'])) { $return['error'] = 1; $errormsg[] = "Maintenance reason can be up to 5000 characters long and may only<br>contain letters, numbers, spaces and these characters: - , . _ # ( ) = + : ;"; } } else { $return['notes'] = ''; } # vmprofileid $profiles = getVMProfiles(); if ($return['type'] == 'blade' && $return['stateid'] == 20 && !array_key_exists($return['vmprofileid'], $profiles)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for VM Host Profile"; } # platformid $platforms = getPlatforms(); if (!array_key_exists($return['platformid'], $platforms)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Platform"; } # scheduleid $schedules = getSchedules(); if (!array_key_exists($return['scheduleid'], $schedules)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Schedule"; } # ram if ($return['ram'] < 500 || $return['ram'] > 16777215) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for RAM"; } # cores if ($return['cores'] < 1 || $return['cores'] > 255) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for No. Cores"; } # procspeed if ($return['procspeed'] < 500 || $return['procspeed'] > 10000) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Processor Speed"; } # network if (!preg_match('/^(10|100|1000|10000|100000)$/', $return['network'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Network"; } # predictivemoduleid $premodules = getPredictiveModules(); if (!array_key_exists($return['predictivemoduleid'], $premodules)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Predictive Loading Module"; } $naterror = 0; # natenabled if ($return['natenabled'] != 0 && $return['natenabled'] != 1) { $return['error'] = 1; $errormsg[] = "Invalid value for Connect Using NAT"; $naterror = 1; } # nathostid $nathosts = getNAThosts(); if ($return['natenabled'] && $return['nathostid'] == 0 || $return['nathostid'] != 0 && !array_key_exists($return['nathostid'], $nathosts)) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for NAT Host"; $naterror = 1; } # nat change - check for active reservations $vclreloadid = getUserlistID('vclreload@Local'); if ($return['mode'] == 'edit') { if ($olddata['nathostid'] == '') { $olddata['nathostid'] = 0; } if (!$naterror && ($olddata['natenabled'] != $return['natenabled'] || $olddata['nathostid'] != $return['nathostid'])) { $query = "SELECT rq.id " . "FROM request rq, " . "reservation rs " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = {$return['rscid']} AND " . "rq.start <= NOW() AND " . "rq.end > NOW() AND " . "rq.stateid NOT IN (1,5,11,12) AND " . "rq.laststateid NOT IN (1,5,11,12) AND " . "rq.userid != {$vclreloadid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $return['error'] = 1; $errormsg[] = "This computer has an active reservation. NAT settings cannot be changed for computers having<br>active reservations."; } } } $nathosterror = 0; # nathostenabled if ($return['nathostenabled'] != 0 && $return['nathostenabled'] != 1) { $return['error'] = 1; $errormsg[] = "Invalid value for Use as NAT Host"; $nathosterror = 1; } # natpublicIPaddress if ($return['nathostenabled'] && ($return['mode'] == 'edit' || $addmode == 'single')) { if (!validateIPv4addr($return['natpublicIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid NAT Public IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; $nathosterror = 1; } # natinternalIPaddress if (!validateIPv4addr($return['natinternalIPaddress'])) { $return['error'] = 1; $errormsg[] = "Invalid NAT Internal IP address. Must be w.x.y.z with each of " . "w, x, y, and z being between 1 and 255 (inclusive)"; $nathosterror = 1; } } # nat host change - check for active reservations if (!$nathosterror && $return['mode'] == 'edit') { if ($olddata['nathostenabled'] != $return['nathostenabled'] || $olddata['natpublicIPaddress'] != $return['natpublicIPaddress'] || $olddata['natinternalIPaddress'] != $return['natinternalIPaddress']) { $query = "SELECT rq.id " . "FROM request rq, " . "reservation rs, " . "nathostcomputermap nhcm, " . "nathost nh " . "WHERE rs.requestid = rq.id AND " . "rs.computerid = nhcm.computerid AND " . "nhcm.nathostid = nh.id AND " . "nh.resourceid = {$olddata['resourceid']} AND " . "rq.start <= NOW() AND " . "rq.end > NOW() AND " . "rq.stateid NOT IN (1,5,11,12) AND " . "rq.laststateid NOT IN (1,5,11,12) AND " . "rq.userid != {$vclreloadid}"; $qh = doQuery($query); if (mysql_num_rows($qh)) { $return['error'] = 1; $errormsg[] = "This computer is the NAT host for other computers that have active reservations. NAT host<br>settings cannot be changed while providing NAT for active reservations."; } } } # location if (!preg_match('/^([-a-zA-Z0-9_\\. ,@#\\(\\)]{0,255})$/', $return['location'])) { $return['error'] = 1; $errormsg[] = "Invalid value submitted for Location"; } if ($return['mode'] == 'add') { $return['addmode'] = $addmode; } if ($return['error']) { $return['errormsg'] = implode('<br>', $errormsg); } return $return; }
function getTimeSlots($compids, $end = 0, $start = 0) { global $viewmode; if (empty($compids)) { return array(); } $requestid = processInputVar("requestid", ARG_NUMERIC, 0); $platsel = getContinuationVar("platforms"); if (empty($platsel)) { $platsel = processInputVar("platforms", ARG_MULTINUMERIC); } $schsel = getContinuationVar("schedules"); if (empty($schsel)) { $schsel = processInputVar("schedules", ARG_MULTINUMERIC); } # all computations done with unix timestamps if ($end != 0) { $enddate = unixToDatetime($end); } if ($start != 0) { $startdate = unixToDatetime($start); } $computerids = array(); $reservedComputerids = array(); $schedules = getSchedules(); $times = array(); $scheduleids = array(); $compinlist = implode(",", $compids); $query = "SELECT id, scheduleid " . "FROM computer " . "WHERE scheduleid IS NOT NULL AND " . "scheduleid != 0 AND " . "id IN ({$compinlist}) "; if (!empty($schsel) && !empty($platsel)) { $schinlist = implode(',', $schsel); $platinlist = implode(',', $platsel); $query .= "AND scheduleid IN ({$schinlist}) " . "AND platformid IN ({$platinlist})"; } $qh = doQuery($query, 155); while ($row = mysql_fetch_row($qh)) { array_push($computerids, $row[0]); $times[$row[0]] = array(); $scheduleids[$row[0]] = $row[1]; } if ($start != 0 && $end != 0) { $query = "SELECT rs.computerid, " . "rq.start, " . "rq.end + INTERVAL 900 SECOND AS end, " . "rq.id, " . "u.unityid, " . "i.prettyname " . "FROM reservation rs, " . "request rq, " . "user u, " . "image i " . "WHERE (rq.start < '{$enddate}' AND " . "rq.end > '{$startdate}') AND " . "rq.id = rs.requestid AND " . "u.id = rq.userid AND " . "i.id = rs.imageid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY rs.computerid, " . "rq.start"; } else { $query = "SELECT rs.computerid, " . "rq.start, " . "rq.end + INTERVAL 900 SECOND AS end, " . "rq.id, " . "u.unityid, " . "i.prettyname " . "FROM reservation rs, " . "request rq, " . "user u, " . "image i " . "WHERE rq.end > NOW() AND " . "rq.id = rs.requestid AND " . "u.id = rq.userid AND " . "i.id = rs.imageid AND " . "rq.stateid NOT IN (1,5,12) " . "ORDER BY rs.computerid, " . "rq.start"; } $qh = doQuery($query, 156); $id = ""; while ($row = mysql_fetch_row($qh)) { if ($row[3] == $requestid) { continue; } if ($id != $row[0]) { $count = 0; $id = $row[0]; array_push($reservedComputerids, $id); } $times[$id][$count] = array(); $times[$id][$count]["start"] = datetimeToUnix($row[1]); $times[$id][$count]["end"] = datetimeToUnix($row[2]); $times[$id][$count]["requestid"] = $row[3]; $times[$id][$count]["unityid"] = $row[4]; $times[$id][$count++]["prettyimage"] = $row[5]; } # use floor function to get to a 15 min increment for start if ($start != 0) { $start = unixFloor15($start); } else { $start = unixFloor15() + 900; } # last time to look at if ($end != 0) { $endtime = $end; } else { $endtime = $start + DAYSAHEAD * SECINDAY; } $blockData = getBlockTimeData($start, $endtime); $reserveInfo = array(); // 0 = reserved, 1 = available foreach ($computerids as $id) { $reserveInfo[$id] = array(); $first = 1; # loop from $start to $endtime by 15 minute increments for ($current = $start, $count = 0, $max = count($times[$id]); $current < $endtime; $current += 900) { /*print "compid - $id<br>\n"; print "count - $count<br>\n"; print "current - " . unixToDatetime($current) . "<br>\n"; if(array_key_exists($count, $times[$id])) { print "start - " . unixToDatetime($times[$id][$count]["start"]) . "<br>\n"; print "end - " . unixToDatetime($times[$id][$count]["end"]) . "<br>\n"; } print "-----------------------------------------------------<br>\n";*/ $reserveInfo[$id][$current]['blockRequest'] = 0; if (scheduleClosed($id, $current, $schedules[$scheduleids[$id]])) { $reserveInfo[$id][$current]["available"] = 0; $reserveInfo[$id][$current]["scheduleclosed"] = 1; continue; } if ($blockid = isBlockRequestTime($id, $current, $blockData)) { $reserveInfo[$id][$current]['blockRequest'] = 1; $reserveInfo[$id][$current]['blockRequestInfo']['groupid'] = $blockData[$blockid]['groupid']; $reserveInfo[$id][$current]['blockRequestInfo']['imageid'] = $blockData[$blockid]['imageid']; $reserveInfo[$id][$current]['blockRequestInfo']['name'] = $blockData[$blockid]['name']; $reserveInfo[$id][$current]['blockRequestInfo']['image'] = $blockData[$blockid]['image']; } $reserveInfo[$id][$current]["scheduleclosed"] = 0; //if computer not in $reservedComputerids, it is free if (!in_array($id, $reservedComputerids)) { $reserveInfo[$id][$current]["available"] = 1; continue; } //if past an end if ($count != $max && $current >= $times[$id][$count]["end"]) { $count++; } # past the end of all reservations if ($count == $max) { $reserveInfo[$id][$current]["available"] = 1; continue; } //if before any start times if ($count == 0 && $current < $times[$id][0]["start"]) { $reserveInfo[$id][$current]["available"] = 1; continue; } //if between a start and end time if ($current >= $times[$id][$count]["start"] && $current < $times[$id][$count]["end"]) { if ($first) { # set the previous 15 minute block to show as busy to allow for load time $first = 0; $reserveInfo[$id][$current - 900]['blockRequest'] = 0; $reserveInfo[$id][$current - 900]["scheduleclosed"] = 0; $reserveInfo[$id][$current - 900]["available"] = 0; $reserveInfo[$id][$current - 900]["requestid"] = $times[$id][$count]["requestid"]; $reserveInfo[$id][$current - 900]["unityid"] = $times[$id][$count]["unityid"]; $reserveInfo[$id][$current - 900]["prettyimage"] = $times[$id][$count]["prettyimage"]; } $reserveInfo[$id][$current]["available"] = 0; $reserveInfo[$id][$current]["requestid"] = $times[$id][$count]["requestid"]; $reserveInfo[$id][$current]["unityid"] = $times[$id][$count]["unityid"]; $reserveInfo[$id][$current]["prettyimage"] = $times[$id][$count]["prettyimage"]; continue; } //if after previous end but before this start if ($current >= $times[$id][$count - 1]["end"] && $current < $times[$id][$count]["start"]) { $reserveInfo[$id][$current]["available"] = 1; continue; } # shouldn't get here; print debug info if we do if ($viewmode == ADMIN_DEVELOPER) { print "******************************************************<br>\n"; print "current - " . unixToDatetime($current) . "<br>\n"; print "endtime - " . unixToDatetime($endtime) . "<br>\n"; print "count - {$count}<br>\n"; print "max - {$max}<br>\n"; print "start - " . unixToDatetime($times[$id][$count]["start"]) . "<br>\n"; print "end - " . unixToDatetime($times[$id][$count]["end"]) . "<br>\n"; print "------------------------------------------------------<br>\n"; } } } return $reserveInfo; }
function submitScheduleGroups() { $groupinput = processInputVar("schedulegroup", ARG_MULTINUMERIC); $schedules = getSchedules(); # build an array of memberships currently in the db $tmp = getUserResources(array("groupAdmin"), array("administer"), 1); $schedulegroupsIDs = array_keys($tmp["schedule"]); // ids of groups that user can administer $resources = getUserResources(array("scheduleAdmin"), array("administer"), 0, 0); $userScheduleIDs = array_keys($resources["schedule"]); // ids of schedules that user can administer $schedulemembership = getResourceGroupMemberships("schedule"); $baseschedulegroups = $schedulemembership["schedule"]; // all schedule group memberships $schedulegroups = array(); foreach (array_keys($baseschedulegroups) as $scheduleid) { if (in_array($scheduleid, $userScheduleIDs)) { foreach ($baseschedulegroups[$scheduleid] as $grpid) { if (in_array($grpid, $schedulegroupsIDs)) { if (array_key_exists($scheduleid, $schedulegroups)) { array_push($schedulegroups[$scheduleid], $grpid); } else { $schedulegroups[$scheduleid] = array($grpid); } } } } } # build an array of posted in memberships $newmembers = array(); foreach (array_keys($groupinput) as $key) { list($scheduleid, $grpid) = explode(':', $key); if (array_key_exists($scheduleid, $newmembers)) { array_push($newmembers[$scheduleid], $grpid); } else { $newmembers[$scheduleid] = array($grpid); } } $adds = array(); $removes = array(); foreach (array_keys($schedules) as $scheduleid) { $id = $schedules[$scheduleid]["resourceid"]; // if $scheduleids not in $userScheduleIds, don't bother with it if (!in_array($scheduleid, $userScheduleIDs)) { continue; } // if $scheduleid is not in $newmembers or $schedulegroups, do nothing if (!array_key_exists($scheduleid, $newmembers) && !array_key_exists($scheduleid, $schedulegroups)) { continue; } // check that $scheduleid is in $newmembers, if not, remove it from all groups if (!array_key_exists($scheduleid, $newmembers)) { $removes[$id] = $schedulegroups[$scheduleid]; continue; } // check that $scheduleid is in $schedulegroups, if not, add all groups in // $newmembers if (!array_key_exists($scheduleid, $schedulegroups)) { $adds[$id] = $newmembers[$scheduleid]; continue; } // adds are groupids that are in $newmembers, but not in $schedulegroups $adds[$id] = array_diff($newmembers[$scheduleid], $schedulegroups[$scheduleid]); if (count($adds[$id]) == 0) { unset($adds[$id]); } // removes are groupids that are in $schedulegroups, but not in $newmembers $removes[$id] = array_diff($schedulegroups[$scheduleid], $newmembers[$scheduleid]); if (count($removes[$id]) == 0) { unset($removes[$id]); } } foreach (array_keys($adds) as $scheduleid) { foreach ($adds[$scheduleid] as $grpid) { $query = "INSERT INTO resourcegroupmembers " . "(resourceid, resourcegroupid) " . "VALUES ({$scheduleid}, {$grpid})"; doQuery($query, 291); } } foreach (array_keys($removes) as $scheduleid) { foreach ($removes[$scheduleid] as $grpid) { $query = "DELETE FROM resourcegroupmembers " . "WHERE resourceid = {$scheduleid} AND " . "resourcegroupid = {$grpid}"; doQuery($query, 292); } } viewSchedules(); }
function printComputerInfo($ipaddress, $stateid, $owner, $platformid, $scheduleid, $currentimgid, $ram, $numprocs, $procspeed, $network, $hostname, $compid, $type, $provisioningid) { $states = getStates(); $platforms = getPlatforms(); $schedules = getSchedules(); $images = getImages(); $provisioning = getProvisioning(); print "<TABLE>\n"; print " <TR>\n"; print " <TH align=right>Hostname:</TH>\n"; print " <TD>{$hostname}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>IP Address:</TH>\n"; print " <TD>{$ipaddress}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>State:</TH>\n"; print " <TD>" . $states[$stateid] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Owner:</TH>\n"; print " <TD>{$owner}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Platform:</TH>\n"; print " <TD>" . $platforms[$platformid] . "</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Schedule:</TH>\n"; print " <TD>" . $schedules[$scheduleid]["name"] . "</TD>\n"; print " </TR>\n"; if (!empty($currentimgid)) { print " <TR>\n"; print " <TH align=right>Current Image:</TH>\n"; print " <TD>" . $images[$currentimgid]["prettyname"] . "</TD>\n"; print " </TR>\n"; } print " <TR>\n"; print " <TH align=right>RAM (MB):</TH>\n"; print " <TD>{$ram}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>No. Processors:</TH>\n"; print " <TD>{$numprocs}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Processor Speed (MHz):</TH>\n"; print " <TD>{$procspeed}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Network Speed (Mbps):</TH>\n"; print " <TD>{$network}</TD>\n"; print " </TR>\n"; if (!empty($compid)) { print " <TR>\n"; print " <TH align=right>Computer ID:</TH>\n"; print " <TD>{$compid}</TD>\n"; print " </TR>\n"; } print " <TR>\n"; print " <TH align=right>Type:</TH>\n"; print " <TD>{$type}</TD>\n"; print " </TR>\n"; print " <TR>\n"; print " <TH align=right>Provisioning Engine:</TH>\n"; print " <TD>" . $provisioning[$provisioningid]['prettyname'] . "</TD>\n"; print " </TR>\n"; print "</TABLE>\n"; }
function getData($args) { return getSchedules(); }