PageRenderTime 24ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/tine20/Expressomail/Preference.php

https://gitlab.com/rsilveira1987/Expresso
PHP | 306 lines | 185 code | 27 blank | 94 comment | 3 complexity | 028f96ff3be2597b3459306ffebc6aba MD5 | raw file
  1. <?php
  2. /**
  3. * Tine 2.0
  4. *
  5. * @package Expressomail
  6. * @subpackage Backend
  7. * @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
  8. * @author Philipp Schüle <p.schuele@metaways.de>
  9. * @copyright Copyright (c) 2009-2011 Metaways Infosystems GmbH (http://www.metaways.de)
  10. *
  11. * @todo make UPDATEINTERVAL a free form preference
  12. */
  13. /**
  14. * backend for Expressomail preferences
  15. *
  16. * @package Expressomail
  17. * @subpackage Backend
  18. */
  19. class Expressomail_Preference extends Tinebase_Preference_Abstract
  20. {
  21. /**************************** application preferences/settings *****************/
  22. /**
  23. * default email account to use
  24. *
  25. */
  26. const DEFAULTACCOUNT = 'defaultEmailAccount';
  27. /**
  28. * email folder update interval
  29. *
  30. */
  31. const UPDATEINTERVAL = 'updateInterval';
  32. /**
  33. * use expressomail in addressbook
  34. *
  35. */
  36. const USEINADB = 'useInAdb';
  37. /**
  38. * use for default note
  39. *
  40. */
  41. const AUTOATTACHNOTE = 'autoAttachNote';
  42. /**
  43. * show Emails Per Page option
  44. *
  45. */
  46. const EMAILS_PERPAGE = 'emailsPerPage';
  47. /**
  48. * show delete confirmation
  49. *
  50. * @todo add this to more apps?
  51. */
  52. const CONFIRM_DELETE = 'confirmDelete';
  53. /**
  54. * default filter name
  55. */
  56. const DEFAULTPERSISTENTFILTER_NAME = 'All inboxes'; // _("All inboxes")
  57. /**
  58. * Message Editor opens with toggle button "Sign Message" pressed
  59. */
  60. const ALWAYS_SIGN_MESSAGE = 'alwaysSign';
  61. /**
  62. * Enable encryped messages
  63. */
  64. const ENABLE_ENCRYPTED_MESSAGE = 'enableEncryptedMessage';
  65. /**
  66. * application
  67. *
  68. * @var string
  69. */
  70. protected $_application = 'Expressomail';
  71. /**
  72. * preference names that have no default option
  73. *
  74. * @var array
  75. */
  76. protected $_skipDefaultOption = array(self::DEFAULTACCOUNT);
  77. /**
  78. * show Use Trash option
  79. *
  80. */
  81. const MOVEDELETED_TOTRASH = 'confirmUseTrash';
  82. /**
  83. * show Use Trash option
  84. *
  85. */
  86. const DELETE_FROMTRASH = 'deleteFromTrash';
  87. /**************************** public functions *********************************/
  88. /**
  89. * get all possible application prefs
  90. *
  91. * @return array all application prefs
  92. */
  93. public function getAllApplicationPreferences()
  94. {
  95. $allPrefs = array(
  96. self::DEFAULTACCOUNT,
  97. self::UPDATEINTERVAL,
  98. self::USEINADB,
  99. self::AUTOATTACHNOTE,
  100. self::CONFIRM_DELETE,
  101. self::EMAILS_PERPAGE,
  102. self::MOVEDELETED_TOTRASH,
  103. self::DELETE_FROMTRASH,
  104. self::ALWAYS_SIGN_MESSAGE,
  105. self::ENABLE_ENCRYPTED_MESSAGE,
  106. );
  107. return $allPrefs;
  108. }
  109. /**
  110. * get translated right descriptions
  111. *
  112. * @return array with translated descriptions for this applications preferences
  113. */
  114. public function getTranslatedPreferences()
  115. {
  116. $translate = Tinebase_Translation::getTranslation($this->_application);
  117. $prefDescriptions = array(
  118. self::DEFAULTACCOUNT => array(
  119. 'label' => $translate->_('Default Email Account'),
  120. 'description' => $translate->_('The default email account to use when sending mails.'),
  121. ),
  122. self::UPDATEINTERVAL => array(
  123. 'label' => $translate->_('Email Update Interval'),
  124. 'description' => $translate->_('How often should Expressomail check for new Emails (in minutes).'),
  125. ),
  126. self::USEINADB => array(
  127. 'label' => $translate->_('Use in Addressbook'),
  128. 'description' => $translate->_('Compose Emails from the Addressbook with Expressomail.'),
  129. ),
  130. self::AUTOATTACHNOTE => array(
  131. 'label' => $translate->_('Use for NOTES'),
  132. 'description' => $translate->_('Save Note default Value.'),
  133. ),
  134. self::CONFIRM_DELETE => array(
  135. 'label' => $translate->_('Confirm Delete'),
  136. 'description' => $translate->_('Show confirmation dialog when deleting mails.'),
  137. ),
  138. self::EMAILS_PERPAGE => array(
  139. 'label' => $translate->_('Emails shown in each page'),
  140. 'description' => $translate->_('Choose a number of emails to show in each page'),
  141. ),
  142. self::MOVEDELETED_TOTRASH => array(
  143. 'label' => $translate->_('Move Deleted Messages to Trash'),
  144. 'description' => $translate->_('Choose yes, to Move Deleted Messages to Trash.'),
  145. ),
  146. self::DELETE_FROMTRASH => array(
  147. 'label' => $translate->_('Delete trash messages after how many days'),
  148. 'description' => $translate->_('Choose a number of days'),
  149. ),
  150. self::ALWAYS_SIGN_MESSAGE => array(
  151. 'label' => $translate->_('Digitally sign messages by default when sending mail'),
  152. 'description' => $translate->_('Choose yes, to open message editor with toggle button "Sign Message" pressed'),
  153. ),
  154. self::ENABLE_ENCRYPTED_MESSAGE => array(
  155. 'label' => $translate->_('Enable sending encrypted messages'),
  156. 'description' => $translate->_('Choose yes, to enable sending encrypted messages (only if preference "Windows Type" is set to "Browser windows").'),
  157. ),
  158. );
  159. return $prefDescriptions;
  160. }
  161. /**
  162. * get preference defaults if no default is found in the database
  163. *
  164. * @param string $_preferenceName
  165. * @return Tinebase_Model_Preference
  166. */
  167. public function getApplicationPreferenceDefaults($_preferenceName, $_accountId=NULL, $_accountType=Tinebase_Acl_Rights::ACCOUNT_TYPE_USER)
  168. {
  169. $preference = $this->_getDefaultBasePreference($_preferenceName);
  170. switch($_preferenceName) {
  171. case self::USEINADB:
  172. $preference->value = 1;
  173. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  174. <options>
  175. <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
  176. </options>';
  177. break;
  178. case self::DEFAULTACCOUNT:
  179. $preference->personal_only = TRUE;
  180. $preference->value = '';
  181. break;
  182. case self::UPDATEINTERVAL:
  183. $preference->value = 5;
  184. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  185. <options>';
  186. for ($i = 1; $i <= 20; $i++) {
  187. $preference->options .= '<option>
  188. <label>'. $i . '</label>
  189. <value>'. $i . '</value>
  190. </option>';
  191. }
  192. $preference->options .= '</options>';
  193. break;
  194. case self::AUTOATTACHNOTE:
  195. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  196. <options>
  197. <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
  198. </options>';
  199. break;
  200. case self::CONFIRM_DELETE:
  201. $preference->value = 1;
  202. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  203. <options>
  204. <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
  205. </options>';
  206. break;
  207. case self::EMAILS_PERPAGE:
  208. $preference->value = 50;
  209. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  210. <options>';
  211. for ($i = 25; $i <= 100; $i=$i*2) {
  212. $preference->options .= '<option>
  213. <label>'. $i . '</label>
  214. <value>'. $i . '</value>
  215. </option>';
  216. }
  217. $preference->options .= '</options>';
  218. break;
  219. case self::MOVEDELETED_TOTRASH:
  220. $preference->value = 1;
  221. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  222. <options>
  223. <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
  224. </options>';
  225. break;
  226. case self::DELETE_FROMTRASH:
  227. $preference->value = 0;
  228. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  229. <options>';
  230. for ($i = 1; $i <= 5; $i++) {
  231. $preference->options .= '<option>
  232. <label>'. $i . '</label>
  233. <value>'. $i . '</value>
  234. </option>';
  235. }
  236. $preference->options .= '</options>';
  237. break;
  238. case self::ALWAYS_SIGN_MESSAGE:
  239. $preference->value = 0;
  240. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  241. <options>
  242. <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
  243. </options>';
  244. break;
  245. case self::ENABLE_ENCRYPTED_MESSAGE:
  246. $preference->value = 1;
  247. $preference->options = '<?xml version="1.0" encoding="UTF-8"?>
  248. <options>
  249. <special>' . Tinebase_Preference_Abstract::YES_NO_OPTIONS . '</special>
  250. </options>';
  251. break;
  252. default:
  253. throw new Tinebase_Exception_NotFound('Default preference with name ' . $_preferenceName . ' not found.');
  254. }
  255. return $preference;
  256. }
  257. /**
  258. * get special options
  259. *
  260. * @param string $_value
  261. * @return array
  262. */
  263. protected function _getSpecialOptions($_value)
  264. {
  265. $result = array();
  266. switch($_value) {
  267. case self::DEFAULTACCOUNT:
  268. // get all user accounts
  269. $accounts = Expressomail_Controller_Account::getInstance()->search();
  270. foreach ($accounts as $account) {
  271. $result[] = array($account->getId(), $account->name);
  272. }
  273. break;
  274. default:
  275. $result = parent::_getSpecialOptions($_value);
  276. }
  277. return $result;
  278. }
  279. }