");
$con = mysqli_connect(
getenv("DB_HOST"),
getenv("DB_USERNAME"),
getenv("DB_PASSWORD"),
getenv("DB_DATABASE"),
getenv("DB_PORT")
);
if (mysqli_connect_errno()) {
error_log(mysqli_connect_error());
die;
}
//used to find if there are any profiles at the path listed.
$param = $path . "%";
$query = mysqli_prepare($con, "SELECT * FROM cms_personnel_ou_pub WHERE link LIKE ?");
$query->bind_param("s", $param);
$query->execute();
$result = $query->get_result();
$row_cnt = mysqli_num_rows($result);
$addsq = '';
if ($additional != '') {
$additions = explode(",", $additional);
foreach ($additions as $uid) {
if (isset($qs) && $qs != '') {
$addsq .= " OR userid = '" . trim($uid) . "'";
} else {
if ($addsq != '') {
$addsq .= " OR";
} else {
$addsq .= "(";
}
$addsq .= " userid = '" . trim($uid) . "'";
}
}
$addsq .= ")";
$addsq .= " and link like '" . $site . "%'";
if ($manual != '') {
$addsq = ' OR ' . $addsq;
}
}
//Alex added to initalize variables
$manualq = '';
$qs = '';
$linkq = '';
if ($manual != '') {
$manualq = " order by FIELD (userid";
$qs = "";
$manual_order = explode(",", $manual);
foreach (array_reverse($manual_order) as $uid) {
if ($uid != '') {
$manualq .= ",'" . trim($uid) . "'";
if ($qs != '') {
$qs .= " OR ";
}
$qs .= "(userid = '" . trim($uid) . "' AND link like '" . $site . "%')";
}
}
$manualq .= ") desc, REPLACE(lastname,\"-\",\"\") asc, firstname asc";
}
if ($path != '' && $row_cnt > 0) {
if ($qs == '' && $addsq == '' && $linkq == '' && $manualq == '') {
$linkq = "link like '" . $path . "%'";
$manualq .= "ORDER BY REPLACE(lastname,\"-\",\"\"), firstname asc";
} else {
$linkq = "OR link like '" . $path . "%'";
}
} else {
if ($qs == '' && $addsq == '' && $linkq == '' && $manualq == '') {
$linkq = "link like '" . $link . "%'";
} else {
$linkq = "";
}
}
if ($manual == '') {
if ($manualq == '') {
$manualq = "order by REPLACE(lastname,\"-\",\"\") asc, firstname asc";
}
}
$query = "Select * from cms_personnel_ou_pub where $qs $addsq $linkq $manualq";
$result = mysqli_query($con, $query);
unset($_GET['ct']);
$md5name = http_build_query($_GET);
// define the path and name of cached file
$cachefile = 'cache/'.urlencode($link).'-'.md5($md5name)."&number=".mysqli_num_rows($result).'.txt';
// define how long we want to keep the file in seconds.
//$cachetime = 7200; //1 hours --- need to fine tune
// Check if the cached file is still fresh. If it is, serve it up and exit.
if (file_exists($cachefile) && time() - $cachetime < filemtime($cachefile) && filesize($cachefile) > 0) {
echo "";
include($cachefile);
mysqli_close($con);
exit;
}
if (mysqli_num_rows($result) > 0) {
ob_start();
if ($displaytype == 'focus') { echo " "; }
if ($displaytype == 'publications') { echo "
"; }
if(strlen($_SERVER['QUERY_STRING']) > 10) {
$fp = fopen($cachefile, 'w');
fwrite($fp, ob_get_contents());
fclose($fp);
}
// finally send browser output
ob_end_flush();
}
mysqli_close($con);
?>
"; }
if ($displaytype == 'publications') { echo "
bind_param("s", $link);
$query->execute();
}
}
if ($displaytype == 'focus') { echo "
