diff --git a/phpgwapi/inc/class.bolink.inc.php b/phpgwapi/inc/class.bolink.inc.php
index 1190dbf5b5..eea8139da4 100644
--- a/phpgwapi/inc/class.bolink.inc.php
+++ b/phpgwapi/inc/class.bolink.inc.php
@@ -14,582 +14,38 @@
* @version $Id$
*/
-include_once(EGW_API_INC . '/class.solink.inc.php');
-
/**
- * generalized linking between entries of eGroupware apps - BO layer
- *
- * The BO-layer implementes some extra features on top of the so-layer:
- * 1) It handles links to not already existing entries. This is used by the eTemplate link-widget, which allows to
- * setup links even for new / not already existing entries, before they get saved.
- * In that case you have to set the first id to 0 for the link-function and pass the array returned in that id
- * (not the return-value) after saveing your new entry again to the link function.
- * 2) Attaching files: they are saved in the vfs and not the link-table (!).
- * Attached files are stored under $vfs_basedir='/infolog' in the vfs!
- * 3) It manages the link-registry, in which apps can register themselfs by implementing some hooks
- * 4) It notifies apps, who registered for that service, about changes in the links their entries
+ * Generalized linking between entries of eGroupware apps - BO layer
+ *
+ * @deprecated use egw_link class with it's static methods instead
*/
-class bolink extends solink
+class bolink extends egw_link
{
- /**
- * other apps can participate in the linking by implementing a 'search_link' hook, which
- * has to return an array in the format of an app_register entry below
- *
- * @var array
- */
- var $app_register = array(
- 'projects' => array(
- 'query' => 'projects_query',
- 'title' => 'projects_title',
- 'view' => array (
- 'menuaction' => 'projects.uiprojects.view_project'
- ),
- 'view_id' => 'project_id'
- ),
- 'felamimail' => array(
- 'add' => array(
- 'menuaction' => 'felamimail.uicompose.compose',
- ),
- 'add_popup' => '700x750',
- ),
-/*
- 'email' => array(
- 'view' => array(
- 'menuaction' => 'email.uimessage.message'
- ),
- 'view_id' => 'msgball[acctnum:folder:msgnum]' // id is a tupple/array, fields separated by ':'
- ),
-*/
- );
- var $public_functions = array( // functions callable via menuaction
- 'get_file' => True
+ var $public_functions = array(
+ 'get_file' => true,
);
/**
- * Instance of the vfs class
- *
- * @var vfs
+ * @deprecated use egw_link::VFS_APPNAME
*/
- var $vfs;
- var $vfs_basedir='/infolog';
- var $vfs_appname='file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app
- var $valid_pathes = array();
- var $send_file_ips = array();
- /**
- * Caches link titles for a better performance
- *
- * @var array
- */
- var $title_cache = array();
-
- /**
- * constructor
- */
- function bolink( )
- {
- $this->solink( ); // call constructor of derived class
-
- $this->vfs =& CreateObject('phpgwapi.vfs');
-
- $this->link_pathes = $GLOBALS['egw_info']['server']['link_pathes'];
- $this->send_file_ips = $GLOBALS['egw_info']['server']['send_file_ips'];
-
- // other apps can participate in the linking by implementing a search_link hook, which
- // has to return an array in the format of an app_register entry
- // for performance reasons, we do it only once / cache it in the session
- if (!($search_link_hooks = $GLOBALS['egw']->session->appsession('search_link_hooks','phpgwapi')))
- {
- $search_link_hooks = $GLOBALS['egw']->hooks->process('search_link');
- $GLOBALS['egw']->session->appsession('search_link_hooks','phpgwapi',$search_link_hooks);
- }
- if (is_array($search_link_hooks))
- {
- foreach($search_link_hooks as $app => $data)
- {
- if (is_array($data))
- {
- $this->app_register[$app] = $data;
- }
- }
- }
- if (!($this->title_cache = $GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi'))) $this->title_cache = array();
- }
+ var $vfs_appname = egw_link::VFS_APPNAME;
/**
- * Called by egw::egw_final to store the title-cache in the session
+ * Overwrite private constructor of egw_links, to allow (depricated) instancated usage
*
*/
- function save_session_cache()
+ function __construct()
{
- $GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi',$this->title_cache);
- }
-
- /**
- * creats a link between $app1,$id1 and $app2,$id2 - $id1 does NOT need to exist yet
- *
- * Does NOT check if link already exists.
- * File-attachments return a negative link-id !!!
- *
- * @param string $app1 app of $id1
- * @param string/array &$id1 id of item to linkto or 0 if item not yet created or array with links
- * of not created item or $file-array if $app1 == $this->vfs_appname (see below).
- * If $id==0 it will be set on return to an array with the links for the new item.
- * @param string/array $app2 app of 2.linkend or array with links ($id2 not used)
- * @param string $id2='' id of 2. item of $file-array if $app2 == $this->vfs_appname (see below)
- * $file array with informations about the file in format of the etemplate file-type
- * $file['name'] name of the file (no directory)
- * $file['type'] mine-type of the file
- * $file['tmp_name'] name of the uploaded file (incl. directory)
- * $file['path'] path of the file on the client computer
- * $file['ip'] of the client (path and ip in $file are only needed if u want a symlink (if possible))
- * @param string $remark='' Remark to be saved with the link (defaults to '')
- * @param int $owner=0 Owner of the link (defaults to user)
- * @param int $lastmod=0 timestamp of last modification (defaults to now=time())
- * @param int $no_notify=0 &1 dont notify $app1, &2 dont notify $app2
- * @return int/boolean False (for db or param-error) or on success link_id (Please not the return-value of $id1)
- */
- function link( $app1,&$id1,$app2,$id2='',$remark='',$owner=0,$lastmod=0,$no_notify=0 )
- {
- if ($this->debug)
- {
- echo "
bolink.link('$app1',$id1,'".print_r($app2,true)."',".print_r($id2,true).",'$remark',$owner,$lastmod)
\n"; - } - if (!$app1 || !$app2 || $app1 == $app2 && $id1 == $id2) - { - return False; - } - if (is_array($id1) || !$id1) // create link only in $id1 array - { - if (!is_array($id1)) - { - $id1 = array( ); - } - $link_id = $this->temp_link_id($app2,$id2); - - $id1[$link_id] = array( - 'app' => $app2, - 'id' => $id2, - 'remark' => $remark, - 'owner' => $owner, - 'link_id' => $link_id, - 'lastmod' => time() - ); - if ($this->debug) - { - _debug_array($id1); - } - return $link_id; - } - if (is_array($app2) && !$id2) - { - reset($app2); - $link_id = True; - while ($link_id && list(,$link) = each($app2)) - { - if (!is_array($link)) // check for unlink-marker - { - //echo "link='$link' is no arraybolink::get_links(app='$app',id='$id',only_app='$only_app',order='$order')
\n"; - - if (is_array($id) || !$id) - { - $ids = array(); - if (is_array($id)) - { - if ($not_only = $only_app[0]) - { - $only_app = substr(1,$only_app); - } - end($id); - foreach (array_reverse($id) as $link) { - if (is_array($link) // check for unlink-marker - && !($only_app && $not_only == ($link['app'] == $only_app))) - { - $ids[$link['link_id']] = $only_app ? $link['id'] : $link; - } - } - # the old version of the foreach from above - # left here for reference. can be deleted later - # - #while ($link = current($id)) - #{ - # if (!is_array($link) || // check for unlink-marker - # $only_app && $not_only == ($link['app'] == $only_app)) - # { - # continue; - # } - # $ids[$link['link_id']] = $only_app ? $link['id'] : $link; - # prev($id); - #} - } - return $ids; - } - $ids = solink::get_links($app,$id,$only_app,$order); - - if (empty($only_app) || $only_app == $this->vfs_appname || - ($only_app[0] == '!' && $only_app != '!'.$this->vfs_appname)) - { - if ($vfs_ids = $this->list_attached($app,$id)) - { - $ids += $vfs_ids; - } - } - //echo "ids="; print_r($ids); echo "\n"; - - return $ids; - } - - /** - * Read one link specified by it's link_id or by the two end-points - * - * If $id is an array (links not yet created) only link_ids are allowed. - * - * @param int/string $app_link_id > 0 link_id of link or app-name of link - * @param string/array $id='' id if $app_link_id is an appname or array with links, if 1. entry not yet created - * @param string $app2='' second app - * @param string $id2='' id in $app2 - * @return array with link-data or False - */ - function get_link($app_link_id,$id='',$app2='',$id2='') - { - if (is_array($id)) - { - if (strpos($app_link_id,':') === false) $app_link_id = $this->temp_link_id($app2,$id2); // create link_id of temporary link, if not given - - if (isset($id[$app_link_id]) && is_array($id[$app_link_id])) // check for unlinked-marker - { - return $id[$app_link_id]; - } - return False; - } - if (intval($app_link_id) < 0 || $app_link_id == $this->vfs_appname || $app2 == $this->vfs_appname) - { - if (intval($app_link_id) < 0) // vfs link_id ? - { - return $this->fileinfo2link(-$app_link_id); - } - if ($app_link_id == $this->vfs_appname) - { - return $this->info_attached($app2,$id2,$id); - } - return $this->info_attached($app_link_id,$id,$id2); - } - return solink::get_link($app_link_id,$id,$app2,$id2); - } - - /** - * Remove link with $link_id or all links matching given $app,$id - * - * Note: if $link_id != '' and $id is an array: unlink removes links from that array only - * unlink has to be called with &$id to see the result (depricated) or unlink2 has to be used !!! - * - * @param $link_id link-id to remove if > 0 - * @param string $app='' appname of first endpoint - * @param string/array $id='' id in $app or array with links, if 1. entry not yet created - * @param string $app2='' app of second endpoint - * @param string $id2='' id in $app2 - * @return the number of links deleted - */ - function unlink($link_id,$app='',$id='',$owner='',$app2='',$id2='') - { - return $this->unlink2($link_id,$app,$id,$owner,$app2,$id2); - } - - /** - * Remove link with $link_id or all links matching given $app,$id - * - * @param $link_id link-id to remove if > 0 - * @param string $app='' appname of first endpoint - * @param string/array &$id='' id in $app or array with links, if 1. entry not yet created - * @param string $app2='' app of second endpoint, or !file (other !app are not yet supported!) - * @param string $id2='' id in $app2 - * @return the number of links deleted - */ - function unlink2($link_id,$app,&$id,$owner='',$app2='',$id2='') - { - if ($this->debug) - { - echo "
bolink::unlink('$link_id','$app','$id','$owner','$app2','$id2')
\n"; - } - if ($link_id < 0) // vfs-link? - { - return $this->delete_attached(-$link_id); - } - elseif ($app == $this->vfs_appname) - { - return $this->delete_attached($app2,$id2,$id); - } - elseif ($app2 == $this->vfs_appname) - { - return $this->delete_attached($app,$id,$id2); - } - if (!is_array($id)) - { - if (!$link_id && !$app2 && !$id2 && $app2 != '!'.$this->vfs_appname) - { - $this->delete_attached($app,$id); // deleting all attachments - unset($this->title_cache[$app.':'.$id]); - } - $deleted =& solink::unlink($link_id,$app,$id,$owner,$app2 != '!'.$this->vfs_appname ? $app2 : '',$id2); - - // only notify on real links, not the one cached for writing or fileattachments - $this->notify_unlink($deleted); - - return count($deleted); - } - if (!$link_id) $link_id = $this->temp_link_id($app2,$id2); // create link_id of temporary link, if not given - - if (isset($id[$link_id])) - { - $id[$link_id] = False; // set the unlink marker - - if ($this->debug) - { - _debug_array($id); - } - return True; - } - return False; - } - - /** - * get list/array of link-aware apps the user has rights to use - * - * @param string $must_support capability the apps need to support, eg. 'add', default ''=list all apps - * @return array with app => title pairs - */ - function app_list($must_support='') - { - $apps = array(); - foreach($this->app_register as $app => $reg) - { - if ($must_support && !isset($reg[$must_support])) continue; - - if ($GLOBALS['egw_info']['user']['apps'][$app]) - { - $apps[$app] = $GLOBALS['egw_info']['apps'][$app]['title']; - } - } - return $apps; - } - - /** - * Searches for a $pattern in the entries of $app - * - * @param string $app app to search - * @param string $pattern pattern to search - * @return array with $id => $title pairs of matching entries of app - */ - function query($app,$pattern) - { - if ($app == '' || !is_array($reg = $this->app_register[$app]) || !isset($reg['query'])) - { - return array(); - } - $method = $reg['query']; - - if ($this->debug) - { - echo "bolink.query('$app','$pattern') => '$method'
\n"; - } - return strchr($method,'.') ? ExecMethod($method,$pattern) : $this->$method($pattern); - } - - /** - * returns the title (short description) of entry $id and $app - * - * @param string $app appname - * @param string $id id in $app - * @param array $link=null link-data for file-attachments - * @return string/boolean string with title, null if $id does not exist in $app or false if no perms to view it - */ - function title($app,$id,$link=null) - { - if ($this->debug) - { - echo "bolink::title('$app','$id')
\n"; - } - if (!$id) return ''; - - if (isset($this->title_cache[$app.':'.$id])) - { - return $this->title_cache[$app.':'.$id]; - } - if ($app == $this->vfs_appname) - { - if (is_array($id) && $link) - { - $link = $id; - $id = $link['name']; - } - if (is_array($link)) - { - $size = $link['size']; - if ($size_k = intval($size / 1024)) - { - if (intval($size_k / 1024)) - { - $size = sprintf('%3.1dM',doubleval($size_k)/1024.0); - } - else - { - $size = $size_k.'k'; - } - } - $extra = ': '.$link['type'] . ' '.$size; - } - return $this->title_cache[$app.':'.$id] = $id.$extra; - } - if ($app == '' || !is_array($reg = $this->app_register[$app]) || !isset($reg['title'])) - { - return array(); - } - $method = $reg['title']; - - $title = strchr($method,'.') ? ExecMethod($method,$id) : $this->$method($id); - - if ($id && is_null($title)) // $app,$id has been deleted ==> unlink all links to it - { - $this->unlink(0,$app,$id); - return False; - } - return $this->title_cache[$app.':'.$id] = $title; - } - - /** - * Add new entry to $app, evtl. already linked to $to_app, $to_id - * - * @param string $app appname of entry to create - * @param string $to_app appname to link the new entry to - * @param string $to_id id in $to_app - * @return array/boolean with name-value pairs for link to add-methode of $app or false if add not supported - */ - function add($app,$to_app='',$to_id='') - { - //echo "bolink::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]); - if ($app == '' || !is_array($reg = $this->app_register[$app]) || !isset($reg['add'])) - { - return false; - } - $params = $reg['add']; - - if ($reg['add_app'] && $to_app && $reg['add_id'] && $to_id) - { - $params[$reg['add_app']] = $to_app; - $params[$reg['add_id']] = $to_id; - } - return $params; - } - - /** - * view entry $id of $app - * - * @param string $app appname - * @param string $id id in $app - * @param array $link=null link-data for file-attachments - * @return array with name-value pairs for link to view-methode of $app to view $id - */ - function view($app,$id,$link=null) - { - if ($app == $this->vfs_appname && !empty($id) && is_array($link)) - { - return $this->get_file($link); - } - if ($app == '' || !is_array($reg = $this->app_register[$app]) || !isset($reg['view']) || !isset($reg['view_id'])) - { - return array(); - } - $view = $reg['view']; - - $names = explode(':',$reg['view_id']); - if (count($names) > 1) - { - $id = explode(':',$id); - while (list($n,$name) = each($names)) - { - $view[$name] = $id[$n]; - } - } - else - { - $view[$reg['view_id']] = $id; - } - return $view; - } - - /** - * Check if $app uses a popup for $action - * - * @param string $app app-name - * @param string $action='view' name of the action, atm. 'view' or 'add' - * @return boolean/string false if no popup is used or $app is not registered, otherwise string with the prefered popup size (eg. '640x400) - */ - function is_popup($app,$action='view') - { - if (!($reg = $this->app_register[$app]) || !$reg[$action.'_popup']) - { - return false; - } - return $reg[$action.'_popup']; - } - - function get_file($link='') + function get_file(array $link=null) { if (is_array($link)) { @@ -600,19 +56,17 @@ class bolink extends solink 'filename' => $link['id'] ); } - $app = get_var('app','GET'); - $id = get_var('id','GET'); - $filename = get_var('filename','GET'); + $app = $_GET['app']; + $id = $_GET['id']; + $filename = $_GET['filename']; if (empty($app) || empty($id) || empty($filename) || !$this->title($app,$id)) { - $GLOBALS['egw_info']['flags']['nonavbar'] = false; - $GLOBALS['egw']->common->egw_header(); - echo '
bolink::vfs_path('$app','$id','$file') = '$path'
\n"; - } - return $relatives ? array( - 'string' => $path, - 'relatives' => is_array($relatives) ? $relatives : array($relatives) - ) : $path; - } - - /** - * Put a file to the corrosponding place in the VFS and set the attributes - * - * @param string $app appname to linke the file to - * @param string $id id in $app - * @param array $file informations about the file in format of the etemplate file-type - * $file['name'] name of the file (no directory) - * $file['type'] mine-type of the file - * $file['tmp_name'] name of the uploaded file (incl. directory) - * $file['path'] path of the file on the client computer - * $file['ip'] of the client (path and ip are only needed if u want a symlink (if possible)) - * @param string $comment='' comment to add to the link - * @return int negative id of phpgw_vfs table as negative link-id's are for vfs attachments - */ - function attach_file($app,$id,$file,$comment='') - { - if ($this->debug) - { - echo "attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment'
\n"; - } - // create the root for attached files in infolog, if it does not exists - $vfs_data = array('string'=>$this->vfs_basedir,'relatives'=>array(RELATIVE_ROOT)); - if (!($this->vfs->file_exists($vfs_data))) - { - $this->vfs->override_acl = 1; - $this->vfs->mkdir($vfs_data); - $this->vfs->override_acl = 0; - } - - $vfs_data = $this->vfs_path($app,False,False,RELATIVE_ROOT); - if (!($this->vfs->file_exists($vfs_data))) - { - $this->vfs->override_acl = 1; - $this->vfs->mkdir($vfs_data); - $this->vfs->override_acl = 0; - } - $vfs_data = $this->vfs_path($app,$id,False,RELATIVE_ROOT); - if (!($this->vfs->file_exists($vfs_data))) - { - $this->vfs->override_acl = 1; - $this->vfs->mkdir($vfs_data); - $this->vfs->override_acl = 0; - } - $fname = $this->vfs_path($app,$id,$file['name']); - $tfname = ''; - if (!empty($file['path']) && is_array($this->link_pathes) && count($this->link_pathes)) - { - $file['path'] = str_replace('\\\\','/',$file['path']); // vfs uses only '/' - @reset($this->link_pathes); - while ((list($valid,$trans) = @each($this->link_pathes)) && !$tfname) - { // check case-insensitive for WIN etc. - $check = $valid[0] == '\\' || strpos(':',$valid) !== false ? 'eregi' : 'ereg'; - $valid2 = str_replace('\\','/',$valid); - //echo "attach_file: ereg('".$this->send_file_ips[$valid]."', '$file[ip]')=".ereg($this->send_file_ips[$valid],$file['ip'])."
\n"; - if ($check('^('.$valid2.')(.*)$',$file['path'],$parts) && - ereg($this->send_file_ips[$valid],$file['ip']) && // right IP - $this->vfs->file_exists(array('string'=>$trans.$parts[2],'relatives'=>array(RELATIVE_NONE|VFS_REAL)))) - { - $tfname = $trans.$parts[2]; - } - //echo "attach_file: full_fname='$file[path]', valid2='$valid2', trans='$trans', check=$check, tfname='$tfname', parts=(x,'${parts[1]}','${parts[2]}')
\n"; - } - if ($tfname && !$this->vfs->securitycheck(array('string'=>$tfname))) - { - return False; //lang('Invalid filename').': '.$tfname; - } - } - $this->vfs->override_acl = 1; - $this->vfs->cp(array( - 'symlink' => !!$tfname, // try a symlink - 'from' => $tfname ? $tfname : $file['tmp_name'], - 'to' => $fname, - 'relatives' => array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT), - )); - $this->vfs->set_attributes(array( - 'string' => $fname, - 'relatives' => array (RELATIVE_ROOT), - 'attributes' => array ( - 'mime_type' => $file['type'], - 'comment' => stripslashes ($comment), - 'app' => $app - ))); - $this->vfs->override_acl = 0; - - $link = $this->info_attached($app,$id,$file['name']); - - return is_array($link) ? $link['link_id'] : False; - } - - /** - * deletes an attached file - * - * @param int/string $app > 0: file_id of an attchemnt or $app/$id entry which linked to - * @param string $id='' id in app - * @param string $fname filename - */ - function delete_attached($app,$id='',$fname = '') - { - if (intval($app) > 0) // is file_id - { - $link = $this->fileinfo2link($file_id=$app); - $app = $link['app2']; - $id = $link['id2']; - $fname = $link['id']; - } - if ($this->debug) - { - echo "bolink::delete_attached('$app','$id','$fname') file_id=$file_id
\n"; - } - if (empty($app) || empty($id)) - { - return False; // dont delete more than all attachments of an entry - } - $vfs_data = $this->vfs_path($app,$id,$fname,RELATIVE_ROOT); - - $Ok = false; - if ($this->vfs->file_exists($vfs_data)) - { - $this->vfs->override_acl = 1; - $Ok = $this->vfs->delete($vfs_data); - $this->vfs->override_acl = 0; - } - // if filename given (and now deleted) check if dir is empty and remove it in that case - if ($fname && !count($this->vfs->ls($vfs_data=$this->vfs_path($app,$id,'',RELATIVE_ROOT)))) - { - $this->vfs->override_acl = 1; - $this->vfs->delete($vfs_data); - $this->vfs->override_acl = 0; - } - return $Ok; - } - - /** - * converts the infos vfs has about a file into a link - * - * @param string $app appname - * @param string $id id in app - * @param string $filename filename - * @return array 'kind' of link-array - */ - function info_attached($app,$id,$filename) - { - $this->vfs->override_acl = 1; - $attachments = $this->vfs->ls($this->vfs_path($app,$id,$filename,RELATIVE_NONE)); - $this->vfs->override_acl = 0; - - if (!count($attachments) || !$attachments[0]['name']) - { - return False; - } - return $this->fileinfo2link($attachments[0]); - } - - /** - * converts a fileinfo (row in the vfs-db-table) in a link - * - * @param array/int $fileinfo a row from the vfs-db-table (eg. returned by the vfs ls function) or a file_id of that table - * @return array a 'kind' of link-array - */ - function fileinfo2link($fileinfo) - { - if (!is_array($fileinfo)) - { - $fileinfo = $this->vfs->ls(array('file_id' => $fileinfo)); - list(,$fileinfo) = each($fileinfo); - - if (!is_array($fileinfo)) - { - return False; - } - } - $lastmod = $fileinfo[!empty($fileinfo['modified']) ? 'modified' : 'created']; - list($y,$m,$d) = explode('-',$lastmod); - $lastmod = mktime(0,0,0,$m,$d,$y); - - $dir_parts = array_reverse(explode('/',$fileinfo['directory'])); - - return array( - 'app' => $this->vfs_appname, - 'id' => $fileinfo['name'], - 'app2' => $dir_parts[1], - 'id2' => $dir_parts[0], - 'remark' => $fileinfo['comment'], - 'owner' => $fileinfo['owner_id'], - 'link_id' => -$fileinfo['file_id'], - 'lastmod' => $lastmod, - 'size' => $fileinfo['size'], - 'type' => $fileinfo['mime_type'] - ); - } - - /** - * lists all attachments to $app/$id - * - * @param string $app appname - * @param string $id id in app - * @return array with link_id => 'kind' of link-array pairs - */ - function list_attached($app,$id) - { - $this->vfs->override_acl = 1; - $attachments = $this->vfs->ls($this->vfs_path($app,$id,False,RELATIVE_ROOT)); - $this->vfs->override_acl = 0; - - if (!count($attachments) || !$attachments[0]['name']) - { - return False; - } - foreach($attachments as $fileinfo) - { - $link = $this->fileinfo2link($fileinfo); - $attached[$link['link_id']] = $link; - } - return $attached; - } - - /** - * checks if path starts with a '\\' or has a ':' in it - * - * @param string $path path to check - * @return boolean true if windows path, false otherwise - */ - function is_win_path($path) - { - return $path{0} == '\\' || $path{1} == ':'; - } - - /** - * reads the attached file and returns the content - * - * @param string $app appname - * @param string $id id in app - * @param string $filename filename - * @return string/boolean content of the attached file, null if $id not found, false if no view perms - */ - function read_attached($app,$id,$filename) - { - $ret = null; - if (empty($app) || !$id || empty($filename) || !($ret = $this->title($app,$id))) - { - return $ret; - } - $this->vfs->override_acl = 1; - $data = $this->vfs->read($this->vfs_path($app,$id,$filename,RELATIVE_ROOT)); - $this->vfs->override_acl = 0; - return $data; - } - - /** - * Checks if filename should be local availible and if so returns - * - * @param string $app appname - * @param string $id id in app - * @param string $filename filename - * @param string $id ip-address of user - * @param boolean $win_user true if user is on windows, otherwise false - * @return string 'file:/path' for HTTP-redirect else return False - */ - function attached_local($app,$id,$filename,$ip,$win_user) - { - //echo "attached_local(app=$app, id='$id', filename='$filename', ip='$ip', win_user='$win_user', count(send_file_ips)=".count($this->send_file_ips).")
\n"; - - if (!$id || !$filename || /* !$this->check_access($info_id,EGW_ACL_READ) || */ - !count($this->send_file_ips)) - { - return False; - } - $link = $this->vfs->ls($this->vfs_path($app,$id,$filename,RELATIVE_ROOT)+array('readlink'=>True)); - $link = @$link[0]['symlink']; - - if ($link && is_array($this->link_pathes)) - { - reset($this->link_pathes); $fname = ''; - while ((list($valid,$trans) = each($this->link_pathes)) && !$fname) - { - if (!$this->is_win_path($valid) == !$win_user && // valid for this OS - $win_user && // only for IE/windows atm - eregi('^'.$trans.'(.*)$',$link,$parts) && // right path - ereg($this->send_file_ips[$valid],$ip)) // right IP - { - $fname = $valid . $parts[1]; - $fname = !$win_user ? str_replace('\\','/',$fname) : str_replace('/','\\',$fname); - return 'file:'.($win_user ? '//' : '' ).$fname; - } - //echo "attached_local: link=$link, valid=$valid, trans='$trans', fname='$fname', parts=(x,'${parts[1]}','${parts[2]}')
\n"; - } - } - return False; - } - - /** - * reverse function of htmlspecialchars() - * - * @param string $str string to decode - * @return string decoded string - */ - function decode_htmlspecialchars($str) - { - return str_replace(array('&','"','<','>'),array('&','"','<','>'),$str); - } - - /** - * get title for a project, should be moved to boprojects.link_title - * - * @param int/array $event project-id or already read project - * @return string/boolean the title (number: title), null if project is not found or false if no perms to view it - */ - function projects_title( $proj ) - { - if (!is_object($this->boprojects)) - { - if (!file_exists(EGW_SERVER_ROOT.'/projects')) // check if projects installed - { - return false; - } - $this->boprojects = createobject('projects.boprojects'); - } - if (!is_array($proj)) - { - $proj = $this->boprojects->read_single_project( $proj ); - } - return is_array($proj) ? $proj['number'].': '.$proj['title'] : False; - } - - /** - * query for projects matching $pattern, should be moved to boprojects.link_query - * - * @param string $pattern pattern to search - * @return array with id => title pairs of matching projects - */ - function projects_query( $pattern ) - { - if (!is_object($this->boprojects)) - { - if (!file_exists(EGW_SERVER_ROOT.'/projects')) // check if projects installed - return array(); - $this->boprojects = createobject('projects.boprojects'); - } - $projs = $this->boprojects->list_projects( array('action'=>'all','query'=>$pattern,'limit'=>FALSE) ); - $content = array(); - while ($projs && list( $key,$proj ) = each( $projs )) - { - $content[$proj['project_id']] = $this->projects_title($proj); - } - return $content; - } - - /** - * notify other apps about changed content in $app,$id - * - * @param string $app name of app in which the updated happend - * @param string $id id in $app of the updated entry - * @param array $data=null updated data of changed entry, as the read-method of the BO-layer would supply it - */ - function notify_update($app,$id,$data=null) - { - foreach($this->get_links($app,$id,'!'.$this->vfs_appname) as $link_id => $link) - { - $this->notify('update',$link['app'],$link['id'],$app,$id,$link_id,$data); - } - unset($this->title_cache[$app.':'.$id]); - } - - /** - * notify an application about a new or deleted links to own entries or updates in the content of the linked entry - * - * Please note: not all apps supply update notifications - * - * @internal - * @param string $type 'link' for new links, 'unlink' for unlinked entries, 'update' of content in linked entries - * @param string $notify_app app to notify - * @param string $notify_id id in $notify_app - * @param string $target_app name of app whos entry changed, linked or deleted - * @param string $target_id id in $target_app - * @param array $data=null data of entry in app2 (optional) - */ - function notify($type,$notify_app,$notify_id,$target_app,$target_id,$link_id,$data=null) - { - if ($link_id && isset($this->app_register[$notify_app]) && isset($this->app_register[$notify_app]['notify'])) - { - ExecMethod($this->app_register[$notify_app]['notify'],array( - 'type' => $type, - 'id' => $notify_id, - 'target_app' => $target_app, - 'target_id' => $target_id, - 'link_id' => $link_id, - 'data' => $data, - )); - } - } - - /** - * notifies about unlinked links - * - * @internal - * @param array &$links unlinked links from the database - */ - function notify_unlink(&$links) - { - foreach($links as $link) - { - // we notify both sides of the link, as the unlink command NOT clearly knows which side initiated the unlink - $this->notify('unlink',$link['link_app1'],$link['link_id1'],$link['link_app2'],$link['link_id2'],$link['link_id']); - $this->notify('unlink',$link['link_app2'],$link['link_id2'],$link['link_app1'],$link['link_id1'],$link['link_id']); - } - } + } } \ No newline at end of file diff --git a/phpgwapi/inc/class.egw_link.inc.php b/phpgwapi/inc/class.egw_link.inc.php new file mode 100644 index 0000000000..190d0165ba --- /dev/null +++ b/phpgwapi/inc/class.egw_link.inc.php @@ -0,0 +1,1076 @@ + + * @copyright 2001-2008 by RalfBecker@outdoor-training.de + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @subpackage link + * @version $Id$ + */ + +/** + * Generalized linking between entries of eGroupware apps + * + * Please note: this class can NOT and does not need to be initialised, all methods are static + * + * To participate in the linking an applications has to implement the following hooks: + * + * /** + * * Hook called by link-class to include app in the appregistry of the linkage + * * + * * @param array/string $location location and other parameters (not used) + * * @return array with method-names + * *% + * function search_link($location) + * { + * return array( + * 'query' => 'app.class.link_query', // method to search app for a pattern: array link_query(string $pattern) + * 'title' => 'app.class.link_title', // method to return title of an entry of app: string/false/null link_title(int/string $id) + * 'titles' => 'app.class.link_titles', // method to return multiple titles: array link_title(array $ids) + * 'view' => array( // get parameters to view an entry of app + * 'menuaction' => 'app.class.method', + * ), + * 'view_id' => 'app_id', // name of get parameter of the id + * 'view_popup' => '400x300', // size of popup (XxY), if view is in popup + * 'add' => array( // get parameter to add an empty entry to app + * 'menuaction' => 'app.class.method', + * ), + * 'add_app' => 'link_app', // name of get parameter to add links to other app + * 'add_id' => 'link_id', // --------------------- " ------------------- id + * 'add_popup' => '400x300', // size of popup (XxY), if add is in popup + * 'notify' => 'app.class.method', // method to be called if an other applications liks or unlinks with app: notify(array $data) + * ); + * } + * All entries are optional, thought you only get conected functionality, if you implement them ... + * + * The BO-layer implementes some extra features on top of the so-layer: + * 1) It handles links to not already existing entries. This is used by the eTemplate link-widget, which allows to + * setup links even for new / not already existing entries, before they get saved. + * In that case you have to set the first id to 0 for the link-static function and pass the array returned in that id + * (not the return-value) after saveing your new entry again to the link static function. + * 2) Attaching files: they are saved in the vfs and not the link-table (!). + * Attached files are stored under $vfs_basedir='/infolog' in the vfs! + * 3) It manages the link-registry, in which apps can register themselfs by implementing some hooks + * 4) It notifies apps, who registered for that service, about changes in the links their entries + */ +class egw_link extends solink +{ + /** + * Basepath for attached files + * + * @todo change to '/apps' once the new vfs is complete + */ + const VFS_BASEDIR = '/infolog'; + /** + * appname used for returned attached files (!= 'filemanager'!) + */ + const VFS_APPNAME = 'file'; // pseudo-appname for own file-attachments in vfs, this is NOT the vfs-app + /** + * Turns on debug-messages + */ + const DEBUG = false; + /** + * other apps can participate in the linking by implementing a 'search_link' hook, which + * has to return an array in the format of an app_register entry below + * + * @var array + */ + static $app_register = array( + 'felamimail' => array( + 'add' => array( + 'menuaction' => 'felamimail.uicompose.compose', + ), + 'add_popup' => '700x750', + ), + ); + /** + * Instance of the vfs class + * + * @var vfs + */ + private static $vfs; + private static $link_pathes = array(); + private static $send_file_ips = array(); + /** + * Caches link titles for a better performance + * + * @var array + */ + private static $title_cache = array(); + + /** + * Private constructor to forbide instanciated use + * + */ + private function __construct() + { + + } + + /** + * initialize our static vars + */ + static function init_static( ) + { + self::$vfs = new vfs(); + + self::$link_pathes =& $GLOBALS['egw_info']['server']['link_pathes']; + self::$send_file_ips =& $GLOBALS['egw_info']['server']['send_file_ips']; + + // other apps can participate in the linking by implementing a search_link hook, which + // has to return an array in the format of an app_register entry + // for performance reasons, we do it only once / cache it in the session + if (!($search_link_hooks = $GLOBALS['egw']->session->appsession('search_link_hooks','phpgwapi'))) + { + $search_link_hooks = $GLOBALS['egw']->hooks->process('search_link'); + $GLOBALS['egw']->session->appsession('search_link_hooks','phpgwapi',$search_link_hooks); + } + if (is_array($search_link_hooks)) + { + foreach($search_link_hooks as $app => $data) + { + if (is_array($data)) + { + self::$app_register[$app] = $data; + } + } + } + if (!(self::$title_cache = $GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi'))) + { + self::$title_cache = array(); + } + } + + /** + * Called by egw::egw_final to store the title-cache in the session + * + */ + static function save_session_cache() + { + $GLOBALS['egw']->session->appsession('link_title_cache','phpgwapi',self::$title_cache); + } + + /** + * creats a link between $app1,$id1 and $app2,$id2 - $id1 does NOT need to exist yet + * + * Does NOT check if link already exists. + * File-attachments return a negative link-id !!! + * + * @param string $app1 app of $id1 + * @param string/array &$id1 id of item to linkto or 0 if item not yet created or array with links + * of not created item or $file-array if $app1 == self::VFS_APPNAME (see below). + * If $id==0 it will be set on return to an array with the links for the new item. + * @param string/array $app2 app of 2.linkend or array with links ($id2 not used) + * @param string $id2='' id of 2. item of $file-array if $app2 == self::VFS_APPNAME (see below)egw_link::link('$app1',$id1,'".print_r($app2,true)."',".print_r($id2,true).",'$remark',$owner,$lastmod)
\n"; + } + if (!$app1 || !$app2 || $app1 == $app2 && $id1 == $id2) + { + return False; + } + if (is_array($id1) || !$id1) // create link only in $id1 array + { + if (!is_array($id1)) + { + $id1 = array( ); + } + $link_id = self::temp_link_id($app2,$id2); + + $id1[$link_id] = array( + 'app' => $app2, + 'id' => $id2, + 'remark' => $remark, + 'owner' => $owner, + 'link_id' => $link_id, + 'lastmod' => time() + ); + if (self::DEBUG) + { + _debug_array($id1); + } + return $link_id; + } + if (is_array($app2) && !$id2) + { + reset($app2); + $link_id = True; + while ($link_id && list(,$link) = each($app2)) + { + if (!is_array($link)) // check for unlink-marker + { + //echo "link='$link' is no arrayegw_link::get_links(app='$app',id='$id',only_app='$only_app',order='$order')
\n"; + + if (is_array($id) || !$id) + { + $ids = array(); + if (is_array($id)) + { + if ($not_only = $only_app[0]) + { + $only_app = substr(1,$only_app); + } + end($id); + foreach (array_reverse($id) as $link) + { + if (is_array($link) // check for unlink-marker + && !($only_app && $not_only == ($link['app'] == $only_app))) + { + $ids[$link['link_id']] = $only_app ? $link['id'] : $link; + } + } + } + return $ids; + } + $ids = solink::get_links($app,$id,$only_app,$order); + + if (empty($only_app) || $only_app == self::VFS_APPNAME || + ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) + { + if ($vfs_ids = self::list_attached($app,$id)) + { + $ids += $vfs_ids; + } + } + //echo "ids="; print_r($ids); echo "\n"; + + return $ids; + } + + /** + * Query the links of multiple entries of one application + * + * @ToDo also query the attachments in a single query, eg. via a directory listing of /apps/$app + * @param string $app + * @param array $ids + * @return array of $id => array($links) pairs + */ + static function get_links_multiple($app,array $ids,$only_app='',$order='link_lastmod DESC' ) + { + $links = solink::get_links($app,$ids,$only_app,$order); + + if (empty($only_app) || $only_app == self::VFS_APPNAME || + ($only_app[0] == '!' && $only_app != '!'.self::VFS_APPNAME)) + { + // todo do that in a single query, eg. directory listing, too + foreach($ids as $id) + { + if (!isset($links[$id])) + { + $links[$id] = array(); + } + if ($vfs_ids = self::list_attached($app,$id)) + { + $links[$id] += $vfs_ids; + } + } + } + return $links; + } + + /** + * Read one link specified by it's link_id or by the two end-points + * + * If $id is an array (links not yet created) only link_ids are allowed. + * + * @param int/string $app_link_id > 0 link_id of link or app-name of link + * @param string/array $id='' id if $app_link_id is an appname or array with links, if 1. entry not yet created + * @param string $app2='' second app + * @param string $id2='' id in $app2 + * @return array with link-data or False + */ + static function get_link($app_link_id,$id='',$app2='',$id2='') + { + //echo '
'.__METHOD__."($app_link_id,$id,$app2,$id2)
\n"; echo function_backtrace(); + if (is_array($id)) + { + if (strpos($app_link_id,':') === false) $app_link_id = self::temp_link_id($app2,$id2); // create link_id of temporary link, if not given + + if (isset($id[$app_link_id]) && is_array($id[$app_link_id])) // check for unlinked-marker + { + return $id[$app_link_id]; + } + return False; + } + if ((int)$app_link_id < 0 || $app_link_id == self::VFS_APPNAME || $app2 == self::VFS_APPNAME) + { + if ((int)$app_link_id < 0) // vfs link_id ? + { + return self::fileinfo2link(-$app_link_id); + } + if ($app_link_id == self::VFS_APPNAME) + { + return self::info_attached($app2,$id2,$id); + } + return self::info_attached($app_link_id,$id,$id2); + } + return solink::get_link($app_link_id,$id,$app2,$id2); + } + + /** + * Remove link with $link_id or all links matching given $app,$id + * + * Note: if $link_id != '' and $id is an array: unlink removes links from that array only + * unlink has to be called with &$id to see the result (depricated) or unlink2 has to be used !!! + * + * @param $link_id link-id to remove if > 0 + * @param string $app='' appname of first endpoint + * @param string/array $id='' id in $app or array with links, if 1. entry not yet created + * @param string $app2='' app of second endpoint + * @param string $id2='' id in $app2 + * @return the number of links deleted + */ + static function unlink($link_id,$app='',$id='',$owner='',$app2='',$id2='') + { + return self::unlink2($link_id,$app,$id,$owner,$app2,$id2); + } + + /** + * Remove link with $link_id or all links matching given $app,$id + * + * @param $link_id link-id to remove if > 0 + * @param string $app='' appname of first endpoint + * @param string/array &$id='' id in $app or array with links, if 1. entry not yet created + * @param string $app2='' app of second endpoint, or !file (other !app are not yet supported!) + * @param string $id2='' id in $app2 + * @return the number of links deleted + */ + static function unlink2($link_id,$app,&$id,$owner='',$app2='',$id2='') + { + if (self::DEBUG) + { + echo "egw_link::unlink('$link_id','$app','$id','$owner','$app2','$id2')
\n"; + } + if ($link_id < 0) // vfs-link? + { + return self::delete_attached(-$link_id); + } + elseif ($app == self::VFS_APPNAME) + { + return self::delete_attached($app2,$id2,$id); + } + elseif ($app2 == self::VFS_APPNAME) + { + return self::delete_attached($app,$id,$id2); + } + if (!is_array($id)) + { + if (!$link_id && !$app2 && !$id2 && $app2 != '!'.self::VFS_APPNAME) + { + self::delete_attached($app,$id); // deleting all attachments + unset(self::$title_cache[$app.':'.$id]); + } + $deleted =& solink::unlink($link_id,$app,$id,$owner,$app2 != '!'.self::VFS_APPNAME ? $app2 : '',$id2); + + // only notify on real links, not the one cached for writing or fileattachments + self::notify_unlink($deleted); + + return count($deleted); + } + if (!$link_id) $link_id = self::temp_link_id($app2,$id2); // create link_id of temporary link, if not given + + if (isset($id[$link_id])) + { + $id[$link_id] = False; // set the unlink marker + + if (self::DEBUG) + { + _debug_array($id); + } + return True; + } + return False; + } + + /** + * get list/array of link-aware apps the user has rights to use + * + * @param string $must_support capability the apps need to support, eg. 'add', default ''=list all apps + * @return array with app => title pairs + */ + static function app_list($must_support='') + { + $apps = array(); + foreach(self::$app_register as $app => $reg) + { + if ($must_support && !isset($reg[$must_support])) continue; + + if ($GLOBALS['egw_info']['user']['apps'][$app]) + { + $apps[$app] = $GLOBALS['egw_info']['apps'][$app]['title']; + } + } + return $apps; + } + + /** + * Searches for a $pattern in the entries of $app + * + * @param string $app app to search + * @param string $pattern pattern to search + * @return array with $id => $title pairs of matching entries of app + */ + static function query($app,$pattern) + { + if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['query'])) + { + return array(); + } + $method = $reg['query']; + + if (self::DEBUG) + { + echo "egw_link::query('$app','$pattern') => '$method'
\n"; + } + return ExecMethod($method,$pattern); + } + + /** + * returns the title (short description) of entry $id and $app + * + * @param string $app appname + * @param string $id id in $app + * @param array $link=null link-data for file-attachments + * @return string/boolean string with title, null if $id does not exist in $app or false if no perms to view it + */ + static function title($app,$id,$link=null) + { + if (self::DEBUG) + { + echo "egw_link::title('$app','$id')
\n"; + } + if (!$id) return ''; + + if (isset(self::$title_cache[$app.':'.$id])) + { + return self::$title_cache[$app.':'.$id]; + } + if ($app == self::VFS_APPNAME) + { + if (is_array($id) && $link) + { + $link = $id; + $id = $link['name']; + } + if (is_array($link)) + { + $size = $link['size']; + if ($size_k = (int)($size / 1024)) + { + if ((int)($size_k / 1024)) + { + $size = sprintf('%3.1dM',doubleval($size_k)/1024.0); + } + else + { + $size = $size_k.'k'; + } + } + $extra = ': '.$link['type'] . ' '.$size; + } + return self::$title_cache[$app.':'.$id] = $id.$extra; + } + if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['title'])) + { + return array(); + } + $method = $reg['title']; + + $title = ExecMethod($method,$id); + + if ($id && is_null($title)) // $app,$id has been deleted ==> unlink all links to it + { + self::unlink(0,$app,$id); + return False; + } + return self::$title_cache[$app.':'.$id] = $title; + } + + /** + * Query the titles off multiple id's of one app + * + * Apps can implement that hook, if they have a quicker (eg. less DB queries) method to query the title of multiple entries. + * If it's not implemented, we call the regular title method multiple times. + * + * @param string $app + * @param array $ids + */ + static function titles($app,array $ids) + { + $titles = $ids_to_query = array(); + foreach($ids as $id) + { + if (!isset(self::$title_cache[$app.':'.$id])) + { + if (isset(self::$app_register[$app]['titles'])) + { + $ids_to_query[] = $id; // titles method --> collect links to query at once + } + else + { + self::title($app,$id); // no titles method --> fallback to query each link separate + } + } + $titles[$id] = $title_cache[$app.':'.$id]; + } + if ($ids_to_query) + { + $titles = array_merge($titles,ExecMethod(self::$app_register[$app]['titles'],$ids_to_query)); + } + return $titles; + } + + /** + * Add new entry to $app, evtl. already linked to $to_app, $to_id + * + * @param string $app appname of entry to create + * @param string $to_app appname to link the new entry to + * @param string $to_id id in $to_app + * @return array/boolean with name-value pairs for link to add-methode of $app or false if add not supported + */ + static function add($app,$to_app='',$to_id='') + { + //echo "egw_link::add('$app','$to_app','$to_id') app_register[$app] ="; _debug_array($app_register[$app]); + if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['add'])) + { + return false; + } + $params = $reg['add']; + + if ($reg['add_app'] && $to_app && $reg['add_id'] && $to_id) + { + $params[$reg['add_app']] = $to_app; + $params[$reg['add_id']] = $to_id; + } + return $params; + } + + /** + * view entry $id of $app + * + * @ToDo use webdav url of new vfs, once ACL for /apps is ready + * @param string $app appname + * @param string $id id in $app + * @param array $link=null link-data for file-attachments + * @return array with name-value pairs for link to view-methode of $app to view $id + */ + static function view($app,$id,$link=null) + { + if ($app == self::VFS_APPNAME && !empty($id) && is_array($link)) + { + return array( + 'menuaction' => 'phpgwapi.bolink.get_file', + 'app' => $link['app2'], + 'id' => $link['id2'], + 'filename' => $link['id'] + ); + } + if ($app == '' || !is_array($reg = self::$app_register[$app]) || !isset($reg['view']) || !isset($reg['view_id'])) + { + return array(); + } + $view = $reg['view']; + + $names = explode(':',$reg['view_id']); + if (count($names) > 1) + { + $id = explode(':',$id); + while (list($n,$name) = each($names)) + { + $view[$name] = $id[$n]; + } + } + else + { + $view[$reg['view_id']] = $id; + } + return $view; + } + + /** + * Check if $app uses a popup for $action + * + * @param string $app app-name + * @param string $action='view' name of the action, atm. 'view' or 'add' + * @return boolean/string false if no popup is used or $app is not registered, otherwise string with the prefered popup size (eg. '640x400) + */ + static function is_popup($app,$action='view') + { + if (!($reg = self::$app_register[$app]) || !$reg[$action.'_popup']) + { + return false; + } + return $reg[$action.'_popup']; + } + + /** + * path to the attached files of $app/$ip or the directory for $app if no $id,$file given + * + * All link-files are based in the vfs-subdir '/infolog'. For other apps + * separate subdirs with name app are created. + * + * @ToDo change to new VFS_BASEDIR /apps (incl. /apps/infolog) + * @param string $app appname + * @param string $id='' id in $app + * @param string $file='' filename + * @param boolean/array $relatives=False return path as array with path in string incl. relatives + * @return string/array path or array with path and relatives, depending on $relatives + */ + static function vfs_path($app,$id='',$file='',$relatives=False) + { + $path = self::VFS_BASEDIR . ($app == '' || $app == 'infolog' ? '' : '/'.$app) . + ($id != '' ? '/' . $id : '') . ($file != '' ? '/' . $file : ''); + + if (self::DEBUG) + { + echo "
egw_link::vfs_path('$app','$id','$file') = '$path'
\n"; + } + return $relatives ? array( + 'string' => $path, + 'relatives' => is_array($relatives) ? $relatives : array($relatives) + ) : $path; + } + + /** + * Put a file to the corrosponding place in the VFS and set the attributes + * + * @param string $app appname to linke the file to + * @param string $id id in $app + * @param array $file informations about the file in format of the etemplate file-type + * $file['name'] name of the file (no directory) + * $file['type'] mine-type of the file + * $file['tmp_name'] name of the uploaded file (incl. directory) + * $file['path'] path of the file on the client computer + * $file['ip'] of the client (path and ip are only needed if u want a symlink (if possible)) + * @param string $comment='' comment to add to the link + * @return int negative id of phpgw_vfs table as negative link-id's are for vfs attachments + */ + static function attach_file($app,$id,$file,$comment='') + { + if (self::DEBUG) + { + echo "attach_file: app='$app', id='$id', tmp_name='$file[tmp_name]', name='$file[name]', size='$file[size]', type='$file[type]', path='$file[path]', ip='$file[ip]', comment='$comment'
\n"; + } + // create the root for attached files in infolog, if it does not exists + $vfs_data = array('string'=>self::VFS_BASEDIR,'relatives'=>array(RELATIVE_ROOT)); + if (!(self::$vfs->file_exists($vfs_data))) + { + self::$vfs->override_acl = 1; + self::$vfs->mkdir($vfs_data); + self::$vfs->override_acl = 0; + } + + $vfs_data = self::vfs_path($app,False,False,RELATIVE_ROOT); + if (!(self::$vfs->file_exists($vfs_data))) + { + self::$vfs->override_acl = 1; + self::$vfs->mkdir($vfs_data); + self::$vfs->override_acl = 0; + } + $vfs_data = self::vfs_path($app,$id,False,RELATIVE_ROOT); + if (!(self::$vfs->file_exists($vfs_data))) + { + self::$vfs->override_acl = 1; + self::$vfs->mkdir($vfs_data); + self::$vfs->override_acl = 0; + } + $fname = self::vfs_path($app,$id,$file['name']); + $tfname = ''; + if (!empty($file['path']) && is_array(self::$link_pathes) && count(self::$link_pathes)) + { + $file['path'] = str_replace('\\\\','/',$file['path']); // vfs uses only '/' + @reset(self::$link_pathes); + while ((list($valid,$trans) = @each(self::$link_pathes)) && !$tfname) + { // check case-insensitive for WIN etc. + $check = $valid[0] == '\\' || strpos(':',$valid) !== false ? 'eregi' : 'ereg'; + $valid2 = str_replace('\\','/',$valid); + //echo "attach_file: ereg('".self::$send_file_ips[$valid]."', '$file[ip]')=".ereg(self::$send_file_ips[$valid],$file['ip'])."
\n"; + if ($check('^('.$valid2.')(.*)$',$file['path'],$parts) && + ereg(self::$send_file_ips[$valid],$file['ip']) && // right IP + self::$vfs->file_exists(array('string'=>$trans.$parts[2],'relatives'=>array(RELATIVE_NONE|VFS_REAL)))) + { + $tfname = $trans.$parts[2]; + } + //echo "attach_file: full_fname='$file[path]', valid2='$valid2', trans='$trans', check=$check, tfname='$tfname', parts=(x,'${parts[1]}','${parts[2]}')
\n"; + } + if ($tfname && !self::$vfs->securitycheck(array('string'=>$tfname))) + { + return False; //lang('Invalid filename').': '.$tfname; + } + } + self::$vfs->override_acl = 1; + self::$vfs->cp(array( + 'symlink' => !!$tfname, // try a symlink + 'from' => $tfname ? $tfname : $file['tmp_name'], + 'to' => $fname, + 'relatives' => array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT), + )); + self::$vfs->set_attributes(array( + 'string' => $fname, + 'relatives' => array (RELATIVE_ROOT), + 'attributes' => array ( + 'mime_type' => $file['type'], + 'comment' => stripslashes ($comment), + 'app' => $app + ))); + self::$vfs->override_acl = 0; + + $link = self::info_attached($app,$id,$file['name']); + + return is_array($link) ? $link['link_id'] : False; + } + + /** + * deletes an attached file + * + * @param int/string $app > 0: file_id of an attchemnt or $app/$id entry which linked to + * @param string $id='' id in app + * @param string $fname filename + */ + static function delete_attached($app,$id='',$fname = '') + { + if ((int)$app > 0) // is file_id + { + $link = self::fileinfo2link($file_id=$app); + $app = $link['app2']; + $id = $link['id2']; + $fname = $link['id']; + } + if (self::DEBUG) + { + echo "egw_link::delete_attached('$app','$id','$fname') file_id=$file_id
\n"; + } + if (empty($app) || empty($id)) + { + return False; // dont delete more than all attachments of an entry + } + $vfs_data = self::vfs_path($app,$id,$fname,RELATIVE_ROOT); + + $Ok = false; + if (self::$vfs->file_exists($vfs_data)) + { + self::$vfs->override_acl = 1; + $Ok = self::$vfs->delete($vfs_data); + self::$vfs->override_acl = 0; + } + // if filename given (and now deleted) check if dir is empty and remove it in that case + if ($fname && !count(self::$vfs->ls($vfs_data=self::vfs_path($app,$id,'',RELATIVE_ROOT)))) + { + self::$vfs->override_acl = 1; + self::$vfs->delete($vfs_data); + self::$vfs->override_acl = 0; + } + return $Ok; + } + + /** + * converts the infos vfs has about a file into a link + * + * @param string $app appname + * @param string $id id in app + * @param string $filename filename + * @return array 'kind' of link-array + */ + static function info_attached($app,$id,$filename) + { + self::$vfs->override_acl = 1; + $attachments = self::$vfs->ls(self::vfs_path($app,$id,$filename,RELATIVE_NONE)); + self::$vfs->override_acl = 0; + + if (!count($attachments) || !$attachments[0]['name']) + { + return False; + } + return self::fileinfo2link($attachments[0]); + } + + /** + * converts a fileinfo (row in the vfs-db-table) in a link + * + * @param array/int $fileinfo a row from the vfs-db-table (eg. returned by the vfs ls static function) or a file_id of that table + * @return array a 'kind' of link-array + */ + static function fileinfo2link($fileinfo) + { + if (!is_array($fileinfo)) + { + $fileinfo = self::$vfs->ls(array('file_id' => $fileinfo)); + list(,$fileinfo) = each($fileinfo); + + if (!is_array($fileinfo)) + { + return False; + } + } + $lastmod = $fileinfo[!empty($fileinfo['modified']) ? 'modified' : 'created']; + list($y,$m,$d) = explode('-',$lastmod); + $lastmod = mktime(0,0,0,$m,$d,$y); + + $dir_parts = array_reverse(explode('/',$fileinfo['directory'])); + + return array( + 'app' => self::VFS_APPNAME, + 'id' => $fileinfo['name'], + 'app2' => $dir_parts[1], + 'id2' => $dir_parts[0], + 'remark' => $fileinfo['comment'], + 'owner' => $fileinfo['owner_id'], + 'link_id' => -$fileinfo['file_id'], + 'lastmod' => $lastmod, + 'size' => $fileinfo['size'], + 'type' => $fileinfo['mime_type'] + ); + } + + /** + * lists all attachments to $app/$id + * + * @param string $app appname + * @param string $id id in app + * @return array with link_id => 'kind' of link-array pairs + */ + static function list_attached($app,$id) + { + self::$vfs->override_acl = 1; + $attachments = self::$vfs->ls(self::vfs_path($app,$id,False,RELATIVE_ROOT)); + self::$vfs->override_acl = 0; + + if (!count($attachments) || !$attachments[0]['name']) + { + return False; + } + foreach($attachments as $fileinfo) + { + $link = self::fileinfo2link($fileinfo); + $attached[$link['link_id']] = $link; + } + return $attached; + } + + /** + * checks if path starts with a '\\' or has a ':' in it + * + * @param string $path path to check + * @return boolean true if windows path, false otherwise + */ + static function is_win_path($path) + { + return $path{0} == '\\' || $path{1} == ':'; + } + + /** + * reads the attached file and returns the content + * + * @param string $app appname + * @param string $id id in app + * @param string $filename filename + * @return string/boolean content of the attached file, null if $id not found, false if no view perms + */ + static function read_attached($app,$id,$filename) + { + $ret = null; + if (empty($app) || !$id || empty($filename) || !($ret = self::title($app,$id))) + { + return $ret; + } + self::$vfs->override_acl = 1; + $data = self::$vfs->read(self::vfs_path($app,$id,$filename,RELATIVE_ROOT)); + self::$vfs->override_acl = 0; + + return $data; + } + + /** + * Checks if filename should be local availible and if so returns + * + * @param string $app appname + * @param string $id id in app + * @param string $filename filename + * @param string $id ip-address of user + * @param boolean $win_user true if user is on windows, otherwise false + * @return string 'file:/path' for HTTP-redirect else return False + */ + static function attached_local($app,$id,$filename,$ip,$win_user) + { + //echo "attached_local(app=$app, id='$id', filename='$filename', ip='$ip', win_user='$win_user', count(send_file_ips)=".count(self::$send_file_ips).")
\n"; + + if (!$id || !$filename || /* !self::check_access($info_id,EGW_ACL_READ) || */ + !count(self::$send_file_ips)) + { + return False; + } + $link = self::$vfs->ls(self::vfs_path($app,$id,$filename,RELATIVE_ROOT)+array('readlink'=>True)); + $link = @$link[0]['symlink']; + + if ($link && is_array(self::$link_pathes)) + { + reset(self::$link_pathes); $fname = ''; + while ((list($valid,$trans) = each(self::$link_pathes)) && !$fname) + { + if (!self::is_win_path($valid) == !$win_user && // valid for this OS + $win_user && // only for IE/windows atm + eregi('^'.$trans.'(.*)$',$link,$parts) && // right path + ereg(self::$send_file_ips[$valid],$ip)) // right IP + { + $fname = $valid . $parts[1]; + $fname = !$win_user ? str_replace('\\','/',$fname) : str_replace('/','\\',$fname); + return 'file:'.($win_user ? '//' : '' ).$fname; + } + //echo "attached_local: link=$link, valid=$valid, trans='$trans', fname='$fname', parts=(x,'${parts[1]}','${parts[2]}')
\n"; + } + } + return False; + } + + /** + * reverse static function of htmlspecialchars() + * + * @param string $str string to decode + * @return string decoded string + */ + static private function decode_htmlspecialchars($str) + { + return str_replace(array('&','"','<','>'),array('&','"','<','>'),$str); + } + + /** + * notify other apps about changed content in $app,$id + * + * @param string $app name of app in which the updated happend + * @param string $id id in $app of the updated entry + * @param array $data=null updated data of changed entry, as the read-method of the BO-layer would supply it + */ + static function notify_update($app,$id,$data=null) + { + foreach(self::get_links($app,$id,'!'.self::VFS_APPNAME) as $link_id => $link) + { + self::notify('update',$link['app'],$link['id'],$app,$id,$link_id,$data); + } + unset(self::$title_cache[$app.':'.$id]); + } + + /** + * notify an application about a new or deleted links to own entries or updates in the content of the linked entry + * + * Please note: not all apps supply update notifications + * + * @internal + * @param string $type 'link' for new links, 'unlink' for unlinked entries, 'update' of content in linked entries + * @param string $notify_app app to notify + * @param string $notify_id id in $notify_app + * @param string $target_app name of app whos entry changed, linked or deleted + * @param string $target_id id in $target_app + * @param array $data=null data of entry in app2 (optional) + */ + static private function notify($type,$notify_app,$notify_id,$target_app,$target_id,$link_id,$data=null) + { + if ($link_id && isset(self::$app_register[$notify_app]) && isset(self::$app_register[$notify_app]['notify'])) + { + ExecMethod(self::$app_register[$notify_app]['notify'],array( + 'type' => $type, + 'id' => $notify_id, + 'target_app' => $target_app, + 'target_id' => $target_id, + 'link_id' => $link_id, + 'data' => $data, + )); + } + } + + /** + * notifies about unlinked links + * + * @internal + * @param array &$links unlinked links from the database + */ + static private function notify_unlink(&$links) + { + foreach($links as $link) + { + // we notify both sides of the link, as the unlink command NOT clearly knows which side initiated the unlink + self::notify('unlink',$link['link_app1'],$link['link_id1'],$link['link_app2'],$link['link_id2'],$link['link_id']); + self::notify('unlink',$link['link_app2'],$link['link_id2'],$link['link_app1'],$link['link_id1'],$link['link_id']); + } + } +} +egw_link::init_static(); \ No newline at end of file diff --git a/phpgwapi/inc/class.solink.inc.php b/phpgwapi/inc/class.solink.inc.php index 8bd739e2da..bed17fd333 100644 --- a/phpgwapi/inc/class.solink.inc.php +++ b/phpgwapi/inc/class.solink.inc.php @@ -8,6 +8,7 @@ * * @link http://www.egroupware.org * @author Ralf Beckersolink.link('$app1',$id1,'$app2',$id2,'$remark',$owner)
\n"; } @@ -88,9 +77,9 @@ class solink } if (!$owner) { - $owner = $this->user; + $owner = self::$user; } - return $this->db->insert($this->link_table,array( + return self::$db->insert(self::TABLE,array( 'link_app1' => $app1, 'link_id1' => $id1, 'link_app2' => $app2, @@ -98,7 +87,7 @@ class solink 'link_remark' => $remark, 'link_lastmod' => $lastmod ? $lastmod : time(), 'link_owner' => $owner, - ),False,__LINE__,__FILE__) ? $this->db->get_last_insert_id($this->link_table,'link_id') : false; + ),False,__LINE__,__FILE__) ? self::$db->get_last_insert_id(self::TABLE,'link_id') : false; } /** @@ -108,9 +97,9 @@ class solink * @param string $remark new text for the remark * @return boolean true on success, else false */ - function update_remark($link_id,$remark) + static function update_remark($link_id,$remark) { - return $this->db->update($this->link_table,array( + return self::$db->update(self::TABLE,array( 'link_remark' => $remark, 'link_lastmod' => time(), ),array( @@ -122,44 +111,38 @@ class solink * returns array of links to $app,$id * * @param string $app appname - * @param string $id id in $app + * @param string/array $id id(s) in $app * @param string $only_app if set return only links from $only_app (eg. only addressbook-entries) or NOT from if $only_app[0]=='!' * @param string $order defaults to newest links first - * @return array of links (only_app: ids) or empty array if no matching links found + * @return array id => links pairs if $id is an array or just the links (only_app: ids) or empty array if no matching links found */ - function get_links( $app,$id,$only_app='',$order='link_lastmod DESC' ) + static function get_links( $app,$id,$only_app='',$order='link_lastmod DESC' ) { - if ($this->debug) + if (self::DEBUG) { - echo "solink.get_links($app,$id,$only_app,$order)
\n"; + echo "solink.get_links($app,".print_r($id,true).",$only_app,$order)
\n"; + } + if ($not_only = $only_app[0] == '!') + { + $only_app = substr($only_app,1); } $links = array(); - - $this->db->select($this->link_table,'*',$this->db->expression($this->link_table,'(',array( + foreach(self::$db->select(self::TABLE,'*',self::$db->expression(self::TABLE,'(',array( 'link_app1' => $app, 'link_id1' => $id, ),') OR (',array( 'link_app2' => $app, 'link_id2' => $id, ),')' - ),__LINE__,__FILE__,False,$order ? " ORDER BY $order" : ''); - - $this->db->query($sql,__LINE__,__FILE__); - - if ($not_only = $only_app[0] == '!') + ),__LINE__,__FILE__,False,$order ? " ORDER BY $order" : '') as $row) { - $only_app = substr($only_app,1); - } - while ($this->db->next_record()) - { - $row = $this->db->Record; - - if ($row['link_app1'] == $app AND $row['link_id1'] == $id) + if ($row['link_app1'] == $app && in_array($row['link_id1'],(array)$id)) { $link = array( 'app' => $row['link_app2'], 'id' => $row['link_id2'] ); + $app_id = $row['link_id1']; } else { @@ -167,20 +150,21 @@ class solink 'app' => $row['link_app1'], 'id' => $row['link_id1'] ); + $app_id = $row['link_id1']; } if ($only_app && $not_only == ($link['app'] == $only_app) || !$GLOBALS['egw_info']['user']['apps'][$link['app']]) { continue; } - $link['remark'] = $row['link_remark']; - $link['owner'] = $row['link_owner']; - $link['lastmod'] = $row['link_lastmod']; - $link['link_id'] = $row['link_id']; - - $links[$row['link_id']] = $only_app && !$not_only ? $link['id'] : $link; + $links[$app_id][$row['link_id']] = $only_app && !$not_only ? $link['id'] : $link+array( + 'remark' => $row['link_remark'], + 'owner' => $row['link_owner'], + 'lastmod' => $row['link_lastmod'], + 'link_id' => $row['link_id'], + ); } - return $links; + return is_array($id) ? $links : ($links[$id] ? $links[$id] : array()); } /** @@ -192,9 +176,9 @@ class solink * @param string $id2='' id in $app2, if no integer link_id given in $app_link_id * @return array with link-data or False */ - function get_link($app_link_id,$id='',$app2='',$id2='') + static function get_link($app_link_id,$id='',$app2='',$id2='') { - if ($this->debug) + if (self::DEBUG) { echo "solink.get_link('$app_link_id',$id,'$app2','$id2')
\n"; } @@ -208,12 +192,7 @@ class solink { return False; } - $vars2addslashes = array('app_link_id','id','app2','id2'); - foreach ($vars2addslashes as $var) - { - $$var = $this->db->db_addslashes($$var); - } - $where = $this->db->expression($this->link_table,'(',array( + $where = self::$db->expression(self::TABLE,'(',array( 'link_app1' => $app_link_id, 'link_id1' => $id, 'link_app2' => $app2, @@ -225,15 +204,13 @@ class solink 'link_id1' => $id2, ),')'); } - $this->db->select($this->link_table,'*',$where,__LINE__,__FILE__); - - if ($this->db->next_record()) + foreach(self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__) as $row) { - if ($this->debug) + if (self::DEBUG) { - _debug_array($this->db->Record); + _debug_array($row); } - return $this->db->Record; + return $row; } return False; } @@ -249,9 +226,9 @@ class solink * @param string $id2='' id in $app2 * @return array with deleted links */ - function &unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='') + static function &unlink($link_id,$app='',$id='',$owner=0,$app2='',$id2='') { - if ($this->debug) + if (self::DEBUG) { echo "solink.unlink($link_id,$app,$id,$owner,$app2,$id2)
\n"; } @@ -274,11 +251,11 @@ class solink $check1['link_id1'] = $id; $check2['link_id2'] = $id; } - $where = $this->db->expression($this->link_table,'((',$check1,') OR (',$check2,'))'); + $where = self::$db->expression(self::TABLE,'((',$check1,') OR (',$check2,'))'); } elseif ($app != '' && $app2 != '') { - $where = $this->db->expression($this->link_table,'(',array( + $where = self::$db->expression(self::TABLE,'(',array( 'link_app1' => $app, 'link_id1' => $id, 'link_app2' => $app2, @@ -296,13 +273,12 @@ class solink $where['link_owner'] = $owner; } } - $this->db->select($this->link_table,'*',$where,__LINE__,__FILE__); $deleted = array(); - while (($row = $this->db->row(true))) + foreach(self::$db->select(self::TABLE,'*',$where,__LINE__,__FILE__) as $row) { $deleted[] = $row; } - $this->db->delete($this->link_table,$where,__LINE__,__FILE__); + self::$db->delete(self::TABLE,$where,__LINE__,__FILE__); return $deleted; } @@ -317,15 +293,15 @@ class solink * @param int $new_owner account_id of new owner * @return int number of links changed */ - function chown($owner,$new_owner) + static function chown($owner,$new_owner) { if ((int)$owner <= 0 || (int) $new_owner <= 0) { return 0; } - $this->db->update($this->link_table,array('owner'=>$new_owner),array('owner'=>$owner),__LINE__,__FILE__); + self::$db->update(self::TABLE,array('owner'=>$new_owner),array('owner'=>$owner),__LINE__,__FILE__); - return $this->db->affected_rows(); + return self::$db->affected_rows(); } /** @@ -342,53 +318,58 @@ class solink * bolink::get_3links('timesheet','projectmanager',$pm_id) returns the links (c) between the timesheet and the project, * plus the other app/id in the keys 'app3' and 'id3' * - * Please note / ToDo: - * at the moment only those links are returned, who are initiated by $app1, means for whom link_app1=$app1 - * * @param string $app app the returned links are linked on one side (atm. this must be link_app1!) * @param string $target_app app the returned links other side link also to * @param string/array $target_id=null id(s) the returned links other side link also to * @return array with links from entries from $app to $target_app/$target_id plus the other (b) link_id/app/id in the keys 'link3'/'app3'/'id3' */ - function get_3links($app,$target_app,$target_id=null) + static function get_3links($app,$target_app,$target_id=null) { - $links = array(); - $table_def = $this->db->get_table_definitions('phpgwapi',$this->link_table); + $table = self::TABLE; $arrayofselects=array( // retrieve the type of links, where the relation is realized as timesheet->infolog/tracker via infolog->projectmanager to timesheet->projectmanager - array('table'=>$this->link_table, + array('table'=>self::TABLE, 'cols'=>'c.*,b.link_app1 AS app3,b.link_id1 AS id3,b.link_id AS link3', - 'where'=>'a.link_app1='.$this->db->quote($app).' AND c.link_app2='.$this->db->quote($target_app). - (!$target_id ? '' : $this->db->expression($this->link_table,' AND c.',array('link_id2' => $target_id))), + 'where'=>'a.link_app1='.self::$db->quote($app).' AND c.link_app2='.self::$db->quote($target_app). + (!$target_id ? '' : self::$db->expression(self::TABLE,' AND c.',array('link_id2' => $target_id))), 'join'=>" a - JOIN $this->link_table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1 - JOIN $this->link_table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2", - 'table_def'=>$table_def + JOIN $table b ON a.link_id2=b.link_id1 AND a.link_app2=b.link_app1 + JOIN $table c ON a.link_id1=c.link_id1 AND a.link_app1=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app2 AND c.link_id2=b.link_id2", ), // retrieve the type of links, where the relation is realized as timesheet->infolog/tracker and projectmanager->timesheet - array('table'=>$this->link_table, + array('table'=>self::TABLE, 'cols'=>'b.link_id, b.link_app2 as app1, b.link_id2 as id1, b.link_app1 as app2, b.link_id1 as id2, b.link_remark,b.link_lastmod,b.link_owner,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3', - 'where'=>'a.link_app1='.$this->db->quote($app).' AND b.link_app1='.$this->db->quote($target_app). - (!$target_id ? '' : $this->db->expression($this->link_table,' AND b.',array('link_id1' => $target_id))), + 'where'=>'a.link_app1='.self::$db->quote($app).' AND b.link_app1='.self::$db->quote($target_app). + (!$target_id ? '' : self::$db->expression(self::TABLE,' AND b.',array('link_id1' => $target_id))), 'join'=>" a - JOIN $this->link_table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2 - JOIN egw_links c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1", - 'table_def'=>$table_def), + JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2 + JOIN $table c ON a.link_id2=c.link_id1 AND a.link_app2=c.link_app1 AND a.link_id!=c.link_id AND c.link_app2=b.link_app1 AND c.link_id2=b.link_id1", + ), // retrieve the type of links, where the relation is realized as timesheet->projectmanager and infolog->timesheet - array('table'=>$this->link_table, + array('table'=>self::TABLE, 'cols'=>'a.*,c.link_app1 AS app3,c.link_id1 AS id3,c.link_id AS link3', - 'where'=>'a.link_app1='.$this->db->quote($app).' AND a.link_app2='.$this->db->quote($target_app). - (!$target_id ? '' : $this->db->expression($this->link_table,' AND a.',array('link_id2' => $target_id))), + 'where'=>'a.link_app1='.self::$db->quote($app).' AND a.link_app2='.self::$db->quote($target_app). + (!$target_id ? '' : self::$db->expression(self::TABLE,' AND a.',array('link_id2' => $target_id))), 'join'=>" a - JOIN $this->link_table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2 - JOIN egw_links c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1", - 'table_def'=>$table_def), + JOIN $table b ON a.link_id1=b.link_id2 AND a.link_app1=b.link_app2 + JOIN $table c ON a.link_id2=c.link_id2 AND a.link_app2=c.link_app2 AND a.link_id!=c.link_id AND c.link_app1=b.link_app1 AND c.link_id1=b.link_id1", + ), ); - $this->db->union($arrayofselects,__LINE__,__FILE__); - while (($row = $this->db->row(true,'link_'))) - { - $links[] = $row; - } + $links = array(); + foreach(self::$db->union($arrayofselects,__LINE__,__FILE__) as $row) + { + $links[] = egw_db::strip_array_keys($row,'link_'); + } return $links; } + + /** + * constructor + */ + static function init_static( ) + { + self::$db = $GLOBALS['egw']->db; + self::$user =& $GLOBALS['egw_info']['user']['account_id']; + } } +solink::init_static();