If you are not redirected, click here to access the PDSP IMS site.
// so this populates drop downs.
// it will essentially query table $tableName
// select $ddValueField, $ddEntryField from $tableName
// $ddEntryField is what shows up in the drop down, the value for those
// entries will be specified by $ddValueField.
function populateDropDown($tableName, $ddEntryField, $ddValueField) {
printBasicDropDown($tableName, $ddEntryField, $ddValueField, NULL);
}
function populateDropDownLimit($tableName, $ddEntryField, $ddValueField, $limit) {
printBasicDropDown($tableName, $ddEntryField, $ddValueField, $limit);
}
function printBasicDropDown($tableName, $ddEntryField, $ddValueField, $limit) {
$query = "select ".$ddValueField.", ".$ddEntryField." from ".$tableName;
$queryError = "Unable to query table: ".$tableName." with query: ";
global $link;
$queryResult = mysqli_query($link,$query) or die($queryError.$query);
print("");
if (mysqli_num_rows($queryResult) != 0) {
while ($row = mysqli_fetch_row($queryResult)) {
// maybe check to see if the value is null, if so, don't include it?
$ddOption = $row[1];
if ($limit != NULL) $ddOption = substr($ddOption, 0, $limit);
print("");
}
}
else {
print("");
}
mysqli_free_result($queryResult);
}
function populateDropDownOrderBy($tableName, $ddEntryField, $ddValueField, $orderByField) {
$query = "select ".$ddValueField.", ".$ddEntryField." from ".$tableName;
$query.= " order by ".$orderByField;
$queryError = "Unable to query table: ".$tableName." with query: ";
global $link;
$queryResult = mysqli_query($link,$query) or die($queryError.$query);
if (mysqli_num_rows($queryResult) != 0) {
while ($row = mysqli_fetch_row($queryResult)) {
// maybe check to see if the value is null, if so, don't include it?
print("");
}
}
else {
print("");
}
mysqli_free_result($queryResult);
}
// all these functions are very similar, and if php supported overloading methods
// we'd be in business. Unfortunately, you can't do that, so we have all these
// crazy names.
function populateDropDownSelOrderBy($tableName, $ddEntryField, $ddValueField,
$orderByField, $sel) {
$query = getBaseQuery($ddValueField, $ddEntryField, $tableName)." order by ".$orderByField;
$queryError = "Unable to query table: ".$tableName." with query: ";
doQuery($query, $queryError, $sel, NULL);
}
function populateDropDownSelLimitOrderBy($tableName, $ddEntryField, $ddValueField,
$orderByField, $sel, $maxLength) {
$query = getBaseQuery($ddValueField, $ddEntryField, $tableName)." order by ".$orderByField;
$queryError = "Unable to query table: ".$tableName." with query: ";
//print("Limiting the length! ");
doQuery($query, $queryError, $sel, $maxLength);
}
// so this one uses a lookup table to figure out what to populate the drop down with
// it also orders by, and you can select a value as well, so this is like everything
// else we've been using, in addition to using role specific population...joy
function populateRoleDropDownSelOrderBy($ddTableName, $lookupTableName, $roleIDColName, $roleID,
$ddIDColName, $ddNameColName, $orderByField, $sel) {
$query = "select distinct ".$ddTableName.".".$ddIDColName.", ";
$query.= $ddNameColName." from ".$ddTableName;
$query.= ", ".$lookupTableName." where ";
$query.= $ddTableName.".".$ddIDColName." = ".$lookupTableName.".".$ddIDColName;
// so if the sel field is NULL, ignore it
if ($sel == NULL) {
$query.= " and ".$roleIDColName." = ".$roleID." order by ".$orderByField;
}
else {
$query.= " and (".$roleIDColName." = ".$roleID." or ".$ddTableName.".".$ddIDColName;
$query.= " = ".$sel.") order by ".$orderByField;
}
$queryError = "Unable to populate status drop down! ";
doQuery($query, $queryError, $sel, NULL);
}
// anyway, this stuff down here is common to them all
function getBaseQuery($ddValueField, $ddEntryField, $tableName) {
return "select ".$ddValueField.", ".$ddEntryField." from ".$tableName;
}
// you specify with the id, not with the name
// so make sure that $ddValueField is the field you are looking for
function doQuery($query, $queryError, $specify, $maxLength) {
global $link;
$queryResult = mysqli_query($link,$query) or die($queryError.$query);
if (mysqli_num_rows($queryResult) != 0) {
if ($maxLength != NULL) {
// so here we have to trim the value down to maxLength
//$ddOption = substr($ddOption, 0, $maxLength);
}
if ($specify != NULL) {
while ($row = mysqli_fetch_row($queryResult)) {
print("");
//}
//print(">");
if (strlen($row[1]) > $maxLength) {
$newString = substr($row[1], 0, $maxLength);
print($newString."...");
}
else {
print($row[1]);
}
//print("\n");
//print($row[1]);
}
else print($row[1]);
print("");
}
}
else {
while ($row = mysqli_fetch_row($queryResult)) {
// maybe check to see if the value is null, if so, don't include it?
print("");
}
}
}
else {
print("");
}
mysqli_free_result($queryResult);
}
?>
// base class for project logging
// this is fairly general, as long as we follow the project
// structure in the database...
// For now we probably only want to log receptor searches, maybe later
// we'll need track other things
// so we'll need to think about where and when this file is called
// the search page when the user selects a receptor is probably the best place,
class projectLog {
var $thisUserIP;
var $LOG_TABLE_NAME; // constant for the log table name
function projectLog( $userIP) {
$this->thisUserIP = $userIP;
$this->LOG_TABLE_NAME = "pdspTEMP.projectLog";
}
// this is the only method that actually accesses the
// database
function logAccess($recID, $desc) {
$query = "insert into ".$this->LOG_TABLE_NAME. " (";
$query.= "userIPAddress, recID, accessDesc, ";
$query.= "accessDateTime) values ('";
$query.= $this->thisUserIP."',".$recID.", '".$desc."', now())";
global $link;
mysqli_query($link,$query) or die ("Unable to log access! Error: ".mysqli_error($link)." Query: ".$query." ");
// otherwise, we're good to go :)
}
}
?>