mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-01-13 17:38:19 +01:00
picture upload completed
This commit is contained in:
parent
021b1314c7
commit
86bc6b2069
@ -91,47 +91,92 @@ class bo_resources
|
|||||||
@abstract saves a resource including picture upload ...
|
@abstract saves a resource including picture upload ...
|
||||||
@param array $resource array with key => value of all needed datas
|
@param array $resource array with key => value of all needed datas
|
||||||
@return string msg if somthing went wrong
|
@return string msg if somthing went wrong
|
||||||
|
TODO make thumb an picture sizes choosable by preferences
|
||||||
|
TODO better handling for not 4:3 images
|
||||||
*/
|
*/
|
||||||
function save($resource)
|
function save($resource)
|
||||||
{
|
{
|
||||||
|
if(!$this->acl->is_permitted($resource['cat_id'],PHPGW_ACL_EDIT))
|
||||||
|
{
|
||||||
|
return lang('You are not permitted to edit this reource!');
|
||||||
|
}
|
||||||
|
|
||||||
if($resource['own_file']['size']>0 && ($resource['picture_src']=='db_src' || sizeof($resource['picture_src'])<1))
|
if($resource['own_file']['size']>0 && ($resource['picture_src']=='db_src' || sizeof($resource['picture_src'])<1))
|
||||||
{
|
{
|
||||||
$resource['picture_src'] = 'db_src';
|
$resource['picture_src'] = 'db_src';
|
||||||
switch($resource['own_file']['type'])
|
switch($resource['own_file']['type'])
|
||||||
{
|
{
|
||||||
case 'image/gif':
|
case 'image/gif':
|
||||||
$resource['db_src'] = imagecreatefromgif($resource['own_file']['tmp_name']);
|
$src_img = imagecreatefromgif($resource['own_file']['tmp_name']);
|
||||||
break;
|
break;
|
||||||
case 'image/jpeg':
|
case 'image/jpeg':
|
||||||
case 'image/pjpeg':
|
case 'image/pjpeg':
|
||||||
$resource['db_src'] = imagecreatefromjpeg($resource['own_file']['tmp_name']);
|
$src_img = imagecreatefromjpeg($resource['own_file']['tmp_name']);
|
||||||
break;
|
break;
|
||||||
case 'image/png':
|
case 'image/png':
|
||||||
case 'image/x-png':
|
case 'image/x-png':
|
||||||
$resource['db_src'] = imagecreatefrompng($resource['own_file']['tmp_name']);
|
$src_img = imagecreatefrompng($resource['own_file']['tmp_name']);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return 'Picture type is not supported, sorry!';
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ob_start();
|
||||||
|
imagepng($src_img);
|
||||||
|
$resource['picture'] = ob_get_contents();
|
||||||
|
$resource['picture_thumb'] = ob_get_contents();
|
||||||
|
ob_end_clean();
|
||||||
|
}
|
||||||
|
imagedestroy($src_img);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($resource['picture_src'] == 'gen_src')
|
if($resource['picture_src'] == 'gen_src')
|
||||||
{
|
{
|
||||||
|
// welches bild? --> picture_src = dateiname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $this->so->save($resource) ? false : lang('Something went wrong by saving resource');
|
||||||
return $this->so->save_data($resource);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete($id)
|
function delete($id)
|
||||||
{
|
{
|
||||||
return $this->so->delete(array('id'=>$id));
|
return $this->so->delete(array('id'=>$id)) ? false : lang('Something went wrong by saving resource');
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_images($params)
|
function get_images($params)
|
||||||
{
|
{
|
||||||
$id = implode($params);
|
$id = implode($params);
|
||||||
$picture = $this->so->get_value('picture',$id);
|
$picture = $this->so->get_value('picture_thumb',$id);
|
||||||
if($picture)
|
if($picture)
|
||||||
{
|
{
|
||||||
// $picture = GD($picture);
|
// $picture = GD($picture);
|
||||||
|
@ -110,4 +110,32 @@ class so_resources
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@function save
|
||||||
|
@abstract saves a resource including binary datas
|
||||||
|
@param array $resource key => value
|
||||||
|
@return array with key => value or false if not found
|
||||||
|
*/
|
||||||
|
function save($resource)
|
||||||
|
{
|
||||||
|
$where = array('id' => $resource['id']);
|
||||||
|
$data = array( 'name' => $resource['name'],
|
||||||
|
'cat_id' => $resource['cat_id'],
|
||||||
|
'short_description' => $resource['short_description'],
|
||||||
|
'long_description' => $resource['long_description'],
|
||||||
|
'location' => $resource['location'],
|
||||||
|
'quantity' => $resource['quantity'],
|
||||||
|
'useable' => $resource['useable'],
|
||||||
|
'bookable' => $resource['bookable'],
|
||||||
|
'buyable' => $resource['buyable'],
|
||||||
|
'prize' => $resource['prize'],
|
||||||
|
'accessories' => $resource['accessories'],
|
||||||
|
'picture_src' => $resource['picture_src'],
|
||||||
|
'picture_thumb' => $resource['picture_thumb'],
|
||||||
|
'picture' => $resource['picture']
|
||||||
|
);
|
||||||
|
return $this->db->insert($this->rs_table,$data,$where,__LINE__,__FILE__) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
$setup_info['resources']['name'] = 'resources';
|
$setup_info['resources']['name'] = 'resources';
|
||||||
$setup_info['resources']['title'] = 'resources';
|
$setup_info['resources']['title'] = 'resources';
|
||||||
$setup_info['resources']['version'] = '0.0.1.012';
|
$setup_info['resources']['version'] = '0.0.1.013';
|
||||||
$setup_info['resources']['app_order'] = 1;
|
$setup_info['resources']['app_order'] = 1;
|
||||||
$setup_info['resources']['tables'] = array('egw_resources');
|
$setup_info['resources']['tables'] = array('egw_resources');
|
||||||
$setup_info['resources']['enable'] = 1;
|
$setup_info['resources']['enable'] = 1;
|
||||||
@ -46,3 +46,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,8 @@
|
|||||||
'long_description' => array('type' => 'longtext'),
|
'long_description' => array('type' => 'longtext'),
|
||||||
'picture' => array('type' => 'blob'),
|
'picture' => array('type' => 'blob'),
|
||||||
'accessories' => array('type' => 'varchar','precision' => '50'),
|
'accessories' => array('type' => 'varchar','precision' => '50'),
|
||||||
'picture_src' => array('type' => 'varchar','precision' => '20')
|
'picture_src' => array('type' => 'varchar','precision' => '20'),
|
||||||
|
'picture_thumb' => array('type' => 'blob')
|
||||||
),
|
),
|
||||||
'pk' => array('id'),
|
'pk' => array('id'),
|
||||||
'fk' => array(),
|
'fk' => array(),
|
||||||
|
Loading…
Reference in New Issue
Block a user