template = $template; $this->template->set_file(array("body" => 'uiwidgets.tpl')); $this->charset = $GLOBALS['egw']->translation->charset(); if (!is_object($GLOBALS['egw']->html)) { $GLOBALS['egw']->html = CreateObject('phpgwapi.html'); } } function encodeFolderName($_folderName) { return $GLOBALS['egw']->translation->convert($_folderName, 'UTF7-IMAP', $this->charset); } /** * create a folder tree * * this function will create a foldertree based on javascript * on click the sorounding form gets submitted * * @param _folders array containing the list of folders * @param _selected string containing the selected folder * @param _selectedFolderCount integer contains the count of unread messages in the selected folder * @param _topFolderName string containing the top folder name * @param _topFolderDescription string containing the description for the top folder * @param _formName string name of the sorounding form * @param _hiddenVar string hidden form value, transports the selected folder * @param _useDisplayCharset bool use displaycharset for foldernames (used by uisieve only) * * @return string the html code, to be added into the template */ function createHTMLFolder($_folders, $_selected, $_selectedFolderCount, $_topFolderName, $_topFolderDescription, $_divName, $_displayCheckBox, $_useDisplayCharset = false) { // create a list of all folders, also the ones which are not subscribed foreach($_folders as $key => $obj) { $folderParts = explode($obj->delimiter,$key); if(is_array($folderParts)) { $partCount = count($folderParts); $string = ''; for($i = 0; $i < $partCount-1; $i++) { if(!empty($string)) $string .= $obj->delimiter; $string .= $folderParts[$i]; if(!$allFolders[$string]) { $allFolders[$string] = clone($obj); $allFolders[$string]->folderName = $string; $allFolders[$string]->shortFolderName = array_pop(explode($obj->delimiter, $string)); $allFolders[$string]->displayName = $this->encodeFolderName($allFolders[$string]->folderName); $allFolders[$string]->shortDisplayName = $this->encodeFolderName($allFolders[$string]->shortFolderName); } } } $allFolders[$key] = $obj; } $folderImageDir = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/templates/default/images/'; // careful! "d = new..." MUST be on a new line!!! $folder_tree_new = ''; $folder_tree_new .= ""; return $folder_tree_new; } function createSignatureTable($_signatureList) { $linkData = array ( 'menuaction' => 'felamimail.uipreferences.editSignature' ); $urlEditSignature = $GLOBALS['egw']->link('/index.php',$linkData); if(is_array($_signatureList) && !empty($_signatureList)) { foreach($_signatureList as $signature) { $description = ($signature['defaultsignature'] == true) ? $signature['description'] .' ('. lang('default') .')' : $signature['description']; $tableRows[] = array( '1' => $GLOBALS['egw']->html->checkbox('signatureID', false, $signature['signatureid']), '.1' => 'style="width:30px"', '2' => ''. @htmlspecialchars($description, ENT_QUOTES, $this->charset) .'', ); } return $GLOBALS['egw']->html->table($tableRows, 'style="width:100%;"'); } return ''; } // $_folderType 0: normal imap folder 1: sent folder 2: draft folder // $_rowStyle felamimail or outlook function messageTable($_headers, $_folderType, $_readInNewWindow, $_rowStyle='felamimail') { $this->t =& CreateObject('phpgwapi.Template',EGW_APP_TPL); $this->t->set_file(array("body" => 'mainscreen.tpl')); $this->t->set_block('body','header_row_felamimail'); $this->t->set_block('body','header_row_outlook'); $this->t->set_block('body','message_table'); $timestamp7DaysAgo = mktime(date("H"), date("i"), date("s"), date("m"), date("d")-7, date("Y")); $timestampNow = mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y")); $dateToday = date("Y-m-d"); $i=0; foreach((array)$_headers['header'] as $header) { #_debug_array($header); #if($i<10) {$i++;continue;} #if($i>20) {continue;} $i++; // create the listing of subjects $maxSubjectLength = 60; $maxAddressLength = 20; $maxSubjectLengthBold = 50; $maxAddressLengthBold = 14; $flags = ""; if(!empty($header['recent'])) $flags .= "R"; if(!empty($header['flagged'])) $flags .= "F"; if(!empty($header['answered'])) $flags .= "A"; if(!empty($header['deleted'])) $flags .= "D"; if(!empty($header['seen'])) $flags .= "S"; $this->t->set_var('row_text', ''); // the status icon if($header['deleted']) { $this->t->set_var('image_url',$GLOBALS['egw']->html->image('felamimail','kmmsgdel')); } elseif($header['recent']) { $this->t->set_var('image_url',$GLOBALS['egw']->html->image('felamimail','kmmsgnew')); } elseif($header['answered']) { $this->t->set_var('image_url',$GLOBALS['egw']->html->image('felamimail','kmmsgreplied')); } elseif($header['seen']) { $this->t->set_var('image_url',$GLOBALS['egw']->html->image('felamimail','kmmsgread')); } else { $this->t->set_var('image_url',$GLOBALS['egw']->html->image('felamimail','kmmsgunseen')); } // the css for this row if($header['deleted']) { $this->t->set_var('row_css_class','header_row_D'); } elseif($header['recent'] && !$header['seen']) { $this->t->set_var('row_css_class','header_row_R'); } elseif($header['flagged']) { if($header['seen']) { $this->t->set_var('row_css_class','header_row_FS'); } else { $this->t->set_var('row_css_class','header_row_F'); } } elseif($header['seen']) { $this->t->set_var('row_css_class','header_row_S'); } else { $this->t->set_var('row_css_class','header_row_'); } // filter out undisplayable characters $search = array('[\016]','[\017]', '[\020]','[\021]','[\022]','[\023]','[\024]','[\025]','[\026]','[\027]', '[\030]','[\031]','[\032]','[\033]','[\034]','[\035]','[\036]','[\037]'); $replace = ''; $header['subject'] = preg_replace($search,$replace,$header['subject']); $header['subject'] = @htmlspecialchars($header['subject'],ENT_QUOTES,$this->displayCharset); // curly brackets get messed up by the template! $header['subject'] = str_replace(array('{','}'),array('{','}'),$header['subject']); if (!empty($header['subject'])) { // make the subject shorter if it is to long $fullSubject = $header['subject']; #if(strlen($header['subject']) > $maxSubjectLength) #{ # $header['subject'] = substr($header['subject'],0,$maxSubjectLength)."..."; #} $this->t->set_var('header_subject', $header['subject']); #$this->t->set_var('attachments', $header['attachment']); $this->t->set_var('full_subject', $fullSubject); } else { $this->t->set_var('header_subject', @htmlspecialchars('('. lang('no subject') .')', ENT_QUOTES, $this->displayCharset)); } # _debug_array($header); if($header['mimetype'] == 'multipart/mixed' || $header['mimetype'] == 'multipart/related' || substr($header['mimetype'],0,11) == 'application' || substr($header['mimetype'],0,5) == 'audio') { $image = $GLOBALS['egw']->html->image('felamimail','attach'); $this->t->set_var('attachment_image', $image); } else { $this->t->set_var('attachment_image', ' '); } if ($_folderType > 0) { // sent or drafts folder if (!empty($header['to_name'])) { $sender_name = $header['to_name']; $full_address = $header['to_name'].' <'.$header['to_address'].'>'; } else { $sender_name = $header['to_address']; $full_address = $header['to_address']; } } else { if (!empty($header['sender_name'])) { $sender_name = $header['sender_name']; $full_address = $header['sender_name'].' <'.$header['sender_address'].'>'; } else { $sender_name = $header['sender_address']; $full_address = $header['sender_address']; } } $this->t->set_var('sender_name', @htmlspecialchars($sender_name, ENT_QUOTES, $this->charset)); $this->t->set_var('full_address', @htmlspecialchars($full_address, ENT_QUOTES, $this->charset)); $this->t->set_var('message_counter', $i); $this->t->set_var('message_uid', $header['uid']); if ($dateToday == date('Y-m-d', $header['date'])) { $this->t->set_var('date', date('H:i:s', $header['date'])); } else { $this->t->set_var('date', date($GLOBALS['egw_info']['user']['preferences']['common']['dateformat'], $header['date'])); } $this->t->set_var('size', $this->show_readable_size($header['size'])); if($_folderType == 2) { $linkData = array ( 'menuaction' => 'felamimail.uicompose.composeFromDraft', 'icServer' => 0, 'folder' => base64_encode($GLOBALS['egw_info']['user']['preferences']['felamimail']['draftFolder']), 'uid' => $header['uid'], 'id' => $header['id'], ); $this->t->set_var('url_read_message', $GLOBALS['egw']->link('/index.php',$linkData)); $windowName = 'composeFromDraft_'.$header['uid']; $this->t->set_var('read_message_windowName', $windowName); } else { # _debug_array($header); $linkData = array ( 'menuaction' => 'felamimail.uidisplay.display', 'showHeader' => 'false', 'uid' => $header['uid'], 'id' => $header['id'], ); $this->t->set_var('url_read_message', $GLOBALS['egw']->link('/index.php',$linkData)); $windowName = ($_readInNewWindow == 1 ? 'displayMessage' : 'displayMessage_'.$header['uid']); $this->t->set_var('read_message_windowName', $windowName); } if($_folderType > 0) { // sent or draft folder if(!empty($header['to_name'])) { list($mailbox, $host) = explode('@',$header['to_address']); $senderAddress = imap_rfc822_write_address($mailbox, $host, $header['to_name']); } else { $senderAddress = $header['to_address']; } } else { if(!empty($header['sender_name'])) { list($mailbox, $host) = explode('@',$header['sender_address']); $senderAddress = imap_rfc822_write_address($mailbox, $host, $header['sender_name']); } else { $senderAddress = $header['sender_address']; } } $linkData = array ( 'menuaction' => 'felamimail.uicompose.compose', 'send_to' => base64_encode($senderAddress) ); $windowName = 'compose'.$header['uid']; $this->t->set_var('url_compose',"egw_openWindowCentered('".$GLOBALS['egw']->link('/index.php',$linkData)."','$windowName',700,egw_getWindowOuterHeight());"); $linkData = array ( 'menuaction' => 'addressbook.uicontacts.edit', 'presets[email]' => urlencode($header['sender_address']), 'presets[n_given]' => urlencode($header['sender_name']), 'referer' => urlencode($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']) ); //TODO: url_add_to_addressbook isn't in any of the templates. //If you want to use it, you need to adopt syntax to the new addressbook (popup) $this->t->set_var('url_add_to_addressbook',$GLOBALS['egw']->link('/index.php',$linkData)); $this->t->set_var('msg_icon_sm',$msg_icon_sm); $this->t->set_var('phpgw_images',EGW_IMAGES); switch($_rowStyle) { case 'outlook': $this->t->parse('message_rows','header_row_outlook',True); break; default: $this->t->parse('message_rows','header_row_felamimail',True); break; } } $this->t->parse("out","message_table"); return $this->t->get('out','message_table'); } /** * create multiselectbox * * this function will create a multiselect box. Hard to describe! :) * * @param _selectedValues Array of values for already selected values(the left selectbox) * @param _predefinedValues Array of values for predefined values(the right selectbox) * @param _valueName name for the variable containing the selected values * @param _boxWidth the width of the multiselectbox( example: 100px, 100%) * * @returns the html code, to be added into the template */ function multiSelectBox($_selectedValues, $_predefinedValues, $_valueName, $_boxWidth="100%") { $this->template->set_block('body','multiSelectBox'); if(is_array($_selectedValues)) { foreach($_selectedValues as $key => $value) { $options .= ""; } $this->template->set_var('multiSelectBox_selected_options',$options); } $options = ''; if(is_array($_predefinedValues)) { foreach($_predefinedValues as $key => $value) { if($key != $_selectedValues["$key"]) $options .= ""; } $this->template->set_var('multiSelectBox_predefinded_options',$options); } $this->template->set_var('multiSelectBox_valueName', $_valueName); $this->template->set_var('multiSelectBox_boxWidth', $_boxWidth); return $this->template->fp('out','multiSelectBox'); } function navbarButton($_imageName, $_imageAction, $_toolTip='', $_float='left') { $image = $GLOBALS['egw']->common->image('felamimail',$_imageName); $float = $_float == 'right' ? 'right' : 'left'; return ""; } function navbarSeparator() { return ''; } /* Returns a string showing the size of the message/attachment */ function show_readable_size($bytes, $_mode='short') { $bytes /= 1024; $type = 'k'; if ($bytes / 1024 > 1) { $bytes /= 1024; $type = 'M'; } if ($bytes < 10) { $bytes *= 10; settype($bytes, 'integer'); $bytes /= 10; } else settype($bytes, 'integer'); return $bytes . ' ' . $type ; } function tableView($_headValues, $_tableWidth="100%") { $this->template->set_block('body','tableView'); $this->template->set_block('body','tableViewHead'); if(is_array($_headValues)) { foreach($_headValues as $head) { $this->template->set_var('tableHeadContent',$head); $this->template->parse('tableView_Head','tableViewHead',True); } } if(is_array($this->tableViewRows)) { foreach($this->tableViewRows as $tableRow) { $rowData .= ""; foreach($tableRow as $tableData) { switch($tableData['type']) { default: $rowData .= ''.$tableData['text'].''; break; } } $rowData .= ""; } } $this->template->set_var('tableView_width', $_tableWidth); $this->template->set_var('tableView_Rows', $rowData); return $this->template->fp('out','tableView'); } function tableViewAddRow() { $this->tableViewRows[] = array(); end($this->tableViewRows); return key($this->tableViewRows); } function tableViewAddTextCell($_rowID,$_text) { $this->tableViewRows[$_rowID][]= array ( 'type' => 'text', 'text' => $_text ); } function quotaDisplay($_usage, $_limit) { $this->t =& CreateObject('phpgwapi.Template',EGW_APP_TPL); $this->t->set_file(array("body" => 'mainscreen.tpl')); $this->t->set_block('body','quota_block'); if($_limit == 0) { $quotaPercent=100; } else { $quotaPercent=round(($_usage*100)/$_limit); } $quotaLimit=$this->show_readable_size($_limit*1024); $quotaUsage=$this->show_readable_size($_usage*1024); $this->t->set_var('leftWidth',$quotaPercent); if($quotaPercent > 90 && $_limit>0) { $this->t->set_var('quotaBG','red'); } elseif($quotaPercent > 80 && $_limit>0) { $this->t->set_var('quotaBG','yellow'); } else { $this->t->set_var('quotaBG','#66ff66'); } if($_limit > 0) { $quotaText = $quotaUsage .'/'.$quotaLimit; } else { $quotaText = $quotaUsage; } if($quotaPercent > 50) { $this->t->set_var('quotaUsage_left', $quotaText); $this->t->set_var('quotaUsage_right',''); } else { $this->t->set_var('quotaUsage_left',''); $this->t->set_var('quotaUsage_right', $quotaText); } $this->t->parse('out','quota_block'); return $this->t->get('out','quota_block'); } } ?>