예제 #1
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with INTUITEL for Moodle Adaptor.  If not, see <http://www.gnu.org/licenses/>.
/**
 * REST interface.
 *
 * @package    block_intuitel
 * @author Juan Pablo de Castro, Elena Verdú.
 * @copyright  2015 Intuitel Consortium
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
use intuitel\IntuitelXMLSerializer;
use intuitel\IntuitelController;
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
require_once "model/LOFactory.php";
require_once "model/intuitelLO.php";
require_once 'model/serializer.php';
require_once 'model/exceptions.php';
block_intuitel_disable_moodle_page_exception_handler();
block_intuitel_check_access();
$params = array();
$serializer = new IntuitelXMLSerializer();
$xml = block_intuitel_get_input_message();
global $log;
$log->LogDebug("USE_PERF request received: {$xml}");
$response = IntuitelController::ProcessUsePerfRequest($xml);
header('Content-type: text/xml');
$log->LogDebug("USE_PERF response sent: {$response}");
echo $response;
예제 #2
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with INTUITEL for Moodle Adaptor.  If not, see <http://www.gnu.org/licenses/>.
/**
 * REST interface.
 *
 * @package    block_intuitel
 * @author Juan Pablo de Castro, Elena Verdú.
 * @copyright  2015 Intuitel Consortium
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
use intuitel\Intuitel;
use intuitel\IntuitelXMLSerializer;
use intuitel\idFactory;
use intuitel\IntuitelController;
use intuitel\ProtocolErrorException;
require_once "../../config.php";
require_once 'locallib.php';
require_once 'model/exceptions.php';
block_intuitel_disable_moodle_page_exception_handler();
$xml = block_intuitel_get_input_message('POST|GET');
list($validated, $useridsvalidated, $response) = IntuitelController::ProcessAuthRequest($xml);
if ($validated) {
    $_SESSION['user_validated'] = true;
    $_SESSION['user_ids_validated'] = $useridsvalidated;
} else {
    session_destroy();
}
header('Content-type: text/xml');
echo $response;
예제 #3
0
/**
 * Report user's activities to INTUITEL.
 * @param unknown $cmid
 * @param unknown $courseid
 * @param unknown $user_id
 * @param boolean $ignorelo whether to send LoId to INTUITEL (ignored in simulation mode)
 * @return Ambigous <string, lang_string, unknown, mixed>
 */
