<?php	// TWIG		Preference Functions.	?>
<?php

 // Get Preferences from database or from cookies
 Function GetPref($pref) {
  global $PHP_AUTH_USER, $dbconfig;
  if ($dbconfig) {
   $result=dbQuery("SELECT * FROM $dbconfig[prefs_table] WHERE username = '$PHP_AUTH_USER'");
   $prefs=dbResultArray($result,0);
  }
  else {
   $cn = $PHP_AUTH_USER . "_twig" . $pref;
   $prefs[$pref] = $$cn;
  }
  return $prefs[$pref];
 }

 Function PutPref($pref, $value) {
  global $PHP_AUTH_USER, $dbconfig;
  if ($dbconfig) {
   if (!GetPref("username")) {
    $result=dbQuery("INSERT INTO $dbconfig[prefs_table] (username) VALUES ('$PHP_AUTH_USER')");
   }
   $query = "UPDATE $dbconfig[prefs_table] SET $pref = '$value' WHERE username = '$PHP_AUTH_USER'";
   $result=dbQuery($query);
  }
  else {
   $cn = $PHP_AUTH_USER . "_twig" . $pref;
   SetCookie($cn,$$cn,mktime(0,0,0,12,31,2000),"/");
  }
 }

?>
