/** * Get the details of the papers that are currently available for the current user and lab * @param array $paper_display Reference to array in which to build details of available papers * @param array $types Array of paper types to check for * @param UserObject $userObj The current user * @param mysqli $db Database reference * @param string $exclude Option ID of a paper to exclude from the check * @return integer The number of currently active papers */ public function get_active_papers(&$paper_display, $types, $userObj, $db, $exclude = '') { $type_sql = ''; foreach ($types as $type) { if ($type_sql != '') { $type_sql .= ' OR '; } $type_sql .= "paper_type='{$type}'"; } $exclude_sql = ''; if ($exclude != '') { $exclude_sql = ' AND property_id != ' . $exclude; } $paper_no = 0; $paper_query = $db->prepare("SELECT property_id, paper_type, crypt_name, paper_title, bidirectional, fullscreen, MAX(screen) AS max_screen, labs, calendar_year, password, completed FROM (papers, properties) LEFT JOIN log_metadata ON properties.property_id = log_metadata.paperID AND userID = ? WHERE papers.paper = properties.property_id AND (labs != '' OR password != '') AND ({$type_sql}) AND deleted IS NULL AND start_date < DATE_ADD(NOW(),interval 15 minute) AND end_date > NOW() {$exclude_sql} GROUP BY paper"); $paper_query->bind_param('i', $userObj->get_user_ID()); $paper_query->execute(); $paper_query->store_result(); $paper_query->bind_result($property_id, $paper_type, $crypt_name, $paper_title, $bidirectional, $fullscreen, $max_screen, $labs, $calendar_year, $password, $completed); while ($paper_query->fetch()) { if ($labs != '') { $machineOK = false; $labs = str_replace(",", " OR lab=", $labs); $lab_info = $db->query("SELECT address FROM client_identifiers WHERE address = '" . NetworkUtils::get_client_address() . "' AND (lab = {$labs})"); if ($lab_info->num_rows > 0) { $machineOK = true; } $lab_info->close(); } else { $machineOK = true; } if (strpos($userObj->get_username(), 'user') !== 0) { $moduleIDs = Paper_utils::get_modules($property_id, $db); if (count($moduleIDs) > 0) { $moduleOK = false; if ($calendar_year != '') { $cal_sql = "AND calendar_year = '" . $calendar_year . "'"; } else { $cal_sql = ''; } $module_in = implode(',', array_keys($moduleIDs)); $moduleInfo = $db->prepare("SELECT userID FROM modules_student WHERE userID = ? {$cal_sql} AND idMod IN ({$module_in})"); $moduleInfo->bind_param('i', $userObj->get_user_ID()); $moduleInfo->execute(); $moduleInfo->store_result(); $moduleInfo->bind_result($tmp_userID); $moduleInfo->fetch(); if ($moduleInfo->num_rows() > 0) { $moduleOK = true; } $moduleInfo->close(); } else { $moduleOK = true; } } else { $moduleOK = true; } if ($machineOK == true and $moduleOK == true) { $paper_display[$paper_no]['id'] = $property_id; $paper_display[$paper_no]['paper_title'] = $paper_title; $paper_display[$paper_no]['crypt_name'] = $crypt_name; $paper_display[$paper_no]['paper_type'] = $paper_type; $paper_display[$paper_no]['max_screen'] = $max_screen; $paper_display[$paper_no]['bidirectional'] = $bidirectional; $paper_display[$paper_no]['password'] = $password; $paper_display[$paper_no]['completed'] = $completed; $paper_no++; } } $paper_query->close(); return $paper_no; }