failWithMessage("Something went wrong selecting the worksheet with Version ID ({$vid}) - {$msg}");
}
$queries = array("SELECT V.`Worksheet ID` WID, V.`WName` WName, V.`VName` VName, V.`Author ID` AuthorID, S.`Initials` Author, V.`Date Added` Date, V.`Link` Link FROM TWORKSHEETVERSION V JOIN TSTAFF S ON V.`Author ID` = S.`Staff ID` WHERE V.`Version ID` = {$vid};", "SELECT S.`Stored Question ID` ID, S.`Number` Number, S.`Marks` Marks FROM TSTOREDQUESTIONS S WHERE S.`Version ID` = {$vid} ORDER BY S.`Question Order`;", "SELECT S.`Stored Question ID` ID, T.`Name` Name FROM TSTOREDQUESTIONS S JOIN TQUESTIONTAGS Q ON S.`Stored Question ID` = Q.`Stored Question ID` JOIN TTAGS T ON Q.`Tag ID` = T.`Tag ID` WHERE S.`Version ID` = {$vid} ORDER BY T.`Name`;", "SELECT T.`Name` Name, T.`Tag ID` ID FROM TSTOREDQUESTIONS S JOIN TQUESTIONTAGS Q ON S.`Stored Question ID` = Q.`Stored Question ID` JOIN TTAGS T ON Q.`Tag ID` = T.`Tag ID` GROUP BY T.`Name` ORDER BY COUNT(T.`Name`) DESC, T.`Name`; ", "SELECT S.`Initials` Initials, S.`User ID` ID FROM TSTAFF S ORDER BY S.`Initials`;");
$errors = array("Something went wrong retrieving the worksheet with Version ID ({$vid})", "Something went wrong retrieving questions for the worksheet with Version ID ({$vid})", "Something went wrong retrieving tags for the worksheet with Version ID ({$vid})", "Something went wrong loading all of the tags, please try again.", "Something went wrong loading all of the staff, please try again");
$variables = array("worksheet", "questions", "tags", "alltags", "staff");
for ($i = 0; $i < count($queries); $i++) {
    if (!$stopFlag) {
        $query = $queries[$i];
        $error = $errors[$i];
        $variable = $variables[$i];
        if (isset($query, $variable, $error)) {
            try {
                ${$variable} = db_select_exception($query);
            } catch (Exception $ex) {
                $stopFlag = true;
                failWithMessage($error, $ex);
            }
        } else {
            $stopFlag = true;
        }
    }
}
if (isset($_SESSION['message'])) {
    $Message = $_SESSION['message'];
    $message = $Message->getMessage();
    $type = $Message->getType();
    unset($_SESSION['message']);
}
function failWithMessage($msg, $ex)
{
    $_SESSION['message'] = new Message("ERROR", $msg);
Exemple #2
0
function getPageTestLocations()
{
    global $webPageTestLocations, $webPageTestLocationsAPCKey, $webPageTestLocationsTTL, $webPageTestLocationsById, $webPageTestBase, $webPageTestKey;
    if (is_null($webPageTestKey)) {
        return;
    }
    if (function_exists('apc_cache_info') && apc_cache_info('user', TRUE) && function_exists('apc_fetch')) {
        $apc_webPageTestLocations = apc_fetch($webPageTestLocationsAPCKey);
        if (is_array($apc_webPageTestLocations)) {
            $webPageTestLocations = $apc_webPageTestLocations;
            foreach ($webPageTestLocations as $loc) {
                $webPageTestLocationsById[$loc['id']] = $loc;
            }
        }
    }
    if (count($webPageTestLocations) > 0) {
        return;
    }
    // Getting a list of locations from WebPageTest
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $webPageTestBase . 'getLocations.php?f=xml&k=' . urlencode($webPageTestKey));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch);
    if (empty($output)) {
        $err = curl_error($ch);
        curl_close($ch);
        failWithMessage("API call ({$locationsURL}) failed: " . $err);
    }
    $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($code != 200) {
        curl_close($ch);
        failWithMessage("PageTest didn't accept the request: {$code}");
    }
    curl_close($ch);
    $xml = new SimpleXMLElement($output);
    if (empty($xml)) {
        failWithMessage("Failed to parse XML response");
    }
    if ($xml->statusCode != 200) {
        failWithMessage("PageTest getLocations returned failure status code: " . $xml->statusCode . " (" . $xml->statusText . ")");
    }
    foreach ($xml->data->location as $location) {
        $id = (string) $location->id;
        $loc = array('id' => $id, 'default' => $location->default == 1 ? true : false, 'title' => $location->Label . ' using ' . $location->Browser, 'tests' => (string) $location->PendingTests->Total);
        $webPageTestLocations[] = $loc;
        $webPageTestLocationsById["{$id}"] = $loc;
    }
    if (function_exists('apc_cache_info') && apc_cache_info('user', TRUE) && function_exists('apc_store')) {
        apc_store($webPageTestLocationsAPCKey, $webPageTestLocations, $webPageTestLocationsTTL);
    }
}
Exemple #3
0
             continue;
         }
         $metric = $rule_metric_map[$rule];
         if (!array_key_exists('ruleScore', $data)) {
             error_log('Rule score is not specified: ' . $rule . ' (skipping)');
             continue;
         }
         $value = filter_var($data['ruleScore'], FILTER_VALIDATE_INT);
         if ($value === false) {
             error_log('Rule score is not an integer: ' . $rule . ' = ' . $data['ruleScore'] . ' (skipping)');
             continue;
         }
         $rules[$metric] = $value;
     }
     if (!array_key_exists('version', $response) || !is_array($response['version']) || !array_key_exists('major', $response['version']) || ($major = filter_var($response['version']['major'], FILTER_VALIDATE_INT) === false || !array_key_exists('minor', $response['version']) || ($minor = filter_var($response['version']['minor'], FILTER_VALIDATE_INT) === false))) {
         failWithMessage("Number of resources is not returned");
     }
     $sdk_version = "{$major}.{$minor}";
     $got_data = true;
 } else {
     if (array_key_exists('v', $_GET) && array_key_exists('w', $_GET) && ($core_metrics['w'] = filter_var($_GET['w'], FILTER_VALIDATE_INT)) !== false && array_key_exists('o', $_GET) && ($core_metrics['o'] = filter_var($_GET['o'], FILTER_VALIDATE_FLOAT)) !== false && array_key_exists('l', $_GET) && ($core_metrics['l'] = filter_var($_GET['l'], FILTER_VALIDATE_INT)) !== false && array_key_exists('r', $_GET) && ($core_metrics['r'] = filter_var($_GET['r'], FILTER_VALIDATE_INT)) !== false && array_key_exists('t', $_GET) && ($core_metrics['t'] = filter_var($_GET['t'], FILTER_VALIDATE_INT)) !== false) {
         $sdk_version = $_GET['v'];
         // list of old metric names that should still be suported
         $metric_renames = array('pSpecifyCharsetEarly' => 'pCharsetEarly', 'pProxyCache' => 'pCacheValid', 'pPutCssInTheDocumentHead' => 'pCssInHead', 'pOptimizeTheOrderOfStylesAndScripts' => 'pCssJsOrder', 'pMinimizeRequestSize' => 'pMinReqSize', 'pParallelizeDownloadsAcrossHostnames' => 'pParallelDl', 'pServeStaticContentFromACookielessDomain' => 'pNoCookie', 'pAvoidBadRequests' => 'pBadReqs', 'pLeverageBrowserCaching' => 'pBrowserCache', 'pRemoveQueryStringsFromStaticResources' => 'pRemoveQuery', 'pServeScaledImages' => 'pScaleImgs', 'pSpecifyACacheValidator' => 'pCacheValid', 'pSpecifyAVaryAcceptEncodingHeader' => 'pVaryAE', 'pSpecifyImageDimensions' => 'pImgDims');
         foreach ($metrics as $metric) {
             $param = $metric;
             foreach (array_reverse($metric_renames) as $from => $to) {
                 // if legacy parameter name is sent, use it to get the value
                 if ($metric == $to && !array_key_exists($metric, $_GET) && array_key_exists($from, $_GET)) {
                     $param = $from;
                 }
Exemple #4
0
    $userid = $user->getUserId();
    $userRole = $user->getRole();
} else {
    header($resultArray[1]);
    exit;
}
if (!authoriseUserRoles($userRole, ["SUPER_USER"])) {
    header("Location: unauthorisedAccess.php");
    exit;
}
$query = "SELECT S.`Initials` Initials, S.`User ID` ID FROM TSTAFF S ORDER BY S.`Initials`;";
try {
    $staff = db_select_exception($query);
} catch (Exception $ex) {
    $msg = $ex->getMessage();
    failWithMessage("There was an error loading all of the users.", $msg);
}
if (isset($_SESSION['message'])) {
    $Message = $_SESSION['message'];
    $message = $Message->getMessage();
    $type = $Message->getType();
    unset($_SESSION['message']);
}
function failWithMessage($msg, $error)
{
    $msg = $msg . " Please refresh and try again. If this continues to happen then please contact our support <a href='mailto:contact.smarkbook@gmail.com'>team</a>.";
    $_SESSION['message'] = new Message("ERROR", $msg);
    errorLog($msg . ' - ' . $error);
}
?>
Exemple #5
0
    if ($code != 200) {
        curl_close($ch);
        failWithMessage("PageTest didn't accept the request: {$code}");
    }
    curl_close($ch);
    $xml = new SimpleXMLElement($output);
    if (empty($xml)) {
        failWithMessage("Failed to parse XML response");
    }
    if ($xml->statusCode != 200) {
        failWithMessage("PageTest returned failure status code: " . $xml->statusCode . " (" . $xml->statusText . ")");
    }
    $testId = $xml->data->testId;
    if (!$private || $keepPrivatePageTests) {
        # adding new entry
        $query = sprintf("INSERT INTO pagetest (url_id, test_id, location)\n\t\t\tVALUES ('%d', '%s', '%s')", mysql_real_escape_string($url_id), mysql_real_escape_string($testId), mysql_real_escape_string($location));
        if (!mysql_query($query)) {
            failWithMessage(mysql_error());
        }
        # updating modification date for the URL
        $query = sprintf("UPDATE urls SET last_update = now() WHERE id = %d", mysql_real_escape_string($url_id));
        $result = mysql_query($query);
    }
    $current_user = User::get();
    if (!is_null($current_user)) {
        $current_user->recordActivity(SHOWSLOW_ACTIVITY_PAGETEST_START);
    }
    header('Location: ' . $webPageTestBase . 'result/' . $testId . '/');
    exit;
}
header('Location: ' . $showslow_base);
}
$gwid = $worksheetDetails["gwid"];
//Set up completed worksheets
$notes = $_POST["notes"];
$daysLate = $_POST["dates"];
$cwid = $_POST["ids"];
$completionStatus = $_POST["completion"];
$completedWorksheets = array("notes" => $notes, "dates" => $daysLate, "completion" => $completionStatus, "cwid" => $cwid);
try {
    $postData = array("details" => $worksheetDetails, "newResults" => $newResults, "compWorksheets" => $completedWorksheets, "type" => "UPDATE", "userid" => $userid, "userval" => $userval);
    $data = array("data" => json_encode($postData));
    $resp = sendCURLRequest("/requests/setWorksheetResult.php", $data);
    $respArray = json_decode($resp[1], TRUE);
    if (!$respArray["result"]) {
        //Failure
        failWithMessage($gwid, $respArray["message"]);
    }
} catch (Exception $ex) {
    $message = "There was an error saving the results, please try again.";
    failWithMessageAndException($gwid, $message, $ex);
}
$message = 'Results succesfully updated.';
completeWithMessage($gwid, $message);
function failWithMessage($gwid, $message)
{
    $type = 'ERROR';
    $_SESSION['message'] = new Message($type, $message);
    header("Location: ../editSetResults.php?gwid={$gwid}");
    exit;
}
function failWithMessageAndException($gwid, $message, $ex)