Changeset 1627 for trunk/phpgwapi


Ignore:
Timestamp:
11/12/09 09:06:56 (14 years ago)
Author:
amuller
Message:

Ticket #597 - Implementações novas, com arquivos restritos, quota, ckeditor

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpgwapi/inc/class.vfs_sql.inc.php

    r1575 r1627  
    3838                var $working_id; 
    3939                var $working_lid; 
     40                var $my_home; 
    4041                var $meta_types; 
    4142                var $now; 
     
    5253                        $this->working_id = $GLOBALS['phpgw_info']['user']['account_id']; 
    5354                        $this->working_lid = $GLOBALS['phpgw']->accounts->id2name($this->working_id); 
     55                        $this->my_home = $this->fakebase.'/'.$this->working_lid; 
    5456                        $this->now = date ('Y-m-d H:i:s'); 
    5557 
     
    6466                        $this->attributes[] = 'deleteable'; 
    6567                        $this->attributes[] = 'content'; 
     68                        $this->attributes[] = 'type'; 
    6669 
    6770                        /* 
     
    612615                function acl_check ($data) 
    613616                { 
     617 
    614618                        if (!is_array ($data)) 
    615619                        { 
    616620                                $data = array (); 
    617621                        } 
     622 
     623                        /* ExpressoLivre principle: In your home you do what you want*/ 
     624                        if (strpos($data['string'],$this->my_home) === 0) 
     625                                return True; 
    618626 
    619627                        $default_values = array 
     
    845853                                $data = array (); 
    846854                        } 
     855 
     856                        $path = explode('/',$data['string']); 
     857                        $quota = $this->get_quota(array('string' => '/'.$path[1].'/'.$path[2])); 
     858                        if ($quota > 0 && $this->get_size($data) >= $quota * 1024 * 1024) 
     859                                return false; 
     860 
    847861 
    848862                        $default_values = array 
     
    10821096                                $data = array (); 
    10831097                        } 
     1098                        $path = explode('/',$data['to']); 
     1099                        $quota = $this->get_quota(array('string' => '/'.$path[1].'/'.$path[2])); 
     1100                        $size = $this->get_size(array('string' => $data['to'], 'relatives' => $data['relatives'][1])); 
     1101                        if ($quota > 0 && $size >= $quota * 1024 * 1024) 
     1102                                return false; 
    10841103 
    10851104                        $default_values = array 
     
    13441363                                $data = array (); 
    13451364                        } 
     1365 
     1366                        $path = explode('/',$data['to']); 
     1367                        $quota = $this->get_quota(array('string' => '/'.$path[1].'/'.$path[2])); 
     1368                        $size = $this->get_size(array('string' => $data['to'], 'relatives' => $data['relatives'][1])); 
     1369                        if ($quota > 0 && $size >= $quota * 1024 * 1024) 
     1370                                return false; 
     1371 
    13461372 
    13471373                        $default_values = array 
     
    23252351                        return $size; 
    23262352                } 
     2353                /* 
     2354                 * get the quota defined for the path in sql table 
     2355                 */ 
     2356                function get_quota($data){ 
     2357                        if (!is_array ($data)) 
     2358                        { 
     2359                                $data = array (); 
     2360                        } 
     2361 
     2362                        $default_values = array 
     2363                                ( 
     2364                                        'relatives'     => array (RELATIVE_CURRENT) 
     2365                                ); 
     2366 
     2367                        $data = array_merge ($this->default_values ($data, $default_values), $data); 
     2368 
     2369                        $p = $this->path_parts (array( 
     2370                                        'string'        => $data['string'], 
     2371                                        'relatives'     => RELATIVE_NONE 
     2372                                ) 
     2373                        ); 
     2374 
     2375                        if (!$this->acl_check (array( 
     2376                                'string'        => $p->fake_full_path, 
     2377                                'relatives'     => $p->mask, 
     2378                                'operation'     => PHPGW_ACL_READ 
     2379                        )) 
     2380                        ) 
     2381                        { 
     2382                                return False; 
     2383                        } 
     2384                        $query = $GLOBALS['phpgw']->db->query ("SELECT quota_size FROM phpgw_vfs_quota WHERE directory = '".$data['string']."' LIMIT 1;", __LINE__,__FILE__); 
     2385 
     2386                        $GLOBALS['phpgw']->db->next_record (); 
     2387                        $record = $GLOBALS['phpgw']->db->Record; 
     2388                        return $record['quota_size']; 
     2389                } 
     2390                function set_quota($data){ 
     2391                        if (!is_array ($data)) 
     2392                        { 
     2393                                $data = array (); 
     2394                        } 
     2395 
     2396                        $default_values = array 
     2397                                ( 
     2398                                        'relatives'     => array (RELATIVE_CURRENT) 
     2399                                ); 
     2400 
     2401                        $data = array_merge ($this->default_values ($data, $default_values), $data); 
     2402 
     2403                        $p = $this->path_parts (array( 
     2404                                        'string'        => $data['string'], 
     2405                                        'relatives'     => array ($data['relatives'][0]) 
     2406                                ) 
     2407                        ); 
     2408 
     2409                        if (!$this->acl_check (array( 
     2410                                'string'        => $p->fake_full_path, 
     2411                                'relatives'     => array ($p->mask), 
     2412                                'operation'     => PHPGW_ACL_READ 
     2413                        )) 
     2414                        ) 
     2415                        { 
     2416                                return False; 
     2417                        } 
     2418                        // INSERT INTO phpgw_vfs_quota values('/home/amuller',200); 
     2419                        // 
     2420                        return $GLOBALS['phpgw']->db->query("INSERT INTO phpgw_vfs_quota VALUES ('".$data['string']."',".$data['new_quota'].");", __LINE__,__FILE__); 
     2421                } 
     2422 
    23272423 
    23282424                /*! 
     
    23992495                        $dir = $p->fake_full_path; 
    24002496 
     2497 
    24012498                        /* If they pass us a file or 'nofiles' is set, return the info for $dir only */ 
    24022499                        if (@$data['file_id'] 
     
    24282525                                else 
    24292526                                { 
    2430                                         $sql .= "directory='".$GLOBALS['phpgw']->db->db_addslashes($p->fake_leading_dirs_clean). 
    2431                                                 "' AND name='".$GLOBALS['phpgw']->db->db_addslashes($p->fake_name_clean)."'". 
     2527                                        $sql .= " directory='".$GLOBALS['phpgw']->db->db_addslashes($p->fake_leading_dirs_clean)."' AND". 
     2528                                                " name='".$GLOBALS['phpgw']->db->db_addslashes($p->fake_name_clean)."'". 
    24322529                                                $this->extra_sql (array ('query_type' => VFS_SQL_SELECT)); 
    24332530                                } 
     
    25082605                        /* SELECT all, the, attributes FROM phpgw_vfs WHERE file=$dir */ 
    25092606                        $sql = 'SELECT '; 
     2607                        if (!$this->acl_check (array ( 
     2608                                'string' => $p->fake_full_path, 
     2609                                'relatives' => array ($p->mask), 
     2610                                'operation' => PHPGW_ACL_PRIVATE) 
     2611                        )) 
     2612                        $query_type = " type != 1 AND"; 
     2613                        else 
     2614                                $query_type = ""; 
    25102615 
    25112616                        foreach($this->attributes as $num => $attribute) 
     
    25202625 
    25212626                        $dir_clean = $this->clean_string (array ('string' => $dir)); 
    2522                         $sql .= " FROM phpgw_vfs WHERE directory LIKE '".$GLOBALS['phpgw']->db->db_addslashes($dir_clean)."%'"; 
     2627                        $sql .= " FROM phpgw_vfs WHERE ".$query_type." directory LIKE '".$GLOBALS['phpgw']->db->db_addslashes($dir_clean)."%'"; 
    25232628                        $sql .= $this->extra_sql (array ('query_type' => VFS_SQL_SELECT)); 
    25242629 
     
    25272632                                $sql .= " AND mime_type='".$data['mime_type']."'"; 
    25282633                        } 
    2529  
    2530                         $sql .= ' ORDER BY '.$data['orderby']; 
    2531  
     2634                        if (strlen($data['orderby']) > 0) 
     2635                                $sql .= ' ORDER BY '.$data['orderby']; 
    25322636                        $query = $GLOBALS['phpgw']->db->query ($sql, __LINE__, __FILE__); 
    25332637 
Note: See TracChangeset for help on using the changeset viewer.