Skip to content

Commit

Permalink
Fix PHP notices, 7
Browse files Browse the repository at this point in the history
Format PHP code
  • Loading branch information
francoisjacquet committed Aug 2, 2019
1 parent 7a21078 commit 52f22a7
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 118 deletions.
6 changes: 3 additions & 3 deletions ProgramFunctions/StudentsUsersInfo.fnc.php
Expand Up @@ -55,7 +55,7 @@ function _makeTextInput( $column, $name, $request )
$options .= $field['REQUIRED'] === 'Y' ? ' required' : '';

return TextInput(
$value[ $column ],
issetVal( $value[ $column ], '' ),
$request . '[' . $column . ']',
$name,
$options,
Expand Down Expand Up @@ -102,7 +102,7 @@ function _makeDateInput( $column, $name, $request )
}

return DateInput(
$value[ $column ],
issetVal( $value[ $column ], '' ),
$request . '[' . $column . ']',
$name,
$div,
Expand Down Expand Up @@ -165,7 +165,7 @@ function _makeSelectInput( $column, $name, $request )
$extra = ( $field['REQUIRED'] === 'Y' ? 'required': '' );

return SelectInput(
$value[ $column ],
issetVal( $value[ $column ], '' ),
$request . '[' . $column . ']',
$name,
$options,
Expand Down
3 changes: 2 additions & 1 deletion functions/ErrorMessage.fnc.php
Expand Up @@ -65,7 +65,8 @@ function ErrorMessage( $errors, $code = 'error' )

if ( count( $errors ) === 1 )
{
$return .= ': ' . issetVal( $errors[0], $errors[1] ) . '</p>';
// Note: do not use issetVal() here.
$return .= ': ' . ( isset( $errors[0] ) ? $errors[0] : $errors[1] ) . '</p>';
}

// More than one error: list.
Expand Down
5 changes: 5 additions & 0 deletions functions/GetGrade.fnc.php
Expand Up @@ -32,6 +32,11 @@ function GetGrade( $grade, $column = 'TITLE' )
FROM SCHOOL_GRADELEVELS", array(), array( 'ID' ) );
}

if ( ! isset( $grades[ $grade ] ) )
{
return '';
}

$extra = '';

if ( $column === 'TITLE' )
Expand Down
2 changes: 1 addition & 1 deletion functions/GetStaffList.fnc.php
Expand Up @@ -317,7 +317,7 @@ function appendStaffSQL( $sql, $extra = array() )
);
}

if ( $extra['profile'] )
if ( ! empty( $extra['profile'] ) )
{
$options = array( $extra['profile'] => $options[ $extra['profile'] ] );
}
Expand Down
2 changes: 1 addition & 1 deletion functions/ListOutput.fnc.php
Expand Up @@ -818,7 +818,7 @@ class="button" alt="" title="' . htmlspecialchars( _( 'Search' ), ENT_QUOTES ) .

foreach ( (array) $column_names as $key => $value )
{
echo '<td>' . $link['add']['html'][$key] . '</td>';
echo '<td>' . issetVal( $link['add']['html'][$key], '' ) . '</td>';
}

