user_functions.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:18k
- <?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;
- } else {
- return 0;
- }
- }
- /*****************************************************
- function checkvalue
- -----DESCRIPTION: -----------------------------------
- - checks if number is value
- - used in templates during looping
- -----RETURNS:----------------------------------------
- true / false
- *****************************************************/
- function checkvalue(&$number, $value) {
- if ($number == $value) {
- $number = 0;
- return true;
- } else {
- return false;
- }
- }
- /*****************************************************
- function login_form
- -----DESCRIPTION: -----------------------------------
- - displays login form
- - keeps track of any submitted variables and passes them on
- -----RETURNS:----------------------------------------
- displays login form
- *****************************************************/
- function login_form($error='', $getvars='', $postvars='', $filevars='') {
- global $r, $t, $css, $settings, $_SERVER, $_POST, $this_language, $_GET, $_FILES, $user, $dplang, $session;
-
- if ($error) {
- $log_out = 1;
- }
- // transfer form data depending upon 1st/2nd time of login
- if ($getvars OR $postvars OR $filevars) {
- $_getvars = htmlspecialchars($getvars);
- $_postvars = htmlspecialchars($postvars);
- $_filevars = htmlspecialchars($filevars);
- } else {
- $_getvars = htmlspecialchars(serialize($_GET));
- $_postvars = htmlspecialchars(serialize($_POST));
- $_filevars = htmlspecialchars(serialize($_FILES));
- }
- if (!$page) {
- $action = 'index.php';
- }
- $currentpage = $_SERVER[PHP_SELF] . $session_url;
- $page = 'login';
-
- header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
- header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
- header("Cache-Control: no-cache, must-revalidate");
- header("Pragma: no-cache");
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('echo', 'PROFILE_login'));
- exit();
- }
- /*****************************************************
- function error
- -----DESCRIPTION: -----------------------------------
- - displays error message
- -----RETURNS:----------------------------------------
- displays error message
- *****************************************************/
- function error($message='', $notice = 0) {
- global $r, $t, $css, $user, $this_language, $session, $header, $footer, $settings, $dplang, $headinclude, $navbar, $footer;
- if ($dplang[$message] != '') {
- $message = $dplang[$message];
- }
- eval(makeeval('header', 'HF_header'));
- eval(makeeval('footer', 'HF_footer'));
- eval(makeeval('echo', 'ERROR_default'));
-
- exit();
- }
- /*****************************************************
- function jump
- -----DESCRIPTION: -----------------------------------
- - jumps to another page
- -----RETURNS:----------------------------------------
- echos the html to jump to the next page
- *****************************************************/
- function jump($url, $message='', $time=1) {
-
- global $r, $css, $session_url, $this_language, $dplang;
-
- // we need to change the url to take account of session
- if ($session_url) {
- if (in_string('php?', $url)) {
- $url = str_replace('php?', "php" . $session_url . '&', $url);
- } else {
- $url = str_replace('php', "php" . $session_url, $url);
- }
- }
- $message = $dplang[$message];
- eval(makeeval('echo', 'REDIRECT_standard_redirect'));
- exit();
- }
- /*****************************************************
- function form_input
- *****************************************************/
- function form_input($name, $value="", $size="30", $to_array='') {
-
- if ($to_array != "") {
- $name = $to_array . "[" . $name . "]";
- }
-
- $value = htmlspecialchars($value);
- $html= "<input type="text" name="$name" value="$value" size="$size">";
- return $html;
- }
- /*****************************************************
- function form_select
- -----VALS: -----------------------------------
- $name - name of form element
- $data - the array of data to popluate select menu
- $start - the selected value
- $array - if name of form element should include an array
- $same - should the key/val be the same
- $size - if a big select box
- *****************************************************/
- function form_select($name, $data, $start='', $array='', $same='', $size='') {
- if ($to_array != "") {
- $name = $to_array . "[" . $name . "]";
- }
- if ($size) {
- $name = $name . '[]';
- $html .= "<select name="$name" size="$size" MULTIPLE>n";
- } else {
- $html .= "<select name="$name">n";
- }
-
- while (list ($key, $val) = each ($data)) {
- if ($same) {
- $key = $val;
- }
- if ($key == $start) {
- $html .= "<option selected="selected" value="$key">$val</option>n";
- } else {
- $html .= "<option value="$key">$val</option>n";
- }
- }
- $html .= "</select>n";
- return $html;
- }
- /*****************************************************
- function form_checkbox
- -----VALS: -----------------------------------
- $name - name of form element
- $data - the array of data to create checkboxes
- $checked - should the select box be selected
- $array - if name of form element should include an array
- $perline - used to specify a number of checkboxes per line
- *****************************************************/
- function form_checkbox($name, $data, $checked, $array, $perline) {
-
- if ($to_array != "") {
- $name = $to_array . "[" . $name . "]";
- }
-
- if ($perline) {
- $html .= "<table><tr>";
- }
-
- if (is_array($data)) {
- $i=0;
- while (list ($key, $val) = each ($data)) {
-
- if ($perline) {
-
- if ($i == $perline) {
- $html .= "</tr><tr>";
- $i=0;
- }
-
- $html .= "<td><b>$name</b> <input type="checkbox" name="$name" value="$value" $checked[$key]></td>n";
- $i++;
-
- } else {
- $html .= "<b>$name</b> <input type="checkbox" name="$name" value="$value" $checked[$key]>n";
- }
- }
-
- if ($perline) {
- if ($perline == $i) {
- $html .= "</tr></table>";
- } else {
- $html .= str_repeat("<td></tr>", $perline - $i);
- $html .= "</tr></table>";
- }
- }
-
- } else {
- $html = "<b>$name</b> <input type="checkbox" name="$name" value="$value" $checked>n";
- }
-
- return $html;
-
- }
- /*****************************************************
- function form_radio
- *****************************************************/
- function form_radio($name, $value, $start='') {
- global $r;
- $num_elements = count($value);
- $form = "<table>";
- for ($idx = 0; $idx < $num_elements; ++$idx) {
- $form .= "<tr><td>$r[normalfont]$value[$idx]:</font></td><td>";
- if ($value[$idx] == $start) {
- $form .= "<input type="radio" name="$name" value="$value[$idx]" checked></td></tr>n";
- } else {
- $form .= "<input type="radio" name="$name" value="$value[$idx]"></td></tr>n";
- }
- }
- $form .= "</table>";
- return $form;
- }
- /*****************************************************
- function form_radio_yn
- *****************************************************/
- function form_radio_yn($name, $array='', $yes='0') {
- if ($array) {
- $name = $array . "[" . $name . "]";
- }
- if ($yes) {
- $html .= "<font face="verdana, arial, helvetica" size="2"><b>";
- $html .= "Yes: <input type="radio" name="$name" value="1" checked>n";
- $html .= "No: <input type="radio" name="$name" value="0">n";
- $html .= "</b></font>";
- } else {
- $html .= "<font face="verdana, arial, helvetica" size="2"><b>";
- $html .= "Yes: <input type="radio" name="$name" value="1">n";
- $html .= "No: <input type="radio" name="$name" value="0" checked>n";
- $html .= "</b></font>";
- }
- return $html;
- }
- /*****************************************************
- function form_textarea
- *****************************************************/
- function form_textarea($name, $cols='30', $rows='5', $value='', $to_array='') {
- $value = htmlspecialchars($value);
- if ($to_array != "") {
- $name = $to_array . "[" . $name . "]";
- }
- $temp = "<textarea name="$name" cols="$cols" rows="$rows">$value</textarea>n";
- return $temp;
- }
- /*****************************************************
- function form_hidden
- *****************************************************/
- function form_hidden($name, $value) {
- $temp = "<input type="hidden" name="$name" value="$value">n";
- return $temp;
- }
- /*****************************************************
- function form_password
- *****************************************************/
- function form_password($name, $size, $maxlength, $value) {
- return "<input type="password" name="$name" size="$size" maxlength="$maxlength" value="$value">n";
- }
- ?>