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

Revision 3636, 17.2 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");
11require_once("class.notifications.inc.php");
12
13class uiconfig
14{
15        private $bo;
16        private $template;
17       
18        var $public_functions = array
19        (
20                'createFolder'          => True,
21                'folders'                       => True,
22                'groups_users'          => True,               
23                'load_quota'            => True,
24                'notifyUploads'         => True,
25                'renameFolder'          => True,
26                'removeFolder'          => True,
27                'reconstructFolder'     => True,
28                'search_dir'            => True,
29                'set_owner'                     => True,               
30                'search_user'           => True,
31                'set_permission'        => True,
32                'update_quota'          => True,
33                'quota'                         => True
34         );
35
36        function uiconfig()
37        {
38                 $this->bo                      = CreateObject('filemanager.bofilemanager');
39                 $this->template        = $GLOBALS['phpgw']->template;
40                 
41                 $GLOBALS['phpgw_info']['flags'] = array
42                         (
43                                 'currentapp'           => 'filemanager',
44                                 'noheader'             => False,
45                                 'nonavbar'             => False,
46                                 'nofooter'             => False,
47                                 'noappheader'          => False,
48                                 'enable_browser_class'  => True
49                         );
50        }
51
52        function vfs_functions(){}
53       
54        function folders()
55        {
56                $GLOBALS['phpgw']->common->phpgw_header();
57
58                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
59                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
60                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
61
62
63                $this->template->set_file(array('config_list' => 'config_folders.tpl'));
64                $this->template->set_block('config_list','body','body');
65               
66                $vars = array(
67                                                'lang_directory'        => lang('directory'),
68                                                'lang_search'           => lang('search'),
69                                                'lang_remove'           => lang('remove'),
70                                                'lang_rename'           => lang('rename'),
71                                                'lang_create'           => lang('create'),
72                                                'lang_reconstruct'      => lang('reconstruct')
73                                        );
74
75                $this->template->set_var($vars);
76                $this->template->pparse('out','body');
77       
78        $GLOBALS['phpgw']->common->phpgw_footer();
79        $GLOBALS['phpgw']->common->phpgw_exit();
80       
81         }
82
83         function groups_users()
84         {
85                $GLOBALS['phpgw']->common->phpgw_header();
86
87                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
88                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
89                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
90
91                $this->template->set_file(array('config_list' => 'config_owner.tpl'));
92                $this->template->set_block('config_list','body','body');
93               
94                $vars = array(
95                                                'lang_directory'                => lang('directory'),
96                                                'lang_search'                   => lang('search'),
97                                                'lang_setowner'                 => lang('set owner'),
98                                                'lang_setperm'                  => lang('set permission'),
99                                                'lang_users_and_groups' => lang('Users and groups')
100                                        );
101               
102                $this->template->set_var($vars);
103                $this->template->pparse('out','body');
104
105        $GLOBALS['phpgw']->common->phpgw_footer();
106        $GLOBALS['phpgw']->common->phpgw_exit();
107         }
108
109        function createFolder()
110        {
111                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
112                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
113                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
114                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
115                         
116                 $this->bo = CreateObject('filemanager.bofilemanager');
117                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
118                 if (strlen($name) < 2)
119                         return false;
120                 $c = CreateObject('phpgwapi.config','filemanager');
121                 $c->read_repository();
122                 $current_config = $c->config_data;
123
124                 $this->bo->vfs->override_acl = 1;
125
126                 if ( $this->bo->vfs->mkdir(array(
127                         'string' => $name,
128                         'relatives' => array(RELATIVE_NONE)
129                 )) )
130                 if ( $this->bo->vfs->set_quota(array(
131                         'string' => $name,
132                         'relatives' => array(RELATIVE_NONE),
133                         'new_quota' => $current_config['filemanager_quota_size']
134                 )) )
135                 $return = True;
136
137                 $this->bo->vfs->override_acl = 0;
138                 if ($return){
139                         echo "Folder created";
140                 }
141                 else
142                         echo "Error";
143         }
144
145         function removeFolder()
146         {
147                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
148                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
149                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
150                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
151                         
152                 $this->bo = CreateObject('filemanager.bofilemanager');
153                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
154                 if (strlen($name) < 2)
155                         return false;
156                 if (    $this->bo->vfs->delete(array(
157                         'string' => $name,
158                         'relatives' => array(RELATIVE_NONE)
159                 )) )
160                 {
161                         /* Clean the log */
162                         $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_vfs WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
163                         if ($GLOBALS['phpgw']->db->Error)
164                                 echo "Erro";
165                         else
166                         {               
167                                 $GLOBALS['phpgw']->db->query('DELETE FROM phpgw_vfs_quota WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
168                                 if (!$GLOBALS['phpgw']->db->Error)
169                                         echo lang('directory removed sucessfully');
170                                 else
171                                         echo "Erro";
172                         }
173                 }
174                 return;
175
176        }
177       
178        function reconstructFolder()
179        {
180                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
181                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
182                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
183                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
184                         
185                 $this->bo = CreateObject('filemanager.bofilemanager');
186                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
187                 if (strlen($name) < 2)
188                         return false;
189                 $this->bo->vfs->update_real(array(
190                         'string'        => $name,
191                         'relatives'     => array(RELATIVE_NONE)
192                 ),True);
193                 $this->bo->vfs->flush_journal(array(
194                         'string' => $name,
195                         'relatives' => array(RELATIVE_NONE),
196                         'deleteall' => True
197                 ));
198                 echo lang('Your operation was successfully executed');
199        }
200
201        function renameFolder()
202        {
203                 $GLOBALS['phpgw_info']['flags'] = array
204                         (
205                                 'currentapp'    => 'filemanager',
206                                 'noheader'      => True,
207                                 'nonavbar' => True,
208                                 'nofooter'      => True,
209                                 'noappheader'   => True,
210                                 'enable_browser_class'  => True
211                         );
212                 $this->bo = CreateObject('filemanager.bofilemanager');
213                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
214                 $to = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['to']));
215                 if (strlen($name) < 2)
216                         return false;
217                if ( $this->bo->vfs->mv(array(
218                         'from'        => $name,
219                         'to'   => $to,
220                         'relatives'     => array(RELATIVE_NONE)
221                 )) ){
222                         $this->bo->vfs->flush_journal(array(
223                                 'string' => $name,
224                                 'relatives' => array(RELATIVE_NONE),
225                                 'deleteall' => True
226                         ));
227                         echo lang('Your operation was successfully executed');
228                 }
229                else
230                        echo lang('Error');
231        }
232
233        function quota()
234        {
235                $GLOBALS['phpgw']->common->phpgw_header();
236
237                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/connector.js'></script>";
238                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/common_functions.js'></script>";
239                echo "<script src='".$GLOBALS['phpgw_info']['flags']['currentapp']."/js/config.js'></script>";
240
241                $this->template->set_file(array('config_list' => 'config_quota.tpl'));
242                $this->template->set_block('config_list','body','body');
243
244                $vars = array(
245                                                'lang_directory' => lang('directory'),
246                                                'lang_save' =>lang('save'),                                             
247                                                'lang_search' => lang('search')
248                                        );
249
250                $this->template->set_var($vars);
251                $this->template->pparse('out','body');
252
253                $GLOBALS['phpgw']->common->phpgw_footer();
254        $GLOBALS['phpgw']->common->phpgw_exit();
255        }
256         
257        function notifyUploads()
258        {
259                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Filemanager') ." - " . lang("Email notify uploads");
260                $GLOBALS['phpgw']->common->phpgw_header();
261               
262                $notify                 = new notifications();
263                $value_email_to = "";
264
265                if( $_POST['button_add'] || $_GET['editUser'] )
266                {
267                        if( $_GET['editUser'] )
268                        {
269                                $result = $notify->SearchId($_GET['editUser']);
270                                $emails_to = explode(",", $result[0]['email_to']);
271                               
272                                for( $i = 0 ; $i < count($emails_to); $i++ )
273                                {
274                                        $value_email_to .= "<tr>";
275                                        $value_email_to .= "<td>".$emails_to[$i]."</td>";
276                                        $value_email_to .= "<td align='center'>";
277                                        $value_email_to .= "<a href='javascript:void();' onclick='notify.deleteEmail(\"".$emails_to[$i]."\",this);'>Remover</a>";
278                                        $value_email_to .= "</td>";
279                                        $value_email_to .= "</tr>";
280                                }
281                        }
282                       
283                        $vars = array(
284                                                        'action_url_back'       => "./index.php?menuaction=filemanager.uiconfig.notifyUploads",
285                                                        'attr_readonly'         => ( $result[0]['email_from'] ) ? 'readonly="readonly"' : "",
286                                                        'lang_Add'                      => lang("Add"),
287                                                        'lang_Back'                     => lang("Back"),
288                                                        'lang_Email'            => lang("Email"),
289                                                        'lang_Excluir'          => lang("Delete"),
290                                                        'lang_legend1'          => lang("When the user with the email send a file"),
291                                                        'lang_legend2'          => lang("Notify email"),
292                                                        'lang_legend3'          => lang("Emails reported"),
293                                                        'lang_from'                     => lang("From"),
294                                                        'lang_to'                       => lang("To"),
295                                                        'value_email_from'      => ( $result[0]['email_from'] ) ? $result[0]['email_from'] : "",
296                                                        'value_email_to'        => $value_email_to
297                        );
298                       
299                        $handle = "AddEmail";
300                }
301                else
302                {       
303                        if( trim( $_POST['search_email'] ) != "" )
304                        {
305                                $limit  = 10;
306                                $offset = 1;
307                               
308                                if( $_POST['bt_next'] )
309                                        $offset = $_POST['button_next'] + 1 ;                           
310
311                                if( $_POST['bt_previous'] && $_POST['button_next'] > 1)
312                                {
313                                        $offset = $_POST['button_next'] - 1;
314                                }
315                               
316                                $result = $notify->SearchEmail( $_POST['search_email'], $limit, $offset );
317
318                                foreach( $result as $tmp )
319                                {
320                                        $value_email_to .= '<tr>';
321                                        $value_email_to .= '<td align="left" width="40%">'.$tmp['email_from'].'</td>';
322                                        $value_email_to .= '<td align="left" width="40%">'.str_replace(",", "<br/>", $tmp['email_to']).'</td>';
323                                        $value_email_to .= '<td align="center" width="10%"><a href="./index.php?menuaction=filemanager.uiconfig.notifyUploads&editUser='.$tmp['filemanager_id'].'">'.lang("Edit").'</a></td>';
324                                        $value_email_to .= '<td align="center" width="10%"><a href="javascript:void();" onclick="notify.deleteEmailUser(\''.$tmp['filemanager_id'].'\', this);">'.lang("Delete").'</a></td>';
325                                        $value_email_to .= '</tr>';
326                                }
327                        }
328                       
329                        $vars = array(
330                                                        'action_url'                    => "./index.php?menuaction=filemanager.uiconfig.notifyUploads",
331                                                        'action_url_back'               => "./admin",
332                                                        'display_bt_previous'   => ( $offset > 1 ) ? "line" : "none",
333                                                        'display_bt_next'               => ( count($result) < $limit ) ? "none" : "line",
334                                                        'lang_Add'                              => lang("Add"),
335                                                        'lang_Back'                             => lang("Back"),
336                                                        'lang_Delete'                   => lang("Delete"),
337                                                        'lang_Edit'                             => lang("Edit"),
338                                                        'lang_From'                             => lang("From"),
339                                                        'lang_To'                               => lang("To"),
340                                                        'lang_search'                   => lang("Search"),
341                                                        'lang_next'                             => lang("Next"),
342                                                        'lang_previous'                 => lang("Previous"),
343                                                        'value_search_email'    => $_POST['search_email'],
344                                                        'value_email_to'                => $value_email_to,
345                                                        'value_next'                    => $offset,                                                     
346                                                        'value_previous'                => $limit
347                                                 );
348                       
349                        $handle = "index";
350                }
351
352                $this->template->set_file(array('config_email' => 'notify_upload.tpl'));
353                $this->template->set_block('config_email',$handle);
354                $this->template->set_var($vars);
355                $this->template->pparse('out',$handle);
356
357        $GLOBALS['phpgw']->common->phpgw_footer();
358        $GLOBALS['phpgw']->common->phpgw_exit();
359        }
360         
361        function search_dir()
362        {
363                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
364                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
365                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
366                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
367                         
368                 $name = $GLOBALS['phpgw']->db->db_addslashes($_GET['name']);
369                 $GLOBALS['phpgw']->db->query('SELECT DISTINCT directory FROM phpgw_vfs WHERE (directory like \'%'.$name.'%\') LIMIT 20',__LINE__,__FILE__);
370                 while ($GLOBALS['phpgw']->db->next_record()){
371                         $val = $GLOBALS['phpgw']->db->row();
372                         echo "<option>".$val['directory']."</option>";
373                 }
374                 $GLOBALS['phpgw']->db->query('SELECT directory,name from phpgw_vfs WHERE directory = \'/home\' and name like \'%'.$name.'%\' LIMIT 1',__LINE__,__FILE__);
375                 if ($GLOBALS['phpgw']->db->next_record()){
376                         $val = $GLOBALS['phpgw']->db->row();
377                         echo "<option>".$val['directory']."/".$val['name']."</option>";
378                 }
379               
380
381        }
382       
383        function search_user()
384        {
385                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
386                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
387                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
388                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
389
390                 $account_info = $GLOBALS['phpgw']->accounts->get_list('both',0,'','',$_GET['name'],'all');
391
392                 foreach($account_info as $val)
393                         echo "<option value='".$val['account_id']."'>".$val['account_lid']."</option>";
394        }
395       
396        function set_permission()
397        {
398                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
399                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
400                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
401                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
402
403                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
404                 $perms = ($_GET['perms'])*1;
405                 $owner = ($_GET['owner'])*1;
406                 $dirs=explode('/',$name);
407                 $GLOBALS['phpgw']->db->query('SELECT owner_id  from phpgw_vfs  WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\' LIMIT 1',__LINE__,__FILE__);
408                 if ($GLOBALS['phpgw']->db->next_record()){
409                         $val = $GLOBALS['phpgw']->db->row();
410                         $owner_id = $val['owner_id'];
411                 }
412
413                 $query = "SELECT count(*) FROM phpgw_acl WHERE acl_appname = 'filemanager' and acl_account = '".$owner_id."' and acl_location='".$owner."'";
414                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
415                         $val = $GLOBALS['phpgw']->db->row();
416                 else
417                 {
418                         echo $GLOBALS['phpgw']->db->error;
419                         return false;
420                 }
421                 if ($val['count'] == '1')
422                        $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__);
423                 else
424                         $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_acl values('filemanager','".$owner."','".$owner_id."',".$perms.")",__LINE__,__FILE__);
425                 if ($GLOBALS['phpgw']->db->Error)
426                         echo "Erro";
427                 else
428                 {
429                        echo lang('entry updated sucessfully');
430                 }
431                 return;
432        }
433
434
435        function set_owner()
436        {
437                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
438                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
439                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
440                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
441                 
442                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
443                 $owner = ($_GET['owner'])*1;
444
445                 $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
446                 if ($GLOBALS['phpgw']->db->Error)
447                         echo "Erro";
448                 else
449                 {
450                         $dirs=explode('/',$name);
451                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\'',__LINE__,__FILE__);
452                         if ($GLOBALS['phpgw']->db->Error)
453                                 echo "Erro";
454                         else
455                         {
456                                 echo lang('entry updated sucessfully');
457                         }
458                 }
459                 return;
460        }
461
462        function update_quota()
463        {
464                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
465                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
466                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
467                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
468                         
469                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
470                 $size = ($_GET['val'])*1;
471
472                 /* See if quota exists or not */
473                 $query = "SELECT count(directory) FROM phpgw_vfs_quota WHERE directory = '".$name."' LIMIT 1";
474                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
475                         $val = $GLOBALS['phpgw']->db->row();
476                 else
477                 {
478                         echo $GLOBALS['phpgw']->db->error;
479                         return false;
480                 }
481                 if ($val['count'] == '1')
482                 {
483                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs_quota SET quota_size = '.$size.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
484                         if ($GLOBALS['phpgw']->db->Error)
485                                 echo "Erro";
486                         else
487                                 echo lang('entry updated sucessfully');
488                 }
489                 else
490                 {
491                         /*preferences does not exist*/
492                         $query = "INSERT INTO phpgw_vfs_quota values ('".$name."',".$size.")";
493                         if (!$GLOBALS['phpgw']->db->query($query))
494                                 echo $GLOBALS['phpgw']->db->error;
495                         else
496                                 echo lang('entry updated sucessfully');
497                 }
498                 return;
499         }
500         
501         function load_quota()
502         {
503                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
504                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
505                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
506                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
507                         
508                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
509                 $GLOBALS['phpgw']->db->query('SELECT quota_size FROM phpgw_vfs_quota WHERE directory = \''.$name.'\' LIMIT 1',__LINE__,__FILE__);
510                 $GLOBALS['phpgw']->db->next_record();
511                 $val =$GLOBALS['phpgw']->db->row();
512                 echo $val['quota_size'];
513                 return;
514
515         }
516}
517
518?>
Note: See TracBrowser for help on using the repository browser.