adding end date check in get shows just incase nobody checks calendar for a while.

preferences had to be updated because there will be no user id if the daemon process updates the date pouplated until pref.
This commit is contained in:
naomiaro 2011-04-04 00:02:35 -04:00
parent 2033b904c8
commit 7f775105e2
4 changed files with 37 additions and 14 deletions

View file

@ -6,19 +6,38 @@ class Application_Model_Preference
public static function SetValue($key, $value){
global $CC_CONFIG, $CC_DBC;
$auth = Zend_Auth::getInstance();
$id = $auth->getIdentity()->id;
//called from a daemon process
if(!Zend_Auth::getInstance()->hasIdentity()) {
$id = NULL;
}
else {
$auth = Zend_Auth::getInstance();
$id = $auth->getIdentity()->id;
}
$key = pg_escape_string($key);
$value = pg_escape_string($value);
//Check if key already exists
$sql = "SELECT COUNT(*) FROM cc_pref"
." WHERE keystr = '$key'";
$result = $CC_DBC->GetOne($sql);
if ($result == 1){
if ($result == 1 && is_null($id)){
$sql = "UPDATE cc_pref"
." SET subjid = NULL, valstr = '$value'"
." WHERE keystr = '$key'";
}
else if ($result == 1 && !is_null($id)){
$sql = "UPDATE cc_pref"
." SET subjid = $id, valstr = '$value'"
." WHERE keystr = '$key'";
} else {
}
else if(is_null($id)) {
$sql = "INSERT INTO cc_pref (keystr, valstr)"
." VALUES ('$key', '$value')";
}
else {
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
." VALUES ($id, '$key', '$value')";
}