<?php
    include '/home/mustelap/public_html/admin/load.php';

    $time_left	     = isset($_GET['time_left']) && !empty($_GET['time_left']) ? $_GET['time_left'] : 14;
    $result          = $course->getUnfinishedCourses($time_left);

    if(!empty($result)) {
        foreach($result as $row) {
            $course_id           = $row['id'];
            $course_title        = $row['title'];
            $name                = $row['name'];
            $surname             = $row['surname'];
            $user_email          = $row['email'];
            $valid_until         = $row['valid_until'];
            $progress            = $row['progress'];

            $email_template = file_get_contents(DIR_COMMON.'/email/templates/course-time-left.html');
            $email_template = str_replace('%base_url%', $App->url, $email_template);
            $email_template = str_replace('%name%', $name." ".$surname, $email_template);
            $email_template = str_replace('%course_title%', $course_title, $email_template);
            $email_template = str_replace('%valid_until%', $valid_until, $email_template);
            $email_template = str_replace('%time_left%', $time_left.' gün', $email_template);
            
            $email->send(
                array(
                    'to'                 => array(array('name'=>$name." ".$surname, 'email'=>$user_email)),
                    'is_html'            => true,
                    'subject'            => 'Eğitim Durumu Bilgilendirme',
                    'body'               => $email_template
                )
            );
        }
        $utils->errorLog("info", "Kalan eğitim süresi epostaları gönderildi! Kalan gün: ".$time_left, 0, 'cron job');
    }else{
        $utils->errorLog("info", "Kalan eğitim süresi epostaları gönderilemedi! Kalan gün: ".$time_left, 0, 'cron job');
    }
