attendance_edit.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for editing an attendance.
  5. *
  6. * @author Christian Fasanando <christian1827@gmail.com>
  7. *
  8. * @package chamilo.attendance
  9. */
  10. // protect a course script
  11. api_protect_course_script(true);
  12. // error messages
  13. if (isset($error)) {
  14. echo Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error', false);
  15. }
  16. if (!isset($error)) {
  17. $token = Security::get_token();
  18. }
  19. $attendance_weight = api_float_val($attendance_weight);
  20. // display form
  21. $form = new FormValidator(
  22. 'attendance_edit',
  23. 'POST',
  24. 'index.php?action=attendance_edit&'.api_get_cidreq().'&attendance_id='.$attendance_id
  25. );
  26. $form->addElement('header', '', get_lang('Edit'));
  27. $form->addElement('hidden', 'sec_token', $token);
  28. $form->addElement('hidden', 'attendance_id', $attendance_id);
  29. $form->addText('title', get_lang('Title'), true);
  30. $form->applyFilter('title', 'html_filter');
  31. $form->addHtmlEditor(
  32. 'description',
  33. get_lang('Description'),
  34. false,
  35. false,
  36. [
  37. 'ToolbarSet' => 'Basic',
  38. 'Width' => '100%',
  39. 'Height' => '200',
  40. ]
  41. );
  42. // Advanced Parameters
  43. $skillList = [];
  44. if (Gradebook::is_active()) {
  45. if (!empty($attendance_qualify_title) || !empty($attendance_weight)) {
  46. $form->addButtonAdvancedSettings('id_qualify');
  47. $form->addElement('html', '<div id="id_qualify_options" style="display:block">');
  48. $form->addElement(
  49. 'checkbox',
  50. 'attendance_qualify_gradebook',
  51. '',
  52. get_lang('QualifyAttendanceGradebook'),
  53. [
  54. 'checked' => 'true',
  55. 'onclick' => 'javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}',
  56. ]
  57. );
  58. $form->addElement('html', '<div id="options_field" style="display:block">');
  59. } else {
  60. $form->addButtonAdvancedSettings('id_qualify');
  61. $form->addElement('html', '<div id="id_qualify_options" style="display:none">');
  62. $form->addElement(
  63. 'checkbox',
  64. 'attendance_qualify_gradebook',
  65. '',
  66. get_lang('QualifyAttendanceGradebook'),
  67. 'onclick="javascript: if(this.checked){document.getElementById(\'options_field\').style.display = \'block\';}else{document.getElementById(\'options_field\').style.display = \'none\';}"'
  68. );
  69. $form->addElement('html', '<div id="options_field" style="display:none">');
  70. }
  71. GradebookUtils::load_gradebook_select_in_tool($form);
  72. $form->addElement('text', 'attendance_qualify_title', get_lang('TitleColumnGradebook'));
  73. $form->applyFilter('attendance_qualify_title', 'html_filter');
  74. $form->addElement(
  75. 'text',
  76. 'attendance_weight',
  77. get_lang('QualifyWeight'),
  78. 'value="0.00" Style="width:40px" onfocus="javascript: this.select();"'
  79. );
  80. $form->applyFilter('attendance_weight', 'html_filter');
  81. $form->addElement('html', '</div>');
  82. $skillList = Skill::addSkillsToForm($form, ITEM_TYPE_ATTENDANCE, $attendance_id);
  83. $form->addElement('html', '</div>');
  84. }
  85. $form->addButtonUpdate(get_lang('Save'));
  86. // set default values
  87. $default['title'] = Security::remove_XSS($title);
  88. $default['description'] = Security::remove_XSS($description, STUDENT);
  89. $default['attendance_qualify_title'] = $attendance_qualify_title;
  90. $default['attendance_weight'] = $attendance_weight;
  91. $default['skills'] = array_keys($skillList);
  92. $link_info = GradebookUtils::isResourceInCourseGradebook(
  93. api_get_course_id(),
  94. 7,
  95. $attendance_id,
  96. api_get_session_id()
  97. );
  98. $default['category_id'] = $link_info['category_id'];
  99. $form->setDefaults($default);
  100. $form->display();