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

/**
 * Version Edition Form
 *
 * Allows granted user to modify existing permissions and
 * to add or remove groups and users
 *
 * @author     vinadelmar <vinadelmar@users.sourceforge.net>
 * @since      2006-04-25
 * @version    1.0.0
 * @package    Core
 * @subpackage Forms
 */
class VersionEditionForm extends EditionForm {

	var $content;
	var $contentsManager;

	/**
	 * Constructor
	 *
	 * @access public
	 * @param object $acl
	 * @param string $mode
	 */
	function VersionEditionForm(&$version, &$versionManager, &$content, &$contentsManager) {
		parent::EditionForm($version, $versionManager);
		$this->content = &$content;
		$this->contentsManager = &$contentsManager;
	}

	function populateUIContainer(&$guiContainer, $currLangId, $action) {
    if($action == ASK_MODIF_CONTENT) {
      $contentId = $this->content->getContentId();
  		$contentType = $this->content->getContentTypeName();

  		$txtList = &new egStatic("st_versions_1", LANG_VERSIONS_AVAILABLE_STATIC." : ", 10, 5, 150, 0, true);
  		$guiContainer->addObject($txtList);

  		$versionsList = $this->objectManager->getVersionsList($contentId, $contentType);

      if(count($versionsList) == 0) {
        $txtNotFound = &new egStatic("st_versions_2", '(No version found)', 10, 35, 150, 0, false);
        $guiContainer->addObject($txtNotFound);
      }
      else {
        $vPos = 35;
        $i = 0;
     		foreach($versionsList as $version) {
     				$deleted  = '';
            if(isset($_GET['deleted'])) {
              $deleted = '&deleted=true';
            }
            $verLink = "openWindow(\'index.php?display=edit_version&mode=ask_restore_version&content_id=".$contentId."&type_name=".$contentType."&version_id=".$version['version_id']."$deleted\', 540, 600, 50, 50)";

            $link = &new egLink("version_link_".$i, $version['version_date']." by ".$version['user_login'], 10, $vPos, 200, 18, $verLink, 'interface/icons/icon_version.png');
            $guiContainer->addObject($link);

            $vPos += 25;
            ++$i;
        }
      }

			return '';
    }
    else if($action == ASK_RESTORE_VERSION) {
      // add script for warning and confirmation
      $contentEditionForm = &new ContentEditionForm($this->content, $this->contentsManager);
			$contentEditionForm->populateUIContainer($guiContainer, $currLangId, $action);

			$script = "
      function validationFunction() {
      	if(window.confirm('".LANG_VERSIONS_RESTORE_WARNING." ".LANG_CONFIRM."')) {
          return true;
      	}
      	return false;
      }
      ";
      return $script;
    }
	}

}
?>