2005-02-03 17:42:20 +01:00
|
|
|
|
<?php
|
|
|
|
|
/**************************************************************************\
|
|
|
|
|
* eGroupWare - resources - Resource Management System *
|
|
|
|
|
* http://www.egroupware.org *
|
|
|
|
|
* Written by Lukas Weiss [ichLukas@gmx.net] and *
|
|
|
|
|
* Cornelius Weiss [nelius@gmx.net] *
|
|
|
|
|
* ----------------------------------------------- *
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify it *
|
|
|
|
|
* under the terms of the GNU General Public License as published by the *
|
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your *
|
|
|
|
|
* option) any later version. *
|
|
|
|
|
\**************************************************************************/
|
|
|
|
|
|
|
|
|
|
class bo_resources
|
|
|
|
|
{
|
|
|
|
|
/*var $public_functions = array
|
|
|
|
|
(
|
|
|
|
|
'get_rows' => True
|
|
|
|
|
);*/
|
|
|
|
|
|
|
|
|
|
function bo_resources()
|
|
|
|
|
{
|
|
|
|
|
$this->so = CreateObject('resources.so_resources');
|
|
|
|
|
$this->acl = CreateObject('resources.bo_acl');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
@function get_rows
|
|
|
|
|
@abstract get rows for resources list
|
|
|
|
|
@autor Cornelius Wei<EFBFBD> <egw@von-und-zu-weiss.de>
|
|
|
|
|
*/
|
|
|
|
|
function get_rows($query,&$rows,&$readonlys)
|
|
|
|
|
{
|
|
|
|
|
$query['search'] = $query['search'] ? $query['search'] : '*';
|
|
|
|
|
|
|
|
|
|
$criteria = array( 'name' => $query['search'],
|
|
|
|
|
'short_description' => $query['search']
|
|
|
|
|
);
|
|
|
|
|
$cats = $query['filter'] ? array($query['filter'] => '') : $this->acl->get_cats(PHPGW_ACL_READ);
|
|
|
|
|
|
|
|
|
|
$rows = array( 0 => array( 'id' => '',
|
|
|
|
|
'name' => '',
|
|
|
|
|
'short_description' => '',
|
|
|
|
|
'useable' => '',
|
|
|
|
|
'bookable' => '',
|
|
|
|
|
'cat_id' => '',
|
|
|
|
|
'location' => ''
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
$order_by = $query['order'] ? $query['order'].' '. $query['sort'] : '';
|
|
|
|
|
|
|
|
|
|
$nr = $this->so->search($criteria,$cats,&$rows,$order_by,$offset=$query['start'],$num_rows=0);
|
|
|
|
|
|
|
|
|
|
foreach($rows as $num => $resource)
|
|
|
|
|
{
|
|
|
|
|
if (!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_EDIT))
|
|
|
|
|
{
|
|
|
|
|
$readonlys["edit[$resource[id]]"] = true;
|
|
|
|
|
}
|
|
|
|
|
if (!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_DELETE))
|
|
|
|
|
{
|
|
|
|
|
$readonlys["delete[$resource[id]]"] = true;
|
|
|
|
|
}
|
|
|
|
|
if (!$resource['bookable'] /* && calender-acl viewable */)
|
|
|
|
|
{
|
|
|
|
|
$readonlys["bookable[$resource[id]]"] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $nr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
@function read
|
|
|
|
|
@abstract reads a resource exept binary datas
|
|
|
|
|
@param int $id resource id
|
|
|
|
|
@return array with key => value or false if not found or allowed
|
|
|
|
|
*/
|
|
|
|
|
function read($id)
|
|
|
|
|
{
|
|
|
|
|
if(!$this->acl->is_permitted($this->so->get_value('cat_id',$id),PHPGW_ACL_READ))
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return /* all exept pictures(blobs) */$this->so->read($id);
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-12 09:25:26 +01:00
|
|
|
|
/*!
|
|
|
|
|
@function save
|
|
|
|
|
@abstract saves a resource including picture upload ...
|
|
|
|
|
@param array $resource array with key => value of all needed datas
|
|
|
|
|
@return string msg if somthing went wrong
|
2005-02-12 16:49:38 +01:00
|
|
|
|
TODO make thumb an picture sizes choosable by preferences
|
|
|
|
|
TODO better handling for not 4:3 images
|
2005-02-12 09:25:26 +01:00
|
|
|
|
*/
|
|
|
|
|
function save($resource)
|
2005-02-03 17:42:20 +01:00
|
|
|
|
{
|
2005-02-12 16:49:38 +01:00
|
|
|
|
if(!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_EDIT))
|
|
|
|
|
{
|
|
|
|
|
return lang('You are not permitted to edit this reource!');
|
|
|
|
|
}
|
|
|
|
|
|
2005-02-12 09:25:26 +01:00
|
|
|
|
if($resource['own_file']['size']>0 && ($resource['picture_src']=='db_src' || sizeof($resource['picture_src'])<1))
|
|
|
|
|
{
|
|
|
|
|
$resource['picture_src'] = 'db_src';
|
|
|
|
|
switch($resource['own_file']['type'])
|
|
|
|
|
{
|
|
|
|
|
case 'image/gif':
|
2005-02-12 16:49:38 +01:00
|
|
|
|
$src_img = imagecreatefromgif($resource['own_file']['tmp_name']);
|
2005-02-12 09:25:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 'image/jpeg':
|
|
|
|
|
case 'image/pjpeg':
|
2005-02-12 16:49:38 +01:00
|
|
|
|
$src_img = imagecreatefromjpeg($resource['own_file']['tmp_name']);
|
2005-02-12 09:25:26 +01:00
|
|
|
|
break;
|
|
|
|
|
case 'image/png':
|
|
|
|
|
case 'image/x-png':
|
2005-02-12 16:49:38 +01:00
|
|
|
|
$src_img = imagecreatefrompng($resource['own_file']['tmp_name']);
|
2005-02-12 09:25:26 +01:00
|
|
|
|
break;
|
|
|
|
|
default:
|
2005-02-12 16:49:38 +01:00
|
|
|
|
return lang('Picture type is not supported, sorry!');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$img_size = getimagesize($resource['own_file']['tmp_name']);
|
|
|
|
|
if($img_size[0] > 64 || $img_size[1] > 48)
|
|
|
|
|
{
|
|
|
|
|
$dst_img = imagecreatetruecolor(64, 48);
|
|
|
|
|
imagecopyresized($dst_img,$src_img,0,0,0,0,64,48,$img_size[0],$img_size[1]);
|
|
|
|
|
ob_start();
|
|
|
|
|
imagepng($dst_img);
|
|
|
|
|
$resource['picture_thumb'] = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
|
|
|
|
|
if($img_size[0] > 320 || $img_size[1] > 240)
|
|
|
|
|
{
|
|
|
|
|
$dst_img = imagecreatetruecolor(320, 240);
|
|
|
|
|
imagecopyresized($dst_img,$src_img,0,0,0,0,320,240,$img_size[0],$img_size[1]);
|
|
|
|
|
ob_start();
|
|
|
|
|
imagepng($dst_img);
|
|
|
|
|
$resource['picture'] = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ob_start();
|
|
|
|
|
imagepng($src_img);
|
|
|
|
|
$resource['picture'] = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
}
|
|
|
|
|
imagedestroy($dst_img);
|
2005-02-12 09:25:26 +01:00
|
|
|
|
}
|
2005-02-12 16:49:38 +01:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ob_start();
|
|
|
|
|
imagepng($src_img);
|
|
|
|
|
$resource['picture'] = ob_get_contents();
|
|
|
|
|
$resource['picture_thumb'] = ob_get_contents();
|
|
|
|
|
ob_end_clean();
|
|
|
|
|
}
|
|
|
|
|
imagedestroy($src_img);
|
2005-02-12 09:25:26 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if($resource['picture_src'] == 'gen_src')
|
|
|
|
|
{
|
2005-02-12 16:49:38 +01:00
|
|
|
|
// welches bild? --> picture_src = dateiname
|
2005-02-12 09:25:26 +01:00
|
|
|
|
}
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete($id)
|
|
|
|
|
{
|
2005-02-12 16:49:38 +01:00
|
|
|
|
return $this->so->delete(array('id'=>$id)) ? false : lang('Something went wrong by saving resource');
|
2005-02-03 17:42:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function get_images($params)
|
2005-02-12 09:25:26 +01:00
|
|
|
|
{
|
2005-02-03 17:42:20 +01:00
|
|
|
|
$id = implode($params);
|
2005-02-12 16:49:38 +01:00
|
|
|
|
$picture = $this->so->get_value('picture_thumb',$id);
|
2005-02-03 17:42:20 +01:00
|
|
|
|
if($picture)
|
|
|
|
|
{
|
|
|
|
|
// $picture = GD($picture);
|
|
|
|
|
header('Content-type: image/png');
|
|
|
|
|
echo $picture;
|
|
|
|
|
}
|
|
|
|
|
header('Content-type: image/png');
|
2005-02-12 09:25:26 +01:00
|
|
|
|
echo file_get_contents(PHPGW_INCLUDE_ROOT.'/resources/templates/default/images/generic.png');
|
2005-02-03 17:42:20 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|