phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] old/img/inc hook_preferences.inc.php, 1.1 hook_manual


From: skwashd
Subject: [Phpgroupware-cvs] old/img/inc hook_preferences.inc.php, 1.1 hook_manual.inc.php, 1.1 hook_admin.inc.php, 1.1 hook_add_def_pref.inc.php, 1.1 hook_about.inc.php, 1.1 class.boimg.inc.php, 1.1 class.img.inc.php, 1.1 header.inc.php, 1.1 class.uiimg.inc.php, 1.1 class.soimg.inc.php, 1.1
Date: Thu, 5 May 2005 02:56:00 +0200

Update of old/img/inc

Added Files:
     Branch: MAIN
            hook_preferences.inc.php 
            hook_manual.inc.php 
            hook_admin.inc.php 
            hook_add_def_pref.inc.php 
            hook_about.inc.php 
            class.boimg.inc.php 
            class.img.inc.php 
            header.inc.php 
            class.uiimg.inc.php 
            class.soimg.inc.php 

Log Message:
cvs clean up

====================================================
Index: hook_preferences.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare                                                          
   *
        * http://www.phpgroupware.org                                           
   *
        * --------------------------------------------                          
   *
        *  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.                                           
   *
        
\**************************************************************************/
        /* $Id: hook_preferences.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp 
$ */
        {
                $file = Array
                (
//                      'Preferences'     => 
$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.preferences'),
                        'Grant Access'    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uiaclprefs.index&acl_app='.$appname),
                        'Edit Categories' => 
$GLOBALS['phpgw']->link('/index.php','menuaction=preferences.uicategories.index&cats_app='.$appname
 . '&cats_level=True&global_cats=True')
                );
//Do not modify below this line
                display_section($appname,$file);
        }
?>

====================================================
Index: hook_manual.inc.php
<?php
    /**************************************************************************\
    * phpGroupWare - Manual                                                     
                       *
    * http://www.phpgroupware.org                                              *
    * Written by Mark Peters <address@hidden>                        *
    * --------------------------------------------                             *
    *  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.                                              *
    \**************************************************************************/

        /* $Id: hook_manual.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        // Only Modify the $file variable.....
        $file = Array();
        //Do not modify below this line
        display_manual_section($appname,$file);
?>

====================================================
Index: hook_admin.inc.php
<?php
        
/**************************************************************************\
        * phpGroupWare - Image Editor                                           
   *
        * http://www.phpgroupware.org                                           
   *
        * -----------------------------------------------                       
   *
        *  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.                                           
   *
        
\**************************************************************************/
        /* $Id: hook_admin.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        {
                $file = Array
                (
                        'Site Configuration' => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' 
. $appname)
                );

//Do not modify below this line
                $GLOBALS['phpgw']->common->display_mainscreen($appname,$file);
        }
?>

====================================================
Index: hook_add_def_pref.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare - Image Editor                                              *
  * http://www.phpgroupware.org                                              *
  * -----------------------------------------------                          *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: hook_add_def_pref.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        
$GLOBALS['pref']->change('img','img_font','Verdana,Arial,Helvetica,sans-serif');
        $GLOBALS['pref']->change('img','img_font_size','3');
?>

====================================================
Index: hook_about.inc.php
<?php
    /**************************************************************************\
    * phpGroupWare - about                                                     *
    * http://www.phpgroupware.org                                              *
    * --------------------------------------------                             *
    * 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.                                               *
    \**************************************************************************/
    /* $Id: hook_about.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        function about_app($tpl,$handle)
        {
                $t = 
CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('phpgwapi'));
                $s = $t->set_file(array('about' => 'about_app.tpl'));
                $s .= $t->set_var('app_title',lang('img'));
                $s .= $t->set_var('written_by',lang('written by'));
                $s .= $t->set_var('developers','Miles Lott 
&lt;address@hidden&gt;');
                $s .= $t->fp('out','about');
                return $s;
        }

====================================================
Index: class.boimg.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare - Image Editor                                              *
  * http://www.phpgroupware.org                                              *
  * This application written by Miles Lott <address@hidden>        *
  * --------------------------------------------                             *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: class.boimg.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        /* img business object class */
        class boimg
        {
                var $so;
                var $grants;

                var $debug = False;

                var $start;
                var $limit;
                var $query;
                var $sort;
                var $order;
                var $filter;
                var $cat_id;
                var $total;

                function boimg($debug=False)
                {
                        $this->so  = CreateObject('img.soimg',$debug);
                        $this->img = CreateObject('img.img',$debug);
                        $this->debug = $debug;
                        $this->read_sessiondata();

                        $this->grants = $this->so->grants;

                        $start   = get_var('start',Array('GET','POST'));
                        $query   = get_var('query',Array('GET','POST'));
                        $sort    = get_var('sort',Array('GET','POST'));
                        $order   = get_var('order',Array('GET','POST'));
                        $filter  = get_var('filter',Array('GET','POST'));
                        $cat_id  = get_var('cat_id',Array('GET','POST'));
                        $fcat_id = get_var('fcat_id',Array('GET','POST'));

                        if(!empty($start) || ($start == '0') || ($start == 0))
                        {
                                $this->start = $start;
                        }
                        if($limit)
                        {
                                $this->limit  = $limit;
                        }
                        if((empty($query) && !empty($this->query)) || 
!empty($query))
                        {
                                $this->query  = $query;
                        }

                        if(isset($fcat_id)) { $this->cat_id = $fcat_id; }
                        if($fcat_id == '0' || $fcat_id == 0 || $fcat_id == '') 
{ $this->cat_id = 0; }
                        if(isset($sort))    { $this->sort   = $sort;   }
                        if(isset($order))   { $this->order  = $order;  }
                        if(isset($filter))  { $this->filter = $filter; }
                }

                /* The next two functions are for reading list position data 
for admin display */
                function save_sessiondata($data)
                {
                        
$GLOBALS['phpgw']->session->appsession('session_data','img',$data);
                }

                function read_sessiondata()
                {
                        $data = 
$GLOBALS['phpgw']->session->appsession('session_data','img');

                        $this->start  = $data['start'];
                        $this->limit  = $data['limit'];
                        $this->query  = $data['query'];
                        $this->sort   = $data['sort'];
                        $this->order  = $data['order'];
                        $this->filter = $data['filter'];
                        $this->cat_id = $data['cat_id'];
                }

                function index($data='')
                {
                        return 
$this->so->index($this->start,$this->query,$this->sort,$this->order,$this->cat_id,$this->limit);
                }

                function read($data)
                {
                        return $this->so->read($data);
                }

                function add($data)
                {
                        unset ($data['id']);
                        return $this->so->edit($data);
                }

                function edit($data)
                {
                        return $this->so->edit($data);
                }

                function delete($data)
                {
                        if(is_array($data))
                        {
                                $id = $data['id'];
                        }
                        else
                        {
                                $id = $data;
                        }
                        return $this->so->delete($id);
                }
        }
?>

