nearly finished port of infolog.edit

improved handling of linkage with not yet written entries
This commit is contained in:
Ralf Becker 2002-10-09 00:37:00 +00:00
parent 27e25a05d2
commit 4870c4a3d7
2 changed files with 37 additions and 23 deletions

View File

@ -91,11 +91,11 @@
@result db-errno or -1 (for param-error) or 0 for success @result db-errno or -1 (for param-error) or 0 for success
@result if $id1==0 or already an array: $id1 is array with links @result if $id1==0 or already an array: $id1 is array with links
*/ */
function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0 ) function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0 )
{ {
if ($this->debug) if ($this->debug)
{ {
echo "<p>bolink.link('$app1',$id1,'$app2',$id2,'$remark',$owner)</p>\n"; echo "<p>bolink.link('$app1',$id1,'$app2',$id2,'$remark',$owner,$lastmod)</p>\n";
} }
if (!$app1 || !$app2 || !$id1 && is_array($id2) || $app1 == $app2 && $id1 == $id2) if (!$app1 || !$app2 || !$id1 && is_array($id2) || $app1 == $app2 && $id1 == $id2)
{ {
@ -112,7 +112,8 @@
'id' => $id2, 'id' => $id2,
'remark' => $remark, 'remark' => $remark,
'owner' => $owner, 'owner' => $owner,
'link_id' => "$app2:$id2" 'link_id' => "$app2:$id2",
'lastmod' => time()
); );
return 0; return 0;
} }
@ -122,7 +123,7 @@
$err = 0; $err = 0;
while (!$err && list(,$link) = each($app2)) while (!$err && list(,$link) = each($app2))
{ {
$err = solink::link($app1,$id1,$link['app'],$link['id'],$link['remark'],$link['owner']); $err = solink::link($app1,$id1,$link['app'],$link['id'],$link['remark'],$link['owner'],$link['lastmod']);
} }
return $err; return $err;
} }
@ -150,14 +151,15 @@
{ {
$only_app = substr(1,$only_app); $only_app = substr(1,$only_app);
} }
reset($id); end($id);
while (list($key,$link) = each($id)) while ($link = current($id))
{ {
if ($only_app && $not_only == ($link['app'] == $only_app)) if ($only_app && $not_only == ($link['app'] == $only_app))
{ {
continue; continue;
} }
$ids[$key] = $link; $ids[$link['link_id']] = $link;
prev($id);
} }
} }
return $ids; return $ids;
@ -167,20 +169,20 @@
/*! /*!
@function unlink @function unlink
@syntax unlink( $link_id,$app='',$id='',$owner='' ) @syntax unlink( $link_id,$app='',$id='',$owner='',$app2='',$id2='' )
@author ralfbecker @author ralfbecker
@abstract Remove link with $link_id or all links matching given $app,$id @abstract Remove link with $link_id or all links matching given $app,$id
@param $link_id link-id to remove if > 0 @param $link_id link-id to remove if > 0
@param $app,$id,$owner if $link_id <= 0: removes all links matching the non-empty params @param $app,$id,$owner,$app2,$id2 if $link_id <= 0: removes all links matching the non-empty params
@discussion Note: if $link_id != '' and $id is an array: unlink removes links from that array only @discussion Note: if $link_id != '' and $id is an array: unlink removes links from that array only
@discussion unlink has to be called with &$id so see the result !!! @discussion unlink has to be called with &$id so see the result !!!
@result the number of links deleted @result the number of links deleted
*/ */
function unlink($link_id,$app='',$id='',$owner='') function unlink($link_id,$app='',$id='',$owner='',$app2='',$id2='')
{ {
if ($link_id > 0 || !is_array($id)) if ($link_id > 0 || !is_array($id))
{ {
return solink::unlink($link_id,$app,$id,$owner); return solink::unlink($link_id,$app,$id,$owner,$app2,$id2);
} }
$result = isset($id[$link_id]); $result = isset($id[$link_id]);
@ -193,7 +195,7 @@
@function app_list @function app_list
@syntax app_list( ) @syntax app_list( )
@author ralfbecker @author ralfbecker
@abstrac get list/array of link-aware apps @abstrac get list/array of link-aware apps the user has rights to use
@result array( $app => lang($app), ... ) @result array( $app => lang($app), ... )
*/ */
function app_list( ) function app_list( )
@ -201,9 +203,12 @@
reset ($this->app_register); reset ($this->app_register);
$apps = array(); $apps = array();
while (list($app,$reg) = each($this->app_register)) while (list($app,$reg) = each($this->app_register))
{
if ($GLOBALS['phpgw_info']['user']['apps'][$app])
{ {
$apps[$app] = lang($app); $apps[$app] = lang($app);
} }
}
return $apps; return $apps;
} }

