| Current Path : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/views/templates/ |
| Current File : /home/g/i/t/giteleslfp/www/administrator/components/com_templateck/views/templates/view.html.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;
jimport('joomla.application.component.view');
jimport('joomla.filesystem.folder');
/**
* View class for a list of Templateck.
*/
class TemplateckViewTemplates extends JViewLegacy {
protected $items;
protected $pagination;
protected $state;
/**
* Display the view
*/
public function display($tpl = null) {
//$this->sqlFix = $this->get('SqlCheck');
$this->state = $this->get('State');
$this->items = $this->get('Items');
$this->pagination = $this->get('Pagination');
$this->checkDbIntegrity();
// Check for errors.
if (count($errors = $this->get('Errors'))) {
JError::raiseError(500, implode("\n", $errors));
return false;
}
$this->addToolbar();
// $this->sidebar = JHtmlSidebar::render();
parent::display($tpl);
}
/**
* Add the page title and toolbar.
*
* @since 1.6
*/
protected function addToolbar() {
// require_once JPATH_COMPONENT . '/helpers/templateck.php';
$state = $this->get('State');
$canDo = TemplateckHelper::getActions($state->get('filter.category_id'));
// Get the toolbar object instance
$bar = JToolBar::getInstance('toolbar');
JToolBarHelper::title(TCK_Text::_('COM_TEMPLATECK_TITLE_TEMPLATES'), 'templates.png');
//Check if the form exists before showing the add/edit buttons
// $formPath = JPATH_COMPONENT_ADMINISTRATOR . '/views/templateinfos';
// if (file_exists($formPath)) {
if ($canDo->get('core.create')) {
JToolBarHelper::addNew('template.edit', 'JTOOLBAR_NEW');
}
TemplateckHelper::loadCkbox();
TemplateckHelper::loadCkFramework();
if ($canDo->get('core.edit')) {
JToolBarHelper::editList('template.edit', 'JTOOLBAR_EDIT');
JToolBarHelper::custom('templates.copy', 'tck-copyTemplate', 'tck-copyTemplate', 'CK_COPY_TEMPLATE');
// JToolBarHelper::custom('templateinfos.installGabarit', 'tck-installGabarit', 'tck-installGabarit', 'CK_INSTALL_GABARIT', false);
// JToolBarHelper::custom('templateinfos.exportGabarit', 'tck-exportGabarit', 'tck-exportGabarit', 'CK_EXPORT_GABARIT', true);
$importButton = '<button class="btn btn-small" onclick="CKBox.open({handler: \'inline\', content: \'ckimportmodal\', fullscreen: false, size: {x: \'600px\', y: \'200px\'}});">
<span class="icon-forward-2"></span>
' . TCK_Text::_('CK_IMPORT') . '
</button>';
$bar->appendButton('Custom', $importButton, 'import');
$exportButton = '<button class="btn btn-small" onclick="ckExportPage(document.adminForm);">
<span class="icon-share"></span>
' . TCK_Text::_('CK_EXPORT') . '
</button>';
$bar->appendButton('Custom', $exportButton, 'export');
}
// }
if ($canDo->get('core.edit.state')) {
if (isset($this->items[0]->state)) {
JToolBarHelper::divider();
} else {
//If this component does not use state then show a direct delete button as we can not trash
JToolBarHelper::trash('templates.delete');
}
if (isset($this->items[0]->state)) {
JToolBarHelper::divider();
}
}
//Show trash and delete for components that uses the state field
if (isset($this->items[0]->state)) {
if ($state->get('filter.state') == -2 && $canDo->get('core.delete')) {
// JToolBarHelper::deleteList('', 'templates.delete','JTOOLBAR_EMPTY_TRASH');
JToolBarHelper::divider();
} else if ($canDo->get('core.edit.state')) {
JToolBarHelper::trash('templates.delete', 'JTOOLBAR_TRASH');
JToolBarHelper::divider();
}
}
if ($canDo->get('core.admin')) {
JToolBarHelper::preferences('com_templateck');
}
TemplateckHelper::addSidebar();
}
/**
* private function to check if the template templatecreatorck is installed
*/
// function _checkIfTemplateInstalled() {
// $app = JFactory::getApplication();
// if (TCK_Folder::exists(JPATH_ROOT . '/templates/templatecreatorck')) {
// return;
// } else {
// $app->enqueueMessage(TCK_Text::_('TEMPLATE_TEMPLATECREATORCK_NOT_INSTALLED'), 'error');
// }
//
// return;
// }
private function checkDbIntegrity() {
$this->searchColumn('widgets');
$this->searchColumn('modules');
$this->searchColumn('stylecode', 'longtext');
$this->searchColumn('identifier', 'varchar(10)');
$this->searchTable('layouts');
}
private function searchColumn($name, $type = 'text') {
$db = JFactory::getDbo();
// test if the widget columns not exists
$query = "SHOW COLUMNS FROM #__templateck_templates LIKE '" . $name . "'";
$db->setQuery($query);
if ($db->execute()) {
if ( $db->loadResult()) {
//echo 'existe deja!';return;
} else {
// add the SQL field to the main table
$db->setQuery('ALTER TABLE `#__templateck_templates` ADD `' . $name . '` ' . $type . ' NOT NULL;');
if (!$db->execute()) {
echo '<p class="alert alert-danger">Error during table column ' . $name . ' update process !</p>';
} else {
echo '<p class="alert alert-success">Table column ' . $name . ' updated !</p>';
}
}
} else {
echo 'SQL error - Check existing ' . $name . ' column';
return false;
}
}
/**
* Look if the table exists, if not then create it
*
* @param type $tableName
*/
private function searchTable($tableName) {
$db = JFactory::getDbo();
$tablesList = $db->getTableList();
$tableExists = in_array($db->getPrefix() . 'templateck_' . $tableName, $tablesList);
// test if the table not exists
if (! $tableExists) {
$query = "CREATE TABLE IF NOT EXISTS #__templateck_" . $tableName . " (
`id` int(11) NOT NULL AUTO_INCREMENT,
`template_id` int(11) NOT NULL,
`type` text NOT NULL,
`htmlcode` longtext NOT NULL,
`styles` text NOT NULL,
`published` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)
)";
$db->setQuery($query);
// // add the SQL field to the main table
// $query = 'ALTER TABLE `' . $table . '` ADD `' . $name . '` text NOT NULL;';
if (! $db->execute($query)) {
echo '<p class="alert alert-danger">Error during table ' . $tableName . ' creation process !</p>';
} else {
echo '<p class="alert alert-success">Table ' . $tableName . ' created with success !</p>';
}
}
}
}