/**
  * Generate the add / edit account form
  * @param type $attrib
  * @return string html of the form
  */
 function gen_form($attrib)
 {
     require_once dirname(__FILE__) . '/includes/fetchMailRc.php';
     $fetchmail_rc_id = get_input_value('_fetchmail_rc_id', RCUBE_INPUT_GET);
     $fetchmailDatas = new fetchMailRc($fetchmail_rc_id);
     // Show hidden input with the id
     $hidden_id = new html_hiddenfield(array("id" => "_fetchmail_rc_id", "name" => "_fetchmail_rc_id", "value" => $fetchmail_rc_id));
     $formToReturn .= '<form action="" id="fetchmail_rc_form" class="propform"><fieldset><legend>' . $this->gettext("configuration") . '</legend>' . ($formToReturn .= $hidden_id->show());
     $formToReturn .= '<table class="propform">';
     // Mail host
     $field_name = "_mail_host";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_host'))) . ' <span class="required">*</span></td><td>';
     $input_name = new html_inputfield(array('name' => $field_name, 'id' => $field_name, 'value' => $fetchmailDatas->get_mail_host()));
     $formToReturn .= $input_name->show() . "</td></tr>";
     // Mail host
     $field_name = "_mail_ssl";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_ssl'))) . '</td><td>';
     $input_ssl = new html_checkbox(array('name' => $field_name, 'id' => $field_name, "value" => 1));
     $formToReturn .= $input_ssl->show($fetchmailDatas->get_mail_ssl()) . "</td></tr>";
     // Mail Login
     $field_name = "_mail_username";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_username'))) . ' <span class="required">*</span></td><td>';
     $input_username = new html_inputfield(array('name' => $field_name, 'id' => $field_name, 'value' => $fetchmailDatas->get_mail_username()));
     $formToReturn .= $input_username->show() . "</td></tr>";
     // Mail password
     $field_name = "_mail_password";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_password'))) . ' <span class="required">*</span></td><td>';
     $input_password = new html_passwordfield(array('name' => $field_name, 'id' => $field_name));
     $formToReturn .= $input_password->show() . "</td></tr>";
     // Mail arguments
     $field_name = "_mail_arguments";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_arguments'))) . '</td><td>';
     $input_arguments = new html_inputfield(array('name' => $field_name, 'id' => $field_name, 'value' => $fetchmailDatas->get_mail_arguments()));
     $formToReturn .= $input_arguments->show() . "</td></tr>";
     // Mail protocol
     $field_name = "_mail_protocol";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_protocol'))) . ' <span class="required">*</span></td><td>';
     $input_protocol = new html_select(array('name' => $field_name, 'id' => $field_name));
     $input_protocol->add(fetchMailRc::PROTOCOL_AUTO, fetchMailRc::PROTOCOL_AUTO);
     $input_protocol->add(fetchMailRc::PROTOCOL_IMAP, fetchMailRc::PROTOCOL_IMAP);
     $input_protocol->add(fetchMailRc::PROTOCOL_POP2, fetchMailRc::PROTOCOL_POP2);
     $input_protocol->add(fetchMailRc::PROTOCOL_POP3, fetchMailRc::PROTOCOL_POP3);
     $formToReturn .= $input_protocol->show($fetchmailDatas->get_mail_protocol()) . "</td></tr>";
     // Mail disabled
     $field_name = "_mail_disabled";
     $formToReturn .= '<tr><td class="title">' . html::label($field_name, Q($this->gettext('mail_disabled'))) . '</td><td>';
     $input_enabled = new html_checkbox(array('name' => $field_name, 'id' => $field_name, "value" => 1));
     if ($fetchmail_rc_id) {
         $formToReturn .= $input_enabled->show(!$fetchmailDatas->get_enabled()) . "</td></tr>";
     } else {
         $formToReturn .= $input_enabled->show(0) . "</td></tr>";
     }
     $formToReturn .= "</table></fieldset>";
     // Show the test and debug block
     $formToReturn .= "<fieldset>";
     $formToReturn .= "<legend>" . $this->gettext("accountstatus") . "</legend>";
     $formToReturn .= '<table class="propform">';
     $formToReturn .= '<tr>';
     $formToReturn .= '<td class="title">' . $this->gettext("lastimport") . "</td>";
     $formToReturn .= "<td>" . $fetchmailDatas->get_date_last_retrieve() . "</td>";
     $formToReturn .= "</tr>";
     $formToReturn .= '<tr>';
     $formToReturn .= '<td class="title">' . $this->gettext("status") . "</td>";
     $statusMessage = $this->gettext("status_successful");
     if ($fetchmailDatas->get_count_errors() > 0) {
         $statusMessage = "<b>" . $this->gettext("errorlabel") . "</b> : " . $fetchmailDatas->get_last_error() . "<br />";
         $statusMessage .= "<b>" . $this->gettext("nbconsecutiveserrors") . "</b> : " . $fetchmailDatas->get_count_errors();
     }
     $formToReturn .= "<td>" . ($fetchmailDatas->get_date_last_retrieve() == "0000-00-00 00:00:00" ? $this->gettext("notalreadyautoimported") : $statusMessage) . "</td>";
     $formToReturn .= "</tr>";
     $formToReturn .= '<tr>';
     $formToReturn .= '<td class="title">' . $this->gettext("testaccount") . '</td>';
     $formToReturn .= '<td><a href="javascript:;" onclick="return rcmail.command(\'plugin.fetchmail_rc.test_account\',\'\',this)">' . $this->gettext("testaccount") . '</a></td>';
     $formToReturn .= '</tr>';
     $formToReturn .= '<tr>';
     $formToReturn .= '<td class="title">' . $this->gettext("forceretrieve") . '</td>';
     $formToReturn .= '<td><a href="javascript:;" onclick="return rcmail.command(\'plugin.fetchmail_rc.forceretrieve\',\'\',this)">' . $this->gettext("forceretrieve") . '</a></td>';
     $formToReturn .= '</tr>';
     $formToReturn .= "</table>";
     $formToReturn .= "</fieldset>";
     $formToReturn .= "</form>";
     return $formToReturn;
 }