PageRenderTime 70ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 1ms

/lib/functions.inc.php

https://github.com/nicdev007/sitracker
PHP | 8271 lines | 6657 code | 583 blank | 1031 comment | 727 complexity | 1810309353abba2fe30fb3015ee75462 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. // functions.inc.php - Function library and defines for SiT -Support Incident Tracker
  3. //
  4. // SiT (Support Incident Tracker) - Support call tracking system
  5. // Copyright (C) 2000-2009 Salford Software Ltd. and Contributors
  6. //
  7. // This software may be used and distributed according to the terms
  8. // of the GNU General Public License, incorporated herein by reference.
  9. //
  10. // Authors: Ivan Lucas, <ivanlucas[at]users.sourceforge.net>
  11. // Tom Gerrard, <tomgerrard[at]users.sourceforge.net> - 2001 onwards
  12. // Martin Kilcoyne - 2000
  13. // Paul Heaney, <paulheaney[at]users.sourceforge.net>
  14. // Kieran Hogg, <kieran[at]sitracker.org>
  15. // Many functions here simply extract various snippets of information from
  16. // Most are legacy and can replaced by improving the pages that call them to
  17. // use SQL joins.
  18. // Prevent script from being run directly (ie. it must always be included
  19. if (realpath(__FILE__) == realpath($_SERVER['SCRIPT_FILENAME']))
  20. {
  21. exit;
  22. }
  23. include (APPLICATION_LIBPATH . 'classes.inc.php');
  24. include (APPLICATION_LIBPATH . 'group.class.php');
  25. include (APPLICATION_LIBPATH . 'user.class.php');
  26. include (APPLICATION_LIBPATH . 'contact.class.php');
  27. include (APPLICATION_LIBPATH . 'incident.class.php');
  28. include (APPLICATION_LIBPATH . 'ldap.inc.php');
  29. include (APPLICATION_LIBPATH . 'base.inc.php');
  30. include_once (APPLICATION_LIBPATH . 'billing.inc.php');
  31. include_once (APPLICATION_LIBPATH . 'user.inc.php');
  32. include_once (APPLICATION_LIBPATH . 'sla.inc.php');
  33. include_once (APPLICATION_LIBPATH . 'ftp.inc.php');
  34. include_once (APPLICATION_LIBPATH . 'tags.inc.php');
  35. include_once (APPLICATION_LIBPATH . 'string.inc.php');
  36. include_once (APPLICATION_LIBPATH . 'html.inc.php');
  37. include_once (APPLICATION_LIBPATH . 'tasks.inc.php');
  38. include_once (APPLICATION_LIBPATH . 'export.inc.php');
  39. // function stripslashes_array($data)
  40. // {
  41. // if (is_array($data))
  42. // {
  43. // foreach ($data as $key => $value)
  44. // {
  45. // $data[$key] = stripslashes_array($value);
  46. // }
  47. // return $data;
  48. // }
  49. // else
  50. // {
  51. // return stripslashes($data);
  52. // }
  53. // }
  54. if (version_compare(PHP_VERSION, "5.1.0", ">="))
  55. {
  56. date_default_timezone_set($CONFIG['timezone']);
  57. }
  58. //Prevent Magic Quotes from affecting scripts, regardless of server settings
  59. //Make sure when reading file data,
  60. //PHP doesn't "magically" mangle backslashes!
  61. set_magic_quotes_runtime(FALSE);
  62. if (get_magic_quotes_gpc())
  63. {
  64. // All these global variables are slash-encoded by default,
  65. // because magic_quotes_gpc is set by default!
  66. // (And magic_quotes_gpc affects more than just $_GET, $_POST, and $_COOKIE)
  67. // We don't strip slashes from $_FILES as of 3.32 as this should be safe without
  68. // doing and it will break windows file paths if we do
  69. $_SERVER = stripslashes_array($_SERVER);
  70. $_GET = stripslashes_array($_GET);
  71. $_POST = stripslashes_array($_POST);
  72. $_COOKIE = stripslashes_array($_COOKIE);
  73. $_ENV = stripslashes_array($_ENV);
  74. $_REQUEST = stripslashes_array($_REQUEST);
  75. $HTTP_SERVER_VARS = stripslashes_array($HTTP_SERVER_VARS);
  76. $HTTP_GET_VARS = stripslashes_array($HTTP_GET_VARS);
  77. $HTTP_POST_VARS = stripslashes_array($HTTP_POST_VARS);
  78. $HTTP_COOKIE_VARS = stripslashes_array($HTTP_COOKIE_VARS);
  79. $HTTP_POST_FILES = stripslashes_array($HTTP_POST_FILES);
  80. $HTTP_ENV_VARS = stripslashes_array($HTTP_ENV_VARS);
  81. if (isset($_SESSION))
  82. {
  83. #These are unconfirmed (?)
  84. $_SESSION = stripslashes_array($_SESSION, '');
  85. $HTTP_SESSION_VARS = stripslashes_array($HTTP_SESSION_VARS, '');
  86. }
  87. // The $GLOBALS array is also slash-encoded, but when all the above are
  88. // changed, $GLOBALS is updated to reflect those changes. (Therefore
  89. // $GLOBALS should never be modified directly). $GLOBALS also contains
  90. // infinite recursion, so it's dangerous...
  91. }
  92. /**
  93. * Authenticate a user with a username/password pair
  94. * @author Ivan Lucas
  95. * @param string $username. A username
  96. * @param string $password. A password (non-md5)
  97. * @return an integer to indicate whether the user authenticated against the database
  98. * @retval int 0 the credentials were wrong or the user was not found.
  99. * @retval int 1 to indicate user is authenticated and allowed to continue.
  100. */
  101. function authenticateSQL($username, $password)
  102. {
  103. global $dbUsers;
  104. $password = md5($password);
  105. if ($_SESSION['auth'] == TRUE)
  106. {
  107. // Already logged in
  108. return 1;
  109. }
  110. // extract user
  111. $sql = "SELECT id FROM `{$dbUsers}` ";
  112. $sql .= "WHERE username = '{$username}' AND password = '{$password}' AND status != 0 ";
  113. // a status of 0 means the user account is disabled
  114. $result = mysql_query($sql);
  115. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  116. // return appropriate value
  117. if (mysql_num_rows($result) == 0)
  118. {
  119. mysql_free_result($result);
  120. return 0;
  121. }
  122. else
  123. {
  124. journal(CFG_LOGGING_MAX,'User Authenticated',"{$username} authenticated from " . getenv('REMOTE_ADDR'),CFG_JOURNAL_LOGIN,0);
  125. return 1;
  126. }
  127. }
  128. /**
  129. * Authenticate a user
  130. * @author Lea Anthony
  131. * @param string $username. Username
  132. * @param string $password. Password
  133. * @return an integer to indicate whether the user authenticated against any authentication backends
  134. * @retval bool false the credentials were wrong or the user was not found.
  135. * @retval bool true to indicate user is authenticated and allowed to continue.
  136. */
  137. function authenticate($username, $password)
  138. {
  139. global $CONFIG;
  140. $toReturn = false;
  141. $sql = "SELECT id, password, status, user_source FROM `{$GLOBALS['dbUsers']}` WHERE username = '{$username}'";
  142. $result = mysql_query($sql);
  143. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  144. if (mysql_num_rows($result) == 1)
  145. {
  146. // Exist in SiT DB
  147. $obj = mysql_fetch_object($result);
  148. if ($obj->user_source == 'sit')
  149. {
  150. if (md5($password) == $obj->password AND $obj->status != 0) $toReturn = true;
  151. else $toReturn = false;
  152. }
  153. elseif ($obj->user_source == 'ldap')
  154. {
  155. // Auth against LDAP and sync
  156. $toReturn = authenticateLDAP($username, $password, $obj->id);
  157. if ($toReturn === -1)
  158. {
  159. // Communication with LDAP server failed
  160. if ($CONFIG['ldap_allow_cached_password'])
  161. {
  162. // Use cached password
  163. if (md5($password) == $obj->password AND $obj->status != 0) $toReturn = true;
  164. else $toReturn = false;
  165. }
  166. else
  167. {
  168. $toReturn = false;
  169. }
  170. }
  171. elseif ($toReturn)
  172. {
  173. $toReturn = true;
  174. }
  175. else
  176. {
  177. $toReturn = false;
  178. }
  179. }
  180. }
  181. elseif (mysql_num_rows($result) > 1)
  182. {
  183. // Multiple this should NEVER happen
  184. trigger_error($GLOBALS['strUsernameNotUnique'], E_USER_ERROR);
  185. $toReturn = false;
  186. }
  187. else
  188. {
  189. // Don't exist, check LDAP etc
  190. if ($CONFIG['use_ldap'])
  191. {
  192. $toReturn = authenticateLDAP($username, $password);
  193. if ($toReturn === -1) $toReturn = false;
  194. }
  195. }
  196. if ($toReturn)
  197. {
  198. journal(CFG_LOGGING_MAX,'User Authenticated',"{$username} authenticated from " . getenv('REMOTE_ADDR'),CFG_JOURNAL_LOGIN,0);
  199. }
  200. debug_log ("authenticate returning {$toReturn}");
  201. return $toReturn;
  202. }
  203. function authenticateContact($username, $password)
  204. {
  205. debug_log ("authenticateContact called");
  206. global $CONFIG;
  207. $toReturn = false;
  208. $sql = "SELECT id, password, contact_source, active FROM `{$GLOBALS['dbContacts']}` WHERE username = '{$username}'";
  209. $result = mysql_query($sql);
  210. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  211. if (mysql_num_rows($result) == 1)
  212. {
  213. debug_log ("Authenticate: Just one contact in db");
  214. // Exists in SiT DB
  215. $obj = mysql_fetch_object($result);
  216. if ($obj->contact_source == 'sit')
  217. {
  218. if ((md5($password) == $obj->password OR $password == $obj->password) AND $obj->active == 'true') $toReturn = true;
  219. else $toReturn = false;
  220. }
  221. elseif ($obj->contact_source == 'ldap')
  222. {
  223. // Auth against LDAP and sync
  224. $toReturn = authenticateLDAP($username, $password, $obj->id, false);
  225. if ($toReturn === -1)
  226. {
  227. // Communication with LDAP server failed
  228. if ($CONFIG['ldap_allow_cached_password'])
  229. {
  230. debug_log ("LDAP connection failed, using cached password");
  231. // Use cached password
  232. if ((md5($password) == $obj->password OR $password == $obj->password) AND $obj->active == 'true') $toReturn = true;
  233. else $toReturn = false;
  234. debug_log ("Cached contact {$toReturn} {$password}");
  235. }
  236. else
  237. {
  238. debug_log ("Cached passwords are not enabled");
  239. $toReturn = false;
  240. }
  241. }
  242. elseif ($toReturn)
  243. {
  244. $toReturn = true;
  245. }
  246. else
  247. {
  248. $toReturn = false;
  249. }
  250. }
  251. else
  252. {
  253. debug_log ("Source SOMETHING ELSE this shouldn't happen'");
  254. $toReturn = false;
  255. }
  256. }
  257. elseif (mysql_num_rows($result) > 1)
  258. {
  259. debug_log ("Multiple");
  260. // Multiple this should NEVER happen
  261. trigger_error($GLOBALS['strUsernameNotUnique'], E_USER_ERROR);
  262. $toReturn = false;
  263. }
  264. else
  265. {
  266. debug_log ("Authenticate: No matching contact found in db");
  267. // Don't exist, check LDAP etc
  268. if ($CONFIG['use_ldap'])
  269. {
  270. $toReturn = authenticateLDAP($username, $password, 0, false);
  271. if ($toReturn === -1) $toReturn = false;
  272. }
  273. }
  274. debug_log ("authenticateContact returning {$toReturn}");
  275. return $toReturn;
  276. }
  277. /**
  278. * See if a customer exists in the database
  279. * @author Lea Anthony
  280. * @param string $username. Username of customer
  281. * @retval bool TRUE exists in db
  282. * @retval bool FALSE does not exist in db
  283. */
  284. function customerExistsInDB($username)
  285. {
  286. global $dbContacts;
  287. $exists = 0;
  288. $sql = "SELECT id FROM `{$dbContacts}` WHERE username='$username'";
  289. $result = mysql_query($sql);
  290. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_ERROR);
  291. while( $res = mysql_fetch_array($result) )
  292. {
  293. $exists = 1;
  294. }
  295. return $exists;
  296. }
  297. /**
  298. * Returns a specified column from a specified table in the database given an ID primary key
  299. * @author Ivan Lucas
  300. * @param string $column a database column
  301. * @param string $table a database table
  302. * @param int $id the primary key / id column
  303. * @return A column from the database
  304. * @note it's not always efficient to read a single column at a time, but when you only need
  305. * one column, this is handy
  306. */
  307. function db_read_column($column, $table, $id)
  308. {
  309. $sql = "SELECT `$column` FROM `{$table}` WHERE id ='$id' LIMIT 1";
  310. $result = mysql_query($sql);
  311. if (mysql_error()) trigger_error("MySQL Query Error ".mysql_error(), E_USER_WARNING);
  312. if (mysql_num_rows($result) == 0)
  313. {
  314. $column = FALSE;
  315. }
  316. else
  317. {
  318. list($column) = mysql_fetch_row($result);
  319. }
  320. return $column;
  321. }
  322. /**
  323. * @author Ivan Lucas
  324. */
  325. function permission_name($permissionid)
  326. {
  327. global $dbPermissions;
  328. $name = db_read_column('name', $dbPermissions, $permissionid);
  329. if (empty($name)) $name = $GLOBALS['strUnknown'];
  330. return $name;
  331. }
  332. /**
  333. * Get the name associated with software ID / skill ID
  334. * @author Ivan Lucas
  335. * @param int $softwareid
  336. * @returns string. Skill/Software Name
  337. * @note Software was renamed skills for v3.30
  338. */
  339. function software_name($softwareid)
  340. {
  341. global $now, $dbSoftware, $strEOL, $strEndOfLife;
  342. $sql = "SELECT * FROM `{$dbSoftware}` WHERE id = '{$softwareid}'";
  343. $result = mysql_query($sql);
  344. if (mysql_num_rows($result) >= 1)
  345. {
  346. $software = mysql_fetch_object($result);
  347. $lifetime_end = mysql2date($software->lifetime_end);
  348. if ($lifetime_end > 0 AND $lifetime_end < $now)
  349. {
  350. $name = "<span class='deleted'>{$software->name}</span> (<abbr title='{$strEndOfLife}'>{$strEOL}</abbr>)";
  351. }
  352. else
  353. {
  354. $name = $software->name;
  355. }
  356. }
  357. else
  358. {
  359. $name = $GLOBALS['strUnknown'];
  360. }
  361. return $name;
  362. }
  363. /**
  364. * Find a contacts real name
  365. * @author Ivan Lucas
  366. * @param int $id. Contact ID
  367. * @returns string. Full name or 'Unknown'
  368. */
  369. function contact_realname($id)
  370. {
  371. global $dbContacts;
  372. $sql = "SELECT forenames, surname FROM `{$dbContacts}` WHERE id='$id'";
  373. $result = mysql_query($sql);
  374. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  375. if (mysql_num_rows($result) == 0)
  376. {
  377. mysql_free_result($result);
  378. return ($GLOBALS['strUnknown']);
  379. }
  380. else
  381. {
  382. $contact = mysql_fetch_object($result);
  383. $realname = "{$contact->forenames} {$contact->surname}";
  384. mysql_free_result($result);
  385. return $realname;
  386. }
  387. }
  388. /**
  389. * Return a contacts site name
  390. * @author Ivan Lucas
  391. * @param int $id. Contact ID
  392. * @returns string. Full site name or 'Unknown'
  393. * @note this returns the site _NAME_ not the siteid for the site id use contact_siteid()
  394. */
  395. function contact_site($id)
  396. {
  397. global $dbContacts, $dbSites;
  398. //
  399. $sql = "SELECT s.name FROM `{$dbContacts}` AS c, `{$dbSites}` AS s WHERE c.siteid = s.id AND c.id = '$id'";
  400. $result = mysql_query($sql);
  401. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  402. if (mysql_num_rows($result) == 0)
  403. {
  404. mysql_free_result($result);
  405. return $GLOBALS['strUnknown'];
  406. }
  407. else
  408. {
  409. list($contactsite) = mysql_fetch_row($result);
  410. mysql_free_result($result);
  411. $contactsite = $contactsite;
  412. return $contactsite;
  413. }
  414. }
  415. /**
  416. * Return a contacts site ID
  417. * @author Ivan Lucas
  418. * @param int $id. Contact ID
  419. * @returns int. Site ID
  420. */
  421. function contact_siteid($id)
  422. {
  423. return db_read_column('siteid', $GLOBALS['dbContacts'], $id);
  424. }
  425. /**
  426. * Return a contacts email address
  427. * @author Ivan Lucas
  428. * @param int $id. Contact ID
  429. * @returns string. Email address
  430. */
  431. function contact_email($id)
  432. {
  433. return db_read_column('email', $GLOBALS['dbContacts'], $id);
  434. }
  435. /**
  436. * Return a contacts phone number
  437. * @author Ivan Lucas
  438. * @param integer $id. Contact ID
  439. * @returns string. Phone number
  440. */
  441. function contact_phone($id)
  442. {
  443. return db_read_column('phone', $GLOBALS['dbContacts'], $id);
  444. }
  445. /**
  446. * Return a contacts fax number
  447. * @author Ivan Lucas
  448. * @param int $id. Contact ID
  449. * @returns string. Fax number
  450. */
  451. function contact_fax($id)
  452. {
  453. return db_read_column('fax', $GLOBALS['dbContacts'], $id);
  454. }
  455. /**
  456. * Return the number of incidents ever logged against a contact
  457. * @author Ivan Lucas
  458. * @param int $id. Contact ID
  459. * @returns int.
  460. */
  461. function contact_count_incidents($id)
  462. {
  463. global $dbIncidents;
  464. $count = 0;
  465. $sql = "SELECT COUNT(id) FROM `{$dbIncidents}` WHERE contact='$id'";
  466. $result = mysql_query($sql);
  467. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  468. else list($count) = mysql_fetch_row($result);
  469. mysql_free_result($result);
  470. return $count;
  471. }
  472. /**
  473. * Return the number of incidents ever logged against a site
  474. * @author Kieran
  475. * @param int $id. Site ID
  476. * @returns int.
  477. */
  478. function site_count_incidents($id)
  479. {
  480. global $dbIncidents, $dbContacts;
  481. $id = intval($id);
  482. $count = 0;
  483. $sql = "SELECT COUNT(i.id) FROM `{$dbIncidents}` AS i, `{$dbContacts}` as c ";
  484. $sql .= "WHERE i.contact = c.id ";
  485. $sql .= "AND c.siteid='$id'";
  486. $result = mysql_query($sql);
  487. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  488. else list($count) = mysql_fetch_row($result);
  489. mysql_free_result($result);
  490. return $count;
  491. }
  492. /**
  493. * Return the number of inventory items for a site
  494. * @author Kieran
  495. * @param int $id. Site ID
  496. * @returns int.
  497. */
  498. function site_count_inventory_items($id)
  499. {
  500. global $dbInventory;
  501. $count = 0;
  502. $sql = "SELECT COUNT(id) FROM `{$dbInventory}` WHERE siteid='$id'";
  503. $result = mysql_query($sql);
  504. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  505. else list($count) = mysql_fetch_row($result);
  506. mysql_free_result($result);
  507. return $count;
  508. }
  509. /**
  510. * Return the number of inventory items for a contact
  511. * @author Kieran
  512. * @param int $id. Contact ID
  513. * @returns int.
  514. */
  515. function contact_count_inventory_items($id)
  516. {
  517. global $dbInventory;
  518. $count = 0;
  519. $sql = "SELECT COUNT(id) FROM `{$dbInventory}` WHERE contactid='$id'";
  520. $result = mysql_query($sql);
  521. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  522. else list($count) = mysql_fetch_row($result);
  523. mysql_free_result($result);
  524. return $count;
  525. }
  526. /**
  527. * The number representing the total number of currently OPEN incidents submitted by a given contact.
  528. * @author Ivan Lucas
  529. * @param int $id. The Contact ID to check
  530. * @returns integer. The number of currently OPEN incidents for the given contact
  531. */
  532. function contact_count_open_incidents($id)
  533. {
  534. global $dbIncidents;
  535. $sql = "SELECT COUNT(id) FROM `{$dbIncidents}` WHERE contact=$id AND status<>2";
  536. $result = mysql_query($sql);
  537. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  538. list($count) = mysql_fetch_row($result);
  539. mysql_free_result($result);
  540. return $count;
  541. }
  542. /**
  543. * Creates a vcard electronic business card for the given contact
  544. * @author Ivan Lucas
  545. * @param int $id Contact ID
  546. * @returns string vcard
  547. */
  548. function contact_vcard($id)
  549. {
  550. global $dbContacts, $dbSites;
  551. $sql = "SELECT *, s.name AS sitename, s.address1 AS siteaddress1, s.address2 AS siteaddress2, ";
  552. $sql .= "s.city AS sitecity, s.county AS sitecounty, s.country AS sitecountry, s.postcode AS sitepostcode ";
  553. $sql .= "FROM `{$dbContacts}` AS c, `{$dbSites}` AS s ";
  554. $sql .= "WHERE c.siteid = s.id AND c.id = '$id' LIMIT 1";
  555. $result = mysql_query($sql);
  556. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  557. $contact = mysql_fetch_object($result);
  558. $vcard = "BEGIN:VCARD\r\n";
  559. $vcard .= "N:{$contact->surname};{$contact->forenames};{$contact->courtesytitle}\r\n";
  560. $vcard .= "FN:{$contact->forenames} {$contact->surname}\r\n";
  561. if (!empty($contact->jobtitle)) $vcard .= "TITLE:{$contact->jobtitle}\r\n";
  562. if (!empty($contact->sitename)) $vcard .= "ORG:{$contact->sitename}\r\n";
  563. if ($contact->dataprotection_phone != 'Yes') $vcard .= "TEL;TYPE=WORK:{$contact->phone}\r\n";
  564. if ($contact->dataprotection_phone != 'Yes' && !empty($contact->fax))
  565. {
  566. $vcard .= "TEL;TYPE=WORK;TYPE=FAX:{$contact->fax}\r\n";
  567. }
  568. if ($contact->dataprotection_phone != 'Yes' && !empty($contact->mobile))
  569. {
  570. $vcard .= "TEL;TYPE=WORK;TYPE=CELL:{$contact->mobile}\r\n";
  571. }
  572. if ($contact->dataprotection_email != 'Yes' && !empty($contact->email))
  573. {
  574. $vcard .= "EMAIL;TYPE=INTERNET:{$contact->email}\r\n";
  575. }
  576. if ($contact->dataprotection_address != 'Yes')
  577. {
  578. if ($contact->address1 != '')
  579. {
  580. $vcard .= "ADR;WORK:{$contact->address1};{$contact->address2};{$contact->city};{$contact->county};{$contact->postcode};{$contact->country}\r\n";
  581. }
  582. else
  583. {
  584. $vcard .= "ADR;WORK:{$contact->siteaddress1};{$contact->siteaddress2};{$contact->sitecity};{$contact->sitecounty};{$contact->sitepostcode};{$contact->sitecountry}\r\n";
  585. }
  586. }
  587. if (!empty($contact->notes))
  588. {
  589. $vcard .= "NOTE:{$contact->notes}\r\n";
  590. }
  591. $vcard .= "REV:".iso_8601_date($contact->timestamp_modified)."\r\n";
  592. $vcard .= "END:VCARD\r\n";
  593. return $vcard;
  594. }
  595. /**
  596. * @author Ivan Lucas
  597. * @param int $id Incident ID
  598. * @returns integer. UserID of the user that currently owns the incident
  599. */
  600. function incident_owner($id)
  601. {
  602. return db_read_column('owner', $GLOBALS['dbIncidents'], $id);
  603. }
  604. /**
  605. * @author Ivan Lucas
  606. * @param int $id Incident ID
  607. * @returns integer. UserID of the user that currently temporarily owns the incident
  608. */
  609. function incident_towner($id)
  610. {
  611. return db_read_column('towner', $GLOBALS['dbIncidents'], $id);
  612. }
  613. /**
  614. * @author Ivan Lucas
  615. * @param int $id Incident ID
  616. * @returns integer. ContactID of the contact this incident is logged against
  617. */
  618. function incident_contact($id)
  619. {
  620. return db_read_column('contact', $GLOBALS['dbIncidents'], $id);
  621. }
  622. /**
  623. * @author Ivan Lucas
  624. * @param int $id Incident ID
  625. * @returns integer. Contract ID of the maintenance contract this incident is logged against
  626. */
  627. function incident_maintid($id)
  628. {
  629. $maintid = db_read_column('maintenanceid', $GLOBALS['dbIncidents'], $id);
  630. if ($maintid == '')
  631. {
  632. trigger_error("!Error: No matching record while reading in incident_maintid() Incident ID: {$id}", E_USER_WARNING);
  633. }
  634. else
  635. {
  636. return ($maintid);
  637. }
  638. }
  639. /**
  640. * @author Ivan Lucas
  641. * @param int $id Incident ID
  642. * @returns string. Title of the incident
  643. */
  644. function incident_title($id)
  645. {
  646. return db_read_column('title', $GLOBALS['dbIncidents'], $id);
  647. }
  648. /**
  649. * @author Ivan Lucas
  650. * @param int $id Incident ID
  651. * @returns id. Current incident status ID
  652. */
  653. function incident_status($id)
  654. {
  655. return db_read_column('status', $GLOBALS['dbIncidents'], $id);
  656. }
  657. /**
  658. * @author Ivan Lucas
  659. * @param int $id Incident ID
  660. * @returns id. Current incident Priority ID
  661. */
  662. function incident_priority($id)
  663. {
  664. return db_read_column('priority', $GLOBALS['dbIncidents'], $id);
  665. }
  666. /**
  667. * @author Ivan Lucas
  668. * @param int $id Incident ID
  669. * @returns id. Current incident external ID
  670. */
  671. function incident_externalid($id)
  672. {
  673. return db_read_column('externalid', $GLOBALS['dbIncidents'], $id);
  674. }
  675. /**
  676. * @author Ivan Lucas
  677. * @param int $id Incident ID
  678. * @returns string. Current incident external engineer
  679. */
  680. function incident_externalengineer($id)
  681. {
  682. return db_read_column('externalengineer', $GLOBALS['dbIncidents'], $id);
  683. }
  684. /**
  685. * @author Ivan Lucas
  686. * @param int $id Incident ID
  687. * @returns string. Current incident external email address
  688. */
  689. function incident_externalemail($id)
  690. {
  691. return db_read_column('externalemail', $GLOBALS['dbIncidents'], $id);
  692. }
  693. /**
  694. * @author Ivan Lucas
  695. * @param int $id Incident ID
  696. * @returns string. Current incident CC email address
  697. */
  698. function incident_ccemail($id)
  699. {
  700. return db_read_column('ccemail', $GLOBALS['dbIncidents'], $id);
  701. }
  702. /**
  703. * @author Ivan Lucas
  704. * @param int $id Incident ID
  705. * @returns int. UNIX Timestamp of the time of the next action for this incident
  706. */
  707. function incident_timeofnextaction($id)
  708. {
  709. return db_read_column('timeofnextaction', $GLOBALS['dbIncidents'], $id);
  710. }
  711. /**
  712. * Returns a string of HTML nicely formatted for the incident details page containing any additional
  713. * product info for the given incident.
  714. * @author Ivan Lucas
  715. * @param int $incidentid The incident ID
  716. * @returns string HTML
  717. */
  718. function incident_productinfo_html($incidentid)
  719. {
  720. global $dbProductInfo, $dbIncidentProductInfo, $strNoProductInfo;
  721. // TODO extract appropriate product info rather than *
  722. $sql = "SELECT *, TRIM(incidentproductinfo.information) AS info FROM `{$dbProductInfo}` AS p, {$dbIncidentProductInfo}` ipi ";
  723. $sql .= "WHERE incidentid = $incidentid AND productinfoid = p.id AND TRIM(p.information) !='' ";
  724. $result = mysql_query($sql);
  725. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  726. if (mysql_num_rows($result) == 0)
  727. {
  728. return ('<tr><td>{$strNoProductInfo}</td><td>{$strNoProductInfo}</td></tr>');
  729. }
  730. else
  731. {
  732. // generate HTML
  733. while ($productinfo = mysql_fetch_object($result))
  734. {
  735. if (!empty($productinfo->info))
  736. {
  737. $html = "<tr><th>{$productinfo->moreinformation}:</th><td>";
  738. $html .= urlencode($productinfo->info);
  739. $html .= "</td></tr>\n";
  740. }
  741. }
  742. echo $html;
  743. }
  744. }
  745. /**
  746. * prints the HTML for a drop down list of contacts, with the given name
  747. * and with the given id selected.
  748. * @author Ivan Lucas
  749. */
  750. function contact_drop_down($name, $id, $showsite = FALSE, $required = FALSE)
  751. {
  752. global $dbContacts, $dbSites;
  753. if ($showsite)
  754. {
  755. $sql = "SELECT c.id AS contactid, s.id AS siteid, surname, forenames, ";
  756. $sql .= "s.name AS sitename, s.department AS department ";
  757. $sql .= "FROM `{$dbContacts}` AS c, `{$dbSites}` AS s WHERE c.siteid = s.id AND c.active = 'true' ";
  758. $sql .= "AND s.active = 'true' ";
  759. $sql .= "ORDER BY s.name, s.department, surname ASC, forenames ASC";
  760. }
  761. else
  762. {
  763. $sql = "SELECT c.id AS contactid, surname, forenames FROM `{$dbContacts}` AS c, `{$dbSites}` AS s ";
  764. $sql .= "WHERE c.siteid = s.id AND s.active = 'true' AND c.active = 'true' ";
  765. $sql .= "ORDER BY forenames ASC, surname ASC";
  766. }
  767. $result = mysql_query($sql);
  768. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  769. $html = "<select name='$name' id='$name'";
  770. if ($required)
  771. {
  772. $html .= " class='required' ";
  773. }
  774. $html .= ">\n";
  775. if ($id == 0)
  776. {
  777. $html .= "<option selected='selected' value='0'></option>\n";
  778. }
  779. $prevsite=0;
  780. while ($contacts = mysql_fetch_object($result))
  781. {
  782. if ($showsite AND $prevsite != $contacts->siteid AND $prevsite != 0)
  783. {
  784. $html .= "</optgroup>\n";
  785. }
  786. if ($showsite AND $prevsite != $contacts->siteid)
  787. {
  788. $html .= "<optgroup label='".htmlentities($contacts->sitename, ENT_COMPAT, 'UTF-8').", ".htmlentities($contacts->department, ENT_COMPAT, $GLOBALS['i18ncharset'])."'>";
  789. }
  790. $realname = "{$contacts->forenames} {$contacts->surname}";
  791. $html .= "<option ";
  792. if ($contacts->contactid == $id)
  793. {
  794. $html .= "selected='selected' ";
  795. }
  796. $html .= "value='{$contacts->contactid}'>{$realname}";
  797. $html .= "</option>\n";
  798. $prevsite = $contacts->siteid;
  799. }
  800. if ($showsite)
  801. {
  802. $html.= "</optgroup>";
  803. }
  804. $html .= "</select>\n";
  805. return $html;
  806. }
  807. /**
  808. * prints the HTML for a drop down list of contacts along with their site, with the given name and
  809. * and with the given id selected.
  810. * @author Ivan Lucas
  811. * @param string $name. The name of the field
  812. * @param int $id. Select this contactID by default
  813. * @param int $siteid. (optional) Filter list to show contacts from this siteID only
  814. * @param mixed $exclude int|array (optional) Do not show this contactID in the list, accepts an integer or array of integers
  815. * @param bool $showsite (optional) Suffix the name with the site name
  816. * @param bool $allownone (optional) Allow 'none' to be selected (blank value)
  817. * @returns string. HTML select
  818. */
  819. function contact_site_drop_down($name, $id, $siteid='', $exclude='', $showsite=TRUE, $allownone=FALSE)
  820. {
  821. global $dbContacts, $dbSites;
  822. $sql = "SELECT c.id AS contactid, forenames, surname, siteid, s.name AS sitename ";
  823. $sql .= "FROM `{$dbContacts}` AS c, `{$dbSites}` AS s ";
  824. $sql .= "WHERE c.siteid = s.id AND c.active = 'true' AND s.active = 'true' ";
  825. if (!empty($siteid)) $sql .= "AND s.id='$siteid' ";
  826. if (!empty($exclude))
  827. {
  828. if (is_array($exclude))
  829. {
  830. foreach ($exclude AS $contactid)
  831. {
  832. $sql .= "AND c.id != $contactid ";
  833. }
  834. }
  835. else
  836. {
  837. $sql .= "AND c.id != $exclude ";
  838. }
  839. }
  840. $sql .= "ORDER BY surname ASC";
  841. $result = mysql_query($sql);
  842. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  843. $html = "<select name='$name'>";
  844. if (mysql_num_rows($result) > 0)
  845. {
  846. if ($allownone) $html .= "<option value='' selected='selected'>{$GLOBALS['strNone']}</option>";
  847. while ($contacts = mysql_fetch_object($result))
  848. {
  849. $html .= "<option ";
  850. if ($contacts->contactid == $id)
  851. {
  852. $html .= "selected='selected' ";
  853. }
  854. $html .= "value='{$contacts->contactid}'>";
  855. if ($showsite)
  856. {
  857. $html .= htmlspecialchars("{$contacts->surname}, {$contacts->forenames} - {$contacts->sitename}");
  858. }
  859. else
  860. {
  861. $html .= htmlspecialchars("{$contacts->surname}, {$contacts->forenames}");
  862. }
  863. $html .= "</option>\n";
  864. }
  865. }
  866. else $html .= "<option value=''>{$GLOBALS['strNone']}</option>";
  867. $html .= "</select>\n";
  868. return $html;
  869. }
  870. /**
  871. * HTML for a drop down list of products
  872. * @author Ivan Lucas
  873. * @param string $name. name/id to use for the select element
  874. * @param int $id. Product ID
  875. * @param bool $required.
  876. * @returns string. HTML select
  877. * @note With the given name and with the given id selected.
  878. */
  879. function product_drop_down($name, $id, $required = FALSE)
  880. {
  881. global $dbProducts;
  882. // extract products
  883. $sql = "SELECT id, name FROM `{$dbProducts}` ORDER BY name ASC";
  884. $result = mysql_query($sql);
  885. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  886. $html = "<select name='{$name}' id='{$name}'";
  887. if ($required)
  888. {
  889. $html .= " class='required' ";
  890. }
  891. $html .= ">";
  892. if ($id == 0)
  893. {
  894. $html .= "<option selected='selected' value='0'></option>\n";
  895. }
  896. while ($products = mysql_fetch_object($result))
  897. {
  898. $html .= "<option value='{$products->id}'";
  899. if ($products->id == $id)
  900. {
  901. $html .= " selected='selected'";
  902. }
  903. $html .= ">{$products->name}</option>\n";
  904. }
  905. $html .= "</select>\n";
  906. return $html;
  907. }
  908. /**
  909. * HTML for a drop down list of skills (was called software)
  910. * @author Ivan Lucas
  911. * @param string $name. name/id to use for the select element
  912. * @param int $id. Software ID
  913. * @returns HTML select
  914. */
  915. function skill_drop_down($name, $id)
  916. {
  917. global $now, $dbSoftware, $strEOL;
  918. // extract software
  919. $sql = "SELECT id, name, lifetime_end FROM `{$dbSoftware}` ";
  920. $sql .= "ORDER BY name ASC";
  921. $result = mysql_query($sql);
  922. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  923. $html = "<select name='{$name}' id='{$name}' >";
  924. if ($id == 0)
  925. {
  926. $html .= "<option selected='selected' value='0'>{$GLOBALS['strNone']}</option>\n";
  927. }
  928. while ($software = mysql_fetch_object($result))
  929. {
  930. $html .= "<option value='{$software->id}'";
  931. if ($software->id == $id)
  932. {
  933. $html .= " selected='selected'";
  934. }
  935. $html .= ">{$software->name}";
  936. $lifetime_start = mysql2date($software->lifetime_start);
  937. $lifetime_end = mysql2date($software->lifetime_end);
  938. if ($lifetime_end > 0 AND $lifetime_end < $now)
  939. {
  940. $html .= " ({$strEOL})";
  941. }
  942. $html .= "</option>\n";
  943. }
  944. $html .= "</select>\n";
  945. return $html;
  946. }
  947. /**
  948. * Generates a HTML dropdown of software products
  949. * @author Kieran Hogg
  950. * @param string $name. name/id to use for the select element
  951. * @returns HTML select
  952. */
  953. function softwareproduct_drop_down($name, $id, $productid, $visibility='internal')
  954. {
  955. global $dbSoftware, $dbSoftwareProducts;
  956. // extract software
  957. $sql = "SELECT id, name FROM `{$dbSoftware}` AS s, ";
  958. $sql .= "`{$dbSoftwareProducts}` AS sp WHERE s.id = sp.softwareid ";
  959. $sql .= "AND productid = '$productid' ";
  960. $sql .= "ORDER BY name ASC";
  961. $result = mysql_query($sql);
  962. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  963. if (mysql_num_rows($result) >=1)
  964. {
  965. $html = "<select name='$name' id='$name'>";
  966. if ($visibility == 'internal' AND $id == 0)
  967. {
  968. $html .= "<option selected='selected' value='0'></option>\n";
  969. }
  970. elseif ($visiblity = 'external' AND $id == 0)
  971. {
  972. $html .= "<option selected='selected' value=''>{$GLOBALS['strUnknown']}</option>\n";
  973. }
  974. while ($software = mysql_fetch_object($result))
  975. {
  976. $html .= "<option";
  977. if ($software->id == $id)
  978. {
  979. $html .= " selected='selected'";
  980. }
  981. $html .= " value='{$software->id}'>{$software->name}</option>\n";
  982. }
  983. $html .= "</select>\n";
  984. }
  985. else
  986. {
  987. $html = "-";
  988. }
  989. return $html;
  990. }
  991. /**
  992. * A HTML Select listbox for vendors
  993. * @author Ivan Lucas
  994. * @param string $name. name/id to use for the select element
  995. * @param int $id. Vendor ID to preselect
  996. * @returns HTML select
  997. */
  998. function vendor_drop_down($name, $id)
  999. {
  1000. global $dbVendors;
  1001. $sql = "SELECT id, name FROM `{$dbVendors}` ORDER BY name ASC";
  1002. $result = mysql_query($sql);
  1003. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1004. $html = "<select name='$name'>";
  1005. if ($id == 0)
  1006. {
  1007. $html .= "<option selected='selected' value='0'></option>\n";
  1008. }
  1009. while ($row = mysql_fetch_object($result))
  1010. {
  1011. $html .= "<option";
  1012. if ($row->id == $id)
  1013. {
  1014. $html .= " selected='selected'";
  1015. }
  1016. $html .= " value='{$row->id}'>{$row->name}</option>\n";
  1017. }
  1018. $html .= "</select>";
  1019. return $html;
  1020. }
  1021. /**
  1022. * A HTML Select listbox for Site Types
  1023. * @author Ivan Lucas
  1024. * @param string $name. name/id to use for the select element
  1025. * @param int $id. Site Type ID to preselect
  1026. * @todo TODO i18n needed site types
  1027. * @returns HTML select
  1028. */
  1029. function sitetype_drop_down($name, $id)
  1030. {
  1031. global $dbSiteTypes;
  1032. $sql = "SELECT typeid, typename FROM `{$dbSiteTypes}` ORDER BY typename ASC";
  1033. $result = mysql_query($sql);
  1034. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1035. $html .= "<select name='$name'>\n";
  1036. if ($id == 0)
  1037. {
  1038. $html .= "<option selected='selected' value='0'></option>\n";
  1039. }
  1040. while ($obj = mysql_fetch_object($result))
  1041. {
  1042. $html .= "<option ";
  1043. if ($obj->typeid == $id)
  1044. {
  1045. $html .="selected='selected' ";
  1046. }
  1047. $html .= "value='{$obj->typeid}'>{$obj->typename}</option>\n";
  1048. }
  1049. $html .= "</select>";
  1050. return $html;
  1051. }
  1052. /**
  1053. * Returns the HTML for a drop down list of upported products for the given contact and with the
  1054. * given name and with the given product selected
  1055. * @author Ivan Lucas
  1056. * @todo FIXME this should use the contract and not the contact
  1057. */
  1058. function supported_product_drop_down($name, $contactid, $productid)
  1059. {
  1060. global $CONFIG, $dbSupportContacts, $dbMaintenance, $dbProducts, $strXIncidentsLeft;
  1061. $sql = "SELECT *, p.id AS productid, p.name AS productname FROM `{$dbSupportContacts}` AS sc, `{$dbMaintenance}` AS m, `{$dbProducts}` AS p ";
  1062. $sql .= "WHERE sc.maintenanceid = m.id AND m.product = p.id ";
  1063. $sql .= "AND sc.contactid='$contactid'";
  1064. $result = mysql_query($sql);
  1065. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1066. if ($CONFIG['debug']) $html .= "<!-- Original product {$productid}-->";
  1067. $html .= "<select name=\"$name\">\n";
  1068. if ($productid == 0)
  1069. {
  1070. $html .= "<option selected='selected' value='0'>No Contract - Not Product Related</option>\n";
  1071. }
  1072. if ($productid == -1)
  1073. {
  1074. $html .= "<option selected='selected' value='0'></option>\n";
  1075. }
  1076. while ($products = mysql_fetch_objecy($result))
  1077. {
  1078. $remainingstring = sprintf($strXIncidentsLeft, incidents_remaining($products->incidentpoolid));
  1079. $html .= "<option ";
  1080. if ($productid == $products->productid)
  1081. {
  1082. $html .= "selected='selected' ";
  1083. }
  1084. $html .= "value='{$products->productid}'>";
  1085. $html .= servicelevel_name($products->servicelevelid)." ".$products->productname.", Exp:".date($CONFIG['dateformat_shortdate'], $products->expirydate).", $remainingstring";
  1086. $html .= "</option>\n";
  1087. }
  1088. $html .= "</select>\n";
  1089. return $html;
  1090. }
  1091. /**
  1092. * A HTML Select listbox for user roles
  1093. * @author Ivan Lucas
  1094. * @param string $name. name to use for the select element
  1095. * @param int $id. Role ID to preselect
  1096. * @returns HTML select
  1097. */
  1098. function role_drop_down($name, $id)
  1099. {
  1100. global $dbRoles;
  1101. $sql = "SELECT id, rolename FROM `{$dbRoles}` ORDER BY rolename ASC";
  1102. $result = mysql_query($sql);
  1103. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1104. $html = "<select name='{$name}'>";
  1105. if ($id == 0)
  1106. {
  1107. $html .= "<option selected='selected' value='0'></option>\n";
  1108. }
  1109. while ($role = mysql_fetch_object($result))
  1110. {
  1111. $html .= "<option value='{$role->id}'";
  1112. if ($role->id == $id)
  1113. {
  1114. $html .= " selected='selected'";
  1115. }
  1116. $html .= ">{$role->rolename}</option>\n";
  1117. }
  1118. $html .= "</select>\n";
  1119. return $html;
  1120. }
  1121. /**
  1122. * A HTML Select listbox for user groups
  1123. * @author Ivan Lucas
  1124. * @param string $name. name attribute to use for the select element
  1125. * @param int $selected. Group ID to preselect
  1126. * @returns HTML select
  1127. */
  1128. function group_drop_down($name, $selected)
  1129. {
  1130. global $grouparr, $numgroups;
  1131. $html = "<select name='$name'>";
  1132. $html .= "<option value='0'>{$GLOBALS['strNone']}</option>\n";
  1133. if ($numgroups >= 1)
  1134. {
  1135. foreach ($grouparr AS $groupid => $groupname)
  1136. {
  1137. $html .= "<option value='$groupid'";
  1138. if ($groupid == $selected)
  1139. {
  1140. $html .= " selected='selected'";
  1141. }
  1142. $html .= ">$groupname</option>\n";
  1143. }
  1144. }
  1145. $html .= "</select>\n";
  1146. return $html;
  1147. }
  1148. /**
  1149. * A HTML Form and Select listbox for user groups, with javascript to reload page
  1150. * @param int $selected. Group ID to preselect
  1151. * @param string $urlargs. (Optional) text to pass after the '?' in the url (parameters)
  1152. * @returns int Number of groups found
  1153. * @note outputs a HTML form directly
  1154. */
  1155. function group_selector($selected, $urlargs='')
  1156. {
  1157. $gsql = "SELECT * FROM `{$GLOBALS['dbGroups']}` ORDER BY name";
  1158. $gresult = mysql_query($gsql);
  1159. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1160. while ($group = mysql_fetch_object($gresult))
  1161. {
  1162. $grouparr[$group->id] = $group->name;
  1163. }
  1164. $numgroups = mysql_num_rows($gresult);
  1165. if (!empty($urlargs)) $urlargs = "&amp;{$urlargs}";
  1166. if ($numgroups >= 1)
  1167. {
  1168. echo "<form action='{$_SERVER['PHP_SELF']}?{$urlargs}' class='filterform' method='get'>";
  1169. echo "{$GLOBALS['strGroup']}: <select name='choosegroup' onchange='window.location.href=this.options[this.selectedIndex].value'>";
  1170. echo "<option value='{$_SERVER['PHP_SELF']}?gid=all{$urlargs}'";
  1171. if ($selected == 'all') echo " selected='selected'";
  1172. echo ">{$GLOBALS['strAll']}</option>\n";
  1173. echo "<option value='{$_SERVER['PHP_SELF']}?gid=allonline{$urlargs}'";
  1174. if ($selected == 'allonline') echo " selected='selected'";
  1175. echo ">{$GLOBALS['strAllOnline']}</option>\n";
  1176. foreach ($grouparr AS $groupid => $groupname)
  1177. {
  1178. echo "<option value='{$_SERVER['PHP_SELF']}?gid={$groupid}{$urlargs}'";
  1179. if ($groupid == $selected) echo " selected='selected'";
  1180. echo ">{$groupname}</option>\n";
  1181. }
  1182. echo "<option value='{$_SERVER['PHP_SELF']}?gid=0{$urlargs}'";
  1183. if ($selected === '0') echo " selected='selected'";
  1184. echo ">{$GLOBALS['strUsersNoGroup']}</option>\n";
  1185. echo "</select>\n";
  1186. echo "</form>\n";
  1187. }
  1188. return $numgroups;
  1189. }
  1190. /**
  1191. * Return HTML for a box to select interface style/theme
  1192. * @author Ivan Lucas
  1193. * @param string $name. Name attribute
  1194. * @param int $id. Interface style ID
  1195. * @returns string. HTML
  1196. */
  1197. function interfacestyle_drop_down($name, $id)
  1198. {
  1199. global $dbInterfaceStyles;
  1200. // extract statuses
  1201. $sql = "SELECT id, name FROM `{$dbInterfaceStyles}` ORDER BY name ASC";
  1202. $result = mysql_query($sql);
  1203. $html = "<select name=\"{$name}\">";
  1204. if ($id == 0)
  1205. {
  1206. $html .= "<option selected='selected' value='0'></option>\n";
  1207. }
  1208. while ($styles = mysql_fetch_object($result))
  1209. {
  1210. $html .= "<option ";
  1211. if ($styles->id == $id)
  1212. {
  1213. $html .= "selected='selected'";
  1214. }
  1215. $html .= " value=\"{$styles->id}\">{$styles->name}</option>\n";
  1216. }
  1217. $html .= "</select>\n";
  1218. return $html;
  1219. }
  1220. /**
  1221. * Retrieve cssurl and headerhtml for given interface style
  1222. * @author Ivan Lucas
  1223. * @param int $id. Interface style ID
  1224. * @returns asoc array.
  1225. */
  1226. function interface_style($id)
  1227. {
  1228. global $CONFIG, $dbInterfaceStyles;
  1229. $sql = "SELECT cssurl, headerhtml FROM `{$dbInterfaceStyles}` WHERE id='$id'";
  1230. $result = mysql_query($sql);
  1231. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1232. if (mysql_num_rows($result) == 0)
  1233. {
  1234. mysql_free_result($result);
  1235. $style = (array($CONFIG['default_css_url'],'')); // default style
  1236. }
  1237. else
  1238. {
  1239. $style = mysql_fetch_assoc($result);
  1240. mysql_free_result($result);
  1241. }
  1242. if (empty($style))
  1243. {
  1244. $style = (array($CONFIG['default_css_url'],'')); // default style
  1245. }
  1246. return ($style);
  1247. }
  1248. /**
  1249. * prints the HTML for a drop down list of incident status names (EXCLUDING 'CLOSED'),
  1250. * with the given name and with the given id selected.
  1251. * @author Ivan Lucas
  1252. * @param string $name. Text to use for the HTML select name and id attributes
  1253. * @param int $id. Status ID to preselect
  1254. * @param bool $disabled. Disable the select box when TRUE
  1255. * @returns string. HTML.
  1256. */
  1257. function incidentstatus_drop_down($name, $id, $disabled = FALSE)
  1258. {
  1259. global $dbIncidentStatus;
  1260. // extract statuses
  1261. $sql = "SELECT id, name FROM `{$dbIncidentStatus}` WHERE id<>2 AND id<>7 AND id<>10 ORDER BY name ASC";
  1262. $result = mysql_query($sql);
  1263. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1264. if (mysql_num_rows($result) < 1)
  1265. {
  1266. trigger_error("Zero rows returned",E_USER_WARNING);
  1267. }
  1268. $html = "<select id='{$name}' name='{$name}'";
  1269. if ($disabled)
  1270. {
  1271. $html .= " disabled='disabled' ";
  1272. }
  1273. $html .= ">";
  1274. // if ($id == 0) $html .= "<option selected='selected' value='0'></option>\n";
  1275. while ($statuses = mysql_fetch_object($result))
  1276. {
  1277. $html .= "<option ";
  1278. if ($statuses->id == $id)
  1279. {
  1280. $html .= "selected='selected' ";
  1281. }
  1282. $html .= "value='{$statuses->id}'";
  1283. $html .= ">{$GLOBALS[$statuses->name]}</option>\n";
  1284. }
  1285. $html .= "</select>\n";
  1286. return $html;
  1287. }
  1288. /**
  1289. * Return HTML for a select box of closing statuses
  1290. * @author Ivan Lucas
  1291. * @param string $name. Name attribute
  1292. * @param int $id. ID of Closing Status to pre-select. None selected if 0 or blank.
  1293. * @todo Requires database i18n
  1294. * @returns string. HTML
  1295. */
  1296. function closingstatus_drop_down($name, $id, $required = FALSE)
  1297. {
  1298. global $dbClosingStatus;
  1299. // extract statuses
  1300. $sql = "SELECT id, name FROM `{$dbClosingStatus}` ORDER BY name ASC";
  1301. $result = mysql_query($sql);
  1302. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1303. $html = "<select name='{$name}'";
  1304. if ($required)
  1305. {
  1306. $html .= " class='required' ";
  1307. }
  1308. $html .= ">";
  1309. if ($id == 0)
  1310. {
  1311. $html .= "<option selected='selected' value='0'></option>\n";
  1312. }
  1313. while ($statuses = mysql_fetch_object($result))
  1314. {
  1315. $html .= "<option ";
  1316. if ($statuses->id == $id)
  1317. {
  1318. $html .= "selected='selected' ";
  1319. }
  1320. $html .= "value='{$statuses->id}'>";
  1321. if (isset($GLOBALS[$statuses->name]))
  1322. {
  1323. $html .= $GLOBALS[$statuses->name];
  1324. }
  1325. else
  1326. {
  1327. $html .= $statuses->name;
  1328. }
  1329. $html .= "</option>\n";
  1330. }
  1331. $html .= "</select>\n";
  1332. return $html;
  1333. }
  1334. /**
  1335. * Return HTML for a select box of user statuses
  1336. * @author Ivan Lucas
  1337. * @param string $name. Name attribute
  1338. * @param int $id. ID of User Status to pre-select. None selected if 0 or blank.
  1339. * @param bool $userdisable. (optional). When TRUE an additional option is given to allow disabling of accounts
  1340. * @returns string. HTML
  1341. */
  1342. function userstatus_drop_down($name, $id, $userdisable = FALSE)
  1343. {
  1344. global $dbUserStatus;
  1345. // extract statuses
  1346. $sql = "SELECT id, name FROM `{$dbUserStatus}` ORDER BY name ASC";
  1347. $result = mysql_query($sql);
  1348. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1349. $html = "<select name='$name'>\n";
  1350. if ($userdisable)
  1351. {
  1352. $html .= "<option class='disable' selected='selected' value='0'>ACCOUNT DISABLED</option>\n";
  1353. }
  1354. while ($statuses = mysql_fetch_object($result))
  1355. {
  1356. if ($statuses->id > 0)
  1357. {
  1358. $html .= "<option ";
  1359. if ($statuses->id == $id)
  1360. {
  1361. $html .= "selected='selected' ";
  1362. }
  1363. $html .= "value='{$statuses->id}'>";
  1364. $html .= "{$GLOBALS[$statuses->name]}</option>\n";
  1365. }
  1366. }
  1367. $html .= "</select>\n";
  1368. return $html;
  1369. }
  1370. /**
  1371. * Return HTML for a select box of user statuses with javascript to effect changes immediately
  1372. * Includes two extra options for setting Accepting yes/no
  1373. * @author Ivan Lucas
  1374. * @param string $name. Name attribute
  1375. * @param int $id. ID of User Status to pre-select. None selected if 0 or blank.
  1376. * @returns string. HTML
  1377. */
  1378. function userstatus_bardrop_down($name, $id)
  1379. {
  1380. global $dbUserStatus;
  1381. // extract statuses
  1382. $sql = "SELECT id, name FROM `{$dbUserStatus}` ORDER BY name ASC";
  1383. $result = mysql_query($sql);
  1384. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1385. $html = "<select name='$name' title='{$GLOBALS['strSetYourStatus']}' onchange=\"if ";
  1386. $html .= "(this.options[this.selectedIndex].value != 'null') { ";
  1387. $html .= "window.open(this.options[this.selectedIndex].value,'_top') }\">";
  1388. $html .= "\n";
  1389. while ($statuses = mysql_fetch_object($result))
  1390. {
  1391. if ($statuses->id > 0)
  1392. {
  1393. $html .= "<option ";
  1394. if ($statuses->id == $id)
  1395. {
  1396. $html .= "selected='selected' ";
  1397. }
  1398. $html .= "value='set_user_status.php?mode=setstatus&amp;";
  1399. $html .= "userstatus={$statuses->id}'>";
  1400. $html .= "{$GLOBALS[$statuses->name]}</option>\n";
  1401. }
  1402. }
  1403. $html .= "<option value='set_user_status.php?mode=setaccepting";
  1404. $html .= "&amp;accepting=Yes' class='enable seperator'>";
  1405. $html .= "{$GLOBALS['strAccepting']}</option>\n";
  1406. $html .= "<option value='set_user_status.php?mode=setaccepting&amp;";
  1407. $html .= "accepting=No' class='disable'>{$GLOBALS['strNotAccepting']}";
  1408. $html .= "</option></select>\n";
  1409. return $html;
  1410. }
  1411. /**
  1412. * Return HTML for a select box of user email templates
  1413. * @author Ivan Lucas
  1414. * @param string $name. Name attribute
  1415. * @param int $id. ID of Template to pre-select. None selected if 0 or blank.
  1416. * @param string $type. Type to display.
  1417. * @returns string. HTML
  1418. */
  1419. function emailtemplate_drop_down($name, $id, $type)
  1420. {
  1421. global $dbEmailTemplates;
  1422. // INL 22Apr05 Added a filter to only show user templates
  1423. $sql = "SELECT id, name, description FROM `{$dbEmailTemplates}` WHERE type='{$type}' ORDER BY name ASC";
  1424. $result = mysql_query($sql);
  1425. if (mysql_error()) trigger_error(mysql_error(),E_USER_WARNING);
  1426. $html = "<select name=\"{$name}\">";
  1427. if ($id == 0)
  1428. {
  1429. $html .= "<option selected='selected' value='0'></option>\n";
  1430. }
  1431. while ($template = mysql_fetch_object($result))
  1432. {
  1433. $html .= "<option ";
  1434. if (!empty($template->description))
  1435. {
  1436. $html .= "title='{$template->description}' ";
  1437. }
  1438. if ($template->id == $id)
  1439. {
  1440. $html .= "selected='selected' ";
  1441. }
  1442. $html .= "value='{$template->id}'>{$template->name}</option>";
  1443. $html .= "\n";
  1444. }
  1445. $html .= "</select>\n";
  1446. return $html;
  1447. }
  1448. /**
  1449. * Return HTML for a select box of priority names (with icons)
  1450. * @author Ivan Lucas
  1451. * @param string $name. Name attribute
  1452. * @param int $id. ID of priority to pre-select. None selected if 0 or blank.
  1453. * @param int $max. The maximum priority ID to list.
  1454. * @param bool $disable. Disable the control when TRUE.
  1455. * @returns string. HTML
  1456. */
  1457. function priority_drop_down($name, $id, $max=4, $disable = FALSE)
  1458. {
  1459. global $CONFIG, $iconset;
  1460. // INL 8Oct02 - Removed DB Query
  1461. $html = "<select id='priority' name='$name' ";
  1462. if ($disable)
  1463. {
  1464. $html .= "disabled='disabled'";
  1465. }
  1466. $html .= ">";
  1467. if ($id == 0)
  1468. {
  1469. $html .= "<option selected='selected' value='0'></option>\n";
  1470. }
  1471. $html .= "<option style='text-indent: 14px; background-image: url({$CONFIG['application_webpath']}images/low_priority.gif); background-repeat:no-repeat;' value='1'";
  1472. if ($id == 1)
  1473. {
  1474. $html .= " selected='selected'";
  1475. }
  1476. $html .= ">{$G…

Large files files are truncated, but you can click here to view the full file