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

📄 general_functions.php

📁 本代码是为客户联系管理而做的系统
💻 PHP
📖 第 1 页 / 共 5 页
字号:

	// check we serialized
	if (is_array($data)) {
		$data = serialize($data);
	}

	$db->query("SELECT id FROM data WHERE name = '" . mysql_escape_string($name) . "'");
	if ($db->num_rows()) {
		$db->query("	
						UPDATE data SET 
						data = '" . mysql_escape_string($data) . "'
						WHERE name = '" . mysql_escape_string($name) . "'
				");
	} else {
		$db->query("
			INSERT INTO data SET 
				data = '" . mysql_escape_string($data) . "', 
				name = '" . mysql_escape_string($name) . "', 
				isdefault = '1'
			");
	}

	if (is_array($cached_data)) {
		$cached_data[$name] = $data;
	} else {
		get_data($name);
	}
	
	return $data;

}

/*****************************************************
	function do_wordwrap

-----DESCRIPTION: -----------------------------------
	- ensures there are no long (non HTML) words

-----ARGUMENTS: -------------------------------------
	text		:	the text to format
	cols		:	max length
	cut			:	what to cut with

-----RETURNS:----------------------------------------
	formatted text

*****************************************************/

function do_wordwrap($text, $cols='100', $cut=' ') {

	$len=strlen($text);
  
	$tag=0;

	for ($i=0;$i<$len;$i++) {
		$chr = substr($text,$i,1);
		if ($chr=="<") { 
			$tag++;
		} elseif ($chr==">") {
			$tag--;
		} elseif (!$tag && ($chr==" " OR $chr=="\n" OR $chr=="\r")) {
			$wordlen=0;
			$spacer = 1;
		} elseif (!$tag) {
			$wordlen++;
		}

		if (!$tag && !($wordlen%$cols)) {
			if (!$spacer) {
				$chr .= $cut;
				$spacer = 0;
			}
		}
		$result .= $chr;
	} 
    
  return $result;
} 

/*****************************************************
	function dp_code

-----DESCRIPTION: -----------------------------------
	- makes HTML for an unchecked text source to display in browser
	- removes real HTML (security)
	- to be expanded to support <b><i> etc type replacements

-----ARGUMENTS: -------------------------------------
	text		:	the text to format

-----RETURNS:----------------------------------------
	formatted text

*****************************************************/

function dp_code($text, $no_ent = 0) {

	// prevent long words
	$text = do_wordwrap($text);

	// remove html
	if (!$no_ent) {
		$text = strip_tags($text, '<a><b><i><u>');
	}

	// turn links into html
	$text = eregi_replace("([ \t]|^)www\.", " http://www.", $text);
	$text = eregi_replace("([ \t]|^)ftp\.", " ftp://ftp.", $text);
	$text = eregi_replace("(http://[^ )\r\n]+)", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $text);
	$text = eregi_replace("(https://[^ )\r\n]+)", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $text);
	$text = eregi_replace("(ftp://[^ )\r\n]+)", "<a href=\"\\1\" target=\"_blank\">\\1</a>", $text);
	$text = eregi_replace("([-a-z0-9_]+(\.[_a-z0-9-]+)*@([a-z0-9-]+(\.[a-z0-9-]+)+))", "<a href=\"mailto:\\1\">\\1</a>", $text);

	// line breaks
	$text = nl2br($text);

	return $text;
}
	
/*****************************************************
	function dp_mail

-----DESCRIPTION: -----------------------------------
	- sends emails
	- sends either smtp mail or using mail() mail depending upon settings
	- supports attachments
	- supports multiple users (bcc)

	NOTE: If a template named "EMAIL_footer" exists and the "email_footer"
	setting is true, the contents of the EMAIL_FOOTER template will be
	appended to $message.

-----ARGUMENTS: -------------------------------------
	to			:	email address or array of email addresses to send to
	subject		:	subject of the email
	message		:	text version of the email
	from		:	either the from email address or an array of person name and then email address
	return		:	the return-path for failed emails/autoresponders
	attachments	:	array of attachment date (data, name, filetype)
	html		:	html porting of email if there is one
	nofooter	:	don't include footer
	silent		:	don't emit errors
	extraheaders:	extra headers

-----RETURNS:----------------------------------------
	null, prints errors if any are raised

*****************************************************/

function dp_mail($to, $subject, $message, $from=NULL, $return=NULL, $attachments=NULL, $html=NULL, $nofooter=NULL, $silent=NULL, $extraheaders=NULL) {

	global $smtp_settings, $settings, $use_smtp, $dplang;

	require_once(INCLUDE_PATH . 'functions/mail/class_smtp.php');
	require_once(INCLUDE_PATH . 'functions/mail/class_htmlMimeMail.php');
	require_once(INCLUDE_PATH . 'functions/mail/class_mimePart.php');
	require_once(INCLUDE_PATH . 'functions/mail/class_RFC822.php');

	// copyright
	$message = $message . add_copyright();

	// sort settings
	if (!$from) {
		$from = $settings['email_from'];
	}

	// specify the from
	if (is_array($from)) {
		$from = "\"$from[0]\" <$from[1]>";
	} else {
		$from = "\"$settings[email_from_name]\" <$from>";
	}

	// make to into array of who we are sending to
	if (!is_array($to)) {
		$to = array($to);
	}

	// validate emails
	foreach($to AS $t) {
		if (validate_email($t)) {
			$to_good[] = $t;
		}
	}

	// only continue if we have some valid emails to send
	if (is_array($to_good)) {
		$to = $to_good;
	} else {
		return;
	}

	// set the return email address
	if (!$return) {
		$return = $settings['email_bounce'];
	}

	// Create the mail object.
	$mail = new htmlMimeMail(); _a();

	// text or html
	if ($html) {
		$mail->setHtml(trim($html), trim($message));	
	} else {
		$mail->setText(wordwrap(trim($message), 79));
	}

	if (is_array($attachments)) {
		require_once(INCLUDE_PATH . 'data/mimetypes.php');
		foreach($attachments AS $key => $var) {
			if (isset($mimetypes[$var['extension']])) {
				$mime = $mimetypes[$var['extension']];
			} else {
				$mime = 'text/plain';
			}
			$mail->addAttachment($var['data'], $var['name'], $mime);
		}
	}

	// Set the return path of the message
	$mail->setReturnPath($return);

	// SMTP settings
	$mail->setSMTPParams(
		ifr($smtp_settings['host'], NULL), 
		ifr($smtp_settings['port'], NULL), 
		ifr($smtp_settings['helo'], NULL), 
		ifr($smtp_settings['auth'], NULL), 
		ifr($smtp_settings['user'], NULL), 
		ifr($smtp_settings['pass'], NULL)
	);

	$mail->setCrlf("\r\n");					// line returns
	$mail->setFrom($from);					// from
	$mail->setSubject(trim($subject));		// subject
	$mail->setHeader('X-Mailer', 'DeskPRO Nullified');
	$extraheaders = @array_merge($extraheaders, get_extra_headers());
	if (is_array($extraheaders)) {
		foreach ($extraheaders AS $key => $var) {
			if ($var != '' AND $key != '') {
				$mail->setHeader($key, $var);
			}
		}
	}

	// Send it using SMTP / mail()
	if ($use_smtp) {
		$result = $mail->send($to, 'smtp');
	} else {
		$result = $mail->send($to);
	}

	if (!$result AND $use_smtp) {
		$result = $mail->send($to);
	}

	if (!$result) {
		if (defined('TECHZONE') or defined('ADMINZONE')) {
			$tos = join(', ', $to);
			$errors = "An error occured while sending mail to $tos.<br />\n";
			if (defined('DEVELOPERMODE')) {
				$errors .= join("<br />\n", $mail->errors);
			}
		} else {
			$errors = "An error occured while sending mail.";
		}
		if (!$silent) {
			print $errors;
			if (defined('DEBUG_EMAIL')) {
				print_rr(func_get_args());
				echo "<hr>";
				print_rr($mail);
			}
		} else {
			return;
		}
		exit;
	}
}

/*****************************************************
	function notify_user

-----DESCRIPTION: -----------------------------------
	- used to send emails to techs based on ticket changes

-----ARGUMENTS: -------------------------------------
	type				:	is either new / reply_tech / new_tech
	ticket				:	this is the full ticket array, used in emails
	user				:	this is the full user details, used in emails
	message				:	this is the last message (for new/reply)
	attachments (opt)	:	array/one of attachments (data, filename, filetype)
	gateway	(opt)		:	(for new ticket) which gateway id this is
	extrainfo (opt)		:	extra variables passed to dp_mail

-----RETURNS:----------------------------------------
	The message mailed to the user.

*****************************************************/

function notify_user($type, $ticket, $user_details, $message, $attachments='', $gateway='', $extrainfo='') {

	$user_details_tmp = $user_details;
	global $db, $settings, $session, $email_footer, $user_details, $dplang;

	$user_details = $user_details_tmp;
	unset($user_details_tmp);

	/*		
		language is only used for user zone emails, so we check first the session of the user
		is initiating the sending of the email. If a tech/admin is initiating then we need
		to check the user setting
	*/

	if (defined('USERZONE')) {
		if ($session['language']) {
			$language = $session['language'];
		} else {
			$language = $settings['default_language'];
		}
	} else {
		if ($user_details['language']) {
			$language = $user['language'];
		} else {
			$language = $settings['default_language'];
		}
	}
	if (!$language) {
		$language = $settings['default_language'];
	}

	/*
		need to get the gateway reply line from $dplang
	*/

	$lang = $db->query_return("
		SELECT text FROM template_words 
		WHERE wordref = 'gateway_reply_cut' 
		AND language = '" . mysql_escape_string($language) . "'
	");

	$dplang['gateway_reply_cut'] = $lang['text'];

	// get attachment data for ticketlog
	if (is_array($attachments)) {
		foreach ($attachments AS $key => $var) {
			$ticketlog_attachments[] = array(
				'name' => $var[name],
				'size' => $var[size]
			);
		}
	}
	$ticketlog_attachments = serialize($ticketlog_attachments);

	/*********************************************
					NEW TICKET (USER)
	*********************************************/
	
	if ($type == 'new_user') {
		
		// web creation
		if ((!$ticket[gatewayid]) AND ($settings[email_autonew])) {
			
			$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE is_default");
			$send = 1;

		// email creation
		} elseif ($settings['email_autonew']) { 

			// get gateway information
			if (!$gateway) { 
				$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE id = '$ticket[gatewayid]'");
			} elseif ($gateway) {
				$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE id = '$gateway'");
			} else {
				$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE is_default");
			}
			if ($gateway[auto_new]) {
				$send = 1;
			}
		}

		if ($send OR ($user_details['awaiting_validation'])) {
			
			if ($ticket['email']) {
				$user_details['email'] = $ticket['email'];
			}

			// if the user is awaiting validation of some sort
			$user_details = update_user_details($user_details);
			if ($user_details[awaiting_validation] OR $user_details[awaiting_manual_validation]) {
				eval(makeemaileval('message', 'BODY_newquestion_validate', $subject, $ticket));
			} else {
				eval(makeemaileval('message', 'BODY_newquestion', $subject, $ticket));
			}

			dp_mail($user_details[email], $subject, trim($message), $gateway[email], $settings[email_return], $attachments, NULL, NULL, NULL, $extrainfo['headers']);	
			
			ticketlog($ticket['id'], 'email_sent_to_user', NULL, NULL, "To: $user_details[email], Subject: $subject", '', $ticketlog_attachments);
		}


	/*********************************************
					NEW TICKET (TECH)
	*********************************************/

	} elseif ($type == 'new_tech') {

		// get the relevant message portions
		$user_message = $message[0];
		$tech_message = $message[1];

		$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE is_default");
		$user_details = update_user_details($user_details);
	
		eval(makeemaileval('message', 'BODY_newquestion_tech', $subject, $ticket));
		dp_mail($user_details[email], $subject, trim($message), $gateway[email], $settings[email_return], $attachments, NULL, NULL, NULL, $extrainfo['headers']);	
			
		ticketlog($ticket['id'], 'email_sent_to_user', NULL, NULL, "To: $user_details[email], Subject: $subject",  '', $ticketlog_attachments);

	/*********************************************
					REPLY TICKET (USER)
	*********************************************/
	
	} elseif ($type == 'reply_user') {
		
		if ($settings[email_autoreply] == "1") {
			if ($gateway) {
				$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE id = '$gateway'");
			} else {
				$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE is_default");
			}

			if ($gateway[auto_reply] == 1) {
				$send = 1;
			}
			
			if ($send) {
				if ($ticket['email']) {
					$user_details['email'] = $ticket['email'];
				}
				if (!$ticket['body'] AND $message) {
					$ticket['body'] = $message;
				}
				
				$user_details = update_user_details($user_details);
				eval(makeemaileval('message', 'BODY_question_user_reply', $subject, $ticket));
				
				dp_mail($user_details[email], $subject, trim($message), $gateway[email], $settings[email_return], $attachments,  NULL, NULL, NULL, $extrainfo['headers']);	
				
				ticketlog($ticket['id'], 'email_sent_to_user', NULL, NULL, "To: $user[email], Subject: $subject", '', $ticketlog_attachments);
			}
		}

	/*********************************************
					NEW REPLY (TECH)
	*********************************************/
	
	} elseif ($type == 'reply_tech') {
		
		if ($gateway) {
			$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE id = '$gateway'");
		} else {
			$gateway = $db->query_return("SELECT * FROM gateway_accounts WHERE is_default");
		}

⌨️ 快捷键说明

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