thematic.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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'),'','32').'</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'),'','32').'</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'),'','32').'</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'),'','32').'</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'),22).'</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'),22).'</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'),'',22).'</a>';
  85. } else {
  86. $actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',22);
  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'),'',22).'</a>';
  90. } else {
  91. $actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',22);
  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'),'',22).'</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'),'',22).'</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('h2', 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 class="thickbox" 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'),32).'</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().'&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 />';
  120. echo '<div style="text-align:right"><a class="thickbox" href="index.php?'.api_get_cidreq().'&action=thematic_advance_add&thematic_id='.$thematic['id'].'">'.Display::return_icon('add.png',get_lang('NewThematicAdvance'),'','32').'</a></div>';
  121. }
  122. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  123. if (!empty($thematic_advance_data[$thematic['id']])) {
  124. echo '<table width="100%">';
  125. foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
  126. $thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
  127. $thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
  128. echo '<tr>';
  129. echo '<td width="90%" class="thematic_advance_content" id="thematic_advance_content_id_'.$thematic_advance['id'].'">';
  130. $edit_link = '';
  131. if (api_is_allowed_to_edit(null, true)) {
  132. $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(),22).'</a>';
  133. $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'),'',22).'</a></center>';
  134. //Links
  135. $edit_link = Display::div(Display::div($edit_link , array('id'=>'thematic_advance_tools_'.$thematic_advance['id'], 'class'=>'thematic_advance_actions')), array('style'=>'height:20px;'));
  136. }
  137. $thematic_advance_item = isset($thematic_advance_div[$thematic['id']][$thematic_advance['id']]) ? $thematic_advance_div[$thematic['id']][$thematic_advance['id']] : null;
  138. echo Display::div($thematic_advance_item, array('id'=>'thematic_advance_'.$thematic_advance['id']));
  139. echo $edit_link;
  140. echo '</td>';
  141. //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
  142. if (api_is_allowed_to_edit(null, true)) {
  143. if (empty($thematic_id)) {
  144. $checked = '';
  145. if ($last_done_thematic_advance == $thematic_advance['id']) {
  146. $checked = 'checked';
  147. }
  148. $style = '';
  149. if ($thematic_advance['done_advance'] == 1) {
  150. $style = ' style="background-color:#E5EDF9" ';
  151. } else {
  152. $style = ' style="background-color:#fff" ';
  153. }
  154. echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>';
  155. 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)">';
  156. echo '</center></td>';
  157. } else {
  158. if ($thematic_advance['done_advance'] == 1) {
  159. echo '<td><center>'.get_lang('Done').'</center></td>';
  160. } else {
  161. echo '<td><center>-</center></td>';
  162. }
  163. }
  164. }
  165. echo '</tr>';
  166. }
  167. echo '</table>';
  168. } else {
  169. echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>';
  170. }
  171. echo '</td>';
  172. echo '</tr>';
  173. } //End for
  174. echo '</table>';
  175. } else {
  176. echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
  177. }
  178. } else if ($action == 'thematic_add' || $action == 'thematic_edit') {
  179. // Display form
  180. $form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
  181. if ($action == 'thematic_edit') {
  182. $form->addElement('header', '', get_lang('EditThematicSection'));
  183. }
  184. $form->addElement('hidden', 'sec_token', $token);
  185. $form->addElement('hidden', 'action', $action);
  186. if (!empty($thematic_id)) {
  187. $form->addElement('hidden', 'thematic_id',$thematic_id);
  188. }
  189. $form->add_textfield('title', get_lang('Title'), true, array('size'=>'50'));
  190. $form->add_html_editor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150'));
  191. //$form->addElement('html','<div class="clear" style="margin-top:50px;"></div>');
  192. $form->addElement('style_submit_button', null, get_lang('Save'), 'class="save"');
  193. $show_form = true;
  194. if (!empty($thematic_data)) {
  195. if (api_get_session_id()) {
  196. if ($thematic_data['session_id'] != api_get_session_id()) {
  197. $show_form = false;
  198. Display::display_error_message(get_lang('NotAllowedClickBack'),false);
  199. }
  200. }
  201. // set default values
  202. $default['title'] = $thematic_data['title'];
  203. $default['content'] = $thematic_data['content'];
  204. $form->setDefaults($default);
  205. }
  206. // error messages
  207. if ($error) {
  208. Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
  209. }
  210. if ($show_form)
  211. $form->display();
  212. }