Minor - Cleanup course progress code

1.10.x
Yannick Warnier 10 years ago
parent f810f69e37
commit da86364ec5
  1. 445
      main/course_progress/thematic.php
  2. 4
      main/course_progress/thematic_controller.php
  3. 120
      main/course_progress/thematic_plan.php

@ -17,52 +17,52 @@ $user_info = api_get_user_info();
$param_gradebook = '&'.api_get_cidreq(); $param_gradebook = '&'.api_get_cidreq();
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
echo '<div class="actions">'; echo '<div class="actions">';
switch ($action) { switch ($action) {
case 'thematic_add' : case 'thematic_add' :
case 'thematic_import_select' : case 'thematic_import_select' :
echo '<a href="index.php?'.api_get_cidreq().'">'. echo '<a href="index.php?'.api_get_cidreq().'">'.
Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ThematicDetails'),'',ICON_SIZE_MEDIUM).'</a>'; Display::return_icon('back.png',get_lang('BackTo').' '.get_lang('ThematicDetails'),'',ICON_SIZE_MEDIUM).'</a>';
break; break;
case 'thematic_list' : case 'thematic_list' :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'. 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>'; Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
break; break;
case 'thematic_details' : case 'thematic_details' :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'. 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>'; Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_import_select'.$url_token.'">'. 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>'; Display::return_icon('import_csv.png',get_lang('ImportThematic'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export'.$url_token.'">'. 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>'; Display::return_icon('export_csv.png',get_lang('ExportThematic'),'', ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_export_pdf'.$url_token.'">'. 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>'; Display::return_icon('pdf.png',get_lang('ExportToPDF'),'', ICON_SIZE_MEDIUM).'</a>';
break; break;
default : default :
echo '<a href="index.php?'.api_get_cidreq().'&action=thematic_add'.$url_token.'">'. 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>'; Display::return_icon('new_course_progress.png',get_lang('NewThematicSection'),'',ICON_SIZE_MEDIUM).'</a>';
} }
echo '</div>'; echo '</div>';
} }
if ($action == 'thematic_list') { if ($action == 'thematic_list') {
$table = new SortableTable( $table = new SortableTable(
'thematic_list', 'thematic_list',
array('Thematic', 'get_number_of_thematics'), array('Thematic', 'get_number_of_thematics'),
array('Thematic', 'get_thematic_data') array('Thematic', 'get_thematic_data')
); );
$parameters['action'] = $action; $parameters['action'] = $action;
$table->set_additional_parameters($parameters); $table->set_additional_parameters($parameters);
$table->set_header(0, '', false, array('style'=>'width:20px;')); $table->set_header(0, '', false, array('style'=>'width:20px;'));
$table->set_header(1, get_lang('Title'), false ); $table->set_header(1, get_lang('Title'), false );
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$table->set_header(2, get_lang('Actions'), false,array('style'=>'text-align:center;width:40%;')); $table->set_header(2, get_lang('Actions'), false,array('style'=>'text-align:center;width:40%;'));
$table->set_form_actions(array ('thematic_delete_select' => get_lang('DeleteAllThematics'))); $table->set_form_actions(array ('thematic_delete_select' => get_lang('DeleteAllThematics')));
} }
$table->display(); $table->display();
} elseif ($action == 'thematic_details') { } elseif ($action == 'thematic_details') {
@ -70,219 +70,220 @@ if ($action == 'thematic_list') {
Display::display_confirmation_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull')); Display::display_confirmation_message(get_lang('ThematicSectionHasBeenCreatedSuccessfull'));
} }
if (isset($last_id) && $last_id) { if (isset($last_id) && $last_id) {
$link_to_thematic_plan = '<a href="index.php?'.api_get_cidreq().'&action=thematic_plan_list&thematic_id='.$last_id.'">'. $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>'; Display::return_icon('lesson_plan.png', get_lang('ThematicPlan'), array('style'=>'vertical-align:middle;float:none;'),ICON_SIZE_SMALL).'</a>';
$link_to_thematic_advance = '<a href="index.php?'.api_get_cidreq().'&action=thematic_advance_list&thematic_id='.$last_id.'">'. $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>'; Display::return_icon('lesson_plan_calendar.png', get_lang('ThematicAdvance'), array('style'=>'vertical-align:middle;float:none;'),ICON_SIZE_SMALL).'</a>';
Display::display_confirmation_message( Display::display_confirmation_message(
get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'),$link_to_thematic_plan, $link_to_thematic_advance), get_lang('ThematicSectionHasBeenCreatedSuccessfull').'<br />'.sprintf(get_lang('NowYouShouldAddThematicPlanXAndThematicAdvanceX'),$link_to_thematic_plan, $link_to_thematic_advance),
false false
); );
} }
// display title // display title
if (!empty($thematic_id)) { if (!empty($thematic_id)) {
} else { } else {
// display information // display information
$message = '<strong>'.get_lang('Information').'</strong><br />'; $message = '<strong>'.get_lang('Information').'</strong><br />';
$message .= get_lang('ThematicDetailsDescription'); $message .= get_lang('ThematicDetailsDescription');
Display::display_normal_message($message, false); Display::display_normal_message($message, false);
echo '<br />'; echo '<br />';
} }
// Display thematic data // Display thematic data
if (!empty($thematic_data)) { if (!empty($thematic_data)) {
// display progress // display progress
echo '<div style="text-align:right;"><h2>'.get_lang('Progress').': <span id="div_result">'.$total_average_of_advances.'</span> %</h2></div>'; echo '<div style="text-align:right;"><h2>'.get_lang('Progress').': <span id="div_result">'.$total_average_of_advances.'</span> %</h2></div>';
echo '<table width="100%" class="data_table">'; echo '<table width="100%" class="data_table">';
echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>'; echo '<tr><th width="33%">'.get_lang('Thematic').'</th><th>'.get_lang('ThematicPlan').'</th><th width="33%">'.get_lang('ThematicAdvance').'</th></tr>';
foreach ($thematic_data as $thematic) { foreach ($thematic_data as $thematic) {
$my_thematic_id = $thematic['id']; $my_thematic_id = $thematic['id'];
$session_star = ''; $session_star = '';
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
if (api_get_session_id() == $thematic['session_id']) { if (api_get_session_id() == $thematic['session_id']) {
$session_star = api_get_session_image(api_get_session_id(), $user_info['status']); $session_star = api_get_session_image(api_get_session_id(), $user_info['status']);
} }
} }
//@todo add a validation in order to load or not course thematics in the session thematic //@todo add a validation in order to load or not course thematics in the session thematic
echo '<tr>'; echo '<tr>';
$actions_first_col = ''; $actions_first_col = '';
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
// Thematic title // Thematic title
$actions_first_col = Display::url( $actions_first_col = Display::url(
Display::return_icon('cd.gif', get_lang('Copy')), 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 'index.php?'.api_get_cidreq().'&action=thematic_copy&thematic_id='.$my_thematic_id.$param_gradebook.$url_token
); );
if (api_get_session_id() == 0 ) { if (api_get_session_id() == 0 ) {
if ($thematic['display_order'] > 1) { if ($thematic['display_order'] > 1) {
$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>'; $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>';
} else { } else {
$actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL); $actions_first_col .= ' '.Display::return_icon('up_na.png','&nbsp;','',ICON_SIZE_SMALL);
} }
if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) { if (isset($thematic['max_thematic_item']) && $thematic['display_order'] < $thematic['max_thematic_item']) {
$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>'; $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>';
} else { } else {
$actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL); $actions_first_col .= ' '.Display::return_icon('down_na.png','&nbsp;','',ICON_SIZE_SMALL);
} }
} }
if (api_get_session_id() == $thematic['session_id']) { if (api_get_session_id() == $thematic['session_id']) {
$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>'; $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>';
$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>'; $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>';
} }
$actions_first_col = Display::div($actions_first_col, array('id'=>'thematic_id_content_'.$thematic['id'], 'class'=>'thematic_tools')); $actions_first_col = Display::div($actions_first_col, array('id'=>'thematic_id_content_'.$thematic['id'], 'class'=>'thematic_tools'));
$actions_first_col = Display::div($actions_first_col, array('style'=>'height:20px')); $actions_first_col = Display::div($actions_first_col, array('style'=>'height:20px'));
} }
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')); 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'));
// Display 2nd column - thematic plan data // Display 2nd column - thematic plan data
echo '<td>'; echo '<td>';
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) { //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
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">'. 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">'.
Display::return_icon('edit.png', get_lang('EditThematicPlan'), array('style'=>'vertical-align:middle'),ICON_SIZE_MEDIUM).'</a></div><br />'; Display::return_icon('edit.png', get_lang('EditThematicPlan'), array('style'=>'vertical-align:middle'),ICON_SIZE_MEDIUM).'</a></div><br />';
} }
if (empty($thematic_plan_div[$thematic['id']])) { if (empty($thematic_plan_div[$thematic['id']])) {
echo Display::div('', array('id' => "thematic_plan_".$thematic['id'])); echo Display::div('', array('id' => "thematic_plan_".$thematic['id']));
} else { } else {
echo $thematic_plan_div[$thematic['id']]; echo $thematic_plan_div[$thematic['id']];
} }
echo '</td>'; echo '</td>';
// Display 3rd column - thematic advance data // Display 3rd column - thematic advance data
echo '<td style="vertical-align:top">'; echo '<td style="vertical-align:top">';
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) { //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
echo '<div style="text-align:right"><a href="index.php?'.api_get_cidreq().'&action=thematic_advance_add&thematic_id='.$thematic['id'].'">'. 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>'; Display::return_icon('add.png',get_lang('NewThematicAdvance'),'',ICON_SIZE_MEDIUM).'</a></div>';
} }
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) { //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (!empty($thematic_advance_data[$thematic['id']])) { if (!empty($thematic_advance_data[$thematic['id']])) {
echo '<table width="100%">'; echo '<table width="100%">';
foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) { foreach ($thematic_advance_data[$thematic['id']] as $thematic_advance) {
$thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']); $thematic_advance['start_date'] = api_get_local_time($thematic_advance['start_date']);
$thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG); $thematic_advance['start_date'] = api_format_date($thematic_advance['start_date'], DATE_TIME_FORMAT_LONG);
echo '<tr>'; echo '<tr>';
echo '<td width="90%" class="thematic_advance_content" id="thematic_advance_content_id_'.$thematic_advance['id'].'">'; echo '<td width="90%" class="thematic_advance_content" id="thematic_advance_content_id_'.$thematic_advance['id'].'">';
$edit_link = ''; $edit_link = '';
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$edit_link = '<a class="ajax" 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>'; $edit_link = '<a class="ajax" 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>';
$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'].'">'. $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>'; Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).'</a></center>';
//Links //Links
$edit_link = Display::div( $edit_link = Display::div(
Display::div($edit_link , array('id'=>'thematic_advance_tools_'.$thematic_advance['id'], 'class'=>'thematic_advance_actions')), Display::div($edit_link , array('id'=>'thematic_advance_tools_'.$thematic_advance['id'], 'class'=>'thematic_advance_actions')),
array('style'=>'height:20px;') array('style'=>'height:20px;')
); );
} }
$thematic_advance_item = isset($thematic_advance_div[$thematic['id']][$thematic_advance['id']]) ? $thematic_advance_div[$thematic['id']][$thematic_advance['id']] : null; $thematic_advance_item = isset($thematic_advance_div[$thematic['id']][$thematic_advance['id']]) ? $thematic_advance_div[$thematic['id']][$thematic_advance['id']] : null;
echo Display::div($thematic_advance_item, array('id'=>'thematic_advance_'.$thematic_advance['id'])); echo Display::div($thematic_advance_item, array('id'=>'thematic_advance_'.$thematic_advance['id']));
echo $edit_link; echo $edit_link;
echo '</td>'; echo '</td>';
//if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) { //if (api_is_allowed_to_edit(null, true) && api_get_session_id() == $thematic['session_id']) {
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
if (empty($thematic_id)) { if (empty($thematic_id)) {
$checked = ''; $checked = '';
if ($last_done_thematic_advance == $thematic_advance['id']) { if ($last_done_thematic_advance == $thematic_advance['id']) {
$checked = 'checked'; $checked = 'checked';
} }
$style = ''; $style = '';
if ($thematic_advance['done_advance'] == 1) { if ($thematic_advance['done_advance'] == 1) {
$style = ' style="background-color:#E5EDF9" '; $style = ' style="background-color:#E5EDF9" ';
} else { } else {
$style = ' style="background-color:#fff" '; $style = ' style="background-color:#fff" ';
} }
echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>'; echo '<td id="td_done_thematic_'.$thematic_advance['id'].'" '.$style.'><center>';
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)">'; 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)">';
echo '</center></td>'; echo '</center></td>';
} else { } else {
if ($thematic_advance['done_advance'] == 1) { if ($thematic_advance['done_advance'] == 1) {
echo '<td><center>'.get_lang('Done').'</center></td>'; echo '<td><center>'.get_lang('Done').'</center></td>';
} else { } else {
echo '<td><center>-</center></td>'; echo '<td><center>-</center></td>';
} }
} }
} }
echo '</tr>'; echo '</tr>';
} }
echo '</table>'; echo '</table>';
} else { } else {
echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>'; echo '<div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div>';
} }
echo '</td>'; echo '</td>';
echo '</tr>'; echo '</tr>';
} //End for } //End for
echo '</table>'; echo '</table>';
} else { } else {
echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>'; echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
} }
} else if ($action == 'thematic_add' || $action == 'thematic_edit') { } elseif ($action == 'thematic_add' || $action == 'thematic_edit') {
// Display form // Display form
$form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq()); $form = new FormValidator('thematic_add','POST','index.php?action=thematic_add&'.api_get_cidreq());
if ($action == 'thematic_edit') { if ($action == 'thematic_edit') {
$form->addElement('header', '', get_lang('EditThematicSection')); $form->addElement('header', '', get_lang('EditThematicSection'));
} }
$form->addElement('hidden', 'sec_token', $token); $form->addElement('hidden', 'sec_token', $token);
$form->addElement('hidden', 'action', $action); $form->addElement('hidden', 'action', $action);
if (!empty($thematic_id)) { if (!empty($thematic_id)) {
$form->addElement('hidden', 'thematic_id',$thematic_id); $form->addElement('hidden', 'thematic_id',$thematic_id);
} }
$form->addText('title', get_lang('Title'), true, array('size'=>'50')); $form->addText('title', get_lang('Title'), true, array('size'=>'50'));
$form->addHtmlEditor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Height' => '150')); $form->addHtmlEditor('content', get_lang('Content'), false, false, array('ToolbarSet' => 'TrainingDescription', 'Height' => '150'));
$form->addButtonSave(get_lang('Save')); $form->addButtonSave(get_lang('Save'));
$show_form = true; $show_form = true;
if (!empty($thematic_data)) { if (!empty($thematic_data)) {
if (api_get_session_id()) { if (api_get_session_id()) {
if ($thematic_data['session_id'] != api_get_session_id()) { if ($thematic_data['session_id'] != api_get_session_id()) {
$show_form = false; $show_form = false;
Display::display_error_message(get_lang('NotAllowedClickBack'),false); Display::display_error_message(get_lang('NotAllowedClickBack'),false);
} }
} }
// set default values // set default values
$default['title'] = $thematic_data['title']; $default['title'] = $thematic_data['title'];
$default['content'] = $thematic_data['content']; $default['content'] = $thematic_data['content'];
$form->setDefaults($default); $form->setDefaults($default);
} }
// error messages // error messages
if (isset($error)) { if (isset($error)) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false); Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
} }
if ($show_form) if ($show_form) {
$form->display(); $form->display();
} else if ($action == 'thematic_import_select') { }
} elseif ($action == 'thematic_import_select') {
// Create form to upload csv file. // Create form to upload csv file.
$form = new FormValidator('thematic_import','POST','index.php?action=thematic_import&'.api_get_cidreq().$url_token); $form = new FormValidator('thematic_import','POST','index.php?action=thematic_import&'.api_get_cidreq().$url_token);
$form->addElement('header', get_lang('ImportThematic')); $form->addElement('header', get_lang('ImportThematic'));
$form->addElement('file', 'file'); $form->addElement('file', 'file');
$form->addElement('checkbox', 'replace', null, get_lang('DeleteAllThematic')); $form->addElement('checkbox', 'replace', null, get_lang('DeleteAllThematic'));
$form->addButtonImport(get_lang('Import'), 'SubmitImport'); $form->addButtonImport(get_lang('Import'), 'SubmitImport');
$form->display(); $form->display();
} }

