📄 devmode_functions.php
字号:
<?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: devmode_functions.php,v $
// | $Date: 2004/02/13 02:12:31 $
// | $Revision: 1.29 $
// +-------------------------------------------------------------+
// | File Details:
// | - Utility functions for the administration interface
// | developer mode tools
// +-------------------------------------------------------------+
error_reporting(E_ALL ^ E_NOTICE);
/*****************************************************
function template_reparse()
-----DESCRIPTION: -----------------------------------
Re-parse all templates stored in the DB
-----ARGUMENTS: -------------------------------------
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function template_reparse() {
global $db;
$db->query("SELECT * FROM template");
while ($result = $db->row_array()) {
$template = parse_conditionals($result[template_unparsed]);
$db2->query("UPDATE template SET template = '" . mysql_escape_string($template) . "' WHERE id = '$result[id]'");
}
}
/*****************************************************
function dev_import_templates()
-----DESCRIPTION: -----------------------------------
Read all templates in from files, parse them, and
update the database.
-----ARGUMENTS: -------------------------------------
location Directory to import from
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_import_templates($location) {
global $db;
if (!file_exists($location)) {
mistake("[ERROR] $location doesn't exist; cannot import\n");
}
if (!is_dir($location)) {
mistake("[ERROR] $location isn't a directory; cannot import\n");
}
if (!($dir = @opendir($location))) {
mistake("[ERROR] Can't open $location for reading; cannot import\n");
}
while ($file = @readdir($dir)) {
if ($file == '.' OR $file == '..' OR (substr($file, 0, 1) == '.') OR !is_file("$location/$file")) {
continue;
}
// read file
if ($handle = @fopen($location . "/$file", 'rb')) {
$template = @fread($handle, filesize($location . "/$file"));
$file = str_replace('.html', '', $file);
@fclose($handle);
$parsed_template = parse_conditionals($template);
$db->query("SELECT * FROM template WHERE name = '" . mysql_escape_string($file) . "'");
if ($db->num_rows()) {
$db->query("
UPDATE template SET
template = '" . mysql_escape_string($parsed_template) . "',
template_unparsed = '" . mysql_escape_string($template) . "'
WHERE name = '" . mysql_escape_string($file) . "'
");
$return .= "[NOTICE] Imported $file.\n";
} else {
$db->query("INSERT INTO template SET
template = '" . mysql_escape_string($parsed_template) . "',
template_unparsed = '" . mysql_escape_string($template) . "',
name = '" . mysql_escape_string($file) . "',
category = '0',
description = '',
upgraded = '0',
changed = '0',
custom = '0',
version_upgrade = '0',
displayorder = '9999',
backup = '0'
");
$return .= "[NOTICE] Added new template $file.\n";
}
} else {
$return .= "[WARN] Couldn't open file \"$file\" for reading.\n";
}
}
return $return;
}
/*****************************************************
function dev_import_mail_templates()
-----DESCRIPTION: -----------------------------------
Read all mail templates in from files, parse them, and
update the database.
-----ARGUMENTS: -------------------------------------
location Directory to import from
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_import_mail_templates($location) {
global $db, $_REQUEST;
if (!file_exists($location)) {
$errors[] = "[ERROR] $location doesn't exist; cannot import e-mail templates: $php_errormsg";
}
if (!@is_dir($location)) {
$errors[] = "[ERROR] $location isn't a directory or can't be stat()'d; cannot import e-mail templates: $php_errormsg";
}
$orig_langs = $_REQUEST['languages'];
if (in_array('tech', $_REQUEST['languages']) OR !$_REQUEST['languages']) {
$get_tech = 1;
if (count($_REQUEST['languages'])) {
foreach($_REQUEST['languages'] AS $val) {
if ($val != 'tech') {
$langs[] = $val;
}
$_REQUEST['languages'] = $langs;
}
$get_norm = 1;
} else {
if (!$_REQUEST['languages']) {
$get_norm = 1;
} else {
$_REQUEST['languages'] = NULL;
}
}
} else {
$get_norm = 1;
}
if (!count($errors)) {
if ($_REQUEST['languages']) {
$langs = ' where ID in ' . array2sql($_REQUEST['languages']);
}
$db->query("SELECT id, name FROM languages $langs");
if (!$db->num_rows() AND !$get_tech) {
$errors[] = "No languages are defined. Cannot import.";
}
while ($res = $db->row_array()) {
$languages[$res['id']]['name'] = $res['name'];
$languages[$res['id']]['dir'] = $location.'/'.$res['name'];
}
$languages[-1]['name'] = 'Tech bodies';
$languages[-1]['dir'] = $location;
foreach ($languages AS $lang_id => $lang_data) {
if (!@file_exists($languages[$lang_id]['dir'])) {
$errors[] = "Directory " . $languages[$lang_id]['dir'] . " doesn't exist: $php_errormsg";
continue;
}
if (!@is_dir($languages[$lang_id]['dir'])) {
// It's a plain file, not a directory. Can't import like this.
$errors[] = $languages[$lang_id]['dir'] . " exists but isn't a directory or can't be stat()'d: $php_errormsg";
continue;
}
if (!$dirhandle = opendir($languages[$lang_id]['dir'])) {
$errors[] = $languages[$lang_id]['dir'] . " exists but can't be opened for reading: $php_errormsg";
continue;
} else {
while (false !== ($file = readdir($dirhandle))) {
$template = basename($file, '.txt');
$file = $languages[$lang_id]['dir'].'/'.$file;
if (($file != '.') AND ($file != '..') AND is_file($file)) {
if ((stristr($file, 'TECHBODY') AND $get_tech) OR (!stristr($file, 'TECHBODY') AND !$get_tech) OR (!stristr($file, 'TECHBODY') AND $get_norm)) {
if ($handle = @fopen($file, 'rb')) {
$data = array();
while (!feof($handle)) {
$data[] = fgets($handle, 4096);
}
if (preg_match("/^Subject:(.*)$/i", $data[0], $matches)) {
$subject = ", subject = '" . mysql_escape_string(trim($matches[1])) . "'";
array_shift($data);
} else {
$subject = '';
}
$data = join('', $data);
$parsed = parse_conditionals($data);
$db->query("SELECT id FROM template_email WHERE
name = '" . mysql_escape_string($template) . "'
AND language = $lang_id
AND !backup");
if ($db->num_rows()) {
$db->query("UPDATE template_email
SET template = '" . mysql_escape_string($parsed) . "',
template_unparsed = '" . mysql_escape_string($data) . "'
$subject
WHERE language = $lang_id
AND name = '" . mysql_escape_string($template) . "'
AND !backup
");
if ($db->affected_rows()) {
$imported[$template][$lang_id] = -2;
} else {
$imported[$template][$lang_id] = -1;
}
} else {
$imported[$template][$lang_id] = -2;
if (stristr($file, 'TECHBODY')) {
$import_cat = 'Tech Emails';
} else{
$import_cat = 'User Emails';
}
$db->query("INSERT INTO template_email SET
template = '" . mysql_escape_string($parsed) . "',
template_unparsed = '" . mysql_escape_string($data) . "',
name = '" . mysql_escape_string($template) . "',
language = '$lang_id',
category = '$import_cat',
description = '',
upgraded = '0',
changed = '0',
custom = '1',
version_upgrade = '0',
displayorder = '9999',
backup = '0'
$subject
");
$db->query("INSERT INTO template_email SET
template = '" . mysql_escape_string($parsed) . "',
template_unparsed = '" . mysql_escape_string($data) . "',
name = '" . mysql_escape_string($template) . "',
language = '$lang_id',
category = '$import_cat',
description = '',
upgraded = '0',
changed = '0',
custom = '1',
version_upgrade = '0',
displayorder = '9999',
backup = '1'
$subject
");
}
} else {
$imported[$template][$lang_id] = 0;
$errors[] = "Can't open $file: $php_errormsg";
}
}
}
}
closedir($dirhandle);
}
}
$cols = array('Template Name');
foreach ($languages as $lang) {
$cols[] = $lang['name'];
}
foreach ($imported AS $template => $val) {
$row = array($template);
foreach ($languages AS $lang_id => $lang) {
if ($val[$lang_id] == -2) {
$result = '<FONT COLOR="green">Imported</FONT>';
} elseif ($val[$lang_id] == -1) {
$result = '<FONT COLOR="green">No Change</FONT>';
} elseif ($val[$lang_id] === FALSE) {
$result = '<FONT COLOR="red">Error</FONT>';
} else {
$result = 'Not defined';
}
$row[] = "<CENTER>$result</CENTER>";
if (is_string($val[$lang_id])) {
$errors[] = $val[$lang_id];
}
}
$rows[] = $row;
}
}
table_header('Import Results');
table_content($cols, $rows);
table_footer();
if (count($errors)) {
table_header('Import Errors');
table_content(NULL, $errors);
table_footer();
}
}
/*****************************************************
function dev_remove_edit()
-----DESCRIPTION: -----------------------------------
Remove the "changed" and "upgraded" status flags on
all templates.
-----ARGUMENTS: -------------------------------------
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_remove_edit() {
global $db;
$db->query('UPDATE template SET changed = 0, upgraded = 0, version_upgrade = 0');
}
/*****************************************************
function dev_make_default()
-----DESCRIPTION: -----------------------------------
Make all templates "stock" templates (remove their
custom flag)
-----ARGUMENTS: -------------------------------------
None
-----RETURNS: ---------------------------------------
Nothing.
*****************************************************/
function dev_make_default() {
global $db;
$db->query("UPDATE template SET custom = '0'");
}
/*****************************************************
function dev_undo_changes()
-----DESCRIPTION: -----------------------------------
Clear all templates' changed and upgraded flags.
-----ARGUMENTS: -------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -