function setDefaults()
 {
     require_once PHPGW_INCLUDE_ROOT . '/felamimail/inc/class.felamimail_bosignatures.inc.php';
     $boSignatures = new felamimail_bosignatures();
     if ($signatureData = $boSignatures->getDefaultSignature()) {
         if (is_array($signatureData)) {
             $this->sessionData['signatureID'] = $signatureData['signatureid'];
         } else {
             $this->sessionData['signatureID'] = $signatureData;
         }
     } else {
         $this->sessionData['signatureID'] = -1;
     }
     // retrieve the signature accociated with the identity
     $accountData = $this->bopreferences->getAccountData($this->preferences, 'active');
     if ($accountData['identity']->signature) {
         $this->sessionData['signatureID'] = $accountData['identity']->signature;
     }
     // apply the current mailbox to the compose session data of the/a new email
     $appsessionData = $GLOBALS['phpgw']->session->appsession('session_data');
     $this->sessionData['mailbox'] = $appsessionData['mailbox'];
     $this->sessionData['mimeType'] = 'html';
     if (!empty($this->preferencesArray['composeOptions']) && $this->preferencesArray['composeOptions'] == "text") {
         $this->sessionData['mimeType'] = 'text/plain';
     }
     $this->saveSessionData();
 }
 function compose($_focusElement = 'to')
 {
     // read the data from session
     // all values are empty for a new compose window
     $sessionData = $this->bocompose->getSessionData();
     if (is_array($_REQUEST['preset'])) {
         if ($_REQUEST['preset']['file'] && is_readable($_REQUEST['preset']['file'])) {
             $this->bocompose->addAttachment(array_merge($sessionData, $_REQUEST['preset']));
             $sessionData = $this->bocompose->getSessionData();
         }
         foreach (array('to', 'cc', 'bcc', 'subject', 'body') as $name) {
             if ($_REQUEST['preset'][$name]) {
                 $sessionData[$name] = $_REQUEST['preset'][$name];
             }
         }
     }
     // is the to address set already?
     if (!empty($_REQUEST['send_to'])) {
         $sessionData['to'] = base64_decode($_REQUEST['send_to']);
     }
     //is the MimeType set/requested
     if (!empty($_REQUEST['mimeType'])) {
         $sessionData['mimeType'] = $_REQUEST['mimeType'];
     }
     // is a certain signature requested?
     // only the following values are supported (and make sense)
     // no => means -2
     // system => means -1
     // default => fetches the default, which is standard behavior
     if (!empty($_REQUEST['signature']) && (strtolower($_REQUEST['signature']) == 'no' || strtolower($_REQUEST['signature']) == 'system')) {
         $presetSig = strtolower($_REQUEST['signature']) == 'no' ? -2 : -1;
     }
     $this->display_app_header();
     $this->t->set_file(array("composeForm" => "composeForm.tpl"));
     $this->t->set_block('composeForm', 'header', 'header');
     $this->t->set_block('composeForm', 'body_input');
     $this->t->set_block('composeForm', 'attachment', 'attachment');
     $this->t->set_block('composeForm', 'attachment_row', 'attachment_row');
     $this->t->set_block('composeForm', 'attachment_row_bold');
     $this->t->set_block('composeForm', 'destination_row');
     $this->t->set_block('composeForm', 'simple_text');
     $this->translate();
     /*		$this->t->set_var("link_addressbook",$GLOBALS['phpgw']->link('/index.php',array(
     				'menuaction' => 'addressbook.addressbook_ui.emailpopup'
     			),true));
     */
     $this->t->set_var("link_addressbook", $GLOBALS['phpgw']->link('/felamimail/addressbook.php', false, true));
     $this->t->set_var("focusElement", $_focusElement);
     $linkData = array('menuaction' => 'felamimail.uicompose.selectFolder');
     $this->t->set_var('folder_select_url', $GLOBALS['phpgw']->link('/index.php', $linkData, true));
     $linkData = array('menuaction' => 'felamimail.uicompose.fileSelector', 'composeid' => $this->composeID);
     $this->t->set_var('file_selector_url', $GLOBALS['phpgw']->link('/index.php', $linkData, true));
     $linkData = array('menuaction' => 'felamimail.uicompose.action', 'composeid' => $this->composeID);
     $this->t->set_var("link_action", $GLOBALS['phpgw']->link('/index.php', $linkData, true));
     $this->t->set_var('folder_name', $this->bofelamimail->sessionData['mailbox']);
     $this->t->set_var('compose_id', $this->composeID);
     // check for some error messages from last posting attempt
     if ($errorInfo = $this->bocompose->getErrorInfo()) {
         $this->t->set_var('errorInfo', "<font color=\"red\"><b>{$errorInfo}</b></font>");
     } else {
         $this->t->set_var('errorInfo', '&nbsp;');
     }
     // header
     $allIdentities = $this->mailPreferences->getIdentity();
     #_debug_array($allIdentities);
     $defaultIdentity = 0;
     foreach ($allIdentities as $key => $singleIdentity) {
         #$identities[$singleIdentity->id] = $singleIdentity->realName.' <'.$singleIdentity->emailAddress.'>';
         $identities[$key] = $singleIdentity->realName . ' <' . $singleIdentity->emailAddress . '>';
         if (!empty($singleIdentity->default)) {
             #$defaultIdentity = $singleIdentity->id;
             $defaultIdentity = $key;
             $sessionData['signatureID'] = $singleIdentity->signature;
         }
     }
     $selectFrom = html::select('identity', $defaultIdentity, $identities, true, "style='width:100%;' onchange='changeIdentity(this);'");
     $this->t->set_var('select_from', $selectFrom);
     // navbar(, kind of)
     $this->t->set_var('img_clear_left', $GLOBALS['phpgw']->common->image('felamimail', 'clear_left'));
     $this->t->set_var('img_fileopen', $GLOBALS['phpgw']->common->image('phpgwapi', 'fileopen'));
     $this->t->set_var('img_mail_send', $GLOBALS['phpgw']->common->image('felamimail', 'mail_send'));
     $this->t->set_var('img_attach_file', $GLOBALS['phpgw']->common->image('felamimail', 'attach'));
     $this->t->set_var('ajax-loader', $GLOBALS['phpgw']->common->image('felamimail', 'ajax-loader'));
     $this->t->set_var('img_fileexport', $GLOBALS['phpgw']->common->image('felamimail', 'fileexport'));
     // prepare print url/button
     $this->t->set_var('img_print_it', $GLOBALS['phpgw']->common->image('felamimail', 'fileprint'));
     $this->t->set_var('lang_print_it', lang('print it'));
     $this->t->set_var('print_it', $printURL);
     // from, to, cc, replyto
     $destinationRows = 0;
     foreach (array('to', 'cc', 'bcc', 'replyto', 'folder') as $destination) {
         foreach ((array) $sessionData[$destination] as $key => $value) {
             $selectDestination = html::select('destination[]', $destination, $this->destinations, false, "style='width: 100%;' onchange='fm_compose_changeInputType(this)'");
             $this->t->set_var('select_destination', $selectDestination);
             $this->t->set_var('address', @htmlentities($value, ENT_QUOTES, $this->displayCharset));
             $this->t->parse('destinationRows', 'destination_row', True);
             $destinationRows++;
         }
     }
     while ($destinationRows < 3) {
         // and always add one empty row
         $selectDestination = html::select('destination[]', 'to', $this->destinations, false, "style='width: 100%;' onchange='fm_compose_changeInputType(this)'");
         $this->t->set_var('select_destination', $selectDestination);
         $this->t->set_var('address', '');
         $this->t->parse('destinationRows', 'destination_row', True);
         $destinationRows++;
     }
     // and always add one empty row
     $selectDestination = html::select('destination[]', 'to', $this->destinations, false, "style='width: 100%;' onchange='fm_compose_changeInputType(this)'");
     $this->t->set_var('select_destination', $selectDestination);
     $this->t->set_var('address', '');
     $this->t->parse('destinationRows', 'destination_row', True);
     $this->t->set_var("subject", @htmlentities($sessionData['subject'], ENT_QUOTES, $this->displayCharset));
     $this->t->set_var('addressbookImage', $GLOBALS['phpgw']->common->image('phpgwapi/templates/phpgw_website', 'users'));
     //		$this->t->set_var('infologImage',html::image('felamimail','to_infolog',lang('Save as infolog'),'width="17px" height="17px" valign="middle"' ));
     //		$this->t->set_var('lang_save_as_infolog',lang('Save as infolog'));
     $this->t->set_var('lang_no_recipient', lang('No recipient address given!'));
     $this->t->set_var('lang_no_subject', lang('No subject given!'));
     $this->t->pparse("out", "header");
     // body
     if ($sessionData['mimeType'] == 'html') {
         $style = "border:0px; width:100%; height:400px;";
         $this->t->set_var('tinymce', html::fckEditorQuick('body', 'simple', $sessionData['body']));
         $this->t->set_var('mimeType', 'html');
         $ishtml = 1;
     } else {
         $style = "border:0px; width:100%; height:400px;";
         $this->t->set_var('tinymce', html::fckEditorQuick('body', 'ascii', $sessionData['body']));
         $this->t->set_var('mimeType', 'text');
         $ishtml = 0;
     }
     require_once PHPGW_INCLUDE_ROOT . '/felamimail/inc/class.felamimail_bosignatures.inc.php';
     $boSignatures = new felamimail_bosignatures();
     $signatures = $boSignatures->getListOfSignatures();
     if (empty($sessionData['signatureID'])) {
         if ($signatureData = $boSignatures->getDefaultSignature()) {
             if (is_array($signatureData)) {
                 $sessionData['signatureID'] = $signatureData['signatureid'];
             } else {
                 $sessionData['signatureID'] = $signatureData;
             }
         }
     }
     $selectSignatures = array('-2' => lang('no signature'));
     foreach ($signatures as $signature) {
         $selectSignatures[$signature['fm_signatureid']] = $signature['fm_description'];
     }
     $selectBox = html::select('signatureID', $presetSig ? $presetSig : $sessionData['signatureID'], $selectSignatures, true, "style='width: 70%;' onchange='fm_compose_changeInputType(this)'");
     $this->t->set_var("select_signature", $selectBox);
     $this->t->set_var("lang_editormode", lang("Editor type"));
     $this->t->set_var("toggle_editormode", lang("Editor type") . ":&nbsp;<span><input name=\"_is_html\" value=\"" . $ishtml . "\" type=\"hidden\" /><input name=\"_editorselect\" onchange=\"fm_toggle_editor(this)\" " . ($ishtml ? "checked=\"checked\"" : "") . " id=\"_html\" value=\"html\" type=\"radio\"><label for=\"_html\">HTML</label><input name=\"_editorselect\" onchange=\"fm_toggle_editor(this)\" " . ($ishtml ? "" : "checked=\"checked\"") . " id=\"_plain\" value=\"plain\" type=\"radio\"><label for=\"_plain\">Plain text</label></span>");
     $this->t->pparse("out", "body_input");
     // attachments
     if (is_array($sessionData['attachments']) && count($sessionData['attachments']) > 0) {
         $imgClearLeft = $GLOBALS['phpgw']->common->image('felamimail', 'clear_left');
         foreach ((array) $sessionData['attachments'] as $id => $attachment) {
             $tempArray = array('1' => $attachment['name'], '2' => $attachment['type'], '.2' => "style='text-align:center;'", '3' => $attachment['size'], '4' => "<img src='{$imgClearLeft}' onclick=\"fm_compose_deleteAttachmentRow(this,'{$_composeID}','{$id}')\">");
             $tableRows[] = $tempArray;
         }
         if (count($tableRows) > 0) {
             $table = html::table($tableRows, "style='width:100%'");
         }
         $this->t->set_var('attachment_rows', $table);
     } else {
         $this->t->set_var('attachment_rows', '');
     }
     $this->t->pparse("out", "attachment");
 }
 function listSignatures()
 {
     $this->display_app_header(TRUE);
     $this->t->set_root(PHPGW_APP_TPL);
     $this->t->set_file(array("body" => "preferences_list_signatures.tpl"));
     $this->t->set_block('body', 'main');
     $this->translate();
     #print "<pre>";print_r($folderList);print "</pre>";
     // set the default values for the sort links (sort by subject)
     $linkData = array('menuaction' => 'felamimail.uipreferences.listFolder');
     $this->t->set_var('form_action', $GLOBALS['phpgw']->link('/index.php', $linkData));
     $linkData = array('menuaction' => 'felamimail.uipreferences.editSignature');
     $this->t->set_var('url_addSignature', $GLOBALS['phpgw']->link('/index.php', $linkData));
     $this->t->set_var('url_image_add', $GLOBALS['phpgw']->common->image('phpgwapi', 'new'));
     $this->t->set_var('url_image_delete', $GLOBALS['phpgw']->common->image('phpgwapi', 'delete'));
     $felamimail_bosignatures = new felamimail_bosignatures();
     $signatures = $felamimail_bosignatures->getListOfSignatures();
     $this->t->set_var('table', $this->uiwidgets->createSignatureTable($signatures));
     $this->t->pparse("out", "main");
     $this->bofelamimail->closeConnection();
 }
 function saveSignature($_mode, $_id, $_description, $_signature, $_isDefaultSignature)
 {
     require_once PHPGW_INCLUDE_ROOT . '/felamimail/inc/class.felamimail_bosignatures.inc.php';
     $boSignatures = new felamimail_bosignatures();
     $isDefaultSignature = $_isDefaultSignature == 'true' ? true : false;
     $signatureID = $boSignatures->saveSignature($_id, $_description, $_signature, $isDefaultSignature);
     $response =& new xajaxResponse();
     if ($_mode == 'save') {
         #$response->addAssign('signatureID', 'value', $signatureID);
         $response->addScript("opener.fm_refreshSignatureTable()");
         $response->addScript("document.getElementById('signatureDesc').focus();window.close();");
     } else {
         $response->addScript("opener.fm_refreshSignatureTable()");
         $response->addAssign('signatureID', 'value', $signatureID);
     }
     return $response->getXML();
 }