@ -55,8 +55,8 @@ class ThematicController
if (api_is_allowed_to_edit(null, true)) { if (api_is_allowed_to_edit(null, true)) {
$id = isset($_POST['thematic_id']) ? $_POST['thematic_id'] : null; $id = isset($_POST['thematic_id']) ? $_POST['thematic_id'] : null;
$title = $_POST['title']; $title = trim($_POST['title']);
$content = $_POST['content']; $content = trim($_POST['content']);
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$thematic->set_thematic_attributes($id, $title, $content, $session_id); $thematic->set_thematic_attributes($id, $title, $content, $session_id);
$last_id = $thematic->thematic_save(); $last_id = $thematic->thematic_save();

@ -19,7 +19,7 @@ $new_id = ADD_THEMATIC_PLAN;
if (!empty($thematic_simple_list)) if (!empty($thematic_simple_list))
foreach($thematic_simple_list as $item) { foreach($thematic_simple_list as $item) {
if ($item >= ADD_THEMATIC_PLAN) { if ($item >= ADD_THEMATIC_PLAN) {
$new_id = $item + 1; $new_id = $item + 1;
$default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title']; $default_thematic_plan_title[$item] = $new_thematic_plan_data[$item]['title'];
} }
} }
@ -35,10 +35,10 @@ if (isset($message) && $message == 'ok') {
$param_gradebook = null; $param_gradebook = null;
if ($action == 'thematic_plan_list') { if ($action == 'thematic_plan_list') {
$form = new FormValidator( $form = new FormValidator(
'thematic_plan_add', 'thematic_plan_add',
'POST', 'POST',
'index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook 'index.php?action=thematic_plan_list&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook
); );
$form->addElement('hidden', 'action', 'thematic_plan_add'); $form->addElement('hidden', 'action', 'thematic_plan_add');
//$form->addElement('hidden', 'thematic_plan_token', $token); //$form->addElement('hidden', 'thematic_plan_token', $token);
$form->addElement('hidden', 'thematic_id', $thematic_id); $form->addElement('hidden', 'thematic_id', $thematic_id);
@ -46,17 +46,17 @@ if ($action == 'thematic_plan_list') {
foreach ($default_thematic_plan_title as $id => $title) { foreach ($default_thematic_plan_title as $id => $title) {
$form->addElement('hidden', 'description_type['.$id.']', $id); $form->addElement('hidden', 'description_type['.$id.']', $id);
$form->addText('title['.$id.']', get_lang('Title'), false, array('size'=>'50')); $form->addText('title['.$id.']', get_lang('Title'), false, array('size'=>'50'));
$form->addHtmlEditor( $form->addHtmlEditor(
'description['.$id.']', 'description['.$id.']',
get_lang('Description'), get_lang('Description'),
false, false,
false, false,
array( array(
'ToolbarStartExpanded' => 'false', 'ToolbarStartExpanded' => 'false',
'ToolbarSet' => 'TrainingDescription', 'ToolbarSet' => 'TrainingDescription',
'Height' => '150' 'Height' => '150'
) )
); );
if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) { if (!empty($thematic_simple_list) && in_array($id, $thematic_simple_list)) {
$thematic_plan = $new_thematic_plan_data[$id]; $thematic_plan = $new_thematic_plan_data[$id];
@ -70,56 +70,56 @@ if ($action == 'thematic_plan_list') {
$default['description['.$id.']']= ''; $default['description['.$id.']']= '';
} }
$form->setDefaults($default); $form->setDefaults($default);
} }
$form->addButtonSave(get_lang('Save')); $form->addButtonSave(get_lang('Save'));
$form->display(); $form->display();
} else if ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') { } elseif ($action == 'thematic_plan_add' || $action == 'thematic_plan_edit') {
if ($description_type >= ADD_THEMATIC_PLAN) { if ($description_type >= ADD_THEMATIC_PLAN) {
$header_form = get_lang('NewBloc'); $header_form = get_lang('NewBloc');
} else { } else {
$header_form = $default_thematic_plan_title[$description_type]; $header_form = $default_thematic_plan_title[$description_type];
} }
if (!$error) { if (!$error) {
$token = md5(uniqid(rand(),TRUE)); $token = md5(uniqid(rand(),TRUE));
$_SESSION['thematic_plan_token'] = $token; $_SESSION['thematic_plan_token'] = $token;
} }
// display form // display form
$form = new FormValidator('thematic_plan_add','POST','index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"'); $form = new FormValidator('thematic_plan_add','POST','index.php?action=thematic_plan_edit&thematic_id='.$thematic_id.'&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"');
//$form->addElement('header', '', $header_form); //$form->addElement('header', '', $header_form);
$form->addElement('hidden', 'action', $action); $form->addElement('hidden', 'action', $action);
$form->addElement('hidden', 'thematic_plan_token', $token); $form->addElement('hidden', 'thematic_plan_token', $token);
if (!empty($thematic_id)) { if (!empty($thematic_id)) {
$form->addElement('hidden', 'thematic_id', $thematic_id); $form->addElement('hidden', 'thematic_id', $thematic_id);
} }
if (!empty($description_type)) { if (!empty($description_type)) {
$form->addElement('hidden', 'description_type', $description_type); $form->addElement('hidden', 'description_type', $description_type);
} }
$form->addText('title', get_lang('Title'), true, array('size'=>'50')); $form->addText('title', get_lang('Title'), true, array('size'=>'50'));
$form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarStartExpanded'=>'false', 'ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150')); $form->addHtmlEditor('description', get_lang('Description'), false, false, array('ToolbarStartExpanded'=>'false', 'ToolbarSet' => 'TrainingDescription', 'Width' => '80%', 'Height' => '150'));
$form->addButtonSave(get_lang('Save')); $form->addButtonSave(get_lang('Save'));
if ($description_type < ADD_THEMATIC_PLAN) { if ($description_type < ADD_THEMATIC_PLAN) {
$default['title'] = $default_thematic_plan_title[$description_type]; $default['title'] = $default_thematic_plan_title[$description_type];
} }
if (!empty($thematic_plan_data)) { if (!empty($thematic_plan_data)) {
// set default values // set default values
$default['title'] = $thematic_plan_data[0]['title']; $default['title'] = $thematic_plan_data[0]['title'];
$default['description'] = $thematic_plan_data[0]['description']; $default['description'] = $thematic_plan_data[0]['description'];
} }
$form->setDefaults($default); $form->setDefaults($default);
if (isset($default_thematic_plan_question[$description_type])) { if (isset($default_thematic_plan_question[$description_type])) {
$message = '<strong>'.get_lang('QuestionPlan').'</strong><br />'; $message = '<strong>'.get_lang('QuestionPlan').'</strong><br />';
$message .= $default_thematic_plan_question[$description_type]; $message .= $default_thematic_plan_question[$description_type];
Display::display_normal_message($message, false); Display::display_normal_message($message, false);
} }
// error messages // error messages
if ($error) { if ($error) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false); Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
} }
$form->display(); $form->display();
} }

Loading…
Cancel
Save