echo '</tr></tbody>';
Expand Down
12 changes: 11 additions & 1 deletion index.php
Expand Up @@ -289,6 +289,13 @@
}
else
{
if ( ! isset( $_REQUEST['modfunc'] ) )
{
$_REQUEST['modfunc'] = false;
}

$_REQUEST['modname'] = false;

$_ROSARIO['page'] = 'create-account';

Warehouse( 'header' );
Expand Down Expand Up @@ -440,7 +447,10 @@
<?php endif; ?>
</form>
<input class="toggle" type="checkbox" id="toggle1" />
<label class="toggle" for="toggle1"><?php echo _( 'About' ); ?></label>
<label class="toggle" for="toggle1"><?php
// @todo Use <detail><summary> & remove CSS hack.
// @link https://caniuse.com/#search=details
echo _( 'About' ); ?></label>
<div class="about-rosariosis toggle-me">
<?php // System disclaimer. ?>
<p class="size-3">
Expand Down
2 changes: 1 addition & 1 deletion modules/Grades/Assignments.php
Expand Up @@ -385,7 +385,7 @@
{
$hide_previous_assignment_types_sql = '';

if ( $gradebook_config['HIDE_PREVIOUS_ASSIGNMENT_TYPES'] )
if ( ! empty( $gradebook_config['HIDE_PREVIOUS_ASSIGNMENT_TYPES'] ) )
{
// @since 4.5 Hide previous quarters assignment types.
$hide_previous_assignment_types_sql = " AND CREATED_MP='" . UserMP() . "' OR CREATED_MP IS NULL";
Expand Down
37 changes: 26 additions & 11 deletions modules/Grades/Grades.php
Expand Up @@ -32,7 +32,9 @@
$gradebook_config = ProgramUserConfig( 'Gradebook' );

//$max_allowed = Preferences('ANOMALOUS_MAX','Gradebook')/100;
$max_allowed = ( $gradebook_config['ANOMALOUS_MAX'] ? $gradebook_config['ANOMALOUS_MAX'] / 100 : 1 );
$max_allowed = ( isset( $gradebook_config['ANOMALOUS_MAX'] ) && $gradebook_config['ANOMALOUS_MAX'] ?
$gradebook_config['ANOMALOUS_MAX'] / 100 :
1 );

if ( ! empty( $_REQUEST['student_id'] ) )
{
Expand Down Expand Up @@ -225,7 +227,7 @@

$sql = '';

if ( $current_RET[$student_id][$assignment_id] )
if ( ! empty( $current_RET[$student_id][$assignment_id] ) )
{
$sql = "UPDATE GRADEBOOK_GRADES SET ";

Expand Down Expand Up @@ -290,7 +292,7 @@

if ( ProgramConfig( 'grades', 'GRADES_DOES_LETTER_PERCENT' ) <= 0 )
{
if ( $gradebook_config['LETTER_GRADE_ALL'] != 'Y' )
if ( empty( $gradebook_config['LETTER_GRADE_ALL'] ) )
{
$LO_columns['LETTER_GRADE'] = _( 'Letter' );
}
Expand Down Expand Up @@ -474,7 +476,7 @@
if ( ProgramConfig( 'grades', 'GRADES_DOES_LETTER_PERCENT' ) <= 0 )
{
if ( empty( $_REQUEST['assignment_id'] )
|| $gradebook_config['LETTER_GRADE_ALL'] != 'Y' )
|| empty( $gradebook_config['LETTER_GRADE_ALL'] ) )
{
$LO_columns['LETTER_GRADE'] = _( 'Letter' );
}
Expand Down Expand Up @@ -579,8 +581,14 @@
}

$tabs[] = array(
'title' => $color . $type[1]['TITLE'] . ( $gradebook_config['WEIGHT'] == 'Y' ? '|' . number_format( 100 * $type[1]['FINAL_GRADE_PERCENT'], 0 ) . '%' : '' ),
'link' => 'Modules.php?modname=' . $_REQUEST['modname'] . '&type_id=' . $id . ( $_REQUEST['assignment_id'] == 'all' ? '&assignment_id=all' : '' ) . ( UserStudentID() ? '&student_id=' . UserStudentID() : '' ) . '&include_inactive=' . $_REQUEST['include_inactive'] . '&include_all=' . $_REQUEST['include_all'],
'title' => $color . $type[1]['TITLE'] .
( isset( $gradebook_config['WEIGHT'] ) && $gradebook_config['WEIGHT'] == 'Y' ?
'|' . number_format( 100 * $type[1]['FINAL_GRADE_PERCENT'], 0 ) . '%' :
'' ),
'link' => 'Modules.php?modname=' . $_REQUEST['modname'] . '&type_id=' . $id .
( $_REQUEST['assignment_id'] == 'all' ? '&assignment_id=all' : '' ) .
( UserStudentID() ? '&student_id=' . UserStudentID() : '' ) .
'&include_inactive=' . $_REQUEST['include_inactive'] . '&include_all=' . $_REQUEST['include_all'],
);
}

Expand Down Expand Up @@ -746,7 +754,8 @@ function _makeExtraAssnCols( $assignment_id, $column )
else
{
if ( ! empty( $_REQUEST['include_all'] )
|| ( $current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['POINTS'] != ''
|| ( ( isset( $current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['POINTS'] )
&& $current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['POINTS'] != '' )
|| ! $assignments_RET[$assignment_id][1]['DUE_EPOCH']
|| $assignments_RET[$assignment_id][1]['DUE_EPOCH'] >= $THIS_RET['START_EPOCH']
&& ( ! $THIS_RET['END_EPOCH']
Expand All @@ -755,7 +764,7 @@ function _makeExtraAssnCols( $assignment_id, $column )
$total_points = $assignments_RET[$assignment_id][1]['POINTS'];

//FJ default points
$points = $current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['POINTS'];
$points = issetVal( $current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['POINTS'] );
$div = true;

if ( is_null( $points ) )
Expand Down Expand Up @@ -804,8 +813,14 @@ function _makeExtraAssnCols( $assignment_id, $column )
{
if ( $partial_points['PARTIAL_TOTAL'] != 0 || $gradebook_config['WEIGHT'] != 'Y' )
{
$total += $partial_points['PARTIAL_POINTS'] * ( $gradebook_config['WEIGHT'] == 'Y' ? $partial_points['FINAL_GRADE_PERCENT'] / $partial_points['PARTIAL_TOTAL'] : 1 );
$total_percent += ( $gradebook_config['WEIGHT'] == 'Y' ? $partial_points['FINAL_GRADE_PERCENT'] : $partial_points['PARTIAL_TOTAL'] );
$total += $partial_points['PARTIAL_POINTS'] *
( isset( $gradebook_config['WEIGHT'] ) && $gradebook_config['WEIGHT'] == 'Y' ?
$partial_points['FINAL_GRADE_PERCENT'] / $partial_points['PARTIAL_TOTAL'] :
1 );

$total_percent += ( isset( $gradebook_config['WEIGHT'] ) && $gradebook_config['WEIGHT'] == 'Y' ?
$partial_points['FINAL_GRADE_PERCENT'] :
$partial_points['PARTIAL_TOTAL'] );
}
}

Expand Down Expand Up @@ -912,7 +927,7 @@ function _makeExtraAssnCols( $assignment_id, $column )
|| $assignments_RET[$assignment_id][1]['DUE_EPOCH'] <= $THIS_RET['END_EPOCH'] ) ) )
{
return TextInput(
$current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['COMMENT'],
issetVal( $current_RET[$THIS_RET['STUDENT_ID']][$assignment_id][1]['COMMENT'] ),
'values[' . $THIS_RET['STUDENT_ID'] . '][' . $assignment_id . '][COMMENT]',
'',
' maxlength=100'
Expand Down
108 changes: 55 additions & 53 deletions modules/Students/Student.php
Expand Up @@ -152,19 +152,22 @@
$error[] = _( 'Please fill in the required fields' );
}

// Check username unicity.
$existing_username = DBGet( "SELECT 'exists'
FROM STAFF
WHERE USERNAME='" . $_REQUEST['students']['USERNAME'] . "'
AND SYEAR='" . UserSyear() . "'
UNION SELECT 'exists'
FROM STUDENTS
WHERE USERNAME='" . $_REQUEST['students']['USERNAME'] . "'
AND STUDENT_ID!='" . UserStudentID() . "'" );

if ( ! empty( $existing_username ) )
if ( isset( $_REQUEST['students']['USERNAME'] ) )
{
$error[] = _( 'A user with that username already exists. Choose a different username and try again.' );
// Check username unicity.
$existing_username = DBGet( "SELECT 'exists'
FROM STAFF
WHERE USERNAME='" . $_REQUEST['students']['USERNAME'] . "'
AND SYEAR='" . UserSyear() . "'
UNION SELECT 'exists'
FROM STUDENTS
WHERE USERNAME='" . $_REQUEST['students']['USERNAME'] . "'
AND STUDENT_ID!='" . UserStudentID() . "'" );

if ( ! empty( $existing_username ) )
{
$error[] = _( 'A user with that username already exists. Choose a different username and try again.' );
}
}

if ( UserStudentID() && ! $error )
Expand All @@ -183,60 +186,62 @@
if ( ! empty( $_REQUEST['students'] ) && ! $error )
{
$sql = "UPDATE STUDENTS SET ";
$fields_RET = DBGet( "SELECT ID,TYPE FROM CUSTOM_FIELDS ORDER BY SORT_ORDER", array(), array( 'ID' ) );

$fields_RET = DBGet( "SELECT ID,TYPE
FROM CUSTOM_FIELDS
ORDER BY SORT_ORDER", array(), array( 'ID' ) );

$go = false;

foreach ( (array) $_REQUEST['students'] as $column => $value )
{
if ( 1 ) //!empty($value) || $value=='0')
if ( isset( $fields_RET[str_replace( 'CUSTOM_', '', $column )][1]['TYPE'] )
&& $fields_RET[str_replace( 'CUSTOM_', '', $column )][1]['TYPE'] == 'numeric'
&& $value != ''
&& ! is_numeric( $value ) )
{
//FJ check numeric fields
$error[] = _( 'Please enter valid Numeric data.' );
continue;
}

if ( $fields_RET[str_replace( 'CUSTOM_', '', $column )][1]['TYPE'] == 'numeric' && $value != '' && ! is_numeric( $value ) )
if ( ! is_array( $value ) )
{
//FJ add password encryption

if ( $column !== 'PASSWORD' )
{
$error[] = _( 'Please enter valid Numeric data.' );
continue;
$sql .= $column . "='" . str_replace( '&#39;', "''", $value ) . "',";
$go = true;
}

if ( ! is_array( $value ) )
if ( $column == 'PASSWORD' && ! empty( $value ) && $value !== str_repeat( '*', 8 ) )
{
//FJ add password encryption

if ( $column !== 'PASSWORD' )
{
$sql .= $column . "='" . str_replace( '&#39;', "''", $value ) . "',";
$go = true;
}

if ( $column == 'PASSWORD' && ! empty( $value ) && $value !== str_repeat( '*', 8 ) )
{
$value = str_replace( "''", "'", $value );
$sql .= $column . "='" . encrypt_password( $value ) . "',";
$go = true;
}
$value = str_replace( "''", "'", $value );
$sql .= $column . "='" . encrypt_password( $value ) . "',";
$go = true;
}
else
{
// FJ fix bug none selected not saved.
$sql_multiple_input = '';
}
else
{
// FJ fix bug none selected not saved.
$sql_multiple_input = '';

foreach ( (array) $value as $val )
foreach ( (array) $value as $val )
{
if ( $val )
{
if ( $val )
{
$sql_multiple_input .= $val . '||';
}
$sql_multiple_input .= $val . '||';
}
}

if ( $sql_multiple_input )
{
$sql_multiple_input = "||" . $sql_multiple_input;
}
if ( $sql_multiple_input )
{
$sql_multiple_input = "||" . $sql_multiple_input;
}

$sql .= $column . "='" . $sql_multiple_input . "',";
$sql .= $column . "='" . $sql_multiple_input . "',";

$go = true;
}
$go = true;
}
}

Expand Down Expand Up @@ -687,10 +692,7 @@
echo '<form name="student" id="student" action="' . $form_action . '"
method="POST" enctype="multipart/form-data">';

if ( $_REQUEST['student_id'] !== 'new' )
{
$name = $student['FULL_NAME'] . ' - ' . $student['STUDENT_ID'];
}
$name = $_REQUEST['student_id'] !== 'new' ? $student['FULL_NAME'] . ' - ' . $student['STUDENT_ID'] : '';

DrawHeader( $name, $delete_button . SubmitButton() );

Expand Down

0 comments on commit 52f22a7

Please sign in to comment.