예제 #1
0
            // no need to connect to DB ...
            // $cistatus =  $dh->course_instance_status_get($sess_id_course_instance);
            $cistatus = $courseInstanceObj->status;
            if ($cistatus == ADA_COURSEINSTANCE_STATUS_PUBLIC and ($id_profile == AMA_TYPE_STUDENT or $id_profile == AMA_TYPE_GUEST)) {
                $user_status = ADA_STATUS_VISITOR;
            }
        }
    }
    //}
}
if (in_array('node', $thisUserNeededObjAr)) {
    /**
     *  get Node Object
     */
    $nodeObj = read_node_from_DB($id_node);
    if (ADA_Error::isError($nodeObj)) {
        $nodeObj->handleError();
    }
    $node_family = $nodeObj->template_family;
    $node_author_id = $nodeObj->author;
    $node_type = $nodeObj->type;
}
// FIXME: verificare bene questa parte
$reg_enabled = false;
// links to bookmarks disabled
$log_enabled = false;
// links to history disabled
$mod_enabled = false;
// links to modify nodes  disabled
$com_enabled = false;
// links to comunicate among users  disabled
예제 #2
0
 public static function render($layout_dataAr = array(), $content_dataAr = array(), $renderer = NULL, $options = array(), $menuoptions = array())
 {
     /**
      * @author giorgio 03/apr/2014
      * 
      * If query string wants a pdf, let's obey by setting the $renderer
      */
     if (isset($_GET['pdfExport']) && intval($_GET['pdfExport']) === 1) {
         $renderer = ARE_PDF_RENDER;
     }
     if (!isset($id_profile)) {
         $id_profile = null;
     }
     switch ($renderer) {
         case ARE_PRINT_RENDER:
             $layoutObj = read_layout_from_DB($id_profile, isset($layout_dataAr['family']) ? $layout_dataAr['family'] : '', isset($layout_dataAr['node_type']) ? $layout_dataAr['node_type'] : '', isset($layout_dataAr['node_author_id']) ? $layout_dataAr['node_author_id'] : '', isset($layout_dataAr['node_course_id']) ? $layout_dataAr['node_course_id'] : '', isset($layout_dataAr['module_dir']) ? $layout_dataAr['module_dir'] : '');
             // TODO: controlli su layoutObj
             $layout_template = $layoutObj->template;
             $layout_CSS = $layoutObj->CSS_filename;
             if (!empty($layout_dataAr['CSS_filename']) && is_array($layout_dataAr['CSS_filename'])) {
                 $tmp = explode(';', $layoutObj->CSS_filename);
                 $tmp = array_merge($tmp, $layout_dataAr['CSS_filename']);
                 //$tmp = array_merge($layout_dataAr['JS_filename'],$tmp);
                 $layoutObj->CSS_filename = implode(';', $tmp);
                 $layout_CSS = implode(';', $tmp);
             }
             /*
              * optional arguments for HTML constructor
              */
             $user_name = isset($options['user_name']) ? $options['user_name'] : '';
             $course_title = isset($options['course_title']) ? $options['course_title'] : '';
             $node_title = isset($options['node_title']) ? $options['user_name'] : '';
             $meta_keywords = isset($options['meta_keywords']) ? $options['meta_keywords'] : '';
             $author = isset($options['author']) ? $options['author'] : '';
             $meta_refresh_time = isset($options['meta_refresh_time']) ? $options['meta_refresh_time'] : '';
             $meta_refresh_url = isset($options['meta_refresh_url']) ? $options['meta_refresh_url'] : '';
             $onload_func = isset($options['onload_func']) ? $options['onload_func'] : '';
             $static_dir = isset($options['static_dir']) ? $options['static_dir'] : ROOT_DIR . 'services/media/cache/';
             $html_renderer = new HTML($layout_template, $layout_CSS, $user_name, $course_title, $node_title, $meta_keywords, $author, null, null, $onload_func, $layoutObj);
             $html_renderer->fillin_templateFN($content_dataAr);
             $imgpath = dirname($layout_template);
             $html_renderer->resetImgSrcFN($imgpath, isset($layoutObj->family) ? $layoutObj->family : ADA_TEMPLATE_FAMILY);
             $html_renderer->apply_styleFN();
             $html_renderer->outputFN('page');
             break;
         case ARE_XML_RENDER:
             $today = today_dateFN();
             $title = $options['course_title'];
             $portal = $options['portal'];
             $xml_renderer = new Generic_XML($portal, $today, $title);
             $xml_renderer->idNode = $options['id'];
             $xml_renderer->URL = $options['URL'];
             $xml_renderer->fillinFN($content_dataAr);
             $xml_renderer->outputFN('page');
             break;
         case ARE_FILE_RENDER:
             $layoutObj = read_layout_from_DB($id_profile, isset($layout_dataAr['family']) ? $layout_dataAr['family'] : null, isset($layout_dataAr['node_type']) ? $layout_dataAr['node_type'] : null, isset($layout_dataAr['node_author_id']) ? $layout_dataAr['node_author_id'] : null, isset($layout_dataAr['node_course_id']) ? $layout_dataAr['node_course_id'] : null, isset($layout_dataAr['module_dir']) ? $layout_dataAr['module_dir'] : null);
             // TODO: controlli su layoutObj
             $layout_template = $layoutObj->template;
             $layout_CSS = $layoutObj->CSS_filename;
             /*
              * optional arguments for HTML constructor
              */
             $user_name = isset($options['user_name']) ? $options['user_name'] : '';
             $course_title = isset($options['course_title']) ? $options['course_title'] : '';
             $node_title = isset($options['node_title']) ? $options['user_name'] : '';
             $meta_keywords = isset($options['meta_keywords']) ? $options['meta_keywords'] : '';
             $author = isset($options['author']) ? $options['author'] : '';
             $meta_refresh_time = isset($options['meta_refresh_time']) ? $options['meta_refresh_time'] : '';
             $meta_refresh_url = isset($options['meta_refresh_url']) ? $options['meta_refresh_url'] : '';
             $onload_func = isset($options['onload_func']) ? $options['onload_func'] : '';
             $static_dir = isset($options['static_dir']) ? $options['static_dir'] : ROOT_DIR . 'services/media/cache/';
             if (!file_exists($static_dir)) {
                 mkdir($static_dir);
             }
             $static_filename = md5($_SERVER['REQUEST_URI'] . $_SERVER['QUERY_STRING']);
             $cached_file = $static_dir . $static_filename;
             $html_renderer = new HTML($layout_template, $layout_CSS, $user_name, $course_title, $node_title, $meta_keywords, $author, $meta_refresh_time, $meta_refresh_url, $onload_func, $layoutObj);
             $html_renderer->full_static_filename = $cached_file;
             $html_renderer->static_filename = $static_filename;
             $html_renderer->fillin_templateFN($content_dataAr);
             $imgpath = dirname($layout_template);
             $html_renderer->resetImgSrcFN($imgpath, isset($layoutObj->family) ? $layoutObj->family : ADA_TEMPLATE_FAMILY);
             $html_renderer->apply_styleFN();
             $html_renderer->outputFN('file');
             break;
         case ARE_HTML_RENDER:
         case ARE_PDF_RENDER:
         default:
             $layoutObj = read_layout_from_DB($id_profile, isset($layout_dataAr['family']) ? $layout_dataAr['family'] : null, isset($layout_dataAr['node_type']) ? $layout_dataAr['node_type'] : null, isset($layout_dataAr['node_author_id']) ? $layout_dataAr['node_author_id'] : null, isset($layout_dataAr['node_course_id']) ? $layout_dataAr['node_course_id'] : null, isset($layout_dataAr['module_dir']) ? $layout_dataAr['module_dir'] : null);
             // TODO: controlli su layoutObj
             $layout_template = $layoutObj->template;
             $layout_CSS = $layoutObj->CSS_filename;
             /**
              * @author giorgio 19/ago/2014
              * 
              * fix javascript inclusion as follows:
              * - if the PhP has not included JQUERY, include it as first element
              * - if the PhP has not included SEMANTICUI_JS, include it just after JQUERY
              * - if the PhP has not included JQUERY_NO_CONFLICT include it as last element
              * 
              * This way, any PhP can include what it needs and in the right order of inclusion
              */
             /**
              * @author giorgio 10/nov/2014
              * 
              * If the browser is InternetExplorer 8 or less, use smartmenus instead of semantic-ui
              * 
              * NOTE: $_SESSION['IE-version'] is set by module_init_functions.inc.php
              */
             $JSToUse = isset($_SESSION['IE-version']) && $_SESSION['IE-version'] !== false && $_SESSION['IE-version'] <= 8 ? SMARTMENUS_JS : SEMANTICUI_JS;
             $CSSToUse = isset($_SESSION['IE-version']) && $_SESSION['IE-version'] !== false && $_SESSION['IE-version'] <= 8 ? SMARTMENUS_CSS : SEMANTICUI_CSS;
             if (!empty($layout_dataAr['JS_filename']) && is_array($layout_dataAr['JS_filename'])) {
                 // if jquery is not included in the script itself, add it at first position
                 if (!in_array(JQUERY, $layout_dataAr['JS_filename'])) {
                     $layout_dataAr['JS_filename'] = array_merge(array(JQUERY), $layout_dataAr['JS_filename']);
                 }
                 // if $JSToUse is not included in the script itself, add it just after JQUERY
                 if (!in_array($JSToUse, $layout_dataAr['JS_filename'])) {
                     // find the key for JQUERY
                     $key = array_search(JQUERY, $layout_dataAr['JS_filename']);
                     // add $JSToUse after JQUERY slicing the original array
                     $layout_dataAr['JS_filename'] = array_merge(array_slice($layout_dataAr['JS_filename'], 0, $key + 1), array($JSToUse), array_slice($layout_dataAr['JS_filename'], $key + 1));
                 }
                 // if jquery noconflict is not included in the script itself, add it at last position
                 if (!in_array(JQUERY_NO_CONFLICT, $layout_dataAr['JS_filename'])) {
                     array_push($layout_dataAr['JS_filename'], JQUERY_NO_CONFLICT);
                 }
                 $tmp = explode(';', $layoutObj->JS_filename);
                 $tmp = array_merge($tmp, $layout_dataAr['JS_filename']);
                 //$tmp = array_merge($layout_dataAr['JS_filename'],$tmp);
                 $layoutObj->JS_filename = implode(';', $tmp);
             } else {
                 // add jquery, semantic and jquery noconflict
                 $layoutObj->JS_filename .= ';' . JQUERY . ';' . $JSToUse . ';' . JQUERY_NO_CONFLICT;
             }
             $tmp = explode(';', $layoutObj->CSS_filename);
             if (!empty($layout_dataAr['CSS_filename']) && is_array($layout_dataAr['CSS_filename'])) {
                 $tmp = array_merge($tmp, $layout_dataAr['CSS_filename']);
             }
             /**
              * @author giorgio 06/ago/2014
              * add $CSSToUse last
              */
             $tmp[] = $CSSToUse;
             //$tmp = array_merge($layout_dataAr['JS_filename'],$tmp);
             $layoutObj->CSS_filename = implode(';', $tmp);
             $layout_CSS = implode(';', $tmp);
             /*
              * optional arguments for HTML constructor
              */
             $user_name = isset($options['user_name']) ? $options['user_name'] : '';
             $course_title = isset($options['course_title']) ? $options['course_title'] : '';
             $node_title = isset($options['node_title']) ? $options['user_name'] : '';
             $meta_keywords = isset($options['meta_keywords']) ? $options['meta_keywords'] : '';
             $author = isset($options['author']) ? $options['author'] : '';
             $meta_refresh_time = isset($options['meta_refresh_time']) ? $options['meta_refresh_time'] : '';
             $meta_refresh_url = isset($options['meta_refresh_url']) ? $options['meta_refresh_url'] : '';
             $onload_func = isset($options['onload_func']) ? $options['onload_func'] : '';
             /**
              * @author giorgio 19/ago/2014
              *
              * make menu here
              */
             require_once ROOT_DIR . '/include/menu_class.inc.php';
             // menu property created 'on-the-fly'
             $layoutObj->menu = new Menu($layoutObj->module_dir, basename($_SERVER['SCRIPT_FILENAME']), $_SESSION['sess_userObj']->getType(), $menuoptions);
             if ($renderer == ARE_PDF_RENDER) {
                 $orientation = isset($options['orientation']) ? $options['orientation'] : '';
                 $outputfile = isset($options['outputfile']) ? $options['outputfile'] : '';
                 // must be called $html_renderer for below code, but it's not :)
                 $html_renderer = new PDF($layout_template, $layout_CSS, $user_name, $course_title, $node_title, $meta_keywords, $author, $meta_refresh_time, $meta_refresh_url, $onload_func, $layoutObj, $outputfile, $orientation);
             } else {
                 $html_renderer = new HTML($layout_template, $layout_CSS, $user_name, $course_title, $node_title, $meta_keywords, $author, $meta_refresh_time, $meta_refresh_url, $onload_func, $layoutObj);
             }
             /**
              * @author giorgio 25/set/2013
              * merge the content_dataAr with the one generated by the widgets if it's needed
              */
             if (!is_null($layoutObj->WIDGET_filename)) {
                 if (!isset($layout_dataAr['widgets'])) {
                     $layout_dataAr['widgets'] = '';
                 }
                 $widgets_dataAr = $html_renderer->fillin_widgetsFN($layoutObj->WIDGET_filename, $layout_dataAr['widgets']);
                 if (!ADA_Error::isError($widgets_dataAr)) {
                     $content_dataAr = array_merge($content_dataAr, $widgets_dataAr);
                 }
             }
             /**
              * adamenu must be the first key of $content_dataAr
              * for the template_field substitution to work inside the menu
              */
             $content_dataAr = array('adamenu' => $layoutObj->menu->getHtml()) + $content_dataAr;
             $content_dataAr['isVertical'] = $layoutObj->menu->isVertical() ? ' vertical' : '';
             $html_renderer->fillin_templateFN($content_dataAr);
             $imgpath = dirname($layout_template);
             // $html_renderer->resetImgSrcFN($imgpath,$template_family);
             $html_renderer->resetImgSrcFN($imgpath, $layoutObj->family);
             $html_renderer->apply_styleFN();
             $html_renderer->outputFN($renderer == ARE_PDF_RENDER ? 'pdf' : 'page');
             break;
     }
 }
