Your IP : 216.73.216.55


Current Path : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/controllers/
Upload File :
Current File : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/controllers/template.php

<?php

/**
 * @name		Template Creator CK
 * @copyright	Copyright (C) since 2011. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 * @author		Cedric Keiflin - http://www.template-creator.com - http://www.joomlack.fr
 */
// No direct access
defined('TCK_LOADED') or die;
require_once TEMPLATECREATORCK_PATH . '/controller.php';

/**
 * Template controller class.
 */
class TemplateckControllerTemplate extends TemplateckController {

	/**
	 * Method to check out an item for editing and redirect to the edit form.
	 *
	 * @since	1.6
	 */
	public function edit() {
		$app = JFactory::getApplication();

		// Get the previous edit id (if any) and the current edit id.
		$previousId = (int) $app->getUserState('com_templateck.edit.template.id');
		
		$editIds = $app->input->get('cid', null, 'array');
		if (count($editIds)) {
			$editId = (int) $editIds[0];
		} else {
			$editId = (int) $app->input->get('id', null, 'int');
		}

		// Set the user id for the user to edit in the session.
		$app->setUserState('com_templateck.edit.template.id', $editId);
		// Get the model.
		$model = $this->getModel('Template', 'TemplateckModel');

		// Check out the item
		if ($editId) {
			$model->checkout($editId);
		}

		// Check in the previous user.
		if ($previousId) {
			$model->checkin($previousId);
		}

		$template = $app->input->get('template', '') ? '&template=' . $app->input->get('template', '') : '';

		// Redirect to the edit screen.
		TemplateckHelper::redirect(TEMPLATECREATORCK_ADMIN_URL . '&view=template&layout=edit&id=' . $editId);
//		$this->setRedirect('index.php?option=com_templateck&view=template&layout=edit&id=' . $editId, false);
	}

	/**
	 * Method to save a user's profile data.
	 *
	 * @return	void
	 * @since	1.6
	 */
	public function save() {
		// Check for request forgeries.
		TemplateckHelper::checkToken();

		// Initialise variables.
		$app = JFactory::getApplication();
		$model = $this->getModel('Template', 'TemplateckModel');

		// Get the user data.
		$data = $this->input->getArray($_POST);

		// Validate the posted data.
		$form = $model->getForm();
		if (!$form) {
			JError::raiseError(500, $model->getError());
			return false;
		}

		// Validate the posted data.
//		$data = $model->validate($form, $data);

		// Check for errors.
		if ($data === false) {
			// Get the validation messages.
			$errors = $model->getErrors();

			// Push up to three validation messages out to the user.
			for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) {
				if ($errors[$i] instanceof Exception) {
					$app->enqueueMessage($errors[$i]->getMessage(), 'warning');
				} else {
					$app->enqueueMessage($errors[$i], 'warning');
				}
			}

			// Save the data in the session.
			$app->setUserState('com_templateck.edit.template.data', $data);

			// Redirect back to the edit screen.
			$id = (int) $app->getUserState('com_templateck.edit.template.id');
			$this->setRedirect(TEMPLATECREATORCK_ADMIN_URL + '&view=template&layout=edit&id=' . $id, false);
			return false;
		}

		// Attempt to save the data.
		$return = $model->save($data);

		// Check for errors.
		if ($return === false) {
			// Save the data in the session.
			$app->setUserState('com_templateck.edit.template.data', $data);

			// Redirect back to the edit screen.
			$id = (int) $app->getUserState('com_templateck.edit.template.id');
			$app->enqueueMessage(TCK_Text::sprintf('Save failed', $model->getError()), 'warning');
			$this->setRedirect(TEMPLATECREATORCK_ADMIN_URL + '&view=template&task=template.edit&layout=edit&id=' . $id, false);
			return false;
		}


		// Check in the profile.
		if ($return) {
			$model->checkin($return);
		}

		// Clear the profile id from the session.
		$app->setUserState('com_templateck.edit.template.id', null);

		// Redirect to the list screen.
		$app->enqueueMessage(TCK_Text::_('CK_ITEM_SAVED_SUCCESS'));
		$this->setRedirect('index.php?option=com_templateck&view=template&task=template.edit&layout=edit&id=' . $return, false);

