templates.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:24k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: templates.php,v $
- // | $Date: 2004/02/10 01:34:25 $
- // | $Revision: 1.75 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - User interface template maintenance, import, and export
- // | (administration interface)
- // +-------------------------------------------------------------+
- error_reporting(E_ALL & ~E_NOTICE);
- include("./global.php");
- include "./../includes/functions/conditional_functions.php";
- include "./../includes/functions/devmode_functions.php";
- // default do
- $_REQUEST['do'] = trim($_REQUEST['do']);
- if (!isset($_REQUEST['do']) or $_REQUEST['do'] == "") {
- $_REQUEST['do'] = "view";
- }
- // globalise variables
- $global = array (
- array('category'),
- array('id')
- );
- rg($global);
- ########################################################################################
- ############################### VIEW TEMPLATES ###############################
- ########################################################################################
- if ($_REQUEST['do'] == "view") {
- admin_header('Styles', 'View User Templates');
- // get template categories
- $db->query("SELECT * FROM template_cat");
- while ($result = $db->row_array()) {
- $cats[$result['id']] = $result['name'];
- }
- /***************************************************
- DEFAULT TEMPLATES
- ***************************************************/
- // get default, non backup templates
- $db->query("
- SELECT * FROM template
- WHERE custom = 0
- AND backup = 0
- ORDER BY category, displayorder
- ");
-
- while ($template = $db->row_array()) {
- if ($lastcategory != $template[category]) {
- $table[] = table_midheader($cats[$template[category]]);
- }
-
- if ($template[upgraded] == "1") {
- $word = "<font color="red">CHANGED</font>";
- } elseif ($template[changed] == 1) {
- $word = "<font color="orange">EDITED</font>";
- } else {
- $word = '';
- }
- $bit = jprompt('Are you sure you want to restore this template to its original?\nAll your modifications will be lost', "templates.php?do=restore&id=$template[id]", 'Restore Default');
-
- // set if we have a restore to default link
- $table[] = array(
- "<b>$template[name]</b> $word",
- $template[description],
- iff($template[changed], $bit, ''),
- "<a href="templates.php?do=edit&id=$template[id]">Edit</a>"
- );
- $lastcategory = $template[category];
- }
- $width = array('20%', '40%', '15%', '15%');
- table_header("User Templates");
- table_content($columns, $table, '', '', '', '', $width, $bottomline);
- table_footer();
- unset($templates_temp, $table, $bottomline, $columns, $uncreated, $notemplate);
- /***************************************************
- CUSTOM TEMPLATES
- ***************************************************/
- // get custom templates
- $db->query("
- SELECT * FROM template
- WHERE custom = 1
- AND backup = 0
- ");
- while ($template = $db->row_array()) {
- $templates_temp[] = $template[name];
- $bit = jprompt('Are you sure you want to delete this template?', "templates.php?do=restore&id=$template", 'Delete');
- $table[] = array(
- "<b>$template[name]</b>",
- $template[description],
- $bit,
- "<a href="templates.php?do=editcustom&id=$template[id]">Edit</a>"
- );
-
- }
- table_header("Custom Templates");
- table_content($cols, $table, '', '', '', '', $width, $bottomline);
- table_footer();
- echo "<b>KEY:</b><ul>
- <li><font color="red">CHANGED</font> : The template has been upgraded since you last changed it. You should find the changes made or revert the template.</li>
- <li><font color="orange">EDITED</font> : You have made changes to this template.</li>
- </ul>
- ";
- }
- ########################################################################################
- ############################### EDIT CUSTOM TEMPLATE ###############################
- ########################################################################################
- /***************************************************
- QUERY TO UPDATE CUSTOM TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "editcustom2") {
- $temp = $db->query_return("SELECT name FROM template WHERE id = $id");
- $template = parse_conditionals($_REQUEST[template_unparsed]);
- // update descriptions and names
- $db->query("
- UPDATE template SET
- description = '" . mysql_escape_string($_REQUEST[description]) . "',
- category = $_REQUEST[category]
- WHERE name = '" . mysql_escape_string($temp[name]) . "'
- ");
- $db->query("
- UPDATE template SET
- template = '" . mysql_escape_string($template) . "',
- template_unparsed = '" . mysql_escape_string($_REQUEST[template_unparsed]) . "'
- WHERE id = $id
- ");
- jump("templates.php?do=view&category=$_REQUEST[category]", "Template Updated");
- }
- /***************************************************
- SHOW TO EDIT CUSTOM TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "editcustom") {
- admin_header('Styles', 'Edit User Templates');
- // get the category details
- $db->query("SELECT * FROM template_cat");
- while ($categories = $db->row_array()) {
- $cat[$categories[id]] = $categories[name];
- }
- $template = $db->query_return("SELECT *
- FROM template
- WHERE id = $id
- ");
- $table[] = array('<b>Name</b>', $template[name]);
- $bit = form_select('category', $cat, '', $template[category]);
- $table[] = array('<b>Category</b>', $bit);
- $bit = form_textarea('description', '120', '4', $template[description]);
- $table[] = array('<b>Description</b>', $bit);
- $bit = form_textarea('template_unparsed', '120', '40', $template[template_unparsed]);
- $table[] = array('<b>Template</b>', $bit);
- table_header("Edit Custom Template " . $template[name], 'templates.php', array('do' => 'editcustom2', 'id' => $id));
- table_content($columns, $table);
- table_footer('Edit Template');
- unset($table);
- }
- ########################################################################################
- ############################### EDIT DEFAULT TEMPLATE ###############################
- ########################################################################################
- /***************************************************
- QUERY TO UPDATE DEFAULT TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "edit2") {
- $temp = $db->query_return("SELECT category FROM template WHERE id = $id");
- $template = parse_conditionals($_REQUEST['template_unparsed']);
- $db->query("UPDATE template SET
- template = '" . mysql_escape_string($template) . "',
- template_unparsed = '" . mysql_escape_string($_REQUEST['template_unparsed']) . "',
- " . iff(developer_check(1), "
- description = '" . mysql_escape_string($_REQUEST[description]) . "',
- category = '" . mysql_escape_string($_REQUEST[category]) . "',
- ") . "
- changed = 1
- WHERE id = '$id'
- ");
-
- jump("templates.php?do=view&category=$temp[category]", "Template Updated");
- }
- /***************************************************
- SHOW TO EDIT DEFAULT TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "edit") {
- admin_header('Styles', 'Edit User Templates');
- // get the category details
- $db->query("SELECT * FROM template_cat");
- while ($categories = $db->row_array()) {
- $cat[$categories[id]] = $categories[name];
- }
-
- $template = $db->query_return("SELECT *
- FROM template
- WHERE id = $id
- ");
-
- $table[] = array('<b>Name</b>', $template[name]);
- if (developer_check(1)) {
- $table[] = array('<b>Category</b>', form_select('category', $cat, '', $template[category]));
- } else {
- $table[] = array('<b>Category</b>', $cat[$template[category]]);
- }
- if (developer_check(1)) {
- $table[] = array('<b>Description</b>', form_textarea('description', '70', '4', $template[description]));
- } else {
- $table[] = array('<b>Description</b>', $template[description]);
- }
- $backup = $db->query_return("SELECT * FROM template WHERE name = '$template[name]' AND backup = 1");
- $table[] = array('<b>Edit Template</b>', form_textarea('template_unparsed', '120', '15', $template[template_unparsed]));
- $table[] = array('<b>Backup Template</b>' , '<br /><b>Template shown for reference. Editing it will have no affect</b><br /><br />' .form_textarea('backup', '120', '10', $backup[template_unparsed]));
- table_header("Edit Template " . $template[name], 'templates.php', array('do' => 'edit2', 'id' => $id));
- table_content($columns, $table);
- table_footer('Edit Template');
- unset($table);
- }
- ########################################################################################
- ############################### CREATE TEMPLATES ###############################
- ########################################################################################
- /***************************************************
- QUERY TO CREATE TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "add2") {
- $template = parse_conditionals($_REQUEST[template_unparsed]);
- // check template does not exist
- $db->query("SELECT id FROM template
- WHERE name = '" . mysql_escape_string($_REQUEST[name]) . "'
- ");
- if ($db->num_rows() > 0) {
-
- alert('There is already a template with this name');
- $_REQUEST['do'] = 'add';
-
- } else {
- $db->query("
- INSERT into template SET
- name = '" . mysql_escape_string($_REQUEST['name']) . "',
- description = '" . mysql_escape_string($_REQUEST['description']) . "',
- template = '" . mysql_escape_string($template) . "',
- template_unparsed = '" . mysql_escape_string($_REQUEST['template_unparsed']) . "',
- custom = 1
- ");
- jump("templates.php?do=view&category=$_REQUEST[category]", "Template Created");
- }
- }
- /***************************************************
- SHOW TO CREATE NEW TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "add") {
- admin_header('Styles', 'Create Template');
- $bit = form_input('name', iff($_REQUEST[name], $_REQUEST[name], $template[name]));
- $table[] = array('<b>Name</b>', $bit);
- $bit = form_textarea('description', '60', '4', iff($_REQUEST[description], $_REQUEST[description], $template[description]));
- $table[] = array('<b>Description</b>', $bit);
- $bit = form_textarea('template_unparsed', '120', '40', iff($_REQUEST[template_unparsed], $_REQUEST[template_unparsed], $template[template_unparsed]));
- $table[] = array('<b>Template</b>', $bit);
- $extra = form_hidden('do', 'edit2');
- table_header("Create New Template", 'templates.php', array('do' => 'add2'));
- table_content($columns, $table);
- table_footer('Create Template');
- unset($table);
- }
- ########################################################################################
- ############################### RESTORE / DELETE TEMPLATES #############################
- ########################################################################################
- /***************************************************
- DELETE CUSTOM TEMPLATE
- ***************************************************/
- if ($_REQUEST['do'] == "delete") {
- $db->query("DELETE FROM template WHERE id = $id");
- jump("templates.php?do=view&category=$_REQUEST[category]", 'Custom template deleted');
- }
- /***************************************************
- RESTORE DEFAULT TEMPLATE FROM BACKUP
- ***************************************************/
- if ($_REQUEST['do'] == "restore") {
- $template = $db->query_return("SELECT * FROM template WHERE id = $id");
- if (!$db->num_rows()) {
- mistake('Template to restore not found.');
- }
- $template_backup = $db->query_return("
- SELECT * FROM template
- WHERE name = '$template[name]'
- AND backup = 1
- ");
- if ($db->num_rows()) {
- $db->query("
- UPDATE template SET
- template = '" . mysql_escape_string($template_backup[template]) . "',
- template_unparsed = '" . mysql_escape_string($template_backup[template_unparsed]) . "',
- upgraded = 0,
- changed = 0,
- backup = 0
- WHERE id = '$id'
- ");
- jump("templates.php?do=view&category=$_REQUEST[category]", "Template restored from backup");
- } else {
- mistake('Backup template not found');
- }
- }
- ########################################################################################
- ############################### SEARCH / REPLACE ######################################
- ########################################################################################
- ############################### PREG REPLACE (!) ###############################
- if ($_REQUEST['do'] == "preg_replace") {
- admin_header('Styles', 'Template Search Results');
- $table[] = array('<b>Search For</b><br />Enter your search keyword', form_input('keyword'));
- $table[] = array('<b>Replace With</b><br />Text to replace with', form_input('replace'));
- $table[] = array('<b>Treat replace as PHP code</b>', '<input type="checkbox" name="phpcode" value="1">');
- table_header("Search for templates", 'templates.php', array('do' => 'preg_replace2'));
- table_content($columns, $table);
- table_footer('Search');
- }
- ############################### PREG REPLACE (2) ###############################
- if ($_REQUEST['do'] == "preg_replace2") {
- $db2 = new DB_Sql;
- $db2->User=constant('DATABASE_USER');
- $db2->Password=constant('DATABASE_PASSWORD');
- $db2->Host=constant('DATABASE_HOST');
- $db2->Database=constant('DATABASE_NAME');
- $db->query("SELECT id, name, template_unparsed FROM template");
- while ($result = $db->row_array()) {
- if ($_REQUEST[phpcode] == "1") {
- $newtemplate = preg_replace("/$_REQUEST[keyword]/siUe", $_REQUEST['replace'], $result['template_unparsed']);
- } else {
- $newtemplate = preg_replace("/$_REQUEST[keyword]/siU", $_REQUEST['replace'], $result['template_unparsed']);
- echo $newtemplate;
- }
- if ($newtemplate != $result[template_unparsed]) {
- echo $result['template_unparsed'];
- echo $newtemplate;
- exit();
- }
- if ($newtemplate != $result[template_unparsed]) {
- $parsed = parse_conditionals($newtemplate);
- /*
- $db2->query("UPDATE template
- SET template_unparsed = '" . mysql_escape_string($newtemplate) . "',
- template = '" . mysql_escape_string($parsed) . "'
- WHERE id = '$result[id]'
- ");
- */
- echo $result[name] . '<br />';
- }
- }
- }
- ############################### FIND TEMPLATES ###############################
- if ($_REQUEST['do'] == "find") {
- admin_header('Styles', 'Find In Templates');
- $table[] = array('<b>Search For</b><br />Enter your search keyword', form_input('keyword'));
- $table[] = table_midheader('Replace');
- $table[] = array('<b>Run replacements</b>', '<input type="checkbox" name="doreplace" value="1">');
- $table[] = array('<b>Replace With</b><br />Text to replace with', form_input('replace'));
- table_header("Search for templates", 'templates.php', array('do' => 'find2'));
- table_content($columns, $table);
- table_footer('Search');
- unset($table);
- }
- ############################### FIND TEMPLATES ###############################
- if ($_REQUEST['do'] == "find2") {
- admin_header('Styles', 'Search Results');
- $db->query("SELECT * FROM template WHERE template_unparsed LIKE '%" . mysql_escape_string($_REQUEST[keyword]) . "%' $where");
- while ($template = $db->row_array()) {
- $template[template_unparsed] = str_replace($_REQUEST['keyword'], $_REQUEST['replace'], $template[template_unparsed]);
- $template[template] = parse_conditionals($template[template_unparsed]);
- $update_templates[] = array($template[id], $template[name], $template[template], $template[category], $template[description], $template[upgraded], $template[changed], $template[custom], $template[version_upgrade], $template[template_unparsed], $template[displayorder]);
- $table[] = array($template[name], $template[category]);
- $secondrow[] = "<textarea cols="100" rows="15">" . htmlspecialchars($template[template_unparsed]) . "</textarea>";
- }
- // echo multi_array2sql($update_templates);
- if ($_REQUEST['doreplace']) {
- $db->query("
- REPLACE INTO template (id, name, template, category, description, upgraded, changed, custom, version_upgrade, template_unparsed, displayorder)
- VALUES " . multi_array2sql($update_templates) . "");
- } else {
-
- table_header("Search for templates", 'templates.php', array('do' => 'find2'));
- table_content($columns, $table, '', '', '', $secondrow);
- table_footer('Search');
- unset($table);
- }
- }
- ########################################################################################
- ############################### DEVELOPER ONLY SECTION ###############################
- ########################################################################################
- ############################### EXPORT TEMPLATES TO FILES ###############################
- if ($_REQUEST['do'] == "dev_export") {
- developer_check();
- admin_header('Styles', 'Export To Files');
- $location = dirname(__FILE__);
- $location .= '/templates/';
- dev_export_templates($location);
- echo "<P>Export completed.</P>n";
- }
- ############################# EXPORT MAIL TEMPLATES TO FILES #############################
- if ($_REQUEST['do'] == 'dev_export_mail') {
- developer_check();
- admin_header('Styles, Export Mail To Files');
- $languages = $db->query_return_array_id("SELECT id, name FROM languages", 'name');
- echo "<FORM METHOD="POST" ACTION="templates.php">";
- echo form_hidden('do', 'do_dev_export_mail');
- $languages['tech'] = "Tech Mails";
- $rows[] = array('<B>Languages to Export</B>', form_select('languages', $languages, NULL, array_keys($languages), NULL, NULL, 6));
- table_header("Select Languages to Export to /admin/templates/email/*");
- table_content(NULL, $rows);
- table_footer('Export Languages');
- exit;
- }
- if ($_REQUEST['do'] == 'do_dev_export_mail') {
- developer_check();
- admin_header('Styles', 'Export Mail To Files');
- if (ini_set('track_errors', 1) === FALSE) {
- $errors[] = "[WARNING] track_errors is not enabled and could not be enabled; detailed errors will not be available.";
- $php_errormsg = 'Unknown error.';
- }
-
- $location = dirname(__FILE__) . '/templates/email';
- dev_export_mail_templates($location);
- }
- ############################### IMPORT TEMPLATES FROM FILES ###############################
- if ($_REQUEST['do'] == 'dev_import') {
- admin_header('Styles', 'Import From Files');
- $location = dirname(__FILE__);
- $location .= '/templates/';
- dev_import_templates($location);
- echo "Import completed.<BR />";
- }
- ############################### IMPORT MAIL TEMPLATES FROM FILES ###############################
- if ($_REQUEST['do'] == 'dev_import_mail') {
- developer_check();
- admin_header('Styles', 'Import Mail From Files');
- $languages = $db->query_return_array_id("SELECT id, name FROM languages", 'name');
- $languages['tech'] = "Tech Mails";
- echo "<FORM METHOD="POST" ACTION="templates.php">";
- echo form_hidden('do', 'do_dev_import_mail');
- $rows[] = array('<B>Languages to Import</B>', form_select('languages', $languages, NULL, array_keys($languages), NULL, NULL, 6));
- table_header("Select Languages to Import to /admin/templates/email/*");
- table_content(NULL, $rows);
- table_footer('Import Languages');
- exit;
- }
- if ($_REQUEST['do'] == 'do_dev_import_mail') {
- developer_check();
-
- admin_header('Styles', 'Import Mail From Files');
- if (ini_set('track_errors', 1) === FALSE) {
- $errors[] = "[WARNING] track_errors is not enabled and could not be enabled; detailed errors will not be available.";
- $php_errormsg = 'Unknown error.';
- }
-
- $location = dirname(__FILE__) . '/templates/email';
- dev_import_mail_templates($location);
- }
- ############################### TEMPLATE MAINTENANCE ###############################
- if ($_REQUEST['do'] == "search_images") {
- developer_check();
- admin_header('Styles', 'Image Usage');
- if (is_win()) {
- echo "<B>Error:</B> This function is not currently supported on Windows platforms.";
- admin_footer();
- exit;
- }
- if (!chdir('../images')) {
- echo "<B>Error:</B> Couldn't chdir() to ../images/";
- admin_footer();
- exit;
- }
- $images = exec("find . -type f -name '*gif'", $output, $retval);
- if (!chdir('../')) {
- echo "<B>Error:</B> Couldn't chdir() to base of installation";
- admin_footer();
- exit;
- }
- if ($retval) {
- echo "<B>Error:</B> Find failed.";
- print_rr($output);
- admin_footer();
- exit;
- }
- if (is_array($output)) {
- $not_used = array();
- foreach ($output AS $image) {
- $image = substr($image, 2);
- unset($messages);
- exec('grep -onri "' . $image . '" *', $messages, $return);
- if (count($messages)) {
- foreach ($messages AS $message) {
- if (stristr($message, 'js') or stristr($message, 'php')) {
- $message = split(':', $message);
- $used[$image]['files'][$message[0]][] = array($message[1], $message[2]);
- $used[$image]['count']++;
- } elseif (stristr($message, 'html')) {
- $message = split(':', $message);
- $used[$image]['templates'][$message[0]][] = array($message[1], $message[2]);
- $used[$image]['count']++;
- }
- }
- }
- if (!$used[$image]['count']) {
- $not_used[] = $image;
- unset ($used[$image]);
- }
- }
- }
- if (is_array($used)) {
- print "<TABLE CELLPADDING="2" CELLSPACING="0">";
- $rowscount = 0;
- foreach($used AS $image => $use) {
- if ($rowscount % 2) {
- $bgcolor="#EEEEFF";
- } else {
- $bgcolor="white";
- }
- echo "<TR VALIGN="top" BGCOLOR="$bgcolor"><TD WIDTH="33%">$image (use count: $use[count])</TD>n";
- echo "<TD ROWSPAN="2" WIDTH="33%">";
- if (is_array($use['templates'])) {
- foreach ($use['templates'] AS $filename => $file) {
- echo "<TABLE><TR><TD COLSPAN="2">$filename</TD></TR>n";
- $lines = array();
- foreach ($file AS $linenum) {
- $lines[] = $linenum[0];
- }
- $lines = join(', ', $lines);
- echo "<TD> </TD><TD>Line number(s): $lines</TD></TR>n";
- echo "</TABLE>n";
- }
- } else {
- echo "Not used in any template.n";
- }
- echo "</TD>n";
- echo "<TD ROWSPAN="2" WIDTH="34%">";
- if (is_array($use['files'])) {
- foreach ($use['files'] AS $filename => $file) {
- echo "<TABLE><TR><TD COLSPAN="2">$filename</TD></TR>n";
- $lines = array();
- foreach ($file AS $linenum) {
- $lines[] = $linenum[0];
- }
- $lines = join(', ', $lines);
- echo "<TD> </TD><TD>Line number(s): $lines</TD></TR>n";
- echo "</TABLE>n";
- }
- } else {
- echo "Not used in any files.n";
- }
- echo "</TD>n";
- echo "</TR><TR VALIGN="top" BGCOLOR="$bgcolor"><TD>";
- $tmpimage = html_image($image);
- echo "<TABLE CELLPADDING="4"><TR VALIGN="top"><TD BGCOLOR="white">$tmpimage</TD><TD BGCOLOR="black">$tmpimage</TD></TR></TABLE>";
- echo "</TD></TR>n";
- $rowscount++;
- }
- echo "</TABLE>n";
- }
- print "<P><B>Unused Images:</B><BR>";
- if (is_array($not_used)) {
- if (count($not_used)) {
- print "<TABLE>";
- foreach($not_used AS $image) {
- $tmpimage = html_image($image);
- echo "<TR VALIGN="top"><TD VALIGN="top" ALIGN="right">$image</TD><TD><TABLE CELLPADDING="4"><TR><TD BGCOLOR="white">$tmpimage</TD><TD BGCOLOR="black">$tmpimage</TD></TR></TABLE></TD></TR>";
- }
- print "</TABLE>";
- } else {
- print "None";
- }
- } else {
- print "None";
- }
- print "</P>";
- exit;
- }