예제 #3
0
function parameter_controlFN($neededObjAr = array(), $allowedUsersAr = array())
{
    $invalid_session = FALSE;
    $invalid_user = FALSE;
    $invalid_node = FALSE;
    $invalid_course = FALSE;
    $invalid_course_instance = FALSE;
    $invalid_user_level = FALSE;
    $guest_user_not_allowed = FALSE;
    /*
     * ADA common data handler
     */
    $common_dh = isset($GLOBALS['common_dh']) ? $GLOBALS['common_dh'] : null;
    if (!$common_dh instanceof AMA_Common_DataHandler) {
        $common_dh = AMA_Common_DataHandler::instance();
        $GLOBALS['common_dh'] = $common_dh;
    }
    /*
     * User object: always load a user
     */
    $sess_id_user = isset($_SESSION['sess_id_user']) ? (int) $_SESSION['sess_id_user'] : 0;
    $sess_userObj = read_user($sess_id_user);
    if (ADA_Error::isError($sess_userObj)) {
        $sess_userObj->handleError();
    }
    $_SESSION['sess_id_user'] = $sess_id_user;
    if ($sess_userObj instanceof ADAGenericUser) {
        $_SESSION['sess_userObj'] = $sess_userObj;
        /*
         * Check if this user is allowed to access the current module
         */
        if (!in_array($sess_userObj->getType(), $allowedUsersAr)) {
            header('Location: ' . $sess_userObj->getHomePage());
            exit;
        }
    } else {
        unset($_SESSION['sess_userObj']);
        $invalid_user = TRUE;
    }
    $id_profile = $sess_userObj->getType();
    /*
     * Get needed object for this user from $neededObjAr 
     */
    if (is_array($neededObjAr) && isset($neededObjAr[$id_profile]) && is_array($neededObjAr[$id_profile])) {
        $thisUserNeededObjAr = $neededObjAr[$id_profile];
    } else {
        $thisUserNeededObjAr = array();
    }
    /*
     * 
     * 'default_tester' AL MOMENTO VIENE RICHIESTO SOLO DA USER.php
     * QUI ABBIAMO NECESSITA' DI CANCELLARE LA VARIABILE DI SESSIONE
     * sess_id_course.
     * Gia' che ci siamo facciamo unset anche di sess_id_node 
     * e di sess_id_course_instance
     * 
     * Tester selection: 
     * 
     * se ho richiesto la connessione al database del tester di default, 
     * controllo che il tipo di utente sia ADAUser (al momento e' l'unico ad
     * avere questa necessita').
     * 
     * se non ho richiesto la connessione al tester di default, allora verifico
     * se l'utente e' di tipo ADAUser, e ottengo la connessione al database
     * tester appropriato. 
     */
    if (in_array('default_tester', $thisUserNeededObjAr) && $id_profile == AMA_TYPE_STUDENT) {
        $_SESSION['sess_selected_tester'] = NULL;
        unset($_SESSION['sess_id_course']);
        unset($_SESSION['sess_id_course_instance']);
        unset($_SESSION['sess_id_node']);
    } else {
        if ($id_profile == AMA_TYPE_STUDENT) {
            if (isset($_REQUEST['id_course'])) {
                $id_course = DataValidator::is_uinteger($_REQUEST['id_course']);
            } else {
                $id_course = false;
            }
            if (isset($_SESSION['sess_id_course'])) {
                $sess_id_course = DataValidator::is_uinteger($_SESSION['sess_id_course']);
            } else {
                $sess_id_course = false;
            }
            if (isset($_REQUEST['id_node'])) {
                $req_id_node = DataValidator::validate_node_id($_REQUEST['id_node']);
            } else {
                $req_id_node = false;
            }
            if ($id_course === FALSE && $sess_id_course === FALSE && $req_id_node !== FALSE) {
                $id_course = substr($req_id_node, 0, strpos($req_id_node, '_'));
            }
            if ($id_course !== FALSE && $id_course !== $sess_id_course) {
                $tester_infoAr = $common_dh->get_tester_info_from_id_course($id_course);
                if (AMA_Common_DataHandler::isError($tester_infoAr)) {
                    $selected_tester = NULL;
                } else {
                    $selected_tester = $tester_infoAr['puntatore'];
                }
                $_SESSION['sess_selected_tester'] = $selected_tester;
            }
        }
    }
    /* 
     * ADA tester data handler
     * Data validation on $sess_selected_tester is performed by MultiPort::getDSN()
     */
    /**
     * giorgio 12/ago/2013
     * set selected tester if it's not a multiprovider environment
     */
    if (!MULTIPROVIDER && isset($GLOBALS['user_provider'])) {
        $sess_selected_tester = $GLOBALS['user_provider'];
    } else {
        $sess_selected_tester = isset($_SESSION['sess_selected_tester']) ? $_SESSION['sess_selected_tester'] : null;
    }
    //$dh = AMA_DataHandler::instance(MultiPort::getDSN($sess_selected_tester));
    $sess_selected_tester_dsn = MultiPort::getDSN($sess_selected_tester);
    $_SESSION['sess_selected_tester_dsn'] = $sess_selected_tester_dsn;
    $dh = new AMA_DataHandler($sess_selected_tester_dsn);
    $GLOBALS['dh'] = $dh;
    if (empty($GLOBALS['sess_id'])) {
        $invalid_session = TRUE;
    }
    /*
     * Node object
     */
    // TODO: portare in sessione $nodeObj?
    if (in_array('node', $thisUserNeededObjAr)) {
        $id_node = isset($_REQUEST['id_node']) ? DataValidator::validate_node_id($_REQUEST['id_node']) : false;
        $sess_id_node = isset($_SESSION['sess_id_node']) ? DataValidator::validate_node_id($_SESSION['sess_id_node']) : false;
        if ($id_node !== FALSE) {
            $dataHa = $dh->get_node_info($id_node);
            if (AMA_DataHandler::isError($dataHa) || !is_array($dataHa)) {
                $invalid_node = TRUE;
            } else {
                $_SESSION['sess_id_node'] = $id_node;
            }
        } elseif ($sess_id_node !== FALSE) {
            $dataHa = $dh->get_node_info($sess_id_node);
            if (AMA_DataHandler::isError($dataHa) || !is_array($dataHa)) {
                $invalid_node = TRUE;
            } else {
                $_SESSION['sess_id_node'] = $sess_id_node;
            }
        } else {
            $invalid_node = TRUE;
        }
        /**
         * @author giorgio 18/mag/2015
         * 
         * Could be that a non-student has request a node from
         * the default tester in a multiprovider environment
         * Check this before giving up an marking the node as invalid
         */
        if (MULTIPROVIDER && $id_profile != AMA_TYPE_STUDENT && $invalid_node === true && $id_node !== false) {
            $invalid_node = checkAndSetPublicTester('node', $id_node);
        }
    }
    /*
     * Course object
     */
    if (in_array('course', $thisUserNeededObjAr)) {
        $id_course = isset($_REQUEST['id_course']) ? DataValidator::is_uinteger($_REQUEST['id_course']) : false;
        $sess_id_course = isset($_SESSION['sess_id_course']) ? DataValidator::is_uinteger($_SESSION['sess_id_course']) : false;
        /* extracting the course id from node id, if given */
        if (isset($_SESSION['sess_id_node']) && !$invalid_node && $id_course === false) {
            //    if ($nodeObj instanceof Node){
            $courseIdFromNodeId = substr($_SESSION['sess_id_node'], 0, strpos($_SESSION['sess_id_node'], '_'));
            $sess_courseObj = read_course($courseIdFromNodeId);
            if (ADA_Error::isError($sess_courseObj)) {
                unset($_SESSION['sess_courseObj']);
                $invalid_course = TRUE;
            } else {
                if ($sess_userObj instanceof ADAGuest && !$sess_courseObj->getIsPublic()) {
                    unset($_SESSION['sess_courseObj']);
                    $invalid_course = TRUE;
                } else {
                    $_SESSION['sess_courseObj'] = $sess_courseObj;
                    $_SESSION['sess_id_course'] = $courseIdFromNodeId;
                }
            }
        } elseif ($id_course !== FALSE) {
            $sess_courseObj = read_course($id_course);
            if (ADA_Error::isError($sess_courseObj)) {
                unset($_SESSION['sess_courseObj']);
                $invalid_course = TRUE;
            } else {
                if ($sess_userObj instanceof ADAGuest && !$sess_courseObj->getIsPublic()) {
                    unset($_SESSION['sess_courseObj']);
                    $invalid_course = TRUE;
                } else {
                    $_SESSION['sess_courseObj'] = $sess_courseObj;
                    $_SESSION['sess_id_course'] = $id_course;
                }
            }
        } elseif ($sess_id_course !== FALSE) {
            $sess_courseObj = read_course($sess_id_course);
            if (ADA_Error::isError($sess_courseObj)) {
                unset($_SESSION['sess_courseObj']);
                $invalid_course = TRUE;
            } else {
                if ($sess_userObj instanceof ADAGuest && !$sess_courseObj->getIsPublic()) {
                    unset($_SESSION['sess_courseObj']);
                    $invalid_course = TRUE;
                } else {
                    $_SESSION['sess_courseObj'] = $sess_courseObj;
                    $_SESSION['sess_id_course'] = $sess_courseObj->getId();
                }
            }
        } else {
            unset($_SESSION['sess_courseObj']);
            $invalid_course = TRUE;
        }
        /**
         * @author giorgio 18/mag/2015
         *
         * Could be that a non-student has request a course from
         * the default tester in a multiprovider environment
         * Check this before giving up an marking the course as invalid
         */
        if (MULTIPROVIDER && $id_profile != AMA_TYPE_STUDENT && $invalid_course === true && ($id_course !== false || $sess_id_course !== false)) {
            $invalid_course = checkAndSetPublicTester('course', $id_course !== false ? $id_course : $sess_id_course);
            if ($invalid_course === false) {
                $invalid_node = false;
                $sess_courseObj = $_SESSION['sess_courseObj'];
                // SESSION set by checkAndSetPublicTester
            }
        }
    } else {
        unset($_SESSION['sess_courseObj']);
    }
    /**
     * If in a valid NON PUBLIC course and user is student or tutor
     * and
     *  $_SESSION['sess_id_course'] (that is the course_id the user is going into)
     * 	IS NOT EQUAL TO
     *  $sess_id_course (that is the course_id the user is coming form)
     *  
     *  The user has clicked a cross course link, and is handled by unsetting the
     *  $_SESSION['sess_id_course_instance'] and looking for a course instance
     *  to which the user is subscribed.
     *  
     */
    if ($invalid_course === FALSE && $invalid_node === FALSE && isset($sess_courseObj) && !$sess_courseObj->getIsPublic() && in_array($sess_userObj->getType(), array(AMA_TYPE_STUDENT, AMA_TYPE_TUTOR)) && is_numeric($sess_id_course) && intval($_SESSION['sess_id_course']) !== intval($sess_id_course)) {
        /**
         * unset sess_id_course_instance
         */
        unset($_SESSION['sess_id_course_instance']);
        /**
         * Try to find an instance of target course where used is subscribed
         */
        $getAll = true;
        /**
         * Need to get instance the user is allowed to browse, based on user type
         */
        switch ($sess_userObj->getType()) {
            case AMA_TYPE_STUDENT:
                $instances = $dh->get_course_instance_for_this_student_and_course_model($sess_userObj->getId(), $_SESSION['sess_id_course'], $getAll);
                break;
            case AMA_TYPE_TUTOR:
                $instances = $dh->get_course_instance_for_this_student_and_course_model($sess_userObj->getId(), $_SESSION['sess_id_course'], $getAll);
                if (AMA_DB::isError($instances) || !is_array($instances) || count($instances) <= 0) {
                    $instances = array();
                }
                $tutorInstances = $dh->get_tutors_assigned_course_instance($sess_userObj->getId(), $_SESSION['sess_id_course'], $sess_userObj->isSuper());
                if (!AMA_DB::isError($tutorInstances) && is_array($tutorInstances) && count($tutorInstances) > 0) {
                    /**
                     * the returned array is array[id_tutor]=>array[key]=>array['id_istanza_corso']
                     * and needs to be converted to reflect the structre returned in student case
                     */
                    foreach ($tutorInstances[$sess_userObj->getId()] as $tutorInstance) {
                        $instances[]['id_istanza_corso'] = $tutorInstance['id_istanza_corso'];
                    }
                }
                break;
        }
        if (!AMA_DB::isError($instances) && count($instances) > 0) {
            if (count($instances) == 1) {
                /**
                 * User is subscribed to one instance only, good!
                 * Set the $target_course_instance var and proceed
                 */
                $target_course_instance = $instances[0]['id_istanza_corso'];
            } else {
                if (count($instances) > 1 && !isset($_REQUEST['id_course_instance'])) {
                    /**
                     * If there's more than one instance, must build an array of
                     * found instances to ask the user to select one.
                     * 
                     * This array is returned in the 'course' key of the returned
                     * array and so $invalid_course must be populated accordingly.
                     * 
                     * The node that was requested is returned in the 'node' key of
                     * the returned array and so $invalid_node must be populated. 
                     */
                    foreach ($instances as $instance) {
                        $invalid_course[] = $instance['id_istanza_corso'];
                        $invalid_node = $_SESSION['sess_id_node'];
                    }
                } else {
                    if (isset($_REQUEST['id_course_instance'])) {
                        $target_course_instance = $_REQUEST['id_course_instance'];
                    }
                }
            }
        } else {
            /**
             * Mark the course as invalid, and unset session var
             */
            $invalid_course = TRUE;
            unset($_SESSION['sess_id_course']);
        }
    }
    /*
     * Course_instance object
     */
    if (in_array('course_instance', $thisUserNeededObjAr)) {
        /*
         * Se ci troviamo nel tester pubblico, allora non dobbiamo leggere un'istanza corso
         * dato che non ce ne sono.
         */
        if (!$invalid_course && !$sess_courseObj->getIsPublic()) {
            if (isset($target_course_instance)) {
                $id_course_instance = DataValidator::is_uinteger($target_course_instance);
            } else {
                if (isset($_REQUEST['id_course_instance'])) {
                    $id_course_instance = DataValidator::is_uinteger($_REQUEST['id_course_instance']);
                    // FIXME: qui ci va $_REQUEST['id_course_instance']
                } else {
                    $id_course_instance = false;
                }
            }
            $sess_id_course_instance = isset($_SESSION['sess_id_course_instance']) ? DataValidator::is_uinteger($_SESSION['sess_id_course_instance']) : false;
            if ($id_course_instance !== FALSE) {
                $course_instanceObj = read_course_instance_from_DB($id_course_instance);
                if (ADA_Error::isError($course_instanceObj)) {
                    $invalid_course_instance = TRUE;
                } else {
                    $UserType = $sess_userObj->getType();
                    switch ($sess_userObj->getType()) {
                        case AMA_TYPE_STUDENT:
                            $studentLevel = $dh->_get_student_level($sess_id_user, $id_course_instance);
                            if (AMA_DataHandler::isError($studentLevel)) {
                                $invalid_course_instance = TRUE;
                            }
                            break;
                        case AMA_TYPE_TUTOR:
                            if (!$sess_userObj->isSuper() && $course_instanceObj->getServiceLevel() != ADA_SERVICE_TUTORCOMMUNITY) {
                                $tutorsInstance = $dh->course_instance_tutor_get($id_course_instance, $number = 2);
                                if (AMA_DataHandler::isError($tutorsInstance)) {
                                    $invalid_course_instance = TRUE;
                                } elseif (!in_array($sess_id_user, $tutorsInstance)) {
                                    $invalid_course_instance = TRUE;
                                }
                            }
                            break;
                        default:
                            //                  $invalid_course_instance = TRUE;
                            break;
                    }
                    if (!$invalid_course_instance) {
                        $_SESSION['sess_id_course_instance'] = $id_course_instance;
                        $sess_id_course_instance = $_SESSION['sess_id_course_instance'];
                    }
                }
            } elseif ($sess_id_course_instance !== FALSE) {
                $instanceIdRequired = array();
                if (isset($_SESSION['sess_id_node']) && !$invalid_node) {
                    //        if ($nodeObj instanceof Node) { // required a node
                    $instanceIdRequired[] = isset($dataHa['instance']) ? $dataHa['instance'] : null;
                    if ($instanceIdRequired[0] == 0) {
                        // the node is NOT a note
                        $field_list_ar = array();
                        if (isset($_SESSION['sess_id_course']) && !$invalid_course) {
                            $courseIdRequired = $_SESSION['sess_id_course'];
                            $InstanceIdList = $dh->course_instance_get_list($field_list_ar, $courseIdRequired);
                            if (AMA_DataHandler::isError($InstanceIdList) || count($InstanceIdList) == 0) {
                                $invalid_course_instance = TRUE;
                            }
                        } else {
                            $invalid_course_instance = TRUE;
                        }
                        $instanceIdRequired = array();
                        foreach ($InstanceIdList as $InstanceId) {
                            array_push($instanceIdRequired, $InstanceId[0]);
                        }
                    }
                    // end if NOTE
                } elseif ($sess_courseObj instanceof Course) {
                    $courseIdRequired = $sess_courseObj->id;
                    $InstanceIdList = $dh->course_instance_get_list(array(), $courseIdRequired);
                    if (AMA_DataHandler::isError($InstanceIdList) || count($InstanceIdList) == 0) {
                        $invalid_course_instance = TRUE;
                    }
                    $instanceIdRequired = array();
                    foreach ($InstanceIdList as $InstanceId) {
                        array_push($instanceIdRequired, $InstanceId[0]);
                    }
                }
                //          var_dump($instanceIdRequired,$sess_id_course_instance);
                $UserType = $sess_userObj->getType();
                switch ($UserType) {
                    case AMA_TYPE_STUDENT:
                    case AMA_TYPE_TUTOR:
                        if (!in_array($sess_id_course_instance, $instanceIdRequired)) {
                            $invalid_course_instance = TRUE;
                        }
                        break;
                    case AMA_TYPE_SWITCHER:
                    case AMA_TYPE_AUTHOR:
                    default:
                        break;
                }
                //end switch UserType
                $course_instanceObj = read_course_instance_from_DB($sess_id_course_instance);
                if (ADA_Error::isError($course_instanceObj)) {
                    $course_instanceObj->handleError();
                }
                $_SESSION['sess_id_course_instance'] = $sess_id_course_instance;
            } else {
                $invalid_course_instance = TRUE;
            }
        }
        //end isUserBrowsingThePublicTester
    }
    // end if in_array
    /*
     * Check if current user is a ADAGuest user and that he/she has requested
     * a public course instance.
     */
    //
    //  if(in_array('user', $neededObjAr[$user_type]) && in_array('course_instance', $neededObjAr[$user_type])) {
    //    if(!$invalid_user && $sess_userObj instanceof ADAGuest) {
    //      if ($invalid_course_instance || $course_instanceObj->status != ADA_COURSEINSTANCE_STATUS_PUBLIC) {
    //        $guest_user_not_allowed = TRUE;
    //      }
    //    }
    //  }
    // TODO: controllo livello utente
    /*
     * controllare che sia settato $sess_user_level e che il valore sia tra 0 e
     * ADA_MAX_USER_LEVEL
     */
    $parm_errorHa = array('session' => $invalid_session, 'user' => $invalid_user, 'user_level' => $invalid_user_level, 'course' => $invalid_course, 'course_instance' => $invalid_course_instance, 'node' => $invalid_node, 'guest_user_not_allowed' => $guest_user_not_allowed);
    return $parm_errorHa;
}
예제 #4
0
// e ci aggiunge l'id dell'istanza corso
$help = translateFN("Da qui lo studente può rivedere i propri esercizi.");
if (!isset($status)) {
    $status = '';
}
$courseInstanceObj = new Course_instance($id_course_instance);
$courseObj = new Course($courseInstanceObj->id_corso);
$course_title = $courseObj->titolo;
//show course istance name if isn't empty - valerio
if (!empty($courseInstanceObj->title)) {
    $course_title .= ' - ' . $courseInstanceObj->title;
}
if (!is_object($nodeObj)) {
    $nodeObj = read_node_from_DB($node);
}
if (!ADA_Error::isError($nodeObj) and isset($courseObj->id)) {
    $_SESSION['sess_id_course'] = $courseObj->id;
    $node_path = $nodeObj->findPathFN();
}
/*
 * Last access link
 */
