skill_badge_create.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Show information about Mozilla OpenBadges
  6. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  7. * @package chamilo.admin.openbadges
  8. */
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
  12. api_not_allowed(true);
  13. }
  14. $this_section = SECTION_PLATFORM_ADMIN;
  15. $skillId = intval($_GET['id']);
  16. $objSkill = new Skill();
  17. $skill = $objSkill->get($skillId);
  18. $htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/css/core.css" rel="stylesheet">';
  19. // Add badge studio paths
  20. $badgeStudio = [
  21. 'core' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/',
  22. 'media' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/',
  23. 'templates' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/images/templates/',
  24. 'masks' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/images/masks/',
  25. 'script_js' => '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/js/studio.js?"></script>'
  26. ];
  27. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  28. $params = array(
  29. 'name' => $_POST['name'],
  30. 'description' => $_POST['description'],
  31. 'criteria' => $_POST['criteria'],
  32. 'id' => $skillId
  33. );
  34. if ((isset($_FILES['image']) && $_FILES['image']['error'] == 0) || !empty($_POST['badge_studio_image'])) {
  35. $dirPermissions = api_get_permissions_for_new_directories();
  36. $fileName = sha1($_POST['name']);
  37. $badgePath = api_get_path(SYS_UPLOAD_PATH).'badges/';
  38. $existsBadgesDirectory = is_dir($badgePath);
  39. if (!$existsBadgesDirectory) {
  40. $existsBadgesDirectory = api_create_protected_dir('badges', api_get_path(SYS_UPLOAD_PATH));
  41. }
  42. if ($existsBadgesDirectory) {
  43. if (!empty($skill['icon'])) {
  44. $iconFileAbsolutePath = $badgePath.$skill['icon'];
  45. if (Security::check_abs_path($iconFileAbsolutePath, $badgePath)) {
  46. unlink($badgePath.$skill['icon']);
  47. }
  48. }
  49. $skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);
  50. if (!empty($_POST['badge_studio_image'])) {
  51. $badgeImage = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $_POST['badge_studio_image']));
  52. file_put_contents($skillImagePath, $badgeImage);
  53. $skillImage = new Image($skillImagePath);
  54. } else {
  55. $skillImage = new Image($_FILES['image']['tmp_name']);
  56. }
  57. $skillImage->send_image($skillImagePath, -1, 'png');
  58. $skillThumbPath = sprintf("%s%s-small.png", $badgePath, $fileName);
  59. $skillImageThumb = new Image($skillImagePath);
  60. $skillImageThumb->resize(ICON_SIZE_BIG);
  61. $skillImageThumb->send_image($skillThumbPath);
  62. $params['icon'] = sprintf("%s.png", $fileName);
  63. } else {
  64. Session::write('errorMessage', get_lang('UplUnableToSaveFile'));
  65. }
  66. }
  67. $objSkill->update($params);
  68. header('Location: '.api_get_path(WEB_CODE_PATH).'admin/skill_badge_list.php');
  69. exit;
  70. }
  71. $interbreadcrumb = array(
  72. array(
  73. 'url' => api_get_path(WEB_CODE_PATH).'admin/index.php',
  74. 'name' => get_lang('Administration')
  75. ),
  76. array(
  77. 'url' => api_get_path(WEB_CODE_PATH).'admin/skill_badge.php',
  78. 'name' => get_lang('Badges')
  79. )
  80. );
  81. $toolbar = Display::toolbarButton(
  82. get_lang('ManageSkills'),
  83. api_get_path(WEB_CODE_PATH).'admin/skill_list.php',
  84. 'list',
  85. 'primary',
  86. ['title' => get_lang('ManageSkills')]
  87. );
  88. $tpl = new Template(get_lang('CreateBadge'));
  89. $tpl->assign('platformAdminEmail', api_get_setting('emailAdministrator'));
  90. $tpl->assign('skill', $skill);
  91. $tpl->assign('badge_studio', $badgeStudio);
  92. $templateName = $tpl->get_template('skill/badge_create.tpl');
  93. $contentTemplate = $tpl->fetch($templateName);
  94. $tpl->assign(
  95. 'actions',
  96. Display::toolbarAction('toolbar', [$toolbar])
  97. );
  98. $tpl->assign('content', $contentTemplate);
  99. $tpl->display_one_col_template();