View File

@ -57,7 +57,7 @@
@discussion Does NOT check if link already exists @discussion Does NOT check if link already exists
@result db-errno or -1 (for param-error) or 0 for success @result db-errno or -1 (for param-error) or 0 for success
*/ */
function link( $app1,$id1,$app2,$id2,$remark='',$owner=0 ) function link( $app1,$id1,$app2,$id2,$remark='',$owner=0,$lastmod=0 )
{ {
if ($this->debug) if ($this->debug)
{ {
@ -73,7 +73,11 @@
$owner = $this->user; $owner = $this->user;
} }
$remark = $this->db->db_addslashes($remark); $remark = $this->db->db_addslashes($remark);
if (!$lastmod)
{
$lastmod = time(); $lastmod = time();
}
$this->unlink(0,$app1,$id1,'',$app2,$id2); // remove link if one exists
$sql = "INSERT INTO $this->db_name (link_app1,link_id1,link_app2,link_id2,link_remark,link_lastmod,link_owner) ". $sql = "INSERT INTO $this->db_name (link_app1,link_id1,link_app2,link_id2,link_remark,link_lastmod,link_owner) ".
" VALUES ('$app1','$id1','$app2','$id2','$remark',$lastmod,$owner)"; " VALUES ('$app1','$id1','$app2','$id2','$remark',$lastmod,$owner)";
@ -133,7 +137,8 @@
'id' => stripslashes($row['link_id1']) 'id' => stripslashes($row['link_id1'])
); );
} }
if ($only_app && $not_only == ($link['app'] == $only_app)) if ($only_app && $not_only == ($link['app'] == $only_app) ||
!$GLOBALS['phpgw_info']['user']['apps'][$link['app']])
{ {
continue; continue;
} }
@ -149,14 +154,14 @@
/*! /*!
@function unlink @function unlink
@syntax unlink( $link_id,$app='',$id='',$owner='' ) @syntax unlink( $link_id,$app='',$id='',$owner='',$app2='',$id2='' )
@author ralfbecker @author ralfbecker
@abstract Remove link with $link_id or all links matching given params @abstract Remove link with $link_id or all links matching given params
@param $link_id link-id to remove if > 0 @param $link_id link-id to remove if > 0
@param $app,$id,$owner if $link_id <= 0: removes all links matching the non-empty params @param $app,$id,$owner,$app2,$id2 if $link_id <= 0: removes all links matching the non-empty params
@result the number of links deleted @result the number of links deleted
*/ */
function unlink($link_id,$app='',$id='',$owner='') function unlink($link_id,$app='',$id='',$owner='',$app2='',$id2='')
{ {
$sql = "DELETE FROM $this->db_name WHERE "; $sql = "DELETE FROM $this->db_name WHERE ";
if ($link_id > 0) if ($link_id > 0)
@ -169,7 +174,7 @@
} }
else else
{ {
if ($app != '') if ($app != '' && $app2 == '')
{ {
$sql .= "((link_app1='$app'"; $sql .= "((link_app1='$app'";
$sql2 = ''; $sql2 = '';
@ -180,6 +185,11 @@
} }
$sql .= ") OR (link_app2='$app'$sql2))"; $sql .= ") OR (link_app2='$app'$sql2))";
} }
elseif ($app != '' && $app2 != '')
{
$sql .= "((link_app1='$app' AND link_id1='$id' AND link_app2='$app2' AND link_id2='$id2') OR";
$sql .= " (link_app1='$app2' AND link_id1='$id2' AND link_app2='$app' AND link_id2='$id'))";
}
if ($owner != '') if ($owner != '')
{ {
$sql .= ($app != '' ? ' AND ' : '') . "link_owner='$owner'"; $sql .= ($app != '' ? ' AND ' : '') . "link_owner='$owner'";
@ -187,7 +197,7 @@
} }
if ($this->debug) if ($this->debug)
{ {
echo "<p>solink.unlink($link_id,$app,$id,$owner) sql='$sql'</p>\n"; echo "<p>solink.unlink($link_id,$app,$id,$owner,$app2,$id2) sql='$sql'</p>\n";
} }
$this->db->query($sql); $this->db->query($sql);
@ -217,4 +227,3 @@