⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 index.php

📁 jsp程序开发系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
		'2.0.2' => 202,
		'2.1.0' => 210
	);

	$this_version = $db->query_return("SELECT value FROM settings WHERE settings = 'deskpro_version'");
	$this_version = $this_version['value'];
	$this_version = $upgrades["$this_version"];
	
	#################### DO THE UPGRADE TO v2.0.1 #################### 
	
	if ($this_version == 200) {
		
		include('./upgrade_v2/201.php');

		if (!defined('FINISHED')) {
			$step = $_REQUEST['step'] + 1;
			echo "<BR><BR>To continue the upgrade, <A HREF=\"index.php?do=upgrade_v2&step=$step\">click here.</A>\n";
			exit();
		} else {
			echo "<BR><BR>To continue the upgrade, <a href=\"index.php?do=upgrade_v2standard\">click here.</A>\n";
			exit();
		}
	}

	#################### DO THE UPGRADE TO v2.0.2 #################### 
	if ($this_version == 200) {
		
		include('./upgrade_v2/202.php');
	}

	#################### DO STANDARD CODE (INSTALL / UPGRADE) #################### 


}

######################################################################################################################
############################################ GLOBAL CHANGES #################################################################
######################################################################################################################

if ($_REQUEST['do'] == 'upgrade_v2standard') {

	$db = new DB_Sql;
	$db->Halt_On_Error = 'yes';
	$db->User=constant('DATABASE_USER');
	$db->Password=constant('DATABASE_PASSWORD');
	$db->Host=constant('DATABASE_HOST');
	$db->Database=constant('DATABASE_NAME');

	if (!$_REQUEST['step']) {

		do_message("Upgrading your web templates");
		sort_web_templates();
		do_message_yes();

		echo "<BR><BR>To continue the upgrade, <a href=\"index.php?do=upgrade_v2standard&step=1\">click here.</A>\n";

	} elseif ($_REQUEST['step'] == 1) {

		do_message("Upgrading your email templates");
		sort_email_templates();
		do_message_yes();

		echo "<BR><BR>To continue the upgrade, <a href=\"index.php?do=upgrade_v2standard&step=2\">click here.</A>\n";	

	} elseif ($_REQUEST['step'] == 2) {

		do_message("Upgrading the template words");
		sort_words();
		do_message_yes();

		echo "<BR><BR>To continue the upgrade, <a href=\"index.php?do=upgrade_v2standard&step=3\">click here.</A>\n";
	
	} elseif ($_REQUEST['step'] == 3) {

		do_message("Upgrading default data");
		load_data('data.sql');
		do_message_yes();

		echo "<BR><BR>To continue the upgrade, <a href=\"index.php?do=upgrade_v2standard&step=4\">click here.</A>\n";			

	} elseif ($_REQUEST['step'] == 4) {

		do_message("Updating the settings");

		$settings_data = $db->query_return_array("SELECT * FROM settings");

		$queries = array(
			"DELETE FROM settings",
			"DELETE FROM settings_cat"
		);

		execute($queries);

		load_data('settings.sql');

		$queries = array(
			"DELETE FROM settings WHERE settings = ''"
		);

		if (is_array($settings_data)) {
			foreach ($settings_data AS $data) {
				$data['value'] = mysql_escape_string($data['value']);
				$queries[] = "UPDATE settings SET value = '$data[value]' WHERE settings = '$data[settings]'";
			}
		}

		execute($queries);
		do_message_yes();

		echo "<BR><BR>To continue the upgrade, <a href=\"index.php?do=upgrade_v2standard&step=5\">click here.</A>\n";		

	} elseif ($_REQUEST['step'] == 5) {

		echo "Congratulations, your upgrade to DeskPRO v$latest_version is now complete<br /><br />You must now delete the /install/index.php file. You can then log into the <a href=\"./../admin/index.php\">admin area</a>.";

	}
}

######################################################################################################################
############################################ FUNCTIONS #################################################################
######################################################################################################################
	

/*
	function sort_templates

	- This function sets the templates, email templates and words to the current version
	- It expects that the languages have already been created
	- The data will have an installid. This value refers to the installid for the language that element of data belongs to

*/

