phpgroupware-cvs
[Top][All Lists]
Advanced

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

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


From: nomail
Subject: [Phpgroupware-cvs] projects/inc/class.attachedFiles.inc.php, 1.1
Date: Sun, 23 May 2004 13:54:58 -0000

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

date: 2004/04/28 13:34:46;  author: ceb;  state: Exp;

Log Message:
update
=====================================================================
<?php
        /*******************************************************************\
        * phpGroupWare - Projects - attachedFiles                           *
        * http://www.phpgroupware.org                                       *
        * This program is part of the GNU project, see http://www.gnu.org/  *
        *                                                                   *
        * Written by Lars Piepho address@hidden                   *
        * -----------------------------------------------                   *
        * Copyright 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.attachedFiles.inc.php,v 1.1 2004/04/28 13:34:46 ceb Exp $ 
*/

        
        class attachedFiles
        {

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

                function attachedFiles()
                {               
                        $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)
                {
                        //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;                 

                        $this->vfs->override_acl = 1;
                        $this->vfs->mkdir (array (
                                                'string' => $attdir,
                                                'relatives' => array 
(RELATIVE_ALL)));
                        $this->vfs->override_acl = 0;
                                                
                        $this->vfs->override_acl = 1;
                        $this->vfs->cp(array (
                                                'from'  => 
$_FILES['attachment']['tmp_name'],
                                                'to'    => $attdir . '/' . 
$_FILES['attachment']['name'],
                                                '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)
                        {
                                $this->vfs->override_acl = 1;
                                $this->vfs->delete(array (
                                                'string' => $basedir . "/" . 
$project_id,
                                                'relatives' => array 
(RELATIVE_ALL)));
                                $this->vfs->override_acl = 0;
                        }
                        else
                        {
                                $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.attachedFiles.show_file',
                                                                                
                                        'file' => $attachment[$i]
                                                                                
                                        ));
                                if($delete)
                                {
                                        $delFile = basename($attachment[$i]);   
                                
                                        $delLink = 
$GLOBALS['phpgw']->link('/index.php',Array(
                                                                                
                                        'menuaction' => 
'projects.attachedFiles.delete_file',
                                                                                
                                        'project_id' => $project_id,
                                                                                
                                        'file' => $delFile
                                                                                
                                        ));
                                        $del = "<a href=\"" . $delLink . 
"\"><img src=\"projects/templates/default/images/delete.png\"></a>";
                                }
                                
                                $attLink .= "<a href=\"" . $file . "\" 
target=\"_NEW\">" . basename($attachment[$i]) . " </a>&nbsp&nbsp" . $del . 
"<br>";
                        }                                       
                        return ($attLink);
                }
        }
?>




reply via email to

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