extracted address- and some other selection-boxes into class phpgwapi.sbox2

This commit is contained in:
Ralf Becker 2001-05-28 20:20:38 +00:00
parent f07fd0041d
commit 6b6556b628
3 changed files with 43 additions and 135 deletions

View File

@ -85,8 +85,8 @@
'type' => $type,
'from' => $from,
'addr' => $addr,
'addr_id' => $addr_id,
'proj_id' => $proj_id,
'addr_id' => $id_addr,
'proj_id' => $id_project,
'subject' => $subject,
'des' => $des,
'pri' => $pri,
@ -101,7 +101,7 @@
'responsible' => $responsible
));
if (!$addrsearch && !$projectsearch) {
if (!$query_addr && !$query_project) {
Header('Location: ' . $phpgw->link('/infolog/index.php', "cd=15&sort=$sort&order=$order&query=$query&".
"start=$start&filter=$filter&cat_id=$cat_id"));
}
@ -172,7 +172,7 @@
default:
$info_action = 'Info Log - Edit'; break;
}
$t->set_var('lang_info_action',lang($info_action).($addrsearch?' - '.lang('Search for:')." '$addrsearch'":''));
$t->set_var('lang_info_action',lang($info_action) . ($query_addr ? ' - '.lang('Search for:')." '$query_addr'" : ''));
$t->set_var($phpgw->infolog->setStyleSheet( ));
$t->set_var('lang_category',lang('Category'));
$t->set_var('lang_none',lang('None'));
@ -181,76 +181,20 @@
$t->set_var('actionurl',$phpgw->link('/infolog/edit.php'));
$t->set_var('common_hidden_vars',$common_hidden_vars);
$sb2 = CreateObject('phpgwapi.sbox2');
$t->set_var('lang_owner',lang('Owner'));
$t->set_var('owner_info',$phpgw->infolog->accountInfo($phpgw->infolog->data['info_owner']));
$t->set_var('owner_info',$sb2->accountInfo($phpgw->infolog->data['info_owner']));
$t->set_var('lang_type',lang('Type'));
$t->set_var('type_list',$phpgw->infolog->getEnum('type',$phpgw->infolog->data['info_type'],$phpgw->infolog->enums['type']));
$t->set_var('type_list',$sb2->getArrayItem('type',$phpgw->infolog->data['info_type'],$phpgw->infolog->enums['type']));
$t->set_var('lang_prfrom', lang('From'));
$t->set_var('fromval', $phpgw->strip_html($phpgw->infolog->data['info_from']));
$t->set_var('lang_praddr', lang('Phone/Email'));
$t->set_var('addrval', $phpgw->strip_html($phpgw->infolog->data['info_addr']));
$t->set_var('lang_search', lang('Search'));
$t->set_var('lang_prproject', lang('Project'));
$t->set_var('lang_proj_prompt', lang('Pattern for Search in Projects'));
if (($proj_id = $phpgw->infolog->data['info_proj_id']) || $projectsearch) {
$projects = createobject('projects.projects');
if ($projectsearch) {
$projs = $projects->read_projects( 0,0,$projectsearch );
if (count($projs)) {
$project = '<select name="proj_id">';
while (list( $key,$proj ) = each( $projs )) {
$project .= '<option value="'.$proj['id'].'">'.$phpgw->strip_html($proj['title'])."\n";
}
$project .= '<option value="0">'.lang('none')."\n";
$project .= '</select>';
} else {
$project = lang( 'No entrys found for %1, try again ...',"'$projectsearch'" );
}
} else { // read name/company from addressbook entry info_addr_id
list( $proj ) = $projects->read_single_project( $proj_id );
if (count($proj)) {
$project = $proj['title'].'<input type="hidden" name="proj_id" value="' . $proj_id . '">';
$customer_id = $proj['customer'];
}
}
}
if (!$project)
$project = '<span class=note>'.lang('not set, use Button to search for').'</span>';
$t->set_var('project', $project);
$t->set_var('lang_praddrbook', lang('Addressbook'));
$t->set_var('lang_addr_prompt', lang('Pattern for Search in Addressbook'));
if (($addr_id = $phpgw->infolog->data['info_addr_id']) || $addrsearch) {
$contacts = createobject('phpgwapi.contacts');
if ($addrsearch) {
$addrs = $contacts->read( 0,0,'',$addrsearch,'','DESC','org_name,n_family,n_given' );
if (count($addrs)) {
$addrbook = '<select name="addr_id">';
while (list( $key,$addr ) = each( $addrs )) {
$addrbook .= '<option value="'.$addr['id'].'">'.$phpgw->infolog->addr2name( $addr )."\n";
}
$addrbook .= '<option value="0">'.lang('none')."\n";
$addrbook .= '</select>';
} else {
$addrbook = lang( 'No entrys found for %1, try again ...',"'$addrsearch'" );
}
} else { // read name/company from addressbook entry info_addr_id
list( $addr ) = $contacts->read_single_entry( $addr_id );
if (count($addr)) {
$addrbook = $phpgw->infolog->addr2name( $addr ).'<input type="hidden" name="addr_id" value="' . $addr_id . '">';
}
}
}
if (!$addrbook)
$addrbook = '<span class=note>'.lang('not set, use Button to search for').'</span>';
$t->set_var('addrbook', $addrbook);
$t->set_var($sb2->getProject('project',$phpgw->infolog->data['info_proj_id'],$query_project));
$t->set_var($sb2->getAddress('addr',$phpgw->infolog->data['info_addr_id'],$query_addr));
$t->set_var('lang_prsubject', lang('Subject'));
$t->set_var('subjectval', $phpgw->strip_html($phpgw->infolog->data['info_subject']));
@ -289,16 +233,16 @@
$t->set_var('days',lang('days'));
$t->set_var('lang_status',lang('Status'));
$t->set_var('status_list',$phpgw->infolog->getEnum('status',$phpgw->infolog->data['info_status'],$phpgw->infolog->enums['status']));
$t->set_var('status_list',$sb2->getArrayItem('status',$phpgw->infolog->data['info_status'],$phpgw->infolog->enums['status']));
$t->set_var('lang_priority',lang('Priority'));
$t->set_var('priority_list',$phpgw->infolog->getEnum('pri',$phpgw->infolog->data['info_pri'],$phpgw->infolog->enums['priority']));
$t->set_var('priority_list',$sb2->getArrayItem('pri',$phpgw->infolog->data['info_pri'],$phpgw->infolog->enums['priority']));
$t->set_var('lang_confirm',lang('Confirm'));
$t->set_var('confirm_list',$phpgw->infolog->getEnum('confirm',$phpgw->infolog->data['info_confirm'],$phpgw->infolog->enums['confirm']));
$t->set_var('confirm_list',$sb2->getArrayItem('confirm',$phpgw->infolog->data['info_confirm'],$phpgw->infolog->enums['confirm']));
$t->set_var('lang_responsible',lang('Responsible'));
$t->set_var('responsible_list',$phpgw->infolog->getAccount('responsible',$phpgw->infolog->data['info_responsible']));
$t->set_var('responsible_list',$sb2->getAccount('responsible',$phpgw->infolog->data['info_responsible']));
$t->set_var('lang_access_type',lang('Private'));
$t->set_var('access_list', '<input type="checkbox" name="access" value="True"' . ($phpgw->infolog->data['info_access'] == 'private'?' checked':'') . '>');

