thematic.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * View (MVC patter) for thematic control
  5. * @author Christian Fasanando <christian1827@gmail.com>
  6. * @author Julio Montoya <gugli100@gmail.com> Bug fixing
  7. * @package chamilo.course_progress
  8. */
  9. // protect a course script
  10. api_protect_course_script(true);
  11. if (api_is_allowed_to_edit(null, true)) {
  12. echo '<div class="actions" style="margin-bottom:30px">';
  13. switch ($action) {
  14. case 'thematic_add' :
  15. echo '<a href="index.php?'.api_get_cidreq().'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ThematicDetails'),'','32').'</a>';
  16. //echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('view_table.gif',get_lang('ThematicDetails')).' '.get_lang('ThematicDetails').'</a>';//TODO:delete, no need
  17. //echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_list.gif',get_lang('ThematicList')).' '.get_lang('ThematicList').'</a>';//TODO:delete, no need
  18. break;
  19. case 'thematic_list' :
  20. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
  21. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('view_detailed.png',get_lang('ThematicDetails'),'','32').'</a>';
  22. //echo '<strong>'.Display::return_icon('view_list.gif',get_lang('ThematicList')).' '.get_lang('ThematicList').'</strong>&nbsp;&nbsp;';//TODO:delete, no need
  23. break;
  24. case 'thematic_details' :
  25. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
  26. //echo '<strong>'.Display::return_icon('view_table.gif',get_lang('ThematicDetails')).' '.get_lang('ThematicDetails').'</strong>&nbsp;&nbsp;';////TODO:delete, no need
  27. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_text.png',get_lang('ThematicList'),'','32').'</a>';
  28. break;
  29. default :
  30. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'','32').'</a>';
  31. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_details">'.Display::return_icon('view_detailed.png',get_lang('ThematicDetails'),'','32').'</a>';
  32. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_list">'.Display::return_icon('view_text.png',get_lang('ThematicList'),'','32').'</a>';
  33. }
  34. echo '</div>';
  35. }
  36. if ($action == 'thematic_list') {
  37. $table = new SortableTable('thematic_list', array('Thematic', 'get_number_of_thematics'), array('Thematic', 'get_thematic_data'));
  38. $parameters['action'] = $action;
  39. $table->set_additional_parameters($parameters);
  40. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  41. $table->set_header(1, get_lang('Title'), false );
  42. if (api_is_allowed_to_edit(null, true)) {
  43. $table->set_header(2, get_lang('Actions'), false,array('style'=>'text-align:center;width:40%;'));
  44. $table->set_form_actions(array ('thematic_delete_select' => get_lang('DeleteAllThematics')));
  45. }
  46. //echo '<div><strong>'.get_lang('ThematicList').'</strong></div><br />';
  47. $table->display();
  48. } else if ($action == 'thematic_details') {
  49. if ($last_id) {
  50. $link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'.Display::return_icon('lesson_plan.png', get_lang('ThematicPlan'), array('style'=>'vertical-align:middle'),22).'</a>';
  51. $link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'.Display::return_icon('lesson_plan_calendar.png', get_lang('ThematicAdvance'), array('style'=>'vertical-align:middle'),22).'</a>';
  52. Display::display_confirmation_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'),$link_to_thematic_plan, $link_to_thematic_advance), false);
  53. }
  54. // display title
  55. if (!empty($thematic_id)) {
  56. //echo '<div><strong>'.Security::remove_XSS($thematic_data[$thematic_id]['title'], STUDENT).': '.get_lang('Details').'</strong></div><br />';
  57. } else {
  58. //echo '<div><strong>'.get_lang('ThematicDetails').'</strong></div><br />';
  59. // display information
  60. $message = '<strong>'.get_lang('Information').'</strong><br />';
  61. $message .= get_lang('ThematicDetailsDescription');
  62. Display::display_normal_message($message, false);
  63. echo '<br />';
  64. }
  65. // display thematic data
  66. if (!empty($thematic_data)) {
  67. // display progress
  68. echo '<div style="text-align:right;"><h2>'.get_lang('Progress').': <span id="div_result">'.$total_average_of_advances.'</span> %</h2></div>';
  69. echo '<table width="100%" class="data_table">';
  70. echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>';
  71. foreach ($thematic_data as $thematic) {
  72. $session_star = '';
  73. if (api_get_session_id() == $thematic['session_id']) {
  74. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  75. } else {
  76. continue;
  77. }
  78. echo '<tr>';
  79. // display thematic title
  80. echo '<td><h2>'.Security::remove_XSS($thematic['title'], STUDENT).$session_star.'</h2><div>'.Security::remove_XSS($thematic['content'], STUDENT).'</div></td>';
  81. // display thematic plan data
  82. echo '<td>';
  83. if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  84. echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_plan_list&thematic_id='.$thematic['id'].'">'.Display::return_icon('edit.png',get_lang('EditThematicPlan'),array('style'=>'vertical-align:middle'),22).'</a></div><br />';
  85. }
  86. $new_thematic_plan_data = array();
  87. if (!empty($thematic_plan_data[$thematic['id']]))
  88. foreach($thematic_plan_data[$thematic['id']] as $thematic_item) {
  89. $thematic_simple_list[] = $thematic_item['description_type'];
  90. $new_thematic_plan_data[$thematic_item['description_type']] = $thematic_item;
  91. }
  92. $new_id = ADD_THEMATIC_PLAN;
  93. if (!empty($thematic_simple_list))
  94. foreach($thematic_simple_list as $item) {
  95. if ($item >= ADD_THEMATIC_PLAN) {
  96. $new_id = $item + 1;
  97. $default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
  98. }
  99. }
  100. $no_data = true;
  101. if (!empty($default_thematic_plan_title)) {
  102. foreach ($default_thematic_plan_title as $id=>$title) {
  103. //avoid others
  104. if ($title == 'Others' && empty($thematic_plan_data[$thematic['id']][$id]['description'])) { continue; }
  105. if (!empty($thematic_plan_data[$thematic['id']][$id]['title']) && !empty($thematic_plan_data[$thematic['id']][$id]['description'])) {
  106. echo '<h3>'.Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['title'], STUDENT).'</h3><div>';
  107. echo Security::remove_XSS($thematic_plan_data[$thematic['id']][$id]['description'], STUDENT).'</div>';
  108. $no_data = false;
  109. } else {
  110. //echo '<h3>'.$title.'</strong></h3><br />';
  111. }
  112. }
  113. }
  114. if ($no_data) {
  115. echo '<div><em>'.get_lang('StillDoNotHaveAThematicPlan').'</em></div>';
  116. }
  117. echo '</td>';
  118. // display thematic advance data
  119. echo '<td>';
  120. if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  121. echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_advance_list&thematic_id='.$thematic['id'].'">'.Display::return_icon('edit.png',get_lang('EditThematicAdvance'),array('style'=>'vertical-align:middle'),22).'</a></div><br />';
  122. }
  123. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  124. if (!empty($thematic_advance_data[$thematic['id']])) {
  125. echo '<table width="100%">';
  126. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  127. $thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
  128. $thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
  129. echo '<tr>';
  130. echo '<td width="90%">';
  131. echo '<div><strong>'.$thematic_advance['start_date'].'</strong></div>';
  132. echo '<div>'.Security::remove_XSS($thematic_advance['content'], STUDENT).'</div>';
  133. echo '<div>'.get_lang('DurationInHours').' : '.$thematic_advance['duration'].'</div>';
  134. echo '</td>';
  135. if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  136. if (empty($thematic_id)) {
  137. $checked = '';
  138. if ($last_done_thematic_advance == $thematic_advance['id']) {
  139. $checked = 'checked';
  140. }
  141. $style = '';
  142. if ($thematic_advance['done_advance'] == 1) {
  143. $style = ' style="background-color:#E5EDF9" ';
  144. } else {
  145. $style = ' style="background-color:#fff" ';
  146. }
  147. echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center><input type="radio" id="done_thematic_'.$thematic_advance['id'].'" name="done_thematic" value="'.$thematic_advance['id'].'" '.$checked.' onclick="update_done_thematic_advance(this.value)"></center></td>';
  148. } else {
  149. if ($thematic_advance['done_advance'] == 1) {
  150. echo '<td><center>'.get_lang('Done').'</center></td>';
  151. } else {
  152. echo '<td><center>-</center></td>';
  153. }
  154. }
  155. }
  156. echo '</tr>';
  157. }
  158. echo '</table>';
  159. } else {
  160. echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>';
  161. }
  162. echo '</td>';
  163. echo '</tr>';
  164. } //End for
  165. echo '</table>';
  166. } else {
  167. echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
  168. }
  169. } else if ($action == 'thematic_add' || $action == 'thematic_edit') {
  170. if (!$error) {
  171. //@todo why the heck you create your token? use Security::get_token()! jm
  172. $token = md5(uniqid(rand(),TRUE));
  173. $_SESSION['thematic_token'] = $token;
  174. }
  175. // Display form
  176. $form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
  177. if ($action == 'thematic_edit') {
  178. $form->addElement('header', '', get_lang('EditThematicSection'));
  179. }
  180. $form->addElement('hidden', 'thematic_token',$token);
  181. $form->addElement('hidden', 'action', $action);
  182. if (!empty($thematic_id)) {
  183. $form->addElement('hidden', 'thematic_id',$thematic_id);
  184. }
  185. $form->add_textfield('title', get_lang('Title'), true, array('size'=>'50'));
  186. $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '100%', 'Height' => '250'));
  187. $form->addElement('html','<div class="clear" style="margin-top:50px;"></div>');
  188. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  189. $show_form = true;
  190. if (!empty($thematic_data)) {
  191. if (api_get_session_id()) {
  192. if ($thematic_data['session_id'] != api_get_session_id()) {
  193. $show_form = false;
  194. Display::display_error_message(get_lang('NotAllowedClickBack'),false);
  195. }
  196. }
  197. // set default values
  198. $default['title'] = $thematic_data['title'];
  199. $default['content'] = $thematic_data['content'];
  200. $form->setDefaults($default);
  201. }
  202. // error messages
  203. if ($error) {
  204. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
  205. }
  206. if ($show_form)
  207. $form->display();
  208. }