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

Revision 3874, 16.7 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1647 - Erro na Gestao de Cotas do File Manager

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
10//require_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                $this->template->set_file(array('config_list' => 'config_folders.tpl'));
59                $this->template->set_block('config_list','body','body');
60               
61                $vars = array(
62                                                'lang_back'                     => lang('Back'),
63                                                'lang_directory'                => lang('directory'),
64                                                'lang_search'           => lang('search'),
65                                                'lang_remove'           => lang('remove'),
66                                                'lang_rename'           => lang('rename'),
67                                                'lang_create'           => lang('create'),
68                                                'lang_reconstruct'      => lang('reconstruct'),
69                                                'lang_Folder_ Management' => lang('Folder Management'),
70                                                'path_filemanager'      => $GLOBALS['phpgw_info']['flags']['currentapp']
71                                        );
72
73                $this->template->set_var($vars);
74                $this->template->pparse('out','body');
75       
76        $GLOBALS['phpgw']->common->phpgw_footer();
77        $GLOBALS['phpgw']->common->phpgw_exit();
78       
79         }
80
81         function groups_users()
82         {
83                $GLOBALS['phpgw']->common->phpgw_header();
84
85                $this->template->set_file(array('config_list' => 'config_owner.tpl'));
86                $this->template->set_block('config_list','body','body');
87               
88                $vars = array(
89                                                'lang_Add'                              => lang('Add'),
90                                                'lang_directory'                        => lang('directory'),
91                                                'lang_Delete'                           => lang('Delete'),
92                                                'lang_Edit'                             => lang('Edit'),
93                                                'lang_Read'                             => lang('Read'),
94                                                'lang_private'                  => lang('private'),             
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                                                'path_filemanager'              => $GLOBALS['phpgw_info']['flags']['currentapp']
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($_POST['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                 else
175                         echo lang("No permission to delete the folder %1", $name );
176
177        }
178       
179        function reconstructFolder()
180        {
181                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
182                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
183                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
184                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
185                         
186                 $this->bo = CreateObject('filemanager.bofilemanager');
187                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_POST['dir']));
188                 if (strlen($name) < 2)
189                         return false;
190                 $this->bo->vfs->update_real(array(
191                         'string'        => $name,
192                         'relatives'     => array(RELATIVE_NONE)
193                 ),True);
194                 $this->bo->vfs->flush_journal(array(
195                         'string' => $name,
196                         'relatives' => array(RELATIVE_NONE),
197                         'deleteall' => True
198                 ));
199                 echo lang('Your operation was successfully executed');
200        }
201
202        function renameFolder()
203        {
204                 $GLOBALS['phpgw_info']['flags'] = array
205                         (
206                                 'currentapp'    => 'filemanager',
207                                 'noheader'      => True,
208                                 'nonavbar' => True,
209                                 'nofooter'      => True,
210                                 'noappheader'   => True,
211                                 'enable_browser_class'  => True
212                         );
213                 $this->bo = CreateObject('filemanager.bofilemanager');
214                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
215                 $to = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['to']));
216                 if (strlen($name) < 2)
217                         return false;
218                if ( $this->bo->vfs->mv(array(
219                         'from'        => $name,
220                         'to'   => $to,
221                         'relatives'     => array(RELATIVE_NONE)
222                 )) ){
223                         $this->bo->vfs->flush_journal(array(
224                                 'string' => $name,
225                                 'relatives' => array(RELATIVE_NONE),
226                                 'deleteall' => True
227                         ));
228                         echo lang('Your operation was successfully executed');
229                 }
230                else
231                        echo lang('Error');
232        }
233
234        function quota()
235        {
236                $GLOBALS['phpgw']->common->phpgw_header();
237
238                $this->template->set_file(array('config_list' => 'config_quota.tpl'));
239                $this->template->set_block('config_list','body','body');
240
241                $vars = array(
242                        'lang_back'                             => lang('Back'),
243                        'lang_directory'                        => lang('directory'),
244                        'lang_save'                             =>lang('save'),                                         
245                        'lang_search'                   => lang('search'),
246                        'lang_Management_Quota' => lang('Management Quota'),   
247                        'path_filemanager'      => $GLOBALS['phpgw_info']['flags']['currentapp']
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                $_options = "";
369                $query = "";
370
371                $name = $GLOBALS['phpgw']->db->db_addslashes($_POST['name']);
372
373                $query = 'SELECT directory,name from phpgw_vfs WHERE directory = \'/home\' and name like \'%'.$name.'%\' LIMIT 1';
374
375                $GLOBALS['phpgw']->db->query( $query,__LINE__,__FILE__ );
376
377                while ( $GLOBALS['phpgw']->db->next_record() )
378                {
379                        $val = $GLOBALS['phpgw']->db->row();
380                        $_options .= "<option>".$val['directory']."/".$val['name']."</option>";
381                }
382
383                echo $_options;
384        }
385       
386        function search_user()
387        {
388                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
389                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
390                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
391                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
392
393                 $account_info = $GLOBALS['phpgw']->accounts->get_list('both',0,'','',$_GET['name'],'all');
394
395                 foreach($account_info as $val)
396                         echo "<option value='".$val['account_id']."'>".$val['account_lid']."</option>";
397        }
398       
399        function set_permission()
400        {
401                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
402                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
403                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
404                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
405
406                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
407                 $perms = ($_GET['perms'])*1;
408                 $owner = ($_GET['owner'])*1;
409                 $dirs=explode('/',$name);
410                 $GLOBALS['phpgw']->db->query('SELECT owner_id  from phpgw_vfs  WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\' LIMIT 1',__LINE__,__FILE__);
411                 if ($GLOBALS['phpgw']->db->next_record()){
412                         $val = $GLOBALS['phpgw']->db->row();
413                         $owner_id = $val['owner_id'];
414                 }
415
416                 $query = "SELECT count(*) FROM phpgw_acl WHERE acl_appname = 'filemanager' and acl_account = '".$owner_id."' and acl_location='".$owner."'";
417                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
418                         $val = $GLOBALS['phpgw']->db->row();
419                 else
420                 {
421                         echo $GLOBALS['phpgw']->db->error;
422                         return false;
423                 }
424                 if ($val['count'] == '1')
425                        $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__);
426                 else
427                         $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_acl values('filemanager','".$owner."','".$owner_id."',".$perms.")",__LINE__,__FILE__);
428                 if ($GLOBALS['phpgw']->db->Error)
429                         echo "Erro";
430                 else
431                 {
432                        echo lang('entry updated sucessfully');
433                 }
434                 return;
435        }
436
437
438        function set_owner()
439        {
440                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
441                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
442                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
443                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
444                 
445                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['dir']));
446                 $owner = ($_GET['owner'])*1;
447
448                 $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
449                 if ($GLOBALS['phpgw']->db->Error)
450                         echo "Erro";
451                 else
452                 {
453                         $dirs=explode('/',$name);
454                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs SET owner_id = '.$owner.' WHERE directory = \'/'.$dirs[1].'\' and name=\''.$dirs[2].'\'',__LINE__,__FILE__);
455                         if ($GLOBALS['phpgw']->db->Error)
456                                 echo "Erro";
457                         else
458                         {
459                                 echo lang('entry updated sucessfully');
460                         }
461                 }
462                 return;
463        }
464
465        function update_quota()
466        {
467                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
468                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
469                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
470                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
471
472                 $name  = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_POST['dir']));
473                 $size  = ($_POST['val']) * 1;
474
475                 /* See if quota exists or not */
476                 $query = "SELECT count(directory) FROM phpgw_vfs_quota WHERE directory = '".$name."' LIMIT 1";
477                 if ($GLOBALS['phpgw']->db->query($query) && $GLOBALS['phpgw']->db->next_record())
478                         $val = $GLOBALS['phpgw']->db->row();
479                 else
480                 {
481                         echo $GLOBALS['phpgw']->db->error;
482                         return false;
483                 }
484                 if ($val['count'] == '1')
485                 {
486                         $GLOBALS['phpgw']->db->query('UPDATE phpgw_vfs_quota SET quota_size = '.$size.' WHERE directory = \''.$name.'\'',__LINE__,__FILE__);
487                         if ($GLOBALS['phpgw']->db->Error)
488                                 echo "Erro";
489                         else
490                                 echo lang('entry updated sucessfully');
491                 }
492                 else
493                 {
494                         /*preferences does not exist*/
495                         $query = "INSERT INTO phpgw_vfs_quota values ('".$name."',".$size.")";
496                         if (!$GLOBALS['phpgw']->db->query($query))
497                                 echo $GLOBALS['phpgw']->db->error;
498                         else
499                                 echo lang('entry updated sucessfully');
500                 }
501         }
502         
503         function load_quota()
504         {
505                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
506                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
507                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
508                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
509                         
510                 $name = $GLOBALS['phpgw']->db->db_addslashes(base64_decode($_GET['name']));
511                 $GLOBALS['phpgw']->db->query('SELECT quota_size FROM phpgw_vfs_quota WHERE directory = \''.$name.'\' LIMIT 1',__LINE__,__FILE__);
512                 $GLOBALS['phpgw']->db->next_record();
513                 $val =$GLOBALS['phpgw']->db->row();
514                 echo $val['quota_size'];
515                 return;
516
517         }
518}
519
520?>
Note: See TracBrowser for help on using the repository browser.