career_diagram.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /*
  4. *
  5. * Requires extra_field_values.value to be longtext to save diagram:
  6. *
  7. UPDATE extra_field_values SET created_at = NULL WHERE CAST(created_at AS CHAR(20)) = '0000-00-00 00:00:00';
  8. UPDATE extra_field_values SET updated_at = NULL WHERE CAST(updated_at AS CHAR(20)) = '0000-00-00 00:00:00';
  9. ALTER TABLE extra_field_values modify column value longtext null;
  10. */
  11. require_once __DIR__.'/../inc/global.inc.php';
  12. if (api_get_configuration_value('allow_career_diagram') == false) {
  13. api_not_allowed(true);
  14. }
  15. $this_section = SECTION_COURSES;
  16. $careerId = isset($_GET['career_id']) ? $_GET['career_id'] : 0;
  17. if (empty($careerId)) {
  18. api_not_allowed(true);
  19. }
  20. $career = new Career();
  21. $careerInfo = $career->get($careerId);
  22. if (empty($careerInfo)) {
  23. api_not_allowed(true);
  24. }
  25. $userId = api_get_user_id();
  26. $allow = UserManager::userHasCareer($userId, $careerId) || api_is_platform_admin();
  27. if ($allow === false) {
  28. api_not_allowed(true);
  29. }
  30. $htmlHeadXtra[] = api_get_js('jsplumb2.js');
  31. $htmlHeadXtra[] = api_get_asset('qtip2/jquery.qtip.min.js');
  32. $htmlHeadXtra[] = api_get_css_asset('qtip2/jquery.qtip.min.css');
  33. // setting breadcrumbs
  34. $interbreadcrumb[] = [
  35. 'url' => api_get_path(WEB_CODE_PATH).'auth/my_progress.php',
  36. 'name' => get_lang('Progress'),
  37. ];
  38. $interbreadcrumb[] = [
  39. 'url' => '#',
  40. 'name' => get_lang('Careers'),
  41. ];
  42. $extraFieldValue = new ExtraFieldValue('career');
  43. // Check urls
  44. $itemUrls = $extraFieldValue->get_values_by_handler_and_field_variable(
  45. $careerId,
  46. 'career_urls',
  47. false,
  48. false,
  49. false
  50. );
  51. $urlToString = '';
  52. if (!empty($itemUrls) && !empty($itemUrls['value'])) {
  53. $urls = explode(',', $itemUrls['value']);
  54. $urlToString = '&nbsp;&nbsp;';
  55. if (!empty($urls)) {
  56. foreach ($urls as $urlData) {
  57. $urlData = explode('@', $urlData);
  58. if (isset($urlData[1])) {
  59. $urlToString .= Display::url($urlData[0], $urlData[1]).'&nbsp;';
  60. } else {
  61. $urlToString .= $urlData[0].'&nbsp;';
  62. }
  63. }
  64. }
  65. }
  66. $tpl = new Template(get_lang('Diagram'));
  67. $html = Display::page_subheader2($careerInfo['name'].$urlToString);
  68. $diagram = Career::renderDiagramByColumn($careerInfo, $tpl, $userId);
  69. if (!empty($diagram)) {
  70. $html .= $diagram;
  71. } else {
  72. Display::addFlash(
  73. Display::return_message(
  74. sprintf(get_lang('Career %s doesn\'t have a diagram.'), $careerInfo['name']),
  75. 'warning'
  76. )
  77. );
  78. }
  79. $tpl->assign('content', $html);
  80. $layout = $tpl->get_template('career/diagram.tpl');
  81. $tpl->display($layout);