2005-02-03 17:42:20 +01:00
|
|
|
<?php
|
2005-11-09 22:03:35 +01:00
|
|
|
/**
|
2005-11-11 00:35:55 +01:00
|
|
|
* eGroupWare - resources
|
2005-11-09 22:03:35 +01:00
|
|
|
*
|
2005-11-11 00:35:55 +01:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2005-11-09 22:03:35 +01:00
|
|
|
* @package resources
|
2005-11-11 00:35:55 +01:00
|
|
|
* @link http://www.egroupware.org
|
2005-11-09 22:03:35 +01:00
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
|
2005-11-11 00:35:55 +01:00
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General userinterface object for resources
|
|
|
|
*
|
|
|
|
* @package resources
|
2005-11-09 22:03:35 +01:00
|
|
|
*/
|
2011-03-23 16:25:59 +01:00
|
|
|
class resources_ui
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'index' => True,
|
|
|
|
'edit' => True,
|
2005-06-11 16:58:07 +02:00
|
|
|
'select' => True,
|
2005-02-03 17:42:20 +01:00
|
|
|
'writeLangFile' => True
|
2010-02-05 04:34:17 +01:00
|
|
|
);
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
2009-11-05 20:37:28 +01:00
|
|
|
* Constructor
|
2005-06-10 22:40:57 +02:00
|
|
|
*
|
|
|
|
*/
|
2009-11-05 20:37:28 +01:00
|
|
|
function __construct()
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
// print_r($GLOBALS['egw_info']); die();
|
2008-03-25 17:07:08 +01:00
|
|
|
$this->tmpl = new etemplate('resources.show');
|
2011-03-23 16:25:59 +01:00
|
|
|
$this->bo = new resources_bo();
|
2005-06-18 10:00:03 +02:00
|
|
|
// $this->calui = CreateObject('resources.ui_calviews');
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* main resources list.
|
|
|
|
*
|
2005-06-13 11:18:06 +02:00
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-10 22:40:57 +02:00
|
|
|
* @param array $content content from eTemplate callback
|
2008-04-20 21:37:12 +02:00
|
|
|
*
|
2005-06-10 22:40:57 +02:00
|
|
|
*/
|
2005-02-03 17:42:20 +01:00
|
|
|
function index($content='')
|
|
|
|
{
|
|
|
|
if (is_array($content))
|
2005-06-13 11:18:06 +02:00
|
|
|
{
|
2005-03-02 09:35:10 +01:00
|
|
|
$sessiondata = $content['nm'];
|
2005-10-09 12:13:10 +02:00
|
|
|
unset($sessiondata['rows']);
|
|
|
|
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-13 11:18:06 +02:00
|
|
|
if (isset($content['btn_delete_selected']))
|
2005-10-09 12:13:10 +02:00
|
|
|
{
|
|
|
|
foreach($content['nm']['rows'] as $row)
|
2005-06-13 11:18:06 +02:00
|
|
|
{
|
2005-10-09 12:13:10 +02:00
|
|
|
if($res_id = $row['checkbox'][0])
|
|
|
|
{
|
|
|
|
$msg .= '<p>'. $this->bo->delete($res_id). '</p><br>';
|
|
|
|
}
|
2005-06-13 11:18:06 +02:00
|
|
|
}
|
|
|
|
return $this->index($msg);
|
|
|
|
}
|
2005-10-09 12:13:10 +02:00
|
|
|
foreach($content['nm']['rows'] as $row)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-10-09 12:13:10 +02:00
|
|
|
if(isset($row['delete']))
|
|
|
|
{
|
|
|
|
$res_id = array_search('pressed',$row['delete']);
|
|
|
|
return $this->index($this->bo->delete($res_id));
|
|
|
|
}
|
|
|
|
if(isset($row['view_acc']))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2012-11-14 19:00:02 +01:00
|
|
|
$sessiondata['filter2'] = array_search('pressed',$row['view_acc']);
|
2005-10-09 12:13:10 +02:00
|
|
|
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$sessiondata);
|
|
|
|
return $this->index();
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
}
|
2011-06-06 19:46:01 +02:00
|
|
|
if ($content['nm']['action'])
|
|
|
|
{
|
|
|
|
if (!count($content['nm']['selected']) && !$content['nm']['select_all'])
|
|
|
|
{
|
|
|
|
$msg = lang('You need to select some entries first!');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ($this->action($content['nm']['action'],$content['nm']['selected'],$content['nm']['select_all'],
|
|
|
|
$success,$failed,$action_msg,'resources_index_nm',$msg))
|
|
|
|
{
|
|
|
|
$msg .= lang('%1 resource(s) %2',$success,$action_msg);
|
|
|
|
}
|
|
|
|
elseif(empty($msg))
|
|
|
|
{
|
|
|
|
$msg .= lang('%1 resource(s) %2, %3 failed because of insufficent rights !!!',$success,$action_msg,$failed);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg .= lang('%1 resource(s) %2, %3 failed',$success,$action_msg,$failed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-08 17:27:46 +02:00
|
|
|
} else {
|
|
|
|
$msg = $content;
|
2005-03-02 09:35:10 +01:00
|
|
|
}
|
2005-06-13 14:21:18 +02:00
|
|
|
$content = array();
|
|
|
|
$content['msg'] = $msg;
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 18:00:26 +02:00
|
|
|
$content['nm']['header_left'] = 'resources.resource_select.header';
|
2011-06-08 04:27:42 +02:00
|
|
|
$content['nm']['header_right'] = 'resources.show.nm_right';
|
2011-03-23 16:25:59 +01:00
|
|
|
$content['nm']['get_rows'] = 'resources.resources_bo.get_rows';
|
2005-02-03 17:42:20 +01:00
|
|
|
$content['nm']['no_filter'] = False;
|
2007-02-25 20:42:15 +01:00
|
|
|
$content['nm']['filter_label'] = lang('Category');
|
2012-11-13 18:26:31 +01:00
|
|
|
$content['nm']['filter2_label'] = 'Display';
|
2005-02-21 16:56:21 +01:00
|
|
|
$content['nm']['filter_no_lang'] = true;
|
|
|
|
$content['nm']['no_cat'] = true;
|
2005-06-29 11:30:08 +02:00
|
|
|
$content['nm']['bottom_too'] = true;
|
2005-06-13 14:21:18 +02:00
|
|
|
$content['nm']['order'] = 'name';
|
|
|
|
$content['nm']['sort'] = 'ASC';
|
2010-11-15 21:14:50 +01:00
|
|
|
$content['nm']['store_state'] = 'get_rows';
|
2011-06-06 19:46:01 +02:00
|
|
|
$content['nm']['row_id'] = 'res_id';
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-13 17:14:46 +02:00
|
|
|
$nm_session_data = $GLOBALS['egw']->session->appsession('session_data','resources_index_nm');
|
|
|
|
if($nm_session_data)
|
|
|
|
{
|
|
|
|
$content['nm'] = $nm_session_data;
|
|
|
|
}
|
2006-01-17 17:49:46 +01:00
|
|
|
$content['nm']['options-filter']= array(''=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ);
|
2012-11-13 18:26:31 +01:00
|
|
|
$content['nm']['options-filter2'] = resources_bo::$filter_options;
|
|
|
|
|
2012-12-17 23:14:32 +01:00
|
|
|
$config = config::read('resources');
|
|
|
|
if($config['history'])
|
|
|
|
{
|
|
|
|
$content['nm']['options-filter2'][resources_bo::DELETED] = lang('Deleted');
|
|
|
|
}
|
|
|
|
|
2009-12-09 00:10:06 +01:00
|
|
|
if($_GET['search']) {
|
|
|
|
$content['nm']['search'] = $_GET['search'];
|
|
|
|
}
|
2012-11-13 18:26:31 +01:00
|
|
|
if($_GET['view_accs_of'])
|
|
|
|
{
|
2012-11-14 19:00:02 +01:00
|
|
|
$content['nm']['filter2'] = (int)$_GET['view_accs_of'];
|
2012-11-13 18:26:31 +01:00
|
|
|
}
|
2011-06-06 19:46:01 +02:00
|
|
|
$content['nm']['actions'] = $this->get_actions();
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-02-03 17:42:20 +01:00
|
|
|
// check if user is permitted to add resources
|
2005-06-10 22:40:57 +02:00
|
|
|
if(!$this->bo->acl->get_cats(EGW_ACL_ADD))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
|
|
|
$no_button['add'] = true;
|
|
|
|
}
|
2005-02-28 16:19:31 +01:00
|
|
|
$no_button['back'] = true;
|
2005-06-10 22:40:57 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('resources');
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-07-01 17:01:07 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .= "<script LANGUAGE=\"JavaScript\">
|
|
|
|
function js_btn_book_selected(form)
|
|
|
|
{
|
|
|
|
resources = '';
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-10-18 23:20:33 +02:00
|
|
|
el = form.getElementsByTagName(\"input\");
|
|
|
|
for (var i = 0; i < el.length; i++)
|
2005-07-01 17:01:07 +02:00
|
|
|
{
|
2005-10-18 23:20:33 +02:00
|
|
|
if(el[i].name.substr(el[i].name.length-12,el[i].name.length) == '[checkbox][]' && el[i].checked)
|
2005-07-01 17:01:07 +02:00
|
|
|
{
|
|
|
|
if(resources.length > 0)
|
|
|
|
{
|
|
|
|
resources += ',';
|
|
|
|
}
|
2005-10-18 23:20:33 +02:00
|
|
|
resources += 'r' + el[i].value;
|
2005-07-01 17:01:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(resources.length == 0)
|
|
|
|
{
|
|
|
|
alert('". lang('No resources selected'). "');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return resources;
|
|
|
|
}
|
|
|
|
</script>";
|
2005-06-12 16:36:15 +02:00
|
|
|
|
2011-06-08 04:27:42 +02:00
|
|
|
egw_framework::validate_file('.','resources','resources');
|
|
|
|
|
2012-11-14 19:00:02 +01:00
|
|
|
if($content['nm']['filter2'] > 0)
|
2005-02-28 16:19:31 +01:00
|
|
|
{
|
2012-11-14 19:00:02 +01:00
|
|
|
$master = $this->bo->so->read(array('res_id' => $content['nm']['filter2']));
|
|
|
|
$content['nm']['options-filter2'] = resources_bo::$filter_options + array(
|
|
|
|
$master['res_id'] => lang('accessories of') . ' ' . $master['name']
|
|
|
|
);
|
2011-03-23 16:25:59 +01:00
|
|
|
$content['nm']['get_rows'] = 'resources.resources_bo.get_rows';
|
2005-11-03 23:48:30 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('resources') . ' - ' . lang('accessories of '). ' '. $master['name'] .
|
2005-03-02 09:35:10 +01:00
|
|
|
($master['short_description'] ? ' [' . $master['short_description'] . ']' : '');
|
2005-02-28 16:19:31 +01:00
|
|
|
}
|
2005-03-01 11:20:03 +01:00
|
|
|
$preserv = $content;
|
2011-06-11 13:12:39 +02:00
|
|
|
|
2012-11-26 22:04:31 +01:00
|
|
|
$options = array();
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
$GLOBALS['egw']->session->appsession('session_data','resources_index_nm',$content['nm']);
|
2005-03-01 11:58:04 +01:00
|
|
|
$this->tmpl->read('resources.show');
|
2011-03-23 16:25:59 +01:00
|
|
|
return $this->tmpl->exec('resources.resources_ui.index',$content,$sel_options,$no_button,$preserv);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
|
2011-06-06 19:46:01 +02:00
|
|
|
/**
|
|
|
|
* Get actions / context menu for index
|
|
|
|
*
|
|
|
|
* @return array see nextmatch_widget::egw_actions()
|
|
|
|
*/
|
|
|
|
protected function get_actions()
|
|
|
|
{
|
|
|
|
$actions = array(
|
|
|
|
'edit' => array(
|
|
|
|
'default' => true,
|
2011-06-08 04:27:42 +02:00
|
|
|
'caption' => 'open',
|
2011-06-06 19:46:01 +02:00
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'url' => 'menuaction=resources.resources_ui.edit&res_id=$id',
|
|
|
|
'popup' => egw_link::get_registry('resources', 'add_popup'),
|
2011-06-11 13:12:39 +02:00
|
|
|
'group' => $group=1,
|
2011-06-06 19:46:01 +02:00
|
|
|
'disableClass' => 'rowNoEdit',
|
|
|
|
),
|
2012-11-20 22:30:35 +01:00
|
|
|
'add' => array(
|
|
|
|
'caption' => 'New resource',
|
2012-12-05 20:25:32 +01:00
|
|
|
'url' => 'menuaction=resources.resources_ui.edit&accessory_of=-1',
|
2012-11-20 22:30:35 +01:00
|
|
|
'popup' => egw_link::get_registry('resources', 'add_popup'),
|
|
|
|
'group' => $group,
|
|
|
|
),
|
2012-11-13 18:26:31 +01:00
|
|
|
'view-acc' => array(
|
|
|
|
'caption' => 'View accessories',
|
|
|
|
'icon' => 'view_acc',
|
|
|
|
'allowOnMultiple' => false,
|
|
|
|
'url' => 'menuaction=resources.resources_ui.index&view_accs_of=$id',
|
|
|
|
'group' => $group,
|
|
|
|
'enableClass' => 'hasAccessories'
|
|
|
|
),
|
2012-11-20 22:30:35 +01:00
|
|
|
'new_accessory' => array(
|
|
|
|
'caption' => 'New accessory',
|
|
|
|
'icon' => 'new',
|
2011-06-06 19:46:01 +02:00
|
|
|
'group' => $group,
|
2012-11-20 22:30:35 +01:00
|
|
|
'url' => 'menuaction=resources.resources_ui.edit&res_id=0&accessory_of=$id',
|
|
|
|
'popup' => egw_link::get_registry('resources', 'add_popup'),
|
|
|
|
'disableClass' => 'no_new_accessory',
|
|
|
|
'allowOnMultiple' => false
|
2011-06-06 19:46:01 +02:00
|
|
|
),
|
2012-11-20 22:30:35 +01:00
|
|
|
|
|
|
|
|
2011-06-09 16:07:22 +02:00
|
|
|
'select_all' => array(
|
|
|
|
'caption' => 'Whole query',
|
|
|
|
'checkbox' => true,
|
|
|
|
'hint' => 'Apply the action on the whole query, NOT only the shown entries',
|
|
|
|
'group' => ++$group,
|
|
|
|
),
|
2011-06-08 17:27:46 +02:00
|
|
|
'view-calendar' => array(
|
2011-06-08 04:27:42 +02:00
|
|
|
'caption' => 'View calendar',
|
|
|
|
'icon' => 'calendar/planner',
|
|
|
|
'group' => ++$group,
|
|
|
|
'allowOnMultiple' => true,
|
|
|
|
'disableClass' => 'no_view_calendar',
|
|
|
|
),
|
|
|
|
'book' => array(
|
|
|
|
'caption' => 'Book resource',
|
|
|
|
'icon' => 'navbar',
|
|
|
|
'group' => $group,
|
|
|
|
'allowOnMultiple' => true,
|
|
|
|
'disableClass' => 'no_book',
|
|
|
|
),
|
2011-06-06 19:46:01 +02:00
|
|
|
/*
|
|
|
|
'documents' => resources_merge::document_action(
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['resources']['document_dir'],
|
|
|
|
++$group, 'Insert in document', 'document_',
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['resources']['default_document']
|
|
|
|
),
|
|
|
|
*/
|
|
|
|
'delete' => array(
|
|
|
|
'caption' => 'Delete',
|
|
|
|
'group' => ++$group,
|
2011-06-08 04:27:42 +02:00
|
|
|
'disableClass' => 'no_delete',
|
2012-11-26 22:04:31 +01:00
|
|
|
'nm_action' => 'open_popup',
|
|
|
|
'hideOnDisabled' => true
|
2011-06-06 19:46:01 +02:00
|
|
|
),
|
2012-12-17 23:14:32 +01:00
|
|
|
'restore' => array(
|
|
|
|
'caption' => 'Un-delete',
|
2012-12-19 19:12:42 +01:00
|
|
|
'icon' => 'revert',
|
2012-12-17 23:14:32 +01:00
|
|
|
'enableClass' => 'deleted',
|
|
|
|
'hideOnDisabled' => true,
|
|
|
|
'group' => $group,
|
|
|
|
)
|
2011-06-06 19:46:01 +02:00
|
|
|
);
|
|
|
|
return $actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* apply an action to multiple timesheets
|
|
|
|
*
|
|
|
|
* @param string/int $action 'status_to',set status to timeshhets
|
|
|
|
* @param array $checked timesheet id's to use if !$use_all
|
|
|
|
* @param boolean $use_all if true use all timesheets of the current selection (in the session)
|
|
|
|
* @param int &$success number of succeded actions
|
|
|
|
* @param int &$failed number of failed actions (not enought permissions)
|
|
|
|
* @param string &$action_msg translated verb for the actions, to be used in a message like %1 timesheets 'deleted'
|
|
|
|
* @param string/array $session_name 'index' or 'email', or array with session-data depending if we are in the main list or the popup
|
|
|
|
* @return boolean true if all actions succeded, false otherwise
|
|
|
|
*/
|
|
|
|
function action($action,$checked,$use_all,&$success,&$failed,&$action_msg,$session_name,&$msg)
|
|
|
|
{
|
|
|
|
$success = $failed = 0;
|
|
|
|
if ($use_all)
|
|
|
|
{
|
|
|
|
// get the whole selection
|
2011-06-08 17:27:46 +02:00
|
|
|
$query = is_array($session_name) ? $session_name : $GLOBALS['egw']->session->appsession('session_data', $session_name);
|
2011-06-06 19:46:01 +02:00
|
|
|
|
|
|
|
@set_time_limit(0); // switch off the execution time limit, as it's for big selections to small
|
|
|
|
$query['num_rows'] = -1; // all
|
2011-06-08 17:27:46 +02:00
|
|
|
$this->bo->get_rows($query,$resources,$readonlys);
|
2012-12-10 16:44:30 +01:00
|
|
|
$checked = array();
|
2011-06-08 17:27:46 +02:00
|
|
|
foreach($resources as $resource)
|
|
|
|
{
|
|
|
|
$checked[] = $resource['res_id'];
|
|
|
|
}
|
2011-06-06 19:46:01 +02:00
|
|
|
}
|
2011-06-08 17:27:46 +02:00
|
|
|
//echo __METHOD__."('$action', ".array2string($checked).', '.array2string($use_all).",,, '$session_name')";
|
2011-06-06 19:46:01 +02:00
|
|
|
|
|
|
|
// Dialogs to get options
|
|
|
|
list($action, $settings) = explode('_', $action, 2);
|
|
|
|
|
|
|
|
switch($action)
|
|
|
|
{
|
2011-06-08 17:27:46 +02:00
|
|
|
case 'view-calendar':
|
|
|
|
$resource_ids = array(0);
|
|
|
|
$url_params = array(
|
|
|
|
'menuaction' => 'calendar.calendar_uiviews.planner',
|
|
|
|
'sortby' => 'user',
|
|
|
|
);
|
|
|
|
foreach($checked as $n => $id)
|
|
|
|
{
|
|
|
|
$resource_ids[] = 'r'.$id;
|
|
|
|
}
|
|
|
|
$url_params['owner'] = implode(',',$resource_ids);
|
|
|
|
$success = count($resource_ids);
|
2012-12-05 20:25:32 +01:00
|
|
|
egw_framework::set_onload('window.location.href = "'.egw::link('/index.php',$url_params,'calendar').'"');
|
2011-06-08 17:27:46 +02:00
|
|
|
$action_msg = lang('view calendar');
|
|
|
|
break;
|
|
|
|
case 'book':
|
|
|
|
$resource_ids = array();
|
|
|
|
$url_params = array(
|
|
|
|
'menuaction' => 'calendar.calendar_uiforms.edit'
|
|
|
|
);
|
|
|
|
foreach($checked as $n => $id)
|
|
|
|
{
|
|
|
|
$resource_ids[] = 'r'.$id;
|
|
|
|
}
|
|
|
|
$url_params['participants'] = implode(',',$resource_ids);
|
|
|
|
$success = count($resource_ids);
|
|
|
|
egw_framework::set_onload("egw_openWindowCentered2('".egw::link('/index.php',$url_params) ."','_blank');");
|
|
|
|
$action_msg = lang('booked');
|
|
|
|
break;
|
2012-12-17 23:14:32 +01:00
|
|
|
case 'restore':
|
|
|
|
$action_msg = lang('restored');
|
|
|
|
foreach($checked as $n=>$id)
|
|
|
|
{
|
2013-01-02 23:15:26 +01:00
|
|
|
// Extra data
|
|
|
|
if(!$id) continue;
|
2012-12-17 23:14:32 +01:00
|
|
|
$resource = $this->bo->read($id);
|
|
|
|
$resource['deleted'] = null;
|
|
|
|
$this->bo->save($resource);
|
2012-12-19 19:12:42 +01:00
|
|
|
$success++;
|
2012-12-17 23:14:32 +01:00
|
|
|
}
|
|
|
|
break;
|
2011-06-06 19:46:01 +02:00
|
|
|
case 'delete':
|
|
|
|
$action_msg = lang('deleted');
|
2012-11-27 19:08:13 +01:00
|
|
|
$promoted_accessories = 0;
|
|
|
|
foreach($checked as $n => &$id)
|
2011-06-06 19:46:01 +02:00
|
|
|
{
|
2013-01-02 23:15:26 +01:00
|
|
|
// Extra data
|
|
|
|
if(!$id) continue;
|
2012-11-07 00:17:26 +01:00
|
|
|
if($settings == 'promote')
|
|
|
|
{
|
2012-11-27 19:08:13 +01:00
|
|
|
// Handle a selected accessory
|
|
|
|
$resource = $this->bo->read($id);
|
|
|
|
if($resource['accessory_of'] > 0)
|
|
|
|
{
|
|
|
|
$resource['accessory_of'] = -1;
|
2012-12-03 21:20:42 +01:00
|
|
|
$this->bo->save($resource);
|
2012-11-27 19:08:13 +01:00
|
|
|
$promoted_accessories++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-01-03 17:35:02 +01:00
|
|
|
// Make associated accessories into resources - include deleted
|
|
|
|
$accessories = $this->bo->get_acc_list($id,true);
|
2012-11-07 00:17:26 +01:00
|
|
|
foreach($accessories as $acc_id => $name)
|
|
|
|
{
|
|
|
|
$acc = $this->bo->read($acc_id);
|
|
|
|
$acc['accessory_of'] = -1;
|
|
|
|
$this->bo->save($acc);
|
2012-11-27 19:08:13 +01:00
|
|
|
$promoted_accessories++;
|
|
|
|
|
|
|
|
// Don't need to process these ones now
|
|
|
|
$checked_key = array_search($acc_id, $checked);
|
|
|
|
if($checked_key !== false) unset($checked[$checked_key]);
|
2012-11-07 00:17:26 +01:00
|
|
|
}
|
|
|
|
}
|
2012-12-12 01:28:54 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Remove checked accessories, deleting resource will remove them
|
|
|
|
// We get an error if we try to delete them after they're gone
|
|
|
|
$accessories = $this->bo->get_acc_list($id);
|
2013-01-02 23:15:26 +01:00
|
|
|
|
2012-12-12 01:28:54 +01:00
|
|
|
foreach($accessories as $acc_id => $name)
|
|
|
|
{
|
|
|
|
$checked_key = array_search($acc_id, $checked);
|
|
|
|
if($checked_key !== false)
|
|
|
|
{
|
|
|
|
$success++;
|
|
|
|
unset($checked[$checked_key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-06 19:46:01 +02:00
|
|
|
$error = $this->bo->delete($id);
|
|
|
|
if (!$error)
|
|
|
|
{
|
|
|
|
$success++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg = $error . "\n";
|
|
|
|
$failed++;
|
|
|
|
}
|
|
|
|
}
|
2012-11-27 19:08:13 +01:00
|
|
|
if($promoted_accessories) $action_msg .= ", " . lang('%1 accessories now resources',$promoted_accessories);
|
2011-06-06 19:46:01 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $failed == 0;
|
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
2005-06-13 11:18:06 +02:00
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-10 22:40:57 +02:00
|
|
|
* invokes add or edit dialog for resources
|
|
|
|
*
|
|
|
|
* @param $content Content from the eTemplate Exec call or id on inital call
|
|
|
|
*/
|
2005-03-02 09:35:10 +01:00
|
|
|
function edit($content=0,$accessory_of = -1)
|
2008-04-20 21:37:12 +02:00
|
|
|
{
|
2005-02-03 17:42:20 +01:00
|
|
|
if (is_array($content))
|
|
|
|
{
|
2012-11-26 22:04:31 +01:00
|
|
|
list($button) = @each($content['button']);
|
|
|
|
unset($content['button']);
|
|
|
|
switch($button)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2012-11-26 22:04:31 +01:00
|
|
|
case 'save':
|
|
|
|
case 'apply':
|
2005-02-24 19:24:26 +01:00
|
|
|
unset($content['save']);
|
2012-11-27 17:47:12 +01:00
|
|
|
unset($content['apply']);
|
2005-06-11 21:54:04 +02:00
|
|
|
// if($content['id'] != 0)
|
|
|
|
// {
|
|
|
|
// // links are already saved by eTemplate
|
|
|
|
// unset($resource['link_to']['to_id']);
|
|
|
|
// }
|
2012-11-27 17:47:12 +01:00
|
|
|
$result = $this->bo->save($content);
|
|
|
|
if(is_numeric($result))
|
|
|
|
{
|
|
|
|
$content['res_id'] = $result;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$content['msg'] = $result;
|
|
|
|
}
|
2012-11-26 22:04:31 +01:00
|
|
|
break;
|
|
|
|
case 'delete':
|
2005-02-24 19:24:26 +01:00
|
|
|
unset($content['delete']);
|
2005-06-29 11:30:08 +02:00
|
|
|
$content['msg'] = $this->bo->delete($content['res_id']);
|
2012-11-26 22:04:31 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-11-27 17:47:12 +01:00
|
|
|
$js = "opener.egw_refresh('".str_replace("'","\\'",$content['msg'])."','addressbook',{$content['res_id']});";
|
2012-11-26 22:04:31 +01:00
|
|
|
if($button != 'apply' && !$content['msg'])
|
|
|
|
{
|
2005-03-02 09:35:10 +01:00
|
|
|
$js .= 'window.close();';
|
|
|
|
echo "<html><body><script>$js</script></body></html>\n";
|
2005-06-10 22:40:57 +02:00
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
2005-02-24 19:24:26 +01:00
|
|
|
}
|
2012-11-27 17:47:12 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .= "<script>$js</script>";
|
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2012-12-05 00:57:02 +01:00
|
|
|
$nm_session_data = $GLOBALS['egw']->session->appsession('session_data','resources_index_nm');
|
2012-11-26 22:04:31 +01:00
|
|
|
$res_id = is_numeric($content) ? (int)$content : $content['res_id'];
|
|
|
|
if (isset($_GET['res_id'])) $res_id = $_GET['res_id'];
|
2012-12-05 00:57:02 +01:00
|
|
|
if (isset($nm_session_data['filter2']) && $nm_session_data['filter2'] > 0) $accessory_of = $nm_session_data['filter2'];
|
2012-11-26 22:04:31 +01:00
|
|
|
if (isset($_GET['accessory_of'])) $accessory_of = $_GET['accessory_of'];
|
|
|
|
$content = array('res_id' => $res_id);
|
|
|
|
|
|
|
|
if ($res_id > 0)
|
|
|
|
{
|
|
|
|
$content = $this->bo->read($res_id);
|
|
|
|
$content['gen_src_list'] = strpos($content['picture_src'],'.') !== false ? $content['picture_src'] : false;
|
|
|
|
$content['picture_src'] = strpos($content['picture_src'],'.') !== false ? 'gen_src' : $content['picture_src'];
|
|
|
|
$content['link_to'] = array(
|
|
|
|
'to_id' => $res_id,
|
|
|
|
'to_app' => 'resources'
|
|
|
|
);
|
2012-12-05 00:42:56 +01:00
|
|
|
} elseif ($accessory_of > 0) {
|
2012-12-03 21:20:42 +01:00
|
|
|
// Pre-set according to parent
|
|
|
|
$owner = $this->bo->read($accessory_of);
|
2012-12-05 00:57:02 +01:00
|
|
|
if($owner['accessory_of'] > 0)
|
|
|
|
{
|
|
|
|
// Accessory of accessory not allowed, grab parent resource
|
|
|
|
$accessory_of = $owner['accessory_of'];
|
|
|
|
$owner = $this->bo->read($accessory_of);
|
|
|
|
}
|
2012-12-03 21:20:42 +01:00
|
|
|
$content['cat_id'] = $owner['cat_id'];
|
|
|
|
$content['bookable'] = true;
|
|
|
|
} else {
|
|
|
|
// New resource
|
|
|
|
$content['cat_id'] = $nm_session_data['filter'];
|
|
|
|
$content['bookable'] = true;
|
2005-02-25 12:15:27 +01:00
|
|
|
}
|
2012-11-26 22:04:31 +01:00
|
|
|
if ($_GET['msg']) $content['msg'] = strip_tags($_GET['msg']);
|
|
|
|
|
2005-02-28 16:19:31 +01:00
|
|
|
// some presetes
|
2005-06-29 11:30:08 +02:00
|
|
|
$content['resource_picture'] = $this->bo->get_picture($content['res_id'],$content['picture_src'],$size=true);
|
2005-02-28 16:19:31 +01:00
|
|
|
$content['quantity'] = $content['quantity'] ? $content['quantity'] : 1;
|
|
|
|
$content['useable'] = $content['useable'] ? $content['useable'] : 1;
|
2005-11-03 23:48:30 +01:00
|
|
|
$content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : $accessory_of;
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2012-12-17 23:14:32 +01:00
|
|
|
$content['history'] = array(
|
|
|
|
'id' => $res_id,
|
|
|
|
'app' => 'resources',
|
|
|
|
'status-widgets' => array(
|
|
|
|
'accessory_of' => 'link-entry:resources'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$sel_options['status'] = resources_bo::$field2label;
|
|
|
|
|
2005-03-02 09:35:10 +01:00
|
|
|
$sel_options['gen_src_list'] = $this->bo->get_genpicturelist();
|
2005-06-10 22:40:57 +02:00
|
|
|
$sel_options['cat_id'] = $this->bo->acl->get_cats(EGW_ACL_ADD);
|
2008-04-20 21:37:12 +02:00
|
|
|
$sel_options['cat_id'] = count($sel_options['cat_id']) == 1 ? $sel_options['cat_id'] :
|
2012-11-26 22:04:31 +01:00
|
|
|
array('' => lang('select one')) + $sel_options['cat_id'];
|
2005-03-02 09:35:10 +01:00
|
|
|
if($accessory_of > 0 || $content['accessory_of'] > 0)
|
2005-02-28 16:19:31 +01:00
|
|
|
{
|
2005-03-02 09:35:10 +01:00
|
|
|
$content['accessory_of'] = $content['accessory_of'] ? $content['accessory_of'] : $accessory_of;
|
2005-02-28 16:19:31 +01:00
|
|
|
}
|
2012-11-14 19:00:02 +01:00
|
|
|
$search_options = array('accessory_of' => -1);
|
2012-12-03 21:20:42 +01:00
|
|
|
$sel_options['accessory_of'] = array(-1 => lang('none')) + (array)$this->bo->link_query('',$search_options);
|
2012-11-14 19:00:02 +01:00
|
|
|
if($res_id) unset($sel_options['accessory_of'][$res_id]);
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-10-09 12:13:10 +02:00
|
|
|
// $content['general|page|pictures|links'] = 'resources.edit_tabs.page'; //debug
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2012-11-14 19:00:02 +01:00
|
|
|
// Permissions
|
|
|
|
$read_only = array();
|
|
|
|
if($res_id && !$this->bo->acl->is_permitted($content['cat_id'],EGW_ACL_EDIT))
|
2005-10-09 12:13:10 +02:00
|
|
|
{
|
2012-11-14 19:00:02 +01:00
|
|
|
$read_only['__ALL__'] = true;
|
2005-10-09 12:13:10 +02:00
|
|
|
}
|
2012-12-17 23:14:32 +01:00
|
|
|
$config = config::read('resources');
|
|
|
|
if(!$this->bo->acl->is_permitted($content['cat_id'],EGW_ACL_DELETE) ||
|
|
|
|
($content['deleted'] && !$GLOBALS['egw_info']['user']['apps']['admin'] && $config['history'] == 'history'))
|
2005-03-21 10:52:53 +01:00
|
|
|
{
|
2012-11-14 19:00:02 +01:00
|
|
|
$read_only['delete'] = true;
|
2008-04-20 21:37:12 +02:00
|
|
|
}
|
2012-12-03 21:20:42 +01:00
|
|
|
|
|
|
|
// Disable custom tab if there are no custom fields defined
|
|
|
|
$read_only['tabs']['custom'] = !(config::get_customfields('resources',true));
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2012-11-14 19:00:02 +01:00
|
|
|
$preserv = $content;
|
|
|
|
$this->tmpl->read('resources.edit');
|
|
|
|
return $this->tmpl->exec('resources.resources_ui.edit',$content,$sel_options,$read_only,$preserv,2);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 16:58:07 +02:00
|
|
|
/**
|
|
|
|
* select resources
|
|
|
|
*
|
|
|
|
* @author Lukas Weiss <wnz.gh05t@users.sourceforge.net>
|
|
|
|
*/
|
2005-06-11 17:41:12 +02:00
|
|
|
function select($content='')
|
2005-06-11 16:58:07 +02:00
|
|
|
{
|
2006-05-18 18:14:35 +02:00
|
|
|
$GLOBALS['phpgw']->js->set_onload("copyOptions('exec[resources][selectbox]');");
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 21:46:50 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .= "<script LANGUAGE=\"JavaScript\">
|
2005-06-11 17:41:12 +02:00
|
|
|
window.focus();
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-12 13:15:22 +02:00
|
|
|
openerid='resources_selectbox';
|
2005-06-11 21:46:50 +02:00
|
|
|
id='exec[nm][rows][selectbox]';
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-09-06 23:45:37 +02:00
|
|
|
function addOption(label,value,button_id,useable)
|
2005-06-11 17:41:12 +02:00
|
|
|
{
|
2009-11-24 12:55:10 +01:00
|
|
|
var quantity = document.getElementById(button_id+'[default_qty]').value;
|
2005-09-13 23:42:46 +02:00
|
|
|
value = value+':'+quantity;
|
2005-09-06 23:45:37 +02:00
|
|
|
if(quantity>useable) {
|
|
|
|
alert('".lang('You chose more resources than available')."');
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
label = label+'['+quantity+'/'+useable+']';
|
2005-06-11 21:46:50 +02:00
|
|
|
openerSelectBox = opener.document.getElementById(openerid);
|
|
|
|
if (openerSelectBox) {
|
2005-06-11 17:41:12 +02:00
|
|
|
select = '';
|
|
|
|
for(i=0; i < openerSelectBox.length; i++) {
|
|
|
|
with (openerSelectBox.options[i]) {
|
|
|
|
if (selected || openerSelectBox.selectedIndex == i) {
|
|
|
|
select += (value.slice(0,1)==',' ? '' : ',')+value;
|
|
|
|
}
|
|
|
|
}
|
2005-06-11 16:58:07 +02:00
|
|
|
}
|
2005-06-11 17:41:12 +02:00
|
|
|
select += (select ? ',' : '')+value;
|
2005-09-13 23:42:46 +02:00
|
|
|
opener.selectbox_add_option(openerid,label,value,0);
|
2005-06-11 16:58:07 +02:00
|
|
|
}
|
2005-06-11 21:46:50 +02:00
|
|
|
selectBox = document.getElementById(id);
|
2005-06-11 17:41:12 +02:00
|
|
|
if (selectBox) {
|
2005-09-13 23:42:46 +02:00
|
|
|
var resource_value = value.split(':');
|
2005-06-11 17:41:12 +02:00
|
|
|
for (i=0; i < selectBox.length; i++) {
|
2005-09-13 23:42:46 +02:00
|
|
|
var selectvalue = selectBox.options[i].value.split(':');
|
|
|
|
if (selectvalue[0] == resource_value[0]) {
|
2008-04-20 21:37:12 +02:00
|
|
|
selectBox.options[i] = null;
|
|
|
|
selectBox.options[selectBox.length] = new Option(label,value,false,true);
|
2005-06-11 17:41:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i >= selectBox.length) {
|
|
|
|
selectBox.options[selectBox.length] = new Option(label,value,false,true);
|
2005-06-11 16:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 21:46:50 +02:00
|
|
|
function removeSelectedOptions()
|
2005-06-11 17:41:12 +02:00
|
|
|
{
|
2005-06-11 21:46:50 +02:00
|
|
|
openerSelectBox = opener.document.getElementById(openerid);
|
2005-06-11 17:41:12 +02:00
|
|
|
if (openerSelectBox == null) window.close();
|
2005-06-11 21:46:50 +02:00
|
|
|
selectBox = document.getElementById(id);
|
2005-06-11 17:41:12 +02:00
|
|
|
for (i=0; i < selectBox.length; i++) {
|
|
|
|
if (selectBox.options[i].selected) {
|
|
|
|
for (j=0; j < openerSelectBox.length; j++) {
|
|
|
|
if (openerSelectBox[j].value == selectBox.options[i].value) {
|
|
|
|
openerSelectBox.removeChild(openerSelectBox[j]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
selectBox.options[i--] = null;
|
|
|
|
}
|
2005-06-11 16:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 21:46:50 +02:00
|
|
|
function copyOptions()
|
2005-06-11 17:41:12 +02:00
|
|
|
{
|
2005-06-11 21:46:50 +02:00
|
|
|
openerSelectBox = opener.document.getElementById(openerid);
|
|
|
|
selectBox = document.getElementById(id);
|
2005-06-11 16:58:07 +02:00
|
|
|
for (i=0; i < openerSelectBox.length; i++) {
|
|
|
|
with (openerSelectBox.options[i]) {
|
2005-06-11 17:41:12 +02:00
|
|
|
if (selected && value.slice(0,1) != ',') {
|
|
|
|
selectBox.options[selectBox.length] = new Option(text,value);
|
2005-06-11 16:58:07 +02:00
|
|
|
}
|
|
|
|
}
|
2005-06-11 17:41:12 +02:00
|
|
|
}
|
2005-06-11 16:58:07 +02:00
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 21:46:50 +02:00
|
|
|
function oneLineSubmit()
|
2005-06-11 17:41:12 +02:00
|
|
|
{
|
2005-09-13 23:42:46 +02:00
|
|
|
/*
|
2005-06-11 21:46:50 +02:00
|
|
|
openerSelectBox = opener.document.getElementById(openerid);
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-06-11 17:41:12 +02:00
|
|
|
if (openerSelectBox) {
|
|
|
|
if (openerSelectBox.selectedIndex >= 0) {
|
|
|
|
selected = openerSelectBox.options[openerSelectBox.selectedIndex].value;
|
|
|
|
if (selected.slice(0,1) == ',') selected = selected.slice(1);
|
2005-06-18 10:00:03 +02:00
|
|
|
opener.selectbox_add_option(openerid,'multiple*',selected,1);
|
2005-06-11 17:41:12 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (i=0; i < openerSelectBox.length; i++) {
|
|
|
|
with (openerSelectBox.options[i]) {
|
|
|
|
if (selected) {
|
2005-06-18 10:00:03 +02:00
|
|
|
opener.selectbox_add_option(openerid,text,value,1);
|
2005-06-11 17:41:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
}
|
2005-06-11 17:41:12 +02:00
|
|
|
}
|
|
|
|
}
|
2005-09-13 23:42:46 +02:00
|
|
|
*/
|
2005-06-11 17:41:12 +02:00
|
|
|
window.close();
|
|
|
|
}</script>";
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2009-09-29 11:30:41 +02:00
|
|
|
if (!is_array($content))
|
|
|
|
{
|
2009-11-05 20:37:28 +01:00
|
|
|
if (!($content['nm'] = egw_cache::getSession('resources','get_rows')))
|
|
|
|
{
|
|
|
|
$content['nm'] = array(
|
|
|
|
'header_left' => 'resources.resource_select.header',
|
|
|
|
'show_bookable' => true,
|
2011-03-23 16:25:59 +01:00
|
|
|
'get_rows' => 'resources.resources_bo.get_rows',
|
2009-11-05 20:37:28 +01:00
|
|
|
'filter_label' => 'Category',
|
|
|
|
'filter_help' => lang('Select a category'),
|
|
|
|
'options-filter'=> array(''=>lang('all categories'))+(array)$this->bo->acl->get_cats(EGW_ACL_READ),
|
|
|
|
'no_filter2' => true,
|
|
|
|
'filter_no_lang'=> true,
|
|
|
|
'no_cat' => true,
|
|
|
|
'rows' => array('js_id' => 1),
|
|
|
|
'csv_fields' => false,
|
|
|
|
'default_cols' => 'name,cat_id,quantity', // I columns to use if there's no user or default pref
|
|
|
|
'store_state' => 'get_rows', // store in session as for location get_rows
|
|
|
|
);
|
|
|
|
$content['nm']['filter'] = $GLOBALS['egw_info']['user']['preferences']['resources']['filter'];
|
|
|
|
}
|
2009-09-29 11:30:41 +02:00
|
|
|
}
|
2005-06-11 16:58:07 +02:00
|
|
|
$sel_options = array();
|
|
|
|
$no_button = array();
|
|
|
|
$this->tmpl->read('resources.resource_select');
|
2011-03-23 16:25:59 +01:00
|
|
|
return $this->tmpl->exec('resources.resources_ui.select',$content,$sel_options,$no_button,$preserv,2);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-09-28 01:29:06 +02:00
|
|
|
/**
|
|
|
|
* get_calendar_sidebox
|
|
|
|
* get data für calendar sidebox
|
|
|
|
*
|
|
|
|
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
|
2010-10-13 09:15:09 +02:00
|
|
|
* @param array $param with keys menuaction, owner and optional date and return_array
|
2005-09-28 01:29:06 +02:00
|
|
|
* @return array with: label=>link or array with text
|
|
|
|
*/
|
2006-03-06 08:15:54 +01:00
|
|
|
function get_calendar_sidebox($param)
|
2005-09-28 01:29:06 +02:00
|
|
|
{
|
2011-06-03 02:05:37 +02:00
|
|
|
$cats = $this->bo->acl->get_cats(EGW_ACL_CALREAD);
|
2005-11-02 11:37:00 +01:00
|
|
|
if (!$cats) return array();
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2010-10-13 09:15:09 +02:00
|
|
|
if(array_key_exists('return_array', $param))
|
|
|
|
{
|
|
|
|
$return_array = $param['return_array'];
|
|
|
|
unset($param['return_array']);
|
|
|
|
}
|
|
|
|
|
2006-03-06 08:15:54 +01:00
|
|
|
$owners = explode(',',$param['owner']);
|
|
|
|
unset($param['owner']);
|
|
|
|
$res_cats = $selected = array();
|
|
|
|
|
2005-09-28 01:29:06 +02:00
|
|
|
// this gets the resource-ids of the cats and implodes them to the array-key of the selectbox,
|
|
|
|
// so it is possible to select all resources of a category
|
2011-06-03 02:05:37 +02:00
|
|
|
$allowed_list = array();
|
2008-04-20 21:37:12 +02:00
|
|
|
foreach($cats as $cat_id => $cat_name)
|
2005-09-28 01:29:06 +02:00
|
|
|
{
|
2005-10-27 20:43:08 +02:00
|
|
|
if ($resources = $this->bo->so->search(array('cat_id' => $cat_id, 'bookable' => '1'),'res_id'))
|
2005-09-30 05:51:59 +02:00
|
|
|
{
|
2006-03-06 08:15:54 +01:00
|
|
|
$keys = array();
|
2005-09-30 05:51:59 +02:00
|
|
|
foreach($resources as $res)
|
|
|
|
{
|
2006-03-06 08:15:54 +01:00
|
|
|
$keys[] = 'r'.$res['res_id'];
|
2011-06-03 02:05:37 +02:00
|
|
|
$allowed_list[] = $res['res_id'];
|
2006-03-06 08:15:54 +01:00
|
|
|
}
|
|
|
|
$res_cats[implode(',',$keys)] = $cat_name;
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2006-03-06 08:15:54 +01:00
|
|
|
if (count(array_intersect($keys,$owners)) == count($keys))
|
|
|
|
{
|
|
|
|
$selected[] = implode(',',$keys);
|
|
|
|
$owners = array_diff($owners,$keys);
|
2005-09-30 05:51:59 +02:00
|
|
|
}
|
|
|
|
}
|
2005-09-28 01:29:06 +02:00
|
|
|
}
|
2006-03-06 08:15:54 +01:00
|
|
|
// add already selected single resources to the selectbox, eg. call of the resource-calendar from the resources app
|
2012-12-05 20:25:32 +01:00
|
|
|
$resources = array();
|
2006-03-06 08:15:54 +01:00
|
|
|
$res_ids = array();
|
|
|
|
foreach($owners as $key => $owner)
|
|
|
|
{
|
|
|
|
if ($owner{0} == 'r')
|
|
|
|
{
|
|
|
|
$res_ids[] = (int) substr($owner,1);
|
|
|
|
$selected[] = $owner;
|
|
|
|
}
|
|
|
|
}
|
2012-12-05 20:25:32 +01:00
|
|
|
|
2011-06-03 02:05:37 +02:00
|
|
|
// Take out resources not allowed by perms, above
|
|
|
|
$res_ids = array_intersect($res_ids,$allowed_list);
|
2006-03-06 08:15:54 +01:00
|
|
|
if (count($res_ids))
|
|
|
|
{
|
|
|
|
foreach($this->bo->so->search(array('res_id' => $res_ids),'res_id,name') as $data)
|
|
|
|
{
|
|
|
|
$resources['r'.$data['res_id']] = $data['name'];
|
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
}
|
2010-10-13 09:15:09 +02:00
|
|
|
if(!isset($return_array))
|
|
|
|
{
|
|
|
|
$selectbox = html::select(
|
|
|
|
'owner',
|
|
|
|
$selected,
|
|
|
|
array_merge($resources,$res_cats),
|
|
|
|
$no_lang=true,
|
2012-12-05 20:25:32 +01:00
|
|
|
$options='data-placeholder="'.lang('select resources').'" style="width: 100%;" onchange="load_cal(\''.
|
2012-01-09 22:26:41 +01:00
|
|
|
egw::link('/index.php',$param,false).'\',\'uical_select_resource\',true);" id="uical_select_resource"',
|
2012-12-05 20:25:32 +01:00
|
|
|
$multiple=4,
|
|
|
|
true
|
2010-10-13 09:15:09 +02:00
|
|
|
);
|
|
|
|
return array(
|
|
|
|
array(
|
2012-12-05 20:25:32 +01:00
|
|
|
// Add some jQuery to make sure dropdown is displayed
|
|
|
|
'text' => $selectbox . "<script>\$j('select[name=\"owner\[\]\"]').parent('td').css('overflow','visible').parents('div.divSidebox').css('overflow','visible');</script>",
|
2010-10-13 09:15:09 +02:00
|
|
|
'no_lang' => True,
|
|
|
|
'link' => False
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return array_merge($resources,$res_cats);
|
|
|
|
}
|
2005-09-28 01:29:06 +02:00
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-06-29 11:30:08 +02:00
|
|
|
|