PageRenderTime 12ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/admin/admin_topic_templates.php

http://torrentpier2.googlecode.com/
PHP | 196 lines | 168 code | 26 blank | 2 comment | 24 complexity | a4c5605777c9bf2c256267dbb2b0503f MD5 | raw file
  1<?php
  2
  3// ACP Header - START
  4if (!empty($setmodules))
  5{
  6	$module['Mods']['Release_Templates'] = basename(__FILE__);
  7	return;
  8}
  9require('./pagestart.php');
 10// ACP Header - END
 11
 12require(LANG_DIR .'lang_admin_bt.php');
 13
 14$mode = (string) request_var('mode', '');
 15
 16if ($mode == 'templates')
 17{
 18	$sql = "SELECT * FROM ". BB_TOPIC_TPL_OLD ." ORDER BY tpl_name";
 19
 20	foreach (DB()->fetch_rowset($sql) as $i => $row)
 21	{
 22		$template->assign_block_vars('tpl', array(
 23			'ROW_CLASS'   => !($i % 2) ? 'row4' : 'row5',
 24			'ID'          => $row['tpl_id'],
 25			'NAME'        => $row['tpl_name'],
 26		));
 27	}
 28
 29    $template->assign_vars(array(
 30		'TPL_LIST'      => true,
 31		'S_ACTION'      => "admin_topic_templates.php?mode=delete",
 32	));
 33}
 34else if ($mode == 'add' || $mode == 'edit')
 35{
 36    $template->assign_vars(array(
 37		'TPL'    => true,
 38	));
 39
 40    if($mode == 'edit')
 41    {
 42    	$tpl_id = (int) request_var('tpl', '');
 43    	if(!$tpl_id) bb_die('');
 44
 45    	$row = DB()->fetch_row("SELECT * FROM ". BB_TOPIC_TPL_OLD ." WHERE tpl_id = $tpl_id");
 46        if(!$row) bb_die('');
 47
 48        $template->assign_vars(array(
 49			'S_ACTION'      => "admin_topic_templates.php?mode=edit&tpl=$tpl_id",
 50		));
 51    }
 52    else
 53    {
 54    	$template->assign_vars(array(
 55			'S_ACTION'      => "admin_topic_templates.php?mode=add",
 56		));
 57    }
 58
 59    $tpl_name =	isset($_POST['tpl_name']) ? $_POST['tpl_name'] : @$row['tpl_name'];
 60    $tpl_script = isset($_POST['tpl_script']) ? $_POST['tpl_script'] : @$row['tpl_script'];
 61    $tpl_template = isset($_POST['tpl_template']) ? $_POST['tpl_template'] : @$row['tpl_template'];
 62    $tpl_desc = isset($_POST['tpl_desc']) ? $_POST['tpl_desc'] : @$row['tpl_desc'];
 63
 64    $template->assign_vars(array(
 65		'NAME'      => $tpl_name,
 66		'SCRIPT'    => $tpl_script,
 67		'TEMP'      => $tpl_template,
 68		'DESC'      => $tpl_desc,
 69	));
 70
 71    if(isset($_POST['submit']))
 72    {
 73	    if($mode == 'edit')
 74	    {
 75	    	DB()->query("UPDATE ". BB_TOPIC_TPL_OLD ." SET
 76					tpl_name = '". DB()->escape($tpl_name) ."',
 77					tpl_script = '". DB()->escape($tpl_script) ."',
 78					tpl_template = '". DB()->escape($tpl_template) ."',
 79					tpl_desc = '". DB()->escape($tpl_desc) ."'
 80				WHERE tpl_id = $tpl_id
 81			");
 82			$message = $lang['CHANGED'];
 83	    }
 84	    else
 85	    {
 86	    	DB()->query("INSERT INTO ". BB_TOPIC_TPL_OLD ." (tpl_name, tpl_script, tpl_template, tpl_desc)
 87				VALUES ('". DB()->escape($tpl_name) ."', '". DB()->escape($tpl_script) ."', '". DB()->escape($tpl_template) ."', '". DB()->escape($tpl_desc) ."')");
 88			$message = $lang['ADEDD'];
 89	    }
 90
 91	    bb_die($message);
 92	}
 93}
 94else if ($mode == 'delete')
 95{
 96    $tpl_ids = isset($_POST['tpl_id']) ? $_POST['tpl_id'] : bb_die($lang['NOT_CHOOSE']);
 97
 98    foreach ($tpl_ids as $tpl_id)
 99	{
100		$hidden_fields['tpl_id'][] = $tpl_id;
101	}
102
103    if (isset($_POST['confirm']))
104	{
105		DB()->query("DELETE FROM ". BB_TOPIC_TPL_OLD ." WHERE tpl_id IN(". join(',', $tpl_ids) .")");
106		bb_die($lang['REMOVED']);
107	}
108	else
109	{
110		$names = DB()->fetch_rowset("SELECT tpl_name FROM ". BB_TOPIC_TPL_OLD ." WHERE tpl_id IN(". join(',', $tpl_ids) .") ORDER BY tpl_name", 'tpl_name');
111
112		print_confirmation(array(
113			'QUESTION'      => $lang['QUESTION'],
114			'ITEMS_LIST'    => join('\n</li>\n<li>\n', $names),
115			'FORM_ACTION'   => "admin_topic_templates.php?mode=delete",
116			'HIDDEN_FIELDS' => build_hidden_fields($hidden_fields),
117		));
118	}
119}
120else
121{
122	$forums = DB()->fetch_rowset("
123		SELECT f.forum_id, f.forum_parent, f.topic_tpl_id, f.forum_name
124		FROM ". BB_CATEGORIES ." c, ". BB_FORUMS ." f
125		WHERE f.cat_id = c.cat_id
126		ORDER BY c.cat_order, f.forum_order
127	");
128
129	$tpl_ary = array();
130	$available_tpl_id = array(0);
131	$tpl_select = array($lang['TPL_NONE'] => 0);
132
133	$sql = "SELECT * FROM ". BB_TOPIC_TPL_OLD ." ORDER BY tpl_name";
134
135	foreach (DB()->fetch_rowset($sql) as $row)
136	{
137		$tpl_ary[$row['tpl_id']] = $row;
138		$available_tpl_id[] = $row['tpl_id'];
139
140		$name = isset($lang[strtoupper('TPL_'. $row['tpl_name'])]) ? $lang[strtoupper('TPL_'. $row['tpl_name'])] : $row['tpl_desc'];
141		$tpl_select[$name] = $row['tpl_id'];
142	}
143
144	if (isset($_POST['submit']) && @is_array($_POST['forum_tpl']))
145	{
146		$cur_val = $new_val = array();
147
148		foreach ($forums as $forum)
149		{
150			$cur_val["{$forum['forum_id']}"] = (int) $forum['topic_tpl_id'];
151		}
152		foreach ($_POST['forum_tpl'] as $forum_id => $tpl_id)
153		{
154			if (isset($cur_val["$forum_id"]) && in_array($tpl_id, $available_tpl_id))
155			{
156				$new_val["$forum_id"] = (int) $tpl_id;
157			}
158		}
159		if ($new_settings = array_diff_assoc($new_val, $cur_val))
160		{
161			foreach ($new_settings as $forum_id => $tpl_id)
162			{
163				DB()->query("
164					UPDATE ". BB_FORUMS ." SET
165						topic_tpl_id = ". (int) $tpl_id ."
166					WHERE forum_id = ". (int) $forum_id ."
167				");
168			}
169		}
170
171		$message = $lang['CONFIG_UPD'] .'<br /><br />';
172		$message .= sprintf($lang['RETURN_CONFIG'], '<a href="admin_topic_templates.php">', '</a>') .'<br /><br />';
173		$message .= sprintf($lang['CLICK_RETURN_ADMIN_INDEX'], '<a href="index.php?pane=right">', '</a>');
174
175		message_die(GENERAL_MESSAGE, $message);
176	}
177
178	foreach ($forums as $i => $forum)
179	{
180		$template->assign_block_vars('forum', array(
181			'ROW_CLASS'   => !($i % 2) ? 'row4' : 'row5',
182			'SF_PAD'      => ($forum['forum_parent']) ? 'padding-left: 20px;' : '',
183			'TPL_SELECT'  => build_select("forum_tpl[{$forum['forum_id']}]", $tpl_select, $forum['topic_tpl_id']),
184			'FORUM_CLASS' => ($forum['forum_parent']) ? 'gen' : 'gen',
185			'FORUM_STYLE' => ($forum['topic_tpl_id']) ? 'font-weight: bold;' : '',
186			'FORUM_ID'    => $forum['forum_id'],
187			'FORUM_NAME'  => htmlCHR($forum['forum_name']),
188		));
189	}
190
191	$template->assign_vars(array(
192		'FORUM_LIST'    => true,
193		'S_ACTION'      => "admin_topic_templates.php",
194	));
195}
196print_page('admin_topic_templates.tpl', 'admin');