📄 user_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: user_functions.php,v $
// | $Date: 2004/02/10 01:34:25 $
// | $Revision: 1.31 $
// +-------------------------------------------------------------+
// | File Details:
// | - Utility functions for the user interface
// +-------------------------------------------------------------+
error_reporting(E_ALL ^ E_NOTICE);
/*****************************************************
function check_user
-----DESCRIPTION: -----------------------------------
- runs user_p_check for checks on logged in users
- displays login form if user is not logged in
-----RETURNS:----------------------------------------
true or displays login form
*****************************************************/
function check_user($skip = 0) {
global $user, $session;
if (!$skip) {
user_p_checks();
}
if ($user OR $session[userid]) {
return 1;
} else {
login_form();
}
}
/*****************************************************
function user_p_checks
-----DESCRIPTION: -----------------------------------
- a number of checks run on a registered user who
is not quite a "full" user because something needs to be completed.
In the future this should be replaced with user groups
-----RETURNS:----------------------------------------
directly prints any errors, starting in the order the user
can do something about
*****************************************************/
function user_p_checks() {
global $user, $dplang;
// user needs to validate themselves
if ($user[awaiting_validation]) {
error($dplang['error_awaiting_validation'] . " <a href=\"profile.php?do=resend_welcome\">$dplang[click_here]</a>.", 1);
}
// user awaiting tech to validate them
if ($user[awaiting_manual_validation]) {
error($dplang['error_awaiting_manual_validation'], 1);
}
}
/*******************************************************
function user_category_array
---- DESCRIPTION: --------------------------------------
Replace names of non-user-viewable categories with the
display name for the selected display category.
---- RETURN: -------------------------------------------
An array containing re-mapped categories (categories
that are not meant to be shown to users are given
the "displayed" name here)
********************************************************/
function user_category_array($location='new') {
global $db, $session, $settings;
// categories not viewable to users
if (!$settings[category_user_viewable]) {
return false;
}
// do users get to pick the category on new ticket?
if ($location == 'new' AND !$settings[category_user_start]) {
return false;
}
// do users get to edit the ticket category?
if ($location == 'edit' AND !$settings[category_user_editable]) {
return false;
}
// still here so we are getting some categories
// if we are not logged in, only categories for logged out users picked
if (!$session[userid]) {
$term = 'WHERE require_registration = 0';
}
// get category data
$categories = $db->query_return_array("SELECT * FROM ticket_cat $term ORDER by cat_order");
// no categories?
if (!$db->num_rows()) {
return false;
}
foreach ($categories AS $category) {
if (!$category['user_view']) {
$cat_replace[$category['id']] = $category['show_category'];
}
if (!$category['user_select'] AND ($location == 'edit' OR $location == 'new')) {
$cat_replace[$category['id']] = 1;
}
}
// check on language
if ($session[language] == $settings[default_language]) {
foreach ($categories AS $cat) {
$cats[$cat[id]] = $cat[name];
}
} else {
// get category languages
if (!$category_languages) {
$category_languages = unserialize(get_data('category_languages'));
}
foreach ($categories AS $cat) {
if ($category_languages[$session[language]][$cat[id]]['name'] != '') {
$cats[$cat[id]] = $category_languages[$session[language]][$cat[id]]['name'];
} else {
$cats[$cat[id]] = $cat[name];
}
}
}
if (is_array($cat_replace)) {
foreach ($cat_replace AS $repl => $with) {
if ($location == 'edit' OR $location == 'new') {
unset($cats[$repl]);
} else {
$cats[$repl] = $cats[$with];
}
}
}
return $cats;
}
/*******************************************************
function user_priority_array
---- DESCRIPTION: --------------------------------------
Replace names of non-user-viewable priorities with the
display name for the selected display priority.
---- RETURN: -------------------------------------------
An array containing re-mapped priorities (priorities
that are not meant to be shown to users are given
the "displayed" name here)
********************************************************/
function user_priority_array($location='new') {
global $db, $session, $settings;
// priorities not viewable to users
if (!$settings[priority_user_viewable]) {
return false;
}
// do users get to pick the priority on new ticket?
if ($location == 'new' AND !$settings[priority_user_start]) {
return false;
}
// do users get to edit the ticket priority?
if ($location == 'edit' AND !$settings[priority_user_editable]) {
return false;
}
// still here so we are getting some priorities
// if we are not logged in, only priorities for logged out users picked
if (!$session[userid]) {
$term = 'WHERE require_registration = 0';
}
// get priority data
$priorities = $db->query_return_array("SELECT * FROM ticket_pri $term ORDER by pri_order");
// no priorities?
if (!$db->num_rows()) {
return false;
}
foreach ($priorities AS $priority) {
if (!$priority['user_view']) {
$pri_replace[$priority['id']] = $priority['show_priority'];
}
if (!$priority['user_select'] AND ($location == 'edit' OR $location == 'new')) {
$pri_replace[$priority['id']] = 1;
}
}
// check on language
if ($session[language] == $settings[default_language]) {
foreach ($priorities AS $pri) {
$pris[$pri[id]] = $pri[name];
}
} else {
// get priority languages
if (!$priority_languages) {
$priority_languages = unserialize(get_data('priority_languages'));
}
foreach ($priorities AS $pri) {
if ($priority_languages[$session[language]][$pri[id]]['name'] != '') {
$pris[$pri[id]] = $priority_languages[$session[language]][$pri[id]]['name'];
} else {
$pris[$pri[id]] = $pri[name];
}
}
}
if (is_array($pri_replace)) {
foreach ($pri_replace AS $repl => $with) {
if ($location == 'edit' OR $location == 'new') {
unset($pris[$repl]);
} else {
$pris[$repl] = $pris[$with];
}
}
}
return $pris;
}
/*****************************************************
function make_password
-----DESCRIPTION: -----------------------------------
- makes a password
-----RETURNS:----------------------------------------
8 alphanumeric keys
*****************************************************/
function make_password() {
return substr(md5(time()),0,8);
}
/*****************************************************
function get_replacements
-----DESCRIPTION: -----------------------------------
- gets and parses the replacement variables
- evals() them in the presence of the settings variables and themselves
-----RETURNS:----------------------------------------
true
*****************************************************/
function get_replacements() {
global $db, $settings, $r;
$db->query("SELECT name, value from template_replace");
while ($replace = $db->row_array()) {
$r[$replace[name]] = $replace[value];
}
foreach ($r AS $key => $var) {
eval("\$r[$key] = \"" . $var . "\";");
}
}
/*****************************************************
function add_navigation
-----DESCRIPTION: -----------------------------------
- navigation for user interface
-----RETURNS:----------------------------------------
the html
*****************************************************/
function add_navigation($name, $url) {
return ' // ' . "<a class=\"light\" href=\"$url\">$name</a>";
}
/*****************************************************
function divides
-----DESCRIPTION: -----------------------------------
- checks if a number is divisible.
-----RETURNS:----------------------------------------
true / false
*****************************************************/
function divides($number, $value) {
if (is_int($number / $value)) {
return 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -