2002-10-09 02:34:45 +02:00
|
|
|
<?php
|
2006-04-20 19:12:30 +02:00
|
|
|
/**
|
|
|
|
* eGroupWare eTemplate Extension - Link Widgets / UI for the link class
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2002-10-09 02:34:45 +02:00
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* eTemplate Extension: several widgets as user-interface for the link-class
|
|
|
|
*
|
2005-11-10 15:51:12 +01:00
|
|
|
* All widgets use the link-registry, to "know" which apps use popups (and what size).
|
2007-08-06 15:52:17 +02:00
|
|
|
* Participating apps need to register a proper "search_link" hook - see eTemplate-reference (LinkWidgets) for info.
|
2005-11-10 15:51:12 +01:00
|
|
|
* If run in a popup and the app uses no popups, a target will be set, to open a new full decorated window.
|
|
|
|
*
|
|
|
|
* The class contains the following widgets:
|
|
|
|
* - link: Show a link to one linked entry specified by an array with keys app, id and optional title and help-message
|
2007-10-31 09:16:34 +01:00
|
|
|
* Optionally the application can be specified as option and the value can be just the id.
|
2005-11-10 15:51:12 +01:00
|
|
|
* - link-to: Widget to create links to an other entries of link-aware apps
|
2007-08-06 15:52:17 +02:00
|
|
|
* If the variables $data['widget_id']['to_app'] = $app and $data['widget_id']['to_id'] = $entry_id
|
|
|
|
* are set, this widget creates the links without further interaction with the calling code.
|
2005-04-15 00:14:01 +02:00
|
|
|
* If the entry does not yet exist, the widget returns an array with the new links in the id. After the
|
2007-08-06 15:52:17 +02:00
|
|
|
* entry was successfuly created, bolink::link($app,$new_id,$arr) has to be called to create the links!
|
|
|
|
* - link-list: Widget to show the links to an entry in a table with an unlink icon for each link. Needs the same
|
|
|
|
* pair of variables as link-to widget and needs to have the same id, as the data is shared with link-to.
|
2005-11-10 15:51:12 +01:00
|
|
|
* - link-string: comma-separated list of link-titles with a link to its view method, value is like get_links()
|
|
|
|
* or array with keys to_app and to_id (widget calls then get_links itself)
|
|
|
|
* - link-add: Add a new entry of the select app, which is already linked to a given entry
|
2006-09-29 21:55:00 +02:00
|
|
|
* - link-entry: Allow to select an entry of a selectable or in options specified app
|
2007-08-06 15:52:17 +02:00
|
|
|
* - link-apps: Select an app registered in the link system, options: '' or 'add'
|
2005-02-22 23:11:00 +01:00
|
|
|
*
|
2005-11-10 15:51:12 +01:00
|
|
|
*<code>
|
2005-04-15 00:14:01 +02:00
|
|
|
* $content[$name] = array(
|
|
|
|
* 'to_app' => // I string appname of the entry to link to
|
|
|
|
* 'to_id' => // IO int id of the entry to link to, for new entries 0, returns the array with new links
|
|
|
|
* // the following params apply only for the link-to widget!
|
|
|
|
* 'no_files' => // I boolean suppress attach-files, default no
|
|
|
|
* 'search_label' => // I string label to use instead of search
|
|
|
|
* 'link_label' => // I string label for the link button, default 'Link'
|
2005-12-06 08:11:14 +01:00
|
|
|
* // optional only for the link-add widget
|
|
|
|
* 'extra' => // I array with extra parameters, eg. array('cat_id' => 15)
|
2007-03-09 12:21:56 +01:00
|
|
|
* // optional for link-string:
|
|
|
|
* 'only_app' => // I string with appname, eg. 'projectmananager' to list only linked projects
|
2005-04-15 00:14:01 +02:00
|
|
|
* );
|
2005-11-10 15:51:12 +01:00
|
|
|
*</code>
|
|
|
|
*
|
2007-08-06 15:52:17 +02:00
|
|
|
* This widget is independent of the UI as it only uses etemplate-widgets and has therefore no render-function.
|
2005-02-22 23:11:00 +01:00
|
|
|
*
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage extensions
|
2005-11-10 15:51:12 +01:00
|
|
|
* @author Ralf Becker <RalfBecker@outdoor-training.de>
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2005-02-22 23:11:00 +01:00
|
|
|
*/
|
2002-10-09 02:34:45 +02:00
|
|
|
class link_widget
|
|
|
|
{
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
2005-11-10 15:51:12 +01:00
|
|
|
* @var array exported methods of this class
|
2005-02-22 23:11:00 +01:00
|
|
|
*/
|
2002-10-09 02:34:45 +02:00
|
|
|
var $public_functions = array(
|
2006-09-29 21:55:00 +02:00
|
|
|
'pre_process' => True,
|
|
|
|
'post_process' => True,
|
|
|
|
'ajax_search' => True,
|
2002-10-09 02:34:45 +02:00
|
|
|
);
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
2005-11-10 15:51:12 +01:00
|
|
|
* @var array availible extensions and there names for the editor
|
2005-02-22 23:11:00 +01:00
|
|
|
*/
|
2005-11-10 15:51:12 +01:00
|
|
|
var $human_name = array(
|
|
|
|
'link' => 'Link',
|
2003-06-29 19:00:05 +02:00
|
|
|
'link-to' => 'LinkTo',
|
|
|
|
'link-list' => 'LinkList',
|
2005-11-10 15:51:12 +01:00
|
|
|
'link-string' => 'LinkString',
|
2006-10-05 08:36:47 +02:00
|
|
|
'link-add' => 'LinkEntry',
|
|
|
|
'link-entry' => 'Select entry',
|
2006-09-29 21:55:00 +02:00
|
|
|
'link-apps' => 'LinkApps',
|
2002-10-09 02:34:45 +02:00
|
|
|
);
|
2005-11-10 15:51:12 +01:00
|
|
|
/**
|
|
|
|
* @var boolean $debug switches debug-messages on and off
|
|
|
|
*/
|
2003-02-22 13:29:04 +01:00
|
|
|
var $debug = False;
|
2005-11-10 15:51:12 +01:00
|
|
|
/**
|
2006-09-29 21:55:00 +02:00
|
|
|
* reference to the link class
|
|
|
|
*
|
|
|
|
* @var bolink
|
2005-11-10 15:51:12 +01:00
|
|
|
*/
|
|
|
|
var $link;
|
2002-10-09 02:34:45 +02:00
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* Constructor of the extension
|
|
|
|
*
|
|
|
|
* @param string $ui '' for html
|
|
|
|
*/
|
2006-09-29 21:55:00 +02:00
|
|
|
function link_widget($ui='')
|
2002-10-09 02:34:45 +02:00
|
|
|
{
|
2005-04-15 00:14:01 +02:00
|
|
|
if (!is_object($GLOBALS['egw']->link))
|
|
|
|
{
|
2006-09-20 06:48:59 +02:00
|
|
|
$GLOBALS['egw']->link =& CreateObject('phpgwapi.bolink');
|
2005-04-15 00:14:01 +02:00
|
|
|
}
|
|
|
|
$this->link =& $GLOBALS['egw']->link;
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* pre-processing of the extension
|
|
|
|
*
|
|
|
|
* This function is called before the extension gets rendered
|
|
|
|
*
|
|
|
|
* @param string $name form-name of the control
|
|
|
|
* @param mixed &$value value / existing content, can be modified
|
|
|
|
* @param array &$cell array with the widget, can be modified for ui-independent widgets
|
|
|
|
* @param array &$readonlys names of widgets as key, to be made readonly
|
|
|
|
* @param mixed &$extension_data data the extension can store persisten between pre- and post-process
|
|
|
|
* @param object &$tmpl reference to the template we belong too
|
|
|
|
* @return boolean true if extra label is allowed, false otherwise
|
|
|
|
*/
|
2002-10-09 02:34:45 +02:00
|
|
|
function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
|
|
|
|
{
|
2006-09-29 21:55:00 +02:00
|
|
|
$extension_data['type'] = $type = $cell['type'];
|
2007-05-14 16:51:32 +02:00
|
|
|
$extension_data['needed'] = $cell['needed'];
|
2005-11-12 14:22:05 +01:00
|
|
|
$help = $cell['help'] ? ($value['help'] ? $value['help'] : $cell['help']) : lang('view this linked entry in its application');
|
2005-11-10 15:51:12 +01:00
|
|
|
|
|
|
|
if (($type == 'link-to' || $type == 'link-add') && ($cell['readonly'] || $readonlys))
|
2004-02-05 14:27:20 +01:00
|
|
|
{
|
2005-06-16 23:32:07 +02:00
|
|
|
//echo "<p>link-to is readonly, cell=".print_r($cell,true).", readonlys=".print_r($readonlys)."</p>\n";
|
2004-02-05 14:27:20 +01:00
|
|
|
// readonly ==> omit the whole widget
|
|
|
|
$cell = $tmpl->empty_cell();
|
|
|
|
return;
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
if (!is_array($value) && in_array($type,array('link-to','link-list','link-add')))
|
2005-11-10 15:51:12 +01:00
|
|
|
{
|
|
|
|
$value = array(
|
|
|
|
'to_id' => $value,
|
|
|
|
'to_app' => $GLOBALS['egw_info']['flags']['currentapp']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if ($this->debug)
|
|
|
|
{
|
|
|
|
echo "<p>link_widget::pre_process($name,$value,".print_r($cell,true).",$readonlys,,)</p>\n";
|
|
|
|
echo "<p>start: $cell[type][$name]::pre_process: value ="; _debug_array($value);
|
|
|
|
echo "extension_data[$cell[type]][$name] ="; _debug_array($extension_data);
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
switch ($cell['type'])
|
2003-06-29 19:00:05 +02:00
|
|
|
{
|
2005-11-10 15:51:12 +01:00
|
|
|
case 'link':
|
2005-11-12 14:22:05 +01:00
|
|
|
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
|
|
|
$cell['no_lang'] = 1;
|
|
|
|
$link = $target = $popup = '';
|
2007-10-31 09:16:34 +01:00
|
|
|
if (!is_array($value) && $value && isset($GLOBALS['egw_info']['apps'][$cell['size']]))
|
|
|
|
{
|
|
|
|
$value = array(
|
|
|
|
'id' => $value,
|
|
|
|
'app' => $cell['size'],
|
|
|
|
);
|
|
|
|
$cell['size'] = '';
|
|
|
|
}
|
2005-11-12 14:22:05 +01:00
|
|
|
if ($value['app'] && $value['id'])
|
2005-11-10 15:51:12 +01:00
|
|
|
{
|
2005-11-12 14:22:05 +01:00
|
|
|
$view = $this->link->view($value['app'],$value['id']);
|
|
|
|
$link = $view['menuaction']; unset($view['menuaction']);
|
|
|
|
foreach($view as $var => $val)
|
|
|
|
{
|
|
|
|
$link .= '&'.$var.'='.$val;
|
|
|
|
}
|
|
|
|
if (!($popup = $this->link->is_popup($value['app'],'view')) &&
|
|
|
|
$GLOBALS['egw_info']['etemplate']['output_mode'] == 2) // we are in a popup
|
|
|
|
{
|
|
|
|
$target = '_blank';
|
|
|
|
}
|
|
|
|
if (!$cell['help'])
|
|
|
|
{
|
2006-09-27 15:41:51 +02:00
|
|
|
$cell['help'] = $value['help'];
|
2005-11-12 14:22:05 +01:00
|
|
|
$cell['no_lang'] = 2;
|
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
}
|
2005-11-12 14:22:05 +01:00
|
|
|
elseif (!$value['title'])
|
2005-11-10 15:51:12 +01:00
|
|
|
{
|
2005-11-12 14:22:05 +01:00
|
|
|
$cell = $tmpl->empty_cell();
|
|
|
|
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
|
|
|
return;
|
2005-11-10 15:51:12 +01:00
|
|
|
}
|
|
|
|
$cell['type'] = 'label';
|
2007-09-14 12:07:18 +02:00
|
|
|
// size: [b[old]][i[talic]],[link],[activate_links],[label_for],[link_target],[link_popup_size],[link_title]
|
2005-11-12 14:22:05 +01:00
|
|
|
list($cell['size']) = explode(',',$cell['size']);
|
2007-09-14 12:07:18 +02:00
|
|
|
$cell['size'] .= ','.$link.',,,'.$target.','.$popup.','.$value['extra_title'];
|
2005-11-10 15:51:12 +01:00
|
|
|
$value = $value['title'] ? $value['title'] : $this->link->title($value['app'],$value['id']);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case 'link-string':
|
2003-06-29 19:00:05 +02:00
|
|
|
$str = '';
|
2007-03-09 12:21:56 +01:00
|
|
|
if ($value && !is_array($value) && $cell['size'])
|
2005-11-10 15:51:12 +01:00
|
|
|
{
|
2007-03-09 12:21:56 +01:00
|
|
|
$value = array('to_id' => $value);
|
|
|
|
list($value['to_app'],$value['only_app']) = explode(',',$cell['size']);
|
|
|
|
}
|
|
|
|
if ($value['to_id'] && $value['to_app'])
|
|
|
|
{
|
|
|
|
$value = $this->link->get_links($value['to_app'],$value['to_id'],$only_app = $value['only_app']);
|
|
|
|
if ($only_app)
|
|
|
|
{
|
|
|
|
foreach($value as $key => $id)
|
|
|
|
{
|
|
|
|
$value[$key] = array(
|
|
|
|
'id' => $id,
|
|
|
|
'app' => $only_app,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
}
|
2003-06-29 19:00:05 +02:00
|
|
|
if (is_array($value))
|
|
|
|
{
|
|
|
|
foreach ($value as $link)
|
|
|
|
{
|
2005-11-12 14:22:05 +01:00
|
|
|
$options .= " onMouseOver=\"self.status='".addslashes($tmpl->html->htmlspecialchars($help))."'; return true;\"";
|
|
|
|
$options .= " onMouseOut=\"self.status=''; return true;\"";
|
2005-07-30 14:49:11 +02:00
|
|
|
if (($popup = $this->link->is_popup($link['app'],'view')))
|
|
|
|
{
|
|
|
|
list($w,$h) = explode('x',$popup);
|
|
|
|
$options = ' onclick="window.open(this,this.target,\'width='.(int)$w.',height='.(int)$h.',location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes\'); return false;"';
|
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
elseif ($GLOBALS['egw_info']['etemplate']['output_mode'] == 2) // we are in a popup
|
|
|
|
{
|
|
|
|
$options = ' target="_blank"';
|
|
|
|
}
|
2003-06-29 19:00:05 +02:00
|
|
|
$str .= ($str !== '' ? ', ' : '') . $tmpl->html->a_href(
|
2004-04-12 14:28:35 +02:00
|
|
|
$tmpl->html->htmlspecialchars($this->link->title($link['app'],$link['id'])),
|
2005-07-30 14:49:11 +02:00
|
|
|
'/index.php',$this->link->view($link['app'],$link['id'],$link),$options);
|
2003-06-29 19:00:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$cell['type'] = 'html';
|
2005-11-12 14:22:05 +01:00
|
|
|
$cell['readonly'] = True; // set it readonly to NOT call our post_process function
|
2003-06-29 19:00:05 +02:00
|
|
|
$value = $str;
|
|
|
|
return True;
|
2002-10-20 17:06:52 +02:00
|
|
|
|
2005-11-10 15:51:12 +01:00
|
|
|
case 'link-add':
|
2006-12-12 15:38:52 +01:00
|
|
|
$apps = $this->link->app_list($type == 'link-add' ? 'add_app' : 'query');
|
2006-12-11 08:53:16 +01:00
|
|
|
if (!$apps || !$value['to_id'] || is_array($value['to_id'])) // cant do an add without apps or already created entry
|
2005-11-10 15:51:12 +01:00
|
|
|
{
|
|
|
|
$cell = $tmpl->empty_cell();
|
|
|
|
return;
|
2002-10-20 17:06:52 +02:00
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
asort($apps); // sort them alphabetic
|
2006-12-11 08:53:16 +01:00
|
|
|
$value['options-add_app'] = array();
|
2005-11-10 15:51:12 +01:00
|
|
|
foreach($apps as $app => $label)
|
|
|
|
{
|
2005-12-06 08:11:14 +01:00
|
|
|
$link = $GLOBALS['egw']->link('/index.php',$this->link->add($app,$value['to_app'],$value['to_id'])+
|
|
|
|
(is_array($value['extra']) ? $value['extra'] : array()));
|
2005-11-10 15:51:12 +01:00
|
|
|
if (($popup = $this->link->is_popup($app,'add')))
|
|
|
|
{
|
|
|
|
list($w,$h) = explode('x',$popup);
|
|
|
|
$action = "window.open('$link','_blank','width=$w,height=$h,location=no,menubar=no,toolbar=no,scrollbars=yes,status=yes');";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$action = "location.href = '$link';";
|
|
|
|
}
|
2006-12-11 08:53:16 +01:00
|
|
|
$value['options-add_app'][$action] = $label;
|
|
|
|
// modify add_app default to the action used as value
|
|
|
|
if (isset($value['add_app']) && $app == $value['add_app']) $value['add_app'] = $action;
|
2005-11-10 15:51:12 +01:00
|
|
|
}
|
|
|
|
$tpl =& new etemplate('etemplate.link_widget.add');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'link-to':
|
2006-09-29 21:55:00 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
|
|
|
|
if ($value['search_label'] && $extension_data['search_label'] != $value['search_label']) $value['search_label'] = lang($value['search_label']);
|
|
|
|
$extension_data = $value;
|
|
|
|
$tpl =& new etemplate('etemplate.link_widget.to');
|
|
|
|
if ($value['link_label']) $tpl->set_cell_attribute('create','label',$value['link_label']);
|
|
|
|
if ($value['search_label']) $tpl->set_cell_attribute('search','label',$value['search_label']);
|
|
|
|
/* old request code
|
2005-11-10 15:51:12 +01:00
|
|
|
$value['msg'] = '';
|
|
|
|
if ($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
|
|
|
|
2005-02-16 00:22:10 +01:00
|
|
|
$tpl =& new etemplate('etemplate.link_widget.create');
|
2005-04-15 00:14:01 +02:00
|
|
|
if ($value['link_label'])
|
|
|
|
{
|
|
|
|
$tpl->set_cell_attribute('create','label',$value['link_label']);
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-10 15:51:12 +01:00
|
|
|
// error from search or upload
|
|
|
|
$value['msg'] = $value['button'] == 'search' ? lang('Nothing found - try again !!!') : $extension_data['msg'];
|
|
|
|
|
2002-10-09 02:34:45 +02:00
|
|
|
if (!$value['button'])
|
|
|
|
{
|
|
|
|
$extension_data = $value;
|
|
|
|
}
|
|
|
|
$value = array_merge($extension_data,$value);
|
2006-12-12 15:38:52 +01:00
|
|
|
$value['options-app'] = $this->link->app_list('query');
|
2005-11-02 21:02:27 +01:00
|
|
|
asort($value['options-app']); // sort them alphabetic
|
2002-10-09 02:34:45 +02:00
|
|
|
|
2005-02-16 00:22:10 +01:00
|
|
|
$tpl =& new etemplate('etemplate.link_widget.search');
|
2005-04-15 00:14:01 +02:00
|
|
|
if ($value['search_label'])
|
|
|
|
{
|
|
|
|
$tpl->set_cell_attribute('app','label',$value['search_label']);
|
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
$tpl->set_cell_attribute('comment','onchange',"set_style_by_class('*','hide_comment','display',this.checked ? 'block' : 'none');");
|
|
|
|
unset($value['comment']);
|
2006-09-29 21:55:00 +02:00
|
|
|
}*/
|
2002-10-09 02:34:45 +02:00
|
|
|
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;
|
|
|
|
}
|
2005-02-16 00:22:10 +01:00
|
|
|
$tpl =& new etemplate('etemplate.link_widget.list');
|
2002-10-09 02:34:45 +02:00
|
|
|
$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);
|
2007-10-15 19:27:25 +02:00
|
|
|
$value[$row]['mime_icon'] = '';
|
2003-10-04 18:58:09 +02:00
|
|
|
if (!is_array($link['id']))
|
|
|
|
{
|
|
|
|
$value[$row]['view'] = $this->link->view($link['app'],$link['id'],$link);
|
2005-11-10 15:51:12 +01:00
|
|
|
if (!($value[$row]['popup'] = $this->link->is_popup($link['app'],'view')) &&
|
|
|
|
$GLOBALS['egw_info']['etemplate']['output_mode'] == 2) // we are in a popup
|
|
|
|
{
|
|
|
|
$value[$row]['target'] = '_blank'; // we create a new window as the linked page is no popup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($link['app'] == $this->link->vfs_appname)
|
|
|
|
{
|
|
|
|
$value[$row]['label'] = 'Delete';
|
|
|
|
$value[$row]['help'] = lang('Delete this file');
|
2007-10-15 19:27:25 +02:00
|
|
|
|
|
|
|
// Get mimetype and thumbnail
|
|
|
|
if(in_array($GLOBALS['egw_info']['user']['preferences']['common']['link_list_format'], array('icons', 'icons_and_text') )) {
|
|
|
|
$value[$row]['mime_icon'] = ExecMethod2('filemanager.uifilemanager.mime_icon', $value[$row]['type']);
|
|
|
|
}
|
|
|
|
if($GLOBALS['egw_info']['user']['preferences']['common']['link_list_thumbnail'] && $GLOBALS['egw_info']['server']['link_list_thumbnail'] > 0) {
|
|
|
|
list($image) = explode('/', $value[$row]['type']);
|
|
|
|
if($image == 'image') {
|
|
|
|
$value[$row]['thumbnail'] = '<img src="' .
|
|
|
|
$GLOBALS['egw_info']['server']['webserver_url'].
|
|
|
|
'/etemplate/inc/thumbnail.inc.php?image=' .
|
|
|
|
$this->link->vfs_path(
|
|
|
|
$value[$row]['view']['app'], $value[$row]['view']['id'], $value[$row]['view']['filename']
|
|
|
|
) . '" />';
|
|
|
|
}
|
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-10-15 19:27:25 +02:00
|
|
|
if(in_array($GLOBALS['egw_info']['user']['preferences']['common']['link_list_format'], array('icons', 'icons_and_text') )) {
|
|
|
|
// Hardcoded sizes to match the mimetype icons. Uses the navbar image and CSS to resize.
|
|
|
|
$value[$row]['mime_icon'] = $tmpl->html->image($value[$row]['app'], 'navbar', $value[$row]['app'], 'style="width: 16px; height: 16px;"');
|
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
$value[$row]['label'] = 'Unlink';
|
|
|
|
$value[$row]['help'] = lang('Remove this link (not the entry itself)');
|
2003-10-04 18:58:09 +02:00
|
|
|
}
|
2007-10-15 19:27:25 +02:00
|
|
|
// Remove appname if they only want icons
|
|
|
|
if($value[$row]['mime_icon'] && $GLOBALS['egw_info']['user']['preferences']['common']['link_list_format'] == 'icons') {
|
|
|
|
$value[$row]['app'] = '';
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
|
|
|
break;
|
2006-09-29 21:55:00 +02:00
|
|
|
|
|
|
|
case 'link-entry':
|
|
|
|
$GLOBALS['egw_info']['flags']['include_xajax'] = true;
|
|
|
|
$tpl =& new etemplate('etemplate.link_widget.entry');
|
2006-11-07 19:04:33 +01:00
|
|
|
$options = $cell['size'] ? explode(',',$cell['size']) : array();
|
|
|
|
$app = $extension_data['app'] = array_shift($options);
|
2006-09-29 21:55:00 +02:00
|
|
|
if ($value) // show pre-selected entry in select-box and not the search
|
|
|
|
{
|
|
|
|
// add selected-entry plus "new search" to the selectbox-options
|
|
|
|
if (($app = $cell['size']))
|
|
|
|
{
|
|
|
|
$id = $value;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
list($app,$id) = explode(':',$value);
|
|
|
|
}
|
2006-10-23 13:22:15 +02:00
|
|
|
$titles = array();
|
|
|
|
foreach(explode(',',$id) as $id)
|
2006-09-29 21:55:00 +02:00
|
|
|
{
|
2006-10-23 13:22:15 +02:00
|
|
|
if ($id && ($title = $this->link->title($app,$id)))
|
|
|
|
{
|
|
|
|
$titles[$id] = $title;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($titles)
|
|
|
|
{
|
|
|
|
$titles[''] = lang('new search').' ...';
|
2006-09-29 21:55:00 +02:00
|
|
|
$selectbox =& $tpl->get_widget_by_name('id');
|
2006-10-23 13:22:15 +02:00
|
|
|
$selectbox['sel_options'] = $titles;
|
2006-09-29 21:55:00 +02:00
|
|
|
// remove link_hide class from select-box-line
|
|
|
|
$span =& $tpl->get_cell_attribute('select_line','span');
|
|
|
|
$span = str_replace('link_hide','',$span);
|
|
|
|
// add link_hide class to search_line
|
|
|
|
$span =& $tpl->get_cell_attribute('search_line','span');
|
|
|
|
$span .= ' link_hide';
|
|
|
|
unset($span);
|
|
|
|
}
|
|
|
|
}
|
2006-11-07 19:04:33 +01:00
|
|
|
if ($extension_data['app']) // no app-selection, using app given in first option
|
2006-09-29 21:55:00 +02:00
|
|
|
{
|
|
|
|
$tpl->disable_cells('app');
|
|
|
|
$onchange =& $tpl->get_cell_attribute('search','onclick');
|
|
|
|
$onchange = str_replace("document.getElementById(form::name('app')).value",'\''.$cell['size'].'\'',$onchange);
|
|
|
|
unset($onchange);
|
|
|
|
}
|
|
|
|
$value = array(
|
2006-10-27 12:48:29 +02:00
|
|
|
'app' => $app,
|
2006-11-07 19:04:33 +01:00
|
|
|
'no_app_sel' => !!$extension_data['app'],
|
2006-09-29 21:55:00 +02:00
|
|
|
'id' => $value,
|
|
|
|
);
|
2006-11-07 19:04:33 +01:00
|
|
|
if ($options) // limit the app-selectbox to the given apps
|
|
|
|
{
|
|
|
|
$tpl->set_cell_attribute('app','type','select');
|
|
|
|
$tpl->set_cell_attribute('app','no_lang',true);
|
2006-12-12 15:38:52 +01:00
|
|
|
$apps = $this->link->app_list('query');
|
2006-11-07 19:04:33 +01:00
|
|
|
asort($apps); // sort them alphabetic
|
|
|
|
foreach($apps as $app => $label)
|
|
|
|
{
|
|
|
|
if (!in_array($app,$options)) unset($apps[$app]);
|
|
|
|
}
|
|
|
|
$value['options-app'] = $apps;
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'link-apps':
|
2006-12-12 15:38:52 +01:00
|
|
|
$apps = $this->link->app_list($cell['size'] ? $cell['size'] : 'query');
|
2006-09-29 21:55:00 +02:00
|
|
|
if (!$apps) // cant do an add without apps or already created entry
|
|
|
|
{
|
|
|
|
$cell = $tmpl->empty_cell();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
asort($apps); // sort them alphabetic
|
|
|
|
$cell['sel_options'] = $apps;
|
|
|
|
$cell['no_lang'] = True; // already translated
|
|
|
|
$cell['type'] = 'select';
|
|
|
|
return true;
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|
|
|
|
$cell['size'] = $cell['name'];
|
|
|
|
$cell['type'] = 'template';
|
|
|
|
$cell['name'] = $tpl->name;
|
2005-04-15 00:14:01 +02:00
|
|
|
$cell['obj'] =& $tpl;
|
2005-02-16 00:22:10 +01:00
|
|
|
// keep the editor away from the generated tmpls
|
|
|
|
$tpl->no_onclick = true;
|
2002-10-09 02:34:45 +02:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2005-02-22 23:11:00 +01:00
|
|
|
/**
|
|
|
|
* postprocessing method, called after the submission of the form
|
|
|
|
*
|
|
|
|
* It has to copy the allowed/valid data from $value_in to $value, otherwise the widget
|
|
|
|
* will return no data (if it has a preprocessing method). The framework insures that
|
|
|
|
* the post-processing of all contained widget has been done before.
|
|
|
|
*
|
|
|
|
* Only used by select-dow so far
|
|
|
|
*
|
|
|
|
* @param string $name form-name of the widget
|
|
|
|
* @param mixed &$value the extension returns here it's input, if there's any
|
|
|
|
* @param mixed &$extension_data persistent storage between calls or pre- and post-process
|
|
|
|
* @param boolean &$loop can be set to true to request a re-submision of the form/dialog
|
|
|
|
* @param object &$tmpl the eTemplate the widget belongs too
|
|
|
|
* @param mixed &value_in the posted values (already striped of magic-quotes)
|
|
|
|
* @return boolean true if $value has valid content, on false no content will be returned!
|
|
|
|
*/
|
2002-10-09 02:34:45 +02:00
|
|
|
function post_process($name,&$value,&$extension_data,&$loop,&$tmpl,$value_in)
|
|
|
|
{
|
2005-06-16 23:32:07 +02:00
|
|
|
//echo "<p>link_widget::post_process('$name',value=".print_r($value,true).",ext=".print_r($extension_data,true).",$loop,,value_in=".print_r($value_in,true)."</p>\n";
|
|
|
|
|
2006-09-29 21:55:00 +02:00
|
|
|
switch($extension_data['type'])
|
|
|
|
{
|
|
|
|
case 'link-entry':
|
2007-05-14 16:51:32 +02:00
|
|
|
if (!$value_in['id'] && $extension_data['needed'])
|
|
|
|
{
|
|
|
|
$tmpl->set_validation_error($name,lang('Field must not be empty !!!'),'');
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
$value = $extension_data['app'] ? $value_in['id'] : $value['app'].':'.$value_in['id'];
|
|
|
|
return !!$value_in['id'];
|
|
|
|
|
|
|
|
case 'link-apps':
|
2007-05-14 16:51:32 +02:00
|
|
|
if (!$value_in && $extension_data['needed'])
|
|
|
|
{
|
|
|
|
$tmpl->set_validation_error($name,lang('Field must not be empty !!!'),'');
|
|
|
|
return true;
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
$value = $value_in;
|
|
|
|
return !!$value;
|
|
|
|
}
|
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]);
|
2005-11-10 15:51:12 +01:00
|
|
|
unset($value['msg']);
|
|
|
|
unset($extension_data['msg']);
|
2002-10-09 02:34:45 +02:00
|
|
|
|
2005-11-10 15:51:12 +01:00
|
|
|
if (is_array($extension_data))
|
|
|
|
{
|
|
|
|
$value = is_array($value) ? array_merge($extension_data,$value) : $extension_data;
|
|
|
|
}
|
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']);
|
2006-09-29 21:55:00 +02:00
|
|
|
$value['remark'] = $value['query'] = '';
|
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':
|
2005-11-10 15:51:12 +01:00
|
|
|
if (is_array($value['file']) && $value['to_app'] &&
|
|
|
|
!empty($value['file']['tmp_name']) && $value['file']['tmp_name'] != 'none')
|
2002-10-20 17:06:52 +02:00
|
|
|
{
|
2005-11-10 15:51:12 +01:00
|
|
|
if (!$value['to_id'] || is_array($value['to_id'])) // otherwise the webserver deletes the file
|
2003-10-04 18:58:09 +02:00
|
|
|
{
|
2005-11-10 15:51:12 +01:00
|
|
|
move_uploaded_file($value['file']['tmp_name'],$value['file']['tmp_name'].'+');
|
|
|
|
$value['file']['tmp_name'] .= '+';
|
2003-10-04 18:58:09 +02:00
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
$link_id = $this->link->link($value['to_app'],$value['to_id'],
|
|
|
|
$this->link->vfs_appname,$value['file'],$value['remark']);
|
2006-01-06 05:50:11 +01:00
|
|
|
$value['remark'] = '';
|
2005-11-10 15:51:12 +01:00
|
|
|
|
2005-02-16 00:22:10 +01:00
|
|
|
if (isset($value['primary']) && !$value['anz_links'] )
|
|
|
|
{
|
|
|
|
$value['primary'] = $link_id;
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
unset($value['comment']);
|
2003-02-22 13:29:04 +01:00
|
|
|
unset($value['file']);
|
2002-10-20 17:06:52 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-10 15:51:12 +01:00
|
|
|
$value['msg'] = 'You need to select a file first!';
|
2002-10-20 17:06:52 +02:00
|
|
|
}
|
2005-11-10 15:51:12 +01:00
|
|
|
$extension_data = $value;
|
2002-10-20 17:06:52 +02:00
|
|
|
$loop = True;
|
|
|
|
break;
|
|
|
|
|
2002-10-09 02:34:45 +02:00
|
|
|
case 'unlink':
|
2003-02-22 13:29:04 +01:00
|
|
|
if ($this->debug)
|
|
|
|
{
|
2005-06-16 23:32:07 +02:00
|
|
|
//echo "<p>unlink(link-id=$unlink,$value[to_app],$value[to_id])</p>\n";
|
2003-02-22 13:29:04 +01:00
|
|
|
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;
|
2005-11-12 14:22:05 +01:00
|
|
|
|
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;
|
|
|
|
}
|
2006-09-29 21:55:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ajax callback to search in $app for $pattern, result is displayed in $id
|
|
|
|
*
|
|
|
|
* @param string $app app-name to search
|
|
|
|
* @param string $pattern search-pattern
|
|
|
|
* @param string $id_res id of selectbox to show the result
|
|
|
|
* @param string $id_hide id(s) of the search-box/-line to hide after a successful search
|
|
|
|
* @param string $id_show id(s) of the select-box/-line to show after a successful search
|
|
|
|
* @param string $id_input id of the search input-field
|
|
|
|
*/
|
|
|
|
function ajax_search($app,$pattern,$id_res,$id_hide,$id_show,$id_input)
|
|
|
|
{
|
|
|
|
$response = new xajaxResponse();
|
|
|
|
//$args = func_get_args(); $response->addAlert("link_widget::ajax_search('".implode("','",$args)."')");
|
|
|
|
|
|
|
|
if (!($found = $this->link->query($app,$pattern == lang('Search') ? '' : $pattern))) // ignore the blur-text
|
|
|
|
{
|
2006-10-26 14:11:11 +02:00
|
|
|
$GLOBALS['egw']->translation->add_app('etemplate');
|
2006-09-29 21:55:00 +02:00
|
|
|
$response->addAlert(lang('Nothing found - try again !!!'));
|
|
|
|
$response->addScript("document.getElementById('$id_input').select();");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$script = "var select = document.getElementById('$id_res');\nselect.options.length=0;\n";
|
|
|
|
foreach($found as $id => $title)
|
|
|
|
{
|
|
|
|
$script .= "select.options[select.options.length] = new Option('".addslashes($title)."','$id');\n";
|
|
|
|
}
|
|
|
|
$script .= "select.options[select.options.length] = new Option('".addslashes(lang('New search').' ...')."','');\n";
|
|
|
|
foreach(explode(',',$id_show) as $id)
|
|
|
|
{
|
|
|
|
$script .= "document.getElementById('$id').style.display='inline';\n";
|
|
|
|
}
|
|
|
|
foreach(explode(',',$id_hide) as $id)
|
|
|
|
{
|
|
|
|
$script .= "document.getElementById('$id').style.display='none';\n";
|
|
|
|
}
|
|
|
|
//$response->addAlert($script);
|
|
|
|
$response->addScript($script);
|
|
|
|
}
|
|
|
|
return $response->getXML();
|
|
|
|
}
|
2002-10-09 02:34:45 +02:00
|
|
|
}
|