thematic.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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">';
  15. switch ($action) {
  16. case 'thematic_add' :
  17. case 'thematic_import_select' :
  18. echo '<a href="index.php?'.api_get_cidreq().'">'.Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ThematicDetails'),'',ICON_SIZE_MEDIUM).'</a>';
  19. break;
  20. case 'thematic_list' :
  21. 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>';
  22. break;
  23. case 'thematic_details' :
  24. 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>';
  25. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'.Display::return_icon('import_csv.png',get_lang('ImportThematic'),'',ICON_SIZE_MEDIUM).'</a>';
  26. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'.Display::return_icon('export_csv.png',get_lang('ExportThematic'),'', ICON_SIZE_MEDIUM).'</a>';
  27. echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'.Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>';
  28. break;
  29. default :
  30. 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>';
  31. }
  32. echo '</div>';
  33. }
  34. if ($action == 'thematic_list') {
  35. $table = new SortableTable('thematic_list', array('Thematic', 'get_number_of_thematics'), array('Thematic', 'get_thematic_data'));
  36. $parameters['action'] = $action;
  37. $table->set_additional_parameters($parameters);
  38. $table->set_header(0, '', false, array('style'=>'width:20px;'));
  39. $table->set_header(1, get_lang('Title'), false );
  40. if (api_is_allowed_to_edit(null, true)) {
  41. $table->set_header(2, get_lang('Actions'), false,array('style'=>'text-align:center;width:40%;'));
  42. $table->set_form_actions(array ('thematic_delete_select' => get_lang('DeleteAllThematics')));
  43. }
  44. $table->display();
  45. } elseif ($action == 'thematic_details') {
  46. if (isset($_GET['thematic_plan_save_message']) && $_GET['thematic_plan_save_message'] == 'ok') {
  47. Display::display_confirmation_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'));
  48. }
  49. if (isset($last_id) && $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;float:none;'),ICON_SIZE_SMALL).'</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;float:none;'),ICON_SIZE_SMALL).'</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. } else {
  57. // display information
  58. $message = '<strong>'.get_lang('Information').'</strong><br />';
  59. $message .= get_lang('ThematicDetailsDescription');
  60. Display::display_normal_message($message, false);
  61. echo '<br />';
  62. }
  63. // display thematic data
  64. if (!empty($thematic_data)) {
  65. // display progress
  66. echo '<div style="text-align:right;"><h2>'.get_lang('Progress').': <span id="div_result">'.$total_average_of_advances.'</span> %</h2></div>';
  67. echo '<table width="100%" class="data_table">';
  68. echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>';
  69. foreach ($thematic_data as $thematic) {
  70. $my_thematic_id = $thematic['id'];
  71. $session_star = '';
  72. if (api_is_allowed_to_edit(null, true)) {
  73. if (api_get_session_id() == $thematic['session_id']) {
  74. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  75. }
  76. }
  77. //@todo add a validation in order to load or not course thematics in the session thematic
  78. /*
  79. if (api_get_session_id() == $thematic['session_id']) {
  80. $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
  81. } else {
  82. continue;
  83. } */
  84. echo '<tr>';
  85. $actions_first_col = '';
  86. if (api_is_allowed_to_edit(null, true)) {
  87. // Thematic title
  88. $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);
  89. if (api_get_session_id() == 0 ) {
  90. if ($thematic['display_order'] > 1) {
  91. $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>';
  92. } else {
  93. $actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
  94. }
  95. if ($thematic['display_order'] < $thematic['max_thematic_item']) {
  96. $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>';
  97. } else {
  98. $actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
  99. }
  100. }
  101. if (api_get_session_id() == $thematic['session_id']) {
  102. $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>';
  103. $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>';
  104. }
  105. $actions_first_col = Display::div($actions_first_col, array('id'=>'thematic_id_content_'.$thematic['id'], 'class'=>'thematic_tools'));
  106. $actions_first_col = Display::div($actions_first_col, array('style'=>'height:20px'));
  107. }
  108. 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'));
  109. // Display 2nd column - thematic plan data
  110. echo '<td>';
  111. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  112. if (api_is_allowed_to_edit(null, true)) {
  113. 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">'.
  114. Display::return_icon('edit.png', get_lang('EditThematicPlan'), array('style'=>'vertical-align:middle'),ICON_SIZE_MEDIUM).'</a></div><br />';
  115. }
  116. if (empty($thematic_plan_div[$thematic['id']])) {
  117. echo Display::div('', array('id' => "thematic_plan_".$thematic['id']));
  118. } else {
  119. echo $thematic_plan_div[$thematic['id']];
  120. }
  121. echo '</td>';
  122. // Display 3rd column - thematic advance data
  123. echo '<td style="vertical-align:top">';
  124. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  125. if (api_is_allowed_to_edit(null, true)) {
  126. 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>';
  127. }
  128. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  129. if (!empty($thematic_advance_data[$thematic['id']])) {
  130. echo '<table width="100%">';
  131. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  132. $thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
  133. $thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
  134. echo '<tr>';
  135. echo '<td width="90%" class="thematic_advance_content" id="thematic_advance_content_id_'.$thematic_advance['id'].'">';
  136. $edit_link = '';
  137. if (api_is_allowed_to_edit(null, true)) {
  138. $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=no_header" >'.Display::return_icon('edit.png',get_lang('EditThematicAdvance'),array(),ICON_SIZE_SMALL).'</a>';
  139. $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'].'">'.
  140. Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a></center>';
  141. //Links
  142. $edit_link = Display::div(Display::div($edit_link , array('id'=>'thematic_advance_tools_'.$thematic_advance['id'], 'class'=>'thematic_advance_actions')), array('style'=>'height:20px;'));
  143. }
  144. $thematic_advance_item = isset($thematic_advance_div[$thematic['id']][$thematic_advance['id']]) ? $thematic_advance_div[$thematic['id']][$thematic_advance['id']] : null;
  145. echo Display::div($thematic_advance_item, array('id'=>'thematic_advance_'.$thematic_advance['id']));
  146. echo $edit_link;
  147. echo '</td>';
  148. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  149. if (api_is_allowed_to_edit(null, true)) {
  150. if (empty($thematic_id)) {
  151. $checked = '';
  152. if ($last_done_thematic_advance == $thematic_advance['id']) {
  153. $checked = 'checked';
  154. }
  155. $style = '';
  156. if ($thematic_advance['done_advance'] == 1) {
  157. $style = ' style="background-color:#E5EDF9" ';
  158. } else {
  159. $style = ' style="background-color:#fff" ';
  160. }
  161. echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>';
  162. 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)">';
  163. echo '</center></td>';
  164. } else {
  165. if ($thematic_advance['done_advance'] == 1) {
  166. echo '<td><center>'.get_lang('Done').'</center></td>';
  167. } else {
  168. echo '<td><center>-</center></td>';
  169. }
  170. }
  171. }
  172. echo '</tr>';
  173. }
  174. echo '</table>';
  175. } else {
  176. echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>';
  177. }
  178. echo '</td>';
  179. echo '</tr>';
  180. } //End for
  181. echo '</table>';
  182. } else {
  183. echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
  184. }
  185. } else if ($action == 'thematic_add' || $action == 'thematic_edit') {
  186. // Display form
  187. $form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
  188. if ($action == 'thematic_edit') {
  189. $form->addElement('header', '', get_lang('EditThematicSection'));
  190. }
  191. $form->addElement('hidden', 'sec_token', $token);
  192. $form->addElement('hidden', 'action', $action);
  193. if (!empty($thematic_id)) {
  194. $form->addElement('hidden', 'thematic_id',$thematic_id);
  195. }
  196. $form->add_textfield('title', get_lang('Title'), true, array('size'=>'50'));
  197. $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150'));
  198. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  199. $show_form = true;
  200. if (!empty($thematic_data)) {
  201. if (api_get_session_id()) {
  202. if ($thematic_data['session_id'] != api_get_session_id()) {
  203. $show_form = false;
  204. Display::display_error_message(get_lang('NotAllowedClickBack'),false);
  205. }
  206. }
  207. // set default values
  208. $default['title'] = $thematic_data['title'];
  209. $default['content'] = $thematic_data['content'];
  210. $form->setDefaults($default);
  211. }
  212. // error messages
  213. if ($error) {
  214. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
  215. }
  216. if ($show_form)
  217. $form->display();
  218. } else if ($action == 'thematic_import_select') {
  219. // Create form to upload csv file.
  220. $form = new FormValidator('thematic_import','POST','index.php?action=thematic_import&'.api_get_cidreq().$url_token);
  221. $form->addElement('header', get_lang('ImportThematic'));
  222. $form->addElement('file', 'file');
  223. $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllThematic'));
  224. $form->addElement('style_submit_button', 'SubmitImport', get_lang('Import'), 'class="save"');
  225. $form->display();
  226. }