Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

edit.inc 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------+
  4. | program/steps/addressbook/edit.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. | Show edit form for a contact entry or to add a new one |
  15. | |
  16. +-----------------------------------------------------------------------+
  17. | Author: Thomas Bruederli <roundcube@gmail.com> |
  18. +-----------------------------------------------------------------------+
  19. */
  20. if ($RCMAIL->action == 'edit') {
  21. // Get contact ID and source ID from request
  22. $cids = rcmail_get_cids();
  23. $source = key($cids);
  24. $cid = array_shift($cids[$source]);
  25. // Initialize addressbook
  26. $CONTACTS = rcmail_contact_source($source, true);
  27. // Contact edit
  28. if ($cid && ($record = $CONTACTS->get_record($cid, true))) {
  29. $OUTPUT->set_env('cid', $record['ID']);
  30. }
  31. // editing not allowed here
  32. if ($CONTACTS->readonly || $record['readonly']) {
  33. $OUTPUT->show_message('sourceisreadonly');
  34. $RCMAIL->overwrite_action('show');
  35. return;
  36. }
  37. }
  38. else {
  39. $source = rcube_utils::get_input_value('_source', rcube_utils::INPUT_GPC);
  40. if (strlen($source)) {
  41. $CONTACTS = $RCMAIL->get_address_book($source, true);
  42. }
  43. if (!$CONTACTS || $CONTACTS->readonly) {
  44. $CONTACTS = $RCMAIL->get_address_book(-1, true);
  45. $source = $RCMAIL->get_address_book_id($CONTACTS);
  46. }
  47. // Initialize addressbook
  48. $CONTACTS = rcmail_contact_source($source, true);
  49. }
  50. $SOURCE_ID = $source;
  51. rcmail_set_sourcename($CONTACTS);
  52. $OUTPUT->add_handlers(array(
  53. 'contactedithead' => 'rcmail_contact_edithead',
  54. 'contacteditform' => 'rcmail_contact_editform',
  55. 'contactphoto' => 'rcmail_contact_photo',
  56. 'photouploadform' => 'rcmail_upload_photo_form',
  57. 'sourceselector' => 'rcmail_source_selector',
  58. 'filedroparea' => 'rcmail_photo_drop_area',
  59. ));
  60. $OUTPUT->set_pagetitle($RCMAIL->gettext(($RCMAIL->action == 'add' ? 'addcontact' : 'editcontact')));
  61. if ($RCMAIL->action == 'add' && $OUTPUT->template_exists('contactadd')) {
  62. $OUTPUT->send('contactadd');
  63. }
  64. // this will be executed if no template for addcontact exists
  65. $OUTPUT->send('contactedit');
  66. function rcmail_get_edit_record()
  67. {
  68. global $RCMAIL, $CONTACTS;
  69. // check if we have a valid result
  70. if ($GLOBALS['EDIT_RECORD']) {
  71. $record = $GLOBALS['EDIT_RECORD'];
  72. }
  73. else if ($RCMAIL->action != 'add'
  74. && !(($result = $CONTACTS->get_result()) && ($record = $result->first()))
  75. ) {
  76. $RCMAIL->output->show_message('contactnotfound', 'error');
  77. return false;
  78. }
  79. return $record;
  80. }
  81. function rcmail_contact_edithead($attrib)
  82. {
  83. global $RCMAIL;
  84. // check if we have a valid result
  85. $record = rcmail_get_edit_record();
  86. $i_size = $attrib['size'] ?: 20;
  87. $form = array(
  88. 'head' => array(
  89. 'name' => $RCMAIL->gettext('contactnameandorg'),
  90. 'content' => array(
  91. 'prefix' => array('size' => $i_size),
  92. 'firstname' => array('size' => $i_size, 'visible' => true),
  93. 'middlename' => array('size' => $i_size),
  94. 'surname' => array('size' => $i_size, 'visible' => true),
  95. 'suffix' => array('size' => $i_size),
  96. 'name' => array('size' => 2*$i_size),
  97. 'nickname' => array('size' => 2*$i_size),
  98. 'organization' => array('size' => 2*$i_size),
  99. 'department' => array('size' => 2*$i_size),
  100. 'jobtitle' => array('size' => 2*$i_size),
  101. )
  102. )
  103. );
  104. list($form_start, $form_end) = get_form_tags($attrib);
  105. unset($attrib['form'], $attrib['name'], $attrib['size']);
  106. // return the address edit form
  107. $out = rcmail_contact_form($form, $record, $attrib);
  108. return $form_start . $out . $form_end;
  109. }
  110. function rcmail_contact_editform($attrib)
  111. {
  112. global $RCMAIL, $CONTACT_COLTYPES;
  113. $record = rcmail_get_edit_record();
  114. // copy (parsed) address template to client
  115. if (preg_match_all('/\{([a-z0-9]+)\}([^{]*)/i', $RCMAIL->config->get('address_template', ''), $templ, PREG_SET_ORDER))
  116. $RCMAIL->output->set_env('address_template', $templ);
  117. $i_size = $attrib['size'] ?: 40;
  118. $t_rows = $attrib['textarearows'] ?: 10;
  119. $t_cols = $attrib['textareacols'] ?: 40;
  120. $form = array(
  121. 'contact' => array(
  122. 'name' => $RCMAIL->gettext('properties'),
  123. 'content' => array(
  124. 'email' => array('size' => $i_size, 'visible' => true),
  125. 'phone' => array('size' => $i_size, 'visible' => true),
  126. 'address' => array('visible' => true),
  127. 'website' => array('size' => $i_size),
  128. 'im' => array('size' => $i_size),
  129. ),
  130. ),
  131. 'personal' => array(
  132. 'name' => $RCMAIL->gettext('personalinfo'),
  133. 'content' => array(
  134. 'gender' => array('visible' => true),
  135. 'maidenname' => array('size' => $i_size),
  136. 'birthday' => array('visible' => true),
  137. 'anniversary' => array(),
  138. 'manager' => array('size' => $i_size),
  139. 'assistant' => array('size' => $i_size),
  140. 'spouse' => array('size' => $i_size),
  141. ),
  142. ),
  143. );
  144. if (isset($CONTACT_COLTYPES['notes'])) {
  145. $form['notes'] = array(
  146. 'name' => $RCMAIL->gettext('notes'),
  147. 'content' => array(
  148. 'notes' => array('size' => $t_cols, 'rows' => $t_rows, 'label' => false, 'visible' => true, 'limit' => 1),
  149. ),
  150. 'single' => true,
  151. );
  152. }
  153. list($form_start, $form_end) = get_form_tags($attrib);
  154. unset($attrib['form']);
  155. // return the complete address edit form as table
  156. $out = rcmail_contact_form($form, $record, $attrib);
  157. return $form_start . $out . $form_end;
  158. }
  159. function rcmail_upload_photo_form($attrib)
  160. {
  161. global $RCMAIL, $OUTPUT;
  162. // set defaults
  163. $attrib += array('id' => 'rcmUploadform', 'buttons' => 'yes');
  164. // find max filesize value
  165. $max_filesize = parse_bytes(ini_get('upload_max_filesize'));
  166. $max_postsize = parse_bytes(ini_get('post_max_size'));
  167. if ($max_postsize && $max_postsize < $max_filesize) {
  168. $max_filesize = $max_postsize;
  169. }
  170. $max_filesize = $RCMAIL->show_bytes($max_filesize);
  171. $hidden = new html_hiddenfield(array('name' => '_cid', 'value' => $GLOBALS['cid']));
  172. $input = new html_inputfield(array('type' => 'file', 'name' => '_photo', 'size' => $attrib['size']));
  173. $button = new html_inputfield(array('type' => 'button'));
  174. $content = $hidden->show() . html::div(null, $input->show())
  175. . html::div('hint', $RCMAIL->gettext(array('name' => 'maxuploadsize', 'vars' => array('size' => $max_filesize))));
  176. if (rcube_utils::get_boolean($attrib['buttons'])) {
  177. $content .= html::div('buttons',
  178. $button->show($RCMAIL->gettext('close'), array(
  179. 'class' => 'button',
  180. 'onclick' => "$('#$attrib[id]').hide()"
  181. ))
  182. . ' ' .
  183. $button->show($RCMAIL->gettext('upload'), array(
  184. 'class' => 'button mainaction',
  185. 'onclick' => rcmail_output::JS_OBJECT_NAME . ".command('upload-photo', this.form)"
  186. ))
  187. );
  188. }
  189. $out = html::div($attrib,
  190. $OUTPUT->form_tag(array(
  191. 'id' => $attrib['id'] . 'Frm',
  192. 'name' => 'uploadform',
  193. 'method' => 'post',
  194. 'enctype' => 'multipart/form-data'
  195. ),
  196. $content
  197. )
  198. );
  199. $OUTPUT->add_label('addphoto','replacephoto');
  200. $OUTPUT->add_gui_object('uploadform', $attrib['id'].'Frm');
  201. return $out;
  202. }
  203. // similar function as in /steps/settings/edit_identity.inc
  204. function get_form_tags($attrib)
  205. {
  206. global $CONTACTS, $EDIT_FORM, $RCMAIL, $SOURCE_ID;
  207. $form_start = $form_end = '';
  208. if (empty($EDIT_FORM)) {
  209. $hiddenfields = new html_hiddenfield();
  210. if ($RCMAIL->action == 'edit')
  211. $hiddenfields->add(array('name' => '_source', 'value' => $SOURCE_ID));
  212. $hiddenfields->add(array('name' => '_gid', 'value' => $CONTACTS->group_id));
  213. $hiddenfields->add(array('name' => '_search', 'value' => rcube_utils::get_input_value('_search', rcube_utils::INPUT_GPC)));
  214. if (($result = $CONTACTS->get_result()) && ($record = $result->first()))
  215. $hiddenfields->add(array('name' => '_cid', 'value' => $record['ID']));
  216. $form_start = $RCMAIL->output->request_form(array(
  217. 'name' => "form", 'method' => "post",
  218. 'task' => $RCMAIL->task, 'action' => 'save',
  219. 'request' => 'save.'.intval($record['ID']),
  220. 'noclose' => true) + $attrib, $hiddenfields->show());
  221. $form_end = !strlen($attrib['form']) ? '</form>' : '';
  222. $EDIT_FORM = $attrib['form'] ?: 'form';
  223. $RCMAIL->output->add_gui_object('editform', $EDIT_FORM);
  224. }
  225. return array($form_start, $form_end);
  226. }
  227. function rcmail_source_selector($attrib)
  228. {
  229. global $RCMAIL, $SOURCE_ID;
  230. $sources_list = $RCMAIL->get_address_sources(true, true);
  231. if (count($sources_list) < 2) {
  232. $source = $sources_list[$SOURCE_ID];
  233. $hiddenfield = new html_hiddenfield(array('name' => '_source', 'value' => $SOURCE_ID));
  234. return html::span($attrib, $source['name'] . $hiddenfield->show());
  235. }
  236. $attrib['name'] = '_source';
  237. $attrib['is_escaped'] = true;
  238. $attrib['onchange'] = rcmail_output::JS_OBJECT_NAME . ".command('save', 'reload', this.form)";
  239. $select = new html_select($attrib);
  240. foreach ($sources_list as $source)
  241. $select->add($source['name'], $source['id']);
  242. return $select->show($SOURCE_ID);
  243. }
  244. /**
  245. * Register container as active area to drop photos onto
  246. */
  247. function rcmail_photo_drop_area($attrib)
  248. {
  249. global $OUTPUT;
  250. if ($attrib['id']) {
  251. $OUTPUT->add_gui_object('filedrop', $attrib['id']);
  252. $OUTPUT->set_env('filedrop', array('action' => 'upload-photo', 'fieldname' => '_photo', 'single' => 1, 'filter' => '^image/.+'));
  253. }
  254. }