source: trunk/filemanager/inc/class.uiconfig.inc.php @ 2000

Revision 2000, 14.0 KB checked in by amuller, 14 years ago (diff)

Ticket #597 - Implementação do módulo gerenciador de arquivos

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