Formatting

This commit is contained in:
Miles Lott 2001-05-06 12:33:36 +00:00
parent d3af581109
commit 80124149a7

View File

@ -12,54 +12,61 @@
/* $Id$ */ /* $Id$ */
$phpgw_info["flags"] = array( $phpgw_info['flags'] = array(
"currentapp" => "addressbook", 'currentapp' => 'addressbook',
"enable_contacts_class" => True, 'enable_contacts_class' => True,
"enable_nextmatchs_class" => True 'enable_nextmatchs_class' => True
); );
include("../header.inc.php"); include('../header.inc.php');
$t = new Template($phpgw->common->get_tpl_dir("addressbook")); $t = new Template($phpgw->common->get_tpl_dir('addressbook'));
$t->set_file(array( $t->set_file(array(
"addressbook_header" => "header.tpl", 'addressbook_header' => 'header.tpl',
"column" => "column.tpl", 'column' => 'column.tpl',
"row" => "row.tpl", 'row' => 'row.tpl',
"addressbook_footer" => "footer.tpl" )); 'addressbook_footer' => 'footer.tpl'
));
$this = CreateObject("phpgwapi.contacts"); $this = CreateObject('phpgwapi.contacts');
//$this->delete_all($phpgw_info["user"]["account_id"]); //$this->delete_all($phpgw_info['user']['account_id']);
//exit; //exit;
$customfields = array(); $customfields = array();
while (list($col,$descr) = @each($phpgw_info["user"]["preferences"]["addressbook"])) { while (list($col,$descr) = @each($phpgw_info['user']['preferences']['addressbook']))
if ( substr($col,0,6) == 'extra_' ) { {
if ( substr($col,0,6) == 'extra_' )
{
$field = ereg_replace('extra_','',$col); $field = ereg_replace('extra_','',$col);
$field = ereg_replace(' ','_',$field); $field = ereg_replace(' ','_',$field);
$customfields[$field] = ucfirst($field); $customfields[$field] = ucfirst($field);
} }
} }
if (!isset($cat_id)) { if (!isset($cat_id))
$cat_id = $phpgw_info["user"]["preferences"]["addressbook"]["default_category"]; {
$cat_id = $phpgw_info['user']['preferences']['addressbook']['default_category'];
} }
if ($phpgw_info["user"]["preferences"]["addressbook"]["autosave_category"]) { if ($phpgw_info['user']['preferences']['addressbook']['autosave_category'])
$phpgw->preferences->delete("addressbook","default_category"); {
$phpgw->preferences->add("addressbook","default_category",$cat_id); $phpgw->preferences->delete('addressbook','default_category');
$phpgw->preferences->add('addressbook','default_category',$cat_id);
} }
$phpgw->preferences->save_repository(); $phpgw->preferences->save_repository();
$extrafields = array( $extrafields = array(
"ophone" => "ophone", 'ophone' => 'ophone',
"address2" => "address2", 'address2' => 'address2',
"address3" => "address3" 'address3' => 'address3'
); );
$qfields = $this->stock_contact_fields + $extrafields + $customfields; $qfields = $this->stock_contact_fields + $extrafields + $customfields;
// create column list and the top row of the table based on user prefs // create column list and the top row of the table based on user prefs
while ($column = each($this->stock_contact_fields)) { while ($column = each($this->stock_contact_fields))
{
$test = strtolower($column[0]); $test = strtolower($column[0]);
if (isset($phpgw_info["user"]["preferences"]["addressbook"][$test]) && if (isset($phpgw_info['user']['preferences']['addressbook'][$test]) &&
$phpgw_info["user"]["preferences"]["addressbook"][$test]) { $phpgw_info['user']['preferences']['addressbook'][$test])
{
$showcol = display_name($column[0]); $showcol = display_name($column[0]);
$cols .= " <td height=\"21\">\n"; $cols .= " <td height=\"21\">\n";
$cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">'; $cols .= ' <font size="-1" face="Arial, Helvetica, sans-serif">';
@ -72,12 +79,14 @@
$columns_to_display[$column[0]] = True; $columns_to_display[$column[0]] = True;
} }
} }
$nonstd = $extrafields + $customfields; $nonstd = $extrafields + $customfields;
while ($column = each($nonstd)) { while ($column = each($nonstd))
{
$test = strtolower($column[1]); $test = strtolower($column[1]);
if (isset($phpgw_info["user"]["preferences"]["addressbook"][$test]) && if (isset($phpgw_info['user']['preferences']['addressbook'][$test]) &&
$phpgw_info["user"]["preferences"]["addressbook"][$test]) { $phpgw_info['user']['preferences']['addressbook'][$test])
{
$showcol = display_name($column[0]); $showcol = display_name($column[0]);
// This must be a custom field // This must be a custom field
if (!$showcol) { $showcol = $column[1]; } if (!$showcol) { $showcol = $column[1]; }
@ -92,19 +101,24 @@
} }
} }
if (! $start) if (!$start)
{
$start = 0; $start = 0;
}
if($phpgw_info["user"]["preferences"]["common"]["maxmatchs"] && if($phpgw_info['user']['preferences']['common']['maxmatchs'] &&
$phpgw_info["user"]["preferences"]["common"]["maxmatchs"] > 0) { $phpgw_info['user']['preferences']['common']['maxmatchs'] > 0)
$offset = $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]; {
} else { $offset = $phpgw_info['user']['preferences']['common']['maxmatchs'];
}
else
{
$offset = 30; $offset = 30;
} }
// Set qfilter to display entries where tid=n (normal contact entry), // Set qfilter to display entries where tid=n (normal contact entry),
// else they may be accounts, etc. // else they may be accounts, etc.
if (!$filter) { $filter = "none"; } if (!$filter) { $filter = 'none'; }
if ($filter == "none") { if ($filter == "none") {
if (!$cat_id) { if (!$cat_id) {
@ -114,15 +128,15 @@
} }
} elseif($filter == "private") { } elseif($filter == "private") {
if (!$cat_id) { if (!$cat_id) {
$qfilter = 'tid=n,access=private,owner='.$phpgw_info["user"]["account_id"]; $qfilter = 'tid=n,access=private,owner='.$phpgw_info['user']['account_id'];
} else { } else {
$qfilter = 'tid=n,access=private,owner='.$phpgw_info["user"]["account_id"].',cat_id='.$cat_id; $qfilter = 'tid=n,access=private,owner='.$phpgw_info['user']['account_id'].',cat_id='.$cat_id;
} }
} elseif($filter == "yours") { } elseif($filter == "yours") {
if (!$cat_id) { if (!$cat_id) {
$qfilter = 'tid=n,owner='.$phpgw_info["user"]["account_id"]; $qfilter = 'tid=n,owner='.$phpgw_info['user']['account_id'];
} else { } else {
$qfilter = 'tid=n,owner='.$phpgw_info["user"]["account_id"].',cat_id='.$cat_id; $qfilter = 'tid=n,owner='.$phpgw_info['user']['account_id'].',cat_id='.$cat_id;
} }
} else { } else {
if (!$cat_id) { if (!$cat_id) {
@ -133,16 +147,18 @@
} }
// Check if prefs were set, if not, create some defaults // Check if prefs were set, if not, create some defaults
if (!$columns_to_display ) { if (!$columns_to_display )
{
$columns_to_display = array( $columns_to_display = array(
"n_given" => "n_given", 'n_given' => 'n_given',
"n_family" => "n_family", 'n_family' => 'n_family',
"org_name" => "org_name" 'org_name' => 'org_name'
); );
$columns_to_display = $columns_to_display + $customfields; $columns_to_display = $columns_to_display + $customfields;
// No prefs,. so cols above may have been set to "" or a bunch of <td></td> // No prefs,. so cols above may have been set to "" or a bunch of <td></td>
$cols=""; $cols="";
while ($column = each($columns_to_display)) { while ($column = each($columns_to_display))
{
$showcol = display_name($column[0]); $showcol = display_name($column[0]);
if (!$showcol) { $showcol = $column[1]; } if (!$showcol) { $showcol = $column[1]; }
$cols .= " <td height=\"21\">\n"; $cols .= " <td height=\"21\">\n";
@ -152,128 +168,150 @@
$cols .= "</font>\n </td>"; $cols .= "</font>\n </td>";
$cols .= "\n"; $cols .= "\n";
} }
$noprefs=lang("Please set your preferences for this app"); $noprefs=lang('Please set your preferences for this app');
} }
$qcols = $columns_to_display; $qcols = $columns_to_display;
if (!$userid) { $userid = $phpgw_info["user"]["account_id"]; } if (!$userid) { $userid = $phpgw_info['user']['account_id']; }
// read the entry list // read the entry list
$entries = addressbook_read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order,$userid); $entries = addressbook_read_entries($start,$offset,$qcols,$query,$qfilter,$sort,$order,$userid);
$search_filter = $phpgw->nextmatchs->show_tpl("/addressbook/index.php", $search_filter = $phpgw->nextmatchs->show_tpl('/addressbook/index.php',
$start, $this->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query&cat_id=$cat_id","75%", $start, $this->total_records,"&order=$order&filter=$filter&sort=$sort&query=$query&cat_id=$cat_id","75%",
$phpgw_info["theme"]["th_bg"],1,1,1,1); $phpgw_info["theme"]["th_bg"],1,1,1,1);
if ($this->total_records > $phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) { if ($this->total_records > $phpgw_info['user']['preferences']['common']['maxmatchs'])
if ($start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"] > $this->total_records) { {
if ($start + $phpgw_info['user']['preferences']['common']['maxmatchs'] > $this->total_records)
{
$end = $this->total_records; $end = $this->total_records;
} else {
$end = $start + $phpgw_info["user"]["preferences"]["common"]["maxmatchs"];
} }
$lang_showing=lang("showing x - x of x",($start + 1),$end,$this->total_records); else
} else { {
$lang_showing=lang("showing x",$this->total_records); $end = $start + $phpgw_info['user']['preferences']['common']['maxmatchs'];
}
$lang_showing=lang('showing x - x of x',($start + 1),$end,$this->total_records);
}
else
{
$lang_showing=lang('showing x',$this->total_records);
} }
// set basic vars and parse the header // set basic vars and parse the header
$t->set_var(font,$phpgw_info["theme"]["font"]); $t->set_var(font,$phpgw_info['theme']['font']);
$t->set_var("lang_view",lang("View")); $t->set_var('lang_view',lang('View'));
$t->set_var("lang_vcard",lang("VCard")); $t->set_var('lang_vcard',lang('VCard'));
$t->set_var("lang_edit",lang("Edit")); $t->set_var('lang_edit',lang('Edit'));
$t->set_var("lang_owner",lang("Owner")); $t->set_var('lang_owner',lang('Owner'));
$t->set_var(searchreturn,$noprefs . " " . $searchreturn); $t->set_var('searchreturn',$noprefs . ' ' . $searchreturn);
$t->set_var(lang_showing,$lang_showing); $t->set_var('lang_showing',$lang_showing);
$t->set_var(search_filter,$search_filter); $t->set_var('search_filter',$search_filter);
$t->set_var(cats,lang('Category')); $t->set_var('cats',lang('Category'));
$t->set_var(cats_url,$phpgw->link("/addressbook/index.php")); $t->set_var('cats_url',$phpgw->link('/addressbook/index.php'));
$t->set_var(cats_link,cat_option($cat_id)); $t->set_var('cats_link',cat_option($cat_id));
$t->set_var(lang_cats,lang('Select')); $t->set_var('lang_cats',lang('Select'));
$t->set_var("lang_addressbook",lang("Address book")); $t->set_var('lang_addressbook',lang('Address book'));
$t->set_var("th_bg",$phpgw_info["theme"]["th_bg"]); $t->set_var('th_bg',$phpgw_info['theme']['th_bg']);
$t->set_var("th_font",$phpgw_info["theme"]["font"]); $t->set_var('th_font',$phpgw_info['theme']['font']);
$t->set_var("th_text",$phpgw_info["theme"]["th_text"]); $t->set_var('th_text',$phpgw_info['theme']['th_text']);
$t->set_var("lang_add",lang("Add")); $t->set_var('lang_add',lang('Add'));
$t->set_var("add_url",$phpgw->link("/addressbook/add.php")); $t->set_var('add_url',$phpgw->link('/addressbook/add.php'));
$t->set_var("lang_addvcard",lang("AddVCard")); $t->set_var('lang_addvcard',lang('AddVCard'));
$t->set_var("vcard_url",$phpgw->link("/addressbook/vcardin.php")); $t->set_var('vcard_url',$phpgw->link('/addressbook/vcardin.php'));
$t->set_var("lang_import",lang("Import Contacts")); $t->set_var('lang_import',lang('Import Contacts'));
$t->set_var("import_url",$phpgw->link("/addressbook/import.php")); $t->set_var('import_url',$phpgw->link('/addressbook/import.php'));
$t->set_var("lang_export",lang("Export Contacts")); $t->set_var('lang_export',lang('Export Contacts'));
$t->set_var("export_url",$phpgw->link("/addressbook/export.php")); $t->set_var('export_url',$phpgw->link('/addressbook/export.php'));
$t->set_var("start",$start); $t->set_var('start',$start);
$t->set_var("sort",$sort); $t->set_var('sort',$sort);
$t->set_var("order",$order); $t->set_var('order',$order);
$t->set_var("filter",$filter); $t->set_var('filter',$filter);
$t->set_var("query",$query); $t->set_var('query',$query);
$t->set_var("cat_id",$cat_id); $t->set_var('cat_id',$cat_id);
$t->set_var("qfield",$qfield); $t->set_var('qfield',$qfield);
$t->set_var("query",$query); $t->set_var('query',$query);
$t->set_var("start",$start); $t->set_var('start',$start);
$t->set_var("filter",$filter); $t->set_var('filter',$filter);
$t->set_var("cols",$cols); $t->set_var('cols',$cols);
$t->pparse("out","addressbook_header"); $t->pparse('out','addressbook_header');
// Show the entries // Show the entries
for ($i=0;$i<count($entries);$i++) { // each entry for ($i=0;$i<count($entries);$i++) // each entry
$t->set_var(columns,""); {
$t->set_var('columns','');
$tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color);
$t->set_var(row_tr_color,$tr_color); $t->set_var('row_tr_color',$tr_color);
$myid = $entries[$i]["id"]; $myid = $entries[$i]['id'];
$myowner = $entries[$i]["owner"]; $myowner = $entries[$i]['owner'];
while ($column = each($columns_to_display)) { // each entry column while ($column = each($columns_to_display)) // each entry column
{
$ref=$data=""; $ref=$data="";
$coldata = $entries[$i][$column[0]]; $coldata = $entries[$i][$column[0]];
// Some fields require special formatting. // Some fields require special formatting.
if ($column[0] == "url") { if ($column[0] == 'url')
{
if ( !empty($coldata) && (substr($coldata,0,7) != 'http://') ) { $coldata = 'http://' . $coldata; } if ( !empty($coldata) && (substr($coldata,0,7) != 'http://') ) { $coldata = 'http://' . $coldata; }
$ref='<a href="'.$coldata.'" target="_new">'; $ref='<a href="'.$coldata.'" target="_new">';
$data=$coldata.'</a>'; $data=$coldata.'</a>';
} elseif ( ($column[0] == "email") || ($column[0] == "email_home") ) { }
if ($phpgw_info["user"]["apps"]["email"]) { elseif ( ($column[0] == 'email') || ($column[0] == 'email_home') )
{
if ($phpgw_info['user']['apps']['email'])
{
$ref='<a href="'.$phpgw->link("/email/compose.php","to=" . urlencode($coldata)).'" target="_new">'; $ref='<a href="'.$phpgw->link("/email/compose.php","to=" . urlencode($coldata)).'" target="_new">';
} else { }
else
{
$ref='<a href="mailto:'.$coldata.'">'; $ref='<a href="mailto:'.$coldata.'">';
} }
$data=$coldata."</a>"; $data=$coldata."</a>";
} else { // But these do not }
else // But these do not
{
$ref=""; $data=$coldata; $ref=""; $data=$coldata;
} }
$t->set_var(col_data,$ref.$data); $t->set_var('col_data',$ref.$data);
$t->parse("columns","column",True); $t->parse('columns','column',True);
} }
if (1) { if (1)
$t->set_var(row_view_link,$phpgw->link("/addressbook/view.php", {
$t->set_var('row_view_link',$phpgw->link('/addressbook/view.php',
"ab_id=$myid&start=$start&order=$order&filter=" "ab_id=$myid&start=$start&order=$order&filter="
. "$filter&query=$query&sort=$sort&cat_id=$cat_id")); . "$filter&query=$query&sort=$sort&cat_id=$cat_id"));
} else { }
$t->set_var(row_view_link,""); else
$t->set_var("lang_view",lang("Private")); {
$t->set_var('row_view_link','');
$t->set_var('lang_view',lang('Private'));
} }
$t->set_var(row_vcard_link,$phpgw->link("/addressbook/vcardout.php", $t->set_var('row_vcard_link',$phpgw->link('/addressbook/vcardout.php',
"ab_id=$myid&start=$start&sort=$sort&order=$order&filter=" "ab_id=$myid&start=$start&sort=$sort&order=$order&filter="
. "$filter&query=$query&sort=$sort&cat_id=$cat_id")); . "$filter&query=$query&sort=$sort&cat_id=$cat_id"));
// echo '<br>: ' . $this->grants[$myowner] . ' - ' . $myowner; // echo '<br>: ' . $this->grants[$myowner] . ' - ' . $myowner;
if ($this->check_perms($this->grants[$myowner],PHPGW_ACL_EDIT) || $myowner == $phpgw_info['user']['account_id']) { if ($this->check_perms($this->grants[$myowner],PHPGW_ACL_EDIT) || $myowner == $phpgw_info['user']['account_id'])
$t->set_var(row_edit,'<a href="' . $phpgw->link("/addressbook/edit.php", {
$t->set_var('row_edit','<a href="' . $phpgw->link("/addressbook/edit.php",
"ab_id=$myid&start=$start&sort=$sort&order=$order&filter=" "ab_id=$myid&start=$start&sort=$sort&order=$order&filter="
. "$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('Edit') . '</a>'); . "$filter&query=$query&sort=$sort&cat_id=$cat_id") . '">' . lang('Edit') . '</a>');
} else { }
$t->set_var(row_edit,'&nbsp;'); else
{
$t->set_var('row_edit','&nbsp;');
} }
$t->set_var(row_owner,$phpgw->accounts->id2name($myowner)); $t->set_var('row_owner',$phpgw->accounts->id2name($myowner));
$t->parse("rows","row",True); $t->parse('rows','row',True);
$t->pparse("out","row"); $t->pparse('out','row');
reset($columns_to_display); // If we don't reset it, our inside while won't loop reset($columns_to_display); // If we don't reset it, our inside while won't loop
} }
$t->pparse("out","addressbook_footer"); $t->pparse('out','addressbook_footer');
$phpgw->common->phpgw_footer(); $phpgw->common->phpgw_footer();
?> ?>