got infolog working:

- referers are handled now correct
- hooks are working again (only addressbook::view ported so far)
This commit is contained in:
Ralf Becker 2002-10-16 00:23:39 +00:00
parent d1b7fc8035
commit 0df9d71782
4 changed files with 158 additions and 151 deletions

View File

@ -25,7 +25,7 @@
'readProj' => True,
'readAddr' => True,
'anzSubs' => True,
'readIdArray' => True,
'search' => True,
'get_rows' => True,
'accountInfo' => True, // in class boinfolog (this class)
'addr2name' => True,
@ -288,11 +288,11 @@
return $this->so->anzSubs( $info_id );
}
function readIdArray($order,$sort,$filter,$cat_id,$query,$action,$action_id,
$ordermethod,&$start,&$total)
function search($order,$sort,$filter,$cat_id,$query,$action,$action_id,
$ordermethod,&$start,&$total)
{
return $this->so->readIdArray($order,$sort,$filter,$cat_id,$query,
$action,$action_id,$ordermethod,$start,$total);
return $this->so->search($order,$sort,$filter,$cat_id,$query,
$action,$action_id,$ordermethod,$start,$total);
}
@ -478,9 +478,9 @@
function link_query( $pattern )
{
$start = $total = 0;
$ids = $this->readIdArray('','','','',$pattern,'','','',&$start,&$total);
$ids = $this->search('','','','',$pattern,'','','',&$start,&$total);
$content = array();
while (is_array($ids) && list( $id,$parent ) = each( $ids ))
while (is_array($ids) && list( $id,$info ) = each( $ids ))
{
$content[$id] = $this->link_title($id);
}

View File

@ -158,7 +158,29 @@
$this->data = array( 'info_owner' => $this->user,
'info_pri' => 'normal' );
}
function db2data(&$data)
{
$data = $this->db->Record;
reset($this->maybe_slashes);
while (list($key) = each($this->maybe_slashes))
{
$data[$key] = stripslashes($data[$key]);
}
/*
$links = $this->links->get_links('infolog',$this->data['info_id']);
while (list($nul,$link) = each($links))
{
if ($link['app'] == 'addressbook')
$data['info_addr_id'] = $link['id'];
if ($link['app'] == 'projects')
$data['info_proj_id'] = $link['id'];
if ($link['app'] == 'calendar')
$data['info_event_id'] = $link['id'];
}
*/
}
function read($info_id) // did _not_ ensure ACL
{
if ($info_id <= 0 || $info_id != $this->data['info_id'] &&
@ -169,24 +191,9 @@
}
if ($info_id != $this->data['info_id']) // data yet read in
{
$this->data = $this->db->Record;
reset($this->maybe_slashes);
while (list($key) = each($this->maybe_slashes))
{
$this->data[$key] = stripslashes($this->data[$key]);
}
$links = $this->links->get_links('infolog',$this->data['info_id']);
while (list($nul,$link) = each($links))
{
if ($link['app'] == 'addressbook')
$this->data['info_addr_id'] = $link['id'];
if ($link['app'] == 'projects')
$this->data['info_proj_id'] = $link['id'];
if ($link['app'] == 'calendar')
$this->data['info_event_id'] = $link['id'];
}
$this->db2data($this->data);
}
return $this->data;
return $this->data;
}
function delete($info_id) // did _not_ ensure ACL
@ -252,6 +259,10 @@
function anzSubs( $info_id )
{
if ($info_id <= 0)
{
return 0;
}
$this->db->query('select count(*) FROM phpgw_infolog where '.
"info_id_parent=$info_id",__LINE__,__FILE__);
@ -260,37 +271,27 @@
return $this->db->f(0);
}
function readIdArray($order,$sort,$filter,$cat_id,$query,$action,$action_id,
$ordermethod,&$start,&$total)
function search($order,$sort,$filter,$cat_id,$query,$action,$action_id,
$ordermethod,&$start,&$total)
{
//echo "<p>soinfolog.readIdArray(action='$action',action_id='$action_id')</p>\n";
//echo "<p>soinfolog.search(action='$action/$action_id')</p>\n";
$action2app = array(
'addr' => 'addressbook',
'addressbook' => 'addressbook',
'proj' => 'projects',
'projects' => 'projects',
'event' => 'calendar',
'calendar' => 'calendar'
'event' => 'calendar'
);
if ($action != '' && isset($action2app[$action]))
if (isset($action2app[$action]))
{
$links = $this->links->get_links($action2app[$action],$action_id);
$total = count($links);
if ($start > $total)
$action = $action2app[$action];
}
if ($action != '')
{
$links = $this->links->get_links($action=='sp'?'infolog':$action,$action_id,'infolog');
if (count($links))
{
$start = 0;
$link_extra = ($action == 'sp' ? 'OR' : 'AND').' info_id IN ('.implode(',',$links).')';
}
$ids = array();
while (list($n,$link) = each($links) &&
$n < $start+$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'])
{
if ($n >= $start)
{
$ids[''.$link['id']] = 0;
}
}
//echo "<p>soinfolog.readIdArray($action,$action_id) ids ="; _debug_array($ids);
return $ids;
}
if ($order)
{
@ -309,17 +310,6 @@
{
$filtermethod .= " AND info_cat='$cat_id' ";
}
/* not longer used
switch ($action)
{
case 'addr': $filtermethod .= " AND info_addr_id=$action_id ";
break;
case 'proj': $filtermethod .= " AND info_proj_id=$action_id ";
break;
case 'event': $filtermethod .= " AND info_event_id=$action_id ";
break;
}
*/
if ($query) // we search in _from, _subject and _des for $query
{
$sql_query = "AND (info_from like '%$query%' OR info_subject ".
@ -332,21 +322,29 @@
{
$pid = '';
}
$this->db->query("SELECT COUNT(*) FROM phpgw_infolog WHERE $filtermethod $pid $sql_query",__LINE__,__FILE__);
$this->db->next_record();
$total = $this->db->f(0);
if (!$start || $start > $total)
{
$start = 0;
}
$this->db->limit_query($sql="SELECT info_id,info_id_parent FROM phpgw_infolog WHERE $filtermethod $pid $sql_query $ordermethod",$start,__LINE__,__FILE__);
$ids = array( );
while ($this->db->next_record())
if ($action == '' || $action == 'sp' || count($links))
{
$this->db->query($sql="SELECT COUNT(*) FROM phpgw_infolog i WHERE ($filtermethod $pid $sql_query) $link_extra",__LINE__,__FILE__);
$this->db->next_record();
$total = $this->db->f(0);
if (!$start || $start > $total)
{
$start = 0;
}
$this->db->limit_query($sql="SELECT * FROM phpgw_infolog WHERE ($filtermethod $pid $sql_query) $link_extra $ordermethod",$start,__LINE__,__FILE__);
while ($this->db->next_record())
{
$this->db2data(&$info);
$ids[$info['info_id']] = $info;
}
}
else
{
$ids[$this->db->f('info_id')] = $this->db->f('info_id_parent');
$start = $total = 0;
}
return $ids;
}

View File

@ -85,17 +85,21 @@
$this->html = &$this->tmpl->html;
}
function get_info($id,&$readonlys,$action='',$action_id='')
function get_info($info,&$readonlys,$action='',$action_id='')
{
$info = $this->bo->read($id);
$info['anzSubs'] = $this->bo->anzSubs($id);
if (!is_array($info))
{
$info = $this->bo->read($info);
}
$id = $info['info_id'];
$info += $this->formatInfo($info,$action,$action_id);
$info['info_des'] = nl2br($info['info_des']);
$info['info_anz_subs'] = $this->bo->anzSubs($id);
$readonlys["edit[$id]"] = !$this->bo->check_access($id,PHPGW_ACL_EDIT);
$readonlys["delete[$id]"] = !$this->bo->check_access($id,PHPGW_ACL_DELETE);
$readonlys["sp[$id]"] = !$this->bo->check_access($id,PHPGW_ACL_ADD);
$readonlys["view[$id]"] = $info['anzSubs'] < 1;
$readonlys["view[$id]"] = $info['info_anz_subs'] < 1;
$readonlys['view[0]'] = True; // no parent
return $info;
@ -105,19 +109,19 @@
{
//echo "<p>uiinfolog.get_rows(start=$query[start],search='$query[search]',filter='$query[filter]',cat_id=$query[cat_id],action='$query[action]/$query[action_id]')</p>\n";
$ids = $this->bo->readIdArray($query['order'],$query['sort'],$query['filter'],$query['cat_id'],
$ids = $this->bo->search($query['order'],$query['sort'],$query['filter'],$query['cat_id'],
$query['search'],$query['action'],$query['action_id'],$query['ordermethod'],
$query['start'],$total);
if (!is_array($ids))
{
$ids = array( );
}
$rows = array( $total );
$readonlys = array();
while (list($id,$parent) = each($ids))
while (list($id,$info) = each($ids))
{
$rows[] = $this->get_info($id,$readonlys,$query['action'],$query['action_id']);
$rows[] = $this->get_info($info,$readonlys,$query['action'],$query['action_id']);
}
//echo "<p>readonlys = "; _debug_array($readonlys);
reset($rows);
@ -125,68 +129,49 @@
return $total;
}
function delete($values=0,$referer='')
{
$info_id = is_array($values) ? $values['info_id'] : $values;
$referer = is_array($values) ? $values['referer'] : $referer;
if (is_array($values) || $info_id <= 0)
{
if ($values['delete'] && $info_id > 0 && $this->bo->check_access($info_id,PHPGW_ACL_DELETE))
{
$this->bo->delete($info_id);
}
return $referer ? $this->tmpl->header($referer) : $this->index();
}
$readonlys = $values = array();
$values['main'][1] = $this->get_info($info_id,&$readonlys['main']);
$this->tmpl->read('infolog.delete');
$values['main']['no_actions'] = True;
$persist['info_id'] = $info_id;
$persist['referer'] = $referer;
$this->tmpl->exec('infolog.uiinfolog.delete',$values,'',$readonlys,$persist);
}
function index($values = 0,$action='',$action_id='',$referer=0)
{
$referer = is_array($values) ? $values['referer'] : $referer;
//echo "<p>uiinfolog::index(action='$action/$action_id',referer='$referer/$values[referer]')</p>\n";
if (!is_array($values))
{
$values = array('nm' => $GLOBALS['phpgw']->session->appsession('session_data','infolog'));
}
$action = $action ? $action : $values['nm']['action'];
$action_id = $action_id ? $action_id : $values['nm']['action_id'];
if ($values['add'] || $values['cancel'] || isset($values['nm']['rows']) || isset($values['main']))
else
{
$data = $values['nm'];
unset($data['rows']);
$GLOBALS['phpgw']->session->appsession('session_data','infolog',$data);
}
$action = $action ? $action : $values['action'];
$action_id = $action_id ? $action_id : $values['action_id'];
if ($values['add'] || $values['cancel'] || isset($values['nm']['rows']) || isset($values['main']))
{
if ($values['add'])
{
list($type) = each($values['add']);
return $this->edit(0,$values['nm']['action'],$values['nm']['action_id'],$type,$referer);
return $this->edit(0,$action,$action_id,$type,$referer);
}
else
{
list($action,$action_id) = isset($values['main']) ? each($values['main']) : @each($values['nm']['rows']);
list($action_id) = @each($action_id);
//echo "<p>infolog::index: action='$action', id='$action_id'</p>\n";
switch($action)
list($do,$do_id) = isset($values['main']) ? each($values['main']) : @each($values['nm']['rows']);
list($do_id) = @each($do_id);
//echo "<p>infolog::index: do='$do/$do_id', referer="; _debug_array($referer);
switch($do)
{
case 'edit':
return $this->edit($action_id,'','','',$referer);
return $this->edit($do_id,$action,$action_id,'',$referer);
case 'delete':
return $this->delete($action_id,$referer);
return $this->delete($do_id,$referer);
case 'sp':
return $this->edit(0,$action,$action_id,'',$referer);
return $this->edit(0,'sp',$do_id,'',$referer);
case 'view':
$value = array();
$action = 'sp';
$action_id = $do_id;
break;
default:
$value = array();
@ -201,7 +186,7 @@
case 'sp':
if (!$this->bo->read($action_id))
{
$action = '';
$action = '';
$action_id = 0;
break;
}
@ -216,15 +201,38 @@
$values['nm']['options-filter'] = $this->filters;
$values['nm']['get_rows'] = 'infolog.uiinfolog.get_rows';
$values['nm']['no_filter2'] = True;
$persist['nm']['action'] = $values['nm']['action'] = $action;
$persist['nm']['action_id'] = $values['nm']['action_id'] = $action_id;
$persist['action'] = $values['nm']['action'] = $action;
$persist['action_id'] = $values['nm']['action_id'] = $action_id;
$persist['referer'] = $referer;
$GLOBALS['phpgw']->session->appsession('session_data','infolog',$values['nm']);
$this->tmpl->exec('infolog.uiinfolog.index',$values,'',$readonlys,$persist);
}
function delete($values=0,$referer='')
{
$info_id = is_array($values) ? $values['info_id'] : $values;
$referer = is_array($values) ? $values['referer'] : $referer;
if (is_array($values) || $info_id <= 0)
{
if ($values['delete'] && $info_id > 0 && $this->bo->check_access($info_id,PHPGW_ACL_DELETE))
{
$this->bo->delete($info_id);
}
return $referer ? $this->tmpl->location($referer) : $this->index();
}
$readonlys = $values = array();
$values['main'][1] = $this->get_info($info_id,&$readonlys['main']);
$this->tmpl->read('infolog.delete');
$values['main']['no_actions'] = True;
$persist['info_id'] = $info_id;
$persist['referer'] = $referer;
$this->tmpl->exec('infolog.uiinfolog.delete',$values,'',$readonlys,$persist);
}
/*!
@function edit
@syntax edit( $content=0,$action='',$action_id=0,$type='' )
@ -237,22 +245,13 @@
*/
function edit($content = 0,$action = '',$action_id=0,$type='',$referer='')
{
$referer = is_array($content) ? $content['referer'] : $referer;
if (is_array($values) || $info_id < 0)
{
if ($values['delete'] && $info_id > 0 && $this->bo->check_access($info_id,PHPGW_ACL_DELETE))
{
$this->bo->delete($info_id);
}
return $referer ? $this->tmpl->header($referer) : $this->index();
}
if (is_array($content))
{
$info_id = $content['info_id'];
$action = $content['action'];
$action_id = $content['action_id'];
$referer = $content['referer'];
if ($content['save'] || $content['delete'] || $content['cancel'])
{
if ($content['save'] && (!$info_id || $this->bo->check_access($info_id,PHPGW_ACL_EDIT)))
@ -266,9 +265,14 @@
}
elseif ($content['delete'] && $info_id > 0)
{
if (!$referer && $action) $referer = array(
'menuaction' => 'infolog.uiinfolog.index',
'action' => $action,
'action_id' => $action_id
);
return $this->delete($info_id,$referer); // checks ACL first
}
return $referer ? $this->tmpl->header($referer) : $this->index();
return $referer ? $this->tmpl->location($referer) : $this->index(0,$action,$action_id);
}
}
else
@ -278,21 +282,23 @@
$action_id = $action_id ? $action_id : get_var('action_id',array('POST','GET'));
$info_id = $content ? $content : get_var('info_id', array('POST','GET'));
$type = $type ? $type : get_var('type', array('POST','GET'));
$referer = ''.$referer != '' ? $referer : get_var('HTTP_REFERER','SERVER');
$referer = $referer !== '' ? $referer :
ereg_replace('^.*'.$GLOBALS['phpgw_info']['server']['webserver_url'],'',
get_var('HTTP_REFERER',Array('GLOBAL')));
//echo "<p>uiinfolog::edit: info_id=$info_id, action='$action', action_id='$action_id', type='$type', referer='$referer'</p>\n";
if (!isset($this->bo->enums['type'][$type]))
{
$type = 'note';
}
$this->bo->read( $action == 'sp' && $action_id > 0 ? $action_id : $info_id );
$this->bo->read( $info_id || $action != 'sp' ? $info_id : $action_id );
$content = $this->bo->so->data;
if ($action_id && $action == 'sp') // new SubProject
if (!$info_id && $action_id && $action == 'sp') // new SubProject
{
if (!$this->bo->check_access($action_id,PHPGW_ACL_ADD))
{
return $referer ? $this->tmpl->header($referer) : $this->index();
return $referer ? $this->tmpl->location($referer) : $this->index(0,$action,$action_id);
}
$parent = $this->bo->so->data;
$content['info_id'] = $info_id = 0;
@ -315,7 +321,7 @@
{
if ($info_id && !$this->bo->check_access($info_id,PHPGW_ACL_EDIT))
{
return $referer ? $this->tmpl->header($referer) : $this->index();
return $referer ? $this->tmpl->location($referer) : $this->index(0,$action,$action_id);
}
}
$content['links'] = $content['link_to'] = array(
@ -343,7 +349,7 @@
}
}
$readonlys['delete'] = $action != '';
$content['appheader'] = $this->messages[$action ? ($action == 'sp' ? 'add_sub' : 'add') : 'edit'];
$content['appheader'] = $this->messages[$info_id ? 'edit' : ($action == 'sp' ? 'add_sub' : 'add')];
//echo "<p>uiinfolog.edit(info_id=$info_id,mode=$mode) content = "; _debug_array($content);
$this->tmpl->read('infolog.edit');
@ -357,7 +363,8 @@
'info_id_parent' => $content['info_id_parent'],
'action' => $action,
'action_id' => $action_id,
'referer' => $referer
'referer' => $referer,
'link_to' => array('to_id' => $content['link_to']['to_id']) // in case tab gets not viewed
));
}
@ -727,8 +734,8 @@
$GLOBALS['phpgw']->template->parse('info_headers','info_headers');
// -------------- end header declaration -----------------
$ids = $this->bo->readIdArray($order,$sort,$filter,$cat_id,$query,
$action,$action_id,$ordermethod,$start,$total);
$ids = $this->bo->search($order,$sort,$filter,$cat_id,$query,
$action,$action_id,$ordermethod,$start,$total);
$maxmatchs = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
if ($total > $maxmatchs)
@ -797,13 +804,13 @@
{
$GLOBALS['phpgw']->template->set_var('info_headers','');
}
while (list($id,$parent) = each($ids))
while (list($id,$info) = each($ids))
{
$subproact = $this->bo->anzSubs($id);
$this->nextmatchs->template_alternate_row_color($GLOBALS['phpgw']->template);
$GLOBALS['phpgw']->template->set_var( $this->formatInfo( $id,$action,$action_id ));
$GLOBALS['phpgw']->template->set_var( $this->formatInfo( $info,$action,$action_id ));
if ($this->bo->check_access($id,PHPGW_ACL_EDIT))
{

View File

@ -16,16 +16,18 @@
$GLOBALS['phpgw']->translation->add_app('infolog');
/* echo "<p>hook_addressbook_view(ab_id=$ab_id)</p>"; */
//echo "<p>hook_addressbook_view(ab_id=$GLOBALS[ab_id])</p>\n";
/*
$link = CreateObject('infolog.uilink');
$out = '<table>'.$link->getEntry('entry','addressbook',$GLOBALS['ab_id'])."\n".
$link->showLinks('links','addressbook',$GLOBALS['ab_id'],'!infolog')."</table>\n";
$html = CreateObject('etemplate.html');
$out = $html->form($out,'','/index.php',array('menuaction'=>'addressbook.uiaddressbook.view','ab_id'=>$GLOBALS['ab_id']));
$GLOBALS['phpgw']->template->set_var('phpgw_body',$out,True);
*/
$infolog = CreateObject('infolog.uiinfolog');
$infolog->get_list(True,'addr',$GLOBALS['ab_id']);
$infolog->index(0,'addressbook',$GLOBALS['ab_id'],array(
'menuaction' => 'addressbook.uiaddressbook.view',
'ab_id' => $GLOBALS['ab_id']
));
$GLOBALS['phpgw_info']['flags']['currentapp'] = $save_app;