<?php
/*
 * This file is part of the Easy-CMS project.
 * Easy-CMS is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * Easy-CMS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * @package    Core
 * @subpackage Forms
 */

/**
 */
include_once('classes/core/Site.class.php');
include_once('classes/core/forms/EditionForm.class.php');
include_once('classes/core/forms/MenuForm.class.php');

include_once('classes/core/menus/Menu.class.php');
include_once('classes/core/menus/MenusManager.class.php');
include_once('classes/core/forms/ACLForm.class.php');

/**
 * MenuEditionForm : edition form for Menus
 *
 * @access     public
 * @author	   Cedric Francoys <cedric.francoys@easy-cms.org>
 * @version	   MenuEditionForm.class, Sun Dec 26 16:42:13 CET 2004
 * @package	   Core
 * @subpackage Forms
 */

class MenuEditionForm extends EditionForm {
	/**
	 * Class constructor
	 *
	 * @access   public
 	 * @param    string    The mode in which the form is to be displayed.
 	 * @return   void
	 */
	function MenuEditionForm(&$menu, &$menusManager) {
		parent::EditionForm($menu, $menusManager);
	}

	function populateUIContainer(&$guiContainer, $currLangId, $action) {
		if($action == ASK_DELETE_MENU) {
			$summary = "";
			$summary .= "<b>".LANG_MENU_IDENTIFIER_STATIC." :</b> ".$this->object->getMenuId();
			$summary .= "<br /><b>".LANG_MENU_NAME_STATIC." :</b> ".$this->object->getMenuName($currLangId);
			$txtLang = &new egStatic("sta_1", LANG_MENU_DELETION_MESSAGE.LANG_COLON."<br /><br />".$summary."<br /><br />".LANG_MENU_DELETION_CONFIRM, 20, 20, 300, 0);
			$guiContainer->addObject($txtLang);
		}
		else {
			$valuesTable = &$this->object->getMenuValuesTable();
			$langsArray = $this->objectManager->getLangsArray();
      $menuTemplates = $this->objectManager->getMenuTemplates();

			$defaultTemplate = '';

	    // look for the first defined language
			foreach ($langsArray as $langId => $langName) {
	      if(isset($valuesTable[$langId])) {
	        $referenceLangId = $langId;
	        break;
	      }
	    }

			$langList = &new egDropDownPropertyList("ddl_lang_1", "Language", 400, 10, 80);
			$txtLang = &new egStatic("sta_1", LANG_LANGUAGE_LISTBOX.' :', 330, 10, 80, 0, true);

      $show_edition_containers = true;

			if(count($langsArray) > 1) {
				$guiContainer->addObject($langList);
				$guiContainer->addObject($txtLang);
        $show_edition_containers = false;
			}


	 		$previousTop = 30;

			$idText = &new egStatic("st_value_id", LANG_MENU_IDENTIFIER_STATIC.' :', 5, $previousTop, 80, 0, true);
			$idValue = &new egStatic("obj_item_id", $valuesTable['id'], 90, $previousTop, 80, 0);
	 		$previousTop += 30;

			foreach ($langsArray as $langId => $langName) {
	      $editionContainer = &new egContainer('edt_ctn_'.$langId, 5, $previousTop, 500, 30, $show_edition_containers);
	      $guiContainer->addContainer($editionContainer);
				$langList->addListItem(new egPropertyPage('lti_'.$langId, ucfirst($langName), $editionContainer->getContainerName()));

	      if($langId == $currLangId) {
	        $langList->setSelectedItemByLabel(ucfirst($langName));
	      }

	      // create same fields for this lang than in the reference language
	      if(!isset($valuesTable[$langId])) {
	        if(!isset($referenceLangId)) {
						$valuesTable[$langId]['name'] = '';
	        }
					else {
		        foreach ($valuesTable[$referenceLangId] as $field => $value) {
	  	        $valuesTable[$langId][$field] = '';
	    	    }
					}
	      }

			  $nameText = &new egStatic("st_value_name_".$langId, LANG_MENU_NAME_STATIC.' :', 0, 0, 80, 0, true);
				$nameValue = &new egEdit("obj_item_name_".$langId, $valuesTable[$langId]['name'], 85, 0, 390, 18, $langId.'[name]');

				$editionContainer->addObject($nameText);
				$editionContainer->addObject($nameValue);
	    }
   		$previousTop += 30;

			$typeText = &new egStatic("st_value_type", LANG_MENU_CONTAINS_STATIC.' :', 5, $previousTop, 80, 0, true);
      $typeValue = &new egStatic("st_item_type", "pages", 90, $previousTop, 80, 0);
      $templateText = &new egStatic("st_value_template", LANG_MENU_TEMPLATE_STATIC.' :', 265, $previousTop, 80, 0, true);
    	$templateValue = &new egDropDownListBox("obj_item_template", 350, $previousTop, 130, null, 'template_id');
      foreach($menuTemplates as $id => $templateName) {
        $templateValue->addListItem(new egListItem("lti_templates_".$id, str_replace('_', ' ', $templateName), null, $id));
      }
      $templateValue->setSelectedItemByValue($valuesTable['template_id']);
		  $guiContainer->addObject($templateText);
		  $guiContainer->addObject($templateValue);

   		$previousTop += 30;

      $depthText = &new egStatic("st_value_depth", LANG_MENU_MAXLEVEL_STATIC.' :', 5, $previousTop, 80, 0, true);
			$depthValue = &new egEdit("obj_item_depth_".$langId, $valuesTable['max_level'], 90, $previousTop, 30, 18, 'max_level');

      $depthComment = &new egStatic("st_comment_depth", "<i>".LANG_MENU_MAXLEVEL_COMMENT_STATIC."</i>", 90, $previousTop+18, 200, 0);
   		$previousTop += 50;

      $showText = &new egStatic("st_value_show", LANG_CONTAINER_SHOW_STATIC.' :', 5, $previousTop, 80, 0, true);
  		$showValue = &new egEdit("obj_item_show", $valuesTable['count_shown'], 90, $previousTop, 33, 18, 'count_shown');
      $showText2 = &new egStatic("st_value_show2", LANG_CONTAINER_ITEMS_STATIC, 133, $previousTop, 200, 0, true);

      $showComment = &new egStatic("st_comment_show", "<i>".LANG_CONTAINER_SHOW_COMMENT_STATIC."</i>", 90, $previousTop+18, 350, 0);
   		$previousTop += 50;


	    if($this->object->getMenuId() != 0){

	      $orderText = &new egStatic("st_value_order", LANG_MENU_ORDER_STATIC.' :', 5, $previousTop, 80, 0, true);
	      $orderManual = &new egRadiobutton("obj_item_order_manual", LANG_CONTAINER_MANUALSORT_STATIC, 90, $previousTop, 100, null, "sorting_type", SORTING_BY_LIST, ($valuesTable['sorting_type'] == SORTING_BY_LIST));
	      $orderAuto = &new egRadiobutton("obj_item_order_auto",LANG_CONTAINER_AUTOSORT_STATIC, 220, $previousTop, 100, null, "sorting_type", SORTING_BY_FIELD, ($valuesTable['sorting_type'] == SORTING_BY_FIELD));
	   		$previousTop += 40;

	      $sortByText = &new egStatic("st_value_sort_by", LANG_MENU_SORT_STATIC.' :', 5, $previousTop, 80, 0, true);
	    	$sortByValue = &new egDropDownListBox("obj_item_sort_field", 90, $previousTop, 100, null, 'sort_field');

        $sortByValue->addListItem(new egListItem("lti_field_1", LANG_PAGE_IDENTIFIER_STATIC, null, 'id'));
        $sortByValue->addListItem(new egListItem("lti_field_2", LANG_PAGE_NAME_STATIC, null, 'name'));
        $sortByValue->addListItem(new egListItem("lti_field_3", LANG_PAGE_TITLE_STATIC, null, 'title'));
        $sortByValue->addListItem(new egListItem("lti_field_4", LANG_PAGE_ALIAS_STATIC, null, 'alias'));

	      $sortByValue->setSelectedItemByValue($valuesTable['sort_field']);

	      $sortOnText = &new egStatic("st_value_sort_on", LANG_MENU_ON_STATIC, 210, $previousTop, 80, 0, true);

	      $sortOrderContainer = &new egContainer('edt_sort_order_ctn', 250, $previousTop-10, 150, 60, true);
	      $sortOnAsc  = &new egRadiobutton("obj_item_sort_on_asc", LANG_MENU_ASCENDING_STATIC, 0, 0, 100, null, "sort_order", SORT_ASCENDING, ($valuesTable['sort_order'] == SORT_ASCENDING));
	      $sortOnDesc = &new egRadiobutton("obj_item_sort_on_desc", LANG_MENU_DESCENDING_STATIC, 0, 25, 100, null, "sort_order", SORT_DESCENDING, ($valuesTable['sort_order'] == SORT_DESCENDING));
	      $sortOrderContainer->addObject($sortOnAsc);
	      $sortOrderContainer->addObject($sortOnDesc);
	    }

			$guiContainer->addObject($idText);
			$guiContainer->addObject($idValue);

			$guiContainer->addObject($typeText);
			$guiContainer->addObject($typeValue);

			$guiContainer->addObject($orderText);
			$guiContainer->addObject($orderManual);
			$guiContainer->addObject($orderAuto);

			$guiContainer->addObject($depthText);
			$guiContainer->addObject($depthValue);
			$guiContainer->addObject($depthComment);

			$guiContainer->addObject($showText);
			$guiContainer->addObject($showValue);
			$guiContainer->addObject($showText2);
			$guiContainer->addObject($showComment);

			$guiContainer->addObject($sortByText);
		  $guiContainer->addObject($sortByValue);

			$guiContainer->addObject($sortOnText);
			$guiContainer->addObject($sortOrderContainer);

			$scriptLine = "
function chooseTemplate(id) {
  edit_hidden_control_template_id.setValue(id);
}
";

		  return $scriptLine;
		}
	}
} 

?>