NewLanguageSystem: header.php

File header.php, 5.9 kB (added by mickecarlsson, 4 years ago)

Proposal file, put it in admin directory

Line 
1 <?php /* $Id: header.php 5016 2007-09-09 11:11:11Z diego_iastrubni $ */
2 //Copyright (C) 2004 Coalescent Systems Inc. (info@coalescentsystems.ca)
3 //
4 //This program is free software; you can redistribute it and/or
5 //modify it under the terms of the GNU General Public License
6 //as published by the Free Software Foundation; either version 2
7 //of the License, or (at your option) any later version.
8 //
9 //This program is distributed in the hope that it will be useful,
10 //but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //GNU General Public License for more details.
13
14 @header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); 
15 @header('Expires: Sat, 01 Jan 2000 00:00:00 GMT'); 
16 @header('Cache-Control: post-check=0, pre-check=0',false); 
17 @header('Pragma: no-cache'); 
18 //session_cache_limiter('public, no-store');
19
20 /** Loads a view (from the views/ directory) with a number of named parameters created as local variables.
21  * @param  string   The name of the view.
22  * @param  array    The parameters to pass. Note that the key will be turned into a variable name for use by the view.
23  *                  For example, passing array('foo'=>'bar'); will create a variable $foo that can be used by
24  *                  the code in the view.
25  */
26 function loadview($viewname, $parameters = false) {
27   ob_start();
28   showview($viewname, $parameters);
29   $contents = ob_get_contents();
30   ob_end_clean();
31   return $contents;
32 }
33 /** Outputs the contents of a view.
34  * @param  string   The name of the view.
35  * @param  array    The parameters to pass. Note that the key will be turned into a variable name for use by the view.
36  *                  For example, passing array('foo'=>'bar'); will create a variable $foo that can be used by
37  *                  the code in the view.
38  */
39 function showview($viewname, $parameters = false) {
40   if (is_array($parameters)) {
41     extract($parameters);
42   }
43  
44   $viewname = str_replace('..','.',$viewname); // protect against going to subdirectories
45   if (file_exists('views/'.$viewname.'.php')) {
46     include('views/'.$viewname.'.php');
47   }
48 }
49
50 //get the current file name
51 $currentFile = $_SERVER["PHP_SELF"];
52 $parts = explode('/', $currentFile);
53 //header('Content-type: text/html; charset=utf-8');
54 $currentFile = $parts[count($parts) - 1];
55 //todo: can this be removed? what is it used for?
56
57
58 // Emulate gettext extension functions if gettext is not available
59 if (!function_exists('_')) {
60   function _($str) {
61     return $str;
62   }
63 }
64 if (!function_exists('gettext')) {
65   function gettext($message) {
66     return $message;
67   }
68 }
69 if (!function_exists('dgettext')) {
70   function dgettext($domain, $message) {
71     return $message;
72   }
73 }
74
75 // setup locale
76 function set_language() {
77     global $currentlang;
78   if (isset($_COOKIE['lang'])) {
79         $currentlang = $_COOKIE['lang'];
80       } else {
81         $currentlang = 'en_US';
82         }
83   if (file_exists("language/lang-$currentlang.php")) {
84         include_once("language/lang-$currentlang.php");
85         } else {
86         include_once("language/lang-en_US.php");
87         }
88 }
89
90    
91    
92 //  if (extension_loaded('gettext')) {
93 //    if (isset($_COOKIE['lang'])) {
94 //      setlocale(LC_ALL,  $_COOKIE['lang']);
95 //      putenv("LANGUAGE=".$_COOKIE['lang']);
96 //    } else {
97 //      setlocale(LC_ALL,  'en_US');
98 //    }
99 //    if (is_dir("language")) {
100 //          if (file_exists("language/lang-$currentlang.php")) {
101 //            include("language/lang-$currentlang.php");
102 //          } else {
103 //              include("language/lang-en_US.php");
104 //             }
105 //      }
106 //      }
107     // else use the old language style
108 //  else
109 //  {
110 //    bindtextdomain('amp','./i18n');
111 //    bind_textdomain_codeset('amp', 'utf8');
112 //    textdomain('amp');
113 //  }
114 //}
115 set_language();
116
117
118 // systems running on sqlite3 (or pgsql) this function is not available
119 // instead of changing the whole code, lets hack our own version of this function.
120 // according to the documentation found here: http://il2.php.net/mysql_real_escape_string
121 // this shold be enough.
122 // Fixes ticket: http://freepbx.org/trac/ticket/1963
123 if (!function_exists('mysql_real_escape_string')) {
124   function mysql_real_escape_string($str) {
125     $str = str_replace( "\x00", "\\" . "\x00", $str );
126     $str = str_replace( "\x1a", "\\" . "\x1a", $str );
127     $str = str_replace( "\n" , "\\". "\n"    , $str );
128     $str = str_replace( "\r" , "\\". "\r"    , $str );
129     $str = str_replace( "\\" , "\\". "\\"    , $str );
130     $str = str_replace( "'" , "''"           , $str );
131     $str = str_replace( '"' , '""'           , $str );
132     return $str;
133   }
134 }
135
136 // include base functions
137 require_once('functions.inc.php');
138 require_once('common/php-asmanager.php');
139
140 // get settings
141 $amp_conf = parse_amportal_conf("/etc/amportal.conf");
142 $asterisk_conf  = parse_asterisk_conf($amp_conf["ASTETCDIR"]."/asterisk.conf");
143 $astman   = new AGI_AsteriskManager();
144
145 // attempt to connect to asterisk manager proxy
146 if (!isset($amp_conf["ASTMANAGERPROXYPORT"]) || !$res = $astman->connect("127.0.0.1:".$amp_conf["ASTMANAGERPROXYPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
147   // attempt to connect directly to asterisk, if no proxy or if proxy failed
148   if (!$res = $astman->connect("127.0.0.1:".$amp_conf["ASTMANAGERPORT"], $amp_conf["AMPMGRUSER"] , $amp_conf["AMPMGRPASS"])) {
149     // couldn't connect at all
150     unset( $astman );
151   }
152 }
153 // connect to database
154 require_once('common/db_connect.php'); //PEAR must be installed
155
156 // default password check
157 $nt = notifications::create($db);
158 if ($amp_conf['AMPMGRPASS'] == $amp_conf_defaults['AMPMGRPASS'][1]) {
159   $nt->add_warning('core', 'AMPMGRPASS', _("Default Asterisk Manager Password Used"), _("You are using the default Asterisk Manager password that is widely known, you should set a secure password"));
160 } else {
161   $nt->delete('core', 'AMPMGRPASS');
162 }
163
164 // always run a session
165 @session_start();
166
167 // do authentication - header_auth exits if unauthorized
168 include('header_auth.php');
169
170 ?>