[RCU] Vacation responder issue

omar.crea at thyme.it omar.crea at thyme.it
Wed Feb 18 15:37:51 CET 2009


Hi all, 
I want to add a vacation responder (i.e. the possibility to save a string 
to my db representing the text to display when the user set the
auto-responder 
on) to my Roundcube installation. 
I find some examples of vacation plugins on the forum, but they are 
not as I want it: I need a plugin that uses only Roundcube and read/write 
the text message of the responder from/to a db. (while the other responders

use cPanel or COM or others...)

I tried to implement the plugin basing my code on the changepasswd plugin
(see 
http://wheaties.us/blog/2008/12/21/change-password-roundcube/). 

The problem is that using this code I cannot show the current value of the
vacation 
responder text on the browser page, while I'm able to change it in the db. 

Here is what I tried to write:

--- File program/steps/settings/vacationresp.inc --- (new)
<?php
$OUTPUT->set_pagetitle(rcube_label('vacationresp'));
$OUTPUT->add_handler('vacationresp', 'rcmail_vacationresp_form');
// $OUTPUT->include_script('vacationresp.js');
$OUTPUT->add_label('vacationfailed','vacationchanged');
$OUTPUT->send('vacationresp');

function rcmail_vacationresp_form($attrib) {
    list($form_start, $form_end) = get_form_tags($attrib,
'save_vacationresp');
    unset($attrib['form']);
    
    // return the complete edit form as table
    $out = $form_start;
    $table = new html_table(array('cols' => 2));


    if (!isset($no_override['curvacation']))
    {   
        $field_id = 'rcmfd_curvac';
        //$input_curvac = new html_textarea(array('name' => '_curvacation',
'id' => $field_id));
        $input_curvac = new html_textarea(array('name' => '_curvacation',
'id' => $field_id, 'size' => 40));

        $table->add('title', html::label($field_id,
Q(rcube_label('curvacation'))));
        //$table->add(null, $input_curvac->show());
        $table->add(null, $input_curvac->show('_vacation'));
        // $table->add(null, $input_curvac->show($show_vacation));
    }
    $out .= $table->show($attrib);
    $out .= $form_end;

    return $out;
}
?>

--- File program/steps/settings/save_vacationresp.inc --- (new)
<?php
require_once('plugins/vacationresp/config.inc.php');

$old_vac = $_POST['_curvacation'];
$sql_select = str_replace(array('%u'), 
                array($_SESSION['username']),
                $vacationresp_config['sql_select']);
$sql_update = str_replace(array('%u', '%o'), 
                array($_SESSION['username'], $old_vac),
                $vacationresp_config['sql_update']);
$user_db = new rcube_mdb2($vacationresp_config['db_dsnw'],
$vacationresp_config['db_dsnr'], $vacationresp_config['db_persistent']);
$user_db->db_connect('w');

if ($err_str = $user_db->is_error()) {
  raise_error(array(
    'code' => 603,
    'type' => 'db',
    'message' => $err_str), FALSE, TRUE);
}
$user_db->query($sql_select);

if ($user_db->num_rows() == 1) {
    $updated = false;
    $updated = $user_db->query($sql_update);

    if ($updated) {
        $OUTPUT->show_message('vacationchanged', 'confirmation');
    }
    else {
        $OUTPUT->show_message('vacationfailed', 'error');
    }
}
else {
    $OUTPUT->show_message('vacationfailed', 'error');
}
rcmail_overwrite_action('vacationresp');
?>

--- File program/js/app.js --- (modified)
      case 'settings':
        this.enable_command('preferences', 'identities', 'save', 'folders',
'changepasswd', 'vacationresp', true);

        if (this.env_action='vacationresp')
          this.enable_command('save_vacationresp', true);

      case 'vacationresp':
        this.goto_url('vacationresp');
        break;

      case 'save_vacationresp':
        this.gui_objects.editform.submit();
        break;

--- File program/plugins/vacationresp/config.inc.php --- (new)
<?php
$vacationresp_config = array();
$vacationresp_config['db_dsnw'] =
'mysql://roundcube:round@localhost/roundcubemail';
$vacationresp_config['db_dsnr'] = ''; 
$vacationresp_config['db_persistent'] = FALSE;
$vacationresp_config['sql_select'] = "SELECT username FROM users WHERE
username = '%u';";
$vacationresp_config['sql_update'] = "UPDATE users SET vacation = '%o'
WHERE username = '%u';";
?>

--- File program/plugins/vacationresp/vacationresp.php
<?php
class vacationresp extends rcube_plugin
{
    function init()
    {   
        // preperation for Plugin API
        // not used yet
    }   
}
?>

--- File skins/default/templates/vacationresp.html --- (new)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<link rel="stylesheet" type="text/css" href="/settings.css" />
<script type="text/javascript" src="/functions.js"></script>
</head>
<body onload="rcube_init_settings_tabs()">
<roundcube:include file="/includes/taskbar.html" />
<roundcube:include file="/includes/header.html" />
<roundcube:include file="/includes/settingstabs.html" />
<div id="userprefs-box">
<div id="userprefs-title"><roundcube:label name="vacation" /></div>
<div style="padding:15px 0 15px 15px">
<roundcube:object name="vacationresp" />
<div style="clear:left"></div>    
</div>
</div>
<p id="listbuttons"><roundcube:button command="save_vacationresp"
type="input" class="button mainaction" label="save" /></p>    
</body>
</html>

--- File skins/default/includes/settingstabs.html --- (modified)
<span id="settingstabvacationresp" class="tablink"><roundcube:button
command="vacationresp" type="link" label="vacation" title="vacationresp"
class="tablink" /></span>

Someone knows how to pass the current vacation text value to the showed
page? 
Thanks in advance. 



_______________________________________________
List info: http://lists.roundcube.net/users/



More information about the users mailing list