[ Index ] |
PHP Cross Reference of Eventum |
[Summary view] [Print] [Text view]
1 <?php 2 /* vim: set expandtab tabstop=4 shiftwidth=4 encoding=utf-8: */ 3 // +----------------------------------------------------------------------+ 4 // | Eventum - Issue Tracking System | 5 // +----------------------------------------------------------------------+ 6 // | Copyright (c) 2003, 2004, 2005, 2006, 2007 MySQL AB | 7 // | | 8 // | This program is free software; you can redistribute it and/or modify | 9 // | it under the terms of the GNU General Public License as published by | 10 // | the Free Software Foundation; either version 2 of the License, or | 11 // | (at your option) any later version. | 12 // | | 13 // | This program is distributed in the hope that it will be useful, | 14 // | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 // | GNU General Public License for more details. | 17 // | | 18 // | You should have received a copy of the GNU General Public License | 19 // | along with this program; if not, write to: | 20 // | | 21 // | Free Software Foundation, Inc. | 22 // | 59 Temple Place - Suite 330 | 23 // | Boston, MA 02111-1307, USA. | 24 // +----------------------------------------------------------------------+ 25 // | Authors: João Prado Maia <jpm@mysql.com> | 26 // +----------------------------------------------------------------------+ 27 // 28 // @(#) $Id: class.prefs.php 3246 2007-02-09 09:10:12Z glen $ 29 // 30 31 require_once (APP_INC_PATH . "class.error_handler.php"); 32 require_once (APP_INC_PATH . "class.user.php"); 33 require_once (APP_INC_PATH . "class.date.php"); 34 35 /** 36 * Class to handle the business logic related to the user preferences 37 * available in the application. 38 * 39 * @version 1.0 40 * @author João Prado Maia <jpm@mysql.com> 41 */ 42 43 class Prefs 44 { 45 /** 46 * Method used to get the system-wide default preferences. 47 * 48 * @access public 49 * @param array $projects An array of projects this user will have access too. 50 * @return string The serialized array of the default preferences 51 */ 52 function getDefaults($projects) 53 { 54 $prefs = array( 55 'receive_assigned_emails' => array(), 56 'receive_new_emails' => array(), 57 'timezone' => Date_API::getDefaultTimezone(), 58 'list_refresh_rate' => APP_DEFAULT_REFRESH_RATE, 59 'emails_refresh_rate' => APP_DEFAULT_REFRESH_RATE, 60 'email_signature' => '', 61 'auto_append_sig' => 'no', 62 'auto_append_note_sig' => 'no' 63 ); 64 foreach ($projects as $prj_id) { 65 $prefs['receive_assigned_emails'][$prj_id] = APP_DEFAULT_ASSIGNED_EMAILS; 66 $prefs['receive_new_emails'][$prj_id] = APP_DEFAULT_NEW_EMAILS; 67 } 68 return serialize($prefs); 69 } 70 71 72 /** 73 * Method used to get the preferences set by a specific user. 74 * 75 * @access public 76 * @param integer $usr_id The user ID 77 * @return array The preferences 78 */ 79 function get($usr_id) 80 { 81 static $returns; 82 83 $usr_id = Misc::escapeInteger($usr_id); 84 85 if (!empty($returns[$usr_id])) { 86 return $returns[$usr_id]; 87 } 88 89 $stmt = "SELECT 90 usr_preferences 91 FROM 92 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user 93 WHERE 94 usr_id=$usr_id"; 95 $res = $GLOBALS["db_api"]->dbh->getOne($stmt); 96 if (PEAR::isError($res)) { 97 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 98 return ""; 99 } else { 100 $res = @unserialize($res); 101 // check for the refresh rate variables, and use the default values if appropriate 102 if (empty($res['list_refresh_rate'])) { 103 $res['list_refresh_rate'] = APP_DEFAULT_REFRESH_RATE; 104 } 105 if (empty($res['emails_refresh_rate'])) { 106 $res['emails_refresh_rate'] = APP_DEFAULT_REFRESH_RATE; 107 } 108 $returns[$usr_id] = $res; 109 return $returns[$usr_id]; 110 } 111 } 112 113 114 /** 115 * Method used to set the preferences for a specific user. 116 * 117 * @access public 118 * @param integer $usr_id The user ID 119 * @return integer 1 if the update worked, -1 otherwise 120 */ 121 function set($usr_id) 122 { 123 // if the user is trying to upload a new signature, override any changes to the textarea 124 if (!empty($_FILES["file_signature"]["name"])) { 125 $_POST['signature'] = Misc::getFileContents($_FILES["file_signature"]["tmp_name"]); 126 } 127 128 $data = serialize(array( 129 'close_popup_windows' => $_POST['close_popup_windows'], 130 'receive_assigned_emails' => $_POST['receive_assigned_emails'], 131 'receive_new_emails' => @$_POST['receive_new_emails'], 132 'timezone' => $_POST['timezone'], 133 'list_refresh_rate' => $_POST['list_refresh_rate'], 134 'emails_refresh_rate' => $_POST['emails_refresh_rate'], 135 'email_signature' => @$_POST['signature'], 136 'auto_append_sig' => @$_POST['auto_append_sig'], 137 'auto_append_note_sig' => @$_POST['auto_append_note_sig'] 138 )); 139 $stmt = "UPDATE 140 " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "user 141 SET 142 usr_preferences='" . Misc::escapeString($data) . "' 143 WHERE 144 usr_id=" . Misc::escapeInteger($usr_id); 145 $res = $GLOBALS["db_api"]->dbh->query($stmt); 146 if (PEAR::isError($res)) { 147 Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__); 148 return -1; 149 } else { 150 return 1; 151 } 152 } 153 } 154 155 // benchmarking the included file (aka setup time) 156 if (APP_BENCHMARK) { 157 $GLOBALS['bench']->setMarker('Included Prefs Class'); 158 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Dec 19 21:21:33 2007 | Cross-referenced by PHPXref 0.7 |