commit | author | age
|
5edb5b
|
1 |
<?php |
T |
2 |
|
|
3 |
/** |
|
4 |
* Present identities settings dialog to new users |
|
5 |
* |
|
6 |
* When a new user is created, this plugin checks the default identity |
|
7 |
* and sets a session flag in case it is incomplete. An overlay box will appear |
|
8 |
* on the screen until the user has reviewed/completed his identity. |
|
9 |
* |
|
10 |
* @version 1.0 |
|
11 |
* @author Thomas Bruederli |
|
12 |
*/ |
|
13 |
class new_user_dialog extends rcube_plugin |
|
14 |
{ |
fb915a
|
15 |
public $task = 'login|mail'; |
5edb5b
|
16 |
|
T |
17 |
function init() |
|
18 |
{ |
|
19 |
$this->add_hook('create_identity', array($this, 'create_identity')); |
|
20 |
|
|
21 |
// register additional hooks if session flag is set |
|
22 |
if ($_SESSION['plugin.newuserdialog']) { |
|
23 |
$this->add_hook('render_page', array($this, 'render_page')); |
|
24 |
$this->register_action('plugin.newusersave', array($this, 'save_data')); |
|
25 |
} |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Check newly created identity at first login |
|
30 |
*/ |
|
31 |
function create_identity($p) |
|
32 |
{ |
|
33 |
// set session flag when a new user was created and the default identity seems to be incomplete |
a183b7
|
34 |
if ($p['login'] && !$p['complete']) |
5edb5b
|
35 |
$_SESSION['plugin.newuserdialog'] = true; |
T |
36 |
} |
|
37 |
|
|
38 |
/** |
|
39 |
* Callback function when HTML page is rendered |
|
40 |
* We'll add an overlay box here. |
|
41 |
*/ |
|
42 |
function render_page($p) |
|
43 |
{ |
a183b7
|
44 |
if ($_SESSION['plugin.newuserdialog']) { |
T |
45 |
$this->add_texts('localization'); |
|
46 |
|
5edb5b
|
47 |
$rcmail = rcmail::get_instance(); |
T |
48 |
$identity = $rcmail->user->get_identity(); |
|
49 |
$identities_level = intval($rcmail->config->get('identities_level', 0)); |
|
50 |
|
|
51 |
// compose user-identity dialog |
|
52 |
$table = new html_table(array('cols' => 2)); |
|
53 |
|
|
54 |
$table->add('title', $this->gettext('name')); |
|
55 |
$table->add(null, html::tag('input', array('type' => "text", 'name' => "_name", 'value' => $identity['name']))); |
|
56 |
|
|
57 |
$table->add('title', $this->gettext('email')); |
|
58 |
$table->add(null, html::tag('input', array('type' => "text", 'name' => "_email", 'value' => $identity['email'], 'disabled' => ($identities_level == 1 || $identities_level == 3)))); |
|
59 |
|
|
60 |
// add overlay input box to html page |
|
61 |
$rcmail->output->add_footer(html::div(array('id' => "newuseroverlay"), |
|
62 |
html::tag('form', array( |
|
63 |
'action' => $rcmail->url('plugin.newusersave'), |
|
64 |
'method' => "post"), |
a183b7
|
65 |
html::tag('h3', null, Q($this->gettext('identitydialogtitle'))) . |
T |
66 |
html::p('hint', Q($this->gettext('identitydialoghint'))) . |
5edb5b
|
67 |
$table->show() . |
T |
68 |
html::p(array('class' => "formbuttons"), |
|
69 |
html::tag('input', array('type' => "submit", 'class' => "button mainaction", 'value' => $this->gettext('save')))) |
|
70 |
) |
|
71 |
)); |
|
72 |
|
|
73 |
$this->include_stylesheet('newuserdialog.css'); |
|
74 |
} |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Handler for submitted form |
|
79 |
* |
|
80 |
* Check fields and save to default identity if valid. |
|
81 |
* Afterwards the session flag is removed and we're done. |
|
82 |
*/ |
|
83 |
function save_data() |
|
84 |
{ |
|
85 |
$rcmail = rcmail::get_instance(); |
|
86 |
$identity = $rcmail->user->get_identity(); |
|
87 |
$identities_level = intval($rcmail->config->get('identities_level', 0)); |
|
88 |
|
|
89 |
$save_data = array( |
|
90 |
'name' => get_input_value('_name', RCUBE_INPUT_POST), |
|
91 |
'email' => get_input_value('_email', RCUBE_INPUT_POST), |
|
92 |
); |
|
93 |
|
|
94 |
// don't let the user alter the e-mail address if disabled by config |
|
95 |
if ($identities_level == 1 || $identities_level == 3) |
|
96 |
$save_data['email'] = $identity['email']; |
|
97 |
|
|
98 |
// save data if not empty |
b590cb
|
99 |
if (!empty($save_data['name']) && !empty($save_data['email'])) { |
5edb5b
|
100 |
$rcmail->user->update_identity($identity['identity_id'], $save_data); |
929a50
|
101 |
$rcmail->session->remove('plugin.newuserdialog'); |
5edb5b
|
102 |
} |
T |
103 |
|
|
104 |
$rcmail->output->redirect(''); |
|
105 |
} |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
?> |