function block_intuitel_forward_learner_update_request($cmid, $courseid, $user_id, $ignorelo = false)
{
    $debug = optional_param('debug', false, PARAM_BOOL);
    $debug_response = optional_param('debugresponse', null, PARAM_ALPHANUM);
    // this param instruct Intuitel mock objects to respond with a pre-recorded response.
    $mmid = Intuitel::getIDFactory()->getNewMessageUUID();
    if (empty($cmid)) {
        $loId = Intuitel::getIDFactory()->getLoIdfromId('course', $courseid);
    } else {
        $loId = Intuitel::getIDFactory()->getLoIdfromId('module', $cmid);
    }
    // GET CURRENT USER id
    $userId = Intuitel::getIDFactory()->getUserId($user_id);
    global $CFG, $log;
    if ($ignorelo == true && get_config('block_intuitel', 'debug_server') == true) {
        $log->LogDebug("LMS send refreshing Learner message. Normal Learner procedure because in SIMULATED mode.");
    }
    if ($ignorelo == true && get_config('block_intuitel', 'debug_server') == false) {
        // Ignore reporting to INTUITEL. Just send a Learner message with no LoId to repeat reasoning
        // But simulated mode need loid to be sent
        $learnerUpdateMessage = '<INTUITEL>';
        $learnerUpdateMessage .= '	<Learner mId="' . $mmid . '" uId="' . $userId->id . '"  time="' . time() . '"/>';
        $learnerUpdateMessage .= '</INTUITEL>';
        $log->LogDebug("LMS send refreshing Learner message.");
    } else {
        // normal reporting of current and unreported events
        $log->LogDebug("LMS send normal Learner message for user {$userId->id}");
        if (get_config('block_intuitel', 'report_from_logevent')) {
            // get events unreported since last polling
            $events_user = Intuitel::getAdaptorInstance()->getLearnerUpdateData(array($user_id));
            $events = key_exists($userId->id, $events_user) ? $events_user[$userId->id] : null;
        }
        if (!get_config('block_intuitel', 'report_from_logevent') || !$events) {
            $event = new VisitEvent($userId, $loId, time());
            $events = array($event);
        }
        $debug_param = get_config('block_intuitel', 'debug_server') ? 'debugcourse="' . $courseid . '"' : '';
        // when using mock REST service help it with native courseid.
        $learnerUpdateMessage = '<INTUITEL>';
        $log->LogDebug("LearnerUpdate: LMS has found " . count($events) . " events regarding user {$userId} .");
        foreach ($events as $ev) {
            $learnerUpdateMessage .= '	<Learner mId="' . $mmid . '" uId="' . $ev->userId . '" loId="' . $ev->loId->id() . '" time="' . $ev->time . '" ' . $debug_param . '/>';
        }
        $learnerUpdateMessage .= '</INTUITEL>';
    }
    //  disable_moodle_page_exception_handler();
    $return = "No response from Intuitel";
    $log->LogDebug("LMS sending: {$learnerUpdateMessage}");
    try {
        $return = block_intuitel_submit_to_intuitel($learnerUpdateMessage, array('debugresponse' => $debug_response));
        if ($debug) {
            debugging("<p> Response from INTUITEL was: <p><pre>{$return}</pre>", DEBUG_DEVELOPER);
        }
        $log->LogDebug("LearnerUpdate: INTUITEL response was: {$return}.");
        // parse and generate TUG AND LORE html and messages
        list($html, $intuitel_elements) = IntuitelController::ProcessUpdateLearnerRequest($return, $courseid);
        if (count($intuitel_elements->Learner->Tug) > 0) {
            $response = IntuitelXMLSerializer::getIntuitelXMLTemplate();
            foreach ($intuitel_elements->Learner->Tug as $tug) {
                $mid = IntuitelXMLSerializer::get_required_attribute($tug, 'mId');
                $text = str_replace('<![CDATA[', '', $tug->MData);
                $text = str_replace(']]>', '', $tug->MData);
                $text = strip_tags($text);
                Intuitel::getAdaptorInstance()->logTugView($courseid, $user_id, $mid, substr('mId=' . $mid . ' ' . $text, 0, 255));
                IntuitelController::addTUGInmediateResponse($response, IntuitelXMLSerializer::get_required_attribute($tug, 'uId'), IntuitelXMLSerializer::get_required_attribute($tug, 'mId'), "OK");
            }
            $xml = $response->asXML();
            block_intuitel_submit_to_intuitel($xml);
            $log->LogDebug("TUG inmediate response sent: {$xml}");
        }
        if (count($intuitel_elements->Learner->Lore) > 0) {
            $response = IntuitelXMLSerializer::getIntuitelXMLTemplate();
            foreach ($intuitel_elements->Learner->Lore as $lore) {
                $mid = IntuitelXMLSerializer::get_required_attribute($lore, 'mId');
                $lores = array();
                foreach ($lore->LorePrio as $lorePrio) {
                    try {
                        $loid = IntuitelXMLSerializer::get_required_attribute($lorePrio, 'loId');
                        $cmid = Intuitel::getIDFactory()->getIdfromLoId(new LOId($loid));
                        $lo = Intuitel::getAdaptorInstance()->createLO(new LOId($loid));
                        $lores[] = "({$cmid})\"{$lo->loName}\"";
                    } catch (Exception $ex) {
                        $lores[] = $loid;
                    }
                }
                if (count($lores)) {
                    // log activity
                    Intuitel::getAdaptorInstance()->logLoreView($courseid, $user_id, $mid, substr(join(',', $lores), 0, 255));
                }
                $xml = IntuitelController::addLOREInmediateResponse($response, IntuitelXMLSerializer::get_required_attribute($lore, 'uId'), IntuitelXMLSerializer::get_required_attribute($lore, 'mId'), "OK");
            }
            $xml = $response->asXML();
            block_intuitel_submit_to_intuitel($xml);
        }
        $html = '<div>' . $html . '</div>';
    } catch (ProtocolErrorException $exception) {
        // error
        $a = new stdClass();
        $a->service_point = block_intuitel_get_service_endpoint();
        $a->status_code = $exception->getStatusCode();
        $a->message = $exception->getMessage();
        $html = get_string('protocol_error_intuitel_node_malfunction', 'block_intuitel', $a);
        $log->LogError("INTUITEL error: {$a->message} Return value:" . $return);
    }
    return $html;
}
예제 #4
0
// along with INTUITEL for Moodle Adaptor.  If not, see <http://www.gnu.org/licenses/>.
/**
 * REST interface.
 *
 * @package    block_intuitel
 * @author Juan Pablo de Castro, Elena Verdú.
 * @copyright  2015 Intuitel Consortium
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
use intuitel\IntuitelXMLSerializer;
use intuitel\Intuitel;
use intuitel\ProtocolErrorException;
use intuitel\IntuitelController;
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
require_once 'model/exceptions.php';
require_once 'model/intuitelController.php';
block_intuitel_disable_moodle_page_exception_handler();
block_intuitel_check_access();
global $CFG;
$xml = block_intuitel_get_input_message();
$intuitel_msg = IntuitelController::getIntuitelXML($xml);
$lmsProfile = $intuitel_msg->LmsProfile;
$mid = IntuitelXMLSerializer::get_required_attribute($lmsProfile, 'mId');
if (!isset($mid)) {
    throw new ProtocolErrorException("Bad LmsProfile request.");
}
$serializer = new IntuitelXMLSerializer();
$properties = Intuitel::getAdaptorInstance()->getLMSProfile();
header('Content-type: text/xml');
echo $serializer->serializeLMSProfile($mid, $properties);
예제 #5
0
//
// INTUITEL for Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// INTUITEL for Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with INTUITEL for Moodle Adaptor.  If not, see <http://www.gnu.org/licenses/>.
/**
 * REST interface.
 *
 * @package    block_intuitel
 * @author Juan Pablo de Castro, Elena Verdú.
 * @copyright  2015 Intuitel Consortium
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
use intuitel\IntuitelController;
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
require_once 'model/exceptions.php';
block_intuitel_disable_moodle_page_exception_handler();
block_intuitel_check_access();
$xml = block_intuitel_get_input_message();
$response = IntuitelController::ProcessLoreRequest($xml);
header('Content-type: text/xml');
echo $response;
예제 #6
0
if ($show == 'events') {
    header('Content-type: text/plain');
    foreach ($events as $event) {
        $time = date('Y-m-d H:i:s', $event->time);
        $class = get_class($event);
        if ($class == 'intuitel\\VisitEvent') {
            $lo = $adaptor->createLO($event->loId);
            $loType = Intuitel::getIDFactory()->getType($lo->loId);
            echo "{$time}  --> {$lo->loName}\n";
        } else {
            echo "{$time} --> {$event->description}\n";
        }
    }
    die;
}
list($revisits, $durations) = IntuitelController::compute_revisits($events, $totime);
$node_list = $revisits;
//
$first_node = isset($durations[0]->loId) ? (string) $durations[0]->loId : null;
$node_lines = '';
$clusters = array();
$node_style = "shape = box, style=\"rounded,filled\" fillcolor=white";
if ($forcestructure) {
    $rankdir = 'TD';
    $constraint = 'constraint=no';
    $constraint_structure = 'style=dotted constraint=yes color=red';
} else {
    $constraint = 'constraint=yes';
    $constraint_structure = 'style=dotted constraint=no color=red';
}
if ($rankdir == 'default') {
예제 #7
0
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
require_once 'model/exceptions.php';
require_once 'model/intuitelController.php';
global $log;
block_intuitel_disable_moodle_page_exception_handler();
if (!isset($_SESSION['user_validated'])) {
    block_intuitel_check_access();
} else {
    $log->LogDebug("Mapping request authenticated as:" . join(',', $_SESSION['user_ids_validated']));
}
$params = array();
$serializer = new IntuitelXMLSerializer();
$xml = block_intuitel_get_input_message();
$log->LogDebug("loMapping Request: {$xml}");
$intuitel_elements = IntuitelController::getIntuitelXML($xml);
$loMappings = IntuitelXMLSerializer::get_required_element($intuitel_elements, 'LoMapping');
$loMappingResults = array();
foreach ($loMappings as $loMapping) {
    $mid = IntuitelXMLSerializer::get_required_attribute($loMapping, 'mId');
    if (isset($loMappingResults[$mid])) {
        throw new ProtocolErrorException("Duplicated message id: {$mid}");
    }
    $params = $serializer->parse_mapping_request($loMapping);
    // support sending KVP for testing
    foreach ($_GET as $name => $value) {
        if ($name != 'xml' && $name != 'XDEBUG_SESSION_START') {
            $val = optional_param($name, null, PARAM_TEXT);
            if (isset($val)) {
                // CHECK if NULL is valid parameter
                $params[$name] = $val;
예제 #8
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with INTUITEL for Moodle Adaptor.  If not, see <http://www.gnu.org/licenses/>.
/**
 * REST interface.
 *
 * @package    block_intuitel
 * @author Juan Pablo de Castro, Elena Verdú.
 * @copyright  2015 Intuitel Consortium
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
use intuitel\Intuitel;
use intuitel\IntuitelController;
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
require_once "model/LOFactory.php";
require_once "model/intuitelLO.php";
require_once 'model/serializer.php';
require_once 'model/exceptions.php';
require_once 'model/intuitelController.php';
block_intuitel_disable_moodle_page_exception_handler();
block_intuitel_check_access();
$params = array();
$xml = block_intuitel_get_input_message();
global $log;
$log->LogDebug("USE_ENV request received: {$xml}");
$response = IntuitelController::processUseEnvRequest($xml);
header('Content-type: text/xml');
echo $response;
$log->LogDebug("USE_ENV response sent: {$response}");
예제 #9
0
require_once '../../model/intuitelLO.php';
//require_once('DumbIntuitel.php');
require_once 'SmartyIntuitel.php';
// test this with: http://localhost/moodle2/blocks/intuitel/tests/mockrest/intuitel.php?xml=%3CINTUITEL%3E%3CLearner%20uId=%22pepe%22/%3E%3C/INTUITEL%3E
// http://localhost/moodle2/blocks/intuitel/tests/mockrest/intuitel.php?xml=%3CINTUITEL%3E%3CLearner%20uId=%22pepe%22%20loId=%22wqHKFQmiYXEq4tE6y4BztVFIdzsIe2d7localhost-CO2%22%20debugcourse=%222%22/%3E%3C/INTUITEL%3E
// http://localhost/moodle2/blocks/intuitel/tests/mockrest/intuitel.php?debugresponse=true&userid=3&xml=%3CINTUITEL%3E%3CLearner%20uId=%22pepe%22%20loId=%22wqHKFQmiYXEq4tE6y4BztVFIdzsIe2d7localhost-CO2%22%20debugcourse=%222%22/%3E%3C/INTUITEL%3E
// accept: debugcourse with native courseid to simulare Lore Loids
//          debugresponse to enable HTML page formating
//          userid to use native userid in the request.
$debugresponse = optional_param('debugresponse', false, PARAM_ALPHANUM);
if ($debugresponse == false) {
    block_intuitel_disable_moodle_page_exception_handler();
}
$native_userid = optional_param('userid', null, PARAM_INTEGER);
$query = block_intuitel_get_input_message();
$intuitelMsg = IntuitelController::getIntuitelXML($query);
//sleep(4);
if ($intuitelMsg->Learner) {
    if ($native_userid) {
        // Debugging backdoor
        $learnerid = Intuitel::getIDFactory()->getUserId($native_userid);
    } else {
        $learnerid = (string) $intuitelMsg->Learner['uId'];
    }
    $loId = new LOId((string) $intuitelMsg->Learner['loId']);
    $nativeCourseId = (string) $intuitelMsg->Learner['debugcourse'];
    $adaptor = Intuitel::getAdaptorInstanceForCourse();
    $idFactory = Intuitel::getIdFactory();
    if ($nativeCourseId) {
        global $PAGE;
        $context = context_course::instance($nativeCourseId);
예제 #10
0
      * YUI form submittion does not support two submit buttons this is a workaround.
      */
     $tugcancelledfield = optional_param('_intuitel_TUG_cancel', null, PARAM_ALPHA);
     if ($tugcancelledfield !== '') {
         // The browser use Javascript.
         if ($tugcancelledfield === 'true') {
             $_REQUEST['_intuitel_user_intent'] = 'cancel';
         } else {
             $_REQUEST['_intuitel_user_intent'] = 'submit';
         }
     }
     // JPC: end of workaround for YUI bug with forms.
     if ($_REQUEST['_intuitel_user_intent'] === 'submit') {
         // Ignore cancellation of the TUG messages.
         // TODO: Avoid sending this form in the User Interface but find a way to work without javascript too.
         $message = IntuitelController::ProcessTUGResponse($USER->id, $_REQUEST, $courseid);
         $log->LogDebug("LMS sends TUG answer: {$message}");
         block_intuitel_submit_to_intuitel($message);
     } else {
         $mid = required_param('mId', PARAM_ALPHANUMEXT);
         Intuitel::getAdaptorInstance()->logTugDismiss($courseid, $USER->id, $mid, 'DISMISS mId=' . $mid);
     }
 } else {
     if ($action == 'GEOLOCATION') {
         require_login();
         session_write_close();
         // Release the session to avoid block requests while waiting intuitel response.
         $adaptor = Intuitel::getAdaptorInstance();
         // Location.
         $lat = required_param('lat', PARAM_FLOAT);
         $lon = required_param('lon', PARAM_FLOAT);
 /**
  * @see IntuitelController::compute_durations
  * @param array $eventsArray
  * @return array:VisitEvent array:VisitEvent  durations,revisits arrays
  */
 public static function compute_revisits(array $eventsArray, $totime = null)
 {
     $revisits = array();
     $durations = IntuitelController::compute_durations($eventsArray, $totime);
     $dur_obj = new \ArrayObject($durations);
     $duration_copy = $dur_obj->getArrayCopy();
     // copy to process and destroy with array_pop
     while (($current = array_pop($duration_copy)) != null) {
         if (array_key_exists($current->loId->id, $revisits) == true) {
             $count = $revisits[$current->loId->id];
         } else {
             $count = 0;
         }
         $revisits[$current->loId->id] = $count + 1;
     }
     return array($revisits, $durations);
 }
예제 #12
0
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with INTUITEL for Moodle Adaptor.  If not, see <http://www.gnu.org/licenses/>.
/**
 * REST interface.
 *
 * @package    block_intuitel
 * @author Juan Pablo de Castro, Elena Verdú.
 * @copyright  2015 Intuitel Consortium
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
use intuitel\Intuitel;
use intuitel\IntuitelXMLSerializer;
use intuitel\idFactory;
use intuitel\IntuitelController;
require_once dirname(dirname(dirname(__FILE__))) . '/config.php';
require_once 'locallib.php';
require_once "model/LOFactory.php";
require_once "model/intuitelLO.php";
require_once 'model/serializer.php';
require_once 'model/intuitelController.php';
block_intuitel_disable_moodle_page_exception_handler();
block_intuitel_check_access();
$params = array();
$xml = block_intuitel_get_input_message();
$response = IntuitelController::ProcessLearnerRequest($xml);
header('Content-type: text/xml');
echo $response;