summaryrefslogtreecommitdiff
path: root/plugins/new_user_dialog
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2009-07-09 08:18:35 +0000
committerthomascube <thomas@roundcube.net>2009-07-09 08:18:35 +0000
commit5edb5b6634b13098ee2d72078bc317f5a770a893 (patch)
treee084fd5ea9faef2922c684f131c1804bde1ab870 /plugins/new_user_dialog
parent742d61aaf32875645f50456d263fe649db5eef0a (diff)
Create plugin to present identities settings dialog to new users
Diffstat (limited to 'plugins/new_user_dialog')
-rw-r--r--plugins/new_user_dialog/new_user_dialog.php107
-rw-r--r--plugins/new_user_dialog/newuserdialog.css48
2 files changed, 155 insertions, 0 deletions
diff --git a/plugins/new_user_dialog/new_user_dialog.php b/plugins/new_user_dialog/new_user_dialog.php
new file mode 100644
index 000000000..c49dfc019
--- /dev/null
+++ b/plugins/new_user_dialog/new_user_dialog.php
@@ -0,0 +1,107 @@
+<?php
+
+/**
+ * Present identities settings dialog to new users
+ *
+ * When a new user is created, this plugin checks the default identity
+ * and sets a session flag in case it is incomplete. An overlay box will appear
+ * on the screen until the user has reviewed/completed his identity.
+ *
+ * @version 1.0
+ * @author Thomas Bruederli
+ */
+class new_user_dialog extends rcube_plugin
+{
+ public $task = 'mail';
+
+ function init()
+ {
+ $this->add_hook('create_identity', array($this, 'create_identity'));
+
+ // register additional hooks if session flag is set
+ if ($_SESSION['plugin.newuserdialog']) {
+ $this->add_hook('render_page', array($this, 'render_page'));
+ $this->register_action('plugin.newusersave', array($this, 'save_data'));
+ }
+ }
+
+ /**
+ * Check newly created identity at first login
+ */
+ function create_identity($p)
+ {
+ // set session flag when a new user was created and the default identity seems to be incomplete
+ $rcmail = rcmail::get_instance();
+ if ($p['login'] && !$p['complete'] && (empty($p['record']['name']) || $p['record']['name'] == $rcmail->user->data['username']))
+ $_SESSION['plugin.newuserdialog'] = true;
+ }
+
+ /**
+ * Callback function when HTML page is rendered
+ * We'll add an overlay box here.
+ */
+ function render_page($p)
+ {
+ if ($_SESSION['plugin.newuserdialog'] && $p['template'] == 'mail') {
+ $rcmail = rcmail::get_instance();
+ $identity = $rcmail->user->get_identity();
+ $identities_level = intval($rcmail->config->get('identities_level', 0));
+
+ // compose user-identity dialog
+ $table = new html_table(array('cols' => 2));
+
+ $table->add('title', $this->gettext('name'));
+ $table->add(null, html::tag('input', array('type' => "text", 'name' => "_name", 'value' => $identity['name'])));
+
+ $table->add('title', $this->gettext('email'));
+ $table->add(null, html::tag('input', array('type' => "text", 'name' => "_email", 'value' => $identity['email'], 'disabled' => ($identities_level == 1 || $identities_level == 3))));
+
+ // add overlay input box to html page
+ $rcmail->output->add_footer(html::div(array('id' => "newuseroverlay"),
+ html::tag('form', array(
+ 'action' => $rcmail->url('plugin.newusersave'),
+ 'method' => "post"),
+ html::tag('h3', null, 'Please complete your sender identity') . // TODO: localize title
+ $table->show() .
+ html::p(array('class' => "formbuttons"),
+ html::tag('input', array('type' => "submit", 'class' => "button mainaction", 'value' => $this->gettext('save'))))
+ )
+ ));
+
+ $this->include_stylesheet('newuserdialog.css');
+ }
+ }
+
+ /**
+ * Handler for submitted form
+ *
+ * Check fields and save to default identity if valid.
+ * Afterwards the session flag is removed and we're done.
+ */
+ function save_data()
+ {
+ $rcmail = rcmail::get_instance();
+ $identity = $rcmail->user->get_identity();
+ $identities_level = intval($rcmail->config->get('identities_level', 0));
+
+ $save_data = array(
+ 'name' => get_input_value('_name', RCUBE_INPUT_POST),
+ 'email' => get_input_value('_email', RCUBE_INPUT_POST),
+ );
+
+ // don't let the user alter the e-mail address if disabled by config
+ if ($identities_level == 1 || $identities_level == 3)
+ $save_data['email'] = $identity['email'];
+
+ // save data if not empty
+ if (!empty($save_data['name']) && !empty($save_data['name'])) {
+ $rcmail->user->update_identity($identity['identity_id'], $save_data);
+ rcube_sess_unset('plugin.newuserdialog');
+ }
+
+ $rcmail->output->redirect('');
+ }
+
+}
+
+?> \ No newline at end of file
diff --git a/plugins/new_user_dialog/newuserdialog.css b/plugins/new_user_dialog/newuserdialog.css
new file mode 100644
index 000000000..91ea8f127
--- /dev/null
+++ b/plugins/new_user_dialog/newuserdialog.css
@@ -0,0 +1,48 @@
+/** Styles for the new-user-dialog overlay box */
+
+#newuseroverlay {
+ position: absolute;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ z-index: 10000;
+ background: rgba(0,0,0,0.5) !important;
+ background: black;
+
+ /** IE hacks */
+ -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=85)";
+ width: expression(document.documentElement.clientWidth+'px');
+ height: expression(document.documentElement.clientHeight+'px');
+}
+
+#newuseroverlay h3 {
+ color: #333;
+ font-size: normal;
+ margin-top: 0.5em;
+}
+
+#newuseroverlay form {
+ width: 30em;
+ margin: 6em auto;
+ padding: 1em 2em;
+ background: #F6F6F6;
+ border: 2px solid #999;
+}
+
+#newuseroverlay table td.title
+{
+ color: #666;
+ text-align: right;
+ padding-right: 1em;
+ white-space: nowrap;
+}
+
+#newuseroverlay table td input
+{
+ width: 20em;
+}
+
+#newuseroverlay .formbuttons {
+ text-align: center;
+} \ No newline at end of file