00001 <?php 00002 // functions.inc.php - Function library and defines for SiT -Support Incident Tracker 00003 // 00004 // SiT (Support Incident Tracker) - Support call tracking system 00005 // Copyright (C) 2010-2011 The Support Incident Tracker Project 00006 // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors 00007 // 00008 // This software may be used and distributed according to the terms 00009 // of the GNU General Public License, incorporated herein by reference. 00010 // 00011 // Authors: Ivan Lucas, <ivanlucas[at]users.sourceforge.net> 00012 // Tom Gerrard, <tomgerrard[at]users.sourceforge.net> - 2001 onwards 00013 // Martin Kilcoyne - 2000 00014 // Paul Heaney, <paulheaney[at]users.sourceforge.net> 00015 // Kieran Hogg, <kieran[at]sitracker.org> 00016 00017 // Many functions here simply extract various snippets of information from 00018 // Most are legacy and can replaced by improving the pages that call them to 00019 // use SQL joins. 00020 00021 // Prevent script from being run directly (ie. it must always be included 00022 if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME'])) 00023 { 00024 exit; 00025 } 00026 00027 include (APPLICATION_LIBPATH . 'classes.inc.php'); 00028 include (APPLICATION_LIBPATH . 'ldap.inc.php'); 00029 include (APPLICATION_LIBPATH . 'base.inc.php'); 00030 include_once (APPLICATION_LIBPATH . 'billing.inc.php'); 00031 include_once (APPLICATION_LIBPATH . 'user.inc.php'); 00032 include_once (APPLICATION_LIBPATH . 'sla.inc.php'); 00033 include_once (APPLICATION_LIBPATH . 'ftp.inc.php'); 00034 include_once (APPLICATION_LIBPATH . 'tags.inc.php'); 00035 include_once (APPLICATION_LIBPATH . 'string.inc.php'); 00036 include_once (APPLICATION_LIBPATH . 'html.inc.php'); 00037 include_once (APPLICATION_LIBPATH . 'tasks.inc.php'); 00038 include_once (APPLICATION_LIBPATH . 'export.inc.php'); 00039 00040 // function stripslashes_array($data) 00041 // { 00042 // if (is_array($data)) 00043 // { 00044 // foreach ($data as $key => $value) 00045 // { 00046 // $data[$key] = stripslashes_array($value); 00047 // } 00048 // return $data; 00049 // } 00050 // else 00051 // { 00052 // return stripslashes($data); 00053 // } 00054 // } 00055 00056 if (version_compare(PHP_VERSION, "5.1.0", ">=")) 00057 { 00058 date_default_timezone_set($CONFIG['timezone']); 00059 } 00060 00061 //Prevent Magic Quotes from affecting scripts, regardless of server settings 00062 //Make sure when reading file data, 00063 //PHP doesn't "magically" mangle backslashes! 00064 set_magic_quotes_runtime(FALSE); 00065 00066 if (get_magic_quotes_gpc()) 00067 { 00068 00069 // All these global variables are slash-encoded by default, 00070 // because magic_quotes_gpc is set by default! 00071 // (And magic_quotes_gpc affects more than just $_GET, $_POST, and $_COOKIE) 00072 // We don't strip slashes from $_FILES as of 3.32 as this should be safe without 00073 // doing and it will break windows file paths if we do 00074 $_SERVER = stripslashes_array($_SERVER); 00075 $_GET = stripslashes_array($_GET); 00076 $_POST = stripslashes_array($_POST); 00077 $_COOKIE = stripslashes_array($_COOKIE); 00078 $_ENV = stripslashes_array($_ENV); 00079 $_REQUEST = stripslashes_array($_REQUEST); 00080 $HTTP_SERVER_VARS = stripslashes_array($HTTP_SERVER_VARS); 00081 $HTTP_GET_VARS = stripslashes_array($HTTP_GET_VARS); 00082 $HTTP_POST_VARS = stripslashes_array($HTTP_POST_VARS); 00083 $HTTP_COOKIE_VARS = stripslashes_array($HTTP_COOKIE_VARS); 00084 $HTTP_POST_FILES = stripslashes_array($HTTP_POST_FILES); 00085 $HTTP_ENV_VARS = stripslashes_array($HTTP_ENV_VARS); 00086 if (isset($_SESSION)) 00087 { 00088 #These are unconfirmed (?) 00089 $_SESSION = stripslashes_array($_SESSION, ''); 00090 $HTTP_SESSION_VARS = stripslashes_array($HTTP_SESSION_VARS, ''); 00091 } 00092 // The $GLOBALS array is also slash-encoded, but when all the above are 00093 // changed, $GLOBALS is updated to reflect those changes. (Therefore 00094 // $GLOBALS should never be modified directly). $GLOBALS also contains 00095 // infinite recursion, so it's dangerous... 00096 } 00097 00098 00108 function authenticateSQL($username, $password) 00109 { 00110 global $dbUsers; 00111 00112 $password = md5($password); 00113 if ($_SESSION['auth'] == TRUE) 00114 { 00115 // Already logged in 00116 return 1; 00117 } 00118 00119 // extract user 00120 $sql = "SELECT id FROM `{$dbUsers}` "; 00121 $sql .= "WHERE username = '{$username}' AND password = '{$password}' AND status != 0 "; 00122 // a status of 0 means the user account is disabled 00123 $result = mysql_query($sql); 00124 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00125 00126 // return appropriate value 00127 if (mysql_num_rows($result) == 0) 00128 { 00129 mysql_free_result($result); 00130 return 0; 00131 } 00132 else 00133 { 00134 journal(CFG_LOGGING_MAX,'User Authenticated',"{$username} authenticated from " . getenv('REMOTE_ADDR'),CFG_JOURNAL_LOGIN,0); 00135 return 1; 00136 } 00137 } 00138 00139 00149 function authenticate($username, $password) 00150 { 00151 global $CONFIG; 00152 $toReturn = false; 00153 00154 if (!empty($username) AND !empty($password)) 00155 { 00156 $sql = "SELECT id, LOWER(password) AS password, status, user_source FROM `{$GLOBALS['dbUsers']}` WHERE username = '{$username}'"; 00157 $result = mysql_query($sql); 00158 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00159 if (mysql_num_rows($result) == 1) 00160 { 00161 // Exist in SiT DB 00162 $obj = mysql_fetch_object($result); 00163 if ($obj->user_source == 'sit') 00164 { 00165 if (md5($password) == $obj->password AND $obj->status != 0) $toReturn = true; 00166 else $toReturn = false; 00167 } 00168 elseif ($obj->user_source == 'ldap') 00169 { 00170 // Auth against LDAP and sync 00171 $toReturn = authenticateLDAP(stripslashes($username), $password, $obj->id); 00172 if ($toReturn === -1) 00173 { 00174 // Communication with LDAP server failed 00175 if ($CONFIG['ldap_allow_cached_password']) 00176 { 00177 // Use cached password 00178 if (md5($password) == $obj->password AND $obj->status != 0) $toReturn = true; 00179 else $toReturn = false; 00180 } 00181 else 00182 { 00183 $toReturn = false; 00184 } 00185 } 00186 elseif ($toReturn) 00187 { 00188 $toReturn = true; 00189 } 00190 else 00191 { 00192 $toReturn = false; 00193 } 00194 } 00195 } 00196 elseif (mysql_num_rows($result) > 1) 00197 { 00198 // Multiple this should NEVER happen 00199 trigger_error("Username not unique", E_USER_ERROR); 00200 $toReturn = false; 00201 } 00202 else 00203 { 00204 // Don't exist, check LDAP etc 00205 if ($CONFIG['use_ldap']) 00206 { 00207 $toReturn = authenticateLDAP($username, $password); 00208 if ($toReturn === -1) $toReturn = false; 00209 } 00210 } 00211 00212 if ($toReturn) 00213 { 00214 journal(CFG_LOGGING_MAX,'User Authenticated',"{$username} authenticated from " . getenv('REMOTE_ADDR'),CFG_JOURNAL_LOGIN,0); 00215 debug_log ("Authenticate: User authenticated",TRUE); 00216 } 00217 else 00218 { 00219 debug_log ("authenticate: User NOT authenticated",TRUE); 00220 } 00221 } 00222 else 00223 { 00224 debug_log ("Blank username or password for user thus denying access"); 00225 $toReturn = false; 00226 } 00227 00228 return $toReturn; 00229 } 00230 00231 00232 function authenticateContact($username, $password) 00233 { 00234 debug_log ("authenticateContact called"); 00235 global $CONFIG; 00236 $toReturn = false; 00237 00238 if (!empty($username) AND !empty($password)) 00239 { 00240 $sql = "SELECT id, password, contact_source, active FROM `{$GLOBALS['dbContacts']}` WHERE username = '{$username}'"; 00241 $result = mysql_query($sql); 00242 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00243 if (mysql_num_rows($result) == 1) 00244 { 00245 debug_log ("Authenticate: Just one contact in db"); 00246 // Exists in SiT DB 00247 $obj = mysql_fetch_object($result); 00248 if ($obj->contact_source == 'sit') 00249 { 00250 if ((md5($password) == $obj->password OR $password == $obj->password) AND $obj->active == 'true') $toReturn = true; 00251 else $toReturn = false; 00252 } 00253 elseif ($obj->contact_source == 'ldap') 00254 { 00255 // Auth against LDAP and sync 00256 $toReturn = authenticateLDAP($username, $password, $obj->id, false); 00257 if ($toReturn === -1) 00258 { 00259 // Communication with LDAP server failed 00260 if ($CONFIG['ldap_allow_cached_password']) 00261 { 00262 debug_log ("LDAP connection failed, using cached password"); 00263 // Use cached password 00264 if ((md5($password) == $obj->password OR $password == $obj->password) AND $obj->active == 'true') $toReturn = true; 00265 else $toReturn = false; 00266 debug_log ("Cached contact {$toReturn} {$password}"); 00267 00268 } 00269 else 00270 { 00271 debug_log ("Cached passwords are not enabled"); 00272 $toReturn = false; 00273 } 00274 } 00275 elseif ($toReturn) 00276 { 00277 $toReturn = true; 00278 } 00279 else 00280 { 00281 $toReturn = false; 00282 } 00283 } 00284 else 00285 { 00286 debug_log ("Source SOMETHING ELSE this shouldn't happen'"); 00287 $toReturn = false; 00288 } 00289 } 00290 elseif (mysql_num_rows($result) > 1) 00291 { 00292 debug_log ("Multiple"); 00293 // Multiple this should NEVER happen 00294 trigger_error($GLOBALS['strUsernameNotUnique'], E_USER_ERROR); 00295 $toReturn = false; 00296 } 00297 else 00298 { 00299 debug_log ("Authenticate: No matching contact '$username' found in db"); 00300 // Don't exist, check LDAP etc 00301 if ($CONFIG['use_ldap'] AND !empty($CONFIG['ldap_customer_group'])) 00302 { 00303 $toReturn = authenticateLDAP($username, $password, 0, false); 00304 if ($toReturn === -1) $toReturn = false; 00305 } 00306 } 00307 } 00308 else 00309 { 00310 debug_log ("Blank username or password for user thus denying access"); 00311 $toReturn = false; 00312 } 00313 00314 debug_log ("authenticateContact returning {$toReturn}"); 00315 return $toReturn; 00316 } 00317 00325 function customerExistsInDB($username) 00326 { 00327 global $dbContacts; 00328 $exists = 0; 00329 $sql = "SELECT id FROM `{$dbContacts}` WHERE username='$username'"; 00330 $result = mysql_query($sql); 00331 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 00332 00333 while( $res = mysql_fetch_array($result) ) 00334 { 00335 $exists = 1; 00336 } 00337 00338 return $exists; 00339 } 00340 00341 00352 function db_read_column($column, $table, $id) 00353 { 00354 $sql = "SELECT `$column` FROM `{$table}` WHERE id ='$id' LIMIT 1"; 00355 $result = mysql_query($sql); 00356 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 00357 if (mysql_num_rows($result) == 0) 00358 { 00359 $column = FALSE; 00360 } 00361 else 00362 { 00363 list($column) = mysql_fetch_row($result); 00364 } 00365 return $column; 00366 } 00367 00368 00372 function permission_name($permissionid) 00373 { 00374 global $dbPermissions; 00375 $name = db_read_column('name', $dbPermissions, $permissionid); 00376 if (empty($name)) $name = $GLOBALS['strUnknown']; 00377 return $name; 00378 } 00379 00380 00388 function software_name($softwareid) 00389 { 00390 global $now, $dbSoftware, $strEOL, $strEndOfLife; 00391 00392 $sql = "SELECT * FROM `{$dbSoftware}` WHERE id = '{$softwareid}'"; 00393 $result = mysql_query($sql); 00394 if (mysql_num_rows($result) >= 1) 00395 { 00396 $software = mysql_fetch_object($result); 00397 $lifetime_end = mysql2date($software->lifetime_end); 00398 if ($lifetime_end > 0 AND $lifetime_end < $now) 00399 { 00400 $name = "<span class='deleted'>{$software->name}</span> (<abbr title='{$strEndOfLife}'>{$strEOL}</abbr>)"; 00401 } 00402 else 00403 { 00404 $name = $software->name; 00405 } 00406 } 00407 else 00408 { 00409 $name = $GLOBALS['strUnknown']; 00410 } 00411 00412 return $name; 00413 } 00414 00415 00422 function contact_realname($id) 00423 { 00424 global $dbContacts; 00425 $sql = "SELECT forenames, surname FROM `{$dbContacts}` WHERE id='$id'"; 00426 $result = mysql_query($sql); 00427 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00428 00429 if (mysql_num_rows($result) == 0) 00430 { 00431 mysql_free_result($result); 00432 return ($GLOBALS['strUnknown']); 00433 } 00434 else 00435 { 00436 $contact = mysql_fetch_object($result); 00437 $realname = "{$contact->forenames} {$contact->surname}"; 00438 mysql_free_result($result); 00439 return $realname; 00440 } 00441 } 00442 00443 00451 function contact_site($id) 00452 { 00453 global $dbContacts, $dbSites; 00454 // 00455 $sql = "SELECT s.name FROM `{$dbContacts}` AS c, `{$dbSites}` AS s WHERE c.siteid = s.id AND c.id = '$id'"; 00456 $result = mysql_query($sql); 00457 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00458 00459 if (mysql_num_rows($result) == 0) 00460 { 00461 mysql_free_result($result); 00462 return $GLOBALS['strUnknown']; 00463 } 00464 else 00465 { 00466 list($contactsite) = mysql_fetch_row($result); 00467 mysql_free_result($result); 00468 $contactsite = $contactsite; 00469 return $contactsite; 00470 } 00471 } 00472 00473 00480 function contact_siteid($id) 00481 { 00482 return db_read_column('siteid', $GLOBALS['dbContacts'], $id); 00483 } 00484 00485 00492 function contact_email($id) 00493 { 00494 return db_read_column('email', $GLOBALS['dbContacts'], $id); 00495 } 00496 00497 00504 function contact_phone($id) 00505 { 00506 return db_read_column('phone', $GLOBALS['dbContacts'], $id); 00507 } 00508 00509 00516 function contact_fax($id) 00517 { 00518 return db_read_column('fax', $GLOBALS['dbContacts'], $id); 00519 } 00520 00521 00528 function contact_count_incidents($id) 00529 { 00530 global $dbIncidents; 00531 $count = 0; 00532 00533 $sql = "SELECT COUNT(id) FROM `{$dbIncidents}` WHERE contact='$id'"; 00534 $result = mysql_query($sql); 00535 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00536 else list($count) = mysql_fetch_row($result); 00537 mysql_free_result($result); 00538 00539 return $count; 00540 } 00541 00542 00549 function site_count_incidents($id) 00550 { 00551 global $dbIncidents, $dbContacts; 00552 $id = intval($id); 00553 $count = 0; 00554 00555 $sql = "SELECT COUNT(i.id) FROM `{$dbIncidents}` AS i, `{$dbContacts}` as c "; 00556 $sql .= "WHERE i.contact = c.id "; 00557 $sql .= "AND c.siteid='$id'"; 00558 $result = mysql_query($sql); 00559 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00560 else list($count) = mysql_fetch_row($result); 00561 mysql_free_result($result); 00562 00563 return $count; 00564 } 00565 00566 00573 function site_count_inventory_items($id) 00574 { 00575 global $dbInventory; 00576 $count = 0; 00577 00578 $sql = "SELECT COUNT(id) FROM `{$dbInventory}` WHERE siteid='$id'"; 00579 $result = mysql_query($sql); 00580 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00581 else list($count) = mysql_fetch_row($result); 00582 mysql_free_result($result); 00583 00584 return $count; 00585 } 00586 00587 00594 function contact_count_inventory_items($id) 00595 { 00596 global $dbInventory; 00597 $count = 0; 00598 00599 $sql = "SELECT COUNT(id) FROM `{$dbInventory}` WHERE contactid='$id'"; 00600 $result = mysql_query($sql); 00601 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00602 else list($count) = mysql_fetch_row($result); 00603 mysql_free_result($result); 00604 00605 return $count; 00606 } 00607 00608 00609 00616 function contact_count_open_incidents($id) 00617 { 00618 global $dbIncidents; 00619 $sql = "SELECT COUNT(id) FROM `{$dbIncidents}` WHERE contact=$id AND status<>2"; 00620 $result = mysql_query($sql); 00621 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00622 00623 list($count) = mysql_fetch_row($result); 00624 mysql_free_result($result); 00625 00626 return $count; 00627 } 00628 00629 00636 function contact_vcard($id) 00637 { 00638 global $dbContacts, $dbSites; 00639 $sql = "SELECT *, s.name AS sitename, s.address1 AS siteaddress1, s.address2 AS siteaddress2, "; 00640 $sql .= "s.city AS sitecity, s.county AS sitecounty, s.country AS sitecountry, s.postcode AS sitepostcode "; 00641 $sql .= "FROM `{$dbContacts}` AS c, `{$dbSites}` AS s "; 00642 $sql .= "WHERE c.siteid = s.id AND c.id = '$id' LIMIT 1"; 00643 $result = mysql_query($sql); 00644 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00645 $contact = mysql_fetch_object($result); 00646 $vcard = "BEGIN:VCARD\r\n"; 00647 $vcard .= "N:{$contact->surname};{$contact->forenames};{$contact->courtesytitle}\r\n"; 00648 $vcard .= "FN:{$contact->forenames} {$contact->surname}\r\n"; 00649 if (!empty($contact->jobtitle)) $vcard .= "TITLE:{$contact->jobtitle}\r\n"; 00650 if (!empty($contact->sitename)) $vcard .= "ORG:{$contact->sitename}\r\n"; 00651 if ($contact->dataprotection_phone != 'Yes') $vcard .= "TEL;TYPE=WORK:{$contact->phone}\r\n"; 00652 if ($contact->dataprotection_phone != 'Yes' && !empty($contact->fax)) 00653 { 00654 $vcard .= "TEL;TYPE=WORK;TYPE=FAX:{$contact->fax}\r\n"; 00655 } 00656 00657 if ($contact->dataprotection_phone != 'Yes' && !empty($contact->mobile)) 00658 { 00659 $vcard .= "TEL;TYPE=WORK;TYPE=CELL:{$contact->mobile}\r\n"; 00660 } 00661 00662 if ($contact->dataprotection_email != 'Yes' && !empty($contact->email)) 00663 { 00664 $vcard .= "EMAIL;TYPE=INTERNET:{$contact->email}\r\n"; 00665 } 00666 00667 if ($contact->dataprotection_address != 'Yes') 00668 { 00669 if ($contact->address1 != '') 00670 { 00671 $vcard .= "ADR;WORK:{$contact->address1};{$contact->address2};{$contact->city};{$contact->county};{$contact->postcode};{$contact->country}\r\n"; 00672 } 00673 else 00674 { 00675 $vcard .= "ADR;WORK:{$contact->siteaddress1};{$contact->siteaddress2};{$contact->sitecity};{$contact->sitecounty};{$contact->sitepostcode};{$contact->sitecountry}\r\n"; 00676 } 00677 } 00678 if (!empty($contact->notes)) 00679 { 00680 $vcard .= "NOTE:{$contact->notes}\r\n"; 00681 } 00682 00683 $vcard .= "REV:".iso_8601_date($contact->timestamp_modified)."\r\n"; 00684 $vcard .= "END:VCARD\r\n"; 00685 return $vcard; 00686 } 00687 00688 00694 function incident_owner($id) 00695 { 00696 return db_read_column('owner', $GLOBALS['dbIncidents'], $id); 00697 } 00698 00699 00705 function incident_towner($id) 00706 { 00707 return db_read_column('towner', $GLOBALS['dbIncidents'], $id); 00708 } 00709 00710 00716 function incident_contact($id) 00717 { 00718 return db_read_column('contact', $GLOBALS['dbIncidents'], $id); 00719 } 00720 00721 00727 function incident_maintid($id) 00728 { 00729 $maintid = db_read_column('maintenanceid', $GLOBALS['dbIncidents'], $id); 00730 if ($maintid == '') 00731 { 00732 trigger_error("!Error: No matching record while reading in incident_maintid() Incident ID: {$id}", E_USER_WARNING); 00733 } 00734 else 00735 { 00736 return ($maintid); 00737 } 00738 } 00739 00740 00746 function incident_title($id) 00747 { 00748 return db_read_column('title', $GLOBALS['dbIncidents'], $id); 00749 } 00750 00751 00757 function incident_status($id) 00758 { 00759 return db_read_column('status', $GLOBALS['dbIncidents'], $id); 00760 } 00761 00762 00768 function incident_priority($id) 00769 { 00770 return db_read_column('priority', $GLOBALS['dbIncidents'], $id); 00771 } 00772 00773 00779 function incident_externalid($id) 00780 { 00781 return db_read_column('externalid', $GLOBALS['dbIncidents'], $id); 00782 } 00783 00784 00790 function incident_externalengineer($id) 00791 { 00792 return db_read_column('externalengineer', $GLOBALS['dbIncidents'], $id); 00793 } 00794 00795 00801 function incident_externalemail($id) 00802 { 00803 return db_read_column('externalemail', $GLOBALS['dbIncidents'], $id); 00804 } 00805 00806 00812 function incident_ccemail($id) 00813 { 00814 return db_read_column('ccemail', $GLOBALS['dbIncidents'], $id); 00815 } 00816 00817 00823 function incident_timeofnextaction($id) 00824 { 00825 return db_read_column('timeofnextaction', $GLOBALS['dbIncidents'], $id); 00826 } 00827 00828 00836 function incident_productinfo_html($incidentid) 00837 { 00838 global $dbProductInfo, $dbIncidentProductInfo, $strNoProductInfo; 00839 00840 // TODO extract appropriate product info rather than * 00841 $sql = "SELECT *, TRIM(incidentproductinfo.information) AS info FROM `{$dbProductInfo}` AS p, {$dbIncidentProductInfo}` ipi "; 00842 $sql .= "WHERE incidentid = $incidentid AND productinfoid = p.id AND TRIM(p.information) !='' "; 00843 $result = mysql_query($sql); 00844 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00845 00846 if (mysql_num_rows($result) == 0) 00847 { 00848 return ('<tr><td>{$strNoProductInfo}</td><td>{$strNoProductInfo}</td></tr>'); 00849 } 00850 else 00851 { 00852 // generate HTML 00853 while ($productinfo = mysql_fetch_object($result)) 00854 { 00855 if (!empty($productinfo->info)) 00856 { 00857 $html = "<tr><th>{$productinfo->moreinformation}:</th><td>"; 00858 $html .= urlencode($productinfo->info); 00859 $html .= "</td></tr>\n"; 00860 } 00861 } 00862 echo $html; 00863 } 00864 } 00865 00866 00872 function contact_drop_down($name, $id, $showsite = FALSE, $required = FALSE) 00873 { 00874 global $dbContacts, $dbSites; 00875 if ($showsite) 00876 { 00877 $sql = "SELECT c.id AS contactid, s.id AS siteid, surname, forenames, "; 00878 $sql .= "s.name AS sitename, s.department AS department "; 00879 $sql .= "FROM `{$dbContacts}` AS c, `{$dbSites}` AS s WHERE c.siteid = s.id AND c.active = 'true' "; 00880 $sql .= "AND s.active = 'true' "; 00881 $sql .= "ORDER BY s.name, s.department, surname ASC, forenames ASC"; 00882 } 00883 else 00884 { 00885 $sql = "SELECT c.id AS contactid, surname, forenames FROM `{$dbContacts}` AS c, `{$dbSites}` AS s "; 00886 $sql .= "WHERE c.siteid = s.id AND s.active = 'true' AND c.active = 'true' "; 00887 $sql .= "ORDER BY forenames ASC, surname ASC"; 00888 } 00889 00890 $result = mysql_query($sql); 00891 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00892 00893 $html = "<select name='$name' id='$name'"; 00894 if ($required) 00895 { 00896 $html .= " class='required' "; 00897 } 00898 $html .= ">\n"; 00899 if ($id == 0) 00900 { 00901 $html .= "<option selected='selected' value='0'></option>\n"; 00902 } 00903 00904 $prevsite=0; 00905 while ($contacts = mysql_fetch_object($result)) 00906 { 00907 if ($showsite AND $prevsite != $contacts->siteid AND $prevsite != 0) 00908 { 00909 $html .= "</optgroup>\n"; 00910 } 00911 00912 if ($showsite AND $prevsite != $contacts->siteid) 00913 { 00914 $html .= "<optgroup label='{$contacts->sitename}, {$contacts->department}'>"; 00915 } 00916 00917 $realname = "{$contacts->forenames} {$contacts->surname}"; 00918 $html .= "<option "; 00919 if ($contacts->contactid == $id) 00920 { 00921 $html .= "selected='selected' "; 00922 } 00923 $html .= "value='{$contacts->contactid}'>{$realname}"; 00924 $html .= "</option>\n"; 00925 00926 $prevsite = $contacts->siteid; 00927 } 00928 if ($showsite) 00929 { 00930 $html.= "</optgroup>"; 00931 } 00932 00933 $html .= "</select>\n"; 00934 return $html; 00935 } 00936 00937 00950 function contact_site_drop_down($name, $id, $siteid='', $exclude='', $showsite=TRUE, $allownone=FALSE) 00951 { 00952 global $dbContacts, $dbSites; 00953 $sql = "SELECT c.id AS contactid, forenames, surname, siteid, s.name AS sitename "; 00954 $sql .= "FROM `{$dbContacts}` AS c, `{$dbSites}` AS s "; 00955 $sql .= "WHERE c.siteid = s.id AND c.active = 'true' AND s.active = 'true' "; 00956 if (!empty($siteid)) $sql .= "AND s.id='$siteid' "; 00957 if (!empty($exclude)) 00958 { 00959 if (is_array($exclude)) 00960 { 00961 foreach ($exclude AS $contactid) 00962 { 00963 $sql .= "AND c.id != $contactid "; 00964 } 00965 } 00966 else 00967 { 00968 $sql .= "AND c.id != $exclude "; 00969 } 00970 } 00971 $sql .= "ORDER BY surname ASC"; 00972 $result = mysql_query($sql); 00973 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 00974 $html = "<select name='$name'>"; 00975 if (mysql_num_rows($result) > 0) 00976 { 00977 if ($allownone) $html .= "<option value='' selected='selected'>{$GLOBALS['strNone']}</option>"; 00978 while ($contacts = mysql_fetch_object($result)) 00979 { 00980 $html .= "<option "; 00981 if ($contacts->contactid == $id) 00982 { 00983 $html .= "selected='selected' "; 00984 } 00985 00986 $html .= "value='{$contacts->contactid}'>"; 00987 if ($showsite) 00988 { 00989 $html .= htmlspecialchars("{$contacts->surname}, {$contacts->forenames} - {$contacts->sitename}"); 00990 } 00991 else 00992 { 00993 $html .= htmlspecialchars("{$contacts->surname}, {$contacts->forenames}"); 00994 } 00995 $html .= "</option>\n"; 00996 } 00997 } 00998 else $html .= "<option value=''>{$GLOBALS['strNone']}</option>"; 00999 01000 $html .= "</select>\n"; 01001 return $html; 01002 } 01003 01004 01014 function product_drop_down($name, $id, $required = FALSE) 01015 { 01016 global $dbProducts; 01017 // extract products 01018 $sql = "SELECT id, name FROM `{$dbProducts}` ORDER BY name ASC"; 01019 $result = mysql_query($sql); 01020 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01021 01022 $html = "<select name='{$name}' id='{$name}'"; 01023 if ($required) 01024 { 01025 $html .= " class='required' "; 01026 } 01027 $html .= ">"; 01028 01029 01030 if ($id == 0) 01031 { 01032 $html .= "<option selected='selected' value='0'></option>\n"; 01033 } 01034 01035 while ($products = mysql_fetch_object($result)) 01036 { 01037 $html .= "<option value='{$products->id}'"; 01038 if ($products->id == $id) 01039 { 01040 $html .= " selected='selected'"; 01041 } 01042 $html .= ">{$products->name}</option>\n"; 01043 } 01044 $html .= "</select>\n"; 01045 return $html; 01046 01047 } 01048 01049 01056 function softwareproduct_drop_down($name, $id, $productid, $visibility='internal') 01057 { 01058 global $dbSoftware, $dbSoftwareProducts; 01059 // extract software 01060 $sql = "SELECT id, name FROM `{$dbSoftware}` AS s, "; 01061 $sql .= "`{$dbSoftwareProducts}` AS sp WHERE s.id = sp.softwareid "; 01062 $sql .= "AND productid = '$productid' "; 01063 $sql .= "ORDER BY name ASC"; 01064 $result = mysql_query($sql); 01065 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01066 01067 if (mysql_num_rows($result) >=1) 01068 { 01069 $html = "<select name='$name' id='$name'>"; 01070 01071 if ($visibility == 'internal' AND $id == 0) 01072 { 01073 $html .= "<option selected='selected' value='0'></option>\n"; 01074 } 01075 elseif ($visiblity = 'external' AND $id == 0) 01076 { 01077 $html .= "<option selected='selected' value=''>{$GLOBALS['strUnknown']}</option>\n"; 01078 } 01079 01080 while ($software = mysql_fetch_object($result)) 01081 { 01082 $html .= "<option"; 01083 if ($software->id == $id) 01084 { 01085 $html .= " selected='selected'"; 01086 } 01087 $html .= " value='{$software->id}'>{$software->name}</option>\n"; 01088 } 01089 $html .= "</select>\n"; 01090 } 01091 else 01092 { 01093 $html = FALSE; 01094 } 01095 01096 return $html; 01097 } 01098 01099 01107 function vendor_drop_down($name, $id) 01108 { 01109 global $dbVendors; 01110 $sql = "SELECT id, name FROM `{$dbVendors}` ORDER BY name ASC"; 01111 $result = mysql_query($sql); 01112 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01113 $html = "<select name='$name'>"; 01114 if ($id == 0) 01115 { 01116 $html .= "<option selected='selected' value='0'></option>\n"; 01117 } 01118 01119 while ($row = mysql_fetch_object($result)) 01120 { 01121 $html .= "<option"; 01122 if ($row->id == $id) 01123 { 01124 $html .= " selected='selected'"; 01125 } 01126 $html .= " value='{$row->id}'>{$row->name}</option>\n"; 01127 } 01128 $html .= "</select>"; 01129 01130 return $html; 01131 } 01132 01133 01142 function sitetype_drop_down($name, $id) 01143 { 01144 global $dbSiteTypes; 01145 $sql = "SELECT typeid, typename FROM `{$dbSiteTypes}` ORDER BY typename ASC"; 01146 $result = mysql_query($sql); 01147 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01148 $html .= "<select name='$name'>\n"; 01149 if ($id == 0) 01150 { 01151 $html .= "<option selected='selected' value='0'></option>\n"; 01152 } 01153 01154 while ($obj = mysql_fetch_object($result)) 01155 { 01156 $html .= "<option "; 01157 if ($obj->typeid == $id) 01158 { 01159 $html .="selected='selected' "; 01160 } 01161 01162 $html .= "value='{$obj->typeid}'>{$obj->typename}</option>\n"; 01163 } 01164 $html .= "</select>"; 01165 return $html; 01166 } 01167 01168 01175 function skill_drop_down($name, $id) 01176 { 01177 global $now, $dbSoftware, $strEOL; 01178 01179 // extract software 01180 $sql = "SELECT id, name, lifetime_end FROM `{$dbSoftware}` "; 01181 $sql .= "ORDER BY name ASC"; 01182 $result = mysql_query($sql); 01183 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01184 01185 $html = "<select name='{$name}' id='{$name}' >"; 01186 01187 if ($id == 0) 01188 { 01189 $html .= "<option selected='selected' value='0'>{$GLOBALS['strNone']}</option>\n"; 01190 } 01191 01192 while ($software = mysql_fetch_object($result)) 01193 { 01194 $html .= "<option value='{$software->id}'"; 01195 if ($software->id == $id) 01196 { 01197 $html .= " selected='selected'"; 01198 } 01199 01200 $html .= ">{$software->name}"; 01201 $lifetime_start = mysql2date($software->lifetime_start); 01202 $lifetime_end = mysql2date($software->lifetime_end); 01203 if ($lifetime_end > 0 AND $lifetime_end < $now) 01204 { 01205 $html .= " ({$strEOL})"; 01206 } 01207 $html .= "</option>\n"; 01208 } 01209 $html .= "</select>\n"; 01210 01211 return $html; 01212 } 01213 01214 01221 function supported_product_drop_down($name, $contactid, $productid) 01222 { 01223 global $CONFIG, $dbSupportContacts, $dbMaintenance, $dbProducts, $strXIncidentsLeft; 01224 01225 $sql = "SELECT *, p.id AS productid, p.name AS productname FROM `{$dbSupportContacts}` AS sc, `{$dbMaintenance}` AS m, `{$dbProducts}` AS p "; 01226 $sql .= "WHERE sc.maintenanceid = m.id AND m.product = p.id "; 01227 $sql .= "AND sc.contactid='$contactid'"; 01228 01229 $result = mysql_query($sql); 01230 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01231 01232 if ($CONFIG['debug']) $html .= "<!-- Original product {$productid}-->"; 01233 $html .= "<select name=\"$name\">\n"; 01234 if ($productid == 0) 01235 { 01236 $html .= "<option selected='selected' value='0'>No Contract - Not Product Related</option>\n"; 01237 } 01238 01239 if ($productid == -1) 01240 { 01241 $html .= "<option selected='selected' value='0'></option>\n"; 01242 } 01243 01244 while ($products = mysql_fetch_objecy($result)) 01245 { 01246 $remainingstring = sprintf($strXIncidentsLeft, incidents_remaining($products->incidentpoolid)); 01247 $html .= "<option "; 01248 if ($productid == $products->productid) 01249 { 01250 $html .= "selected='selected' "; 01251 } 01252 $html .= "value='{$products->productid}'>"; 01253 $html .= servicelevel_name($products->servicelevelid)." ".$products->productname.", Exp:".date($CONFIG['dateformat_shortdate'], $products->expirydate).", $remainingstring"; 01254 $html .= "</option>\n"; 01255 } 01256 $html .= "</select>\n"; 01257 return $html; 01258 } 01259 01260 01268 function role_drop_down($name, $id) 01269 { 01270 01271 global $dbRoles; 01272 $sql = "SELECT id, rolename FROM `{$dbRoles}` ORDER BY rolename ASC"; 01273 $result = mysql_query($sql); 01274 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01275 01276 $html = "<select name='{$name}'>"; 01277 if ($id == 0) 01278 { 01279 $html .= "<option selected='selected' value='0'></option>\n"; 01280 } 01281 01282 while ($role = mysql_fetch_object($result)) 01283 { 01284 $html .= "<option value='{$role->id}'"; 01285 if ($role->id == $id) 01286 { 01287 $html .= " selected='selected'"; 01288 } 01289 01290 $html .= ">{$role->rolename}</option>\n"; 01291 } 01292 $html .= "</select>\n"; 01293 return $html; 01294 } 01295 01296 01304 function group_drop_down($name, $selected) 01305 { 01306 global $grouparr, $numgroups; 01307 $html = "<select name='$name'>"; 01308 $html .= "<option value='0'>{$GLOBALS['strNone']}</option>\n"; 01309 if ($numgroups >= 1) 01310 { 01311 foreach ($grouparr AS $groupid => $groupname) 01312 { 01313 $html .= "<option value='$groupid'"; 01314 if ($groupid == $selected) 01315 { 01316 $html .= " selected='selected'"; 01317 } 01318 $html .= ">$groupname</option>\n"; 01319 } 01320 } 01321 $html .= "</select>\n"; 01322 return $html; 01323 } 01324 01325 01333 function group_selector($selected, $urlargs='') 01334 { 01335 $gsql = "SELECT * FROM `{$GLOBALS['dbGroups']}` ORDER BY name"; 01336 $gresult = mysql_query($gsql); 01337 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01338 while ($group = mysql_fetch_object($gresult)) 01339 { 01340 $grouparr[$group->id] = $group->name; 01341 } 01342 $numgroups = mysql_num_rows($gresult); 01343 01344 if (!empty($urlargs)) $urlargs = "&{$urlargs}"; 01345 if ($numgroups >= 1) 01346 { 01347 echo "<form action='{$_SERVER['PHP_SELF']}?{$urlargs}' class='filterform' method='get'>"; 01348 echo "{$GLOBALS['strGroup']}: <select name='choosegroup' onchange='window.location.href=this.options[this.selectedIndex].value'>"; 01349 echo "<option value='{$_SERVER['PHP_SELF']}?gid=all{$urlargs}'"; 01350 if ($selected == 'all') echo " selected='selected'"; 01351 echo ">{$GLOBALS['strAll']}</option>\n"; 01352 echo "<option value='{$_SERVER['PHP_SELF']}?gid=allonline{$urlargs}'"; 01353 if ($selected == 'allonline') echo " selected='selected'"; 01354 echo ">{$GLOBALS['strAllOnline']}</option>\n"; 01355 foreach ($grouparr AS $groupid => $groupname) 01356 { 01357 echo "<option value='{$_SERVER['PHP_SELF']}?gid={$groupid}{$urlargs}'"; 01358 if ($groupid == $selected) echo " selected='selected'"; 01359 echo ">{$groupname}</option>\n"; 01360 } 01361 echo "<option value='{$_SERVER['PHP_SELF']}?gid=0{$urlargs}'"; 01362 if ($selected === '0') echo " selected='selected'"; 01363 echo ">{$GLOBALS['strUsersNoGroup']}</option>\n"; 01364 echo "</select>\n"; 01365 echo "</form>\n"; 01366 } 01367 01368 return $numgroups; 01369 } 01370 01371 01379 function interfacestyle_drop_down($name, $id) 01380 { 01381 global $dbInterfaceStyles; 01382 // extract statuses 01383 $sql = "SELECT id, name FROM `{$dbInterfaceStyles}` ORDER BY name ASC"; 01384 $result = mysql_query($sql); 01385 $html = "<select name=\"{$name}\">"; 01386 if ($id == 0) 01387 { 01388 $html .= "<option selected='selected' value='0'></option>\n"; 01389 } 01390 01391 while ($styles = mysql_fetch_object($result)) 01392 { 01393 $html .= "<option "; 01394 if ($styles->id == $id) 01395 { 01396 $html .= "selected='selected'"; 01397 } 01398 01399 $html .= " value=\"{$styles->id}\">{$styles->name}</option>\n"; 01400 } 01401 $html .= "</select>\n"; 01402 return $html; 01403 } 01404 01405 01412 function interface_style($id) 01413 { 01414 global $CONFIG, $dbInterfaceStyles; 01415 01416 $sql = "SELECT cssurl, headerhtml FROM `{$dbInterfaceStyles}` WHERE id='$id'"; 01417 $result = mysql_query($sql); 01418 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01419 01420 if (mysql_num_rows($result) == 0) 01421 { 01422 mysql_free_result($result); 01423 $style = (array($CONFIG['default_css_url'],'')); // default style 01424 } 01425 else 01426 { 01427 $style = mysql_fetch_assoc($result); 01428 mysql_free_result($result); 01429 } 01430 01431 if (empty($style)) 01432 { 01433 $style = (array($CONFIG['default_css_url'],'')); // default style 01434 } 01435 01436 return ($style); 01437 } 01438 01439 01449 function incidentstatus_drop_down($name, $id, $disabled = FALSE) 01450 { 01451 global $dbIncidentStatus; 01452 // extract statuses 01453 $sql = "SELECT id, name FROM `{$dbIncidentStatus}` WHERE id<>2 AND id<>7 AND id<>10 ORDER BY name ASC"; 01454 $result = mysql_query($sql); 01455 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01456 if (mysql_num_rows($result) < 1) 01457 { 01458 trigger_error("Zero rows returned",E_USER_WARNING); 01459 } 01460 01461 $html = "<select id='{$name}' name='{$name}'"; 01462 if ($disabled) 01463 { 01464 $html .= " disabled='disabled' "; 01465 } 01466 $html .= ">"; 01467 // if ($id == 0) $html .= "<option selected='selected' value='0'></option>\n"; 01468 while ($statuses = mysql_fetch_object($result)) 01469 { 01470 $html .= "<option "; 01471 if ($statuses->id == $id) 01472 { 01473 $html .= "selected='selected' "; 01474 } 01475 01476 $html .= "value='{$statuses->id}'"; 01477 $html .= ">{$GLOBALS[$statuses->name]}</option>\n"; 01478 } 01479 $html .= "</select>\n"; 01480 return $html; 01481 } 01482 01483 01492 function closingstatus_drop_down($name, $id, $required = FALSE) 01493 { 01494 global $dbClosingStatus; 01495 // extract statuses 01496 $sql = "SELECT id, name FROM `{$dbClosingStatus}` ORDER BY name ASC"; 01497 $result = mysql_query($sql); 01498 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01499 $html = "<select name='{$name}'"; 01500 if ($required) 01501 { 01502 $html .= " class='required' "; 01503 } 01504 $html .= ">"; 01505 if ($id == 0) 01506 { 01507 $html .= "<option selected='selected' value='0'></option>\n"; 01508 } 01509 01510 while ($statuses = mysql_fetch_object($result)) 01511 { 01512 $html .= "<option "; 01513 if ($statuses->id == $id) 01514 { 01515 $html .= "selected='selected' "; 01516 } 01517 $html .= "value='{$statuses->id}'>"; 01518 if (isset($GLOBALS[$statuses->name])) 01519 { 01520 $html .= $GLOBALS[$statuses->name]; 01521 } 01522 else 01523 { 01524 $html .= $statuses->name; 01525 } 01526 $html .= "</option>\n"; 01527 } 01528 $html .= "</select>\n"; 01529 01530 return $html; 01531 } 01532 01533 01542 function userstatus_drop_down($name, $id, $userdisable = FALSE) 01543 { 01544 global $dbUserStatus; 01545 // extract statuses 01546 $sql = "SELECT id, name FROM `{$dbUserStatus}` ORDER BY name ASC"; 01547 $result = mysql_query($sql); 01548 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01549 01550 $html = "<select name='$name'>\n"; 01551 if ($userdisable) 01552 { 01553 $html .= "<option class='disable' selected='selected' value='0'>ACCOUNT DISABLED</option>\n"; 01554 } 01555 01556 while ($statuses = mysql_fetch_object($result)) 01557 { 01558 if ($statuses->id > 0) 01559 { 01560 $html .= "<option "; 01561 if ($statuses->id == $id) 01562 { 01563 $html .= "selected='selected' "; 01564 } 01565 $html .= "value='{$statuses->id}'>"; 01566 $html .= "{$GLOBALS[$statuses->name]}</option>\n"; 01567 } 01568 } 01569 $html .= "</select>\n"; 01570 01571 return $html; 01572 } 01573 01574 01583 function userstatus_bardrop_down($name, $id) 01584 { 01585 global $dbUserStatus; 01586 // extract statuses 01587 $sql = "SELECT id, name FROM `{$dbUserStatus}` ORDER BY name ASC"; 01588 $result = mysql_query($sql); 01589 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01590 01591 $html = "<select name='$name' title='{$GLOBALS['strSetYourStatus']}' onchange=\"if "; 01592 $html .= "(this.options[this.selectedIndex].value != 'null') { "; 01593 $html .= "window.open(this.options[this.selectedIndex].value,'_top') }\">"; 01594 $html .= "\n"; 01595 while ($statuses = mysql_fetch_object($result)) 01596 { 01597 if ($statuses->id > 0) 01598 { 01599 $html .= "<option "; 01600 if ($statuses->id == $id) 01601 { 01602 $html .= "selected='selected' "; 01603 } 01604 01605 $html .= "value='set_user_status.php?mode=setstatus&"; 01606 $html .= "userstatus={$statuses->id}'>"; 01607 $html .= "{$GLOBALS[$statuses->name]}</option>\n"; 01608 } 01609 } 01610 $html .= "<option value='set_user_status.php?mode=setaccepting"; 01611 $html .= "&accepting=Yes' class='enable seperator'>"; 01612 $html .= "{$GLOBALS['strAccepting']}</option>\n"; 01613 $html .= "<option value='set_user_status.php?mode=setaccepting&"; 01614 $html .= "accepting=No' class='disable'>{$GLOBALS['strNotAccepting']}"; 01615 $html .= "</option></select>\n"; 01616 01617 return $html; 01618 } 01619 01620 01629 function emailtemplate_drop_down($name, $id, $type) 01630 { 01631 global $dbEmailTemplates; 01632 // INL 22Apr05 Added a filter to only show user templates 01633 01634 $sql = "SELECT id, name, description FROM `{$dbEmailTemplates}` WHERE type='{$type}' ORDER BY name ASC"; 01635 $result = mysql_query($sql); 01636 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01637 01638 $html = "<select name=\"{$name}\">"; 01639 if ($id == 0) 01640 { 01641 $html .= "<option selected='selected' value='0'></option>\n"; 01642 } 01643 01644 while ($template = mysql_fetch_object($result)) 01645 { 01646 $html .= "<option "; 01647 if (!empty($template->description)) 01648 { 01649 $html .= "title='{$template->description}' "; 01650 } 01651 01652 if ($template->id == $id) 01653 { 01654 $html .= "selected='selected' "; 01655 } 01656 $html .= "value='{$template->id}'>{$template->name}</option>"; 01657 $html .= "\n"; 01658 } 01659 $html .= "</select>\n"; 01660 01661 return $html; 01662 } 01663 01664 01674 function priority_drop_down($name, $id, $max=4, $disable = FALSE) 01675 { 01676 global $CONFIG, $iconset; 01677 // INL 8Oct02 - Removed DB Query 01678 $html = "<select id='priority' name='$name' "; 01679 if ($disable) 01680 { 01681 $html .= "disabled='disabled'"; 01682 } 01683 01684 $html .= ">"; 01685 if ($id == 0) 01686 { 01687 $html .= "<option selected='selected' value='0'></option>\n"; 01688 } 01689 01690 $html .= "<option style='text-indent: 14px; background-image: url({$CONFIG['application_webpath']}images/low_priority.gif); background-repeat:no-repeat;' value='1'"; 01691 if ($id == 1) 01692 { 01693 $html .= " selected='selected'"; 01694 } 01695 01696 $html .= ">{$GLOBALS['strLow']}</option>\n"; 01697 $html .= "<option style='text-indent: 14px; background-image: url({$CONFIG['application_webpath']}images/med_priority.gif); background-repeat:no-repeat;' value='2'"; 01698 if ($id == 2) 01699 { 01700 $html .= " selected='selected'"; 01701 } 01702 01703 $html .= ">{$GLOBALS['strMedium']}</option>\n"; 01704 $html .= "<option style='text-indent: 14px; background-image: url({$CONFIG['application_webpath']}images/high_priority.gif); background-repeat:no-repeat;' value='3'"; 01705 if ($id==3) 01706 { 01707 $html .= " selected='selected'"; 01708 } 01709 01710 $html .= ">{$GLOBALS['strHigh']}</option>\n"; 01711 if ($max >= 4) 01712 { 01713 $html .= "<option style='text-indent: 14px; background-image: url({$CONFIG['application_webpath']}images/crit_priority.gif); background-repeat:no-repeat;' value='4'"; 01714 if ($id==4) 01715 { 01716 $html .= " selected='selected'"; 01717 } 01718 $html .= ">{$GLOBALS['strCritical']}</option>\n"; 01719 } 01720 $html .= "</select>\n"; 01721 01722 return $html; 01723 } 01724 01725 01733 function accepting_drop_down($name, $userid) 01734 { 01735 if (user_accepting($userid) == "Yes") 01736 { 01737 $html = "<select name=\"$name\">\n"; 01738 $html .= "<option selected='selected' value=\"Yes\">{$GLOBALS['strYes']}</option>\n"; 01739 $html .= "<option value=\"No\">{$GLOBALS['strNo']}</option>\n"; 01740 $html .= "</select>\n"; 01741 } 01742 else 01743 { 01744 $html = "<select name=\"$name\">\n"; 01745 $html .= "<option value=\"Yes\">{$GLOBALS['strYes']}</option>\n"; 01746 $html .= "<option selected='selected' value=\"No\">{$GLOBALS['strNo']}</option>\n"; 01747 $html .= "</select>\n"; 01748 } 01749 return $html; 01750 } 01751 01752 01759 function escalation_path_drop_down($name, $id) 01760 { 01761 global $dbEscalationPaths; 01762 $sql = "SELECT id, name FROM `{$dbEscalationPaths}` "; 01763 $sql .= "ORDER BY name ASC"; 01764 $result = mysql_query($sql); 01765 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01766 $html = "<select name='{$name}' id='{$name}' >"; 01767 $html .= "<option selected='selected' value='0'>{$GLOBALS['strNone']}</option>\n"; 01768 while ($path = mysql_fetch_object($result)) 01769 { 01770 $html .= "<option value='{$path->id}'"; 01771 if ($path->id ==$id) 01772 { 01773 $html .= " selected='selected'"; 01774 } 01775 $html .= ">{$path->name}</option>\n"; 01776 } 01777 $html .= "</select>\n"; 01778 01779 return $html; 01780 } 01781 01782 01793 function priority_name($id, $syslang = FALSE) 01794 { 01795 switch ($id) 01796 { 01797 case 1: 01798 if (!$syslang) $value = $GLOBALS['strLow']; 01799 else $value = $_SESSION['syslang']['strLow']; 01800 break; 01801 case 2: 01802 if (!$syslang) $value = $GLOBALS['strMedium']; 01803 else $value = $_SESSION['syslang']['strMedium']; 01804 break; 01805 case 3: 01806 if (!$syslang) $value = $GLOBALS['strHigh']; 01807 else $value = $_SESSION['syslang']['strHigh']; 01808 break; 01809 case 4: 01810 if (!$syslang) $value = $GLOBALS['strCritical']; 01811 else $value = $_SESSION['syslang']['strCritical']; 01812 break; 01813 case '': 01814 if (!$sylang) $value = $GLOBALS['strNotSet']; 01815 else $value = $_SESSION['syslang']['strNotSet']; 01816 break; 01817 default: 01818 if (!$syslang) $value = $GLOBALS['strUnknown']; 01819 else $value = $_SESSION['syslang']['strUnknown']; 01820 break; 01821 } 01822 return $value; 01823 } 01824 01825 01826 // Returns HTML for an icon to indicate priority 01827 function priority_icon($id) 01828 { 01829 global $CONFIG; 01830 switch ($id) 01831 { 01832 case 1: $html = "<img src='{$CONFIG['application_webpath']}images/low_priority.gif' width='10' height='16' alt='{$GLOBALS['strLowPriority']}' title='{$GLOBALS['strLowPriority']}' />"; break; 01833 case 2: $html = "<img src='{$CONFIG['application_webpath']}images/med_priority.gif' width='10' height='16' alt='{$GLOBALS['strMediumPriority']}' title='{$GLOBALS['strMediumPriority']}' />"; break; 01834 case 3: $html = "<img src='{$CONFIG['application_webpath']}images/high_priority.gif' width='10' height='16' alt='{$GLOBALS['strHighPriority']}' title='{$GLOBALS['strHighPriority']}' />"; break; 01835 case 4: $html = "<img src='{$CONFIG['application_webpath']}images/crit_priority.gif' width='16' height='16' alt='{$GLOBALS['strCriticalPriority']}' title='{$GLOBALS['strCriticalPriority']}' />"; break; 01836 default: $html = '?'; break; 01837 } 01838 return $html; 01839 } 01840 01841 01848 function incident_lastupdate($id) 01849 { 01850 // Find the most recent update 01851 $sql = "SELECT userid, type, sla, currentowner, currentstatus, LEFT(bodytext,500) AS body, timestamp, nextaction, id "; 01852 $sql .= "FROM `{$GLOBALS['dbUpdates']}` WHERE incidentid='{$id}' AND bodytext != '' ORDER BY timestamp DESC, id DESC LIMIT 1"; 01853 $result = mysql_query($sql); 01854 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01855 01856 if (mysql_num_rows($result) == 0) 01857 { 01858 trigger_error("Zero records while retrieving incident last update for incident {$id}",E_USER_WARNING); 01859 } 01860 else 01861 { 01862 $update = mysql_fetch_array($result); 01863 01864 mysql_free_result($result); 01865 // Remove Tags from update Body 01866 $update['body'] = trim($update['body']); 01867 $update['body'] = $update['body']; 01868 return array($update['userid'], $update['type'] ,$update['currentowner'], $update['currentstatus'], $update['body'], $update['timestamp'], $update['nextaction'], $update['id']); 01869 } 01870 } 01871 01872 01879 function incident_firstupdate($id) 01880 { 01881 $sql = "SELECT bodytext FROM `{$GLOBALS['dbUpdates']}` WHERE incidentid='$id' AND customervisibility='show' ORDER BY timestamp ASC, id ASC LIMIT 1"; 01882 $result = mysql_query($sql); 01883 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01884 01885 if (mysql_num_rows($result) >= 1) 01886 { 01887 list($bodytext) = mysql_fetch_row($result); 01888 $bodytext = strip_tags($bodytext); 01889 } 01890 else 01891 { 01892 $bodytext = ''; 01893 } 01894 01895 return $bodytext; 01896 } 01897 01898 01908 function incidentstatus_name($id, $type='internal') 01909 { 01910 global $dbIncidentStatus; 01911 01912 if ($type == 'external') 01913 { 01914 $type = 'ext_name'; 01915 } 01916 else 01917 { 01918 $type = 'name'; 01919 } 01920 01921 $sql = "SELECT {$type} FROM `{$dbIncidentStatus}` WHERE id='{$id}'"; 01922 $result = mysql_query($sql); 01923 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01924 01925 if (mysql_num_rows($result) == 0) 01926 { 01927 $name = ''; 01928 } 01929 else 01930 { 01931 $incidentstatus = mysql_fetch_assoc($result); 01932 $name = $GLOBALS[$incidentstatus[$type]]; 01933 } 01934 return $name; 01935 } 01936 01937 01938 function closingstatus_name($id) 01939 { 01940 global $dbClosingStatus; 01941 if ($id != '') 01942 { 01943 $closingstatus = db_read_column('name', $GLOBALS['dbClosingStatus'], $id); 01944 } 01945 else 01946 { 01947 $closingstatus = 'strUnknown'; 01948 } 01949 01950 return ($GLOBALS[$closingstatus]); 01951 } 01952 01953 01964 function incident_drop_down($name, $id, $contactid = 0) 01965 { 01966 global $dbIncidents; 01967 01968 $html = ''; 01969 01970 $sql = "SELECT * FROM `{$dbIncidents}` WHERE status != ".STATUS_CLOSED . " "; 01971 if ($contactid > 0) $sql .= "AND contact = {$contactid}"; 01972 $result = mysql_query($sql); 01973 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 01974 01975 if (mysql_num_rows($result) > 0) 01976 { 01977 $html = "<select id='{$name}' name='{$name}' {$select}>\n"; 01978 while ($incident = mysql_fetch_object($result)) 01979 { 01980 // FIXME unfinished 01981 $html .= "<option value='{$incident->id}'>[{$incident->id}] - "; 01982 $html .= "{$incident->title}</option>"; 01983 } 01984 01985 $html .= "</select>"; 01986 } 01987 else 01988 { 01989 $html = "<input type='text' name='{$name}' value='' size='10' maxlength='12' />"; 01990 } 01991 return $html; 01992 } 01993 01994 01995 /* Returns a string representing the name of */ 01996 /* the given user status. Returns an empty string if the */ 01997 /* status does not exist. */ 01998 function userstatus_name($id) 01999 { 02000 $status = db_read_column('name', $GLOBALS['dbUserStatus'], $id); 02001 return $GLOBALS[$status]; 02002 } 02003 02004 02005 02006 /* Returns a string representing the name of */ 02007 /* the given product. Returns an empty string if the product */ 02008 /* does not exist. */ 02009 function product_name($id) 02010 { 02011 return db_read_column('name', $GLOBALS['dbProducts'], $id); 02012 } 02013 02014 02022 function format_seconds($seconds, $showseconds = FALSE) 02023 { 02024 global $str1Year, $str1Hour, $str1Minute, $str1Day, $str1Month, $strXSeconds, $str1Second; 02025 global $strXHours, $strXMinutes, $strXDays, $strXMonths, $strXYears; 02026 02027 if ($seconds <= 0) 02028 { 02029 return sprintf($strXMinutes, 0); 02030 } 02031 elseif ($seconds <= 60 AND $seconds >= 1 AND $showseconds == FALSE) 02032 { 02033 return $str1Minute; 02034 } 02035 elseif ($seconds < 60 AND $seconds >= 1 AND $showseconds == TRUE) 02036 { 02037 if ($seconds == 1) 02038 { 02039 return $str1Second; 02040 } 02041 else 02042 { 02043 return sprintf($strXSeconds, $seconds); 02044 } 02045 } 02046 else 02047 { 02048 $years = floor($seconds / ( 2629800 * 12)); 02049 $remainder = ($seconds % ( 2629800 * 12)); 02050 $months = floor($remainder / 2629800); 02051 $remainder = ($seconds % 2629800); 02052 $days = floor($remainder / 86400); 02053 $remainder = ($remainder % 86400); 02054 $hours = floor($remainder / 3600); 02055 $remainder = ($remainder % 3600); 02056 $minutes = floor($remainder / 60); 02057 02058 $return_string = ''; 02059 02060 if ($years > 0) 02061 { 02062 if ($years == 1) 02063 { 02064 $return_string .= $str1Year.' '; 02065 } 02066 else 02067 { 02068 $return_string .= sprintf($strXYears, $years).' '; 02069 } 02070 } 02071 02072 if ($months > 0 AND $years < 2) 02073 { 02074 if ($months == 1) 02075 { 02076 $return_string .= $str1Month." "; 02077 } 02078 else 02079 { 02080 $return_string .= sprintf($strXMonths, $months).' '; 02081 } 02082 } 02083 02084 if ($days > 0 AND $months < 6) 02085 { 02086 if ($days == 1) 02087 { 02088 $return_string .= $str1Day." "; 02089 } 02090 else 02091 { 02092 $return_string .= sprintf($strXDays, $days)." "; 02093 } 02094 } 02095 02096 if ($months < 1 AND $days < 7 AND $hours > 0) 02097 { 02098 if ($hours == 1) 02099 { 02100 $return_string .= $str1Hour." "; 02101 } 02102 else 02103 { 02104 $return_string .= sprintf($strXHours, $hours)." "; 02105 } 02106 } 02107 elseif ($months < 1 AND $days < 1 AND $hours > 0) 02108 { 02109 if ($minutes == 1) 02110 { 02111 $return_string .= $str1Minute." "; 02112 } 02113 elseif ($minutes > 1) 02114 { 02115 $return_string .= sprintf($strXMinutes, $minutes)." "; 02116 } 02117 } 02118 02119 if ($months < 1 AND $days < 1 AND $hours < 1) 02120 { 02121 if ($minutes <= 1) 02122 { 02123 $return_string .= $str1Minute." "; 02124 } 02125 else 02126 { 02127 $return_string .= sprintf($strXMinutes, $minutes)." "; 02128 } 02129 } 02130 02131 $return_string = trim($return_string); 02132 if (empty($return_string)) $return_string = "({$seconds})"; 02133 return $return_string; 02134 } 02135 } 02136 02137 02145 function format_workday_minutes($minutes) 02146 { 02147 global $CONFIG, $strXMinutes, $str1Minute, $strXHours, $strXHour; 02148 global $strXWorkingDay, $strXWorkingDays; 02149 $working_day_mins = ($CONFIG['end_working_day'] - $CONFIG['start_working_day']) / 60; 02150 $days = floor($minutes / $working_day_mins); 02151 $remainder = ($minutes % $working_day_mins); 02152 $hours = floor($remainder / 60); 02153 $minutes = floor($remainder % 60); 02154 02155 if ($days == 1) 02156 { 02157 $time = sprintf($strXWorkingDay, $days); 02158 } 02159 elseif ($days > 1) 02160 { 02161 $time = sprintf($strXWorkingDays, $days); 02162 } 02163 02164 if ($days <= 3 AND $hours == 1) 02165 { 02166 $time .= " ".sprintf($strXHour, $hours); 02167 } 02168 elseif ($days <= 3 AND $hours > 1) 02169 { 02170 $time .= " ".sprintf($strXHours, $hours); 02171 } 02172 elseif ($days > 3 AND $hours >= 1) 02173 { 02174 $time = "> ".$time; 02175 } 02176 02177 if ($days < 1 AND $hours < 8 AND $minutes == 1) 02178 { 02179 $time .= " ".$str1Minute; 02180 } 02181 elseif ($days < 1 AND $hours < 8 AND $minutes > 1) 02182 { 02183 $time .= " ".sprintf($strXMinutes, $minutes); 02184 } 02185 02186 if ($days == 1 AND $hours < 8 AND $minutes == 1) 02187 { 02188 $time .= " ".$str1Minute; 02189 } 02190 elseif ($days == 1 AND $hours < 8 AND $minutes > 1) 02191 { 02192 $time .= " ".sprintf($strXMinutes, $minutes); 02193 } 02194 02195 $time = trim($time); 02196 02197 return $time; 02198 } 02199 02200 02208 function format_date_friendly($date) 02209 { 02210 global $CONFIG, $now; 02211 if (ldate('dmy', $date) == ldate('dmy', time())) 02212 { 02213 $datestring = "{$GLOBALS['strToday']} @ ".ldate($CONFIG['dateformat_time'], $date); 02214 } 02215 elseif (ldate('dmy', $date) == ldate('dmy', (time() - 86400))) 02216 { 02217 $datestring = "{$GLOBALS['strYesterday']} @ ".ldate($CONFIG['dateformat_time'], $date); 02218 } 02219 elseif ($date < $now-86400 AND 02220 $date > $now-(86400*6)) 02221 { 02222 $datestring = ldate('l', $date)." @ ".ldate($CONFIG['dateformat_time'], $date); 02223 } 02224 else 02225 { 02226 $datestring = ldate($CONFIG['dateformat_datetime'], $date); 02227 } 02228 02229 return ($datestring); 02230 } 02231 02232 02233 02234 02235 /* calculates the value of the unix timestamp */ 02236 /* which is the number of given days, hours and minutes from */ 02237 /* the current time. */ 02238 function calculate_time_of_next_action($days, $hours, $minutes) 02239 { 02240 $now = time(); 02241 $return_value = $now + ($days * 86400) + ($hours * 3600) + ($minutes * 60); 02242 return ($return_value); 02243 } 02244 02245 02254 function maintenance_servicelevel($maintid) 02255 { 02256 global $CONFIG, $dbMaintenance; 02257 $sql = "SELECT servicelevelid FROM `{$dbMaintenance}` WHERE id='{$maintid}' "; 02258 $result = mysql_query($sql); 02259 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 02260 02261 if (mysql_num_rows($result) < 1) 02262 { 02263 // in case there is no maintenance contract associated with the incident, use default service level 02264 // if there is a maintenance contract then we should throw an error because there should be 02265 // service level 02266 if ($maintid == 0) 02267 { 02268 // Convert the default service level tag to an ide and use that 02269 $servicelevelid = servicelevel_tag2id($CONFIG['default_service_level']); 02270 } 02271 } 02272 else 02273 { 02274 list($servicelevelid) = mysql_fetch_row($result); 02275 } 02276 return $servicelevelid; 02277 02278 } 02279 02280 02281 function maintenance_siteid($id) 02282 { 02283 return db_read_column('site', $GLOBALS['dbMaintenance'], $id); 02284 02285 } 02286 02287 02288 // Returns the number of remaining incidents given an incident pool id 02289 // Returns 'Unlimited' if theres no match on ID 02290 function incidents_remaining($id) 02291 { 02292 $remaining = db_read_column('incidentsremaining', $GLOBALS['dbIncidentPools'], $id); 02293 if (empty($remaining)) 02294 { 02295 $remaining = '∞'; 02296 } 02297 02298 return $remaining; 02299 } 02300 02301 02302 function decrement_free_incidents($siteid) 02303 { 02304 global $dbSites; 02305 $sql = "UPDATE `{$dbSites}` SET freesupport = (freesupport - 1) WHERE id='$siteid'"; 02306 mysql_query($sql); 02307 if (mysql_affected_rows() < 1) 02308 { 02309 trigger_error("No rows affected while updating freesupport",E_USER_ERROR); 02310 } 02311 02312 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 02313 else return TRUE; 02314 } 02315 02316 02317 function increment_incidents_used($maintid) 02318 { 02319 global $dbMaintenance; 02320 $sql = "UPDATE `{$dbMaintenance}` SET incidents_used = (incidents_used + 1) WHERE id='$maintid'"; 02321 mysql_query($sql); 02322 if (mysql_affected_rows() < 1) trigger_error("No rows affected while updating freesupport",E_USER_ERROR); 02323 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 02324 else return TRUE; 02325 } 02326 02327 02338 function sit_error_handler($errno, $errstr, $errfile, $errline, $errcontext) 02339 { 02340 global $CONFIG, $sit, $siterrors; 02341 02342 // if error has been supressed with an @ 02343 if (error_reporting() == 0) 02344 { 02345 return; 02346 } 02347 02348 $errortype = array( 02349 E_ERROR => 'Fatal Error', 02350 E_WARNING => 'Warning', 02351 E_PARSE => 'Parse Error', 02352 E_NOTICE => 'Notice', 02353 E_CORE_ERROR => 'Core Error', 02354 E_CORE_WARNING => 'Core Warning', 02355 E_COMPILE_ERROR => 'Compile Error', 02356 E_COMPILE_WARNING => 'Compile Warning', 02357 E_USER_ERROR => 'Application Error', 02358 E_USER_WARNING => 'Application Warning', 02359 E_USER_NOTICE => 'Application Notice'); 02360 02361 if (defined('E_STRICT')) $errortype[E_STRICT] = 'Strict Runtime notice'; 02362 02363 $trace_errors = array(E_ERROR, E_USER_ERROR); 02364 02365 $user_errors = E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE; 02366 $system_errors = E_ERROR | E_WARNING | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING; 02367 $warnings = E_WARNING | E_USER_WARNING | E_CORE_WARNING | E_COMPILE_WARNING; 02368 $notices = E_NOTICE | E_USER_NOTICE; 02369 02370 if (($errno & $user_errors) OR ($errno & $system_errors)) 02371 { 02372 if (empty($CONFIG['error_logfile']) === FALSE AND is_writable($CONFIG['error_logfile']) === TRUE) 02373 { 02374 $displayerrors = FALSE; 02375 } 02376 else 02377 { 02378 $displayerrors = TRUE; 02379 } 02380 02381 if ($errno & $notices) $class = 'info'; 02382 elseif ($errno & $warnings) $class = 'warning'; 02383 else $class = 'error'; 02384 02385 $backtrace = debug_backtrace(); 02386 if (php_sapi_name() != 'cli') 02387 { 02388 $tracelog = ''; 02389 if ($displayerrors) 02390 { 02391 echo "<p class='{$class}'><strong>{$errortype[$errno]} [{$errno}]</strong><br />"; 02392 echo "{$errstr} in {$errfile} @ line {$errline}"; 02393 if ($CONFIG['debug']) echo "<br /><strong>Backtrace</strong>:"; 02394 } 02395 02396 foreach ($backtrace AS $trace) 02397 { 02398 if (!empty($trace['file'])) 02399 { 02400 if ($CONFIG['debug'] AND $displayerrors) 02401 { 02402 echo "<br />{$trace['file']} @ line {$trace['line']}"; 02403 } 02404 02405 $tracelog .= "{$trace['file']} @ line {$trace['line']}"; 02406 if (!empty($trace['function'])) 02407 { 02408 $tracelog .= " {$trace['function']}()"; 02409 if ($displayerrors) echo " {$trace['function']}() "; 02410 // foreach ($trace['args'] AS $arg) 02411 // { 02412 // echo "$arg • "; 02413 // } 02414 } 02415 $tracelog .= "\n"; 02416 } 02417 } 02418 if ($errno != E_NOTICE) 02419 { 02420 $logentry = " {$errortype[$errno]} [{$errno}] {$errstr} (in line {$errline} of file {$errfile})\n"; 02421 } 02422 02423 if ($errno == E_ERROR 02424 || $errno == E_USER_ERROR 02425 || $errno == E_CORE_ERROR 02426 || $errno == E_CORE_WARNING 02427 || $errno == E_COMPILE_ERROR 02428 || $errno == E_COMPILE_WARNING) 02429 { 02430 $logentry .= "Context: [CONTEXT-BEGIN]\n".print_r($errcontext, TRUE)."\n[CONTEXT-END]\n----------\n\n"; 02431 $siterrors++; 02432 } 02433 02434 debug_log($logentry); 02435 if ($displayerrors) 02436 { 02437 echo "</p>"; 02438 // Tips, to help diagnose errors 02439 if (strpos($errstr, 'Unknown column') !== FALSE OR 02440 preg_match("/Table '(.*)' doesn't exist/", $errstr)) 02441 { 02442 echo "<p class='tip'>The SiT schema may need updating to fix this problem."; 02443 if (user_permission($sit[2], 22)) echo "Visit <a href='setup.php'>Setup</a>"; // Only show this to admin 02444 echo "</p>"; 02445 } 02446 02447 if (strpos($errstr, 'headers already sent') !== FALSE) 02448 { 02449 echo "<p class='tip'>This warning may be caused by a problem that occurred before the "; 02450 echo "page was displayed, or sometimes by a syntax error or "; 02451 echo "extra whitespace in your config file.</p>"; 02452 } 02453 02454 if (strpos($errstr, 'You have an error in your SQL syntax') !== FALSE OR 02455 strpos($errstr, 'Query Error Incorrect table name') !== FALSE) 02456 { 02457 echo "<p class='tip'>You may have found a bug in SiT, please <a href=\"{$CONFIG['bugtracker_url']}\">report it</a>.</p>"; 02458 } 02459 } 02460 } 02461 else 02462 { 02463 debug_log("ERROR: {$errortype[$errno]} {$errstr} in {$errfile} at line {$errline}\n"); 02464 if (!empty($tracelog)) debug_log("ERROR: Backtrace:\n{$tracelog}\n"); 02465 } 02466 } 02467 } 02468 02469 02479 function debug_log($logentry, $debugmodeonly = FALSE) 02480 { 02481 global $CONFIG; 02482 02483 if ($debugmodeonly == FALSE 02484 OR ($debugmodeonly == TRUE AND $CONFIG['debug_mode'] == TRUE)) 02485 { 02486 $logentry = $_SERVER["SCRIPT_NAME"] . ' ' .$logentry; 02487 02488 if (substr($logentry, -1) != "\n") $logentry .= "\n"; 02489 if (!empty($CONFIG['error_logfile'])) 02490 { 02491 if (file_exists($CONFIG['error_logfile'])) 02492 { 02493 if (is_writable($CONFIG['error_logfile'])) 02494 { 02495 $fp = fopen($CONFIG['error_logfile'], 'a+'); 02496 if ($fp) 02497 { 02498 fwrite($fp, date('c').' '.$logentry); 02499 fclose($fp); 02500 } 02501 else 02502 { 02503 echo "<p class='error'>Could not log message to error_logfile</p>"; 02504 trigger_error("Could not log message to error_logfile", E_USER_NOTICE); 02505 return FALSE; 02506 } 02507 return TRUE; 02508 } 02509 else 02510 { 02511 trigger_error("Debug log file (error_logfile) [{$CONFIG['error_logfile']}] not writable", E_USER_WARNING); 02512 } 02513 } 02514 else 02515 { 02516 trigger_error("Debug log file (error_logfile) [{$CONFIG['error_logfile']}] not found", E_USER_WARNING); 02517 } 02518 02519 } 02520 else 02521 { 02522 return FALSE; 02523 } 02524 } 02525 else return TRUE; 02526 } 02527 02528 02529 02538 function site_drop_down($name, $id, $required = FALSE, $showinactive = FALSE) 02539 { 02540 global $dbSites, $strEllipsis; 02541 $sql = "SELECT id, name, department FROM `{$dbSites}` "; 02542 if (!$showinactive) $sql .= "WHERE active = 'true' "; 02543 $sql .= "ORDER BY name ASC"; 02544 $result = mysql_query($sql); 02545 02546 $html = "<select name='{$name}'"; 02547 if ($required) 02548 { 02549 $html .= " class='required' "; 02550 } 02551 $html .= ">\n"; 02552 if ($id == 0) 02553 { 02554 $html .="<option selected='selected' value='0'></option>\n"; 02555 } 02556 02557 while ($sites = mysql_fetch_object($result)) 02558 { 02559 $text = $sites->name; 02560 if (!empty($sites->department)) 02561 { 02562 $text.= ", ".$sites->department; 02563 } 02564 02565 if (strlen($text) >= 55) 02566 { 02567 $text = mb_substr(trim($text), 0, 55, 'UTF-8').$strEllipsis; 02568 } 02569 else 02570 { 02571 $text = $text; 02572 } 02573 02574 $html .= "<option "; 02575 if ($sites->id == $id) 02576 { 02577 $html .= "selected='selected' "; 02578 } 02579 02580 $html .= "value='{$sites->id}'>{$text}</option>\n"; 02581 } 02582 $html .= "</select>\n"; 02583 02584 return $html; 02585 } 02586 02587 02588 function site_name($id) 02589 { 02590 $sitename = db_read_column('name', $GLOBALS['dbSites'], $id); 02591 if (empty($sitename)) 02592 { 02593 $sitename = $GLOBALS['strUnknown']; 02594 } 02595 02596 return ($sitename); 02597 } 02598 02599 02609 function maintenance_drop_down($name, $id, $siteid = '', $excludes = '', $return = FALSE, $showonlyactive = FALSE, $adminid = '') 02610 { 02611 global $GLOBALS, $now; 02612 // TODO make maintenance_drop_down a hierarchical selection box sites/contracts 02613 // extract all maintenance contracts 02614 $sql = "SELECT s.name AS sitename, p.name AS productname, m.id AS id "; 02615 $sql .= "FROM `{$GLOBALS['dbMaintenance']}` AS m, `{$GLOBALS['dbSites']}` AS s, `{$GLOBALS['dbProducts']}` AS p "; 02616 $sql .= "WHERE site = s.id AND product = p.id "; 02617 if (!empty($siteid)) $sql .= "AND s.id = {$siteid} "; 02618 02619 if ($showonlyactive) 02620 { 02621 $sql .= "AND (m.expirydate > {$now} OR m.expirydate = -1) "; 02622 } 02623 02624 if ($adminid != '') 02625 { 02626 $sql .= "AND admincontact = '{$adminid}' "; 02627 } 02628 02629 $sql .= "ORDER BY s.name ASC"; 02630 $result = mysql_query($sql); 02631 $results = 0; 02632 // print HTML 02633 $html .= "<select name='{$name}'>"; 02634 if ($id == 0 AND $results > 0) 02635 { 02636 $html .= "<option selected='selected' value='0'></option>\n"; 02637 } 02638 02639 while ($maintenance = mysql_fetch_object($result)) 02640 { 02641 if (!is_array($excludes) OR (is_array($excludes) AND !in_array($maintenance->id, $excludes))) 02642 { 02643 $html .= "<option "; 02644 if ($maintenance->id == $id) 02645 { 02646 $html .= "selected='selected' "; 02647 } 02648 $html .= "value='{$maintenance->id}'>{$maintenance->sitename} | {$maintenance->productname}</option>"; 02649 $html .= "\n"; 02650 $results++; 02651 } 02652 } 02653 02654 if ($results == 0) 02655 { 02656 $html .= "<option>{$GLOBALS['strNoRecords']}</option>"; 02657 } 02658 $html .= "</select>"; 02659 02660 if ($return) 02661 { 02662 return $html; 02663 } 02664 else 02665 { 02666 echo $html; 02667 } 02668 } 02669 02670 02671 // prints the HTML for a drop down list of resellers, with the given name and with the given id 02672 // selected. */ 02673 function reseller_drop_down($name, $id) 02674 { 02675 global $dbResellers; 02676 $sql = "SELECT id, name FROM `{$dbResellers}` ORDER BY name ASC"; 02677 $result = mysql_query($sql); 02678 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 02679 02680 // print HTML 02681 echo "<select name='{$name}'>"; 02682 02683 if ($id == 0 OR empty($id)) 02684 { 02685 echo "<option selected='selected' value='0'></option>\n"; 02686 } 02687 else 02688 { 02689 echo "<option value='0'></option>\n"; 02690 } 02691 02692 while ($resellers = mysql_fetch_object($result)) 02693 { 02694 echo "<option "; 02695 if ($resellers->id == $id) 02696 { 02697 echo "selected='selected' "; 02698 } 02699 02700 echo "value='{$resellers->id}'>{$resellers->name}</option>"; 02701 echo "\n"; 02702 } 02703 02704 echo "</select>"; 02705 } 02706 02707 02708 // prints the HTML for a drop down list of 02709 // licence types, with the given name and with the given id 02710 // selected. 02711 function licence_type_drop_down($name, $id) 02712 { 02713 global $dbLicenceTypes; 02714 $sql = "SELECT id, name FROM `{$dbLicenceTypes}` ORDER BY name ASC"; 02715 $result = mysql_query($sql); 02716 02717 // print HTML 02718 echo "<select name='{$name}'>"; 02719 02720 if ($id == 0) 02721 { 02722 echo "<option selected='selected' value='0'></option>\n"; 02723 } 02724 02725 while ($licencetypes = mysql_fetch_object($result)) 02726 { 02727 echo "<option "; 02728 if ($licencetypes->id == $id) 02729 { 02730 echo "selected='selected' "; 02731 } 02732 02733 echo "value='{$licencetypes->id}'>{$licencetypes->name}</option>"; 02734 echo "\n"; 02735 } 02736 02737 echo "</select>"; 02738 } 02739 02740 02744 function countdayincidents($day, $month, $year) 02745 { 02746 // Counts the number of incidents opened on a specified day 02747 global $dbIncidents; 02748 $unixstartdate = mktime(0,0,0,$month,$day,$year); 02749 $unixenddate = mktime(23,59,59,$month,$day,$year); 02750 $sql = "SELECT count(id) FROM `{$dbIncidents}` "; 02751 $sql .= "WHERE opened BETWEEN '$unixstartdate' AND '$unixenddate' "; 02752 $result = mysql_query($sql); 02753 list($count) = mysql_fetch_row($result); 02754 mysql_free_result($result); 02755 return $count; 02756 } 02757 02758 02762 function countdayclosedincidents($day, $month, $year) 02763 { 02764 // Counts the number of incidents closed on a specified day 02765 global $dbIncidents; 02766 $unixstartdate = mktime(0,0,0,$month,$day,$year); 02767 $unixenddate = mktime(23,59,59,$month,$day,$year); 02768 $sql = "SELECT COUNT(id) FROM `{$dbIncidents}` "; 02769 $sql .= "WHERE closed BETWEEN '$unixstartdate' AND '$unixenddate' "; 02770 $result = mysql_query($sql); 02771 list($count) = mysql_fetch_row($result); 02772 mysql_free_result($result); 02773 return $count; 02774 } 02775 02776 02780 function countdaycurrentincidents($day, $month, $year) 02781 { 02782 global $dbIncidents; 02783 // Counts the number of incidents currently open on a specified day 02784 $unixstartdate = mktime(0,0,0,$month,$day,$year); 02785 $unixenddate = mktime(23,59,59,$month,$day,$year); 02786 $sql = "SELECT COUNT(id) FROM `{$dbIncidents}` "; 02787 $sql .= "WHERE opened <= '$unixenddate' AND closed >= '$unixstartdate' "; 02788 $result = mysql_query($sql); 02789 list($count) = mysql_fetch_row($result); 02790 mysql_free_result($result); 02791 return $count; 02792 } 02793 02794 02808 function journal($loglevel, $event, $bodytext, $journaltype, $refid) 02809 { 02810 global $CONFIG, $sit, $dbJournal; 02811 // Journal Types 02812 // 1 = Logon/Logoff 02813 // 2 = Support Incidents 02814 // 3 = -Unused- 02815 // 4 = Sites 02816 // 5 = Contacts 02817 // 6 = Admin 02818 // 7 = User Management 02819 // 8 = Maintenance 02820 // 9 = Products 02821 // 10 = Other 02822 // 11 = Triggers 02823 // 12 = Knowledgebase 02824 02825 // Logging Level 02826 // 0 = No logging 02827 // 1 = Minimal Logging 02828 // 2 = Normal Logging 02829 // 3 = Full Logging 02830 // 4 = Max Debug Logging 02831 02832 $bodytext = mysql_real_escape_string($bodytext); 02833 if ($loglevel <= $CONFIG['journal_loglevel']) 02834 { 02835 $sql = "INSERT INTO `{$dbJournal}` "; 02836 $sql .= "(userid, event, bodytext, journaltype, refid) "; 02837 $sql .= "VALUES ('".$_SESSION['userid']."', '$event', '$bodytext', '$journaltype', '$refid') "; 02838 $result = mysql_query($sql); 02839 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 02840 return TRUE; 02841 } 02842 else 02843 { 02844 // Below minimum log level - do nothing 02845 return FALSE; 02846 } 02847 } 02848 02849 02862 function send_email($to, $from, $subject, $body, $replyto='', $cc='', $bcc='') 02863 { 02864 global $CONFIG, $application_version_string; 02865 02866 $crlf = "\n"; 02867 02868 if (empty($to)) trigger_error('Empty TO address in email', E_USER_WARNING); 02869 02870 $extra_headers = ''; 02871 if (!empty($replyto)) $extra_headers .= "Reply-To: {$replyto}" . $crlf; 02872 if (!empty($email_cc)) 02873 { 02874 $extra_headers .= "CC: {$cc}" . $crlf; 02875 } 02876 if (!empty($email_bcc)) 02877 { 02878 $extra_headers .= "BCC: {$bcc}" . $crlf; 02879 } 02880 if (!empty($CONFIG['support_email'])) 02881 { 02882 $extra_headers .= "Errors-To: {$CONFIG['support_email']}" . $crlf; 02883 } 02884 $extra_headers .= "X-Mailer: {$CONFIG['application_shortname']} {$application_version_string}/PHP " . phpversion() . $crlf; 02885 $extra_headers .= "X-Originating-IP: {$_SERVER['REMOTE_ADDR']}" . $crlf; 02886 // $extra_headers .= "\r\n"; 02887 02888 if ($CONFIG['demo']) 02889 { 02890 $rtnvalue = TRUE; 02891 } 02892 else 02893 { 02894 // $rtnvalue = mail($to, $subject, $body, $extra_headers); 02895 02896 $mime = new MIME_mail($from, $to, html_entity_decode($subject), '', $extra_headers, $mailerror); 02897 $mime -> attach($body, '', "text/plain; charset={$GLOBALS['i18ncharset']}", 'quoted-printable', 'inline'); 02898 02899 // actually send the email 02900 $rtnvalue = $mime -> send_mail(); 02901 if (!empty($mailerror)) debug_log("Outoing email error: {$mailerror}"); 02902 } 02903 02904 return $rtnvalue; 02905 } 02906 02907 02913 function generate_password($length=8) 02914 { 02915 $possible = '0123456789'.'abcdefghijkmnpqrstuvwxyz'.'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.'-'; 02916 // $possible = '23456789'.'abcdefghjkmnpqrstuvwxyz'.'ABCDEFGHJKLMNPQRSTUVWXYZ'.'-'; 02917 // not using 1's 0's etc. to save confusion 02918 // '-=!&'; 02919 $str = ''; 02920 while (strlen($str) < $length) 02921 { 02922 $str .= substr($possible, (rand() % strlen($possible)),1); 02923 } 02924 return $str; 02925 } 02926 02927 02928 if (!function_exists('list_dir')) 02929 { 02930 // returns an array contains all files in a directory and optionally recurses subdirectories 02931 function list_dir($dirname, $recursive = 1) 02932 { 02933 // try to figure out what delimeter is being used (for windows or unix)... 02934 $delim = (strstr($dirname,"/")) ? "/" : "\\"; 02935 02936 if ($dirname[strlen($dirname)-1] != $delim) 02937 $dirname .= $delim; 02938 02939 $handle = opendir($dirname); 02940 if ($handle == FALSE) 02941 { 02942 trigger_error("Error in list_dir() Problem attempting to open directory: {$dirname}",E_USER_WARNING); 02943 } 02944 02945 $result_array = array(); 02946 02947 while ($file = readdir($handle)) 02948 { 02949 if ($file == '.' || $file == '..') 02950 { 02951 continue; 02952 } 02953 02954 if (is_dir($dirname.$file) && $recursive) 02955 { 02956 $x = list_dir($dirname.$file.$delim); 02957 $result_array = array_merge($result_array, $x); 02958 } 02959 else 02960 { 02961 $result_array[] = $dirname.$file; 02962 } 02963 } 02964 closedir($handle); 02965 02966 if (sizeof($result_array)) 02967 { 02968 natsort($result_array); 02969 02970 if ($_SESSION['update_order'] == "desc") 02971 { 02972 $result_array = array_reverse($result_array); 02973 } 02974 } 02975 return $result_array; 02976 } 02977 } 02978 02979 02980 if (!function_exists('is_number')) 02981 { 02982 function is_number($string) 02983 { 02984 $number = TRUE; 02985 for ($i=0; $i < strlen($string); $i++) 02986 { 02987 if (!(ord(substr($string, $i, 1)) <= 57 && ord(substr($string, $i, 1)) >= 48)) 02988 { 02989 $number = FALSE; 02990 } 02991 } 02992 return $number; 02993 } 02994 } 02995 02996 02997 // recursive copy from one directory to another 02998 function rec_copy ($from_path, $to_path) 02999 { 03000 if ($from_path == '') trigger_error('Cannot move file', 'from_path not set', E_USER_WARNING); 03001 if ($to_path == '') trigger_error('Cannot move file', 'to_path not set', E_USER_WARNING); 03002 03003 $mk = mkdir($to_path, 0700); 03004 if (!$mk) trigger_error('Failed creating directory: {$to_path}',E_USER_WARNING); 03005 $this_path = getcwd(); 03006 if (is_dir($from_path)) 03007 { 03008 chdir($from_path); 03009 $handle = opendir('.'); 03010 while (($file = readdir($handle)) !== false) 03011 { 03012 if (($file != ".") && ($file != "..")) 03013 { 03014 if (is_dir($file)) 03015 { 03016 rec_copy ($from_path.$file."/", 03017 $to_path.$file."/"); 03018 chdir($from_path); 03019 } 03020 03021 if (is_file($file)) 03022 { 03023 if (!(substr(rtrim($file),strlen(rtrim($file))-8,4) == 'mail' 03024 || substr(rtrim($file),strlen(rtrim($file))-10,5) == 'part1' 03025 || substr(rtrim($file),strlen(rtrim($file))-8,4) == '.vcf')) 03026 { 03027 copy($from_path.$file, $to_path.$file); 03028 } 03029 } 03030 } 03031 } 03032 closedir($handle); 03033 } 03034 } 03035 03036 03040 function getattachmenticon($filename) 03041 { 03042 global $CONFIG, $iconset; 03043 // Maybe sometime make this use mime typesad of file extensions 03044 $ext = strtolower(substr($filename, (strlen($filename)-3) , 3)); 03045 $imageurl = "{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/unknown.png"; 03046 03047 $type_image = "{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/file_image.png"; 03048 03049 $filetype[]="gif"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03050 $filetype[]="jpg"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03051 $filetype[]="bmp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03052 $filetype[]="png"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03053 $filetype[]="pcx"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03054 $filetype[]="xls"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/spreadsheet.png"; 03055 $filetype[]="csv"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/spreadsheet.png"; 03056 $filetype[]="zip"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tgz.png"; 03057 $filetype[]="arj"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/zip.png"; 03058 $filetype[]="rar"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/rar.png"; 03059 $filetype[]="cab"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tgz.png"; 03060 $filetype[]="lzh"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tgz.png"; 03061 $filetype[]="txt"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/txt.png"; 03062 $filetype[]="f90"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_f.png"; 03063 $filetype[]="f77"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_f.png"; 03064 $filetype[]="inf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source.png"; 03065 $filetype[]="ins"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source.png"; 03066 $filetype[]="adm"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source.png"; 03067 $filetype[]="f95"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_f.png"; 03068 $filetype[]="cpp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_cpp.png"; 03069 $filetype[]="for"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_f.png"; 03070 $filetype[]=".pl"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_pl.png"; 03071 $filetype[]=".py"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source_py.png"; 03072 $filetype[]="rtm"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/misc_doc.png"; 03073 $filetype[]="doc"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/wordprocessing.png"; 03074 $filetype[]="rtf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/wordprocessing.png"; 03075 $filetype[]="wri"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/wordprocessing.png"; 03076 $filetype[]="wri"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/wordprocessing.png"; 03077 $filetype[]="pdf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/pdf.png"; 03078 $filetype[]="htm"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/html.png"; 03079 $filetype[]="tml"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/html.png"; 03080 $filetype[]="wav"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/sound.png"; 03081 $filetype[]="mp3"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/sound.png"; 03082 $filetype[]="voc"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/sound.png"; 03083 $filetype[]="exe"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03084 $filetype[]="com"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03085 $filetype[]="nlm"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03086 $filetype[]="evt"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/log.png"; 03087 $filetype[]="log"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/log.png"; 03088 $filetype[]="386"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03089 $filetype[]="dll"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03090 $filetype[]="asc"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/txt.png"; 03091 $filetype[]="asp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/html.png"; 03092 $filetype[]="avi"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/video.png"; 03093 $filetype[]="bkf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tar.png"; 03094 $filetype[]="chm"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/man.png"; 03095 $filetype[]="hlp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/man.png"; 03096 $filetype[]="dif"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/txt.png"; 03097 $filetype[]="hta"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/html.png"; 03098 $filetype[]="reg"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/resource.png"; 03099 $filetype[]="dmp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/core.png"; 03100 $filetype[]="ini"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source.png"; 03101 $filetype[]="jpe"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03102 $filetype[]="mht"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/html.png"; 03103 $filetype[]="msi"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03104 $filetype[]="aot"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03105 $filetype[]="pgp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03106 $filetype[]="dbg"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03107 $filetype[]="axt"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/source.png"; // zen text 03108 $filetype[]="rdp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03109 $filetype[]="sig"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/document.png"; 03110 $filetype[]="tif"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/image.png"; 03111 $filetype[]="ttf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/font_ttf.png"; 03112 $filetype[]="for"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/font_bitmap.png"; 03113 $filetype[]="vbs"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/shellscript.png"; 03114 $filetype[]="vbe"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/shellscript.png"; 03115 $filetype[]="bat"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/shellscript.png"; 03116 $filetype[]="wsf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/shellscript.png"; 03117 $filetype[]="cmd"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/shellscript.png"; 03118 $filetype[]="scr"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03119 $filetype[]="xml"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/xml.png"; 03120 $filetype[]="zap"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03121 $filetype[]=".ps"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/postscript.png"; 03122 $filetype[]=".rm"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/real_doc.png"; 03123 $filetype[]="ram"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/real_doc.png"; 03124 $filetype[]="vcf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/vcard.png"; 03125 $filetype[]="wmf"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/vectorgfx.png"; 03126 $filetype[]="cer"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/document.png"; 03127 $filetype[]="tmp"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/unknown.png"; 03128 $filetype[]="cap"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03129 $filetype[]="tr1"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/binary.png"; 03130 $filetype[]=".gz"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tgz.png"; 03131 $filetype[]="tar"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tar.png"; 03132 $filetype[]="nfo"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/info.png"; 03133 $filetype[]="pal"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/colorscm.png"; 03134 $filetype[]="iso"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/cdimage.png"; 03135 $filetype[]="jar"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/java_src.png"; 03136 $filetype[]="eml"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/message.png"; 03137 $filetype[]=".sh"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/shellscript.png"; 03138 $filetype[]="bz2"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/tgz.png"; 03139 $filetype[]="out"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/log.png"; 03140 $filetype[]="cfg"; $imgurl[]="{$CONFIG['application_webpath']}images/icons/{$iconset}/32x32/mimetypes/log.png"; 03141 03142 $cnt = count($filetype); 03143 if ( $cnt > 0 ) 03144 { 03145 $a = 0; 03146 $stop = FALSE; 03147 while ($a < $cnt && $stop == FALSE) 03148 { 03149 if ($ext == $filetype[$a]) 03150 { 03151 $imageurl = $imgurl[$a]; 03152 $stop = TRUE; 03153 } 03154 $a++; 03155 } 03156 } 03157 unset ($filetype); 03158 unset ($imgurl); 03159 return $imageurl; 03160 } 03161 03162 03163 function count_incoming_updates() 03164 { 03165 $sql = "SELECT id FROM `{$GLOBALS['dbUpdates']}` WHERE incidentid=0"; 03166 $result = mysql_query($sql); 03167 $count = mysql_num_rows($result); 03168 mysql_free_result($result); 03169 return $count; 03170 } 03171 03172 03173 function global_signature() 03174 { 03175 $sql = "SELECT signature FROM `{$GLOBALS['dbEmailSig']}` ORDER BY RAND() LIMIT 1"; 03176 $result = mysql_query($sql); 03177 list($signature) = mysql_fetch_row($result); 03178 mysql_free_result($result); 03179 return $signature; 03180 } 03181 03182 03183 function holiday_type ($id) 03184 { 03185 switch ($id) 03186 { 03187 case HOL_HOLIDAY: 03188 $holidaytype = $GLOBALS['strHoliday']; 03189 break; 03190 case HOL_SICKNESS: 03191 $holidaytype = $GLOBALS['strAbsentSick']; 03192 break; 03193 case HOL_WORKING_AWAY: 03194 $holidaytype = $GLOBALS['strWorkingAway']; 03195 break; 03196 case HOL_TRAINING: 03197 $holidaytype = $GLOBALS['strTraining']; 03198 break; 03199 case HOL_FREE: 03200 $holidaytype = $GLOBALS['strCompassionateLeave']; 03201 break; 03202 case HOL_PUBLIC: 03203 $holidaytype = $GLOBALS['strPublicHoliday']; 03204 break; 03205 default: 03206 $holidaytype = $GLOBALS['strUnknown']; 03207 break; 03208 } 03209 return ($holidaytype); 03210 } 03211 03212 03213 function holiday_approval_status($approvedid, $approvedby=-1) 03214 { 03215 global $strApproved, $strApprovedFree, $strRequested, $strNotRequested, $strDenied; 03216 global $strArchivedDenied, $strArchivedNotRequested, $strArchivedRequested; 03217 global $strArchivedApproved, $strArchivedApprovedFree, $strApprovalStatusUnknown; 03218 03219 // We add 10 to normal status when we archive holiday 03220 switch ($approvedid) 03221 { 03222 case -2: 03223 $status = $strNotRequested; 03224 break; 03225 case -1: 03226 $status = $strDenied; 03227 break; 03228 case 0: 03229 if ($approvedby == 0) 03230 { 03231 $status = $strNotRequested; 03232 } 03233 else 03234 { 03235 $status = $strRequested; 03236 } 03237 break; 03238 case 1: 03239 $status = $strApproved; 03240 break; 03241 case 2: 03242 $status = $strApprovedFree; 03243 break; 03244 case 8: 03245 $status = $strArchivedNotRequested; 03246 break; 03247 case 9: 03248 $status = $strArchivedDenied; 03249 break; 03250 case 10: 03251 $status = $strArchivedRequested; 03252 break; 03253 case 11: 03254 $status = $strArchivedApproved; 03255 break; 03256 case 12: 03257 $status = $strArchivedApprovedFree; 03258 break; 03259 default: 03260 $status = $strApprovalStatusUnknown; 03261 break; 03262 } 03263 return $status; 03264 } 03265 03266 03267 function holidaytype_drop_down($name, $id) 03268 { 03269 $holidaytype[HOL_HOLIDAY] = $GLOBALS['strHoliday']; 03270 $holidaytype[HOL_SICKNESS] = $GLOBALS['strAbsentSick']; 03271 $holidaytype[HOL_WORKING_AWAY] = $GLOBALS['strWorkingAway']; 03272 $holidaytype[HOL_TRAINING] = $GLOBALS['strTraining']; 03273 $holidaytype[HOL_FREE] = $GLOBALS['strCompassionateLeave']; 03274 03275 $html = "<select name='$name'>"; 03276 if ($id == 0) 03277 { 03278 $html .= "<option selected value='0'></option>\n"; 03279 } 03280 03281 foreach ($holidaytype AS $htypeid => $htype) 03282 { 03283 $html .= "<option"; 03284 if ($htypeid == $id) 03285 { 03286 $html .= " selected='selected'"; 03287 } 03288 $html .= " value='{$htypeid}'>{$htype}</option>\n"; 03289 } 03290 $html .= "</select>\n"; 03291 return $html; 03292 } 03293 03294 03303 function check_group_holiday($userid, $date, $length='day') 03304 { 03305 global $dbUsers, $dbHolidays; 03306 03307 $namelist = ''; 03308 $groupid = user_group_id($userid); 03309 if (!empty($groupid)) 03310 { 03311 // list group members 03312 $msql = "SELECT id AS userid FROM `{$dbUsers}` "; 03313 $msql .= "WHERE groupid='{$groupid}' AND id != '$userid' "; 03314 $mresult = mysql_query($msql); 03315 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 03316 while ($member = mysql_fetch_object($mresult)) 03317 { 03318 // check to see if this group member has holiday 03319 $hsql = "SELECT id FROM `{$dbHolidays}` WHERE userid='{$member->userid}' AND date = FROM_UNIXTIME({$date}) "; 03320 if ($length == 'am' OR $length == 'pm') 03321 { 03322 $hsql .= "AND (length = '{$length}' OR length = 'day') "; 03323 } 03324 03325 $hresult = mysql_query($hsql); 03326 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 03327 if (mysql_num_rows($hresult) >= 1) 03328 { 03329 $namelist .= user_realname($member->userid)." ($length)"; 03330 $namelist .= " "; 03331 } 03332 } 03333 } 03334 return $namelist; 03335 } 03336 03337 03348 function country_drop_down($name, $country, $extraattributes='') 03349 { 03350 global $CONFIG; 03351 if ($country == '') $country = $CONFIG['home_country']; 03352 03353 if ($country == 'UK') $country = 'UNITED KINGDOM'; 03354 $countrylist[] = 'ALBANIA'; 03355 $countrylist[] = 'ALGERIA'; 03356 $countrylist[] = 'AMERICAN SAMOA'; 03357 $countrylist[] = 'ANDORRA'; 03358 $countrylist[] = 'ANGOLA'; 03359 $countrylist[] = 'ANGUILLA'; 03360 $countrylist[] = 'ANTIGUA'; 03361 $countrylist[] = 'ARGENTINA'; 03362 $countrylist[] = 'ARMENIA'; 03363 $countrylist[] = 'ARUBA'; 03364 $countrylist[] = 'AUSTRALIA'; 03365 $countrylist[] = 'AUSTRIA'; 03366 $countrylist[] = 'AZERBAIJAN'; 03367 $countrylist[] = 'BAHAMAS'; 03368 $countrylist[] = 'BAHRAIN'; 03369 $countrylist[] = 'BANGLADESH'; 03370 $countrylist[] = 'BARBADOS'; 03371 $countrylist[] = 'BELARUS'; 03372 $countrylist[] = 'BELGIUM'; 03373 $countrylist[] = 'BELIZE'; 03374 $countrylist[] = 'BENIN'; 03375 $countrylist[] = 'BERMUDA'; 03376 $countrylist[] = 'BHUTAN'; 03377 $countrylist[] = 'BOLIVIA'; 03378 $countrylist[] = 'BONAIRE'; 03379 $countrylist[] = 'BOSNIA HERZEGOVINA'; 03380 $countrylist[] = 'BOTSWANA'; 03381 $countrylist[] = 'BRAZIL'; 03382 $countrylist[] = 'BRUNEI'; 03383 $countrylist[] = 'BULGARIA'; 03384 $countrylist[] = 'BURKINA FASO'; 03385 $countrylist[] = 'BURUNDI'; 03386 $countrylist[] = 'CAMBODIA'; 03387 $countrylist[] = 'CAMEROON'; 03388 $countrylist[] = 'CANADA'; 03389 $countrylist[] = 'CANARY ISLANDS'; 03390 $countrylist[] = 'CAPE VERDE ISLANDS'; 03391 $countrylist[] = 'CAYMAN ISLANDS'; 03392 $countrylist[] = 'CENTRAL AFRICAN REPUBLIC'; 03393 $countrylist[] = 'CHAD'; 03394 $countrylist[] = 'CHANNEL ISLANDS'; 03395 $countrylist[] = 'CHILE'; 03396 $countrylist[] = 'CHINA'; 03397 $countrylist[] = 'COLOMBIA'; 03398 $countrylist[] = 'COMOROS ISLANDS'; 03399 $countrylist[] = 'CONGO'; 03400 $countrylist[] = 'COOK ISLANDS'; 03401 $countrylist[] = 'COSTA RICA'; 03402 $countrylist[] = 'CROATIA'; 03403 $countrylist[] = 'CUBA'; 03404 $countrylist[] = 'CURACAO'; 03405 $countrylist[] = 'CYPRUS'; 03406 $countrylist[] = 'CZECH REPUBLIC'; 03407 $countrylist[] = 'DENMARK'; 03408 $countrylist[] = 'DJIBOUTI'; 03409 $countrylist[] = 'DOMINICA'; 03410 $countrylist[] = 'DOMINICAN REPUBLIC'; 03411 $countrylist[] = 'ECUADOR'; 03412 $countrylist[] = 'EGYPT'; 03413 $countrylist[] = 'EL SALVADOR'; 03414 $countrylist[] = 'EQUATORIAL GUINEA'; 03415 $countrylist[] = 'ERITREA'; 03416 $countrylist[] = 'ESTONIA'; 03417 $countrylist[] = 'ETHIOPIA'; 03418 $countrylist[] = 'FAROE ISLANDS'; 03419 $countrylist[] = 'FIJI ISLANDS'; 03420 $countrylist[] = 'FINLAND'; 03421 $countrylist[] = 'FRANCE'; 03422 $countrylist[] = 'FRENCH GUINEA'; 03423 $countrylist[] = 'GABON'; 03424 $countrylist[] = 'GAMBIA'; 03425 $countrylist[] = 'GEORGIA'; 03426 $countrylist[] = 'GERMANY'; 03427 $countrylist[] = 'GHANA'; 03428 $countrylist[] = 'GIBRALTAR'; 03429 $countrylist[] = 'GREECE'; 03430 $countrylist[] = 'GREENLAND'; 03431 $countrylist[] = 'GRENADA'; 03432 $countrylist[] = 'GUADELOUPE'; 03433 $countrylist[] = 'GUAM'; 03434 $countrylist[] = 'GUATEMALA'; 03435 $countrylist[] = 'GUINEA REPUBLIC'; 03436 $countrylist[] = 'GUINEA-BISSAU'; 03437 $countrylist[] = 'GUYANA'; 03438 $countrylist[] = 'HAITI'; 03439 $countrylist[] = 'HONDURAS REPUBLIC'; 03440 $countrylist[] = 'HONG KONG'; 03441 $countrylist[] = 'HUNGARY'; 03442 $countrylist[] = 'ICELAND'; 03443 $countrylist[] = 'INDIA'; 03444 $countrylist[] = 'INDONESIA'; 03445 $countrylist[] = 'IRAN'; 03446 $countrylist[] = 'IRELAND, REPUBLIC'; 03447 $countrylist[] = 'ISRAEL'; 03448 $countrylist[] = 'ITALY'; 03449 $countrylist[] = 'IVORY COAST'; 03450 $countrylist[] = 'JAMAICA'; 03451 $countrylist[] = 'JAPAN'; 03452 $countrylist[] = 'JORDAN'; 03453 $countrylist[] = 'KAZAKHSTAN'; 03454 $countrylist[] = 'KENYA'; 03455 $countrylist[] = 'KIRIBATI, REP OF'; 03456 $countrylist[] = 'KOREA, SOUTH'; 03457 $countrylist[] = 'KUWAIT'; 03458 $countrylist[] = 'KYRGYZSTAN'; 03459 $countrylist[] = 'LAOS'; 03460 $countrylist[] = 'LATVIA'; 03461 $countrylist[] = 'LEBANON'; 03462 $countrylist[] = 'LESOTHO'; 03463 $countrylist[] = 'LIBERIA'; 03464 $countrylist[] = 'LIBYA'; 03465 $countrylist[] = 'LIECHTENSTEIN'; 03466 $countrylist[] = 'LITHUANIA'; 03467 $countrylist[] = 'LUXEMBOURG'; 03468 $countrylist[] = 'MACAU'; 03469 $countrylist[] = 'MACEDONIA'; 03470 $countrylist[] = 'MADAGASCAR'; 03471 $countrylist[] = 'MALAWI'; 03472 $countrylist[] = 'MALAYSIA'; 03473 $countrylist[] = 'MALDIVES'; 03474 $countrylist[] = 'MALI'; 03475 $countrylist[] = 'MALTA'; 03476 $countrylist[] = 'MARSHALL ISLANDS'; 03477 $countrylist[] = 'MARTINIQUE'; 03478 $countrylist[] = 'MAURITANIA'; 03479 $countrylist[] = 'MAURITIUS'; 03480 $countrylist[] = 'MEXICO'; 03481 $countrylist[] = 'MOLDOVA, REP OF'; 03482 $countrylist[] = 'MONACO'; 03483 $countrylist[] = 'MONGOLIA'; 03484 $countrylist[] = 'MONTSERRAT'; 03485 $countrylist[] = 'MOROCCO'; 03486 $countrylist[] = 'MOZAMBIQUE'; 03487 $countrylist[] = 'MYANMAR'; 03488 $countrylist[] = 'NAMIBIA'; 03489 $countrylist[] = 'NAURU, REP OF'; 03490 $countrylist[] = 'NEPAL'; 03491 $countrylist[] = 'NETHERLANDS'; 03492 $countrylist[] = 'NEVIS'; 03493 $countrylist[] = 'NEW CALEDONIA'; 03494 $countrylist[] = 'NEW ZEALAND'; 03495 $countrylist[] = 'NICARAGUA'; 03496 $countrylist[] = 'NIGER'; 03497 $countrylist[] = 'NIGERIA'; 03498 $countrylist[] = 'NIUE'; 03499 $countrylist[] = 'NORWAY'; 03500 $countrylist[] = 'OMAN'; 03501 $countrylist[] = 'PAKISTAN'; 03502 $countrylist[] = 'PANAMA'; 03503 $countrylist[] = 'PAPUA NEW GUINEA'; 03504 $countrylist[] = 'PARAGUAY'; 03505 $countrylist[] = 'PERU'; 03506 $countrylist[] = 'PHILLIPINES'; 03507 $countrylist[] = 'POLAND'; 03508 $countrylist[] = 'PORTUGAL'; 03509 $countrylist[] = 'PUERTO RICO'; 03510 $countrylist[] = 'QATAR'; 03511 $countrylist[] = 'REUNION ISLAND'; 03512 $countrylist[] = 'ROMANIA'; 03513 $countrylist[] = 'RUSSIAN FEDERATION'; 03514 $countrylist[] = 'RWANDA'; 03515 $countrylist[] = 'SAIPAN'; 03516 $countrylist[] = 'SAO TOME & PRINCIPE'; 03517 $countrylist[] = 'SAUDI ARABIA'; 03518 $countrylist[] = 'SENEGAL'; 03519 $countrylist[] = 'SEYCHELLES'; 03520 $countrylist[] = 'SIERRA LEONE'; 03521 $countrylist[] = 'SINGAPORE'; 03522 $countrylist[] = 'SLOVAKIA'; 03523 $countrylist[] = 'SLOVENIA'; 03524 $countrylist[] = 'SOLOMON ISLANDS'; 03525 $countrylist[] = 'SOUTH AFRICA'; 03526 $countrylist[] = 'SPAIN'; 03527 $countrylist[] = 'SRI LANKA'; 03528 $countrylist[] = 'ST BARTHELEMY'; 03529 $countrylist[] = 'ST EUSTATIUS'; 03530 $countrylist[] = 'ST KITTS'; 03531 $countrylist[] = 'ST LUCIA'; 03532 $countrylist[] = 'ST MAARTEN'; 03533 $countrylist[] = 'ST VINCENT'; 03534 $countrylist[] = 'SUDAN'; 03535 $countrylist[] = 'SURINAME'; 03536 $countrylist[] = 'SWAZILAND'; 03537 $countrylist[] = 'SWEDEN'; 03538 $countrylist[] = 'SWITZERLAND'; 03539 $countrylist[] = 'SYRIA'; 03540 $countrylist[] = 'TAHITI'; 03541 $countrylist[] = 'TAIWAN'; 03542 $countrylist[] = 'TAJIKISTAN'; 03543 $countrylist[] = 'TANZANIA'; 03544 $countrylist[] = 'THAILAND'; 03545 $countrylist[] = 'TOGO'; 03546 $countrylist[] = 'TONGA'; 03547 $countrylist[] = 'TRINIDAD & TOBAGO'; 03548 $countrylist[] = 'TURKEY'; 03549 $countrylist[] = 'TURKMENISTAN'; 03550 $countrylist[] = 'TURKS & CAICOS ISLANDS'; 03551 $countrylist[] = 'TUVALU'; 03552 $countrylist[] = 'UGANDA'; 03553 // $countrylist[] = 'UK'; 03554 $countrylist[] = 'UKRAINE'; 03555 $countrylist[] = 'UNITED KINGDOM'; 03556 $countrylist[] = 'UNITED STATES'; 03557 $countrylist[] = 'URUGUAY'; 03558 $countrylist[] = 'UTD ARAB EMIRATES'; 03559 $countrylist[] = 'UZBEKISTAN'; 03560 $countrylist[] = 'VANUATU'; 03561 $countrylist[] = 'VENEZUELA'; 03562 $countrylist[] = 'VIETNAM'; 03563 $countrylist[] = 'VIRGIN ISLANDS'; 03564 $countrylist[] = 'VIRGIN ISLANDS (UK)'; 03565 $countrylist[] = 'WESTERN SAMOA'; 03566 $countrylist[] = 'YEMAN, REP OF'; 03567 $countrylist[] = 'YUGOSLAVIA'; 03568 $countrylist[] = 'ZAIRE'; 03569 $countrylist[] = 'ZAMBIA'; 03570 $countrylist[] = 'ZIMBABWE'; 03571 03572 if (in_array(strtoupper($country), $countrylist)) 03573 { 03574 // make drop down 03575 $html = "<select id=\"{$name}\" name=\"{$name}\" {$extraattributes}>"; 03576 foreach ($countrylist as $key => $value) 03577 { 03578 $value = htmlspecialchars($value); 03579 $html .= "<option value='$value'"; 03580 if ($value == strtoupper($country)) 03581 { 03582 $html .= " selected='selected'"; 03583 } 03584 $html .= ">$value</option>\n"; 03585 } 03586 $html .= "</select>"; 03587 } 03588 else 03589 { 03590 // make editable input box 03591 $html = "<input maxlength='100' name='{$name}' size='40' value='{$country}' {$extraattributes} />"; 03592 } 03593 return $html; 03594 } 03595 03596 03597 function check_email($email, $check_dns = FALSE) 03598 { 03599 if ((preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) || 03600 (preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email))) 03601 { 03602 if ($check_dns) 03603 { 03604 $host = explode('@', $email); 03605 // Check for MX record 03606 if ( checkdnsrr($host[1], 'MX') ) return TRUE; 03607 // Check for A record 03608 if ( checkdnsrr($host[1], 'A') ) return TRUE; 03609 // Check for CNAME record 03610 if ( checkdnsrr($host[1], 'CNAME') ) return TRUE; 03611 } 03612 else 03613 { 03614 return TRUE; 03615 } 03616 } 03617 return FALSE; 03618 } 03619 03620 03621 function incident_get_next_target($incidentid) 03622 { 03623 global $now; 03624 // Find the most recent SLA target that was met 03625 $sql = "SELECT sla,timestamp FROM `{$GLOBALS['dbUpdates']}` WHERE incidentid='{$incidentid}' AND type='slamet' ORDER BY id DESC LIMIT 1"; 03626 $result = mysql_query($sql); 03627 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 03628 03629 $target = ''; 03630 if (mysql_num_rows($result) > 0) 03631 { 03632 $upd = mysql_fetch_object($result); 03633 switch ($upd->sla) 03634 { 03635 case 'opened': 03636 $target->type = 'initialresponse'; 03637 break; 03638 case 'initialresponse': 03639 $target->type = 'probdef'; 03640 break; 03641 case 'probdef': 03642 $target->type = 'actionplan'; 03643 break; 03644 case 'actionplan': 03645 $target->type = 'solution'; 03646 break; 03647 case 'solution': 03648 $target->type = ''; 03649 break; 03650 case 'closed': 03651 $target->type = 'opened'; 03652 break; 03653 } 03654 03655 $target->since = calculate_incident_working_time($incidentid, $upd->timestamp, $now); 03656 } 03657 else 03658 { 03659 $target->type = 'regularcontact'; 03660 $target->since = 0; 03661 } 03662 return $target; 03663 } 03664 03665 03666 function target_type_name($targettype) 03667 { 03668 switch ($targettype) 03669 { 03670 case 'opened': 03671 $name = $GLOBALS['strOpened']; 03672 break; 03673 case 'initialresponse': 03674 $name = $GLOBALS['strInitialResponse']; 03675 break; 03676 case 'probdef': 03677 $name = $GLOBALS['strProblemDefinition']; 03678 break; 03679 case 'actionplan': 03680 $name = $GLOBALS['strActionPlan']; 03681 break; 03682 case 'solution': 03683 $name = $GLOBALS['strResolutionReprioritisation']; 03684 break; 03685 case 'closed': 03686 $name = ''; 03687 break; 03688 case 'regularcontact': 03689 $name = ''; 03690 break; // Contact Customer 03691 default: 03692 $name = ''; 03693 break; 03694 } 03695 return $name; 03696 } 03697 03698 03707 function incident_time_since_review($incidentid) 03708 { 03709 global $now; 03710 $sql = "SELECT timestamp FROM `{$GLOBALS['dbUpdates']}` "; 03711 $sql .= "WHERE incidentid='{$incidentid}' AND type='reviewmet' "; 03712 $sql .= "ORDER BY id DESC LIMIT 1"; 03713 $result = mysql_query($sql); 03714 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 03715 03716 if (mysql_num_rows($result) > 0) 03717 { 03718 $upd = mysql_fetch_object($result); 03719 $timesincereview = floor(($now - $upd->timestamp) / 60); 03720 } 03721 return $timesincereview; 03722 } 03723 03724 03733 function mysql2date($mysqldate, $utc = FALSE) 03734 { 03735 // for the zero/blank case, return 0 03736 if (empty($mysqldate)) 03737 { 03738 return 0; 03739 } 03740 03741 if ($mysqldate == '0000-00-00 00:00:00' OR $mysqldate == '0000-00-00') 03742 { 03743 return 0; 03744 } 03745 03746 // Takes a MYSQL date and converts it to a proper PHP date 03747 $day = substr($mysqldate, 8, 2); 03748 $month = substr($mysqldate, 5, 2); 03749 $year = substr($mysqldate, 0, 4); 03750 03751 if (strlen($mysqldate) > 10) 03752 { 03753 $hour = substr($mysqldate, 11, 2); 03754 $minute = substr($mysqldate, 14, 2); 03755 $second = substr($mysqldate, 17, 2); 03756 if ($utc) $phpdate = gmmktime($hour, $minute, $second, $month, $day, $year); 03757 else $phpdate = mktime($hour, $minute, $second, $month, $day, $year); 03758 } 03759 else 03760 { 03761 if ($utc) $phpdate = gmmktime(0, 0, 0, $month, $day, $year); 03762 else $phpdate = mktime(0, 0, 0, $month, $day, $year); 03763 } 03764 03765 return $phpdate; 03766 } 03767 03768 03775 function mysqlts2date($mysqldate) 03776 { 03777 // for the zero/blank case, return 0 03778 if (empty($mysqldate)) return 0; 03779 03780 // Takes a MYSQL date and converts it to a proper PHP date 03781 if (strlen($mysqldate) == 14) 03782 { 03783 $day = substr($mysqldate, 6, 2); 03784 $month = substr($mysqldate, 4, 2); 03785 $year = substr($mysqldate, 0, 4); 03786 $hour = substr($mysqldate, 8, 2); 03787 $minute = substr($mysqldate, 10, 2); 03788 $second = substr($mysqldate, 12, 2); 03789 } 03790 elseif (strlen($mysqldate) > 14) 03791 { 03792 $day = substr($mysqldate, 8, 2); 03793 $month = substr($mysqldate, 5, 2); 03794 $year = substr($mysqldate, 0, 4); 03795 $hour = substr($mysqldate, 11, 2); 03796 $minute = substr($mysqldate, 14, 2); 03797 $second = substr($mysqldate, 17, 2); 03798 } 03799 $phpdate = mktime($hour, $minute, $second, $month, $day, $year); 03800 return $phpdate; 03801 } 03802 03803 03804 function iso_8601_date($timestamp) 03805 { 03806 $date_mod = date('Y-m-d\TH:i:s', $timestamp); 03807 $pre_timezone = date('O', $timestamp); 03808 $time_zone = substr($pre_timezone, 0, 3).":".substr($pre_timezone, 3, 2); 03809 $date_mod .= $time_zone; 03810 return $date_mod; 03811 } 03812 03820 function is_public_holiday($time, $publicholidays) 03821 { 03822 if (!empty($publicholidays)) 03823 { 03824 foreach ($publicholidays AS $holiday) 03825 { 03826 if ($time >= $holiday->starttime AND $time <= $holiday->endtime) 03827 { 03828 return $holiday->endtime-$time; 03829 } 03830 } 03831 } 03832 03833 return 0; 03834 } 03835 03843 function calculate_working_time($t1, $t2, $publicholidays) 03844 { 03845 // PH 16/12/07 Old function commented out, rewritten to support public holidays. Old code to be removed once we're happy this is stable 03846 // KH 13/07/08 Use old function again for 3.35 beta 03847 // Note that this won't work if we have something 03848 // more complicated than a weekend 03849 03850 global $CONFIG; 03851 $swd = $CONFIG['start_working_day'] / 3600; 03852 $ewd = $CONFIG['end_working_day'] / 3600; 03853 03854 // Just in case the time params are the wrong way around ... 03855 if ( $t1 > $t2 ) 03856 { 03857 $t3 = $t2; 03858 $t2 = $t1; 03859 $t1 = $t3; 03860 } 03861 03862 // We don't need all the elements here. hours, days and year are used 03863 // later on to calculate the difference. wday is just used in this 03864 // section 03865 $at1 = getdate($t1); 03866 $at2 = getdate($t2); 03867 03868 // Make sure that the start time is on a valid day and within normal hours 03869 // if it isn't then move it forward to the next work minute 03870 if ($at1['hours'] > $ewd) 03871 { 03872 do 03873 { 03874 $at1['yday'] ++; 03875 $at1['wday'] ++; 03876 $at1['wday'] %= 7; 03877 if ($at1['yday'] > 365) 03878 { 03879 $at1['year'] ++; 03880 $at1['yday'] = 0; 03881 } 03882 } while (!in_array($at1['wday'], $CONFIG['working_days'])); 03883 03884 $at1['hours'] = $swd; 03885 $at1['minutes'] = 0; 03886 } 03887 else 03888 { 03889 if (($at1['hours'] < $swd) || (!in_array($at1['wday'], $CONFIG['working_days']))) 03890 { 03891 while (!in_array($at1['wday'], $CONFIG['working_days'])) 03892 { 03893 $at1['yday'] ++; 03894 $at1['wday'] ++; 03895 $at1['wday'] %= 7; 03896 if ($at1['days']>365) 03897 { 03898 $at1['year'] ++; 03899 $at1['yday'] = 0; 03900 } 03901 } 03902 $at1['hours'] = $swd; 03903 $at1['minutes'] = 0; 03904 } 03905 } 03906 03907 // Same again but for the end time 03908 // if it isn't then move it backward to the previous work minute 03909 if ( $at2['hours'] < $swd) 03910 { 03911 do 03912 { 03913 $at2['yday'] --; 03914 $at2['wday'] --; 03915 if ($at2['wday'] < 0) $at2['wday'] = 6; 03916 if ($at2['yday'] < 0) 03917 { 03918 $at2['yday'] = 365; 03919 $at2['year'] --; 03920 } 03921 } while (!in_array($at2['wday'], $CONFIG['working_days'])); 03922 03923 $at2['hours'] = $ewd; 03924 $at2['minutes'] = 0; 03925 } 03926 else 03927 { 03928 if (($at2['hours'] > $ewd) || (!in_array($at2['wday'], $CONFIG['working_days']))) 03929 { 03930 while (!in_array($at2['wday'],$CONFIG['working_days'])) 03931 { 03932 $at2['yday'] --; 03933 $at2['wday'] --; 03934 if ($at2['wday'] < 0) $at2['wday'] = 6; 03935 if ($at2['yday'] < 0) 03936 { 03937 $at2['yday'] = 365; 03938 $at2['year'] --; 03939 } 03940 } 03941 $at2['hours'] = $ewd; 03942 $at2['minutes'] = 0; 03943 } 03944 } 03945 03946 $t1 = mktime($at1['hours'], $at1['minutes'], 0, 1, $at1['yday'] + 1, $at1['year']); 03947 $t2 = mktime($at2['hours'], $at2['minutes'], 0, 1, $at2['yday'] + 1, $at2['year']); 03948 03949 // This catches a special case where both times are outside working days/hours 03950 // and have been adjusted (above), this will mean that t2 is before t1 now 03951 // and we can treat this as 0 minutes, which means the target was met outside 03952 // the expected time, so we record 0 working minutes. 03953 if ($t1 > $t2) return 0; 03954 03955 $weeks = floor(($t2 - $t1) / (60 * 60 * 24 * 7)); 03956 $t1 += $weeks * 60 * 60 * 24 * 7; 03957 03958 while ( date('z', $t2) != date('z', $t1) ) 03959 { 03960 if (in_array(date('w', $t1), $CONFIG['working_days'])) $days++; 03961 $t1 += (60 * 60 * 24); 03962 } 03963 03964 // this could be negative and that's not ok 03965 $coefficient = 1; 03966 if ($t2 < $t1) 03967 { 03968 $t3 = $t2; 03969 $t2 = $t1; 03970 $t1 = $t3; 03971 $coefficient =- 1; 03972 } 03973 03974 $min = floor( ($t2 - $t1) / 60 ) * $coefficient; 03975 03976 $minutes = $min + ($weeks * count($CONFIG['working_days']) + $days ) * ($ewd - $swd) * 60; 03977 03978 return $minutes; 03979 03980 //new version below 03981 /* 03982 global $CONFIG; 03983 $swd = $CONFIG['start_working_day']/3600; 03984 $ewd = $CONFIG['end_working_day']/3600; 03985 03986 // Just in case they are the wrong way around ... 03987 03988 if ( $t1 > $t2 ) 03989 { 03990 $t3 = $t2; 03991 $t2 = $t1; 03992 $t1 = $t3; 03993 } 03994 03995 $currenttime = $t1; 03996 03997 $timeworked = 0; 03998 03999 $t2date = getdate($t2); 04000 04001 $midnight = 1440; // 24 * 60 minutes 04002 04003 while ($currenttime < $t2) // was <= 04004 { 04005 $time = getdate($currenttime); 04006 04007 $ph = 0; 04008 04009 if (in_array($time['wday'], $CONFIG['working_days']) AND $time['hours'] >= $swd 04010 AND $time['hours'] <= $ewd AND (($ph = is_public_holiday($currenttime, $publicholidays)) == 0)) 04011 { 04012 if ($t2date['yday'] == $time['yday'] AND $t2date['year'] == $time['year']) 04013 { 04014 // if end same day as time 04015 $c = $t2 - $currenttime; 04016 $timeworked += $c/60; 04017 $currenttime += $c; 04018 } 04019 else 04020 { 04021 // End on a different day 04022 $secondsintoday = (($t2date['hours']*60)*60)+($t2date['minutes']*60)+$t2date['seconds']; 04023 04024 $timeworked += ($CONFIG['end_working_day']-$secondsintoday)/60; 04025 04026 $currenttime += ($midnight*$secondsintoday)+$swd; 04027 } 04028 } 04029 else 04030 { 04031 // Jump closer to the next work minute 04032 if (!in_array($time['wday'], $CONFIG['working_days'])) 04033 { 04034 // Move to next day 04035 $c = ($time['hours'] * 60) + $time['minutes']; 04036 $diff = $midnight - $c; 04037 $currenttime += ($diff * 60); // to seconds 04038 04039 // Jump to start of working day 04040 $currenttime += ($swd * 60); 04041 } 04042 else if ($time['hours'] < $swd) 04043 { 04044 // jump to beginning of working day 04045 $c = ($time['hours'] * 60) + $time['minutes']; 04046 $diff = ($swd * 60) - $c; 04047 $currenttime += ($diff * 60); // to seconds 04048 } 04049 else if ($time['hours'] > $ewd) 04050 { 04051 // Jump to the start of the next working day 04052 $c = ($midnight - (($time['hours'] * 60) + $time['minutes'])) + ($swd * 60); 04053 $currenttime += ($c * 60); 04054 } 04055 else if ($ph != 0) 04056 { 04057 // jump to the minute after the public holiday 04058 $currenttime += $ph + 60; 04059 04060 // Jump to start of working day 04061 $currenttime += ($swd * 60); 04062 } 04063 else 04064 { 04065 $currenttime += 60; // move to the next minute 04066 } 04067 } 04068 } 04069 04070 return $timeworked; 04071 */ 04072 } 04073 04074 04078 function is_active_status($status, $states) 04079 { 04080 if (in_array($status, $states)) return false; 04081 else return true; 04082 } 04083 04084 04092 function get_public_holidays($startdate, $enddate) 04093 { 04094 $sql = "SELECT * FROM `{$GLOBALS['dbHolidays']}` "; 04095 $sql .= "WHERE type = ".HOL_PUBLIC." AND (`date` >= FROM_UNIXTIME({$startdate}) AND `date` <= FROM_UNIXTIME({$enddate}))"; 04096 04097 $result = mysql_query($sql); 04098 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04099 04100 $publicholidays = array(); 04101 04102 if (mysql_num_rows($result) > 0) 04103 { 04104 // Assume public holidays are ALL day 04105 while ($obj = mysql_fetch_object($result)) 04106 { 04107 $holiday = new Holiday(); 04108 $holiday->starttime = $obj->date; 04109 $holiday->endtime = ($obj->date + (60 * 60 * 24)); 04110 04111 $publicholidays[] = $holiday; 04112 } 04113 } 04114 return $publicholidays; 04115 } 04116 04117 04128 function calculate_incident_working_time($incidentid, $t1, $t2, $states=array(2,7,8)) 04129 { 04130 if ( $t1 > $t2 ) 04131 { 04132 $t3 = $t2; 04133 $t2 = $t1; 04134 $t1 = $t3; 04135 } 04136 04137 $startofday = mktime(0, 0, 0, date("m", $t1), date("d", $t1), date("Y", $t1)); 04138 $endofday = mktime(23, 59, 59, date("m", $t2), date("d", $t2), date("Y", $t2)); 04139 04140 $publicholidays = get_public_holidays($startofday, $endofday); 04141 04142 $sql = "SELECT id, currentstatus, timestamp FROM `{$GLOBALS['dbUpdates']}` WHERE incidentid='{$incidentid}' ORDER BY id ASC"; 04143 $result = mysql_query($sql); 04144 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04145 04146 $time = 0; 04147 $timeptr = 0; 04148 $laststatus = 2; // closed 04149 while ($update = mysql_fetch_array($result)) 04150 { 04151 // if ($t1<=$update['timestamp']) 04152 if ($t1 <= $update['timestamp']) 04153 { 04154 if ($timeptr == 0) 04155 { 04156 // This is the first update 04157 // If it's active, set the ptr = t1 04158 // otherwise set to current timestamp ??? 04159 if (is_active_status($laststatus, $states)) 04160 { 04161 $timeptr = $t1; 04162 } 04163 else 04164 { 04165 $timeptr = $update['timestamp']; 04166 } 04167 } 04168 04169 if ($t2 < $update['timestamp']) 04170 { 04171 // If we have reached the very end of the range, increment time to end of range, break 04172 if (is_active_status($laststatus, $states)) 04173 { 04174 $time += calculate_working_time($timeptr, $t2, $publicholidays); 04175 } 04176 break; 04177 } 04178 04179 // if status has changed or this is the first (active update) 04180 if (is_active_status($laststatus, $states) != is_active_status($update['currentstatus'], $states)) 04181 { 04182 // If it's active and we've not reached the end of the range, increment time 04183 if (is_active_status($laststatus, $states) && ($t2 >= $update['timestamp'])) 04184 { 04185 $time += calculate_working_time($timeptr, $update['timestamp'], $publicholidays); 04186 } 04187 else 04188 { 04189 $timeptr = $update['timestamp']; 04190 } 04191 // if it's not active set the ptr 04192 } 04193 } 04194 $laststatus = $update['currentstatus']; 04195 } 04196 mysql_free_result($result); 04197 04198 // Calculate remainder 04199 if (is_active_status($laststatus, $states) && ($t2 >= $update['timestamp'])) 04200 { 04201 $time += calculate_working_time($timeptr, $t2, $publicholidays); 04202 } 04203 04204 return $time; 04205 } 04206 04207 04214 function readable_date($date, $lang = 'user') 04215 { 04216 global $SYSLANG, $CONFIG; 04217 // 04218 // e.g. Yesterday @ 5:28pm 04219 if (ldate('dmy', $date) == ldate('dmy', time())) 04220 { 04221 if ($lang == 'user') 04222 { 04223 $datestring = "{$GLOBALS['strToday']} @ ".ldate($CONFIG['dateformat_time'], $date); 04224 } 04225 else 04226 { 04227 $datestring = "{$SYSLANG['strToday']} @ ".ldate($CONFIG['dateformat_time'], $date); 04228 } 04229 } 04230 elseif (ldate('dmy', $date) == ldate('dmy', (time()-86400))) 04231 { 04232 if ($lang == 'user') 04233 { 04234 $datestring = "{$GLOBALS['strYesterday']} @ ".ldate($CONFIG['dateformat_time'], $date); 04235 } 04236 else 04237 { 04238 $datestring = "{$SYSLANG['strYesterday']} @ ".ldate($CONFIG['dateformat_time'], $date); 04239 } 04240 } 04241 else 04242 { 04243 $datestring = ldate($CONFIG['dateformat_longdate'] . ' @ ' . $CONFIG['dateformat_time'], $date); 04244 } 04245 return $datestring; 04246 } 04247 04248 04254 function contact_notify_email($contactid) 04255 { 04256 global $dbContacts; 04257 $sql = "SELECT notify_contactid FROM `{$dbContacts}` WHERE id='{$contactid}' LIMIT 1"; 04258 $result = mysql_query($sql); 04259 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04260 list($notify_contactid) = mysql_fetch_row($result); 04261 04262 $sql = "SELECT email FROM `{$dbContacts}` WHERE id='{$notify_contactid}' LIMIT 1"; 04263 $result = mysql_query($sql); 04264 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04265 list($email) = mysql_fetch_row($result); 04266 04267 return $email; 04268 } 04269 04270 04279 function contact_notify($contactid, $level=0) 04280 { 04281 global $dbContacts; 04282 $notify_contactid = 0; 04283 if ($level == 0) 04284 { 04285 return $contactid; 04286 } 04287 else 04288 { 04289 $sql = "SELECT notify_contactid FROM `{$dbContacts}` WHERE id='{$contactid}' LIMIT 1"; 04290 $result = mysql_query($sql); 04291 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04292 list($notify_contactid) = mysql_fetch_row($result); 04293 04294 if ($level > 0) 04295 { 04296 $newlevel = $level -1; 04297 $notify_contactid = contact_notify($notify_contactid, $newlevel); 04298 04299 } 04300 return $notify_contactid; 04301 } 04302 } 04303 04304 04309 function software_backup_dropdown($name, $userid, $softwareid, $backupid) 04310 { 04311 global $dbUsers, $dbUserSoftware, $dbSoftware; 04312 $sql = "SELECT *, u.id AS userid FROM `{$dbUserSoftware}` AS us, `{$dbSoftware}` AS s, `{$dbUsers}` AS u "; 04313 $sql .= "WHERE us.softwareid = s.id "; 04314 $sql .= "AND s.id = '{$softwareid}' "; 04315 $sql .= "AND userid != '{$userid}' AND u.status > 0 "; 04316 $sql .= "AND us.userid = u.id "; 04317 $sql .= " ORDER BY realname"; 04318 $result = mysql_query($sql); 04319 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04320 $countsw = mysql_num_rows($result); 04321 if ($countsw >= 1) 04322 { 04323 $html = "<select name='{$name}'>\n"; 04324 $html .= "<option value='0'"; 04325 if ($user->userid==0) $html .= " selected='selected'"; 04326 $html .= ">{$GLOBALS['strNone']}</option>\n"; 04327 while ($user = mysql_fetch_object($result)) 04328 { 04329 $html .= "<option value='{$user->userid}'"; 04330 if ($user->userid == $backupid) $html .= " selected='selected'"; 04331 $html .= ">{$user->realname}</option>\n"; 04332 } 04333 $html .= "</select>\n"; 04334 } 04335 else 04336 { 04337 $html .= "<input type='hidden' name='$name' value='0' />{$GLOBALS['strNoneAvailable']}"; 04338 } 04339 return ($html); 04340 } 04341 04342 04347 function software_backup_userid($userid, $softwareid) 04348 { 04349 global $dbUserSoftware; 04350 $backupid = 0; // default 04351 // Find out who is the substitute for this user/skill 04352 $sql = "SELECT backupid FROM `{$dbUserSoftware}` WHERE userid = '{$userid}' AND softwareid = '{$softwareid}'"; 04353 $result = mysql_query($sql); 04354 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04355 list($backupid) = mysql_fetch_row($result); 04356 $backup1 = $backupid; 04357 04358 // If that substitute is not accepting then try and find another 04359 if (empty($backupid) OR user_accepting($backupid) != 'Yes') 04360 { 04361 $sql = "SELECT backupid FROM `{$dbUserSoftware}` WHERE userid='{$backupid}' AND userid!='{$userid}' "; 04362 $sql .= "AND softwareid='{$softwareid}' AND backupid!='{$backup1}'"; 04363 $result = mysql_query($sql); 04364 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04365 list($backupid) = mysql_fetch_row($result); 04366 $backup2 = $backupid; 04367 } 04368 04369 // One more iteration, is the backup of the backup accepting? If not try another 04370 if (empty($backupid) OR user_accepting($backupid)!='Yes') 04371 { 04372 $sql = "SELECT backupid FROM `{$dbUserSoftware}` WHERE userid='{$backupid}' AND userid!='{$userid}' "; 04373 $sql .= "AND softwareid='{$softwareid}' AND backupid!='{$backup1}' AND backupid!='{$backup2}'"; 04374 $result = mysql_query($sql); 04375 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04376 list($backupid) = mysql_fetch_row($result); 04377 } 04378 return ($backupid); 04379 } 04380 04381 04392 function incident_backup_switchover($userid, $accepting) 04393 { 04394 global $now, $dbIncidents, $dbUpdates, $dbTempAssigns, $dbUsers, $dbUserStatus; 04395 04396 $usersql = "SELECT u.*, us.name AS statusname "; 04397 $usersql .= "FROM `{$dbUsers}` AS u, `{$dbUserStatus}` AS us "; 04398 $usersql .= "WHERE u.id = '{$userid}' AND u.status = us.id"; 04399 $userresult = mysql_query($usersql); 04400 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04401 $user = mysql_fetch_row($userresult); 04402 04403 if (strtolower($accepting) == 'no') 04404 { 04405 // Look through the incidents that this user OWNS (and are not closed) 04406 $sql = "SELECT * FROM `{$dbIncidents}` WHERE (owner='{$userid}' OR towner='{$userid}') AND status!=2"; 04407 $result = mysql_query($sql); 04408 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04409 while ($incident = mysql_fetch_object($result)) 04410 { 04411 // Try and find a backup/substitute engineer 04412 $backupid = software_backup_userid($userid, $incident->softwareid); 04413 04414 if (empty($backupid) OR user_accepting($backupid) == 'No') 04415 { 04416 // no backup engineer found so add to the holding queue 04417 // Look to see if this assignment is in the queue already 04418 $fsql = "SELECT * FROM `{$dbTempAssigns}` WHERE incidentid='{$incident->id}' AND originalowner='{$userid}'"; 04419 $fresult = mysql_query($fsql); 04420 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04421 if (mysql_num_rows($fresult) < 1) 04422 { 04423 // it's not in the queue, and the user isn't accepting so add it 04424 //$userstatus=user_status($userid); 04425 $userstatus = $user['status']; 04426 $usql = "INSERT INTO `{$dbTempAssigns}` (incidentid,originalowner,userstatus) VALUES ('{$incident->id}', '{$userid}', '$userstatus')"; 04427 mysql_query($usql); 04428 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04429 } 04430 } 04431 else 04432 { 04433 // do an automatic temporary reassign 04434 // update incident 04435 $rusql = "UPDATE `{$dbIncidents}` SET "; 04436 $rusql .= "towner='{$backupid}', lastupdated='$now' WHERE id='{$incident->id}' LIMIT 1"; 04437 mysql_query($rusql); 04438 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04439 04440 // add update 04441 $username=user_realname($userid); 04442 //$userstatus = userstatus_name(user_status($userid)); 04443 $userstatus = $user['statusname']; 04444 //$usermessage=user_message($userid); 04445 $usermessage = $user['message']; 04446 $bodytext = "Previous Incident Owner ({$username}) {$userstatus} {$usermessage}"; 04447 $assigntype = 'tempassigning'; 04448 $risql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, bodytext, type, timestamp, currentowner, currentstatus) "; 04449 $risql .= "VALUES ('{$incident->id}', '0', '{$bodytext}', '{$assigntype}', '{$now}', "; 04450 $risql .= "'{$backupid}', "; 04451 $risql .= "'{$incident->status}')"; 04452 mysql_query($risql); 04453 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04454 04455 // Look to see if this assignment is in the queue already 04456 $fsql = "SELECT * FROM `{$dbTempAssigns}` WHERE incidentid='{$incident->id}' AND originalowner='{$userid}'"; 04457 $fresult = mysql_query($fsql); 04458 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04459 if (mysql_num_rows($fresult) < 1) 04460 { 04461 //$userstatus=user_status($userid); 04462 $userstatus = $user['status']; 04463 $usql = "INSERT INTO `{$dbTempAssigns}` (incidentid,originalowner,userstatus,assigned) VALUES ('{$incident->id}', '{$userid}', '$userstatus','yes')"; 04464 mysql_query($usql); 04465 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04466 } 04467 else 04468 { 04469 // mark the temp assigns table so it's not showing in the holding queue 04470 $tasql = "UPDATE `{$dbTempAssigns}` SET assigned='yes' WHERE originalowner='$userid' AND incidentid='{$incident->id}' LIMIT 1"; 04471 mysql_query($tasql); 04472 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04473 } 04474 } 04475 } 04476 } 04477 elseif ($accepting=='') 04478 { 04479 // Do nothing when accepting status doesn't exist 04480 } 04481 else 04482 { 04483 // The user is now ACCEPTING, so first have a look to see if there are any reassignments in the queue 04484 $sql = "SELECT * FROM `{$dbTempAssigns}` WHERE originalowner='{$userid}' "; 04485 $result = mysql_query($sql); 04486 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04487 while ($assign = mysql_fetch_object($result)) 04488 { 04489 if ($assign->assigned == 'yes') 04490 { 04491 // Incident has actually been reassigned, so have a look if we can grab it back. 04492 $lsql = "SELECT id,status FROM `{$dbIncidents}` "; 04493 $lsql .= "WHERE id='{$assign->incidentid}' AND owner='{$assign->originalowner}' AND towner!=''"; 04494 $lresult = mysql_query($lsql); 04495 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04496 while ($incident = mysql_fetch_object($lresult)) 04497 { 04498 // Find our tempassign 04499 $usql = "SELECT id,currentowner FROM `{$dbUpdates}` "; 04500 $usql .= "WHERE incidentid='{$incident->id}' AND userid='0' AND type='tempassigning' "; 04501 $usql .= "ORDER BY id DESC LIMIT 1"; 04502 $uresult = mysql_query($usql); 04503 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04504 list($prevassignid,$tempowner) = mysql_fetch_row($uresult); 04505 04506 // Look to see if the temporary owner has updated the incident since we temp assigned it 04507 // If he has, we leave it in his queue 04508 $usql = "SELECT id FROM `{$dbUpdates}` "; 04509 $usql .= "WHERE incidentid='{$incident->id}' AND id > '{$prevassignid}' AND userid='{$tempowner}' LIMIT 1 "; 04510 $uresult = mysql_query($usql); 04511 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04512 if (mysql_num_rows($uresult) < 1) 04513 { 04514 // Incident appears not to have been updated by the temporary owner so automatically reassign back to orignal owner 04515 // update incident 04516 $rusql = "UPDATE `{$dbIncidents}` SET "; 04517 $rusql .= "towner='', lastupdated='{$now}' WHERE id='{$incident->id}' LIMIT 1"; 04518 mysql_query($rusql); 04519 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04520 04521 // add update 04522 $username = user_realname($userid); 04523 //$userstatus = userstatus_name(user_status($userid)); 04524 $userstatus = $user['statusname']; 04525 //$usermessage=user_message($userid); 04526 $usermessage = $user['message']; 04527 $bodytext = "Reassigning to original owner {$username} ({$userstatus})"; 04528 $assigntype = 'reassigning'; 04529 $risql = "INSERT INTO `{$dbUpdates}` (incidentid, userid, bodytext, type, timestamp, currentowner, currentstatus) "; 04530 $risql .= "VALUES ('{$incident->id}', '0', '{$bodytext}', '{$assigntype}', '{$now}', "; 04531 $risql .= "'{$backupid}', "; 04532 $risql .= "'{$incident->status}')"; 04533 mysql_query($risql); 04534 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04535 04536 // remove from assign queue now, all done 04537 $rsql = "DELETE FROM `{$dbTempAssigns}` WHERE incidentid='{$assign->incidentid}' AND originalowner='{$assign->originalowner}'"; 04538 mysql_query($rsql); 04539 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04540 } 04541 } 04542 } 04543 else 04544 { 04545 // now have a look to see if the reassign was completed 04546 $ssql = "SELECT id FROM `{$dbIncidents}` WHERE id='{$assign->incidentid}' LIMIT 1"; 04547 $sresult = mysql_query($ssql); 04548 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04549 if (mysql_num_rows($sresult) >= 1) 04550 { 04551 // reassign wasn't completed, or it was already assigned back, simply remove from assign queue 04552 $rsql = "DELETE FROM `{$dbTempAssigns}` WHERE incidentid='{$assign->incidentid}' AND originalowner='{$assign->originalowner}'"; 04553 mysql_query($rsql); 04554 if (mysql_error()) trigger_error(mysql_error(),E_USER_ERROR); 04555 } 04556 } 04557 } 04558 } 04559 return; 04560 } 04561 04562 04570 function format_external_id($externalid, $escalationpath='') 04571 { 04572 global $CONFIG, $dbEscalationPaths; 04573 04574 if (!empty($escalationpath)) 04575 { 04576 // Extract escalation path 04577 $epsql = "SELECT id, name, track_url, home_url, url_title FROM `{$dbEscalationPaths}` "; 04578 if (!empty($escalationpath)) $epsql .= "WHERE id='$escalationpath' "; 04579 $epresult = mysql_query($epsql); 04580 if (mysql_error()) trigger_error(mysql_error(), E_USER_WARNING); 04581 if (mysql_num_rows($epresult) >= 1) 04582 { 04583 while ($escalationpath = mysql_fetch_object($epresult)) 04584 { 04585 $epath['name'] = $escalationpath->name; 04586 $epath['track_url'] = $escalationpath->track_url; 04587 $epath['home_url'] = $escalationpath->home_url; 04588 $epath['url_title'] = $escalationpath->url_title; 04589 } 04590 if (!empty($externalid)) 04591 { 04592 $epathurl = str_replace('%externalid%', $externalid, $epath['track_url']); 04593 $html = "<a href='{$epathurl}' title='{$epath['url_title']}'>{$externalid}</a>"; 04594 } 04595 else 04596 { 04597 $epathurl = $epath['home_url']; 04598 $html = "<a href='{$epathurl}' title='{$epath['url_title']}'>{$epath['name']}</a>"; 04599 } 04600 } 04601 } 04602 else 04603 { 04604 $html = $externalid; 04605 } 04606 return $html; 04607 } 04608 04609 04610 // Converts a PHP.INI integer into a byte value 04611 function return_bytes($val) 04612 { 04613 $val = trim($val); 04614 $last = strtolower($val{strlen($val)-1}); 04615 switch ($last) 04616 { 04617 // The 'G' modifier is available since PHP 5.1.0 04618 case 'g': 04619 $val *= 1024; 04620 case 'm': 04621 $val *= 1024; 04622 case 'k': 04623 $val *= 1024; 04624 } 04625 return $val; 04626 } 04627 04628 04629 // FIXME use this instead of hardcoding tabs 04630 function draw_tabs($tabsarray, $selected='') 04631 { 04632 if ($selected=='') $selected=key($tabsarray); 04633 $html .= "<div class='tabcontainer'>"; 04634 $html .= "<ul class='tabnav'>"; 04635 foreach ($tabsarray AS $tab => $url) 04636 { 04637 $html .= "<li><a href='$url'"; 04638 if (strtolower($tab) == strtolower($selected)) 04639 { 04640 $html .= " class='active'"; 04641 } 04642 $tab = str_replace('_', ' ', $tab); 04643 $html .= ">$tab</a></li>\n"; 04644 } 04645 $html .= "</ul>"; 04646 $html .= "</div>"; 04647 04648 return ($html); 04649 } 04650 04651 04659 function send_feedback($contractid) 04660 { 04661 global $CONFIG; 04662 if (!$CONFIG['feedback_enabled']) 04663 { 04664 return FALSE; 04665 } 04666 else 04667 { 04668 foreach ($CONFIG['no_feedback_contracts'] AS $contract) 04669 { 04670 if ($contract == $contractid) 04671 { 04672 return FALSE; 04673 } 04674 } 04675 } 04676 04677 return TRUE; 04678 } 04679 04686 function create_incident_feedback($formid, $incidentid) 04687 { 04688 global $dbFeedbackRespondents; 04689 $contactid = incident_contact($incidentid); 04690 $email = contact_email($contactid); 04691 04692 $sql = "INSERT INTO `{$dbFeedbackRespondents}` (formid, contactid, email, incidentid) VALUES ("; 04693 $sql .= "'".mysql_real_escape_string($formid)."', "; 04694 $sql .= "'".mysql_real_escape_string($contactid)."', "; 04695 $sql .= "'".mysql_real_escape_string($email)."', "; 04696 $sql .= "'".mysql_real_escape_string($incidentid)."') "; 04697 mysql_query($sql); 04698 if (mysql_error()) trigger_error ("MySQL Error: ".mysql_error(), E_USER_ERROR); 04699 $blankformid = mysql_insert_id(); 04700 return $blankformid; 04701 } 04702 04703 04704 function file_permissions_info($perms) 04705 { 04706 if (($perms & 0xC000) == 0xC000) $info = 's'; 04707 elseif (($perms & 0xA000) == 0xA000) $info = 'l'; 04708 elseif (($perms & 0x8000) == 0x8000) $info = '-'; 04709 elseif (($perms & 0x6000) == 0x6000) $info = 'b'; 04710 elseif (($perms & 0x4000) == 0x4000) $info = 'd'; 04711 elseif (($perms & 0x2000) == 0x2000) $info = 'c'; 04712 elseif (($perms & 0x1000) == 0x1000) $info = 'p'; 04713 else $info = 'u'; 04714 04715 // Owner 04716 $info .= (($perms & 0x0100) ? 'r' : '-'); 04717 $info .= (($perms & 0x0080) ? 'w' : '-'); 04718 $info .= (($perms & 0x0040) ? 04719 (($perms & 0x0800) ? 's' : 'x' ) : 04720 (($perms & 0x0800) ? 'S' : '-')); 04721 04722 // Group 04723 $info .= (($perms & 0x0020) ? 'r' : '-'); 04724 $info .= (($perms & 0x0010) ? 'w' : '-'); 04725 $info .= (($perms & 0x0008) ? 04726 (($perms & 0x0400) ? 's' : 'x' ) : 04727 (($perms & 0x0400) ? 'S' : '-')); 04728 04729 // World 04730 $info .= (($perms & 0x0004) ? 'r' : '-'); 04731 $info .= (($perms & 0x0002) ? 'w' : '-'); 04732 $info .= (($perms & 0x0001) ? 04733 (($perms & 0x0200) ? 't' : 'x' ) : 04734 (($perms & 0x0200) ? 'T' : '-')); 04735 04736 return $info; 04737 } 04738 04739 04740 04741 04742 function external_escalation($escalated, $incid) 04743 { 04744 foreach ($escalated as $i => $id) 04745 { 04746 if ($id == $incid) 04747 { 04748 return "yes"; 04749 } 04750 } 04751 04752 return "no"; 04753 } 04754 04755 04756 04763 function bbcode($text) 04764 { 04765 global $CONFIG; 04766 $bbcode_regex = array(0 => "/\[b\](.*?)\[\/b\]/s", 04767 1 => "/\[i\](.*?)\[\/i\]/s", 04768 2 => "/\[u\](.*?)\[\/u\]/s", 04769 3 => "/\[quote\](.*?)\[\/quote\]/s", 04770 4 => "/\[size=(.+?)\](.+?)\[\/size\]/is", 04771 5 => "/\[url\](.*?)\[\/url\]/s", 04772 6 => "/\[size=(.+?)\](.+?)\[\/size\]/is", 04773 7 => "/\[img\](.*?)\[\/img\]/s", 04774 8 => "/\[size=(.+?)\](.+?)\[\/size\]/is", 04775 9 => "/\[color\](.*?)\[\/color\]/s", 04776 10 => "/\[size=(.+?)\](.+?)\[\/size\]/is", 04777 11 => "/\[size\](.*?)\[\/size\]/s", 04778 12 => "/\[code\](.*?)\[\/code\]/s", 04779 13 => "/\[hr\]/s", 04780 14 => "/\[s\](.*?)\[\/s\]/s", 04781 15 => "/\[\[att\=(.*?)]](.*?)\[\[\/att]]/s", 04782 16 => "/\[url=(.+?)\](.+?)\[\/url\]/is"); 04783 04784 $bbcode_replace = array(0 => "<strong>$1</strong>", 04785 1 => "<em>$1</em>", 04786 2 => "<u>$1</u>", 04787 3 => "<blockquote><p>$1</p></blockquote>", 04788 4 => "<blockquote cite=\"$1\"><p>$1 said:<br />$2</p></blockquote>", 04789 5 => '<a href="$1" title="$1">$1</a>', 04790 6 => "<a href=\"$1\" title=\"$1\">$2</a>", 04791 7 => "<img src=\"$1\" alt=\"User submitted image\" />", 04792 8 => "<span style=\"color:$1\">$2</span>", 04793 9 => "<span style=\"color:red;\">$1</span>", 04794 10 => "<span style=\"font-size:$1\">$2</span>", 04795 11 => "<span style=\"font-size:large\">$1</span>", 04796 12 => "<code>$1</code>", 04797 13 => "<hr />", 04798 14 => "<span style=\"text-decoration:line-through\">$1</span>", 04799 15 => "<a href=\"{$CONFIG['application_webpath']}download.php?id=$1\">$2</a>", 04800 16 => "<a href=\"$1\">$2</a>"); 04801 04802 $html = preg_replace($bbcode_regex, $bbcode_replace, $text); 04803 return $html; 04804 } 04805 04806 04807 function strip_bbcode_tooltip($text) 04808 { 04809 $bbcode_regex = array(0 => '/\[url\](.*?)\[\/url\]/s', 04810 04811 1 => '/\[url\=(.*?)\](.*?)\[\/url\]/s', 04812 2 => '/\[color\=(.*?)\](.*?)\[\/color\]/s', 04813 3 => '/\[size\=(.*?)\](.*?)\[\/size\]/s', 04814 4 => '/\[blockquote\=(.*?)\](.*?)\[\/blockquote\]/s', 04815 5 => '/\[blockquote\](.*?)\[\/blockquote\]/s', 04816 6 => "/\[s\](.*?)\[\/s\]/s"); 04817 $bbcode_replace = array(0 => '$1', 04818 1 => '$2', 04819 2 => '$2', 04820 3 => '$2', 04821 4 => '$2', 04822 5 => '$1', 04823 6 => '$1' 04824 ); 04825 04826 return preg_replace($bbcode_regex, $bbcode_replace, $text); 04827 } 04828 04829 04836 function bbcode_toolbar($elementid) 04837 { 04838 $html = "\n<div class='bbcode_toolbar'>BBCode: "; 04839 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[b]', '[/b]')\">B</a> "; 04840 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[i]', '[/i]')\">I</a> "; 04841 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[u]', '[/u]')\">U</a> "; 04842 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[s]', '[/s]')\">S</a> "; 04843 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[quote]', '[/quote]')\">Quote</a> "; 04844 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[url]', '[/url]')\">Link</a> "; 04845 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[img]', '[/img]')\">Img</a> "; 04846 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[color]', '[/color]')\">Color</a> "; 04847 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[size]', '[/size]')\">Size</a> "; 04848 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '[code]', '[/code]')\">Code</a> "; 04849 $html .= "<a href=\"javascript:insertBBCode('{$elementid}', '', '[hr]')\">HR</a> "; 04850 $html .= "</div>\n"; 04851 return $html; 04852 } 04853 04854 04855 function parse_updatebody($updatebody, $striptags = TRUE) 04856 { 04857 if (!empty($updatebody)) 04858 { 04859 $updatebody = str_replace("<hr>", "[hr]\n", $updatebody); 04860 if ($striptags) 04861 { 04862 $updatebody = strip_tags($updatebody); 04863 } 04864 else 04865 { 04866 $updatebody = str_replace("<hr>", "", $updatebody); 04867 } 04868 $updatebody = nl2br($updatebody); 04869 $updatebody = str_replace("&quot;", """, $updatebody); 04870 $updatebody = str_replace("&gt;", ">", $updatebody); 04871 $updatebody = str_replace("&lt;", "<", $updatebody); 04872 // Insert path to attachments 04873 //new style 04874 $updatebody = preg_replace("/\[\[att\=(.*?)\]\](.*?)\[\[\/att\]\]/","$2", $updatebody); 04875 //old style 04876 $updatebody = preg_replace("/\[\[att\]\](.*?)\[\[\/att\]\]/","$1", $updatebody); 04877 //remove tags that are incompatable with tool tip 04878 $updatebody = strip_bbcode_tooltip($updatebody); 04879 //then show compatable BBCode 04880 $updatebody = bbcode($updatebody); 04881 if (strlen($updatebody) > 490) $updatebody .= '...'; 04882 } 04883 04884 return $updatebody; 04885 } 04886 04887 04894 function add_note_form($linkid, $refid) 04895 { 04896 global $now, $sit, $iconset; 04897 $html = "<form name='addnote' action='note_add.php' method='post'>"; 04898 $html .= "<div class='detailhead note'> <div class='detaildate'>".readable_date($now)."</div>\n"; 04899 $html .= icon('note', 16, $GLOBALS['strNote ']); 04900 $html .= " ".sprintf($GLOBALS['strNewNoteByX'], user_realname($sit[2]))."</div>\n"; 04901 $html .= "<div class='detailentry note'>"; 04902 $html .= "<textarea rows='3' cols='40' name='bodytext' style='width: 94%; margin-top: 5px; margin-bottom: 5px; margin-left: 3%; margin-right: 3%; background-color: transparent; border: 1px dashed #A2A86A;'></textarea>"; 04903 if (!empty($linkid)) 04904 { 04905 $html .= "<input type='hidden' name='link' value='{$linkid}' />"; 04906 } 04907 else 04908 { 04909 $html .= " {$GLOBALS['strLInk']} <input type='text' name='link' size='3' />"; 04910 } 04911 04912 if (!empty($refid)) 04913 { 04914 $html .= "<input type='hidden' name='refid' value='{$refid}' />"; 04915 } 04916 else 04917 { 04918 $html .= " {$GLOBALS['strRefID']} <input type='text' name='refid' size='4' />"; 04919 } 04920 04921 $html .= "<input type='hidden' name='action' value='addnote' />"; 04922 $html .= "<input type='hidden' name='rpath' value='{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}' />"; 04923 $html .= "<div style='text-align: right'><input type='submit' value='{$GLOBALS['strAddNote']}' /></div>\n"; 04924 $html .= "</div>\n"; 04925 $html .= "</form>"; 04926 return $html; 04927 } 04928 04929 04937 function show_notes($linkid, $refid, $delete = TRUE) 04938 { 04939 global $sit, $iconset, $dbNotes; 04940 $sql = "SELECT * FROM `{$dbNotes}` WHERE link='{$linkid}' AND refid='{$refid}' ORDER BY timestamp DESC, id DESC"; 04941 $result = mysql_query($sql); 04942 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 04943 $countnotes = mysql_num_rows($result); 04944 if ($countnotes >= 1) 04945 { 04946 while ($note = mysql_fetch_object($result)) 04947 { 04948 $html .= "<div class='detailhead note'> <div class='detaildate'>".readable_date(mysqlts2date($note->timestamp)); 04949 if ($delete) 04950 { 04951 $html .= "<a href='note_delete.php?id={$note->id}&rpath="; 04952 $html .= "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}' "; 04953 $html .= "onclick=\"return confirm_action('{$strAreYouSureDelete}');\">"; 04954 $html .= icon('delete', 16)."</a>"; 04955 } 04956 $html .= "</div>\n"; // /detaildate 04957 $html .= icon('note', 16)." "; 04958 $html .= sprintf($GLOBALS['strNoteAddedBy'], user_realname($note->userid,TRUE)); 04959 $html .= "</div>\n"; // detailhead 04960 $html .= "<div class='detailentry note'>"; 04961 $html .= nl2br(bbcode($note->bodytext)); 04962 $html .= "</div>\n"; 04963 } 04964 } 04965 return $html; 04966 } 04967 04968 04986 function dashlet($dashboard, $dashletid, $icon, $title='', $link='', $content='') 04987 { 04988 global $strLoading; 04989 if (empty($icon)) $icon = icon('dashboard', 16); 04990 if (empty($title)) $title = $GLOBALS['strUntitled']; 04991 $displayfn = "dashboard_{$dashboard}_display"; 04992 $editfn = "dashboard_{$dashboard}_edit"; 04993 04994 $html .= "<div class='windowbox' id='{$dashletid}'>"; 04995 $html .= "<div class='windowtitle'>"; 04996 $html .= "<div class='innerwindow'>"; 04997 if (function_exists($displayfn)) 04998 { 04999 $html .= "<a href=\"javascript:get_and_display('ajaxdata.php?action=dashboard_display&dashboard={$dashboard}&did={$dashletid}','win{$dashletid}',true);\">"; 05000 $html .= icon('reload', 16, '', '', "refresh{$dashletid}")."</a>"; 05001 } 05002 05003 if (function_exists($editfn)) 05004 { 05005 $html .= "<a href=\"javascript:get_and_display('ajaxdata.php?action=dashboard_edit&dashboard={$dashboard}&did={$dashletid}','win{$dashletid}',false);\">"; 05006 $html .= icon('edit', 16)."</a>"; 05007 } 05008 $html .= "</div>"; 05009 if (!empty($link)) $html .= "<a href=\"{$link}\">{$icon}</a> <a href=\"{$link}\">{$title}</a>"; 05010 else $html .= "{$icon} {$title}"; 05011 $html .= "</div>\n"; 05012 $html .= "<div class='window' id='win{$dashletid}'>"; 05013 $html .= $content; 05014 $displayfn = "dashboard_{$dashboard}_display"; 05015 if (function_exists($displayfn)) 05016 { 05017 $html .= "<script type='text/javascript'>\n//<![CDATA[\nget_and_display('ajaxdata.php?action=dashboard_display&dashboard={$dashboard}','win{$dashletid}',true);\n//]]>\n</script>\n"; 05018 } 05019 $html .= "</div></div>"; 05020 05021 return $html; 05022 } 05023 05024 05042 function dashlet_link($dashboard, $dashletid, $text='', $action='', $params='', $refresh = FALSE, $formid='') 05043 { 05044 if ($action == 'edit') 05045 { 05046 $action = 'dashboard_edit'; 05047 } 05048 elseif ($action == 'save') 05049 { 05050 $action = 'dashboard_save'; 05051 } 05052 else 05053 { 05054 $action = 'dashboard_display'; 05055 } 05056 05057 if (empty($text)) 05058 { 05059 $text = $GLOBALS['strUntitled']; 05060 } 05061 05062 // Ensure the dashlet ID is always correct, 'win' gets prepended with each subpage 05063 // We only need it once 05064 $dashletid = 'win'.str_replace('win', '', $dashletid); 05065 05066 // Convert refresh boolean to javascript text for boolean 05067 if ($refresh) $refresh = 'true'; 05068 else $refresh = 'false'; 05069 05070 if ($action == 'dashboard_save' AND $formid == '') 05071 { 05072 $formid = "{$dashboard}form"; 05073 } 05074 05075 if ($action == 'dashboard_save') 05076 { 05077 $html .= "<a href=\"javascript:ajax_save("; 05078 } 05079 else 05080 { 05081 $html .= "<a href=\"javascript:get_and_display("; 05082 } 05083 05084 $html .= "'ajaxdata.php?action={$action}&dashboard={$dashboard}&did={$dashletid}"; 05085 if (is_array($params)) 05086 { 05087 foreach ($params AS $pname => $pvalue) 05088 { 05089 $html .= "&{$pname}={$pvalue}"; 05090 } 05091 } 05092 //$html .= "&editaction=do_add&type={$type}"; 05093 05094 if ($action != 'dashboard_save') 05095 { 05096 $html .= "', '{$dashletid}'"; 05097 $html .= ", $refresh"; 05098 } 05099 else 05100 { 05101 $html .= "', '{$formid}'"; 05102 } 05103 $html .= ");\">{$text}</a>"; 05104 05105 return $html; 05106 } 05107 05108 05117 function dashboard_do($context, $row=0, $dashboardid=0) 05118 { 05119 global $DASHBOARDCOMP; 05120 $dashletid = "{$row}-{$dashboardid}"; 05121 $action = $DASHBOARDCOMP[$context]; 05122 if ($action != NULL || $action != '') 05123 { 05124 if (function_exists($action)) $action($dashletid); 05125 } 05126 } 05127 05128 05129 function show_dashboard_component($row, $dashboardid) 05130 { 05131 global $dbDashboard; 05132 $sql = "SELECT name FROM `{$dbDashboard}` WHERE enabled = 'true' AND id = '$dashboardid'"; 05133 $result = mysql_query($sql); 05134 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05135 05136 if (mysql_num_rows($result) == 1) 05137 { 05138 $obj = mysql_fetch_object($result); 05139 dashboard_do("dashboard_".$obj->name, 'db_'.$row, $dashboardid); 05140 } 05141 } 05142 05143 05148 function show_links($origtab, $colref, $level=0, $parentlinktype='', $direction='lr') 05149 { 05150 global $dbLinkTypes, $dbLinks; 05151 // Maximum recursion 05152 $maxrecursions = 15; 05153 05154 if ($level <= $maxrecursions) 05155 { 05156 $sql = "SELECT * FROM `{$dbLinkTypes}` WHERE origtab='$origtab' "; 05157 if (!empty($parentlinktype)) $sql .= "AND id='{$parentlinktype}'"; 05158 $result = mysql_query($sql); 05159 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05160 while ($linktype = mysql_fetch_object($result)) 05161 { 05162 // Look up links of this type 05163 $lsql = "SELECT * FROM `{$dbLinks}` WHERE linktype='{$linktype->id}' "; 05164 if ($direction=='lr') $lsql .= "AND origcolref='{$colref}'"; 05165 elseif ($direction=='rl') $lsql .= "AND linkcolref='{$colref}'"; 05166 $lresult = mysql_query($lsql); 05167 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05168 if (mysql_num_rows($lresult) >= 1) 05169 { 05170 if (mysql_num_rows($lresult) >= 1) 05171 { 05172 $html .= "<ul>"; 05173 $html .= "<li>"; 05174 while ($link = mysql_fetch_object($lresult)) 05175 { 05176 $recsql = "SELECT {$linktype->selectionsql} AS recordname FROM {$linktype->linktab} WHERE "; 05177 if ($direction=='lr') $recsql .= "{$linktype->linkcol}='{$link->linkcolref}' "; 05178 elseif ($direction=='rl') $recsql .= "{$linktype->origcol}='{$link->origcolref}' "; 05179 $recresult = mysql_query($recsql); 05180 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05181 while ($record = mysql_fetch_object($recresult)) 05182 { 05183 if ($link->direction == 'bi') 05184 { 05185 $html .= "<strong>{$linktype->name}</strong> "; 05186 } 05187 elseif ($direction == 'lr') 05188 { 05189 $html .= "<strong>{$linktype->lrname}</strong> "; 05190 } 05191 elseif ($direction == 'rl') 05192 { 05193 $html .= "<strong>{$linktype->rlname}</strong> "; 05194 } 05195 else 05196 { 05197 $html = $GLOBALS['strError']; 05198 } 05199 05200 if ($direction == 'lr') 05201 { 05202 $currentlinkref = $link->linkcolref; 05203 } 05204 elseif ($direction == 'rl') 05205 { 05206 $currentlinkref = $link->origcolref; 05207 } 05208 05209 $viewurl = str_replace('%id%',$currentlinkref,$linktype->viewurl); 05210 05211 $html .= "{$currentlinkref}: "; 05212 if (!empty($viewurl)) $html .= "<a href='$viewurl'>"; 05213 $html .= "{$record->recordname}"; 05214 if (!empty($viewurl)) $html .= "</a>"; 05215 $html .= " - ".user_realname($link->userid,TRUE); 05216 $html .= show_links($linktype->linktab, $currentlinkref, $level+1, $linktype->id, $direction); // Recurse 05217 $html .= "</li>\n"; 05218 } 05219 } 05220 $html .= "</ul>\n"; 05221 } 05222 else $html .= "<p>{$GLOBALS['strNone']}</p>"; 05223 } 05224 } 05225 } 05226 else $html .= "<p class='error'>{$GLOBALS['strError']}: Maximum number of {$maxrecursions} recursions reached</p>"; 05227 return $html; 05228 } 05229 05230 05235 function show_create_links($table, $ref) 05236 { 05237 global $dbLinkTypes; 05238 $html .= "<p align='center'>{$GLOBALS['strAddLink']}: "; 05239 $sql = "SELECT * FROM `{$dbLinkTypes}` WHERE origtab='$table' OR linktab='$table' "; 05240 $result = mysql_query($sql); 05241 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05242 $numlinktypes = mysql_num_rows($result); 05243 $rowcount = 1; 05244 while ($linktype = mysql_fetch_object($result)) 05245 { 05246 if ($linktype->origtab == $table AND $linktype->linktab != $table) 05247 { 05248 $html .= "<a href='link_add.php?origtab=tasks&origref={$ref}&linktype={$linktype->id}'>{$linktype->lrname}</a>"; 05249 } 05250 elseif ($linktype->origtab != $table AND $linktype->linktab == $table) 05251 { 05252 $html .= "<a href='link_add.php?origtab=tasks&origref={$ref}&linktype={$linktype->id}'>{$linktype->rlname}</a>"; 05253 } 05254 else 05255 { 05256 $html .= "<a href='link_add.php?origtab=tasks&origref={$ref}&linktype={$linktype->id}'>{$linktype->lrname}</a> | "; 05257 $html .= "<a href='link_add.php?origtab=tasks&origref={$ref}&linktype={$linktype->id}&dir=rl'>{$linktype->rlname}</a>"; 05258 } 05259 05260 if ($rowcount < $numlinktypes) $html .= " | "; 05261 $rowcount++; 05262 } 05263 $html .= "</p>"; 05264 return $html; 05265 } 05266 05267 05276 function draw_chart_image($type, $width, $height, $data, $legends, $title='', $unit='') 05277 { 05278 global $CONFIG; 05279 // Graph settings 05280 if (empty($width)) $width = 500; 05281 if (empty($height)) $height = 150; 05282 05283 05284 if (!empty($CONFIG['font_file']) AND file_exists($CONFIG['font_file'])) $use_ttf = TRUE; 05285 else $use_ttf = FALSE; 05286 05287 $countdata = count($data); 05288 $sumdata = array_sum($data); 05289 05290 if ($countdata > 8) $height += (($countdata - 8) * 14); 05291 05292 $img = imagecreatetruecolor($width, $height); 05293 05294 $white = imagecolorallocate($img, 255, 255, 255); 05295 $blue = imagecolorallocate($img, 240, 240, 255); 05296 $midblue = imagecolorallocate($img, 204, 204, 255); 05297 $darkblue = imagecolorallocate($img, 32, 56, 148); 05298 $black = imagecolorallocate($img, 0, 0, 0); 05299 $grey = imagecolorallocate($img, 224, 224, 224); 05300 $red = imagecolorallocate($img, 255, 0, 0); 05301 05302 imagefill($img, 0, 0, $white); 05303 05304 $rgb[] = "190,190,255"; 05305 $rgb[] = "205,255,255"; 05306 $rgb[] = "255,255,156"; 05307 $rgb[] = "156,255,156"; 05308 $rgb[] = "255,205,195"; 05309 $rgb[] = "255,140,255"; 05310 $rgb[] = "100,100,155"; 05311 $rgb[] = "98,153,90"; 05312 $rgb[] = "205,210,230"; 05313 $rgb[] = "192,100,100"; 05314 $rgb[] = "204,204,0"; 05315 $rgb[] = "255,102,102"; 05316 $rgb[] = "0,204,204"; 05317 $rgb[] = "0,255,0"; 05318 $rgb[] = "255,168,88"; 05319 $rgb[] = "128,0,128"; 05320 $rgb[] = "0,153,153"; 05321 $rgb[] = "255,230,204"; 05322 $rgb[] = "128,170,213"; 05323 $rgb[] = "75,75,75"; 05324 // repeats... 05325 $rgb[] = "190,190,255"; 05326 $rgb[] = "156,255,156"; 05327 $rgb[] = "255,255,156"; 05328 $rgb[] = "205,255,255"; 05329 $rgb[] = "255,205,195"; 05330 $rgb[] = "255,140,255"; 05331 $rgb[] = "100,100,155"; 05332 $rgb[] = "98,153,90"; 05333 $rgb[] = "205,210,230"; 05334 $rgb[] = "192,100,100"; 05335 $rgb[] = "204,204,0"; 05336 $rgb[] = "255,102,102"; 05337 $rgb[] = "0,204,204"; 05338 $rgb[] = "0,255,0"; 05339 $rgb[] = "255,168,88"; 05340 $rgb[] = "128,0,128"; 05341 $rgb[] = "0,153,153"; 05342 $rgb[] = "255,230,204"; 05343 $rgb[] = "128,170,213"; 05344 $rgb[] = "75,75,75"; 05345 05346 switch ($type) 05347 { 05348 case 'pie': 05349 // Set Pie Postition. CenterX,CenterY 05350 $cx = '120'; 05351 $cy ='60'; 05352 05353 // Set Size-dimensions. SizeX,SizeY,SizeZ 05354 $sx = '200'; 05355 $sy='100'; 05356 $sz ='15'; 05357 05358 // Title 05359 if (!empty($title)) 05360 { 05361 $cy += 10; 05362 if ($use_ttf) 05363 { 05364 imagettftext($img, 10, 0, 2, 10, $black, $CONFIG['font_file'], $title); 05365 } 05366 else 05367 { 05368 imagestring($img, 2, 2, ($legendY-1), "{$title}", $black); 05369 } 05370 } 05371 05372 $angle_sum[-1] = 0; 05373 05374 //convert to angles. 05375 for ($i = 0; $i < $countdata; $i++) 05376 { 05377 if ($sumdata > 0) 05378 { 05379 $angle[$i] = (($data[$i] / $sumdata) * 360); 05380 } 05381 else 05382 { 05383 $angle[$i] = 0; 05384 } 05385 $angle_sum[$i] = array_sum($angle); 05386 } 05387 05388 $background = imagecolorallocate($img, 255, 255, 255); 05389 //Random colors. 05390 05391 for ($i = 0; $i <= $countdata; $i++) 05392 { 05393 $rgbcolors = explode(',',$rgb[$i]); 05394 $colors[$i] = imagecolorallocate($img, $rgbcolors[0], $rgbcolors[1], $rgbcolors[2]); 05395 $colord[$i] = imagecolorallocate($img, ($rgbcolors[0]/1.5), ($rgbcolors[1]/1.5), ($rgbcolors[2]/1.5)); 05396 } 05397 05398 //3D effect. 05399 $legendY = 80 - ($countdata * 10); 05400 05401 if ($legendY < 10) $legendY = 10; 05402 05403 for ($z = 1; $z <= $sz; $z++) 05404 { 05405 for ($i = 0; $i < $countdata; $i++) 05406 { 05407 imagefilledarc($img, $cx, ($cy + $sz) - $z, $sx, $sy, $angle_sum[$i-1], $angle_sum[$i], $colord[$i], IMG_ARC_PIE); 05408 } 05409 05410 } 05411 05412 $originalLegendY = $legendY; 05413 05414 //Top of the pie. 05415 for ($i = 0; $i < $countdata; $i++) 05416 { 05417 $wrapped = false; 05418 05419 // If its the same angle don't try and draw anything otherwise you end up with the whole pie being this colour 05420 if ($angle_sum[$i - 1] != $angle_sum[$i]) 05421 { 05422 imagefilledarc($img, $cx, $cy, $sx, $sy, $angle_sum[$i-1], $angle_sum[$i], $colors[$i], IMG_ARC_PIE); 05423 } 05424 05425 imagefilledrectangle($img, 255, ($legendY + 1), 264, ($legendY + 9), $colors[$i]); 05426 // Legend 05427 if ($unit == 'seconds') 05428 { 05429 $data[$i] = format_seconds($data[$i]); 05430 } 05431 05432 $l = mb_substr(urldecode($legends[$i]), 0, 27, 'UTF-8'); 05433 if (strlen(urldecode($legends[$i])) > 27) $l .= $GLOBALS['strEllipsis']; 05434 05435 $ll = "{$l} ({$data[$i]})"; 05436 if (strlen($ll) > 27) 05437 { 05438 $ll = "{$l}\n({$data[$i]})"; 05439 $wrapped = true; 05440 } 05441 05442 if ($use_ttf) 05443 { 05444 imagettftext($img, 8, 0, 270, ($legendY + 9), $black, $CONFIG['font_file'], $ll); 05445 } 05446 else 05447 { 05448 imagestring($img,2, 270, ($legendY - 1), $ll, $black); 05449 } 05450 // imagearc($img,$cx,$cy,$sx,$sy,$angle_sum[$i1] ,$angle_sum[$i], $blue); 05451 $legendY += 15; 05452 if ($wrapped) $legendY += 15; 05453 } 05454 05455 imagerectangle($img, 250, $originalLegendY - 5, 470, $legendY, $black); 05456 break; 05457 05458 case 'line': 05459 $maxdata = 0; 05460 $colwidth=round($width/$countdata); 05461 $rowheight=round($height/10); 05462 foreach ($data AS $dataval) 05463 { 05464 if ($dataval > $maxdata) $maxdata = $dataval; 05465 } 05466 05467 imagerectangle($img, $width-1, $height-1, 0, 0, $black); 05468 for ($i = 1; $i < $countdata; $i++) 05469 { 05470 imageline($img, $i * $colwidth, 0, $i * $colwidth, $width, $grey); 05471 imageline($img, 2, $i * $rowheight, $width - 2, $i * $rowheight, $grey); 05472 } 05473 05474 for ($i = 0; $i < $countdata; $i++) 05475 { 05476 $dataheight = ($height-($data[$i] / $maxdata) * $height); 05477 $legendheight = $dataheight > ($height - 15) ? $height - 15 : $dataheight; 05478 $nextdataheight = ($height - ($data[$i + 1] / $maxdata) * $height); 05479 imageline($img, $i * $colwidth, $dataheight, ($i + 1) * $colwidth, $nextdataheight, $red); 05480 imagestring($img, 3, $i*$colwidth, $legendheight, mb_substr($legends[$i], 0, 6, 'UTF-8'), $darkblue); 05481 } 05482 imagestring($img,3, 10, 10, $title, $red); 05483 break; 05484 05485 case 'bar': 05486 $maxdata = 0; 05487 $colwidth = round($width / $countdata); 05488 $rowheight = round($height / 10); 05489 foreach ($data AS $dataval) 05490 { 05491 if ($dataval > $maxdata) $maxdata = $dataval; 05492 } 05493 05494 imagerectangle($img, $width-1, $height-1, 0, 0, $black); 05495 for ($i = 1; $i < $countdata; $i++) 05496 { 05497 imageline($img, $i * $colwidth, 0, $i * $colwidth, $width, $grey); 05498 imageline($img, 2, $i*$rowheight, $width - 2, $i * $rowheight, $grey); 05499 } 05500 05501 for ($i = 0; $i < $countdata; $i++) 05502 { 05503 $dataheight = ($height - ($data[$i] / $maxdata) * $height); 05504 $legendheight = $dataheight > ($height - 15) ? $height - 15 : $dataheight; 05505 imagefilledrectangle($img, $i * $colwidth, $dataheight, ($i + 1) * $colwidth, $height, $darkblue); 05506 imagefilledrectangle($img, ($i * $colwidth)+1, $dataheight + 1, (($i + 1) * $colwidth)-3, ($height-2), $midblue); 05507 imagestring($img, 3, ($i*$colwidth)+4, $legendheight, mb_substr($legends[$i], 0, 5,'UTF-8'), $darkblue); 05508 } 05509 imagestring($img,3, 10, 10, $title, $red); 05510 break; 05511 05512 05513 default: 05514 imagerectangle($img, $width-1, $height-1, 1, 1, $red); 05515 imagestring($img,3, 10, 10, "Invalid chart type", $red); 05516 } 05517 05518 // Return a PNG image 05519 return $img; 05520 } 05521 05522 05526 function display_drafts($type, $result) 05527 { 05528 global $iconset; 05529 global $id; 05530 global $CONFIG; 05531 05532 if ($type == 'update') 05533 { 05534 $page = "incident_update.php"; 05535 $editurlspecific = ''; 05536 } 05537 else if ($type == 'email') 05538 { 05539 $page = "incident_email.php"; 05540 $editurlspecific = "&step=2"; 05541 } 05542 05543 echo "<p align='center'>{$GLOBALS['strDraftChoose']}</p>"; 05544 05545 $html = ''; 05546 05547 while ($obj = mysql_fetch_object($result)) 05548 { 05549 $html .= "<div class='detailhead'>"; 05550 $html .= "<div class='detaildate'>".date($CONFIG['dateformat_datetime'], $obj->lastupdate); 05551 $html .= "</div>"; 05552 $html .= "<a href='{$page}?action=editdraft&draftid={$obj->id}&id={$id}{$editurlspecific}' class='info'>"; 05553 $html .= icon('edit', 16, $GLOBALS['strDraftEdit'])."</a>"; 05554 $html .= "<a href='{$page}?action=deletedraft&draftid={$obj->id}&id={$id}' class='info'>"; 05555 $html .= icon('delete', 16, $GLOBALS['strDraftDelete'])."</a>"; 05556 $html .= "</div>"; 05557 $html .= "<div class='detailentry'>"; 05558 $html .= nl2br($obj->content)."</div>"; 05559 } 05560 05561 return $html; 05562 } 05563 05564 05565 function ansort($x,$var,$cmp='strcasecmp') 05566 { 05567 // Numeric descending sort of multi array 05568 if ( is_string($var) ) $var = "'$var'"; 05569 05570 if ($cmp=='numeric') 05571 { 05572 uasort($x, create_function('$a,$b', 'return '.'( $a['.$var.'] < $b['.$var.']);')); 05573 } 05574 else 05575 { 05576 uasort($x, create_function('$a,$b', 'return '.$cmp.'( $a['.$var.'],$b['.$var.']);')); 05577 } 05578 return $x; 05579 } 05580 05581 05582 function array_remove_duplicate($array, $field) 05583 { 05584 foreach ($array as $sub) 05585 { 05586 $cmp[] = $sub[$field]; 05587 } 05588 05589 $unique = array_unique($cmp); 05590 foreach ($unique as $k => $rien) 05591 { 05592 $new[] = $array[$k]; 05593 } 05594 return $new; 05595 } 05596 05597 05598 function array_multi_search($needle, $haystack, $searchkey) 05599 { 05600 foreach ($haystack AS $thekey => $thevalue) 05601 { 05602 if ($thevalue[$searchkey] == $needle) return $thekey; 05603 } 05604 return FALSE; 05605 } 05606 05607 05608 // Implode assocative array 05609 function implode_assoc($glue1, $glue2, $array) 05610 { 05611 foreach ($array as $key => $val) 05612 { 05613 $array2[] = $key.$glue1.$val; 05614 } 05615 05616 return implode($glue2, $array2); 05617 } 05618 05619 05626 function time_dropdown($name, $time='') 05627 { 05628 if ($time) 05629 { 05630 $time = explode(':', $time); 05631 } 05632 05633 $html = "<select name='$name'>\n"; 05634 $html .= "<option></option>"; 05635 for ($hours = 0; $hours < 24; $hours++) 05636 { 05637 for ($mins = 0; $mins < 60; $mins+=15) 05638 { 05639 $hours = str_pad($hours, 2, "0", STR_PAD_LEFT); 05640 $mins = str_pad($mins, 2, "0", STR_PAD_RIGHT); 05641 05642 if ($time AND $time[0] == $hours AND $time[1] == $mins) 05643 { 05644 $html .= "<option selected='selected' value='$hours:$mins'>$hours:$mins</option>"; 05645 } 05646 else 05647 { 05648 if ($time AND $time[0] == $hours AND $time[1] < $mins AND $time[1] > ($mins - 15)) 05649 { 05650 $html .= "<option selected='selected' value='$time[0]:$time[1]'>$time[0]:$time[1]</option>\n"; 05651 } 05652 else 05653 { 05654 $html .= "<option value='$hours:$mins'>$hours:$mins</option>\n"; 05655 } 05656 } 05657 } 05658 } 05659 $html .= "</select>"; 05660 return $html; 05661 } 05662 05663 05669 function exact_seconds($seconds) 05670 { 05671 $days = floor($seconds / (24 * 60 * 60)); 05672 $seconds -= $days * (24 * 60 * 60); 05673 $hours = floor($seconds / (60 * 60)); 05674 $seconds -= $hours * (60 * 60); 05675 $minutes = floor($seconds / 60); 05676 $seconds -= $minutes * 60; 05677 05678 $string = ""; 05679 if ($days != 0) $string .= "{$days} {$GLOBALS['strDays']}, "; 05680 if ($hours != 0) $string .= "{$hours} {$GLOBALS['strHours']}, "; 05681 if ($minutes != 0) $string .= "{$minutes} {$GLOBALS['strMinutes']}, "; 05682 $string .= "{$seconds} {$GLOBALS['strSeconds']}"; 05683 05684 return $string; 05685 } 05686 05687 05693 function show_form_errors($formname) 05694 { 05695 if ($_SESSION['formerrors'][$formname]) 05696 { 05697 foreach ($_SESSION['formerrors'][$formname] as $error) 05698 { 05699 05700 if (substr(trim($error), 0, 1) != "<") 05701 { 05702 $html .= user_alert($error, E_USER_ERROR); 05703 } 05704 else 05705 { 05706 $html .= $error; 05707 } 05708 } 05709 } 05710 return $html; 05711 } 05712 05713 05719 function clear_form_errors($formname) 05720 { 05721 unset($_SESSION['formerrors'][$formname]); 05722 } 05723 05724 05730 function clear_form_data($formname) 05731 { 05732 unset($_SESSION['formdata'][$formname]); 05733 } 05734 05735 05742 function utc_time($time = '') 05743 { 05744 global $now; 05745 if ($time == '') 05746 { 05747 $time = $now; 05748 } 05749 $tz = strftime('%z', $time); 05750 $tzmins = (substr($tz, -4, 2) * 60) + substr($tz, -2, 2); 05751 $tzsecs = $tzmins * 60; // convert to seconds 05752 if (substr($tz, 0, 1) == '+') 05753 { 05754 $time -= $tzsecs; 05755 } 05756 else 05757 { 05758 $time += $tzsecs; 05759 } 05760 return $time; 05761 } 05762 05763 05776 function ldate($format, $date = '', $utc = FALSE) 05777 { 05778 global $now, $CONFIG; 05779 if ($date == '') $date = $GLOBALS['now']; 05780 if ($_SESSION['utcoffset'] != '') 05781 { 05782 if ($utc === FALSE) 05783 { 05784 // Adjust the date back to UTC 05785 $date = utc_time($date); 05786 } 05787 // Adjust the display time to the users local timezone 05788 $useroffsetsec = $_SESSION['utcoffset'] * 60; 05789 $date += $useroffsetsec; 05790 } 05791 05792 // Adjust the display time according to DST 05793 if ($utc === FALSE AND date('I', $date) > 0) 05794 { 05795 $date += $CONFIG['dst_adjust'] * 60; // Add an hour of DST 05796 } 05797 05798 $datestring = date($format, $date); 05799 05800 // Internationalise date endings (e.g. st) 05801 if (strpos($format, 'S') !== FALSE) 05802 { 05803 $endings = array('st', 'nd', 'rd', 'th'); 05804 $i18nendings = array($GLOBALS['strst'], $GLOBALS['strnd'], 05805 $GLOBALS['strrd'], $GLOBALS['strth']); 05806 $datestring = str_replace($endings, $i18nendings, $datestring); 05807 } 05808 05809 05810 // Internationalise full day names 05811 if (strpos($format, 'l') !== FALSE) 05812 { 05813 $days = array('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'); 05814 $i18ndays = array($GLOBALS['strMonday'], $GLOBALS['strTuesday'], $GLOBALS['strWednesday'], 05815 $GLOBALS['strThursday'], $GLOBALS['strFriday'], $GLOBALS['strSaturday'], $GLOBALS['strSunday']); 05816 $datestring = str_replace($days, $i18ndays, $datestring); 05817 } 05818 05819 // Internationalise abbreviated day names 05820 if (strpos($format, 'D') !== FALSE) 05821 { 05822 $days = array('Mon','Tue','Wed','Thu','Fri','Sat','Sun'); 05823 $i18ndays = array($GLOBALS['strMon'], $GLOBALS['strTue'], $GLOBALS['strWed'], 05824 $GLOBALS['strThu'], $GLOBALS['strFri'], $GLOBALS['strSat'], $GLOBALS['strSun']); 05825 $datestring = str_replace($days, $i18ndays, $datestring); 05826 } 05827 05828 // Internationalise full month names 05829 if (strpos($format, 'F') !== FALSE) 05830 { 05831 $months = array('January','February','March','April','May','June','July','August','September','October','November','December'); 05832 $i18nmonths = array($GLOBALS['strJanuary'], $GLOBALS['strFebruary'], $GLOBALS['strMarch'], 05833 $GLOBALS['strApril'], $GLOBALS['strMay'], $GLOBALS['strJune'], $GLOBALS['strJuly'], 05834 $GLOBALS['strAugust'], $GLOBALS['strSeptember'], $GLOBALS['strOctober'], 05835 $GLOBALS['strNovember'], $GLOBALS['strDecember']); 05836 $datestring = str_replace($months, $i18nmonths, $datestring); 05837 } 05838 05839 // Internationalise short month names 05840 if (strpos($format, 'M') !== FALSE) 05841 { 05842 $months = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); 05843 $i18nmonths = array($GLOBALS['strJanAbbr'], $GLOBALS['strFebAbbr'], $GLOBALS['strMarAbbr'], 05844 $GLOBALS['strAprAbbr'], $GLOBALS['strMayAbbr'], $GLOBALS['strJunAbbr'], $GLOBALS['strJulAbbr'], 05845 $GLOBALS['strAugAbbr'], $GLOBALS['strSepAbbr'], $GLOBALS['strOctAbbr'], 05846 $GLOBALS['strNovAbbr'], $GLOBALS['strDecAbbr']); 05847 $datestring = str_replace($months, $i18nmonths, $datestring); 05848 } 05849 05850 // Internationalise am/pm 05851 if (strpos($format, 'a') !== FALSE) 05852 { 05853 $months = array('am','pm'); 05854 $i18nmonths = array($GLOBALS['strAM'], $GLOBALS['strPM']); 05855 $datestring = str_replace($months, $i18nmonths, $datestring); 05856 } 05857 05858 return $datestring; 05859 } 05860 05861 05868 function open_activities_for_incident($incientid) 05869 { 05870 global $dbLinks, $dbLinkTypes, $dbTasks; 05871 // Running Activities 05872 05873 $sql = "SELECT DISTINCT origcolref, linkcolref "; 05874 $sql .= "FROM `{$dbLinks}` AS l, `{$dbLinkTypes}` AS lt "; 05875 $sql .= "WHERE l.linktype=4 "; 05876 $sql .= "AND linkcolref={$incientid} "; 05877 $sql .= "AND direction='left'"; 05878 $result = mysql_query($sql); 05879 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05880 05881 if (mysql_num_rows($result) > 0) 05882 { 05883 //get list of tasks 05884 $sql = "SELECT * FROM `{$dbTasks}` WHERE enddate IS NULL "; 05885 while ($tasks = mysql_fetch_object($result)) 05886 { 05887 if (empty($orSQL)) $orSQL = "("; 05888 else $orSQL .= " OR "; 05889 $orSQL .= "id={$tasks->origcolref} "; 05890 } 05891 05892 if (!empty($orSQL)) 05893 { 05894 $sql .= "AND {$orSQL})"; 05895 } 05896 $result = mysql_query($sql); 05897 05898 // $num = mysql_num_rows($result); 05899 while ($obj = mysql_fetch_object($result)) 05900 { 05901 $num[] = $obj->id; 05902 } 05903 } 05904 else 05905 { 05906 $num = null; 05907 } 05908 05909 return $num; 05910 } 05911 05912 05919 function open_activities_for_site($siteid) 05920 { 05921 global $dbIncidents, $dbContacts; 05922 05923 $openactivites = 0; 05924 05925 if (!empty($siteid) AND $siteid != 0) 05926 { 05927 $sql = "SELECT i.id FROM `{$dbIncidents}` AS i, `{$dbContacts}` AS c "; 05928 $sql .= "WHERE i.contact = c.id AND "; 05929 $sql .= "c.siteid = {$siteid} AND "; 05930 $sql .= "(i.status != 2 AND i.status != 7)"; 05931 05932 $result = mysql_query($sql); 05933 05934 while ($obj = mysql_fetch_object($result)) 05935 { 05936 $openactivites += count(open_activities_for_incident($obj->id)); 05937 } 05938 } 05939 05940 return $openactivites; 05941 } 05942 05943 05950 function schedule_actions_due() 05951 { 05952 global $now; 05953 global $dbScheduler; 05954 05955 $actions = FALSE; 05956 $sql = "SELECT * FROM `{$dbScheduler}` WHERE `status` = 'enabled' AND type = 'interval' "; 05957 $sql .= "AND UNIX_TIMESTAMP(start) <= $now AND (UNIX_TIMESTAMP(end) >= $now OR UNIX_TIMESTAMP(end) = 0) "; 05958 $sql .= "AND IF(UNIX_TIMESTAMP(lastran) > 0, UNIX_TIMESTAMP(lastran) + `interval`, UNIX_TIMESTAMP(NOW())) <= $now "; 05959 $sql .= "AND IF(UNIX_TIMESTAMP(laststarted) > 0, UNIX_TIMESTAMP(lastran), -1) <= IF(UNIX_TIMESTAMP(laststarted) > 0, UNIX_TIMESTAMP(laststarted), 0)"; 05960 $result = mysql_query($sql); 05961 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05962 if (mysql_num_rows($result) > 0) 05963 { 05964 while ($action = mysql_fetch_object($result)) 05965 { 05966 $actions[$action->action] = $actions->params; 05967 } 05968 } 05969 05970 // Month 05971 $sql = "SELECT * FROM `{$dbScheduler}` WHERE `status` = 'enabled' AND type = 'date' "; 05972 $sql .= "AND UNIX_TIMESTAMP(start) <= $now AND (UNIX_TIMESTAMP(end) >= $now OR UNIX_TIMESTAMP(end) = 0) "; 05973 $sql .= "AND ((date_type = 'month' AND (DAYOFMONTH(CURDATE()) > date_offset OR (DAYOFMONTH(CURDATE()) = date_offset AND CURTIME() >= date_time)) "; 05974 $sql .= "AND DATE_FORMAT(CURDATE(), '%Y-%m') != DATE_FORMAT(lastran, '%Y-%m') ) ) "; // not run this month 05975 $sql .= "AND IF(UNIX_TIMESTAMP(lastran) > 0, UNIX_TIMESTAMP(lastran) + `interval`, UNIX_TIMESTAMP(NOW())) <= $now "; 05976 $sql .= "AND IF(UNIX_TIMESTAMP(laststarted) > 0, UNIX_TIMESTAMP(lastran), -1) <= IF(UNIX_TIMESTAMP(laststarted) > 0, UNIX_TIMESTAMP(laststarted), 0)"; 05977 $result = mysql_query($sql); 05978 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05979 if (mysql_num_rows($result) > 0) 05980 { 05981 while ($action = mysql_fetch_object($result)) 05982 { 05983 $actions[$action->action] = $actions->params; 05984 } 05985 } 05986 05987 // Year TODO CHECK 05988 $sql = "SELECT * FROM `{$dbScheduler}` WHERE `status` = 'enabled' "; 05989 $sql .= "AND type = 'date' AND UNIX_TIMESTAMP(start) <= $now "; 05990 $sql .= "AND (UNIX_TIMESTAMP(end) >= $now OR UNIX_TIMESTAMP(end) = 0) "; 05991 $sql .= "AND ((date_type = 'year' AND (DAYOFYEAR(CURDATE()) > date_offset "; 05992 $sql .= "OR (DAYOFYEAR(CURDATE()) = date_offset AND CURTIME() >= date_time)) "; 05993 $sql .= "AND DATE_FORMAT(CURDATE(), '%Y') != DATE_FORMAT(lastran, '%Y') ) ) "; // not run this year 05994 $sql .= "AND IF(UNIX_TIMESTAMP(lastran) > 0, UNIX_TIMESTAMP(lastran) + `interval`, UNIX_TIMESTAMP(NOW())) <= $now "; 05995 $sql .= "AND IF(UNIX_TIMESTAMP(laststarted) > 0, UNIX_TIMESTAMP(lastran), -1) <= IF(UNIX_TIMESTAMP(laststarted) > 0, UNIX_TIMESTAMP(laststarted), 0)"; 05996 $result = mysql_query($sql); 05997 if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING); 05998 if (mysql_num_rows($result) > 0) 05999 { 06000 while ($action = mysql_fetch_object($result)) 06001 { 06002 $actions[$action->action] = $actions->params; 06003 } 06004 } 06005 06006 if (is_array($actions)) debug_log('Scheduler actions due: '.implode(', ',array_keys($actions))); 06007 06008 return $actions; 06009 } 06010 06011 06018 function schedule_action_started($action) 06019 { 06020 global $now; 06021 06022 $nowdate = date('Y-m-d H:i:s', $now); 06023 06024 $sql = "UPDATE `{$GLOBALS['dbScheduler']}` SET laststarted = '$nowdate' "; 06025 $sql .= "WHERE action = '{$action}'"; 06026 mysql_query($sql); 06027 if (mysql_error()) 06028 { 06029 trigger_error(mysql_error(),E_USER_ERROR); 06030 return FALSE; 06031 } 06032 if (mysql_affected_rows() > 0) return TRUE; 06033 else return FALSE; 06034 } 06035 06036 06043 function schedule_action_done($doneaction, $success = TRUE) 06044 { 06045 global $now; 06046 global $dbScheduler; 06047 06048 if ($success != TRUE) 06049 { 06050 trigger('TRIGGER_SCHEDULER_TASK_FAILED', array('schedulertask' => $doneaction)); 06051 } 06052 06053 $nowdate = date('Y-m-d H:i:s', $now); 06054 $sql = "UPDATE `{$dbScheduler}` SET lastran = '$nowdate', laststarted = NULL"; 06055 if ($success == FALSE) $sql .= ", success=0, status='disabled' "; 06056 else $sql .= ", success=1 "; 06057 $sql .= "WHERE action = '{$doneaction}'"; 06058 mysql_query($sql); 06059 if (mysql_error()) 06060 { 06061 trigger_error(mysql_error(),E_USER_ERROR); 06062 return FALSE; 06063 } 06064 if (mysql_affected_rows() > 0) return TRUE; 06065 else return FALSE; 06066 } 06067 06068 06075 function supported_contacts($maintid) 06076 { 06077 global $dbSupportContacts, $dbContacts; 06078 $sql = "SELECT c.forenames, c.surname, sc.contactid AS contactid "; 06079 $sql .= "FROM `{$dbSupportContacts}` AS sc, `{$dbContacts}` AS c "; 06080 $sql .= "WHERE sc.contactid=c.id AND sc.maintenanceid='{$maintid}' "; 06081 $sql .= "ORDER BY c.surname, c.forenames "; 06082 $result = mysql_query($sql); 06083 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06084 if (!empty($result)) 06085 { 06086 while ($row = mysql_fetch_object($result)) 06087 { 06088 $returnarray[] = $row->contactid; 06089 } 06090 return $returnarray; 06091 } 06092 else return NULL; 06093 } 06094 06095 06103 function admin_contact_contracts($contactid, $siteid) 06104 { 06105 $sql = "SELECT DISTINCT m.id "; 06106 $sql .= "FROM `{$GLOBALS['dbMaintenance']}` AS m "; 06107 $sql .= "WHERE m.admincontact={$contactid} "; 06108 $sql .= "AND m.site={$siteid} "; 06109 06110 $result = mysql_query($sql); 06111 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06112 if ($result) 06113 { 06114 while ($row = mysql_fetch_object($result)) 06115 { 06116 $contractsarray[] = $row->id; 06117 } 06118 } 06119 06120 return $contractsarray; 06121 } 06122 06123 06130 function contact_contracts($contactid, $siteid, $checkvisible = TRUE) 06131 { 06132 $sql = "SELECT DISTINCT m.id AS id 06133 FROM `{$GLOBALS['dbMaintenance']}` AS m, 06134 `{$GLOBALS['dbContacts']}` AS c, 06135 `{$GLOBALS['dbSupportContacts']}` AS sc 06136 WHERE m.site={$siteid} 06137 AND sc.maintenanceid=m.id 06138 AND sc.contactid=c.id "; 06139 if ($checkvisible) 06140 { 06141 $sql .= "AND m.var_incident_visible_contacts = 'yes'"; 06142 } 06143 06144 if ($result = mysql_query($sql)) 06145 { 06146 while ($row = mysql_fetch_object($result)) 06147 { 06148 $contractsarray[] = $row->id; 06149 } 06150 } 06151 return $contractsarray; 06152 } 06153 06154 06161 function all_contact_contracts($contactid, $siteid) 06162 { 06163 $sql = "SELECT DISTINCT m.id AS id 06164 FROM `{$GLOBALS['dbMaintenance']}` AS m 06165 WHERE m.site={$siteid} 06166 AND m.var_incident_visible_all = 'yes'"; 06167 06168 if ($result = mysql_query($sql)) 06169 { 06170 while ($row = mysql_fetch_object($result)) 06171 { 06172 $contractsarray[] = $row->id; 06173 } 06174 } 06175 return $contractsarray; 06176 } 06177 06178 06185 function valid_username($username) 06186 { 06187 $username = clean_dbstring($username); 06188 $valid = TRUE; 06189 06190 if (!empty($username)) 06191 { 06192 $tables = array('dbUsers', 'dbContacts'); 06193 06194 foreach ($tables AS $table) 06195 { 06196 $sql = "SELECT username FROM `{$GLOBALS[$table]}` WHERE username='{$username}'"; 06197 if ($result = mysql_query($sql) AND mysql_num_rows($result) != 0) 06198 { 06199 $valid = FALSE; 06200 } 06201 } 06202 } 06203 else 06204 { 06205 $valid = FALSE; 06206 } 06207 06208 return $valid; 06209 } 06210 06211 06217 function session_regenerate() 06218 { 06219 if (function_exists('session_regenerate_id')) 06220 { 06221 if (!version_compare(phpversion(),"5.1.0",">=")) session_regenerate_id(FALSE); 06222 else session_regenerate_id(); 06223 } 06224 } 06225 06226 06232 function contract_software() 06233 { 06234 $contract = intval($contract); 06235 $sql = "SELECT s.id 06236 FROM `{$GLOBALS['dbMaintenance']}` AS m, 06237 `{$GLOBALS['dbProducts']}` AS p, 06238 `{$GLOBALS['dbSoftwareProducts']}` AS sp, 06239 `{$GLOBALS['dbSoftware']}` AS s 06240 WHERE m.product=p.id 06241 AND p.id=sp.productid 06242 AND sp.softwareid=s.id "; 06243 $sql .= "AND (1=0 "; 06244 if (is_array($_SESSION['contracts'])) 06245 { 06246 foreach ($_SESSION['contracts'] AS $contract) 06247 { 06248 $sql .= "OR m.id={$contract} "; 06249 } 06250 } 06251 $sql .= ")"; 06252 06253 if ($result = mysql_query($sql)) 06254 { 06255 while ($row = mysql_fetch_object($result)) 06256 { 06257 $softwarearray[] = $row->id; 06258 } 06259 } 06260 06261 return $softwarearray; 06262 } 06263 06264 06272 function help_link($context) 06273 { 06274 global $strHelpChar; 06275 $html = "<span class='helplink'>[<a href='#' tabindex='-1' onmouseover=\""; 06276 $html .= "contexthelp(this, '$context'"; 06277 if ($_SESSION['portalauth'] == TRUE) $html .= ",'portal'"; 06278 else $html .= ",'standard'"; 06279 $html .= ");return false;\">{$strHelpChar}<span>"; 06280 $html .= "</span></a>]</span>"; 06281 06282 return $html; 06283 } 06284 06285 06293 function get_file_upload_error_message($errorcode, $name) 06294 { 06295 $str = "<div class='detailinfo'>\n"; 06296 06297 $str .= "An error occurred while uploading <strong>{$_FILES['attachment']['name']}</strong>"; 06298 06299 $str .= "<p class='error'>"; 06300 switch ($errorcode) 06301 { 06302 case UPLOAD_ERR_INI_SIZE: $str .= "The file exceded the maximum size set in PHP"; break; 06303 case UPLOAD_ERR_FORM_SIZE: $str .= "The uploaded file was too large"; break; 06304 case UPLOAD_ERR_PARTIAL: $str .= "The file was only partially uploaded"; break; 06305 case UPLOAD_ERR_NO_FILE: $str .= "No file was uploaded"; break; 06306 case UPLOAD_ERR_NO_TMP_DIR: $str .= "Temporary folder is missing"; break; 06307 default: $str .= "An unknown file upload error occurred"; break; 06308 } 06309 $str .= "</p>"; 06310 $str .= "</div>"; 06311 06312 return $str; 06313 } 06314 06315 06323 function readable_file_size($filesize) 06324 { 06325 global $strBytes, $strKBytes, $strMBytes, $strGBytes, $strTBytes; 06326 $j = 0; 06327 06328 $ext = array($strBytes, $strKBytes, $strMBytes, $strGBytes, $strTBytes); 06329 while ($filesize >= pow(1024,$j)) 06330 { 06331 ++$j; 06332 } 06333 $filemax = round($filesize / pow(1024,$j-1) * 100) / 100 . ' ' . $ext[$j-1]; 06334 06335 return $filemax; 06336 } 06337 06338 06347 function contract_details($id, $mode='internal') 06348 { 06349 global $CONFIG, $iconset, $dbMaintenance, $dbSites, $dbResellers, $dbLicenceTypes, $now; 06350 06351 $sql = "SELECT m.*, m.notes AS maintnotes, s.name AS sitename, "; 06352 $sql .= "r.name AS resellername, lt.name AS licensetypename "; 06353 $sql .= "FROM `{$dbMaintenance}` AS m, `{$dbSites}` AS s, "; 06354 $sql .= "`{$dbResellers}` AS r, `{$dbLicenceTypes}` AS lt "; 06355 $sql .= "WHERE s.id = m.site "; 06356 $sql .= "AND m.id='{$id}' "; 06357 $sql .= "AND m.reseller = r.id "; 06358 $sql .= "AND (m.licence_type IS NULL OR m.licence_type = lt.id) "; 06359 if ($mode == 'external') $sql .= "AND m.site = '{$_SESSION['siteid']}'"; 06360 06361 $maintresult = mysql_query($sql); 06362 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06363 06364 $maint = mysql_fetch_object($maintresult); 06365 06366 $html = "<table align='center' class='vertical'>"; 06367 $html .= "<tr><th>{$GLOBALS['strContract']} {$GLOBALS['strID']}:</th>"; 06368 $html .= "<td><h3>".icon('contract', 32)." "; 06369 $html .= "{$maint->id}</h3></td></tr>"; 06370 $html .= "<tr><th>{$GLOBALS['strStatus']}:</th><td>"; 06371 if ($maint->term == 'yes') 06372 { 06373 $html .= "<strong>{$GLOBALS['strTerminated']}</strong>"; 06374 } 06375 else 06376 { 06377 $html .= $GLOBALS['strActive']; 06378 } 06379 06380 if ($maint->expirydate < $now AND $maint->expirydate != '-1') 06381 { 06382 $html .= "<span class='expired'>, {$GLOBALS['strExpired']}</span>"; 06383 } 06384 $html .= "</td></tr>\n"; 06385 $html .= "<tr><th>{$GLOBALS['strSite']}:</th>"; 06386 06387 if ($mode == 'internal') 06388 { 06389 $html .= "<td><a href=\"site_details.php?id=".$maint->site."\">".$maint->sitename."</a></td></tr>"; 06390 } 06391 else 06392 { 06393 $html .= "<td><a href=\"sitedetails.php\">".$maint->sitename."</a></td></tr>"; 06394 } 06395 $html .= "<tr><th>{$GLOBALS['strAdminContact']}:</th>"; 06396 06397 if ($mode == 'internal') 06398 { 06399 $html .= "<td><a href=\"contact_details.php?id="; 06400 $html .= "{$maint->admincontact}\">"; 06401 $html .= contact_realname($maint->admincontact)."</a></td></tr>"; 06402 } 06403 else 06404 { 06405 $html .= "<td><a href='contactdetails.php?id={$maint->admincontact}'>"; 06406 $html .= contact_realname($maint->admincontact)."</a></td></tr>"; 06407 } 06408 06409 $html .= "<tr><th>{$GLOBALS['strReseller']}:</th><td>"; 06410 06411 if (empty($maint->resellername)) 06412 { 06413 $html .= $GLOBALS['strNoReseller']; 06414 } 06415 else 06416 { 06417 $html .= $maint->resellername; 06418 } 06419 $html .= "</td></tr>"; 06420 $html .= "<tr><th>{$GLOBALS['strProduct']}:</th><td>".product_name($maint->product)."</td></tr>"; 06421 $html .= "<tr><th>{$GLOBALS['strIncidents']}:</th>"; 06422 $html .= "<td>"; 06423 $incidents_remaining = $maint->incident_quantity - $maint->incidents_used; 06424 06425 if ($maint->incident_quantity == 0) 06426 { 06427 $quantity = $GLOBALS['strUnlimited']; 06428 } 06429 else 06430 { 06431 $quantity = $maint->incident_quantity; 06432 } 06433 06434 $html .= sprintf($GLOBALS['strUsedNofN'], $maint->incidents_used, $quantity); 06435 if ($maint->incidents_used >= $maint->incident_quantity AND 06436 $maint->incident_quantity != 0) 06437 { 06438 $html .= " ({$GLOBALS['strZeroRemaining']})"; 06439 } 06440 06441 $html .= "</td></tr>"; 06442 if ($maint->licence_quantity != '0') 06443 { 06444 $html .= "<tr><th>{$GLOBALS['strLicense']}:</th>"; 06445 $html .= "<td>{$maint->licence_quantity} {$maint->licensetypename}</td></tr>\n"; 06446 } 06447 06448 $html .= "<tr><th>{$GLOBALS['strServiceLevel']}:</th><td>".servicelevel_name($maint->servicelevelid)."</td></tr>"; 06449 $html .= "<tr><th>{$GLOBALS['strExpiryDate']}:</th><td>"; 06450 if ($maint->expirydate == '-1') 06451 { 06452 $html .= "{$GLOBALS['strUnlimited']}"; 06453 } 06454 else 06455 { 06456 $html .= ldate($CONFIG['dateformat_datetime'], $maint->expirydate); 06457 } 06458 06459 $html .= "</td></tr>"; 06460 06461 if ($mode == 'internal') 06462 { 06463 $timed = db_read_column('timed', $GLOBALS['dbServiceLevels'], $maint->servicelevelid); 06464 if ($timed == 'yes') $timed = TRUE; 06465 else $timed = FALSE; 06466 $html .= "<tr><th>{$GLOBALS['strService']}</th><td>"; 06467 $html .= contract_service_table($id, $timed); 06468 $html .= "</td></tr>\n"; 06469 06470 if ($timed) 06471 { 06472 $html .= "<tr><th>{$GLOBALS['strBalance']}</th><td>{$CONFIG['currency_symbol']}".number_format(get_contract_balance($id, TRUE, TRUE), 2); 06473 $multiplier = get_billable_multiplier(strtolower(date('D', $now)), date('G', $now)); 06474 $html .= " (≅".contract_unit_balance($id, TRUE, TRUE)." units)"; 06475 $html .= "</td></tr>"; 06476 } 06477 } 06478 06479 if ($maint->maintnotes != '' AND $mode == 'internal') 06480 { 06481 $html .= "<tr><th>{$GLOBALS['strNotes']}:</th><td>{$maint->maintnotes}</td></tr>"; 06482 } 06483 $html .= "</table>"; 06484 06485 if ($mode == 'internal') 06486 { 06487 $html .= "<p align='center'>"; 06488 $html .= "<a href=\"contract_edit.php?action=edit&maintid=$id\">{$GLOBALS['strEditContract']}</a>"; 06489 if ($maint->term != 'yes') 06490 { 06491 $html .= " | <a href='contract_add_service.php?contractid={$id}'>{$GLOBALS['strAddService']}</a></p>"; 06492 } 06493 } 06494 $html .= "<h3>{$GLOBALS['strContacts']}</h3>"; 06495 06496 if (mysql_num_rows($maintresult) > 0) 06497 { 06498 if ($maint->allcontactssupported == 'yes') 06499 { 06500 $html .= "<p class='info'>{$GLOBALS['strAllSiteContactsSupported']}</p>"; 06501 } 06502 else 06503 { 06504 $allowedcontacts = $maint->supportedcontacts; 06505 06506 $supportedcontacts = supported_contacts($id); 06507 $numberofcontacts = 0; 06508 06509 $numberofcontacts = sizeof($supportedcontacts); 06510 if ($allowedcontacts == 0) 06511 { 06512 $allowedcontacts = $GLOBALS['strUnlimited']; 06513 } 06514 $html .= "<table align='center'>"; 06515 $supportcount = 1; 06516 06517 if ($numberofcontacts > 0) 06518 { 06519 foreach ($supportedcontacts AS $contact) 06520 { 06521 $html .= "<tr><th>{$GLOBALS['strContact']} #{$supportcount}:</th>"; 06522 $html .= "<td>".icon('contact', 16)." "; 06523 if ($mode == 'internal') 06524 { 06525 $html .= "<a href=\"contact_details.php?"; 06526 } 06527 else 06528 { 06529 $html .= "<a href=\"contactdetails.php?"; 06530 } 06531 $html .= "id={$contact}\">".contact_realname($contact)."</a>, "; 06532 $html .= contact_site($contact). "</td>"; 06533 06534 if ($mode == 'internal') 06535 { 06536 $html .= "<td><a href=\"contract_delete_contact.php?contactid=".$contact."&maintid=$id&context=maintenance\">{$GLOBALS['strRemove']}</a></td></tr>\n"; 06537 } 06538 else 06539 { 06540 $html .= "<td><a href=\"{$_SERVER['PHP_SELF']}?id={$id}&contactid=".$contact."&action=remove\">{$GLOBALS['strRemove']}</a></td></tr>\n"; 06541 } 06542 $supportcount++; 06543 } 06544 $html .= "</table>"; 06545 } 06546 else 06547 { 06548 $html .= "<p class='info'>{$GLOBALS['strNoRecords']}<p>"; 06549 } 06550 } 06551 06552 if ($maint->allcontactssupported != 'yes') 06553 { 06554 $html .= "<p align='center'>"; 06555 $html .= sprintf($GLOBALS['strUsedNofN'], 06556 "<strong>".$numberofcontacts."</strong>", 06557 "<strong>".$allowedcontacts."</strong>"); 06558 $html .= "</p>"; 06559 06560 if ($numberofcontacts < $allowedcontacts OR $allowedcontacts == 0 AND $mode == 'internal') 06561 { 06562 $html .= "<p align='center'><a href='contract_add_contact.php?maintid={$id}&siteid={$maint->site}&context=maintenance'>"; 06563 $html .= "{$GLOBALS['strAddContact']}</a></p>"; 06564 } 06565 else 06566 { 06567 $html .= "<h3>{$GLOBALS['strAddContact']}</h3>"; 06568 $html .= "<form action='{$_SERVER['PHP_SELF']}?id={$id}&action="; 06569 $html .= "add' method='post' >"; 06570 $html .= "<p align='center'>{$GLOBLAS['strAddNewSupportedContact']} "; 06571 $html .= contact_site_drop_down('contactid', 06572 'contactid', 06573 maintenance_siteid($id), 06574 supported_contacts($id)); 06575 $html .= help_link('NewSupportedContact'); 06576 $html .= " <input type='submit' value='{$GLOBALS['strAdd']}' /></p></form>"; 06577 } 06578 if ($mode == 'external') 06579 { 06580 $html .= "<p align='center'><a href='addcontact.php'>"; 06581 $html .= "{$GLOBALS['strAddNewSiteContact']}</a></p>"; 06582 } 06583 } 06584 06585 $html .= "<br />"; 06586 $html .= "<h3>{$GLOBALS['strSkillsSupportedUnderContract']}:</h3>"; 06587 // supported software 06588 $sql = "SELECT * FROM `{$GLOBALS[dbSoftwareProducts]}` AS sp, `{$GLOBALS[dbSoftware]}` AS s "; 06589 $sql .= "WHERE sp.softwareid = s.id AND productid='{$maint->product}' "; 06590 $result = mysql_query($sql); 06591 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06592 06593 if (mysql_num_rows($result)>0) 06594 { 06595 $html .="<table align='center'>"; 06596 while ($software = mysql_fetch_object($result)) 06597 { 06598 $software->lifetime_end = mysql2date($software->lifetime_end); 06599 $html .= "<tr><td> ".icon('skill', 16)." "; 06600 if ($software->lifetime_end > 0 AND $software->lifetime_end < $now) 06601 { 06602 $html .= "<span class='deleted'>"; 06603 } 06604 $html .= $software->name; 06605 if ($software->lifetime_end > 0 AND $software->lifetime_end < $now) 06606 { 06607 $html .= "</span>"; 06608 } 06609 $html .= "</td></tr>\n"; 06610 } 06611 $html .= "</table>\n"; 06612 } 06613 else 06614 { 06615 $html .= "<p align='center'>{$GLOBALS['strNone']} / {$GLOBALS['strUnknown']}<p>"; 06616 } 06617 } 06618 else 06619 { 06620 $html = "<p align='center'>{$GLOBALS['strNothingToDisplay']}</p>"; 06621 } 06622 06623 return $html; 06624 } 06625 06626 06635 function upload_file($file, $incidentid, $updateid, $type='public') 06636 { 06637 global $CONFIG, $now; 06638 $att_max_filesize = return_bytes($CONFIG['upload_max_filesize']); 06639 $incident_attachment_fspath = $CONFIG['attachment_fspath'] . $id; //FIXME $id never declared 06640 if ($file['name'] != '') 06641 { 06642 // try to figure out what delimeter is being used (for windows or unix)... 06643 //.... // $delim = (strstr($filesarray[$c],"/")) ? "/" : "\\"; 06644 $delim = (strstr($file['tmp_name'],"/")) ? "/" : "\\"; 06645 06646 // make incident attachment dir if it doesn't exist 06647 $umask = umask(0000); 06648 if (!file_exists($CONFIG['attachment_fspath'] . "$id")) 06649 { 06650 $mk = @mkdir($CONFIG['attachment_fspath'] ."$id", 0770); 06651 if (!$mk) trigger_error("Failed creating incident attachment directory: {$incident_attachment_fspath }{$id}", E_USER_WARNING); 06652 } 06653 $mk = @mkdir($CONFIG['attachment_fspath'] .$id . "{$delim}{$now}", 0770); 06654 if (!$mk) trigger_error("Failed creating incident attachment (timestamp) directory: {$incident_attachment_fspath} {$id} {$delim}{$now}", E_USER_WARNING); 06655 umask($umask); 06656 $returnpath = $id.$delim.$now.$delim.$file['name']; 06657 $filepath = $incident_attachment_fspath.$delim.$now.$delim; 06658 $newfilename = $filepath.$file['name']; 06659 06660 // Move the uploaded file from the temp directory into the incidents attachment dir 06661 $mv = move_uploaded_file($file['tmp_name'], $newfilename); 06662 if (!$mv) trigger_error('!Error: Problem moving attachment from temp directory to: '.$newfilename, E_USER_WARNING); 06663 06664 // Check file size before attaching 06665 if ($file['size'] > $att_max_filesize) 06666 { 06667 trigger_error("User Error: Attachment too large or file upload error - size: {$file['size']}", E_USER_WARNING); 06668 // throwing an error isn't the nicest thing to do for the user but there seems to be no guaranteed 06669 // way of checking file sizes at the client end before the attachment is uploaded. - INL 06670 return FALSE; 06671 } 06672 else 06673 { 06674 if (!empty($sit[2])) 06675 { 06676 $usertype = 'user'; 06677 $userid = $sit[2]; 06678 } 06679 else 06680 { 06681 $usertype = 'contact'; 06682 $userid = $_SESSION['contactid']; 06683 } 06684 $sql = "INSERT INFO `{$GLOBALS['dbFiles']}` 06685 (category, filename, size, userid, usertype, path, filedate, refid) 06686 VALUES 06687 ('{$type}', '{$file['name']}', '{$file['size']}', '{$userid}', '{$usertype}', '{$filepath}', '{$now}', '{$id}')"; 06688 $result = mysql_query($sql); 06689 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 06690 06691 return $returnpath; 06692 } 06693 } 06694 } 06695 06696 06707 function group_user_selector($title, $level="engineer", $groupid, $type='radio') 06708 { 06709 global $dbUsers, $dbGroups; 06710 $str .= "<tr><th>{$title}</th>"; 06711 $str .= "<td align='center'>"; 06712 06713 $sql = "SELECT DISTINCT(g.name), g.id FROM `{$dbUsers}` AS u, `{$dbGroups}` AS g "; 06714 $sql .= "WHERE u.status > 0 AND u.groupid = g.id ORDER BY g.name"; 06715 $result = mysql_query($sql); 06716 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06717 06718 while ($row = mysql_fetch_object($result)) 06719 { 06720 if ($type == 'radio') 06721 { 06722 $str .= "<input type='radio' name='group' id='{$row->name}' onclick='groupMemberSelect(\"{$row->name}\", \"TRUE\")' "; 06723 } 06724 elseif ($type == 'checkbox') 06725 { 06726 $str .= "<input type='checkbox' name='{$row->name}' id='{$row->name}' onclick='groupMemberSelect(\"{$row->name}\", \"FALSE\")' "; 06727 } 06728 06729 if ($groupid == $row->id) 06730 { 06731 $str .= " checked='checked' "; 06732 $groupname = $row->name; 06733 } 06734 06735 $str .= "/>{$row->name} \n"; 06736 } 06737 06738 $str .="<br />"; 06739 06740 06741 $sql = "SELECT u.id, u.realname, g.name FROM `{$dbUsers}` AS u, `{$dbGroups}` AS g "; 06742 $sql .= "WHERE u.status > 0 AND u.groupid = g.id ORDER BY username"; 06743 $result = mysql_query($sql); 06744 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 06745 06746 if ($level == "management") 06747 { 06748 $str .= "<select name='users[]' id='include' multiple='multiple' size='20'>"; 06749 } 06750 elseif ($level == "engineer") 06751 { 06752 $str .= "<select name='users[]' id='include' multiple='multiple' size='20' style='display:none'>"; 06753 } 06754 06755 while ($row = mysql_fetch_object($result)) 06756 { 06757 $str .= "<option value='{$row->id}'>{$row->realname} ({$row->name})</option>\n"; 06758 } 06759 $str .= "</select>"; 06760 $str .= "<br />"; 06761 if ($level == "engineer") 06762 { 06763 $visibility = " style='display:none'"; 06764 } 06765 06766 $str .= "<input type='button' id='selectall' onclick='doSelect(true, \"include\")' value='Select All' {$visibility} />"; 06767 $str .= "<input type='button' id='clearselection' onclick='doSelect(false, \"include\")' value='Clear Selection' {$visibility} />"; 06768 06769 $str .= "</td>"; 06770 $str .= "</tr>\n"; 06771 06772 // FIXME make this XHTML valid 06773 $str .= "<script type='text/javascript'>\n//<![CDATA[\ngroupMemberSelect(\"{$groupname}\", \"TRUE\");\n//]]>\n</script>"; 06774 06775 return $str; 06776 } 06777 06778 06787 function show_next_action($formid) 06788 { 06789 global $now, $strAM, $strPM; 06790 $html = "{$GLOBALS['strPlaceIncidentInWaitingQueue']}<br />"; 06791 06792 $oldtimeofnextaction = incident_timeofnextaction($id); //FIXME $id never populated 06793 if ($oldtimeofnextaction < 1) 06794 { 06795 $oldtimeofnextaction = $now; 06796 } 06797 $wait_time = ($oldtimeofnextaction - $now); 06798 06799 $na_days = floor($wait_time / 86400); 06800 $na_remainder = $wait_time % 86400; 06801 $na_hours = floor($na_remainder / 3600); 06802 $na_remainder = $wait_time % 3600; 06803 $na_minutes = floor($na_remainder / 60); 06804 if ($na_days < 0) $na_days = 0; 06805 if ($na_hours < 0) $na_hours = 0; 06806 if ($na_minutes < 0) $na_minutes = 0; 06807 06808 $html .= "<label>"; 06809 $html .= "<input checked='checked' type='radio' name='timetonextaction' "; 06810 $html .= "id='ttna_none' onchange=\"update_ttna();\" onclick=\"this.blur();\" "; 06811 // $html .= "onclick=\"$('timetonextaction_days').value = ''; window.document.updateform."; 06812 // $html .= "timetonextaction_hours.value = ''; window.document.updateform."; timetonextaction_minutes.value = '';\" 06813 $html .= " value='None' />{$GLOBALS['strNo']}"; 06814 $html .= "</label><br />"; 06815 06816 $html .= "<label><input type='radio' name='timetonextaction' "; 06817 $html .= "id='ttna_time' value='time' onchange=\"update_ttna();\" onclick=\"this.blur();\" />"; 06818 $html .= "{$GLOBALS['strForXDaysHoursMinutes']}</label><br />\n"; 06819 $html .= "<span id='ttnacountdown'"; 06820 if (empty($na_days) AND 06821 empty($na_hours) AND 06822 empty($na_minutes)) 06823 { 06824 $html .= " style='display: none;'"; 06825 } 06826 $html .= ">"; 06827 $html .= " <input name='timetonextaction_days' "; 06828 $html .= " id='timetonextaction_days' value='{$na_days}' maxlength='3' "; 06829 $html .= "onclick=\"$('ttna_time').checked = true;\" "; 06830 $html .= "size='3' /> {$GLOBALS['strDays']} "; 06831 $html .= "<input maxlength='2' name='timetonextaction_hours' "; 06832 $html .= "id='timetonextaction_hours' value='{$na_hours}' "; 06833 $html .= "onclick=\"$('ttna_time').checked = true;\" "; 06834 $html .= "size='3' /> {$GLOBALS['strHours']} "; 06835 $html .= "<input maxlength='2' name='timetonextaction_minutes' id='"; 06836 $html .= "timetonextaction_minutes' value='{$na_minutes}' "; 06837 $html .= "onclick=\"$('ttna_time').checked = true;\" "; 06838 $html .= "size='3' /> {$GLOBALS['strMinutes']}"; 06839 $html .= "<br />\n</span>"; 06840 06841 $html .= "<label><input type='radio' name='timetonextaction' id='ttna_date' "; 06842 $html .= "value='date' onchange=\"update_ttna();\" onclick=\"this.blur();\" />"; 06843 $html .= "{$GLOBALS['strUntilSpecificDateAndTime']}</label><br />\n"; 06844 $html .= "<div id='ttnadate' style='display: none;'>"; 06845 $html .= "<input name='date' id='timetonextaction_date' size='10' value='{$date}' "; 06846 $html .= "onclick=\"$('ttna_date').checked = true;\" /> "; 06847 $html .= date_picker("{$formid}.timetonextaction_date"); 06848 $html .= " <select name='timeoffset' id='timeoffset' "; 06849 $html .= "onclick=\"$('ttna_date').checked = true;\" >"; 06850 $html .= "<option value='0'></option>"; 06851 $html .= "<option value='0'>8:00 $strAM</option>"; 06852 $html .= "<option value='1'>9:00 $strAM</option>"; 06853 $html .= "<option value='2'>10:00 $strAM</option>"; 06854 $html .= "<option value='3'>11:00 $strAM</option>"; 06855 $html .= "<option value='4'>12:00 $strPM</option>"; 06856 $html .= "<option value='5'>1:00 $strPM</option>"; 06857 $html .= "<option value='6'>2:00 $strPM</option>"; 06858 $html .= "<option value='7'>3:00 $strPM</option>"; 06859 $html .= "<option value='8'>4:00 $strPM</option>"; 06860 $html .= "<option value='9'>5:00 $strPM</option>"; 06861 $html .= "</select>"; 06862 $html .= "<br />\n</div>"; 06863 06864 return $html; 06865 } 06866 06867 06876 function kb_article($id, $mode='internal') 06877 { 06878 global $CONFIG, $iconset; 06879 $id = intval($id); 06880 if (!is_number($id) OR $id == 0) 06881 { 06882 trigger_error("Incorrect KB ID", E_USER_ERROR); 06883 include (APPLICATION_INCPATH . 'htmlfooter.inc.php'); 06884 exit; 06885 } 06886 06887 $sql = "SELECT * FROM `{$GLOBALS['dbKBArticles']}` WHERE docid='{$id}' LIMIT 1"; 06888 $result = mysql_query($sql); 06889 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06890 $kbarticle = mysql_fetch_object($result); 06891 06892 if (empty($kbarticle->title)) 06893 { 06894 $kbarticle->title = $GLOBALS['strUntitled']; 06895 } 06896 $html .= "<div id='kbarticle'"; 06897 if ($kbarticle->distribution == 'private') $html .= " class='expired'"; 06898 if ($kbarticle->distribution == 'restricted') $html .= " class='urgent'"; 06899 $html .= ">"; 06900 $html .= "<h2 class='kbtitle'>{$kbarticle->title}</h2>"; 06901 06902 if (!empty($kbarticle->distribution) AND $kbarticle->distribution != 'public') 06903 { 06904 $html .= "<h2 class='kbdistribution'>{$GLOBALS['strDistribution']}: ".ucfirst($kbarticle->distribution)."</h2>"; 06905 } 06906 06907 // Lookup what software this applies to 06908 $ssql = "SELECT * FROM `{$GLOBALS['dbKBSoftware']}` AS kbs, `{$GLOBALS['dbSoftware']}` AS s "; 06909 $ssql .= "WHERE kbs.softwareid = s.id AND kbs.docid = '{$id}' "; 06910 $ssql .= "ORDER BY s.name"; 06911 $sresult = mysql_query($ssql); 06912 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06913 if (mysql_num_rows($sresult) >= 1) 06914 { 06915 $html .= "<h3>{$GLOBALS['strEnvironment']}</h3>"; 06916 $html .= "<p>{$GLOBALS['strTheInfoInThisArticle']}:</p>\n"; 06917 $html .= "<ul>\n"; 06918 while ($kbsoftware = mysql_fetch_object($sresult)) 06919 { 06920 $html .= "<li>{$kbsoftware->name}</li>\n"; 06921 } 06922 $html .= "</ul>\n"; 06923 } 06924 06925 $csql = "SELECT * FROM `{$GLOBALS['dbKBContent']}` WHERE docid='{$id}' "; 06926 $cresult = mysql_query($csql); 06927 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 06928 $restrictedcontent = 0; 06929 while ($kbcontent = mysql_fetch_object($cresult)) 06930 { 06931 switch ($kbcontent->distribution) 06932 { 06933 case 'private': 06934 if ($mode != 'internal') 06935 { 06936 echo "<p class='error'>{$GLOBALS['strPermissionDenied']}</p>"; 06937 include (APPLICATION_INCPATH . 'htmlfooter.inc.php'); 06938 exit; 06939 } 06940 $html .= "<div class='kbprivate'><h3>{$kbcontent->header} (private)</h3>"; 06941 $restrictedcontent++; 06942 break; 06943 case 'restricted': 06944 if ($mode != 'internal') 06945 { 06946 echo "<p class='error'>{$GLOBALS['strPermissionDenied']}</p>"; 06947 include (APPLICATION_INCPATH . 'htmlfooter.inc.php'); 06948 exit; 06949 } 06950 $html .= "<div class='kbrestricted'><h3>{$kbcontent->header}</h3>"; 06951 $restrictedcontent++; 06952 break; 06953 default: 06954 $html .= "<div><h3>{$kbcontent->header}</h3>"; 06955 } 06956 //$html .= "<{$kbcontent->headerstyle}>{$kbcontent->header}</{$kbcontent->headerstyle}>\n"; 06957 $html .= ''; 06958 $kbcontent->content=nl2br($kbcontent->content); 06959 $search = array("/(?<!quot;|[=\"]|:\/{2})\b((\w+:\/{2}|www\.).+?)"."(?=\W*([<>\s]|$))/i", "/(([\w\.]+))(@)([\w\.]+)\b/i"); 06960 $replace = array("<a href=\"$1\">$1</a>", "<a href=\"mailto:$0\">$0</a>"); 06961 $kbcontent->content = preg_replace("/href=\"www/i", "href=\"http://www", preg_replace ($search, $replace, $kbcontent->content)); 06962 $html .= bbcode($kbcontent->content); 06963 $author[]=$kbcontent->ownerid; 06964 $html .= "</div>\n"; 06965 06966 } 06967 06968 if ($restrictedcontent > 0) 06969 { 06970 $html .= "<h3>{$GLOBALS['strKey']}</h3>"; 06971 $html .= "<p><span class='keykbprivate'>{$GLOBALS['strPrivate']}</span>".help_link('KBPrivate')." "; 06972 $html .= "<span class='keykbrestricted'>{$GLOBALS['strRestricted']}</span>".help_link('KBRestricted')."</p>"; 06973 } 06974 06975 06976 $html .= "<h3>{$GLOBALS['strArticle']}</h3>"; 06977 //$html .= "<strong>{$GLOBALS['strDocumentID']}</strong>: "; 06978 $html .= "<p><strong>{$CONFIG['kb_id_prefix']}".leading_zero(4,$kbarticle->docid)."</strong> "; 06979 $pubdate = mysql2date($kbarticle->published); 06980 if ($pubdate > 0) 06981 { 06982 $html .= "{$GLOBALS['strPublished']} "; 06983 $html .= ldate($CONFIG['dateformat_date'],$pubdate)."<br />"; 06984 } 06985 06986 if ($mode == 'internal') 06987 { 06988 if (is_array($author)) 06989 { 06990 $author=array_unique($author); 06991 $countauthors=count($author); 06992 $count=1; 06993 if ($countauthors > 1) 06994 { 06995 $html .= "<strong>{$GLOBALS['strAuthors']}</strong>:<br />"; 06996 } 06997 else 06998 { 06999 $html .= "<strong>{$GLOBALS['strAuthor']}:</strong> "; 07000 } 07001 foreach ($author AS $authorid) 07002 { 07003 $html .= user_realname($authorid,TRUE); 07004 if ($count < $countauthors) $html .= ", " ; 07005 $count++; 07006 } 07007 } 07008 } 07009 07010 $html .= "<br />"; 07011 if (!empty($kbarticle->keywords)) 07012 { 07013 $html .= "<strong>{$GLOBALS['strKeywords']}</strong>: "; 07014 if ($mode == 'internal') 07015 { 07016 $html .= preg_replace("/\[([0-9]+)\]/", "<a href=\"incident_details.php?id=$1\" target=\"_blank\">$0</a>", $kbarticle->keywords); 07017 } 07018 else 07019 { 07020 $html .= $kbarticle->keywords; 07021 } 07022 $html .= "<br />"; 07023 } 07024 07025 //$html .= "<h3>{$GLOBALS['strDisclaimer']}</h3>"; 07026 $html .= "</p><hr />"; 07027 $html .= $CONFIG['kb_disclaimer_html']; 07028 $html .= "</div>"; 07029 07030 if ($mode == 'internal') 07031 { 07032 $html .= "<p align='center'>"; 07033 $html .= "<a href='kb.php'>{$GLOBALS['strBackToList']}</a> | "; 07034 $html .= "<a href='kb_article.php?id={$kbarticle->docid}'>{$GLOBALS['strEdit']}</a></p>"; 07035 } 07036 return $html; 07037 } 07038 07047 function show_edit_site($site, $mode='internal') 07048 { 07049 global $CONFIG; 07050 $sql = "SELECT * FROM `{$GLOBALS['dbSites']}` WHERE id='$site' "; 07051 $siteresult = mysql_query($sql); 07052 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 07053 while ($siterow = mysql_fetch_array($siteresult)) 07054 { 07055 if ($mode == 'internal') 07056 { 07057 $html .= "<h2>".icon('site', 32)." {$GLOBALS['strEditSite']}: {$site} - "; 07058 $html .= site_name($site)."</h2>"; 07059 } 07060 else 07061 { 07062 $html .= "<h2>".icon('site', 32)." ".site_name($site)."</h2>"; 07063 } 07064 07065 $html .= "<form name='edit_site' action='{$_SERVER['PHP_SELF']}"; 07066 $html .= "?action=update' method='post' onsubmit='return "; 07067 $html .= "confirm_action(\"{$GLOBALS['strAreYouSureMakeTheseChanges']}\")'>"; 07068 $html .= "<table align='center' class='vertical'>"; 07069 $html .= "<tr><th>{$GLOBALS['strName']}:</th>"; 07070 $html .= "<td><input class='required' maxlength='50' name='name' size='40' value='{$siterow['name']}' />"; 07071 $html .= "<span class='required'>{$GLOBALS['strRequired']}</span></td></tr>\n"; 07072 if ($mode == 'internal') 07073 { 07074 $html .= "<tr><th>{$GLOBALS['strTags']}:</th><td><textarea rows='2' cols='60' name='tags'>"; 07075 $html .= list_tags($site, TAG_SITE, false)."</textarea>\n"; 07076 } 07077 $html .= "<tr><th>{$GLOBALS['strDepartment']}:</th>"; 07078 $html .= "<td><input maxlength='50' name='department' size='40' value='{$siterow['department']}' />"; 07079 $html .= "</td></tr>\n"; 07080 $html .= "<tr><th>{$GLOBALS['strAddress1']}:</th>"; 07081 $html .= "<td><input maxlength='50' name='address1'"; 07082 $html .= "size='40' value='{$siterow['address1']}' />"; 07083 $html .= "</td></tr>\n"; 07084 $html .= "<tr><th>{$GLOBALS['strAddress2']}: </th><td><input maxlength='50' name='address2' size='40' value='{$siterow['address2']}' /></td></tr>\n"; 07085 $html .= "<tr><th>{$GLOBALS['strCity']}:</th><td><input maxlength='255' name='city' size='40' value='{$siterow['city']}' /></td></tr>\n"; 07086 $html .= "<tr><th>{$GLOBALS['strCounty']}:</th><td><input maxlength='255' name='county' size='40' value='{$siterow['county']}' /></td></tr>\n"; 07087 $html .= "<tr><th>{$GLOBALS['strPostcode']}:</th><td><input maxlength='255' name='postcode' size='40' value='{$siterow['postcode']}' /></td></tr>\n"; 07088 $html .= "<tr><th>{$GLOBALS['strCountry']}:</th><td>".country_drop_down('country', $siterow['country'])."</td></tr>\n"; 07089 $html .= "<tr><th>{$GLOBALS['strTelephone']}:</th><td>"; 07090 $html .= "<input maxlength='255' name='telephone' size='40' value='{$siterow['telephone']}' />"; 07091 $html .= "</td></tr>\n"; 07092 $html .= "<tr><th>{$GLOBALS['strFax']}:</th><td>"; 07093 $html .= "<input maxlength='255' name='fax' size='40' value='{$siterow['fax']}' /></td></tr>\n"; 07094 $html .= "<tr><th>{$GLOBALS['strEmail']}:</th><td>"; 07095 $html .= "<input maxlength='255' name='email' size='40' value='{$siterow['email']}' />"; 07096 $html .= "</td></tr>\n"; 07097 $html .= "<tr><th>{$GLOBALS['strWebsite']}:</th><td>"; 07098 $html .= "<input maxlength='255' name='websiteurl' size='40' value='{$siterow['websiteurl']}' /></td></tr>\n"; 07099 $html .= "<tr><th>{$GLOBALS['strSiteType']}:</th><td>\n"; 07100 $html .= sitetype_drop_down('typeid', $siterow['typeid']); 07101 $html .= "</td></tr>\n"; 07102 if ($mode == 'internal') 07103 { 07104 $html .= "<tr><th>{$GLOBALS['strSalesperson']}:</th><td>"; 07105 $html .= user_drop_down('owner', $siterow['owner'], $accepting = FALSE, '', '', TRUE); 07106 $html .= "</td></tr>\n"; 07107 } 07108 if ($mode == 'internal') 07109 { 07110 $html .= "<tr><th>{$GLOBALS['strIncidentPool']}:</th>"; 07111 $incident_pools = explode(',', "{$GLOBALS['strNone']},{$CONFIG['incident_pools']}"); 07112 if (array_key_exists($siterow['freesupport'], $incident_pools) == FALSE) 07113 { 07114 array_unshift($incident_pools,$siterow['freesupport']); 07115 } 07116 $html .= "<td>".array_drop_down($incident_pools,'incident_pool',$siterow['freesupport'])."</td></tr>"; 07117 $html .= "<tr><th>{$GLOBALS['strActive']}:</th><td><input type='checkbox' name='active' "; 07118 if ($siterow['active'] == 'true') 07119 { 07120 $html .= "checked='".$siterow['active']."'"; 07121 } 07122 $html .= " value='true' /></td></tr>\n"; 07123 $html .= "<tr><th>{$GLOBALS['strNotes']}:</th><td>"; 07124 $html .= "<textarea rows='5' cols='30' name='notes'>{$siterow['notes']}</textarea>"; 07125 $html .= "</td></tr>\n"; 07126 } 07127 plugin_do('edit_site_form'); 07128 $html .= "</table>\n"; 07129 $html .= "<input name='site' type='hidden' value='$site' />"; 07130 $html .= "<p><input name='submit' type='submit' value='{$GLOBALS['strSave']}' /></p>"; 07131 $html .= "</form>"; 07132 } 07133 return $html; 07134 } 07135 07136 07145 function show_add_contact($siteid = 0, $mode = 'internal') 07146 { 07147 global $CONFIG; 07148 $returnpage = cleanvar($_REQUEST['return']); 07149 if (!empty($_REQUEST['name'])) 07150 { 07151 $name = explode(' ',cleanvar(urldecode($_REQUEST['name'])), 2); 07152 $_SESSION['formdata']['add_contact']['forenames'] = ucfirst($name[0]); 07153 $_SESSION['formdata']['add_contact']['surname'] = ucfirst($name[1]); 07154 } 07155 07156 $html = show_form_errors('add_contact'); 07157 clear_form_errors('add_contact'); 07158 $html .= "<h2>".icon('contact', 32)." "; 07159 $html .= "{$GLOBALS['strNewContact']}</h2>"; 07160 07161 if ($mode == 'internal') 07162 { 07163 $html .= "<h5 class='warning'>{$GLOBALS['strAvoidDupes']}</h5>"; 07164 } 07165 $html .= "<form name='contactform' action='{$_SERVER['PHP_SELF']}' "; 07166 $html .= "method='post' onsubmit=\"return confirm_action('{$GLOBALS['strAreYouSureAdd']}')\">"; 07167 $html .= "<table align='center' class='vertical'>"; 07168 $html .= "<tr><th>{$GLOBALS['strName']}</th>\n"; 07169 07170 $html .= "<td>"; 07171 $html .= "\n<table><tr><td align='center'>{$GLOBALS['strTitle']}<br />"; 07172 $html .= "<input maxlength='50' name='courtesytitle' title=\""; 07173 $html .= "{$GLOBALS['strCourtesyTitle']}\" size='7'"; 07174 if ($_SESSION['formdata']['add_contact']['courtesytitle'] != '') 07175 { 07176 $html .= "value='{$_SESSION['formdata']['add_contact']['courtesytitle']}'"; 07177 } 07178 $html .= "/></td>\n"; 07179 07180 $html .= "<td align='center'>{$GLOBALS['strForenames']}<br />"; 07181 $html .= "<input class='required' maxlength='100' name='forenames' "; 07182 $html .= "size='15' title=\"{$GLOBALS['strForenames']}\""; 07183 if ($_SESSION['formdata']['add_contact']['forenames'] != '') 07184 { 07185 $html .= "value='{$_SESSION['formdata']['add_contact']['forenames']}'"; 07186 } 07187 $html .= "/></td>\n"; 07188 07189 $html .= "<td align='center'>{$GLOBALS['strSurname']}<br />"; 07190 $html .= "<input class='required' maxlength='100' name='surname' "; 07191 $html .= "size='20' title=\"{$GLOBALS['strSurname']}\""; 07192 if ($_SESSION['formdata']['add_contact']['surname'] != '') 07193 { 07194 $html .= "value='{$_SESSION['formdata']['add_contact']['surname']}'"; 07195 } 07196 $html .= " /> <span class='required'>{$GLOBALS['strRequired']}</span></td></tr>\n"; 07197 $html .= "</table>\n</td></tr>\n"; 07198 07199 $html .= "<tr><th>{$GLOBALS['strJobTitle']}</th><td><input maxlength='255'"; 07200 $html .= " name='jobtitle' size='35' title=\"{$GLOBALS['strJobTitle']}\""; 07201 if ($_SESSION['formdata']['add_contact']['jobtitle'] != '') 07202 { 07203 $html .= "value='{$_SESSION['formdata']['add_contact']['jobtitle']}'"; 07204 } 07205 $html .= " /></td></tr>\n"; 07206 if ($mode == 'internal') 07207 { 07208 $html .= "<tr><th>{$GLOBALS['strSite']}</th><td>"; 07209 $html .= site_drop_down('siteid',$siteid, TRUE)."<span class='required'>{$GLOBALS['strRequired']}</span></td></tr>\n"; 07210 } 07211 else 07212 { 07213 // For external always force the site to be the session site 07214 $html .= "<input type='hidden' name='siteid' value='{$_SESSION['siteid']}' />"; 07215 } 07216 07217 $html .= "<tr><th>{$GLOBALS['strDepartment']}</th><td><input maxlength='255' name='department' size='35'"; 07218 if ($_SESSION['formdata']['add_contact']['department'] != '') 07219 { 07220 $html .= "value='{$_SESSION['formdata']['add_contact']['department']}'"; 07221 } 07222 $html .= "/></td></tr>\n"; 07223 07224 $html .= "<tr><th>{$GLOBALS['strEmail']}</th><td>"; 07225 $html .= "<input class='required' maxlength='100' name='email' size='35'"; 07226 if ($_SESSION['formdata']['add_contact']['email']) 07227 { 07228 $html .= "value='{$_SESSION['formdata']['add_contact']['email']}'"; 07229 } 07230 $html .= "/><span class='required'>{$GLOBALS['strRequired']}</span> "; 07231 07232 $html .= "<label>"; 07233 $html .= html_checkbox('dataprotection_email', 'No'); 07234 $html .= "{$GLOBALS['strEmail']} {$GLOBALS['strDataProtection']}</label>".help_link("EmailDataProtection"); 07235 $html .= "</td></tr>\n"; 07236 07237 $html .= "<tr><th>{$GLOBALS['strTelephone']}</th><td><input maxlength='50' name='phone' size='35'"; 07238 if ($_SESSION['formdata']['add_contact']['phone'] != '') 07239 { 07240 $html .= "value='{$_SESSION['formdata']['add_contact']['phone']}'"; 07241 } 07242 $html .= "/> "; 07243 07244 $html .= "<label>"; 07245 $html .= html_checkbox('dataprotection_phone', 'No'); 07246 $html .= "{$GLOBALS['strTelephone']} {$GLOBALS['strDataProtection']}</label>".help_link("TelephoneDataProtection"); 07247 $html .= "</td></tr>\n"; 07248 07249 $html .= "<tr><th>{$GLOBALS['strMobile']}</th><td><input maxlength='100' name='mobile' size='35'"; 07250 if ($_SESSION['formdata']['add_contact']['mobile'] != '') 07251 { 07252 $html .= "value='{$_SESSION['formdata']['add_contact']['mobile']}'"; 07253 } 07254 $html .= "/></td></tr>\n"; 07255 07256 $html .= "<tr><th>{$GLOBALS['strFax']}</th><td><input maxlength='50' name='fax' size='35'"; 07257 if ($_SESSION['formdata']['add_contact']['fax']) 07258 { 07259 $html .= "value='{$_SESSION['formdata']['add_contact']['fax']}'"; 07260 } 07261 $html .= "/></td></tr>\n"; 07262 07263 $html .= "<tr><th>{$GLOBALS['strAddress']}</th><td><label>"; 07264 $html .= html_checkbox('dataprotection_address', 'No'); 07265 $html .= " {$GLOBALS['strAddress']} {$GLOBALS['strDataProtection']}</label>"; 07266 $html .= help_link("AddressDataProtection")."</td></tr>\n"; 07267 $html .= "<tr><th></th><td><label><input type='checkbox' name='usesiteaddress' value='yes' onclick=\"$('hidden').toggle();\" /> {$GLOBALS['strSpecifyAddress']}</label></td></tr>\n"; 07268 $html .= "<tbody id='hidden' style='display:none'>"; 07269 $html .= "<tr><th>{$GLOBALS['strAddress1']}</th>"; 07270 $html .= "<td><input maxlength='255' name='address1' size='35' /></td></tr>\n"; 07271 $html .= "<tr><th>{$GLOBALS['strAddress2']}</th>"; 07272 $html .= "<td><input maxlength='255' name='address2' size='35' /></td></tr>\n"; 07273 $html .= "<tr><th>{$GLOBALS['strCity']}</th><td><input maxlength='255' name='city' size='35' /></td></tr>\n"; 07274 $html .= "<tr><th>{$GLOBALS['strCounty']}</th><td><input maxlength='255' name='county' size='35' /></td></tr>\n"; 07275 $html .= "<tr><th>{$GLOBALS['strCountry']}</th><td>"; 07276 $html .= country_drop_down('country', $CONFIG['home_country'])."</td></tr>\n"; 07277 $html .= "<tr><th>{$GLOBALS['strPostcode']}</th><td><input maxlength='255' name='postcode' size='35' /></td></tr>\n"; 07278 $html .= "</tbody>"; 07279 if ($mode == 'internal') 07280 { 07281 $html .= "<tr><th>{$GLOBALS['strNotes']}</th><td><textarea cols='60' rows='5' name='notes'>"; 07282 if ($_SESSION['formdata']['add_contact']['notes'] != '') 07283 { 07284 $html .= $_SESSION['formdata']['add_contact']['notes']; 07285 } 07286 $html .= "</textarea></td></tr>\n"; 07287 } 07288 $html .= "<tr><th>{$GLOBALS['strEmailDetails']}</th>"; 07289 // Check the box to send portal details, only if portal is enabled 07290 $html .= "<td><input type='checkbox' id='emaildetails' name='emaildetails'"; 07291 if ($CONFIG['portal'] == TRUE) $html .= " checked='checked'"; 07292 else $html .= " disabled='disabled'"; 07293 $html .= " />"; 07294 $html .= "<label for='emaildetails'>{$GLOBALS['strEmailContactLoginDetails']}</label></td></tr>"; 07295 $html .= "</table>\n\n"; 07296 if (!empty($returnpage)) $html .= "<input type='hidden' name='return' value='{$returnpage}' />"; 07297 $html .= "<p><input name='submit' type='submit' value=\"{$GLOBALS['strAddContact']}\" /></p>"; 07298 $html .= "</form>\n"; 07299 07300 //cleanup form vars 07301 clear_form_data('add_contact'); 07302 07303 return $html; 07304 } 07305 07306 07312 function process_add_contact($mode = 'internal') 07313 { 07314 global $now, $CONFIG, $dbContacts, $sit; 07315 // Add new contact 07316 // External variables 07317 $siteid = clean_int($_REQUEST['siteid']); 07318 $email = strtolower(clean_dbstring($_REQUEST['email'])); 07319 $dataprotection_email = clean_dbstring($_REQUEST['dataprotection_email']); 07320 $dataprotection_phone = clean_dbstring($_REQUEST['dataprotection_phone']); 07321 $dataprotection_address = clean_dbstring($_REQUEST['dataprotection_address']); 07322 $username = clean_dbstring($_REQUEST['username']); 07323 $courtesytitle = clean_dbstring($_REQUEST['courtesytitle']); 07324 $forenames = clean_dbstring($_REQUEST['forenames']); 07325 $surname = clean_dbstring($_REQUEST['surname']); 07326 $jobtitle = clean_dbstring($_REQUEST['jobtitle']); 07327 $address1 = clean_dbstring($_REQUEST['address1']); 07328 $address2 = clean_dbstring($_REQUEST['address2']); 07329 $city = clean_dbstring($_REQUEST['city']); 07330 $county = clean_dbstring($_REQUEST['county']); 07331 if (!empty($address1)) $country = clean_dbstring($_REQUEST['country']); 07332 else $country=''; 07333 $postcode = clean_dbstring($_REQUEST['postcode']); 07334 $phone = clean_dbstring($_REQUEST['phone']); 07335 $mobile = clean_dbstring($_REQUEST['mobile']); 07336 $fax = clean_dbstring($_REQUEST['fax']); 07337 $department = clean_dbstring($_REQUEST['department']); 07338 $notes = clean_dbstring($_REQUEST['notes']); 07339 $returnpage = cleanvar($_REQUEST['return']); 07340 $_SESSION['formdata']['add_contact'] = cleanvar($_REQUEST, TRUE, FALSE, FALSE); 07341 07342 $errors = 0; 07343 // check for blank name 07344 if ($surname == '') 07345 { 07346 $errors++; 07347 $_SESSION['formerrors']['add_contact']['surname'] = sprintf($GLOBALS['strFieldMustNotBeBlank'], $GLOBALS['strSurname']); 07348 } 07349 // check for blank site 07350 if ($siteid == '') 07351 { 07352 $errors++; 07353 $_SESSION['formerrors']['add_contact']['siteid'] = sprintf($GLOBALS['strFieldMustNotBeBlank'], $GLOBALS['strSite']); 07354 } 07355 // check for blank email 07356 if ($email == '' OR $email=='none' OR $email=='n/a') 07357 { 07358 $errors++; 07359 $_SESSION['formerrors']['add_contact']['email'] = sprintf($GLOBALS['strFieldMustNotBeBlank'], $GLOBALS['strEmail']); 07360 } 07361 if ($siteid==0 OR $siteid=='') 07362 { 07363 $errors++; 07364 $_SESSION['formerrors']['add_contact']['siteid'] = sprintf($GLOBALS['strFieldMustNotBeBlank'], $GLOBALS['strSite']); 07365 } 07366 // Check this is not a duplicate 07367 $sql = "SELECT id FROM `{$dbContacts}` WHERE email='$email' AND LCASE(surname)=LCASE('$surname') LIMIT 1"; 07368 $result = mysql_query($sql); 07369 if (mysql_num_rows($result) >= 1) 07370 { 07371 $errors++; 07372 $_SESSION['formerrors']['add_contact']['duplicate'] = $GLOBALS['strContactRecordExists']; 07373 } 07374 07375 07376 // add contact if no errors 07377 if ($errors == 0) 07378 { 07379 if (!empty($dataprotection_email)) 07380 { 07381 $dataprotection_email = 'Yes'; 07382 } 07383 else 07384 { 07385 $dataprotection_email = 'No'; 07386 } 07387 07388 if (!empty($dataprotection_phone)) 07389 { 07390 $dataprotection_phone = 'Yes'; 07391 } 07392 else 07393 { 07394 $dataprotection_phone = 'No'; 07395 } 07396 07397 if (!empty($dataprotection_address)) 07398 { 07399 $dataprotection_address = 'Yes'; 07400 } 07401 else 07402 { 07403 $dataprotection_address = 'No'; 07404 } 07405 07406 // generate username and password 07407 07408 $username = strtolower(mb_substr($surname, 0, strcspn($surname, " "), 'UTF-8')); 07409 $prepassword = generate_password(); 07410 07411 $password = md5($prepassword); 07412 07413 $sql = "INSERT INTO `{$dbContacts}` (username, password, courtesytitle, forenames, surname, jobtitle, "; 07414 $sql .= "siteid, address1, address2, city, county, country, postcode, email, phone, mobile, fax, "; 07415 $sql .= "department, notes, dataprotection_email, dataprotection_phone, dataprotection_address, "; 07416 $sql .= "timestamp_added, timestamp_modified) "; 07417 $sql .= "VALUES ('$username', '$password', '$courtesytitle', '$forenames', '$surname', '$jobtitle', "; 07418 $sql .= "'$siteid', '$address1', '$address2', '$city', '$county', '$country', '$postcode', '$email', "; 07419 $sql .= "'$phone', '$mobile', '$fax', '$department', '$notes', '$dataprotection_email', "; 07420 $sql .= "'$dataprotection_phone', '$dataprotection_address', '$now', '$now')"; 07421 $result = mysql_query($sql); 07422 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 07423 07424 // concatenate username with insert id to make unique 07425 $newid = mysql_insert_id(); 07426 $username = $username . $newid; 07427 $sql = "UPDATE `{$dbContacts}` SET username='{$username}' WHERE id='{$newid}'"; 07428 $result = mysql_query($sql); 07429 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 07430 07431 if (!$result) 07432 { 07433 if ($mode == 'internal') 07434 { 07435 html_redirect("contact_add.php", FALSE); 07436 } 07437 else 07438 { 07439 html_redirect("addcontact.php", FALSE); 07440 } 07441 } 07442 else 07443 { 07444 clear_form_data('add_contact'); 07445 clear_form_errors('add_contact'); 07446 $sql = "SELECT username, password FROM `{$dbContacts}` WHERE id=$newid"; 07447 $result = mysql_query($sql); 07448 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 07449 else 07450 { 07451 if ($CONFIG['portal'] AND $_POST['emaildetails'] == 'on') 07452 { 07453 $emaildetails = 1; 07454 } 07455 else 07456 { 07457 $emaildetails = 0; 07458 } 07459 07460 trigger('TRIGGER_NEW_CONTACT', array('contactid' => $newid, 07461 'prepassword' => $prepassword, 07462 'userid' => $sit[2], 07463 'emaildetails' => $emaildetails 07464 )); 07465 07466 07467 if ($returnpage == 'addincident') 07468 { 07469 html_redirect("incident_add.php?action=findcontact&contactid={$newid}"); 07470 exit; 07471 } 07472 elseif ($mode == 'internal') 07473 { 07474 html_redirect("contact_details.php?id={$newid}"); 07475 exit; 07476 } 07477 else 07478 { 07479 html_redirect("contactdetails.php?id={$newid}"); 07480 exit; 07481 } 07482 } 07483 } 07484 07485 } 07486 else 07487 { 07488 if ($mode == 'internal') 07489 { 07490 html_redirect('contact_add.php', FALSE); 07491 } 07492 else 07493 { 07494 html_redirect('addcontact.php', FALSE); 07495 } 07496 } 07497 } 07498 07499 07507 function kb_name($kbid) 07508 { 07509 $kbid = intval($kbid); 07510 $sql = "SELECT title FROM `{$GLOBALS['dbKBArticles']}` WHERE docid='{$kbid}'"; 07511 $result = mysql_query($sql); 07512 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 07513 else 07514 { 07515 $row = mysql_fetch_object($result); 07516 return $row->title; 07517 } 07518 } 07519 07520 07527 function application_url() 07528 { 07529 global $CONFIG; 07530 if (empty($CONFIG['application_uriprefix'])) 07531 { 07532 $url = parse_url($_SERVER['HTTP_REFERER']); 07533 if ($_SERVER['HTTPS'] == 'off' OR empty($_SERVER['HTTPS'])) 07534 { 07535 $baseurl = "http://"; 07536 } 07537 else 07538 { 07539 $baseurl = "https://"; 07540 } 07541 $baseurl .= "{$_SERVER['HTTP_HOST']}"; 07542 } 07543 else 07544 { 07545 $baseurl = "{$CONFIG['application_uriprefix']}"; 07546 } 07547 $baseurl .= "{$CONFIG['application_webpath']}"; 07548 07549 return $baseurl; 07550 } 07551 07552 07560 function contract_product($maintid) 07561 { 07562 $maintid = intval($maintid); 07563 $productid = db_read_column('product', $GLOBALS['dbMaintenance'], $maintid); 07564 $sql = "SELECT name FROM `{$GLOBALS['dbProducts']}` WHERE id='{$productid}'"; 07565 $result = mysql_query($sql); 07566 $productobj = mysql_fetch_object($result); 07567 if (!empty($productobj->name)) 07568 { 07569 return $productobj->name; 07570 } 07571 else 07572 { 07573 return $GLOBALS['strUnknown']; 07574 } 07575 } 07576 07577 07585 function contract_site($maintid) 07586 { 07587 $maintid = intval($maintid); 07588 $sql = "SELECT site FROM `{$GLOBALS['dbMaintenance']}` WHERE id='{$maintid}'"; 07589 $result = mysql_query($sql); 07590 $maintobj = mysql_fetch_object($result); 07591 07592 $sitename = site_name($maintobj->site); 07593 if (!empty($sitename)) 07594 { 07595 return $sitename; 07596 } 07597 else 07598 { 07599 return $GLOBALS['strUnknown']; 07600 } 07601 } 07602 07603 07611 function setup_user_triggers($userid) 07612 { 07613 $return = TRUE; 07614 $userid = intval($userid); 07615 if ($userid != 0) 07616 { 07617 $sqls[] = "INSERT INTO `{$GLOBALS['dbTriggers']}` (`triggerid`, `userid`, `action`, `template`, `parameters`, `checks`) 07618 VALUES('TRIGGER_INCIDENT_ASSIGNED', {$userid}, 'ACTION_NOTICE', 'NOTICE_INCIDENT_ASSIGNED', '', '{userid} == {$userid}');"; 07619 $sqls[] = "INSERT INTO `{$GLOBALS['dbTriggers']}` (`triggerid`, `userid`, `action`, `template`, `parameters`, `checks`) 07620 VALUES('TRIGGER_SIT_UPGRADED', {$userid}, 'ACTION_NOTICE', 'NOTICE_SIT_UPGRADED', '', '');"; 07621 $sqls[] = "INSERT INTO `{$GLOBALS['dbTriggers']}` (`triggerid`, `userid`, `action`, `template`, `parameters`, `checks`) 07622 VALUES('TRIGGER_INCIDENT_CLOSED', {$userid}, 'ACTION_NOTICE', 'NOTICE_INCIDENT_CLOSED', '', '{userid} == {$userid}');"; 07623 $sqls[] = "INSERT INTO `{$GLOBALS['dbTriggers']}` (`triggerid`, `userid`, `action`, `template`, `parameters`, `checks`) 07624 VALUES('TRIGGER_INCIDENT_NEARING_SLA', {$userid}, 'ACTION_NOTICE', 'NOTICE_INCIDENT_NEARING_SLA', '', 07625 '{ownerid} == {$userid} OR {townerid} == {$userid}');"; 07626 $sqls[] = "INSERT INTO `{$GLOBALS['dbTriggers']}` (`triggerid`, `userid`, `action`, `template`, `parameters`, `checks`) 07627 VALUES('TRIGGER_LANGUAGE_DIFFERS', {$userid}, 'ACTION_NOTICE', 'NOTICE_LANGUAGE_DIFFERS', '', '');"; 07628 07629 07630 foreach ($sqls AS $sql) 07631 { 07632 mysql_query($sql); 07633 if (mysql_error()) 07634 { 07635 trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 07636 $return = FALSE; 07637 } 07638 } 07639 } 07640 else 07641 { 07642 trigger_error("setup_user_triggers() Invalid userid '{$userid}' specified", E_USER_NOTICE); 07643 $return = FALSE; 07644 } 07645 07646 return $return; 07647 } 07648 07649 07657 function contract_slaid($maintid) 07658 { 07659 $maintid = intval($maintid); 07660 $slaid = db_read_column('servicelevelid', $GLOBALS['dbMaintenance'], $maintid); 07661 return $slaid; 07662 } 07663 07664 07672 function site_salespersonid($siteid) 07673 { 07674 $siteid = intval($siteid); 07675 $salespersonid = db_read_column('owner', $GLOBALS['dbSites'], $siteid); 07676 return $salespersonid; 07677 } 07678 07679 07687 function site_salesperson($siteid) 07688 { 07689 $siteid = intval($siteid); 07690 $salespersonid = db_read_column('owner', $GLOBALS['dbSites'], $siteid); 07691 return user_realname($salespersonid); 07692 } 07693 07694 07699 function application_version_string() 07700 { 07701 global $application_version_string; 07702 return $application_version_string; 07703 } 07704 07705 07711 function database_schema_version() 07712 { 07713 $return = ''; 07714 $sql = "SELECT `schemaversion` FROM `{$GLOBALS['dbSystem']}` WHERE id = 0"; 07715 $result = mysql_query($sql); 07716 if (mysql_error()) 07717 { 07718 trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 07719 $return = FALSE; 07720 } 07721 07722 if (mysql_num_rows($result) > 0) 07723 { 07724 list($return) = mysql_fetch_row($result); 07725 } 07726 07727 return $return; 07728 } 07729 07730 07731 07732 07740 function contact_username($userid) 07741 { 07742 $userid = intval($userid); 07743 return db_read_column('username', $GLOBALS['dbContacts'], $userid); 07744 } 07745 07746 07753 function populate_syslang() 07754 { 07755 global $CONFIG; 07756 07757 // Populate $SYSLANG with first the native lang and then the system lang 07758 // This is so that we have a complete language file 07759 $nativefile = APPLICATION_I18NPATH . "en-GB.inc.php"; 07760 $file = APPLICATION_I18NPATH . "{$CONFIG['default_i18n']}.inc.php"; 07761 07762 if (file_exists($nativefile)) 07763 { 07764 $fh = fopen($nativefile, "r"); 07765 07766 $theData = fread($fh, filesize($nativefile)); 07767 fclose($fh); 07768 $nativelines = explode("\n", $theData); 07769 07770 if (file_exists($file)) 07771 { 07772 $fh = fopen($file, "r"); 07773 $theData = fread($fh, filesize($file)); 07774 fclose($fh); 07775 $lines = $nativelines += explode("\n", $theData); 07776 } 07777 else 07778 { 07779 trigger_error("File specified in \$CONFIG['default_i18n'] can't be found", E_USER_ERROR); 07780 $lines = $nativelines; 07781 } 07782 07783 foreach ($lines as $values) 07784 { 07785 $badchars = array("$", "\"", "\\", "<?php", "?>"); 07786 $values = trim(str_replace($badchars, '', $values)); 07787 if (substr($values, 0, 3) == "str") 07788 { 07789 $vars = explode("=", $values); 07790 $vars[0] = trim($vars[0]); 07791 $vars[1] = trim(substr_replace($vars[1], "",-2)); 07792 $vars[1] = substr_replace($vars[1], "",0, 1); 07793 $SYSLANG[$vars[0]] = $vars[1]; 07794 } 07795 } 07796 $_SESSION['syslang'] = $SYSLANG; 07797 } 07798 else 07799 { 07800 trigger_error("Native language file 'en-GB' can't be found", E_USER_ERROR); 07801 } 07802 } 07803 07804 07812 function user_contracts_table($userid, $mode = 'internal') 07813 { 07814 global $now, $CONFIG, $sit; 07815 if ((!empty($sit[2]) AND user_permission($sit[2], 30) 07816 OR ($_SESSION['usertype'] == 'admin'))) // view supported products 07817 { 07818 $html .= "<h4>".icon('contract', 16)." {$GLOBALS['strContracts']}:</h4>"; 07819 // Contracts we're explicit supported contact for 07820 $sql = "SELECT sc.maintenanceid AS maintenanceid, m.product, p.name AS productname, "; 07821 $sql .= "m.expirydate, m.term "; 07822 $sql .= "FROM `{$GLOBALS['dbContacts']}` AS c, "; 07823 $sql .= "`{$GLOBALS['dbSupportContacts']}` AS sc, "; 07824 $sql .= "`{$GLOBALS['dbMaintenance']}` AS m, "; 07825 $sql .= "`{$GLOBALS['dbProducts']}` AS p "; 07826 $sql .= "WHERE c.id = '{$userid}' "; 07827 $sql .= "AND (sc.maintenanceid=m.id AND sc.contactid='$userid') "; 07828 $sql .= "AND m.product=p.id "; 07829 // Contracts we're an 'all supported' on 07830 $sql .= "UNION "; 07831 $sql .= "SELECT m.id AS maintenanceid, m.product, p.name AS productname, "; 07832 $sql .= "m.expirydate, m.term "; 07833 $sql .= "FROM `{$GLOBALS['dbContacts']}` AS c, "; 07834 $sql .= "`{$GLOBALS['dbMaintenance']}` AS m, "; 07835 $sql .= "`{$GLOBALS['dbProducts']}` AS p "; 07836 $sql .= "WHERE c.id = '{$userid}' AND c.siteid = m.site "; 07837 $sql .= "AND m.allcontactssupported = 'yes' "; 07838 $sql .= "AND m.product=p.id "; 07839 07840 $result = mysql_query($sql); 07841 if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING); 07842 if (mysql_num_rows($result)>0) 07843 { 07844 $html .= "<table align='center' class='vertical'>"; 07845 $html .= "<tr>"; 07846 $html .= "<th>{$GLOBALS['strID']}</th><th>{$GLOBALS['strProduct']}</th><th>{$GLOBALS['strExpiryDate']}</th>"; 07847 $html .= "</tr>\n"; 07848 07849 $supportcount=1; 07850 $shade='shade2'; 07851 while ($supportedrow = mysql_fetch_array($result)) 07852 { 07853 if ($supportedrow['term'] == 'yes') 07854 { 07855 $shade='expired'; 07856 } 07857 07858 if ($supportedrow['expirydate'] < $now AND $supportedrow['expirydate'] != -1) 07859 { 07860 $shade='expired'; 07861 } 07862 07863 $html .= "<tr><td class='$shade'>"; 07864 $html .= ''.icon('contract', 16)." "; 07865 if ($mode == 'internal') 07866 { 07867 $html .= "<a href='contract_details.php?id="; 07868 } 07869 else 07870 { 07871 $html .= "<a href='contracts.php?id="; 07872 } 07873 $html .= "{$supportedrow['maintenanceid']}'>"; 07874 $html .= "{$GLOBALS['strContract']}: "; 07875 $html .= "{$supportedrow['maintenanceid']}</a></td>"; 07876 $html .= "<td class='$shade'>{$supportedrow['productname']}</td>"; 07877 $html .= "<td class='$shade'>"; 07878 if ($supportedrow['expirydate'] == -1) 07879 { 07880 $html .= $GLOBALS['strUnlimited']; 07881 } 07882 else 07883 { 07884 $html .= ldate($CONFIG['dateformat_date'], $supportedrow['expirydate']); 07885 } 07886 if ($supportedrow['term'] == 'yes') 07887 { 07888 $html .= " {$GLOBALS['strTerminated']}"; 07889 } 07890 07891 $html .= "</td>"; 07892 $html .= "</tr>\n"; 07893 $supportcount++; 07894 $shade = 'shade2'; 07895 } 07896 $html .= "</table>\n"; 07897 } 07898 else 07899 { 07900 $html .= "<p align='center'>{$GLOBALS['strNone']}</p>\n"; 07901 } 07902 07903 if ($mode == 'internal') 07904 { 07905 $html .= "<p align='center'>"; 07906 $html .= "<a href='contract_add_contact.php?contactid={$userid}&context=contact'>"; 07907 $html .= "{$GLOBALS['strAssociateContactWithContract']}</a></p>\n"; 07908 } 07909 07910 } 07911 07912 return $html; 07913 } 07914 07915 // -------------------------- // -------------------------- // -------------------------- 07916 // leave this section at the bottom of functions.inc.php ================================ 07917 07918 // Evaluate and Load plugins 07919 if (is_array($CONFIG['plugins'])) 07920 { 07921 foreach ($CONFIG['plugins'] AS $plugin) 07922 { 07923 $plugin = trim($plugin); 07924 // Remove any dots 07925 $plugin = str_replace('.','',$plugin); 07926 // Remove any slashes 07927 $plugin = str_replace('/','',$plugin); 07928 07929 $plugini18npath = APPLICATION_PLUGINPATH . "{$plugin}". DIRECTORY_SEPARATOR . "i18n". DIRECTORY_SEPARATOR; 07930 if ($plugin != '') 07931 { 07932 if (file_exists(APPLICATION_PLUGINPATH . "{$plugin}.php")) 07933 { 07934 include (APPLICATION_PLUGINPATH . "{$plugin}.php"); 07935 // Load i18n if it exists 07936 if (file_exists($plugini18npath)) 07937 { 07938 @include ("{$plugini18npath}{$CONFIG['default_i18n']}.inc.php"); 07939 if (!empty($_SESSION['lang']) 07940 AND $_SESSION['lang'] != $CONFIG['default_i18n']) 07941 { 07942 @include ("{$plugini18npath}{$_SESSION['lang']}.inc.php"); 07943 } 07944 } 07945 } 07946 else 07947 { 07948 // Only trigger a warning if headers are sent 07949 // No need to break whole pages 07950 if (headers_sent()) 07951 { 07952 trigger_error("Plugin '{$plugin}' could not be found.", E_USER_WARNING); 07953 } 07954 } 07955 } 07956 } 07957 } 07958 07959 07968 function plugin_register($context, $action) 07969 { 07970 global $PLUGINACTIONS; 07971 $PLUGINACTIONS[$context][] = $action; 07972 } 07973 07974 07986 function plugin_do($context, $optparams = FALSE) 07987 { 07988 global $PLUGINACTIONS; 07989 07990 // Make global variables available to plugins, careful not overwrite vars 07991 // used in plugin_do function scope (Mantis 1433) 07992 foreach ($GLOBALS as $key => $val) 07993 { 07994 if ($key != 'context' AND $key != 'optparams' AND $key != 'PLUGINACTIONS') 07995 { 07996 global $$key; 07997 } 07998 } 07999 $rtnvalue = ''; 08000 if (is_array($PLUGINACTIONS[$context])) 08001 { 08002 foreach ($PLUGINACTIONS[$context] AS $pluginaction) 08003 { 08004 // Call Variable function (function with variable name) 08005 if ($optparams) 08006 { 08007 $rtn = $pluginaction($optparams); 08008 } 08009 else 08010 { 08011 $rtn = $pluginaction(); 08012 } 08013 08014 // Append return value 08015 if (is_array($rtn) AND is_array($rtnvalue)) 08016 { 08017 array_push($rtnvalue, $rtn); 08018 } 08019 elseif (is_array($rtn) AND !is_array($rtnvalue)) 08020 { 08021 $rtnvalue=array(); array_push($rtnvalue, $rtn); 08022 } 08023 else 08024 { 08025 $rtnvalue .= $rtn; 08026 } 08027 } 08028 } 08029 return $rtnvalue; 08030 } 08031 08032 08039 function is_day_bank_holiday($day, $month, $year) 08040 { 08041 global $dbHolidays; 08042 08043 $date = "{$year}-{$month}-{$day}"; 08044 $sql = "SELECT * FROM `{$dbHolidays}` WHERE type = 10 AND date = '{$date}'"; 08045 08046 $result = mysql_query($sql); 08047 if (mysql_error()) 08048 { 08049 trigger_error(mysql_error(),E_USER_ERROR); 08050 return FALSE; 08051 } 08052 08053 if (mysql_num_rows($result) > 0) return TRUE; 08054 else return FALSE; 08055 } 08056 08057 08066 function create_report($data, $output = 'table', $filename = 'report.csv') 08067 { 08068 $data = explode("\n", $data); 08069 if ($output == 'table') 08070 { 08071 $html = "\n<table align='center'><tr>\n"; 08072 $headers = explode(',', $data[0]); 08073 $rows = sizeof($headers); 08074 foreach ($headers as $header) 08075 { 08076 $html .= colheader($header, $header); 08077 } 08078 $html .= "</tr>"; 08079 08080 if (sizeof($data) == 1) 08081 { 08082 $html .= "<tr><td rowspan='{$rows}'>{$GLOBALS['strNoRecords']}</td></tr>"; 08083 } 08084 else 08085 { 08086 // use 1 -> sizeof as we've already done one row 08087 for ($i = 1; $i < sizeof($data); $i++) 08088 { 08089 $html .= "<tr>"; 08090 $values = explode(',', $data[$i]); 08091 foreach ($values as $value) 08092 { 08093 $html .= "<td>$value</td>"; 08094 } 08095 $html .= "</tr>"; 08096 } 08097 } 08098 $html .= "</table>"; 08099 } 08100 else 08101 { 08102 $html = header("Content-type: text/csv\r\n"); 08103 $html .= header("Content-disposition-type: attachment\r\n"); 08104 $html .= header("Content-disposition: filename={$filename}"); 08105 08106 foreach ($data as $line) 08107 { 08108 if (!beginsWith($line, "\"")) 08109 { 08110 $line = "\"".str_replace(",", "\",\"",$line)."\"\r\n"; 08111 } 08112 08113 $html .= $line; 08114 } 08115 } 08116 08117 return $html; 08118 } 08119 08120 08127 function alpha_index($baseurl = '#') 08128 { 08129 global $i18nAlphabet; 08130 08131 $html = ''; 08132 if (!empty($i18nAlphabet)) 08133 { 08134 $len = utf8_strlen($i18nAlphabet); 08135 for ($i = 0; $i < $len; $i++) 08136 { 08137 $html .= "<a href=\"{$baseurl}"; 08138 $html .= urlencode(utf8_substr($i18nAlphabet, $i, 1))."\">"; 08139 $html .= utf8_substr($i18nAlphabet, $i, 1)."</a> | \n"; 08140 08141 } 08142 } 08143 return $html; 08144 } 08145 08146 08153 function emoticons($text) 08154 { 08155 global $CONFIG; 08156 $smiley_url = "{$CONFIG['application_uriprefix']}{$CONFIG['application_webpath']}images/emoticons/"; 08157 $smiley_regex = array(0 => "/\:[-]?\)/s", 08158 1 => "/\:[-]?\(/s", 08159 2 => "/\;[-]?\)/s", 08160 3 => "/\:[-]?[pP]/s", 08161 4 => "/\:[-]?@/s", 08162 5 => "/\:[-]?[Oo]/s", 08163 6 => "/\:[-]?\\$/s", 08164 7 => "/\\([Yy]\)/s", 08165 8 => "/\\([Nn]\)/s", 08166 9 => "/\\([Bb]\)/s", 08167 10 => "/\:[-]?[dD]/s" 08168 ); 08169 08170 $smiley_replace = array(0 => "<img src='{$smiley_url}smile.png' alt='$1' title='$1' />", 08171 1 => "<img src='{$smiley_url}sad.png' alt='$1' title='$1' />", 08172 2 => "<img src='{$smiley_url}wink.png' alt='$1' title='$1' />", 08173 3 => "<img src='{$smiley_url}tongue.png' alt='$1' title='$1' />", 08174 4 => "<img src='{$smiley_url}angry.png' alt='$1' title='$1' />", 08175 5 => "<img src='{$smiley_url}omg.png' alt='$1' title='$1' />", 08176 6 => "<img src='{$smiley_url}embarassed.png' alt='$1' title='$1' />", 08177 7 => "<img src='{$smiley_url}thumbs_up.png' alt='$1' title='$1' />", 08178 8 => "<img src='{$smiley_url}thumbs_down.png' alt='$1' title='$1' />", 08179 9 => "<img src='{$smiley_url}beer.png' alt='$1' title='$1' />", 08180 10 => "<img src='{$smiley_url}teeth.png' alt='$1' title='$1' />" 08181 ); 08182 08183 $html = preg_replace($smiley_regex, $smiley_replace, $text); 08184 return $html; 08185 } 08186 08187 08207 function new_update($incidentid, $text, $type = 'default', $sla = '', $userid = 0, $currentowner = '', 08208 $currentstatus = 1, $visibility = 'show') 08209 { 08210 global $now; 08211 $text = clean_dbstring($text); 08212 $sql = "INSERT INTO `{$GLOBALS['dbUpdates']}` (incidentid, userid, "; 08213 $sql .= "type, bodytext, timestamp, currentowner, currentstatus, "; 08214 $sql .= "customervisibility, sla) VALUES ('{$incidentid}', '{$userid}', "; 08215 $sql .= "'{$type}', '{$text}', '{$now}', '{$currentowner}', "; 08216 $sql .= "'{$currentstatus}', '{$visibility}', '{$sla}')"; 08217 $result = mysql_query($sql); 08218 if (mysql_error()) 08219 { 08220 trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 08221 return FALSE; 08222 } 08223 else 08224 { 08225 return mysql_insert_id(); 08226 } 08227 } 08228 08229 08245 function create_temp_incoming($updateid, $from, $subject, $emailfrom, 08246 $contactid = '', $incidentid = 0, $locked = '', 08247 $lockeduntil = '', $reason = '', 08248 $reason_user = '', $reason_time = '') 08249 { 08250 global $dbTempIncoming; 08251 $sql = "INSERT INTO `{$dbTempIncoming}`(updateid, `from`, subject, "; 08252 $sql .= "emailfrom, contactid, incidentid, locked, lockeduntil, "; 08253 $sql .= "reason, reason_user, reason_time) VALUES('{$updateid}', "; 08254 $sql .= "'{$from}', '{$subject}', '{$emailfrom}', '{$contactid}', "; 08255 $sql .= "'{$incidentid}', '{$locked}', '{$lockeduntil}', '{$reason}', "; 08256 $sql .= "'{$reason_user}', '{$reason_time}')"; 08257 $result = mysql_query($sql); 08258 if (mysql_error()) 08259 { 08260 trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR); 08261 return FALSE; 08262 } 08263 else 08264 { 08265 return mysql_insert_id(); 08266 } 08267 } 08268 08269 08270 08276 function is_assoc($array) 08277 { 08278 return is_array($array) && count($array) !== array_reduce(array_keys($array), 'is_assoc_callback', 0); 08279 } 08280 08281 08289 function is_assoc_callback($a, $b) 08290 { 08291 return $a === $b ? $a + 1 : 0; 08292 } 08293 08294 08295 08303 function cfgVarInput($setupvar, $showvarnames = FALSE) 08304 { 08305 global $CONFIG, $CFGVAR; 08306 08307 if ($CFGVAR[$setupvar]['type'] == 'languageselect' 08308 OR $CFGVAR[$setupvar]['type'] == 'languagemultiselect') 08309 { 08310 $available_languages = available_languages(); 08311 } 08312 08313 $html .= "<div class='configvar'>"; 08314 if ($CFGVAR[$setupvar]['title']!='') $title = $CFGVAR[$setupvar]['title']; 08315 else $title = $setupvar; 08316 $html .= "<h4>{$title}</h4>"; 08317 if ($CFGVAR[$setupvar]['help']!='') $html .= "<p class='helptip'>{$CFGVAR[$setupvar]['help']}</p>\n"; 08318 08319 $value = ''; 08320 if (!$cfg_file_exists OR ($cfg_file_exists AND $cfg_file_writable)) 08321 { 08322 $value = $CONFIG[$setupvar]; 08323 if (is_bool($value)) 08324 { 08325 if ($value==TRUE) $value='TRUE'; 08326 else $value='FALSE'; 08327 } 08328 elseif (is_array($value)) 08329 { 08330 if (is_assoc($value)) 08331 { 08332 $value = "array(".implode_assoc('=>',',',$value).")"; 08333 } 08334 else 08335 { 08336 $value="array(".implode(',',$value).")"; 08337 } 08338 } 08339 if ($setupvar=='db_password' AND $_REQUEST['action']!='reconfigure') $value=''; 08340 } 08341 $value = stripslashes($value); 08342 switch ($CFGVAR[$setupvar]['type']) 08343 { 08344 case 'select': 08345 $html .= "<select name='{$setupvar}' id='{$setupvar}'>"; 08346 if (empty($CFGVAR[$setupvar]['options'])) $CFGVAR[$setupvar]['options'] = "TRUE|FALSE"; 08347 $options = explode('|', $CFGVAR[$setupvar]['options']); 08348 foreach ($options AS $option) 08349 { 08350 $html .= "<option value=\"{$option}\""; 08351 if ($option == $value) $html .= " selected='selected'"; 08352 $html .= ">{$option}</option>\n"; 08353 } 08354 $html .= "</select>"; 08355 break; 08356 case 'percent': 08357 $html .= "<select name='{$setupvar}' id='{$setupvar}'>"; 08358 for($i = 0; $i <= 100; $i++) 08359 { 08360 $html .= "<option value=\"{$i}\""; 08361 if ($i == $value) $html .= " selected='selected'"; 08362 $html .= ">{$i}</option>\n"; 08363 } 08364 $html .= "</select>%"; 08365 break; 08366 case 'interfacestyleselect': 08367 $html .= interfacestyle_drop_down($setupvar, $value); 08368 break; 08369 case 'languageselect': 08370 if (empty($value)) $value = $_SESSION['lang']; 08371 $html .= array_drop_down($available_languages, $setupvar, $value, '', TRUE); 08372 break; 08373 case 'languagemultiselect': 08374 if (empty($value)) 08375 { 08376 foreach ($available_languages AS $code => $lang) 08377 { 08378 $value[] = $code; 08379 } 08380 $checked = TRUE; 08381 } 08382 else 08383 { 08384 $checked = FALSE; 08385 $replace = array('array(', ')', "'"); 08386 $value = str_replace($replace, '', $value); 08387 $value = explode(',', $value); 08388 } 08389 $html .= array_drop_down($available_languages, $setupvar, $value, '', TRUE, TRUE); 08390 $attributes = "onchange=\"toggle_multiselect('{$setupvar}[]')\""; 08391 $html .= "<label>".html_checkbox($setupvar.'checkbox', $checked, ""); 08392 $html .= $GLOBALS['strAll']."</label>"; 08393 break; 08394 case 'slaselect': 08395 $html .= serviceleveltag_drop_down($setupvar, $value, TRUE); 08396 break; 08397 case 'userselect': 08398 $html .= user_drop_down($setupvar, $value, FALSE, FALSE, '', TRUE); 08399 break; 08400 case 'siteselect': 08401 $html .= site_drop_down($setupvar, $value, FALSE); 08402 break; 08403 case 'userstatusselect': 08404 $html .= userstatus_drop_down($setupvar, $value); 08405 break; 08406 case 'roleselect': 08407 $html .= role_drop_down($setupvar, $value); 08408 break; 08409 case 'number': 08410 $html .= "<input type='text' name='{$setupvar}' id='{$setupvar}' size='7' value=\"{$value}\" />"; 08411 break; 08412 case '1darray': 08413 $replace = array('array(', ')', "'"); 08414 $value = str_replace($replace, '', $value); 08415 $html .= "<input type='text' name='{$setupvar}' id='{$setupvar}' size='60' value=\"{$value}\" />"; 08416 break; 08417 case '2darray': 08418 $replace = array('array(', ')', "'", '\r','\n'); 08419 $value = str_replace($replace, '', $value); 08420 $value = str_replace(',', "\n", $value); 08421 $html .= "<textarea name='{$setupvar}' id='{$setupvar}' cols='60' rows='10'>{$value}</textarea>"; 08422 break; 08423 case 'password': 08424 $html .= "<input type='password' id='cfg{$setupvar}' name='{$setupvar}' size='16' value=\"{$value}\" /> ".password_reveal_link("cfg{$setupvar}"); 08425 break; 08426 case 'ldappassword': 08427 $html .= "<input type='password' id='cfg{$setupvar}' name='{$setupvar}' size='16' value=\"{$value}\" /> ".password_reveal_link("cfg{$setupvar}"); 08428 $html.= " <a href='javascript:void(0);' onclick=\"checkLDAPDetails('status{$setupvar}');\">{$GLOBALS['strCheckLDAPDetails']}</a>"; 08429 break; 08430 case 'textreadonly': 08431 $html .= "<input type='text' name='{$setupvar}' id='{$setupvar}' size='60' value=\"{$value}\" readonly='readonly' />"; 08432 break; 08433 case 'text': 08434 default: 08435 if (strlen($CONFIG[$setupvar]) < 65) 08436 { 08437 $html .= "<input type='text' name='{$setupvar}' id='{$setupvar}' size='60' value=\"{$value}\" />"; 08438 } 08439 else 08440 { 08441 $html .= "<textarea name='{$setupvar}' id='{$setupvar}' cols='60' rows='10'>{$value}</textarea>"; 08442 } 08443 } 08444 if (!empty($CFGVAR[$setupvar]['unit'])) $html .= " {$CFGVAR[$setupvar]['unit']}"; 08445 if (!empty($CFGVAR[$setupvar]['helplink'])) $html .= ' '.help_link($CFGVAR[$setupvar]['helplink']); 08446 if ($setupvar == 'db_password' AND $_REQUEST['action'] != 'reconfigure' AND $value != '') 08447 { 08448 $html .= "<p class='info'>The current password setting is not shown</p>"; 08449 } 08450 08451 if ($showvarnames) $html .= "<br />(<var>\$CONFIG['$setupvar']</var>)"; 08452 08453 if ($CFGVAR[$setupvar]['statusfield'] == 'TRUE') 08454 { 08455 $html .= "<div id='status{$setupvar}'></div>"; 08456 } 08457 08458 $html .= "</div>"; 08459 $html .= "<br />\n"; 08460 if ($c == 1) $c == 2; 08461 else $c = 1; 08462 08463 return $html; 08464 } 08465 08466 08473 function cfgSave($setupvars) 08474 { 08475 global $dbConfig; 08476 foreach ($setupvars AS $key => $value) 08477 { 08478 $sql = "REPLACE INTO `{$dbConfig}` (`config`, `value`) VALUES ('{$key}', '{$value}')"; 08479 mysql_query($sql); 08480 if (mysql_error()) trigger_error(mysql_error(). " $sql",E_USER_WARNING); 08481 } 08482 return TRUE; 08483 } 08484 08485 08490 function password_reveal_link($id) 08491 { 08492 $html = "<a href=\"javascript:password_reveal('$id')\" id=\"link{$id}\">{$GLOBALS['strReveal']}</a>"; 08493 return $html; 08494 } 08495 08496 08497 function holding_email_update_id($holding_email) 08498 { 08499 $holding_email = intval($holding_email); 08500 return db_read_column('updateid', $GLOBALS['dbTempIncoming'], $holding_email); 08501 } 08502 08503 08504 function delete_holding_queue_update($updateid) 08505 { 08506 $sql = "DELETE FROM {$GLOBALS['dbTempIncoming']} WHERE updateid = '{$updateid}'"; 08507 mysql_query($sql); 08508 if (mysql_error()) 08509 { 08510 trigger_error(mysql_error(). " $sql",E_USER_WARNING); 08511 return FALSE; 08512 } 08513 else 08514 { 08515 return TRUE; 08516 } 08517 } 08518 08519 08520 function num_unread_emails() 08521 { 08522 global $dbTempIncoming; 08523 $sql = "SELECT COUNT(*) AS count FROM `{$dbTempIncoming}`"; 08524 $result = mysql_query($sql); 08525 if (mysql_error()) trigger_error(mysql_error(). " $sql",E_USER_WARNING); 08526 list($count) = mysql_fetch_row($result); 08527 return $count; 08528 } 08529 08530 08538 function is_kb_article($id, $mode) 08539 { 08540 $rtn = FALSE; 08541 global $dbKBArticles; 08542 $id = clean_int($id); 08543 if ($id > 0) 08544 { 08545 $sql = "SELECT distribution FROM `{$dbKBArticles}` "; 08546 $sql .= "WHERE docid = '{$id}'"; 08547 $result = mysql_query($sql); 08548 if (mysql_error()) trigger_error(mysql_error(). " $sql",E_USER_WARNING); 08549 list($visibility) = mysql_fetch_row($result); 08550 if ($visibility == 'public' && $mode == 'public') 08551 { 08552 $rtn = TRUE; 08553 } 08554 else if (($visibility == 'private' OR $visibility == 'restricted') AND 08555 $mode == 'private') 08556 { 08557 $rtn = TRUE; 08558 } 08559 } 08560 return $rtn; 08561 } 08562 08563 08572 function feedback_hash($formid, $contactid, $incidentid) 08573 { 08574 $hashtext = urlencode($formid)."&&".urlencode($contactid)."&&".urlencode($incidentid); 08575 $hashcode4 = str_rot13($hashtext); 08576 $hashcode3 = gzcompress($hashcode4); 08577 $hashcode2 = base64_encode($hashcode3); 08578 $hashcode1 = trim($hashcode2); 08579 $hashcode = urlencode($hashcode1); 08580 return $hashcode; 08581 } 08582 08583 08584 function feedback_qtype_listbox($type) 08585 { 08586 global $CONFIG, $strRating, $strOptions, $strMultipleOptions, $strText; 08587 08588 $html .= "<select name='type'>\n"; 08589 $html .= "<option value='rating'"; 08590 if ($type == 'rating') $html .= " selected='selected'"; 08591 $html .= ">{$strRating}</option>"; 08592 08593 $html .= "<option value='options'"; 08594 if ($type == 'options') $html .= " selected='selected'"; 08595 $html .= ">{$strOptions}</option>"; 08596 08597 $html .= "<option value='multioptions'"; 08598 if ($type == 'multioptions') $html .= " selected='selected'"; 08599 $html .= ">{$strMultipleOptions}</option>"; 08600 08601 $html .= "<option value='text'"; 08602 if ($type == 'text') $html .= " selected='selected'"; 08603 $html .= ">{$strText}</option>"; 08604 08605 $html .= "</select>\n"; 08606 08607 return $html; 08608 } 08609 08610 08611 function mime_type($file) 08612 { 08613 if (function_exists("mime_content_type")) 08614 { 08615 return mime_content_type($file); 08616 } 08617 elseif (DIRECTORY_SEPARATOR == '/') 08618 { 08619 //This only works on *nix, but better than failing 08620 $file = escapeshellarg($file); 08621 $mime = shell_exec("file -bi " . $file); 08622 return $mime; 08623 } 08624 else 08625 { 08626 return 'application/octet-stream'; 08627 } 08628 } 08629 08630 // ** Place no more function defs below this ** 08631 08632 08633 // These are the modules that we are dependent on, without these something 08634 // or everything will fail, so let's throw an error here. 08635 // Check that the correct modules are loaded 08636 if (!extension_loaded('mysql')) trigger_error('SiT requires the php/mysql module', E_USER_ERROR); 08637 if (!extension_loaded('imap') AND $CONFIG['enable_inbound_mail'] == 'POP/IMAP') 08638 { 08639 trigger_error('SiT requires the php IMAP module to recieve incoming mail.' 08640 .' If you really don\'t need this, you can set $CONFIG[\'enable_inbound_mail\'] to false'); 08641 } 08642 if (version_compare(PHP_VERSION, "5.0.0", "<")) trigger_error('INFO: You are running an older PHP version, some features may not work properly.', E_USER_NOTICE); 08643 if (@ini_get('register_globals') == 1 OR strtolower(@ini_get('register_globals')) == 'on') 08644 { 08645 trigger_error('Error: php.ini MUST have register_globals set to off, there are potential security risks involved with leaving it as it is!', E_USER_ERROR); 08646 die('Stopping SiT now, fix your php and try again.'); 08647 } 08648 08649 ?>
For more help developing with SiT! see http://sitracker.org/wiki/DevelopmentHowTo