From a71b394eb2e5ebd2c2229458d2242088807c5728 Mon Sep 17 00:00:00 2001 From: stevetruckstuff Date: Mon, 14 Aug 2006 15:50:43 +0000 Subject: [PATCH] Add template for address book listings along with required files git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@11584 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- src/addressbook.php | 235 ++++++++----------------- templates/default/addressbook_list.tpl | 112 ++++++++++++ templates/default/stylesheet.tpl | 72 +++++++- templates/util_addressbook.php | 72 ++++++++ 4 files changed, 323 insertions(+), 168 deletions(-) create mode 100644 templates/default/addressbook_list.tpl create mode 100644 templates/util_addressbook.php diff --git a/src/addressbook.php b/src/addressbook.php index 7b933923..8b5c68b3 100644 --- a/src/addressbook.php +++ b/src/addressbook.php @@ -26,13 +26,14 @@ require_once(SM_PATH . 'functions/forms.php'); /** lets get the global vars we may need */ /* From the address form */ -sqgetGlobalVar('addaddr', $addaddr, SQ_POST); -sqgetGlobalVar('editaddr', $editaddr, SQ_POST); -sqgetGlobalVar('deladdr', $deladdr, SQ_POST); -sqgetGlobalVar('sel', $sel, SQ_POST); -sqgetGlobalVar('oldnick', $oldnick, SQ_POST); -sqgetGlobalVar('backend', $backend, SQ_POST); -sqgetGlobalVar('doedit', $doedit, SQ_POST); +//sqgetGlobalVar('change_abook', $change_abook, SQ_POST); +sqgetGlobalVar('addaddr', $addaddr, SQ_POST); +sqgetGlobalVar('editaddr', $editaddr, SQ_POST); +sqgetGlobalVar('deladdr', $deladdr, SQ_POST); +sqgetGlobalVar('sel', $sel, SQ_POST); +sqgetGlobalVar('oldnick', $oldnick, SQ_POST); +sqgetGlobalVar('backend', $backend, SQ_POST); +sqgetGlobalVar('doedit', $doedit, SQ_POST); /* Get sorting order */ $abook_sort_order = get_abook_sort(); @@ -47,12 +48,29 @@ $abook = addressbook_init(true, false); // FIXME: do we have to stop use of address book, when localbackend is not present. if($abook->localbackend == 0) { - plain_error_message( - _("No personal address book is defined. Contact administrator."), - $color); + plain_error_message(_("No personal address book is defined. Contact administrator.")); exit(); } +$current_backend = $abook->localbackend; +if (sqgetGlobalVar('new_bnum',$new_backend,SQ_POST) && array_key_exists($new_backend,$abook->backends)) { + $current_backend = (int) $new_backend; +} + +$abook_selection = ' '; +$list_backends = array(); +if (count($abook->backends) > 1) { + foreach($abook->get_backend_list() as $oBackend) { + if ($oBackend->listing) { + $list_backends[$oBackend->bnum]=$oBackend->sname; + } + } + if (count($list_backends)>1) { + $abook_selection = addSelect('new_bnum',$list_backends,$current_backend,true) + .addSubmit(_("Change"),'change_abook'); + } +} + $defdata = array(); $formerror = ''; $abortform = false; @@ -61,6 +79,7 @@ $defselected = array(); $form_url = 'addressbook.php'; /* Handle user's actions */ +//if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST' && !isset($change_abook)) { if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') { /************************************************** @@ -214,165 +233,56 @@ if(sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'P /* Display error messages */ if (!empty($formerror)) { - echo html_tag( 'table', - html_tag( 'tr', - html_tag( 'td', - "\n". '
' . _("ERROR") . ': ' . nl2br(htmlspecialchars($formerror)) . '' ."\n", - 'center' ) - ), - 'center', '', 'width="100%"' ); + plain_error_message(nl2br(htmlspecialchars($formerror))); } /* Display the address management part */ -if ($showaddrlist) { - /* Get and sort address list */ - $alist = $abook->list_addr(); - if(!is_array($alist)) { - plain_error_message(nl2br(htmlspecialchars($abook->error)), $color); - exit; - } - +$addresses = array(); +while (list($k, $backend) = each ($abook->backends)) { + $a = array(); + $a['BackendID'] = $backend->bnum; + $a['BackendSource'] = $backend->sname; + $a['BackendWritable'] = $backend->writeable; + $a['Addresses'] = array(); + + $alist = $abook->list_addr($backend->bnum); usort($alist,'alistcmp'); - $prevbackend = -1; - $headerprinted = false; - - echo html_tag( 'p', '' . _("Add address") . '', 'center' ) . "\n"; - - /* List addresses */ - if (count($alist) > 0) { - echo addForm($form_url, 'post'); - if ($abook->add_extra_field) { - $abook_fields = 6; - } else { - $abook_fields = 5; - } - while(list($undef,$row) = each($alist)) { - - /* New table header for each backend */ - if($prevbackend != $row['backend']) { - if($prevbackend < 0) { - echo html_tag( 'table', - html_tag( 'tr', - html_tag( 'td', - addSubmit(_("Edit selected"), 'editaddr'). - addSubmit(_("Delete selected"), 'deladdr'), - 'center', '', "colspan=\"$abook_fields\"" ) - ) . - html_tag( 'tr', - html_tag( 'td', ' 
', 'center', '', "colspan=\"$abook_fields\"" ) - ), - 'center' ); - echo "\n\n" . - html_tag( 'table', '', 'center', '', 'border="0" cellpadding="1" cellspacing="0" width="90%"' ) . - html_tag( 'tr', "\n" . - html_tag( 'th', ' ', 'left', '', 'width="1%"' ) . "\n" . - html_tag( 'th', _("Nickname") . - show_abook_sort_button($abook_sort_order, _("sort by nickname"), 0, 1), - 'left', '', 'width="1%"' ) . "\n" . - html_tag( 'th', _("Name") . - show_abook_sort_button($abook_sort_order, _("sort by name"), 2, 3), - 'left', '', 'width="1%"' ) . "\n" . - html_tag( 'th', _("E-mail") . - show_abook_sort_button($abook_sort_order, _("sort by email"), 4, 5), - 'left', '', 'width="1%"' ) . "\n" . - html_tag( 'th', _("Info") . - show_abook_sort_button($abook_sort_order, _("sort by info"), 6, 7), - 'left', '', 'width="1%"' ) . - ($abook->add_extra_field ? html_tag( 'th', ' ','left', '', 'width="1%"'): '') . - "\n", - '', $color[9] ) . "\n"; - } - - // Separate different backends with
- if($prevbackend > 0) { - echo html_tag( 'tr', - html_tag( 'td', "
", 'center', '' ,"colspan=\"$abook_fields\"" ) - ); - } - - // Print backend name - echo html_tag( 'tr', - html_tag( 'td', "\n" . '' . $row['source'] . '' . "\n", 'center', $color[0] ,"colspan=\"$abook_fields\"" ) - ); - - $line = 0; - $headerprinted = true; - } /* End of header */ - - $prevbackend = $row['backend']; - - /* Check if this user is selected */ - $selected = in_array($row['backend'] . ':' . $row['nickname'], $defselected); - - /* Print one row, with alternating color */ - if ($line % 2) { - $tr_bgcolor = $color[12]; - } else { - $tr_bgcolor = $color[4]; - } - echo html_tag( 'tr', '', '', $tr_bgcolor); - if ($abook->backends[$row['backend']]->writeable) { - $id = $row['backend'].':'.$row['nickname']; - echo html_tag( 'td', - '' . - addCheckBox("sel[$id]", $selected, $id). - '' , - 'center', '', 'valign="top" width="1%"' ); - $label1 = ''; - } else { - echo html_tag( 'td', - ' ' , - 'center', '', 'valign="top" width="1%"' ); - $label1 = $label2 = ''; - } - echo html_tag( 'td', - ' ' . $label1 . htmlspecialchars($row['nickname']) . $label2 . ' ', - 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ); - - echo html_tag( 'td', - ' ' . $label1 . htmlspecialchars($row['name']) . $label2 . ' ', - 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ); - - // email address column - echo html_tag( 'td', '', 'left', '', 'valign="top" width="1%" style="white-space: nowrap;"' ) . ' '; - $email = $abook->full_address($row); - echo makeComposeLink('src/compose.php?send_to='.rawurlencode($email), - htmlspecialchars($row['email'])). - ' '."\n"; - - // info column - echo html_tag( 'td', ' ' . htmlspecialchars($row['label']) . ' ', 'left', '', 'valign="top" width="1%"' ); - - // add extra column if third party backend needs it - if ($abook->add_extra_field) { - echo html_tag( 'td', - ' ' . (isset($row['extra']) ? $row['extra'] : '') . ' ', - 'left', '', 'valign="top" width="1%"' ); - } - echo "\n"; - $line++; - } - echo "" . - "\n\n"; - - /* End of list. Add edit/delete select buttons */ - if ($headerprinted) { - echo html_tag( 'table', - html_tag( 'tr', - html_tag( 'td', - addSubmit(_("Edit selected"), 'editaddr') . - addSubmit(_("Delete selected"), 'deladdr'), - 'center', '', "colspan=\"$abook_fields\"" ) - ), - 'center' ); - } - echo "\n"; + $start = 200; + $count = count($alist); + if ($start >= $count) $start = 0; + $alist = array_slice($alist,$start,15); + + while(list($undef,$row) = each($alist)) { + $contact = array ( + 'FirstName' => htmlspecialchars($row['firstname']), + 'LastName' => htmlspecialchars($row['lastname']), + 'FullName' => htmlspecialchars($row['name']), + 'NickName' => htmlspecialchars($row['nickname']), + 'Email' => htmlspecialchars($row['email']), + 'FullAddress' => htmlspecialchars($abook->full_address($row)), + 'Info' => htmlspecialchars($row['label']), + 'Extra' => (isset($row['extra']) ? $row['extra'] : NULL), + ); + $a['Addresses'][] = $contact; } -} /* end of addresslist */ + + $addresses[$backend->bnum] = $a; +} +if ($showaddrlist) { + echo addForm($form_url, 'post'); + + $oTemplate->assign('addresses', $addresses); + $oTemplate->assign('current_backend', $current_backend); + $oTemplate->assign('backends', $list_backends); + + $oTemplate->display('addressbook_list.tpl'); + + echo "\n"; +} + /* Display the "new address" form */ echo '' . "\n"; abook_create_form($form_url,'addaddr',_("Add to address book"),_("Add address"),$defdata); @@ -382,5 +292,6 @@ echo "\n"; echo "\n"; do_hook('addressbook_bottom'); echo "\n\n"; + $oTemplate->display('footer.tpl'); -?> +?> \ No newline at end of file diff --git a/templates/default/addressbook_list.tpl b/templates/default/addressbook_list.tpl new file mode 100644 index 00000000..45616471 --- /dev/null +++ b/templates/default/addressbook_list.tpl @@ -0,0 +1,112 @@ +'; +/** Begin template **/ +$source = $addresses[$current_backend]; +$abook_has_extra_field = isset($source['Addresses'][0]) && !is_null($source['Addresses'][0]['Extra']); +$colspan = $abook_has_extra_field ? 6 : 5; +?> +
+ + + + + + + + + + + + + + + '; + } + ?> + + '."\n"; + } + foreach ($source['Addresses'] as $contact) { + $id = $current_backend.':'.$contact['NickName']; + ?> + > + + + + + + '.$contact['Extra'].''."\n"; + } + ?> + + +
class="header1"> + +
+ name="editaddr" id="editaddr" /> + name="deladdr" id="deladdr" /> + class="abookSwitch"> + + name="change_abook" id="change_abook" /> +
'._("Address book is empty").'
' : ''); ?>
+
\ No newline at end of file diff --git a/templates/default/stylesheet.tpl b/templates/default/stylesheet.tpl index ff073b32..14dd669e 100644 --- a/templates/default/stylesheet.tpl +++ b/templates/default/stylesheet.tpl @@ -136,6 +136,13 @@ td.header2 { padding-bottom: 4px; } +tr.even { + background: ; +} +tr.odd { + background: ; +} + .table_standard { border:1px solid ; } @@ -207,12 +214,6 @@ td.header2 { .table_messageList td.spacer { background: ; } -.table_messageList tr.even { - background: ; -} -.table_messageList tr.odd { - background: ; -} .table_messageList tr.mouse_over { background: ; } @@ -302,4 +303,63 @@ td.header2 { margin-right: auto; width: 80%; text-align: left; +} + +/* addressbook_list.tpl defs */ +#addressList { + text-align: center; +} + +#addressList input { + font-size: 75%; +} + +#addressList select { + font-size: 75%; +} + +#addressList table { + margin-left: auto; + margin-right: auto; + width: 90%; + border: 1px solid ; + margin-top: 8px; + margin-bottom: 8px; +} + +#addressList td { + text-align: left; + padding: 2px; +} + +#addressList td.header1 { + text-align: center; + background: ; +} +#addressList td.abookSwitch { + background: ; + text-align: right; +} + +#addressList td.abookButtons { + background: ; +} + +#addressList td.abookField { + border-left: 1px solid ; + border-right: 1px solid ; +} + +#addressList td.colHeader { + text-align: center; + font-weight: bold; + font-size: 98%; + background: ; + padding-top: 0px; + padding-bottom: 0px; +} + +#addressList td.abookEmpty { + text-align:center; + font-weight: bold; } \ No newline at end of file diff --git a/templates/util_addressbook.php b/templates/util_addressbook.php new file mode 100644 index 00000000..ca2967b3 --- /dev/null +++ b/templates/util_addressbook.php @@ -0,0 +1,72 @@ + \ No newline at end of file -- 2.25.1