You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

edit_folder.inc 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/settings/edit_folder.inc |
  5. | |
  6. | This file is part of the Roundcube Webmail client |
  7. | Copyright (C) 2005-2013, The Roundcube Dev Team |
  8. | |
  9. | Licensed under the GNU General Public License version 3 or |
  10. | any later version with exceptions for skins & plugins. |
  11. | See the README file for a full license statement. |
  12. | |
  13. | PURPOSE: |
  14. | Provide functionality to create/edit a folder |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Aleksander Machniak <alec@alec.pl> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. // register UI objects
  21. $OUTPUT->add_handlers(array(
  22. 'folderdetails' => 'rcmail_folder_form',
  23. ));
  24. $OUTPUT->add_label('nonamewarning');
  25. $OUTPUT->send('folderedit');
  26. // WARNING: folder names in UI are encoded with RCUBE_CHARSET
  27. function rcmail_folder_form($attrib)
  28. {
  29. global $RCMAIL;
  30. $storage = $RCMAIL->get_storage();
  31. // edited folder name (empty in create-folder mode)
  32. $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_GPC, true);
  33. // predefined path for new folder
  34. $parent = rcube_utils::get_input_value('_path', rcube_utils::INPUT_GPC, true);
  35. $threading_supported = $storage->get_capability('THREAD');
  36. $delimiter = $storage->get_hierarchy_delimiter();
  37. // Get mailbox parameters
  38. if (strlen($mbox)) {
  39. $options = rcmail_folder_options($mbox);
  40. $namespace = $storage->get_namespace();
  41. $path = explode($delimiter, $mbox);
  42. $folder = array_pop($path);
  43. $path = implode($delimiter, $path);
  44. $folder = rcube_charset::convert($folder, 'UTF7-IMAP');
  45. $hidden_fields = array('name' => '_mbox', 'value' => $mbox);
  46. }
  47. else {
  48. $options = array();
  49. $path = $parent;
  50. // allow creating subfolders of INBOX folder
  51. if ($path == 'INBOX') {
  52. $path = $storage->mod_folder($path, 'in');
  53. }
  54. }
  55. // remove personal namespace prefix
  56. if (strlen($path)) {
  57. $path_id = $path;
  58. $path = $storage->mod_folder($path.$delimiter);
  59. if ($path[strlen($path)-1] == $delimiter) {
  60. $path = substr($path, 0, -1);
  61. }
  62. }
  63. $form = array();
  64. // General tab
  65. $form['props'] = array(
  66. 'name' => $RCMAIL->gettext('properties'),
  67. );
  68. // Location (name)
  69. if ($options['protected']) {
  70. $foldername = str_replace($delimiter, ' &raquo; ', rcube::Q($RCMAIL->localize_folderpath($mbox)));
  71. }
  72. else if ($options['norename']) {
  73. $foldername = rcube::Q($folder);
  74. }
  75. else {
  76. if (isset($_POST['_name']))
  77. $folder = trim(rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST, true));
  78. $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
  79. $foldername = $foldername->show($folder);
  80. if ($options['special']) {
  81. $foldername .= '&nbsp;(' . rcube::Q($RCMAIL->localize_foldername($mbox)) .')';
  82. }
  83. }
  84. $form['props']['fieldsets']['location'] = array(
  85. 'name' => $RCMAIL->gettext('location'),
  86. 'content' => array(
  87. 'name' => array(
  88. 'label' => $RCMAIL->gettext('foldername'),
  89. 'value' => $foldername,
  90. ),
  91. ),
  92. );
  93. if (!empty($options) && ($options['norename'] || $options['protected'])) {
  94. // prevent user from moving folder
  95. $hidden_path = new html_hiddenfield(array('name' => '_parent', 'value' => $path));
  96. $form['props']['fieldsets']['location']['content']['name']['value'] .= $hidden_path->show();
  97. }
  98. else {
  99. $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id;
  100. $exceptions = array($mbox);
  101. // Exclude 'prefix' namespace from parent folders list (#1488349)
  102. // If INBOX. namespace exists, folders created as INBOX subfolders
  103. // will be listed at the same level - selecting INBOX as a parent does nothing
  104. if ($prefix = $storage->get_namespace('prefix')) {
  105. $exceptions[] = substr($prefix, 0, -1);
  106. }
  107. $select = $RCMAIL->folder_selector(array(
  108. 'id' => '_parent',
  109. 'name' => '_parent',
  110. 'noselection' => '---',
  111. 'maxlength' => 150,
  112. 'unsubscribed' => true,
  113. 'skip_noinferiors' => true,
  114. 'exceptions' => $exceptions,
  115. 'additional' => strlen($selected) ? array($selected) : null,
  116. ));
  117. $form['props']['fieldsets']['location']['content']['path'] = array(
  118. 'label' => $RCMAIL->gettext('parentfolder'),
  119. 'value' => $select->show($selected),
  120. );
  121. }
  122. // Settings
  123. $form['props']['fieldsets']['settings'] = array(
  124. 'name' => $RCMAIL->gettext('settings'),
  125. );
  126. // Settings: threading
  127. if ($threading_supported && ($mbox == 'INBOX' || (!$options['noselect'] && !$options['is_root']))) {
  128. $select = new html_select(array('name' => '_viewmode', 'id' => '_viewmode'));
  129. $select->add($RCMAIL->gettext('list'), 0);
  130. $select->add($RCMAIL->gettext('threads'), 1);
  131. if (isset($_POST['_viewmode'])) {
  132. $value = (int) $_POST['_viewmode'];
  133. }
  134. else if (strlen($mbox)) {
  135. $a_threaded = $RCMAIL->config->get('message_threading', array());
  136. $default_mode = $RCMAIL->config->get('default_list_mode', 'list');
  137. $value = (int) (isset($a_threaded[$mbox]) ? $a_threaded[$mbox] : $default_mode == 'threads');
  138. }
  139. $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
  140. 'label' => $RCMAIL->gettext('listmode'),
  141. 'value' => $select->show($value),
  142. );
  143. }
  144. /*
  145. // Settings: sorting column
  146. $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
  147. $select->add($RCMAIL->gettext('nonesort'), '');
  148. $select->add($RCMAIL->gettext('arrival'), 'arrival');
  149. $select->add($RCMAIL->gettext('sentdate'), 'date');
  150. $select->add($RCMAIL->gettext('subject'), 'subject');
  151. $select->add($RCMAIL->gettext('fromto'), 'from');
  152. $select->add($RCMAIL->gettext('replyto'), 'replyto');
  153. $select->add($RCMAIL->gettext('cc'), 'cc');
  154. $select->add($RCMAIL->gettext('size'), 'size');
  155. $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
  156. $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
  157. 'label' => $RCMAIL->gettext('listsorting'),
  158. 'value' => $select->show($value),
  159. );
  160. // Settings: sorting order
  161. $select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
  162. $select->add($RCMAIL->gettext('asc'), 'ASC');
  163. $select->add($RCMAIL->gettext('desc'), 'DESC');
  164. $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
  165. $form['props']['fieldsets']['settings']['content']['sortord'] = array(
  166. 'label' => $RCMAIL->gettext('listorder'),
  167. 'value' => $select->show(),
  168. );
  169. */
  170. // Information (count, size) - Edit mode
  171. if (strlen($mbox)) {
  172. // Number of messages
  173. $form['props']['fieldsets']['info'] = array(
  174. 'name' => $RCMAIL->gettext('info'),
  175. 'content' => array()
  176. );
  177. if ((!$options['noselect'] && !$options['is_root']) || $mbox == 'INBOX') {
  178. $msgcount = $storage->count($mbox, 'ALL', true, false);
  179. // Size
  180. if ($msgcount) {
  181. // create link with folder-size command
  182. $onclick = sprintf("return %s.command('folder-size', '%s', this)",
  183. rcmail_output::JS_OBJECT_NAME, rcube::JQ($mbox));
  184. $size = html::a(array('href' => '#', 'onclick' => $onclick,
  185. 'id' => 'folder-size'), $RCMAIL->gettext('getfoldersize'));
  186. }
  187. else {
  188. // no messages -> zero size
  189. $size = 0;
  190. }
  191. $form['props']['fieldsets']['info']['content']['count'] = array(
  192. 'label' => $RCMAIL->gettext('messagecount'),
  193. 'value' => (int) $msgcount
  194. );
  195. $form['props']['fieldsets']['info']['content']['size'] = array(
  196. 'label' => $RCMAIL->gettext('size'),
  197. 'value' => $size,
  198. );
  199. }
  200. // show folder type only if we have non-private namespaces
  201. if (!empty($namespace['shared']) || !empty($namespace['others'])) {
  202. $form['props']['fieldsets']['info']['content']['foldertype'] = array(
  203. 'label' => $RCMAIL->gettext('foldertype'),
  204. 'value' => $RCMAIL->gettext($options['namespace'] . 'folder'));
  205. }
  206. }
  207. // Allow plugins to modify folder form content
  208. $plugin = $RCMAIL->plugins->exec_hook('folder_form',
  209. array('form' => $form, 'options' => $options,
  210. 'name' => $mbox, 'parent_name' => $parent));
  211. $form = $plugin['form'];
  212. // Set form tags and hidden fields
  213. list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
  214. unset($attrib['form'], $attrib['id']);
  215. // return the complete edit form as table
  216. $out = "$form_start\n";
  217. // Create form output
  218. foreach ($form as $idx => $tab) {
  219. if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
  220. $content = '';
  221. foreach ($tab['fieldsets'] as $fieldset) {
  222. $subcontent = rcmail_get_form_part($fieldset, $attrib);
  223. if ($subcontent) {
  224. $subcontent = html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent;
  225. $content .= html::tag('fieldset', null, $subcontent) ."\n";
  226. }
  227. }
  228. }
  229. else {
  230. $content = rcmail_get_form_part($tab, $attrib);
  231. }
  232. if ($idx != 'props') {
  233. $out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) ."\n";
  234. }
  235. else {
  236. $out .= $content ."\n";
  237. }
  238. }
  239. $out .= "\n$form_end";
  240. $RCMAIL->output->set_env('messagecount', (int) $msgcount);
  241. $RCMAIL->output->set_env('folder', $mbox);
  242. if ($mbox !== null && empty($_POST)) {
  243. $RCMAIL->output->command('parent.set_quota', $RCMAIL->quota_content(null, $mbox));
  244. }
  245. return $out;
  246. }
  247. function rcmail_get_form_part($form, $attrib = array())
  248. {
  249. global $RCMAIL;
  250. $content = '';
  251. if (is_array($form['content']) && !empty($form['content'])) {
  252. $table = new html_table(array('cols' => 2));
  253. foreach ($form['content'] as $col => $colprop) {
  254. $colprop['id'] = '_'.$col;
  255. $label = $colprop['label'] ?: $RCMAIL->gettext($col);
  256. $table->add('title', html::label($colprop['id'], rcube::Q($label)));
  257. $table->add(null, $colprop['value']);
  258. }
  259. $content = $table->show($attrib);
  260. }
  261. else {
  262. $content = $form['content'];
  263. }
  264. return $content;
  265. }