career_diagram.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Fhaculty\Graph\Graph;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. /*
  8. *
  9. * Requires extra_field_values.value to be longtext to save diagram:
  10. *
  11. UPDATE extra_field_values SET created_at = NULL WHERE CAST(created_at AS CHAR(20)) = '0000-00-00 00:00:00';
  12. UPDATE extra_field_values SET updated_at = NULL WHERE CAST(updated_at AS CHAR(20)) = '0000-00-00 00:00:00';
  13. ALTER TABLE extra_field_values modify column value longtext null;
  14. */
  15. $cidReset = true;
  16. require_once __DIR__.'/../inc/global.inc.php';
  17. if (api_get_configuration_value('allow_career_diagram') == false) {
  18. api_not_allowed(true);
  19. }
  20. $this_section = SECTION_PLATFORM_ADMIN;
  21. $allowCareer = api_get_configuration_value('allow_session_admin_read_careers');
  22. api_protect_admin_script($allowCareer);
  23. $htmlHeadXtra[] = api_get_js('jsplumb2.js');
  24. $careerId = isset($_GET['id']) ? $_GET['id'] : 0;
  25. if (empty($careerId)) {
  26. api_not_allowed(true);
  27. }
  28. $career = new Career();
  29. $careerInfo = $career->get($careerId);
  30. if (empty($careerInfo)) {
  31. api_not_allowed(true);
  32. }
  33. // setting breadcrumbs
  34. $interbreadcrumb[] = [
  35. 'url' => 'index.php',
  36. 'name' => get_lang('PlatformAdmin'),
  37. ];
  38. $interbreadcrumb[] = [
  39. 'url' => 'career_dashboard.php',
  40. 'name' => get_lang('CareersAndPromotions'),
  41. ];
  42. $interbreadcrumb[] = [
  43. 'url' => 'careers.php',
  44. 'name' => get_lang('Careers'),
  45. ];
  46. $action = isset($_GET['action']) ? $_GET['action'] : '';
  47. $check = Security::check_token('request');
  48. $token = Security::get_token();
  49. if ($action == 'add') {
  50. $interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
  51. $toolName = get_lang('Add');
  52. } elseif ($action == 'edit') {
  53. $interbreadcrumb[] = ['url' => 'careers.php', 'name' => get_lang('Careers')];
  54. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
  55. $toolName = get_lang('Edit');
  56. } else {
  57. $toolName = get_lang('Careers');
  58. }
  59. $extraFieldValue = new ExtraFieldValue('career');
  60. $item = $extraFieldValue->get_values_by_handler_and_field_variable(
  61. $careerId,
  62. 'career_diagram',
  63. false,
  64. false,
  65. false
  66. );
  67. // Check urls
  68. $itemUrls = $extraFieldValue->get_values_by_handler_and_field_variable(
  69. $careerId,
  70. 'career_urls',
  71. false,
  72. false,
  73. false
  74. );
  75. $urlToString = '';
  76. if (!empty($itemUrls) && !empty($itemUrls['value'])) {
  77. $urls = explode(',', $itemUrls['value']);
  78. $urlToString = '&nbsp;&nbsp;';
  79. if (!empty($urls)) {
  80. foreach ($urls as $urlData) {
  81. $urlData = explode('@', $urlData);
  82. if (isset($urlData[1])) {
  83. $urlToString .= Display::url($urlData[0], $urlData[1]).'&nbsp;';
  84. } else {
  85. $urlToString .= $urlData[0].'&nbsp;';
  86. }
  87. }
  88. }
  89. }
  90. $tpl = new Template(get_lang('Diagram'));
  91. $html = Display::page_subheader2($careerInfo['name'].$urlToString);
  92. if (!empty($item) && isset($item['value']) && !empty($item['value'])) {
  93. /** @var Graph $graph */
  94. $graph = UnserializeApi::unserialize('career', $item['value']);
  95. $html .= Career::renderDiagramByColumn($graph, $tpl);
  96. } else {
  97. Display::addFlash(
  98. Display::return_message(
  99. sprintf(get_lang('CareerXDoesntHaveADiagram'), $careerInfo['name']),
  100. 'warning'
  101. )
  102. );
  103. }
  104. $tpl->assign('content', $html);
  105. $layout = $tpl->get_template('career/diagram.tpl');
  106. $tpl->display($layout);