		// Flush the data from the session.
		$app->setUserState('com_templateck.edit.template.data', null);
	}

	function cancel() {
		//Redirect back to list
		$this->setRedirect('index.php?option=com_templateck&view=templates', false);
		// }
	}

	/**
	* Write the export file
	*/
	public function export() {
		$model = $this->getModel('Template', 'TemplateckModel');
		$model->export();
	}

	function download() {
		$filepath = $this->input->get('filepath', '', 'string');
		TemplateckHelper::pushFileForDownload($filepath);
	}
	/**
	 * import a theme from a zip file
	 * @return void
	 */
	function import() {
		$model = $this->getModel('Template', 'TemplateckModel');
		if (!$model->import()) {
			$msg = TCK_Text::_('CK_INSTALL_GABARIT_ERROR');
			$link = TEMPLATECREATORCK_ADMIN_GENERAL_URL;
			$type = 'error';
		} else {
			$msg = TCK_Text::_('CK_GABARIT_INSTALLED');
			$link = TEMPLATECREATORCK_ADMIN_GENERAL_URL;
			$type = 'message';
		}

		$this->setRedirect($link, $msg, $type);
	}

	/**
	 * import a theme from a zip file
	 * @return void
	 */
	function ajaxImport() {
		TemplateckHelper::checkAjaxToken();
		$input = new TCK_Input();
		$model = $this->getModel('Template', 'TemplateckModel');
		$file = $input->get('gabariturl', null, 'url');

		$id = $model->ajaxInstallGabarit($file);

		echo '{"status" : "' . ($id ? '1' : '0') . '", "id" : "' . $id . '"}';
		exit;
	}

	/**
	 * import a theme from a zip file
	 * @return void
	 */
	function importData() {
		$model = $this->getModel('Template', 'TemplateckModel');
		$this->modules = $model->importData();
		if (! $this->modules) {
			die ('erreur du model');
			// $msg = TCK_Text::_('CK_INSTALL_GABARIT_ERROR');
			// $link = TEMPLATECREATORCK_ADMIN_GENERAL_URL;
			// $type = 'error';
		} else {
			JToolBarHelper::title('Template Creator CK - ' . TCK_Text::_('CK_IMPORT_DATA'));
			require TEMPLATECREATORCK_PATH . '/views/quickdata/tmpl/default.php';
			// die (' model ok');
			// $msg = TCK_Text::_('CK_GABARIT_INSTALLED');
			// $link = TEMPLATECREATORCK_ADMIN_GENERAL_URL;
			// $type = 'message';
	}

		// $this->setRedirect($link, $msg, $type);
	}

	/**
	 * import a theme from a zip file
	 * @return void
	 */
	function importQuickData() {
		$modules= $this->input->get('modules', '', 'array');
		$app = JFactory::getApplication();
		foreach ($modules as $module) {
			if (isset($module['selectedimport']) && $module['selectedimport'] == 'on') {
				$result = $this->importModule($module['settings']);
			}
			$app->enqueueMessage($result['msg'], $result['type']);
		}
		
		$this->setRedirect(TEMPLATECREATORCK_ADMIN_GENERAL_URL . '&task=quickdata.message&tmpl=component');
	}

	function importModule($module) {
		$module = unserialize($module);
		$model = $this->getModel('Quickdata', 'TemplateckModel');
		$moduleid = $model->importModule($module);
		if (! $moduleid) {
			$msg = TCK_Text::_('CK_INSTALL_MODULE_ERROR') . ' : ' . $module->module . ' - ' . $module->position;
			$link = TEMPLATECREATORCK_ADMIN_GENERAL_URL;
			$type = 'error';
		} else {
			$msg = TCK_Text::_('CK_MODULE_INSTALLED') . ' - ID : ' . $moduleid;
			$link = TEMPLATECREATORCK_ADMIN_GENERAL_URL;
			$type = 'message';
		}
		return array('msg' => $msg, 'link' => $link, 'type' => $type);
	}
}