From 3daaf14c25ae51f2c4a820f3087ece1a30346380 Mon Sep 17 00:00:00 2001 From: Miles Lott Date: Fri, 13 Jul 2001 09:03:31 +0000 Subject: [PATCH] Moved preferences to ui/bo --- addressbook/inc/class.boaddressbook.inc.php | 53 + addressbook/inc/class.uiaddressbook.inc.php | 1097 +++++++++-------- addressbook/inc/hook_preferences.inc.php | 2 +- addressbook/preferences.php | 230 ---- addressbook/templates/default/preferences.tpl | 92 +- addressbook/templates/default/view.tpl | 24 +- 6 files changed, 707 insertions(+), 791 deletions(-) delete mode 100644 addressbook/preferences.php diff --git a/addressbook/inc/class.boaddressbook.inc.php b/addressbook/inc/class.boaddressbook.inc.php index e52f9d2578..8174f9ce7e 100644 --- a/addressbook/inc/class.boaddressbook.inc.php +++ b/addressbook/inc/class.boaddressbook.inc.php @@ -232,5 +232,58 @@ { return $this->so->delete_entry($ab_id); } + + function save_preferences($prefs,$other,$qfields,$fcat_id) + { + global $phpgw; + $phpgw->preferences->read_repository(); + if (is_array($prefs)) + { +/* _debug_array($prefs);exit; */ + while (list($pref,$x) = each($qfields)) + { + /* echo '
checking: ' . $pref . '=' . $prefs[$pref]; */ + if ($prefs[$pref] == 'on') + { + $phpgw->preferences->add('addressbook',$pref,'addressbook_on'); + } + else + { + $phpgw->preferences->delete('addressbook',$pref); + } + } + } + + if(is_array($other)) + { + $phpgw->preferences->delete('addressbook','mainscreen_showbirthdays'); + if ($other['mainscreen_showbirthdays']) + { + $phpgw->preferences->add('addressbook','mainscreen_showbirthdays'); + } + + $phpgw->preferences->delete('addressbook','default_filter'); + if ($other['default_filter']) + { + $phpgw->preferences->add('addressbook','default_filter'); + } + + $phpgw->preferences->delete('addressbook','autosave_category'); + if ($other['autosave_category']) + { + $phpgw->preferences->add('addressbook','autosave_category',True); + } + } + + if($fcat_id) + { + $phpgw->preferences->delete('addressbook','default_category'); + $phpgw->preferences->add('addressbook','default_category',$fcat_id); + } + + $phpgw->preferences->save_repository(True); + /* _debug_array($prefs);exit; */ + Header('Location: ' . $phpgw->link('/preferences/index.php')); + } } ?> diff --git a/addressbook/inc/class.uiaddressbook.inc.php b/addressbook/inc/class.uiaddressbook.inc.php index e738c4f6f8..11f647e4e6 100644 --- a/addressbook/inc/class.uiaddressbook.inc.php +++ b/addressbook/inc/class.uiaddressbook.inc.php @@ -40,7 +40,8 @@ 'add_email' => True, 'copy' => True, 'edit' => True, - 'delete' => True + 'delete' => True, + 'preferences' => True ); var $extrafields = array( @@ -135,29 +136,17 @@ function read_custom_fields() { - $i = 0; $j = 0; $fields = array(); @reset($this->prefs); while (list($col,$descr) = @each($this->prefs)) { + $tmp = ''; if ( substr($col,0,6) == 'extra_' ) { - $fields[$j]['name'] = ereg_replace('extra_','',$col); - $fields[$j]['name'] = ereg_replace(' ','_',$fields[$j]['name']); - $fields[$j]['id'] = $i; - - if ($query && ($fields[$j]['name'] != $query)) - { - unset($fields[$j]['name']); - unset($fields[$j]['id']); - } - else - { - /* echo "
".$j.": '".$fields[$j]['name']."'"; */ - $j++; - } + $tmp = ereg_replace('extra_','',$col); + $tmp = ereg_replace(' ','_',$tmp); + $fields[$tmp] = $tmp; } - $i++; } @reset($fields); return $fields; @@ -561,10 +550,594 @@ $phpgw->common->phpgw_footer(); } + function add_email() + { + global $phpgw,$phpgw_info,$name,$refereri,$add_email; + + $named = explode(' ', $name); + for ($i=count($named);$i>=0;$i--) { $names[$i] = $named[$i]; } + if ($names[2]) + { + $fields['n_given'] = $names[0]; + $fields['n_middle'] = $names[1]; + $fields['n_family'] = $names[2]; + } + else + { + $fields['n_given'] = $names[0]; + $fields['n_family'] = $names[1]; + } + $fields['email'] = $add_email; + $fields['access'] = 'private'; + $fields['tid'] = 'n'; + $referer = urlencode($referer); + + $this->bo->add_entry($phpgw_info['user']['account_id'],$fields); + $ab_id = $this->bo->get_lastid(); + + Header('Location: ' + . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer")); + } + + function copy() + { + global $phpgw,$phpgw_info,$ab_id; + + $addnew = $this->bo->read_entry($ab_id,$this->contacts->stock_contact_fields,$phpgw_info['user']['account_id']); + + $addnew[0]['note'] .= "\nCopied from ".$phpgw->accounts->id2name($addnew[0]['owner']).", record #".$addnew[0]['id']."."; + $addnew[0]['owner'] = $phpgw_info['user']['account_id']; + $addnew[0]['id'] = ''; + $fields = $addnew[0]; + + $this->bo->add_entry($fields['owner'],$fields); + $ab_id = $this->bo->get_lastid(); + + Header("Location: " . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.edit&ab_id=$ab_id")); + } + + function add() + { + global $phpgw,$phpgw_info,$submit; + + if ($submit) + { + $fields = $this->get_form(); + + $referer = urlencode($fields['referer']); + unset($fields['referer']); + + $this->bo->add_entry($phpgw_info['user']['account_id'],$fields); + + $ab_id = $this->bo->get_lastid(); + + Header('Location: ' + . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer")); + $phpgw->common->phpgw_exit(); + } + + $this->template->set_file(array('add' => 'add.tpl')); + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->addressbook_form('','menuaction=addressbook.uiaddressbook.add','Add','',$customfields,$this->cat_id); + + $this->template->set_var('lang_ok',lang('ok')); + $this->template->set_var('lang_clear',lang('clear')); + $this->template->set_var('lang_cancel',lang('cancel')); + $this->template->set_var('cancel_url',$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + $this->template->parse('out','add'); + $this->template->pparse('out','add'); + + $phpgw->common->phpgw_footer(); + } + + function edit() + { + global $phpgw,$phpgw_info,$submit,$ab_id; + + if ($submit) + { + $fields = $this->get_form(); + /* _debug_array($fields);exit; */ + $check = $this->bo->read_entry($fields['ab_id'],array('owner' => 'owner', 'tid' => 'tid')); + + if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_EDIT) && $check[0]['owner'] != $phpgw_info['user']['account_id']) + { + $userid = $check[0]['owner']; + } + else + { + $userid = $phpgw_info['user']['account_id']; + } + $referer = urlencode($fields['referer']); + unset($fields['referer']); + + $this->bo->update_entry($userid,$fields); + + Header("Location: " + . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=" . $fields['ab_id'] . "&referer=$referer")); + $phpgw->common->phpgw_exit(); + } + + /* First, make sure they have permission to this entry */ + $check = $this->bo->read_entry($ab_id,array('owner' => 'owner', 'tid' => 'tid')); + + if ( !$this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_EDIT) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) + { + Header("Location: " . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + /* Read in user custom fields, if any */ + $customfields = $this->read_custom_fields(); + + /* merge in extra fields */ + $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; + $fields = $this->bo->read_entry($ab_id,$qfields); + $this->addressbook_form('edit','menuaction=addressbook.uiaddressbook.edit',lang('Edit'),$fields[0],$customfields); + + $this->template->set_file(array('edit' => 'edit.tpl')); + + $this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $this->template->set_var('ab_id',$ab_id); + $this->template->set_var('tid',$check[0]['tid']); + $this->template->set_var('referer',$referer); + $this->template->set_var('lang_ok',lang('ok')); + $this->template->set_var('lang_clear',lang('clear')); + $this->template->set_var('lang_cancel',lang('cancel')); + $this->template->set_var('lang_submit',lang('submit')); + $this->template->set_var('cancel_link','
'); + + if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) || $check[0]['owner'] == $phpgw_info['user']['account_id']) + { + $this->template->set_var('delete_link',''); + $this->template->set_var('delete_button',''); + } + + $this->template->pfp('out','edit'); + $phpgw->common->phpgw_footer(); + } + + + function delete() + { + global $phpgw,$phpgw_info,$entry,$ab_id,$confirm; + + if (!$ab_id) + { + $ab_id = $entry['ab_id']; + } + if (!$ab_id) + { + Header('Location: ' . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + } + + $check = $this->bo->read_entry($ab_id,array('owner' => 'owner', 'tid' => 'tid')); + + if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) && $check[0]['owner'] != $phpgw_info['user']['account_id']) + { + Header('Location: ' . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + $this->template->set_file(array('delete' => 'delete.tpl')); + + if ($confirm != 'true') + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + $this->template->set_var('lang_sure',lang('Are you sure you want to delete this entry ?')); + $this->template->set_var('no_link',$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + $this->template->set_var('lang_no',lang('NO')); + $this->template->set_var('yes_link',$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.delete&ab_id=' . $ab_id . '&confirm=true')); + $this->template->set_var('lang_yes',lang('YES')); + $this->template->pparse('out','delete'); + + $phpgw->common->phpgw_footer(); + } + else + { + $this->bo->delete_entry($ab_id); + + @Header('Location: ' . $phpgw->link('/addressbook/index.php','menuaction=addressbook.uiaddressbook.get_list')); + } + } + + function view() + { + global $phpgw,$phpgw_info,$ab_id,$submit,$referer; + + // First, make sure they have permission to this entry + $check = $this->bo->read_entry($ab_id,array('owner' => 'owner')); + $perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ); + + if ( (!$perms) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) + { + Header("Location: " . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + + if (!$ab_id) + { + Header("Location: " . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); + $phpgw->common->phpgw_exit(); + } + elseif (!$submit && $ab_id) + { + $phpgw->common->phpgw_header(); + echo parse_navbar(); + } + + $this->template->set_file(array('view_t' => 'view.tpl')); + $this->template->set_block('view_t','view_header','view_header'); + $this->template->set_block('view_t','view_row','view_row'); + $this->template->set_block('view_t','view_footer','view_footer'); + $this->template->set_block('view_t','view_buttons','view_buttons'); + + $customfields = $this->read_custom_fields(); + /* _debug_array($this->prefs); */ + while (list($column,$x) = each($this->contacts->stock_contact_fields)) + { + if (isset($this->prefs[$column]) && $this->prefs[$column]) + { + $columns_to_display[$column] = True; + $colname[$column] = $column; + } + } + + // No prefs? + if (!$columns_to_display ) + { + $columns_to_display = array( + 'n_given' => 'n_given', + 'n_family' => 'n_family', + 'org_name' => 'org_name', + 'tel_work' => 'tel_work', + 'tel_home' => 'tel_home', + 'email' => 'email', + 'email_home' => 'email_home' + ); + while ($column = each($columns_to_display)) + { + $colname[$column[0]] = $column[1]; + } + $noprefs = " - " . lang('Please set your preferences for this app'); + } + + /* merge in extra fields */ + $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; + + $fields = $this->bo->read_entry($ab_id,$qfields); + + $record_owner = $fields[0]['owner']; + + if ($fields[0]["access"] == 'private') + { + $access_check = lang('private'); + } + else + { + $access_check = lang('public'); + } + + $this->template->set_var('lang_viewpref',lang("Address book - view") . $noprefs); + + @reset($qfields); + while (list($column,$null) = @each($qfields)) + { + if($this->display_name($colname[$column])) + { + $this->template->set_var('display_col',$this->display_name($colname[$column])); + } + elseif($this->display_name($column)) + { + $this->template->set_var('display_col',$this->display_name($column)); + } + else + { + $this->template->set_var('display_col',ucfirst($column)); + } + $ref = $data = ""; + if ($fields[0][$column]) + { + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $this->template->set_var('th_bg',$tr_color); + $coldata = $fields[0][$column]; + /* Some fields require special formatting. */ + if ( ($column == 'note' || $column == 'pubkey') && $coldata ) + { + $datarray = explode ("\n",$coldata); + if ($datarray[1]) + { + while (list($key,$info) = each ($datarray)) + { + if ($key) + { + $data .= ' ' .$info; + } + else + { + /* First row, don't close td/tr */ + $data .= $info; + } + } + $data .= ""; + } + else + { + $data = $coldata; + } + } + elseif($column == 'label' && $coldata) + { + $data .= $this->contacts->formatted_address($fields[0]['id'],'',False); + } + elseif ($column == "url" && $coldata) + { + $ref = ''; + $data = $coldata . ''; + } + elseif ( (($column == "email") || ($column == "email_home")) && $coldata) + { + if ($phpgw_info["user"]["apps"]["email"]) + { + $ref=''; + } + else + { + $ref = ''; + } + $data = $coldata.""; + } + else + { + /* But these do not */ + $ref = ""; $data = $coldata; + } + + if (!$data) + { + $this->template->set_var('ref_data'," "); + } + else + { + $this->template->set_var('ref_data',$ref . $data); + } + $this->template->parse('cols','view_row',True); + } + } + /* Following cleans up view_row, since we were only using it to fill {cols} */ + $this->template->set_var('view_row',''); + + $fields['cat_id'] = is_array($this->cat_id) ? implode(',',$this->cat_id) : $this->cat_id; + + $cats = explode(',',$fields[0]['cat_id']); + if ($cats[1]) + { + while (list($key,$contactscat) = each($cats)) + { + if ($contactscat) + { + $catinfo = $this->cat->return_single($contactscat); + $catname .= $catinfo[0]['name'] . '; '; + } + } + if (!$this->cat_id) + { + $this->cat_id = $cats[0]; + } + } + else + { + $fields[0]['cat_id'] = ereg_replace(',','',$fields[0]['cat_id']); + $catinfo = $this->cat->return_single($fields[0]['cat_id']); + $catname = $catinfo[0]['name']; + if (!$this->cat_id) + { + $this->cat_id = $fields[0]['cat_id']; + } + } + + if (!$catname) { $catname = lang('none'); } + + // These are in the footer + $this->template->set_var('lang_owner',lang('Record owner')); + $this->template->set_var('owner',$phpgw->common->grab_owner_name($record_owner)); + $this->template->set_var('lang_access',lang('Record access')); + $this->template->set_var('access',$access_check); + $this->template->set_var('lang_category',lang('Category')); + $this->template->set_var('catname',$catname); + + if (($this->contacts->grants[$record_owner] & PHPGW_ACL_EDIT) || ($record_owner == $phpgw_info['user']['account_id'])) + { + $extra_vars = array('cd' => 16,'query' => $this->query,'cat_id' => $this->cat_id); + + if ($referer) + { + $extra_vars += array('referer' => urlencode($referer)); + } + + $this->template->set_var('edit_button',$this->html_1button_form('edit','Edit', + $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.edit&ab_id=' .$ab_id))); + } + $this->template->set_var('copy_button',$this->html_1button_form('submit','copy', + $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.copy&ab_id=' . $fields[0]['id']))); + + if ($fields[0]['n_family'] && $fields[0]['n_given']) + { + $this->template->set_var('vcard_button',$this->html_1button_form('VCardForm','VCard', + $phpgw->link('/index.php','menuaction=addressbook.uivcard.out&ab_id=' .$ab_id))); + } + else + { + $this->template->set_var('vcard_button',lang('no vcard')); + } + + $this->template->set_var('done_button',$this->html_1button_form('DoneForm','Done', + $referer ? ereg_replace('/phpgroupware','',$referer) : $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list'))); + $this->template->set_var('access_link',$access_link); + + $this->template->pfp('out','view_t'); + + $phpgw->common->hook('addressbook_view'); + + $phpgw->common->phpgw_footer(); + } + + function html_1button_form($name,$lang,$link) + { + $html = '' . "\n"; + $html .= '' . "\n"; + $html .= '
' . "\n"; + return $html; + } + + function preferences() + { + global $phpgw,$phpgw_info,$submit,$prefs,$other,$fcat_id; + /* _debug_array($this->prefs); */ + $customfields = $this->read_custom_fields(); + + $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; + + if ($submit) + { + $totalerrors = 0; + if (!count($prefs)) + { + $errors[$totalerrors++] = lang('You must select at least 1 column to display'); + } + if (!$totalerrors) + { + @reset($qfields); + $this->bo->save_preferences($prefs,$other,$qfields,$fcat_id); + } + } + + $phpgw->common->phpgw_header(); + echo parse_navbar(); + + if ($totalerrors) + { + echo '

' . $phpgw->common->error_list($errors) . '
'; + } + + $this->template->set_file(array('preferences' => 'preferences.tpl')); + + $this->template->set_var(action_url,$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.preferences')); + + $i = 0; $j = 0; + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + + while (list($col, $descr) = each($qfields)) + { + // echo "
test: $col - $i $j - " . count($abc); + $i++; $j++; + $showcol = $this->display_name($col); + if (!$showcol) { $showcol = $col; } + // yank the *'s prior to testing for a valid column description + $coltest = ereg_replace("\*","",$showcol); + if ($coltest) + { + $this->template->set_var($col,$showcol); + if ($phpgw_info['user']['preferences']['addressbook'][$col]) + { + $this->template->set_var($col.'_checked',' checked'); + } + else + { + $this->template->set_var($col.'_checked',''); + } + } + } + + if ($customfields) + { + $custom_var = ' + + '.lang('Custom').' '.lang('Fields').': + + + +'; + while( list($cf) = each($customfields) ) + { + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $custom_var .= "\n" . '' . "\n"; + $custom_var .= ' prefs[$cf] ? ' checked' : '') + . '>' . $cf . '' . "\n" + . '' . "\n"; + } + $this->template->set_var('custom_fields',$custom_var); + } + else + { + $this->template->set_var('custom_fields',''); + } + + $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); + $this->template->set_var(tr_color,$tr_color); + $this->template->set_var('lang_showbirthday',lang('show birthday reminders on main screen')); + + if ($this->prefs['mainscreen_showbirthdays']) + { + $this->template->set_var('show_birthday',' checked'); + } + else + { + $this->template->set_var('show_birthday',''); + } + + $list = array( + '' => lang('All'), + 'private' => lang('Private'), + 'blank' => lang('Blank') + ); + $this->template->set_var('lang_default_filter',lang('Default Filter')); + $this->template->set_var('filter_select',$this->formatted_list('other[default_filter]',$list,$this->prefs['default_filter'])); + + $this->template->set_var('lang_autosave',lang('Autosave default category')); + if ($this->prefs['autosave_category']) + { + $this->template->set_var('autosave',' checked'); + } + else + { + $this->template->set_var('autosave',''); + } + $this->template->set_var('lang_defaultcat',lang('Default Category')); + $this->template->set_var('cat_select',$this->cat_option($this->prefs['default_category'])); + $this->template->set_var('lang_abprefs',lang('Addressbook').' '.lang('Preferences')); + $this->template->set_var('lang_fields',lang('Fields to show in address list')); + $this->template->set_var('lang_personal',lang('Personal')); + $this->template->set_var('lang_business',lang('Business')); + $this->template->set_var('lang_home',lang('Home')); + $this->template->set_var('lang_phones',lang('Extra').' '.lang('Phone Numbers')); + $this->template->set_var('lang_other',lang('Other').' '.lang('Fields')); + $this->template->set_var('lang_otherprefs',lang('Other').' '.lang('Preferences')); + $this->template->set_var('lang_submit',lang('submit')); + $this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']); + $this->template->set_var('th_text',$phpgw_info['theme']['th_text']); + $this->template->set_var('row_on',$phpgw_info['theme']['row_on']); + $this->template->set_var('row_off',$phpgw_info['theme']['row_off']); + + $this->template->pparse('out','preferences'); + $phpgw->common->phpgw_footer(); + } + function get_form() { global $entry,$fcat_id; - /* _debug_array($entry); */ + /* _debug_array($entry); exit; */ if (!$entry['bday_month'] && !$entry['bday_day'] && !$entry['bday_year']) { @@ -661,9 +1234,10 @@ } $fields['adr_two_type'] = substr($typeb,0,-1); - while (list($name,$val) = @each($entry['customfields'])) + $custom = $this->read_custom_fields(); + while (list($name,$val) = @each($custom)) { - $fields[$name] = $val; + $fields[$name] = $entry[$val]; } $fields['ophone'] = $entry['ophone']; @@ -800,7 +1374,7 @@   '.$value.': - + '; } @@ -1099,486 +1673,5 @@ $this->template->pfp('out','form'); } //end form function - - function add_email() - { - global $phpgw,$phpgw_info,$name,$refereri,$add_email; - - $named = explode(' ', $name); - for ($i=count($named);$i>=0;$i--) { $names[$i] = $named[$i]; } - if ($names[2]) - { - $fields['n_given'] = $names[0]; - $fields['n_middle'] = $names[1]; - $fields['n_family'] = $names[2]; - } - else - { - $fields['n_given'] = $names[0]; - $fields['n_family'] = $names[1]; - } - $fields['email'] = $add_email; - $fields['access'] = 'private'; - $fields['tid'] = 'n'; - $referer = urlencode($referer); - - $this->bo->add_entry($phpgw_info['user']['account_id'],$fields); - $ab_id = $this->bo->get_lastid(); - - Header('Location: ' - . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer")); - } - - function copy() - { - global $phpgw,$phpgw_info,$ab_id; - - $addnew = $this->bo->read_entry($ab_id,$this->contacts->stock_contact_fields,$phpgw_info['user']['account_id']); - - $addnew[0]['note'] .= "\nCopied from ".$phpgw->accounts->id2name($addnew[0]['owner']).", record #".$addnew[0]['id']."."; - $addnew[0]['owner'] = $phpgw_info['user']['account_id']; - $addnew[0]['id'] = ''; - $fields = $addnew[0]; - - $this->bo->add_entry($fields['owner'],$fields); - $ab_id = $this->bo->get_lastid(); - - Header("Location: " . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.edit&ab_id=$ab_id")); - } - - function add() - { - global $phpgw,$phpgw_info,$submit; - - if ($submit) - { - $fields = $this->get_form(); - - $referer = urlencode($fields['referer']); - unset($fields['referer']); - - $this->bo->add_entry($phpgw_info['user']['account_id'],$fields); - - $ab_id = $this->bo->get_lastid(); - - Header('Location: ' - . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=$ab_id&referer=$referer")); - $phpgw->common->phpgw_exit(); - } - - $this->template->set_file(array('add' => 'add.tpl')); - - $phpgw->common->phpgw_header(); - echo parse_navbar(); - - $this->addressbook_form('','menuaction=addressbook.uiaddressbook.add','Add','',$customfields,$this->cat_id); - - $this->template->set_var('lang_ok',lang('ok')); - $this->template->set_var('lang_clear',lang('clear')); - $this->template->set_var('lang_cancel',lang('cancel')); - $this->template->set_var('cancel_url',$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $this->template->parse('out','add'); - $this->template->pparse('out','add'); - - $phpgw->common->phpgw_footer(); - } - - function edit() - { - global $phpgw,$phpgw_info,$submit,$ab_id; - - if ($submit) - { - $fields = $this->get_form(); - $check = $this->bo->read_entry($fields['ab_id'],array('owner' => 'owner', 'tid' => 'tid')); - - if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_EDIT) && $check[0]['owner'] != $phpgw_info['user']['account_id']) - { - $userid = $check[0]['owner']; - } - else - { - $userid = $phpgw_info['user']['account_id']; - } - $referer = urlencode($fields['referer']); - unset($fields['referer']); - - $this->bo->update_entry($userid,$fields); - - Header("Location: " - . $phpgw->link('/index.php',"menuaction=addressbook.uiaddressbook.view&ab_id=" . $fields['ab_id'] . "&referer=$referer")); - $phpgw->common->phpgw_exit(); - } - - /* First, make sure they have permission to this entry */ - $check = $this->bo->read_entry($ab_id,array('owner' => 'owner', 'tid' => 'tid')); - - if ( !$this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_EDIT) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) - { - Header("Location: " . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $phpgw->common->phpgw_exit(); - } - - $phpgw->common->phpgw_header(); - echo parse_navbar(); - - /* Read in user custom fields, if any */ - $customfields = $this->read_custom_fields(); - - /* merge in extra fields */ - $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; - $fields = $this->bo->read_entry($ab_id,$qfields); - $this->addressbook_form('edit','menuaction=addressbook.uiaddressbook.edit',lang('Edit'),$fields[0],$customfields); - - $this->template->set_file(array('edit' => 'edit.tpl')); - - $this->template->set_var('th_bg',$phpgw_info['theme']['th_bg']); - $this->template->set_var('ab_id',$ab_id); - $this->template->set_var('tid',$check[0]['tid']); - $this->template->set_var('referer',$referer); - $this->template->set_var('lang_ok',lang('ok')); - $this->template->set_var('lang_clear',lang('clear')); - $this->template->set_var('lang_cancel',lang('cancel')); - $this->template->set_var('lang_submit',lang('submit')); - $this->template->set_var('cancel_link','
'); - - if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) || $check[0]['owner'] == $phpgw_info['user']['account_id']) - { - $this->template->set_var('delete_link',''); - $this->template->set_var('delete_button',''); - } - - $this->template->pfp('out','edit'); - $phpgw->common->phpgw_footer(); - } - - function view() - { - global $phpgw,$phpgw_info,$ab_id,$submit,$referer; - - // First, make sure they have permission to this entry - $check = $this->bo->read_entry($ab_id,array('owner' => 'owner')); - $perms = $this->contacts->check_perms($this->contacts->grants[$check[0]['owner']],PHPGW_ACL_READ); - - if ( (!$perms) && ($check[0]['owner'] != $phpgw_info['user']['account_id']) ) - { - Header("Location: " . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $phpgw->common->phpgw_exit(); - } - - if (!$ab_id) - { - Header("Location: " . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $phpgw->common->phpgw_exit(); - } - elseif (!$submit && $ab_id) - { - $phpgw->common->phpgw_header(); - echo parse_navbar(); - } - - $this->template->set_file(array('view_t' => 'view.tpl')); - $this->template->set_block('view_t','view_header','view_header'); - $this->template->set_block('view_t','view_row','view_row'); - $this->template->set_block('view_t','view_footer','view_footer'); - $this->template->set_block('view_t','view_buttons','view_buttons'); - - $customfields = $this->read_custom_fields(); - - while ($column = each($this->contacts->stock_contact_fields)) - { - if (isset($this->prefs[$column[0]]) && $this->prefs[$column[0]]) - { - $columns_to_display[$column[0]] = True; - $colname[$column[0]] = $column[0]; - } - } - - // No prefs? - if (!$columns_to_display ) - { - $columns_to_display = array( - 'n_given' => 'n_given', - 'n_family' => 'n_family', - 'org_name' => 'org_name', - 'tel_work' => 'tel_work', - 'tel_home' => 'tel_home', - 'email' => 'email', - 'email_home' => 'email_home' - ); - while ($column = each($columns_to_display)) - { - $colname[$column[0]] = $column[1]; - } - $noprefs = " - " . lang('Please set your preferences for this app'); - } - - /* merge in extra fields */ - $qfields = $this->contacts->stock_contact_fields + $this->extrafields + $customfields; - - $fields = $this->bo->read_entry($ab_id,$qfields); - - $record_owner = $fields[0]['owner']; - - if ($fields[0]["access"] == 'private') - { - $access_check = lang('private'); - } - else - { - $access_check = lang('public'); - } - - $this->template->set_var('lang_viewpref',lang("Address book - view") . $noprefs); - - @reset($qfields); - while (list($column,$null) = @each($qfields)) - { - if($this->display_name($colname[$column])) - { - $this->template->set_var('display_col',$this->display_name($colname[$column])); - } - elseif($this->display_name($column)) - { - $this->template->set_var('display_col',$this->display_name($column)); - } - else - { - $this->template->set_var('display_col',ucfirst($column)); - } - $ref = $data = ""; - if ($fields[0][$column]) - { - $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); - $this->template->set_var('th_bg',$tr_color); - $coldata = $fields[0][$column]; - /* Some fields require special formatting. */ - if ( ($column == 'note' || $column == 'pubkey') && $coldata ) - { - $datarray = explode ("\n",$coldata); - if ($datarray[1]) - { - while (list($key,$info) = each ($datarray)) - { - if ($key) - { - $data .= ' ' .$info; - } - else - { - /* First row, don't close td/tr */ - $data .= $info; - } - } - $data .= ""; - } - else - { - $data = $coldata; - } - } - elseif($column == 'label' && $coldata) - { - $data .= $this->contacts->formatted_address($fields[0]['id'],'',False); - } - elseif ($column == "url" && $coldata) - { - $ref = ''; - $data = $coldata . ''; - } - elseif ( (($column == "email") || ($column == "email_home")) && $coldata) - { - if ($phpgw_info["user"]["apps"]["email"]) - { - $ref=''; - } - else - { - $ref = ''; - } - $data = $coldata.""; - } - else - { - /* But these do not */ - $ref = ""; $data = $coldata; - } - - if (!$data) - { - $this->template->set_var('ref_data'," "); - } - else - { - $this->template->set_var('ref_data',$ref . $data); - } - $this->template->parse('cols','view_row',True); - } - } - /* Following cleans up view_row, since we were only using it to fill {cols} */ - $this->template->set_var('view_row',''); - - $fields['cat_id'] = is_array($this->cat_id) ? implode(',',$this->cat_id) : $this->cat_id; - - $cats = explode(',',$fields[0]['cat_id']); - if ($cats[1]) - { - while (list($key,$contactscat) = each($cats)) - { - if ($contactscat) - { - $catinfo = $this->cat->return_single($contactscat); - $catname .= $catinfo[0]['name'] . '; '; - } - } - if (!$this->cat_id) - { - $this->cat_id = $cats[0]; - } - } - else - { - $fields[0]['cat_id'] = ereg_replace(',','',$fields[0]['cat_id']); - $catinfo = $this->cat->return_single($fields[0]['cat_id']); - $catname = $catinfo[0]['name']; - if (!$this->cat_id) - { - $this->cat_id = $fields[0]['cat_id']; - } - } - - if (!$catname) { $catname = lang('none'); } - - // These are in the footer - $this->template->set_var('lang_owner',lang('Record owner')); - $this->template->set_var('owner',$phpgw->common->grab_owner_name($record_owner)); - $this->template->set_var('lang_access',lang("Record access")); - $this->template->set_var('access',$access_check); - $this->template->set_var('lang_category',lang('Category')); - $this->template->set_var('catname',$catname); - - if (($this->contacts->grants[$record_owner] & PHPGW_ACL_EDIT) || ($record_owner == $phpgw_info['user']['account_id'])) - { - $extra_vars = array('cd' => 16,'query' => $this->query,'cat_id' => $this->cat_id); - - if ($referer) - { - $extra_vars += array('referer' => urlencode($referer)); - } - - $this->template->set_var('edit_button',$this->html_1button_form('edit','Edit',array(),'/index.php','menuaction=addressbook.uiaddressbook.edit&ab_id=' .$ab_id)); - } - $this->template->set_var('copy_button',$this->html_1button_form('submit','copy',array(), - '/index.php','menuaction=addressbook.uiaddressbook.copy&ab_id=' . $fields[0]['id'])); - - if ($fields[0]['n_family'] && $fields[0]['n_given']) - { - $this->template->set_var('vcard_button',$this->html_1button_form('VCardForm','VCard',array(),'/index.php','menuaction=addressbook.uivcard.out&ab_id=' .$ab_id)); - } - else - { - $this->template->set_var('vcard_button',lang('no vcard')); - } - - $this->template->set_var('done_button',$this->html_1button_form('DoneForm','Done',array(), - $referer ? ereg_replace('/phpgroupware','',$referer) : '/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $this->template->set_var('access_link',$access_link); - - $this->template->pfp('out','view_t'); - - $phpgw->common->hook('addressbook_view'); - - $phpgw->common->phpgw_footer(); - } - - function delete() - { - global $phpgw,$phpgw_info,$entry,$ab_id,$confirm; - - if (!$ab_id) - { - $ab_id = $entry['ab_id']; - } - if (!$ab_id) - { - Header('Location: ' . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - } - - $check = $this->bo->read_entry($ab_id,array('owner' => 'owner', 'tid' => 'tid')); - - if (($this->contacts->grants[$check[0]['owner']] & PHPGW_ACL_DELETE) && $check[0]['owner'] != $phpgw_info['user']['account_id']) - { - Header('Location: ' . $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $phpgw->common->phpgw_exit(); - } - - $this->template->set_file(array('delete' => 'delete.tpl')); - - if ($confirm != 'true') - { - $phpgw->common->phpgw_header(); - echo parse_navbar(); - - $this->template->set_var('lang_sure',lang('Are you sure you want to delete this entry ?')); - $this->template->set_var('no_link',$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.get_list')); - $this->template->set_var('lang_no',lang('NO')); - $this->template->set_var('yes_link',$phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.delete&ab_id=' . $ab_id . '&confirm=true')); - $this->template->set_var('lang_yes',lang('YES')); - $this->template->pparse('out','delete'); - - $phpgw->common->phpgw_footer(); - } - else - { - $this->bo->delete_entry($ab_id); - - @Header('Location: ' . $phpgw->link('/addressbook/index.php','menuaction=addressbook.uiaddressbook.get_list')); - } - } - - function html_input_hidden($vars) - { - if (!is_array($vars)) { return ''; } - while (list($name,$value) = each($vars)) - { - if ($value != '') // dont need to send all the empty vars - { - $html .= '' . "\n"; - } - } - return $html; - } - - function html_submit_button($name,$lang) - { - return '' . "\n"; - } - - function phpgw_link($url,$vars='') - { - global $phpgw; - if (is_array( $vars )) - { - while(list($name,$value) = each($vars)) - { - if ($value != '') // dont need to send all the empty vars - { - $v[] = "$name=$value"; - } - } - $vars = implode('&',$v); - } - return $phpgw->link($url,$vars); - } - - function html_1button_form($name,$lang,$hidden_vars,$url,$url_vars='',$method='POST') - { - $html = "phpgw_link($url,$url_vars)."\">\n"; - $html .= $this->html_input_hidden($hidden_vars); - $html .= $this->html_submit_button($name,$lang); - $html .= "
\n"; - return $html; - } } ?> diff --git a/addressbook/inc/hook_preferences.inc.php b/addressbook/inc/hook_preferences.inc.php index f915ef2621..86e34ea1c4 100644 --- a/addressbook/inc/hook_preferences.inc.php +++ b/addressbook/inc/hook_preferences.inc.php @@ -15,7 +15,7 @@ // Only Modify the $file and $title variables..... $title = $appname; $file = Array( - 'Preferences' => $phpgw->link('/addressbook/preferences.php'), + 'Preferences' => $phpgw->link('/index.php','menuaction=addressbook.uiaddressbook.preferences'), 'Grant Access' => $phpgw->link('/preferences/acl_preferences.php','acl_app='.$appname), 'Edit Categories' => $phpgw->link('/preferences/categories.php','cats_app='.$appname . '&cats_level=True&global_cats=True'), 'Edit custom fields' => $phpgw->link('/addressbook/fields.php') diff --git a/addressbook/preferences.php b/addressbook/preferences.php deleted file mode 100644 index c9f8be5fd2..0000000000 --- a/addressbook/preferences.php +++ /dev/null @@ -1,230 +0,0 @@ - 'addressbook', - 'noheader' => True, - 'nonavbar' => True, - 'noappheader' => True, - 'noappfooter' => True, - 'enable_contacts_class' => True, - 'enable_categories_class' => True, - 'enable_nextmatchs_class' => True - ); - - include('../header.inc.php'); - - $contacts = CreateObject('phpgwapi.contacts'); - - $extrafields = array( - 'ophone' => 'ophone', - 'address2' => 'address2', - 'address3' => 'address3' - ); - - $phpgw->preferences->read_repository(); - $customfields = array(); - if ($phpgw_info['user']['preferences']['addressbook']) - { - while (list($col,$descr) = each($phpgw_info['user']['preferences']['addressbook'])) - { - if ( substr($col,0,6) == 'extra_' ) - { - $field = ereg_replace('extra_','',$col); - $customfields[$field] = ucfirst($field); - } - } - } - - $qfields = $contacts->stock_contact_fields + $extrafields + $customfields; - - if ($submit) - { - $totalerrors = 0; - if (! count($ab_selected)) - { - $errors[$totalerrors++] = lang('You must select at least 1 column to display'); - } - if (! $totalerrors) - { - $phpgw->preferences->read_repository(); - while (list($pref[0]) = each($qfields)) - { - if ($ab_selected["$pref[0]"]) - { - $phpgw->preferences->change('addressbook',$pref[0],'addressbook_' . $ab_selected["$pref[0]"]); - } - else - { - $phpgw->preferences->delete('addressbook',$pref[0],'addressbook_' . $ab_selected["$pref[0]"]); - } - } - - if ($mainscreen_showbirthdays) - { - $phpgw->preferences->delete('addressbook','mainscreen_showbirthdays'); - $phpgw->preferences->add('addressbook','mainscreen_showbirthdays'); - } - else - { - $phpgw->preferences->delete('addressbook','mainscreen_showbirthdays'); - } - if ($default_filter) - { - $phpgw->preferences->delete('addressbook','default_filter'); - $phpgw->preferences->add('addressbook','default_filter'); - } - else - { - $phpgw->preferences->delete('addressbook','default_filter'); - } - if ($autosave_category) - { - $phpgw->preferences->delete('addressbook','autosave_category'); - $phpgw->preferences->add('addressbook','autosave_category',True); - } - else - { - $phpgw->preferences->delete('addressbook','autosave_category'); - } - - if ($cat_id) - { - $phpgw->preferences->delete('addressbook','default_category'); - $phpgw->preferences->add('addressbook','default_category',$cat_id); - } - else - { - $phpgw->preferences->delete('addressbook','default_category'); - } - - $phpgw->preferences->save_repository(True); - Header('Location: ' . $phpgw->link('/preferences/index.php')); - } - } - - $phpgw->common->phpgw_header(); - echo parse_navbar(); - - if ($totalerrors) - { - echo '

