function _validate_note($note) { global $NOTE_KEYS; foreach ($NOTE_KEYS as $key) { if (isset($note[$key]) === false) { return false; } $note[$key] = to_sql_type($note[$key]); //prepare for sql } return $note; }
function setUserPrefs($userId, $prefs) { global $dbCon; $cols = array('color', 'font_color', 'font_size', 'font_type', 'width', 'height', 'bg_color', 'bg_img'); $cols_Vals = array(); foreach ($cols as $col) { if (isset($prefs[$col])) { $cols_Vals[] = $col . '=' . to_sql_type($prefs[$col]); } } $cols_Vals = implode(', ', $cols_Vals); try { $sql = "UPDATE user_prefs SET {$cols_Vals} WHERE(user_id={$userId})"; //echo ($sql); $rowCount = $dbCon->exec($sql); if ($rowCount > 0) { $reply = array('prefs_set' => true); } else { $reply = array('prefs_set' => false); } } catch (Exception $e) { $reply = array('errors' => $e->getMessage()); } replyJson($reply); }