<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Modules :: NitroBOSubModule :: Menu |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2006 June Systems B.V. |
// +---------------------------------------------------------------------------+
// | This source file is copyrighted by June Systems BV, the Netherlands |
// | If you would like to use this file in your projects, please contact |
// | hide@address.com |
// +---------------------------------------------------------------------------+
// | Authors: Jesper Avôt <hide@address.com> |
// +---------------------------------------------------------------------------+
//
// $Id: Module.inc.php 229 2008-04-17 09:20:31Z oli $
//
/**
* TODO: Fix menu list into a tree node list. @See: Nitro TreeNode card.
*/
/**
* Include Form controls and Listing classes
*/
require_once "Nitro/Libraries/Form.inc.php";
require_once "Nitro/Libraries/Listing.inc.php";
/**
* Menu
*
* @author Jesper Avôt <hide@address.com>
* @copyright 2006 June Systems B.V.
* @package Modules
* @subpackage NitroBO
*/
class NitroBO_Menu extends NitroBOSubModule {
/**
* Define some Module things
*/
var $ModuleName = "NitroBO_Menu";
var $ModuleVersion = "1.0";
var $ModuleAuthor = Array("Jesper Avôt");
/**
* Does Nothing
*/
function NitroBO_Menu() { }
/**
* GetSettingsDefinition function
*
* Which Settings are allowed in this Module?
*/
function GetSettingsDefinition()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
if (!isset($this->_ModuleSettings)) {
$this->_ModuleSettings = Array(
'P' => Array('SessionVariable' => FALSE, 'FormVariable' => 'P', 'Default' => NULL),
'MenuID' => Array('SessionVariable' => FALSE, 'FormVariable' => 'MenuID', 'Default' => NULL),
'AddMenu' => Array('SessionVariable' => FALSE, 'FormVariable' => 'AddMenu', 'Default' => NULL),
'AddVer' => Array('SessionVariable' => FALSE, 'FormVariable' => 'AddVer', 'Default' => NULL),
'Lang' => Array('SessionVariable' => FALSE, 'FormVariable' => 'Lang', 'Default' => NULL),
'Ver' => Array('SessionVariable' => FALSE, 'FormVariable' => 'Ver', 'Default' => NULL),
'Name' => Array('SessionVariable' => FALSE, 'FormVariable' => 'Name', 'Default' => NULL),
'IDString' => Array('SessionVariable' => FALSE, 'FormVariable' => 'IDString', 'Default' => NULL),
'ParentID' => Array('SessionVariable' => FALSE, 'FormVariable' => 'ParentID', 'Default' => NULL),
'MenuData' => Array('SessionVariable' => FALSE, 'FormVariable' => 'MenuData', 'Default' => NULL),
'RemoveVersion' => Array('SessionVariable' => FALSE, 'FormVariable' => 'RemoveVersion', 'Default' => NULL),
'CloseTab' => Array('SessionVariable' => FALSE, 'FormVariable' => 'CloseTab', 'Default' => NULL),
'ModFilter' => Array('SessionVariable' => FALSE, 'FormVariable' => 'ModFilter/', 'Default' => NULL),
'Start' => Array('SessionVariable' => FALSE, 'FormVariable' => 'Start', 'Default' => 0)
);
}
DebugCloseGroup(DEBUG_MOD_OK);
return $this->_ModuleSettings;
}
/**
* GetSettingsDefinition function
*
* Which Settings are allowed in this Module for XML Requests?
*/
function GetXMLDefinition()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
if (!isset($this->_XMLDefinition)) {
$this->_XMLDefinition = Array(
'DeleteMenu' => Array('Type' => "HTML",
'Name' => "Delete Menu",
'DivID' => "UserField",
'FunctionName' => "DeleteMenu"),
'EditMenu' => Array('Type' => "HTML",
'Name' => "Edit Menu",
'DivID' => "EditField",
'FunctionName' => "EditMenu"),
'SaveMenu' => Array('Type' => "HTML",
'Name' => "Save Menu",
'DivID' => "ErrorDiv",
'FunctionName' => "SaveMenu"),
'Version' => Array('Type' => "HTML",
'Name' => "Add Menu Version",
'DivID' => "UserField",
'FunctionName' => "addVersion"),
'FilterMod' => Array('Type' => "HTML",
'Name' => "Filter Menu List",
'DivID' => "UserField",
'FunctionName' => "ShowMenuList"),
'MenuList' => Array('Type' => "HTML",
'Name' => "User Menu",
'DivID' => "UserField",
'FunctionName' => "ShowMenuList")
);
}
DebugCloseGroup(DEBUG_MOD_OK);
return $this->_XMLDefinition;
}
/**
* GetObjectsDefinition function
*
* Which Objects are allowed ?
*/
function GetObjectsDefinition()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$this->_ModuleObjects = Array(
'Draw' => Array('Type' => 'HTML',
'Name' => 'Text',
'FunctionName' => 'Draw',
'Default' => TRUE)
);
DebugCloseGroup(DEBUG_MOD_OK);
return $this->_ModuleObjects;
}
/**
* DeleteMenu function
*/
function DeleteMenu()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$MenuID = (int)$this->GetSetting('MenuID');
$Transaction = new Transaction($this->DB, $this->Sess->UserID, TRUE);
$Transaction->addData('Menu',
Array('MenuID' => $MenuID),
Array('MenuID' => $MenuID),
'DELETE');
$Transaction->addData('MenuData',
Array('MenuID' => $MenuID),
Array('MenuID' => $MenuID),
'DELETE');
$RV = Array("UserField" => ($Transaction->Commit() !== FALSE) ? $this->ShowMenuList() : "");
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* EditMenu function
*/
function EditMenu()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$MenuID = (int)($this->GetSetting('MenuID') ? $this->GetSetting('MenuID') : "0");
if ($this->GetSetting('AddMenu')) {
$data = Array("ParentID" => "", "SortOrder" => "", "IDString" => "", "Name" => "");
$MenuItems = Array();
$formadd = TRUE;
$Name = "Add New Menu";
} else {
$Query = "SELECT
*
FROM
`Menu`
WHERE
MenuID = " . $MenuID;
$data = $this->DB->getRow($Query);
$DQuery = "SELECT
Language,
Version,
Title,
Description,
PageID,
Forward,
Target,
Published,
VisibleFrom,
VisibleTill
FROM
`MenuData`
WHERE
MenuID = " . $MenuID;
$Result = $this->DB->query($DQuery);
$MenuItems = Array();
if ($Result->NumRows() > 0) {
while ($Data = $Result->fetchArray()) {
if (!$Data['Language'] || $Data['Language'] == "") $Data['Language'] = "Default";
if (!$MenuItems[$Data['Language']]) $MenuItems[$Data['Language']] = Array();
$MenuItems[$Data['Language']][$Data['Version']] = $Data;
}
}
$formadd = FALSE;
$Name = $data["Name"];
}
$PQuery = "SELECT
DISTINCT
MenuID AS ID,
IF( ParentID != 0, CONCAT( ' ', Name ), Name ) AS Name
FROM
`Menu`
WHERE
MenuID != 0
AND
MenuID != " . $MenuID . "
ORDER
BY
ParentID";
if ($this->GetSetting('AddVer')) {
$Lang = $this->GetSetting('Lang');
$Vers = $this->GetSetting('Ver');
$MenuItems[$Lang][$Vers] = Array("Language" => $Lang, "Version" => $Vers, "Title" => "", "Description" => "", "PageID" => 0, "Forward" => 0, "Target" => "", "Published" => 0, "VisibleFrom" => "", "VisibleTill" => "");
}
$FormName = "EditMenuForm_" . ($this->GetSetting('MenuID') ? $this->GetSetting('MenuID') : 'NEW'.NitroCreateRandomString(4));
$Form = new Form($FormName, "/?P=" . $this->GetSetting('P'), "POST", "application/x-www-form-urlencoded");
$Form->HideButtons();
$Form->AddOptionString("P", "HIDDEN/VALUE=" . $this->GetSetting('P'));
$Form->AddOptionString("MenuID", "HIDDEN/VALUE=" . $this->GetSetting('MenuID'));
if ($formadd == TRUE) {
$Form->AddOptionString("AddMenu", "HIDDEN/VALUE=1");
}
$Form->AddOptionString("ErrorDiv_" . $MenuID, "DIV/LABLE= ");
$Form->AddOptionString("Name", "TEXT/VALUE=" . $data["Name"] . "/LABLE=" . Language('Name') . "/STYLE=width: 250px;");
$Form->AddOptionString("IDString", "TEXT/VALUE=" . $data["IDString"] . "/LABLE=" . Language('IDString') . "/STYLE=width: 250px;");
$Form->AddOptionString("ParentID", "SELECT/VALUES=0:" . Language('None') . "/QUERY=".$this->NitroBODBAlias.":" . $PQuery . "/SELECTED=" . $data['ParentID'] . "/LABLE=" . Language('Parent') . "/STYLE=width: 250px;");
$tabJscript = "";
$LanguageTab = new FormTab('Language_' . $MenuID);
if (is_array($this->AllowedLanguages) && count($this->AllowedLanguages)) {
$tabJscript.= "if(!theTabs['Language_" . $MenuID . "']) theTabs['Language_" . $MenuID . "'] = new Array();";
foreach ($this->AllowedLanguages AS $LangCode => $LangName) {
if (!is_array($PageData[$LangCode])) $PageData[$LangCode] = Array();
$this->EditLanguageTab($LanguageTab, $tabJscript, $MenuID, $LangCode, $MenuItems);
}
}
$Form->AddOption($LanguageTab);
$Custom = urlencode("<input type='button' onclick=\"ModuleXMLRequest('SaveMenu', GetXMLURL('" . $FormName . "')); return false;\" value='" . Language('Save') . "' />");
$Custom.= urlencode("<input type='button' onclick=\"ModuleXMLRequest('SaveMenu', GetXMLURL('" . $FormName . "') + '&CloseTab=1'); return false;\" value='" . Language('Save and Close') . "' />");
$Custom.= urlencode("<input type='button' onclick=\"DeletePageTab('" . $MenuID . "'); return false;\" value='" . Language('Cancel') . "' />");
$Form->AddOptionString("Temp", "HTML/LABLE= /VALUE=" . $Custom);
$Form->SetTemplateIDs("file:" . NITRO_PATH . "Defaults/Templates/BackOffice/form.tpl", "file:" . NITRO_PATH . "Defaults/Templates/BackOffice/widget.tpl");
$RV = Array("JSCRIPT:()" => $tabJscript . ($this->GetSetting('AddVer') || $this->GetSetting('RemoveVersion') ? "UpdatePageTab('" . $MenuID . "', 'Content', '" . rawurlencode($Form->Draw()) . "');" : "AddPageTab('" . $MenuID . "', '" . rawurlencode($Form->Draw()) . "', '" . rawurlencode($Name) . "');"));
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* Draw a Language tab and contents with the given options
*
* object $LanguageTab LanguageVersion tab to draw into
* string $tabJscript String to append and Javascript added by this function
* int $MenuID ID of menu being editted
* string $LangCode Language code
* array $PageData ???
*/
function EditLanguageTab(&$LanguageTab, &$tabJscript, $MenuID, $LangCode, $MenuItems)
{
$LangName = $this->AllowedLanguages[$LangCode];
$tabJscript.= "theTabs['Language_" . $MenuID . "']['" . $LangCode . "'] = '" . $LangName . "';";
$LanguageTab->AddTab($LangName, $LangCode);
$LanguageVersionTab = new FormTab($LangCode . "Version_" . $MenuID);
$tabJscript.= "if(!theTabs['" . $LangCode . "Version_" . $MenuID . "']) theTabs['" . $LangCode . "Version_" . $MenuID . "'] = new Array();";
if (is_array($MenuItems[$LangCode])) {
foreach ($MenuItems[$LangCode] AS $Ver => $Content) {
$this->EditLanguageVersionTab($LanguageVersionTab, $tabJscript, $MenuID, $LangCode, $Ver, $Content);
if ($Content['Published'] OR !$Content['Title']) $LanguageVersionTab->SetSelectedTab($LangCode.$Ver); // Set last published tab selected
}
}
$LanguageVersionTab->AddAction(Language('Add Version'), "#", "", "ModuleXMLRequest('Version', GetXMLURL('Language_" . $MenuID . "_TAB_" . $LangCode."') + '&AddVer=1&Ver=" . (count($MenuItems[$LangCode]) + 1) . "&Lang=" . $LangCode . "&MenuID=" . $MenuID . "'); return false;");
$LanguageTab->AddOption($LanguageVersionTab);
}
/**
* Draw a Language Version tab and contents with the given options
*
* object $LanguageVersionTab LanguageVersion tab to draw into
* string $tabJscript String to append and Javascript added by this function
* int $MenuID ID of menu being editted
* string $LangCode Language code being editted/added
* int $Ver Version being editted/added
* array $Content ???
*/
function EditLanguageVersionTab(&$LanguageVersionTab, &$tabJscript, $MenuID, $LangCode, $Ver, $Content)
{
$tabJscript.= "theTabs['" . $LangCode . "Version_" . $MenuID . "']['" . $LangCode . $Ver . "'] = '" . $LangCode . $Ver . "';";
$LanguageVersionTab->AddTab( "v" . $Ver, $LangCode . $Ver);
$Widgets = Array("MenuData[" . $LangCode . "][" . $Ver . "][Title]" => "TEXT/LABEL=" . Language('Title') . "/VALUE=" . $Content['Title'] . "/STYLE=width: 250px;",
"MenuData[" . $LangCode . "][" . $Ver . "][Published]" => "CHECKBOX/LABEL=" . Language('Published') . "/VALUE=1:" . Language('Yes') . "/SELECTED=" . $Content['Published'],
"MenuData[" . $LangCode . "][" . $Ver . "][VisibleFrom]" => "TEXT/LABEL=" . Language('Visible From') . "/VALUE=" . $Content['VisibleFrom'] . "/STYLE=width: 250px;",
"MenuData[" . $LangCode . "][" . $Ver . "][VisibleTill]" => "TEXT/LABEL=" . Language('Visible Till') . "/VALUE=" . $Content['VisibleTill'] . "/STYLE=width: 250px;",
"MenuData[" . $LangCode . "][" . $Ver . "][PageID]" => "SELECT/LABEL=" . Language('Page') . "/VALUES=0:" . Language('None') . "/DB=NitroBO:Page:PageID:Name/SELECTED=" . $Content['PageID'] . "/STYLE=width: 250px;",
"MenuData[" . $LangCode . "][" . $Ver . "][Target]" => "TEXT/LABEL=" . Language('Target') . "/VALUE=" . $Content['Target'] . "/STYLE=width: 250px;",
"MenuData[" . $LangCode . "][" . $Ver . "][Forward]" => "SELECT/LABEL=" . Language('Forward') . "/VALUES=0:" . Language('None') . "/Query=".$this->NitroBODBAlias.":" . $PQuery . "/SELECTED=" . $Content['Forward'] . "/STYLE=width: 250px;",
"MenuData[" . $LangCode . "][" . $Ver . "][Description]" => "TEXTAREA/LABEL=" . Language('Description') . "/VALUE=" . $Content['Description'] . "/STYLE=width: 350px;/ROWS=10");
$LanguageVersionTab->AddOptionsFromArray($Widgets);
/* No removing of versions in this version of Nitro
$DeleteBTN = urlencode("<input type='button' onclick=\"ModuleXMLRequest('Version', GetXMLURL('EditPageForm_" . $this->GetSetting('MenuID') . "') + '&Ver=" . $Ver . "&Lang=" . $LangCode . "&MenuID=" . $MenuID . "&RemoveVersion=1'); return false;\" value='" . Language('Delete Version') . "' />");
if ($LangCode == "Default" && $Ver > 1) {
$LanguageVersionTab->AddOptionString("DeleteBTN", "HTML/LABLE= /VALUE=" . $DeleteBTN);
} else if ($LangCode != "Default" && $Ver == count($PageData[$LangCode])) {
$LanguageVersionTab->AddOptionString("DeleteBTN", "HTML/LABLE= /VALUE=" . $DeleteBTN);
}
*/
}
/**
* addVersion function
*
* @return mixed Output of the EditMenu function.
*/
function addVersion()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$WidgetTemplate = new NitroTemplate('file:' . NITRO_PATH . "Defaults/Templates/BackOffice/widget.tpl");
$MenuID = $this->GetSetting('MenuID');
$LangCode = $this->GetSetting('Lang');
$LanguageTab = new FormTab("Language_" . $MenuID);
$tabJscript = '';
// Get MenuData from POST and add new empty version
$MenuData = $this->GetSetting('MenuData');
$NewVersion = count($MenuData[$LangCode]) + 1;
$MenuData[$LangCode][$NewVersion] = Array('MenuDataID' => 'NEW-'.$MenuID.'-'.$LangCode.'-'.$NewVersion);
$this->EditLanguageTab($LanguageTab, $tabJscript, $MenuID, $LangCode, $MenuData);
// There is only 1 widget on this tab, the version tab widget !
$LanguageTabRV = $LanguageTab->Options[$LangCode][0]->Draw($WidgetTemplate);
DebugCloseGroup(DEBUG_MOD_OK);
return array('JSCRIPT:()' => $tabJscript, 'Language_' . $MenuID . '_TAB_' . $LangCode => $LanguageTabRV['Controls']);
}
/**
* RemoveVersion function
*/
function RemoveVersion($MenuID, $Version, $Lang)
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$Transaction = new Transaction($this->DB, $this->Sess->UserID, TRUE);
$Transaction->addData('MenuData',
Array("MenuID" => (int)$MenuID,
"Version" => (int)$Version,
"Language" => ($Lang == "Default" ? "" : $Lang)),
Array("MenuID" => (int)$MenuID,
"Version" => (int)$Version,
"Language" => ($Lang == "Default" ? "" : $Lang)),
"DELETE");
$RV = ($Transaction->Commit() !== FALSE) ? TRUE : FALSE;
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* SaveVersions function
*
* @param int $MenuID The current MenuID
* @param array $Langs Array with the data to save.
* @return boolean (TRUE/FALSE)
*/
function SaveVersions($MenuID, $Langs, $Add = FALSE)
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$Transaction = new Transaction($this->DB, $this->Sess->UserID, TRUE);
if (is_array($Langs)) {
foreach ($Langs AS $Lang => $Versions) {
if (is_array($Versions)) {
foreach ($Versions AS $Version => $Data) {
if (is_array($Data)) {
$Data['MenuID'] = (int)$MenuID;
$Data['Language'] = ($Lang == "Default") ? "" : $Lang;
$Data['Version'] = (int)$Version;
if ($Data['VisibleFrom'] == "") $Data['VisibleFrom'] = NULL;
if ($Data['VisibleTill'] == "") $Data['VisibleTill'] = NULL;
if ($Add !== FALSE) {
if ($Data['Title'] != "" && ($Data['PageID'] != "" || $Data['PageID'] != 0)) {
$Transaction->addData('MenuData', $Data);
}
} else {
$Transaction->addData('MenuData', $Data);
}
}
}
}
}
}
$RV = ($Transaction->Commit() !== FALSE) ? TRUE : FALSE;
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* SaveMenu function
*/
function SaveMenu()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$MenuID = (int)$this->GetSetting('MenuID');
if (!strlen($this->GetSetting('Name'))) {
$RV = Array("ErrorDiv_" . $MenuID => $this->PrePareMSG(Array("Error", "Please fill in a Name.", TRUE), $MenuID));
} else {
$RV = $this->_SaveMenuInfo();
}
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* _SaveMenuInfo function (private)
**/
function _SaveMenuInfo()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
if (!$this->GetSetting('IDString') || ($this->GetSetting('IDString') && $this->GetSetting('IDString') == "")) {
$IDString = NitroCreateRandomString(10);
while ($this->DB->getOne("SELECT MenuID FROM `Menu` WHERE IDString LIKE " . NitroPrepareDB($IDString))) $IDString = NitroCreateRandomString(10);
} else {
$IDString = $this->GetSetting('IDString');
}
$Transaction = new Transaction($this->DB, $this->Sess->UserID, TRUE);
$ID = $Transaction->addData('Menu',
Array('Name' => $this->GetSetting('Name'),
'IDString' => $IDString,
'ParentID' => (int)$this->GetSetting('ParentID'),
'MenuID' => (int)$this->GetSetting('MenuID')));
$Commit = $Transaction->Commit();
if ($this->GetSetting('AddMenu')) {
$newObjectID = (int)$this->DB->getOne("SELECT
MenuID
FROM
Menu
ORDER
BY
MenuID
DESC
LIMIT
1");
} else {
$newObjectID = (int)$this->GetSetting('MenuID');
}
$ResultID = $newObjectID;
// Save the VersionSettings
$this->SaveVersions($ResultID, $this->GetSetting('MenuData'), ($this->GetSetting('AddMenu') ? TRUE : FALSE));
if ($Commit !== FALSE) {
$RV = Array("NoError", Language('Menu Saved'), TRUE);
} else {
$RV = Array("Error", Language('Menu could not be Saved'));
}
DebugCloseGroup(DEBUG_MOD_OK);
if ($this->GetSetting('AddMenu')) {
return Array("JSCRIPT:()" => ($this->GetSetting('CloseTab') ? "" : "ModuleXMLRequest('EditMenu', '&MenuID=" . $ResultID . "'); " ) . "DeletePageTab('0', true); window.parent.Menu.location.reload(true);", "UserField" => $this->ShowMenuList());
} else {
return Array("UserField" => $this->ShowMenuList(), (!$this->GetSetting('CloseTab') ? "ErrorDiv_" . $ResultID : "") => $this->PrePareMSG($RV, $ResultID), "JSCRIPT:()" => ($this->GetSetting('CloseTab') ? "DeletePageTab('" . $ResultID . "', true);" : "UpdatePageTab('" . $ResultID . "', 'DisplayName', '" . $this->GetSetting('Name') . "');") . " window.parent.Menu.location.reload(true);");
}
}
/**
* Draw function
*/
function Draw()
{
DebugGroup(__CLASS__, __FUNCTION__, "NitroBO->SubModule->" . $this->ModuleName . "->" . __FUNCTION__, __FILE__, __LINE__, DEBUG_MOD_OK);
$RV = $this->CreateTabInterface(Language('Menu Management'), $this->ShowMenuList(TRUE));
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* ShowMenuList function
*/
function ShowMenuList($inDiv = FALSE)
{
DebugGroup(__CLASS__, __FUNCTION__, 'ShowUserList function', __FILE__, __LINE__, DEBUG_MOD_OK);
$addimg = "<img src=\"./GetObject.php?NitroDefault=Images/Add.gif\" width=\"16\" height=\"16\" alt\"Add\" border=\"0\" />";
$this->editimg = "<img src=\"./GetObject.php?NitroDefault=Images/Edit.gif\" width=\"16\" height=\"16\" alt\"Edit\" border=\"0\" />";
$this->deleteimg = "<img src=\"./GetObject.php?NitroDefault=Images/Delete.gif\" width=\"16\" height=\"16\" alt\"Delete\" border=\"0\" />";
$this->tree_img = "<img src=\"./GetObject.php?NitroDefault=Images/BackOffice/Tree/tree_bottom.gif\" width=\"19\" height=\"22\" alt\"Delete\" border=\"0\" style=\"position:relative; top:4px;\" />";
$this->treeback_img = "<img src=\"./GetObject.php?NitroDefault=Images/BackOffice/Tree/tree_back.gif\" width=\"30\" height=\"22\" alt\"Delete\" border=\"0\" />";
$Start = Array(TRUE, (strlen($this->GetSetting('Start')) && $this->GetSetting('Start') !== 0 ? $this->GetSetting('Start') : 0));
$Filter = Array(TRUE, (strlen($this->GetSetting('ModFilter')) && $this->GetSetting('ModFilter') !== 0 ? $this->GetSetting('ModFilter') : FALSE));
$List = new Listing2("", "Menu_" . $this->GetSetting('P'), ($inDiv !== FALSE ? "UserField" : FALSE), $Start, $Filter, "Menu_");
$List->EnableRowHighlighting = TRUE;
$List->AddListAction($addimg, "#", "ModuleXMLRequest('EditMenu', '&AddMenu=1&MenuID=AddMenu'); return false;", "", Language('Add Menu'));
$List->AddColumn(Language('Name'), "Name");
$List-> SetColumnStyles('padding:0; width:600px;',"Name");
$List->AddColumn(Language('Sort order'), "Sortorder");
$List->AddColumn(Language('IDString'), "IDString");
$List->AddColumn(Language('Languages'), "Languages");
$List->AddAction("Edit", " ");
$List->AddAction("Delete", " ");
$List->hideFilter[] = "Sortorder";
$List->hideFilter[] = "IDString";
$List->hideFilter[] = "Languages";
$List->usePages = FALSE;
$Query = "SELECT
SQL_CALC_FOUND_ROWS
M.MenuID,
M.ParentID,
M.Name,
M.IDString,
M.SortOrder,
MD.Language
FROM `Menu` AS M
LEFT JOIN `MenuData` AS MD
ON M.MenuID = MD.MenuID
" . ($List->Filter['Name'] ? "WHERE " : "") . "
" . ($List->Filter['Name'] ? " M.Name LIKE " . NitroPrepareDB("%" . $List->Filter['Name'] . "%") . " " : "") . "
ORDER BY
M.ParentID,
M.SortOrder,
MD.Language
" . ($List->usePages !== FALSE ? "LIMIT " . (int)$List->Start . ", " . (int)$List->maxPerPage : "");
$Result = $this->DB->query($Query);
//$List->allPages = $this->DB->getOne("SELECT FOUND_ROWS()");
// $List->onChange = "MenuList";
$MenuItems = Array();
$Languages = Array();
if ($Result->numRows()) {
while ($Data = $Result->fetchArray()) {
$MenuItems[$Data['MenuID']] = $Data;
if (isset($Data['Language'])) {
$Lang = (strlen($Data['Language']) ? $Data['Language'] : 'Default');
$Languages[$Data['MenuID']][$Lang] = $Lang;
}
}
foreach ($MenuItems AS $MenuID => $MenuData) {
if (!$MenuData['ParentID']) {
$this->DrawRow($List, $MenuItems, $MenuID);
}
}
}
$Result->free();
$List-> SetTemplate("file:" . NITRO_PATH . "Defaults/Templates/BackOffice/Listing.tpl");
$RV = $List->Draw();
DebugCloseGroup(DEBUG_MOD_OK);
return $RV;
}
/**
* function DrawRow
* Draws menu items in hierarchical order
*
*/
function DrawRow(&$List, $MenuItems, $MenuID, $Depth = 0)
{
// draw this row (parent)
$ListRow = new ListingRow2();
$ListRow->AddData("Name", "<table cellpadding=0 cellspacing=0><tr><td nowrap>". str_repeat($this->treeback_img, $Depth).$this->tree_img.' '.$MenuItems[$MenuID]["Name"] ."</td></tr></table>");
$ListRow->AddData("Sortorder", $MenuItems[$MenuID]["SortOrder"] . "</span>");
$ListRow->AddData("IDString", $MenuItems[$MenuID]["IDString"]);
$ListRow->AddData("Languages", (is_array($Languages[$Data['MenuID']]) && count($Languages[$Data['MenuID']]) ? implode(', ', $Languages[$Data['MenuID']]) : Language('None')));
$ListRow->SetAction("Edit", $this->editimg, "#", "ModuleXMLRequest('EditMenu', '&MenuID=" . $MenuItems[$MenuID]["MenuID"] . "'); return false;", FALSE, TRUE, Language('Edit') . space() . $MenuItems[$MenuID]["Name"]);
$ListRow->SetAction("Delete", $this->deleteimg, "#", "if(confirm('Item is going to be removed, are you sure?')) ModuleXMLRequest('DeleteMenu', '&MenuID=" . $MenuItems[$MenuID]["MenuID"] . "'); return false;", FALSE, TRUE, Language('Delete') . space() . $MenuItems[$MenuID]["Name"]);
$List->AddListRow($ListRow);
unset($ListRow);
// echo str_repeat(' ', $Depth).$MenuID." - Depth: ".$Depth." - ParentID: ".$MenuItems[$MenuID]['ParentID']."<BR>";
// $Depth defines how deep you are in the structure, use it to count spaces/tabs needed to display properly
// draw children
foreach ($MenuItems AS $Child_MenuID => $Child_MenuData) {
if ((int)$Child_MenuData['ParentID'] === (int)$MenuID) {
$this->DrawRow($List, $MenuItems, $Child_MenuID, ($Depth + 1));
}
}
}
}
?>