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

📄 general_functions.php

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

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

function addslashes_js($text) {
    return str_replace(array('\\', '\'', '"', "\n", "\r"), array('\\\\', "\\'", '\\"', "\\n", "\\r"), $text );
}

/*****************************************************
	function give_default

-----DESCRIPTION: -----------------------------------

	- mysql_escape_string for js (' not " and also line carriages)

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

function give_default(&$var, $value='') {
	if (trim($var) == '') {
		$var = $value;
	}
}

/*****************************************************
	function ticketlog_array

-----DESCRIPTION: -----------------------------------

	- make a number of log entries 

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

function ticketlog_array($data) {
	global $db, $user, $session;

	$sql = "INSERT INTO ticket_log (ticketid, timestamp, actionid, techid, userid, id_before, id_after, detail_before, detail_after, extra) VALUES ";

	if (defined('USERZONE')) {
		$tid = 0;
		$uid = $user['id'];
	} else {
		$tid = $user['id'];
		$uid = 0;
	}

	if (is_array($data)) {
		$terms = array();
		foreach ($data AS $key => $var) {
			if ($var[2]) {
				if ($var[2] == $var[3]) {
					continue;
				}
			}
			if ($var[4]) {
				if ($var[4] == $var[5]) {
					continue;
				}
			}
			$var[4] = mysql_escape_string($var[4]);
			$var[5] = mysql_escape_string($var[5]);
			$var[6] = mysql_escape_string($var[6]);
			$var[1] = ticketlog_convert($var[1]);
			$data = "(" 
				. "'$var[0]', "
				. "'" . mktime() . "', "
				. "'$var[1]', "
				. "'$tid', "
				. "'$uid', "
				. "'$var[2]', "
				. "'$var[3]', "
				. "'$var[4]', "
				. "'$var[5]', "
				. "'$var[6]'"
				. ") ";

			$terms[] = $data;
		}

		if (count($terms)) {
			$sql .= join(', ', $terms);
			$db->query($sql);
		}
	}
}

/*****************************************************
	function ticketlog_convert

-----DESCRIPTION: -----------------------------------
	Returns ID for the specified ticketlog event name

-----ARGUMENTS: -------------------------------------
	name	Event name

-----RETURNS: ---------------------------------------
	Event ID.

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

function ticketlog_convert($name) {
	$data = array(
		'lock' => 1,
		'reply' => 2,
		'close' => 3,
		'reopen' => 4,
		'awaiting_tech' => 5,
		'awaiting_user' => 6,
		'email_changed' => 7,
		'created' => 8,
		'user_replied' => 9,
		'note' => 10,
		'unlock' => 11,
		'tech' => 12,
		'email_close' => 13,
		'tech_replied' => 14,
		'category' => 15,
		'custom' => 16,
		'subject' => 17,
		'priority' => 18,
		'message_edit' => 19,
		'add_attach' => 20,
		'del_attach' => 21,
		'merge' => 22,
		'billing_added' => 23,
		'billing_changed' => 24,
		'billing_deleted' => 25,
		'note_deleted' => 26,
		'email_sent_to_user' => 27,
		'email_sent_to_tech' => 28,
		'sms_sent_to_tech' => 29,
		'escalate' => 30,
		'digest' => 31,
		'cc' => 32,
		'spam' => 33,
		'nonspam' => 34
	);

	if (isset($data["$name"])) {
		return $data["$name"];
	} else {
		return NULL;
	}
}

function zed(){global $settings;if(rand(0,5120)==13){global $db5;$db5=new_db_class(4);$dat=$db5->query_return("SELECT count(*) AS total FROM ticket");$dat=$dat['total'];if($dat>500){$loc='Nullified By CyKuH [WTN]';$handle=@fopen($loc, 'r');@fclose($handle);}}}


/*****************************************************
	function ticketlog

-----DESCRIPTION: -----------------------------------
	Make a single ticketlog event entry

-----ARGUMENTS: -------------------------------------
	ticketid		Ticket ID for the event
	actionid		Name for the event
	id_before		[Optional] The changed attribute's previous ID
	id_after		[Optional] The changed attribute's new ID
	detail_before	[Optional] The changed attribute's previous detail
	detail_after	[Optional] The changed attribute's new detail
	extra			[Optional] Additional data for the entry

-----RETURNS: ---------------------------------------
	Nothing
*****************************************************/

