Hi,
I am a beginner at php. I have the following problem. I installed a cms in a subdirectory and had someone create a mod with me. The problem is in the following code in all the places it says $_SERVER["DOCUMENT_ROOT"] it points to the root of the server with the corresponding file. The problem is the file is in a subdirectory and I have no clue how to code it (using the include function or what not). Can someone look at it and code the 5-6 places where it points to document root to the actual file in the subdirectory folder? The file is located in the subdirectory folder called society.
The Code:
<?php
/ Check Structure Availability /
if (!defined("CORE_STRAP")) die("Out of structure call");
/ Administrative restriction /
(!me('is_administrator')&&!me('is_superadministrator')?die("Access restricted"):NULL);
/
Initialize the template engine and load the
template file
/
$tpl = new template;
$tpl -> Load("admin");
/// FUNCTION SAVE GROUPS CONFIG ////////////
function saveGroupsConfig($Item, $Val){
global $GROUPS_CONFIG;
//Check if we can write that file
if (is_writable($SERVER["DOCUMENT_ROOT"]."/modules/groups/groups_config.php")) {
//Create the new line to be inserted
$newLine = "\$GROUPS_CONFIG[\"".$Item."\"] = ";
//Play with values types, we will try
//to assign the value as integer, bool,
//or string.
if (is_numeric($Val)) $newLine .= $Val;
elseif (is_bool($Val)) $newLine .= ($Val?"true":"false");
else $newLine .= "\"".str_replace("\"", "\\"", stripslashes($Val))."\"";
//Append line termination
$newLine .= ";";
//Load the configuration file body into a buffer
$configBody = @file_get_contents($SERVER["DOCUMENT_ROOT"]."/modules/groups/groups_config.php");
//Swap the old line with the new one
$configBody = preg_replace(
'/\$GROUPS_CONFIG\["'.preg_quote($Item).'"\]./',
$newLine,
$configBody
);
// Backup the configuration file before we make any change
copy($SERVER["DOCUMENT_ROOT"]."/modules/groups/groups_config.php", "system/cache/backups/autobackup".date("dmyhi")."groups_config.php");
//Save the buffer into the configuration file ...
ignore_user_abort(true);
if ($handle = fopen($SERVER["DOCUMENT_ROOT"]."/modules/groups/groups_config.php", "w")) {
//Tryt to lock the file and write
flock($handle, LOCK_EX);
fwrite($handle, $configBody);
flock($handle, LOCK_UN);
fclose($handle);
ignore_user_abort(false);
//Override the actual configuration
$GROUPS_CONFIG[$Item] = $Val;
return true;
}
}
else
{
return false;
}
}
/// CHECK IF CHANGE SHOULD BE MADE //////////////////////////
if (isset($POST["Submit"]))
{
if (isset($POST["grouppics_path"]))
{
saveGroupsConfig("grouppics_path", $POST["grouppics_path"]);
}
if (isset($POST["image_max_size"]))
{
saveGroupsConfig("image_max_size", $POST["image_max_size"]);
}
for ($i = 1 ; $i<=100 ; $i++)
{
$this_posted='txt'.$i;
if (isset($POST[$this_posted]))
{
saveGroupsConfig($this_posted, $POST[$this_posted]);
}
}
}
// Calling the configuration file ////////////////////////////////////////////////////
require($SERVER["DOCUMENT_ROOT"]."/modules/groups/groups_config.php");
$tpl -> AssignArray($GROUPS_CONFIG);
// CHECKING IF CATEGORIES SECTION NEEDS CHANGES ///////////////////////////////
if($GET[action]=="add_category")
{
myQ("INSERT INTO [x]group_categories
(category_name)
VALUES
('".$POST['new_cat_name']."')");
}
if($GET[action]=="rem_category")
{
myQ("DELETE FROM [x]group_categories WHERE id_gcat='".$GET[id]."' ");
}
if($GET[action]=="rename_category")
{
myQ("UPDATE [x]group_categories
SET category_name='".$POST['new_name']."'
WHERE id_gcat='".$GET[id]."'
");
}
// RETRIEVING CATEGORIES ////////////////////////
$categoriesSelect = myQ("
SELECT id_gcat,category_name
FROM [x]group_categories ORDER BY id_gcat DESC
");
if (myNum($categoriesSelect) > 0) {
$limit=myNum($categoriesSelect);
for ($i = 0; $i <$limit ; $i++)
{
$categories=myF($categoriesSelect);
$ReplacementArray[$i] = array(
"category.id" => $categories[0],
"category.name" => $categories[1]
);
}
}
if (isset($ReplacementArray)) {
$tpl -> Zone("groupcategories", "enabled");
$tpl -> Loop("groupcategories_loop", $ReplacementArray);
}
// TEMPLATE REPROCESS & FLUSH ////////////////////////////////////////////////////
$tpl -> CleanZones();
/ Get the frame templates, flush the TPL result into it /
$frame = new template;
$frame -> Load("!theme/{$GLOBALS["THEME"]}/templates/admin/frame.tpl");
$frame -> AssignArray(array(
"jump" => $tpl->Flush(1)
));
/ Assign Location Value /
$locationArray = explode(".", $_GET["L"]);
for ($i=0; $i<count($locationArray); $i++) {
$locationAppendResult[] = $locationArray[$i];
if ($i > 0) $location[] = "<a href=\"?L=".implode(".", $locationAppendResult)."\">{$locationArray[$i]}</a>";
}
$frame -> AssignArray(array("location" => implode(" » ", $location)));
/ Set the forced chromeless mode, flush the template */
$GLOBALS["CHROMELESS_MODE"] = 1;
$frame -> Flush();
?>