options_highlight.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. <?php
  2. /**
  3. * options_highlight.php
  4. *
  5. * Displays message highlighting options
  6. *
  7. * @copyright &copy; 1999-2007 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. * @subpackage prefs
  12. */
  13. /** This is the options_highlight page */
  14. define('PAGE_NAME', 'options_highlight');
  15. /**
  16. * Include the SquirrelMail initialization file.
  17. */
  18. require('../include/init.php');
  19. // include_once(SM_PATH . 'functions/imap.php');
  20. require_once(SM_PATH . 'functions/forms.php');
  21. /* get globals */
  22. sqGetGlobalVar('action', $action);
  23. sqGetGlobalVar('theid', $theid);
  24. sqGetGlobalVar('identname', $identname);
  25. sqGetGlobalVar('newcolor_choose', $newcolor_choose);
  26. sqGetGlobalVar('newcolor_input', $newcolor_input);
  27. sqGetGlobalVar('color_type', $color_type);
  28. sqGetGlobalVar('match_type', $match_type);
  29. sqGetGlobalVar('value', $value);
  30. /* end of get globals */
  31. function oh_opt( $val, $sel, $tit ) {
  32. echo "<option value=\"$val\"";
  33. if ( $sel )
  34. echo ' selected="selected"';
  35. echo ">$tit</option>\n";
  36. }
  37. if (! isset($action)) {
  38. $action = '';
  39. }
  40. if (! isset($message_highlight_list)) {
  41. $message_highlight_list = array();
  42. }
  43. if (isset($theid) && ($action == 'delete') ||
  44. ($action == 'up') ||
  45. ($action == 'down')) {
  46. $new_rules = array();
  47. switch($action) {
  48. case('delete'):
  49. foreach($message_highlight_list as $rid => $rule) {
  50. if($rid != $theid) {
  51. $new_rules[] = $rule;
  52. }
  53. }
  54. break;
  55. case('down'):
  56. $theid++;
  57. case('up'):
  58. foreach($message_highlight_list as $rid => $rule) {
  59. if($rid == $theid) {
  60. $temp_rule = $new_rules[$rid-1];
  61. $new_rules[$rid-1] = $rule;
  62. $new_rules[$rid] = $temp_rule;
  63. } else {
  64. $new_rules[$rid] = $rule;
  65. }
  66. }
  67. break;
  68. default:
  69. $new_rules = $message_highlight_list;
  70. break;
  71. }
  72. $message_highlight_list = $new_rules;
  73. setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
  74. header( 'Location: ' .get_location(). '/options_highlight.php' );
  75. exit;
  76. } else if ($action == 'save') {
  77. if ($color_type == 1) $newcolor = $newcolor_choose;
  78. elseif ($color_type == 2) $newcolor = $newcolor_input;
  79. else $newcolor = $color_type;
  80. $newcolor = str_replace('#', '', $newcolor);
  81. $newcolor = str_replace('"', '', $newcolor);
  82. $newcolor = str_replace('\'', '', $newcolor);
  83. $value = str_replace(',', ' ', $value);
  84. if(isset($theid)) {
  85. $message_highlight_list[$theid] =
  86. array( 'name' => $identname, 'color' => $newcolor,
  87. 'value' => $value, 'match_type' => $match_type );
  88. } else {
  89. $message_highlight_list[] =
  90. array( 'name' => $identname, 'color' => $newcolor,
  91. 'value' => $value, 'match_type' => $match_type );
  92. }
  93. setPref($data_dir, $username, 'hililist', serialize($message_highlight_list));
  94. }
  95. displayPageHeader($color);
  96. /**
  97. * Display the current rule list
  98. */
  99. $rules = array();
  100. foreach($message_highlight_list as $index=>$rule) {
  101. $a = array();
  102. $a['Name'] = htmlspecialchars($rule['name']);
  103. $a['Color'] = $rule['color'];
  104. $a['MatchField'] = '';
  105. $a['MatchValue'] = htmlspecialchars($rule['value']);
  106. switch ($rule['match_type']) {
  107. case 'from' :
  108. $a['MatchField'] = _("From");
  109. break;
  110. case 'to' :
  111. $a['MatchField'] = _("To");
  112. break;
  113. case 'cc' :
  114. $a['MatchField'] = _("Cc");
  115. break;
  116. case 'to_cc' :
  117. $a['MatchField'] = _("To or Cc");
  118. break;
  119. case 'subject' :
  120. $a['MatchField'] = _("subject");
  121. break;
  122. }
  123. $rules[$index] = $a;
  124. }
  125. $oTemplate->assign('current_rules', $rules);
  126. $oTemplate->assign('add_rule', 'options_highlight.php?action=add');
  127. $oTemplate->assign('edit_rule', 'options_highlight.php?action=edit&amp;theid=');
  128. $oTemplate->assign('delete_rule', 'options_highlight.php?action=delete&amp;theid=');
  129. $oTemplate->assign('move_up', 'options_highlight.php?action=up&amp;theid=');
  130. $oTemplate->assign('move_down', 'options_highlight.php?action=down&amp;theid=');
  131. $oTemplate->display('options_highlight_list.tpl');
  132. /**
  133. * Optionally, display the add/edit dialog
  134. */
  135. if ($action == 'edit' || $action == 'add') {
  136. $color_list[0] = '4444aa';
  137. $color_list[1] = '44aa44';
  138. $color_list[2] = 'aaaa44';
  139. $color_list[3] = '44aaaa';
  140. $color_list[4] = 'aa44aa';
  141. $color_list[5] = 'aaaaff';
  142. $color_list[6] = 'aaffaa';
  143. $color_list[7] = 'ffffaa';
  144. $color_list[8] = 'aaffff';
  145. $color_list[9] = 'ffaaff';
  146. $color_list[10] = 'aaaaaa';
  147. $color_list[11] = 'bfbfbf';
  148. $color_list[12] = 'dfdfdf';
  149. $color_list[13] = 'ffffff';
  150. # helpful color chart from http://www.visibone.com/colorlab/big.html
  151. $new_color_list["0,0"] = 'cccccc';
  152. $new_color_list["0,1"] = '999999';
  153. $new_color_list["0,2"] = '666666';
  154. $new_color_list["0,3"] = '333333';
  155. $new_color_list["0,4"] = '000000';
  156. # red
  157. $new_color_list["1,0"] = 'ff0000';
  158. $new_color_list["1,1"] = 'cc0000';
  159. $new_color_list["1,2"] = '990000';
  160. $new_color_list["1,3"] = '660000';
  161. $new_color_list["1,4"] = '330000';
  162. $new_color_list["2,0"] = 'ffcccc';
  163. $new_color_list["2,1"] = 'cc9999';
  164. $new_color_list["2,2"] = '996666';
  165. $new_color_list["2,3"] = '663333';
  166. $new_color_list["2,4"] = '330000';
  167. $new_color_list["3,0"] = 'ffcccc';
  168. $new_color_list["3,1"] = 'ff9999';
  169. $new_color_list["3,2"] = 'ff6666';
  170. $new_color_list["3,3"] = 'ff3333';
  171. $new_color_list["3,4"] = 'ff0000';
  172. # green
  173. $new_color_list["4,0"] = '00ff00';
  174. $new_color_list["4,1"] = '00cc00';
  175. $new_color_list["4,2"] = '009900';
  176. $new_color_list["4,3"] = '006600';
  177. $new_color_list["4,4"] = '003300';
  178. $new_color_list["5,0"] = 'ccffcc';
  179. $new_color_list["5,1"] = '99cc99';
  180. $new_color_list["5,2"] = '669966';
  181. $new_color_list["5,3"] = '336633';
  182. $new_color_list["5,4"] = '003300';
  183. $new_color_list["6,0"] = 'ccffcc';
  184. $new_color_list["6,1"] = '99ff99';
  185. $new_color_list["6,2"] = '66ff66';
  186. $new_color_list["6,3"] = '33ff33';
  187. $new_color_list["6,4"] = '00ff00';
  188. # blue
  189. $new_color_list["7,0"] = '0000ff';
  190. $new_color_list["7,1"] = '0000cc';
  191. $new_color_list["7,2"] = '000099';
  192. $new_color_list["7,3"] = '000066';
  193. $new_color_list["7,4"] = '000033';
  194. $new_color_list["8,0"] = 'ccccff';
  195. $new_color_list["8,1"] = '9999cc';
  196. $new_color_list["8,2"] = '666699';
  197. $new_color_list["8,3"] = '333366';
  198. $new_color_list["8,4"] = '000033';
  199. $new_color_list["9,0"] = 'ccccff';
  200. $new_color_list["9,1"] = '9999ff';
  201. $new_color_list["9,2"] = '6666ff';
  202. $new_color_list["9,3"] = '3333ff';
  203. $new_color_list["9,4"] = '0000ff';
  204. # yellow
  205. $new_color_list["10,0"] = 'ffff00';
  206. $new_color_list["10,1"] = 'cccc00';
  207. $new_color_list["10,2"] = '999900';
  208. $new_color_list["10,3"] = '666600';
  209. $new_color_list["10,4"] = '333300';
  210. $new_color_list["11,0"] = 'ffffcc';
  211. $new_color_list["11,1"] = 'cccc99';
  212. $new_color_list["11,2"] = '999966';
  213. $new_color_list["11,3"] = '666633';
  214. $new_color_list["11,4"] = '333300';
  215. $new_color_list["12,0"] = 'ffffcc';
  216. $new_color_list["12,1"] = 'ffff99';
  217. $new_color_list["12,2"] = 'ffff66';
  218. $new_color_list["12,3"] = 'ffff33';
  219. $new_color_list["12,4"] = 'ffff00';
  220. # cyan
  221. $new_color_list["13,0"] = '00ffff';
  222. $new_color_list["13,1"] = '00cccc';
  223. $new_color_list["13,2"] = '009999';
  224. $new_color_list["13,3"] = '006666';
  225. $new_color_list["13,4"] = '003333';
  226. $new_color_list["14,0"] = 'ccffff';
  227. $new_color_list["14,1"] = '99cccc';
  228. $new_color_list["14,2"] = '669999';
  229. $new_color_list["14,3"] = '336666';
  230. $new_color_list["14,4"] = '003333';
  231. $new_color_list["15,0"] = 'ccffff';
  232. $new_color_list["15,1"] = '99ffff';
  233. $new_color_list["15,2"] = '66ffff';
  234. $new_color_list["15,3"] = '33ffff';
  235. $new_color_list["15,4"] = '00ffff';
  236. # magenta
  237. $new_color_list["16,0"] = 'ff00ff';
  238. $new_color_list["16,1"] = 'cc00cc';
  239. $new_color_list["16,2"] = '990099';
  240. $new_color_list["16,3"] = '660066';
  241. $new_color_list["16,4"] = '330033';
  242. $new_color_list["17,0"] = 'ffccff';
  243. $new_color_list["17,1"] = 'cc99cc';
  244. $new_color_list["17,2"] = '996699';
  245. $new_color_list["17,3"] = '663366';
  246. $new_color_list["17,4"] = '330033';
  247. $new_color_list["18,0"] = 'ffccff';
  248. $new_color_list["18,1"] = 'ff99ff';
  249. $new_color_list["18,2"] = 'ff66ff';
  250. $new_color_list["18,3"] = 'ff33ff';
  251. $new_color_list["18,4"] = 'ff00ff';
  252. $selected_input = FALSE;
  253. $selected_choose = FALSE;
  254. $selected_predefined = FALSE;
  255. $name = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['name']) ? $message_highlight_list[$theid]['name'] : '';
  256. $field = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['match_type']) ? $message_highlight_list[$theid]['match_type'] : '';
  257. $value = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['value']) ? $message_highlight_list[$theid]['value'] : '';
  258. $color = $action=='edit' && isset($theid) && isset($message_highlight_list[$theid]['color']) ? $message_highlight_list[$theid]['color'] : '';
  259. if ($action == 'edit' && isset($theid) && isset($message_highlight_list[$theid]['color'])) {
  260. for ($i=0; $i < 14; $i++) {
  261. if ($color_list[$i] == $message_highlight_list[$theid]['color']) {
  262. $selected_choose = TRUE;
  263. continue;
  264. }
  265. }
  266. }
  267. $pre_defined_color = 0;
  268. for($x = 0; $x < 5; $x++) {
  269. for($y = 0; $y < 19; $y++) {
  270. $gridindex = "$y,$x";
  271. $gridcolor = $new_color_list[$gridindex];
  272. if ($gridcolor == $color) {
  273. $pre_defined_color = 1;
  274. break;
  275. }
  276. }
  277. }
  278. if (isset($theid) && !isset($message_highlight_list[$theid]['color']))
  279. $selected_choose = TRUE;
  280. else if ($pre_defined_color)
  281. $selected_predefined = TRUE;
  282. else if ($selected_choose == '')
  283. $selected_input = TRUE;
  284. $oTemplate->assign('rule_name', $name);
  285. $oTemplate->assign('rule_value', $value);
  286. $oTemplate->assign('rule_field', $field);
  287. $oTemplate->assign('rule_color', $color);
  288. $oTemplate->assign('color_radio', ($selected_choose ? 1 : ($selected_input ? 2 : 0)));
  289. $oTemplate->assign('color_input', ($selected_input ? $color : ''));
  290. echo addForm('options_highlight.php', 'post', 'f').
  291. addHidden('action', 'save');
  292. if($action == 'edit') {
  293. echo addHidden('theid', (isset($theid)?$theid:''));
  294. }
  295. $oTemplate->display('options_highlight_addedit.tpl');
  296. echo "</form>\n";
  297. }
  298. do_hook('options_highlight_bottom', $null);
  299. $oTemplate->display('footer.tpl');