phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] projects/inc/class.attached_files.inc.php, 1.1


From: nomail
Subject: [Phpgroupware-cvs] projects/inc/class.attached_files.inc.php, 1.1
Date: Wed, 11 Aug 2004 17:05:13 +0200

Update of /projects/inc
Added Files:
        Branch: 
          class.attached_files.inc.php

date: 2004/08/11 15:05:13;  author: ceb;  state: Exp;

Log Message:
update
=====================================================================
<?php
        /*******************************************************************\
        * phpGroupWare - Projects - attached_files                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/  *
        *                                                                   *
        * Written by Lars Piepho address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2004 Free Software Foundation, Inc.              *
        *                                                                   *
        * 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.               *
        *                                                                   *
        * This program is distributed in the hope that it will be useful,   *
        * but WITHOUT ANY WARRANTY; without even the implied warranty of    *
        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU  *
        * General Public License for more details.                          *
        *                                                                   *
        * You should have received a copy of the GNU General Public License *
        * along with this program; if not, write to the Free Software       *
        * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id: class.attached_files.inc.php,v 1.1 2004/08/11 15:05:13 ceb Exp 
$ */

        
        class attached_files
        {

                var $public_functions = array
                (
                        'show_file'             => True,
                        'save_file'     => True,
                        'delete_file'   => True,
                        'get_file'              => True
                );
                var $file;
                var $vfs;
                var $project_id;

                function attached_files()
                {
                        $this->file                     = $_REQUEST['file'];
                        $this->project_id       = $_REQUEST['project_id'];      
        
                        $this->vfs                      = 
CreateObject('phpgwapi.vfs');         
                }

                function show_file()
                {
                        $ls_array = $this->vfs->ls(array
                        (
                                'string'                => $this->file,
                                'relatives'             => array (RELATIVE_ALL),
                                'checksubdirs'  => False,
                                'nofiles'               => True
                        ));

                        if ($ls_array[0]['mime_type'])
                        {
                                $mime_type = $ls_array[0]['mime_type'];
                        }
                        elseif ($GLOBALS['settings']['viewtextplain'])
                        {
                                $mime_type = 'text/plain';
                        }
                        $filename = basename($this->file);
                        header('Content-type: ' . $mime_type);
                        header('Content-Disposition: attachment; filename=' . 
$filename);
                        echo $this->vfs->read(array
                                (
                                        'string'        => $this->file,
                                        'relatives'     => array(RELATIVE_NONE)
                                ));
                        $GLOBALS['phpgw']->common->phpgw_exit();
                }

                function save_file($project_id, $source = '', $destination = '')
                {
                        //Check if home/groupdirectory exists. If not, we 
create it
                        $basedir = $GLOBALS['basedir'] . '/projects';
                        if (!file_exists($basedir))
                        {
                                $this->vfs->override_acl = 1;
                                $this->vfs->mkdir(array
                                (
                                        'string'        => $basedir,
                                        'relatives'     => array (RELATIVE_ALL)
                                ));
                                $this->vfs->override_acl = 0;
                        }                               

                        $attdir = $basedir . '/' . $project_id;                 

                        if (!file_exists($attdir))
                        {
                                $this->vfs->override_acl = 1;
                                $this->vfs->mkdir(array
                                (
                                        'string' => $attdir,
                                        'relatives' => array (RELATIVE_ALL)
                                ));
                                $this->vfs->override_acl = 0;
                        }
                        
                        if(!$source || !$destination)
                        {
                                $source = $_FILES['attachment']['tmp_name'];
                                $destination = $_FILES['attachment']['name'];
                        }
                                                
                        $this->vfs->override_acl = 1;
                        $this->vfs->cp(array 
                        (
                                'from'          => $source,
                                'to'            => $attdir . '/' . $destination,
                                'relatives'     => array 
(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
                        ));
                        $this->vfs->override_acl = 0;
                }

                function delete_file($project_id = true)
                {
                        $basedir = $GLOBALS['basedir'] . '/projects';

                        if(!$this->file && file_exists($basedir . '/' . 
$project_id))
                        {
                                $this->vfs->override_acl = 1;
                                $this->vfs->delete(array
                                (
                                        'string'        => $basedir . '/' . 
$project_id,
                                        'relatives'     => array (RELATIVE_ALL)
                                ));
                                $this->vfs->override_acl = 0;
                        }
                        elseif($this->file)
                        {
                                $this->vfs->override_acl = 1;
                                $this->vfs->rm(array
                                (
                                        'string'        => $basedir . '/' . 
$this->project_id . '/' . $this->file,
                                        'relatives' => array (RELATIVE_ALL)
                                ));
                                $this->vfs->override_acl = 0;
                                
$GLOBALS['phpgw']->redirect_link('/index.php',array
                                                                                
                                        (
                                                                                
                                                'menuaction' => 
'projects.uiprojects.edit_project',
                                                                                
                                                'project_id' => 
$this->project_id
                                                                                
                                        ));
                        }
                }

                function get_files($project_id, $delete = false)
                {
                        $GLOBALS['phpgw']->db->query("SELECT name from 
phpgw_vfs where directory like '/projects/" . $project_id . "' AND size > 0 AND 
mime_type NOT like 'journal-deleted'",__LINE__,__FILE__);
                        $x = 0;
                        while ($GLOBALS['phpgw']->db->next_record() != '')
                        {
                                $attachment[$x] =  '/projects/' . $project_id . 
'/' . $GLOBALS['phpgw']->db->f('name');
                                ++$x;
                        }

                        for($i=0;$i <= $x-1;$i++)
                        {
                                $file = 
$GLOBALS['phpgw']->link('/index.php',array
                                                                                
                                        (
                                                                                
                                                'menuaction'    => 
'projects.attached_files.show_file',
                                                                                
                                                'file'                  => 
$attachment[$i]
                                                                                
                                        ));
                                if($delete)
                                {
                                        $delFile = basename($attachment[$i]);
                                        $delLink = 
$GLOBALS['phpgw']->link('/index.php',array
                                                                                
                                                        (
                                                                                
                                                                'menuaction'    
=> 'projects.attached_files.delete_file',
                                                                                
                                                                'project_id'    
=> $project_id,
                                                                                
                                                                'file'          
        => $delFile
                                                                                
                                                        ));
                                        $del = '<a href="' . $delLink . '"><img 
src="' . $GLOBALS['phpgw']->common->image('phpgwapi','delete') . '" title="' . 
lang('delete') . '" border="0"></a>';
                                }
                                $attLink .= '<a href="' . $file . '" 
target="_blank">' . basename($attachment[$i]) . '</a>&nbsp&nbsp' . $del . '<br 
/>';
                        }
                        return ($attLink);
                }
        }
?>




reply via email to

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