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

Revision 7673, 17.3 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

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