📄 admin-tech_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: admin-tech_functions.php,v $
// | $Date: 2004/02/12 21:16:57 $
// | $Revision: 1.179 $
// +-------------------------------------------------------------+
// | File Details:
// | - Utility functions for the administration and user interfaces
// +-------------------------------------------------------------+
error_reporting(E_ALL ^ E_NOTICE);
/*****************************************************
function language_check
-----DESCRIPTION: -----------------------------------
Determine whether multiple language handling is enabled or not
because it only makes sense if there is a language to actually
use as well as the default language
-----RETURNS: ---------------------------------------
TRUE if yes, FALSE if no.
*****************************************************/
function language_check() {
global $db, $settings;
if ($settings[language_on]) {
$db->query("SELECT id FROM languages WHERE is_selectable AND id != '$settings[default_language]'");
if (!$db->num_rows()) {
unset($settings[language_on]);
return FALSE;
} else {
return TRUE;
}
}
}
/*****************************************************
functions reload_index and reload_index_nourl and reload_index_frameset
-----DESCRIPTION: -----------------------------------
Generate a JavaScript segment that automatically redirects the browser to
the index page to enforce the use of frames. Used for frames that should
never be viewed outside of the tech interface frameset.
reload_index_nourl ignores the requested URL and redirects straight back
to home/index.php.
reload_index_frameset does the reverse and is used for tech/home/index.php;
if the browser *is* in a frameset, break out and start it over again
-----RETURNS:----------------------------------------
None; directly produces output.
*****************************************************/
function reload_index() {
?>
<SCRIPT language="JavaScript">
if (parent.location.href == self.location.href) {
window.location.href = "./index.php?url=" + self.location.href;
}
</SCRIPT>
<?php
}
function reload_index_nourl() {
?>
<SCRIPT language="JavaScript">
if (parent.location.href == self.location.href) {
window.location.href = "./index.php";
}
</SCRIPT>
<?php
}
function reload_index_frameset() {
?>
<SCRIPT language="JavaScript">
if (parent.location.href != self.location.href) {
window.location.href = "./index.php";
}
</SCRIPT>
<?php
}
/*****************************************************
function p_ticket
-----DESCRIPTION: -----------------------------------
Determines whether the current tech has permission to perform specific
tasks involving the current ticket.
-----ARGUMENTS: -------------------------------------
action The action the tech is trying to perform
edit Edit the ticket (or its attachments, messages, etc.)
view View the ticket (or its attachments, messages, etc.)
delete Delete the ticket entirely
close Close or re-open the ticket
ticket [Optional] Ticket data array
-----RETURNS:----------------------------------------
TRUE if the technician has permission, FALSE if not.
*****************************************************/
function p_ticket($action, $ticket='') {
global $user;
if (!$ticket) {
global $ticket;
}
// We're not letting the user do *anything* if he's banned from this category
$bannedcats = split(',', $user[cats_admin]);
if ((in_array($ticket[category], $bannedcats))) {
return 0;
}
if ($action == 'edit') {
// ticket owned by user
if ($ticket['tech'] == $user[id]) {
return 1;
}
// user has permission to edit others tickets (make sure ticket is not locked)
if ($user[p_tech_edit] == '1' AND $ticket[tech] != $user[id] AND $ticket[is_locked] != '1') {
return 1;
}
// not owned by anyone
if (($ticket[tech] == '0') OR ($ticket[tech] == '')) {
return 1;
}
} elseif ($action == 'view') {
// can edit own tickets
if ($ticket[tech] == $user[id]) {
return 1;
}
// check to view others tickets
if ($user[p_tech_view] == '1') {
return 1;
}
// unassigned
if (($ticket[tech] == '0') OR ($ticket[tech] == '')) {
return 1;
}
} elseif ($action == 'delete') {
// delete own tickets
if (($ticket[tech] == $user[id]) AND ($user[p_delete_own] == '1')) {
return 1;
}
// delete others tickets
if (($ticket[tech] != $user[id]) AND ($user[p_delete_other] == '1')) {
return 1;
}
} elseif ($action == 'close') {
// close own tickets
if (($ticket[tech] == $user[id]) AND ($user[p_close_ticket] == '1')) {
return 1;
}
// close others tickets (also need to be able to edit others tickets)
if (($ticket[tech] != $user[id]) AND ($user['p_tech_edit']) AND ($user[p_close_ticket] == '1')) {
return 1;
}
}
return 0;
}
/*****************************************************
function change_index
-----DESCRIPTION: -----------------------------------
- Changes is the index with an assoicative array
*****************************************************/
function change_index($array, $new_index) {
if (is_array($array)) {
foreach ($array AS $key => $var) {
$tmp[$new_index[$key]] = $var;
}
}
return $tmp;
}
/*****************************************************
function error_marker
-----DESCRIPTION: -----------------------------------
Reformats fields differently if they appear in the global value $error_array.
-----ARGUMENTS: -------------------------------------
fieldname The field name to check.
-----GLOBALS: -------------------------------------
error_array The array of errors to check
-----RETURNS:----------------------------------------
If the field is in the array, returns HTML to show the field.
Nothing otherwise.
*****************************************************/
function error_marker($fieldname) {
global $error_array;
if (is_array($error_array)) {
if (in_array($fieldname, $error_array)) {
return "<font color=\"red\"><b>*</b></font> ";
}
}
}
/*****************************************************
function pagenav
-----DESCRIPTION: -----------------------------------
Generate links to navigate multiple page result sets.
-----ARGUMENTS: -------------------------------------
total The total number of entries
perpage Entries shown per page
start Starting entry being viewed
link Base URL to use for all links
form [T/F] Generate form widgets instead of links.
type Show select box and links, or just select box
select Box and links
select_only Box only
elementname The variable containing the identifier value
-----RETURNS:----------------------------------------
HTML to display the navigation links.
*****************************************************/
function pagenav($total, $perpage='20', $start='1', $link, $form, $type, $elementname='searchvalue') {
$pages = ceil($total / $perpage);
if ($pages == 1) {
return '';
}
$html = "<table width=\"300\" align=\"center\"><tr>";
if ($type == "select") {
if ($start > 2) {
if ($form) {
$html .= "<td><a href=\"javascript:submitform('$form','$elementname','1');\">Page 1</a></td>";
} else {
$html .= "<td><a href=\"$link&$elementname=1\">Page 1</a></td>";
}
}
if ($start > 1) {
if ($form) {
$html .= "<td><a href=\"javascript:submitform('$form','$elementname','" . ($start - 1) . "');\">Previous</a></td>";
} else {
$html .= "<td><a href=\"$link\">Previous</a></td>";
}
}
}
if ($type == "select_only" OR $type == "select") {
if ($form) {
$html .= "<td><select name=\"$elementname\" onchange=\"this.form.submit();\">";
} else {
$html .= "<td><select name=\"$elementname\">";
}
for ($i = 1; $i <= $pages; $i++) {
if ($i == $start) {
$selected = ' selected="selected"';
}
$html .= "<option value=\"$i\"$selected>Page $i</option>";
unset($selected);
}
$html .= "</td>";
}
if ($type == "select") {
if (($pages - $start) >= 2) {
if ($form) {
$html .= "<td><a href=\"javascript:submitform('$form','$elementname','" . ($start + 1) . "');\">Next</a></td>";
} else {
$html .= "<td><a href=\"$link\">Previous</a></td>";
}
}
if (($pages - $start) >= 1) {
if ($form) {
$html .= "<td><a href=\"javascript:submitform('$form','$elementname','$pages');\">Page $pages</a></td>";
} else {
$html .= "<td><a href=\"$link\">Page 1</a></td>";
}
}
}
$html .= "</tr></table>";
return $html;
}
/*****************************************************
function alert
-----DESCRIPTION: -----------------------------------
Create a JavaScript alert to display a message.
-----ARGUMENTS: -------------------------------------
text Text to display in the alert box.
-----RETURNS:----------------------------------------
None; directly generates output
*****************************************************/
function alert($text) {
$text = addslashes_js($text);
echo "<SCRIPT language=\"javascript\">
alert('$text');
</SCRIPT>";
}
/*****************************************************
function make_numberarray
-----DESCRIPTION: -----------------------------------
Create an array of numbers.
-----ARGUMENTS: -------------------------------------
start First number
end Last number
empty [T/F] Generate an empty first value
-----RETURNS:----------------------------------------
Array containing the generated number sequence.
*****************************************************/
function make_numberarray($start, $end, $empty='') {
if ($empty) {
$array[0] = '';
}
for ($i = $start; $i < ($end + 1); $i++) {
$array[$i] = $i;
}
return ($array);
}
/*****************************************************
function array_order / array_order2
-----DESCRIPTION: -----------------------------------
Functions used by usort() for ordering.
*****************************************************/
function array_order($a, $b) {
return $a[0] - $b[0];
}
function array_order2($a, $b) {
return $a[1] - $b[1];
}
/*****************************************************
function table_header
-----DESCRIPTION: -----------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -