Author Topic: Vacation responder issue  (Read 3695 times)

Offline ramo102

  • Newbie
  • *
  • Posts: 5
Vacation responder issue
« on: February 18, 2009, 09:40:17 AM »
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
wheaties.us || Andy and Natasha Wheatley's Blog).

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)

Code: [Select]
<?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)

Code: [Select]
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)

Code: [Select]
     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)

Code: [Select]
$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

Code: [Select]
class vacationresp extends rcube_plugin
{
    function init()
    {  
        // preperation for Plugin API
        // not used yet
    }  
}
?>


--- File skins/default/templates/vacationresp.html --- (new)

Code: [Select]
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<roundcube:object name="pagetitle" />












   


type="input" class="button mainaction" label="save" />

   



--- File skins/default/includes/settingstabs.html --- (modified)

Code: [Select]
command="vacationresp" type="link" label="vacation" title="vacationresp"
class="tablink" />


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

Offline ramo102

  • Newbie
  • *
  • Posts: 5
Vacation responder issue
« Reply #1 on: February 23, 2009, 07:18:38 AM »
None can answer me? :(
If I posted in the wrong place, tell me...