tools.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. // The section for the tabs
  5. $this_section = SECTION_COURSES;
  6. $sessionId = api_get_session_id();
  7. if (!empty($sessionId)) {
  8. api_not_allowed();
  9. }
  10. api_protect_course_script(true);
  11. if (!api_is_allowed_to_edit()) {
  12. api_not_allowed(true);
  13. }
  14. $action = isset($_GET['action']) ? $_GET['action'] : '';
  15. $id = isset($_GET['id']) ? intval($_GET['id']) : '';
  16. $toolName = get_lang('CustomizeIcons');
  17. switch ($action) {
  18. case 'delete_icon':
  19. $tool = CourseHome::getTool($id);
  20. if (empty($tool)) {
  21. api_not_allowed(true);
  22. }
  23. $currentUrl = api_get_self().'?'.api_get_cidreq();
  24. Display::addFlash(Display::return_message(get_lang('Updated')));
  25. CourseHome::deleteIcon($id);
  26. header('Location: '.$currentUrl);
  27. exit;
  28. break;
  29. case 'edit_icon':
  30. $tool = CourseHome::getTool($id);
  31. if (empty($tool)) {
  32. api_not_allowed(true);
  33. }
  34. $interbreadcrumb[] = array(
  35. 'url' => api_get_self().'?'.api_get_cidreq(),
  36. 'name' => get_lang('CustomizeIcons'),
  37. );
  38. $toolName = Security::remove_XSS(stripslashes($tool['name']));
  39. $currentUrl = api_get_self().'?action=edit_icon&id='.$id.'&'.api_get_cidreq();
  40. $form = new FormValidator('icon_edit', 'post', $currentUrl);
  41. $form->addHeader(get_lang('EditIcon'));
  42. $form->addHtml('<div class="col-md-7">');
  43. $form->addText('name', get_lang('Name'));
  44. $form->addText('link', get_lang('Links'));
  45. $allowed_picture_types = array('jpg', 'jpeg', 'png');
  46. $form->addFile('icon', get_lang('CustomIcon'));
  47. $form->addRule('icon', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  48. $form->addSelect(
  49. 'target',
  50. get_lang('LinkTarget'),
  51. [
  52. '_self' => get_lang('LinkOpenSelf'),
  53. '_blank' => get_lang('LinkOpenBlank')
  54. ]
  55. );
  56. $form->addSelect(
  57. 'visibility',
  58. get_lang('Visibility'),
  59. array(1 => get_lang('Visible'), 0 => get_lang('Invisible'))
  60. );
  61. $form->addTextarea(
  62. 'description',
  63. get_lang('Description'),
  64. array('rows' => '3', 'cols' => '40')
  65. );
  66. $form->addButtonUpdate(get_lang('Update'));
  67. $form->addHtml('</div>');
  68. $form->addHtml('<div class="col-md-5">');
  69. if (isset($tool['custom_icon']) && !empty($tool['custom_icon'])) {
  70. $form->addLabel(
  71. get_lang('CurrentIcon'),
  72. Display::img(
  73. CourseHome::getCustomWebIconPath().$tool['custom_icon']
  74. )
  75. );
  76. $form->addCheckBox('delete_icon', null, get_lang('DeletePicture'));
  77. }
  78. $form->addHtml('</div>');
  79. $form->setDefaults($tool);
  80. $content = $form->returnForm();
  81. if ($form->validate()) {
  82. $data = $form->getSubmitValues();
  83. CourseHome::updateTool($id, $data);
  84. Display::addFlash(Display::return_message(get_lang('Updated')));
  85. if (isset($data['delete_icon'])) {
  86. CourseHome::deleteIcon($id);
  87. }
  88. $currentUrlReturn = api_get_self().'?'.api_get_cidreq();
  89. header('Location: '.$currentUrlReturn);
  90. exit;
  91. }
  92. break;
  93. case 'list':
  94. default:
  95. $toolList = CourseHome::toolsIconsAction(
  96. api_get_course_int_id(),
  97. api_get_session_id()
  98. );
  99. $iconsTools = '<div id="custom-icons">';
  100. $iconsTools .= Display::page_header(get_lang('CustomizeIcons'), null, 'h4');
  101. $iconsTools .= '<div class="row">';
  102. foreach ($toolList as $tool) {
  103. $tool['name'] = Security::remove_XSS(stripslashes($tool['name']));
  104. $toolIconName = 'Tool'.api_underscore_to_camel_case($tool['name']);
  105. $toolIconName = isset($$toolIconName) ? get_lang($toolIconName) : $tool['name'];
  106. $iconsTools .= '<div class="col-md-2">';
  107. $iconsTools .= '<div class="items-tools">';
  108. if (!empty($tool['custom_icon'])) {
  109. $image = CourseHome::getCustomWebIconPath().$tool['custom_icon'];
  110. $icon = Display::img($image, $toolIconName);
  111. } else {
  112. $image = (substr($tool['image'], 0, strpos($tool['image'], '.'))).'.png';
  113. $icon = Display::return_icon(
  114. $image,
  115. $toolIconName,
  116. array('id' => 'tool_'.$tool['id']),
  117. ICON_SIZE_BIG,
  118. false
  119. );
  120. }
  121. $delete = (!empty($tool['custom_icon'])) ? "<a class=\"btn btn-default\" onclick=\"javascript:
  122. if(!confirm('".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset)).
  123. "')) return false;\" href=\"".api_get_self().'?action=delete_icon&id='.$tool['iid'].'&'.api_get_cidreq()."\">
  124. <em class=\"fa fa-trash-o\"></em></a>" : "";
  125. $edit = '<a class="btn btn-default" href="'.api_get_self().'?action=edit_icon&id='.$tool['iid'].'&'.api_get_cidreq().'"><em class="fa fa-pencil"></em></a>';
  126. $iconsTools .= '<div class="icon-tools">'.$icon.'</div>';
  127. $iconsTools .= '<div class="name-tools">'.$toolIconName.'</div>';
  128. $iconsTools .= '<div class="toolbar">'.$edit.$delete.'</div>';
  129. $iconsTools .= '</div>';
  130. $iconsTools .= '</div>';
  131. }
  132. $iconsTools .= '</div>';
  133. $iconsTools .= '</div>';
  134. $content = $iconsTools;
  135. break;
  136. }
  137. $tpl = new Template($toolName);
  138. $tpl->assign('content', $content);
  139. $template = $tpl->get_template('layout/layout_1_col.tpl');
  140. $tpl->display($template);