if (isset($_SESSION['sess_id_course_instance'])) {
    $last_access = $userObj->get_last_accessFN($_SESSION['sess_id_course_instance'], "UT", null);
    $last_access = AMA_DataHandler::ts_to_date($last_access);
} else {
    $last_access = $userObj->get_last_accessFN(null, "UT", null);
    $last_access = AMA_DataHandler::ts_to_date($last_access);
}
if ($last_access == '' || is_null($last_access)) {
    $last_access = '-';
예제 #5
0
 */
if (is_array($neededObjAr) && isset($neededObjAr[$id_profile]) && is_array($neededObjAr[$id_profile])) {
    $thisUserNeededObjAr = $neededObjAr[$id_profile];
} else {
    $thisUserNeededObjAr = array();
}
if (in_array('course', $thisUserNeededObjAr)) {
    /**
     *  get Course object
     */
    /**
     * @var Object
     */
    $courseObj = read_course($sess_id_course);
    //mydebug(__LINE__,__FILE__,$courseObj);
    if (ADA_Error::isError($courseObj)) {
        $courseObj->handleError();
    } else {
        //mydebug(__LINE__,__FILE__,$courseObj);
        $course_title = $courseObj->titolo;
        //title
        $id_toc = $courseObj->id_nodo_toc;
        //id_toc_node
        $course_media_path = $courseObj->media_path;
        $course_author_id = $courseObj->id_autore;
        $course_family = $courseObj->template_family;
        $course_static_mode = $courseObj->static_mode;
    }
    if (empty($course_media_path)) {
        $media_path = MEDIA_PATH_DEFAULT . $course_author_id . "/";
    } else {