added required input field in attendance - partial CT#603

skala
Cristian Fasanando 15 years ago
parent 896c6dddf8
commit fb025a21b8
  1. 8
      main/attendance/attendance_add.php
  2. 98
      main/attendance/attendance_controller.php
  3. 10
      main/attendance/attendance_edit.php
  4. 4
      main/attendance/thematic.php
  5. 7
      main/inc/lib/attendance.lib.php

@ -11,7 +11,7 @@
api_protect_course_script(true);
// error messages
if (isset($error) && intval($error) == 1) {
if ($error) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
}
@ -20,11 +20,13 @@ if (isset($_SESSION['gradebook'])) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
$token = Security::get_token();
if (!$error) {
$token = Security::get_token();
}
// display form
$form = new FormValidator('attendance_add','POST','index.php?action=attendance_add&'.api_get_cidreq().$param_gradebook,'','style="width: 100%;"');
$form->addElement('header', '', get_lang('CreateANewAttendance'));
$form->addElement('hidden', 'sec_token',$token);
$form->addElement('hidden', 'sec_token', $token);
$form->add_textfield('title', get_lang('Title'), true, array('size'=>'50'));
$form->applyFilter('title','html_filter');

@ -53,33 +53,38 @@
$attendance = new Attendance();
$data = array();
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
$check = Security::check_token();
if ($check) {
$attendance->set_name($_POST['title']);
$attendance->set_description($_POST['description']);
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
$attendance->set_attendance_weight($_POST['attendance_weight']);
$link_to_gradebook = false;
if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
$link_to_gradebook = true;
}
$last_id = $attendance->attendance_add($link_to_gradebook);
Security::clear_token();
}
if ($last_id) {
$this->attendance_sheet('calendar_list',$last_id);
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
if (!empty($_POST['title'])) {
$check = Security::check_token();
if ($check) {
$attendance->set_name($_POST['title']);
$attendance->set_description($_POST['description']);
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
$attendance->set_attendance_weight($_POST['attendance_weight']);
$link_to_gradebook = false;
if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
$link_to_gradebook = true;
}
$last_id = $attendance->attendance_add($link_to_gradebook);
Security::clear_token();
}
$param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
header('location:index.php?action=attendance_sheet_list&attendance_id='.$last_id.'&'.api_get_cidreq().$param_gradebook);
exit;
} else {
$data['error_attendance_add'] = true;
$data['error'] = true;
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('attendance_add');
$this->view->render();
}
} else {
$this->view->set_data($data);
$this->view->set_layout('layout');
@ -97,30 +102,44 @@
public function attendance_edit($attendance_id) {
$attendance = new Attendance();
$data = array();
$attendance_id = intval($attendance_id);
$attendance_id = intval($attendance_id);
if (strtoupper($_SERVER['REQUEST_METHOD']) == "POST") {
$check = Security::check_token();
if ($check) {
$attendance->set_name($_POST['title']);
$attendance->set_description($_POST['description']);
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
$attendance->set_attendance_weight($_POST['attendance_weight']);
$link_to_gradebook = false;
if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
$link_to_gradebook = true;
}
$affected_rows = $attendance->attendance_edit($attendance_id,$link_to_gradebook);
Security::clear_token();
}
if (!empty($_POST['title'])) {
$check = Security::check_token();
if ($check) {
$attendance->set_name($_POST['title']);
$attendance->set_description($_POST['description']);
$attendance->set_attendance_qualify_title($_POST['attendance_qualify_title']);
$attendance->set_attendance_weight($_POST['attendance_weight']);
$link_to_gradebook = false;
if ( isset($_POST['attendance_qualify_gradebook']) && $_POST['attendance_qualify_gradebook'] == 1 ) {
$link_to_gradebook = true;
}
$last_id = $attendance->attendance_edit($attendance_id,$link_to_gradebook);
Security::clear_token();
$param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
header('location:index.php?action=attendance_list&'.api_get_cidreq().$param_gradebook);
exit;
}
} else {
$data['attendance_id'] = $_POST['attendance_id'];
$data['error'] = true;
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('attendance_edit');
$this->view->render();
}
if ($affected_rows) {
$data['message_edit'] = true;
}
$this->attendance_list();
} else {
// default values
$attendance_data = $attendance->get_attendance_by_id($attendance_id);
$data['attendance_id'] = $attendance_data['id'];
@ -133,6 +152,7 @@
$this->view->set_layout('layout');
$this->view->set_template('attendance_edit');
$this->view->render();
}
}

@ -12,7 +12,7 @@
api_protect_course_script(true);
// error messages
if (isset($error) && intval($error) == 1) {
if ($error) {
Display::display_error_message(get_lang('FormHasErrorsPleaseComplete'),false);
}
@ -20,13 +20,17 @@ $param_gradebook = '';
if (isset($_SESSION['gradebook'])) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
$token = Security::get_token();
$attendance_weight = floatval($attendance_weight);
if (!$error) {
$token = Security::get_token();
}
$attendance_weight = floatval($attendance_weight);
// display form
$form = new FormValidator('attendance_edit','POST','index.php?action=attendance_edit&'.api_get_cidreq().'&attendance_id='.$attendance_id.$param_gradebook,'','style="width: 100%;"');
$form->addElement('header', '', get_lang('Edit'));
$form->addElement('hidden', 'sec_token',$token);
$form->addElement('hidden', 'attendance_id', $attendance_id);
$form->add_textfield('title', get_lang('Title'), true, array('size'=>'50'));
$form->applyFilter('title','html_filter');

@ -123,7 +123,7 @@ if ($action == 'thematic_list') {
echo '</tr>';
}
} else {
echo '<tr><td width="90%"><div><em>'.get_lang('StillDoNotHaveAThematicAdvance').'</em></div></td><td>&nbsp;</td>';
echo '<tr><td width="90%"><div><em>'.get_lang('ThereIsNoAThematicAdvance').'</em></div></td><td>&nbsp;</td>';
}
echo '</table>';
@ -133,7 +133,7 @@ if ($action == 'thematic_list') {
echo '</table>';
} else {
echo '<div><em>'.get_lang('ThereIsStillAthematicSection').'</em></div>';
echo '<div><em>'.get_lang('ThereIsNoAThematicSection').'</em></div>';
}
} else if ($action == 'thematic_add' || $action == 'thematic_edit') {

@ -198,7 +198,7 @@ class Attendance
* edit attendaces inside table
* @param int attendance id
* @param bool true for adding link in gradebook or false otherwise (optional)
* @return int affected rows
* @return int last id
*/
public function attendance_edit($attendance_id, $link_to_gradebook = false) {
global $_course;
@ -220,7 +220,6 @@ class Attendance
attendance_weight = '".$weight_calification."'
WHERE id = '$attendance_id'";
Database::query($sql);
$affected_rows = Database::affected_rows();
if (!empty($affected_rows)) {
// update row item property table
$last_id = Database::insert_id();
@ -237,7 +236,9 @@ class Attendance
Database::query('UPDATE '.$table_link.' SET weight='.$weight_calification.' WHERE id='.$link_id.'');
}
}
return $affected_rows;
$last_id = $attendance_id;
return $last_id;
}
/**

Loading…
Cancel
Save