thematic.php 13 KB

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