' . $phpgw->common->error_list($errors) . '
'; - } - - $t = new Template(PHPGW_APP_TPL); - $t->set_file(array( - 'preferences' => 'preferences.tpl' - )); - - $t->set_var(action_url,$phpgw->link('/addressbook/preferences.php')); - - $i = 0; $j = 0; - $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); - - while (list($col, $descr) = each($qfields)) - { - // echo "
test: $col - $i $j - " . count($abc); - $i++; $j++; - $showcol = display_name($col); - if (!$showcol) { $showcol = $col; } - // yank the *'s prior to testing for a valid column description - $coltest = ereg_replace("\*","",$showcol); - if ($coltest) - { - $t->set_var($col,$showcol); - if ($phpgw_info['user']['preferences']['addressbook'][$col]) - { - $t->set_var($col.'_checked',' checked'); - } - else - { - $t->set_var($col.'_checked',''); - } - } - } - - if ($customfields) - { - $custom_var = ' - - '.lang('Custom').' '.lang('Fields').': - - - -'; - while( list($cf) = each($customfields) ) - { - $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); - $custom_var .= "\n" . ''; - $custom_var .= ' ' . $cf . '' . "\n" - . '' . "\n"; - } - $t->set_var('custom_fields',$custom_var); - } - else - { - $t->set_var('custom_fields',''); - } - - $tr_color = $phpgw->nextmatchs->alternate_row_color($tr_color); - $t->set_var(tr_color,$tr_color); - $t->set_var('lang_showbirthday',lang('show birthday reminders on main screen')); - - if ($phpgw_info['user']['preferences']['addressbook']['mainscreen_showbirthdays']) - { - $t->set_var('show_birthday',' checked'); - } - else - { - $t->set_var('show_birthday',''); - } - - $list = array( - '' => lang('All'), - 'private' => lang('Private'), - 'blank' => lang('Blank') - ); - $t->set_var('lang_default_filter',lang('Default Filter')); - $t->set_var('filter_select',formatted_list('default_filter',$list,$phpgw_info['user']['preferences']['addressbook']['default_filter'])); - - $t->set_var('lang_autosave',lang('Autosave default category')); - if ($phpgw_info['user']['preferences']['addressbook']['autosave_category']) - { - $t->set_var('autosave',' checked'); - } - else - { - $t->set_var('autosave',''); - } - $t->set_var('lang_defaultcat',lang('Default Category')); - $t->set_var('cat_select',cat_option($phpgw_info['user']['preferences']['addressbook']['default_category'])); - $t->set_var('lang_abprefs',lang('Addressbook').' '.lang('Preferences')); - $t->set_var('lang_fields',lang('Fields to show in address list')); - $t->set_var('lang_personal',lang('Personal')); - $t->set_var('lang_business',lang('Business')); - $t->set_var('lang_home',lang('Home')); - $t->set_var('lang_phones',lang('Extra').' '.lang('Phone Numbers')); - $t->set_var('lang_other',lang('Other').' '.lang('Fields')); - $t->set_var('lang_otherprefs',lang('Other').' '.lang('Preferences')); - $t->set_var('lang_submit',lang('submit')); - $t->set_var('th_bg',$phpgw_info['theme']['th_bg']); - $t->set_var('th_text',$phpgw_info['theme']['th_text']); - $t->set_var('row_on',$phpgw_info['theme']['row_on']); - $t->set_var('row_off',$phpgw_info['theme']['row_off']); - - $t->pparse('out','preferences'); - $phpgw->common->phpgw_footer(); -?> diff --git a/addressbook/templates/default/preferences.tpl b/addressbook/templates/default/preferences.tpl index 651099a3b3..1e8facdca0 100644 --- a/addressbook/templates/default/preferences.tpl +++ b/addressbook/templates/default/preferences.tpl @@ -9,17 +9,17 @@ {lang_personal}: - {fn} - {n_given} - {n_family} - {n_middle} + {fn} + {n_given} + {n_family} + {n_middle}     - {n_prefix} - {n_suffix} - {bday} + {n_prefix} + {n_suffix} + {bday}       @@ -31,27 +31,27 @@ {lang_business}: - {org_name} - {org_unit} - {title} + {org_name} + {org_unit} + {title}       - {adr_one_street} - {address2} - {address3} - {adr_one_locality} - {adr_one_region} - {adr_one_postalcode} + {adr_one_street} + {address2} + {address3} + {adr_one_locality} + {adr_one_region} + {adr_one_postalcode} - {adr_one_countryname} - {adr_one_type} - {tel_work} - {email} - {email_type} + {adr_one_countryname} + {adr_one_type} + {tel_work} + {email} + {email_type}   @@ -60,19 +60,19 @@ {lang_home}: - {adr_two_street} - {adr_two_locality} - {adr_two_region} - {adr_two_postalcode} + {adr_two_street} + {adr_two_locality} + {adr_two_region} + {adr_two_postalcode}     - {adr_two_countryname} - {adr_two_type} - {tel_home} - {email_home} - {email_home_type} + {adr_two_countryname} + {adr_two_type} + {tel_home} + {email_home} + {email_home_type}   @@ -81,19 +81,19 @@ {lang_phones}: - {tel_voice} - {tel_fax} - {tel_msg} - {tel_cell} - {tel_pager} - {tel_bbs} + {tel_voice} + {tel_fax} + {tel_msg} + {tel_cell} + {tel_pager} + {tel_bbs} - {tel_modem} - {tel_car} - {tel_isdn} - {tel_video} - {ophone} + {tel_modem} + {tel_car} + {tel_isdn} + {tel_video} + {ophone}   @@ -103,9 +103,9 @@ {lang_other}: - {geo} - {url} - {tz} + {geo} + {url} + {tz}       @@ -126,7 +126,7 @@ {filter_select} {lang_showbirthday} - + @@ -136,7 +136,7 @@ {lang_autosave} - + diff --git a/addressbook/templates/default/view.tpl b/addressbook/templates/default/view.tpl index dd544491fe..9089d5cd87 100644 --- a/addressbook/templates/default/view.tpl +++ b/addressbook/templates/default/view.tpl @@ -31,21 +31,21 @@
- - - + +
+ + + - + - + - + - -
{edit_button} - + {copy_button} - + {vcard_button} - + {done_button} -
+