#!/usr/bin/perl

use strict;
use CGI;

use Opals::Context;
use Opals::Template qw(

    tmpl_read
    tmpl_write
    tmpl_rangedPageList

);

use Opals::Course qw(
    
    course_getSchoolYearList
    course_getSchoolYearInfo
    course_getList
    course_findById
    course_add

);

use Opals::Constant;

my $dbh = Opals::Context->dbh();
END { $dbh->disconnect(); }

my $cgi = CGI->new;
my $input = $cgi->Vars();

my ($permission, $cookieList, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => '/txtbk/ajax/course/saveImportCourse.tmpl',
    }
);


my @courseIds = ($cgi->param('courseId'));
my $toSchoolYear = $input->{'selToSchoolYear'};
my ($courseInfo, $newCId, $params);
    foreach my $cId (@courseIds){
        $courseInfo = course_findById($dbh, $cId);
        $params = {
            courseCode  => $courseInfo->{'courseCode'},
            courseName  => $courseInfo->{'courseName'},
            descriptions  => $courseInfo->{'descriptions'},
            grade       => $courseInfo->{'grade'},
            schoolYear  => $toSchoolYear
        };
        $newCId = course_add($dbh,$params);
    }

$template->param(
    saveCode => 1
    
);

tmpl_write($dbh, $cgi, $cookieList, $template);



