<?php
/*
 * This file is part of a larger software package. Please read the License file 
 * in the root of this installation for terms of usage and distribution.
 * 
 * @author The Web Pro Miami, Inc. <info@thewebpro.com>
 * @copyright The Web Pro Miami, Inc. <info@thewebpro.com>, http://www.thewebpro.com/
 * 
 * CORE: manage/dialog/components_toggle.php - version 1.01
*/

$nAdminOnlyPg = 1;

require("../inc/stop_cache.php");

// Secure and connect
require("../../inc/dbconnect.php");
require("../inc/secure_page.php");

// bring in other required files
require("../../inc/config.php");
require("../inc/lang.php");

// config
$nRefreshCall = "nLoadComponentsTable();";

// Get passed-in vars
$nRecID = (isset($_GET['id']) ? $_GET['id'] : NULL);
if(!$nRecID){ $nRecID = (isset($_POST['id']) ? $_POST['id'] : NULL); }

// AJAX Specific vars
$nPassThru = "?id=$nRecID";
$nDivToUpdate = "editModal";
$nPageInDiv = "dialog/component_toggle.php";

// Get additional data
if($nRecID){
	$nSQL = "SELECT * FROM nComponent WHERE nID=$nRecID";
	mysql_select_db($DBName); $Result = mysql_query($nSQL,$Link);
	if($Row = mysql_fetch_array($Result)){
		$nName = $Row["nName"];
		$nActive = $Row["nActive"];
		if(!$nName){ $nName="<em>&lt;"._("unnamed")."&gt;</em>"; }
	}
}
?>

<div id="<?php echo $nDivToUpdate;?>">

<?php
include("../inc/form_class.php");

$nFormName = "FormCompEdit";
$nForm1 = new Form();
//$nForm1->DEBUG = true;
$nForm1->Name = $nFormName;
$nForm1->Action = $_SERVER['PHP_SELF'];
$nForm1->CancelText = _("Cancel");
$nForm1->CancelRedirect = "$.colorbox.close()";
$nForm1->CancelRedirectIsJS = true;
$nForm1->SubmitText = _("Save Changes");
$nForm1->ModifyDBTable = "nComponent";
$nForm1->ModifyDBField = "nID";
$nForm1->ModifyDBID = "$nRecID";
$nForm1->DontProcess = "id";

$nForm1->DBLink = $Link;
$nForm1->nUseADODB = false;
// AJAX settings
$nForm1->SubmitIsJS = true;
$nForm1->SubmitToJS = "return submitForm('$nDivToUpdate','$nPageInDiv$nPassThru','$nFormName');return false;";
// Form styling
$nForm1->FormClass = "form"; // no-border
$nForm1->CleanMarkup = true;
$nForm1->SubmitClass = "button blue";
$nForm1->CancelClass = "button";
$nForm1->ButtonTemplate = "<div class=\"clearfix grey-highlight\"><div class=\"input no-label\">[#Buttons#]</div></div>\n";
$nForm1->FieldTemplate = "<div id=\"[#RowID#]\" class=\"clearfix\" style=\"[#RowStyle#]\">[#Label#]<div class=\"input\" style=\"[#ItemStyle#]\">[#BeforeField#][#Field#][#AfterField#]<span class=\"info\">[#Caption#]</span></div></div>\n";
$nForm1->GroupTemplate = "<div id=\"[#ID#]\" style=\"[#Style#]\" class=\"[#Class#]\">\n[#Name#][#FieldCode#]\n</div>\n";

// Create groups
$nFormGroup1 = new FormGroup();

// Create fields
$nFormField = new FormField("hidden","id");
$nFormField->Value = $nRecID;
$nFormGroup1->AddField($nFormField);

$nFormField = new FormField("static","",_("Component Name:"));
$nFormField->Value = "<div style=\"padding:6px 0;\"><strong>$nName</strong></div>";
$nFormGroup1->AddField($nFormField);

$nFormField = new FormField("select","nActive",_("Component Status:"));
$nFormField->Title = _("NOTE: Disabled components do not display on the site and can be re-activated anytime.");
$nFormField->Rel = "tooltips";
$nEnabledText = _("Enabled");
$nDisabledText = _("Disabled");
$nFormField->DataARRAY = array(
	"1" => "$nEnabledText",
	"0" => "$nDisabledText");
$nFormField->SelectedARRAY = array("$nActive" => "selected");
$nFormField = $nForm1->AddValidation("required",$nFormField);
$nFormField->RowStyle = "clear:both;float:none;";
$nFormGroup1->AddField($nFormField);

// Finalize and display form
$nForm1->AddGroup($nFormGroup1);
$nFormToDisplay = $nForm1->GetForm();

// AJAX redirect if form submitted w/o error, otherwise display form (again, if necessary)
if($nForm1->HasProcessed){
	//echo "<div align=\"center\" id=\"buttonBox\"><BR>";
		//echo "<strong>"._("The component has been succesfully edited!")."</strong><BR><BR>";
		//echo _("What do you want to do next?")."<BR><BR>";
		//echo "<input type=\"button\" name=\"nEdit\" value=\""._("Edit Component")."\" onClick=\"document.location.href='component_edit.php?id=".$_POST["nID"]."'\" class=\"formSubmit\"> ";
		//echo "<input type=\"button\" name=\"nClose\" value=\""._("Close")."\" onClick=\"$.colorbox.close();\" class=\"formCancel\"> ";
	//echo "</div>";
	echo "<script>$nRefreshCall $.colorbox.close();</script>";
} else {
	echo $nFormToDisplay;
	echo "<script>$.colorbox.resize();</script>";
}
?>
</div>

<?php
function nGetPageARRAY(){
	global $DBName,$Link;
	global $nRecID;
	$nDataARRAY = array();
	$nSQL = "SELECT nID,nNavTitle FROM nPage ORDER BY nType,nSectionID,nOrderID";
	mysql_select_db($DBName); $Result = mysql_query($nSQL,$Link);
	while($Row = mysql_fetch_array($Result)){
		$nID = $Row["nID"];
		$nNavTitle = $Row["nNavTitle"];
		$nDataARRAY["$nID"] = "$nNavTitle";
	}
	return $nDataARRAY;
}
?>
<?php require("../../inc/db_close.php"); ?>
