2005-02-03 17:42:20 +01:00
|
|
|
<?php
|
2005-11-11 00:35:55 +01:00
|
|
|
/**
|
|
|
|
* eGroupWare - resources
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package resources
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
|
|
|
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
|
|
|
|
* @version $Id$
|
|
|
|
*/
|
2005-11-09 22:03:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* General business object for resources
|
|
|
|
*
|
|
|
|
* @package resources
|
|
|
|
*/
|
2005-02-03 17:42:20 +01:00
|
|
|
class bo_resources
|
|
|
|
{
|
2005-02-15 17:26:21 +01:00
|
|
|
var $vfs_basedir = '/resources/';
|
|
|
|
var $pictures_dir = '/resources/pictures/';
|
|
|
|
var $thumbs_dir = '/resources/pictures/thumbs/';
|
2005-02-17 09:04:55 +01:00
|
|
|
var $resource_icons = '/resources/templates/default/images/resource_icons/';
|
2005-06-13 14:21:18 +02:00
|
|
|
var $debug = 0;
|
2007-06-25 18:43:32 +02:00
|
|
|
/**
|
|
|
|
* Instance of resources so object
|
|
|
|
*
|
|
|
|
* @var so_resources
|
|
|
|
*/
|
|
|
|
var $so;
|
2005-02-03 17:42:20 +01:00
|
|
|
|
|
|
|
function bo_resources()
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
$this->so =& CreateObject('resources.so_resources');
|
|
|
|
$this->acl =& CreateObject('resources.bo_acl');
|
2005-02-16 11:26:22 +01:00
|
|
|
$this->cats = $this->acl->egw_cats;
|
2005-06-10 22:40:57 +02:00
|
|
|
$this->vfs =& CreateObject('phpgwapi.vfs');
|
2005-10-01 23:12:36 +02:00
|
|
|
$this->link =& CreateObject('phpgwapi.bolink');
|
2005-06-10 22:40:57 +02:00
|
|
|
$this->conf =& CreateObject('phpgwapi.config');
|
2005-03-01 11:58:04 +01:00
|
|
|
$this->conf->read_repository();
|
|
|
|
|
2005-06-29 11:30:08 +02:00
|
|
|
$this->cal_right_transform = array(
|
|
|
|
EGW_ACL_CALREAD => EGW_ACL_READ,
|
|
|
|
EGW_ACL_DIRECT_BOOKING => EGW_ACL_READ | EGW_ACL_ADD | EGW_ACL_EDIT | EGW_ACL_DELETE,
|
|
|
|
EGW_ACL_CAT_ADMIN => EGW_ACL_READ | EGW_ACL_ADD | EGW_ACL_EDIT | EGW_ACL_DELETE,
|
2005-06-12 11:54:29 +02:00
|
|
|
);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* get rows for 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
|
|
|
*/
|
2005-02-03 17:42:20 +01:00
|
|
|
function get_rows($query,&$rows,&$readonlys)
|
|
|
|
{
|
2005-06-13 14:21:18 +02:00
|
|
|
if ($this->debug) _debug_array($query);
|
2005-02-03 17:42:20 +01:00
|
|
|
$query['search'] = $query['search'] ? $query['search'] : '*';
|
2006-03-29 21:56:18 +02:00
|
|
|
$criteria = array('name' => $query['search'], 'short_description' => $query['search'], 'inventory_number' => $query['search']);
|
2005-06-29 11:30:08 +02:00
|
|
|
$read_onlys = 'res_id,name,short_description,quantity,useable,bookable,buyable,cat_id,location,storage_info';
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-06-11 16:11:57 +02:00
|
|
|
$accessory_of = $query['view_accs_of'] ? $query['view_accs_of'] : -1;
|
|
|
|
$filter = array('accessory_of' => $accessory_of);
|
2005-06-13 14:21:18 +02:00
|
|
|
if ($query['filter'])
|
|
|
|
{
|
|
|
|
$filter = $filter + array('cat_id' => $query['filter']);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$readcats = array_flip((array)$this->acl->get_cats(EGW_ACL_READ));
|
|
|
|
if($readcats) $filter = $filter + array('cat_id' => $readcats);
|
|
|
|
}
|
2005-06-11 18:14:11 +02:00
|
|
|
if($query['show_bookable']) $filter = $filter + array('bookable' => true);
|
2005-02-03 17:42:20 +01:00
|
|
|
$order_by = $query['order'] ? $query['order'].' '. $query['sort'] : '';
|
2005-06-11 14:59:11 +02:00
|
|
|
$start = (int)$query['start'];
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2007-05-04 13:37:19 +02:00
|
|
|
$rows = $this->so->search($criteria,$read_onlys,$order_by,'','%',$empty=False,$op='OR',$start,$filter,$join='',$need_full_no_count=false);
|
2005-06-11 14:59:11 +02:00
|
|
|
$nr = $this->so->total;
|
2005-02-28 16:19:31 +01:00
|
|
|
|
2005-09-06 23:45:37 +02:00
|
|
|
// we are called to serve bookable resources (e.g. calendar-dialog)
|
|
|
|
if($query['show_bookable'])
|
|
|
|
{
|
|
|
|
// This is somehow ugly, i know...
|
2006-01-20 08:10:18 +01:00
|
|
|
foreach((array)$rows as $num => $resource)
|
2005-09-06 23:45:37 +02:00
|
|
|
{
|
|
|
|
$rows[$num]['default_qty'] = 1;
|
|
|
|
}
|
|
|
|
// we don't need all the following testing
|
|
|
|
return $nr;
|
|
|
|
}
|
2005-06-11 17:19:47 +02:00
|
|
|
|
2005-06-11 16:11:57 +02:00
|
|
|
foreach((array)$rows as $num => $resource)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
if (!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_EDIT))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["edit[$resource[res_id]]"] = true;
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-06-10 22:40:57 +02:00
|
|
|
if (!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_DELETE))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["delete[$resource[res_id]]"] = true;
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-06-10 22:40:57 +02:00
|
|
|
if ((!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_ADD)) || $accessory_of != -1)
|
2005-02-28 16:19:31 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["new_acc[$resource[res_id]]"] = true;
|
2005-02-28 16:19:31 +01:00
|
|
|
}
|
2007-02-25 21:04:41 +01:00
|
|
|
if (!$resource['bookable'])
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["bookable[$resource[res_id]]"] = true;
|
2005-10-19 00:07:12 +02:00
|
|
|
$readonlys["calendar[$resource[res_id]]"] = true;
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2007-02-25 21:04:41 +01:00
|
|
|
if(!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_CALREAD))
|
|
|
|
{
|
|
|
|
$readonlys["calendar[$resource[res_id]]"] = true;
|
|
|
|
}
|
2005-02-17 15:42:34 +01:00
|
|
|
if (!$resource['buyable'])
|
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["buyable[$resource[res_id]]"] = true;
|
2005-02-17 15:42:34 +01:00
|
|
|
}
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["view_acc[$resource[res_id]]"] = true;
|
|
|
|
$links = $this->link->get_links('resources',$resource['res_id']);
|
2005-10-11 13:59:15 +02:00
|
|
|
if(count($links) != 0 && $accessory_of == -1)
|
2005-02-25 14:18:40 +01:00
|
|
|
{
|
|
|
|
foreach ($links as $link_num => $link)
|
|
|
|
{
|
|
|
|
if($link['app'] == 'resources')
|
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
if($this->so->get_value('accessory_of',$link['res_id']) != -1)
|
2005-02-25 14:18:40 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$readonlys["view_acc[$resource[res_id]]"] = false;
|
2005-02-25 14:18:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-06-29 11:30:08 +02:00
|
|
|
$rows[$num]['picture_thumb'] = $this->get_picture($resource['res_id']);
|
2005-02-20 19:01:52 +01:00
|
|
|
$rows[$num]['admin'] = $this->acl->get_cat_admin($resource['cat_id']);
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
return $nr;
|
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* reads a resource exept binary datas
|
|
|
|
*
|
2005-06-13 11:18:06 +02:00
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-29 11:30:08 +02:00
|
|
|
* @param int $res_id resource id
|
2005-06-10 22:40:57 +02:00
|
|
|
* @return array with key => value or false if not found or allowed
|
|
|
|
*/
|
2005-06-29 11:30:08 +02:00
|
|
|
function read($res_id)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
if(!$this->acl->is_permitted($this->so->get_value('cat_id',$res_id),EGW_ACL_READ))
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
|
|
|
echo lang('You are not permitted to get information about this resource!') . '<br>';
|
|
|
|
echo lang('Notify your administrator to correct this situation') . '<br>';
|
|
|
|
return false;
|
|
|
|
}
|
2005-06-29 11:30:08 +02:00
|
|
|
return $this->so->read(array('res_id' => $res_id));
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* saves a resource. pictures are saved in vfs
|
|
|
|
*
|
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 $resource array with key => value of all needed datas
|
|
|
|
* @return string msg if somthing went wrong; nothing if all right
|
|
|
|
*/
|
2005-02-12 09:25:26 +01:00
|
|
|
function save($resource)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
if(!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_EDIT))
|
2005-02-12 16:49:38 +01:00
|
|
|
{
|
|
|
|
return lang('You are not permitted to edit this reource!');
|
|
|
|
}
|
|
|
|
|
2005-02-24 19:24:26 +01:00
|
|
|
// we need an id to save pictures and make links...
|
2005-06-29 11:30:08 +02:00
|
|
|
if(!$resource['res_id'])
|
2005-02-15 17:26:21 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$resource['res_id'] = $this->so->save($resource);
|
2005-02-15 17:26:21 +01:00
|
|
|
}
|
|
|
|
|
2005-02-17 10:53:46 +01:00
|
|
|
switch ($resource['picture_src'])
|
2005-02-12 09:25:26 +01:00
|
|
|
{
|
2005-02-17 10:53:46 +01:00
|
|
|
case 'own_src':
|
2005-06-29 11:30:08 +02:00
|
|
|
$vfs_data = array('string' => $this->pictures_dir.$resource['res_id'].'.jpg','relatives' => array(RELATIVE_ROOT));
|
2005-02-17 10:53:46 +01:00
|
|
|
if($resource['own_file']['size'] > 0)
|
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$msg = $this->save_picture($resource['own_file'],$resource['res_id']);
|
2005-02-17 10:53:46 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
elseif($this->vfs->file_exists($vfs_data))
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$resource['picture_src'] = 'cat_src';
|
|
|
|
case 'cat_src':
|
|
|
|
break;
|
|
|
|
case 'gen_src':
|
2005-02-17 12:17:19 +01:00
|
|
|
$resource['picture_src'] = $resource['gen_src_list'];
|
2005-02-17 10:53:46 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if($resource['own_file']['size'] > 0)
|
|
|
|
{
|
|
|
|
$resource['picture_src'] = 'own_src';
|
2005-06-29 11:30:08 +02:00
|
|
|
$msg = $this->save_picture($resource['own_file'],$resource['res_id']);
|
2005-02-17 10:53:46 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$resource['picture_src'] = 'cat_src';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// somthing went wrong on saving own picture
|
|
|
|
if($msg)
|
|
|
|
{
|
|
|
|
return $msg;
|
2005-02-12 09:25:26 +01:00
|
|
|
}
|
|
|
|
|
2005-02-17 10:53:46 +01:00
|
|
|
// delete old pictures
|
|
|
|
if($resource['picture_src'] != 'own_src')
|
2005-02-12 09:25:26 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$this->remove_picture($resource['res_id']);
|
2005-02-12 09:25:26 +01:00
|
|
|
}
|
2005-02-24 19:24:26 +01:00
|
|
|
|
|
|
|
// save links
|
|
|
|
if(is_array($resource['link_to']['to_id']))
|
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$this->link->link('resources',$resource['res_id'],$resource['link_to']['to_id']);
|
2005-02-24 19:24:26 +01:00
|
|
|
}
|
2005-02-28 16:19:31 +01:00
|
|
|
if($resource['accessory_of'] != -1)
|
2005-11-03 23:48:30 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$this->link->link('resources',$resource['res_id'],'resources',$resource['accessory_of']);
|
2005-02-28 16:19:31 +01:00
|
|
|
}
|
2005-02-12 16:49:38 +01:00
|
|
|
|
2005-11-03 23:48:30 +01:00
|
|
|
if(!empty($resource['res_id']) && $this->so->get_value("cat_id",$resource['res_id']) != $resource['cat_id'] && $resource['accessory_of'] == -1)
|
|
|
|
{
|
|
|
|
$accessories = $this->get_acc_list($resource['res_id']);
|
|
|
|
foreach($accessories as $accessory => $name)
|
|
|
|
{
|
|
|
|
$acc = $this->so->read($accessory);
|
|
|
|
$acc['cat_id'] = $resource['cat_id'];
|
|
|
|
$this->so->data = $acc;
|
|
|
|
$this->so->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-12 16:49:38 +01:00
|
|
|
return $this->so->save($resource) ? false : lang('Something went wrong by saving resource');
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* deletes resource including pictures and links
|
|
|
|
*
|
|
|
|
* @author Lukas Weiss <wnz_gh05t@users.sourceforge.net>
|
2005-06-29 11:30:08 +02:00
|
|
|
* @param int $res_id id of resource
|
2005-06-10 22:40:57 +02:00
|
|
|
*/
|
2005-06-29 11:30:08 +02:00
|
|
|
function delete($res_id)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-12-04 23:06:02 +01:00
|
|
|
if(!$this->acl->is_permitted($this->so->get_value('cat_id',$res_id),EGW_ACL_DELETE))
|
|
|
|
{
|
|
|
|
return lang('You are not permitted to delete this reource!');
|
|
|
|
}
|
|
|
|
|
2005-10-08 13:06:58 +02:00
|
|
|
if ($this->so->delete(array('res_id'=>$res_id)))
|
|
|
|
{
|
|
|
|
$this->remove_picture($res_id);
|
|
|
|
$this->link->unlink(0,'resources',$res_id);
|
|
|
|
// delete the resource from the calendar
|
|
|
|
ExecMethod('calendar.socal.change_delete_user','r'.$res_id);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return lang('Something went wrong by deleting resource');
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-02-24 14:10:57 +01:00
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* gets list of accessories for resource
|
|
|
|
*
|
2005-06-13 11:18:06 +02:00
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-29 11:30:08 +02:00
|
|
|
* @param int $res_id id of resource
|
2005-06-10 22:40:57 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
2005-06-29 11:30:08 +02:00
|
|
|
function get_acc_list($res_id)
|
2005-02-24 14:10:57 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
if($res_id < 1){return;}
|
|
|
|
$data = $this->so->search('','res_id,name','','','','','',$start,array('accessory_of' => $res_id),'',$need_full_no_count=true);
|
2005-02-24 14:10:57 +01:00
|
|
|
foreach($data as $num => $resource)
|
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$acc_list[$resource['res_id']] = $resource['name'];
|
2005-02-24 14:10:57 +01:00
|
|
|
}
|
|
|
|
return $acc_list;
|
|
|
|
}
|
2005-06-11 14:59:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* returns info about resource for calender
|
2005-09-06 23:45:37 +02:00
|
|
|
* @author Cornelius Weiss<egw@von-und-zu-weiss.de>
|
2005-06-11 14:59:11 +02:00
|
|
|
* @param int/array $res_id single id or array $num => $res_id
|
|
|
|
* @return array
|
|
|
|
*/
|
2005-06-12 10:01:19 +02:00
|
|
|
function get_calendar_info($res_id)
|
2005-06-11 14:59:11 +02:00
|
|
|
{
|
2005-10-08 13:06:58 +02:00
|
|
|
//echo "<p>bo_resources::get_calendar_info(".print_r($res_id,true).")</p>\n";
|
2005-06-12 12:05:39 +02:00
|
|
|
if(!is_array($res_id) && $res_id < 1) return;
|
|
|
|
|
2005-06-29 11:30:08 +02:00
|
|
|
$data = $this->so->search(array('res_id' => $res_id),'res_id,cat_id,name,useable');
|
2005-06-12 11:54:29 +02:00
|
|
|
|
2005-06-12 10:16:12 +02:00
|
|
|
foreach($data as $num => $resource)
|
|
|
|
{
|
2005-06-12 12:05:39 +02:00
|
|
|
$data[$num]['rights'] = false;
|
2005-06-12 11:54:29 +02:00
|
|
|
foreach($this->cal_right_transform as $res_right => $cal_right)
|
|
|
|
{
|
2005-06-12 12:05:39 +02:00
|
|
|
if($this->acl->is_permitted($resource['cat_id'],$res_right))
|
2005-06-12 11:54:29 +02:00
|
|
|
{
|
2005-06-12 12:05:39 +02:00
|
|
|
$data[$num]['rights'] = $cal_right;
|
2005-06-12 11:54:29 +02:00
|
|
|
}
|
|
|
|
}
|
2005-06-12 12:05:39 +02:00
|
|
|
$data[$num]['responsible'] = $this->acl->get_cat_admin($resource['cat_id']);
|
2005-06-12 10:16:12 +02:00
|
|
|
}
|
2005-06-12 12:05:39 +02:00
|
|
|
return $data;
|
2005-06-11 14:59:11 +02:00
|
|
|
}
|
|
|
|
|
2005-06-12 10:56:19 +02:00
|
|
|
/**
|
|
|
|
* returns status for a new calendar entry depending on resources ACL
|
2005-06-13 11:18:06 +02:00
|
|
|
* @author Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-07-01 17:01:07 +02:00
|
|
|
* @param int $res_id single id
|
2005-06-12 10:56:19 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function get_calendar_new_status($res_id)
|
|
|
|
{
|
2005-07-01 17:01:07 +02:00
|
|
|
$data = $this->so->search(array('res_id' => $res_id),'res_id,cat_id,bookable');
|
|
|
|
if($data[0]['bookable'] == 0) return 'x';
|
|
|
|
return $this->acl->is_permitted($data[0]['cat_id'],EGW_ACL_DIRECT_BOOKING) ? A : U;
|
2005-06-12 10:56:19 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
* query infolog for entries matching $pattern
|
|
|
|
*
|
|
|
|
*/
|
2005-02-25 12:15:27 +01:00
|
|
|
function link_query( $pattern )
|
|
|
|
{
|
2006-06-27 18:30:53 +02:00
|
|
|
$criteria = array('name' => $pattern, 'short_description' => $pattern);
|
2005-06-29 11:30:08 +02:00
|
|
|
$only_keys = 'res_id,name,short_description';
|
2006-06-27 18:30:53 +02:00
|
|
|
$filter = array(
|
|
|
|
'cat_id' => array_flip((array)$this->acl->get_cats(EGW_ACL_READ)),
|
|
|
|
//'accessory_of' => '-1'
|
|
|
|
);
|
2007-06-25 18:43:32 +02:00
|
|
|
$data = $this->so->search($criteria,$only_keys,$order_by='',$extra_cols='',$wildcard='%',$empty,$op='OR',false,$filter);
|
2005-02-25 12:15:27 +01:00
|
|
|
foreach($data as $num => $resource)
|
|
|
|
{
|
2007-04-26 22:50:14 +02:00
|
|
|
$list[$resource['res_id']] = $resource['name']. ($resource['short_description'] ? ', ['.$resource['short_description'].']':'');
|
2005-02-25 09:55:37 +01:00
|
|
|
}
|
2005-02-25 12:15:27 +01:00
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
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-29 11:30:08 +02:00
|
|
|
* get title for an infolog entry identified by $res_id
|
2005-06-10 22:40:57 +02:00
|
|
|
*
|
2006-06-24 18:12:56 +02:00
|
|
|
* @return string/boolean string with title, null if resource does not exist or false if no perms to view it
|
2005-06-10 22:40:57 +02:00
|
|
|
*/
|
2005-02-25 12:15:27 +01:00
|
|
|
function link_title( $resource )
|
|
|
|
{
|
2006-06-24 18:12:56 +02:00
|
|
|
if (!is_array($resource))
|
2005-02-25 12:15:27 +01:00
|
|
|
{
|
2006-06-24 18:12:56 +02:00
|
|
|
if (!($resource = $this->so->read(array('res_id' => $resource)))) return null;
|
2005-02-25 12:15:27 +01:00
|
|
|
}
|
2006-06-27 18:30:53 +02:00
|
|
|
if(!$this->acl->is_permitted($resource['cat_id'],EGW_ACL_READ)) return false;
|
|
|
|
|
2006-06-24 18:12:56 +02:00
|
|
|
return $resource['name']. ($resource['short_description'] ? ', ['.$resource['short_description'].']':'');
|
2005-02-25 12:15:27 +01:00
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* resizes and saves an pictures in vfs
|
|
|
|
*
|
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 $file array with key => value
|
|
|
|
* @param int $resource_id
|
|
|
|
* @return mixed string with msg if somthing went wrong; nothing if all right
|
|
|
|
* TODO make thumb an picture sizes choosable by preferences
|
|
|
|
*/
|
2005-02-16 11:26:22 +01:00
|
|
|
function save_picture($file,$resouce_id)
|
|
|
|
{
|
|
|
|
// test upload dir
|
|
|
|
$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);
|
|
|
|
$vfs_data['string'] = $this->pictures_dir;
|
|
|
|
$this->vfs->mkdir($vfs_data);
|
|
|
|
$vfs_data['string'] = $this->thumbs_dir;
|
|
|
|
$this->vfs->mkdir($vfs_data);
|
|
|
|
$this->vfs->override_acl = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch($file['type'])
|
|
|
|
{
|
|
|
|
case 'image/gif':
|
|
|
|
$src_img = imagecreatefromgif($file['tmp_name']);
|
|
|
|
break;
|
|
|
|
case 'image/jpeg':
|
|
|
|
case 'image/pjpeg':
|
|
|
|
$src_img = imagecreatefromjpeg($file['tmp_name']);
|
|
|
|
break;
|
|
|
|
case 'image/png':
|
|
|
|
case 'image/x-png':
|
|
|
|
$src_img = imagecreatefrompng($file['tmp_name']);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return lang('Picture type is not supported, sorry!');
|
|
|
|
}
|
|
|
|
|
2005-02-22 20:02:07 +01:00
|
|
|
$src_img_size = getimagesize($file['tmp_name']);
|
|
|
|
$dst_img_size = array( 0 => 320, 1 => 240);
|
|
|
|
$thumb_size = array( 0 => 64, 1 => 48);
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
$tmp_dir = $GLOBALS['egw_info']['server']['temp_dir'].'/';
|
2005-02-22 20:02:07 +01:00
|
|
|
if($src_img_size[0] > 64 || $src_img_size[1] > 48)
|
2005-02-16 11:26:22 +01:00
|
|
|
{
|
2005-02-22 20:02:07 +01:00
|
|
|
$f = $thumb_size[0] / $src_img_size[0];
|
|
|
|
$f = $thumb_size[1] / $src_img_size[1] < $f ? $thumb_size[1] / $src_img_size[1] : $f;
|
|
|
|
$dst_img = imagecreatetruecolor($src_img_size[0] * $f, $src_img_size[1] * $f);
|
|
|
|
imagecopyresized($dst_img,$src_img,0,0,0,0,$src_img_size[0] * $f,$src_img_size[1] * $f,$src_img_size[0],$src_img_size[1]);
|
2005-02-16 11:26:22 +01:00
|
|
|
imagejpeg($dst_img,$tmp_dir.$resouce_id.'.thumb.jpg');
|
2005-02-22 20:02:07 +01:00
|
|
|
if($src_img_size[0] > $dst_img_size[0] || $src_img_size[1] > $dst_img_size[1])
|
2005-02-16 11:26:22 +01:00
|
|
|
{
|
2005-02-22 20:02:07 +01:00
|
|
|
$f = $dst_img_size[0] / $src_img_size[0];
|
|
|
|
$f = $dst_img_size[1] / $src_img_size[1] < $f ? $dst_img_size[1] / $src_img_size[1] : $f;
|
|
|
|
$dst_img = imagecreatetruecolor($src_img_size[0] * $f, $src_img_size[1] * $f);
|
|
|
|
imagecopyresized($dst_img,$src_img,0,0,0,0,$src_img_size[0] * $f,$src_img_size[1] * $f,$src_img_size[0],$src_img_size[1]);
|
2005-02-16 11:26:22 +01:00
|
|
|
imagejpeg($dst_img,$tmp_dir.$resouce_id.'.jpg');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imagejpeg($src_img,$tmp_dir.$resouce_id.'.jpg');
|
|
|
|
}
|
|
|
|
imagedestroy($dst_img);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imagejpeg($src_img,$tmp_dir.$resouce_id.'.jpg');
|
|
|
|
imagejpeg($src_img,$tmp_dir.$resouce_id.'.thumb.jpg');
|
|
|
|
}
|
|
|
|
imagedestroy($src_img);
|
|
|
|
|
|
|
|
$this->vfs->override_acl = 1;
|
2005-10-11 13:59:15 +02:00
|
|
|
$this->vfs->cp(array(
|
2005-02-16 11:26:22 +01:00
|
|
|
'from' => $tmp_dir.$resouce_id.'.jpg',
|
|
|
|
'to' => $this->pictures_dir.$resouce_id.'.jpg',
|
|
|
|
'relatives' => array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)
|
|
|
|
));
|
|
|
|
$this->vfs->set_attributes(array(
|
|
|
|
'string' => $this->pictures_dir.$resouce_id.'.jpg',
|
|
|
|
'relatives' => array (RELATIVE_ROOT),
|
|
|
|
'attributes' => array (
|
|
|
|
'mime_type' => 'image/jpeg',
|
|
|
|
'comment' => 'picture of resource no.'.$resouce_id,
|
2005-06-10 22:40:57 +02:00
|
|
|
'app' => $GLOBALS['egw_info']['flags']['currentapp']
|
2005-02-16 11:26:22 +01:00
|
|
|
)));
|
2005-10-11 13:59:15 +02:00
|
|
|
$this->vfs->cp(array(
|
2005-02-16 11:26:22 +01:00
|
|
|
'from' => $tmp_dir.$resouce_id.'.thumb.jpg',
|
|
|
|
'to' => $this->thumbs_dir.$resouce_id.'.jpg',
|
|
|
|
'relatives' => array(RELATIVE_NONE|VFS_REAL,RELATIVE_ROOT)
|
|
|
|
));
|
|
|
|
$this->vfs->set_attributes(array(
|
|
|
|
'string' => $this->thumbs_dir.$resouce_id.'.jpg',
|
|
|
|
'relatives' => array (RELATIVE_ROOT),
|
|
|
|
'attributes' => array (
|
|
|
|
'mime_type' => 'image/jpeg',
|
|
|
|
'comment' => 'thumbnail of resource no.'.$resouce_id,
|
2005-06-10 22:40:57 +02:00
|
|
|
'app' => $GLOBALS['egw_info']['flags']['currentapp']
|
2005-02-16 11:26:22 +01:00
|
|
|
)));
|
|
|
|
$this->vfs->override_acl = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* get resource picture either from vfs or from symlink
|
2005-06-13 11:18:06 +02:00
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-29 11:30:08 +02:00
|
|
|
* @param int $res_id id of resource
|
2005-06-10 22:40:57 +02:00
|
|
|
* @param bool $size false = thumb, true = full pic
|
|
|
|
* @return string url of picture
|
|
|
|
*/
|
2005-06-29 11:30:08 +02:00
|
|
|
function get_picture($res_id=0,$size=false)
|
2005-02-14 13:03:06 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
if ($res_id > 0)
|
2005-02-17 12:17:19 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$src = $this->so->get_value('picture_src',$res_id);
|
2005-02-17 12:17:19 +01:00
|
|
|
}
|
2005-02-16 15:50:17 +01:00
|
|
|
switch($src)
|
2005-02-03 17:42:20 +01:00
|
|
|
{
|
2005-02-16 15:50:17 +01:00
|
|
|
case 'own_src':
|
2005-06-10 22:40:57 +02:00
|
|
|
$picture = $this->conf->config_data['dont_use_vfs'] ? $GLOBALS['egw_info']['server']['webserver_url'] : 'vfs:';
|
2005-06-29 11:30:08 +02:00
|
|
|
$picture .= $size ? $this->pictures_dir.$res_id.'.jpg' : $this->thumbs_dir.$res_id.'.jpg';
|
2005-02-16 15:50:17 +01:00
|
|
|
break;
|
|
|
|
case 'cat_src':
|
2005-06-29 11:30:08 +02:00
|
|
|
list($picture) = $this->cats->return_single($this->so->get_value('cat_id',$res_id));
|
2005-02-17 09:04:55 +01:00
|
|
|
$picture = unserialize($picture['data']);
|
2005-02-17 10:53:46 +01:00
|
|
|
if($picture['icon'])
|
|
|
|
{
|
2005-06-10 22:40:57 +02:00
|
|
|
$picture = $GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/images/'.$picture['icon'];
|
2005-02-17 10:53:46 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-02-17 09:04:55 +01:00
|
|
|
case 'gen_src':
|
2005-02-16 15:50:17 +01:00
|
|
|
default :
|
2005-06-10 22:40:57 +02:00
|
|
|
$picture = $GLOBALS['egw_info']['server']['webserver_url'].$this->resource_icons;
|
2007-05-09 10:07:06 +02:00
|
|
|
$picture .= strpos($src,'.') !== false ? $src : 'generic.png';
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-02-16 15:50:17 +01:00
|
|
|
return $picture;
|
2005-02-03 17:42:20 +01:00
|
|
|
}
|
2005-02-17 10:53:46 +01:00
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* remove_picture
|
|
|
|
* removes picture from vfs
|
|
|
|
*
|
2005-06-13 11:18:06 +02:00
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-29 11:30:08 +02:00
|
|
|
* @param int $res_id id of resource
|
2005-06-10 22:40:57 +02:00
|
|
|
* @return bool succsess or not
|
|
|
|
*/
|
2005-06-29 11:30:08 +02:00
|
|
|
function remove_picture($res_id)
|
2005-02-17 10:53:46 +01:00
|
|
|
{
|
2005-06-29 11:30:08 +02:00
|
|
|
$vfs_data = array('string' => $this->pictures_dir.$res_id.'.jpg','relatives' => array(RELATIVE_ROOT));
|
2005-02-17 10:53:46 +01:00
|
|
|
$this->vfs->override_acl = 1;
|
|
|
|
if($this->vfs->file_exists($vfs_data))
|
|
|
|
{
|
|
|
|
$this->vfs->rm($vfs_data);
|
2005-06-29 11:30:08 +02:00
|
|
|
$vfs_data['string'] = $this->thumbs_dir.$res_id.'.jpg';
|
2005-02-17 10:53:46 +01:00
|
|
|
$this->vfs->rm($vfs_data);
|
|
|
|
}
|
|
|
|
$this->vfs->override_acl = 0;
|
|
|
|
}
|
2005-02-03 17:42:20 +01:00
|
|
|
|
2005-06-10 22:40:57 +02:00
|
|
|
/**
|
|
|
|
* get_genpicturelist
|
|
|
|
* gets all pictures from 'generic picutres dir' in selectbox style for eTemplate
|
|
|
|
*
|
2005-06-13 11:18:06 +02:00
|
|
|
* Cornelius Weiss <egw@von-und-zu-weiss.de>
|
2005-06-10 22:40:57 +02:00
|
|
|
* @return array directory contens in eTemplates selectbox style
|
|
|
|
*/
|
2005-02-17 12:17:19 +01:00
|
|
|
function get_genpicturelist()
|
|
|
|
{
|
|
|
|
$icons['generic.png'] = lang('gernal resource');
|
2005-06-10 22:40:57 +02:00
|
|
|
$dir = dir(EGW_SERVER_ROOT.$this->resource_icons);
|
2005-02-17 12:17:19 +01:00
|
|
|
while($file = $dir->read())
|
|
|
|
{
|
|
|
|
if (preg_match('/\\.(png|gif|jpe?g)$/i',$file) && $file != 'generic.png')
|
|
|
|
{
|
|
|
|
$icons[$file] = substr($file,0,strpos($file,'.'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$dir->close();
|
|
|
|
return $icons;
|
|
|
|
}
|
|
|
|
}
|