PageRenderTime 59ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 1ms

/lib/functions.inc.php

https://github.com/paulheaney/sitracker
PHP | 8291 lines | 6676 code | 584 blank | 1031 comment | 727 complexity | 37cd88eba80b3f42df4dfd3434e28e23 MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-2.0, BSD-3-Clause, GPL-2.0

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

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