Ejemplo n.º 1
0
function on_get_send()
{
    global $web, $controls;
    init_page();
    if ($web->isFormValid()) {
        // hide our input form and show the success message
        // which are both in the same template
        $controls['formpers']->hide();
        $controls['areamsg']->show();
        // show the submitted data in a short summary
        $controls['spanfirstname']->setContent($controls['edtfirstname']->getSubmitValue());
        $controls['spanlastname']->setContent($controls['edtlastname']->getSubmitValue());
        $controls['spanemail']->setContent($controls['edtemail']->getSubmitValue());
        $controls['spancountry']->setContent($controls['selcountry']->getSubmitValue());
        // set the correct back link
        $controls['aback']->setHref($_SERVER['PHP_SELF']);
    }
    $web->printTemplate($controls);
}
{
    echo html_writer::start_tag('h4');
    echo get_string('success', 'block_mycourse_recommendations');
    echo html_writer::end_tag('h4');
    echo html_writer::start_tag('hr');
    echo 'Summary of importation:';
    echo html_writer::start_tag('br');
    $insertedcourses = \block_mycourse_recommendations\csv_importer::get_lastinsertedcourses();
    $insertedcourses = get_string('importedcourses', 'block_mycourse_recommendations') . $insertedcourses;
    $insertedusers = \block_mycourse_recommendations\csv_importer::get_lastinsertedusers();
    $insertedusers = get_string('importedusers', 'block_mycourse_recommendations') . $insertedusers;
    $insertedlogs = \block_mycourse_recommendations\csv_importer::get_lastinsertedlogs();
    $insertedlogs = get_string('importedlogs', 'block_mycourse_recommendations') . $insertedlogs;
    echo html_writer::alist(array($insertedcourses, $insertedusers, $insertedlogs));
}
$courseid = init_page();
$actionurl = $_SERVER['PHP_SELF'] . "?courseid={$courseid}";
echo $OUTPUT->header();
echo $OUTPUT->navbar();
$form = new \block_mycourse_recommendations\import_form($actionurl);
$formdata = $form->get_data();
// If the form has submitted, this branch is entered, where the data is imported using the csv importer.
if ($formdata) {
    $coursefile = $form->get_file_content('courses');
    $usersfile = $form->get_file_content('users');
    $logsfile = $form->get_file_content('logs');
    try {
        \block_mycourse_recommendations\csv_importer::import_data($formdata, $coursefile, $usersfile, $logsfile, $courseid);
        print_success_summary();
    } catch (Exception $e) {
        echo get_string('errorimporting', 'block_mycourse_recommendations');