Can't connect to $SESS_DBHOST as $SESS_DBUSER"; echo "
  • MySQL Error: ", mysql_error(); die; } if (! mysql_select_db($SESS_DBNAME, $SESS_DBH)) { echo "
  • Unable to select database $SESS_DBNAME"; die; } return true; } function sess_close() { return true; } function sess_read($key) { global $SESS_DBH, $SESS_LIFE; $qry = "SELECT value FROM sessions WHERE sesskey = '$key' AND expires > " . time(); $qid = mysql_query($qry, $SESS_DBH); if (list($value) = mysql_fetch_row($qid)) { return $value; } return false; } function sess_write($key, $val) { global $SESS_DBNAME, $SESS_DBH, $SESS_LIFE; $expires = time() + $SESS_LIFE; $value = addslashes($val); if (! mysql_select_db($SESS_DBNAME, $SESS_DBH)) { echo "
  • Unable to select database $SESS_DBNAME"; die; } $qry = "INSERT INTO sessions VALUES ('$key', $expires, '$value')"; $qid = mysql_query($qry, $SESS_DBH); if (! $qid) { $qry = "UPDATE sessions SET expires = $expires, value = '$value' WHERE sesskey = '$key' AND expires > " . time(); $qid = mysql_query($qry, $SESS_DBH); } return $qid; } function sess_destroy($key) { global $SESS_DBH; $qry = "DELETE FROM sessions WHERE sesskey = '$key'"; $qid = mysql_query($qry, $SESS_DBH); return $qid; } function sess_gc($maxlifetime) { global $SESS_DBH; $qry = "DELETE FROM sessions WHERE expires < " . time(); $qid = mysql_query($qry, $SESS_DBH); return mysql_affected_rows($SESS_DBH); } /* FOR SOME STRANGE REASON, The session handler functions are not working!!! ** I am disabling them here, for now. ** I really must figure out why this thing ain't working!! Something database-related, I ** guess, but the other sites that use the same security.inc file all seem to be working okay!! ** (e.g. headsup, alumni, hr, and acadaff) ** JDS, 08-SEP-2004 ** ** Problem appears to be fixed. Somehow the selected database was being set to "wse_users". ** I haven't figured out where or how, yet, but I put in a manual mysql_select_db() in the ** sess_write() function to fix the problem. ** JDS, 08-SEP-2004 */ session_set_save_handler( "sess_open", "sess_close", "sess_read", "sess_write", "sess_destroy", "sess_gc"); /* //=== END OF SESSION SAVE HANDLER ===========================================================// ?> ";print_r( $GLOBALS); } ?> 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 = "NameCorporate AffiliationCity, StateEmail 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 .= "
  • " . print_r($leaves,true) . "
  • \n"; if ( $leaves['page_info_id'] > 1 and $leaves['page_info_id'] <= 8 ){ $out = "

    ${leaves['page_title']} [Click for Webpage]

    \n"; } else if ( $leaves['page_info_id'] != 1 ){ $out = "
  • ${leaves['page_title']}
  • \n"; } } else { $out .= format_site_map($leaves, $level); } } return $out; } function setup_site_map_array(){ // Use this function to create the array of all pages with their parent pages // PASS THIS IN AS AN ARG TO setup_site_map_tree() $database = CONTENT_DATABASE; $sql = "SELECT page_info_id AS id , parent_page_iD AS parent_id , page_info.* FROM page_info WHERE page_is_approved = 1 AND show_on_site_map = 1 ORDER BY page_info_id, page_title "; $db_link = mysql_connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD) or die(mysql_error() . " in setup_site_map_array() , line " . __LINE__); $result = mysql_db_query($database, $sql, $db_link) or die(mysql_error() . " in setup_site_map_array() , line " . __LINE__); $i = 0; while ($row = mysql_fetch_assoc($result) ){ $row['process_id'] = $i; $out[$i] = $row; $out[$i][0] = $row; $i++; $last_page_info_id = $row['page_info_id']; } // Hand-edited external links come from the array $SITE_MAP_EXTERNAL in include/config/vars.inc // They get added here $items = $last_page_info_id + 1; foreach ($GLOBALS['SITE_MAP_EXTERNAL'] as $new_item){ $new_item[0] = $new_item; $new_item['id'] = $items++; $new_item['parent_page_id'] = $new_item['parent_id'] ; array_push($out, $new_item); } // print_r($out); // print_r($GLOBALS['SITE_MAP_EXTERNAL']); ////////////// return $out; } ?> no data source, set all values by hand. Useful for one-off pages. * 1 (default) => Use database "$datbase_name" as database. (This defaults to "alumni"). * 2 * $database_name is the name of the databses. Defaults to "alumni". * It is important that you *do* set tag values if you use ($source = 0) or you will get errors! * Use the method setContentTag(), below! * * getContentTag( $tagName ) * setContentTag( $tagName ) * tagName for the last two methods is the name of the tag. You can use * getTagList(1) to get the list of available tag names as an array * getTagList( $format ) * returns list of current available tags * foramt is determined as follows: * 0 (default) => return sorted, space-delimited list * 1 => return list as sorted array * 2 => return list as sorted *associative* array * setContentFromSource( $pageName, $source ) * Private function * Sets all the content for the given page. pageName can be the name of the * page (the directory where the page lives) or the row_id of the page in * the database. * * VARIABLES * ========= * * USAGE * ===== * To instantiate the class, call * $pc = new PageContent("name_of_page"); // name_of_page is meant to be a unique identifier. The directory in which the page resides is good. * * Then set the data inside the instance: * $pc->setContent("page_name"); * "page_name" should be the unique name of the page; we are using the name * of the directory for the page. This will be a unique field in the * database. * * To print or use the content, do: * echo $pc->getContentTag("tagname"); * or, for example, for use with a bTemplate instance called "$bt", do: * $bt->set("tagname", $pc->getContentTag("tagname")); * * If you are not sure what the tags are, you can use the following: * $pc->getTagList(1); * like so: * foreach ($pc->getTagList(1) as $tagname){ * $bt->set($tagname, $pc->getContentTag($tagname); * } */ class SiteContent { var $tags; // array which holds the tagnames and their values var $database; var $db_host; var $db_username; var $db_password; var $db_link; // var $safe_mode; /* Function: SiteContent() * Constructor function for this class sets the default database to "alumni" * and initializes the class with the source data. */ function SiteContent($pageIdentifier, $source = 1, $safe_mode=1, $database = CONTENT_DATABASE, $db_host = DATABASE_HOST, $db_username = DATABASE_USERNAME, $db_password = DATABASE_PASSWORD, $admin_mode = 0 ){ $this->tags = array(); $this->database = $database; $this->db_host = $db_host; $this->db_username = $db_username; $this->db_password = $db_password; $this->db_link = mysql_connect($this->db_host, $this->db_username, $this->db_password) or die("Could not connect : " . mysql_error()); $this->safe_mode = $safe_mode; $this->admin_mode = $admin_mode; $this->setPageList(); $this->setTemplateList(); $this->setPageInfoIdList(); $this->setContentFromSource($pageIdentifier, $source); mysql_close($this->db_link); } function pageIsEditable(){ return $this->tags['page_is_editable']; } function pageIsApproved(){ return $this->tags[page_is_approved]; } function pageIsChanged(){ return $this->tags[page_is_changed]; } function getTag( $tagName ){ return $this->getContentTag($tagName); } function getContentTag( $tagName ){ return $this->tags[$tagName]; } function getPageInfoIdList() { return $this->page_info_id_list; } function getTemplateName(){ // DEBUG // echo "Template in function: " . $this->tags["template_name"] . "
    "; return ($this->tags["template"]) ? $this->tags["template"] : FALSE; } function setContentTag( $tagName, $value, $tf = NULL ){ $this->tags[$tagName] = $value; // if (isset($tf)) $this->tags['tf'] = $tf; } function setVar( $varName, $value ){ $this->$varName = $value; return; } function getVar( $varName ){ return $this->$varName; } function getTagList( $format = 1 ){ $list = array_keys($this->tags); sort($list); switch ($format){ case 0: $out = join($list, " "); break; default: case 1: $out = $list; break; case 2: foreach ($this->tags as $key => $val){ $out[$key] = $val; } break; } return $out; } function getPageList( $format = 0 ){ unset($out); $home = array( 'page_info_id' => '0' , 'page_name' => 'home' , 'template_id' => '1' , 'template' => 'index1.tpl' , 'page_title' => 'Home Page' , 'page_body' => '' , 'nav_rollover_text' => '' , 'meta_keywords' => '' , 'meta_description' => '' , 'parent_page_id' => '' , 'blurb' => '' , 'date_changed' => '' , 'date_created' => '' , 'page_is_editable' => '' , 'page_is_approved' => '' , 'page_is_changed' => '' , 'sort_order' => '' ); switch ($format) { default: case 0: $out[] = $home; foreach ($this->page_list as $rownum => $row) { $out[] = $row; } break; case 1: $out[] = $home; foreach ($this->page_list as $rownum => $row) { $out[] = join(", ", $row); } break; } return $out; } function getTemplateList( $format = 0 ){ unset($out); switch ($format) { default: case 0: foreach ($this->template_list as $rownum => $row) { $out[] = $row; } break; case 1: foreach ($this->template_list as $rownum => $row) { $out[] = join(", ", $row); } break; } return $out; } /* "Private" Methods. (Of course, "private" is not enforced in PHP) */ /* function: setContentFromSource * This function is the one that will have to change when the data is * migrated to a database (from a data file). Possible sources: 0 == from file, * 1 == from db */ function setContentFromSource( $pageIdentifier, $source){ if (isset($pageIdentifier) and ($pageIdentifier != '' and $pageIdentifier != '0')){ switch ($source){ case 0: $this->tags = array("nulltag"=>""); break; case 1: /* Connecting, selecting database */ $link = $this->db_link; mysql_select_db($this->database) or die("Could not select database. MySQL Error: " . mysql_error() . " in private method setContentFromSource()."); /* Performing SQL query */ $sitecontentsql = " SELECT page_url as name , page_filename as filename , page_body as body , page_title as title , pi.* , IF(page_is_approved = 1, 'YES', 'NO') as page_is_approved , DATE_FORMAT( pi.date_changed , '%d-%b-%Y' ) as date_changed , t.template_name as template , t.description as template_description FROM page_info pi LEFT OUTER JOIN templates t ON pi.template_id = t.template_id "; //if ($_SERVER["REMOTE_ADDR"] == '128.220.42.136') { echo $sitecontentsql; exit; } if (is_numeric($pageIdentifier)){ $sitecontentsql .= " WHERE page_info_id = $pageIdentifier "; } else { $sitecontentsql .= " WHERE page_url = '$pageIdentifier' AND page_is_approved = 1"; } // DEBUG // echo "

    $sitecontentsql

    "; $sitecontentresult = mysql_query($sitecontentsql) or die("Query failed : " . mysql_error()); /* Printing results in HTML */ while ($sitecontentrow = mysql_fetch_assoc($sitecontentresult)) { // echo $this->safe_mode; if (is_file(CONTENT_DIR . "/" . $sitecontentrow['name'] . ".inc") ){ // $sitecontentrow['body'] = file_get_contents(CONTENT_DIR . "/" . $sitecontentrow['filename']); if ( $this->safe_mode ) { $sitecontentrow['body'] = ob_get_contents(); } else { /* I am removing the 'body' setup from the constructor * For speed reasons. Set up body manually after the $site object * has been created, that way the 'body' is only processed once ob_start(); include(CONTENT_DIR . "/" . $sitecontentrow['filename']); $sitecontentrow['body'] = ob_get_contents(); ob_end_clean(); */ } } if( is_file(CONTENT_DIR . "/" . $sitecontentrow['page_filename']) ){ $sitecontentrow["page_last_updated"] = date("M j, Y", filemtime(CONTENT_DIR . "/" . $sitecontentrow['page_filename'])); } $page_name = $sitecontentrow['name']; $tags[$page_name] = $sitecontentrow; } /* Free resultset */ // mysql_free_result($sitecontentresult); /* Closing connection */ // mysql_close($link); break; case 2: default: include(INCLUDE_DIR . "/content_array.inc"); break; } } else { // Set default (blank) page content $page_name="nopage"; $link = $this->db_link; $fields = mysql_list_fields($this->database, "page_info", $link); $columns = mysql_num_fields($fields); for ($i = 0; $i < $columns; $i++) { $sitecontentrow[mysql_field_name($fields, $i)] = ""; } $tags[$page_name]=$sitecontentrow; $tags[$page_name]['page_is_editable']=true; } $content = $tags[$page_name]; $this->tags = $content; } function setTemplateList(){ /* Connecting, selecting database */ $link = $this->db_link; mysql_select_db($this->database) or die("Could not select database. MySQL Error: " . mysql_error() . " in private method setContentFromSource()."); /* Performing SQL query */ $sitecontentsql = " SELECT * FROM templates WHERE template_type_id = 2 "; $sitecontentresult = mysql_query($sitecontentsql) or die("Query failed : " . mysql_error()); while ($row = mysql_fetch_assoc($sitecontentresult)) { $out[] = $row; } // mysql_free_result($sitecontentresult); // mysql_close($link); $this->template_list = $out; return; } function setPageList( $format = 0 ){ /* Connecting, selecting database */ $link = $this->db_link; mysql_select_db($this->database) or die("Could not select database. MySQL Error: " . mysql_error() . " in private method setContentFromSource()."); /* Performing SQL query */ $sitecontentsql = " SELECT * , IF(page_is_approved = 1, 'YES', 'NO') as page_is_approved FROM page_info p "; $sitecontentresult = mysql_query($sitecontentsql) or die("Query failed : " . mysql_error()); unset($out); $out[0] = array(); while ($row = mysql_fetch_assoc($sitecontentresult)) { // Bugfix: 21-MAR-2006. Now using the page_info_id as the index for page_list. Hopefully this // will just be a bug FIX and not break anything else! // JDS, 21-MAR-2006 $out[$row['page_info_id']] = $row; } /* Free resultset */ // mysql_free_result($sitecontentresult); /* Closing connection */ // mysql_close($link); $this->page_list = $out; return; } function setPageInfoIdList() { // Returns a list of all available page_info_id's, for use in further queries, if need be. $sitecontentsql = "select page_info_id from page_info"; /* Connecting, selecting database */ $link = $this->db_link; mysql_select_db($this->database) or die("Could not select database. MySQL Error: " . mysql_error() . " in private method setContentFromSource()."); $sitecontentresult = mysql_query($sitecontentsql) or die("Query failed : " . mysql_error()); while ($row = mysql_fetch_assoc($sitecontentresult) ) { $out[] = $row['page_info_id']; } $this->page_info_id_list = $out; return; } function setPageHiearchy(){ // Creates an array that lists the pages "above" the current page and includes the current page. } } ?>