Hi guys im having an issue with the global keyword. Whats happening is that when i try to bring a global variable into the functions scope it just doesnt see the variable inside the file.
Ill post the full code below but heres the jist of whats happening:
a function is called to load a module, we give it prefix if we know it as well as the name of the hook that we want to call, we also pass in any paramaters it needs and we tell it if we want data back or not.
The function then looks up all modules that match our search in the database, if we find results we include the actual modules php file (this file is where things break) and then call our hook.
Heres what a call looks like
php Code:
$content .= loadModules(MODULE_TYPE_PAYMENT_OPTION, "", "showButton", "", "1");
Heres the code for the function we just called
php Code:
//=========================================================
// Load module files so we can call them
//=========================================================
function loadModules($type, $prefix, $hookToCall, $hookArguments, $returnResult) {
$hookFunctionName = "";
$extraSql = "";
$extraSql = ($prefix == "") ? "" : " AND m.modules_prefix = '" . $prefix . "'";
$sql = "SELECT ma.modules_assoc_active, m.modules_viewing_permisions, m.modules_prefix FROM `" . $DBTABLEPREFIX . "modules_assoc` ma LEFT JOIN `" . $DBTABLEPREFIX . "modules` m ON m.modules_id = ma.modules_assoc_module_id WHERE ma.modules_assoc_company_id = '" . $_SESSION['companyid'] . "' AND m.modules_type = '" . $type . "'" . $extraSql . ";";
// We now need to cycle through our modules that match our search, if they are active
if ($row['modules_assoc_active'] == ACTIVE) {
// Piece together our total function name
// Get our module directory structure
$moduleHolderDirectory = ($row['modules_viewing_permisions'] == MODULE_PERM_PUBLIC) ? "global" : $_SESSION['companyid'];
switch ($type) {
case MODULE_TYPE_PAGE:
$moduleTypeDirectory = "pages";
break;
case MODULE_TYPE_PAYMENT_OPTION:
$moduleTypeDirectory = "payment_options";
break;
case MODULE_TYPE_GRAPH:
$moduleTypeDirectory = "graphs";
break;
case MODULE_TYPE_REPORT:
$moduleTypeDirectory = "reports";
break;
case MODULE_TYPE_REGISTER:
$moduleTypeDirectory = "registers";
break;
case MODULE_TYPE_USER:
$moduleTypeDirectory = "users";
break;
case MODULE_TYPE_INVENTORY:
$moduleTypeDirectory = "inventory";
break;
case MODULE_TYPE_ANALYTICS:
$moduleTypeDirectory = "analytics";
break;
}
// Include our module file
$fullModulePath = "modules/" . $moduleHolderDirectory . "/" . $moduleTypeDirectory . "/" . $row['modules_prefix'] . ".php";
include($fullModulePath);
// Call our hook function
if ($returnResult == 1) {
/*
$returnVar = "";
eval("\$returnVar = " . $hookFunctionName . ";");
return $returnVar;
*/
if ($hookArguments != "") {
$returnVar =
call_user_func($row&
#91;'modules_prefix'] . '_' . $hookToCall); }
else {
$returnVar =
call_user_func($row&
#91;'modules_prefix'] . '_' . $hookToCall); }
return $returnVar;
}
else {
eval($hookFunctionName .
";");
}
}
}
}
}
Heres whats breaking
php Code:
//====================================
// Basic Module information
//====================================
$name = "Accept Cash";
$description = "Adds Cash to the list of accepted payment types.";
$developer = "Paden Clayton";
$version = "1.08.11.25";
$prefix = "cash";
$type = MODULE_TYPE_PAYMENT_OPTION;
$viewingPermissions = MODULE_PERM_PUBLIC;
$seperateTab = 0;
$buttonText = "Pay By Cash";
//====================================
// Show Button hook
//====================================
function cash_showButton() {
global $menuvar,
$prefix,
$buttonText;
$content = "
<a href=\"" . $menuvar['PAYMENT'] . "&action=module&prefix=" . $prefix . "\" class=\"button\"><span>" . $buttonText . "</span></a>";
return $content;
}
The items in all caps are defined variables that get used throghuout the system. Ive could get this working by passing the variables as parameters but on a large scale this completely defeats the purpose of making a modular system and really prohibits future changes.
Any ideas on how to fix this issue?