function editAccountData()
 {
     $boPreferences =& CreateObject('felamimail.bopreferences');
     $preferences =& $boPreferences->getPreferences();
     if (!($preferences->userDefinedAccounts || $preferences->userDefinedIdentities)) {
         die('you are not allowed to be here');
     }
     if ($_POST['save'] || $_POST['apply']) {
         // IMAP connection settings
         $icServer =& CreateObject('emailadmin.defaultimap');
         if (is_array($_POST['ic'])) {
             foreach ($_POST['ic'] as $key => $value) {
                 switch ($key) {
                     case 'validatecert':
                         $icServer->{$key} = $value != 'dontvalidate';
                         break;
                     case 'enableSieve':
                         $icServer->{$key} = $value == 'enableSieve';
                         break;
                     default:
                         $icServer->{$key} = $value;
                         break;
                 }
             }
         } else {
             $icServer = NULL;
         }
         // SMTP connection settings
         $ogServer =& CreateObject('emailadmin.defaultsmtp');
         if (is_array($_POST['og'])) {
             foreach ($_POST['og'] as $key => $value) {
                 $ogServer->{$key} = $value;
             }
         } else {
             $ogServer = NULL;
         }
         // identity settings
         $identity =& CreateObject('emailadmin.ea_identity');
         if (is_array($_POST['identity'])) {
             foreach ($_POST['identity'] as $key => $value) {
                 $identity->{$key} = $value;
             }
         }
         $newID = $boPreferences->saveAccountData($icServer, $ogServer, $identity);
         if ($identity->id == 'new') {
             $identity->id = $newID;
         }
         if ((int) $_POST['active']) {
             #$boPreferences->saveAccountData($icServer, $ogServer, $identity);
             $boPreferences->setProfileActive(false);
             $boPreferences->setProfileActive(true, $identity->id);
         } else {
             $boPreferences->setProfileActive(false, $identity->id);
         }
         if ($_POST['save']) {
             ExecMethod('felamimail.uifelamimail.viewMainScreen');
             return;
         }
     } elseif ($_POST['cancel']) {
         ExecMethod('felamimail.uifelamimail.viewMainScreen');
         return;
     }
     $this->display_app_header(TRUE);
     $this->t->set_root(PHPGW_APP_TPL);
     $this->t->set_file(array("body" => "edit_account_data.tpl"));
     $this->t->set_block('body', 'main');
     $this->translate();
     // if there is no accountID with the call of the edit method, retrieve an active account
     $account2retrieve = 'active';
     if ((int) $_GET['accountID']) {
         $account2retrieve = $_GET['accountID'];
     }
     if ($_GET['accountID'] == 'new') {
         $account2retrieve = 'new';
     }
     if (!empty($newID) && $newID > 0) {
         $account2retrieve = $newID;
     }
     if ($account2retrieve != 'new') {
         $accountData = $boPreferences->getAccountData($preferences, $account2retrieve);
     }
     $icServer =& $accountData['icServer'];
     $ogServer =& $accountData['ogServer'];
     $identity =& $accountData['identity'];
     #_debug_array($identity);
     if ($icServer) {
         foreach ($icServer as $key => $value) {
             if (is_object($value) || is_array($value)) {
                 continue;
             }
             switch ($key) {
                 case 'encryption':
                     $this->t->set_var('checked_ic_' . $key . '_' . $value, 'checked');
                     break;
                 case 'enableSieve':
                     $this->t->set_var('checked_ic_' . $key, $value ? 'checked' : '');
                     break;
                 case 'validatecert':
                     $this->t->set_var('checked_ic_' . $key, $value ? '' : 'checked');
                     break;
                 default:
                     $this->t->set_var("ic[{$key}]", $value);
                     break;
             }
         }
     }
     if ($ogServer) {
         foreach ($ogServer as $key => $value) {
             if (is_object($value) || is_array($value)) {
                 continue;
             }
             #print "$key => $value<bR>";
             switch ($key) {
                 case 'smtpAuth':
                     $this->t->set_var('checked_og_' . $key, $value ? 'checked' : '');
                 default:
                     $this->t->set_var("og[{$key}]", $value);
             }
         }
     }
     $felamimail_bosignatures = new felamimail_bosignatures();
     $signatures = $felamimail_bosignatures->getListOfSignatures();
     $allSignatures = array('-2' => lang('no signature'));
     foreach ($signatures as $sigkey => $sig) {
         $allSignatures[$sig['fm_signatureid']] = $sig['fm_description'];
     }
     $sigvalue = -2;
     if ($identity) {
         foreach ($identity as $key => $value) {
             if (is_object($value) || is_array($value)) {
                 continue;
             }
             switch ($key) {
                 case 'signature':
                     $sigvalue = $value;
                     break;
                 default:
                     $this->t->set_var("identity[{$key}]", $value);
             }
         }
         $this->t->set_var('accountID', $identity->id);
         $this->t->set_var('checked_active', $accountData['active'] ? $preferences->userDefinedAccounts ? 'checked' : '' : '');
     } else {
         if ($signatureData = $felamimail_bosignatures->getDefaultSignature()) {
             if (is_array($signatureData)) {
                 $sigvalue = $signatureData['signatureid'];
             } else {
                 $sigvalue = $signatureData;
             }
         }
         $this->t->set_var('accountID', 'new');
     }
     $this->t->set_var('allowAccounts', $preferences->userDefinedAccounts ? 1 : 0);
     $this->t->set_var('identity_selectbox', html::select('identity[signature]', $sigvalue, $allSignatures, true, "style='width: 250px;'"));
     $linkData = array('menuaction' => 'felamimail.uipreferences.editAccountData');
     $this->t->set_var('form_action', $GLOBALS['phpgw']->link('/index.php', $linkData));
     $this->t->parse("out", "main");
     print $this->t->get('out', 'main');
 }
 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");
 }