<?php
/*
* ConPortal - Pomona College ITS & Bucknell University Library & IT scheduling appplication
* Copyright (C) 2005-2008 Pomona College, Bucknell University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of version 2 of the GNU General Public License
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
Implemented in this file
loadPrefs
getPrefs
setPrefs
*/
//Initial loading of Preferences
function loadPrefs()
{
$result = safeQuery("SELECT pref_name, pref_value, pref_description FROM preferences");
while ($row = mysql_fetch_assoc($result))
{
//check to see if our value should be a boolean and not a string
if(strtoupper($row["pref_value"]) == "TRUE")
{
define($row["pref_name"],TRUE);
}
else if(strtoupper($row["pref_value"]) == "FALSE")
{
define($row["pref_name"],FALSE);
}
//otherwise it's just a string
else
{
define($row["pref_name"],$row["pref_value"]);
}
}
return 0;
}
//Get Preferences for use in form
function getPrefs()
{
$result = safeQuery("SELECT pid, pref_name, pref_value, pref_description FROM preferences ORDER BY pid");
$a = array();
while ($row = mysql_fetch_assoc($result))
{
$a[] = $row;
}
return $a;
}
//Set Preferences based on form
function setPrefs($prefArray)
{
//re-insert all the prefs, even the ones that don't change
foreach($prefArray as $pref)
{
if(is_bool($pref["pref_value"]))
{
if($pref["pref_value"])
{
$pref["pref_value"] = "TRUE";
}
else
{
$pref["pref_value"] = "FALSE";
}
}
$result = safeQuery("UPDATE preferences SET pref_value = \"" .
$pref["pref_value"] ."\" WHERE pref_name = \"" . $pref["pref_name"] ."\"");
}
return FALSE;
}