Example #1
0
        $_SESSION['s_lesson_user_type'] = $roles[$userLessons[$_SESSION['s_lessons_ID']]];
        //needed for outputfilter.eF_template_setInnerLinks
        $smarty->assign("T_TITLE_BAR", $currentLesson->lesson['name']);
    } catch (Exception $e) {
        unset($_SESSION['s_lessons_ID']);
        $message = $e->getMessage() . ' (' . $e->getCode() . ')';
        eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?message=" . urlencode($message) . "&message_type=failure");
    }
}
//@todo: remove package_ID from $_SESSION, beware package_ID is needed in lms_commit
if (isset($_SESSION['package_ID']) && !$_GET['commit_lms']) {
    unset($_SESSION['package_ID']);
}
try {
    if (isset($_GET['view_unit']) && eF_checkParameter($_GET['view_unit'], 'id')) {
        $currentContent = new EfrontContentTree($currentLesson);
        //Initialize content
        if ($currentUser->coreAccess['content'] == 'hidden') {
            eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
        }
        if (!$currentLesson || !$currentContent) {
            eF_redirect("" . basename($_SERVER['PHP_SELF']));
        }
        $currentUnit = $currentContent->seekNode($_GET['view_unit']);
        //Initialize current unit
        //The content tree does not hold data, so assign this unit its data
        $unitData = new EfrontUnit($_GET['view_unit']);
        //$_SESSION['s_time_target'] = array($_GET['view_unit'] => 'unit');
        $currentUnit['data'] = $unitData['data'];
        if (G_VERSIONTYPE != 'community') {
            #cpp#ifndef COMMUNITY
Example #2
0
 /**
  * Class constructor
  *
  * This function is used to instantiate the class. The instatiation is done
  * based on a lesson id. If an entry with this id is not found in the database,
  * an eF_ManifestException is thrown.
  * <br/>Example:
  * <code>
  * $manifest = new EfrontManifest(32);                     //32 is a lesson id
  * </code>
  *
  * @param int $lesson_id The lesson id
  * @since 1.0
  * @access public
  */
 function __construct($lesson_id)
 {
     if (!eF_checkParameter($lesson_id, 'id')) {
         throw new eF_ManifestException(_INVALIDID, eF_ManifestException::INVALID_ID);
     }
     $lesson = eF_getTableData("lessons", "*", "id = {$lesson_id}");
     if (sizeof($lesson) == 0) {
         throw new eF_ManifestException(_LESSONDOESNOTEXIST, eF_GroupException::LESSON_NOT_EXISTS);
     } else {
         $this->lesson_id = $lesson_id;
         $content = new EfrontContentTree($this->lesson_id);
         $cunit = $content->getCurrentNode();
         $this->addUnit(new EfrontUnit($cunit[0]));
         $lunits = $content->getNextNodes();
         for ($i = 0; $i < sizeof($lunits); $i++) {
             $this->addUnit(new EfrontUnit($lunits[$i]));
         }
     }
 }
 $_admin_ ? $skillgap_tests = 1 : ($skillgap_tests = 0);
 //An array of legal ids for editing entries
 if (!$_admin_) {
     if (!isset($currentContent)) {
         $result = eF_getTableDataFlat("tests", "id", "lessons_ID=0");
         $legalValues = $result['id'];
         if (isset($_GET['show_solved_test'])) {
             $tests_ID = eF_getTableData("completed_tests", "tests_ID", "id=" . $_GET['show_solved_test']);
             if (!empty($legalValues)) {
                 if (in_array($tests_ID[0]['tests_ID'], $legalValues)) {
                     $set_skill_gap = 1;
                 }
             }
         }
         if ($currentLesson && !$set_skill_gap) {
             $currentContent = new EfrontContentTree($currentLesson);
         } else {
             if (isset($_GET['show_solved_test']) && isset($_GET['test_analysis']) || $set_skill_gap) {
                 //user viewing own skillgap analysis
                 $skillgap_tests = 1;
                 $_change_ = 0;
                 $smarty->assign("_change_", $_change_);
                 if (!empty($legalValues)) {
                     $legalSolvedValues = eF_getTableDataFlat("completed_tests JOIN users_to_skillgap_tests ON completed_tests.tests_ID = users_to_skillgap_tests.tests_ID AND users_to_skillgap_tests.solved = 1", "completed_tests.id", "users_to_skillgap_tests.users_LOGIN='******'login'] . "' and users_to_skillgap_tests.tests_ID in (" . implode(",", $legalValues) . ")");
                     $legalSolvedValues = $legalSolvedValues['id'];
                 }
                 $legalQuestions = eF_getTableDataFlat('questions', "id");
             } else {
                 eF_redirect(basename($_SERVER['PHP_SELF']));
             }
         }
Example #4
0
<?php

if (str_replace(DIRECTORY_SEPARATOR, "/", __FILE__) == $_SERVER['SCRIPT_FILENAME']) {
    exit;
}
!isset($currentUser->coreAccess['content']) || $currentUser->coreAccess['content'] == 'change' ? $_change_ = 1 : ($_change_ = 0);
$smarty->assign("_change_", $_change_);
if (!$_change_) {
    eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
    exit;
}
$loadScripts[] = 'includes/order';
try {
    $currentContent = new EfrontContentTree($currentLesson);
    $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST));
    //Legal values are the array of entities that the current user may actually edit or change.
    foreach ($iterator as $key => $value) {
        $legalValues[] = $key;
    }
    $smarty->assign("T_UNIT_ORDER_TREE", $currentContent->toHTML($iterator, 'dhtmlContentTree', array('delete' => true, 'noclick' => true, 'activate' => true, 'drag' => true, 'expand' => true)));
    $options = array(array('image' => '16x16/undo.png', 'text' => _REPAIRTREE, 'href' => 'javascript:void(0)', 'onClick' => 'if (confirm (\'' . _ORDERWILLPERMANENTLYCHANGE . '\')) repairTree(this);'));
    $smarty->assign("T_TABLE_OPTIONS", $options);
    try {
        if (isset($_POST['delete_nodes']) && $_POST['delete_nodes']) {
            //Needed in order to delete branches as well
            $_POST['delete_nodes'] = array_reverse($_POST['delete_nodes']);
            foreach ($_POST['delete_nodes'] as $value) {
                try {
                    if (in_array($value, $legalValues) && eF_checkParameter($value, 'id')) {
                        $currentContent->removeNode($value);
                        if (($pos = array_search($value, $legalValues)) !== false) {
Example #5
0
 $course->course['seats_remaining'] >= 0 or $course->course['seats_remaining'] = 0;
 $smarty->assign("T_COURSE", $course);
 if (isset($_SESSION['s_type']) && $_SESSION['s_type'] == 'administrator' || in_array($_SESSION['s_login'], array_keys($course->getUsers()))) {
     $smarty->assign("T_HAS_COURSE", true);
 }
 if (G_VERSIONTYPE == 'enterprise') {
     #cpp#ifdef ENTERPRISE
     $result = eF_getTableData("module_hcd_course_to_branch mb, module_hcd_branch b", "mb.branches_ID, b.name", "mb.branches_ID=b.branch_ID and courses_ID=" . $course->course['id']);
     if (!empty($result)) {
         $course->course['location'] = $result[0]['name'];
     }
 }
 #cpp#endif
 $lessons = $course->getCourseLessons();
 foreach ($lessons as $key => $lesson) {
     $content = new EfrontContentTree($lesson);
     if (sizeof($content->tree) > 0) {
         $contentTree[$key] = $content->toHTML(false, 'dhtml_content_tree_' . $lesson->lesson['id'], array('noclick' => 1));
     }
     $lessonInfo[$key] = new LearningObjectInformation(unserialize($lesson->lesson['info']));
     $additionalInfo[$key] = $lesson->getInformation();
 }
 $smarty->assign("T_ADDITIONAL_LESSON_INFO", $additionalInfo);
 $smarty->assign("T_COURSE_LESSON_INFO", $lessonInfo);
 $smarty->assign("T_CONTENT_TREE", $contentTree);
 $smarty->assign("T_LANGUAGES", EfrontSystem::getLanguages(true));
 $smarty->assign("T_COURSE_LESSONS", $lessons);
 $constraints = array('archive' => false, 'active' => true, 'sort' => 'name', 'condition' => 'show_catalog=1');
 if ($course->course['instance_source']) {
     $parentCourse = new EfrontCourse($course->course['instance_source']);
     $instances = $parentCourse->getInstances($constraints);
Example #6
0
<?php

//This file cannot be called directly, only included.
if (str_replace(DIRECTORY_SEPARATOR, "/", __FILE__) == $_SERVER['SCRIPT_FILENAME']) {
    exit;
}
$loadScripts[] = "includes/scorm";
if (!isset($currentUser->coreAccess['content']) || $currentUser->coreAccess['content'] == 'change') {
    $options = array(array('image' => '16x16/scorm.png', 'title' => _SCORMTREE, 'link' => basename($_SERVER['PHP_SELF']) . '?ctg=scorm', 'selected' => $_GET['scorm_review'] || $_GET['scorm_import'] || $_GET['scorm_export'] ? false : true), array('image' => '16x16/unit.png', 'title' => _SCORMREVIEW, 'link' => basename($_SERVER['PHP_SELF']) . '?ctg=scorm&scorm_review=1', 'selected' => !$_GET['scorm_review'] ? false : true), array('image' => '16x16/import.png', 'title' => _SCORMIMPORT, 'link' => basename($_SERVER['PHP_SELF']) . '?ctg=scorm&scorm_import=1', 'selected' => !$_GET['scorm_import'] ? false : true), array('image' => '16x16/export.png', 'title' => _SCORMEXPORT, 'link' => basename($_SERVER['PHP_SELF']) . '?ctg=scorm&scorm_export=1', 'selected' => !$_GET['scorm_export'] ? false : true));
} else {
    $options = array(array('image' => '16x16/scorm.png', 'title' => _SCORMTREE, 'link' => basename($_SERVER['PHP_SELF']) . '?ctg=scorm', 'selected' => $_GET['scorm_review'] || $_GET['scorm_import'] || $_GET['scorm_export'] ? false : true), array('image' => '16x16/unit.png', 'title' => _SCORMREVIEW, 'link' => basename($_SERVER['PHP_SELF']) . '?ctg=scorm&scorm_review=1', 'selected' => !$_GET['scorm_review'] ? false : true));
}
$smarty->assign("T_TABLE_OPTIONS", $options);
$currentContent = new EfrontContentTree($currentLesson);
if ($_GET['scorm_review']) {
    $iterator = new EfrontSCORMFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)));
    foreach ($iterator as $key => $value) {
        $scormContentIds[] = $key;
    }
    if (sizeof($scormContentIds)) {
        $result = eF_getTableData("scorm_data, content, users", "scorm_data.*, content.name as content_name, users.name, users.surname", "scorm_data.users_LOGIN != '' and scorm_data.content_ID IN (" . implode(",", $scormContentIds) . ") and content_ID=content.id and users.login=scorm_data.users_LOGIN");
        $result2004 = array();
        if (G_VERSIONTYPE != 'community') {
            #cpp#ifndef COMMUNITY
            if (G_VERSIONTYPE != 'standard') {
                #cpp#ifndef STANDARD
                $result2004 = eF_getTableData("scorm_data_2004, content, users", "scorm_data_2004.*, content.name as content_name, users.name, users.surname", "scorm_data_2004.users_LOGIN != '' and scorm_data_2004.content_ID IN (" . implode(",", $scormContentIds) . ") and content_ID=content.id and users.login=scorm_data_2004.users_LOGIN");
            }
            #cpp#endif
        }
        #cpp#endif
Example #7
0
 /**
  * Analyse completed test
  *
  * This function is used to analyse completed test. Scores are calculated for
  * each unit and subunit, based on the corresponding questions performance.
  * <br/>Example:
  * <code>
  * list($parentScores, $analysisCode) = $completedTest -> analyseTest();
  * </code>
  * The function returns an array with 2 separate elements: The first element is the array
  * of scores per unit, which is needed in order to display the chart. The second element
  * is the content tree, where the scores per unit are depicted.
  *
  * @return array A results array.
  * @since 3.5.2
  * @access public
  */
 public function analyseTest()
 {
     $parentScores = array();
     foreach ($this->questions as $question) {
         $questionIds[$question->question['content_ID']]['score'] += $question->score;
         $questionIds[$question->question['content_ID']]['total']++;
         $question->score > 0 ? $questionIds[$question->question['content_ID']]['correct'] += $question->score / 100 : null;
     }
     $questionsStats = EfrontStats::getQuestionsUnitStatistics($this->questions);
     //Get unit names and ids
     $content = new EfrontContentTree(key($this->getLesson()));
     if (isset($_GET['entity']) && $_GET['entity']) {
         $temp = $content->seekNode($_GET['entity']);
         $tree[0] = new EfrontUnit(array('id' => 0, 'name' => _NOUNIT, 'active' => 1, $temp['id'] => $temp));
         //Add a bogus unit to hold questions which do not belong to a unit
         $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($tree), RecursiveIteratorIterator::SELF_FIRST));
     } else {
         $tree = $content->tree;
         $tree[0] = new EfrontUnit(array('id' => 0, 'name' => _NOUNIT, 'active' => 1));
         //Add a bogus unit to hold questions which do not belong to a unit
         $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($content->tree), RecursiveIteratorIterator::SELF_FIRST));
     }
     foreach ($iterator as $key => $value) {
         if ($key != 0) {
             foreach ($content->getNodeAncestors($key) as $id => $foo) {
                 $parentScores[$foo['id']]['score'] += $questionIds[$key]['score'];
                 $parentScores[$foo['id']]['total'] += $questionIds[$key]['total'];
                 $parentScores[$foo['id']]['correct'] += $questionIds[$key]['correct'];
             }
             $parentScores[$key]['this_score'] += $questionIds[$key]['score'];
             $parentScores[$key]['this_total'] += $questionIds[$key]['total'];
             $parentScores[$key]['this_correct'] += $questionIds[$key]['correct'];
             $parentScores[$key]['name'] = $value['name'];
             // Check if this chapter is a parent one.
             if (isset($content->tree[$key])) {
                 $parentScores[$key]['top_level'] = 1;
             } else {
                 $parentScores[$key]['top_level'] = 0;
             }
         }
     }
     foreach ($parentScores as $id => $value) {
         if ($value['total']) {
             $parentScores[$id]['percentage'] = round($value['score'] / $value['total'], 2);
         }
         if ($value['this_total']) {
             $parentScores[$id]['this_percentage'] = round($value['this_score'] / $value['this_total'], 2);
         }
         if ($value['total']) {
             $options['custom'][$id] = '
                             <span style = "margin-left:20px;color:gray">' . $parentScores[$id]['percentage'] . '% [' . $value['correct'] . '/' . $value['total'] . ']</span>
                             <img src = "images/16x16/information.png" style = "vertical-align:middle" alt = "" title = "' . _THISLEVEL . ': ' . $parentScores[$id]['this_percentage'] . '% [' . $value['this_correct'] . '/' . $value['this_total'] . ']';
             if ($value['total'] - $value['this_total'] > 0) {
                 $options['custom'][$id] .= '/ ' . _BELOWLEVELS . ': ' . round(($value['score'] - $value['this_score']) / ($value['total'] - $value['this_total']), 2) . '% [' . ($value['correct'] - $value['this_correct']) . '/' . ($value['total'] - $value['this_total']) . '] ';
             }
             $options['custom'][$id] .= '">';
         } else {
             unset($parentScores[$id]);
         }
     }
     $iterator = new analyseTestFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($content->tree), RecursiveIteratorIterator::SELF_FIRST)), array_keys($parentScores));
     $options['show_hide'] = false;
     $options['noclick'] = true;
     //$options['tree_root'] = array('name' => _BACKTOTOP, 'class' => 'examples', 'onclick' => "$('analysis_frame').src = $('analysis_frame').src.replace(/selected_unit=(\d*)/, 'selected_unit='+Element.extend(this).up().id.replace(/node/, ''));");
     //$options['onclick']   = "re = new RegExp(this.up().id.replace(/node/, ''), 'g');if(treeObj.getNodeOrders().match(re).length > 1) $('analysis_frame').src = $('analysis_frame').src.replace(/selected_unit=(\d*)/, 'selected_unit='+Element.extend(this).up().id.replace(/node/, ''));";
     $options['onclick'] = "showGraph(\$('proto_chart'), 'graph_test_analysis', Element.extend(this).up().id.replace(/node/, ''));";
     return array($parentScores, $content->toHTML($iterator, false, $options));
 }
$smarty->assign("_change_", $_change_);
$loadScripts[] = 'scriptaculous/dragdrop';
$loadScripts[] = 'includes/content';
$loadScripts[] = 'includes/comments';
if (!isset($currentContent)) {
    if (!$currentLesson) {
        if ($_GET['view_unit']) {
            $unit = new EfrontUnit($_GET['view_unit']);
            $currentLesson = new EfrontLesson($unit['lessons_ID']);
        } elseif ($_GET['package_ID']) {
            $unit = new EfrontUnit($_GET['package_ID']);
            $currentLesson = new EfrontLesson($unit['lessons_ID']);
        }
        $_SESSION['s_lessons_ID'] = $currentLesson->lesson['id'];
    }
    $currentContent = new EfrontContentTree($currentLesson);
    if ($_student_) {
        $currentContent->markSeenNodes($currentUser);
    }
}
//Legal values are the array of entities that the current user may actually edit or change.
foreach (new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)) as $key => $value) {
    $legalValues[] = $key;
}
if (isset($_GET['add']) || isset($_GET['edit']) && in_array($_GET['edit'], $legalValues) && eF_checkParameter($_GET['edit'], 'id') && $_change_) {
    try {
        if ($_GET['edit']) {
            $currentUnit = $currentContent->seekNode($_GET['edit']);
            //The content tree does not hold data, so assign this unit its data
            $unitData = new EfrontUnit($_GET['edit']);
            $currentUnit['data'] = $unitData['data'];
 public function getModule()
 {
     $smarty = $this->getSmartyVar();
     $currentLesson = $this->getCurrentLesson();
     $currentUser = $this->getCurrentUser();
     try {
         $currentContent = new EfrontContentTree($_SESSION['s_lessons_ID']);
         //Initialize content
     } catch (Exception $e) {
         $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
         $message = _ERRORLOADINGCONTENT . ": " . $_SESSION['s_lessons_ID'] . ": " . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
     }
     //pr($currentUser);exit;
     $roles = EfrontUser::getRoles();
     //pr($roles);
     if ($roles[$currentUser->lessons[$_SESSION['s_lessons_ID']]] == "professor") {
         if (isset($_GET['view_list']) && eF_checkParameter($_GET['view_list'], 'id')) {
             $list = $currentContent->seekNode($_GET['view_list']);
             $questions = $list->getQuestions(true);
             $crosslists = array();
             $possibleCrosslistsIds = array();
             foreach ($questions as $key => $value) {
                 if ($value->question['type'] == 'empty_spaces') {
                     $crosslists[] = $value;
                     $possibleCrosslistsIds[] = $value->question['id'];
                 }
             }
             $questions = $crosslists;
             //pr($questions);
             foreach ($questions as $qid => $question) {
                 $questions[$qid]->question['text'] = str_replace('#', '_', strip_tags($question->question['text']));
                 //If we ommit this line, then the questions list is html formatted, images are displayed etc, which is *not* the intended behaviour
                 //$questions[$qid]->question['answer']           = unserialize($question->question['answer']);
             }
             $res = eF_getTableData("module_crossword_words", "crosslists,options", "content_ID=" . $_GET['view_list']);
             $resCrosslists = unserialize($res[0]['crosslists']);
             $smarty->assign("T_CROSSWORD_LIST_WORDS", $resCrosslists);
             $post_target = $this->moduleBaseUrl . '&view_list=' . $_GET['view_list'] . "&tab=options";
             //Create form elements
             $form = new HTML_QuickForm("list_options", "post", $post_target, "", null, true);
             $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
             $form->addElement('advcheckbox', 'active', _CROSSWORD_ACTIVE, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement("text", "max_word", _LOW, 'size = "5"');
             $form->addRule('max_word', _INVALIDFIELDDATA . ":" . _LOW, 'checkParameter', 'id');
             $form->addElement('advcheckbox', 'reveal_answer', _CROSSWORD_SHOWANSWERFIRST, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('advcheckbox', 'save_pdf', _CROSSWORD_SAVEPDF, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('submit', 'submit_options', _SAVECHANGES, 'onclick ="return optionSubmit();" class = "flatButton"');
             //The submit content button
             $options = unserialize($res[0]['options']);
             $form->setDefaults(array('active' => $options['active'], 'reveal_answer' => $options['reveal_answer'], 'save_pdf' => $options['save_pdf'], 'max_word' => $options['max_word']));
             if ($form->isSubmitted() && $form->validate()) {
                 //If the form is submitted and validated
                 $values = $form->exportValues();
                 unset($values['submit_options']);
                 $options = serialize($values);
                 if (sizeof($res) != 0) {
                     $ok = eF_updateTableData("module_crossword_words", array('options' => $options), "content_ID=" . $_GET['view_list']);
                 } else {
                     $fields = array('content_ID' => $_GET['view_list'], 'options' => $options);
                     $ok = eF_insertTableData("module_crossword_words", $fields);
                 }
                 if ($ok !== false) {
                     $message = _CROSSWORD_SUCCESSFULLY;
                     $message_type = 'success';
                 } else {
                     $message = _CROSSWORD_PROBLEMOCCURED;
                     $message_type = 'failure';
                 }
                 eF_redirect("" . $this->moduleBaseUrl . "&view_list=" . $_GET['view_list'] . "&tab=options&message=" . urlencode($message) . "&message_type=" . $message_type);
             }
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             //Create a smarty renderer
             $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
             //Set javascript error messages
             $form->setRequiredNote(_REQUIREDNOTE);
             $form->accept($renderer);
             //Assign this form to the renderer, so that corresponding template code is created
             $smarty->assign('T_CROSSWORD_OPTIONS', $renderer->toArray());
             //Assign the form to the template
             if (isset($_GET['postAjaxRequest'])) {
                 try {
                     $result = eF_getTableData("module_crossword_words", "crosslists", "content_ID=" . $_GET['view_list']);
                     //pr($result);exit;
                     $crosslistsArray = unserialize($result[0]['crosslists']);
                     if (isset($_GET['id']) && eF_checkParameter($_GET['id'], 'id')) {
                         if (!in_array($_GET['id'], array_values($crosslistsArray))) {
                             $crosslistsArray[] = $_GET['id'];
                             $crosslists = serialize($crosslistsArray);
                             if (sizeof($result) != 0) {
                                 $fields = array('crosslists' => $crosslists);
                                 eF_updateTableData("module_crossword_words", $fields, "content_ID=" . $_GET['view_list']);
                             } else {
                                 $fields = array('content_ID' => $_GET['view_list'], 'crosslists' => $crosslists);
                                 eF_insertTableData("module_crossword_words", $fields);
                             }
                         } elseif (in_array($_GET['id'], array_values($crosslistsArray))) {
                             unset($crosslistsArray[array_search($_GET['id'], $crosslistsArray)]);
                             if (!empty($crosslistsArray)) {
                                 $crosslists = serialize($crosslistsArray);
                                 $fields = array('crosslists' => $crosslists);
                                 eF_updateTableData("module_crossword_words", $fields, "content_ID=" . $_GET['view_list']);
                             } else {
                                 eF_deleteTableData("module_crossword_words", "content_ID=" . $_GET['view_list']);
                             }
                         }
                     } else {
                         if (isset($_GET['addAll'])) {
                             $crosslists = serialize($possibleCrosslistsIds);
                             if (sizeof($result) != 0) {
                                 $fields = array('crosslists' => $crosslists);
                                 eF_updateTableData("module_crossword_words", $fields, "content_ID=" . $_GET['view_list']);
                             } else {
                                 $fields = array('content_ID' => $_GET['view_list'], 'crosslists' => $crosslists);
                                 eF_insertTableData("module_crossword_words", $fields);
                             }
                         } else {
                             if (isset($_GET['removeAll'])) {
                                 $fields = array('crosslists' => "");
                                 eF_updateTableData("module_crossword_words", $fields, "content_ID=" . $_GET['view_list']);
                             }
                         }
                     }
                 } catch (Exception $e) {
                     header("HTTP/1.0 500 ");
                     echo $e->getMessage() . ' (' . $e->getCode() . ')';
                 }
                 exit;
             }
             $smarty->assign("T_CROSSWORD_CROSSLISTS", $crosslists);
             $smarty->assign("T_CROSSWORD_CROSSLISTS_SIZE", sizeof($crosslists));
         } else {
             $listsArray = array();
             $iterator = new EfrontContentFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($currentContent->tree, RecursiveIteratorIterator::SELF_FIRST)));
             foreach ($iterator as $key => $value) {
                 $questions = $value->getQuestions(true);
                 $crosslists = array();
                 foreach ($questions as $key2 => $value2) {
                     if ($value2->question['type'] == 'empty_spaces') {
                         $crosslists[] = $value2;
                     }
                 }
                 if (sizeof($crosslists) > 0) {
                     $listsArray[$value['id']] = array('id' => $value['id'], 'name' => $value['name'], 'questions' => sizeof($crosslists));
                 }
             }
             if (!empty($listsArray)) {
                 $str = implode(",", array_keys($listsArray));
                 $lists = eF_getTableDataFlat("module_crossword_words", "*", "content_ID IN (" . $str . ")");
                 $listsTemp = array_combine(array_values($lists['content_ID']), array_values($lists['options']));
                 $listsTemp2 = array_combine(array_values($lists['content_ID']), array_values($lists['crosslists']));
                 foreach ($listsArray as $key => $value) {
                     $listsArray[$value['id']]['options'] = unserialize($listsTemp[$key]);
                     $crosslistsTemp = unserialize($listsTemp2[$key]);
                     $listsArray[$value['id']]['num_crosslists'] = empty($crosslistsTemp) ? 0 : sizeof($crosslistsTemp);
                 }
             }
             $smarty->assign("T_CROSSWORD_WORDS", $listsArray);
         }
     } elseif ($roles[$currentUser->lessons[$_SESSION['s_lessons_ID']]] == "student") {
         if (isset($_GET['restart_list']) && eF_checkParameter($_GET['restart_list'], 'id')) {
             eF_deleteTableData("module_crossword_users", "users_LOGIN='******'s_login'] . "' AND content_ID=" . $_GET['restart_list']);
         }
         if (isset($_GET['restart_lists'])) {
             eF_deleteTableData("module_crossword_users", "users_LOGIN='******'s_login'] . "'");
         }
         if ($_GET['answer'] == "true") {
             $resUserCard = eF_getTableData("module_crossword_users", "*", "crosslists_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             if (sizeof($resUserCard) == 0) {
                 $fields = array('users_LOGIN' => $_SESSION['s_login'], 'content_ID' => $_GET['view_list'], 'crosslists_ID' => $_GET['view_card'], 'success' => '1');
                 eF_insertTableData("module_crossword_users", $fields);
             } else {
                 $success = $resUserCard[0]['success'] + 1;
                 eF_updateTableData("module_crossword_users", array('success' => $success), "crosslists_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             }
         } elseif ($_GET['answer'] == "false") {
             $resUserCard = eF_getTableData("module_crossword_users", "*", "crosslists_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             $currentListTemp = eF_getTableData("module_crossword_words", "options", "content_ID=" . $_GET['view_list']);
             $listTemp = unserialize($currentListTemp[0]['options']);
             if ($listTemp['wrong'] == 1 && sizeof($resUserCard) != 0 && $resUserCard[0]['success'] != 0) {
                 $success = $resUserCard[0]['success'] - 1;
                 eF_updateTableData("module_crossword_users", array('success' => $success), "crosslists_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             }
         }
         $listsArray = array();
         $iterator = new EfrontContentFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($currentContent->tree, RecursiveIteratorIterator::SELF_FIRST)));
         foreach ($iterator as $key => $value) {
             $listsArray[$value['id']] = array('id' => $value['id'], 'name' => $value['name']);
         }
         if (empty($listsArray)) {
             $smarty->assign("T_CROSSWORD_WORDSNAMES", $listsArray);
             return true;
         }
         $str = implode(",", array_keys($listsArray));
         $lists = eF_getTableData("module_crossword_words", "*", "content_ID IN (" . $str . ")");
         $mastery = eF_getTableDataFlat("module_crossword_users", "*", "content_ID IN (" . $str . ")");
         $masteryArray = array_combine(array_values($mastery['crosslists_ID']), array_values($mastery['success']));
         $questionsDiff = eF_getTableDataFlat("questions", "*", "content_ID IN (" . $str . ")");
         $questionsDiffArray = array_combine(array_values($questionsDiff['id']), array_values($questionsDiff['difficulty']));
         $validLists = array();
         foreach ($lists as $key => $value) {
             $opt = unserialize($value['options']);
             $crosslists = unserialize($value['crosslists']);
             if ($opt['active'] == 1 && !empty($crosslists)) {
                 $value['number_crosslists'] = empty($crosslists) ? 0 : sizeof($crosslists);
                 $validLists[$value['content_ID']] = $value;
                 $validLists[$value['content_ID']]['options'] = $opt;
                 $finishedCrosslists = 0;
                 foreach ($crosslists as $index => $item) {
                     if ($masteryArray[$item] == $opt[$questionsDiffArray[$item]]) {
                         $finishedCrosslists++;
                     }
                 }
                 $conid = $validLists[$value['content_ID']]['content_ID'];
                 $validLists[$value['content_ID']]['non_finished'] = $value['number_crosslists'] - $finishedCrosslists;
                 $validLists[$value['content_ID']]['mastery'] = (double) $finishedCrosslists / sizeof($crosslists) * 100;
                 $respoints = eF_getTableDataFlat("module_crossword_users", "*", "content_ID = '{$conid}' and users_LOGIN='******'s_login'] . "'");
                 $validLists[$value['content_ID']]['points'] = round($respoints['points'][0] / $respoints['totallength'][0] * 100);
                 $validLists[$value['content_ID']]['crosstime'] = $respoints['wordtime'][0];
             }
         }
         //print_r($validLists);
         $smarty->assign("T_CROSSWORD_WORDS", $validLists);
         $smarty->assign("T_CROSSWORD_WORDSNAMES", $listsArray);
         if (isset($_GET['view_list']) && !isset($_GET['pdf'])) {
             $resunit = eF_getTableData("content", "name", "id=" . $_GET['view_list']);
             $smarty->assign("T_CROSSWORD_UNITNAME", $resunit[0]['name']);
             $_SESSION['contentid'] = $_GET['view_list'];
             if (isset($_POST) && !empty($_POST['crosstime'])) {
                 $userlist = eF_getTableData("module_crossword_users", "*", "users_LOGIN='******'s_login'] . "' and content_ID=" . $_GET['view_list'] . "");
                 if (count($userlist) == 0) {
                     $fields = array('users_LOGIN' => $_SESSION['s_login'], 'content_ID' => $_GET['view_list'], 'points' => $_POST['points'], 'totallength' => $_SESSION['WORDLEN'], 'wordtime' => $_POST['crosstime']);
                     eF_insertTableData("module_crossword_users", $fields);
                 } else {
                     $fields = array('points' => $_POST['points'], 'totallength' => $_SESSION['WORDLEN'], 'wordtime' => $_POST['crosstime']);
                     eF_updateTableData("module_crossword_users", $fields, "content_ID=" . $_GET['view_list'] . " and users_LOGIN='******'s_login'] . "'");
                 }
                 $message_type = 'success';
                 $message = _CROSSWORD_GAME_SUCCESSFULLY;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=" . $message_type);
             }
             $contentid = $_GET['view_list'];
             $res = eF_getTableData("module_crossword_words", "crosslists,options", "content_ID=" . $_GET['view_list']);
             $reswords = unserialize($res[0]['crosslists']);
             $maxwords = unserialize($res[0]['options']);
             $maxwords1 = $maxwords['max_word'];
             $smarty->assign("T_CROSSWORD_REVEALANSWER", $maxwords['reveal_answer']);
             $smarty->assign("T_CROSSWORD_MAXWORD", $maxwords1 + 1);
             $_SESSION['CROSSWORD_MAXWORD'] = $maxwords1;
             require_once 'init.php';
             $rowquesans = "";
             foreach ($reswords as $rowques) {
                 $rowquesans .= $rowques . ",";
             }
             $quesids = mb_substr($rowquesans, 0, -1);
             $quesans = eF_getTableData("questions", "text,answer", "id IN({$quesids}) order by rand() limit {$maxwords1}");
             $value = array();
             foreach ($quesans as $row) {
                 $answer = unserialize($row['answer']);
                 $answer1 = explode("|", $answer['0']);
                 $value[] = array('ANSWER' => $answer1['0'], 'QUESTION' => $row['text']);
             }
             if (!empty($value)) {
                 //pr($value);exit;
                 $success = $pc->generateFromWords($value);
                 if (!$success) {
                     $message_type = 'failure';
                     $message = _CROSSWORD_UNABLEGENERATECROSSWORD;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                 } else {
                     $words = $pc->getWords();
                     $wordlen = "";
                     foreach ($words as $rowwords) {
                         $wordlen = $wordlen + $rowwords['wordlength'];
                     }
                     $_SESSION['WORDLEN'] = $wordlen;
                     $smarty->assign("T_CROSSWORD_LENGTH", $_SESSION['WORDLEN']);
                     //vd($words);
                     //because of #1599
                     foreach ($words as $key => $word) {
                         $words[$key]['question'] = str_replace(array("\r\n", "\n"), '<br/>', $word['question']);
                     }
                     //vd($words);
                     $smarty->assign("T_CROSSWORD_ANSWERS", $words);
                 }
             }
             $post_target = $this->moduleBaseUrl . "&view_list=" . $_GET['view_list'] . "";
             $form = new HTML_QuickForm("crossword_game", "post", $post_target, "", null, true);
             $form->addElement('submit', 'submit_crossword', 'SUBMIT', 'class = "flatButton"');
             //The submit content button
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             //Create a smarty renderer
             $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
             //Set javascript error messages
             $form->setRequiredNote(_REQUIREDNOTE);
             $form->accept($renderer);
             //Assign this form to the renderer, so that corresponding template code is created
             $smarty->assign('T_CROSSWORD_SUBMIT', $renderer->toArray());
             //Assign the form to the template
             $message = "";
             //$message_type = 'success';
             // eF_redirect("".$this -> moduleBaseUrl."&popup=1&finish=1&message=".$message."&message_type=".$message_type);
         } else {
             if (isset($_GET['view_list']) && isset($_GET['pdf']) && $_GET['pdf'] == 'cross') {
                 $resunit = eF_getTableData("content", "name,lessons_ID", "id=" . $_GET['view_list']);
                 $reslesson = eF_getTableData("lessons", "name", "id=" . $resunit[0]['lessons_ID']);
                 $res = eF_getTableData("module_crossword_words", "crosslists,options", "content_ID=" . $_GET['view_list']);
                 $reswords = unserialize($res[0]['crosslists']);
                 $maxwords = unserialize($res[0]['options']);
                 $maxwords1 = $maxwords['max_word'];
                 $_SESSION['CROSSWORD_MAXWORD'] = $maxwords1;
                 require_once 'init.php';
                 $rowquesans = "";
                 foreach ($reswords as $rowques) {
                     $rowquesans .= $rowques . ",";
                 }
                 $quesids = mb_substr($rowquesans, 0, -1);
                 $quesans = eF_getTableData("questions", "text,answer", "id IN({$quesids}) order by rand() limit {$maxwords1}");
                 $value = array();
                 foreach ($quesans as $row) {
                     $answer = unserialize($row['answer']);
                     $answer1 = explode("|", $answer['0']);
                     $value[] = array('ANSWER' => $answer1['0'], 'QUESTION' => $row['text']);
                 }
                 $success = $pc->generateFromWords($value);
                 if (!$success) {
                     $message_type = 'failure';
                     $message = _CROSSWORD_UNABLEGENERATECROSSWORD;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=" . $message_type);
                 } else {
                     $currentlesson = $reslesson[0]['name'];
                     $words = $pc->getWords();
                     $answor = array();
                     $html1 = array();
                     $html2 = array();
                     $html1[] = $currentlesson;
                     $html1[] .= $resunit[0]['name'];
                     $html1[] .= _CROSSWORD_ACROSS;
                     $html2[] = _CROSSWORD_DOWN;
                     $k = 1;
                     //pr($words);
                     foreach ($words as $row) {
                         if ($row['axis'] == 1) {
                             $html1[] .= $k . '. ' . $row['question'];
                         } else {
                             $html2[] .= $k . '. ' . $row['question'];
                         }
                         $k++;
                     }
                     //pr($html1);
                     //pr($html2);
                     //exit;
                     $answor[] = array_merge($html1, $html2);
                     //pr($answor); exit;
                     $dd = $pc->getHTML($answor);
                     exit;
                 }
             }
         }
     }
     return true;
 }
 public function getModule()
 {
     $smarty = $this->getSmartyVar();
     // Always show the preview of the data
     if ($_POST['preview'] || $_POST['submit']) {
         if ($_POST['questions_format'] == "gift") {
             $questions = $this->scanGIFT($_POST['imported_data']);
         } else {
             $questions = $this->scanAIKEN(str_replace('\\"', '"', str_replace("\\'", "'", $_POST['imported_data'])));
         }
         if (sizeof($questions)) {
             $smarty->assign("T_PREVIEW_DIV", $this->createPreviewHTML($questions));
         }
     }
     // Submit the data the data
     if ($_POST['submit']) {
         if ($_POST['select_unit'] == -1 || $_POST['select_unit'] == -2) {
             $content_ID = 0;
         } else {
             $content_ID = $_POST['select_unit'];
         }
         $currentLesson = $this->getCurrentLesson();
         $lessons_ID = $currentLesson->lesson['id'];
         $count = 0;
         foreach ($questions as $key => $question) {
             if ($question['type'] != "same" && $question['type'] != "error" && $question['type'] != "no_answer_error") {
                 $question['content_ID'] = $content_ID;
                 $question['lessons_ID'] = $lessons_ID;
                 $question['difficulty'] = "medium";
                 if (sizeof($question['options'])) {
                     $question['options'] = serialize($question['options']);
                     //$question['options'] = str_replace("'", "&#39;", $question['options']);
                     //$question['options'] = str_replace("\r", "", $question['options']);
                 }
                 if (sizeof($question['answer'])) {
                     // Different accounting for answers of multiple many type
                     if ($question['type'] == "multiple_many") {
                         $answers = array();
                         foreach ($question['answer'] as $answer) {
                             $answers[$answer] = "1";
                         }
                         $question['answer'] = $answers;
                     }
                     $question['answer'] = serialize($question['answer']);
                     //$question['answer'] = str_replace("'", "&#39;", $question['answer']);
                     //$question['answer'] = str_replace("\r", "", $question['answer']);
                 }
                 //$question['text'] = str_replace("'", "&#39;", $question['text']);
                 if (isset($question['explanation'])) {
                     //$question['explanation'] = str_replace("'", "&#39;", $question['explanation']);
                     //$question['explanation'] = str_replace("\r", "", $question['explanation']);
                 }
                 if (Question::createQuestion($question)) {
                     $count++;
                 }
             }
         }
         if ($count) {
             $this->setMessageVar($count . " " . _GIFTAIKEN_QUESTIONSIMPORTEDSUCCESSFULLY, "success");
         } else {
             $this->setMessageVar(_GIFTAIKEN_NOQUESTIONCOULDBEIMPORTED, "failure");
         }
     }
     $pos = strpos($_SERVER['REQUEST_URI'], "&message");
     if ($pos) {
         $postUrl = substr($_SERVER['REQUEST_URI'], 0, $pos);
     } else {
         $postUrl = $_SERVER['REQUEST_URI'];
     }
     $importForm = new HTML_QuickForm("import_users_form", "post", $postUrl, "", null, true);
     $importForm->registerRule('checkParameter', 'callback', 'eF_checkParameter');
     //Register this rule for checking user input with our function, eF_checkParameter
     $importForm->addElement('radio', 'questions_format', _GIFTAIKEN_GIFT, null, 'gift', 'id="gift_selection"');
     $importForm->addElement('radio', 'questions_format', _GIFTAIKEN_AIKEN, null, 'aiken', 'id="aiken_selection"');
     $currentLesson = $this->getCurrentLesson();
     $currentContent = new EfrontContentTree($currentLesson->lesson['id']);
     $smarty->assign("T_UNITS", $currentContent->toHTMLSelectOptions());
     $importForm->addElement('textarea', 'imported_data', _GIFTAIKEN_QUESTIONDATATOIMPORT, 'class = "inputProjectTextarea" id="imported_data"');
     $importForm->addElement('submit', 'preview', _PREVIEW, 'class=flatButton onclick="$(\'import_users_form\').action += \'&preview=1\'"');
     $importForm->addElement('submit', 'submit', _SUBMIT, 'class=flatButton');
     $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
     $importForm->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
     $importForm->setRequiredNote(_REQUIREDNOTE);
     $importForm->accept($renderer);
     $smarty->assign('T_GIFTAIKENQUESTIONS_FORM', $renderer->toArray());
     return true;
 }
                 $controlPanelOptions[] = array('text' => _PAYMENTS, 'image' => "32x32/shopping_basket.png", 'href' => "administrator.php?ctg=payments");
             }
         }
         if (EfrontUser::isOptionVisible('version_key')) {
             $controlPanelOptions[] = array('text' => _REGISTRATIONUPDATE, 'image' => "32x32/keys.png", 'href' => "administrator.php?ctg=versionkey");
         }
         //If the edition is not register, simply display the Registration icon
         if (!$GLOBALS['configuration']['version_key']) {
             $controlPanelOptions = array(array('text' => _REGISTRATIONUPDATE, 'image' => "32x32/keys.png", 'href' => "administrator.php?ctg=versionkey"), $controlPanelOptions['backup']);
             //$smarty -> assign ("T_UNREGISTERED", 1);
         }
     }
     #cpp#endif
 } else {
     if ($_professor_) {
         $currentContent = new EfrontContentTree($currentLesson);
         if ($currentUser->coreAccess['content'] != 'hidden') {
             $currentLesson->options['lesson_info'] ? $controlPanelOptions[0] = array('text' => _LESSONINFORMATION, 'image' => "32x32/information.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=lesson_information") : null;
             if (EfrontUser::isOptionVisible('tests')) {
                 $firstNodeIterator = new EfrontVisitableFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)));
             } else {
                 $firstNodeIterator = new EfrontNoTestsFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)));
             }
             if ($currentContent && $currentContent->getFirstNode($firstNodeIterator) && !empty($firstNodeIterator)) {
                 $controlPanelOptions[1] = array('text' => _CONTENTMANAGEMENT, 'image' => "32x32/content.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=content&view_unit=" . $currentContent->getFirstNode($firstNodeIterator)->offsetGet('id'));
             } else {
                 $controlPanelOptions[1] = array('text' => _CONTENTMANAGEMENT, 'image' => "32x32/content.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=content");
             }
             if (!isset($currentUser->coreAccess['content']) || $currentUser->coreAccess['content'] == 'change') {
                 $controlPanelOptions[5] = array('text' => _CONTENTTREEMANAGEMENT, 'image' => "32x32/content_reorder.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=order");
                 $controlPanelOptions[7] = array('text' => _COPYFROMANOTHERLESSON, 'image' => "32x32/lesson_copy.png", 'href' => basename($_SERVER['PHP_SELF']) . "?ctg=copy");
 public function getModule()
 {
     $smarty = $this->getSmartyVar();
     $currentLesson = $this->getCurrentLesson();
     $currentUser = $this->getCurrentUser();
     try {
         $currentContent = new EfrontContentTree($_SESSION['s_lessons_ID']);
         //Initialize content
     } catch (Exception $e) {
         $smarty->assign("T_EXCEPTION_TRACE", $e->getTraceAsString());
         $message = _ERRORLOADINGCONTENT . ": " . $_SESSION['s_lessons_ID'] . ": " . $e->getMessage() . ' (' . $e->getCode() . ') &nbsp;<a href = "javascript:void(0)" onclick = "eF_js_showDivPopup(event, \'' . _ERRORDETAILS . '\', 2, \'error_details\')">' . _MOREINFO . '</a>';
     }
     //pr($currentUser);exit;
     $roles = EfrontUser::getRoles();
     //pr($roles);
     if ($roles[$currentUser->lessons[$_SESSION['s_lessons_ID']]] == "professor") {
         if (isset($_GET['view_deck']) && eF_checkParameter($_GET['view_deck'], 'id')) {
             $deck = $currentContent->seekNode($_GET['view_deck']);
             $questions = $deck->getQuestions(true);
             $cards = array();
             $possibleCardsIds = array();
             foreach ($questions as $key => $value) {
                 if ($value->question['type'] == 'empty_spaces') {
                     $cards[] = $value;
                     $possibleCardsIds[] = $value->question['id'];
                 }
             }
             $questions = $cards;
             //pr($questions);
             foreach ($questions as $qid => $question) {
                 $questions[$qid]->question['text'] = strip_tags($question->question['text']);
                 //If we ommit this line, then the questions list is html formatted, images are displayed etc, which is *not* the intended behaviour
                 //$questions[$qid]->question['answer']           = unserialize($question->question['answer']);
             }
             $res = eF_getTableData("module_flashcards_decks", "cards,options", "content_ID=" . $_GET['view_deck']);
             $resCards = unserialize($res[0]['cards']);
             $smarty->assign("T_FLASHCARDS_DECK_CARDS", $resCards);
             $post_target = $this->moduleBaseUrl . '&view_deck=' . $_GET['view_deck'] . "&tab=options";
             //Create form elements
             $form = new HTML_QuickForm("deck_options", "post", $post_target, "", null, true);
             $form->registerRule('checkParameter', 'callback', 'eF_checkParameter');
             $form->addElement('advcheckbox', 'active', _FLASHCARDS_ACTIVE, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement("text", "low", _LOW, 'size = "5"');
             $form->addElement("text", "medium", _MEDIUM, 'size = "5"');
             $form->addElement("text", "hard", _HIGH, 'size = "5"');
             $form->addElement("text", "very_hard", _VERYHIGH, 'size = "5"');
             $form->addRule('low', _INVALIDFIELDDATA . ":" . _LOW, 'checkParameter', 'id');
             $form->addRule('medium', _INVALIDFIELDDATA . ":" . _MEDIUM, 'checkParameter', 'id');
             $form->addRule('hard', _INVALIDFIELDDATA . ":" . _HIGH, 'checkParameter', 'id');
             $form->addRule('very_hard', _INVALIDFIELDDATA . ":" . _VERYHIGH, 'checkParameter', 'id');
             $form->addElement('advcheckbox', 'answer_first', _FLASHCARDS_SHOWANSWERFIRST, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('advcheckbox', 'shuffle', _FLASHCARDS_SHUFFLECARDS, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('advcheckbox', 'display_mastery', _FLASHCARDS_DISPLAYMASTERY, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('advcheckbox', 'wrong', _FLASHCARDS_WRONGREDUCES, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('advcheckbox', 'show_count', _FLASHCARDS_SHOWSUCCESSCOUNT, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('advcheckbox', 'show_explanation', _FLASHCARDS_SHOWEXPLANATION, null, 'class = "inputCheckbox"', array(0, 1));
             $form->addElement('submit', 'submit_options', _SAVECHANGES, 'class = "flatButton"');
             //The submit content button
             $options = unserialize($res[0]['options']);
             $form->setDefaults(array('active' => $options['active'], 'answer_first' => $options['answer_first'], 'shuffle' => $options['shuffle'], 'display_mastery' => $options['display_mastery'], 'wrong' => $options['wrong'], 'show_count' => $options['show_count'], 'show_explanation' => $options['show_explanation'], 'low' => $options['low'] == "" ? 1 : $options['low'], 'medium' => $options['medium'] == "" ? 2 : $options['medium'], 'hard' => $options['hard'] == "" ? 4 : $options['hard'], 'very_hard' => $options['very_hard'] == "" ? 6 : $options['very_hard']));
             if ($form->isSubmitted() && $form->validate()) {
                 //If the form is submitted and validated
                 $values = $form->exportValues();
                 unset($values['submit_options']);
                 $options = serialize($values);
                 if (sizeof($res) != 0) {
                     $ok = eF_updateTableData("module_flashcards_decks", array('options' => $options), "content_ID=" . $_GET['view_deck']);
                 } else {
                     $fields = array('content_ID' => $_GET['view_deck'], 'options' => $options);
                     $ok = eF_insertTableData("module_flashcards_decks", $fields);
                 }
                 if ($ok !== false) {
                     $message = _FLASHCARDS_SUCCESSFULLY;
                     $message_type = 'success';
                 } else {
                     $message = _FLASHCARDS_PROBLEMOCCURED;
                     $message_type = 'failure';
                 }
                 eF_redirect("" . $this->moduleBaseUrl . "&view_deck=" . $_GET['view_deck'] . "&tab=options&message=" . $message . "&message_type=" . $message_type);
             }
             $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
             //Create a smarty renderer
             $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
             //Set javascript error messages
             $form->setRequiredNote(_REQUIREDNOTE);
             $form->accept($renderer);
             //Assign this form to the renderer, so that corresponding template code is created
             $smarty->assign('T_FLASHCARDS_OPTIONS', $renderer->toArray());
             //Assign the form to the template
             if (isset($_GET['postAjaxRequest'])) {
                 try {
                     $result = eF_getTableData("module_flashcards_decks", "cards", "content_ID=" . $_GET['view_deck']);
                     //pr($result);exit;
                     $cardsArray = unserialize($result[0]['cards']);
                     if (isset($_GET['id']) && eF_checkParameter($_GET['id'], 'id')) {
                         if (!in_array($_GET['id'], array_values($cardsArray))) {
                             $cardsArray[] = $_GET['id'];
                             $cards = serialize($cardsArray);
                             if (sizeof($result) != 0) {
                                 $fields = array('cards' => $cards);
                                 eF_updateTableData("module_flashcards_decks", $fields, "content_ID=" . $_GET['view_deck']);
                             } else {
                                 $fields = array('content_ID' => $_GET['view_deck'], 'cards' => $cards);
                                 eF_insertTableData("module_flashcards_decks", $fields);
                             }
                         } elseif (in_array($_GET['id'], array_values($cardsArray))) {
                             unset($cardsArray[array_search($_GET['id'], $cardsArray)]);
                             if (!empty($cardsArray)) {
                                 $cards = serialize($cardsArray);
                                 $fields = array('cards' => $cards);
                                 eF_updateTableData("module_flashcards_decks", $fields, "content_ID=" . $_GET['view_deck']);
                             } else {
                                 eF_deleteTableData("module_flashcards_decks", "content_ID=" . $_GET['view_deck']);
                             }
                         }
                     } else {
                         if (isset($_GET['addAll'])) {
                             $cards = serialize($possibleCardsIds);
                             if (sizeof($result) != 0) {
                                 $fields = array('cards' => $cards);
                                 eF_updateTableData("module_flashcards_decks", $fields, "content_ID=" . $_GET['view_deck']);
                             } else {
                                 $fields = array('content_ID' => $_GET['view_deck'], 'cards' => $cards);
                                 eF_insertTableData("module_flashcards_decks", $fields);
                             }
                         } else {
                             if (isset($_GET['removeAll'])) {
                                 $fields = array('cards' => "");
                                 eF_updateTableData("module_flashcards_decks", $fields, "content_ID=" . $_GET['view_deck']);
                             }
                         }
                     }
                 } catch (Exception $e) {
                     header("HTTP/1.0 500 ");
                     echo $e->getMessage() . ' (' . $e->getCode() . ')';
                 }
                 exit;
             }
             $smarty->assign("T_FLASHCARDS_CARDS", $cards);
             $smarty->assign("T_FLASHCARDS_CARDS_SIZE", sizeof($cards));
         } else {
             $decksArray = array();
             $iterator = new EfrontContentFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($currentContent->tree, RecursiveIteratorIterator::SELF_FIRST)));
             foreach ($iterator as $key => $value) {
                 $questions = $value->getQuestions(true);
                 $cards = array();
                 foreach ($questions as $key2 => $value2) {
                     if ($value2->question['type'] == 'empty_spaces') {
                         $cards[] = $value2;
                     }
                 }
                 if (sizeof($cards) > 0) {
                     $decksArray[$value['id']] = array('id' => $value['id'], 'name' => $value['name'], 'questions' => sizeof($cards));
                 }
             }
             if (!empty($decksArray)) {
                 $str = implode(",", array_keys($decksArray));
                 $decks = eF_getTableDataFlat("module_flashcards_decks", "*", "content_ID IN (" . $str . ")");
                 $decksTemp = array_combine(array_values($decks['content_ID']), array_values($decks['options']));
                 $decksTemp2 = array_combine(array_values($decks['content_ID']), array_values($decks['cards']));
                 foreach ($decksArray as $key => $value) {
                     $decksArray[$value['id']]['options'] = unserialize($decksTemp[$key]);
                     $cardsTemp = unserialize($decksTemp2[$key]);
                     $decksArray[$value['id']]['num_cards'] = empty($cardsTemp) ? 0 : sizeof($cardsTemp);
                 }
             }
             //pr($decksArray);
             $smarty->assign("T_FLASHCARDS_DECKS", $decksArray);
         }
     } elseif ($roles[$currentUser->lessons[$_SESSION['s_lessons_ID']]] == "student") {
         if (isset($_GET['restart_deck']) && eF_checkParameter($_GET['restart_deck'], 'id')) {
             eF_deleteTableData("module_flashcards_users_to_cards", "users_LOGIN='******'s_login'] . "' AND content_ID=" . $_GET['restart_deck']);
         }
         if (isset($_GET['restart_decks'])) {
             eF_deleteTableData("module_flashcards_users_to_cards", "users_LOGIN='******'s_login'] . "'");
         }
         if ($_GET['answer'] == "true") {
             $resUserCard = eF_getTableData("module_flashcards_users_to_cards", "*", "cards_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             if (sizeof($resUserCard) == 0) {
                 $fields = array('users_LOGIN' => $_SESSION['s_login'], 'content_ID' => $_GET['view_deck'], 'cards_ID' => $_GET['view_card'], 'success' => '1');
                 eF_insertTableData("module_flashcards_users_to_cards", $fields);
             } else {
                 $success = $resUserCard[0]['success'] + 1;
                 eF_updateTableData("module_flashcards_users_to_cards", array('success' => $success), "cards_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             }
         } elseif ($_GET['answer'] == "false") {
             $resUserCard = eF_getTableData("module_flashcards_users_to_cards", "*", "cards_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             $currentDeckTemp = eF_getTableData("module_flashcards_decks", "options", "content_ID=" . $_GET['view_deck']);
             $deckTemp = unserialize($currentDeckTemp[0]['options']);
             if ($deckTemp['wrong'] == 1 && sizeof($resUserCard) != 0 && $resUserCard[0]['success'] != 0) {
                 $success = $resUserCard[0]['success'] - 1;
                 eF_updateTableData("module_flashcards_users_to_cards", array('success' => $success), "cards_ID=" . $_GET['view_card'] . " and users_LOGIN='******'s_login'] . "'");
             }
         }
         $decksArray = array();
         $iterator = new EfrontContentFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator($currentContent->tree, RecursiveIteratorIterator::SELF_FIRST)));
         foreach ($iterator as $key => $value) {
             $decksArray[$value['id']] = array('id' => $value['id'], 'name' => $value['name']);
         }
         if (empty($decksArray)) {
             $smarty->assign("T_FLASHCARDS_DECKSNAMES", $decksArray);
             return true;
         }
         $str = implode(",", array_keys($decksArray));
         $decks = eF_getTableData("module_flashcards_decks", "*", "content_ID IN (" . $str . ")");
         $mastery = eF_getTableDataFlat("module_flashcards_users_to_cards", "*", "content_ID IN (" . $str . ") and users_LOGIN='******'s_login'] . "'");
         $masteryArray = array_combine(array_values($mastery['cards_ID']), array_values($mastery['success']));
         $questionsDiff = eF_getTableDataFlat("questions", "*", "content_ID IN (" . $str . ")");
         $questionsDiffArray = array_combine(array_values($questionsDiff['id']), array_values($questionsDiff['difficulty']));
         $validDecks = array();
         foreach ($decks as $key => $value) {
             $opt = unserialize($value['options']);
             $cards = unserialize($value['cards']);
             if ($opt['active'] == 1 && !empty($cards)) {
                 $value['number_cards'] = empty($cards) ? 0 : sizeof($cards);
                 $validDecks[$value['content_ID']] = $value;
                 $validDecks[$value['content_ID']]['cards'] = $cards;
                 $validDecks[$value['content_ID']]['options'] = $opt;
                 $finishedCards = 0;
                 foreach ($cards as $index => $item) {
                     if ($masteryArray[$item] == $opt[$questionsDiffArray[$item]]) {
                         $finishedCards++;
                     }
                 }
                 $validDecks[$value['content_ID']]['non_finished'] = $value['number_cards'] - $finishedCards;
                 $validDecks[$value['content_ID']]['mastery'] = (double) $finishedCards / sizeof($cards) * 100;
             }
         }
         //pr($masteryArray);
         //pr($validDecks);
         //pr($decksArray);
         $smarty->assign("T_FLASHCARDS_DECKS", $validDecks);
         $smarty->assign("T_FLASHCARDS_DECKSNAMES", $decksArray);
         if (isset($_GET['view_deck'])) {
             $currentDeck = $validDecks[$_GET['view_deck']];
             $resUserSuccess = eF_getTableDataFlat("module_flashcards_users_to_cards", "*", "content_ID=" . $_GET['view_deck'] . " and users_LOGIN='******'s_login'] . "'");
             $successArray = array_combine(array_values($resUserSuccess['cards_ID']), array_values($resUserSuccess['success']));
             //pr($successArray);
             foreach ($currentDeck['cards'] as $key => $value) {
                 $questionTemp = new EmptySpacesQuestion($value);
                 $limit = $currentDeck['options'][$questionTemp->question['difficulty']];
                 if ($successArray[$value] == $limit && $value != $_GET['view_card']) {
                     unset($currentDeck['cards'][$key]);
                 }
             }
             $currentDeck['cards'] = array_values($currentDeck['cards']);
             if ($currentDeck['options']['shuffle'] == 1) {
                 shuffle($currentDeck['cards']);
             }
             if (!empty($currentDeck['cards'])) {
                 if (isset($_GET['view_card'])) {
                     while (current($currentDeck['cards']) != $_GET['view_card'] & next($currentDeck['cards']) !== false) {
                     }
                     if (current($currentDeck['cards']) === false) {
                         reset($currentDeck['cards']);
                     }
                     $_GET['view_card'] = current($currentDeck['cards']);
                 } else {
                     $_GET['view_card'] = $currentDeck['cards'][0];
                 }
                 //echo $_GET['view_card'];
                 $question = new EmptySpacesQuestion($_GET['view_card']);
                 $limit = $currentDeck['options'][$question->question['difficulty']];
                 if ($successArray[$_GET['view_card']] == $limit) {
                     $message = _FLASHCARDS_SUCCESSFULLYCOMPLETEDDECK;
                     $message_type = 'success';
                     eF_redirect($this->moduleBaseUrl . "&reset_popup=1&message=" . urlencode($message) . "&message_type=" . $message_type, true, 'parent');
                 } else {
                     //$form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
                     $form = new HTML_QuickForm();
                     $question->toHTMLQuickForm($form);
                     foreach ($question->answer as $key => $value) {
                         $form->setDefaults(array("question[" . $question->question['id'] . "][{$key}]" => "________"));
                     }
                     $form->freeze();
                     $smarty->assign("T_FLASHCARDS_CURRENTCARD_PREVIEW", $question->toHTML($form));
                     //$smarty -> assign("T_FLASHCARDS_CURRENTCARD_PREVIEW_ANSWERED", $question -> toHTMLSolved(new HTML_QuickForm(), true, false, false));
                     $smarty->assign("T_FLASHCARDS_CURRENTCARD_PREVIEW_ANSWERED", implode("<br/>", $question->answer));
                 }
             } else {
                 $message = _FLASHCARDS_SUCCESSFULLYCOMPLETEDDECK;
                 //$message_type = 'success';
                 eF_redirect("" . $this->moduleBaseUrl . "&popup=1&finish=1&message=" . $message . "&message_type=" . $message_type);
             }
             //pr($question);
             //pr($currentDeck);
             $smarty->assign("T_FLASHCARDS_CURRENTDECK", $currentDeck);
             $smarty->assign("T_FLASHCARDS_CURRENTCARD", $question);
             //pr($currentDeck);
             $smarty->assign("T_FLASHCARDS_SUCCESSARRAY", $successArray);
             $smarty->assign("T_FLASHCARDS_LESSONNAME", $currentLesson->lesson['name']);
         }
     }
     return true;
 }
Example #13
0
                }
            }
        }
        $smarty->assign('T_ALL_USERS', $testUsers);
        $smarty->display($_SESSION['s_type'] . '.tpl');
        exit;
    }
}
if (isset($_GET['ajax']) && $_GET['ajax'] == 'questionsTable') {
    // If no lesson then define the current lesson name => _SKILLGAPTESTS (used for correct filtering)
    $contentTrees = array();
    $difficultiesToWeights = array("low" => 1, "medium" => 2, "high" => 3, "very_high" => 4);
    foreach ($questions as $qid => $question) {
        if ($question['lessons_ID']) {
            if (!isset($contentTrees[$question['lessons_ID']])) {
                $temp = new EfrontContentTree($question['lessons_ID']);
                $contentTrees[$question['lessons_ID']] = $temp->toPathStrings();
            }
        }
        $questions[$qid]['text'] = strip_tags($question['text']);
        //If we ommit this line, then the questions list is html formatted, images are displayed etc, which is *not* the intended behaviour
        $questions[$qid]['parent_name'] = $unitNames[$question['content_ID']];
        $questions[$qid]['weight'] = !empty($testQuestions[$qid]['weight']) ? $testQuestions[$qid]['weight'] : $difficultiesToWeights[$question['difficulty']];
        $questions[$qid]['partof'] = 0;
        $questions[$qid]['estimate_interval'] = eF_convertIntervalToTime($question['estimate']);
        if ($question['lessons_ID'] == 0) {
            $questions[$qid]['name'] = _SKILLGAPTESTS;
        } else {
            $questions[$qid]['name'] = _LESSON . ': "' . $question['name'] . '"';
            $questions[$qid]['lesson_name'] = $lessons[$question['lessons_ID']]['name'];
            $questions[$qid]['parent_unit'] = $contentTrees[$question['lessons_ID']][$question['content_ID']];
Example #14
0
        $currentUser->coreAccess['content'] != 'change' ? $currentLesson->mode = 'browse' : ($currentLesson->mode = 'normal');
        //If the user type's setting is other than 'change' from content, then set lesson mode to 'browse', which means that no unit completion or ' or whatever progress is recorded
    } catch (Exception $e) {
        unset($_SESSION['s_lessons_ID']);
        $message = $e->getMessage() . ' (' . $e->getCode() . ')';
        eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?message=" . urlencode($message) . "&message_type=failure");
        //redirect to user lessons page
    }
}
//@todo: remove package_ID from $_SESSION, beware package_ID is needed in lms_commit
if (isset($_SESSION['package_ID']) && !$_GET['commit_lms']) {
    unset($_SESSION['package_ID']);
}
try {
    if (isset($_GET['view_unit']) && eF_checkParameter($_GET['view_unit'], 'id')) {
        $currentContent = new EfrontContentTree($currentLesson);
        //Initialize content
        $currentContent->markSeenNodes($currentUser);
        if ($currentLesson->lesson['access_limit']) {
            $result = eF_getTableData("users_to_lessons", "access_counter", "users_LOGIN='******'login'] . "' and lessons_ID='" . $currentLesson->lesson['id'] . "'");
            if ($result[0]['access_counter'] >= $currentLesson->lesson['access_limit']) {
                eF_redirect(basename($_SERVER['PHP_SELF']) . "?ctg=lessons&message=" . urlencode(_ACCESSDEPLETED) . "&message_type=failure");
            } else {
                if (!$_SESSION['visited_lesson'][$currentLesson->lesson['id']]) {
                    eF_updateTableData("users_to_lessons", array('access_counter' => $result[0]['access_counter'] + 1), "users_LOGIN='******'login'] . "' and lessons_ID='" . $currentLesson->lesson['id'] . "'");
                    $_SESSION['visited_lesson'][$currentLesson->lesson['id']] = 1;
                }
            }
        }
        if ($currentUser->coreAccess['content'] == 'hidden') {
            eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
Example #15
0
         }
     } catch (Exception $e) {
         header("HTTP/1.0 500 ");
         echo $e->getMessage() . ' (' . $e->getCode() . ')';
     }
     exit;
     //We asked to copy content
 } else {
     $currentContent = new EfrontContentTree($currentLesson, true);
     $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST));
     if (sizeof($currentContent->tree) == 0) {
         $smarty->assign("T_CONTENT_TREE", $currentContent->toHTML($iterator, 'dhtmlTargetTree', array('noclick' => true, 'drag' => false, 'tree_root' => true)));
     } else {
         $smarty->assign("T_CONTENT_TREE", $currentContent->toHTML($iterator, 'dhtmlTargetTree', array('noclick' => true, 'drag' => false, 'expand' => true, 'truncateNames' => EfrontUnit::MAXIMUM_NAME_LENGTH)));
     }
     $sourceContent = new EfrontContentTree($_GET['from'], true);
     $sourceIterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($sourceContent->tree), RecursiveIteratorIterator::SELF_FIRST));
     $smarty->assign("T_SOURCE_TREE", $sourceContent->toHTML($sourceIterator, 'dhtmlSourceTree', array('noclick' => true, 'drag' => true, 'expand' => true)));
     $currentIds[] = 0;
     //0 is a valid parent node
     foreach ($iterator as $key => $value) {
         $currentIds[] = $value['id'];
     }
     //pr($currentIds);
     foreach ($sourceIterator as $key => $value) {
         $sourceIds[] = $value['id'];
     }
     try {
         if (isset($_GET['node_orders'])) {
             //Save new order through AJAX call
             $nodeOrders = explode(",", $_GET['node_orders']);
Example #16
0
 private function getRssSource($source, $mode, $lesson)
 {
     $feeds = $this->getProvidedFeeds();
     foreach ($feeds as $value) {
         if ($value['active'] && $value['mode'] == 'system') {
             $systemFeeds[$value['type']] = $value;
         } else {
             if ($value['active'] && $value['mode'] == 'lesson') {
                 $lessonFeeds[$value['type']] = $value;
             }
         }
     }
     if ($mode == 'system' && !in_array($source, array_keys($systemFeeds))) {
         return array();
     } elseif ($mode == 'lesson' && !in_array($source, array_keys($lessonFeeds))) {
         return array();
     }
     $data = array();
     switch ($source) {
         case 'announcements':
             if ($mode == 'system') {
                 $news = news::getNews(0, true);
             } elseif ($mode == 'lesson') {
                 if ($lesson) {
                     $news = news::getNews($lesson, true);
                 } else {
                     $lessons = eF_getTableDataFlat("lessons", "id, name");
                     $lessonNames = array_combine($lessons['id'], $lessons['name']);
                     $news = news::getNews($lessons['id'], true);
                 }
             }
             $count = 1;
             foreach ($news as $value) {
                 if ($mode == 'lesson' && !$lesson) {
                     $value['title'] = $lessonNames[$value['lessons_ID']] . ': ' . $value['title'];
                     $link = G_SERVERNAME . 'userpage.php?lessons_ID=' . $value['lessons_ID'] . '&amp;ctg=news&amp;view=' . $value['id'];
                 } else {
                     $link = G_SERVERNAME . 'userpage.php?ctg=news&amp;view=' . $value['id'];
                 }
                 $data[] = array('title' => $value['title'], 'link' => $link, 'description' => $value['data']);
                 /*
                     				if ($count++ == $this -> feedLimit) {
                     					break;
                     				}
                 */
             }
             break;
         case 'catalog':
             $constraints = array("return_objects" => false, 'archive' => false, 'active' => true);
             $result = EfrontCourse::getAllCourses($constraints);
             $directionsTree = new EfrontDirectionsTree();
             $directionPaths = $directionsTree->toPathString();
             foreach ($result as $value) {
                 $pathString = $directionPaths[$value['directions_ID']] . '&nbsp;&rarr;&nbsp;' . $value['name'];
                 $data[] = array('title' => $pathString, 'link' => G_SERVERNAME . 'index.php?ctg=lesson_info&amp;courses_ID=' . $value['id'], 'description' => implode("<br>", unserialize($value['info'])));
             }
             $result = eF_getTableData("lessons", "id,name,directions_ID, info", "archive=0 and instance_source = 0 and active=1 and course_only=0", "name");
             foreach ($result as $value) {
                 $pathString = $directionPaths[$value['directions_ID']] . '&nbsp;&rarr;&nbsp;' . $value['name'];
                 $data[] = array('title' => $pathString, 'link' => G_SERVERNAME . 'index.php?ctg=lesson_info&amp;lessons_ID=' . $value['id'], 'description' => implode("<br>", unserialize($value['info'])));
             }
             $data = array_values(eF_multisort($data, 'title', 'asc'));
             //Sort results based on path string
             break;
         case 'calendar':
             if ($mode == 'system') {
                 $events = calendar::getGlobalCalendarEvents();
             } elseif ($mode == 'lesson') {
                 if ($lesson) {
                     $events = calendar::getLessonCalendarEvents($lesson);
                 } else {
                     $events = calendar::getCalendarEventsForAllLessons();
                 }
             }
             foreach ($events as $value) {
                 $value['name'] ? $title = formatTimestamp($value['timestamp']) . ' (' . $value['name'] . ')' : ($title = formatTimestamp($value['timestamp']));
                 $data[] = array('title' => $title, 'link' => G_SERVERNAME . 'userpage.php?ctg=calendar&amp;view_calendar=' . $value['timestamp'] . '&amp;type=0', 'description' => $value['data']);
             }
             break;
             /*
                 		case 'history':
                 			$currentUser = $this -> getCurrentUser();
             
             				$eventObjects = array();
                 			$result = eF_getTableData("events", "*", "", "timestamp DESC limit 100");
             				foreach ($result as $value) {
             					$eventObject = new EfrontEvent($value);
             					$eventObject -> createMessage();
             					pr($eventObject);
             				}
             
                 			break;
             */
         /*
             		case 'history':
             			$currentUser = $this -> getCurrentUser();
         
         				$eventObjects = array();
             			$result = eF_getTableData("events", "*", "", "timestamp DESC limit 100");
         				foreach ($result as $value) {
         					$eventObject = new EfrontEvent($value);
         					$eventObject -> createMessage();
         					pr($eventObject);
         				}
         
             			break;
         */
         case 'structure':
             if ($lesson) {
                 $contentTree = new EfrontContentTree($lesson);
                 $contentPath = $contentTree->toPathStrings();
                 foreach ($contentPath as $key => $value) {
                     $data[] = array('title' => $value, 'link' => G_SERVERNAME . 'userpage.php?lessons_ID=' . $lesson . '&amp;unit=' . $key, 'description' => $value);
                 }
             }
             break;
         case 'forum':
             if ($mode == 'system') {
                 $result = eF_getTableData("f_messages fm JOIN f_topics ft JOIN f_forums ff LEFT OUTER JOIN lessons l ON ff.lessons_ID = l.id", "ff.title as forum_name, fm.body, fm.title, fm.id, ft.id as topic_id, ft.title as topic_title, fm.users_LOGIN, fm.timestamp, l.name as lessons_name, lessons_id as show_lessons_id", "ft.f_forums_ID=ff.id AND fm.f_topics_ID=ft.id ", "fm.timestamp desc LIMIT 100");
             } elseif ($mode == 'lesson') {
                 if ($lesson) {
                     $result = eF_getTableData("f_messages fm JOIN f_topics ft JOIN f_forums ff LEFT OUTER JOIN lessons l ON ff.lessons_ID = l.id", "ff.title as forum_name, fm.body, fm.title, fm.id, ft.id as topic_id, ft.title as topic_title, fm.users_LOGIN, fm.timestamp, l.name as lessons_name, lessons_id as show_lessons_id", "ft.f_forums_ID=ff.id AND fm.f_topics_ID=ft.id AND ff.lessons_ID = '" . $lesson . "'", "fm.timestamp desc LIMIT 100");
                 } else {
                     $result = eF_getTableData("f_messages fm JOIN f_topics ft JOIN f_forums ff LEFT OUTER JOIN lessons l ON ff.lessons_ID = l.id", "ff.title as forum_name, fm.body, fm.title, fm.id, ft.id as topic_id, ft.title as topic_title, fm.users_LOGIN, fm.timestamp, l.name as lessons_name, lessons_id as show_lessons_id", "ft.f_forums_ID=ff.id AND fm.f_topics_ID=ft.id AND ff.lessons_ID != 0", "fm.timestamp desc LIMIT 100");
                 }
             }
             foreach ($result as $value) {
                 $value['title'] = $value['forum_name'] . ' >> ' . $value['topic_title'] . ' >> ' . $value['title'];
                 if ($mode == 'system' && $value['lessons_name'] || $mode == 'lesson' && !$lesson) {
                     $value['title'] = $value['lessons_name'] . ': ' . $value['title'];
                 }
                 $data[] = array('title' => $value['title'], 'link' => G_SERVERNAME . 'userpage.php?ctg=forum&amp;topic=' . $value['topic_id'], 'description' => $value['body']);
             }
             break;
         default:
             break;
     }
     return $data;
 }
Example #17
0
<?php

//This file cannot be called directly, only included.
if (str_replace(DIRECTORY_SEPARATOR, "/", __FILE__) == $_SERVER['SCRIPT_FILENAME']) {
    exit;
}
if (isset($currentUser->coreAccess['content']) && $currentUser->coreAccess['content'] == 'hidden') {
    eF_redirect("" . basename($_SERVER['PHP_SELF']) . "?ctg=control_panel&message=" . urlencode(_UNAUTHORIZEDACCESS) . "&message_type=failure");
}
$loadScripts[] = 'includes/rules';
$currentContent = new EfrontContentTree($currentLesson);
$rules = $currentContent->getRules();
$units = array();
foreach ($iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($currentContent->tree), RecursiveIteratorIterator::SELF_FIRST)) as $key => $value) {
    $units['id'][] = $value['id'];
    $units['name'][] = $value['name'];
    $units['active'][] = $value['active'];
}
$smarty->assign("T_TREE_ACTIVE", array_combine($units['id'], $units['active']));
$smarty->assign("T_TREE_NAMES", array_combine($units['id'], $units['name']));
$smarty->assign("T_RULES", $rules);
$conditions = $currentLesson->getConditions();
$condition_types = array('all_units' => _PASSEDALLUNITS, 'percentage_units' => _PERCENTAGEUNITS, 'specific_unit' => _SPECIFICUNIT, 'all_tests' => _PASSEDALLTESTS, 'specific_test' => _SPECIFICTEST);
if (G_VERSIONTYPE != 'community') {
    #cpp#ifndef COMMUNITY
    if (G_VERSIONTYPE != 'standard') {
        #cpp#ifndef STANDARD
        $condition_types['time_in_lesson'] = _SPENTTIMEINLESSON;
    }
    #cpp#endif
}
 public function fromXML($xmlfile)
 {
     $xml = simplexml_load_file($xmlfile);
     $contentTree = new EfrontContentTree($this->lesson['id']);
     $contentTree->fromXMLNode($xml->lessonId[0]);
     $fields = array();
     $fields['name'] = (string) $xml->lesson->name;
     $fields['info'] = (string) $xml->lesson->info;
     $fields['options'] = (string) $xml->lesson->options;
     $fields['course_only'] = (string) $xml->lesson->course_only;
     //$fields['auto_certificate'] = (string)$xml->lesson->auto_certificate;
     //$fields['auto_complete'] = (string)$xml->lesson->auto_complete;
     //$fields['publish'] = (string)$xml->lesson->publish;
     $lid = ef_inserTableData("lessons", $fields);
     for ($i = 0; $i < sizeof($xml->lesson->conditions->condition); $i++) {
         $condition = array();
         $condition['type'] = $xml->lessonId->conditions->condition[$i]->type;
         $condition['options'] = $xml->lessonId->conditions->condition[$i]->options;
         $condition['relation'] = $xml->lessonId->conditions->condition[$i]->relation;
         $cid = ef_insertTableData("lesson_conditions", $condition);
     }
     for ($i = 0; $i < sizeof($xml->lesson->rules->rule); $i++) {
         $rule = array();
         $rule['content_id'] = $xml->lessonId->rules->rule[$i]->content_id;
         $rule['rule_content_id'] = $xml->lessonId->rules->rule[$i]->rule_content_id;
         $rule['rule_type'] = $xml->lessonId->rules->rule[$i]->rule_type;
         $rule['rule_option'] = $xml->lessonId->rules->rule[$i]->rule_option;
         $rid = ef_insertTableData("rules", $rule);
     }
 }
 public function getSmartyTpl()
 {
     $smarty = $this->getSmartyVar();
     $currentUser = $this->getCurrentUser();
     $currentLesson = $this->getCurrentLesson();
     $currentLessonID = $currentLesson->lesson['id'];
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
         // XXX
         $workbookLessonName = _WORKBOOK_NAME . ' [' . $this->getWorkbookLessonName($currentLessonID) . ']';
         $smarty->assign("T_WORKBOOK_LESSON_NAME", $workbookLessonName);
         $lessonQuestions = $this->getLessonQuestions($currentLessonID);
         $workbookLessons = $this->isWorkbookInstalledByUser($currentUser, $currentUser->getRole($this->getCurrentLesson()), $currentLessonID);
         $workbookItems = $this->getWorkbookItems($currentLessonID);
         $nonOptionalQuestionsNr = $this->getNonOptionalQuestionsNr($workbookItems);
         if ($nonOptionalQuestionsNr != 0) {
             $questionPercentage = (double) (100 / $nonOptionalQuestionsNr);
             $questionPercentage = round($questionPercentage, 2);
         }
         $isWorkbookPublished = $this->isWorkbookPublished($currentLessonID);
     }
     if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
         $workbookSettings = $this->getWorkbookSettings($currentLessonID);
         $smarty->assign("T_WORKBOOK_SETTINGS", $workbookSettings);
     }
     $smarty->assign("T_WORKBOOK_BASEURL", $this->moduleBaseUrl);
     $smarty->assign("T_WORKBOOK_BASELINK", $this->moduleBaseLink);
     global $popup;
     isset($popup) && $popup == 1 ? $popup_ = '&popup=1' : ($popup_ = '');
     if (isset($_REQUEST['question_preview']) && $_REQUEST['question_preview'] == '1' && isset($_REQUEST['question_id']) && eF_checkParameter($_REQUEST['question_id'], 'id')) {
         $id = $_REQUEST['question_id'];
         if (!in_array($id, array_keys($lessonQuestions))) {
             // reused item
             $reusedQuestion = $this->getReusedQuestionDetails($id);
             $type = $reusedQuestion['type'];
         } else {
             $type = $lessonQuestions[$id]['type'];
         }
         echo $this->questionToHtml($id, $type);
         exit;
     }
     if (isset($_REQUEST['get_progress']) && $_REQUEST['get_progress'] == '1') {
         $isWorkbookCompleted = $this->isWorkbookCompleted($currentUser->user['login'], $currentLessonID, array_keys($workbookItems), $nonOptionalQuestionsNr);
         $studentProgress = $this->getStudentProgress($currentUser->user['login'], $currentLessonID);
         if ($isWorkbookCompleted['is_completed'] == 1) {
             $unitToComplete = $workbookSettings['unit_to_complete'];
             $result = eF_updateTableData('module_workbook_progress', array('completion_date' => time()), "lessons_ID='" . $currentLessonID . "' AND users_LOGIN='******'login'] . "'");
             if ($unitToComplete != -1) {
                 $currentUser->setSeenUnit($unitToComplete, $currentLessonID, true);
             }
         }
         echo $studentProgress . '-' . $isWorkbookCompleted['id'];
         exit;
     }
     if (isset($_GET['edit_settings']) && $_GET['edit_settings'] == '1') {
         if ($_SESSION['s_type'] != 'professor') {
             $message = _WORKBOOK_NOACCESS;
             $message_type = 'failure';
             $this->setMessageVar(urlencode($message), $message_type);
         }
         $content = new EfrontContentTree($currentLessonID);
         $iterator = new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($content->tree), RecursiveIteratorIterator::SELF_FIRST), array('ctg_type' => 'theory'));
         $contentOptions = $content->toHTMLSelectOptions($iterator);
         $contentOptions = array(-1 => '-------------') + $contentOptions;
         $workbookSettings = $this->getWorkbookSettings($currentLessonID);
         if ($isWorkbookPublished == 1) {
             $contentOptions[$workbookSettings['unit_to_complete']] = str_replace('&nbsp;', '', $contentOptions[$workbookSettings['unit_to_complete']]);
             $contentOptions[$workbookSettings['unit_to_complete']] = str_replace('&raquo;', '', $contentOptions[$workbookSettings['unit_to_complete']]);
         }
         $form = new HTML_QuickForm("edit_settings_form", "post", $this->moduleBaseUrl . "&edit_settings=1", "", null, true);
         $form->addElement('text', 'lesson_name', _WORKBOOK_LESSON_NAME, 'class="inputText"');
         $form->addRule('lesson_name', _THEFIELD . ' "' . _WORKBOOK_LESSON_NAME . '" ' . _ISMANDATORY, 'required', null, 'client');
         $form->addElement('advcheckbox', 'allow_print', _WORKBOOK_ALLOW_PRINT, null, 'class="inputCheckBox"', array(0, 1));
         $form->addElement('advcheckbox', 'allow_export', _WORKBOOK_ALLOW_EXPORT, null, 'class="inputCheckBox"', array(0, 1));
         $form->addElement('advcheckbox', 'edit_answers', _WORKBOOK_EDIT_ANSWERS, null, 'class="inputCheckBox"', array(0, 1));
         $form->addElement('select', 'unit_to_complete', _WORKBOOK_UNIT_TO_COMPLETE, $contentOptions);
         $form->addElement('submit', 'submit', _UPDATE, 'class="flatButton"');
         if ($isWorkbookPublished == 1) {
             $form->freeze('unit_to_complete');
         }
         $form->setDefaults($workbookSettings);
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $fields = array("lesson_name" => $values['lesson_name'], "allow_print" => $values['allow_print'], "allow_export" => $values['allow_export'], "edit_answers" => $values['edit_answers'], "unit_to_complete" => $values['unit_to_complete']);
             if (eF_updateTableData("module_workbook_settings", $fields, "id=" . $workbookSettings['id'])) {
                 $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_SETTINGS_SUCCESSFULLY_EDITED);
                 $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'success');
             } else {
                 $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_SETTINGS_EDIT_PROBLEM);
                 $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'failure');
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $renderer->setRequiredTemplate('{$html}{if $required}&nbsp;<span class="formRequired">*</span>{/if}');
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_EDIT_SETTINGS_FORM', $renderer->toArray());
     }
     if (isset($_GET['reuse_item']) && $_GET['reuse_item'] == '1') {
         if ($_SESSION['s_type'] != 'professor') {
             $message = _WORKBOOK_NOACCESS;
             $message_type = 'failure';
             $this->setMessageVar(urlencode($message), $message_type);
         }
         $form = new HTML_QuickForm("reuse_item_form", "post", $this->moduleBaseUrl . "&reuse_item=1", "", null, true);
         $form->addElement('text', 'item_id', _WORKBOOK_ITEM_ID, 'class="inputText"');
         $form->addRule('item_id', _THEFIELD . ' "' . _WORKBOOK_ITEM_ID . '" ' . _ISMANDATORY, 'required', null, 'client');
         $form->addElement('submit', 'submit', _WORKBOOK_REUSE_ITEM, 'class="flatButton"');
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $existingIDs = $this->getItemsUniqueIDs();
             if (!in_array($values['item_id'], $existingIDs)) {
                 $message = _WORKBOOK_INVALID_UNIQUE_ID;
                 $message_type = 'failure';
                 $this->setMessageVar(urlencode($message), $message_type);
             } else {
                 $item = $this->getItemByUniqueID($values['item_id']);
                 $fields = array("item_title" => $item['item_title'], "item_text" => $item['item_text'], "item_question" => $item['item_question'], "question_text" => $item['question_text'], "check_answer" => $item['check_answer'], "lessons_ID" => $currentLessonID, "unique_ID" => $this->generateItemID(), "position" => $this->itemPosition($currentLessonID));
                 if (eF_insertTableData("module_workbook_items", $fields)) {
                     $smarty->assign("T_WORKBOOK_MESSAGE", urlencode(_WORKBOOK_ITEM_SUCCESSFULLY_ADDED));
                     $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'success');
                 } else {
                     $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_ITEM_ADD_PROBLEM);
                     $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'failure');
                 }
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $renderer->setRequiredTemplate('{$html}{if $required}&nbsp;<span class="formRequired">*</span>{/if}');
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_REUSE_ITEM_FORM', $renderer->toArray());
     }
     if (isset($_GET['move_item']) && eF_checkParameter($_GET['move_item'], 'id') && in_array($_GET['move_item'], array_keys($workbookItems))) {
         if ($_SESSION['s_type'] != 'professor') {
             $message = _WORKBOOK_NOACCESS;
             $message_type = 'failure';
             $this->setMessageVar(urlencode($message), $message_type);
         }
         $smarty->assign("T_WORKBOOK_ITEMS_COUNT", count($workbookItems));
         $itemPosition = $workbookItems[$_GET['move_item']]['position'];
         $availablePositions = array();
         foreach ($workbookItems as $key => $value) {
             if ($value['position'] != $itemPosition) {
                 $availablePositions[$value['position']] = $value['position'];
             }
         }
         $form = new HTML_QuickForm("move_item_form", "post", $this->moduleBaseUrl . "&move_item=" . $_GET['move_item'], "", null, true);
         $form->addElement('select', 'item_position', _WORKBOOK_ITEM_NEW_POSITION, $availablePositions, '');
         $form->addElement('submit', 'submit', _WORKBOOK_MOVE_ITEM, 'class="flatButton"');
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             $newPosition = $values['item_position'];
             if ($newPosition > $itemPosition) {
                 foreach ($workbookItems as $key => $value) {
                     if ($value['position'] > $itemPosition && $value['position'] <= $newPosition) {
                         eF_updateTableData("module_workbook_items", array('position' => $value['position'] - 1), "id=" . $key);
                     }
                 }
             } else {
                 foreach ($workbookItems as $key => $value) {
                     if ($value['position'] < $itemPosition && $value['position'] >= $newPosition) {
                         eF_updateTableData("module_workbook_items", array('position' => $value['position'] + 1), "id=" . $key);
                     }
                 }
             }
             eF_updateTableData("module_workbook_items", array('position' => $newPosition), "id=" . $_GET['move_item']);
             $smarty->assign("T_WORKBOOK_MESSAGE", _WORKBOOK_ITEM_SUCCESSFULLY_MOVED);
             $smarty->assign("T_WORKBOOK_MESSAGE_TYPE", 'success');
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $renderer->setRequiredTemplate('{$html}{if $required}&nbsp;<span class="formRequired">*</span>{/if}');
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_MOVE_ITEM_FORM', $renderer->toArray());
     }
     if (isset($_GET['delete_item']) && eF_checkParameter($_GET['delete_item'], 'id') && in_array($_GET['delete_item'], array_keys($workbookItems))) {
         $item_id = $_GET['delete_item'];
         $itemPosition = $workbookItems[$item_id]['position'];
         foreach ($workbookItems as $key => $value) {
             if ($value['position'] > $itemPosition) {
                 eF_updateTableData("module_workbook_items", array('position' => $value['position'] - 1), "id=" . $key);
             }
         }
         eF_deleteTableData("module_workbook_items", "id=" . $item_id);
     }
     if (isset($_GET['switch_lesson']) && eF_checkParameter($_GET['switch_lesson'], 'id') && in_array($_GET['switch_lesson'], array_keys($workbookLessons))) {
         $lessonID = $_GET['switch_lesson'];
         eF_redirect("location:" . $this->moduleBaseUrl . "&lessons_ID=" . $lessonID . $popup_);
     }
     if (isset($_GET['add_item']) && $_GET['add_item'] == '1' || isset($_GET['edit_item']) && eF_checkParameter($_GET['edit_item'], 'id') && in_array($_GET['edit_item'], array_keys($workbookItems))) {
         if ($_SESSION['s_type'] != "professor") {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_WORKBOOK_NOACCESS) . $popup_);
         }
         global $load_editor;
         $load_editor = true;
         $questionsText = array();
         $questionsText[-1] = "-----------------------";
         foreach ($lessonQuestions as $key => $value) {
             $questionsText[$key] = $this->truncateText(strip_tags($value['text']), 70);
         }
         if (isset($_GET['edit_item'])) {
             $editItemID = $_GET['edit_item'];
             $editItemQuestion = $workbookItems[$editItemID]['item_question'];
             if ($editItemQuestion != '-1' && !in_array($editItemQuestion, array_keys($questionsText))) {
                 // reused item
                 $reusedQuestion = $this->getReusedQuestionDetails($editItemQuestion);
                 $questionsText[$editItemQuestion] = $this->truncateText(strip_tags($reusedQuestion['text']), 70);
             }
         }
         isset($_GET['add_item']) ? $postTarget = "&add_item=1" : ($postTarget = "&edit_item=" . $_GET['edit_item']);
         $form = new HTML_QuickForm("add_edit_item_form", "post", $this->moduleBaseUrl . $postTarget, "", null, true);
         $form->addElement('text', 'item_title', _WORKBOOK_ITEM_TITLE, 'class="inputText" style="width:500px;"');
         $form->addElement('textarea', 'item_text', _WORKBOOK_ITEM_TEXT, 'class="mceEditor" style="width:99%;height:300px;" id="editor_content_data"');
         $form->addElement('select', 'item_question', _WORKBOOK_ITEM_QUESTION, $questionsText, 'onchange="questionPreview(this)"');
         $form->addElement('advcheckbox', 'check_answer', _WORKBOOK_ITEM_GRADE_ANSWER, null, 'class="inputCheckBox"', array(0, 1));
         if (isset($_GET['add_item'])) {
             $form->addElement('submit', 'submit', _WORKBOOK_ADD_ITEM, 'class="flatButton"');
         } else {
             $form->addElement('submit', 'submit', _WORKBOOK_UPDATE_ITEM, 'class="flatButton"');
         }
         if (isset($_GET['edit_item'])) {
             $editItem = $workbookItems[$_GET['edit_item']];
             $form->setDefaults($editItem);
             if ($isWorkbookPublished == '1') {
                 $editItem['question_title'] = $questionsText[$editItem['item_question']];
                 if ($editItem['check_answer'] == '1') {
                     $editItem['check_answer_text'] = _YES;
                 } else {
                     $editItem['check_answer_text'] = _NO;
                 }
             }
             $smarty->assign('T_WORKBOOK_EDIT_ITEM_DETAILS', $editItem);
         }
         if ($form->isSubmitted() && $form->validate()) {
             $values = $form->exportValues();
             isset($_GET['add_item']) ? $lessonID = $currentLessonID : ($lessonID = $editItem['lessons_ID']);
             isset($_GET['add_item']) ? $uniqueID = $this->generateItemID() : ($uniqueID = $editItem['unique_ID']);
             isset($_GET['add_item']) ? $position = $this->itemPosition($currentLessonID) : ($position = $editItem['position']);
             if ($values['item_question'] != '-1') {
                 $id = $values['item_question'];
                 if (!in_array($id, array_keys($lessonQuestions))) {
                     // edit reused item
                     $reusedQuestion = $this->getReusedQuestionDetails($id);
                     $type = $reusedQuestion['type'];
                 } else {
                     $type = $lessonQuestions[$id]['type'];
                 }
                 $questionText = $this->questionToHtml($id, $type);
             } else {
                 $questionText = '';
             }
             $fields = array("item_title" => $values['item_title'], "item_text" => $values['item_text'], "item_question" => $values['item_question'], "question_text" => $questionText, "check_answer" => $values['check_answer'], "lessons_ID" => $lessonID, "unique_ID" => $uniqueID, "position" => $position);
             if ($values['item_title'] == '' && $values['item_text'] == '' && $values['item_question'] == '-1') {
                 $message = _WORKBOOK_ITEM_EMPTY_FIELDS;
                 if (isset($_GET['add_item'])) {
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure&add_item=1" . $popup_);
                 } else {
                     $itemID = $_GET['edit_item'];
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure&edit_item=" . $itemID . $popup_);
                 }
             }
             if (isset($_GET['add_item'])) {
                 if (eF_insertTableData("module_workbook_items", $fields)) {
                     $message = _WORKBOOK_ITEM_SUCCESSFULLY_ADDED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
                 } else {
                     $message = _WORKBOOK_ITEM_ADD_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
                 }
             } else {
                 if (eF_updateTableData("module_workbook_items", $fields, "id=" . $_GET['edit_item'])) {
                     $message = _WORKBOOK_ITEM_SUCCESSFULLY_EDITED;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
                 } else {
                     $message = _WORKBOOK_ITEM_EDIT_PROBLEM;
                     eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
                 }
             }
         }
         $renderer = new HTML_QuickForm_Renderer_ArraySmarty($smarty);
         $form->setJsWarnings(_BEFOREJAVASCRIPTERROR, _AFTERJAVASCRIPTERROR);
         $form->setRequiredNote(_REQUIREDNOTE);
         $form->accept($renderer);
         $smarty->assign('T_WORKBOOK_ADD_EDIT_ITEM_FORM', $renderer->toArray());
         $basedir = $currentLesson->getDirectory();
         $options = array('lessons_ID' => $currentLessonID, 'metadata' => 0);
         $url = $_SERVER['REQUEST_URI'];
         $extraFileTools = array(array('image' => 'images/16x16/arrow_right.png', 'title' => _INSERTEDITOR, 'action' => 'insert_editor'));
         include "file_manager.php";
     }
     if (isset($_GET['publish_workbook']) && $_GET['publish_workbook'] == '1') {
         $result = eF_getTableData("module_workbook_publish", "publish", "lessons_ID=" . $currentLessonID);
         if (count($result) == 0) {
             if (eF_insertTableData("module_workbook_publish", array('lessons_ID' => $currentLessonID, 'publish' => 1))) {
                 $message = _WORKBOOK_SUCCESSFULLY_PUBLISHED;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
             } else {
                 $message = _WORKBOOK_PUBLISH_PROBLEM;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
             }
         } else {
             if (eF_updateTableData("module_workbook_publish", array('publish' => 1), "lessons_ID=" . $currentLessonID)) {
                 $message = _WORKBOOK_SUCCESSFULLY_PUBLISHED;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=success" . $popup_);
             } else {
                 $message = _WORKBOOK_PUBLISH_PROBLEM;
                 eF_redirect($this->moduleBaseUrl . "&message=" . urlencode($message) . "&message_type=failure" . $popup_);
             }
         }
     }
     if (isset($_GET['reset_workbook_professor']) && $_GET['reset_workbook_professor'] == '1') {
         eF_updateTableData("module_workbook_publish", array('publish' => 0), "lessons_ID=" . $currentLessonID);
         foreach ($workbookItems as $key => $value) {
             eF_deleteTableData("module_workbook_answers", "item_id=" . $key);
             eF_deleteTableData("module_workbook_autosave", "item_id=" . $key);
             eF_deleteTableData("module_workbook_progress", "lessons_ID=" . $currentLessonID);
         }
     }
     if (isset($_GET['reset_workbook_student']) && eF_checkParameter($_GET['reset_workbook_student'], 'id')) {
         $id = $_GET['reset_workbook_student'];
         $result = eF_getTableData("module_workbook_progress", "users_LOGIN", "id=" . $id);
         if ($result[0]['users_LOGIN'] != $currentUser->user['login']) {
             eF_redirect($this->moduleBaseUrl . "&message=" . urlencode(_WORKBOOK_NOACCESS) . $popup_);
         }
         eF_deleteTableData("module_workbook_progress", "id=" . $id);
         foreach ($workbookItems as $key => $value) {
             eF_deleteTableData("module_workbook_answers", "item_id=" . $key . " AND users_LOGIN='******'login'] . "'");
         }
         $unitToComplete = $workbookSettings['unit_to_complete'];
         if ($unitToComplete != -1) {
             $currentUser->setSeenUnit($unitToComplete, $currentLessonID, false);
         }
     }
     if (isset($_GET['download_as']) && $_GET['download_as'] == 'doc') {
         include dirname(__FILE__) . "/classes/html_to_doc.inc.php";
         $workbookAnswers = $this->getWorkbookAnswers($currentUser->user['login'], array_keys($workbookItems));
         $workbookHTML = '';
         foreach ($workbookItems as $key => $value) {
             $workbookHTML .= '<div style="width:98%;float:left;border:1px dotted #808080;padding: 5px 10px;">';
             $workbookHTML .= '<div style="background-color: #EAEAEA;border: 1px solid #AAAAAA;padding: 2px;font-weight: bold;">';
             $workbookHTML .= _WORKBOOK_ITEMS_COUNT . $value['position'];
             if ($value['item_title'] != '') {
                 $workbookHTML .= '&nbsp;-&nbsp;' . $value['item_title'];
             }
             $workbookHTML .= '</div><br/>';
             if ($value['item_text'] != '') {
                 $workbookHTML .= '<div>' . $value['item_text'] . '</div><br/>';
             }
             if ($value['item_question'] != '-1') {
                 $questionType = $lessonQuestions[$value['item_question']]['type'];
                 if ($workbookAnswers[$value['id']] == '') {
                     if ($questionType == 'drag_drop') {
                         $dragDrop = eF_getTableData("questions", "options, answer, text", "id=" . $value['item_question']);
                         $options = unserialize($dragDrop[0]['options']);
                         $answer = unserialize($dragDrop[0]['answer']);
                         shuffle($options);
                         shuffle($answer);
                         $workbookHTML .= $dragDrop[0]['text'];
                         for ($i = 0; $i < count($options); $i++) {
                             $workbookHTML .= '<div>' . $options[$i] . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                             $workbookHTML .= $answer[$i] . '</div>';
                         }
                     } else {
                         $workbookHTML .= '<div>' . $value['question_text'] . '</div>';
                     }
                 } else {
                     $workbookHTML .= '<div>' . $workbookAnswers[$value['id']] . '</div>';
                 }
             }
             $workbookHTML .= '</div><br/>';
         }
         $workbookHTML = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $workbookHTML);
         $fileName = _WORKBOOK_NAME . '_' . $this->getWorkbookLessonName($currentLessonID);
         $fileName = preg_replace('/[\\s]+/', '_', $fileName);
         $htmltodoc = new HTML_TO_DOC();
         $htmltodoc->createDoc($workbookHTML, $fileName, true);
         exit(0);
     }
     if (isset($_GET['download_as']) && $_GET['download_as'] == 'pdf') {
         $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true);
         $pdf->SetCreator(PDF_CREATOR);
         $pdf->SetAuthor(PDF_AUTHOR);
         $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
         $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
         $pdf->setFontSubsetting(false);
         $pdf->AddPage();
         $completion_date = '';
         $resutlt = eF_getTableData('module_workbook_progress', 'completion_date', "users_LOGIN='******'login'] . "' and lessons_ID='" . $currentLessonID . "'");
         if ($resutlt) {
             $completion_date = $resutlt[0]['completion_date'];
         }
         $workbookHTML = '';
         $workbookHTML .= '<table>';
         $workbookHTML .= '<tr>';
         $workbookHTML .= '<td colspan="2">';
         $workbookHTML .= formatLogin($currentUser->user['login']);
         $workbookHTML .= '</td>';
         $workbookHTML .= '</tr>';
         $workbookHTML .= '<tr>';
         $workbookHTML .= '<td>';
         $workbookHTML .= $workbookLessonName;
         $workbookHTML .= '</td>';
         $workbookHTML .= '<td>';
         $workbookHTML .= formatTimestamp($completion_date);
         $workbookHTML .= '</td>';
         $workbookHTML .= '</tr>';
         $workbookHTML .= '</table>';
         $pdf->writeHTML($workbookHTML, true, false, true, false, '');
         $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
         $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
         $pdf->setHeaderFont(array('Freeserif', 'I', 11));
         $pdf->setFooterFont(array('Freeserif', '', 8));
         $pdf->setHeaderData('', '', '', $workbookLessonName);
         $pdf->AliasNbPages();
         $pdf->SetFont('Freeserif', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         $pdf->SetFont('Freeserif', '', 10);
         $pdf->SetTextColor(0, 0, 0);
         $workbookAnswers = $this->getWorkbookAnswers($currentUser->user['login'], array_keys($workbookItems));
         $pdf->AddPage();
         $workbookHTML .= '';
         $itemLogo = new EfrontFile(G_DEFAULTIMAGESPATH . "32x32/unit.png");
         $itemLogoUrl = $itemLogo['path'];
         foreach ($workbookItems as $key => $value) {
             $workbookHTML .= '<div id="pdf-block" style="width:98%;float:left;border:1px dotted #808080;page-break-after:always;">';
             $workbookHTML .= '<div style="background-color: #EAEAEA;font-weight: bold;">';
             $workbookHTML .= '<img src="' . $itemLogoUrl . '"/>&nbsp;' . _WORKBOOK_ITEMS_COUNT . $value['position'];
             if ($value['item_title'] != '') {
                 $workbookHTML .= '&nbsp;-&nbsp;' . $value['item_title'];
             }
             $workbookHTML .= '</div>';
             if ($value['item_text'] != '') {
                 $workbookHTML .= '<div>' . $value['item_text'] . '</div>';
             }
             if ($value['item_question'] != '-1') {
                 $questionType = $lessonQuestions[$value['item_question']]['type'];
                 if ($workbookAnswers[$value['id']] == '') {
                     if ($questionType == 'drag_drop') {
                         $dragDrop = eF_getTableData("questions", "options, answer, text", "id=" . $value['item_question']);
                         $options = unserialize($dragDrop[0]['options']);
                         $answer = unserialize($dragDrop[0]['answer']);
                         shuffle($options);
                         shuffle($answer);
                         $workbookHTML .= $dragDrop[0]['text'];
                         for ($i = 0; $i < count($options); $i++) {
                             $workbookHTML .= '<div>' . $options[$i] . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
                             $workbookHTML .= $answer[$i] . '</div>';
                         }
                     } else {
                         $workbookHTML .= '<div>' . $value['question_text'] . '</div>';
                     }
                 } else {
                     $workbookHTML .= '<div>' . $workbookAnswers[$value['id']] . '</div>';
                 }
             }
             $workbookHTML .= '</div><br/>';
         }
         $workbookHTML = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', "", $workbookHTML);
         $pdf->writeHTML($workbookHTML, true, false, true, false, '');
         $fileName = _WORKBOOK_NAME . '_' . str_replace(' ', '_', $this->getWorkbookLessonName($currentLessonID)) . '.pdf';
         header("Content-type: application/pdf");
         header("Content-disposition: attachment; filename=" . $fileName);
         echo $pdf->Output('', 'S');
         exit(0);
     }
     if (isset($_GET['check_workbook_progress']) && $_GET['check_workbook_progress'] == '1') {
         $lessonStudents = $currentLesson->getUsers('student');
         $workbookStudents = array();
         foreach ($lessonStudents as $userLogin => $value) {
             if ($nonOptionalQuestionsNr != 0) {
                 $studentProgress = $this->getStudentProgress($userLogin, $currentLessonID);
                 $studentProgress .= '%';
             } else {
                 $studentProgress = '-';
             }
             $workbookStudents[$userLogin] = array('login' => $userLogin, 'progress' => $studentProgress);
         }
         $smarty->assign("T_WORKBOOK_STUDENTS", $workbookStudents);
     }
     if (isset($_GET['preview_workbook']) && $_GET['preview_workbook'] == '1' && isset($_GET['student']) && eF_checkParameter($_GET['student'], 'login')) {
         $userLogin = $_GET['student'];
         $studentProgress = $this->getStudentProgress($userLogin, $currentLessonID);
         $smarty->assign("T_WORKBOOK_PREVIEW_STUDENT_PROGRESS", $studentProgress);
         $workbookAnswers = $this->getWorkbookAnswers($userLogin, array_keys($workbookItems));
         $smarty->assign("T_WORKBOOK_PREVIEW_ANSWERS", $workbookAnswers);
     }
     if (isset($_GET['get_reset_message']) && $_GET['get_reset_message'] == '1') {
         echo $this->getResetMessage(array_keys($workbookItems));
         exit;
     }
     if (isset($_POST['item_submitted'])) {
         $itemID = $_POST['item_submitted'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $checkAnswer = $workbookItems[$itemID]['check_answer'];
         if (!in_array($questionID, array_keys($lessonQuestions))) {
             // reused item
             $reusedQuestion = $this->getReusedQuestionDetails($questionID);
             $questionType = $reusedQuestion['type'];
         } else {
             $questionType = $lessonQuestions[$questionID]['type'];
         }
         $question = QuestionFactory::factory($questionID);
         $question->setDone($_POST['question'][$questionID]);
         $results = $question->correct();
         if ($questionType != 'raw_text' && !ef_compare_float($results['score'], 1)) {
             print '-1';
         } else {
             $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
             $fields = array('item_id' => $itemID, 'html_solved' => $question->toHTMLSolved($form), 'users_LOGIN' => $currentUser->user['login']);
             eF_insertTableData("module_workbook_answers", $fields);
             if ($checkAnswer == '1') {
                 $this->updateStudentProgress($currentUser->user['login'], $currentLessonID, $questionPercentage, $nonOptionalQuestionsNr);
             }
             echo $question->toHTMLSolved($form);
         }
         eF_deleteTableData("module_workbook_autosave", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         exit(0);
     }
     if (isset($_POST['item_submitted_autosave'])) {
         $itemID = $_POST['item_submitted_autosave'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $question = QuestionFactory::factory($questionID);
         $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
         $form->setDefaults($_POST);
         $fields = array('item_id' => $itemID, 'autosave_text' => $question->toHTML($form), 'users_LOGIN' => $currentUser->user['login']);
         eF_deleteTableData("module_workbook_autosave", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         eF_insertTableData("module_workbook_autosave", $fields);
         exit(0);
     }
     if (isset($_POST['item_to_update'])) {
         $itemID = $_POST['item_to_update'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $question = QuestionFactory::factory($questionID);
         $question->userAnswer = urldecode($_POST['ans']);
         $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
         $form->setDefaults($_POST);
         print $question->toHTML($form);
         exit(0);
     }
     if (isset($_POST['item_updated'])) {
         $itemID = $_POST['item_updated'];
         $questionID = $workbookItems[$itemID]['item_question'];
         $question = QuestionFactory::factory($questionID);
         $question->setDone($_POST['question'][$questionID]);
         $form = new HTML_QuickForm("questionForm", "post", "", "", null, true);
         $answerToUpdate = eF_getTableData("module_workbook_answers", "id", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         eF_updateTableData("module_workbook_answers", array('html_solved' => $question->toHTMLSolved($form)), "id=" . $answerToUpdate[0]['id']);
         echo $question->toHTMLSolved($form);
         eF_deleteTableData("module_workbook_autosave", "item_id=" . $itemID . " AND users_LOGIN='******'login'] . "'");
         exit(0);
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor' || $currentUser->getRole($this->getCurrentLesson()) == 'student') {
             $workbookItems = $this->getWorkbookItems($currentLessonID);
             $smarty->assign("T_WORKBOOK_ITEMS", $workbookItems);
             $smarty->assign("T_WORKBOOK_LESSONS", $workbookLessons);
             $isWorkbookPublished = $this->isWorkbookPublished($currentLessonID);
             $smarty->assign("T_WORKBOOK_IS_PUBLISHED", $isWorkbookPublished);
             $smarty->assign("T_WORKBOOK_NON_OPTIONAL_QUESTIONS_NR", $nonOptionalQuestionsNr);
         }
         if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
             $workbookOptions[] = array('text' => _SETTINGS, 'image' => $this->moduleBaseLink . 'images/settings.png', 'href' => $this->moduleBaseUrl . '&edit_settings=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _SETTINGS . "', 0)", 'target' => 'POPUP_FRAME', 'id' => 'edit_settings');
             $workbookOptions[] = array('text' => _WORKBOOK_POPUP_INFO, 'image' => $this->moduleBaseLink . 'images/info.png', 'href' => $this->moduleBaseUrl . '&popup_info=1&popup=1', 'onClick' => "eF_js_showDivPopup(event, '" . _WORKBOOK_POPUP_INFO . "', 2)", 'target' => 'POPUP_FRAME', 'id' => 'popup_info');
             $smarty->assign("T_WORKBOOK_OPTIONS", $workbookOptions);
         } else {
             if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
                 $workbookAnswers = $this->getWorkbookAnswers($currentUser->user['login'], array_keys($workbookItems));
                 $smarty->assign("T_WORKBOOK_ANSWERS", $workbookAnswers);
                 $autoSaveAnswers = $this->getAutoSaveAnswers($currentUser->user['login'], array_keys($workbookItems));
                 $smarty->assign("T_WORKBOOK_AUTOSAVE_ANSWERS", $autoSaveAnswers);
                 $studentProgress = $this->getStudentProgress($currentUser->user['login'], $currentLessonID);
                 $smarty->assign("T_WORKBOOK_STUDENT_PROGRESS", $studentProgress);
                 $isWorkbookCompleted = $this->isWorkbookCompleted($currentUser->user['login'], $currentLessonID, array_keys($workbookItems), $nonOptionalQuestionsNr);
                 $smarty->assign("T_WORKBOOK_IS_COMPLETED", $isWorkbookCompleted);
             }
         }
     }
     if ($currentUser->getRole($this->getCurrentLesson()) == 'professor') {
         return $this->moduleBaseDir . "module_workbook_professor.tpl";
     } else {
         if ($currentUser->getRole($this->getCurrentLesson()) == 'student') {
             return $this->moduleBaseDir . "module_workbook_student.tpl";
         }
     }
 }
Example #20
0
             } catch (Exception $e) {
                 $errorMessages[] = $e->getMessage() . ' ' . $e->getCode();
             }
         }
     }
 }
 if (isset($_POST['deactivate_nodes']) && $_POST['deactivate_nodes']) {
     foreach ($_POST['deactivate_nodes'] as $value) {
         if (in_array($value, $legalValues) && eF_checkParameter($value, 'id')) {
             try {
                 // Deactivate also linked units
                 $linked_units = eF_getTableData('content', 'id', 'linked_to=' . $value);
                 foreach ($linked_units as $unit) {
                     $lessons_IDs = eF_getTableData('content', 'lessons_ID', 'id=' . $unit['id']);
                     foreach ($lessons_IDs as $lessons_ID) {
                         $lessonsContent = new EfrontContentTree($lessons_ID['lessons_ID']);
                         $lessonsContent->seekNode($unit['id'])->deactivate();
                     }
                 }
                 $currentContent->seekNode($value)->deactivate();
             } catch (Exception $e) {
                 $errorMessages[] = $e->getMessage() . ' ' . $e->getCode();
             }
         }
     }
 }
 if (isset($_POST['node_orders']) && $_POST['node_orders']) {
     //$nodeOrders        = explode(",", $_POST['node_orders']);
     $previousContentId = 0;
     $legalValues[] = 0;
     //Add 0 to possible content units, since both parent and previous units may be 0
Example #21
0
 /**
  * This function analyzes the manifest. In order to perform faster, manifest entities are analyzed one-by-one (on the fly)
  * during parsing and not stored into memory
  * Algorithm:
  * 1. Detect organization elements. Each one will consist a separate units structure inside efront
  * 2. Dive inside an organization and detect item elements. Each <item> corresponds to a "unit" in efront
  *
  *
  *
  *
  * @param $manifest
  * @return unknown_type
  */
 public static function import2($lesson, $manifest)
 {
     //@todo: parse $lesson
     //foreach ($namespaces as $prefix => $ns) {
     //$xml->registerXPathNamespace($prefix, $ns);
     //}
     //pr($xml -> xpath("$dfn:organizations/$dfn:organization/$dfn:item/adlcp:timeLimitAction"));
     $xml = simplexml_load_file(G_SCORMPATH . 'imsmanifest.xml', 'SimpleXMLIterator');
     $namespaces = $xml->getNamespaces(true);
     if (isset($namespaces[""])) {
         //See notes for xpath() in php.net site
         $dfn = "default";
         $xml->registerXPathNamespace($dfn, $namespaces[""]);
         // register a prefix for that default namespace:
         //$xml -> organizations -> registerXPathNamespace($dfn, $namespaces[""]);  	// register a prefix for that default namespace:
     }
     /**
      * Manifest (1/1): may contain the following elements:
      * - metadata (1/1)
      * - organizations (1/1)
      * - resources (1/1)
      * - manifest
      * - imsss:sequencingCollection (0/1)
      * And the following attributes
      * - identifier (xs:ID, m): unique identifier
      * - version (xs:string, o): manifest version
      * - xml:base (xs:anyURI, o): provides a relative path offset for the content file(s) contained in the manifest
      */
     $manifest['identifier'] = (string) $xml->attributes()->identifier;
     $manifest['version'] = (string) $xml->attributes()->version;
     //@todo: handle 'xml:base'
     //$manifest['xml:base']	= (string)$xml -> attributes() -> xml:base;
     /**
      * Metadata: may contain the following elements:
      * - schema (1/1)
      * - schemaversion (1/1)
      * - {metadata} (0/1)
      */
     $metadata['schema'] = (string) $xml->metadata->schema;
     $metadata['schemaversion'] = (string) $xml->metadata->schemaversion;
     //@todo: handle metadata
     /*
      * Organizations: may contain the following elements:
      * - organization (1/M)
      * And the following attributes:
      * - default (xs:IDREF, m): The id of the default organization
      */
     $organizations['default'] = (string) $xml->organizations->attributes();
     //@todo: check that default is actually an existing organization
     /*
      * Organization: may contain the following elements:
      * - title (1/1)
      * - item (1/M)
      * - metadata (0/1)
      * - imsss:sequencing
      * And the following attributes:
      * - identifier (xs:ID, m): identifier (unique within the manifest)
      * - structure (xs:string, o): Describes the shape of the organization (default: hierarchical)
      * - adlseq:objectivesGlobalToSystem (xs:boolean, o): self-explanatory ;)
      */
     foreach ($xml->organizations->organization as $org) {
         $org->registerXPathNamespace($dfn, $namespaces[""]);
         // register a prefix for that default namespace:
         $id = (string) $org->attributes()->identifier;
         $org->attributes()->structure ? $organization[$id]['structure'] = $org->attributes()->structure : ($organization[$id]['structure'] = 'hierarchical');
         $organization[$id]['title'] = $org->attributes()->title;
         //@todo: the importing may be done below existing elements, take this into account when considering $previousContentId (its initial value may not be 0)
         $contentTree = new EfrontContentTree($lesson);
         $previousContent = $contentTree->getLastNode() or $previousContent = array('id' => 0);
         //Create the "holding" unit, an empty unit that will hold this organization's elements
         $previousContent = $parentContent = EfrontUnit::createUnit(array('name' => $organization[$id]['title'], 'parent_content_ID' => 0, 'previous_content_ID' => $previousContent['id'], 'lessons_ID' => $lesson));
         //Get contents of the organization
         foreach ($org as $key => $value) {
             /*
              * Item: may contain the following elements:
              * - title (1/1)
              * - item 0/M
              * - metadata 0/1
              * - adlcp: timeLimitAction 0/1
              * - adlcp: dataFromLMS 0/1
              * - adlcp: completionThreshold 0/1
              * - imsss:sequencing
              * - adlnav:presentation
              * And the following attributes:
              * - identifier (xs:ID, m): a unique identifier
              * - identifierref (xs:string, o): a reference to a resource
              * - isvisible (xs:boolean, o): whether this item is displayed when the structure of the package is displayed or rendered (Default true)
              * - parameters (xs:string, o): static parameters to be passed to the resource at launch time (max 1000 chars)
              */
             if ($key == 'item') {
                 $itemId = (string) $value->attributes()->identifier;
                 //pr($value -> attributes() -> identifier);
                 $item = array('identifier' => $itemId, 'identifierref' => (string) $value->attributes()->identifierref, 'isvisible' => (string) $value->attributes()->isvisible, 'parameters' => (string) $value->attributes()->parameters, 'title' => (string) $value->title, 'timeLimitAction' => (string) reset($org->xpath("{$dfn}:item[@identifier='{$itemId}']/adlcp:timeLimitAction")), 'dataFromLMS' => (string) reset($org->xpath("{$dfn}:item[@identifier='{$itemId}']/adlcp:dataFromLMS")), 'completionThreshold' => (string) reset($org->xpath("{$dfn}:item[@identifier='{$itemId}']/adlcp:completionThreshold")));
                 //@todo:<imsss:sequencing>, <adlnav:presentation>
                 //@todo: nested items
                 //@todo: metadata
                 $previousContent = EfrontUnit::createUnit(array('name' => $item['title'], 'parent_content_ID' => $parentContent['id'], 'previous_content_ID' => $previousContent['id'], 'lessons_ID' => $lesson));
                 $items[$itemId] = $item['identifierref'];
             }
         }
         //@todo: handle adlseq:objectivesGlobalToSystem
     }
     /*
      * Resources: may contain the following elements:
      * - resource (0/M)
      * And the following attributes:
      * - xml:base (xs:anyURI, o): provides a relative path offset for the content file(s)
      */
     $resources = $xml->resources;
     $resources->registerXPathNamespace($dfn, $namespaces[""]);
     // register a prefix for that default namespace:
     /*
      * Resource: may contain the following elements:
      * - metadata (0/1)
      * - file (0/M)
      * - dependency (0/M)
      * And the following attributes:
      * - identifier (xs:ID, m): a unique identifier
      * - type (xs:string, m): the type of the resource
      * - href (xs:string, o): the �entry point� or �launching point� of this resource
      * - xml:base (xs:anyURI, o): a relative path offset for the files contained in the manifest
      * - adlcp:scormType (xs:string, m): the type of SCORM resource ("sco" or "asset")
      */
     foreach ($resources->resource as $key => $value) {
         $resourceId = (string) $value->attributes()->identifier;
         $resource = array('identifier' => $resourceId, 'type' => (string) $value->attributes()->type, 'href' => (string) $value->attributes()->href, 'base' => (string) $value->attributes($namespaces['xml'])->base, 'scormType' => (string) $value->attributes($namespaces['adlcp'])->scormType);
         /**
          * File: may contain the following elements:
          * - metadata (0/1)
          * And the following attributes:
          * - href (xs:string, m): identifies the location of the file
          */
         foreach ($value->file as $f) {
             $file = array('href' => (string) $f->attributes()->href);
         }
         /**
          * Dependency: may contain the following elements:
          * <none>
          * And the following attributes:
          * - identifierref (xs:string, m): an identifier attribute of a resource
          */
         foreach ($value->dependency as $d) {
             $dependency = array('identifierref' => (string) $d->attributes()->identifierref);
         }
     }
     //@todo: sequencingCollection
     //pr($organization);
     //    	$result = $xml -> xpath("//$dfn:manifest/$dfn:organizations/$dfn:organization");
     /*
     $iterator = new SimpleXMLIterator($xml -> asXML());
     foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST) as $key => $value) {
     
     }
     */
     /*
              //$iterator = new SimpleXMLIterator($data);
              //$iterator = simplexml_load_string($data, 'SimpleXMLIterator');
     */
 }
Example #22
0
                     $uploadedFiles[] = new EfrontFile($uploadDir . $additionalFile);
                 } else {
                     //Assign folders to the $emptyUnits array, so that we can create the empty units hierarchy from them
                     $emptyUnits[] = explode("/", trim($additionalFile, "/"));
                 }
             }
             //Create the empty Units hierarchy
             $currentContent = new EfrontContentTree($currentLesson);
             $treeStructure = $currentContent->createEmptyUnits($emptyUnits, $currentLesson->lesson['id']);
         }
     }
     $file->delete();
     //break;
 } else {
     if (!isset($currentContent)) {
         $currentContent = new EfrontContentTree($currentLesson);
     }
     foreach ($treeStructure as $key => $value) {
         end($value);
         $units[implode("/", $value)] = key($value);
     }
     $offset = str_replace($currentLesson->getDirectory(), "", $file['path']);
     $offsetDir = str_replace($currentLesson->getDirectory(), "", $file['directory']);
     $parentId = $units[dirname($offset)];
     $fields = array('name' => eFront_basename($file['name'], '.' . $pathParts['extension']), 'lessons_ID' => $currentLesson->lesson['id'], 'parent_content_ID' => $parentId ? $parentId : 0);
     $pathParts['extension'] = strtolower($pathParts['extension']);
     if ($pathParts['extension'] == 'pdf') {
         $fields['data'] = '<iframe src="' . $currentLesson->getDirectoryUrl() . '/' . $offset . '"  name="pdfaccept" width="100%" height="600"></iframe>';
         $unit = $currentContent->insertNode($fields);
     } elseif (in_array($pathParts['extension'], array_keys(FileSystemTree::getFileTypes('image')))) {
         $fields['data'] = '<img src="' . $currentLesson->getDirectoryUrl() . '/' . $offset . '" border="0" />';
Example #23
0
//General initializations and parameters
session_cache_limiter('none');
session_start();
$path = "../../libraries/";
/** The configuration file.*/
include_once $path . "configuration.php";
//Access is not allowed to users that are not logged in
if (isset($_SESSION['s_login']) && $_SESSION['s_password']) {
    try {
        $currentUser = EfrontUserFactory::factory($_SESSION['s_login']);
    } catch (EfrontException $e) {
        $message = $e->getMessage() . ' (' . $e->getCode() . ')';
        eF_redirect("index.php?message=" . urlencode($message) . "&message_type=failure");
        exit;
    }
} else {
    eF_redirect("index.php?message=" . urlencode(_YOUCANNOTACCESSTHISPAGE) . "&message_type=failure");
    exit;
}
$loadScripts = array('scriptaculous/prototype', 'EfrontScripts', 'drag-drop-folder-tree');
$contentTree = new EfrontContentTree($_SESSION['s_lessons_ID']);
$visitableIterator = new EfrontVisitableAndEmptyFilterIterator(new EfrontNodeFilterIterator(new RecursiveIteratorIterator(new RecursiveArrayIterator($contentTree->tree), RecursiveIteratorIterator::SELF_FIRST)));
$html = $contentTree->toHTML($visitableIterator, false, array('noclick' => true, 'onclick' => 'setLink(this)'));
$mainScripts = getMainScripts();
$smarty->assign("T_HEADER_MAIN_SCRIPTS", implode(",", $mainScripts));
$smarty->assign("T_CONTENT_TREE", $html);
$smarty->display("browsecontent.tpl");
?>