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

Revision 3632, 15.7 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               
93                $vars = array(
94                                                'lang_directory'                => lang('directory'),
95                                                'lang_search'                   => lang('search'),
96                                                'lang_setowner'                 => lang('set owner'),
97                                                'lang_setperm'                  => lang('set permission'),
98                                                'lang_users_and_groups' => lang('Users and groups')
99                                        );
100               
101                $this->template->set_var($vars);
102                $this->template->pparse('out','body');
103
104        $GLOBALS['phpgw']->common->phpgw_footer();
105        $GLOBALS['phpgw']->common->phpgw_exit();
106         }
107
108        function createFolder()
109        {
110                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
111                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
112                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
113                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
114                         
115                 $this->bo = CreateObject('filemanager.bofilemanager');
116                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
117                 if (strlen($name) < 2)
118                         return false;
119                 $c = CreateObject('phpgwapi.config','filemanager');
120                 $c->read_repository();
121                 $current_config = $c->config_data;
122
123                 $this->bo->vfs->override_acl = 1;
124
125                 if ( $this->bo->vfs->mkdir(array(
126                         'string' => $name,
127                         'relatives' => array(RELATIVE_NONE)
128                 )) )
129                 if ( $this->bo->vfs->set_quota(array(
130                         'string' => $name,
131                         'relatives' => array(RELATIVE_NONE),
132                         'new_quota' => $current_config['filemanager_quota_size']
133                 )) )
134                 $return = True;
135
136                 $this->bo->vfs->override_acl = 0;
137                 if ($return){
138                         echo "Folder created";
139                 }
140                 else
141                         echo "Error";
142         }
143
144         function removeFolder()
145         {
146                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
147                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
148                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
149                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
150                         
151                 $this->bo = CreateObject('filemanager.bofilemanager');
152                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
153                 if (strlen($name) < 2)
154                         return false;
155                 if (    $this->bo->vfs->delete(array(
156                         'string' => $name,
157                         'relatives' => array(RELATIVE_NONE)
158                 )) )
159                 {
160                         /* Clean the log */
161                         $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_vfs WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
162                         if ($GLOBALS['phpgw']->db->Error)
163                                 echo "Erro";
164                         else
165                         {               
166                                 $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_vfs_quota WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
167                                 if (!$GLOBALS['phpgw']->db->Error)
168                                         echo lang('directory removed sucessfully');
169                                 else
170                                         echo "Erro";
171                         }
172                 }
173                 return;
174
175        }
176       
177        function reconstructFolder()
178        {
179                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
180                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
181                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
182                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
183                         
184                 $this->bo = CreateObject('filemanager.bofilemanager');
185                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
186                 if (strlen($name) < 2)
187                         return false;
188                 $this->bo->vfs->update_real(array(
189                         'string'        => $name,
190                         'relatives'     => array(RELATIVE_NONE)
191                 ),True);
192                 $this->bo->vfs->flush_journal(array(
193                         'string' => $name,
194                         'relatives' => array(RELATIVE_NONE),
195                         'deleteall' => True
196                 ));
197                 echo lang('Your operation was successfully executed');
198        }
199
200        function renameFolder()
201        {
202                 $GLOBALS['phpgw_info']['flags'] = array
203                         (
204                                 'currentapp'    => 'filemanager',
205                                 'noheader'      => True,
206                                 'nonavbar' => True,
207                                 'nofooter'      => True,
208                                 'noappheader'   => True,
209                                 'enable_browser_class'  => True
210                         );
211                 $this->bo = CreateObject('filemanager.bofilemanager');
212                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
213                 $to = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['to']));
214                 if (strlen($name) < 2)
215                         return false;
216                if ( $this->bo->vfs->mv(array(
217                         'from'        => $name,
218                         'to'   => $to,
219                         'relatives'     => array(RELATIVE_NONE)
220                 )) ){
221                         $this->bo->vfs->flush_journal(array(
222                                 'string' => $name,
223                                 'relatives' => array(RELATIVE_NONE),
224                                 'deleteall' => True
225                         ));
226                         echo lang('Your operation was successfully executed');
227                 }
228                else
229                        echo lang('Error');
230        }
231
232        function quota()
233        {
234                $GLOBALS['phpgw']->common->phpgw_header();
235
236                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
237                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
238                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
239
240                $this->template->set_file(array('config_list' => 'config_quota.tpl'));
241                $this->template->set_block('config_list','body','body');
242
243                $vars = array(
244                                                'lang_directory' => lang('directory'),
245                                                'lang_save' =>lang('save'),                                             
246                                                'lang_search' => lang('search')
247                                        );
248
249                $this->template->set_var($vars);
250                $this->template->pparse('out','body');
251
252                $GLOBALS['phpgw']->common->phpgw_footer();
253        $GLOBALS['phpgw']->common->phpgw_exit();
254        }
255         
256        function notifyUploads()
257        {
258                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Filemanager') ." - " . lang("Email notify uploads");
259                $GLOBALS['phpgw']->common->phpgw_header();
260               
261                if( $_POST['button_add'] )
262                {
263                        $vars = array(
264                                                        'action_url_back'       => "./index.php?menuaction=filemanager.uiconfig.notifyUploads",
265                                                        'lang_Add'                      => lang("Add"),
266                                                        'lang_Back'                     => lang("Back"),
267                                                        'lang_Email'            => lang("Email"),
268                                                        'lang_Excluir'          => lang("Delete"),
269                                                        'lang_legend1'          => lang("When the user with the email send a file"),
270                                                        'lang_legend2'          => lang("Notify email"),
271                                                        'lang_legend3'          => lang("Emails reported"),
272                                                        'lang_from'                     => lang("From"),
273                                                        'lang_to'                       => lang("To"),
274                                                        'value_conf_email'      => "",
275                                                 );     
276                       
277                        $handle = "AddEmail";
278                }
279                else
280                {       
281                        $value_config = "";
282                       
283                        if( trim($_POST['search_email']) != "" )
284                        {
285                                require_once("class.notifications.inc.php");
286                                $notify = new notifications();
287                                $result = $notify->SearchEmail( $_POST['search_email'] );
288
289                                foreach( $result as $tmp )
290                                {
291                                        $value_config .= '<tr>';
292                                        $value_config .= '<td align="left" width="40%">'.$tmp['email_from'].'</td>';
293                                        $value_config .= '<td align="left" width="40%">'.str_replace(",", "<br/>", $tmp['email_to']).'</td>';
294                                        $value_config .= '<td align="center" width="10%">Editar</td>';
295                                        $value_config .= '<td align="center" width="10%"><a href="javascript:void();" onclick="notify.deleteEmailUser(\''.$tmp['filemanager_id'].'\', this);">Excluir</a></td>';
296                                        $value_config .= '</tr>';
297                                }
298                        }
299                       
300                        $vars = array(
301                                                        'action_url'            => "./index.php?menuaction=filemanager.uiconfig.notifyUploads",
302                                                        'action_url_back'       => "./admin",
303                                                        'bt_previous'           => "<input type='submit' name='bt_previous' value='Anterior' />",
304                                                        'bt_next'                       => "<input type='submit' name='bt_next' value='Proximo' />",
305                                                        'lang_search'           => lang("Search"),
306                                                        'value_config'          => $value_config                                                                                                       
307                                                 );
308                       
309                        $handle = "index";
310                }
311
312                $this->template->set_file(array('config_email' => 'notify_upload.tpl'));
313                $this->template->set_block('config_email',$handle);
314                $this->template->set_var($vars);
315                $this->template->pparse('out',$handle);
316
317        $GLOBALS['phpgw']->common->phpgw_footer();
318        $GLOBALS['phpgw']->common->phpgw_exit();
319        }
320         
321        function search_dir()
322        {
323                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
324                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
325                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
326                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
327                         
328                 $name = $GLOBALS['phpgw']->db->db_addslashes($_GET['name']);
329                 $GLOBALS['phpgw']->db->query('SELECT DISTINCT directory FROM phpgw_vfs WHERE (directory like \'%'.$name.'%\') LIMIT 20',__LINE__,__FILE__);
330                 while ($GLOBALS['phpgw']->db->next_record()){
331                         $val = $GLOBALS['phpgw']->db->row();
332                         echo "<option>".$val['directory']."</option>";
333                 }
334                 $GLOBALS['phpgw']->db->query('SELECT directory,name from phpgw_vfs WHERE directory = \'/home\' and name like \'%'.$name.'%\' LIMIT 1',__LINE__,__FILE__);
335                 if ($GLOBALS['phpgw']->db->next_record()){
336                         $val = $GLOBALS['phpgw']->db->row();
337                         echo "<option>".$val['directory']."/".$val['name']."</option>";
338                 }
339               
340
341        }
342       
343        function search_user()
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                 $account_info = $GLOBALS['phpgw']->accounts->get_list('both',0,'','',$_GET['name'],'all');
351
352                 foreach($account_info as $val)
353                         echo "<option value='".$val['account_id']."'>".$val['account_lid']."</option>";
354        }
355       
356        function set_permission()
357        {
358                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
359                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
360                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
361                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
362
363                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
364                 $perms = ($_GET['perms'])*1;
365                 $owner = ($_GET['owner'])*1;
366                 $dirs=explode('/',$name);
367                 $GLOBALS['phpgw']->db->query('SELECT owner_id  from phpgw_vfs  WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\' LIMIT 1',__LINE__,__FILE__);
368                 if ($GLOBALS['phpgw']->db->next_record()){
369                         $val = $GLOBALS['phpgw']->db->row();
370                         $owner_id = $val['owner_id'];
371                 }
372
373                 $query = "SELECT count(*) FROM phpgw_acl WHERE acl_appname = 'filemanager' and acl_account = '".$owner_id."' and acl_location='".$owner."'";
374                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
375                         $val = $GLOBALS['phpgw']->db->row();
376                 else
377                 {
378                         echo $GLOBALS['phpgw']->db->error;
379                         return false;
380                 }
381                 if ($val['count'] == '1')
382                        $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__);
383                 else
384                         $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_acl values('filemanager','".$owner."','".$owner_id."',".$perms.")",__LINE__,__FILE__);
385                 if ($GLOBALS['phpgw']->db->Error)
386                         echo "Erro";
387                 else
388                 {
389                        echo lang('entry updated sucessfully');
390                 }
391                 return;
392        }
393
394
395        function set_owner()
396        {
397                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
398                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
399                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
400                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
401                 
402                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
403                 $owner = ($_GET['owner'])*1;
404
405                 $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
406                 if ($GLOBALS['phpgw']->db->Error)
407                         echo "Erro";
408                 else
409                 {
410                         $dirs=explode('/',$name);
411                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\'',__LINE__,__FILE__);
412                         if ($GLOBALS['phpgw']->db->Error)
413                                 echo "Erro";
414                         else
415                         {
416                                 echo lang('entry updated sucessfully');
417                         }
418                 }
419                 return;
420        }
421
422        function update_quota()
423        {
424                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
425                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
426                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
427                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
428                         
429                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
430                 $size = ($_GET['val'])*1;
431
432                 /* See if quota exists or not */
433                 $query = "SELECT count(directory) FROM phpgw_vfs_quota WHERE directory = '".$name."' LIMIT 1";
434                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
435                         $val = $GLOBALS['phpgw']->db->row();
436                 else
437                 {
438                         echo $GLOBALS['phpgw']->db->error;
439                         return false;
440                 }
441                 if ($val['count'] == '1')
442                 {
443                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs_quota SET quota_size = '.$size.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
444                         if ($GLOBALS['phpgw']->db->Error)
445                                 echo "Erro";
446                         else
447                                 echo lang('entry updated sucessfully');
448                 }
449                 else
450                 {
451                         /*preferences does not exist*/
452                         $query = "INSERT INTO phpgw_vfs_quota values ('".$name."',".$size.")";
453                         if (!$GLOBALS['phpgw']->db->query($query))
454                                 echo $GLOBALS['phpgw']->db->error;
455                         else
456                                 echo lang('entry updated sucessfully');
457                 }
458                 return;
459         }
460         
461         function load_quota()
462         {
463                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
464                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
465                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
466                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
467                         
468                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
469                 $GLOBALS['phpgw']->db->query('SELECT quota_size FROM phpgw_vfs_quota WHERE directory = \''.$name.'\' LIMIT 1',__LINE__,__FILE__);
470                 $GLOBALS['phpgw']->db->next_record();
471                 $val =$GLOBALS['phpgw']->db->row();
472                 echo $val['quota_size'];
473                 return;
474
475         }
476}
477
478?>
Note: See TracBrowser for help on using the repository browser.