<?php
/*=====================================================================*\
|| ###################################################################
|| # app [#]version[#]
|| # Copyright ©2002-[#]year[#] Iris Studios, Inc.
|| #
|| # This program 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; version [#]gpl[#] of the License.
|| #
|| # This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/
define('SVN', '$Id$');
require_once('./global.php');
require_once('./includes/admin/templates.php');
require_once('./includes/class_style.php');
require_once('./includes/api_error.php');
APIError(array('APIErrorHandler', 'AdminError'));
// ###################################################################
if (empty($_REQUEST['do']))
{
$_REQUEST['do'] = 'modify';
}
// ###################################################################
if ($_REQUEST['do'] == 'kill')
{
$style = new StyleAPI($kalens);
$style->set('styleid', $kalens->in['styleid']);
$style->set_condition();
$style->delete();
$print->redirect('styles.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'delete')
{
$print->page_confirm($lang->string('Are you sure you want to delete this style and any template customizations in it?'), 'styles.php', 'kill', array('styleid' => $kalens->in['styleid']));
}
// ###################################################################
if ($_POST['do'] == 'insert')
{
$db->transaction_start();
if (!$kalens->debug OR ($kalens->debug AND !$kalens->in['usexmlopts']))
{
$style = new StyleAPI($kalens);
$style->set('stylename', $kalens->in['stylename']);
$style->insert();
$styleid = $style->insertid;
}
else
{
$styleid = 0;
}
$result = upload_template_xml(@file_get_contents($_FILES['templatefile']['tmp_name']), $_FILES['templatefile']['name'], $styleid);
if ($result !== true)
{
$print->error($result);
}
$db->transaction_commit();
$print->redirect('styles.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'add')
{
$print->page_start($lang->string('Add New Style'));
$print->form_start('styles.php', 'insert', 'multipart/form-data');
$print->table_start();
$print->table_head($lang->string('Add New Style'));
$print->row_input($lang->string('Name'), 'stylename');
$print->row_upload($lang->string('Upload File (optional)'), 'templatefile');
if ($kalens->debug)
{
$print->row_yesno($lang->string('Import Using XML Settings?'), 'usexmlopts', false);
}
$print->row_submit();
$print->table_end();
$print->form_end();
$print->page_end();
}
// ###################################################################
if ($_POST['do'] == 'update')
{
$style = new StyleAPI($kalens);
$style->set('styleid', $kalens->in['styleid']);
$style->set_condition();
$style->set('stylename', $kalens->in['stylename']);
$style->update();
$print->redirect('styles.php?do=modify');
}
// ###################################################################
if ($_REQUEST['do'] == 'edit')
{
$style = new StyleAPI($kalens);
$style->set('styleid', $kalens->in['styleid']);
$style->set_condition();
$style->fetch();
$print->page_start($lang->string('Edit Style'));
$print->form_start('styles.php', 'update');
$print->form_hidden_field('styleid', $style->objdata['styleid']);
$print->table_start();
$print->table_head(sprintf($lang->string('Edit Style - %1$s (id: %2$d)'), $style->objdata['stylename'], $style->objdata['styleid']));
$print->row_input($lang->string('Name'), 'stylename', $style->objdata['stylename']);
$print->row_submit('<a href="styles.php?do=delete&styleid=' . $style->objdata['styleid'] . '">[' . $lang->string('Delete') . ']</a>');
$print->table_end();
$print->form_end();
$print->page_end();
}
// ###################################################################
if ($_REQUEST['do'] == 'modify')
{
$print->page_start($lang->string('Styles'));
$print->table_start();
$print->table_head($lang->string('Styles'));
if (DEVDEBUG)
{
$print->row_text('<strong>» ' . $lang->string('MASTER STYLE') . '</strong>', '<a href="styles.php?do=download&styleid=-1">[' . $lang->string('Download') . ']</a>');
}
$get_styles = $db->query("SELECT * FROM " . TABLE_PREFIX . "style ORDER BY stylename");
while ($style = $db->fetch_array($get_styles))
{
$print->row_text($style['stylename'], "<a href=\"styles.php?do=edit&styleid=$style[styleid]\">[" . $lang->string('Edit') . "]</a> <a href=\"styles.php?do=download&styleid=$style[styleid]\">[" . $lang->string('Download') . "]</a>");
}
$print->row_span('<a href="styles.php?do=add">[' . $lang->string('Add New Style') . ']</a>', 'tfoot', 'center');
$print->table_end();
$print->page_end();
}
// ###################################################################
if ($_REQUEST['do'] == 'download')
{
$kalens->input_clean('styleid', TYPE_INT);
$customcount = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "template WHERE styleid = " . $kalens->in['styleid']);
if ($customcount['count'] < 1 AND $kalens->in['styleid'] != -1)
{
$print->error($lang->string('There are no customizations made in this style, therefore there is nothing to download.'));
}
download_template_xml('procal_style.xml', $kalens->in['styleid']);
}
/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>