function sort_web_templates() {

	global $db;

	include('./v2data/templates.php');
	$db->query("DELETE FROM template WHERE backup = '1'");

	foreach ($template_data AS $key => $var) {

		$var['template'] = parse_conditionals($var['template_unparsed']);

		// create the backup
		$db->query("
		INSERT INTO template SET 
			name = '" . addslashes($var['name']) . "',
			description = '" . addslashes($var['description']) . "',
			template = '" . addslashes($var['template']) . "',
			backup = 1,
			template_unparsed = '" . addslashes($var['template_unparsed']) . "',
			category = '" . addslashes($var['category']) . "'
		");

		// need details on current template (but not the backup we just created)
		$result = $db->query_return("
			SELECT changed, template_unparsed FROM template 
				WHERE name = '" . addslashes($var['name']) . "' 
				AND !backup
		");

		// dosen't exist so create it
		if (!$db->num_rows()) {

			$db->query("
			INSERT INTO template SET 
				name = '" . addslashes($var['name']) . "',
				description = '" . addslashes($var['description']) . "',
				template = '" . addslashes($var['template']) . "',
				template_unparsed = '" . addslashes($var['template_unparsed']) . "',
				category = '" . addslashes($var['category']) . "'
			");

		} else {

			// first check it is actually different, if the template is the same
			// we only update the description
			if ($result['template_unparsed'] == $var['template_unparsed']) {
		
				$db->query("
					UPDATE template SET
						description = '" . addslashes($var['description']) . "',
						category = '" . addslashes($var['category']) . "',
						changed = '',
						upgraded = ''
					WHERE name = '" . addslashes($var['name']) . "'
					AND !backup
				");

			} else {

				// template has changed, and user has edited it; leave template alone but
				// tell user it has changed
				if ($result['changed'] == 1) {

					$db->query("
						UPDATE template SET
							description = '" . addslashes($var['description']) . "',
							category = '" . addslashes($var['category']) . "',
							upgraded = 1,
							version_upgrade = '$latest_version'
						WHERE name = '" . addslashes($var['name']) . "'
						AND !backup
					");

				// template has changed but user has not edited it; automatically update the
				// template
				} else {

					$db->query("
						UPDATE template SET
							description = '" . addslashes($var['description']) . "',
							template = '" . addslashes($var['template']) . "',
							template_unparsed = '" . addslashes($var['template_unparsed']) . "',
							category = '" . addslashes($var['category']) . "'
						WHERE name = '" . addslashes($var['name']) . "'
						AND !backup
					");

				}
			}
		}
	}
}

function sort_email_templates() {

	global $db;

	// need to link the installid (deskpro language id) to the actual language id
	$db->query("SELECT id, name, installid FROM languages WHERE !custom");
	while ($result = $db->row_array()) {
		$language_convert[$result[installid]] = $result[id];
		$language_convert_name[$result[installid]] = $result[name];
	}

	include('./v2data/email_templates.php');
	$db->query("DELETE FROM template_email WHERE backup = '1'");

	foreach ($template_data AS $key => $var) {

		$var['template'] = parse_conditionals($var['template_unparsed']);

		// create the backup
		$db->query("
			INSERT INTO template_email SET 
			name = '" . addslashes($var['name']) . "',
			description = '" . addslashes($var['description']) . "',
			category = '" . addslashes($var['category']) . "',
			template = '" . addslashes($var['template']) . "',
			subject =  '" . addslashes($var['subject']) . "',
			language = '" . addslashes($language_convert[$var[language]]) . "',
			backup = 1,
			template_unparsed = '" . addslashes($var['template_unparsed']) . "'
		");

		// need details on current template
		$result = $db->query_return("
			SELECT changed, template_unparsed FROM template_email
			WHERE name = '" . addslashes($var['name']) . "'
				AND !backup
				AND language = '" . $language_convert[$var[language]] . "'
		");

		// dosen't exist so create it
		if (!$db->num_rows()) {

			$debug .= "$var[name] for language " . $language_convert_name[$var[language]] . " does not exist, creating it.\n";

			// create the template
			$db->query("
				INSERT INTO template_email SET 
				name = '" . addslashes($var['name']) . "',
				description = '" . addslashes($var['description']) . "',
				category = '" . addslashes($var['category']) . "',
				subject =  '" . addslashes($var['subject']) . "',
				language = '" . $language_convert[$var[language]] . "',
				template_unparsed = '" . addslashes($var['template_unparsed']) . "',
				template = '" . addslashes($var['template']) . "'
			");

		} else {

			// first check it is actually different, if the template is the same
			// we only update the description
			if ($result['template_unparsed'] == $var['template_unparsed']) {

				$debug .= "$var[name] for language " . $language_convert_name[$var[language]] . " is the same. Updating the description.\n";
		
				$db->query("
					UPDATE template_email SET
						description = '" . addslashes($var['description']) . "',
						category = '" . addslashes($var['category']) . "',
						changed = '',
						upgraded = ''
					WHERE name = '" . addslashes($var['name']) . "'
					AND language = '" . addslashes($var['name']) . "'
					AND !backup
				");

			} else {

				// exists and is changed
				if ($result['changed'] == 1) {

					$debug .= "$var[name] for language " . $language_convert_name[$var[language]] . " Template has changed and user has edited it. Set as upgraded.\n";

					$db->query("
						UPDATE template_email SET
							description = '" . addslashes($var['description']) . "',
							upgraded = 1,
							version_upgrade = '$latest_version'
						WHERE name = '" . addslashes($var['name']) . "'
						AND !backup
						AND language = '" . $language_convert[$var[language]] . "'
					");

				// exists but is unchanged so just overwrite it
				} else {

					$debug .= "$var[name] for language " . $language_convert_name[$var[language]] . " Template has changed but user has not touched it, overwrite the template.\n";

					$db->query("
						UPDATE template_email SET
							subject = '" . addslashes($var['subject']) . "',
							description = '" . addslashes($var['description']) . "',
							template = '" . addslashes($var['template']) . "',
							template_unparsed = '" . addslashes($var['template_unparsed']) . "'
						WHERE name = '" . addslashes($var['name']) . "'
						AND !backup
						AND language = '" . $language_convert[$var[language]] . "'
					");

				}
			}
		}
	}	

	// echo "<textarea style=\"width:100%\" rows=\"15\">$debug</textarea>";

}

function sort_words() {

	global $db;

	// need to link the installid (deskpro language id) to the actual language id
	$db->query("SELECT id, installid FROM languages WHERE !custom");
	while ($result = $db->row_array()) {
		$language_convert[$result[installid]] = $result[id];
	}

	include('./v2data/words.php');
	$db->query("DELETE FROM template_words WHERE !cust");

	foreach ($template_data AS $key => $var) {

		$db->query("

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -