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.

new_user_dialog.php 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <?php
  2. /**
  3. * Present identities settings dialog to new users
  4. *
  5. * When a new user is created, this plugin checks the default identity
  6. * and sets a session flag in case it is incomplete. An overlay box will appear
  7. * on the screen until the user has reviewed/completed his identity.
  8. *
  9. * @version @package_version@
  10. * @license GNU GPLv3+
  11. * @author Thomas Bruederli
  12. * @author Aleksander Machniak
  13. */
  14. class new_user_dialog extends rcube_plugin
  15. {
  16. public $task = '';
  17. public $noframe = true;
  18. function init()
  19. {
  20. $this->add_hook('identity_create', array($this, 'create_identity'));
  21. $this->register_action('plugin.newusersave', array($this, 'save_data'));
  22. // register additional hooks if session flag is set
  23. if ($_SESSION['plugin.newuserdialog']) {
  24. $this->add_hook('render_page', array($this, 'render_page'));
  25. }
  26. }
  27. /**
  28. * Check newly created identity at first login
  29. */
  30. function create_identity($p)
  31. {
  32. // set session flag when a new user was created and the default identity seems to be incomplete
  33. if ($p['login'] && !$p['complete']) {
  34. $_SESSION['plugin.newuserdialog'] = true;
  35. }
  36. }
  37. /**
  38. * Callback function when HTML page is rendered
  39. * We'll add an overlay box here.
  40. */
  41. function render_page($p)
  42. {
  43. if ($_SESSION['plugin.newuserdialog']) {
  44. $this->add_texts('localization');
  45. $rcmail = rcmail::get_instance();
  46. $identity = $rcmail->user->get_identity();
  47. $identities_level = intval($rcmail->config->get('identities_level', 0));
  48. // compose user-identity dialog
  49. $table = new html_table(array('cols' => 2));
  50. $table->add('title', $this->gettext('name'));
  51. $table->add(null, html::tag('input', array(
  52. 'type' => 'text',
  53. 'name' => '_name',
  54. 'value' => $identity['name'],
  55. 'disabled' => $identities_level == 4
  56. )));
  57. $table->add('title', $this->gettext('email'));
  58. $table->add(null, html::tag('input', array(
  59. 'type' => 'text',
  60. 'name' => '_email',
  61. 'value' => rcube_utils::idn_to_utf8($identity['email']),
  62. 'disabled' => in_array($identities_level, array(1, 3, 4))
  63. )));
  64. $table->add('title', $this->gettext('organization'));
  65. $table->add(null, html::tag('input', array(
  66. 'type' => 'text',
  67. 'name' => '_organization',
  68. 'value' => $identity['organization'],
  69. 'disabled' => $identities_level == 4
  70. )));
  71. $table->add('title', $this->gettext('signature'));
  72. $table->add(null, html::tag('textarea', array(
  73. 'name' => '_signature',
  74. 'rows' => '3',
  75. ),
  76. $identity['signature']
  77. ));
  78. // add overlay input box to html page
  79. $rcmail->output->add_footer(html::tag('form', array(
  80. 'id' => 'newuserdialog',
  81. 'action' => $rcmail->url('plugin.newusersave'),
  82. 'method' => 'post'
  83. ),
  84. html::p('hint', rcube::Q($this->gettext('identitydialoghint'))) .
  85. $table->show() .
  86. html::p(array('class' => 'formbuttons'),
  87. html::tag('input', array('type' => 'submit',
  88. 'class' => 'button mainaction', 'value' => $this->gettext('save'))))
  89. ));
  90. $title = rcube::JQ($this->gettext('identitydialogtitle'));
  91. $script = "
  92. $('#newuserdialog').show()
  93. .dialog({modal:true, resizable:false, closeOnEscape:false, width:450, title:'$title'})
  94. .submit(function() {
  95. var i, request = {}, form = $(this).serializeArray();
  96. for (i in form)
  97. request[form[i].name] = form[i].value;
  98. rcmail.http_post('plugin.newusersave', request, true);
  99. return false;
  100. });
  101. $('input[name=_name]').focus();
  102. rcube_webmail.prototype.new_user_dialog_close = function() { $('#newuserdialog').dialog('close'); }
  103. ";
  104. // disable keyboard events for messages list (#1486726)
  105. $rcmail->output->add_script($script, 'docready');
  106. $this->include_stylesheet('newuserdialog.css');
  107. }
  108. }
  109. /**
  110. * Handler for submitted form (ajax request)
  111. *
  112. * Check fields and save to default identity if valid.
  113. * Afterwards the session flag is removed and we're done.
  114. */
  115. function save_data()
  116. {
  117. $rcmail = rcmail::get_instance();
  118. $identity = $rcmail->user->get_identity();
  119. $ident_level = intval($rcmail->config->get('identities_level', 0));
  120. $disabled = array();
  121. $save_data = array(
  122. 'name' => rcube_utils::get_input_value('_name', rcube_utils::INPUT_POST),
  123. 'email' => rcube_utils::get_input_value('_email', rcube_utils::INPUT_POST),
  124. 'organization' => rcube_utils::get_input_value('_organization', rcube_utils::INPUT_POST),
  125. 'signature' => rcube_utils::get_input_value('_signature', rcube_utils::INPUT_POST),
  126. );
  127. if ($ident_level == 4) {
  128. $disabled = array('name', 'email', 'organization');
  129. }
  130. else if (in_array($ident_level, array(1, 3))) {
  131. $disabled = array('email');
  132. }
  133. foreach ($disabled as $key) {
  134. $save_data[$key] = $identity[$key];
  135. }
  136. if (empty($save_data['name']) || empty($save_data['email'])) {
  137. $rcmail->output->show_message('formincomplete', 'error');
  138. }
  139. else if (!rcube_utils::check_email($save_data['email'] = rcube_utils::idn_to_ascii($save_data['email']))) {
  140. $rcmail->output->show_message('emailformaterror', 'error', array('email' => $save_data['email']));
  141. }
  142. else {
  143. // save data
  144. $rcmail->user->update_identity($identity['identity_id'], $save_data);
  145. $rcmail->session->remove('plugin.newuserdialog');
  146. // hide dialog
  147. $rcmail->output->command('new_user_dialog_close');
  148. $rcmail->output->show_message('successfullysaved', 'confirmation');
  149. }
  150. $rcmail->output->send();
  151. }
  152. }