skill_badge_create.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Show information about Mozilla OpenBadges
  5. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  6. * @package chamilo.admin.openbadges
  7. */
  8. use ChamiloSession as Session;
  9. $cidReset = true;
  10. require_once '../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. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  19. $params = array(
  20. 'name' => $_POST['name'],
  21. 'description' => $_POST['description'],
  22. 'criteria' => $_POST['criteria'],
  23. 'id' => $skillId
  24. );
  25. if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {
  26. $dirPermissions = api_get_permissions_for_new_directories();
  27. $fileName = sha1($_POST['name']);
  28. $badgePath = api_get_path(SYS_UPLOAD_PATH).'badges/';
  29. $existsBadgesDirectory = is_dir($badgePath);
  30. if (!$existsBadgesDirectory) {
  31. $existsBadgesDirectory = api_create_protected_dir('badges', api_get_path(SYS_UPLOAD_PATH));
  32. }
  33. if ($existsBadgesDirectory) {
  34. if (!empty($skill['icon'])) {
  35. $iconFileAbsolutePath = $badgePath . $skill['icon'];
  36. if (Security::check_abs_path($iconFileAbsolutePath, $badgePath)) {
  37. unlink($badgePath . $skill['icon']);
  38. }
  39. }
  40. $skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);
  41. $skillImage = new Image($_FILES['image']['tmp_name']);
  42. $skillImage->send_image($skillImagePath, -1, 'png');
  43. $skillThumbPath = sprintf("%s%s-small.png", $badgePath, $fileName);
  44. $skillImageThumb = new Image($skillImagePath);
  45. $skillImageThumb->resize(ICON_SIZE_BIG, ICON_SIZE_BIG);
  46. $skillImageThumb->send_image($skillThumbPath);
  47. $params['icon'] = sprintf("%s.png", $fileName);
  48. } else {
  49. Session::write('errorMessage', get_lang('UplUnableToSaveFile'));
  50. }
  51. }
  52. $objSkill->update($params);
  53. header('Location: ' . api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php');
  54. exit;
  55. }
  56. $interbreadcrumb = array(
  57. array(
  58. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/index.php',
  59. 'name' => get_lang('Administration')
  60. ),
  61. array(
  62. 'url' => api_get_path(WEB_CODE_PATH) . 'admin/skill_badge.php',
  63. 'name' => get_lang('Badges')
  64. )
  65. );
  66. $toolbar = Display::toolbarButton(
  67. get_lang('ManageSkills'),
  68. api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php',
  69. 'list',
  70. 'primary',
  71. ['title' => get_lang('ManageSkills')]
  72. );
  73. $tpl = new Template(get_lang('CreateBadge'));
  74. $tpl->assign('platformAdminEmail', api_get_setting('emailAdministrator'));
  75. $tpl->assign('skill', $skill);
  76. $contentTemplate = $tpl->fetch('default/skill/badge_create.tpl');
  77. $tpl->assign('actions', $toolbar);
  78. $tpl->assign('content', $contentTemplate);
  79. $tpl->display_one_col_template();