<?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('config.inc.php');
include_once('classes/core/Site.class.php');
include_once('classes/core/forms/EditionForm.class.php');
include_once('classes/core/forms/PageForm.class.php');

include_once('classes/core/pages/Page.class.php');
include_once('classes/core/pages/PagesManager.class.php');

include_once('interface/egScript.class.php');
include_once('interface/egManager.class.php');
include_once('interface/egContainer.class.php');
include_once('interface/egMenuItem.class.php');
include_once('interface/egFrame.class.php');
include_once('interface/egToolTip.class.php');
include_once('interface/egRichText.class.php');
include_once('interface/egLink.class.php');
include_once('interface/egStatic.class.php');
include_once('interface/egEdit.class.php');
include_once('interface/egCheckBox.class.php');
include_once('interface/egRadioButton.class.php');
include_once('interface/egPressButton.class.php');
include_once('interface/egDropDownListBox.class.php');
include_once('interface/egDropDownPropertyList.class.php');
include_once('interface/egPropertyList.class.php');
include_once('interface/egPropertySheet.class.php');
include_once('interface/egPropertyPage.class.php');

/**
* PageEditionForm : edition form for Pages
*
* @access   public
* @author	Cedric Francoys <cedric.francoys@easy-cms.org>
* @version	PageEditionForm.class, Sun Dec 26 16:41:28 CET 2004
* @package	Forms
*/
class PageEditionForm extends EditionForm {
	/**
	 * Class constructor.
	 * 
	 * @access   public
 	 * @param    string    The mode in which the form is to be displayed.	
 	 * @return   void  
	 */	  
	function PageEditionForm(&$page, &$pagesManager) {
		parent::EditionForm($page, $pagesManager);
	}

	function populateUIContainer(&$guiContainer, $currLangId, $action, $error) {
		if($action == ASK_DELETE_PAGE) {
			if($error) {
				$txtLang = &new egStatic("sta_1", LANG_PAGE_DELETION_DENIED, 20, 20, 300, 0);
				$guiContainer->addObject($txtLang);
			}
			else {
				$summary = "";
				$summary .= "<b>".LANG_PAGE_IDENTIFIER_STATIC." :</b> ".$this->object->getPageId();
				$summary .= "<br /><b>".LANG_PAGE_NAME_STATIC." :</b> ".$this->object->getPageName($currLangId);
				$txtLang = &new egStatic("sta_1", LANG_PAGE_DELETION_MESSAGE.LANG_COLON."<br /><br />".$summary."<br /><br />".LANG_PAGE_DELETION_CONFIRM, 20, 20, 300, 0);
				$guiContainer->addObject($txtLang);
			}
		}
		else {
  		$valuesTable = &$this->object->getPageValuesTable();
  		$langsArray = $this->objectManager->getLangsArray();

      // 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.LANG_COLON, 330, 10, 80, 0, true);

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

  		$framesArray = $this->objectManager->getFramesArray();
  		$isPreSelectedItem = false;
  		$framesList = &new egDropDownListBox("ddl_frame_".$langId, 90, 45, 130, null, "frame_id");
  		foreach ($framesArray as $frameId => $frameName) {
  			$framesList->addListItem(new egListItem("ddli_".$frameId, $frameName, null, $frameId));
  			if($this->object->getPageFrameId() == $frameId) {
  				$framesList->setSelectedItemByValue($frameId);
  				$isPreSelectedItem = true;
  			}
      }
  		if(!$isPreSelectedItem) {
  				$framesList->setSelectedItemByIndex(0);
  		}

  		$frameText = &new egStatic("st_value_frame_".$langId, LANG_PAGE_TEMPLATE_STATIC.LANG_COLON, 5, 45, 80, 0, true);
  		$guiContainer->addObject($frameText);
  		$guiContainer->addObject($framesList);

 			$linkText = &new egStatic("st_value_link", LANG_PAGE_LINK_STATIC.LANG_COLON, 5, 420, 80, 0, true);
 			$linkValue = &new egEdit("obj_item_link", $valuesTable['link'], 90, 420, 305, 18, 'link');
			$linkItemButton = &new egPressbutton("obj_item_link_button", LANG_CHOOSE_BUTTON, 405, 418, 80, null, "openWindow(\'admin/select_page.php?parent_control_name=obj_item_link_value\',425,450,0,0);");

  		$guiContainer->addObject($linkText);
  		$guiContainer->addObject($linkValue);
  		$guiContainer->addObject($linkItemButton);

  		foreach ($langsArray as $langId => $langName) {
        $editionContainer = &new egContainer('edt_ctn_'.$langId, 0, 0, 500, 400, $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'] = '';
  					$valuesTable[$langId]['alias'] = '';
  					$valuesTable[$langId]['title'] = '';
  					$valuesTable[$langId]['description'] = '';
  					$valuesTable[$langId]['keywords'] = '';
          }
  				else {
  	        foreach ($valuesTable[$referenceLangId] as $field => $value) {
    	        $valuesTable[$langId][$field] = '';
      	    }
  				}
        }

    		$previousTop = 75;

  			$nameText = &new egStatic("st_value_name_".$langId, LANG_PAGE_NAME_STATIC.LANG_COLON, 5, $previousTop, 80, 0, true);
  			$nameValue = &new egEdit("obj_item_name_".$langId, $valuesTable[$langId]['name'], 90, $previousTop, 390, 18, $langId.'[name]');
        $previousTop += 25;

  			$aliasText = &new egStatic("st_value_alias_".$langId, LANG_PAGE_ALIAS_STATIC.LANG_COLON, 5, $previousTop, 80, 0, true);
  			$aliasValue = &new egEdit("obj_item_alias_".$langId, $valuesTable[$langId]['alias'], 90, $previousTop, 390, 18, $langId.'[alias]');
        $previousTop += 45;

  			$titleText = &new egStatic("st_value_title_".$langId, LANG_PAGE_TITLE_STATIC.LANG_COLON, 5, $previousTop, 80, 0, true);
  			$titleValue = &new egEdit("obj_item_title_".$langId, $valuesTable[$langId]['title'], 90, $previousTop, 390, 18, $langId.'[title]');
        $previousTop += 25;

  			$descriptionText = &new egStatic("st_value_description_".$langId, LANG_PAGE_DESCRIPTION_STATIC.LANG_COLON, 5, $previousTop, 80, 0, true);
  			$descriptionValue = &new egEdit("obj_item_description_".$langId, $valuesTable[$langId]['description'], 90, $previousTop, 390, 98, $langId.'[description]');
        $previousTop += 105;

  			$keywordsText = &new egStatic("st_value_keywords_".$langId, LANG_PAGE_KEYWORDS_STATIC.LANG_COLON, 5, $previousTop, 80, 0, true);
  			$keywordsValue = &new egEdit("obj_item_keywords_".$langId, $valuesTable[$langId]['keywords'], 90, $previousTop, 390, 98, $langId.'[keywords]');
        $previousTop += 135;

  			$editionContainer->addObject($nameText);
  			$editionContainer->addObject($nameValue);

  			$editionContainer->addObject($aliasText);
  			$editionContainer->addObject($aliasValue);

  			$editionContainer->addObject($titleText);
  			$editionContainer->addObject($titleValue);

  			$editionContainer->addObject($descriptionText);
  			$editionContainer->addObject($descriptionValue);

  			$editionContainer->addObject($keywordsText);
  			$editionContainer->addObject($keywordsValue);
      }
    }
  }
}
?>