function getGlobalDefaults($dbconn) { $defaults = array("ms_tol" => 6, "ms2_tol" => 20, "ms_tol_unit" => "ppm", "ms2_tol_unit" => "ppm", "missed_cleavages" => 4, "notes" => "", "customsettings" => "", "acquisitions" => array(), "sequences" => array()); $getMultiOptions = array("enzyme" => "SELECT id FROM enzyme WHERE is_default = TRUE", "ions" => "SELECT id FROM ion WHERE is_default = TRUE", "crosslinkers" => "SELECT id FROM crosslinker WHERE is_default = TRUE", "losses" => "SELECT id FROM loss WHERE is_default = TRUE", "fixedMods" => "SELECT id FROM modification WHERE is_default_fixed = TRUE", "varMods" => "SELECT id FROM modification WHERE is_default_var = TRUE"); foreach ($getMultiOptions as $key => $value) { pg_prepare($dbconn, $key, $value); $result = pg_execute($dbconn, $key, array()); $defaults[$key] = resultsAsArray($result); } //error_log (print_r($defaults, TRUE)); return $defaults; }
$dbconn = pg_connect($connectionString) or die('Could not connect: ' . pg_last_error()); // Get user rights from database $userRights = getUserRights($dbconn, $_SESSION["user_id"]); $_SESSION["canAddNewSearch"] = $userRights["canAddNewSearch"]; $canSeeAll = $userRights["canSeeAll"]; if (!$userRights["canAddNewSearch"]) { ajaxLoginRedirect(); } else { $possibleValues = array(); $getFieldValues = array("enzymes" => array("q" => "SELECT id, name from enzyme ORDER by name"), "ions" => array("q" => "SELECT id, name from ion ORDER by name"), "xlinkers" => array("q" => "SELECT id, name from crosslinker ORDER by name"), "losses" => array("q" => "SELECT id, name from loss ORDER by name"), "modifications" => array("q" => "SELECT id, name from modification ORDER by name"), "previousAcqui" => $canSeeAll ? array("q" => "SELECT acquisition.id, name AS Name, to_char(upload_date, 'YYYY-MM-DD HH24:MI') AS Date, users.user_name AS User FROM acquisition JOIN users ON (acquisition.uploadedby = users.id) ORDER BY acquisition.id DESC") : array("q" => "SELECT acquisition.id, name AS Name, to_char(upload_date, 'YYYY-MM-DD HH24:MI') AS Date, users.user_name AS User FROM acquisition JOIN users ON (users.id = \$1 AND acquisition.uploadedby = users.id) ORDER BY acquisition.id DESC", "params" => [$_SESSION["user_id"]]), "previousSeq" => $canSeeAll ? array("q" => "SELECT sequence_file.id, name AS Name, to_char(upload_date, 'YYYY-MM-DD HH24:MI') AS Date, users.user_name AS User, file_name as file FROM sequence_file JOIN users ON (sequence_file.uploadedby = users.id) ORDER BY upload_date DESC") : array("q" => "SELECT sequence_file.id, name AS Name, to_char(upload_date, 'YYYY-MM-DD HH24:MI') AS Date, users.user_name AS User, file_name as file FROM sequence_file JOIN users ON (users.id = \$1 AND sequence_file.uploadedby = users.id) ORDER BY upload_date DESC", "params" => [$_SESSION["user_id"]]), "filenames" => array("q" => "SELECT acq_id, name FROM run ORDER by acq_id DESC")); foreach ($getFieldValues as $key => $value) { $query = $value["q"]; $params = isset($value["params"]) ? $value["params"] : array(); pg_prepare($dbconn, $key, $query); $result = pg_execute($dbconn, $key, $params); $possibleValues[$key] = resultsAsArray($result); } // Get basedir for file uploads $query = "SELECT setting FROM base_setting WHERE name='base_directory_path';"; $baseDir = pg_fetch_row(pg_query($query))[0]; // Store this server side 'cos we don't need it client side $_SESSION["baseDir"] = $baseDir; echo json_encode($possibleValues); } //close connection pg_close($dbconn); } catch (Exception $e) { $date = date("d-M-Y H:i:s"); echo json_encode(array("error" => "Error when querying database for default values<br>" . $date)); } }
$previousSeq = resultsAsArray($res); // Get crosslinkers from DB $res = $conn->query("SELECT id, name, is_default from crosslinker WHERE name NOT LIKE '#%' ORDER by name;"); $xlinkers = resultsAsArray($res); // Get enzymes from DB $res = $conn->query("SELECT id, name, is_default from enzyme ORDER by name;"); $enzymes = resultsAsArray($res); // Get modifications from DB $res = $conn->query("SELECT id, name, is_default_fixed, is_default_var from modification WHERE name NOT LIKE '#%' ORDER by name;"); $mods = resultsAsArray($res); // Get ions from DB $res = $conn->query("SELECT id, name, is_default from ion WHERE name NOT LIKE '#%' ORDER by name;"); $ions = resultsAsArray($res); // Get losses from DB $res = $conn->query("SELECT id, name, is_default from loss WHERE name NOT LIKE '#%' ORDER by name;"); $losses = resultsAsArray($res); // Get basedir for file uploads $res = $conn->query("SELECT setting FROM base_setting WHERE name='base_directory_path';"); $baseDir = $res->fetch(PDO::FETCH_BOTH)[0]; // Store this server side 'cos we don't need it client side $_SESSION["baseDir"] = $baseDir; $conn = null; echo json_encode(array("xlinkers" => $xlinkers, "enzymes" => $enzymes, "previousAcqui" => $previousAcqui, "previousSeq" => $previousSeq, "ions" => $ions, "modifications" => $mods, "losses" => $losses)); } catch (Exception $e) { echo json_encode(array("error" => $e->getMessage())); } // Printing results in HTML, assuming id and name field in result set function resultsAsArray($result) { //echo "<p>".$result."</p>"; $arr = array();