source: branches/2.2/filemanager/inc/upload.php @ 3415

Revision 3415, 7.0 KB checked in by amuller, 13 years ago (diff)

Ticket #1391 - Implementando notificação do FM

Line 
1<?php
2require_once '../../header.session.inc.php';
3/* This single file is used to increase upload_max_filesize and post_max_size using .htaccess*/
4if(!isset($GLOBALS['phpgw_info'])){
5        $GLOBALS['phpgw_info']['flags'] = array(
6                'currentapp' => 'filemanager',
7                'nonavbar'   => true,
8                'noheader'   => true
9        );
10}
11require_once '../../header.inc.php';
12
13$bo = CreateObject('filemanager.bofilemanager');
14
15$c = CreateObject('phpgwapi.config','filemanager');
16$c->read_repository();
17$current_config = $c->config_data;
18$upload_max_size = $current_config['filemanager_Max_file_size'];
19$path = $_POST['path'];
20$notifUser = $_POST['notifTo'];
21$show_upload_boxes = count($_FILES['upload_file']['name'])-1;
22
23function create_summaryImage($file){
24        list($width, $height,$image_type) = getimagesize($file);
25        switch($image_type)
26        {
27        case 1:
28                $image_big = imagecreatefromgif($file);
29                break;
30        case 2:
31                $image_big = imagecreatefromjpeg($file);
32                break;
33        case 3:
34                $image_big = imagecreatefrompng($file);
35                break;
36        default:
37                return false;
38        }
39        $max_resolution = 48;
40        if ($width > $height){
41                $new_width = $max_resolution;
42                $new_height = $height*($new_width/$width);
43        }
44        else {
45                $new_height = $max_resolution;
46                $new_width = $width*($new_height/$height);
47        }
48        $image_new = imagecreatetruecolor($new_width, $new_height);
49        imagecopyresampled($image_new, $image_big, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
50        ob_start();
51        imagepng($image_new);
52        $content = ob_get_clean();
53        return $content;
54}
55
56/* Its much faster test all files only one time */
57if(strlen($current_config['filemanager_antivirus_command']) > 0)
58{
59        $command = "nice -n19 ".$current_config['filemanager_antivirus_command'];
60        for($i = 0; $i != $show_upload_boxes; $i++)
61                $command .= " ".$_FILES['upload_file']['tmp_name'][$i];
62        $return=0;
63        exec("bash -c ".escapeshellcmd(escapeshellarg($command)),$output,$return);
64        if ($return == 1)
65        {
66                $_SESSION['response'] = serialize(array(0 => lang('Error:').lang('One of the files sent was considered infected')));
67                return;
68        }
69}
70
71if($path != '/')
72        for($i = 0; $i != $show_upload_boxes; $i++)
73        {
74                if($badchar = $bo->bad_chars($_FILES['upload_file']['name'][$i], True, True))
75                {
76                        $return[] = lang('Error:').lang('File names cannot contain "%1"', $badchar);
77                        continue;
78                }
79
80                # Check to see if the file exists in the database, and get its info at the same time
81                $ls_array = $bo->vfs->ls(array(
82                        'string'=> $path . '/' . $_FILES['upload_file']['name'][$i],
83                        'relatives'     => array(RELATIVE_NONE),
84                        'checksubdirs'  => False,
85                        'nofiles'       => True
86                ));
87
88                $fileinfo = $ls_array[0];
89
90                if($fileinfo['name'])
91                {
92                        if($fileinfo['mime_type'] == 'Directory')
93                        {
94                                $return[] = lang('Error:').lang('Cannot replace %1 because it is a directory', $fileinfo['name']);
95                                continue;
96                        }
97                }
98
99                if ($_FILES['upload_file']['size'][$i] > ($upload_max_size*1024*1024))
100                {
101                        $return[] = lang('The size of %1 has exceded the limit: %2', $_FILES['upload_file']['name'][$i], $upload_max_size);
102                        continue;
103                }
104                elseif($_FILES['upload_file']['size'][$i] > 0)
105                {
106                        if($fileinfo['name'] && $fileinfo['deleteable'] != 'N')
107                        {
108                                $_FILES['upload_file']['name'][$i] = date('Ymd-H:i')."-".$_FILES['upload_file']['name'][$i];
109                                $tmp_arr=array(
110                                        'from'  => $_FILES['upload_file']['tmp_name'][$i],
111                                        'to'    => $_FILES['upload_file']['name'][$i],
112                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
113
114                                );
115                                $bo->vfs->cp($tmp_arr);
116                                $tmp_arr=array(
117                                        'string'=> $_FILES['upload_file']['name'][$i],
118                                        'relatives'     => array(RELATIVE_ALL),
119                                        'attributes'    => array(
120                                                'owner_id' => $bo->userinfo['username'],
121                                                'modifiedby_id' => $bo->userinfo['username'],
122                                                'size' => $_FILES['upload_file']['size'][$i],
123                                                'mime_type' => $_FILES['upload_file']['type'][$i],
124                                                'deleteable' => 'Y',
125                                                'comment' => stripslashes($_POST['upload_comment'][$i])
126                                        )
127                                );
128                                $bo->vfs->set_attributes($tmp_arr);
129
130                                $return[] = lang("There is a file %1, that was not replaced",$_FILES['upload_file']['name'][$i]);
131                        }
132                        else
133                        {
134                                if ($bo->vfs->cp(array(
135                                        'from'=> $_FILES['upload_file']['tmp_name'][$i],
136                                        'to'=> $_FILES['upload_file']['name'][$i],
137                                        'relatives'     => array(RELATIVE_NONE|VFS_REAL, RELATIVE_ALL)
138                                )))
139                                {
140                                        $bo->vfs->set_attributes(array(
141                                                'string'=> $_FILES['upload_file']['name'][$i],
142                                                'relatives'     => array(RELATIVE_ALL),
143                                                'attributes'=> array(
144                                                        'mime_type' => $_FILES['upload_file']['type'][$i],
145                                                        'comment' => stripslashes($_POST['upload_comment'][$i])
146                                                )
147                                        ));
148                                }
149                                else{
150                                        $return[] = lang('Error:').lang('It was not possible to send your file');
151                                }
152
153                        }
154                }
155                elseif($_FILES['upload_file']['name'][$i])
156                {
157                        $bo->vfs->touch(array(
158                                'string'=> $_FILES['upload_file']['name'][$i],
159                                'relatives'     => array(RELATIVE_ALL)
160                        ));
161
162                        $bo->vfs->set_attributes(array(
163                                'string'=> $_FILES['upload_file']['name'][$i],
164                                'relatives'     => array(RELATIVE_ALL),
165                                'attributes'=> array(
166                                        'mime_type' => $_FILES['upload_file']['type'][$i],
167                                        'comment' => stripslashes($_POST['upload_comment'][$i])
168                                )
169                        ));
170
171                }
172
173                if (!(strpos(strtoupper($_FILES['upload_file']['type'][$i]),'IMAGE') === FALSE))
174                {
175                        $content = create_summaryImage($_FILES['upload_file']['tmp_name'][$i]);
176                        if ($content){
177                                $bo->vfs->set_summary(array(
178                                        'string'=> $_FILES['upload_file']['name'][$i],
179                                        'relatives' => array(RELATIVE_ALL),
180                                        'summary'=> $content
181                                ));
182                        }
183
184                }
185        }
186
187if(count($notifUser) > 0)
188{
189        define('PHPGW_INCLUDE_ROOT','../../');
190        define('PHPGW_API_INC','../../phpgwapi/inc');
191        include_once(PHPGW_API_INC.'/class.phpmailer.inc.php');
192        $mail = new PHPMailer();
193        $mail->IsSMTP();
194        $boemailadmin = CreateObject('emailadmin.bo');
195        $emailadmin_profile = $boemailadmin->getProfileList();
196        $emailadmin = $boemailadmin->getProfile($emailadmin_profile[0]['profileID']);
197        $mail->Host = $emailadmin['smtpServer'];
198        $mail->Port = $emailadmin['smtpPort'];
199        $mail->From = $GLOBALS['phpgw']->preferences->values['email'];
200        $mail->FromName = $GLOBALS['phpgw_info']['user']['fullname'];
201        $mail->IsHTML(true);
202        foreach ($notifUser as $userMail)
203        {
204                $mail->AddAddress($userMail);
205                $mail->Subject = lang("Filemanager notification");
206                $mail->Body = lang("The user %1, sent the file \"%2\" (type %3) and asked to notify you.",$GLOBALS['phpgw_info']['user']['fullname'],$_FILES['upload_file']['name'][0],$_FILES['upload_file']['type'][0])."<br>";
207                $mail->Body .= lang("Comments by user: %1",$_POST['upload_comment'][0])."<br>";
208                $mail->Body .= lang("The file can be accessed by: %1","<a href=\"".$GLOBALS['phpgw']->link("index.php").">link</a><br>");
209//              $mail->Body .= lang("The file can be accessed by: %1","<a href=\"".$GLOBALS['phpgw']->link("../index.php","menuaction=filemanager.uifilemanager.view&file=" . urlencode(base64_encode($_FILES['upload_file']['name'][0]))."&path=".urlencode(base64_encode($path)))."\">link</a><br>");
210                if(!$mail->Send()) {
211                        $return[] = $mail->ErrorInfo;
212                }
213        }
214}
215
216if (count($return) > 0){
217                $_SESSION['response'] = serialize($return);
218}
219        else
220                 $_SESSION['response'] = serialize( array( 0 => 'Ok' ) );
221?>
Note: See TracBrowser for help on using the repository browser.