2002-10-09 02:34:45 +02:00
|
|
|
<?php
|
|
|
|
/**************************************************************************\
|
2004-01-27 17:58:19 +01:00
|
|
|
* eGroupWare - eTemplate Extension - InfoLog LinkTo Widget *
|
|
|
|
* http://www.egroupware.org *
|
2002-10-09 02:34:45 +02:00
|
|
|
* Written by Ralf Becker <RalfBecker@outdoor-training.de> *
|
|
|
|
* -------------------------------------------- *
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
* option) any later version. *
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*!
|
|
|
|
@class link_widget
|
|
|
|
@author ralfbecker
|
2003-06-29 19:00:05 +02:00
|
|
|
@abstract link-to: Widget to create links to an other entries of link-aware apps
|
|
|
|
@abstract link-list: Widget to shows the links to an entry and a Unlink Button for each link
|
|
|
|
@abstract link-string: comma-separated list of link-titles with a link to its view method, value is like get_links()
|
2002-10-09 02:34:45 +02:00
|
|
|
@discussion This widget is independent of the UI as it only uses etemplate-widgets and has therefor no
|
2003-06-29 19:00:05 +02:00
|
|
|
render-function.
|
2002-10-09 02:34:45 +02:00
|
|
|
*/
|
|
|
|
class link_widget
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'pre_process' => True,
|
|
|
|
'post_process' => True
|
|
|
|
);
|
|
|
|
var $human_name = array( // this are the names for the editor
|
2003-06-29 19:00:05 +02:00
|
|
|
'link-to' => 'LinkTo',
|
|
|
|
'link-list' => 'LinkList',
|
|
|
|
'link-string' => 'LinkString'
|
2002-10-09 02:34:45 +02:00
|
|
|
);
|
2003-02-22 13:29:04 +01:00
|
|
|
var $debug = False;
|
2002-10-09 02:34:45 +02:00
|
|
|
|
|
|
|
function link_widget($ui)
|
|
|
|
{
|
|
|
|
$this->link = CreateObject('infolog.bolink');
|
|
|
|
}
|
|
|
|
|
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
|
|
|
{
|
2004-02-05 14:27:20 +01:00
|
|
|
if ($cell['type'] == 'link-to' && ($cell['readonly'] || $readonlys))
|
|
|
|
{
|
|
|
|
// readonly ==> omit the whole widget
|
|
|
|
$cell = $tmpl->empty_cell();
|
|
|
|
return;
|
|
|
|
}
|
2003-06-29 19:00:05 +02:00
|
|
|
if ($cell['type'] == 'link-string')
|
|
|
|
{
|
|
|
|
$str = '';
|
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
foreach ($value as $link)
|
|
|
|
{
|
|
|
|
$str .= ($str !== '' ? ', ' : '') . $tmpl->html->a_href(
|
|
|
|
htmlentities($this->link->title($link['app'],$link['id'])),
|
|
|
|
$this->link->view($link['app'],$link['id'],$link));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$cell['type'] = 'html';
|
|
|
|
$cell['readonly'] = True; // is allways readonly
|
|
|
|
$value = $str;
|
|
|
|
|
|
|
|
return True;
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
if (!is_array($value))
|
|
|
|
{
|
|
|
|
$value = array(
|
|
|
|
'to_id' => $value,
|
|
|
|
'to_app' => $GLOBALS['phpgw_info']['flags']['currentapp']
|
|
|
|
);
|
|
|
|
}
|
2003-02-22 13:29:04 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>start: $cell[type][$name]::pre_process: value ="; _debug_array($value);
|
|
|
|
echo "extension_data[$cell[type]][$name] ="; _debug_array($extension_data);
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
switch ($type = $cell['type'])
|
|
|
|
{
|
|
|
|
case 'link-to':
|
2002-10-20 17:06:52 +02:00
|
|
|
if ($value['button'] == 'upload' && !empty($value['file']) && $value['file']['tmp_name'] != 'none')
|
|
|
|
{
|
|
|
|
$value = $extension_data;
|
|
|
|
$value['remark'] = '';
|
|
|
|
|
|
|
|
$tpl = new etemplate('etemplate.link_widget.attach');
|
|
|
|
}
|
|
|
|
elseif ($value['button'] == 'search' && count($ids = $this->link->query($value['app'],$value['query'])))
|
2002-10-09 02:34:45 +02:00
|
|
|
{
|
|
|
|
$extension_data['app'] = $value['app'];
|
2002-10-20 17:06:52 +02:00
|
|
|
|
2002-10-09 02:34:45 +02:00
|
|
|
$value = $extension_data;
|
|
|
|
$value['options-id'] = $ids;
|
|
|
|
$value['remark'] = '';
|
2002-10-20 17:06:52 +02:00
|
|
|
|
2002-10-09 02:34:45 +02:00
|
|
|
$tpl = new etemplate('etemplate.link_widget.create');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!$value['button'])
|
|
|
|
{
|
|
|
|
$extension_data = $value;
|
|
|
|
}
|
|
|
|
$value = array_merge($extension_data,$value);
|
|
|
|
$value['options-app'] = $this->link->app_list();
|
|
|
|
|
|
|
|
$tpl = new etemplate('etemplate.link_widget.search');
|
|
|
|
$tpl->set_cell_attribute('msg','disabled',$value['button'] != 'search');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'link-list':
|
|
|
|
$app = $value['to_app'];
|
2003-02-22 13:29:04 +01:00
|
|
|
$id = isset($extension_data['to_id']) ? $extension_data['to_id'] : $value['to_id'];
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>link-list-widget[$name].preprocess: value="; _debug_array($value);
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
if (!isset($value['title']))
|
|
|
|
{
|
|
|
|
$value['title'] = $this->link->title($app,$id);
|
|
|
|
}
|
2002-10-18 00:10:12 +02:00
|
|
|
$links = $this->link->get_links($app,$id);
|
|
|
|
$value['anz_links'] = count($links);
|
2002-10-09 02:34:45 +02:00
|
|
|
$extension_data = $value;
|
|
|
|
|
2002-10-09 13:50:46 +02:00
|
|
|
if (!count($links))
|
2002-10-09 02:34:45 +02:00
|
|
|
{
|
|
|
|
$cell = $tmpl->empty_cell();
|
2002-10-09 13:50:46 +02:00
|
|
|
$value = '';
|
|
|
|
return True;
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
$tpl = new etemplate('etemplate.link_widget.list');
|
|
|
|
$tpl->data[0]['A'] = $tmpl->data[0]['A']; // set width of first col like the tmpl. calling us
|
|
|
|
for($row=$tpl->rows-1; list(,$link) = each($links); ++$row)
|
|
|
|
{
|
|
|
|
$value[$row] = $link;
|
2002-10-20 17:06:52 +02:00
|
|
|
$value[$row]['title'] = $this->link->title($link['app'],$link['id'],$link);
|
2003-10-04 18:58:09 +02:00
|
|
|
if (!is_array($link['id']))
|
|
|
|
{
|
|
|
|
$value[$row]['view'] = $this->link->view($link['app'],$link['id'],$link);
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$cell['size'] = $cell['name'];
|
|
|
|
$cell['type'] = 'template';
|
|
|
|
$cell['name'] = $tpl->name;
|
|
|
|
$cell['obj'] = &$tpl;
|
|
|
|
|
2003-02-22 13:29:04 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>end: $type"."[$name]::pre_process: value ="; _debug_array($value);
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
return True; // extra Label is ok
|
|
|
|
}
|
|
|
|
|
|
|
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
|
|
|
{
|
2002-10-20 17:06:52 +02:00
|
|
|
$buttons = array('search','create','new','upload','attach');
|
2003-02-22 13:29:04 +01:00
|
|
|
while (!$button && list(,$bname) = each($buttons))
|
2002-10-09 02:34:45 +02:00
|
|
|
{
|
2003-02-22 13:29:04 +01:00
|
|
|
$button = $value[$bname] ? $bname : '';
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
2002-10-20 17:06:52 +02:00
|
|
|
if (is_array($value['unlink']))
|
2002-10-09 02:34:45 +02:00
|
|
|
{
|
|
|
|
$button = 'unlink';
|
|
|
|
list($unlink) = @each($value['unlink']);
|
|
|
|
}
|
|
|
|
unset($value[$button]);
|
|
|
|
|
|
|
|
$value = array_merge($extension_data,$value);
|
2003-02-22 13:29:04 +01:00
|
|
|
|
2002-10-20 17:06:52 +02:00
|
|
|
if ($button && $this->debug)
|
|
|
|
{
|
2003-02-22 13:29:04 +01:00
|
|
|
echo "<p>start: link_widget[$name]::post_process: button='$button', unlink='$unlink', value ="; _debug_array($value);
|
2002-10-20 17:06:52 +02:00
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
switch ($button)
|
|
|
|
{
|
|
|
|
case 'create':
|
|
|
|
if ($value['to_app']) // make the link
|
|
|
|
{
|
2002-10-20 17:06:52 +02:00
|
|
|
$link_id = $this->link->link($value['to_app'],$value['to_id'],
|
|
|
|
$value['app'],$value['id'],$value['remark']);
|
2003-02-22 13:29:04 +01:00
|
|
|
|
2002-10-18 00:10:12 +02:00
|
|
|
if (isset($value['primary']) && !$value['anz_links'] )
|
|
|
|
{
|
2002-10-18 22:20:35 +02:00
|
|
|
$value['primary'] = $link_id;
|
2002-10-18 00:10:12 +02:00
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
|
|
|
// fall-trough
|
|
|
|
case 'search':
|
|
|
|
case 'new':
|
|
|
|
$extension_data = $value;
|
|
|
|
$loop = True;
|
|
|
|
break;
|
|
|
|
|
2002-10-20 17:06:52 +02:00
|
|
|
case 'attach':
|
|
|
|
if (is_array($value['file']) && $value['to_app'])
|
|
|
|
{
|
|
|
|
$link_id = $this->link->link($value['to_app'],$value['to_id'],
|
2003-02-22 13:29:04 +01:00
|
|
|
$this->link->vfs_appname,$value['file'],$value['remark']);
|
2003-10-04 18:58:09 +02:00
|
|
|
if (!is_array($value['to_id']))
|
|
|
|
{
|
|
|
|
unlink($value['file']['tmp_name']);
|
|
|
|
}
|
2003-02-22 13:29:04 +01:00
|
|
|
unset($value['file']);
|
2002-10-20 17:06:52 +02:00
|
|
|
}
|
|
|
|
$extension_data = $value;
|
|
|
|
$loop = True;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'upload': // need to rename file, as php deletes it otherwise
|
2003-02-22 13:29:04 +01:00
|
|
|
if (is_array($value['file']) && !empty($value['file']['tmp_name']) &&
|
2002-10-20 17:06:52 +02:00
|
|
|
$value['file']['tmp_name'] != 'none')
|
|
|
|
{
|
|
|
|
move_uploaded_file($value['file']['tmp_name'],$value['file']['tmp_name'].'+');
|
|
|
|
$value['file']['tmp_name'] .= '+';
|
|
|
|
$extension_data = $value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($value['file']);
|
|
|
|
$button = '';
|
|
|
|
}
|
|
|
|
$loop = True;
|
|
|
|
break;
|
|
|
|
|
2002-10-09 02:34:45 +02:00
|
|
|
case 'unlink':
|
2003-02-22 13:29:04 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>unlink(link-id=$unlink,$value[to_app],$value[to_id])</p>\n";
|
|
|
|
if (is_array($value['to_id'])) _debug_array($value['to_id']);
|
|
|
|
}
|
2004-03-09 22:46:25 +01:00
|
|
|
$this->link->unlink2($unlink,$value['to_app'],$value['to_id']);
|
2003-02-22 13:29:04 +01:00
|
|
|
if (is_array($value['to_id']))
|
|
|
|
{
|
|
|
|
$extension_data['to_id'] = $value['to_id']; // else changes from unlink get lost
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
$loop = True;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$value['button'] = $button;
|
2003-02-22 13:29:04 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>end: link_widget[$name]::post_process: value ="; _debug_array($value);
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|