Source for file helpdesk.php

Documentation is available at helpdesk.php

  1. <?php
  2. /**
  3. * Customer Support module.
  4. * @package helpdesk
  5. * @author Frederic G. MARAND <fgm@osinet.fr>
  6. * Copyright OSI 2005. All rights reserved.
  7. * It is expected that version 1.0 will be GPLed, but this interim work
  8. * is kept closed until 1.0 is ready.
  9. * @todo make it work first
  10. * @version $Id
  11. * 20051005
  12. * - Completed _helpdesk_user and affiliated functions
  13. * 20050920
  14. * - Added _helpdesk_block_view_CUSTOMEROPENTICKETS
  15. * 20050919
  16. * - Added _helpdesk_block_view_MYOPENTICKETS
  17. * - Added access control to _helpdesk_block_view
  18. * 20050918
  19. * - Added _helpdek_block_view_ALLOPENTICKETS
  20. */
  21.  
  22. $_helpdesk_saved_er = error_reporting (E_ALL || E_STRICT) ;
  23.  
  24. /**
  25. * Import helpdesk-related classes and functions
  26. */
  27. require_once("misc.php") ;
  28. require_once("contract.php") ;
  29. require_once("customer.php") ;
  30. require_once("event.php") ;
  31. require_once("timeinfo.php") ;
  32.  
  33. define ('HELPDESKDEBUGALLFUNCTIONS', TRUE) ;
  34.  
  35. /**
  36. * Constants for helpdesk node types
  37. */
  38. define ('HELPDESKNODECONTRACT', 'helpdesk-contra') ;
  39. define ('HELPDESKNODETICKET', 'helpdesk-ticket') ;
  40. define ('HELPDESKNODEFOLLOWUP', 'helpdesk-follow') ;
  41.  
  42. define ('HELPDESKTITLECONTRACT', 'Helpdesk > Contract') ;
  43. define ('HELPDESKTITLETICKET', 'Helpdesk > Ticket') ;
  44. define ('HELPDESKTITLEFOLLOWUP', 'Helpdesk > Followup') ;
  45.  
  46. /**
  47. * Constants for HELPDESK perms
  48. */
  49. define ("HELPDESKPERMUSER", 'Helpdesk > User' ) ;
  50. define ("HELPDESKPERMCUSTOMER", 'Helpdesk > Customer') ;
  51. define ("HELPDESKPERMTECH", 'Helpdesk > Tech') ;
  52. define ("HELPDESKPERMMAX", HELPDESKPERMTECH) ;
  53.  
  54. /**
  55. * Constants for HELPDESK block deltas
  56. */
  57. define ("HELPDESKBLOCKMYOPENTICKETS", 0) ;
  58. define ("HELPDESKBLOCKMYLATESTTICKETS", 1) ;
  59. define ("HELPDESKBLOCKCUSTOMEROPENTICKETS", 2) ;
  60. define ("HELPDESKBLOCKCUSTOMERBALANCE", 3) ;
  61. define ("HELPDESKBLOCKALLOPENTICKETS", 4) ;
  62. define ("HELPDESKBLOCKMAX", HELPDESKBLOCKALLOPENTICKETS) ;
  63.  
  64. /**
  65. * Constants for Drupal variables
  66. */
  67. define ("HELPDESKVARSHOWROLES", 'helpdesk_show_roles') ;
  68. define ("HELPDESKVARTICKETPREFIX", 'helpdesk_ticket_prefix') ; // Unused part of the ticket number
  69. define ("HELPDESKVARTICKETOFFSET", 'helpdesk_ticket_base') ; // Number to be added to nid to build ticket number
  70.  
  71. /**
  72. * Constants for hook_access
  73. */
  74. define ("HELPDESKHOOKACCESSCREATE", "create") ;
  75. define ("HELPDESKHOOKACCESSDELETE", "delete") ;
  76. define ("HELPDESKHOOKACCESSUPDATE", "update") ;
  77. define ("HELPDESKHOOKACCESSVIEW", "view") ;
  78.  
  79. /**
  80. * Helpdesk access control
  81. * User may create an issue, read and close his own issues, add followups to his issues
  82. * Customer has User rights, extended to all users bound to him, and can perform some actions on his contracts
  83. * Tech can do anything HELPDESK-related
  84. * @param string $op create | delete | update | view
  85. * @param object $node the node on which "op" is to be performed
  86. * @return mixed boolean or NULL
  87. * @link http://drupaldocs.org/api/head/function/hook_access Drupal API
  88. */
  89. function helpdesk_access ($op, $node)
  90. {
  91. global $user ;
  92. $ret = FALSE ;
  93. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  94. {
  95. $log = "<pre>HELPDESK_ACCESS ($op, " . _helpdesk_get_node_property($node, 'nid') ;
  96. }
  97. /* By default, node_access is set to just one row :
  98. nid == gid == 0
  99. realm == "all"
  100. grant_update == grant_delete == 0
  101. grant_view == 1
  102. gid appears to be unused in 4.6.*
  103. */
  104. switch ($op)
  105. {
  106. case HELPDESKHOOKACCESSCREATE:
  107. {
  108. // In this case, $node is a string containing the node type, not a node object
  109. // Issue and Followup may be created from the HELPDESK User level, but only HELPDESK Techs can create contracts
  110. switch ($node)
  111. {
  112. case HELPDESKNODECONTRACT :
  113. $ret = user_access (HELPDESKPERMTECH) ;
  114. // echo "<p>Create/Contract, ret = $ret</p>" ;
  115. break ;
  116. case HELPDESKNODETICKET :
  117. case HELPDESKNODEFOLLOWUP :
  118. $ret = user_access (HELPDESKPERMUSER) || user_access (HELPDESKPERMCUSTOMER) || user_access (HELPDESKPERMTECH) ;
  119. // echo "<p>Create/Ticket of Followup, ret = $ret</p>" ;
  120. break ;
  121. default: // Don't worry about other types
  122. echo "<pre>Anomalie dans helpdesk_access/create: node = " ; print_r ($node) ; echo "</pre>" ;
  123. $ret = TRUE ;
  124. break ;
  125. }
  126. break ;
  127. }
  128. case HELPDESKHOOKACCESSDELETE:
  129. {
  130. // For contract traceability, only techs may delete Issue or Followups
  131. $ret = user_access (HELPDESKPERMTECH) ;
  132. echo "<p>helpdesk_access/delete, ret = $ret</p>" ;
  133. break ;
  134. }
  135. case HELPDESKHOOKACCESSUPDATE:
  136. {
  137. /* For traceability, only techs may update Issue or Followups
  138. Users and customers wishing to update a ticket must issue a Followup
  139. Modifiying the status of an issue is handled by creating a
  140. followup with the new status */
  141. $ret = user_access (HELPDESKPERMTECH) ;
  142. //echo "<p>helpdesk_access/update, ret = $ret</p>" ;
  143. break ;
  144. }
  145. case HELPDESKHOOKACCESSVIEW:
  146. {
  147. // For this op, node is supposed to be already assigned
  148. $ret = FALSE ;
  149. /* Helpdesk User may see his own events,
  150. Helpdesk Customer may see the events of his users
  151. Helpdesk tech may view anything */
  152. $ret |= (user_access (HELPDESKPERMUSER) && ($user->uid == $node->uid)) ;
  153. // TODO : HELPDESK Customer access will have to be computed from the HELPDESK users bound to him
  154. $ret |= user_access (HELPDESKPERMCUSTOMER) ; // Will have to be restricted to the tickets of bound users.
  155. $ret |= user_access (HELPDESKPERMTECH) ;
  156. echo "<p>helpdesk_access/view, ret = $ret</p>" ;
  157. break ;
  158. }
  159. default: die ('<p><code>helpdesk_access</code> invoked with an unauthorized value: $op. Aborting.</p>') ;
  160. }
  161. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  162. { echo "$log) = " . $ret . "</pre>" ; }
  163. return $ret ;
  164. }
  165.  
  166. /**
  167. * Implementation of hook_help : provides and manages the helpdesk blocks.
  168. * @param op the operation from the URL (Drupal: list, view, configure, save. ?)
  169. * - 'list': A list of all blocks defined by the module
  170. * - 'configure': A configuration form
  171. * - 'view': Save the configuration options
  172. * - save': Information about a particular block
  173. * @param delta offset
  174. * @return mixed type depends on $op.
  175. * @link http://drupaldocs.org/api/head/function/hook_block Drupal API
  176. * @see _helpdesk_block_list()
  177. * @see _helpdesk_block_configure()
  178. * @see _helpdesk_block_view()
  179. * @see _helpdesk_block_save()
  180. */
  181. function helpdesk_block ($op = 'list', $delta = 0)
  182. {
  183. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  184. { echo "<pre>HELPDESK_BLOCK (op = $op, delta = $delta)</pre>" ; }
  185. // listing of blocks, such as on the admin/block page
  186. switch ($op)
  187. {
  188. case 'list': { return _helpdesk_block_list ($delta) ; }
  189. case 'configure': { return _helpdesk_block_configure ($delta) ; }
  190. case 'save': { return _helpdesk_block_save ($delta) ; }
  191. case 'view': { return _helpdesk_block_view ($delta) ; } // Information about a particular block
  192. default: die('helpdesk_block called with invalid op: $op') ;
  193. }
  194. } // end helpdesk_block
  195. /**
  196. * HELPDESK actions to be performed when a HELPDESK node is deleted
  197. * @param object $node the node to be deleted after this function
  198. * @return void
  199. * @link http://drupaldocs.org/api/head/function/hook_delete
  200. */
  201. function helpdesk_delete ($node)
  202. {
  203. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  204. { echo "<pre>HELPDESK_DELETE (node = " ; print_r ($node) ; echo ")</pre>" ; }
  205. /* This function must:
  206. - either allow the db to become inconsistent (events without contracts, followups without tickets)
  207. - or delete related nodes (followups for a ticket node, tickets and followups for a contract node), causing loss of traceability
  208. In the first version, it will allow the db to become inconsistent: contract numbers are node, and as such
  209. are not reused anyway, so there is no overload risk.
  210. */
  211. switch (_helpdesk_node_type($node))
  212. {
  213. case HELPDESKNODECONTRACT :
  214. $q = 'DELETE FROM {hd_contract} WHERE nid = %d ';
  215. $res = db_query($q, $node->nid);
  216. unset ($q);
  217. unset ($res);
  218. break ;
  219. case HELPDESKNODETICKET :
  220. case HELPDESKNODEFOLLOWUP :
  221. break; // Not yet implemented
  222. }
  223. }
  224. /**
  225. * Helpdesk data entry form. Used for both node add and edit
  226. * testing for $node->nid allows the code to define whether the node is to be created of modified
  227. * @param object $node the node to be entered
  228. * @return string HTML
  229. */
  230. function helpdesk_form (&$node) //XXXwas helpdesk_form(&$node)
  231. {
  232. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  233. { echo "<pre>HELPDESK_FORM (node = " ; print_r ($node) ; echo ")</pre>" ; }
  234.  
  235. $output = '' ;
  236. // In order to be able to attach taxonomy terms to this node, we need
  237. // to display the appropriate form elements.
  238. if (function_exists('taxonomy_node_form'))
  239. {
  240. $output .= implode('', taxonomy_node_form('helpdesk', $node));
  241. }
  242. else
  243. { theme_error('helpdesk cannot find taxonomy_node_form. Have you activated taxonomy.module') ; }
  244. switch (_helpdesk_node_type($node))
  245. {
  246. case HELPDESKNODECONTRACT:
  247. if (!isset($node->{HELPDESKNODECONTRACT})) // Happens at the first step of node creation
  248. {
  249. $node->{HELPDESKNODECONTRACT} = new helpdeskContract();
  250. $node->{HELPDESKNODECONTRACT}->init($node, FALSE); // $node is always set at this point, load from it, not from DB
  251. }
  252. $output = $node->{HELPDESKNODECONTRACT}->form();
  253. break;
  254. case HELPDESKNODETICKET:
  255. $output = helpdeskTicket::createForm ($node) ;
  256. break ;
  257. case HELPDESKNODEFOLLOWUP:
  258. $output = helpdeskFollowup::createForm () ;
  259. break ;
  260. default:
  261. echo "<p>Anomaly: helpdesk_form called for type " . _helpdesk_node_type($node) . "</p>" ;
  262. break;
  263. }
  264. // echo "<p>In helpdesk_form</p>" ;
  265. return $output ;
  266. } // helpdesk_form
  267. /**
  268. * Display help and module information
  269. * Documented values as of 4.6.3 and HEAD on 2005/08/21
  270. * @param string $section Drupal URL path (or: menu item) the help is being requested for, e.g. admin/node or user/edit. Recognizes special descriptors after a "#" sign
  271. * @return help text for section
  272. */
  273. function helpdesk_help ($section = '')
  274. {
  275. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  276. { echo "<pre>HD HELP (section = $section), " ; }
  277.  
  278. $output = '' ;
  279. switch ($section)
  280. {
  281. /* // The name of a module (unused, but there)
  282. case "admin/modules#name" :
  283. break; */
  284. // The description found on the admin/system/modules page.
  285. case "admin/modules#description":
  286. $output = t ("Enable Helpdesk/ticketing functions") ;
  287. break;
  288.  
  289. // The module's help text, displayed on the admin/help page and through the module's individual help link.
  290. case "admin/help#helpdesk":
  291. $output = t ("This module allows for the generation of tickets, and management of helpdesk calls. "
  292. . "It enables tickets to be bound to support contracts and managed by a "
  293. . "helpdesk contract administrator. Various types of charging are available, "
  294. . "included unlimited, time spent, number of tickets, and date limit.") ;
  295. break ;
  296.  
  297. /* // The help for a distributed authorization module (if applicable).
  298. case "user/help#helpdesk":
  299. break ;*/
  300.  
  301. // The description of a node type (if applicable).
  302. case "node/add#" . HELPDESKNODECONTRACT:
  303. $output = t("Define a new helpdesk contract for an existing helpdesk customer") ;
  304. break ;
  305. case "node/add#" . HELPDESKNODETICKET:
  306. $output = t("Obtain a helpdesk ticket for a new helpdesk issue") ;
  307. break ;
  308. case "node/add#" . HELPDESKNODEFOLLOWUP:
  309. $output = t("Add a followup to an existing helpdesk ticket") ;
  310. break ;
  311. }
  312. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  313. echo "output : $output</pre>" ;
  314. return $output;
  315. } // function helpdesk_help
  316. /**
  317. * Upon creation of a helpdesk-related node, perform insertions on our private tables
  318. * We're not supposed to test for access here, as it's already been done earlier in node_add (?)
  319. * @param object $node the node being inserted
  320. * @return void
  321. */
  322. function helpdesk_insert ($node)
  323. {
  324. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  325. { echo "<pre>HD INSERT (node = " ; print_r ($node) ; echo ")</pre>" ; }
  326. switch ($node->type)
  327. {
  328. case HELPDESKNODECONTRACT:
  329. $o = new helpdeskContract();
  330. $o->init($node, FALSE); // Not yet in DB, load from $node
  331. $o->insert();
  332. break ;
  333. case HELPDESKNODETICKET:
  334. echo "<pre>Inserting ticket</pre>" ;
  335. break ;
  336. case HELPDESKNODEFOLLOWUP:
  337. echo "<pre>Inserting followup</pre>" ;
  338. break ;
  339. default :
  340. echo "<pre>helpdesk_insert: insertion d'un type non supporté: $node->type</pre>" ;
  341. break ;
  342. }
  343. }
  344.  
  345. /**
  346. * This hook enables modules to add links to many parts of Drupal.
  347. * Links may be added in nodes or in the navigation block, for example.
  348. * In our case, this will allow followups to be added to either issues or followups (threading)
  349. * @param string $type An identifier declaring what kind of link is being requested. Possible values:
  350. * - node: Links to be placed below a node being viewed.
  351. * - comment: Links to be placed below a comment being viewed.
  352. * @param int $node A node object passed in case of node links.
  353. * @param int $teaser In case of node link: a 0/1 flag depending on whether the node is displayed with its teaser or its full form (on a node/nid page)
  354. * @return array array of links
  355. * @link http://drupaldocs.org/api/head/function/hook_link Drupal API
  356. */
  357. function helpdesk_link($type, $node = NULL, $teaser = FALSE)
  358. {
  359. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  360. { echo "<pre>HD LINK ($type, $node->nid, $teaser)</pre>" ; }
  361.  
  362. if ((!isset($type)) || ($type == 'comment'))
  363. return NULL ;
  364. if (!isset($node))
  365. die("helpdesk_link('node', NULL, $teaser) invoked: invalid set of parameters") ;
  366. /**
  367. * @todo Access should be tested
  368. * @todo It should be possibly to add a followup to the original issue from a followup
  369. **/
  370. switch ($node->type)
  371. {
  372. case HELPDESKNODETICKET:
  373. $links[] = l(t('add followup'), ('helpdesk/followup/' . $node->nid),
  374. array('title' => t('Add a followup to this ticket.')));
  375. break;
  376. case HELPDESKNODEFOLLOWUP:
  377. $links[] = l(t('add followup'), 'helpdesk/followup/' . $node->nid,
  378. array('title' => t('Add a followup to this followup (threaded answer).')));
  379. break;
  380. case HELPDESKNODECONTRACT:
  381. $links[] = l(t('new ticket'), 'node/add/' . HELPDESKNODETICKET . '/' . $node->nid,
  382. array('title' => t('Obtain a ticket for an issue covered by this contract.')));
  383. break;
  384. default:
  385. $links = NULL ; // die("helpdesk_link('node', $node->nid, $teaser) invoked, but node is of type: $node->type");
  386. }
  387. return $links ;
  388. }
  389. /**
  390. * load auxiliary data for HD nodes. We wrap the returned object in an array to prevent mixing with
  391. * other modules and drupal core.
  392. * @param object $node the node being loaded
  393. * @return object the properties to be added to the passed node object
  394. * @link http://drupaldocs.org/api/4.6/function/hook_load Drupal API
  395. */
  396. function helpdesk_load($node)
  397. {
  398. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  399. { echo "<pre>HD LOAD (" . _helpdesk_get_node_property($node, 'nid') . ")</pre>\r\n" ; }
  400. $output = NULL ;
  401. switch ($node->type) // Is supposed to be assigned and valid
  402. {
  403. case HELPDESKNODECONTRACT : // Load attributes from hd_contract/hd_timeinfo
  404. $o = new helpdeskContract();
  405. $o->init($node, TRUE); // Load from DB
  406. break ;
  407. case HELPDESKNODETICKET : // Load attributes and thread from hd_event/hd_timeinfo
  408. break ;
  409. case HELPDESKNODEFOLLOWUP : // Load attributes and thread from hd_event/hd_timeinfo
  410. break ;
  411. default :
  412. die("helpdesk_load invoked for node $node->nid, incorrect type $node->type");
  413. }
  414.  
  415. if (isset($o))
  416. {
  417. $output = array();
  418. $output [$node->type] = $o ;
  419. }
  420. else
  421. return NULL ;
  422. return $output ; // Should contain the auxiliary data
  423. }
  424. /**
  425. * HELPDESK menu is enabled for all users with HELPDESK
  426. * @return array of menu definitions
  427. */
  428. function helpdesk_menu($may_cache) {
  429. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  430. { echo '<pre>HD MENU</pre>' ; }
  431. $items = array();
  432.  
  433. if ($may_cache)
  434. {
  435. $items[] = array('path' => 'node/add/' . HELPDESKNODECONTRACT,
  436. 'title' => t(HELPDESKTITLECONTRACT),
  437. 'access' => helpdesk_access('create', HELPDESKNODECONTRACT));
  438. $items[] = array('path' => 'node/add/' . HELPDESKNODETICKET,
  439. 'title' => t(HELPDESKTITLETICKET),
  440. 'access' => helpdesk_access('create', HELPDESKNODETICKET));
  441. $items[] = array('path' => 'node/add/' . HELPDESKNODEFOLLOWUP,
  442. 'title' => t(HELPDESKTITLEFOLLOWUP),
  443. 'access' => helpdesk_access('create', HELPDESKNODEFOLLOWUP));
  444. $items[] = array('path' => 'helpdesk/followup/',
  445. 'title' => t(HELPDESKTITLEFOLLOWUP),
  446. 'access' => helpdesk_access('create', HELPDESKNODEFOLLOWUP),
  447. 'type' => MENU_CALLBACK); // This is to allow followups to a known node, so it must be called from a node, not from the menu
  448. }
  449.  
  450. // echo "<pre>helpdesk_menu: " ; print_r ($items) ; echo ", may_cache: " . ($may_cache ? "TRUE" : "FALSE") . "</pre>" ;
  451. return $items;
  452. }
  453.  
  454.  
  455. /**
  456. * Implementation of hook_nodeapi, for tracing purposes only
  457. *
  458. * @param object $node
  459. * @param string $op
  460. * @param boolean $teaser
  461. * @param boolean $page
  462. */
  463. function helpdesk_nodeapi(&$node, $op, $teaser = NULL, $page = NULL)
  464. {
  465. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  466. { echo "<pre>HD NODEAPI(node $node->nid, op = $op, teaser = $teaser, page = $page)</pre>\r\n" ; }
  467. }
  468. /**
  469. * Name our node names. See also helpdesk_node_types
  470. * @param mixed node either a string (node type ) or node object
  471. * @return string the human-readable node name
  472. */
  473. function helpdesk_node_name ($node)
  474. {
  475. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  476. {
  477. $ret = "<pre>HD NODE_NAME (" ;
  478. if (is_object($node))
  479. $ret .= "OBJ: nid = " . (isset($node->nid) ? $node->nid : 'new node') . ", type = $node->type" ;
  480. else
  481. $ret .= "Plain: $node" ;
  482.  
  483. $ret .= ")</pre>\r\n" ;
  484. print ($ret);
  485. }
  486. switch (is_string ($node) ? $node : (is_array($node) ? $node['type'] : $node->type))
  487. {
  488. case HELPDESKNODECONTRACT: return t (HELPDESKTITLECONTRACT) ;
  489. case HELPDESKNODETICKET: return t (HELPDESKTITLETICKET) ;
  490. case HELPDESKNODEFOLLOWUP: return t (HELPDESKTITLEFOLLOWUP) ;
  491. }
  492. return NULL;
  493. }
  494. /**
  495. * Define our node types
  496. * @return array the array of our node types
  497. */
  498. function helpdesk_node_types ()
  499. {
  500. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  501. { echo '<pre>HD NODE_TYPES</pre>' ; }
  502. return array (
  503. HELPDESKNODECONTRACT,
  504. HELPDESKNODETICKET,
  505. HELPDESKNODEFOLLOWUP) ;
  506. }
  507. /**
  508. * Valid permissions for this module
  509. * @return array An array of valid permissions for the helpdesk module
  510. */
  511. function helpdesk_perm ()
  512. {
  513. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  514. { echo '<pre>HELPDESK_PERM</pre>' ; }
  515. return array (
  516. HELPDESKPERMUSER,
  517. HELPDESKPERMCUSTOMER,
  518. HELPDESKPERMTECH
  519. ) ;
  520. } // function helpdesk_perm()
  521.  
  522. /**
  523. * Module configuration settings
  524. * @return string settings HTML or deny access
  525. */
  526. function helpdesk_settings ()
  527. {
  528. $output = '' ;
  529. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  530. { echo "<pre>HELPDESK_SETTINGS</pre>" ; }
  531. // only HELPDESK Tech support can access this module
  532. if (!user_access (HELPDESKPERMTECH))
  533. {
  534. return message_access () ;
  535. }
  536. $output .= form_checkbox // checked, description, attributes, required
  537. (
  538. t ("Show users their current roles"), // title
  539. HELPDESKVARSHOWROLES, // name
  540. TRUE, // value
  541. variable_get (HELPDESKVARSHOWROLES, FALSE), // checked
  542. t ("Allow users to see their Drupal roles on their \"My account/edit\" page, \"user roles\" local task."),
  543. NULL, // attributes
  544. FALSE
  545. ) ;
  546. $output .= form_textfield // checked, description, attributes, required
  547. (
  548. t ("Ticket prefix"), // title
  549. HELPDESKVARTICKETPREFIX, // name
  550. variable_get(HELPDESKVARTICKETPREFIX, ''), // initial value
  551. 8, // size of field
  552. 8, // max length
  553. t ("The prefix to be prepended to the node number to build ticket numbers as seen by customers."), // description
  554. NULL, // attributes
  555. FALSE
  556. ) ;
  557. $output .= form_textfield // checked, description, attributes, required
  558. (
  559. t ("Ticket offset"), // title
  560. HELPDESKVARTICKETOFFSET, // name
  561. variable_get(HELPDESKVARTICKETOFFSET, 0), // initial value
  562. 8, // size of field
  563. 8, // max length
  564. t ("The number to be added to the node number to build ticket numbers as seen by customers."), // description
  565. NULL, // attributes
  566. FALSE
  567. ) ;
  568. return $output;
  569. }
  570.  
  571. /**
  572. * Specs: Respond to node updating. This is a hook used by node modules. It is called to allow the module to take action when an edited node is being updated in the database by, for example, updating information in related tables.
  573. * @param object $node The node being updated
  574. * @return void
  575. * @todo see source
  576. */
  577. function helpdesk_update($node)
  578. {
  579. /* For all our nodes:
  580. - copy the node/created, node/changed timestaps to hd_timeinfo
  581. - copy the additional properties to hd_contract, hd_event
  582. */
  583. return ;
  584. }
  585. /**
  586. * Per the docs: This is a hook used by node modules.
  587. * It allows a module to define a custom method of displaying its nodes,
  588. * usually by displaying extra information particular to that node type.
  589. * @param object $node
  590. * @param string $teaser
  591. * @param int $page
  592. * @return void
  593. */
  594. function helpdesk_view(&$node, $teaser = FALSE, $page = FALSE)
  595. {
  596. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  597. { echo "<pre>HELPDESK_VIEW (node = " . _helpdesk_get_node_property($node, 'nid') . ", teaser = $teaser, page = $page)</pre>" ; }
  598.  
  599. $output = '' ;
  600. $node = node_prepare ($node, $teaser) ; // Filter according to node filter settings
  601. if ($teaser)
  602. {
  603. $output = 'We are working on the teaser' ;
  604. $node->teaser = $output ;
  605. $node->body = '' ;
  606. unset ($output) ;
  607. }
  608. else
  609. {
  610. switch ($node->type)
  611. {
  612. case HELPDESKNODETICKET:
  613. if (!isset($node->{$node->type})) // Not coming from a form (hence not a preview). Can come from DB
  614. {
  615. $node->{$node->type} = new helpdeskTicket();
  616. $node->{$node->type}->init($node, TRUE);
  617. }
  618. $onode = $node->{$node->type};
  619. $output = theme_placeholder($onode->getTicket ()) ;
  620. $node->body = $onode->view() . $node->body ;
  621. $node->body = theme_box (sprintf (t('Ticket number %s'), $output), $node->body, 'main') ;
  622. break ;
  623. case HELPDESKNODEFOLLOWUP:
  624. // Same as above
  625. break ;
  626. case HELPDESKNODECONTRACT:
  627. if (!isset($node->{$node->type}))
  628. {
  629. $node->{$node->type} = new helpdeskContract();
  630. $node->{$node->type}->init($node, FALSE);
  631. }
  632. $output .= $node->{$node->type}->view();
  633. $output = theme_box(t('Contract details'), $output, 'main');
  634. $output .= theme_box(t('Contract description'), $node->body, 'main');
  635. $node->body = $output ;
  636. break ;
  637. }
  638. $node->body .= theme_placeholder (t('Notice: for traceability reasons, helpdesk-related nodes cannot be edited by users and customers. To modify, just add a followup.')) ;
  639. unset($o) ;
  640. $node->teaser = 'No teaser when \$teaser is not 1' ;
  641. }
  642. /* $themed_node = theme ('node', $node) ; */
  643. }
  644.  
  645. /**
  646. * Act on user account actions.
  647. * This hook allows modules to react when operations are performed on user accounts.
  648. * Sequence of calls for high-level functions:
  649. * - creation: validate, load, insert, load. We don't care, yet.
  650. * - prepare update: categories, load, form
  651. * - perform update: load, validate, update, load
  652. * - prepare deletion: categories, load
  653. * - perform deletion: categories, load, delete(confirm=1). We should do something about tickets/issues.
  654. * @param string $op Operation to be performed on user
  655. * @param array $edit array of form values submitted by the user
  656. * @param object $account The user object on which the operation is being performed.
  657. * @param string $category The active category of user information being edited.
  658. * @return mixed
  659. * @see _helpdesk_user_load()
  660. */
  661. function helpdesk_user ($op, $edit, $account, $category = NULL) //XXX edit and author should be passed by ref
  662. {
  663. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  664. { echo "<pre>HD USER (op = $op, "
  665. . (isset($edit)
  666. ? (is_array($edit)
  667. ? (array_key_exists('uid', $edit) ? ("edit[uid] = " . $edit['uid']) : print_r($edit, True))
  668. : ("edit: string = [$edit]")
  669. )
  670. : 'edit not set')
  671. . ", user name = "
  672. . (is_object($account)
  673. ? (isset($account->name)
  674. ? $account->name
  675. : 'name not set'
  676. )
  677. : 'not object'
  678. )
  679. .", category = $category)</pre>" ;
  680. }
  681. global $user ; // Masks the user parameter !
  682. $output = NULL ;
  683. switch ($op)
  684. {
  685. case 'view': // The user's account information is being displayed.
  686. { $output = _helpdesk_user_view($user); break ; }
  687. case 'categories': // A set of user information categories is requested.
  688. { $output = _helpdesk_user_categories(); break ; }
  689. case 'load': // The user account is being loaded. The module may respond to this and insert additional information into the user object.
  690. /* in our case, this means loading the linked customer info if we need it later on */
  691. {
  692. if (isset($edit) && is_array($edit) && array_key_exists('uid', $edit))
  693. _helpdesk_user_load($user, $edit['uid']);
  694. $output = NULL ; // user_load is void
  695. break;
  696. }
  697. case 'form': // The user account edit form is about to be displayed. The module should present the form elements it wishes to inject into the form.
  698. { $output = _helpdesk_user_form($edit, $category); break; }
  699. case 'delete': // The user account is being deleted.
  700. /**
  701. * @todo If this user has tickets, followups, or helpdesk contracts, they will be orphaned. The module should grant them to someone else or delete them
  702. */
  703. { $output = NULL; break; }
  704. case "insert": // The user account is being added. As long as we don't store default user information, we needn't care
  705. { $output = NULL; break; }
  706. case "login": // The user just logged in. We don't care.
  707. { $output = NULL; break; }
  708. case "logout": // The user just logged out. We don't care. At some point, this could allow automatic timestamping of pending nodes
  709. { $output = NULL; break; }
  710. case "update": // The user account is being changed. Normally, we shouldn't care as long as we don't store user information
  711. { $output = NULL; break; }
  712. case "validate": // The user account is about to be modified. Normally, we shouldn't care as long as we don't store user information.
  713. { $output = NULL; break; }
  714. }
  715. return $output;
  716. }
  717.  
  718. /**
  719. * Verify a node editing form. This is a hook used by node modules.
  720. * It is called to allow the module to verify that the node is in a format valid to post
  721. * to the site. It can also be used to make changes to the node before submission, such
  722. * as node-type-specific formatting. Errors should be set with form_set_error().
  723. *
  724. * @param object $node The node to be validated.
  725. */
  726. function helpdesk_validate(&$node)
  727. {
  728. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  729. { echo "<pre>HD VALIDATE (node: " . print_r ($node, TRUE) . ")</pre>" ; }
  730. /* Checks to be performed:
  731. - date validity, absolute and relative
  732. - status and severity having valid values
  733. */
  734. }
  735. /* ----- Private functions ------------------------------------------------------------ */
  736. /**
  737. * Defines the name of the blocks attached to a delta
  738. * @param int $delta the block number
  739. * @return string the name of the block
  740. * @see helpdesk_block()
  741. */
  742. function _helpdesk_block_list ($delta)
  743. {
  744. if ($delta > HELPDESKBLOCKMAX)
  745. return NULL ;
  746. // No need to test for HELPDESKPERMUSER as access won't be granted if if is absent
  747. $block [HELPDESKBLOCKMYOPENTICKETS] ["info"] = t('Helpdesk &gt; My current tickets') ;
  748. $block [HELPDESKBLOCKMYLATESTTICKETS] ["info"] = t('Helpdesk &gt; My latest tickets') ;
  749. if (user_access (HELPDESKPERMCUSTOMER))
  750. {
  751. $block [HELPDESKBLOCKCUSTOMEROPENTICKETS]["info"] = t('Helpdesk &gt; Customer\'s current tickets') ;
  752. $block [HELPDESKBLOCKCUSTOMERBALANCE] ["info"] = t('Helpdesk &gt; Customer\'s contracts balance') ;
  753. }
  754. if (user_access (HELPDESKPERMTECH))
  755. {
  756. $block [HELPDESKBLOCKALLOPENTICKETS] ["info"] = t('Helpdesk &gt; Oldest active tickets') ;
  757. }
  758. return $block ;
  759. }
  760.  
  761. /**
  762. * Subroutine for helpdesk_block/configure
  763. * @param int $delta
  764. * @return string HTML for the configuration form
  765. * @see helpdesk_block()
  766. */
  767. function _helpdesk_block_configure ($delta)
  768. {
  769. $output = '' ;
  770. $msg = t("This block (%d) doesn't have any configuration option") ;
  771. switch ($delta)
  772. {
  773. case HELPDESKBLOCKMYOPENTICKETS: $output .= sprintf ($msg, $delta) ; break ;
  774. case HELPDESKBLOCKMYLATESTTICKETS: $output .= sprintf ($msg, $delta) ; break ;
  775. case HELPDESKBLOCKCUSTOMEROPENTICKETS: $output .= sprintf ($msg, $delta) ; break ;
  776. case HELPDESKBLOCKCUSTOMERBALANCE: $output .= sprintf ($msg, $delta) ; break ;
  777. case HELPDESKBLOCKALLOPENTICKETS: $output .= sprintf ($msg, $delta) ; break ;
  778. default: t("You requested an unavailable block.") ;
  779. }
  780.  
  781. return $output ;
  782. }
  783. /**
  784. * Subroutine for helpdesk_block/save
  785. * @param int $delta
  786. * @return void
  787. * @see helpdesk_block()
  788. */
  789. function _helpdesk_block_save ($delta)
  790. {
  791. // variable_set (HELPDESKCONFVAR, $_REQUEST ['edit'][HELPDESKCONFVAR]) ; // No longer used
  792. /* $ret = "REQUEST: <pre>" . var_export ($_REQUEST ['edit'], True) . "</pre>" ;
  793. echo $ret ; */
  794. }
  795. /**
  796. * Checks whether or not the current user is a customer
  797. * Does not depend on bound users or contracts
  798. * @return boolean
  799. */
  800. function _helpdesk_iscustomer ()
  801. {
  802. $s = HELPDESKPERMCUSTOMER ;
  803. // echo "<pre>Perm requested: $s</pre>" ;
  804. return (user_access ($s)) ;
  805. }
  806. /**
  807. * Returns the contracts owned by a customer
  808. * @param int $uidcustomer The UID of the customer being examined. Not necessarily the current user
  809. * @return mixed NULL in case an error (presumably access limitation) happens, array of contracts otherwise, possibly empty
  810. */
  811. function _helpdesk_getnidcontracts ($uidcustomer)
  812. {
  813. /* Can be checked only by tech for any uidcustomer, and by customer for own contracts
  814. */
  815. global $user;
  816. if ((!user_access(HELPDESKPERMTECH)) && (!(user_access(HELPDESKPERMCUSTOMER) && ($user->uid == $uidcustomer))))
  817. return NULL ;
  818. else
  819. {
  820. $q = '
  821. SELECT
  822. n.nid, n.title
  823. FROM {node} n
  824. INNER JOIN {hd_contract} hdc on n.nid = hdc.nid
  825. WHERE
  826. hdc.uidcustomer = %d
  827. ORDER BY
  828. 2
  829. ' ;
  830. $res = db_query($q, $uidcustomer);
  831. while ($o = db_fetch_object($res))
  832. {
  833. $ret[] = $o ;
  834. }
  835. return $ret ;
  836. }
  837. }
  838.  
  839. /**
  840. * Subroutine for helpdesk_block/view
  841. * @param int $delta
  842. * @return array array of HTML blocks
  843. * @see helpdesk_block()
  844. */
  845. function _helpdesk_block_view ($delta)
  846. {
  847. $block = array() ;
  848.  
  849. if ($delta > HELPDESKBLOCKMAX)
  850. return $block;
  851.  
  852. switch ($delta)
  853. {
  854. case HELPDESKBLOCKMYOPENTICKETS:
  855. if (user_access(HELPDESKPERMUSER) || user_access(HELPDESKPERMCUSTOMER) || user_access(HELPDESKPERMTECH))
  856. {
  857. $block['subject'] = t('My open tickets');
  858. $block['content'] = _helpdesk_block_view_MYOPENTICKETS();
  859. }
  860. break ;
  861. case HELPDESKBLOCKMYLATESTTICKETS:
  862. if (user_access(HELPDESKPERMUSER) || user_access(HELPDESKPERMCUSTOMER) || user_access(HELPDESKPERMTECH))
  863. {
  864. $block['subject'] = t('My latest tickets');
  865. $block['content'] = _helpdesk_block_view_MYLATESTTICKETS();
  866. }
  867. break ;
  868. case HELPDESKBLOCKCUSTOMEROPENTICKETS:
  869. if (user_access(HELPDESKPERMCUSTOMER) || user_access(HELPDESKPERMTECH))
  870. {
  871. $block['subject'] = t('Customer\'s open tickets');
  872. $block['content'] = _helpdesk_block_view_CUSTOMEROPENTICKETS();
  873. }
  874. break ;
  875. case HELPDESKBLOCKCUSTOMERBALANCE:
  876. if (user_access(HELPDESKPERMCUSTOMER) || user_access(HELPDESKPERMTECH))
  877. {
  878. $block['subject'] = t('Customer\'s contract balance');
  879. $block['content'] = t('(none)') ;
  880. }
  881. break ;
  882. case HELPDESKBLOCKALLOPENTICKETS:
  883. if (user_access(HELPDESKPERMTECH))
  884. {
  885. $block['subject'] = t('All open tickets');
  886. $block['content'] = _helpdesk_block_view_ALLOPENTICKETS();
  887. }
  888. break ;
  889. }
  890. return $block ;
  891. }
  892.  
  893. /**
  894. * Build a block returning a list of the current user's open tickets.
  895. * - Open tickets are those for which tidstatus matches the first entry in the helpdesk_status vocabulary.
  896. * - SECURITY: relies on _helpdesk_block_view to filter requests. Does not implement security on its own.
  897. * @see _helpdesk_block_view()
  898. * @return string HTML code for the list
  899. */
  900. function _helpdesk_block_view_MYOPENTICKETS()
  901. {
  902. global $user ;
  903. $output = '' ;
  904. $csq = "
  905. SELECT n.nid, n.title
  906. FROM {hd_event} hde
  907. INNER JOIN {node} n on hde.nid = n.nid
  908. WHERE
  909. (n.uid = %d)
  910. and (hde.tidstatus <>
  911. (
  912. SELECT min(td.tid)
  913. FROM term_data td
  914. INNER JOIN vocabulary v on td.vid = v.vid
  915. WHERE
  916. v.name = 'helpdesk_status'
  917. ))
  918. " ;
  919.  
  920. $q = db_query ($csq, array($user->uid)) ;
  921. while ($o = db_fetch_object ($q))
  922. {
  923. $output .= l($o->title, 'node/' . $o->nid) . '<br/>' ;
  924. }
  925. unset ($q);
  926. unset ($csq) ;
  927. return _helpdesk_notempty($output, t('none')) ;
  928. }
  929.  
  930. /**
  931. * Build a block returning a list of all open tickets.
  932. * - Open tickets are those for which tidstatus matches the first entry in the helpdesk_status vocabulary.
  933. * - SECURITY: relies on _helpdesk_block_view to filter requests. Does not implement security on its own. User is assumed to have HELPDESKPERMTECH perm checked by the caller
  934. * @see _helpdesk_block_view()
  935. * @return string HTML code for the list
  936. */
  937. function _helpdesk_block_view_ALLOPENTICKETS()
  938. {
  939. $output = '' ;
  940. $csq = "
  941. SELECT n.nid, n.title
  942. FROM {hd_event} hde
  943. INNER JOIN {node} n on hde.nid = n.nid
  944. WHERE
  945. hde.tidstatus <>
  946. (
  947. SELECT min(td.tid)
  948. FROM term_data td
  949. INNER JOIN {vocabulary} v on td.vid = v.vid
  950. WHERE
  951. v.name = 'helpdesk_status'
  952. )
  953. " ;
  954. $q = db_query ($csq) ;
  955. while ($o = db_fetch_object ($q))
  956. {
  957. $output .= l($o->title, 'node/' . $o->nid) . '<br/>' ;
  958. }
  959. unset ($q);
  960. unset ($csq) ;
  961. return _helpdesk_notempty($output, t('none')) ;
  962. }
  963.  
  964. /**
  965. * Build a block returning a list of the latest tickets for the current user, be they open or not
  966. * - SECURITY: relies on _helpdesk_block_view to filter requests. Does not implement security on its own. User is assumed to have HELPDESKPERMCUSTOMER perm checked by caller
  967. * @see _helpdesk_block_view()
  968. * @return string HTML code for the list
  969. */
  970. function _helpdesk_block_view_MYLATESTTICKETS()
  971. {
  972. global $user ;
  973. $output = '' ;
  974. $csq = "
  975. SELECT n.nid, n.title
  976. FROM {hd_event} hde
  977. INNER JOIN {node} n on hde.nid = n.nid
  978. WHERE
  979. (n.uid = %d)
  980. ORDER BY
  981. n.changed DESC, n.created DESC
  982. " ;
  983.  
  984. $q = db_query ($csq, array($user->uid)) ;
  985. while ($o = db_fetch_object ($q))
  986. {
  987. $output .= l($o->title, 'node/' . $o->nid) . '<br/>' ;
  988. }
  989. unset ($q);
  990. unset ($csq) ;
  991. return _helpdesk_notempty($output, t('none')) ;
  992. }
  993. /**
  994. * Build a block returning a list of all open tickets for the users linked to this customer.
  995. * - Open tickets are those for which tidstatus matches the first entry in the helpdesk_status vocabulary.
  996. * - SECURITY: relies on _helpdesk_block_view to filter requests. Does not implement security on its own. User is assumed to have HELPDESKPERMCUSTOMER perm checked by caller
  997. * @see _helpdesk_block_view()
  998. * @return string HTML code for the list
  999. */
  1000. function _helpdesk_block_view_CUSTOMEROPENTICKETS()
  1001. {
  1002. global $user ;
  1003. $output = '' ;
  1004. $csq = "
  1005. SELECT n.nid, n.title
  1006. FROM {hd_event} hde
  1007. INNER JOIN {node} n on hde.nid = n.nid
  1008. INNER JOIN {hd_user} hdu on n.uid = hdu.uid
  1009. WHERE
  1010. (n.type = '%s')
  1011. AND (hdu.uidcustomer = %d)
  1012. AND hde.tidstatus <>
  1013. (
  1014. SELECT min(td.tid)
  1015. FROM term_data td
  1016. INNER JOIN {vocabulary} v on td.vid = v.vid
  1017. WHERE
  1018. v.name = 'helpdesk_status'
  1019. )
  1020. " ;
  1021. $q = db_query($csq, array(HELPDESKNODETICKET, $user->uid)) ;
  1022. while ($o = db_fetch_object ($q))
  1023. {
  1024. $output .= l($o->title, 'node/' . $o->nid) . '<br/>' ;
  1025. }
  1026. unset ($q);
  1027. unset ($csq) ;
  1028. return _helpdesk_notempty($output, t('none')) ;
  1029. }
  1030. /**
  1031. * Build the public form of the node number from the actual nid
  1032. *
  1033. * @param int $nid The internal node number for the ticket
  1034. * @return string The public form of the ticket number
  1035. * @see _helpdesk_decode_nid()
  1036. */
  1037. function _helpdesk_encode_nid($nid)
  1038. {
  1039. $prefix = variable_get(HELPDESKVARTICKETPREFIX, '') ;
  1040. $offset = variable_get(HELPDESKVARTICKETOFFSET, 0) ;
  1041. $ticketnumber = $prefix . ($nid + $offset) ;
  1042. unset($prefix);
  1043. unset($offset);
  1044. return $ticketnumber;
  1045. }
  1046. /**
  1047. * Extract the actual $node->nid from the public form of the ticket number
  1048. * @param string $ticketnumber The public form of the ticket number
  1049. * @return int The internal node number value for the ticket
  1050. * @see _helpdesk_encode_nid()
  1051. */
  1052. function _helpdesk_decode_nid($ticketnumber)
  1053. {
  1054. $prefix = variable_get(HELPDESKVARTICKETPREFIX, '') ;
  1055. $nid = substr($ticketnumber, strlen($prefix)) ;
  1056. $offset = variable_get(HELPDESKVARTICKETOFFSET, 0) ;
  1057. $nid -= $offset ;
  1058. unset($prefix);
  1059. unset($offset);
  1060. return $nid ;
  1061. }
  1062. /**
  1063. * auxiliary function for helpdesk_user('view')
  1064. * @param object $user
  1065. * @return array An associative array of strings to display, keyed by category name
  1066. * @see helpdesk_user
  1067. * @todo display global account balance, pointer to the list of contracts (for customers),
  1068. * @todo display global ticket starts, pointer to the list of tickets, followups (for users)
  1069. */
  1070. function _helpdesk_user_view($user)
  1071. {
  1072. $ret = NULL;
  1073. $output = NULL;
  1074. if (isset($user->uidCustomer)) // Can't use user_access(HELPDESKPERMUSER): admin will always get info even if he is not a HD user.
  1075. {
  1076. $ret .= t('<p>Helpdesk access managed by %customer-link</p>',
  1077. array('%customer-link' => l($user->customerName, 'user/' . $user->uidCustomer)));
  1078. }
  1079. if ($user->uidCustomer == $user->uid) // we are a customer
  1080. {
  1081. $ret .= "<p></p>";
  1082. $oc = new helpdeskCustomer();
  1083. $oc->uid = $user->uid ;
  1084. $oc->uidCustomer = $user->uidCustomer ;
  1085. $arUsers = $oc->uidUsers();
  1086. foreach($arUsers as $ou)
  1087. {
  1088. $arItems[] = l($ou->name, "user/$ou->uid", NULL) ;
  1089. }
  1090. $ret .= theme_item_list ($arItems, t('Managing helpdesk access for users:')) ;
  1091. unset($arItems);
  1092. unset($arUsers);
  1093. $arContracts = _helpdesk_getnidcontracts($user->uidCustomer); // User has already been checked as a customer: there must be a result
  1094. foreach($arContracts as $oc)
  1095. {
  1096. $arItems[] = l($oc->title, "node/$oc->nid", NULL) ;
  1097. }
  1098. $ret .= theme_item_list ($arItems, t('Holder of contracts:')) ;
  1099. }
  1100. if (isset($ret))
  1101. {
  1102. $ret .= t('Future versions will display more information, like '
  1103. . 'users\' stats: account balance, #tickets, and so on.') ;
  1104. $output = array ('Helpdesk account' => $ret) ;
  1105. }
  1106. return $output;
  1107. }
  1108. /**
  1109. * auxiliary function for helpdesk_user('categorie'). Currently, this displays the user roles and admin status if the module has been set up to do so.
  1110. * @return array
  1111. * @see helpdesk_user
  1112. */
  1113. function _helpdesk_user_categories()
  1114. {
  1115. if (variable_get (HELPDESKVARSHOWROLES, FALSE))
  1116. {
  1117. return array (
  1118. array (
  1119. "name" => "helpdeskroles",
  1120. "title" => t("user roles"),
  1121. "weight" => 1
  1122. )
  1123. ) ;
  1124. }
  1125. else
  1126. return NULL;
  1127. }
  1128.  
  1129. /**
  1130. * auxiliary function for helpdeks_user('form'), to be displayed when user tries to display/edit his own data:
  1131. * @param array $edit array of form values submitted by the user
  1132. * @param string $category The category of personal information to be displayed/edited
  1133. * @return array
  1134. * @see helpdesk_user
  1135. */
  1136. function _helpdesk_user_form($edit, $category)
  1137. {
  1138. global $user;
  1139. if (($category == 'helpdeskroles') && variable_get (HELPDESKVARSHOWROLES, FALSE)) // default category: account
  1140. {
  1141. $output = array
  1142. (
  1143. array
  1144. (
  1145. 'title' => t ('You have been assigned roles:'),
  1146. 'data' => '<li>' . implode ('</li><li>', $edit ['roles']) . '</li>',
  1147. 'weight'=> 0
  1148. )
  1149. ) ;
  1150.  
  1151. if ($user->uid == 1)
  1152. $output [0]['data'] .= t ("<li><em>sysop</em></li>") ;
  1153.  
  1154. if (isset($output))
  1155. $output [0]['data'] = '<ul>' . $output [0]['data'] . "</ul>" ;
  1156. }
  1157. else
  1158. $output = NULL;
  1159. return $output;
  1160. }
  1161. /**
  1162. * implements helpdesk_user('load') : load customer/hd user data upon user load
  1163. * do not load list of bound users for customers: this could be too heavy for something rarely (?) used
  1164. * @param object &$user already loaded core user object
  1165. * @param int $uid user id
  1166. * @return void
  1167. * @see helpdesk_user()
  1168. */
  1169. function _helpdesk_user_load(&$user, $uid)
  1170. {
  1171. if (HELPDESKDEBUGALLFUNCTIONS == TRUE)
  1172. { echo "<pre>HD USER_LOAD (uid = $uid)</pre>" ; }
  1173. $uo = new helpdeskUser();
  1174. $uo->init($uid) ;
  1175. if (isset($uo->uidCustomer))
  1176. {
  1177. $user->uidCustomer = $uo->uidCustomer ;
  1178. $user->customerName = $uo->customerName;
  1179. }
  1180. unset($uo);
  1181. }
  1182. /* ----- End of code, restore entry conditions ---------------------------------------- */
  1183. error_reporting ($_helpdesk_saved_er) ;
  1184. unset ($_helpdesk_saved_er) ;
  1185.  
  1186. //===== Remarks ==========================================================================
  1187. /* To page content, use this type of code:
  1188. $block_content .= "<div class=\"more-link\">"
  1189. . l (t ("more"), "helpdesk", array ("title" => t ("More events on this day.")))
  1190. . "</div>"; */
  1191.  
  1192. /*
  1193. 22/09/05 wnorrix chx: i have written a ticket module, is there a way i can send out a email when there is a comment added a) to the person who filled the ticket b) support team
  1194.  
  1195. /**
  1196. * @todo dans _view_*, mieux formater les blocs
  1197. */
  1198. ?>

Documentation generated on Tue, 01 Nov 2005 23:15:02 +0100 by phpDocumentor 1.3.0RC3