<commit_before><?php

include_once 'check_access_permissions.php';
mustHaveAnyOfTheseRoles( array( 'USER' ) );

include_once 'database.php';
include_once 'tohtml.php';
include_once 'methods.php';

echo userHTML( );

$sem = getCurrentSemester( );
$year = getCurrentYear( );

// User courses.
$myCourses = getMyCourses( $sem, $year, $user = $_SESSION[ 'user' ] );

$runningCourses = array( );
foreach( getSemesterCourses( $year, $sem ) as $rc )
    $runningCourses[ $rc[ 'course_id' ] ] = $rc;


echo '<h3>Registered courses </h3>';


echo alertUser( "
    <strong>Policy for dropping a course </strong> 
    <br>  Upto 30 days from starting of course, you are free to drop a course. 
    After that, you need to write to your course instructor and academic office.
    " );

$tofilter = 'student_id';

echo '<div style="font-size:small">';

echo '<table border="1">';
echo '<tr>';

$action = 'drop';
$count = 0;

echo printInfo( "You are registered for following courses." );
foreach( $myCourses as $c )
{
    $count += 1;
    if( $count % 3 == 0 )
        echo '</tr><tr>';

    echo '<td>';
    echo '<form method="post" action="user_manages_courses_action.php">';


    $cid = $c[ 'course_id' ];
    $course = getTableEntry( 'courses_metadata', 'id', array( 'id' => $cid ) );

    // If more than 30 days have passed, do not allow registering for courses.
    if( strtotime( 'now' ) - strtotime( $runningCourses[ $cid][ 'start_date' ] ) 
            > 30 * 24 * 3600 )
    {
        echo $course['name'] . '<br>' . '<tt>' . 
            humanReadableDate( $runningCourses[ $cid ][ 'start_date' ] ) 
            . ' to ' . humanReadableDate( $runningCourses[$cid]['end_date'] )
            . '</tt>'
            ;

        $action = ''; 
    }

    // TODO: Don't show grades unless student has given feedback.
    if( strlen( $c[ 'grade' ] == 0 ) )
        $tofilter .= ',grade,grade_is_given_on';

    echo dbTableToHTMLTable( 'course_registration', $c, '', $action, $tofilter );
    echo '</form>';
    echo '</td>';
}
    
echo '</tr></table>';
echo '</div>';


// Running course this semester.
$runningCourses = getSemesterCourses( $year, $sem );

$courseMap = array( );
$options = array( );
foreach( $runningCourses as $c )
{
    $cid = $c[ 'course_id' ];
    $options[] = $cid ;
    $courseMap[ $cid ] = $cid . ' - ' . getCourseName( $cid );
}

$courseSelect = arrayToSelectList( 'course_id', $options, $courseMap );

echo "<h3>Register for selected course </h3>";
$default = array( 'student_id' => $_SESSION[ 'user' ] 
                , 'semester' => $sem
                , 'year' => $year
                , 'registered_on' => dbDate( 'now' )
                , 'course_id' => $courseSelect
                );


echo '<form method="post" action="user_manages_courses_action.php">';
echo dbTableToHTMLTable( 'course_registration'
                        , $default
                        , 'course_id,type' 
                        , 'submit', 'last_modified_on,grade,grade_is_given_on'
                      );
echo '</form>';

echo goBackToPageLink( "user.php", "Go back" );

?><commit_msg>Good enough for launching to collect course data.<commit_after><?php

include_once 'check_access_permissions.php';
mustHaveAnyOfTheseRoles( array( 'USER' ) );

include_once 'database.php';
include_once 'tohtml.php';
include_once 'methods.php';

echo userHTML( );

$sem = getCurrentSemester( );
$year = getCurrentYear( );

// User courses.
$myCourses = getMyCourses( $sem, $year, $user = $_SESSION[ 'user' ] );

$runningCourses = array( );
foreach( getSemesterCourses( $year, $sem ) as $rc )
    $runningCourses[ $rc[ 'course_id' ] ] = $rc;


echo '<h1>Course enrollment</h1>';


echo alertUser( "
    <strong>Policy for dropping a course </strong> 
    <br>  Upto 30 days from starting of course, you are free to drop a course. 
    After that, you need to write to your course instructor and academic office.
    " );

$tofilter = 'student_id';

echo '<div style="font-size:small">';

echo '<table border="1">';
echo '<tr>';

$action = 'drop';
$count = 0;

if( count( $myCourses ) > 0 )
    echo "<h2>You are registered for following courses </h2>";

foreach( $myCourses as $c )
{
    $count += 1;
    if( $count % 3 == 0 )
        echo '</tr><tr>';

    echo '<td>';
    echo '<form method="post" action="user_manages_courses_action.php">';


    $cid = $c[ 'course_id' ];
    $course = getTableEntry( 'courses_metadata', 'id', array( 'id' => $cid ) );

    // If more than 30 days have passed, do not allow registering for courses.
    if( strtotime( 'now' ) - strtotime( $runningCourses[ $cid][ 'start_date' ] ) 
            > 30 * 24 * 3600 )
    {
        echo $course['name'] . '<br>' . '<tt>' . 
            humanReadableDate( $runningCourses[ $cid ][ 'start_date' ] ) 
            . ' to ' . humanReadableDate( $runningCourses[$cid]['end_date'] )
            . '</tt>'
            ;

        $action = ''; 
    }

    // TODO: Don't show grades unless student has given feedback.
    if( strlen( $c[ 'grade' ] == 0 ) )
        $tofilter .= ',grade,grade_is_given_on';

    echo dbTableToHTMLTable( 'course_registration', $c, '', $action, $tofilter );
    echo '</form>';
    echo '</td>';
}
    
echo '</tr></table>';
echo '</div>';


// Running course this semester.
$runningCourses = getSemesterCourses( $year, $sem );

$courseMap = array( );
$options = array( );
foreach( $runningCourses as $c )
{
    $cid = $c[ 'course_id' ];
    $options[] = $cid ;
    $courseMap[ $cid ] = $cid . ' - ' . getCourseName( $cid );
}

$courseSelect = arrayToSelectList( 'course_id', $options, $courseMap );

echo "<h2>Registration form</h2>";
//echo printInfo( 
    //"To register for a course, select it from drop-down list,
    //select a type (<tt>CREDIT</tt> or <tt>AUDIT</tt> and press submit button 
    //<button disabled>" . $symbSubmit . "</button>"
    //);

$default = array( 'student_id' => $_SESSION[ 'user' ] 
                , 'semester' => $sem
                , 'year' => $year
                , 'registered_on' => dbDate( 'now' )
                , 'course_id' => $courseSelect
                );


echo '<form method="post" action="user_manages_courses_action.php">';
echo dbTableToHTMLTable( 'course_registration'
                        , $default
                        , 'course_id,type' 
                        , 'submit'
                        , 'status,registered_on,last_modified_on,grade,grade_is_given_on'
                      );
echo '</form>';

echo goBackToPageLink( "user.php", "Go back" );

?>
{'fraction_non_alphanumeric': 0.16827586206896553, 'fraction_numerical': 0.007203065134099617, 'mean_word_length': 2.710062535531552, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4592766', 'n_tokens_mistral': 2224, 'n_tokens_neox': 2126, 'n_words': 561}