Ignore:
Timestamp:
06/15/12 17:00:17 (12 years ago)
Author:
gustavo
Message:

Ticket #2766 - Merge do branch das novas funcionalidaes para o trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/prototype/api/config.php

    r5764 r6528  
    11<?php 
     2 
     3namespace prototype\api; 
    24 
    35class Config  
    46{ 
    5     static $register; 
    6     static $sessionStarted; 
     7        static $register; 
     8        static $sessionStarted; 
    79   
    8     static function module($config , $module = false) 
    9     { 
    10         //Todo: registrar na nova api o currentapp 
    11         if(!$module) 
    12             $module =  $_SESSION['flags']['currentapp']; 
     10        static function module($config , $module = false) 
     11        { 
     12                //Todo: registrar na nova api o currentapp 
     13                if(!$module) 
     14                                $module =  $_SESSION['flags']['currentapp']; 
    1315   
    14         if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] )) 
    15             $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true ); 
     16                if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] )) 
     17                                $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true ); 
    1618         
    17         return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false; 
     19                return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false; 
    1820      
    19     } 
     21        } 
    2022     
    21     static function me($config) 
    22     { 
     23        static function me($config) 
     24        { 
    2325         
    24         return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false; 
    25     } 
     26                return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false; 
     27        } 
    2628     
    27     static function service( $service , $config ) 
    28     { 
    29         if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) 
    30             $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); 
     29        static function service( $service , $config ) 
     30        { 
     31                if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) 
     32                                $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); 
    3133        
    32         return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; 
    33     } 
     34                return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; 
     35        } 
    3436     
    35     static function get( $concept , $config = false , $module = false ) 
    36     { 
    37         $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true ); 
     37        static function get( $concept , $config = false , $module = false ) 
     38        { 
     39                $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true ); 
    3840         
    39         if($config === false) return $load; 
     41                if($config === false) return $load; 
    4042         
    41         return (isset($load[$config])) ? $load[$config] : false; 
    42     } 
     43                return (isset($load[$config])) ? $load[$config] : false; 
     44        } 
    4345     
    44     static function regSet( $name , $value) 
    45     { 
    46         self::$register[$name] = $value; 
    47     } 
    48     static function regGet ($name ) 
    49     { 
    50         return (isset(self::$register[$name]) ? self::$register[$name] : false ); 
    51     } 
     46        static function regSet( $name , $value) 
     47        { 
     48                self::$register[$name] = $value; 
     49        } 
     50        static function regGet ($name ) 
     51        { 
     52                return (isset(self::$register[$name]) ? self::$register[$name] : false ); 
     53        } 
    5254 
    53     static function init( ) 
    54     { 
     55        static function init( ) 
     56        { 
     57     
     58                if( !defined( 'ROOTPATH' ) ) 
     59                                define( 'ROOTPATH', dirname(__FILE__).'/..' ); 
    5560         
    56         if( !defined( 'ROOTPATH' ) ) 
    57             define( 'ROOTPATH', dirname(__FILE__).'/..' ); 
    58          
    59         if ( isset( $_COOKIE[ 'sessionid' ] ) )  
    60         { 
    61             session_id( $_COOKIE[ 'sessionid' ] );  
    62             $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ]; 
    63         } 
     61                if ( isset( $_COOKIE[ 'sessionid' ] ) )  
     62                { 
     63                                session_id( $_COOKIE[ 'sessionid' ] );  
     64                                $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ]; 
     65                } 
    6466                 
    6567        if( !self::$sessionStarted ) 
    66             self::$sessionStarted = session_start(); 
    67 //               
    68 //      if( $header === true ) 
    69 //      { 
    70 //            require_once (dirname(__FILE__).'/../../header.inc.php'); 
    71 // 
    72 //            $_SESSION['wallet']['Sieve']['user']          =  $GLOBALS['phpgw_info']['user']['account_lid']; 
    73 //            $_SESSION['wallet']['Sieve']['password']      =  $GLOBALS['phpgw_info']['user']['passwd']; 
    74 // 
    75 //            $_SESSION['wallet']['Cyrus']['user']          =  $GLOBALS['phpgw_info']['user']['account_lid']; 
    76 //            $_SESSION['wallet']['Cyrus']['password']      =  $GLOBALS['phpgw_info']['user']['passwd']; 
    77 // 
    78 //            $_SESSION['wallet']['user']['uid']                  =  $GLOBALS['phpgw_info']['user']['userid']; 
    79 //            $_SESSION['wallet']['user']['uidNumber']      =  $GLOBALS['phpgw_info']['user']['account_id']; 
    80 //            $_SESSION['wallet']['user']['password']       =  $GLOBALS['phpgw_info']['user']['passwd']; 
    81 //            $_SESSION['wallet']['user']['cn']             =  $GLOBALS['phpgw_info']['user']['cn']; 
    82 //            $_SESSION['wallet']['user']['mail']           =  $GLOBALS['phpgw_info']['user']['email']; 
    83 // 
    84 //            $_SESSION['wallet']['PostgreSQL']['user']     = $GLOBALS['phpgw_info']['server']['db_user']; 
    85 //            $_SESSION['wallet']['PostgreSQL']['password'] = $GLOBALS['phpgw_info']['server']['db_pass']; 
    86 //            $_SESSION['wallet']['PostgreSQL']['dbname']   = $GLOBALS['phpgw_info']['server']['db_name']; 
    87 //            $_SESSION['wallet']['PostgreSQL']['host']     = $GLOBALS['phpgw_info']['server']['db_host']; 
    88 //             
    89 //            $_SESSION['wallet']['OpenLDAP']['context']   =  $GLOBALS['phpgw_info']['server']['ldap_context']; 
    90 //            $_SESSION['wallet']['OpenLDAP']['host']      =  $GLOBALS['phpgw_info']['server']['ldap_host']; 
    91 //            
    92 //      } 
     68                                self::$sessionStarted = session_start(); 
    9369                 
    94     } 
     70        } 
     71     
     72        public static function writeIniFile($assoc_arr, $path, $has_sections) 
     73        { 
     74                $content = '';   
     75                self::_writeIniFile($content, $assoc_arr, $has_sections); 
     76                if( file_put_contents($path, $content) === false) 
     77                { 
     78                        trigger_error("Permission failure when trying to write in the file: $path ", E_USER_WARNING); 
     79                        return false; 
     80                } 
     81                return true; 
     82        } 
     83 
     84        private static function _writeIniFile(&$content, $assoc_arr, $has_sections) 
     85        { 
     86                foreach ($assoc_arr as $key => $val) 
     87                { 
     88                        if (is_array($val)) 
     89                        { 
     90                                if($has_sections) 
     91                                { 
     92                                        $content .= "[$key]\n"; 
     93                                        self::_writeIniFile(&$content, $val, false); 
     94                                } 
     95                                else                             
     96                                        foreach($val as $iKey => $iVal) 
     97                                        { 
     98                                                if (is_int($iKey)) 
     99                                                        $content .= $key ."[] = $iVal\n"; 
     100                                                else 
     101                                                        $content .= $key ."[$iKey] = $iVal\n"; 
     102                                        } 
     103                        } 
     104                        else 
     105                                $content .= "$key = $val\n"; 
     106                } 
     107        } 
    95108 
    96109} 
    97110 
    98     Config::init(); 
     111        Config::init(); 
    99112         
    100113 
Note: See TracChangeset for help on using the changeset viewer.