====================================================
Index: class.img.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare - Image Editor                                              *
  * http://www.phpgroupware.org                                              *
  * This application written by Miles Lott <address@hidden>        *
  * --------------------------------------------                             *
  * some methods borrowed from OIC v1.0.6 - the Online Image Converter       *
  *   Copyright (C) 2001 Ray Lopez (http://www.TheDreaming.com)              *
  * --------------------------------------------                             *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: class.img.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        /* Image conversion and manipulation class */
        class img
        {
                var $debug = False;
                var $tmpfile = '';
                var $tmpdir = '';
                /*
                  Note, GD supports WBMP. This is not the Windoze bitmap 
format, but
                  the monochrome bitmaps used in PDAs, etc.
                  */
                var $convertArray = array('Please 
select','GIF','JPG','PNG','WBMP');
                var $angles       = array();
                /*
                  This is the function to be used for resize, etc.
                  A check is done in the constructor for the nicer function 
available in gd 2.X.
                  Since there is no way to really check, make sure your gd 
version is correct in admin.
                */
                var $icr = 'imagecopyresized';

                /*
                  This setting is used to call convert.  This is the default.
                  Used for rotate, and for conversion if no internal GIF 
support available.
                */
                var $convertcmd   = '/usr/X11R6/bin/convert';

                function img($debug=False)
                {
                        $this->debug   = $debug;
                        $this->angles  = array(lang('Please 
select'),'90','180','270');
                        $this->docroot = 
get_var('DOCUMENT_ROOT',Array('SERVER'));

                        $test = CreateObject('phpgwapi.php_ext');
                        if(!$test->check('gd',True))
                        {
                                echo 'No GD support in this PHP install!';
                                exit;
                        }
                        unset($test);

                        $this->tmpdir  = 
$GLOBALS['phpgw_info']['server']['temp_dir'] . SEP;
                        $this->urlbase = 
$GLOBALS['phpgw_info']['server']['webserver_url'] . '/img/images/';

                        /*
                          Set the location of the convert command.
                        */
                        $config = CreateObject('phpgwapi.config','img');
                        $config->read_repository();
                        $current_config = $config->config_data;
                        $this->convertcmd = $current_config['convert_cmd'] ? 
$current_config['convert_cmd'] : $this->convertcmd;

                        if($current_config['gd_version'] >= 2)
                        {
                                $this->icr = 'imagecopyresampled';
                        }
                }

                function smartcopy($src,$dest)
                {
                        $srctype  = $this->img_type($src);
                        $desttype = $this->img_type($dest);
                        if($this->debug)
                        {
                                echo '<br>smartcopy()' . "\n";
                                echo '<br>Source file: ' . $src . "\n";
                                echo '<br>Target file: ' . $dest . "\n";
                                echo '<br>Source type: ' . $srctype . "\n";
                                echo '<br>Target type: ' . $desttype . "\n";
                        }

                        if($srctype == $desttype)
                        {
                                copy($src,$dest);
                                unlink($src);
                                return $dest;
                        }
                        else
                        {
                                switch ($srctype)
                                {
                                        case '1':
                                                $ext = 'gif';
                                                break;
                                        case '2':
                                                $ext = 'jpg';
                                                break;
                                        case '3':
                                                $ext = 'png';
                                                break;
                                        case '4':
                                                $ext = 'bmp';
                                }
                                switch ($desttype)
                                {
                                        case '1':
                                                $oldext = 'gif';
                                                break;
                                        case '2':
                                                $oldext = 'jpg';
                                                break;
                                        case '3':
                                                $oldext = 'png';
                                                break;
                                        case '4':
                                                $oldext = 'bmp';
                                }
                                $newdest = 
ereg_replace("\.$oldext",".$ext",$dest);
                                if($this->debug)
                                {
                                        echo '<br>Old ext: ' . $oldext . "\n";
                                        echo '<br>New ext: ' . $ext . "\n";
                                        echo '<br>NEW Target file: ' . $newdest 
. "\n";
                                }
                                copy($src,$newdest);
                                unlink($tmpfile);
                                return $newdest;
                        }
                }

                function img_type($imgfile)
                {
                        $imgarray = getimagesize($imgfile);
                        if($this->debug)
                        {
                                echo '<br>img->img_type(): ' . $imgfile . "\n";
                                _debug_array($imgarray);
                        }
                        return $imgarray[2];
                }

                /* Save the temporary file into the document tree, or wherever 
*/
                function save($imagefile,$dest='',$extra='')
                {
                        $imagefile = ereg_replace($this->tmpdir,'',$imagefile);
                        if($dest)
                        {
                                $dest = ereg_replace($this->tmpdir,'',$dest);
                                $destfile = $dest;
                                $dest = PHPGW_APP_ROOT . SEP . 'images' . SEP . 
$destfile . $extra;
                        }
                        else
                        {
                                $destfile = $imagefile;
                                $dest = PHPGW_APP_ROOT . SEP . 'images' . SEP . 
$destfile . $extra;
                        }
                        $url = $this->urlbase . $destfile . $extra;
                        if($this->debug)
                        {
                                echo '<br>img->save(): ' . $this->tmpdir . 
$imagefile . ' as ' . $dest;
                        }
                        copy($this->tmpdir . $imagefile,$dest);
                        return $url;
                }

                /* Create a tmp filename */
                function tmp_file($name='phpgwimg_')
                {
                        srand((double)microtime()*1000000);
                        return($this->tmpdir . $name . rand(1,100000));
                }

                /* format conversion routines */
                function image2jpg($im,$dest='')
                {
                        if (imagetypes() & IMG_JPG)
                        {
                                $filename = $this->tmp_file() . '.jpg';
                                imagejpeg($im, $filename);
                                if($this->debug)
                                {
                                        echo '<br>img->image2jpg(): calling 
img->save(' . $filename . ',' . $dest . ')';
                                }
                                return $this->save($filename,$dest);
                        }
                }

                function image2gif($im,$dest='')
                {
                        if (imagetypes() & IMG_GIF)
                        {
                                $filename = $this->tmp_file() . '.gif';
                                imagegif($im, $filename);
                                if($this->debug)
                                {
                                        echo '<br>img->image2gif(): calling 
img->save(' . $filename . ',' . $dest . ')';
                                }
                                return $this->save($filename,$dest);
                        }
                        else
                        {
                                $filename = $this->tmp_file() . '.png';
                                imagepng($im, $filename);

                                /* Try to call convert to do this, maybe it can 
handle gif */
                                if($this->debug)
                                {
                                        echo '<br>img->image2gif: calling 
img->_convert(' . $filename . ",''," . 'gif)';
                                }
                                return $this->_convert($filename,'','gif');
                        }
                }

                function image2bmp($im,$dest='')
                {
                        if (imagetypes() & IMG_WBMP)
                        {
                                $filename = $this->tmp_file() . '.bmp';
                                imagewbmp($im, $filename);
                                if($this->debug)
                                {
                                        echo '<br>img->image2bmp(): calling 
img->save(' . $filename . ',' . $dest . ')';
                                }
                                return $this->save($filename,$dest);
                        }
                }

                function image2png($im,$dest='')
                {
                        if (imagetypes() & IMG_PNG)
                        {
                                $filename = $this->tmp_file() . '.png';
                                imagepng($im, $filename);
                                if($this->debug)
                                {
                                        echo '<br>img->image2png(): calling 
img->save(' . $filename . ',' . $dest . ')';
                                }
                                return $this->save($filename,$dest);
                        }
                }

                /* Create a scaled thumbnail image */
                function thumbnail($im,$width,$height,$dstW=100,$format='jpg')
                {
                        $filename = $this->tmp_file() . '.' . $format;
                        $dstH = $this->_get_thumbsize($width,$height,$dstW);

                        /* Create a new image handle */
                        $newim = imagecreate($dstW,$dstH);
                        if($this->debug)
                        {
                                echo '<br>img->thumbnail(): calling 
img->_resize($newim,$im,"'
                                        . $dstX . '","' . $dstY . '","' . $srcX 
. '","' . $srcY . '","'
                                        . $dstW . '","' . $dstH . '","' . 
$width . '","' . $height
                                        . '","' . $filename . '","' . $format . 
'")';
                        }
                        return 
($this->_resize($newim,$im,$dstX,$dstY,$srcX,$srcY,$dstW,$dstH,$width,$height,$filename,$format));
                }

                /* Resize an image */
                function resize($im,$width,$height,$dstW,$dstH,$format='png')
                {
                        $filename = $this->tmp_file();
                        $newim = imagecreate($dstW,$dstH);
                        if($this->debug)
                        {
                                echo '<br>img->resize(): calling 
img->_resize($newim,$im,0,0,0,0,"'
                                        . $dstW . '","' . $dstH . '","' . 
$width . '","' . $height
                                        . '","' . $filename . '","' . $format . 
'")';
                        }
                        return 
($this->_resize($newim,$im,0,0,0,0,$dstW,$dstH,$width,$height,$filename,$format));
                }

                /* Crop an image using upper left corner and size attributes */
                function 
crop($im,$width,$height,$dstW,$dstH,$srcX,$srcY,$format='png')
                {
                        $filename = $this->tmp_file() . '.' . $format;
                        $newim = imagecreate($dstW,$dstH);

                        $cmd = $this->icr . 
'($newim,$im,$dstX,$dstY,$srcX,$srcY,$dstW,$dstH,$width,$height);';
                        eval($cmd);
                        if($this->debug)
                        {
                                echo '<br>img->crop(): calling 
img->_resize($newim,$im,"'
                                        . $dstX . '","' . $dstY . '","' . $srcX 
. '","' . $srcY . '","'
                                        . $dstW . '","' . $dstH . '","' . 
$width . '","' . $height
                                        . '","' . $filename . '","' . $format . 
'")';
                        }
                        return 
($this->_resize($newim,$im,$dstX,$dstY,$srcX,$srcY,$dstW,$dstH,$width,$height,$filename,$format));
                }

                /* This one is special.  It uses the convert command (part of 
ImageMagick). */
                function rotate($im,$angle=90)
                {
                        if($this->convertcmd)
                        {
                                $tmpfile = $this->tmp_file('phpgwimg_rot_');
                                if (imagetypes() & IMG_PNG)
                                {
                                        imagepng($im, $tmpfile);
                                        $ext = '.png';
                                }
                                else
                                {
                                        imagejpeg($im, $tmpfile);
                                        $ext = '.jpg';
                                }

                                if(@stat($tmpfile))
                                {
                                        $tmp = $this->tmp_file('phpgwimg_rot_');
                                        $cmd = $this->convertcmd . ' ' . 
$tmpfile . ' -rotation ' . $angle . ' ' . $tmp;
                                        if($this->debug)
                                        {
                                                echo '<br>img->rotate(): ' . 
$cmd;
                                        }
                                        passthru($cmd);
                                        if($this->debug)
                                        {
                                                echo '<br>img->rotate(): 
calling img->save(' . $tmp . ",''," . $ext . ')';
                                        }
                                        return $this->save($tmp,'',$ext);
                                }
                        }
                }

                /* Used mainly for gif support */
                function convert($src,$type)
                {
                        $dest = ereg_replace("\.gif",".$type",$src);
                        $cmd  = $this->convertcmd . ' ' . $src . ' ' . $dest;
                        if($this->debug)
                        {
                                echo '<br>img->convert(): ' . $cmd;
                        }
                        passthru($cmd);

                        return $dest;
                }

                function _convert($src,$dest='',$type='')
                {
                        if($type)
                        {
                                if($dest)
                                {
                                        $tmp = 
ereg_replace($this->tmpdir,'',$dest);
                                }
                                else
                                {
                                        $tmp = $this->tmp_file() . '.' . $type;
                                }
                                $cmd = $this->convertcmd . ' ' . $src . ' ' . 
$tmp;
                                if($this->debug)
                                {
                                        echo '<br>img->_convert(): ' . $cmd;
                                }
                                passthru($cmd);
                                if($this->debug)
                                {
                                        echo '<br>img->_convert(): calling 
img->save(' . $tmp . ')';
                                }
                                return $this->save($tmp,'');
                        }
                }

                /* Called by crop() and thumbnail() to check valid formats, 
resize, and save an image */
                function 
_resize($newim,$im,$dstX,$dstY,$srcX,$srcY,$dstW,$dstH,$width,$height,$filename,$format)
                {
                        $cmd = $this->icr . 
'($newim,$im,$dstX,$dstY,$srcX,$srcY,$dstW,$dstH,$width,$height);';
                        eval($cmd);
                        switch ($format)
                        {
                                case 'bmp':
                                        if (imagetypes() & IMG_WBMP)
                                        {
                                                imagewbmp($newim, $filename);
                                        }
                                        break;
                                case 'gif':
                                        if (imagetypes() & IMG_GIF)
                                        {
                                                imagegif($newim, $filename);
                                        }
                                        else
                                        {
                                                imagepng($newim, $filename);
                                                copy ($filename,$filename . 
'.png');
                                                unlink($filename);
                                                if($this->debug)
                                                {
                                                        echo 
'<br>img->_resize(): calling img->_convert(' . $filename . '.png' . ",''," . 
'gif)';
                                                }
                                                $this->_convert($filename . 
'.png','','gif');
                                        }
                                        break;
                                case 'jpg':
                                        if (imagetypes() & IMG_JPG)
                                        {
                                                imagejpeg($newim, $filename);
                                        }
                                        break;
                                case 'png':
                                default:
                                        if (imagetypes() & IMG_PNG)
                                        {
                                                imagepng($newim, $filename);
                                        }
                        }
                        if($this->debug)
                        {
                                echo '<br>img->_resize(): calling img->save(' . 
$filename . ')';
                        }
                        return $this->save($filename);
                }

                /* Calculate thumbnail image height using width and original 
image size */
                function _get_thumbsize($width,$height,$newW='100')
                {
                        $mult  = $width / $newW;
                        $newH  = round($height / $mult);
                        return $newH;
                }
        }
?>

====================================================
Index: header.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare - Image Editor                                              *
  * http://www.phpgroupware.org                                              *
  * This application written by Miles Lott <address@hidden>        *
  * --------------------------------------------                             *
  * some methods borrowed from OIC v1.0.6 - the Online Image Converter       *
  *   Copyright (C) 2001 Ray Lopez (http://www.TheDreaming.com)              *
  * --------------------------------------------                             *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: header.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        $GLOBALS['phpgw']->template->set_file(array('img_header' => 
'header.tpl'));

        if (isset($phpgw_info['user']['preferences']['img']['img_font']))
        {
                $font = $phpgw_info['user']['preferences']['img']['img_font'];
        }
        else
        {
                $font = set_font();
        }

        
$GLOBALS['phpgw']->template->set_var('bg_color',$phpgw_info['theme']['th_bg']);
        $GLOBALS['phpgw']->template->set_var('font',$font);
        
$GLOBALS['phpgw']->template->set_var('link_categories',$phpgw->link('/preferences/categories.php','cats_app=img&cats_level=True&global_cats=True'));
        
$GLOBALS['phpgw']->template->set_var('lang_categories',lang('Categories'));
        
$GLOBALS['phpgw']->template->set_var('link_img',$phpgw->link('/img/index.php'));
        $GLOBALS['phpgw']->template->set_var('lang_img',lang('Image Editor'));

        $GLOBALS['phpgw']->template->pparse('out','img_header');
?>

====================================================
Index: class.uiimg.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare - Image Editor                                              *
  * http://www.phpgroupware.org                                              *
  * This application written by Miles Lott <address@hidden>        *
  * --------------------------------------------                             *
  * some methods borrowed from OIC v1.0.6 - the Online Image Converter       *
  *   Copyright (C) 2001 Ray Lopez (http://www.TheDreaming.com)              *
  * --------------------------------------------                             *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: class.uiimg.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        /* img admin display class */
        class uiimg
        {
                var $bo;
                var $cat;
                var $template;
                var $nextmatchs;

                /* This setting cascades to all img classes */
                var $debug = False;

                var $start;
                var $limit;
                var $query;
                var $sort;
                var $order;
                var $filter;
                var $cat_id;

                var $public_functions = array(
                        'index' => True,
                        'view'     => True,
                        'add'      => True,
                        'edit'     => True,
                        'delete'   => True,
                        'preferences' => True,
                        'manipulate' => True,
                        'thumbnails' => True
                );

                function uiimg()
                {
                        $this->docroot    = 
get_var('DOCUMENT_ROOT',Array('GLOBAL','SERVER'));
                        $this->bo         = 
CreateObject('img.boimg',$this->debug);
                        $this->cat        = CreateObject('phpgwapi.categories');
                        $this->template   = $GLOBALS['phpgw']->template;
                        $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');

                        $this->start    = $this->bo->start;
                        $this->limit    = $this->bo->limit;
                        $this->query    = $this->bo->query;
                        $this->sort     = $this->bo->sort;
                        $this->order    = $this->bo->order;
                        $this->filter   = $this->bo->filter;
                        $this->cat_id   = $this->bo->cat_id;
                }

                function save_sessiondata()
                {
                        $data = array(
                                'start'  => $this->start,
                                'limit'  => $this->limit,
                                'query'  => $this->query,
                                'sort'   => $this->sort,
                                'order'  => $this->order,
                                'filter' => $this->filter,
                                'cat_id' => $this->cat_id
                        );
                        $this->bo->save_sessiondata($data);
                }

                /* Main index img listing */
                function index()
                {
                        $this->template->set_file(array( 'list' => 'list.tpl'));
                        $this->template->set_block('list','header','header');
                        
$this->template->set_block('list','list_item','list_item');
                        $this->template->set_block('list','footer','footer');

                        $GLOBALS['phpgw']->common->phpgw_header();

                        $this->template->set_var('title',lang('img'));
                        $this->template->set_var('name',lang('List'));
                        
$this->template->set_var('lang_title',$this->nextmatchs->show_sort_order(
                                
$this->sort,'img_title',$this->order,'/index.php',lang('img_title'),'&menuaction=img.uiimg.index'));

                        
$this->template->set_var('lang_name',$this->nextmatchs->show_sort_order(
                                
$this->sort,'img_name',$this->order,'/index.php',lang('img_name'),'&menuaction=img.uiimg.index'));

                        
$this->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
                        $this->template->set_var('query',$this->query);
                        $this->template->set_var('lang_select',lang('Select'));
                        $this->template->set_var('lang_search',lang('Search'));
                        $this->template->set_var('lang_submit',lang('Submit'));
                        $this->template->set_var('lang_view',lang('View'));
                        $this->template->set_var('lang_edit',lang('Edit'));
                        $this->template->set_var('lang_delete',lang('Delete'));
                        
$this->template->set_var('cat_action',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                        
$this->template->set_var('lang_category',lang('Category'));
                        
$this->template->set_var('category_list',$this->cat->formated_list('select','all',$this->cat_id,True));
                        
$this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                        $this->template->pfp('out','header');

                        $list = $this->bo->index($data);
                        while (list($key,$val) = @each($list))
                        {
                                
$this->template->set_var('tr_color',$this->nextmatchs->alternate_row_color($tr_color));
                                
$this->template->set_var('img_name',$val['img_name']);
                                
$this->template->set_var('img_title',$val['img_title']);
                                
$this->template->set_var('view',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.view&img_id='
 . $val['img_id']));
                                
$this->template->set_var('edit',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.edit&img_id='
 . $val['img_id']));
                                
$this->template->set_var('delete',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.delete&img_id='
 . $val['img_id']));
                                $this->template->fp('rows','list_item',True);
                        }

                        
$this->template->set_var('addurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.add'));
                        $this->template->set_var('lang_add',lang('Add'));
                        
$this->template->set_var('thumbnail_link',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.thumbnails'));
                        $this->template->set_var('lang_thumbnail',lang('View 
Thumbnails'));
                        $this->template->pfp('out','footer');

                        $this->save_sessiondata();
                }

                function thumbnails()
                {
                        $this->template->set_file(array( 'list' => 
'thumbnails.tpl'));
                        $this->template->set_block('list','header','header');
                        $this->template->set_block('list','col','col');
                        $this->template->set_block('list','row','row');
                        $this->template->set_block('list','footer','footer');

                        $GLOBALS['phpgw']->common->phpgw_header();

                        $this->template->set_var('title',lang('img'));
                        $this->template->set_var('name',lang('List'));
                        $this->template->set_var('lang_search',lang('Search'));
                        
$this->template->set_var('cat_action',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.thumbnails'));
                        
$this->template->set_var('lang_category',lang('Category'));
                        
$this->template->set_var('category_list',$this->cat->formated_list('select','all',$this->cat_id,True));
                        $this->template->pfp('out','header');

                        $list = $this->bo->index($data);
                        $i=0;
                        $j=0;
                        while (list($key,$val) = @each($list))
                        {
                                $i++;
                                $j++;
                                
$this->template->set_var('tr_color',$this->nextmatchs->alternate_row_color($tr_color));
                                $this->template->set_var('img_name',$j . ': ' . 
$val['img_name'] . '(' . $val['img_title'] . ')');
                                
$this->template->set_var('img_thumb',$val['img_thumb']);
                                
$this->template->set_var('view',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.view&thumb=True&img_id='
 . $val['img_id']));
                                $this->template->fp('cols','col',True);
                                if($i>=5)
                                {
                                        $i=0;
                                        $this->template->fp('rows','row',True);
                                        $this->template->set_var('cols','');
                                }
                        }
                        $this->template->fp('rows','row',True);

                        
$this->template->set_var('addurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.add'));
                        $this->template->set_var('lang_add',lang('Add'));
                        
$this->template->set_var('list_link',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                        $this->template->set_var('lang_list',lang('View List'));
                        $this->template->pfp('out','footer');
                }

                /* Single img view */
                function view($id='')
                {
                        if(!$id)
                        {
                                $id = get_var('img_id',Array('POST','GET'));
                        }

                        if(get_var('thumb',Array('GET')))
                        {
                                $cancel_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.thumbnails');
                        }
                        else
                        {
                                $cancel_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index');
                        }

                        if(get_var('cancel',Array('POST')))
                        {
                                Header('Location: ' . 
$GLOBALS['phpgw']->link('img.uiimg.index'));
                        }
                        if(get_var('edit',Array('POST')))
                        {
                                ExecMethod('img.uiimg.edit',$id);
                        }
                        else
                        {
                                $this->template->set_file(array( 'view' => 
'view.tpl'));
                                
$this->template->set_block('view','header','header');
                                
$this->template->set_block('view','form','form');
                                
$this->template->set_block('view','footer','footer');

                                $this->template->set_var('title',lang('img'));
                                $this->template->set_var('name',lang('view'));
                                
$this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.view'));
                                
$this->template->set_var('cancel_url',$cancel_url);
                                
$this->template->set_var('lang_edit',lang('Edit'));
                                
$this->template->set_var('lang_cancel',lang('Cancel'));
                                $this->template->set_var('row_on', 
$GLOBALS['phpgw_info']['theme']['row_on']);
                                
$this->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);

                                $GLOBALS['phpgw']->common->phpgw_header();

                                $img = $this->bo->read($id);

                                while(list($key,$val) = @each($img[$id]))
                                {
                                        //echo '<br>' . $key . ': ' . $val;
                                        $this->template->set_var($key,$val);
                                        $this->template->set_var('lang_' . 
$key, lang($key));
                                }

                                if($this->debug)
                                {
                                        echo $this->docroot . SEP . 
$img[$id]['img_file'];
                                }
                                $imgSizeArray   = GetImageSize($this->docroot . 
SEP . $img[$id]['img_file']);
                                $imgWidth       = $imgSizeArray[0];
                                $imgHeight      = $imgSizeArray[1];
                                if($this->debug)
                                {
                                        echo '<br>uiiimg->view(): called 
getimagesize(' . $this->docroot . SEP . $img[$id]['img_file'] . ')';
                                        _debug_array($imgSizeArray);
                                }

                                
$this->template->set_var('lang_img_cat',lang('Category'));
                                
$this->template->set_var('img_cat',$this->cat->id2name($img[$id]['img_cat']));
                                $this->template->set_var('img_id',$id);
                                
$this->template->set_var('imglink',$img[$id]['img_file']);
                                $this->template->set_var('imgwidth',$imgWidth);
                                
$this->template->set_var('imgheight',$imgHeight);
                                
$this->template->set_var('lang_img_owner',lang('Entered by'));
                                
$this->template->set_var('img_owner',@$GLOBALS['phpgw']->accounts->id2name($img[$id]['img_owner']));
                                $this->template->pfp('out','header');
                                $this->template->pfp('out','form');
                                $this->template->pfp('out','footer');
                        }
                }

                /* Add an img */
                function add()
                {
                        $posted = get_var('entry',Array('POST'));
                        $img_file = $GLOBALS['HTTP_POST_FILES']['img_file'];

                        if(get_var('cancel',Array('POST')))
                        {
                                Header('Location: ' . 
$GLOBALS['phpgw']->link('img.uiimg.index'));
                        }
                        $this->template->set_file(array( 'add' => 'edit.tpl'));
                        $this->template->set_block('add','header','header');
                        $this->template->set_block('add','form','form');
                        
$this->template->set_block('add','add_footer','add_footer');

                        
$this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.add'));
                        $this->template->set_var('title',lang('img'));
                        $this->template->set_var('name',lang('add'));
                        $this->template->set_var('lang_img_name',lang('Name') . 
':');
                        $this->template->set_var('lang_img_title',lang('Title') 
. ':');
                        
$this->template->set_var('lang_img_des',lang('Description') . ':');
                        
$this->template->set_var('lang_img_file',lang('img_file') . ':');
                        $this->template->set_var('lang_img_thumb','');
                        $this->template->set_var('imglink','');
                        $this->template->set_var('lang_add',lang('Add'));
                        
$this->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                        $this->template->set_var('lang_reset',lang('Reset'));
                        
$this->template->set_var('category_list',$this->cat->formated_list('select','all',$this->cat_id,True));

                        if(!get_var('submit',Array('POST')))
                        {
                                $GLOBALS['phpgw']->common->phpgw_header();
                                $this->template->pfp('out','header');
                                $this->template->pfp('out','form');
                                $this->template->pfp('out','add_footer');
                        }
                        else
                        {
                                if($img_file['tmp_name'] && $img_file['name'])
                                {
                                        if($img_file['tmp_name'] == 'none' || 
empty($img_file['tmp_name']))
                                        {
                                                break;
                                        }
                                        if($img_file['name'] == 'none' || 
empty($img_file['name']))
                                        {
                                                break;
                                        }
                                        $imgSizeArray   = 
GetImageSize($img_file['tmp_name']);
                                        $imgWidth       = $imgSizeArray[0];
                                        $imgHeight      = $imgSizeArray[1];
                                        $imgType        = $imgSizeArray[2];
                                        if($this->debug)
                                        {
                                                echo '<br>uiiimg->add(): called 
getimagesize(' . $img_file['tmp_name'] . ')';
                                                _debug_array($imgSizeArray);
                                        }
                                        switch ($imgType)
                                        {
                                                case '1':
                                                        // GIF
                                                        if (imagetypes() & 
IMG_GIF)
                                                        {
                                                                $im = 
imagecreatefromgif($img_file['tmp_name']);
                                                        }
                                                        else
                                                        {
                                                                
copy($img_file['tmp_name'],$img_file['tmp_name'] . '.gif');
                                                                
@unlink($img_file['tmp_name']);
                                                                $newtmp = 
$this->bo->img->_convert($img_file['tmp_name'] . '.gif',$img_file['tmp_name'] . 
'.png','png');
                                                                if($this->debug)
                                                                {
                                                                        echo 
'<br>uiiimg->add(): called img->_convert('
                                                                                
. $img_file['tmp_name'] . '.gif,'
                                                                                
. $img_file['tmp_name'] . '.png,png) to create: '
                                                                                
. $newtmp;
                                                                }
                                                                unset($newtmp);
                                                                
$img_file['name'] = ereg_replace("\.gif",'.png',$img_file['name']);
                                                                
@unlink($img_file['tmp_name'] . '.gif');
                                                                $im = 
imagecreatefrompng($img_file['tmp_name'] . '.png');
                                                                
@unlink($img_file['tmp_name'] . '.png');
                                                        }
                                                        break;
                                                case '2':
                                                        //JPG
                                                        $im = 
imagecreatefromjpeg($img_file['tmp_name']);
                                                        break;
                                                case '3':
                                                        //PNG
                                                        $im = 
imagecreatefrompng($img_file['tmp_name']);
                                                        break;
                                                case '4':
                                                default:
                                                        $im = 
@ImageCreateFromWBMP($img_file['tmp_name']);
                                        }
                                        unlink($img_file['tmp_name']);
                                        $image = 
$this->bo->img->image2png($im,$img_file['name']);
                                        $thumb = 
$this->bo->img->thumbnail($im,$imgWidth,$imgHeight,100);
                                }

                                $entry = array(
                                        'img_name'   => $posted['img_name'],
                                        'img_title'  => $posted['img_title'],
                                        'img_cat'    => 
get_var('fcat_id',Array('POST')),
                                        'img_des'    => $posted['img_des'],
                                        'img_images' => $posted['img_images'],
                                        'img_copy'   => $posted['img_copy'],
                                        'img_owner'  => 
$GLOBALS['phpgw_info']['user']['account_id']
                                );
                                if($image)
                                {
                                        $entry['img_file'] = $image;
                                }
                                if($thumb)
                                {
                                        $entry['img_thumb'] = $thumb;
                                }
                                $id = $this->bo->add($entry);
                                ExecMethod('img.uiimg.view',$id);
                        }
                }

                /* Edit an existing img */
                function edit($id='')
                {
                        if(!$id)
                        {
                                $id = get_var('img_id',Array('POST','GET'));
                        }

                        if(get_var('cancel',Array('POST')))
                        {
                                Header('Location: ' . 
$GLOBALS['phpgw']->link('index.php','menuaction=img.uiimg.index'));
                        }

                        if(get_var('submit',Array('POST')))
                        {
                                $posted = get_var('entry',Array('POST'));
                                $posted['img_cat'] = 
get_var('fcat_id',Array('POST'));
                                $img_file = 
$GLOBALS['HTTP_POST_FILES']['img_file'];

                                if($img_file['tmp_name'] && $img_file['name'])
                                {
                                        if($img_file['tmp_name'] == 'none' || 
empty($img_file['tmp_name']))
                                        {
                                                break;
                                        }
                                        if($img_file['name'] == 'none' || 
empty($img_file['name']))
                                        {
                                                break;
                                        }
                                        $imgSizeArray   = 
GetImageSize($img_file['tmp_name']);
                                        $imgWidth       = $imgSizeArray[0];
                                        $imgHeight      = $imgSizeArray[1];
                                        $imgType        = $imgSizeArray[2];
                                        if($this->debug)
                                        {
                                                echo '<br>uiiimg->edit(): 
called getimagesize(' . $img_file['tmp_name'] . ')';
                                                _debug_array($imgSizeArray);
                                        }
                                        switch ($imgType)
                                        {
                                                case '1':
                                                        // GIF
                                                        if (imagetypes() & 
IMG_GIF)
                                                        {
                                                                $im = 
imagecreatefromgif($img_file['tmp_name']);
                                                                
$posted['img_file']  = $this->bo->img->image2gif($im,$img_file['name']);
                                                        }
                                                        else
                                                        {
                                                                
copy($img_file['tmp_name'],$img_file['tmp_name'] . '.gif');
                                                                
@unlink($img_file['tmp_name']);
                                                                $newtmp = 
$this->bo->img->_convert($img_file['tmp_name'] . '.gif',$img_file['tmp_name'] . 
'.png','png');
                                                                if($this->debug)
                                                                {
                                                                        echo 
'<br>uiiimg->edit(): called img->_convert('
                                                                                
. $img_file['tmp_name'] . '.gif,'
                                                                                
. $img_file['tmp_name'] . '.png,png) to create: '
                                                                                
. $newtmp;
                                                                }
                                                                unset($newtmp);
                                                                
$img_file['name'] = ereg_replace("\.gif",'.png',$img_file['name']);
                                                                
@unlink($img_file['tmp_name'] . '.gif');
                                                                $im = 
imagecreatefrompng($img_file['tmp_name'] . '.png');
                                                                
@unlink($img_file['tmp_name'] . '.png');
                                                        }
                                                        break;
                                                case '2':
                                                        //JPG
                                                        $im = 
imagecreatefromjpeg($img_file['tmp_name']);
                                                        $posted['img_file']  = 
$this->bo->img->image2jpg($im,$img_file['name']);
                                                        break;
                                                case '3':
                                                        //PNG
                                                        $im = 
imagecreatefrompng($img_file['tmp_name']);
                                                        $posted['img_file']  = 
$this->bo->img->image2png($im,$img_file['name']);
                                                        break;
                                                case '4':
                                                default:
                                                        $im = 
@ImageCreateFromWBMP($img_file['tmp_name']);
                                        }
                                        unlink($img_file['tmp_name']);
                                        $posted['img_thumb'] = 
$this->bo->img->thumbnail($im,$imgWidth,$imgHeight,100);
                                }

                                $this->bo->edit($posted);
                        }

                        $this->template->set_file(array( 'edit' => 'edit.tpl'));
                        $this->template->set_block('edit','header','header');
                        $this->template->set_block('edit','form','form');
                        
$this->template->set_block('edit','edit_footer','edit_footer');

                        $this->template->set_var('title',lang('img'));
                        $this->template->set_var('name',lang('edit'));
                        
$this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.edit'));
                        
$this->template->set_var('cancel_url',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                        $this->template->set_var('lang_load_new',lang('Load 
New'));
                        $this->template->set_var('lang_edit',lang('Edit'));
                        $this->template->set_var('lang_cancel',lang('Cancel'));
                        $this->template->set_var('row_on', 
$GLOBALS['phpgw_info']['theme']['row_on']);
                        
$this->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);

                        $GLOBALS['phpgw']->common->phpgw_header();

                        $img = $this->bo->read($id);
                        
$this->template->set_var('category_list',$this->cat->formated_list('select','all',$img[$id]['img_cat'],True));
                        $this->template->pfp('out','header');

                        while(list($key,$val) = @each($img[$id]))
                        {
                                $this->template->set_var($key,$val);
                                $this->template->set_var('lang_' . $key, 
lang($key) . ':');
                        }

                        if($this->debug)
                        {
                                echo $this->docroot . SEP . 
$img[$id]['img_file'];
                        }
                        $imgSizeArray = GetImageSize($this->docroot . SEP . 
$img[$id]['img_file']);
                        $imgWidth     = $imgSizeArray[0];
                        $imgHeight    = $imgSizeArray[1];
                        $imgType      = $imgSizeArray[2];
                        if($this->debug)
                        {
                                echo '<br>uiiimg->edit(): called getimagesize(' 
. $this->docroot . SEP . $img[$id]['img_file'] . ')';
                                _debug_array($imgSizeArray);
                        }

                        if($imgHeight)
                        {
                                $detailstr = '(' . $imgWidth . ' X ' . 
$imgHeight . ' ' . $this->bo->img->convertArray[$imgType] . ')';
                        }
                        $this->template->set_var('img_link','<a 
href="javascript:openwindow(\''
                                . $img[$id]['img_file'] . "','" . $imgWidth . 
"','" . $imgHeight . '\')"><img src="' . $img[$id]['img_thumb']
                                . '" border="1" align="middle" alt="' . 
$img[$id]['img_file'] . $detailstr . '">&nbsp;</a>'
                        );
                        $this->template->set_var('detailstr',$detailstr);
                        $this->template->set_var('image_id',$id);
                        $this->template->set_var('editurl', 
$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.manipulate'));
                        $this->template->set_var('lang_edit_image', lang('Edit 
Image'));
                        
$this->template->set_var('picture',$img[$id]['img_file']);
                        $this->template->pfp('out','form');

                        $this->template->pfp('out','edit_footer');
                }

                /* Delete an existing img */
                function delete()
                {
                        $img_id = get_var('img_id',Array('POST','GET'));
                        $confirm = get_var('confirm',Array('GET'));

                        if (!$img_id)
                        {
                                Header('Location: ' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                        }

                        if ($confirm != 'true')
                        {
                                $this->template->set_file(array( 'delete' => 
'delete.tpl'));
                                
$this->template->set_block('delete','header','header');
                                
$this->template->set_block('delete','form','form');
                                
$this->template->set_block('delete','footer','footer');

                                $GLOBALS['phpgw']->common->phpgw_header();

                                $this->template->set_var('lang_sure',lang('Are 
you sure you want to delete this entry ?'));
                                
$this->template->set_var('nolink',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.index'));
                                $this->template->set_var('lang_no',lang('NO'));
                                
$this->template->set_var('yeslink',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.delete&img_id='
 . $img_id . '&confirm=true'));
                                
$this->template->set_var('lang_yes',lang('YES'));
                                $this->template->pparse('out','delete');
                        }
                        else
                        {
                                $this->bo->delete($img_id);
                                @Header('Location: ' . 
$GLOBALS['phpgw']->link('/img/index.php','menuaction=img.uiimg.index'));
                        }
                }

                function manipulate()
                {
                        $img_id    = get_var('img_id',Array('POST'));
                        $save      = get_var('save',Array('POST'));
//                      $action    = get_var('action',Array('POST'));
                        $convert   = get_var('convert',Array('POST'));
                        $rotate    = get_var('rotate',Array('POST'));
                        $resize    = get_var('resize',Array('POST'));
                        $dstW      = get_var('dstW',Array('POST'));
                        $dstH      = get_var('dstH',Array('POST'));
                        $angle     = get_var('angle',Array('POST'));
                        $thumbnail = get_var('thumbnail',Array('POST'));

                        $imgWidth = $imgHeight = $imgType = '';

                        $oldfile = 
get_var('oldfile',Array('DEFAULT','POST'),get_var('picture',Array('POST')));
                        if(!ereg("^$this->docroot",$oldfile))
                        {
                                $oldfile = $this->docroot . $oldfile;
                        }

                        $picturefile = 
get_var('picture',Array('DEFAULT','POST'),get_var('picturefile',Array('POST')));
                        if(!ereg("^$this->docroot",$picturefile))
                        {
                                $picturefile = $this->docroot . $picturefile;
                        }

                        if($this->debug)
                        {
                                echo '<br>uiiimg->manipulate(): $picturefile=' 
. $picturefile;
                        }

                        if(stat($picturefile))
                        {
                                $picfile = $picturefile;
                        }
                        else
                        {
                                $picfile = $picturefile['tmp_name'];
                        }
                        if($this->debug)
                        {
                                echo '<br>uiiimg->manipulate(): $picfile=' . 
$picfile;
                        }

                        $conTo  = get_var('conTo',Array('POST'));

                        $GLOBALS['phpgw']->common->phpgw_header();

                        if($save)
                        {
                                $message = lang('Saved') . ' ' . $picfile . ' ' 
. lang('as') . ' ' . $oldfile;
                                $picfile = 
$this->bo->img->smartcopy($picfile,$oldfile);
                                $oldfile = $picfile;
                                $entry = array(
                                        'img_id'    => $img_id,
                                        'img_file'  => $picfile,
                                        'img_thumb' => $thumbnail
                                );
                                $this->bo->edit($entry);
                        }

                        if(($convert || $rotate || $resize) || $picfile)
                        {
                                $imgSizeArray   = GetImageSize($picfile);
                                $imgWidth       = $imgSizeArray[0];
                                $imgHeight      = $imgSizeArray[1];
                                $imgType        = $imgSizeArray[2];
                                if($this->debug)
                                {
                                        echo '<br>uiiimg->manipulate(): called 
getimagesize(' . $picfile . ')';
                                        _debug_array($imgSizeArray);
                                }
                                switch ($imgType)
                                {
                                        case '1':
                                                // GIF
                                                if (imagetypes() & IMG_GIF)
                                                {
                                                        $im = 
imagecreatefromgif($picfile);
                                                }
                                                else
                                                {
                                                        $newtmp = 
$this->bo->img->convert($picfile,'png');
                                                        if($this->debug)
                                                        {
                                                                echo 
'<br>uiiimg->manipulate($convert): called img->convert('
                                                                        . 
$picfile  . ',png) to create: '
                                                                        . 
$newtmp;
                                                        }
                                                        $im = 
imagecreatefrompng($newtmp);
                                                        $picfile = $newtmp;
                                                        $imgType = 3;
                                                }
                                                break;
                                        case '2':
                                                //JPG
                                                $im = 
imagecreatefromjpeg($picfile);
                                                break;
                                        case '3':
                                                //PNG
                                                $im = 
imagecreatefrompng($picfile);
                                                break;
                                        case '4':
                                        default:
                                                $im = 
@ImageCreateFromWBMP($picfile);
                                                if(!$im)
                                                {
                                                        $imgError = 
$errorCode[0];
                                                }
                                }

                                if($imgError)
                                {
                                        echo '<font color="red">' . $imgError . 
'</font><br>';
                                }
                                elseif($convert)
                                {
                                        if($conTo == 1)
                                        {
                                                //GIF
                                                $NewImage = $this->docroot . 
$this->bo->img->image2gif($im);
                                        }
                                        elseif($conTo == 2)
                                        {
                                                //JPG
                                                $NewImage = $this->docroot . 
$this->bo->img->image2jpg($im);
                                        }
                                        elseif($conTo == 3)
                                        {
                                                //PNG
                                                $NewImage = $this->docroot . 
$this->bo->img->image2png($im);
                                        }
                                        elseif($conTo == 4)
                                        {
                                                //BMP
                                                $NewImage = $this->docroot . 
$this->bo->img->image2bmp($im);
                                        }
                                        if($this->debug)
                                        {
                                                echo 
'<br>uiiimg->manipulate($convert): created: ' . $NewImage;
                                        }
                                        $message = lang('Converted') . ' ' . 
$picfile . ' ' . lang('to') . ' ' . $NewImage;

                                        $picfile = $NewImage;
                                }
                                elseif($resize && $dstW && $dstH)
                                {
                                        $_ext = 
strtolower($this->bo->img->convertArray[$imgType]);
                                        $picfile = $this->docroot . 
$this->bo->img->resize($im,$imgWidth,$imgHeight,$dstW,$dstH,$_ext);
                                        if($this->debug)
                                        {
                                                echo 
'<br>uiiimg->manipulate($resize) called img->_resize($im,"'
                                                        . $imgWidth . '","' . 
$imgHeight . '","'
                                                        . $dstW . '","' . $dstH 
. '","' . $_ext . '" to create: '
                                                        . $picfile;
                                        }
                                        $newfile = $picfile . '.' . $_ext;
                                        copy($picfile,$newfile);
                                        unlink($picfile);
                                        $message = lang('Resized') . ' ' . 
$picfile . ' ' . lang('to') . ' ' . $newfile;
                                        $picfile = $newfile;
                                        if($this->debug)
                                        {
                                                echo 
'<br>uiiimg->manipulate($resize) renamed: '
                                                        . $picfile . ' to ' . 
$newfile;
                                        }
                                }
                                elseif($rotate && $angle)
                                {
                                        $message = lang('Rotated') . ' ' . 
$picfile . ' ' . lang('to') . ' ';
                                        $picfile = $this->docroot . 
$this->bo->img->rotate($im,$this->bo->img->angles[$angle]);
                                        if($this->debug)
                                        {
                                                echo 
'<br>uiiimg->manipulate($rotate): called img->rotate($im,"'
                                                        . 
$this->bo->img->angles[$angle] . '") to create: '
                                                        . $picfile;
                                        }
                                        $message .= $picfile;
                                }
                                else
                                {
                                }

                                $imgSizeArray   = GetImageSize($picfile);
                                $imgWidth       = $imgSizeArray[0];
                                $imgHeight      = $imgSizeArray[1];
                                $imgType        = $imgSizeArray[2];
                                switch ($imgType)
                                {
                                        case '1':
                                                // GIF
                                                if (imagetypes() & IMG_GIF)
                                                {
                                                        $im = 
imagecreatefromgif($picfile);
                                                }
                                                else
                                                {
                                                        $newtmp = 
$this->bo->img->convert($picfile,'png');
                                                        if($this->debug)
                                                        {
                                                                echo 
'<br>uiiimg->manipulate(): called img->convert('
                                                                        . 
$picfile  . ',png) to create: '
                                                                        . 
$newtmp;
                                                        }
                                                        $im = 
imagecreatefrompng($newtmp);
//                                                      $picfile = $newtmp;
                                                        $imgType = 3;
                                                }
                                                break;
                                        case '2':
                                                //JPG
                                                $im = 
imagecreatefromjpeg($picfile);
                                                break;
                                        case '3':
                                                //PNG
                                                $im = 
imagecreatefrompng($picfile);
                                                break;
                                        case '4':
                                        default:
                                                $im = 
@ImageCreateFromWBMP($picfile);
                                                if(!$im)
                                                {
                                                        $imgError = 
$errorCode[0];
                                                }
                                }
                                if($this->debug)
                                {
                                        _debug_array($imgSizeArray);
                                }
                                $ext = 
strtolower($this->bo->img->convertArray[$imgType]);
                                if($this->debug)
                                {
                                        echo '<br>uiiimg->manipulate(): calling 
img->thumbnail($im,'
                                                . $imgWidth . '","' . 
$imgHeight . '","100","' . $ext . '")';
                                }
                                $thumb = 
$this->bo->img->thumbnail($im,$imgWidth,$imgHeight,100,$ext);
                                //echo '<a href="' . 
$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.manipulate') . '">' 
. lang('Go Back') . '</a><br><br>';
                        }
                        else
                        {
                                $thumb = PHPGW_IMAGES . '/thumb.jpg';
                        }

                        if($imgHeight)
                        {
                                $detailstr = '(' . $imgWidth . ' X ' . 
$imgHeight . ' ' . $this->bo->img->convertArray[$imgType] . ')';
                        }

                        /* TODO */
                        unset($angle);
                        unset($conTo);
                        unset($dstW);
                        unset($dstH);

                        $this->template->set_file(array('manip' => 
'manip.tpl'));

                        
$this->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.manipulate'));
                        
$this->template->set_var('cancelurl',$GLOBALS['phpgw']->link('/index.php','menuaction=img.uiimg.edit&img_id='
 . $img_id));
                        $this->template->set_var('message',$message);
                        
$this->template->set_var('lang_original',lang('Original'));
                        
$this->template->set_var('lang_current',lang('Current'));
                        $this->template->set_var('lang_load_new',lang('Load 
New'));
                        
$this->template->set_var('lang_convert',lang('Convert'));
                        
$this->template->set_var('lang_convert_to',lang('Convert to'));
                        $this->template->set_var('lang_rotate',lang('Rotate'));
                        $this->template->set_var('lang_resize',lang('Resize'));
                        
$this->template->set_var('lang_target_width',lang('Target Width'));
                        
$this->template->set_var('lang_target_height',lang('Target Height'));
                        $this->template->set_var('lang_save',lang('Save'));
                        $this->template->set_var('lang_cancel',lang('Cancel'));
                        
$this->template->set_var('lang_thumb',lang('Thumbnail'));

                        $this->template->set_var('imgwidth',$imgWidth);
                        $this->template->set_var('imgheight',$imgHeight);
                        $this->template->set_var('dstW',$dstW);
                        $this->template->set_var('dstH',$dstH);
                        $this->template->set_var('img_id',$img_id);
                        $this->template->set_var('img_file',$picfile);
                        $this->template->set_var('oldfile',$oldfile);
                        $this->template->set_var('picfile',$picfile);
                        
$this->template->set_var('picurl',ereg_replace($this->docroot,'',$picfile));
                        $this->template->set_var('detailstr',$detailstr);
                        $this->template->set_var('thumb',$thumb);

                        while(list($key,$arrType) = 
each($this->bo->img->convertArray))
                        {
                                $convert_rows .= '<option value="' . $key . '"';
                                if($conTo == $key)
                                {
                                        $convert_rows .= ' selected';
                                }
                                $convert_rows .= '>'. lang($arrType) . 
'</option>' . "\n";
                        }
                        $this->template->set_var('convert_rows',$convert_rows);

                        while(list($key,$val) = each($this->bo->img->angles))
                        {
                                $rotate_rows .= '<option value="' . $key . '"';
                                if($angle == $key)
                                {
                                        $rotate_rows .= ' selected';
                                }
                                $rotate_rows .= '>'. $val . '</option>' . "\n";
                        }
                        $this->template->set_var('rotate_rows',$rotate_rows);

                        $this->template->pfp('out','manip');
                }

                function jsWindoPopUp($image, $width, $height)
                {
                        echo '<script language="javascript">';
                        echo '    window.open("' . $image . '" 
,"phpGW_Img","width=' . $width
                                . ',height=' . $height
                                . 
',menubar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0,hotkeys=0,locationbar=0");';
                        echo '</script>';
                }
        }
?>

====================================================
Index: class.soimg.inc.php
<?php
  /**************************************************************************\
  * phpGroupWare - Image Editor                                              *
  * http://www.phpgroupware.org                                              *
  * This application written by Miles Lott <address@hidden>        *
  * --------------------------------------------                             *
  *  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.                                              *
  \**************************************************************************/

  /* $Id: class.soimg.inc.php,v 1.1 2005/05/05 00:56:39 skwashd Exp $ */

        /* img storage class */
        class soimg
        {
                var $db;
                var $grants = '';

                var $debug=False;
                var $account_id;
                var $table = 'phpgw_img';
                var $fields = array(
                        'img_id'    => 0,
                        'img_owner' => 0,
                        'img_file'  => '',
                        'img_cat'   => '',
                        'img_name'  => '',
                        'img_title' => '',
                        'img_des'   => '',
                        'img_thumb' => '',
                        'img_copy'  => ''
                );
                var $qstr = '';

                function soimg($debug=False)
                {
                        $this->debug = $debug;
                        $this->db = $GLOBALS['phpgw']->db;
                        $this->account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];

                        $this->grants = 
$GLOBALS['phpgw']->acl->get_grants('img');
                }

                function 
index($start=0,$query='',$sort='ASC',$order='',$cat_id='',$limit=True)
                {
                        $fields = $this->_get_fields();
                        $fieldstr = implode(',',$fields);

                        if (is_array($this->grants))
                        {
                                $grants = $this->grants;
                                while (list($user) = each($grants))
                                {
                                        $public_user_list[] = $user;
                                }
                                reset($public_user_list);
                                $fwhere .= " OR (img_owner IN(" . 
implode(',',$public_user_list) . ")) ";
                        }

                        if($query || $this->qstr)
                        {
                                if($query)
                                {
                                        $querystr = $this->_makequery($query);
                                }
                                elseif($this->qstr)
                                {
                                        $querystr = 
$this->_makequery($this->qstr);
                                }
                                $querystr .= ' AND img_owner=' . 
$this->account_id . $fwhere;
                        }
                        else
                        {
                                $querystr .= ' WHERE img_owner=' . 
$this->account_id . $fwhere;
                        }

                        if ($cat_id)
                        {
                                if($querystr)
                                {
                                        $querystr .= ' AND';
                                }
                                else
                                {
                                        $querystr .= ' WHERE ';
                                }
                                $querystr .= ' img_cat=' . $cat_id;
                        }

                        $sql = "SELECT " . $fieldstr . " FROM " . $this->table 
. $querystr;

                        if($sort && $order)
                        {
                                $sort = ' ORDER BY ' . $order . ' ' . $sort . ' 
';
                        }
                        else
                        {
                                $sort = '';
                        }

                        if($limit)
                        {
                                $qfunc = '$this->db->limit_query("' . $sql . 
$sort . '",' . $start . ',__LINE__,__FILE__);';
                        }
                        else
                        {
                                $qfunc = '$this->db->query("' . $sql . $sort . 
'",__LINE__,__FILE__);';
                        }

                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->total = $this->db->num_rows();

                        eval($qfunc);

                        if($this->db->num_rows())
                        {
                                $this->data = array();
                        }
                        while ($this->db->next_record())
                        {
                                @reset($fields);
                                while(list($a,$b) = @each($fields))
                                {
                                        $this->data[$this->db->f('img_id')][$b] 
= $this->db->f($b);
                                }
                        }
                        return $this->data;
                }

                function read($id)
                {
                        if(is_array($id))
                        {
                                $id = $id['img_id'];
                        }
                        if (!(($this->grants[$check['img_owner']] & 
PHPGW_ACL_DELETE) ||
                                $check['img_owner'] == 
$GLOBALS['phpgw_info']['user']['account_id']))

                        $id = intval($id);
                        $sql = "SELECT * FROM $this->table WHERE img_id=$id";
                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->db->next_record();

                        if (!(($this->grants[$this->db->f('img_owner')] & 
PHPGW_ACL_READ) ||
                                $this->db->f('img_owner') == 
$GLOBALS['phpgw_info']['user']['account_id']))
                        {
                                return array(
                                        'img_id'   => $id,
                                        'img_name' => lang('access denied')
                                );
                        }

                        @reset($this->fields);
                        while(list($a,$b) = @each($this->fields))
                        {
                                $this->data[$this->db->f('img_id')][$a] = 
$this->db->f($a);
                        }
                        return $this->data;
                }

                function edit($data)
                {
                        $mode = 'add';
                        if($data['img_id'])
                        {
                                $mode = 'edit';
                        }

                        $id = intval($data['img_id']);
                        $sql = "SELECT * FROM $this->table WHERE img_id=$id";
                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->db->next_record();

                        if($mode == 'edit')
                        {
                                if (!(($this->grants[$this->db->f('img_owner')] 
& PHPGW_ACL_READ) ||
                                        $this->db->f('img_owner') == 
$GLOBALS['phpgw_info']['user']['account_id']))
                                {
                                        return array(
                                                'img_id'   => $id,
                                                'img_name' => lang('access 
denied')
                                        );
                                }
                        }

                        switch ($mode)
                        {
                                case 'add':
                                        $sql = "INSERT INTO $this->table 
(img_owner,img_file,img_cat,img_name,img_title,img_des,img_thumb,img_copy)"
                                                . " VALUES ("
                                                . "'" . $data['img_owner'] . 
"',"
                                                . "'" . $data['img_file']  . 
"',"
                                                . "'" . $data['img_cat']   . 
"',"
                                                . "'" . 
$this->db->db_addslashes($data['img_name'])  . "',"
                                                . "'" . 
$this->db->db_addslashes($data['img_title']) . "',"
                                                . "'" . 
$this->db->db_addslashes($data['img_des'])   . "',"
                                                . "'" . $data['img_thumb'] . 
"',"
                                                . "'" . $data['img_copy']  . "'"
                                                . ")";

                                        
$this->db->query($sql,__LINE__,__FILE__);
                                        $newid = 
$this->db->get_last_insert_id($this->table,'img_id');
                                        return $newid;
                                        break;
                                case 'edit':
                                        /*
                                         Read the old data and replace new 
values
                                         to make sure we don't lose something.
                                        */
                                        $old = $this->read($data['img_id']);
                                        $olddata = $old[$data['img_id']];

                                        @reset($data);
                                        while(list($key,$val) = @each($data))
                                        {
                                                $olddata[$key] = $val;
                                        }
                                        $data = $olddata;

                                        $sql = "UPDATE $this->table SET "
                                                . "img_owner='" . 
$data['img_owner'] . "',"
                                                . "img_file='"  . 
$data['img_file']  . "',"
                                                . "img_cat='"   . 
$data['img_cat']   . "',"
                                                . "img_name='"  . 
$this->db->db_addslashes($data['img_name'])  . "',"
                                                . "img_title='" . 
$this->db->db_addslashes($data['img_title']) . "',"
                                                . "img_des='"   . 
$this->db->db_addslashes($data['img_des'])   . "',"
                                                . "img_thumb='" . 
$data['img_thumb'] . "',"
                                                . "img_copy='"  . 
$data['img_copy']  . "'"
                                                . "WHERE img_id=" . 
$data['img_id'];

                                        
$this->db->query($sql,__LINE__,__FILE__);
                                        return $data['img_id'];
                                        break;
                                default:
                                        break;
                        }
                }

                function delete($id)
                {
                        $id = intval($id);
                        $sql = "SELECT * FROM $this->table WHERE img_id=$id";
                        $this->db->query($sql,__LINE__,__FILE__);
                        $this->db->next_record();

                        if (!(($this->grants[$this->db->f('img_owner')] & 
PHPGW_ACL_READ) ||
                                $this->db->f('img_owner') == 
$GLOBALS['phpgw_info']['user']['account_id']))
                        {
                                return;
                        }

                        $sql = "DELETE FROM $this->table WHERE img_id=" . $id;
                        $this->db->query($sql,__LINE__,__FILE__);
                }

                function _get_fields()
                {
                        if($this->qfields)
                        {
                                $tmp = explode(',',$this->qfields);
                                @reset($tmp);
                                while(list($key,$val) = @each($tmp))
                                {
                                        $fields[] = $val;
                                }
                        }
                        else
                        {
                                @reset($this->fields);
                                while (list($key,$val) = each($this->fields))
                                {
                                        $fields[] = $key;
                                }
                        }
                        return $fields;
                }

                function _makequery($query='')
                {
                        if (!$query || $this->qstr)
                        {
                                return;
                        }
                        elseif($query)
                        {
                                $look = $query;
                        }
                        else
                        {
                                $look = $this->qstr;
                        }

                        $s = " WHERE (";

                        $fields = $this->_get_fields();
                        while (list($key,$val) = each($fields))
                        {
                                if ($val != 'id')
                                {
                                        $s .= $val . " LIKE '%$look%' OR ";
                                }
                        }
                        $s = substr($s,0,-4);
                        $s .= ")";

                        return $s;
                }
        }
?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]