source: branches/2.2/filemanager/inc/class.uiconfig.inc.php @ 3619

Revision 3619, 14.0 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1468 - Notificacao por email de uploads de arquivos enviados pelo modulo Filemanager

Line 
1<?php
2        /**************************************************************************\
3        * -------------------------------------------------------------------------*
4        * This library is free software; you can redistribute it and/or modify it  *
5        * under the terms of the GNU Lesser General Public License as published by *
6        * the Free Software Foundation; either version 2.1 of the License,         *
7        * or any later version.                                                    *
8        \**************************************************************************/
9
10require_once("load_lang.php");
11
12class uiconfig
13{
14        private $bo;
15        private $template;
16       
17        var $public_functions = array
18        (
19                'createFolder'          => True,
20                'folders'                       => True,
21                'groups_users'          => True,               
22                'load_quota'            => True,
23                'notifyUploads'         => True,
24                'renameFolder'          => True,
25                'removeFolder'          => True,
26                'reconstructFolder'     => True,
27                'search_dir'            => True,
28                'set_owner'                     => True,               
29                'search_user'           => True,
30                'set_permission'        => True,
31                'update_quota'          => True,
32                'quota'                         => True
33         );
34
35        function uiconfig()
36        {
37                 $this->bo                      = CreateObject('filemanager.bofilemanager');
38                 $this->template        = $GLOBALS['phpgw']->template;
39                 
40                 $GLOBALS['phpgw_info']['flags'] = array
41                         (
42                                 'currentapp'           => 'filemanager',
43                                 'noheader'             => False,
44                                 'nonavbar'             => False,
45                                 'nofooter'             => False,
46                                 'noappheader'          => False,
47                                 'enable_browser_class'  => True
48                         );
49        }
50
51        function vfs_functions(){}
52       
53        function folders()
54        {
55                $GLOBALS['phpgw']->common->phpgw_header();
56
57                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
58                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
59                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
60
61
62                $this->template->set_file(array('config_list' => 'config_folders.tpl'));
63                $this->template->set_block('config_list','body','body');
64               
65                $vars = array(
66                                        'lang_directory'        => lang('directory'),
67                                        'lang_search'           => lang('search'),
68                                        'lang_remove'           => lang('remove'),
69                                        'lang_rename'           =>lang('rename'),
70                                        'lang_create'           => lang('create'),
71                                        'lang_reconstruct'      => lang('reconstruct')
72                                );
73
74                $this->template->set_var($vars);
75                $this->template->pparse('out','body');
76       
77        $GLOBALS['phpgw']->common->phpgw_footer();
78        $GLOBALS['phpgw']->common->phpgw_exit();
79       
80         }
81
82         function groups_users()
83         {
84                $GLOBALS['phpgw']->common->phpgw_header();
85
86                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
87                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
88                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
89
90                $this->template->set_file(array('config_list' => 'config_owner.tpl'));
91                $this->template->set_block('config_list','body','body');
92                $vars[lang_users_and_groups]=lang('Users and groups');
93                $vars[lang_search]=lang('search');
94                $vars[lang_directory]=lang('directory');
95                $vars[lang_setowner]=lang('set owner');
96                $vars[lang_setperm]=lang('set permission');
97
98                $this->template->set_var($vars);
99                $this->template->pparse('out','body');
100                    $GLOBALS['phpgw']->common->phpgw_footer();
101                    $GLOBALS['phpgw']->common->phpgw_exit();
102
103         }
104
105        function createFolder()
106        {
107                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
108                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
109                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
110                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
111                         
112                 $this->bo = CreateObject('filemanager.bofilemanager');
113                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
114                 if (strlen($name) < 2)
115                         return false;
116                 $c = CreateObject('phpgwapi.config','filemanager');
117                 $c->read_repository();
118                 $current_config = $c->config_data;
119
120                 $this->bo->vfs->override_acl = 1;
121
122                 if ( $this->bo->vfs->mkdir(array(
123                         'string' => $name,
124                         'relatives' => array(RELATIVE_NONE)
125                 )) )
126                 if ( $this->bo->vfs->set_quota(array(
127                         'string' => $name,
128                         'relatives' => array(RELATIVE_NONE),
129                         'new_quota' => $current_config['filemanager_quota_size']
130                 )) )
131                 $return = True;
132
133                 $this->bo->vfs->override_acl = 0;
134                 if ($return){
135                         echo "Folder created";
136                 }
137                 else
138                         echo "Error";
139         }
140
141         function removeFolder()
142         {
143                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
144                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
145                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
146                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
147                         
148                 $this->bo = CreateObject('filemanager.bofilemanager');
149                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
150                 if (strlen($name) < 2)
151                         return false;
152                 if (    $this->bo->vfs->delete(array(
153                         'string' => $name,
154                         'relatives' => array(RELATIVE_NONE)
155                 )) )
156                 {
157                         /* Clean the log */
158                         $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_vfs WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
159                         if ($GLOBALS['phpgw']->db->Error)
160                                 echo "Erro";
161                         else
162                         {               
163                                 $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_vfs_quota WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
164                                 if (!$GLOBALS['phpgw']->db->Error)
165                                         echo lang('directory removed sucessfully');
166                                 else
167                                         echo "Erro";
168                         }
169                 }
170                 return;
171
172        }
173       
174        function reconstructFolder()
175        {
176                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
177                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
178                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
179                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
180                         
181                 $this->bo = CreateObject('filemanager.bofilemanager');
182                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
183                 if (strlen($name) < 2)
184                         return false;
185                 $this->bo->vfs->update_real(array(
186                         'string'        => $name,
187                         'relatives'     => array(RELATIVE_NONE)
188                 ),True);
189                 $this->bo->vfs->flush_journal(array(
190                         'string' => $name,
191                         'relatives' => array(RELATIVE_NONE),
192                         'deleteall' => True
193                 ));
194                 echo lang('Your operation was successfully executed');
195        }
196
197        function renameFolder()
198        {
199                 $GLOBALS['phpgw_info']['flags'] = array
200                         (
201                                 'currentapp'    => 'filemanager',
202                                 'noheader'      => True,
203                                 'nonavbar' => True,
204                                 'nofooter'      => True,
205                                 'noappheader'   => True,
206                                 'enable_browser_class'  => True
207                         );
208                 $this->bo = CreateObject('filemanager.bofilemanager');
209                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
210                 $to = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['to']));
211                 if (strlen($name) < 2)
212                         return false;
213                if ( $this->bo->vfs->mv(array(
214                         'from'        => $name,
215                         'to'   => $to,
216                         'relatives'     => array(RELATIVE_NONE)
217                 )) ){
218                         $this->bo->vfs->flush_journal(array(
219                                 'string' => $name,
220                                 'relatives' => array(RELATIVE_NONE),
221                                 'deleteall' => True
222                         ));
223                         echo lang('Your operation was successfully executed');
224                 }
225                else
226                        echo lang('Error');
227        }
228
229        function quota()
230        {
231                $GLOBALS['phpgw']->common->phpgw_header();
232                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
233                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
234                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
235
236                $this->template->set_file(array('config_list' => 'config_quota.tpl'));
237                $this->template->set_block('config_list','body','body');
238                $vars[lang_directory]=lang('directory');
239                $vars[lang_search]=lang('search');
240                $vars[lang_save]=lang('save');
241
242                $this->template->set_var($vars);
243                $this->template->pparse('out','body');
244                $GLOBALS['phpgw']->common->phpgw_footer();
245        $GLOBALS['phpgw']->common->phpgw_exit();
246
247        }
248         
249        function notifyUploads()
250        {
251                $GLOBALS['phpgw']->common->phpgw_header();
252               
253                $this->template->set_file(array('config_email' => 'notify_upload.tpl'));
254                $this->template->set_block('config_email','body','body');
255               
256                $vars = array(
257                                                'action_url_back' => './admin',
258                                                'bt_previous' => '<input type="submit" name="bt_previous" value="Anterior" />',
259                                                'bt_next' => '<input type="submit" name="bt_next" value="Proximo" />',                                                                                                 
260                                        );
261               
262                $this->template->set_var($vars);
263                $this->template->pparse('out','body');
264               
265        $GLOBALS['phpgw']->common->phpgw_footer();
266        $GLOBALS['phpgw']->common->phpgw_exit();
267        }
268         
269        function search_dir()
270        {
271                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
272                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
273                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
274                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
275                         
276                 $name = $GLOBALS['phpgw']->db->db_addslashes($_GET['name']);
277                 $GLOBALS['phpgw']->db->query('SELECT DISTINCT directory FROM phpgw_vfs WHERE (directory like \'%'.$name.'%\') LIMIT 20',__LINE__,__FILE__);
278                 while ($GLOBALS['phpgw']->db->next_record()){
279                         $val = $GLOBALS['phpgw']->db->row();
280                         echo "<option>".$val['directory']."</option>";
281                 }
282                 $GLOBALS['phpgw']->db->query('SELECT directory,name from phpgw_vfs WHERE directory = \'/home\' and name like \'%'.$name.'%\' LIMIT 1',__LINE__,__FILE__);
283                 if ($GLOBALS['phpgw']->db->next_record()){
284                         $val = $GLOBALS['phpgw']->db->row();
285                         echo "<option>".$val['directory']."/".$val['name']."</option>";
286                 }
287               
288
289        }
290       
291        function search_user()
292        {
293                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
294                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
295                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
296                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
297
298                 $account_info = $GLOBALS['phpgw']->accounts->get_list('both',0,'','',$_GET['name'],'all');
299
300                 foreach($account_info as $val)
301                         echo "<option value='".$val['account_id']."'>".$val['account_lid']."</option>";
302        }
303       
304        function set_permission()
305        {
306                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
307                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
308                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
309                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
310
311                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
312                 $perms = ($_GET['perms'])*1;
313                 $owner = ($_GET['owner'])*1;
314                 $dirs=explode('/',$name);
315                 $GLOBALS['phpgw']->db->query('SELECT owner_id  from phpgw_vfs  WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\' LIMIT 1',__LINE__,__FILE__);
316                 if ($GLOBALS['phpgw']->db->next_record()){
317                         $val = $GLOBALS['phpgw']->db->row();
318                         $owner_id = $val['owner_id'];
319                 }
320
321                 $query = "SELECT count(*) FROM phpgw_acl WHERE acl_appname = 'filemanager' and acl_account = '".$owner_id."' and acl_location='".$owner."'";
322                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
323                         $val = $GLOBALS['phpgw']->db->row();
324                 else
325                 {
326                         echo $GLOBALS['phpgw']->db->error;
327                         return false;
328                 }
329                 if ($val['count'] == '1')
330                        $GLOBALS['phpgw']->db->query("UPDATE phpgw_acl SET acl_rights = ".$perms." where acl_appname = 'filemanager' and acl_account = '".$owner_id."' AND acl_location = '".$owner."'",__LINE__,__FILE__);
331                 else
332                         $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_acl values('filemanager','".$owner."','".$owner_id."',".$perms.")",__LINE__,__FILE__);
333                 if ($GLOBALS['phpgw']->db->Error)
334                         echo "Erro";
335                 else
336                 {
337                        echo lang('entry updated sucessfully');
338                 }
339                 return;
340        }
341
342
343        function set_owner()
344        {
345                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
346                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
347                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
348                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
349                 
350                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
351                 $owner = ($_GET['owner'])*1;
352
353                 $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
354                 if ($GLOBALS['phpgw']->db->Error)
355                         echo "Erro";
356                 else
357                 {
358                         $dirs=explode('/',$name);
359                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\'',__LINE__,__FILE__);
360                         if ($GLOBALS['phpgw']->db->Error)
361                                 echo "Erro";
362                         else
363                         {
364                                 echo lang('entry updated sucessfully');
365                         }
366                 }
367                 return;
368        }
369
370        function update_quota()
371        {
372                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
373                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
374                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
375                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
376                         
377                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
378                 $size = ($_GET['val'])*1;
379
380                 /* See if quota exists or not */
381                 $query = "SELECT count(directory) FROM phpgw_vfs_quota WHERE directory = '".$name."' LIMIT 1";
382                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
383                         $val = $GLOBALS['phpgw']->db->row();
384                 else
385                 {
386                         echo $GLOBALS['phpgw']->db->error;
387                         return false;
388                 }
389                 if ($val['count'] == '1')
390                 {
391                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs_quota SET quota_size = '.$size.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
392                         if ($GLOBALS['phpgw']->db->Error)
393                                 echo "Erro";
394                         else
395                                 echo lang('entry updated sucessfully');
396                 }
397                 else
398                 {
399                         /*preferences does not exist*/
400                         $query = "INSERT INTO phpgw_vfs_quota values ('".$name."',".$size.")";
401                         if (!$GLOBALS['phpgw']->db->query($query))
402                                 echo $GLOBALS['phpgw']->db->error;
403                         else
404                                 echo lang('entry updated sucessfully');
405                 }
406                 return;
407         }
408         
409         function load_quota()
410         {
411                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
412                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
413                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
414                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
415                         
416                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
417                 $GLOBALS['phpgw']->db->query('SELECT quota_size FROM phpgw_vfs_quota WHERE directory = \''.$name.'\' LIMIT 1',__LINE__,__FILE__);
418                 $GLOBALS['phpgw']->db->next_record();
419                 $val =$GLOBALS['phpgw']->db->row();
420                 echo $val['quota_size'];
421                 return;
422
423         }
424}
425
426?>
Note: See TracBrowser for help on using the repository browser.