2005-02-23 12:48:59 +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
|
|
|
* General hook object for resources
|
|
|
|
* It encapsulats all the diffent hook methods
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2005-11-11 00:35:55 +01:00
|
|
|
* @package resources
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
|
|
|
|
2016-05-05 22:22:04 +02:00
|
|
|
use EGroupware\Api;
|
|
|
|
use EGroupware\Api\Framework;
|
|
|
|
use EGroupware\Api\Egw;
|
|
|
|
use EGroupware\Api\Acl;
|
|
|
|
|
2005-11-11 00:35:55 +01:00
|
|
|
/**
|
|
|
|
* General hook object for resources
|
|
|
|
* It encapsulats all the diffent hook methods
|
|
|
|
* @package resources
|
2005-11-09 22:03:35 +01:00
|
|
|
*/
|
2005-02-25 12:35:51 +01:00
|
|
|
class resources_hooks
|
2005-02-23 12:48:59 +01:00
|
|
|
{
|
2005-02-25 12:35:51 +01:00
|
|
|
function admin_prefs_sidebox($args)
|
2005-02-23 12:48:59 +01:00
|
|
|
{
|
2016-05-26 23:32:00 +02:00
|
|
|
$this->acl = new resources_acl_bo();
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-02-23 12:48:59 +01:00
|
|
|
$appname = 'resources';
|
|
|
|
$location = is_array($args) ? $args['location'] : $args;
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-02-23 12:48:59 +01:00
|
|
|
if ($location == 'sidebox_menu')
|
|
|
|
{
|
2014-01-18 18:54:08 +01:00
|
|
|
// Magic etemplate2 favorites menu (from nextmatch widget)
|
2016-05-05 22:22:04 +02:00
|
|
|
display_sidebox($appname, lang('Favorites'), Framework\Favorites::list_favorites($appname, 'nextmatch-resources.show.rows-favorite'));
|
2014-02-12 22:51:25 +01:00
|
|
|
|
2005-06-12 15:14:46 +02:00
|
|
|
$title = $GLOBALS['egw_info']['apps']['resources']['title'].' '.lang('Menu');
|
2010-06-04 13:37:38 +02:00
|
|
|
$file = array(
|
2016-05-05 22:22:04 +02:00
|
|
|
'Resources list' => Egw::link('/index.php',array(
|
2015-03-05 14:40:38 +01:00
|
|
|
'menuaction' => 'resources.resources_ui.index',
|
|
|
|
'ajax' => 'true')),
|
2005-06-12 15:14:46 +02:00
|
|
|
);
|
2016-05-05 22:22:04 +02:00
|
|
|
if($this->acl->get_cats(Acl::ADD))
|
2005-07-08 17:26:52 +02:00
|
|
|
{
|
2016-05-05 22:22:04 +02:00
|
|
|
$file['Add resource'] = "javascript:egw_openWindowCentered2('".Egw::link('/index.php',array(
|
2011-03-23 16:25:59 +01:00
|
|
|
'menuaction' => 'resources.resources_ui.edit',
|
2012-12-05 20:25:32 +01:00
|
|
|
'accessory_of' => -1
|
2010-06-04 13:37:38 +02:00
|
|
|
),false)."','_blank',800,600,'yes')";
|
2005-07-08 17:26:52 +02:00
|
|
|
}
|
2005-06-12 15:14:46 +02:00
|
|
|
display_sidebox($appname,$title,$file);
|
2005-02-23 12:48:59 +01:00
|
|
|
}
|
|
|
|
|
2013-10-03 11:23:18 +02:00
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['admin'])
|
2005-02-23 12:48:59 +01:00
|
|
|
{
|
|
|
|
$file = Array(
|
2016-05-05 22:22:04 +02:00
|
|
|
'Site Configuration' => Egw::link('/index.php','menuaction=admin.admin_config.index&appname=' . $appname.'&ajax=true'),
|
|
|
|
'Global Categories' => Egw::link('/index.php',array(
|
2011-06-21 23:14:51 +02:00
|
|
|
'menuaction' => 'admin.admin_categories.index',
|
2005-02-23 12:48:59 +01:00
|
|
|
'appname' => $appname,
|
2016-06-29 17:54:06 +02:00
|
|
|
'global_cats'=> true,
|
|
|
|
'ajax' => 'true'
|
|
|
|
)),
|
2016-05-05 22:22:04 +02:00
|
|
|
'Configure Access Permissions' => Egw::link('/index.php',
|
2016-05-26 23:32:00 +02:00
|
|
|
'menuaction=resources.resources_acl_ui.index&ajax=true'),
|
2010-06-04 13:37:38 +02:00
|
|
|
'Custom Fields'=>egw::link('/index.php',
|
2017-01-17 18:24:56 +01:00
|
|
|
'menuaction=admin.admin_customfields.index&appname=resources&ajax=true'),
|
2005-02-23 12:48:59 +01:00
|
|
|
);
|
|
|
|
if ($location == 'admin')
|
|
|
|
{
|
|
|
|
display_section($appname,$file);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
display_sidebox($appname,lang('Admin'),$file);
|
|
|
|
}
|
|
|
|
}
|
2005-02-25 09:55:37 +01:00
|
|
|
}
|
2008-04-20 21:37:12 +02:00
|
|
|
|
2005-02-25 09:55:37 +01:00
|
|
|
function search_link($args)
|
|
|
|
{
|
2005-06-12 11:56:49 +02:00
|
|
|
return array(
|
2011-03-23 16:25:59 +01:00
|
|
|
'query' => 'resources.resources_bo.link_query',
|
|
|
|
'title' => 'resources.resources_bo.link_title',
|
|
|
|
'titles' => 'resources.resources_bo.link_titles',
|
2009-09-29 12:02:09 +02:00
|
|
|
'view' => array(
|
2012-11-26 22:04:31 +01:00
|
|
|
'menuaction' => 'resources.resources_ui.edit'
|
2005-11-11 22:21:50 +01:00
|
|
|
),
|
2009-09-29 12:02:09 +02:00
|
|
|
'view_id' => 'res_id',
|
2005-11-11 22:21:50 +01:00
|
|
|
'view_popup' => '850x600',
|
2011-03-23 16:25:59 +01:00
|
|
|
'view_list' => 'resources.resources_ui.index',
|
2005-11-11 22:21:50 +01:00
|
|
|
'add' => array(
|
2011-03-23 16:25:59 +01:00
|
|
|
'menuaction' => 'resources.resources_ui.edit',
|
2005-11-11 22:21:50 +01:00
|
|
|
),
|
|
|
|
'add_app' => 'link_app',
|
2008-04-20 21:37:12 +02:00
|
|
|
'add_id' => 'link_id',
|
2005-11-11 22:21:50 +01:00
|
|
|
'add_popup' => '800x600',
|
2009-09-20 11:47:48 +02:00
|
|
|
'find_extra' => array('name_preg' => '/^(?(?=^.picture.jpg$)|.+)$/'), // remove pictures from regular attachment list
|
2005-02-25 12:15:27 +01:00
|
|
|
);
|
2005-02-23 12:48:59 +01:00
|
|
|
}
|
2005-06-11 14:59:11 +02:00
|
|
|
|
2005-06-12 09:15:13 +02:00
|
|
|
function calendar_resources($args)
|
2005-06-11 14:59:11 +02:00
|
|
|
{
|
2008-04-20 21:37:12 +02:00
|
|
|
return array(
|
2016-07-19 22:09:58 +02:00
|
|
|
'search' => 'resources_bo::calendar_search',// method to use for the selection of resources, otherwise Link system is used
|
2011-03-23 16:25:59 +01:00
|
|
|
'info' => 'resources.resources_bo.get_calendar_info',// info method, returns array with id, type & name for a given id
|
2005-09-20 23:54:08 +02:00
|
|
|
'max_quantity' => 'useable',// if set, key for max. quantity in array returned by info method
|
2011-03-23 16:25:59 +01:00
|
|
|
'new_status' => 'resources.resources_bo.get_calendar_new_status',// method returning the status for new items, else 'U' is used
|
2005-09-20 23:54:08 +02:00
|
|
|
'type' => 'r',// one char type-identifiy for this resources
|
2008-04-20 21:37:12 +02:00
|
|
|
'icon' => 'calicon',//icon
|
2005-09-20 23:54:08 +02:00
|
|
|
'participants_header' => lang('resources'), // header of participants from this type
|
2018-10-01 18:25:55 +02:00
|
|
|
'check_invite' => 'resources_acl_bo::check_calendar_invite' // Check that the current user is allowed to invite the givent resource
|
2005-06-11 21:28:57 +02:00
|
|
|
);
|
2005-06-11 14:59:11 +02:00
|
|
|
}
|
2011-01-07 23:31:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle deleted category
|
|
|
|
*
|
|
|
|
* Resources' ACL _requires_ a category.
|
|
|
|
* Moves all resources to parent, if it exists. If it doesn't, another category is created.
|
|
|
|
*/
|
2012-11-26 22:04:31 +01:00
|
|
|
function delete_category($args)
|
2011-01-07 23:31:59 +01:00
|
|
|
{
|
2016-05-05 22:22:04 +02:00
|
|
|
$cat = Api\Categories::read($args['cat_id']);
|
2011-01-07 23:31:59 +01:00
|
|
|
|
|
|
|
if(!$cat) return; // Can't find current cat?
|
|
|
|
|
|
|
|
if($cat['parent'] == 0)
|
|
|
|
{
|
|
|
|
// No parent, try the default cat from setup
|
2016-05-05 22:22:04 +02:00
|
|
|
$categories = new Api\Categories('', 'resources');
|
2011-01-07 23:31:59 +01:00
|
|
|
$default = $categories->name2id('General resources');
|
|
|
|
if($default)
|
|
|
|
{
|
|
|
|
$new_cat_id = $default;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Default missing, look for 'No category'
|
|
|
|
$new_cat_id = $categories->name2id('No category');
|
|
|
|
if($new_cat_id == 0) {
|
|
|
|
// No category not there, add it
|
|
|
|
$new_cat_id = $categories->add(array(
|
|
|
|
'name' => 'No category',
|
|
|
|
'description' => 'This category has been added to rescue resources whose category was deleted.',
|
|
|
|
'parent' => 0
|
|
|
|
));
|
|
|
|
$admin = -2;
|
2016-05-26 23:32:00 +02:00
|
|
|
resources_acl_bo::set_rights($new_cat_id, array($admin), array($admin), array($admin), array($admin),array($admin));
|
2011-01-07 23:31:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$new_cat_id = $cat['parent'];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get any resources affected
|
|
|
|
$query = array('filter' => $args['cat_id']);
|
2011-03-23 16:25:59 +01:00
|
|
|
$bo = new resources_bo();
|
2011-01-07 23:31:59 +01:00
|
|
|
$bo->get_rows($query, $resources, $readonly);
|
2016-04-24 15:53:24 +02:00
|
|
|
|
2011-01-07 23:31:59 +01:00
|
|
|
foreach($resources as $resource)
|
|
|
|
{
|
2015-01-27 23:43:17 +01:00
|
|
|
if(is_array($resource))
|
|
|
|
{
|
|
|
|
$resource['cat_id'] = $new_cat_id;
|
|
|
|
$bo->save($resource);
|
|
|
|
}
|
2011-01-07 23:31:59 +01:00
|
|
|
}
|
|
|
|
}
|
2011-03-28 17:37:26 +02:00
|
|
|
|
2013-10-03 11:23:18 +02:00
|
|
|
/**
|
2016-05-05 22:22:04 +02:00
|
|
|
* Hook to tell framework we use only global Api\Categories (return link data in that case and false otherwise)
|
2013-10-03 11:23:18 +02:00
|
|
|
*
|
|
|
|
* @param string|array $data hook-data or location
|
|
|
|
* @return boolean|array
|
|
|
|
*/
|
|
|
|
public static function categories($data)
|
|
|
|
{
|
|
|
|
if ($GLOBALS['egw_info']['user']['apps']['admin'])
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
'menuaction' => 'admin.admin_categories.index',
|
|
|
|
'appname' => $appname,
|
|
|
|
'global_cats'=> true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2005-02-23 12:48:59 +01:00
|
|
|
}
|