Bonjour, j'ai actuellement un petit probleme dans un code en php :
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in c:\program files\easyphp1-8\www\ogame\admin\admin.class.php on line 34
Voici le code :
<?php
define( 'PHP_MIN_VERSION', '5.1.1' );
$g_cached_version = array();
function php_version_at_least( $p_version_string ) {
global $g_cached_version;
if ( isset( $g_cached_version[$p_version_string] ) ) {
return $g_cached_version[$p_version_string];
}
$t_curver = array_pad( explode( '.', phpversion() ), 3, 0 );
$t_minver = array_pad( explode( '.', $p_version_string ), 3, 0 );
for ($i = 0 ; $i < 3 ; $i = $i + 1 ) {
$t_cur = (int)$t_curver[$i];
$t_min = (int)$t_minver[$i];
if ( $t_cur < $t_min ) {
$g_cached_version[$p_version_string] = false;
return false;
} else if ( $t_cur > $t_min ) {
$g_cached_version[$p_version_string] = true;
return true;
}
}
$g_cached_version[$p_version_string] = true;
return true;
}
# --------------------
# Enforce our minimum requirements
if ( !php_version_at_least( PHP_MIN_VERSION ) ) {
ob_end_clean();
PRINT '<b>Your version of PHP is too old. Ugamela requires PHP version ' . PHP_MIN_VERSION . ' or newer</b>';
phpinfo();
die();
}
class admin{
private $path,$modules,$loaded_module_name;
public $smarty,$lang,$db;
function __construct($lang,$path,$db,$debug){
require_once("./lang.class.php");
require_once("./libs/Smarty.class.php");
$this->lang = new lang($lang);
$this->db = $db;
$this->path = $path;
$this->smarty = new Smarty;
$this->smarty->compile_check = true;
//$this->smarty->debugging = $debug;
$this->smarty->template_dir = "templates/";
return true;
}
function load_modules_list(){
$result = $this->db->query("SELECT * FROM {{table}} ORDER BY weight","admin_modules");
while ($row = $this->db->fetch_assoc($result)) {
$this->modules[] = $row;
}
}
function load_module_for_user_by_id($module_name,$user_id){
if ($this->check_user_acces_for_module($module_name,$user_id) == true) {
include_once($this->path.$module_name.".php");
$this->loaded_module_name = $module_name;
} else {
echo $this->lang->translate("permission denied");
}
}
function run_loaded_module(){
if (function_exists($this->loaded_module_name."_run")) {
return call_user_func($this->loaded_module_name."_run",$this);
} else {
echo $this->lang->translate("Module").$this->loaded_module_name.$this->lang->translate("isn't valid ugamela administration module");
}
}
function load_module_info_by_name($module_name){
include_once($this->path.$module_name.".php");
return call_user_func($module_name."_info");
}
function get_module_info_by_id($module_id){
return $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE module_id='".$module_id."';","admin_modules"));
}
function check_user_acces_for_module($module_name,$user_id){
$module = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE module_name='".$module_name."'","admin_modules"));
$acl_user_row = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE user_id='".$user_id."'","admin_acl"));
if ($acl_user_row["admin"] == 1) {
return true;
}
$acl = unserialize($acl_user_row["acl"]);
if ($acl[$module["module_id"]] == true) {
return true;
} else {
return false;
}
}
function grant_user_acces_for_module($module_name,$user_id){
$module = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE module_name='".$module_name."'","admin_modules"));
$acl_user_row = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE user_id='".$user_id."'","admin_acl"));
$acl = unserialize($acl_user_row["acl"]);
$acl[$module["module_id"]] = 1;
$this->db->query("UPDATE {{table}} SET acl='".serialize($acl)."' WHERE user_id='".$user_id."'","admin_acl");
}
function revoke_user_acces_for_module($module_name,$user_id){
$module = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE module_name='".$module_name."'","admin_modules"));
$acl_user_row = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE user_id='".$user_id."'","admin_acl"));
$acl = unserialize($acl_user_row["acl"]);
$acl[$module["module_id"]] = 0;
$this->db->query("UPDATE {{table}} SET acl='".serialize($acl)."' WHERE user_id='".$user_id."'","admin_acl");
}
function grant_admin_permissions_by_user_id($user_id){
$this->db->query("UPDATE {{table}} SET admin='1' WHERE user_id='".$user_id."'","admin_acl");
}
function revoke_admin_permissions_by_user_id($user_id){
$this->db->query("UPDATE {{table}} SET admin='0' WHERE user_id='".$user_id."'","admin_acl");
}
function fetch_admin_status($user_id){
$acl_user_row = $this->db->fetch_assoc($this->db->query("SELECT * FROM {{table}} WHERE user_id='".$user_id."'","admin_acl"));
return $acl_user_row["admin"];
}
function print_modules_for_user_by_id($user_id){
foreach ($this->modules as $module){
if (($this->check_user_acces_for_module($module["module_name"],$user_id)) == true){
$modules[] = array("module_name"=>$module["module_name"],"module_full_name"=>$this->lang->translate($module["module_full_name"]));
}
}
return $modules;
}
function search_modules(){
$dir = opendir($this->path);
while ($entry = readdir($dir)) {
if (is_file($this->path.$entry)) {
$entry = str_replace(".php","",$entry);
$module = $this->db->fetch_assoc($this->db->query("SELECT COUNT(*) as cnt FROM {{table}} WHERE module_name='".$entry."';","admin_modules"));
if ($module["cnt"] == 0) {
$info = $this->load_module_info_by_name($entry);
$this->db->query("INSERT INTO {{table}} (`module_name` , `module_full_name` , `module_description` , `weight` ) VALUES ('".$entry."', '".$info["name"]."', '".$info["description"]."' , '".$info["weight"]."');","admin_modules");
}
}
}
return true;
}
function check_module_exist_by_name($module_name){
$module = $this->db->fetch_assoc($this->db->query("SELECT COUNT(*) as cnt FROM {{table}} WHERE module_name='".$module_name."';","admin_modules"));
if ($module["cnt"] == 0) {
return false;
} else {
return true;
}
}
function safe_get_get_var($var){
global $_GET;
return $this->db->escape_string($_GET[$var]);
}
function safe_get_post_var($var){
global $_POST;
return $this->db->escape_string($_POST[$var]);
}
Trouvez des réponses à vos questions sur les langages, les frameworks et les astuces de codage. Échangez avec d'autres développeurs passionnés pour améliorer vos compétences en programmation et rester au fait des dernières tendances du secteur.