[5341] | 1 | <?php |
---|
| 2 | |
---|
[6528] | 3 | namespace prototype\api; |
---|
| 4 | |
---|
[5341] | 5 | class Config |
---|
| 6 | { |
---|
[6528] | 7 | static $register; |
---|
[6800] | 8 | |
---|
[6528] | 9 | static function module($config , $module = false) |
---|
| 10 | { |
---|
| 11 | //Todo: registrar na nova api o currentapp |
---|
| 12 | if(!$module) |
---|
| 13 | $module = $_SESSION['flags']['currentapp']; |
---|
[5399] | 14 | |
---|
[6528] | 15 | if( !isset( $_SESSION['config'][$module] ) || !isset( $_SESSION['config'][$module][$config] )) |
---|
| 16 | $_SESSION['config'][$module] = parse_ini_file( ROOTPATH."/config/$module.ini", true ); |
---|
[5341] | 17 | |
---|
[6528] | 18 | return isset($_SESSION['config'][$module][$config]) ? $_SESSION['config'][$module][$config] : false; |
---|
[5341] | 19 | |
---|
[6528] | 20 | } |
---|
[5341] | 21 | |
---|
[6528] | 22 | static function me($config) |
---|
| 23 | { |
---|
[5399] | 24 | |
---|
[6528] | 25 | return isset($_SESSION['wallet']['user'][$config]) ? $_SESSION['wallet']['user'][$config] : false; |
---|
| 26 | } |
---|
[5399] | 27 | |
---|
[6528] | 28 | static function service( $service , $config ) |
---|
| 29 | { |
---|
| 30 | if( !isset( $_SESSION['wallet'][$service] ) || !isset( $_SESSION['wallet'][$service][$config] )) |
---|
| 31 | $_SESSION['wallet'][$service] = parse_ini_file( ROOTPATH."/config/$service.srv", true ); |
---|
[5415] | 32 | |
---|
[6528] | 33 | return (isset($_SESSION['wallet'][$service][$config])) ? $_SESSION['wallet'][$service][$config] : false; |
---|
| 34 | } |
---|
[5399] | 35 | |
---|
[6528] | 36 | static function get( $concept , $config = false , $module = false ) |
---|
| 37 | { |
---|
| 38 | $load = parse_ini_file( ROOTPATH."/config/$concept.ini", true ); |
---|
[5437] | 39 | |
---|
[6528] | 40 | if($config === false) return $load; |
---|
[5437] | 41 | |
---|
[6528] | 42 | return (isset($load[$config])) ? $load[$config] : false; |
---|
| 43 | } |
---|
[5437] | 44 | |
---|
[6528] | 45 | static function regSet( $name , $value) |
---|
| 46 | { |
---|
| 47 | self::$register[$name] = $value; |
---|
| 48 | } |
---|
| 49 | static function regGet ($name ) |
---|
| 50 | { |
---|
| 51 | return (isset(self::$register[$name]) ? self::$register[$name] : false ); |
---|
| 52 | } |
---|
[5341] | 53 | |
---|
[6528] | 54 | static function init( ) |
---|
| 55 | { |
---|
| 56 | |
---|
| 57 | if( !defined( 'ROOTPATH' ) ) |
---|
| 58 | define( 'ROOTPATH', dirname(__FILE__).'/..' ); |
---|
[5399] | 59 | |
---|
[6528] | 60 | if ( isset( $_COOKIE[ 'sessionid' ] ) ) |
---|
| 61 | { |
---|
| 62 | session_id( $_COOKIE[ 'sessionid' ] ); |
---|
| 63 | $GLOBALS['phpgw']->session->sessionid = $_COOKIE[ 'sessionid' ]; |
---|
| 64 | } |
---|
[5399] | 65 | |
---|
[6800] | 66 | if( !isset($_SESSION) ) |
---|
| 67 | session_start(); |
---|
[5399] | 68 | |
---|
[6528] | 69 | } |
---|
[6800] | 70 | |
---|
[6528] | 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 | } |
---|
[5399] | 83 | |
---|
[6528] | 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 | } |
---|
| 108 | |
---|
[5341] | 109 | } |
---|
| 110 | |
---|
[6528] | 111 | Config::init(); |
---|
[5399] | 112 | |
---|
| 113 | |
---|
[5341] | 114 | ?> |
---|