/* ------------------------------------------------------------------------ * security.inc * Last Modified: 16-FEB-2001 * ------------------------------------------------------------------------ * Adapted from session_mysql.php: * PHP4 MySQL Session Handler * Version 1.00 * by Ying Zhang (ying@zippydesign.com) */ // SESSION database info $SESS_DBHOST = DATABASE_HOST; // database server hostname $SESS_DBNAME = SESSIONS_DATABASE; // database name $SESS_DBUSER = DATABASE_USERNAME; // database user $SESS_DBPASS = DATABASE_PASSWORD; // database password $SESS_DBH = ""; $SESS_LIFE = get_cfg_var("session.gc_maxlifetime"); function sess_open($save_path, $session_name) { global $SESS_DBHOST, $SESS_DBNAME, $SESS_DBUSER, $SESS_DBPASS, $SESS_DBH; if (! $SESS_DBH = mysql_connect($SESS_DBHOST, $SESS_DBUSER, $SESS_DBPASS)) { echo "
";print_r( $GLOBALS); }
?>
function listing($committee) {
// Pass in $committee first, and $member (optional) second
// Prints the selected committee, passed in as a number, where committees are as follows:
// ( they are in alphabetical order except for the first one, which is the entire SEA Council)
// mysql> select * from committees;
// +--------+--------------------------------+-----------------------+
// | committee_id | committee_name | committee_description |
// +--------+--------------------------------+-----------------------+
// | 1 | SEA Council | NULL |
// | 2 | Communications Subcommittee | NULL |
// | 3 | DC Subcommittee | NULL |
// | 4 | Faculty Relations Subcommittee | NULL |
// | 5 | Maryland Regional Subcommittee | NULL |
// | 6 | Midwest Regional Subcommitte | NULL |
// | 7 | Nominating Committee | NULL |
// | 8 | Southern Regional Subcommittee | NULL |
// | 9 | Student Relations Committee | NULL |
// +--------+--------------------------------+-----------------------+
//
// IMPORTANT:
// $member can be one of
// ('all', 'chair', 'vice_chair', 'secretary', 'treasurer', OR 'regional_liason')
// $output_method can be:
// 0: formatted HTML
// 1: array representing database table structure
$host = DATABASE_HOST;
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
// $member = preg_replace("/_/", " ", $member);
$output_method = 0; // default output
if (func_num_args() == 2) $member = func_get_arg(1);
if (func_num_args() == 3) {
$member = func_get_arg(1);
$output_method = func_get_arg(2);
}
switch ( $member ) {
case "all":
$listing = " and ( cm.standing = '' or cm.standing is null ) ";
$breakem = TRUE;
break;
case "chair":
$listing = " and cs.description = 'Chair' ";
break;
case "vice_chair":
$listing = " and cs.description = 'Vice Chair' ";
break;
case "secretary":
$listing = " and cs.description = 'Secretary' ";
break;
case "treasurer":
$listing = " and cs.description = 'Treasurer' ";
break;
case "regional_liason":
$listing = " and cs.description = 'Regional Liason' ";
break;
default;
$listing = " ";
$breakem = TRUE;
}
switch ($output_method) {
default:
case 0:
$sql = "select * from personal p
LEFT OUTER JOIN committee_memberships cm ON cm.member_id = p.id
LEFT OUTER JOIN committee_standings cs ON cm.standing_id = cs.standing_id
LEFT OUTER JOIN committees c ON c.committee_id = cm.committee_id
LEFT OUTER JOIN years y ON y.member_id = p.id
WHERE cm.committee_id in ('$committee')
$listing
ORDER BY p.lastn";
case 1:
$sql = "select * from personal p
LEFT OUTER JOIN committee_memberships cm ON cm.member_id = p.id
LEFT OUTER JOIN committee_standings cs ON cm.standing_id = cs.standing_id
WHERE cm.committee_id in ('$committee')
$listing
ORDER BY p.lastn";
break;
}
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
$fonto = "";
$fontc = "";
$count = 0;
$last_id = 'START';
// $years = array();
switch ($output_method) {
default:
case 0:
while ($row = mysql_fetch_assoc($result)) {
$row[year] = preg_replace("/^\d\d/", "'", $row[year]);
if ( $count % 2 == 0 and $breakem ) $old_row .= "\n";
$old_row .= "";
if ( $member != 'all' ){
$member = preg_replace("/_/", " ", $member);
$member = ucwords($member);;
$old_row .= "$member
\n";
}
$old_row .= $fonto . $row[firstn] . " " . $row[lastn];
$years[] = $row[year];
if ( $last_id == $row[id] ) {
$years[] = $row[year];
$old_row = "";
} else {
unset ($years);
$out .= $old_row;
$count++;
$old_row = "";
$years[] = $row[year];
}
for ($i = 0; $i < count($years); $i++) {
if ( $years[$i] != $years[$i-1] and $years[$i] != "'00") $old_row .= " " . $years[$i];
}
$old_row .= "
\n";
if ($row[company]) $old_row .= $row[company];
$old_row .= "
\n";
if ($row[city]) $old_row .= $row[city];
if ($row[state]) $old_row .= ", " . $row[state];
$old_row .= "
\n";
if ($row[email]) $old_row .= "" . $row[email] . "$fontc";
$old_row .= "
\n";
$old_row .= " \n";
if ( $count % 2 == 0 and $breakem) $old_row .= " \n";
$last_id = $row[id];
}
$out .= $old_row;
break;
case 1:
if (mysql_num_rows($result) == 0){
$out[] = array("firstn" => "Open", "lastn"=>"");
} else {
while ($row = mysql_fetch_assoc($result)) {
$years_string = "";
$sql = "SELECT * FROM years WHERE member_id = " . $row[id];
$db_link_years = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result_years= mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($year_row = mysql_fetch_assoc($result_years)) {
$years_string .= ($year_row['year'] > 1900)?"'" . substr($year_row['year'], 2) . " ":"";
}
$row['years'] = $years_string;
$out[] = $row;
}
}
break;
}
return $out;
}
function adm_listing($committee) {
// Pass in $committee first, and $member (optional) second
// committees are as listed in "listing()", above
//
// If $committee == 'by_name', then the listing is selected based on the
// first name and last name passed in with $committee
//
// IMPORTANT:
// $member can be one of
// ('all', 'chair', 'vice_chair', 'secretary', 'treasurer', OR 'regional_liason')
//
global $PHP_SELF, $page, $committee_id;
$host = 'data.wse.jhu.edu';
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
// $member = preg_replace("/_/", " ", $member);
if ($committee == 'by_name') {
if (func_num_args() != 3) die("You MUST supply BOTH firstn and lastn args if the first arg is 'by_name'!");
$firstn = func_get_arg(1);
$lastn = func_get_arg(2);
$sql = "select *";
$sql .= "from personal p, years y ";
$sql .= "where y.member_id = p.id ";
if ( $firstn != '') $sql .= " and firstn like '%$firstn%' ";
if ( $lastn != '') $sql .= " and lastn like '%$lastn%' ";
} else {
if (func_num_args() == 2) $member = func_get_arg(1);
switch ( $member ) {
case "chair":
$listing = " and cs.description = 'Chair' ";
break;
case "vice_chair":
$listing = " and cs.description = 'Vice Chair' ";
break;
case "secretary":
$listing = " and cs.description = 'Secretary' ";
break;
case "treasurer":
$listing = " and cs.description = 'Treasurer' ";
break;
case "regional_liason":
$listing = " and cs.description = 'Regional Liason' ";
break;
case "all":
default;
$listing = " and (cm.standing = '' or cm.standing is null ) ";
// $listing = " ";
}
/*
$sql = "select *";
$sql .= "from personal p, committee_memberships cm, committees c, years y ";
$sql .= "where cm.member_id = p.id and y.member_id = p.id and ";
$sql .= " cm.committee_id = c.committee_id and c.committee_id in ('$committee') ";
$sql .= $listing;
$sql .= " order by lastn";
*/
$sql = "select * from personal p
LEFT OUTER JOIN committee_memberships cm ON p.id = cm.member_id
LEFT OUTER JOIN committee_standings cs ON cm.standing_id = cs.standing_id
LEFT OUTER JOIN committees c ON c.committee_id = cm.committee_id
LEFT OUTER JOIN years y ON p.id = y.member_id
WHERE (c.committee_id in ('$committee') OR c.committee_id IS NULL)
$listing";
}
$sql .= " order by p.lastn";
$fonto = "";
$fontc = "";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
$last_id = 'START';
while ($row = mysql_fetch_assoc($result)) {
$bgcolor=($count++ % 2 == 1)?"bgcolor='#cccccc'":""; // alternate gray rows
foreach ($row as $key=>$val){
$row[$key] = ($val)?$val:"n/a";
}
$old_row .= "\n";
$old_row .= "";
$old_row .= "$fontoDELETE$fontc | ";
$old_row .= "";
if ( $member != 'all' ){
$member = preg_replace("/_/", " ", $member);
$member = ucwords($member);
if ( $member != '') $old_row .= "$fonto$member: $fontc";
}
$old_row .= $fonto . $row[firstn] . " " . $row[lastn];
$years[] = $row[year];
if ( $last_id == $row[id] ) {
$years[] = $row[year];
$old_row = "";
} else {
unset ($years);
$out .= $old_row;
$old_row = "";
$years[] = $row[year];
}
for ($i = 0; $i < count($years); $i++) {
if ( $years[$i] != $years[$i-1] and $years[$i] != "0000") $old_row .= " " . $years[$i];
}
$old_row .= "";
$old_row .= " ";
$old_row .= $row[company];
$old_row .= " ";
$old_row .= $row[city] . ", " . $row[state];
$old_row .= " ";
$old_row .= $row[email];
$old_row .= " ";
$old_row .= " \n";
$last_id = $row[id];
}
$out .= $old_row;
if ( mysql_num_rows($result) == 0 and $committee == 'by_name') {
$out = "$fontoNo members were found with that search criteria.$fontc \n";
}
// DEBUG:
// $out .= $sql . "
";
// $out = "Name Corporate Affiliation City, State Email Address " . $out;
return $out;
}
function get_member_info($id) {
global $PHP_SELF;
$fonto = "";
$fontc = "";
$host = 'data.wse.jhu.edu';
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
$years = array();
$years = get_years($id);
$committees = array();
$committees = get_committees($id);
$sql = "select * from personal where id='$id'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$arry[username] = $row[username];
$arry[firstn] = $row[firstn];
$arry[lastn] = $row[lastn];
$arry[address1] = $row[address1];
$arry[address2] = $row[address2];
$arry[city] = $row[city];
$arry[state] = $row[state];
$arry[zip] = $row[zip];
$arry[zipplus4] = $row[zipplus4];
$arry[company] = $row[company];
$arry[email] = $row[email];
$arry[phone1] = $row[phone1];
$arry[phone2] = $row[phone2];
}
$arry[years] = $years;
$arry[committees] = $committees;
return $arry;
}
function get_years($id) {
global $PHP_SELF;
$fonto = "";
$fontc = "";
$host = 'data.wse.jhu.edu';
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
$sql = "select * from years where member_id = '$id'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$years[] = $row[year];
}
return $years;
}
function get_committees($id) {
global $PHP_SELF;
$fonto = "";
$fontc = "";
$host = 'data.wse.jhu.edu';
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
$sql = "select * from committee_memberships where member_id = '$id'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$committees[] = $row[committee_id];
}
return $committees;
}
function get_committee_name($id) {
global $PHP_SELF;
$host = 'data.wse.jhu.edu';
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
$sql = "select committee_name from committees where committee_id = '$id'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
return mysql_result($result, 0);
}
function get_member_name($id) {
global $PHP_SELF;
$host = 'data.wse.jhu.edu';
$db_user = 'alumni';
$db_password = 'seadevusr';
$database = 'alumni';
$sql = "select firstn, lastn from personal where id = '$id'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result) ) {
$fullname .= $row[firstn] . " " . $row[lastn];
}
return $fullname;
}
// WSE_DIRECTORY_FUNCTIONS
function clean_sql($thing){
// Operates on an lvalue
// $thing = preg_replace("/'/", "''", $thing);
return preg_replace("/(-|%|\*|')/", "\\\\$1", $thing);
}
function clean_submission(&$thing, $key, $extra){
$thing = preg_replace("/'/", "''", $thing);
}
function department_url($search_value, $search_field='department_id') {
$database = "wse_directory";
$search_value=preg_replace("/'/", "''", $search_value);
$sql = "select url from departments where $search_field = '$search_value'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
if ( mysql_num_rows($result) == 1) {
while ($row = mysql_fetch_assoc($result)) {
return $row[url];
}
} else {
return false;
}
}
function department($department_id) {
$database = DIRECTORY_DATABASE;
$sql = " select * from departments where department_id = '$department_id'";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
if ( mysql_num_rows($result) == 1) {
while ($row = mysql_fetch_assoc($result)) {
return $row;
}
} else {
return array();
}
}
function d_categories() {
$database = "wse_directory";
$sql = " select * from d_categories order by d_category";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
// $out .= "\n";
}
return $out;
}
function departments() {
$database = "wse_directory";
$sql = " select * from departments order by department";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
// $out .= "\n";
}
return $out;
}
function rd_departments() {
$database = RESEARCH_DATABASE;
$sql = " select * from departments WHERE public_show = 1 order by dept_name";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . " in function rd_departments, line " . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
// $out .= "\n";
}
return $out;
}
function admin_offices() {
$database = "wse_directory";
$sql = "select * from departments where d_category_id=4 ORDER BY department";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
// $out .= "\n";
}
return $out;
}
function persons() {
$database = "wse_directory";
$sql = " select * from person order by lname";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
}
return $out;
}
function p_status() {
$database = "wse_directory";
$sql = " select * from p_status order by p_status";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
}
return $out;
}
function locations() {
$database = "wse_directory";
$sql = " select * from locations order by location";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
}
return $out;
}
function titles() {
$database = "wse_directory";
$sql = " select * from p_title order by p_title";
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
}
return $out;
}
function person($person_id) {
// This is a listing for a single person. A person can be affiliated with more
// than one: "school", "department", and "status"; therefore, these three fields
// should be represented by arrays.
$database = "wse_directory";
$sql = " select
person.*
, departments.*
, departments.department_id
, departments.phone as d_phone
, departments.email as d_email
, departments.location_id as d_location_id
, departments.location_room as d_location_room
, d_locations.nickname as d_location_nickname
, affiliations.affiliation_id
, affiliations.p_status_id
, person.phone as p_phone
, person.email as p_email
, p_title.p_title
, p_status.p_status
, p_location.location_id as p_location_id
, p_location.location as p_location
, p_location.nickname as p_location_nickname
, p_mail.location_id as p_mail_location_id
, p_mail.location as p_mail_location
, p_mail.nickname as p_mail_location_nickname
, person.mail_room as p_mail_room
, person.location_room as p_location_room
, d_locations.location_id as d_location_id
, d_locations.location as d_location
from person
LEFT OUTER JOIN p_title ON person.p_title_id = p_title.p_title_id
LEFT OUTER JOIN locations p_location ON p_location.location_id = person.location_id
LEFT OUTER JOIN locations p_mail ON p_mail.location_id = person.mail_id
LEFT OUTER JOIN affiliations ON affiliations.person_id = person.person_id
LEFT OUTER JOIN departments ON affiliations.department_id = departments.department_id
LEFT OUTER JOIN locations d_locations ON d_locations.location_id = departments.location_id
LEFT OUTER JOIN p_status ON affiliations.p_status_id = p_status.p_status_id
WHERE person.person_id = $person_id
";
// echo $sql; exit;
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
$out = array( 'department_id'=> array(array())
, 'affiliations' => array( array( 'department_id' => ''
, 'person_id' => ''
, 'p_status_id' => ''
, 'school_id' => ''
)
)
);
if ( mysql_num_rows($result) > 0) {
unset($out);
while ($row = mysql_fetch_assoc($result)) {
foreach ( $row as $k=>$v) {
$out['affiliations'][$row['affiliation_id']] =
array( 'department_id' => $row['department_id']
, 'person_id' => $row['person_id']
, 'p_status_id' => $row['p_status_id']
, 'school_id' => $row['school_id']
);
if ( $k == 'department_id' ) {
$out[$k][] = $v;
} else {
$out[$k] = $v;
}
}
}
}
return $out;
}
function where($things = array("person_id is not null")) {
// $things should be an associative array of 'thing' => 'like_where_value'
/*
foreach ($things as $k=>$v) {
if (is_numeric($v)) {
$out_array[] = "$k = $v";
} else {
$out_array[] = "$k like '%$v%'";
}
}
*/
return join(" AND ", $things);
}
function get_listing($table = 'person', $where = "person_id is not null", $group_by = 'n', $order_by = "ORDER BY person.lname" , $backwards_compatible = 1 ) {
// Returns a list of id's from the given table based on the "where" expression.
// IMPORTANT: This list may be grouped by department! Even if it is not grouped,
// (i.e. the group is 'Group By Last Name'), the list is a 4D array:
// list[group][#][table_row][value]
//
// The "where" clause must be established outside of this function.
$database = "wse_directory";
switch ( $table ) {
case "person":
$sql = "select
person.*
, departments.*
, departments.department_id
, departments.phone as d_phone
, departments.email as d_email
, departments.location_id as d_location_id
, departments.location_room as d_location_room
, d_locations.nickname as d_location_nickname
, affiliations.affiliation_id
, affiliations.p_status_id
, person.phone as p_phone
, person.email as p_email
, p_title.p_title
, p_status.p_status
, p_location.location_id as p_location_id
, p_location.location as p_location
, p_location.nickname as p_location_nickname
, p_mail.location_id as p_mail_location_id
, p_mail.location as p_mail_location
, p_mail.nickname as p_mail_location_nickname
, person.mail_room as p_mail_room
, person.location_room as p_location_room
, d_locations.location_id as d_location_id
, d_locations.location as d_location
from person
LEFT OUTER JOIN p_title ON person.p_title_id = p_title.p_title_id
LEFT OUTER JOIN locations p_location ON p_location.location_id = person.location_id
LEFT OUTER JOIN locations p_mail ON p_mail.location_id = person.mail_id
LEFT OUTER JOIN affiliations ON affiliations.person_id = person.person_id
LEFT OUTER JOIN departments ON affiliations.department_id = departments.department_id
LEFT OUTER JOIN locations d_locations ON d_locations.location_id = departments.location_id
LEFT OUTER JOIN p_status ON affiliations.p_status_id = p_status.p_status_id
WHERE $where
$order_by
";
break;
case "departments":
$sql = "select d.* , person.fname contact_fname , person.lname contact_lname , person.phone contact_phone
from departments d
LEFT OUTER JOIN person ON d.contact_id = person.person_id
WHERE $where
$order_by
";
break;
}
// echo $sql; exit;
$db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . " in function get_listing, line " . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . " in function get_listing, line " . __LINE__);
if (mysql_num_rows($result) == 0) return array('Search Failed'=>array());
while ($row = mysql_fetch_assoc($result)) {
if ( $group_by == 'd' ) {
$grouping_string = $row[department];
} else {
$grouping_string = 'Grouped By Last Name';
}
if ( $backwards_compatible == 1 ){
$out[$grouping_string][] = $row;
} else {
$out[$grouping_string][$row['person_id']][] = $row;
}
}
if ( $backwards_compatible == 0 ){
$out2 = array();
$itemnum = 0;
foreach ( $out as $gs => $group ){
foreach ( $group as $person_id => $person_listing ){
foreach ( $person_listing as $rowid => $row ){
foreach ( $row as $item => $value ){
if ( $rowid == 0 or $out[$gs][$person_id][$rowid - 1][$item] == $value){
$out2[$gs][$itemnum][$item] = $value;
} else {
$out2[$gs][$itemnum][$item] .= ",
" .$value;
}
}
}
$itemnum++;
}
}
$out = $out2;
}
return $out;
}
function truncate_group($group, $length = 30){
// This function shortens the name of the group to a fixed length.
// Defaults to length of 30 characters.
// This way is not "smart" enough:
// return substr($group, 0, $length);
if ( strlen($group) > $length )
return preg_replace("/(.{".$length."}[a-zA-Z0-9]+) .*/", "\\1...", $group);
return $group;
}
function setup_breadcrumb(){
// GET THE TREE FROM THE DATABASE
$host = DATABASE_HOST;
$db_user = DATABASE_USERNAME;
$db_password = DATABASE_PASSWORD;
$database = CONTENT_DATABASE;
$sql = "SELECT
self.page_url AS select_var
, self.page_title AS html_head_title
, self.page_title AS nav_bar_title
, self.page_title AS content_title
, parent.page_url AS parent
FROM page_info self
LEFT JOIN page_info parent ON self.parent_page_id = parent.page_info_id";
$db_link = mysql_connect($host, $db_user, $db_password) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$select_var = $row['select_var'];
$parent = $row['parent'];
$html_head_title = $row['html_head_title'];
$nav_bar_title = $row['nav_bar_title'];
$content_title = $row['content_title'];
$out[$select_var] = array( 'parent' => $parent, 'nav_bar_title' => $nav_bar_title, 'html_head_title' => $html_head_title, 'content_title' => $content_title );
}
return $out;
}
function breadcrumb($select, $breadcrumb_arry) {
if ( func_num_args() > 2 ) {
$level = func_get_arg(2);
} else {
$level = 0;
}
// Set default $select to tree root. ABSOLUTELY NECCESSARY!!
if ( ! isset($select) ) $select = 'public_html';
// $breadcrumb_arry[$select]['nav_bar_title'] = preg_replace("/ /", " ", $breadcrumb_arry[$select]['nav_bar_title']);
if ( ! $breadcrumb_arry[$select]['parent'] ){
$out .= "WSE Home";
return $out;
} else {
$level++;
$out .= breadcrumb($breadcrumb_arry[$select]['parent'], $breadcrumb_arry, $level);
if ( $level > 1 ) {
if ($breadcrumb_arry[$select]['nav_bar_title']) $out .= " > " . $breadcrumb_arry[$select]['nav_bar_title'] . "";
} else {
if ($breadcrumb_arry[$select]['nav_bar_title']) $out .= " > " . $breadcrumb_arry[$select]['nav_bar_title'] . "";
}
}
return $out;
}
function setup_news_headlines(){
$host = DATABASE_HOST;
$db_user = DATABASE_USERNAME;
$db_password = DATABASE_PASSWORD;
$database = 'wse_news';
// Changing sort to "publication date" instead of "event_date"
$sql = "select * from news where expire_date > now() and publish_date <= now() order by sort_order, publish_date DESC";
$db_link = mysql_connect($host, $db_user, $db_password) or die(mysql_error() . ", line" . __LINE__);
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
if (mysql_num_rows($result) > 0){
while ($row = mysql_fetch_assoc($result)) {
$out[] = $row;
}
} else {
$sql = "describe news";
$result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . ", line" . __LINE__);
while ($row = mysql_fetch_assoc($result)) {
$out[0][$row['Field']] = '';
}
}
return $out;
}
function create_content_from_file($filename){
// "create_content_from_file()" function allows for the use of PHP
// *inside* content templates, using output buffering to achieve this effect.
// This function assumes that the constant "TEMPLATES_DIR" has been set!!!
ob_start();
if ( preg_match("/\//", $filename) ) {
include( $filename );
} else {
include(TEMPLATES_DIR . "/" . $filename);
}
$out = ob_get_contents();
ob_end_clean();
return $out;
}
function setup_site_map_tree( $list=array()) {
$tree = array();
$nodes = array();
foreach ($list as $node) {
$nodes[$node['id']] = array(0 => $node[0]);
if (is_null($node['parent_id']) or $node['parent_id'] == 0)
$tree[$node['id']] = &$nodes[$node['id']];
else
{
if (!isset($nodes[$node['parent_id']]))
$nodes[$node['parent_id']] = array();
// $nodes[$node['parent_id']][$node['page_title']] = &$nodes[$node['id']];
$nodes[$node['parent_id']][$node['id']] = &$nodes[$node['id']];
}
}
return $tree;
}
function format_site_map($tree, $level = -1){
// This formats the site map into HTML
$level++;
foreach ($tree as $branch => $leaves){
// echo "LEAVES LEAVES LEAVES \n"; print_r( $leaves ); echo "\nNNNNNNNNNNNNNNNNNNNNN
";
if ($branch == 0 ){
// DEBUG
// $out .= "