thematic.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. $token = Security::get_token();
  12. $url_token = "&sec_token=".$token;
  13. if (api_is_allowed_to_edit(null, true)) {
  14. echo '<div class="actions" style="margin-bottom:30px">';
  15. switch ($action) {
  16. case 'thematic_add' :
  17. echo '<a href="index.php?'.api_get_cidreq().'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ThematicDetails'),'',ICON_SIZE_MEDIUM).'</a>';
  18. break;
  19. case 'thematic_list' :
  20. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
  21. break;
  22. case 'thematic_details' :
  23. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
  24. break;
  25. default :
  26. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'.Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
  27. }
  28. echo '</div>';
  29. }
  30. if ($action == 'thematic_list') {
  31. $table = new SortableTable('thematic_list', array('Thematic', 'get_number_of_thematics'), array('Thematic', 'get_thematic_data'));
  32. $parameters['action'] = $action;
  33. $table->set_additional_parameters($parameters);
  34. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  35. $table->set_header(1, get_lang('Title'), false );
  36. if (api_is_allowed_to_edit(null, true)) {
  37. $table->set_header(2, get_lang('Actions'), false,array('style'=>'text-align:center;width:40%;'));
  38. $table->set_form_actions(array ('thematic_delete_select' => get_lang('DeleteAllThematics')));
  39. }
  40. $table->display();
  41. } elseif ($action == 'thematic_details') {
  42. if ($last_id) {
  43. $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'),ICON_SIZE_SMALL).'</a>';
  44. $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'),ICON_SIZE_SMALL).'</a>';
  45. Display::display_confirmation_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'),$link_to_thematic_plan, $link_to_thematic_advance), false);
  46. }
  47. // display title
  48. if (!empty($thematic_id)) {
  49. } else {
  50. // display information
  51. $message = '<strong>'.get_lang('Information').'</strong><br />';
  52. $message .= get_lang('ThematicDetailsDescription');
  53. Display::display_normal_message($message, false);
  54. echo '<br />';
  55. }
  56. // display thematic data
  57. if (!empty($thematic_data)) {
  58. // display progress
  59. echo '<div style="text-align:right;"><h2>'.get_lang('Progress').': <span id="div_result">'.$total_average_of_advances.'</span> %</h2></div>';
  60. echo '<table width="100%" class="data_table">';
  61. echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>';
  62. foreach ($thematic_data as $thematic) {
  63. $my_thematic_id = $thematic['id'];
  64. $session_star = '';
  65. if (api_is_allowed_to_edit(null, true)) {
  66. if (api_get_session_id() == $thematic['session_id']) {
  67. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  68. }
  69. }
  70. //@todo add a validation in order to load or not course thematics in the session thematic
  71. /*
  72. if (api_get_session_id() == $thematic['session_id']) {
  73. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  74. } else {
  75. continue;
  76. } */
  77. echo '<tr>';
  78. $actions_first_col = '';
  79. if (api_is_allowed_to_edit(null, true)) {
  80. // Thematic title
  81. $actions_first_col = Display::url(Display::return_icon('cd.gif', get_lang('Copy')), 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$param_gradebook.$url_token);
  82. if (api_get_session_id() == 0 ) {
  83. if ($thematic['display_order'] > 1) {
  84. $actions_first_col .= ' <a href="'.api_get_self().'?action=moveup&'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('up.png', get_lang('Up'),'',ICON_SIZE_SMALL).'</a>';
  85. } else {
  86. $actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
  87. }
  88. if ($thematic['display_order'] < $thematic['max_thematic_item']) {
  89. $actions_first_col .= ' <a href="'.api_get_self().'?action=movedown&a'.api_get_cidreq().'&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('down.png',get_lang('Down'),'',ICON_SIZE_SMALL).'</a>';
  90. } else {
  91. $actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
  92. }
  93. }
  94. if (api_get_session_id() == $thematic['session_id']) {
  95. $actions_first_col .= '<a href="index.php?'.api_get_cidreq().'&action=thematic_edit&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>';
  96. $actions_first_col .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_delete&thematic_id='.$my_thematic_id.$param_gradebook.$url_token.'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  97. }
  98. $actions_first_col = Display::div($actions_first_col, array('id'=>'thematic_id_content_'.$thematic['id'], 'class'=>'thematic_tools'));
  99. $actions_first_col = Display::div($actions_first_col, array('style'=>'height:20px'));
  100. }
  101. echo Display::tag('td', Display::tag('h3', Security::remove_XSS($thematic['title'], STUDENT).$session_star).Security::remove_XSS($thematic['content'], STUDENT).$actions_first_col, array('id'=>'thematic_td_content_'.$thematic['id'], 'class'=>'thematic_content'));
  102. // Display 2nd column - thematic plan data
  103. echo '<td>';
  104. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  105. if (api_is_allowed_to_edit(null, true)) {
  106. echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&origin=thematic_details&action=thematic_plan_list&thematic_id='.$thematic['id'].'&width=700&height=500">'.
  107. Display::return_icon('edit.png', get_lang('EditThematicPlan'), array('style'=>'vertical-align:middle'),ICON_SIZE_MEDIUM).'</a></div><br />';
  108. }
  109. if (empty($thematic_plan_div[$thematic['id']])) {
  110. echo Display::div('', array('id' => "thematic_plan_".$thematic['id']));
  111. } else {
  112. echo $thematic_plan_div[$thematic['id']];
  113. }
  114. echo '</td>';
  115. // Display 3rd column - thematic advance data
  116. echo '<td style="vertical-align:top">';
  117. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  118. if (api_is_allowed_to_edit(null, true)) {
  119. echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&action=thematic_advance_add&thematic_id='.$thematic['id'].'">'.Display::return_icon('add.png',get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a></div>';
  120. }
  121. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  122. if (!empty($thematic_advance_data[$thematic['id']])) {
  123. echo '<table width="100%">';
  124. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  125. $thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
  126. $thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
  127. echo '<tr>';
  128. echo '<td width="90%" class="thematic_advance_content" id="thematic_advance_content_id_'.$thematic_advance['id'].'">';
  129. $edit_link = '';
  130. if (api_is_allowed_to_edit(null, true)) {
  131. $edit_link = '<a class="thickbox" href="index.php?'.api_get_cidreq().'&action=thematic_advance_edit&thematic_id='.$thematic['id'].'&thematic_advance_id='.$thematic_advance['id'].'" >'.Display::return_icon('edit.png',get_lang('EditThematicAdvance'),array(),ICON_SIZE_SMALL).'</a>';
  132. $edit_link .= '<a onclick="javascript:if(!confirm(\''.get_lang('AreYouSureToDelete').'\')) return false;" href="index.php?'.api_get_cidreq().'&action=thematic_advance_delete&thematic_id='.$thematic['id'].'&thematic_advance_id='.$thematic_advance['id'].'">'.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a></center>';
  133. //Links
  134. $edit_link = Display::div(Display::div($edit_link , array('id'=>'thematic_advance_tools_'.$thematic_advance['id'], 'class'=>'thematic_advance_actions')), array('style'=>'height:20px;'));
  135. }
  136. $thematic_advance_item = isset($thematic_advance_div[$thematic['id']][$thematic_advance['id']]) ? $thematic_advance_div[$thematic['id']][$thematic_advance['id']] : null;
  137. echo Display::div($thematic_advance_item, array('id'=>'thematic_advance_'.$thematic_advance['id']));
  138. echo $edit_link;
  139. echo '</td>';
  140. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  141. if (api_is_allowed_to_edit(null, true)) {
  142. if (empty($thematic_id)) {
  143. $checked = '';
  144. if ($last_done_thematic_advance == $thematic_advance['id']) {
  145. $checked = 'checked';
  146. }
  147. $style = '';
  148. if ($thematic_advance['done_advance'] == 1) {
  149. $style = ' style="background-color:#E5EDF9" ';
  150. } else {
  151. $style = ' style="background-color:#fff" ';
  152. }
  153. echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>';
  154. echo '<input type="radio" class="done_thematic" id="done_thematic_'.$thematic_advance['id'].'" name="done_thematic" value="'.$thematic_advance['id'].'" '.$checked.' onclick="update_done_thematic_advance(this.value)">';
  155. echo '</center></td>';
  156. } else {
  157. if ($thematic_advance['done_advance'] == 1) {
  158. echo '<td><center>'.get_lang('Done').'</center></td>';
  159. } else {
  160. echo '<td><center>-</center></td>';
  161. }
  162. }
  163. }
  164. echo '</tr>';
  165. }
  166. echo '</table>';
  167. } else {
  168. echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>';
  169. }
  170. echo '</td>';
  171. echo '</tr>';
  172. } //End for
  173. echo '</table>';
  174. } else {
  175. echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
  176. }
  177. } else if ($action == 'thematic_add' || $action == 'thematic_edit') {
  178. // Display form
  179. $form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
  180. if ($action == 'thematic_edit') {
  181. $form->addElement('header', '', get_lang('EditThematicSection'));
  182. }
  183. $form->addElement('hidden', 'sec_token', $token);
  184. $form->addElement('hidden', 'action', $action);
  185. if (!empty($thematic_id)) {
  186. $form->addElement('hidden', 'thematic_id',$thematic_id);
  187. }
  188. $form->add_textfield('title', get_lang('Title'), true, array('size'=>'50'));
  189. $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150'));
  190. //$form->addElement('html','<div class="clear" style="margin-top:50px;"></div>');
  191. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  192. $show_form = true;
  193. if (!empty($thematic_data)) {
  194. if (api_get_session_id()) {
  195. if ($thematic_data['session_id'] != api_get_session_id()) {
  196. $show_form = false;
  197. Display::display_error_message(get_lang('NotAllowedClickBack'),false);
  198. }
  199. }
  200. // set default values
  201. $default['title'] = $thematic_data['title'];
  202. $default['content'] = $thematic_data['content'];
  203. $form->setDefaults($default);
  204. }
  205. // error messages
  206. if ($error) {
  207. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
  208. }
  209. if ($show_form)
  210. $form->display();
  211. }