Ejemplo n.º 1
0
/**
 * Shared courses are courses that have students from more than one program enroled in them.
 * Because the Program name is part of the course title in Moodle, the course is essentially
 * duplicated in mdl_accs_newcourses when data is exported from Agresso.
 * So, we make the title include the department instead of the program so a single course shell is created.
 *
 * @author Andrew Zoltay
 * date    2011-06-14
 * @global object $DB Moodle database object
 */
function accs_handle_shared_courses()
{
    global $DB;
    // First identify the all the shared courses.
    try {
        $sql = "SELECT\n                    id, agrcourseoffpk, idnumber, fullname, shortname,\n                    department, program\n                    FROM {accs_newcourses}\n                    WHERE agrcourseoffpk IN (SELECT agrcourseoffpk FROM {accs_newcourses}\n                                            GROUP BY idnumber\n                                            HAVING Count(department) > 1)\n                    ORDER BY agrcourseoffpk;";
        $sharedcourses = $DB->get_records_sql($sql);
    } catch (Exception $e) {
        accs_write_to_log("ERROR - Failed to retrieve list of shared courses from mdl_accs_newcourses");
    }
    $sharedcoursecount = 0;
    $failedcount = 0;
    $previouscoursepk = 0;
    foreach ($sharedcourses as $sharedcourse) {
        // Update them so there is only a single course to be imported into Moodle.
        if ($previouscoursepk != $sharedcourse->agrcourseoffpk) {
            // Reform the course name so it uses department instead of program.
            $shortname = str_replace(trim($sharedcourse->program), trim($sharedcourse->department), $sharedcourse->shortname);
            $fullname = 'SHARED - ' . str_replace(trim($sharedcourse->program), trim($sharedcourse->department), $sharedcourse->fullname);
            // Bundle up the parameters for the execute statement.
            $params = array($fullname, $shortname, $sharedcourse->department, $sharedcourse->department, $sharedcourse->agrcourseoffpk);
            $updatesql = "UPDATE {accs_newcourses}\n                          SET fullname = ?,\n                          shortname = ?,\n                          department = ?,\n                          program = ?\n                          WHERE agrcourseoffpk = ?";
            try {
                $DB->execute($updatesql, $params);
                accs_write_to_log("Updated shared course {$sharedcourse->idnumber}'s title to '{$fullname}'");
                $sharedcoursecount++;
            } catch (Exception $e) {
                accs_write_to_log("ERROR - Failed to update shared course {$sharedcourse->idnumber}");
                $failedcount;
            }
            $previouscoursepk = $sharedcourse->agrcourseoffpk;
        }
    }
    accs_write_to_log("{$sharedcoursecount} 'shared' courses were updated and {$failedcount} 'shared' courses failed to be updated");
}
Ejemplo n.º 2
0
/**
 * Send an email to recipient
 *
 * @author Andrew Zoltay
 * date    2010-05-03
 * @param string $to email recipient
 * @param string $from sender
 * @param string $subject subject of email
 * @param string $body body of the email
 * @return boolean success if email was sent or false otherwise
 */
function accs_send_mail($to, $from, $subject, $body)
{
    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-Type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: ' . $from . "\r\n" . 'X-Mailer: PHP/' . phpversion();
    $status = mail($to, $subject, $body, $headers);
    $sent = false;
    if ($status === true) {
        $sent = true;
    } else {
        accs_write_to_log("ERROR - accs_send_mail: failed to send email notification");
    }
    return $sent;
}
Ejemplo n.º 3
0
/**
 * Close connection to MS SQL Server
 *
 * @author Andrew Zoltay
 * date    2010-04-28
 * @param MS SQL Link identifier $conn to be closed
 * @return none
 */
function accs_mssql_close(&$conn)
{
    if (!mssql_close($conn)) {
        accs_write_to_log('Failed to close MS SQL Server connection');
    }
}