Your IP : 216.73.217.79


Current Path : /var/www/cesa.co.za/cceadmin/
Upload File :
Current File : /var/www/cesa.co.za/cceadmin/inc_functions.php

<?php

$conni = mysqli_connect(EW_CONN_HOST, EW_CONN_USER, EW_CONN_PASS, EW_CONN_DB);
include_once($_SERVER['DOCUMENT_ROOT'] . "/cesanet/inc_shared.php");

// Check if this is the student list
//echo strpos($_REQUEST['REQUEST_URI'], 'CCEStudentslist') . ' is the search' . "\r\n";
//exit;
if (strpos($_REQUEST['REQUEST_URI'], 'CCEStudentslist') > 0) {
    if (!isset($_REQUEST['x_Archived'])) {
        $_REQUEST['x_Archived'] = 0;
    }
    if (!isset($_REQUEST['z_Archived'])) {
        $_REQUEST['z_Archived'] = '=';
    }
    if (!isset($_REQUEST['x_Cancelled'])) {
        $_REQUEST['x_Cancelled'] = 1;
    }
    if (!isset($_REQUEST['z_Cancelled'])) {
        $_REQUEST['z_Cancelled'] = '=';
    }
}

if (!function_exists('GenPassword')) {

    function GenPassword()
    {
        // Password generation
        $length = 8; // Must be a multiple of 2
        $conso = array("b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "y", "z");
        $vocal = array("a", "e", "i", "o", "u");
        $password = "";
        srand((float) microtime() * 1000000);
        $max = $length / 2;
        for ($i = 1; $i <= $max; $i++) {
            $password .= $conso[rand(0, 19)];
            $password .= $vocal[rand(0, 4)];
        }

        return $password;
    }
}

if (!function_exists('DrupalUpdateUser')) {

    function DrupalUpdateUser($username, $password) {}
}

if (!function_exists('DrupalDeleteUser')) {

    function DrupalDeleteUser($username) {}
}

if (!function_exists('AddTopSaveButton')) {

    function AddTopSaveButton($pageobj, $formname)
    {
        $pageobj->setMessage("<input type='button' value='Save' onClick='javascript:document.getElementById(\"" . $formname . "\").submit()'>");
    }
}

if (!function_exists('SendSMS')) {

    function SendSMS($to, $msg)
    {
        $sendurl = "http://api.clickatell.com/http/sendmsg?api_id=3272128&user=CESA1SMS&password=cesa1sms&to=" . $to . "&text=" . urlencode(substr($msg, 0, 160));

        $ch = curl_init($sendurl);

        curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $response = curl_exec($ch);
        curl_close($ch);

        return $response;
    }
}

if (!function_exists('SendAssignmentFeedback')) {

    function SendAssignmentFeedback($AssignmentID, $StudentID, $SendTo, $sMessage, $sAttachment = "", $postData = array())
    {

        global $conni, $env, $sqlf;

        $sUsername = CurrentUserName();
        $sql = "SELECT FacilitatorID, FullName FROM CCEFacilitatorUsers WHERE Username='" . $sUsername . "'";

        // echo $sql . '<br />';

        $rec = mysqli_query($conni, $sql);
        //	echo mysql_num_rows($rec);
        if ($row = mysqli_fetch_assoc($rec)) {
            $sFrom = $row["FullName"];
            if (!empty($row["FacilitatorID"]))
                $SentByFacilitatorID = $row["FacilitatorID"];
        }
        mysqli_free_result($rec);

        //    echo $sFrom;
        //    die();

        $sql = "SELECT CCEModuleID, RefNum, AssignmentName FROM CCEAssignments "
            . "WHERE CCEAssignmentID=" . $AssignmentID;

        //    echo $sql;
        //    exit;

        $rec = mysqli_query($conni, $sql);
        if ($row = mysqli_fetch_assoc($rec)) {
            $sSubject = "Feedback on BCE Assignment " . $row["RefNum"] . ' - ' . $row["AssignmentName"];
            $sModuleID = $row["CCEModuleID"];
        }
        mysqli_free_result($rec);

        $arrSendTo = explode(",", $SendTo);
        array_walk($arrSendTo, function (&$val) {
            return trim($val);
        });

        if ($env == 'dev') {
            $arrSendTo = array('cesa-bce@igotafrica.com');
        }

        $sFrom = "CESA Programme Coordinator";

        // echo 'Please ignore debug info' . "\r\n";
        // var_dump($arrSendTo);
        // echo "\r\n\r\n";

        // echo '<br />';
        // exit;

        $attachmentfile = $sAttachment;

        if (isset($postData['sendFeedbackExamplesButton']) && strlen($postData['sendFeedbackExamplesButton']) > 0) {
            // TODO: Get the e-mail address of the logged in user

            $facilitatorUserObj = new CCEFacilitatorUser($sqlf);
            $loggedInConvenor = $facilitatorUserObj->getLoggedInConvenor();

            // var_dump($loggedInConvenor);
            // exit;

            if (isset($loggedInConvenor['FacilitatorID'])) {
                $arrSendTo = ['F' . $loggedInConvenor['FacilitatorID']];
            } else {
                $arrSendTo = ['TEST'];
            }
        }

        $SystemMessage = 1;

        include($_SERVER['DOCUMENT_ROOT'] . "/cceadmin/inc_sendmessage.php");

        if (empty($cceMessageSendResult['ok'])) {
            $failureMessage = isset($cceMessageSendResult['message'])
                ? $cceMessageSendResult['message']
                : 'Feedback notification could not be sent.';
            if (!empty($cceMessageSendResult['mail_errors'])) {
                $failureMessage .= ' ' . implode('; ', $cceMessageSendResult['mail_errors']);
            }
            if (!empty($cceMessageSendResult['attachment_errors'])) {
                $failureMessage .= ' ' . implode('; ', $cceMessageSendResult['attachment_errors']);
            }
            throw new Exception($failureMessage);
        }

        return $CCEMessageID;
    }
}

if (!function_exists('CCEStudentAssignmentsList_Load')) {

    function CCEStudentAssignmentsList_Load()
    {
        global $conni;
        $_SESSION[EW_SESSION_MESSAGE] = "Average Assignment Score: " . GetAverageAssigScore(intval($_GET["CCEStudentID"]));
    }
}

if (!function_exists('CCEDocumentsUpsert')) {

    function CCEDocumentsUpsert(&$rsOld, &$rsNew = array())
    {
        global $sqlf;

        if (!class_exists('BaseTableClass')) {
            include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/BaseTableClass.php');
        }
        if (!class_exists('CCEDocuments')) {
            include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/CCEDocuments.php');
        }
        if (!isset($sqlf) || !is_object($sqlf)) {
            include_once($_SERVER['DOCUMENT_ROOT'] . '/php/includes/sqlFunctions.php');
            global $sqlf;
        }

        $documentId = isset($rsOld['CCEDocumentID']) ? intval($rsOld['CCEDocumentID']) : 0;
        $weeklySessionID = isset($rsOld['CCEWeeklySessionID']) ? $rsOld['CCEWeeklySessionID'] : 0;

        // array_key_exists: PHPMaker sets cleared integer lookups to NULL in $rsNew.
        // isset(null) is false and would wrongly keep the old session ID, re-linking AppliesToDate.
        if (is_array($rsNew) && array_key_exists('CCEWeeklySessionID', $rsNew)) {
            $weeklySessionID = $rsNew['CCEWeeklySessionID'];
        }

        if ($documentId <= 0 || !is_object($sqlf)) {
            return;
        }

        // Null/empty/non-numeric => cleared (intval yields 0) => clearWeeklySessionLink
        $documents = new CCEDocuments($sqlf);
        $documents->syncWeeklySessionLink($documentId, intval($weeklySessionID));
    }
}

if (!function_exists('encryptFacilitatorPassword')) {

    function encryptFacilitatorPassword($rsOld, &$rsNew = array())
    {

        global $conni;

        if (count($rsNew) <= 0 || (isset($rsNew['Password']) && $rsOld['Password'] != $rsNew['Password'])) {

            if (!isset($rsNew)) {
                $rsNew = array('Password' => $rsOld['Password']);
            }

            $sql = "UPDATE CCEFacilitatorUsers SET Password = '" . md5($rsNew['Password']) . "' WHERE CCEFacilitatorUserID = " . $rsOld['CCEFacilitatorUserID'];
            //        echo $sql;
            //        exit;
            $rec = mysqli_query($conni, $sql);
        }
    }
}

if (!function_exists('ArchivedStudents_Row_Rendering')) {

    function ArchivedStudents_Row_Rendering($object)
    {
        //    var_dump($object);
        //    echo 'One row?<br /><br /><br /><br />';
    }
}