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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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_foldername($mbox, false, true)));
  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. }
  79. $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30));
  80. $foldername = $foldername->show($folder);
  81. if ($options['special'] && ($sname = $RCMAIL->localize_foldername($mbox, false, true)) != $folder) {
  82. $foldername .= '&nbsp;(' . rcube::Q($sname) .')';
  83. }
  84. }
  85. $form['props']['fieldsets']['location'] = array(
  86. 'name' => $RCMAIL->gettext('location'),
  87. 'content' => array(
  88. 'name' => array(
  89. 'label' => $RCMAIL->gettext('foldername'),
  90. 'value' => $foldername,
  91. ),
  92. ),
  93. );
  94. if (!empty($options) && ($options['norename'] || $options['protected'])) {
  95. // prevent user from moving folder
  96. $hidden_path = new html_hiddenfield(array('name' => '_parent', 'value' => $path));
  97. $form['props']['fieldsets']['location']['content']['name']['value'] .= $hidden_path->show();
  98. }
  99. else {
  100. $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path_id;
  101. $exceptions = array($mbox);
  102. // Exclude 'prefix' namespace from parent folders list (#1488349)
  103. // If INBOX. namespace exists, folders created as INBOX subfolders
  104. // will be listed at the same level - selecting INBOX as a parent does nothing
  105. if ($prefix = $storage->get_namespace('prefix')) {
  106. $exceptions[] = substr($prefix, 0, -1);
  107. }
  108. $select = $RCMAIL->folder_selector(array(
  109. 'id' => '_parent',
  110. 'name' => '_parent',
  111. 'noselection' => '---',
  112. 'maxlength' => 150,
  113. 'unsubscribed' => true,
  114. 'skip_noinferiors' => true,
  115. 'exceptions' => $exceptions,
  116. 'additional' => strlen($selected) ? array($selected) : null,
  117. ));
  118. $form['props']['fieldsets']['location']['content']['path'] = array(
  119. 'label' => $RCMAIL->gettext('parentfolder'),
  120. 'value' => $select->show($selected),
  121. );
  122. }
  123. // Settings
  124. $form['props']['fieldsets']['settings'] = array(
  125. 'name' => $RCMAIL->gettext('settings'),
  126. );
  127. // Settings: threading
  128. if ($threading_supported && ($mbox == 'INBOX' || (!$options['noselect'] && !$options['is_root']))) {
  129. $select = new html_select(array('name' => '_viewmode', 'id' => '_viewmode'));
  130. $select->add($RCMAIL->gettext('list'), 0);
  131. $select->add($RCMAIL->gettext('threads'), 1);
  132. if (isset($_POST['_viewmode'])) {
  133. $value = (int) $_POST['_viewmode'];
  134. }
  135. else if (strlen($mbox)) {
  136. $a_threaded = $RCMAIL->config->get('message_threading', array());
  137. $default_mode = $RCMAIL->config->get('default_list_mode', 'list');
  138. $value = (int) (isset($a_threaded[$mbox]) ? $a_threaded[$mbox] : $default_mode == 'threads');
  139. }
  140. $form['props']['fieldsets']['settings']['content']['viewmode'] = array(
  141. 'label' => $RCMAIL->gettext('listmode'),
  142. 'value' => $select->show($value),
  143. );
  144. }
  145. /*
  146. // Settings: sorting column
  147. $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol'));
  148. $select->add($RCMAIL->gettext('nonesort'), '');
  149. $select->add($RCMAIL->gettext('arrival'), 'arrival');
  150. $select->add($RCMAIL->gettext('sentdate'), 'date');
  151. $select->add($RCMAIL->gettext('subject'), 'subject');
  152. $select->add($RCMAIL->gettext('fromto'), 'from');
  153. $select->add($RCMAIL->gettext('replyto'), 'replyto');
  154. $select->add($RCMAIL->gettext('cc'), 'cc');
  155. $select->add($RCMAIL->gettext('size'), 'size');
  156. $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : '';
  157. $form['props']['fieldsets']['settings']['content']['sortcol'] = array(
  158. 'label' => $RCMAIL->gettext('listsorting'),
  159. 'value' => $select->show($value),
  160. );
  161. // Settings: sorting order
  162. $select = new html_select(array('name' => '_sortord', 'id' => '_sortord'));
  163. $select->add($RCMAIL->gettext('asc'), 'ASC');
  164. $select->add($RCMAIL->gettext('desc'), 'DESC');
  165. $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : '';
  166. $form['props']['fieldsets']['settings']['content']['sortord'] = array(
  167. 'label' => $RCMAIL->gettext('listorder'),
  168. 'value' => $select->show(),
  169. );
  170. */
  171. // Information (count, size) - Edit mode
  172. if (strlen($mbox)) {
  173. // Number of messages
  174. $form['props']['fieldsets']['info'] = array(
  175. 'name' => $RCMAIL->gettext('info'),
  176. 'content' => array()
  177. );
  178. if ((!$options['noselect'] && !$options['is_root']) || $mbox == 'INBOX') {
  179. $msgcount = $storage->count($mbox, 'ALL', true, false);
  180. // Size
  181. if ($msgcount) {
  182. // create link with folder-size command
  183. $onclick = sprintf("return %s.command('folder-size', '%s', this)",
  184. rcmail_output::JS_OBJECT_NAME, rcube::JQ($mbox));
  185. $size = html::a(array('href' => '#', 'onclick' => $onclick,
  186. 'id' => 'folder-size'), $RCMAIL->gettext('getfoldersize'));
  187. }
  188. else {
  189. // no messages -> zero size
  190. $size = 0;
  191. }
  192. $form['props']['fieldsets']['info']['content']['count'] = array(
  193. 'label' => $RCMAIL->gettext('messagecount'),
  194. 'value' => (int) $msgcount
  195. );
  196. $form['props']['fieldsets']['info']['content']['size'] = array(
  197. 'label' => $RCMAIL->gettext('size'),
  198. 'value' => $size,
  199. );
  200. }
  201. // show folder type only if we have non-private namespaces
  202. if (!empty($namespace['shared']) || !empty($namespace['others'])) {
  203. $form['props']['fieldsets']['info']['content']['foldertype'] = array(
  204. 'label' => $RCMAIL->gettext('foldertype'),
  205. 'value' => $RCMAIL->gettext($options['namespace'] . 'folder'));
  206. }
  207. }
  208. // Allow plugins to modify folder form content
  209. $plugin = $RCMAIL->plugins->exec_hook('folder_form',
  210. array('form' => $form, 'options' => $options,
  211. 'name' => $mbox, 'parent_name' => $parent));
  212. $form = $plugin['form'];
  213. // Set form tags and hidden fields
  214. list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields);
  215. unset($attrib['form'], $attrib['id']);
  216. // return the complete edit form as table
  217. $out = "$form_start\n";
  218. // Create form output
  219. foreach ($form as $idx => $tab) {
  220. if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) {
  221. $content = '';
  222. foreach ($tab['fieldsets'] as $fieldset) {
  223. $subcontent = rcmail_get_form_part($fieldset, $attrib);
  224. if ($subcontent) {
  225. $subcontent = html::tag('legend', null, rcube::Q($fieldset['name'])) . $subcontent;
  226. $content .= html::tag('fieldset', null, $subcontent) ."\n";
  227. }
  228. }
  229. }
  230. else {
  231. $content = rcmail_get_form_part($tab, $attrib);
  232. }
  233. if ($idx != 'props') {
  234. $out .= html::tag('fieldset', null, html::tag('legend', null, rcube::Q($tab['name'])) . $content) ."\n";
  235. }
  236. else {
  237. $out .= $content ."\n";
  238. }
  239. }
  240. $out .= "\n$form_end";
  241. $RCMAIL->output->set_env('messagecount', (int) $msgcount);
  242. $RCMAIL->output->set_env('folder', $mbox);
  243. if ($mbox !== null && empty($_POST)) {
  244. $RCMAIL->output->command('parent.set_quota', $RCMAIL->quota_content(null, $mbox));
  245. }
  246. return $out;
  247. }
  248. function rcmail_get_form_part($form, $attrib = array())
  249. {
  250. global $RCMAIL;
  251. $content = '';
  252. if (is_array($form['content']) && !empty($form['content'])) {
  253. $table = new html_table(array('cols' => 2));
  254. foreach ($form['content'] as $col => $colprop) {
  255. $colprop['id'] = '_'.$col;
  256. $label = $colprop['label'] ?: $RCMAIL->gettext($col);
  257. $table->add('title', html::label($colprop['id'], rcube::Q($label)));
  258. $table->add(null, $colprop['value']);
  259. }
  260. $content = $table->show($attrib);
  261. }
  262. else {
  263. $content = $form['content'];
  264. }
  265. return $content;
  266. }