<?php

/**
 * @file pages/call4paper/Call4PaperHandler.inc.php
 *
 * Copyright (c) 2014-2021 Simon Fraser University
 * Copyright (c) 2003-2021 John Willinsky
 * Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
 *
 * @class Call4PaperHandler
 * @ingroup pages_call4paper
 *
 * @brief Handle requests for call for papers functions.
 */

import('classes.handler.Handler');

class Call4PaperHandler extends Handler {

	/**
	 * Constructor
	 */
	function __construct() {
		parent::__construct();
	}

	/**
	 * Display the main call for papers page
	 * @param $args array
	 * @param $request PKPRequest
	 */
	function c4p($args, $request) {
		$this->setupTemplate($request);
		$templateMgr = TemplateManager::getManager($request);
		
		// Obtener información del journal
		$journal = $request->getJournal();
		if (!$journal) {
			$request->redirect(null, 'index');
		}

		// Asignar variables al template
		$templateMgr->assign(array(
			'journalTitle' => $journal->getLocalizedName(),
			'journalPath' => $journal->getPath(),
			'currentDate' => date('Y-m-d'),
			'pageTitle' => 'Call for Papers'
		));

		// Mostrar el template personalizado
		$templateMgr->display('frontend/pages/call-for-papers.tpl');
	}

	/**
	 * Display call for papers index (redirects to c4p)
	 * @param $args array
	 * @param $request PKPRequest
	 */
	function index($args, $request) {
		$request->redirect(null, 'call4paper', 'c4p');
	}

	/**
	 * Display submission guidelines
	 * @param $args array
	 * @param $request PKPRequest
	 */
	function guidelines($args, $request) {
		$this->setupTemplate($request);
		$templateMgr = TemplateManager::getManager($request);
		
		$journal = $request->getJournal();
		if (!$journal) {
			$request->redirect(null, 'index');
		}

		$templateMgr->assign(array(
			'journalTitle' => $journal->getLocalizedName(),
			'journalPath' => $journal->getPath(),
			'pageTitle' => 'Submission Guidelines'
		));

		$templateMgr->display('frontend/pages/submissionGuidelines.tpl');
	}

	/**
	 * Display important dates
	 * @param $args array
	 * @param $request PKPRequest
	 */
	function dates($args, $request) {
		$this->setupTemplate($request);
		$templateMgr = TemplateManager::getManager($request);
		
		$journal = $request->getJournal();
		if (!$journal) {
			$request->redirect(null, 'index');
		}

		// Puedes agregar fechas importantes desde la configuración del journal
		$importantDates = array(
			'submissionDeadline' => $journal->getLocalizedSetting('submissionDeadline'),
			'reviewDeadline' => $journal->getLocalizedSetting('reviewDeadline'),
			'finalDecision' => $journal->getLocalizedSetting('finalDecisionDate')
		);

		$templateMgr->assign(array(
			'journalTitle' => $journal->getLocalizedName(),
			'journalPath' => $journal->getPath(),
			'importantDates' => $importantDates,
			'pageTitle' => 'Important Dates'
		));

		$templateMgr->display('frontend/pages/importantDates.tpl');
	}

	/**
	 * Display topics and scope
	 * @param $args array
	 * @param $request PKPRequest
	 */
	function topics($args, $request) {
		$this->setupTemplate($request);
		$templateMgr = TemplateManager::getManager($request);
		
		$journal = $request->getJournal();
		if (!$journal) {
			$request->redirect(null, 'index');
		}

		$templateMgr->assign(array(
			'journalTitle' => $journal->getLocalizedName(),
			'journalPath' => $journal->getPath(),
			'journalScope' => $journal->getLocalizedSetting('focusAndScope'),
			'pageTitle' => 'Topics and Scope'
		));

		$templateMgr->display('frontend/pages/topicsScope.tpl');
	}

	/**
	 * Setup common template variables.
	 * @param $request PKPRequest
	 */
	function setupTemplate($request = null) {
		parent::setupTemplate($request);
		
		// Cargar componentes de idioma necesarios
		AppLocale::requireComponents(
			LOCALE_COMPONENT_APP_COMMON,
			LOCALE_COMPONENT_APP_SUBMISSION,
			LOCALE_COMPONENT_PKP_SUBMISSION
		);

		// Configurar la barra de navegación
		$templateMgr = TemplateManager::getManager($request);
		$templateMgr->assign('pageHierarchy', array(
			array(
				'url' => $request->url(null, 'index'),
				'name' => 'navigation.home'
			),
			array(
				'url' => $request->url(null, 'call4paper', 'c4p'),
				'name' => 'Call for Papers'
			)
		));
	}

	/**
	 * Determine if the journal's setup has been sufficiently completed.
	 * @param $journal Object
	 * @return boolean True iff setup is incomplete
	 */
	function _checkIncompleteSetup($journal) {
		if($journal->getLocalizedAcronym() == '' || 
		   $journal->getData('contactEmail') == '' ||
		   $journal->getData('contactName') == '' || 
		   $journal->getLocalizedData('abbreviation') == '') {
			return true;
		} 
		return false;
	}
}

?>