View File

@ -13,7 +13,7 @@
/* $Id$ */
class infolog
class infolog
{
var $db,$db2;
var $grants;
@ -24,7 +24,6 @@
function infolog( $info_id = 0) {
global $phpgw;
$this->db = $phpgw->db;
$this->db2 = $phpgw->db; // for getAccounts and accountInfo
$this->grants = $phpgw->acl->get_grants('infolog');
$this->enums = array( 'priority' => array( 'urgent' => 'urgent','high' => 'high','normal' => 'normal','low' => 'low' ),
'status' => array( 'offer' => 'offer','ongoing' => 'ongoing','call' => 'call',
@ -89,57 +88,23 @@
list( $style ) = $this->setStyleSheet(); echo $style;
}
function accountInfo($id,$account_data=0) {
function accountInfo($id,$account_data=0,$longname=0) {
global $phpgw;
if (!$id) return '&nbsp;';
if (!$cache[$id]['lid']) {
if (!is_array($account_data)) {
$accounts = createobject('phpgwapi.accounts',$id);
$accounts->db = $this->db2;
$accounts->read_repository();
$account_data = $accounts->data;
}
$cache[$id]['lid'] = $account_data['account_lid'];
$cache[$id]['firstname'] = $account_data['firstname'];
$cache[$id]['lastname'] = $account_data['lastname'];
if (!is_array($account_data)) {
$accounts = createobject('phpgwapi.accounts',$id);
$accounts->db = $phpgw->db;
$accounts->read_repository();
$account_data = $accounts->data;
}
if ($this->longnames)
return $cache[$id]['firstname'].' '.$cache[$id]['lastname'];
if ($longnames)
return $account_data['firstname'].' '.$account_data['lastname'];
return $cache[$id]['lid'];
return $account_data['account_lid'];
}
function getEnum($name, $selected=0, $arr=0,$no_lang=0) { // should be in class common.sbox
if (!is_array($arr))
$arr = array('no','yes');
$out = "<select name=\"$name\">\n";
while ($apair = each($arr)) {
$out .= '<option value="'.$apair[0].'"';
if($selected == $apair[0]) $out .= " SELECTED";
$out .= ">" . ($no_lang ? $apair[1] : lang($apair[1])) . "</option>\n";
}
$out .= "</select>\n";
return $out;
}
function getAccount($name,$selected=0) {
$accounts = createobject('phpgwapi.accounts');
$accounts->db = $this->db2;
$accs = $accounts->get_list('accounts');
$aarr = Array(lang('not assigned'));
while ($a = current($accs)) {
$aarr[$a['account_id']] = $this->accountInfo($a['account_id'],$a);
next($accs);
}
return $this->getEnum($name,$selected,$aarr,1);
}
function addr2name( $addr ) {
global $phpgw;
$name = $addr['n_family'];
@ -150,8 +115,9 @@
$name .= ', '.$addr['n_prefix'];
if ($addr['org_name'])
$name = $addr['org_name'].': '.$name;
return $phpgw->strip_html($name);
}
return $phpgw->strip_html($name);
}
function readProj($proj_id) {
if ($proj_id) {
if (!is_object($this->projects)) {
@ -160,7 +126,7 @@
if (list( $proj ) = $this->projects->read_single_project( $proj_id ))
return $proj;
}
return False;
return False;
}
function readAddr($addr_id) {
@ -171,7 +137,7 @@
if (list( $addr ) = $this->contacts->read_single_entry( $addr_id ))
return $addr;
}
return False;
return False;
}
function formatInfo($info=0,$p_id=0,$a_id=0) { // $info: info_id or array with one row form info-db
@ -216,17 +182,17 @@
$enddate = "<span class=overdue>$enddate</span>";
}
if (!($responsible = $info['info_responsible']) && $info['info_status'] == 'offer') {
$responsible = $phpgw->infolog->icon('status','offer');
$responsible = $this->icon('status','offer');
} else {
$responsible = $phpgw->infolog->accountInfo($responsible);
$responsible = $this->accountInfo($responsible);
}
$owner = $phpgw->infolog->accountInfo($info['info_owner']);
$owner = $this->accountInfo($info['info_owner']);
if ($info['info_access'] == 'private')
$owner = "<span class=private>$owner</span>";
return array(
'type' => $phpgw->infolog->icon('type',$info['info_type']),
'status' => $phpgw->infolog->icon('status',$info['info_status']),
'type' => $this->icon('type',$info['info_type']),
'status' => $this->icon('status',$info['info_status']),
'pri' => lang($info['info_pri']),
'subject' => $subject,
'des' => $info['info_des'],
@ -234,7 +200,7 @@
'enddate' => $enddate,
'owner' => $owner,
'datecreated' => $phpgw->common->show_date($info['info_datecreated'],$phpgw_info['user']['preferences']['common']['dateformat']),
'responsible' => $responsible );
'responsible' => $responsible );
}
function infoHeaders( $do_sort_header=0,$sort=0,$order=0) {
@ -251,7 +217,7 @@
$headers['lang_'.$f] = $lang;
}
}
return $headers;
return $headers;
}
function debug( $str ) {
@ -279,7 +245,7 @@
// $this->debug("check_access(info_id=$info_id (owner=$owner, user=$user),required_rights=$required_rights): access".($access_ok?"Ok":"Denied"));
return $access_ok;
return $access_ok;
}
function aclFilter($filter = 'none') { // sql to be AND into a query to ensure ACL is respected (incl. _PRIVATE)
@ -318,7 +284,7 @@
// echo "<p>aclFilter('$filter')(user='$user') = '$filtermethod'</p>";
return $this->acl_filter[$filter] = $filtermethod; // cache the filter
return $this->acl_filter[$filter] = $filtermethod; // cache the filter
}
function read($info_id) { // did _not_ ensure ACL, has to be done by the calling code
@ -338,7 +304,7 @@
$this->data['info_from'] = '';
}
}
return $this->data;
return $this->data;
}
function init() {
@ -356,7 +322,7 @@
. $phpgw_info['user']['account_id'] . "'))" ,__LINE__,__FILE__);
if ($this->data['info_id'] == $info_id)
$this->init( );
$this->init( );
}
function write($values) { // did _not_ ensure ACL, has to be done by the calling code
@ -399,6 +365,6 @@
//echo '<br>edit(): query: '.$query;
$this->db->query($query,__LINE__,__FILE__);
$this->db->query($query,__LINE__,__FILE__);
}
}
}

View File

@ -28,8 +28,6 @@
$t->set_file(array( 'info_list_t' => 'list.tpl' ));
$t->set_block('info_list_t','info_list','list');
$grants = $phpgw->acl->get_grants('infolog');
$common_hidden_vars =
'<input type="hidden" name="sort" value="' . $sort . '">'
. '<input type="hidden" name="order" value="' . $order . '">'
@ -54,7 +52,7 @@
case 'addr':
$common_hidden_vars .= '<input type="hidden" name="addr_id" value="' . $addr_id . '">';
$addr = $phpgw->infolog->readAddr($addr_id);
$t->set_var(lang_info_action,lang('Info Log').' - '.$phpgw->infolog->addr2name($addr));
$t->set_var(lang_info_action,lang('Info Log').' - '.$phpgw->infolog->sb2->addr2name($addr));
break;
default:
$t->set_var(lang_info_action,lang('Info Log'));