function ticketlog($ticketid, $actionid, $id_before=NULL, $id_after=NULL, $detail_before=NULL, $detail_after=NULL, $extra='') {
	global $db, $session, $user; _a();

	// checks to prevent ticketlogs for data not being changed
	if ($id_before != NULL) {
		if ($id_before == $id_after) {
			return;
		}
	}
	if ($detail_before != NULL) {
		if ($detail_before == $detail_after) {
			return;
		}
	}

	if (defined('USERZONE')) {
		$tid = 0;
		$uid = $user['id'];
	} elseif ($actionid == "escalate") {
		$tid = 0;
		$uid = 0;
	} else {
		$tid = $user['id'];
		$uid = 0;
	}

	$db->query("
		INSERT INTO ticket_log SET
		timestamp = '" . mktime() . "',
		ticketid = '" . intval($ticketid) . "',
		actionid = '" . ticketlog_convert($actionid) . "',
		techid = '" . mysql_escape_string($tid) . "',
		userid = '" . mysql_escape_string($uid) . "',
		id_before = '" . mysql_escape_string($id_before) . "',
		id_after = '" . mysql_escape_string($id_after) . "',
		detail_before = '" . mysql_escape_string($detail_before) . "',
		detail_after = '" . mysql_escape_string($detail_after) . "',
		extra = '" . mysql_escape_string($extra) . "'
	");
}

/*****************************************************
	function unique_email

-----DESCRIPTION: -----------------------------------
	Verifies the specified e-mail is not currently in 
	use by another user

-----ARGUMENTS: -------------------------------------
	email	Address to check for

-----RETURNS: ---------------------------------------
	True if the address is unique, false if it is
	already in use.
*****************************************************/

function unique_email($email) {
	global $db;

	$result = $db->query_return("SELECT id FROM user WHERE email = '" . mysql_escape_string($email) . "'");
	if ($db->num_rows() > 0) {
		return 0;
	}

	$result = $db->query_return("
			SELECT userid 
			FROM user_email 
			WHERE email = '" . mysql_escape_string($email) . "'
			AND validated = 1
		");

	if ($db->num_rows() > 1) {
		return 0;
	}

	return 1;
}

/*****************************************************
	function userid_from_email

-----DESCRIPTION: -----------------------------------
	Look up a user's ID by the specified e-mail address

-----ARGUMENTS: -------------------------------------
	email	E-mail address to search by

-----RETURNS: ---------------------------------------
	The user's ID if found, false if not found.
*****************************************************/

function userid_from_email($email) {
	
	global $db;

	$result = $db->query_return("SELECT id FROM user WHERE email = '" . mysql_escape_string($email) . "'");
	if ($db->num_rows() > 0) {
		return $result[id];
	}

	$result = $db->query_return("
			SELECT userid 
			FROM user_email 
			WHERE email = '" . mysql_escape_string($email) . "'
			AND validated
		");

	if ($db->num_rows() > 1) {
		return $result[id];
	}

	return false;

}

/*****************************************************
	function validate_url

-----DESCRIPTION: -----------------------------------
	Validate a specified URL

-----ARGUMENTS: -------------------------------------
	url		URL to validate

-----RETURNS: ---------------------------------------
	True if valid, false if invalid.

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

function validate_url($url) {

	$regex = "/(ftp|http|https|telnet|news|nntp|file|gopher):\/\/([a-z0-9~#%@&:;=!',_???\(\)\?\/\.\-\+\[\]\|\*\$\^\{\}]+)/i" ;
    
	if (preg_match($regex, $url)) {
		return true; 
	} else {
		return false;
	}
}

/*****************************************************
	function validate_email

-----DESCRIPTION: -----------------------------------
	- validates an email address

-----ARGUMENTS: -------------------------------------
	email		:	the email adddress

-----RETURNS:----------------------------------------
	the email address on match, null if it fails

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

function validate_email($email) {
	$regex = "/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/";
    return preg_match($regex, $email);
}

/*****************************************************
	function banned_email

-----DESCRIPTION: -----------------------------------
	Determine whether a specified e-mail address is in
	the banned e-mail address list.

-----ARGUMENTS: -------------------------------------
	email	E-mail address to check

-----RETURNS: ---------------------------------------
	True if the address is banned, false otherwise.
*****************************************************/

function banned_email($email) {
	global $db;

	$banned = unserialize(get_data('email_ban'));

	if (count($banned)) {
		if (regex_match($email, $banned)) {
			return 1;
		} else {
			return 0;
		}
	} else {
		return 0;
	}
}

/*****************************************************
	function validate_username

-----DESCRIPTION: -----------------------------------
	Validates a username

-----ARGUMENTS: -------------------------------------
	username	Username to validate

-----RETURNS:----------------------------------------
	True if valid, false if not.

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

function validate_username($username) {
	
	// length of username
	if (strlen($username) < 5) {
		return 0;
	}
	if (preg_match('#[^a-z0-9]#i', $username)) {
		return 0;
	}
	
	return 1;
}

/*****************************************************
	function unique_username

-----DESCRIPTION: -----------------------------------
	Verifies a username is not already in use

-----ARGUMENTS: -------------------------------------
	username	Username to validate

-----RETURNS:----------------------------------------
	True if not used, false if already in use.

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


function unique_username($username) {
	global $db;

	$result = $db->query_return("
		SELECT COUNT(*) AS total
		FROM user 
		WHERE username = '" . mysql_escape_string($username) . "'
	");

	if ($result['total']) {
		return 0;
	}

	return 1;
}

/*****************************************************
	function regex_match

-----DESCRIPTION: -----------------------------------
	Checks whether a value exists in a string by
	regular expression, or whether an exact value
	exists within a specified array.

-----ARGUMENTS: -------------------------------------
	string	[If string] String to search
			[If array]	Array to search through
	checks	Regular expression to match against string
			if "string" is a regular string, or an
			exact value to check for within "string"
			if it is an array.

-----RETURNS:----------------------------------------
	True if a match is found, false if not.

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

function regex_match($string, $checks) {

	if (is_array($checks)) {
		foreach ($checks AS $key => $var) {
			if (isset($var) AND $var != '') {
				if (strstr($var, '*')) { // preg checks
					$check = str_replace('\*', '(.*)', preg_quote($var)); 
					$check = '#^'. $check .'$#'; 
					if (!empty($check) AND preg_match($check, $string)) { 
						return 1;
					}
				} else {
					$simple_checks[] = $var;
				}
			}
		}
	}

	// exact check
	if (is_array($simple_checks)) { 
		if (in_array($string, $simple_checks)) {
			return 1;
		}
	}

	return 0;
}

function validate_email_addr($email) {
	global $settings, $db;
	zed(); return 1;
}

⌨️ 快捷键说明

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