admin-tech_functions.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:99k
- <?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: -----------------------------------
- Create a table header.
- -----ARGUMENTS: -------------------------------------
- title Table title
- action [Optional] If specified, generate a form start tag that submits to this file.
- hidden [Optional] Associative array of hidden variables for a form
- show [Optional] [T/F] Expand the table by default
- name [Optional] Name of generated form
- binary [Optional] [T/F] Form is a binary submission form.
- js [Optional] JavaScript to fire on form submit.
- -----RETURNS:----------------------------------------
- None; directly generates HTML.
- *****************************************************/
- function table_header ($title, $action='', $hidden = '', $show = '', $name = '', $binary = '', $js = '') {
- global $settings;
- $title = str_replace('<a href=', '<a class='titl' href=', $title);
- $title2 = $title . "2";
- $js_title = addslashes_js($title);
- $js_title2 = addslashes_js($title2);
- if (!$name) {
- $name2 = explode(' ', $title);
- if ($name2 == ' ') {
- $name = $title;
- } else {
- $name = $name2[1];
- }
- }
- echo "nn<!-- Begin table $title -->nn";
-
- if ($action) {
- $form = "<form action="$action" method="post" name="$name"" . iff($binary, "enctype="multipart/form-data"") . iff($js, $js) . ">n";
- }
-
- if (is_array($hidden)) {
- while (list ($key, $value) = each ($hidden)) {
- $form .= form_hidden($key, $value);
- }
- }
- echo $form;
- echo "
- <div id="$title2">
- <table border="0" cellspacing="0" cellpadding="0" height="21" width="100%">
- <tr>
- <td width="19" bgcolor="#BF4343" align="center">" .
- html_image('spacer.gif', 3) .
- html_image('tech/bul040.gif', 13, 14) .
- html_image('spacer.gif', 3) .
- "</td>
- <td width="10" align="center" bgcolor="#727272">" .
- html_image('spacer.gif', 10) .
- "</td>
- <td nowrap="nowrap" bgcolor="#727272"><div class="tit1">
- <B>$title</B> <a href="javascript:void(0)" onclick="oc('$js_title2');oc('$js_title');">" .
- html_image('tech/bul100.gif') .
- "</a></td>
- </tr>
- </table></div>";
- echo "
- <div id="$title">
- <table border="0" cellspacing="0" cellpadding="0" height="21" width="100%">
- <tr>
- <td width="19" bgcolor="#BF4343" align="center"><img src="".constant('LOC_IMAGES')."spacer.gif" width="3"><img src="".constant('LOC_IMAGES')."tech/bul040.gif" width="13" height="14"><img src="".constant('LOC_IMAGES')."spacer.gif" width="3"></td>
- <td width="10" align="center" bgcolor="#727272"><img src="".constant('LOC_IMAGES')."spacer.gif" width="10"></td>
- <td nowrap="nowrap" bgcolor="#727272"><div class="tit1">
- <b>$title</b> <a href="javascript:void(0)" onclick="oc('$js_title2');oc('$js_title');"><img src="".constant('LOC_IMAGES')."tech/bul101.gif" border=0></a>
- </td>
- <td width="10" align="center" bgcolor="#727272"> </td>
- <td bgcolor="#A4A4A4" width="100%">
- </tr></table>
-
- <table border="0" cellpadding="5" width="100%" align="center" cellspacing="0">
- ";
- echo "<SCRIPT language="javascript">";
- if (!$show) {
- echo "oc('$js_title2');";
- } else {
- echo "oc('$js_title');";
- }
- echo "</SCRIPT>";
-
- }
- function redirect_button($value, $url, $name="button") {
- return "<input type="button" name="$name" value="$value" onclick="javascript:top.center.location='$url'">";
- }
- /*****************************************************
- function table_footer
- -----DESCRIPTION: -----------------------------------
- Produce the table footer to close a table started by table_header.
- -----ARGUMENTS: -------------------------------------
- submit [Optional] Displayed value of the submit button (if any)
- align [Optional] Alignment of the button
- extra [Optional] Additional text to show next to the Submit button
- nospace [Optional] [T/F] Do NOT produce a <br /> tag after the table close tag
- js [Optional] Additional JS to fire on form submission.
- submitname [Optional] Name of the submit button.
- -----RETURNS:----------------------------------------
- None; directly generates output.
- *****************************************************/
- function table_footer ($submit='', $align='center', $extra='', $nospace='', $js='', $submitname = 'submit') {
- if (!$align) {
- $align = 'center';
- }
- if ($submit OR $extra) {
- if ($submit) {
- $submit = "<input type="submit" name="$submitname" value="$submit"$js>";
- }
-
- echo "<tr align="$align"><td colspan="50" class="footerCell">";
- echo " $extra $submit</td></tr>" . iff($submit, "</form>") . "</table>";
-
- } else {
- echo "<tr align="$align"><td colspan="50"> $extra</td></tr></table>";
- }
- echo "</div>";
- if (!$nospace) {
- echo "<br />";
- }
- }
- /*****************************************************
- function table_content
- -----DESCRIPTION: -----------------------------------
- Generate HTML content of a table started by table_header
- -----ARGUMENTS: -------------------------------------
- columns An array containing the names of columns defined in the next argument
- rows An array containing individual rows of data (each row should be an array)
- lines [Optional] An array containing additional rows; row keys here matching row keys in
- the "rows" argument are displayed as expandable detail rows
- class *** Deprecated -- to be removed ***
- top_html [Optional] Additional row of HTML to display before any rows (including the
- "columns" row
- bottomline [Optional] Additional row of HTML to display as an expandable row at the bottom of the table.
- width [Optional] An array of widths (element count should match the number of columns)
- secondrow [Optional] Additional content below the columns
- -----RETURNS:----------------------------------------
- None; directly generates output
- *****************************************************/
- function table_content($columns, $rows, $lines='', $class='', $top_html='', $bottomline='', $width='', $secondrow='') {
-
- // expand arrays if bottomline specified
- if (is_array($bottomline)) {
- $javascript = "<SCRIPT>n";
- while (list ($key, $val) = each ($rows)) {
- if (count($rows[$key]) != 1) {
- if (trim($bottomline[$key]) != '') {
- $key_image1 = $key . 'image1';
- $key_image2 = $key . 'image2';
- array_unshift($rows[$key], "<img align="center" id="$key_image1" src="" . constant('LOC_IMAGES') . "tech/bul101.gif" onclick="oc('$key');oc('$key_image1');oc('$key_image2');"><img align="center" id="$key_image2" src="" . constant('LOC_IMAGES') . "tech/bul100.gif" onclick="oc('$key');oc('$key_image1');oc('$key_image2');">");
- $javascript .= "oc('$key');oc('$key_image1')n";
- } else {
- array_unshift($rows[$key], " ");
- }
- }
- }
- $javascript .= "</SCRIPT>";
- reset($rows);
- }
-
- // find max cols
- if (is_array($rows)) {
- while (list($key1,$val1) = each($rows)) {
- if (count($val1) > $cols) {
- $cols=count($val1);
- }
- }
-
- reset($rows);
- }
- // columns might be greater max cols
- if (count($columns) > $cols) {
- $cols = count($columns);
- }
-
- // allow something before start of internal table
- if ($top_html != "") {
- echo "<tr><td colspan="$cols">$top_html</td></tr>";
- }
-
- // generate columns (top row)
- if (is_array($columns)) {
- echo "n<tr class="headerRow">n ";
- // if we have bottom row add that
- if (is_array($bottomline)) {
- echo "<td width="15" class="headerLeftCell"> </td>n";
- $count = false;
- } else {
- $count = true;
- }
- while (list ($key, $val) = each ($columns)) {
- if ($count) {
- echo "<td class="headerLeftCell"><span class="headerText">$val</span></th>n";
- } else {
- echo "<td class="headerCell"><span class="headerText">$val</span></th>n";
- }
- $count = false;
- }
- echo "n</tr>";
- }
-
- if (!$rows) {
- return;
- }
-
- // generate the rows
- while (list ($key, $val) = each ($rows)) {
-
- // create the row including extra row is $lines is specified
- if ($x==1) {
- if ($lines[$key]) {
- echo "n<tr class="normalRow">n <td colspan="$cols" class="normalCellalt1">$lines[$key]</td></tr>";
- }
- echo "n<tr class="normalRow">";
- $x=0;
- } else {
- if ($lines[$key]) {
- echo "n<tr class="normalRow">n <td colspan="$cols" class="normalCellalt2">$lines[$key]</td></tr>";
- }
- echo "n<tr class="normalRow">n ";
- $x=1;
- }
-
- // colspan if not all cols avaliable
- $col2 = count($val);
- if ($col2 < $cols) {
- $colspan = $cols/$col2;
- }
- if (is_array($val)) {
- while (list ($key2, $val2) = each ($val)) {
- // extra settings
- if (is_array($class)) {
- $td_extra .= " class = "$class[$i]"";
- } else {
- if ($x==1) {
- $td_extra .= " class="normalCellalt2"";
- } else {
- $td_extra .= " class="normalCellalt1"";
- }
- }
- if ($colspan) {
- $td_extra .= " colspan="$colspan"";
- }
- if ((is_array($width)) AND ($cols != $colspan)) {
- $td_extra .= " width = "$width[$td_count]"";
- }
-
- $td_count++;
- give_default($val2, ' ');
- echo "n<td$td_extra>$val2</td>";
- unset($td_extra);
- $i++;
-
- }
- unset($colspan);
- // just one column
- } else {
- if ($colspan) {
- $td_extra .= " colspan="$colspan"";
- }
- $one_column = 1;
- echo "n<td$td_extra" . iff($x, " class="normalCellalt1">", " class="normalCellalt2">") . "$val</td>";
- }
-
- echo "n</tr>";
- $td_count = 0;
- // general second line if specified
- if ($secondrow[$key]) {
-
- if ($bottomline[$key]) { // extra table column
- $bottom_extra = "<td" . iff($x, " class="normalCellalt1">", " class="normalCellalt2">") . "></td>";
- }
- give_default($secondrow[$key], ' ');
- if ($x == 1) {
- echo "n<tr>$bottom_extran <td colspan="$cols" class="normalCellalt2">$secondrow[$key] sdsdf</td></tr>";
- } else {
- echo "n<tr>$bottom_extran <td colspan="$cols" class="normalCellalt1">$secondrow[$key]</td></tr>";
- }
- }
- // generate bottom line if specified
- if (trim($bottomline[$key]) != '') {
- if ($x == 1) {
- echo "n<tr id="$key" class="normalCellalt1">n<td colspan="$cols" class="normalCellalt2">$bottomline[$key]</td></tr>";
- } else {
- echo "n<tr id="$key" class="normalCellalt2">n<td colspan="$cols" class="normalCellalt1">$bottomline[$key]</td></tr>";
- }
- }
- echo "<tr class="borderCell">";
- if ($one_column) {
- ?>
- <td height="1" class="borderCell"><img src="<?php echo constant('LOC_IMAGES'); ?>spacer.gif" width="1" height="1"></td><?php
- } else {
- ?>
- <td height="1" class="borderCell" colspan="30"><img src="<?php echo constant('LOC_IMAGES'); ?>spacer.gif" width="1" height="1"></td>
- <?php
- }
-
- echo "</tr>";
- unset($one_column);
- }
-
- // end table
- echo $javascript;
-
- }
- /*****************************************************
- function js_linespan
- -----DESCRIPTION: -----------------------------------
- Correct line spanning issues in JS strings.
- -----ARGUMENTS: -------------------------------------
- text Text to correct
- -----RETURNS:----------------------------------------
- Corrected text usable in JavaScript
- *****************************************************/
- function js_linespan($text) {
- $text = str_replace("nr","\r\n", $text);
- $text = str_replace("rn","\r\n", $text);
- $text = str_replace("n","\r\n", $text);
- $text = str_replace("r","\r\n", $text);
- return $text;
- }
- /*****************************************************
- function nopermission
- -----DESCRIPTION: -----------------------------------
- Display a "no permission" error page
- -----ARGUMENTS: -------------------------------------
- message Message to display
- -----RETURNS:----------------------------------------
- None; directly generates output and exits
- *****************************************************/
- function nopermission($message='') {
- if (defined('ADMIN_ZONE')) {
- admin_header();
- }
- if (defined('TECH_ZONE')) {
- tech_nav();
- }
- echo "<br /><br />";
- if ($message) {
- echo table_border("<center><b>You do not have permission to $message</b><br /><br />If you believe this is an error, please contact your helpdesk admin</center>");
- } else {
- echo table_border("<center><b>You do not have permission to complete that action</b><br /><br />If you believe this is an error, please contact your helpdesk admin</center>");
- }
-
- exit();
- }
- /*****************************************************
- function mistake
- -----DESCRIPTION: -----------------------------------
- Display an general error page.
- -----ARGUMENTS: -------------------------------------
- message Message to display
- -----RETURNS:----------------------------------------
- None; directly generates output and exits
- *****************************************************/
- function mistake($message='', $noheader = 0) {
- if (!$noheader) {
- if (defined('ADMINZONE')) {
- admin_header();
- }
- if (defined('TECHZONE')) {
- tech_nav();
- }
- }
- echo "<br /><br />";
- if ($message) {
- echo table_border("<P><b>There has been an error:</b><BR /><BR />$message</b></P>");
- } else {
- echo table_border("<P><B>There has been an error:</B><BR /><BR />The action you attempted could not be completed. Please contact your helpdesk administrator for assistance.</P>");
- }
- exit();
- }
- /*****************************************************
- function time_since
- -----DESCRIPTION: -----------------------------------
- Calculates time passed since the specified time.
- - converts number of seconds into days/hours/minutes/seconds
- - displays in x days, y hours, z minutes, v seconds format.
- -----ARGUMENTS: -------------------------------------
- time Timestamp
- -----RETURNS:----------------------------------------
- Time elapsed, expressed in "X days, Y hours, Z minutes, V seconds" format.
- *****************************************************/
- function display_time($time) {
- // calculate components
- $days = floor(($time / (60 * 60 * 24)));
- $time = $time - ($days * 60 * 60 * 24);
- $hours = floor(($time / (60 * 60)));
- $time = $time - ($hours * 60 * 60);
- $minutes = floor(($time / 60));
- $time = ($time - ($minutes * 60));
- $seconds = $time;
-
- // format time
- if ($days != "") {
- if ($days == "1") {
- return $days . " day";
- } else {
- return $days . " days";
- }
- }
-
- if ($hours != "") {
- if ($hours == "1") {
- return $hours . " hour";
- } else {
- return $hours . " hours";
- }
- }
-
- if ($minutes != "") {
- if ($minutes == "1") {
- return $minutes . " minute";
- } else {
- return $minutes . " minutes";
- }
- }
-
- if ($seconds != "") {
- if ($seconds == "1") {
- return $seconds . " second";
- } else {
- return $seconds . " seconds";
- }
- }
- }
- /*****************************************************
- function array_unshift_keys
- -----DESCRIPTION: -----------------------------------
-
- *****************************************************/
- function array_unshift_keys(&$arr, $key, $val) {
- $arr = array_reverse($arr, true);
- $arr[$key] = $val;
- $arr = array_reverse($arr, true);
- count($arr);
- }
- /*****************************************************
- function mini_table
- -----DESCRIPTION: -----------------------------------
- Generates HTML for a small message table
- -----ARGUMENTS: -------------------------------------
- content HTML to insert into the table
- color Table background color (#ABCDEF format)
- width [Optional] Table width.
- -----RETURNS: ---------------------------------------
- HTML for the table.
- *****************************************************/
- function mini_table($content, $color, $width="100%") {
- return "<table width="$width" align="center" cellpadding="3"><tr><td bgcolor="$color">$content</td></tr></table>";
- }
- /*****************************************************
- function convert_date
- -----DESCRIPTION: -----------------------------------
- Calculate timestamp for a given numeric date.
- -----ARGUMENTS: -------------------------------------
- date Date to convert (YYYY-MM-DD format)
- -----RETURNS:----------------------------------------
- Timestamp of specified date, or FALSE for invalid date.
- *****************************************************/
- function convert_date($date) {
- $datebits = explode("-",$date);
- $time = mktime(0, 0, 0, $datebits[1], $datebits[2], $datebits[0]);
- return $time;
- }
- /*****************************************************
- function wysiwyg
- -----DESCRIPTION: -----------------------------------
- Return HTML for a submit button to open the
- WYSIWYG editor.
- -----ARGUMENTS: -------------------------------------
- form Name of the form to update
- element Form element to update
- text Button name and value
- return [Optional] Return value
- -----RETURNS: ---------------------------------------
- HTML for the submit button.
- *****************************************************/
- function wysiwyg($form, $element, $text, $return='') {
-
- return "<input type="button" name="$text" value="$text" onclick="wysiwyg('$form', '$element', '$return')">";
- }
- /*****************************************************
- function form_jump
- -----DESCRIPTION: -----------------------------------
- Display a popup message, then redirect to the specified
- form handler (passing hidden form values along).
- -----ARGUMENTS: -------------------------------------
- url URL to submit to
- message Message to display before jumping
- hidden Form values to submit
- -----RETURNS: ---------------------------------------
- Nothing.
- *****************************************************/
- function form_jump($url, $message, $hidden='') {
- if (defined('ADMINZONE')) {
- admin_mini_header('', "<title>$message</title>");
- }
- if (defined('TECHZONE')) {
- tech_mini_header('', "<title>$message</title>");
- }
- if (!$message) {
- $message = "No actions were specified; no changes made.";
- }
- echo "
- <html>
- <body onload="alert('$message');deskpro.submit();">
- <form method="post" name="deskpro" action="$url">";
- if (is_array($hidden)) {
- foreach ($hidden AS $key => $var) {
- echo form_hidden($key, $var);
- }
- }
- echo "
- <br /><br /><br /><br /><br /><p align="center">
- <input type="submit" name="Click here to continue" value="Click here to continue" onclick="javascript:deskpro.submit();">
- </p>
- </form>
- </body>
- </html>
- ";
- exit();
-
- }
- /*****************************************************
- function jump
- -----DESCRIPTION: -----------------------------------
- Redirect to another URL
- -----ARGUMENTS: -------------------------------------
- url URL to redirect to
- message Message to show during redirection
- -----RETURNS: ---------------------------------------
- Nothing.
- *****************************************************/
- function jump($url, $message) {
- if (defined('ADMINZONE')) {
- admin_mini_header('', "<title>$message</title><meta http-equiv="Refresh" content="1; URL=$url">");
- }
- if (defined('TECHZONE')) {
- tech_mini_header('', "<title>$message</title><meta http-equiv="Refresh" content="1; URL=$url">");
- }
-
- echo "
- <br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
- <table width="720" border="0" cellspacing="0" cellpadding="0" align="left">
- <tr align="center" valign="middle">
- <td align="center">
- <table border="0" cellspacing="0" cellpadding="10" bgcolor="" width="70%">
- <tr>
- <td>
- <center><p><b>$message</b><br />
- <br />
- You are now being re-directed<br />
- <a href="$url">Click here if you do not
- want to wait any longer (or if your browser does not automatically
- forward you).</a> </smallfont> </p></center>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </body>
- </html>
- ";
-
- }
- /*****************************************************
- function jprompt
- -----DESCRIPTION: -----------------------------------
- Return HTML to generate a link that produces a confirmation
- popup, redirecting to the specified URL if the user
- selects 'okay'.
- -----ARGUMENTS: -------------------------------------
- message Message to display
- url URL to redirect to
- text Link text to display
- danger [Deprecated]
- -----RETURNS: ---------------------------------------
- HTML to generate the link.
- *****************************************************/
- function jprompt($message, $url, $text, $danger=0) {
- $nonjs = "<a href="$url">$text</a>";
- $message = addslashes_js($message);
- $url = addslashes_js($url);
- $text = addslashes_js($text);
- $js = "<a href="javascript:jprompt('$message', '$url')">$text</a>";
- return "<script language="JavaScript">document.write('$js');</script><noscript>$nonjs</noscript>";
- }
- /*****************************************************
- function jprompt_multi
- -----DESCRIPTION: -----------------------------------
- Return HTLM to generate a link that produces a double
- popup; the first confirms that an action is desired, and
- the second selects between two actions.
- -----ARGUMENTS: -------------------------------------
- message First message to display
- message2 Second message to display
- urltrue URL to redirect to if second message is answered with "true"
- urlfalse URL to redirect to if second message is answered with "false"
- text Link text to display
- -----RETURNS: ---------------------------------------
- HTML to generate the link.
- *****************************************************/
- function jprompt_multi($message, $message2, $urltrue, $urlfalse, $text) {
- return "<a href="javascript:jprompt_multi('$message', '$message2', '$urltrue', '$urlfalse')">$text</a>";
- }
- /*****************************************************
- function table_thelp
- -----DESCRIPTION: -----------------------------------
- *****************************************************/
- function table_thelp($text, $category, $topic) {
- return "<TABLE><TR><TD>$text</TD><TD VALIGN="middle">" . thelp($category, $topic) . "</TD></TR></TABLE>";
- }
- /*****************************************************
- function thelp
- -----DESCRIPTION: -----------------------------------
- Return a link to popup a tech interface help dialog
- for the given topic
- -----ARGUMENTS: -------------------------------------
- category Category (string, not integer)
- topic Topic (string, not integer)
- -----RETURNS:----------------------------------------
- The HTML for a graphical link to pop up a window
- containing the appropriate help text, or NULL if
- no matching topic is found.
- *****************************************************/
- function thelp($category, $topic) {
- global $settings;
- $category = urlencode($category);
- $topic = urlencode($topic);
- $url = "'../help/deskpro_help.php?category=$category&entry=$topic&mini=1'";
- $gfx = ""../../images/help.gif"";
- return "<A onClick="openWindow($url, 650, 550, 'Help')"><IMG SRC=$gfx BORDER="0" ALIGN="bottom"></A>";
- }
- /*****************************************************
- function ahelp
- -----DESCRIPTION: -----------------------------------
- return a link to popup an admin interface help dialog
- for the given topic
- -----ARGUMENTS: -------------------------------------
- category Category (string, not an integer)
- topic Topic (string, not an integer)
- -----RETURNS:----------------------------------------
- The HTML for a graphical link to pop up a window
- containing the appropriate help text, or NULL if
- no matching topic is found.
- *****************************************************/
- function ahelp($category, $topic) {
- global $settings;
- $category = urlencode($category);
- $topic = urlencode($topic);
- $url = "'../admin/help.php?category=$category&entry=$topic&mini=1'";
- $gfx = ""../images/but071.gif"";
- return "<A onClick="openWindow($url, 500, 550, 'Help')"><IMG SRC=$gfx BORDER="0" ALIGN="bottom"></A>";
- }
- /*****************************************************
- function get_intervals
- -----DESCRIPTION: -----------------------------------
- - Divide the period of time specified by
- $start and $end into time units of $interval
- length.
- -----ARGUMENTS: -------------------------------------
- start : Starting time and date, UNIX
- time stamp format
- end : Ending time and date, UNIX
- time stamp format
- interval : strtotime() acceptable format
- of time and date specification
- (e.g. "+1 years 4 days 3 hours
- 2 minutes")
- -----RETURNS:----------------------------------------
- Returns a two-dimensional array:
- $span[0] = array($spanstart, $spanend);
- $span[1] = array($spanstart, $spanend);
- Values returned are UNIX timestamps.
- *****************************************************/
- function get_intervals($start, $end, $interval) {
- $spans = array();
- while ($start < $end) {
- $spanstart = $start;
- $start = strtotime(date('r', $start) . " $interval");
- if ($start >= $end) {
- $spanend = $end;
- } else {
- $spanend = $start;
- }
- $spans[] = array($spanstart, $spanend);
- }
- return $spans;
- }
- /*****************************************************
- function user_delete
- -----DESCRIPTION: -----------------------------------
- - Delete one or more users, passed in as a value
- (for one user) or an array. This checks the current
- user's permissions before performing the actual
- deletes.
- -----ARGUMENTS: -------------------------------------
- userlist : If an integer, a userid. If an array,
- an array of userids.
- -----RETURNS:----------------------------------------
- Returns the number of users deleted, including zero
- (no users deleted). Returns -1 if the user doesn't have
- permission to delete the user.
- *****************************************************/
- function user_delete($userlist = '') {
- global $user, $db;
- if (!$user['p_delete_users'] AND !$user['is_admin']) {
- return -1;
- }
- $deleted = 0;
- if (is_array($userlist) OR ((int)$userlist)) {
- $queries = array(
- 'DELETE FROM user_session WHERE userid IN ',
- 'DELETE FROM faq_comments WHERE userid IN ',
- 'DELETE FROM faq_rating WHERE userid IN ',
- 'DELETE FROM faq_subscriptions WHERE id IN ',
- 'DELETE FROM tech_start_tickets WHERE userid IN ',
- 'DELETE FROM user_bill WHERE userid IN ',
- 'DELETE FROM user_email WHERE userid IN ',
- 'DELETE FROM user_notes WHERE userid IN ',
- 'UPDATE faq_articles SET userid = 0 WHERE userid IN ',
- 'DELETE FROM user WHERE id IN '
- );
- if (is_array($userlist)) {
- $term = array2sql($userlist);
- } else {
- $term = array2sql(array($userlist));
- }
- // run those queries
- foreach ($queries AS $val) {
- $db->query($val . $term);
- }
- if ($db->affected_rows()) {
- $deleted++;
- }
- $db->query("SELECT id FROM ticket WHERE userid IN $term");
- while ($result = $db->row_array()) {
- $ids[] = $result[id];
- }
- ticket_delete($ids);
- }
- return $deleted;
- }
- /*****************************************************
- function ticket_delete
- -----DESCRIPTION: -----------------------------------
- - Delete one or more tickets, passed in as a
- value (for one ticket) or an array. This checks
- the current user's permissions before performing the
- actual deletes.
- -----ARGUMENTS: -------------------------------------
- ticketlist : If an integer, a ticketid. If an
- array, an array of ticketids.
- -----RETURNS:----------------------------------------
- Returns an array, containing two elements:
- noperms : An array, a list of tickets the calling
- tech has no permission to delete
- deleted : An array, a list of tickets deleted
- by the function.
- If both arrays count() to zero, no tickets were passed
- to the function.
- *****************************************************/
- function ticket_delete($ticketlist = '') {
- global $user, $db;
- if (is_array($ticketlist)) {
- $term = array2sql($ticketlist);
- } else {
- $term = array2sql(array($ticketlist));
- $ticketlist = array($ticketlist);
- }
- if (!count($ticketlist)) {
- return array(NULL, NULL);
- }
- $db->query("SELECT id, tech FROM ticket WHERE id IN $term");
- while ($res = $db->row_array()) {
- if ($res['tech'] == $user['id']) {
- if ($user['p_delete_own']) {
- $delete[] = $res['id'];
- } else {
- $noperms[] = $res['id'];
- }
- } else {
- if ($user['p_delete_other'] or $user['is_admin']) {
- $delete[] = $res['id'];
- } else {
- $noperms[] = $res['id'];
- }
- }
- }
- if (!@count($delete)) {
- return array($noperms, NULL);
- } else {
- $term = array2sql($delete);
- }
- $deleted = 0;
- if (is_array($ticketlist) OR ((int)$ticketlist)) {
- $queries = array(
- 'DELETE FROM tech_ticket_watch WHERE ticketid IN ',
- 'DELETE FROM ticket_attachments WHERE ticketid IN ',
- 'DELETE FROM ticket_log WHERE ticketid IN ',
- 'DELETE FROM ticket_notes WHERE ticketid IN ',
- 'DELETE FROM tech_ticket_save WHERE ticketid IN ',
- 'DELETE FROM ticket_message WHERE ticketid IN ',
- 'DELETE FROM user_bill WHERE ticketid IN ',
- 'DELETE FROM ticket WHERE id IN ',
- 'DELETE FROM tech_ticket_watch WHERE ticketid IN '
- );
- // Grab attachment blobs to delete
- $db->query("SELECT blobid FROM ticket_attachments WHERE ticketid IN $term");
- while ($res = $db->row_array()) {
- $blobs[] = $res['blobid'];
- }
- $db->query("DELETE FROM blobs WHERE id IN " . array2sql($blobs));
- // get ticket messages and delete the source
- $db->query("SELECT id FROM ticket_message WHERE ticketid IN $term");
- while ($res = $db->row_array()) {
- $sources[] = $res['id'];
- }
- $db->query("DELETE FROM gateway_source WHERE id IN " . array2sql($sources));
- foreach ($queries AS $val) {
- $db->query($val . $term);
- }
- }
- return array($noperms, $delete);
- }
- /*****************************************************
- function ban_email
- -----DESCRIPTION: -----------------------------------
- - Adds an e-mail address to the banned list.
- -----ARGUMENTS: -------------------------------------
- email : E-mail address to ban.
- -----RETURNS:----------------------------------------
- Returns -1 if permission denied (can't ban
- users), 0 if already banned, 1 if added
- successfully to banned list.
- *****************************************************/
- function ban_email($email) {
- global $user;
- if (!$user['p_edit_users'] AND !$user['is_admin']) {
- return -1;
- }
- $banned = unserialize(get_data('email_ban'));
- if (!@in_array($email, $banned)) {
- $banned[] = $email;
- update_data('email_ban', serialize($banned));
- return 1;
- } else {
- return 0;
- }
- }
- #####################################################################################
- ################## HTML OUTPUT FUNCTIONS ###########################################
- #####################################################################################
- /*****************************************************
- function start_outline_table
- -----DESCRIPTION: -----------------------------------
- - makes a border for a table (generally for links)
- -----ARGUMENTS: -------------------------------------
- none
- -----RETURNS:----------------------------------------
- echos the HTML directly
- *****************************************************/
- function outline_table($title='', $content='', $width='100%') {
- ?>
- <table width="<?php echo $width; ?>" border="0" cellspacing="0" cellpadding="0">
-
- <tr><td height="18">
- <font color="#BF4343">\</font> <strong><?php echo $title; ?></strong>
- </td></tr>
-
- <tr>
- <td height="19" bgcolor="#D1D1D1">
- <?php
- if (!$width) {
- $width = '100%';
- }
- ?>
- <table width="100%" border="0" cellspacing="1" cellpadding="5">
- <tr><td bgcolor="#FFFFFF">
- <table width="95%" border="0" align="center" cellpadding="0" cellspacing="2">
- <tr><td>
- <?php echo $content; ?>
- </td></tr>
- </table>
- </td></tr></table>
- </td></tr></table>
- <?
-
- }
- /*****************************************************
- function get_javascript
- -----DESCRIPTION: -----------------------------------
- - gets a javascript; takes account of where we are
- -----ARGUMENTS: -------------------------------------
- action : location of the javascript file
- -----RETURNS:----------------------------------------
- The html to the javascript
- *****************************************************/
- function get_javascript($loc) {
- return "n<script language="javascript" src="" . constant('LOC_JAVASCRIPT') . $loc . ""></script>n";
- }
- /*****************************************************
- function get_css
- -----DESCRIPTION: -----------------------------------
- - gets a css; takes account of where we are
- -----ARGUMENTS: -------------------------------------
- action : location of the css file
- -----RETURNS:----------------------------------------
- The html to the css
- *****************************************************/
- function get_css($loc) {
- return "n<link rel="stylesheet" href="" . constant('LOC_CSS') . $loc . "" type="text/css">";
- }
- /*****************************************************
- function global_login
- -----DESCRIPTION: -----------------------------------
- - gets a css; takes account of where we are
- *****************************************************/
- function global_login($message='', $logout = 0) {
- global $_REQUEST, $_GET, $_POST, $_FILES, $req, $settings;
- 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");
- if (defined('ADMINZONE')) {
- admin_mini_header();
- if ($logout OR !$req) {
- $req = 'index.php';
- }
- } else {
- tech_mini_header();
- if ($logout OR !$req) {
- $req = '../home/index.php';
- }
- }
- echo '
- <SCRIPT language="javascript">
- if (parent.frames.length > 0) {
- parent.location.href = self.document.location
- }
- </SCRIPT>
- ';
- echo "<center><BR>";
- echo "<P><BR><BR><table width="400"><tr><td>";
-
- if ($message) {
- echo table_border('<b><center>' . $message . '</center></b>');
- }
- $bit = array('<B>Username</B>', form_input('username', ''));
- $table[] = $bit;
- if (!$_REQUEST['_getvars']) {
- $get = $_GET;
- } else {
- $get = $_REQUEST['_getvars'];
- }
- if (!$_REQUEST['_postvars']) {
- $post = $_POST;
- } else {
- $post = $_REQUEST['_postvars'];
- }
- if (!$_REQUEST['_filevars']) {
- $file = $_FILE;
- } else {
- $file = $_REQUEST['_filevars'];
- }
- $bit = array('<B>Password</B>', form_password('password', '') .
- form_hidden('_getvars', htmlspecialchars(serialize($get))) .
- form_hidden('_postvars', htmlspecialchars(serialize($post))) .
- form_hidden('_filevars', htmlspecialchars(serialize($file))) .
- form_hidden('_request', htmlspecialchars(serialize($_REQUEST))));
- $table[] = $bit;
- $bit = array('<b>Remember me<br /></b>until I log out manually', form_radio_yn('cookie').form_hidden('login_form', 'login').form_hidden('original_uri', urldecode($req)));
- $table[] = $bit;
- echo table_header('Please log in', urldecode($req));
- echo table_content('', $table);
- echo table_footer('Login');
-
- echo "</td></tr></table></center>";
- echo "<script language="JavaScript">
- document.forms[0].username.focus();
- </SCRIPT>";
-
- echo "<BR><BR><BR><BR><center>Powered by: <!--WTN-WDYL-->DeskPRO v $settings[deskpro_version]</a><br />
- Copyright