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

Revision 3873, 16.6 KB checked in by alexandrecorreia, 13 years ago (diff)

Ticket #1646 - Erro em gerenciamento de pastas 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                                                'path_filemanager'      => $GLOBALS['phpgw_info']['flags']['currentapp']
70                                        );
71
72                $this->template->set_var($vars);
73                $this->template->pparse('out','body');
74       
75        $GLOBALS['phpgw']->common->phpgw_footer();
76        $GLOBALS['phpgw']->common->phpgw_exit();
77       
78         }
79
80         function groups_users()
81         {
82                $GLOBALS['phpgw']->common->phpgw_header();
83
84                $this->template->set_file(array('config_list' => 'config_owner.tpl'));
85                $this->template->set_block('config_list','body','body');
86               
87                $vars = array(
88                                                'lang_Add'                              => lang('Add'),
89                                                'lang_directory'                        => lang('directory'),
90                                                'lang_Delete'                           => lang('Delete'),
91                                                'lang_Edit'                             => lang('Edit'),
92                                                'lang_Read'                             => lang('Read'),
93                                                'lang_private'                  => lang('private'),             
94                                                'lang_search'                   => lang('search'),
95                                                'lang_setowner'                 => lang('set owner'),
96                                                'lang_setperm'                  => lang('set permission'),
97                                                'lang_users_and_groups' => lang('Users and groups'),
98                                                'path_filemanager'              => $GLOBALS['phpgw_info']['flags']['currentapp']
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($_POST['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                 else
174                         echo lang("No permission to delete the folder %1", $name );
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($_POST['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                $this->template->set_file(array('config_list' => 'config_quota.tpl'));
238                $this->template->set_block('config_list','body','body');
239
240                $vars = array(
241                                                'lang_directory' => lang('directory'),
242                                                'lang_save' =>lang('save'),                                             
243                                                'lang_search' => lang('search'),
244                                                'path_filemanager'      => $GLOBALS['phpgw_info']['flags']['currentapp']
245                                        );
246
247                $this->template->set_var($vars);
248                $this->template->pparse('out','body');
249
250                $GLOBALS['phpgw']->common->phpgw_footer();
251        $GLOBALS['phpgw']->common->phpgw_exit();
252        }
253         
254        function notifyUploads()
255        {
256                $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Filemanager') ." - " . lang("Email notify uploads");
257                $GLOBALS['phpgw']->common->phpgw_header();
258               
259                $notify                 = new notifications();
260                $value_email_to = "";
261
262                if( $_POST['button_add'] || $_GET['editUser'] )
263                {
264                        if( $_GET['editUser'] )
265                        {
266                                $result = $notify->SearchId($_GET['editUser']);
267                                $emails_to = explode(",", $result[0]['email_to']);
268                               
269                                for( $i = 0 ; $i < count($emails_to); $i++ )
270                                {
271                                        $value_email_to .= "<tr>";
272                                        $value_email_to .= "<td>".$emails_to[$i]."</td>";
273                                        $value_email_to .= "<td align='center'>";
274                                        $value_email_to .= "<a href='javascript:void();' onclick='notify.deleteEmail(\"".$emails_to[$i]."\",this);'>Remover</a>";
275                                        $value_email_to .= "</td>";
276                                        $value_email_to .= "</tr>";
277                                }
278                        }
279                       
280                        $vars = array(
281                                                        'action_url_back'       => "./index.php?menuaction=filemanager.uiconfig.notifyUploads",
282                                                        'attr_readonly'         => ( $result[0]['email_from'] ) ? 'readonly="readonly"' : "",
283                                                        'lang_Add'                      => lang("Add"),
284                                                        'lang_Back'                     => lang("Back"),
285                                                        'lang_Email'            => lang("Email"),
286                                                        'lang_Excluir'          => lang("Delete"),
287                                                        'lang_legend1'          => lang("When the user with the email send a file"),
288                                                        'lang_legend2'          => lang("Notify email"),
289                                                        'lang_legend3'          => lang("Emails reported"),
290                                                        'lang_from'                     => lang("From"),
291                                                        'lang_to'                       => lang("To"),
292                                                        'value_email_from'      => ( $result[0]['email_from'] ) ? $result[0]['email_from'] : "",
293                                                        'value_email_to'        => $value_email_to
294                        );
295                       
296                        $handle = "AddEmail";
297                }
298                else
299                {       
300                        if( trim( $_POST['search_email'] ) != "" )
301                        {
302                                $limit  = 10;
303                                $offset = 1;
304                               
305                                if( $_POST['bt_next'] )
306                                        $offset = $_POST['button_next'] + 1 ;                           
307
308                                if( $_POST['bt_previous'] && $_POST['button_next'] > 1)
309                                {
310                                        $offset = $_POST['button_next'] - 1;
311                                }
312                               
313                                $result = $notify->SearchEmail( $_POST['search_email'], $limit, $offset );
314
315                                foreach( $result as $tmp )
316                                {
317                                        $value_email_to .= '<tr>';
318                                        $value_email_to .= '<td align="left" width="40%">'.$tmp['email_from'].'</td>';
319                                        $value_email_to .= '<td align="left" width="40%">'.str_replace(",", "<br/>", $tmp['email_to']).'</td>';
320                                        $value_email_to .= '<td align="center" width="10%"><a href="./index.php?menuaction=filemanager.uiconfig.notifyUploads&editUser='.$tmp['filemanager_id'].'">'.lang("Edit").'</a></td>';
321                                        $value_email_to .= '<td align="center" width="10%"><a href="javascript:void();" onclick="notify.deleteEmailUser(\''.$tmp['filemanager_id'].'\', this);">'.lang("Delete").'</a></td>';
322                                        $value_email_to .= '</tr>';
323                                }
324                        }
325                       
326                        $vars = array(
327                                                        'action_url'                    => "./index.php?menuaction=filemanager.uiconfig.notifyUploads",
328                                                        'action_url_back'               => "./admin",
329                                                        'display_bt_previous'   => ( $offset > 1 ) ? "line" : "none",
330                                                        'display_bt_next'               => ( count($result) < $limit ) ? "none" : "line",
331                                                        'lang_Add'                              => lang("Add"),
332                                                        'lang_Back'                             => lang("Back"),
333                                                        'lang_Delete'                   => lang("Delete"),
334                                                        'lang_Edit'                             => lang("Edit"),
335                                                        'lang_From'                             => lang("From"),
336                                                        'lang_To'                               => lang("To"),
337                                                        'lang_search'                   => lang("Search"),
338                                                        'lang_next'                             => lang("Next"),
339                                                        'lang_previous'                 => lang("Previous"),
340                                                        'value_search_email'    => $_POST['search_email'],
341                                                        'value_email_to'                => $value_email_to,
342                                                        'value_next'                    => $offset,                                                     
343                                                        'value_previous'                => $limit
344                                                 );
345                       
346                        $handle = "index";
347                }
348
349                $this->template->set_file(array('config_email' => 'notify_upload.tpl'));
350                $this->template->set_block('config_email',$handle);
351                $this->template->set_var($vars);
352                $this->template->pparse('out',$handle);
353
354        $GLOBALS['phpgw']->common->phpgw_footer();
355        $GLOBALS['phpgw']->common->phpgw_exit();
356        }
357         
358        function search_dir()
359        {
360                 $GLOBALS['phpgw_info']['flags']['noheader']    = True;
361                 $GLOBALS['phpgw_info']['flags']['nonavbar']    = True;
362                 $GLOBALS['phpgw_info']['flags']['nofooter']    = True;
363                 $GLOBALS['phpgw_info']['flags']['noappheader'] = True;
364
365                 $_options = "";
366                 $query = "";
367                 
368                 $name = $GLOBALS['phpgw']->db->db_addslashes($_GET['name']);
369                 
370                 $query = 'SELECT directory,name from phpgw_vfs WHERE directory = \'/home\' and name like \'%'.$name.'%\' LIMIT 1';
371                 
372                 $GLOBALS['phpgw']->db->query($query,__LINE__,__FILE__);
373
374                while ($GLOBALS['phpgw']->db->next_record())
375                {
376                         $val = $GLOBALS['phpgw']->db->row();
377                         $_options .= "<option>".$val['directory']."/".$val['name']."</option>";
378                }
379
380                echo $_options;
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.