Example #1
0
 /**
  * @return void  Directly redirects the user or leaves him where he is, but doesn't return anything
  * @param int $userId
  * @param bool $logout_redirect
  * @author Fernando P. García <*****@*****.**>
  */
 public static function logout($user_id = null, $logout_redirect = false)
 {
     global $extAuthSource;
     // Database table definition
     $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
     if (empty($user_id)) {
         $user_id = api_get_user_id();
     }
     $user_id = intval($user_id);
     // Changing global chat status to offline
     if (api_is_global_chat_enabled()) {
         $chat = new Chat();
         $chat->set_user_status(0);
     }
     // selecting the last login of the user
     $sql_last_connection = "SELECT login_id, login_date FROM {$tbl_track_login}\n                              WHERE login_user_id='{$user_id}' ORDER BY login_date DESC LIMIT 0,1";
     $q_last_connection = Database::query($sql_last_connection);
     $i_id_last_connection = null;
     if (Database::num_rows($q_last_connection) > 0) {
         $i_id_last_connection = Database::result($q_last_connection, 0, "login_id");
     }
     if (!isset($_SESSION['login_as']) && !empty($i_id_last_connection)) {
         $current_date = api_get_utc_datetime();
         $s_sql_update_logout_date = "UPDATE {$tbl_track_login} SET logout_date='" . $current_date . "' WHERE login_id = '{$i_id_last_connection}'";
         Database::query($s_sql_update_logout_date);
     }
     Online::loginDelete($user_id);
     //from inc/lib/online.inc.php - removes the "online" status
     //the following code enables the use of an external logout function.
     //example: define a $extAuthSource['ldap']['logout']="file.php" in configuration.php
     // then a function called ldap_logout() inside that file
     // (using *authent_name*_logout as the function name) and the following code
     // will find and execute it
     $uinfo = api_get_user_info($user_id);
     if (isset($uinfo['auth_source']) && $uinfo['auth_source'] != PLATFORM_AUTH_SOURCE && is_array($extAuthSource)) {
         if (is_array($extAuthSource[$uinfo['auth_source']])) {
             $subarray = $extAuthSource[$uinfo['auth_source']];
             if (!empty($subarray['logout']) && file_exists($subarray['logout'])) {
                 require_once $subarray['logout'];
                 $logout_function = $uinfo['auth_source'] . '_logout';
                 if (function_exists($logout_function)) {
                     $logout_function($uinfo);
                 }
             }
         }
     }
     require_once api_get_path(SYS_PATH) . 'main/chat/chat_functions.lib.php';
     exit_of_chat($user_id);
     if ($logout_redirect) {
         header("Location: index.php");
         exit;
     }
 }
Example #2
0
 static function loadSettings($var = null)
 {
     Database::DB()->select('settings');
     if ($var) {
         Database::DB()->where('var', $var, 'IN');
     }
     Database::DB()->exec();
     if (Database::result()->num_rows == 0) {
         throw new Exception('Ошибка при загрузке настроек');
     }
     $arg = array();
     while ($row = Database::result()->fetch_assoc()) {
         $arg[$row['var']] = $row['val'];
     }
     if (is_string($var)) {
         return $arg[$var];
     }
     return $arg;
 }
Example #3
0
 $total_students = count($a_students);
 $sqlExercices = "SELECT count(id) as count FROM " . $t_quiz . " AS quiz WHERE active='1' AND c_id = {$course_id} ";
 $resultExercices = Database::query($sqlExercices);
 $data_exercises = Database::store_result($resultExercices);
 $exercise_count = $data_exercises[0]['count'];
 if ($global) {
     if ($exercise_count == 0) {
         $exercise_count = 2;
     }
     $html_result .= "<tr class='{$s_css_class}'>\n                                <td rowspan={$exercise_count}>";
     $html_result .= $current_course['title'];
     $html_result .= "</td>";
 }
 $sql = "SELECT visibility FROM {$table} WHERE c_id = {$course_id} AND name='quiz'";
 $resultVisibilityQuizz = Database::query($sql);
 if (Database::result($resultVisibilityQuizz, 0, 'visibility') == 1) {
     $sqlExercices = "    SELECT quiz.title,id FROM " . $t_quiz . " AS quiz WHERE c_id = {$course_id}  AND active='1' ORDER BY quiz.title ASC";
     //Getting the exam list
     if (!$global) {
         if (!empty($exercise_id)) {
             $sqlExercices = "    SELECT quiz.title,id FROM " . $t_quiz . " AS quiz WHERE c_id = {$course_id}  AND active='1' AND id = {$exercise_id} ORDER BY quiz.title ASC";
         }
     }
     $resultExercices = Database::query($sqlExercices);
     $i = 0;
     if (Database::num_rows($resultExercices) > 0) {
         while ($a_exercices = Database::fetch_array($resultExercices)) {
             $global_row[] = $current_course['title'];
             if (!$global) {
                 $html_result .= "<tr class='{$s_css_class}'>";
             }
Example #4
0
 /**
  * Unset a document as template
  *
  * @param int $document_id
  * @param string $couse_code
  * @param int $user_id
  */
 public static function unset_document_as_template($document_id, $course_code, $user_id)
 {
     $table_template = Database::get_main_table(TABLE_MAIN_TEMPLATES);
     $course_code = Database::escape_string($course_code);
     $user_id = Database::escape_string($user_id);
     $document_id = Database::escape_string($document_id);
     $sql = 'SELECT id FROM ' . $table_template . ' WHERE course_code="' . $course_code . '" AND user_id="' . $user_id . '" AND ref_doc="' . $document_id . '"';
     $result = Database::query($sql);
     $template_id = Database::result($result, 0, 0);
     FileManager::my_delete(api_get_path(SYS_CODE_PATH) . 'upload/template_thumbnails/' . $template_id . '.jpg');
     $sql = 'DELETE FROM ' . $table_template . ' WHERE course_code="' . $course_code . '" AND user_id="' . $user_id . '" AND ref_doc="' . $document_id . '"';
     Database::query($sql);
 }
 /**
  *
  * @param int   student id
  * @param int   years
  * @param bool  show warning_message
  * @param bool  return_timestamp
  */
 public static function delete_inactive_student($student_id, $years = 2, $warning_message = false, $return_timestamp = false)
 {
     $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
     $sql = 'SELECT login_date FROM ' . $tbl_track_login . '
             WHERE login_user_id = ' . intval($student_id) . '
             ORDER BY login_date DESC LIMIT 0,1';
     if (empty($years)) {
         $years = 1;
     }
     $inactive_time = $years * 31536000;
     //1 year
     $rs = Database::query($sql);
     if (Database::num_rows($rs) > 0) {
         if ($last_login_date = Database::result($rs, 0, 0)) {
             $last_login_date = api_get_local_time($last_login_date, null, date_default_timezone_get());
             if ($return_timestamp) {
                 return api_strtotime($last_login_date);
             } else {
                 if (!$warning_message) {
                     return api_format_date($last_login_date, DATE_FORMAT_SHORT);
                 } else {
                     $timestamp = api_strtotime($last_login_date);
                     $currentTimestamp = time();
                     //If the last connection is > than 7 days, the text is red
                     //345600 = 7 days in seconds 63072000= 2 ans
                     // if ($currentTimestamp - $timestamp > 184590 )
                     if ($currentTimestamp - $timestamp > $inactive_time && UserManager::delete_user($student_id)) {
                         Display::display_normal_message(get_lang('UserDeleted'));
                         echo '<p>', 'id', $student_id, ':', $last_login_date, '</p>';
                     }
                 }
             }
         }
     }
     return false;
 }
Example #6
0
}
if (isset($_GET["user_id"]) && $_GET["user_id"] != "" && !isset($_GET["type"])) {
    $interbreadcrumb[] = array("url" => "teachers.php", "name" => get_lang('Teachers'));
}
function count_courses()
{
    global $nb_courses;
    return $nb_courses;
}
//checking if the current coach is the admin coach
$show_import_icon = false;
if (api_get_setting('add_users_by_coach') == 'true') {
    if (!api_is_platform_admin()) {
        $sql = 'SELECT id_coach FROM ' . Database::get_main_table(TABLE_MAIN_SESSION) . ' WHERE id=' . $id_session;
        $rs = Database::query($sql);
        if (Database::result($rs, 0, 0) != $_user['user_id']) {
            api_not_allowed(true);
        } else {
            $show_import_icon = true;
        }
    }
}
Display::display_header($nameTools);
$a_courses = array();
if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {
    $title = '';
    if (empty($id_session)) {
        if (isset($_GET['user_id'])) {
            $user_id = intval($_GET['user_id']);
            $user_info = api_get_user_info($user_id);
            $title = get_lang('AssignedCoursesTo') . ' ' . api_get_person_name($user_info['firstname'], $user_info['lastname']);
Example #7
0
 /**
  * Returns the form to update or create a document
  *
  * @param	string	Action (add/edit)
  * @param	integer	ID of the lp_item (if already exists)
  * @param	mixed	Integer if document ID, string if info ('new')
  * @return	string	HTML form
  */
 function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     global $charset, $_course;
     require_once api_get_path(LIBRARY_PATH) . 'fileUpload.lib.php';
     require_once api_get_path(LIBRARY_PATH) . 'document.lib.php';
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $path_parts = pathinfo($extra_info['dir']);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     //If action==add an existing document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . "WHERE id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc, __FILE__, __LINE__);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     // create css folder
     $css_name = api_get_setting('stylesheets');
     $perm = api_get_setting('permissions_for_new_directories');
     $perm = octdec(!empty($perm) ? $perm : '0770');
     $css_folder = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/css';
     if (!is_dir($css_folder)) {
         mkdir($css_folder);
         chmod($css_folder, $perm);
         $doc_id = add_document($_course, '/css', 'folder', 0, 'css');
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', $_user['user_id']);
         api_item_property_update($_course, TOOL_DOCUMENT, $doc_id, 'invisible', $_user['user_id']);
     }
     if (!file_exists($css_folder . '/templates.css')) {
         if (file_exists(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css')) {
             $template_content = str_replace('../../img/', api_get_path(REL_CODE_PATH) . 'img/', file_get_contents(api_get_path(SYS_PATH) . 'main/css/' . $css_name . '/templates.css'));
             $template_content = str_replace('images/', api_get_path(REL_CODE_PATH) . 'css/' . $css_name . '/images/', $template_content);
             file_put_contents($css_folder . '/templates.css', $template_content);
         }
     }
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $table_sys_template = Database::get_main_table(TABLE_MAIN_SYSTEM_TEMPLATE);
         $user_id = api_get_user_id();
         // Session used by the ajax request when we are using php 5.3
         $_SESSION['dbName'] = $_course['dbName'];
         // setting some paths
         $img_dir = api_get_path(REL_CODE_PATH) . 'img/';
         $default_course_dir = api_get_path(REL_CODE_PATH) . 'default_course_document/';
         if (!isset($_GET['resource'])) {
             // Load a template into a document
             $query = 'SELECT content, title FROM ' . $table_sys_template . ' WHERE id=' . Database::escape_string(Security::remove_XSS($_GET['tplid']));
             $result = Database::query($query, __FILE__, __LINE__);
             $obj = Database::fetch_object($result);
             $valcontent = $obj->content;
             $valtitle = $obj->title != '' ? get_lang($obj->title) : get_lang('Empty');
             if (isset($_GET['tplid']) && $_GET['tplid'] == 0) {
                 $valcontent = '<head>{CSS}<style type="text/css">.text{font-weight: normal;}</style></head><body></body>';
             }
             $template_css = '';
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $template_css = '<link rel="stylesheet" href="' . api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/css/templates.css" type="text/css" />';
             }
             $js = '';
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery-1.4.2.min.js" language="javascript"></script>';
                 $js .= '<script type="text/javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'jwplayer/jwplayer.js" language="javascript"></script>' . PHP_EOL;
                 if (api_get_setting('show_glossary_in_documents') != 'none') {
                     $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/jquery.highlight.js"></script>';
                     if (api_get_setting('show_glossary_in_documents') == 'ismanual') {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_manual.js"></script>';
                     } else {
                         $js .= '<script language="javascript" src="' . api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/glossary/fck_glossary_automatic.js"></script>';
                     }
                 }
             }
             $valcontent = str_replace('{CSS}', $template_css . $js, $valcontent);
             if (strpos($valcontent, '/css/templates.css') === false) {
                 $valcontent = str_replace('</head>', $template_css . '</head>', $valcontent);
             }
             if (strpos($valcontent, 'javascript/jquery.highlight.js') === false) {
                 $valcontent = str_replace('</head>', $js . '</head>', $valcontent);
             }
             $valcontent = str_replace('{IMG_DIR}', $img_dir, $valcontent);
             $valcontent = str_replace('{REL_PATH}', api_get_path(REL_PATH), $valcontent);
             $valcontent = str_replace('{COURSE_DIR}', $default_course_dir, $valcontent);
         } elseif (isset($_GET['resource']) && $_GET['resource'] == 'mindmap' || $_GET['resource'] == 'video') {
             // Load a mindmap or video into a document
             $propTable = Database::get_course_table(TABLE_ITEM_PROPERTY);
             $curdirpath = '/mindmaps/';
             if ($_GET['resource'] == 'video') {
                 $curdirpath = '/video/';
                 $curdirpath_flv = '/video/flv/';
             }
             $my_course = api_get_course_id();
             $src_path = api_get_path(WEB_COURSE_PATH) . $my_course . '/document';
             $sql = "SELECT path,title FROM {$tbl_doc} doc,{$propTable} prop WHERE doc.id = prop.ref AND prop.tool = '" . TOOL_DOCUMENT . "'\n      AND doc.filetype = 'file' AND (doc.path LIKE '" . $curdirpath . "%' OR doc.path LIKE '" . $curdirpath_flv . "%') AND (doc.path NOT LIKE '" . $curdirpath . "%/%' OR doc.path NOT LIKE '" . $curdirpath_flv . "%/%')\n      AND prop.visibility = 1 AND doc.id = '" . Database::escape_string(Security::remove_XSS($_GET['tplid'])) . "'";
             $rs = Database::query($sql);
             $row = Database::fetch_array($rs);
             $resource = $src_path . $row['path'];
             $valtitle = $row['title'];
             if ($valtitle != '') {
                 $search = array('.png', '.gif', '.jpg', '.mpg', '.flv', '.swf');
                 // Add other extensions
                 $replace = array('', '', '', '', '', '');
                 $valtitle = str_replace($search, $replace, $valtitle);
             }
             if ($_GET['resource'] == 'mindmap') {
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
           <tbody>
               <tr>
                   <td valign="top"><img border="0" vspace="0" hspace="0" src="' . $resource . '" alt="' . $title . '" title="' . $title . '"/></td>
               </tr>
           </tbody>
       </table>';
             } elseif ($_GET['resource'] == 'video') {
                 $sys_resource = api_get_path(SYS_COURSE_PATH) . $my_course . '/document' . $row['path'];
                 $resource_info = pathinfo($sys_resource);
                 //$video_web_path = api_get_path(WEB_LIBRARY_PATH) . 'fckeditor/editor/plugins/flvPlayer/';
                 $valcontent = '<table cellspacing="2" cellpadding="10" border="0" style="width: 95%; height: 500px;">
                                   <tbody>
                                       <tr>
                                          <td valign="top">                     
                                          <!-- Video player plugin -->
                                             <div id="player986311-parent" align="left">
                                             <div style="border-style: none; height: 240px; width: 375px; overflow: hidden; background-color: rgb(220, 220, 220);" id="test">
                                             <div style="display: none; visibility: hidden; width: 0px; height: 0px; overflow: hidden;" id="player986311-config">url=' . $resource . ' width=375 height=240 loop=1 play=true downloadable=false fullscreen=true</div>
                                                 <div class="thePlayer" id="player986311">';
                 if (in_array($resource_info['extension'], array('flv', 'mp4', 'mov'))) {
                     /*if (!api_is_windows_os()) {
                           $valcontent .= '   <script src="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                                               <object id="player986311-parent2" name="player986311-parent2" width="375" height="240" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
                                               <param name="movie" value="'.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf" />
                                               <param name="allowFullScreen" value="true" />
                                               <param name="allowscriptaccess" value="always" />
                                               <param name="seamlesstabbing" value="true" />
                                               <param name="wmode" value="transparent" />
                                               <param name="flashvars" value="id=player986311-parent2&autostart=true&repeat=false&file='.$resource.'&skin='.api_get_path(WEB_CODE_PATH).'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip&controlbar.position=over"  />                
                                               </object>
                                          ';                                                          
                       } else {*/
                     $valcontent .= '           
                             <script src="' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/jwplayer.min.js" type="text/javascript"></script>
                             <div id="player986311-parent2">Loading the player ...</div>
                             <script type="text/javascript">jwplayer("player986311-parent2").setup({flashplayer: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/player.swf",autostart: "true",repeat: "always",file: "' . $resource . '",height: 240,width: 375,skin: "' . api_get_path(WEB_CODE_PATH) . 'inc/lib/fckeditor/editor/plugins/videoPlayer/skins/facebook.zip"});</script>';
                     //}
                 } else {
                     $sType = '';
                     if ($resource_info['extension'] == 'mpg' || $resource_info['extension'] == 'mpeg') {
                         $sType = 'video/mpeg';
                     } else {
                         if ($resource_info['extension'] == 'avi' || $resource_info['extension'] == 'wmv' || $resource_info['extension'] == 'asf') {
                             $sType = 'video/x-msvideo';
                         }
                     }
                     $valcontent .= '<embed type="' . $sType . '" src="' . $resource . '"
                            autosize = "false"
                            autostart = "true"
                            loop = "false"
                            fullscreen = "true"
                            showcontrols = "true"
                            showpositioncontrols = "false"
                            showtracker = "true"
                            showaudiocontrols = "true"
                            showgotobar = "true"
                            showstatusbar = "true"
                            pluginspace = "http://www.microsoft.com/Windows/MediaPlayer/"
                            codebase = "http://www.microsoft.com/Windows/MediaPlayer/"';
                     $valcontent .= 'width="375px" height="240px"';
                     $valcontent .= '></embed>';
                 }
                 $valcontent .= '              </div>
                                              </div>
                                           </div> 
                                         </td>
                                       </tr>
                                   </tbody>
                               </table>';
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title\n\t\t\t\t\t\t\t\t\tFROM " . $tbl_doc . "\n\t\t\t\t\t\t\t\t\tWHERE id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc, __FILE__, __LINE__);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     /* $return = '	<div class="row">
        <div class="form_header">'; */
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "\n\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\tFROM " . $tbl_lp_item . "\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\tlp_id = " . $this->lp_id;
     $result = Database::query($sql, __FILE__, __LINE__);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = $this->arrMenu;
     unset($this->arrMenu);
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang("Warning") . ' !</strong><br />' . get_lang("WarningEditingDocument"), false);
     }
     require_once api_get_path(LIBRARY_PATH) . 'formvalidator/FormValidator.class.php';
     $form = new FormValidator('form', 'POST', api_get_self() . "?" . $_SERVER["QUERY_STRING"], '', 'enctype="multipart/form-data"');
     $defaults["title"] = Security::remove_XSS(api_convert_encoding($item_title, api_get_system_encoding(), $this->encoding));
     if (empty($item_title)) {
         $defaults["title"] = Security::remove_XSS($item_title);
     }
     $defaults["description"] = api_convert_encoding($item_description, $charset, $this->encoding);
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('html', '<div style="float:left;padding-right:135px;">');
         $form->addElement('text', 'title', get_lang('Title'), 'id="idTitle" class="learnpath_item_form" size=44%');
         $form->applyFilter('title', 'html_filter');
         $form->addElement('html', '</div>');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     //$parent_select = & $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" style="width:40%;" onchange="load_cbo(this.value);"');
     $parent_select =& $form->addElement('select', 'parent', '', '', 'class="learnpath_item_form" style="width:40%;display:none;float:left" onchange="load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // the LP name is also the first section and is not in the same charset like the other sections
             $value['value'] = Security::remove_XSS(api_convert_encoding($value['value'], api_get_system_encoding(), $this->encoding));
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = $_SESSION['parent_item_id'];
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang("After") . ' "' . api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding) . '"';
         }
     }
     //$position = & $form->addElement('select', 'previous', get_lang('Position'), '', 'id="idPosition" class="learnpath_item_form" style="width:40%;"');
     $position =& $form->addElement('select', 'previous', '', '', 'id="idPosition" class="learnpath_item_form" style="width:40%;float:left;display:none;"');
     $position->addOption(get_lang("FirstPosition"), 0);
     foreach ($arrHide as $key => $value) {
         $position->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         //comented the prerequisites, only visible in edit (new document)
         //$select_prerequisites=$form->addElement('select', 'prerequisites', get_lang('Prerequisites'),null,'id="prerequisites" class="learnpath_item_form" style="width:263px;"');
         //$select_prerequisites->addOption(get_lang("NoPrerequisites"),0);
         // form element for uploading an mp3 file
         //$form->addElement('file','mp3',get_lang('UploadMp3audio'),'id="mp3" size="33"');
         //$form->addRule('file', 'The extension of the Song file should be *.mp3', 'filename', '/^.*\.mp3$/');
         /* Code deprecated - moved to lp level (not lp-item)
             if ( api_get_setting('search_enabled') === 'true' )
             {
             //add terms field
             $terms = $form->addElement('text','terms', get_lang('SearchFeatureTerms').'&nbsp;:','id="idTerms" class="learnpath_item_form"');
             $terms->setValue($item_terms);
             }
            */
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if ($extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = api_convert_encoding($arrLP[$i]['title'], $charset, $this->encoding);
             }
         }
         /* 	foreach($arrHide as $key => $value){
              $select_prerequisites->addOption($value['value'],$key,'style="padding-left:'.$value['padding'].'px;"');
              if($key==$s_selected_position && $action == 'add'){
              $select_prerequisites -> setSelected(0);
              }
              elseif($key==$id_prerequisite && $action == 'edit'){
              $select_prerequisites -> setSelected($id_prerequisite);
              }
              }
             */
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to claculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     $relative_path = $extra_info['dir'];
                     if ($relative_path == 'n/') {
                         // A new document, it is in the root of the repository.
                         $relative_path = '';
                         $relative_prefix = '';
                     } else {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $relative_path);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     }
                     $editor_config = array('ToolbarSet' => api_is_allowed_to_edit() ? 'Documents' : 'DocumentsStudent', 'Width' => '100%', 'Height' => '700', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/', 'BaseHref' => api_get_path('WEB_COURSE_PATH') . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'save';
                         $text = get_lang('Validate');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('html', '<div style="float:right;margin-top:-55px">');
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $form->addElement('html', '</div>');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('{label}{element}', 'content_lp');
                     //$form->addElement('html', '<div');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     //$form->addElement('html', '</div>');
                     $defaults["content_lp"] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     // Add template to content
     if ($action == 'add' && (isset($_GET['tplid']) && $_GET['tplid'] >= 0)) {
         $defaults["content_lp"] = $valcontent;
         $defaults["title"] = $valtitle;
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save" style="float:right"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('html', '<div style="float:right;margin-top:-55px">');
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
         $form->addElement('html', '</div>');
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
Example #8
0
 /**
  * This function gets last connection time to one learning path
  * @param     int|array    Student id(s)
  * @param     string         Course code
  * @param     int         Learning path id
  * @return     int         Total time
  */
 public static function get_last_connection_time_in_lp($student_id, $course_code, $lp_id, $session_id = 0)
 {
     $course = CourseManager::get_course_information($course_code);
     $student_id = intval($student_id);
     $lp_id = intval($lp_id);
     $last_time = 0;
     $session_id = intval($session_id);
     if (!empty($course)) {
         $course_id = $course['real_id'];
         $lp_table = Database::get_course_table(TABLE_LP_MAIN);
         $t_lpv = Database::get_course_table(TABLE_LP_VIEW);
         $t_lpiv = Database::get_course_table(TABLE_LP_ITEM_VIEW);
         // Check the real number of LPs corresponding to the filter in the
         // database (and if no list was given, get them all)
         $res_row_lp = Database::query("SELECT id FROM {$lp_table} WHERE c_id = {$course_id} AND id = {$lp_id} ");
         $count_row_lp = Database::num_rows($res_row_lp);
         // calculates last connection time
         if ($count_row_lp > 0) {
             $sql = 'SELECT MAX(start_time)
                     FROM ' . $t_lpiv . ' AS item_view
                     INNER JOIN ' . $t_lpv . ' AS view
                         ON item_view.lp_view_id = view.id
                     WHERE
                         item_view.c_id 		= ' . $course_id . ' AND
                         view.c_id 			= ' . $course_id . ' AND
                         view.lp_id 			= ' . $lp_id . '
                         AND view.user_id 	= ' . $student_id . '
                         AND view.session_id = ' . $session_id;
             $rs = Database::query($sql);
             if (Database::num_rows($rs) > 0) {
                 $last_time = Database::result($rs, 0, 0);
             }
         }
     }
     return $last_time;
 }
Example #9
0
    /**
     * Retrieve results and return them as an array of Result objects
     * @param $id result id
     * @param $user_id user id (student)
     * @param $evaluation_id evaluation where this is a result for
     */
    public static function load($id = null, $user_id = null, $evaluation_id = null)
    {
        $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
        $tbl_grade_results = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
        $tbl_course_rel_course = Database::get_main_table(TABLE_MAIN_COURSE_USER);
        $tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
        if (is_null($id) && is_null($user_id) && !is_null($evaluation_id)) {
            $sql_verified_if_exist_evaluation = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . ' WHERE evaluation_id="' . Database::escape_string($evaluation_id) . '";';
            $res_verified_if_exist_evaluation = Database::query($sql_verified_if_exist_evaluation);
            $info_verified_if_exist_evaluation = Database::result($res_verified_if_exist_evaluation, 0, 0);
            if ($info_verified_if_exist_evaluation != 0) {
                $sql_course_rel_user = '';
                if (api_get_session_id()) {
                    $sql_course_rel_user = '******' . $tbl_session_rel_course_user . '
											WHERE status=0 AND c_id="' . api_get_course_int_id() . '" AND id_session=' . api_get_session_id();
                } else {
                    $sql_course_rel_user = '******' . $tbl_course_rel_course . '
					                        WHERE status ="' . STUDENT . '" AND c_id ="' . api_get_course_int_id() . '" ';
                }
                $res_course_rel_user = Database::query($sql_course_rel_user);
                $list_user_course_list = array();
                while ($row_course_rel_user = Database::fetch_array($res_course_rel_user, 'ASSOC')) {
                    $list_user_course_list[] = $row_course_rel_user;
                }
                $current_date = api_get_utc_datetime();
                for ($i = 0; $i < count($list_user_course_list); $i++) {
                    $sql_verified = 'SELECT COUNT(*) AS count FROM ' . $tbl_grade_results . ' WHERE user_id="' . intval($list_user_course_list[$i]['user_id']) . '" AND evaluation_id="' . intval($evaluation_id) . '";';
                    $res_verified = Database::query($sql_verified);
                    $info_verified = Database::result($res_verified, 0, 0);
                    if ($info_verified == 0) {
                        $sql_insert = 'INSERT INTO ' . $tbl_grade_results . '(user_id,evaluation_id,created_at,score)
									 VALUES ("' . intval($list_user_course_list[$i]['user_id']) . '","' . intval($evaluation_id) . '","' . $current_date . '",0);';
                        $res_insert = Database::query($sql_insert);
                    }
                }
                $list_user_course_list = array();
            }
        }
        $sql = "SELECT gr.id, gr.user_id, gr.evaluation_id, gr.created_at, gr.score \n                FROM {$tbl_grade_results} gr\n                LEFT JOIN {$tbl_user} u ON gr.user_id = u.user_id ";
        $paramcount = 0;
        if (!empty($id)) {
            $sql .= ' WHERE gr.id = ' . Database::escape_string($id);
            $paramcount++;
        }
        if (!empty($user_id)) {
            if ($paramcount != 0) {
                $sql .= ' AND';
            } else {
                $sql .= ' WHERE';
            }
            $sql .= ' user_id = ' . Database::escape_string($user_id);
            $paramcount++;
        }
        if (!empty($evaluation_id)) {
            if ($paramcount != 0) {
                $sql .= ' AND';
            } else {
                $sql .= ' WHERE';
            }
            $sql .= ' evaluation_id = ' . Database::escape_string($evaluation_id);
            $paramcount++;
        }
        $result = Database::query($sql);
        $allres = array();
        while ($data = Database::fetch_array($result)) {
            $res = new Result();
            $res->set_id($data['id']);
            $res->set_user_id($data['user_id']);
            $res->set_evaluation_id($data['evaluation_id']);
            $res->set_date(api_get_local_time($data['created_at']));
            $res->set_score($data['score']);
            $allres[] = $res;
        }
        return $allres;
    }
Example #10
0
 /**
  * This function gets the comments of an exercise
  *
  * @param int $exe_id
  * @param int $question_id
  *
  * @return string the comment
  */
 public static function get_comments($exe_id, $question_id)
 {
     $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $sql = "SELECT teacher_comment FROM " . $table_track_attempt . "\n                WHERE\n                    exe_id='" . Database::escape_string($exe_id) . "' AND\n                    question_id = '" . Database::escape_string($question_id) . "'\n                ORDER by question_id";
     $sqlres = Database::query($sql);
     $comm = Database::result($sqlres, 0, "teacher_comment");
     return $comm;
 }
Example #11
0
 /**
  *
  * @global bool $is_platformAdmin
  * @global bool $is_allowedCreateCourse
  * @global object $_user
  * @global int $_cid
  * @global array $_course
  * @global int $_real_cid
  * @global type $_courseUser
  * @global type $is_courseAdmin
  * @global type $is_courseTutor
  * @global type $is_courseCoach
  * @global type $is_courseMember
  * @global type $is_sessionAdmin
  * @global type $is_allowed_in_course
  *
  * @param type $course_id
  * @param type $reset
  */
 static function init_course($course_id, $reset)
 {
     global $_configuration;
     global $is_platformAdmin;
     global $is_allowedCreateCourse;
     global $_user;
     global $_cid;
     global $_course;
     global $_real_cid;
     global $is_courseAdmin;
     //course teacher
     global $is_courseTutor;
     //course teacher - some rights
     global $is_courseCoach;
     //course coach
     global $is_courseMember;
     //course student
     global $is_sessionAdmin;
     global $is_allowed_in_course;
     if ($reset) {
         // Course session data refresh requested or empty data
         if ($course_id) {
             $course_table = Database::get_main_table(TABLE_MAIN_COURSE);
             $course_cat_table = Database::get_main_table(TABLE_MAIN_CATEGORY);
             $sql = "SELECT course.*, course_category.code faCode, course_category.name faName\n                        FROM {$course_table}\n                        LEFT JOIN {$course_cat_table}\n                        ON course.category_code = course_category.code\n                        WHERE course.code = '{$course_id}'";
             $result = Database::query($sql);
             if (Database::num_rows($result) > 0) {
                 $course_data = Database::fetch_array($result);
                 //@TODO real_cid should be cid, for working with numeric course id
                 $_real_cid = $course_data['id'];
                 $_cid = $course_data['code'];
                 $_course = array();
                 $_course['real_id'] = $course_data['id'];
                 $_course['id'] = $course_data['code'];
                 //auto-assigned integer
                 $_course['code'] = $course_data['code'];
                 $_course['name'] = $course_data['title'];
                 $_course['title'] = $course_data['title'];
                 $_course['official_code'] = $course_data['visual_code'];
                 // use in echo
                 $_course['sysCode'] = $course_data['code'];
                 // use as key in db
                 $_course['path'] = $course_data['directory'];
                 // use as key in path
                 $_course['titular'] = $course_data['tutor_name'];
                 // this should be deprecated and use the table course_rel_user
                 $_course['language'] = $course_data['course_language'];
                 $_course['extLink']['url'] = $course_data['department_url'];
                 $_course['extLink']['name'] = $course_data['department_name'];
                 $_course['categoryCode'] = $course_data['faCode'];
                 $_course['categoryName'] = $course_data['faName'];
                 $_course['visibility'] = $course_data['visibility'];
                 $_course['subscribe_allowed'] = $course_data['subscribe'];
                 $_course['unsubscribe'] = $course_data['unsubscribe'];
                 $_course['activate_legal'] = $course_data['activate_legal'];
                 $_course['show_score'] = $course_data['show_score'];
                 //used in the work tool
                 Session::write('_cid', $_cid);
                 Session::write('_course', $_course);
                 //@TODO real_cid should be cid, for working with numeric course id
                 Session::write('_real_cid', $_real_cid);
                 // if a session id has been given in url, we store the session
                 // Database Table Definitions
                 $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
                 if (!empty($_GET['id_session'])) {
                     $_SESSION['id_session'] = intval($_GET['id_session']);
                     $sql = 'SELECT name FROM ' . $tbl_session . ' WHERE id="' . intval($_SESSION['id_session']) . '"';
                     $rs = Database::query($sql);
                     list($_SESSION['session_name']) = Database::fetch_array($rs);
                 } else {
                     Session::erase('session_name');
                     Session::erase('id_session');
                 }
                 if (!isset($_SESSION['login_as'])) {
                     //Course login
                     if (isset($_user['user_id'])) {
                         Event::event_course_login(api_get_course_int_id(), $_user['user_id'], api_get_session_id());
                     }
                 }
             } else {
                 //exit("WARNING UNDEFINED CID !! ");
                 header('location:' . api_get_path(WEB_PATH));
             }
         } else {
             Session::erase('_cid');
             Session::erase('_real_cid');
             Session::erase('_course');
             if (!empty($_SESSION)) {
                 foreach ($_SESSION as $key => $session_item) {
                     if (strpos($key, 'lp_autolaunch_') === false) {
                         continue;
                     } else {
                         if (isset($_SESSION[$key])) {
                             Session::erase($key);
                         }
                     }
                 }
             }
             //Deleting session info
             if (api_get_session_id()) {
                 Session::erase('id_session');
                 Session::erase('session_name');
             }
         }
     } else {
         // Continue with the previous values
         if (empty($_SESSION['_course']) or empty($_SESSION['_cid'])) {
             //no previous values...
             $_cid = -1;
             //set default values that will be caracteristic of being unset
             $_course = -1;
         } else {
             $_cid = $_SESSION['_cid'];
             $_course = $_SESSION['_course'];
             // these lines are usefull for tracking. Indeed we can have lost the id_session and not the cid.
             // Moreover, if we want to track a course with another session it can be usefull
             if (!empty($_GET['id_session'])) {
                 $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
                 $sql = 'SELECT name FROM ' . $tbl_session . ' WHERE id="' . intval($_SESSION['id_session']) . '"';
                 $rs = Database::query($sql);
                 list($_SESSION['session_name']) = Database::fetch_array($rs);
                 $_SESSION['id_session'] = intval($_GET['id_session']);
             }
             if (!isset($_SESSION['login_as'])) {
                 $save_course_access = true;
                 //The value  $_dont_save_user_course_access should be added before the call of global.inc.php see the main/inc/chat.ajax.php file
                 //Disables the updates in the TRACK_E_COURSE_ACCESS table
                 if (isset($_dont_save_user_course_access) && $_dont_save_user_course_access == true) {
                     $save_course_access = false;
                 }
                 if ($save_course_access) {
                     $course_tracking_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
                     /*
                      * When $_configuration['session_lifetime'] is too big 100 hours (in order to let users take exercises with no problems)
                      * the function Tracking::get_time_spent_on_the_course() returns big values (200h) due the condition:
                      * login_course_date > now() - INTERVAL $session_lifetime SECOND
                      *
                      */
                     /*
                                               if (isset($_configuration['session_lifetime'])) {
                                               $session_lifetime    = $_configuration['session_lifetime'];
                                               } else {
                                               $session_lifetime    = 3600; // 1 hour
                                               } */
                     $session_lifetime = 3600;
                     // 1 hour
                     $time = api_get_utc_datetime();
                     if (isset($_user['user_id']) && !empty($_user['user_id'])) {
                         //We select the last record for the current course in the course tracking table
                         //But only if the login date is < than now + max_life_time
                         $sql = "SELECT course_access_id FROM {$course_tracking_table}\n                                    WHERE\n                                        user_id     = " . intval($_user['user_id']) . " AND\n                                        c_id = '" . api_get_course_int_id() . "' AND\n                                        session_id  = " . api_get_session_id() . " AND\n                                        login_course_date > now() - INTERVAL {$session_lifetime} SECOND\n                                    ORDER BY login_course_date DESC LIMIT 0,1";
                         $result = Database::query($sql);
                         if (Database::num_rows($result) > 0) {
                             $i_course_access_id = Database::result($result, 0, 0);
                             //We update the course tracking table
                             $sql = "UPDATE {$course_tracking_table}\n                                        SET logout_course_date = '{$time}', counter = counter+1\n                                        WHERE course_access_id = " . intval($i_course_access_id) . " AND session_id = " . api_get_session_id();
                             Database::query($sql);
                         } else {
                             $sql = "INSERT INTO {$course_tracking_table} (c_id, user_id, login_course_date, logout_course_date, counter, session_id)" . "VALUES('" . api_get_course_int_id() . "', '" . $_user['user_id'] . "', '{$time}', '{$time}', '1','" . api_get_session_id() . "')";
                             Database::query($sql);
                         }
                     }
                 }
             }
         }
     }
     /*  COURSE / USER REL. INIT */
     $session_id = api_get_session_id();
     $user_id = isset($_user['user_id']) ? $_user['user_id'] : null;
     //Course permissions
     $is_courseAdmin = false;
     //course teacher
     $is_courseTutor = false;
     //course teacher - some rights
     $is_courseMember = false;
     //course student
     //Course - User permissions
     $is_sessionAdmin = false;
     if ($reset) {
         if (isset($user_id) && $user_id && isset($_cid) && $_cid) {
             //Check if user is subscribed in a course
             $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
             $sql = "SELECT * FROM {$course_user_table}\n                       WHERE\n                        user_id  = '" . $user_id . "' AND\n                        relation_type <> " . COURSE_RELATION_TYPE_RRHH . " AND\n                        course_code = '{$course_id}'";
             $result = Database::query($sql);
             $cuData = null;
             if (Database::num_rows($result) > 0) {
                 // this  user have a recorded state for this course
                 $cuData = Database::fetch_array($result, 'ASSOC');
                 $is_courseAdmin = (bool) $cuData['status'] == 1;
                 $is_courseTutor = (bool) $cuData['is_tutor'] == 1;
                 $is_courseMember = true;
                 // Checking if the user filled the course legal agreement
                 if ($_course['activate_legal'] == 1 && !api_is_platform_admin()) {
                     $user_is_subscribed = CourseManager::is_user_accepted_legal($user_id, $_course['id'], $session_id);
                     if (!$user_is_subscribed) {
                         $url = api_get_path(WEB_CODE_PATH) . 'course_info/legal.php?course_code=' . $_course['code'] . '&session_id=' . $session_id;
                         header('Location: ' . $url);
                         exit;
                     }
                 }
             }
             //We are in a session course? Check session permissions
             if (!empty($session_id)) {
                 //I'm not the teacher of the course
                 if ($is_courseAdmin == false) {
                     // this user has no status related to this course
                     // The user is subscribed in a session? The user is a Session coach a Session admin ?
                     $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
                     $tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
                     $tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
                     //Session coach, session admin, course coach admin
                     $sql = "SELECT session.id_coach, session_admin_id, session_rcru.user_id\n                                FROM {$tbl_session} session, {$tbl_session_course_user} session_rcru\n                                WHERE\n                                   session_rcru.session_id = session.id AND\n                                   session_rcru.c_id = '{$_real_cid}' AND\n                                   session_rcru.user_id = '{$user_id}' AND\n                                   session_rcru.session_id  = {$session_id} AND\n                                   session_rcru.status = 2";
                     $result = Database::query($sql);
                     $row = Database::store_result($result);
                     //I'm a session admin?
                     if (isset($row) && isset($row[0]) && $row[0]['session_admin_id'] == $user_id) {
                         $is_courseMember = false;
                         $is_courseTutor = false;
                         $is_courseAdmin = false;
                         $is_courseCoach = false;
                         $is_sessionAdmin = true;
                     } else {
                         //Im a coach or a student?
                         $sql = "SELECT user_id, status\n                                    FROM " . $tbl_session_course_user . "\n                                    WHERE\n                                        c_id = '{$_cid}' AND\n                                        user_id = '" . $user_id . "' AND\n                                        session_id = '" . $session_id . "'\n                                    LIMIT 1";
                         $result = Database::query($sql);
                         if (Database::num_rows($result)) {
                             $row = Database::fetch_array($result, 'ASSOC');
                             $session_course_status = $row['status'];
                             switch ($session_course_status) {
                                 case '2':
                                     // coach - teacher
                                     $is_courseMember = true;
                                     $is_courseTutor = true;
                                     $is_courseCoach = true;
                                     $is_sessionAdmin = false;
                                     if (api_get_setting('extend_rights_for_coach') == 'true') {
                                         $is_courseAdmin = true;
                                     } else {
                                         $is_courseAdmin = false;
                                     }
                                     break;
                                 case '0':
                                     //student
                                     $is_courseMember = true;
                                     $is_courseTutor = false;
                                     $is_courseAdmin = false;
                                     $is_sessionAdmin = false;
                                     break;
                                 default:
                                     //unregister user
                                     $is_courseMember = false;
                                     $is_courseTutor = false;
                                     $is_courseAdmin = false;
                                     $is_sessionAdmin = false;
                                     break;
                             }
                         } else {
                             //unregister user
                             $is_courseMember = false;
                             $is_courseTutor = false;
                             $is_courseAdmin = false;
                             $is_sessionAdmin = false;
                         }
                     }
                 }
                 //If I'm the admin platform i'm a teacher of the course
                 if ($is_platformAdmin) {
                     $is_courseAdmin = true;
                 }
             }
         } else {
             // keys missing => not anymore in the course - user relation
             // course
             $is_courseMember = false;
             $is_courseAdmin = false;
             $is_courseTutor = false;
             $is_courseCoach = false;
             $is_sessionAdmin = false;
         }
         //Checking the course access
         $is_allowed_in_course = false;
         if (isset($_course)) {
             switch ($_course['visibility']) {
                 case COURSE_VISIBILITY_OPEN_WORLD:
                     //3
                     $is_allowed_in_course = true;
                     break;
                 case COURSE_VISIBILITY_OPEN_PLATFORM:
                     //2
                     if (isset($user_id) && !api_is_anonymous($user_id)) {
                         $is_allowed_in_course = true;
                     }
                     break;
                 case COURSE_VISIBILITY_REGISTERED:
                     //1
                     if ($is_platformAdmin || $is_courseMember) {
                         $is_allowed_in_course = true;
                     }
                     break;
                 case COURSE_VISIBILITY_CLOSED:
                     //0
                     if ($is_platformAdmin || $is_courseAdmin) {
                         $is_allowed_in_course = true;
                     }
                     break;
                 case COURSE_VISIBILITY_HIDDEN:
                     //4
                     if ($is_platformAdmin) {
                         $is_allowed_in_course = true;
                     }
                     break;
             }
         }
         // check the session visibility
         if ($is_allowed_in_course == true) {
             //if I'm in a session
             if ($session_id != 0) {
                 if (!$is_platformAdmin) {
                     // admin and session coach are *not* affected to the invisible session mode
                     // the coach is not affected because he can log in some days after the end date of a session
                     $session_visibility = api_get_session_visibility($session_id);
                     switch ($session_visibility) {
                         case SESSION_INVISIBLE:
                             $is_allowed_in_course = false;
                             break;
                     }
                     //checking date
                 }
             }
         }
         // save the states
         Session::write('is_courseAdmin', $is_courseAdmin);
         Session::write('is_courseMember', $is_courseMember);
         Session::write('is_courseTutor', $is_courseTutor);
         Session::write('is_courseCoach', $is_courseCoach);
         Session::write('is_allowed_in_course', $is_allowed_in_course);
         Session::write('is_sessionAdmin', $is_sessionAdmin);
     } else {
         // continue with the previous values
         $is_courseAdmin = $_SESSION['is_courseAdmin'];
         $is_courseTutor = $_SESSION['is_courseTutor'];
         $is_courseCoach = $_SESSION['is_courseCoach'];
         $is_courseMember = $_SESSION['is_courseMember'];
         $is_allowed_in_course = $_SESSION['is_allowed_in_course'];
     }
 }
Example #12
0
 /**
  *  Get number of subscriptions of the user
  *
  *  @return -   int     The amount of itemrights
  */
 function get_num_subscriptions()
 {
     $sql = "SELECT COUNT(*) FROM " . Rsys::getTable("subscription") . " s\n\t\t\t            INNER JOIN " . Rsys::getTable("reservation") . " r ON r.id = s.reservation_id\n\t\t\t            INNER JOIN " . Rsys::getTable("item") . " i ON i.id=r.item_id\n\t\t\t            WHERE s.user_id = '" . api_get_user_id() . "'";
     return @Database::result(Database::query($sql), 0, 0);
 }
 /**
  * updates the question in the data base
  * if an exercise ID is provided, we add that exercise ID into the exercise list
  *
  * @author Olivier Brouckaert
  * @param integer $exerciseId - exercise ID if saving in an exercise
  */
 public function save($exerciseId = 0)
 {
     $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $id = $this->id;
     $question = $this->question;
     $description = $this->description;
     $weighting = $this->weighting;
     $position = $this->position;
     $type = $this->type;
     $picture = $this->picture;
     $level = $this->level;
     $extra = $this->extra;
     $c_id = $this->course['real_id'];
     $category = $this->category;
     // question already exists
     if (!empty($id)) {
         $params = ['question' => $question, 'description' => $description, 'ponderation' => $weighting, 'position' => $position, 'type' => $type, 'picture' => $picture, 'extra' => $extra, 'level' => $level];
         Database::update($TBL_QUESTIONS, $params, ['c_id = ? AND id = ?' => [$c_id, $id]]);
         $this->saveCategory($category);
         if (!empty($exerciseId)) {
             api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionUpdated', api_get_user_id());
         }
         if (api_get_setting('search.search_enabled') == 'true') {
             if ($exerciseId != 0) {
                 $this->search_engine_edit($exerciseId);
             } else {
                 /**
                  * actually there is *not* an user interface for
                  * creating questions without a relation with an exercise
                  */
             }
         }
     } else {
         // creates a new question
         $sql = "SELECT max(position)\n                    FROM {$TBL_QUESTIONS} as question,\n                    {$TBL_EXERCISE_QUESTION} as test_question\n                    WHERE\n                        question.id = test_question.question_id AND\n                        test_question.exercice_id = " . intval($exerciseId) . " AND\n                        question.c_id = {$c_id} AND\n                        test_question.c_id = {$c_id} ";
         $result = Database::query($sql);
         $current_position = Database::result($result, 0, 0);
         $this->updatePosition($current_position + 1);
         $position = $this->position;
         $params = ['c_id' => $c_id, 'question' => $question, 'description' => $description, 'ponderation' => $weighting, 'position' => $position, 'type' => $type, 'picture' => $picture, 'extra' => $extra, 'level' => $level];
         $this->id = Database::insert($TBL_QUESTIONS, $params);
         if ($this->id) {
             $sql = "UPDATE {$TBL_QUESTIONS} SET id = iid WHERE iid = {$this->id}";
             Database::query($sql);
             api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'QuizQuestionAdded', api_get_user_id());
             // If hotspot, create first answer
             if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
                 $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
                 $params = ['c_id' => $c_id, 'question_id' => $this->id, 'answer' => '', 'correct' => '', 'comment' => '', 'ponderation' => 10, 'position' => 1, 'hotspot_coordinates' => '0;0|0|0', 'hotspot_type' => 'square'];
                 $id = Database::insert($TBL_ANSWERS, $params);
                 if ($id) {
                     $sql = "UPDATE {$TBL_ANSWERS} SET id = iid, id_auto = iid WHERE iid = {$id}";
                     Database::query($sql);
                 }
             }
             if ($type == HOT_SPOT_DELINEATION) {
                 $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
                 $params = ['c_id' => $c_id, 'question_id' => $this->id, 'answer' => '', 'correct' => '', 'comment' => '', 'ponderation' => 10, 'position' => 1, 'hotspot_coordinates' => '0;0|0|0', 'hotspot_type' => 'delineation'];
                 $id = Database::insert($TBL_ANSWERS, $params);
                 if ($id) {
                     $sql = "UPDATE {$TBL_ANSWERS} SET id = iid, id_auto = iid WHERE iid = {$id}";
                     Database::query($sql);
                 }
             }
             if (api_get_setting('search.search_enabled') == 'true') {
                 if ($exerciseId != 0) {
                     $this->search_engine_edit($exerciseId, true);
                 } else {
                     /**
                      * actually there is *not* an user interface for
                      * creating questions without a relation with an exercise
                      */
                 }
             }
         }
     }
     // if the question is created in an exercise
     if ($exerciseId) {
         // adds the exercise into the exercise list of this question
         $this->addToList($exerciseId, TRUE);
     }
 }
Example #14
0
if (api_is_western_name_order(PERSON_NAME_DATA_EXPORT)) {
    $header[] = get_lang('FirstName', '');
    $header[] = get_lang('LastName', '');
} else {
    $header[] = get_lang('LastName', '');
    $header[] = get_lang('FirstName', '');
}
$header[] = get_lang('ConnectionTime', '');
if (Database::num_rows($result_coachs) > 0) {
    while ($coachs = Database::fetch_array($result_coachs)) {
        $id_coach = $coachs["id_coach"];
        if (isset($_GET["id_student"])) {
            $sql_infos_coach = "SELECT lastname, firstname FROM {$tbl_user} WHERE user_id='{$id_coach}'";
            $result_coachs_infos = Database::query($sql_infos_coach);
            $lastname = Database::result($result_coachs_infos, 0, "lastname");
            $firstname = Database::result($result_coachs_infos, 0, "firstname");
        } else {
            $lastname = $coachs["lastname"];
            $firstname = $coachs["firstname"];
        }
        $sql_connection_time = "SELECT login_date, logout_date FROM {$tbl_track_login} WHERE login_user_id ='{$id_coach}' AND logout_date <> 'null'";
        $result_connection_time = Database::query($sql_connection_time);
        $nb_seconds = 0;
        while ($connections = Database::fetch_array($result_connection_time)) {
            $login_date = $connections["login_date"];
            $logout_date = $connections["logout_date"];
            $timestamp_login_date = strtotime($login_date);
            $timestamp_logout_date = strtotime($logout_date);
            $nb_seconds += $timestamp_logout_date - $timestamp_login_date;
        }
        if ($nb_seconds == 0) {
    /**
     * Writes the current data to the database
     * @return    boolean    Query result
     */
    public function write_to_db()
    {
        if (self::debug > 0) {
            error_log('learnpathItem::write_to_db()', 0);
        }
        // Check the session visibility.
        if (!api_is_allowed_to_session_edit()) {
            if (self::debug > 0) {
                error_log('return false api_is_allowed_to_session_edit');
            }
            return false;
        }
        $course_id = api_get_course_int_id();
        $mode = $this->get_lesson_mode();
        $credit = $this->get_credit();
        $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
        $sql_verified = 'SELECT status FROM ' . $item_view_table . '
		                 WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ;';
        $rs_verified = Database::query($sql_verified);
        $row_verified = Database::fetch_array($rs_verified);
        $my_case_completed = array('completed', 'passed', 'browsed', 'failed');
        $save = true;
        if (isset($row_verified) && isset($row_verified['status'])) {
            if (in_array($row_verified['status'], $my_case_completed)) {
                $save = false;
            }
        }
        if (($save === false && $this->type == 'sco' || $this->type == 'sco' && ($credit == 'no-credit' or $mode == 'review' or $mode == 'browse')) && ($this->seriousgame_mode != 1 && $this->type == 'sco')) {
            if (self::debug > 1) {
                error_log("This info shouldn't be saved as the credit or lesson mode info prevent it");
                error_log('learnpathItem::write_to_db() - credit(' . $credit . ') or lesson_mode(' . $mode . ') prevent recording!', 0);
            }
        } else {
            // Check the row exists.
            $inserted = false;
            // This a special case for multiple attempts and Chamilo exercises.
            if ($this->type == 'quiz' && $this->get_prevent_reinit() == 0 && $this->get_status() == 'completed') {
                // We force the item to be restarted.
                $this->restart();
                $sql = "INSERT INTO {$item_view_table} " . "(c_id, total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "({$course_id}, " . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')";
                if (self::debug > 2) {
                    error_log('learnpathItem::write_to_db() - Inserting into item_view forced: ' . $sql, 0);
                }
                $res = Database::query($sql);
                $this->db_item_view_id = Database::insert_id();
                $inserted = true;
            }
            $check_attempts = self::check_attempts($this->get_attempt_id());
            if (!$check_attempts) {
                return false;
            }
            $item_view_table = Database::get_course_table(TABLE_LP_ITEM_VIEW);
            $check = "SELECT * FROM {$item_view_table}\n                        WHERE\n                            c_id = {$course_id} AND\n                            lp_item_id = " . $this->db_id . " AND\n                            lp_view_id = " . $this->view_id . " AND\n                            view_count = " . $this->get_attempt_id();
            if (self::debug > 2) {
                error_log('learnpathItem::write_to_db() - Querying item_view: ' . $check, 0);
            }
            $check_res = Database::query($check);
            // Depending on what we want (really), we'll update or insert a new row
            // now save into DB.
            $res = 0;
            if (!$inserted && Database::num_rows($check_res) < 1) {
                $sql = "INSERT INTO {$item_view_table} " . "(c_id, total_time, " . "start_time, " . "score, " . "status, " . "max_score, " . "lp_item_id, " . "lp_view_id, " . "view_count, " . "suspend_data, " . "lesson_location)" . "VALUES" . "({$course_id}, " . $this->get_total_time() . "," . "" . $this->current_start_time . "," . "" . $this->get_score() . "," . "'" . $this->get_status(false) . "'," . "'" . $this->get_max() . "'," . "" . $this->db_id . "," . "" . $this->view_id . "," . "" . $this->get_attempt_id() . "," . "'" . Database::escape_string($this->current_data) . "'," . "'" . $this->lesson_location . "')";
                if (self::debug > 2) {
                    error_log('learnpathItem::write_to_db() - Inserting into item_view: ' . $sql, 0);
                }
                $res = Database::query($sql);
                $this->db_item_view_id = Database::insert_id();
            } else {
                $sql = '';
                if ($this->type == 'hotpotatoes') {
                    $sql = "UPDATE {$item_view_table} " . "SET total_time = " . $this->get_total_time() . ", " . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . " status = '" . $this->get_status(false) . "'," . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id();
                } else {
                    // For all other content types...
                    if ($this->type == 'quiz') {
                        $my_status = ' ';
                        $total_time = ' ';
                        if (!empty($_REQUEST['exeId'])) {
                            $TBL_TRACK_EXERCICES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
                            $safe_exe_id = Database::escape_string($_REQUEST['exeId']);
                            $sql = 'SELECT start_date,exe_date FROM ' . $TBL_TRACK_EXERCICES . ' WHERE exe_id = ' . (int) $safe_exe_id;
                            $res = Database::query($sql);
                            $row_dates = Database::fetch_array($res);
                            $time_start_date = api_convert_sql_date($row_dates['start_date']);
                            $time_exe_date = api_convert_sql_date($row_dates['exe_date']);
                            $mytime = (int) $time_exe_date - (int) $time_start_date;
                            $total_time = " total_time = " . $mytime . ", ";
                        }
                    } else {
                        $my_type_lp = learnpath::get_type_static($this->lp_id);
                        // This is a array containing values finished
                        $case_completed = array('completed', 'passed', 'browsed', 'failed');
                        //is not multiple attempts
                        if ($this->seriousgame_mode == 1 && $this->type == 'sco') {
                            $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                            $my_status = " status = '" . $this->get_status(false) . "' ,";
                        } elseif ($this->get_prevent_reinit() == 1) {
                            // Process of status verified into data base.
                            $sql_verified = 'SELECT status FROM ' . $item_view_table . '
                                             WHERE c_id = ' . $course_id . ' AND lp_item_id = "' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ;';
                            $rs_verified = Database::query($sql_verified);
                            $row_verified = Database::fetch_array($rs_verified);
                            // Get type lp: 1=lp dokeos and  2=scorm.
                            // If not is completed or passed or browsed and learning path is scorm.
                            if (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                                //&& $this->type!='dir'
                                $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            } else {
                                // Verified into data base.
                                if (!in_array($row_verified['status'], $case_completed) && $my_type_lp == 2) {
                                    //&& $this->type!='dir'
                                    $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                    $my_status = " status = '" . $this->get_status(false) . "' ,";
                                } elseif (in_array($row_verified['status'], $case_completed) && $my_type_lp == 2 && $this->type != 'sco') {
                                    //&& $this->type!='dir'
                                    $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                    $my_status = " status = '" . $this->get_status(false) . "' ,";
                                } else {
                                    //&& !in_array($row_verified['status'], $case_completed)
                                    //is lp dokeos
                                    if ($my_type_lp == 1 && $this->type != 'chapter') {
                                        $total_time = " total_time = total_time + " . $this->get_total_time() . ", ";
                                        $my_status = " status = '" . $this->get_status(false) . "' ,";
                                    }
                                }
                            }
                        } else {
                            // Multiple attempts are allowed.
                            if (in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                                // Reset zero new attempt ?
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            } elseif (!in_array($this->get_status(false), $case_completed) && $my_type_lp == 2) {
                                $total_time = " total_time = " . $this->get_total_time() . ", ";
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            } else {
                                // It is dokeos LP.
                                $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                $my_status = " status = '" . $this->get_status(false) . "' ,";
                            }
                            // Code added by Isaac Flores.
                            // This code line fixes the problem of wrong status.
                            if ($my_type_lp == 2) {
                                // Verify current status in multiples attempts.
                                $sql_status = 'SELECT status FROM ' . $item_view_table . '
                                               WHERE c_id = ' . $course_id . ' AND lp_item_id="' . $this->db_id . '" AND lp_view_id="' . $this->view_id . '" AND view_count="' . $this->get_attempt_id() . '" ';
                                $rs_status = Database::query($sql_status);
                                $current_status = Database::result($rs_status, 0, 'status');
                                if (in_array($current_status, $case_completed)) {
                                    $my_status = '';
                                    $total_time = '';
                                } else {
                                    $total_time = " total_time = total_time +" . $this->get_total_time() . ", ";
                                }
                            }
                        }
                    }
                    if ($this->type == 'sco') {
                        //IF scorm scorm_update_time has already updated total_tim in db
                        $sql = "UPDATE {$item_view_table} " . " SET " . " score = " . $this->get_score() . ", " . $my_status . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id();
                    } else {
                        $sql = "UPDATE {$item_view_table} " . "SET " . $total_time . " start_time = " . $this->get_current_start_time() . ", " . " score = " . $this->get_score() . ", " . $my_status . " max_score = '" . $this->get_max() . "'," . " suspend_data = '" . Database::escape_string($this->current_data) . "'," . " lesson_location = '" . $this->lesson_location . "' " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND lp_view_id = " . $this->view_id . " " . "AND view_count = " . $this->get_attempt_id();
                    }
                    $this->current_start_time = time();
                }
                if (self::debug > 2) {
                    error_log('learnpathItem::write_to_db() - Updating item_view: ' . $sql, 0);
                }
                $res = Database::query($sql);
            }
            if (is_array($this->interactions) && count($this->interactions) > 0) {
                // Save interactions.
                $tbl = Database::get_course_table(TABLE_LP_ITEM_VIEW);
                $sql = "SELECT id FROM {$tbl} " . "WHERE c_id = {$course_id} AND lp_item_id = " . $this->db_id . " " . "AND   lp_view_id = " . $this->view_id . " " . "AND   view_count = " . $this->get_attempt_id();
                $res = Database::query($sql);
                if (Database::num_rows($res) > 0) {
                    $row = Database::fetch_array($res);
                    $lp_iv_id = $row[0];
                    if (self::debug > 2) {
                        error_log('learnpathItem::write_to_db() - Got item_view_id ' . $lp_iv_id . ', now checking interactions ', 0);
                    }
                    foreach ($this->interactions as $index => $interaction) {
                        $correct_resp = '';
                        if (is_array($interaction[4]) && !empty($interaction[4][0])) {
                            foreach ($interaction[4] as $resp) {
                                $correct_resp .= $resp . ',';
                            }
                            $correct_resp = substr($correct_resp, 0, strlen($correct_resp) - 1);
                        }
                        $iva_table = Database::get_course_table(TABLE_LP_IV_INTERACTION);
                        $iva_sql = "SELECT id FROM {$iva_table} " . "WHERE c_id = {$course_id} AND lp_iv_id = {$lp_iv_id} " . "AND (order_id = {$index} " . "OR interaction_id = '" . Database::escape_string($interaction[0]) . "')";
                        $iva_res = Database::query($iva_sql);
                        // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7)
                        if (Database::num_rows($iva_res) > 0) {
                            // Update (or don't).
                            $iva_row = Database::fetch_array($iva_res);
                            $iva_id = $iva_row[0];
                            $ivau_sql = "UPDATE {$iva_table} " . "SET interaction_id = '" . Database::escape_string($interaction[0]) . "'," . "interaction_type = '" . Database::escape_string($interaction[1]) . "'," . "weighting = '" . Database::escape_string($interaction[3]) . "'," . "completion_time = '" . Database::escape_string($interaction[2]) . "'," . "correct_responses = '" . Database::escape_string($correct_resp) . "'," . "student_response = '" . Database::escape_string($interaction[5]) . "'," . "result = '" . Database::escape_string($interaction[6]) . "'," . "latency = '" . Database::escape_string($interaction[7]) . "'" . "WHERE c_id = {$course_id} AND id = {$iva_id}";
                            Database::query($ivau_sql);
                        } else {
                            // Insert new one.
                            $ivai_sql = "INSERT INTO {$iva_table} (c_id, order_id, lp_iv_id, interaction_id, interaction_type, " . "weighting, completion_time, correct_responses, " . "student_response, result, latency)" . "VALUES" . "({$course_id}, " . $index . "," . $lp_iv_id . ",'" . Database::escape_string($interaction[0]) . "','" . Database::escape_string($interaction[1]) . "'," . "'" . Database::escape_string($interaction[3]) . "','" . Database::escape_string($interaction[2]) . "','" . Database::escape_string($correct_resp) . "'," . "'" . Database::escape_string($interaction[5]) . "','" . Database::escape_string($interaction[6]) . "','" . Database::escape_string($interaction[7]) . "'" . ")";
                            Database::query($ivai_sql);
                        }
                    }
                }
            }
        }
        if (self::debug > 2) {
            error_log('End of learnpathItem::write_to_db()', 0);
        }
        return true;
    }
Example #16
0
 /**
  * @param int $session_id
  * @return mixed
  */
 public static function get_session_category_id_by_session_id($session_id)
 {
     return Database::result(Database::query('SELECT  sc.id session_category
             FROM ' . Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY) . ' sc
             INNER JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION) . ' s
             ON sc.id=s.session_category_id WHERE s.id="' . Database::escape_string($session_id) . '"'), 0, 'session_category');
 }
 /**
  * @param $courseId
  * @param $id_session
  * @return int|mixed
  */
 static function get_count_users_in_course_session($courseId, $id_session)
 {
     $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
     $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
     //Select the number of users
     $sql = " SELECT count(*) FROM {$tbl_session_rel_user} sru, {$tbl_session_rel_course_rel_user} srcru\n                 WHERE  srcru.id_user = sru.id_user AND\n                        srcru.id_session = sru.id_session AND\n                        srcru.c_id = '" . Database::escape_string($courseId) . "' AND\n                        srcru.id_session = '" . intval($id_session) . "'  AND\n                        (sru.moved_to = 0 AND sru.moved_status <> " . SessionManager::SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION . ") AND\n                        sru.relation_type<>" . SESSION_RELATION_TYPE_RRHH;
     $result = Database::query($sql);
     if (Database::num_rows($result)) {
         return Database::result($result, 0, 0);
     }
     return 0;
 }
Example #18
0
function verify_antispam($hash, $input_code)
{
    global $MDB, $IP;
    if (!is_object($MDB)) {
        $MDB = new Database(MDB_HOST, MDB_PORT, MDB_USER, MDB_PASSWORD, MDB_DATABASE);
    }
    $code = $MDB->result("SELECT as_code FROM " . TABLE_PREFIX . "antispam WHERE as_hash='" . HashFilter($hash) . "' AND as_code='" . format_string($input_code) . "' AND timestamp>" . (time() - ANTISPAM_EXPIRE) . " AND ip_address='" . $IP . "'");
    return $code ? true : false;
}
Example #19
0
    /**
     * Creates a new blog in the given course
     * @author Toon Keppens
     * @param Integer $course_id Id
     * @param String $title
     * @param Text $description
     */
    public static function create_blog($title, $subtitle)
    {
        $_user = api_get_user_info();
        $course_id = api_get_course_int_id();
        $current_date = date('Y-m-d H:i:s', time());
        $session_id = api_get_session_id();
        // Tabel definitions
        $tbl_blogs = Database::get_course_table(TABLE_BLOGS);
        $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST);
        $tbl_blogs_posts = Database::get_course_table(TABLE_BLOGS_POSTS);
        $tbl_blogs_tasks = Database::get_course_table(TABLE_BLOGS_TASKS);
        //verified if exist blog
        $sql = 'SELECT COUNT(*) as count FROM ' . $tbl_blogs . '
			  	WHERE
			  	    c_id = ' . $course_id . ' AND
			  	    blog_name="' . Database::escape_string($title) . '" AND
			  	    blog_subtitle="' . Database::escape_string($subtitle) . '"';
        $res = Database::query($sql);
        $info_count = Database::result($res, 0, 0);
        if ($info_count == 0) {
            // Create the blog
            $sql = "INSERT INTO {$tbl_blogs} (c_id, blog_name, blog_subtitle, date_creation, visibility, session_id )\n\t\t\t\t\tVALUES ({$course_id}, '" . Database::escape_string($title) . "', '" . Database::escape_string($subtitle) . "', '" . $current_date . "', '1', '{$session_id}');";
            Database::query($sql);
            $this_blog_id = Database::insert_id();
            if ($this_blog_id > 0) {
                $sql = "UPDATE {$tbl_blogs} SET blog_id = iid WHERE iid = {$this_blog_id}";
                Database::query($sql);
                // insert into item_property
                api_item_property_update(api_get_course_info(), TOOL_BLOGS, $this_blog_id, 'BlogAdded', api_get_user_id());
            }
            // Make first post. :)
            $sql = "INSERT INTO {$tbl_blogs_posts} (c_id, title, full_text, date_creation, blog_id, author_id)\n\t\t\t\t\tVALUES ({$course_id}, '" . get_lang("Welcome") . "', '" . get_lang('FirstPostText') . "','" . $current_date . "', '" . Database::escape_string((int) $this_blog_id) . "', '" . Database::escape_string((int) $_user['user_id']) . "');";
            Database::query($sql);
            $postId = Database::insert_id();
            if ($postId) {
                $sql = "UPDATE {$tbl_blogs_posts} SET post_id = iid WHERE iid = {$postId}";
                Database::query($sql);
            }
            // Put it on course homepage
            $sql = "INSERT INTO {$tbl_tool} (c_id, name, link, image, visibility, admin, address, added_tool, session_id)\n\t\t\t\t\tVALUES ({$course_id}, '" . Database::escape_string($title) . "','blog/blog.php?blog_id=" . (int) $this_blog_id . "','blog.gif','1','0','pastillegris.gif',0,'{$session_id}')";
            Database::query($sql);
            $toolId = Database::insert_id();
            if ($toolId) {
                $sql = "UPDATE {$tbl_tool} SET id = iid WHERE iid = {$toolId}";
                Database::query($sql);
            }
            // Subscribe the teacher to this blog
            Blog::set_user_subscribed($this_blog_id, $_user['user_id']);
        }
    }
 /**
  * Get list of groups for current course.
  * @param int $categoryId The id of the category from which the groups are
  * requested
  * @param string $course_code Default is current course
  * @return array An array with all information about the groups.
  */
 public static function get_group_list($categoryId = null, $course_code = null, $status = null)
 {
     $course_info = api_get_course_info($course_code);
     $session_id = api_get_session_id();
     $course_id = $course_info['real_id'];
     $table_group_user = Database::get_course_table(TABLE_GROUP_USER);
     $table_group = Database::get_course_table(TABLE_GROUP);
     $sql = "SELECT g.id,\n                    g.name,\n                    g.description,\n                    g.category_id,\n                    g.max_student maximum_number_of_members,\n                    g.secret_directory,\n                    g.self_registration_allowed,\n                    g.self_unregistration_allowed,\n                    g.session_id,\n                    g.status,\n                    ug.user_id is_member\n                FROM {$table_group} g\n                LEFT JOIN {$table_group_user} ug\n                ON (\n                    ug.group_id = g.id AND\n                    ug.user_id = '" . api_get_user_id() . "' AND\n                    ug.c_id = {$course_id} AND\n                    g.c_id = {$course_id}\n                )";
     $sql .= " WHERE 1=1 ";
     if (!is_null($categoryId)) {
         $sql .= " AND g.category_id = '" . intval($categoryId) . "' ";
         $session_condition = api_get_session_condition($session_id);
         if (!empty($session_condition)) {
             $sql .= $session_condition;
         }
     } else {
         $session_condition = api_get_session_condition($session_id, true);
     }
     if (!is_null($status)) {
         $sql .= "  AND  g.status = '" . intval($status) . "' ";
     }
     $sql .= " AND g.c_id = {$course_id} ";
     if (!empty($session_condition)) {
         $sql .= $session_condition;
     }
     $sql .= " GROUP BY g.id ORDER BY UPPER(g.name)";
     $groupList = Database::query($sql);
     $groups = array();
     while ($thisGroup = Database::fetch_array($groupList)) {
         $thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['id']));
         if ($thisGroup['session_id'] != 0) {
             $sql = 'SELECT name FROM ' . Database::get_main_table(TABLE_MAIN_SESSION) . '
                     WHERE id=' . $thisGroup['session_id'];
             $rs_session = Database::query($sql);
             if (Database::num_rows($rs_session) > 0) {
                 $thisGroup['session_name'] = Database::result($rs_session, 0, 0);
             }
         }
         $groups[] = $thisGroup;
     }
     return $groups;
 }
    /**
     * Restore surveys
     */
    function restore_surveys()
    {
        if ($this->course->has_resources(RESOURCE_SURVEY)) {
            $table_sur = Database::get_course_table(TABLE_SURVEY);
            $table_que = Database::get_course_table(TABLE_SURVEY_QUESTION);
            $table_ans = Database::get_course_table(TABLE_SURVEY_QUESTION_OPTION);
            $resources = $this->course->resources;
            foreach ($resources[RESOURCE_SURVEY] as $id => $survey) {
                $sql_check = 'SELECT survey_id FROM ' . $table_sur . '
							WHERE 	c_id = ' . $this->destination_course_id . ' AND
									code = "' . self::DBUTF8escapestring($survey->code) . '" AND
									lang = "' . self::DBUTF8escapestring($survey->lang) . '" ';
                $result_check = Database::query($sql_check);
                // check resources inside html from fckeditor tool and copy correct urls into recipient course
                $survey->title = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->title, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $survey->subtitle = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->subtitle, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $survey->intro = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->intro, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $survey->surveythanks = DocumentManager::replace_urls_inside_content_html_from_copy_course($survey->surveythanks, $this->course->code, $this->course->destination_path, $this->course->backup_path, $this->course->info['path']);
                $sql = "INSERT INTO " . $table_sur . " " . "SET\n\t\t\t\t\t\tc_id = " . $this->destination_course_id . " ,\n\t\t\t\t\t\tcode = '" . self::DBUTF8escapestring($survey->code) . "', " . "title = '" . self::DBUTF8escapestring($survey->title) . "', " . "subtitle = '" . self::DBUTF8escapestring($survey->subtitle) . "', " . "author = '" . self::DBUTF8escapestring($survey->author) . "', " . "lang = '" . self::DBUTF8escapestring($survey->lang) . "', " . "avail_from = '" . self::DBUTF8escapestring($survey->avail_from) . "', " . "avail_till = '" . self::DBUTF8escapestring($survey->avail_till) . "', " . "is_shared = '" . self::DBUTF8escapestring($survey->is_shared) . "', " . "template = '" . self::DBUTF8escapestring($survey->template) . "', " . "intro = '" . self::DBUTF8escapestring($survey->intro) . "', " . "surveythanks = '" . self::DBUTF8escapestring($survey->surveythanks) . "', " . "creation_date = '" . self::DBUTF8escapestring($survey->creation_date) . "', " . "invited = '0', " . "answered = '0', " . "invite_mail = '" . self::DBUTF8escapestring($survey->invite_mail) . "', " . "reminder_mail = '" . self::DBUTF8escapestring($survey->reminder_mail) . "'";
                //An existing survey exists with the same code and the same language
                if (Database::num_rows($result_check) == 1) {
                    switch ($this->file_option) {
                        case FILE_SKIP:
                            //Do nothing
                            break;
                        case FILE_RENAME:
                            $survey_code = $survey->code . '_';
                            $i = 1;
                            $temp_survey_code = $survey_code . $i;
                            while (!$this->is_survey_code_available($temp_survey_code)) {
                                $temp_survey_code = $survey_code . ++$i;
                            }
                            $survey_code = $temp_survey_code;
                            $sql = "INSERT INTO " . $table_sur . " " . "SET\n\t\t\t\t\t\t\t\t\tc_id = " . $this->destination_course_id . " ,\n\t\t\t\t\t\t\t\t\tcode = '" . self::DBUTF8escapestring($survey_code) . "', " . "title = '" . self::DBUTF8escapestring($survey->title) . "', " . "subtitle = '" . self::DBUTF8escapestring($survey->subtitle) . "', " . "author = '" . self::DBUTF8escapestring($survey->author) . "', " . "lang = '" . self::DBUTF8escapestring($survey->lang) . "', " . "avail_from = '" . self::DBUTF8escapestring($survey->avail_from) . "', " . "avail_till = '" . self::DBUTF8escapestring($survey->avail_till) . "', " . "is_shared = '" . self::DBUTF8escapestring($survey->is_shared) . "', " . "template = '" . self::DBUTF8escapestring($survey->template) . "', " . "intro = '" . self::DBUTF8escapestring($survey->intro) . "', " . "surveythanks = '" . self::DBUTF8escapestring($survey->surveythanks) . "', " . "creation_date = '" . self::DBUTF8escapestring($survey->creation_date) . "', " . "invited = '0', " . "answered = '0', " . "invite_mail = '" . self::DBUTF8escapestring($survey->invite_mail) . "', " . "reminder_mail = '" . self::DBUTF8escapestring($survey->reminder_mail) . "'";
                            //Insert the new source survey
                            Database::query($sql);
                            $new_id = Database::insert_id();
                            $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
                            foreach ($survey->question_ids as $index => $question_id) {
                                $qid = $this->restore_survey_question($question_id, $new_id);
                                $sql = "UPDATE " . $table_que . " SET survey_id = " . $new_id . " WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                Database::query($sql);
                                $sql = "UPDATE " . $table_ans . " SET survey_id = " . $new_id . " WHERE  c_id = " . $this->destination_course_id . " AND  question_id = {$qid}";
                                Database::query($sql);
                            }
                            break;
                        case FILE_OVERWRITE:
                            // Delete the existing survey with the same code and language and import the one of the source course
                            // getting the information of the survey (used for when the survey is shared)
                            require_once api_get_path(SYS_CODE_PATH) . 'survey/survey.lib.php';
                            $sql_select_existing_survey = "SELECT * FROM {$table_sur} WHERE c_id = " . $this->destination_course_id . " AND survey_id='" . self::DBUTF8escapestring(Database::result($result_check, 0, 0)) . "'";
                            $result = Database::query($sql_select_existing_survey);
                            $survey_data = Database::fetch_array($result, 'ASSOC');
                            // if the survey is shared => also delete the shared content
                            if (is_numeric($survey_data['survey_share'])) {
                                survey_manager::delete_survey($survey_data['survey_share'], true, $this->destination_course_id);
                            }
                            $return = survey_manager::delete_survey($survey_data['survey_id'], false, $this->destination_course_id);
                            //Insert the new source survey
                            Database::query($sql);
                            $new_id = Database::insert_id();
                            $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
                            foreach ($survey->question_ids as $index => $question_id) {
                                $qid = $this->restore_survey_question($question_id, $new_id);
                                $sql = "UPDATE {$table_que} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                Database::query($sql);
                                $sql = "UPDATE {$table_ans} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                                Database::query($sql);
                            }
                            break;
                        default:
                            break;
                    }
                } else {
                    Database::query($sql);
                    $new_id = Database::insert_id();
                    $this->course->resources[RESOURCE_SURVEY][$id]->destination_id = $new_id;
                    foreach ($survey->question_ids as $index => $question_id) {
                        $qid = $this->restore_survey_question($question_id, $new_id);
                        $sql = "UPDATE {$table_que} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                        Database::query($sql);
                        $sql = "UPDATE {$table_ans} SET survey_id = {$new_id} WHERE c_id = " . $this->destination_course_id . " AND question_id = {$qid}";
                        Database::query($sql);
                    }
                }
            }
        }
    }
Example #22
0
 /**
  * Get list of groups for current course.
  * @param int $category The id of the category from which the groups are
  * requested
  * @param string $course_code Default is current course
  * @return array An array with all information about the groups.
  */
 public static function get_group_list($category = null, $course_code = null)
 {
     $my_user_id = api_get_user_id();
     $course_info = api_get_course_info($course_code);
     $course_id = $course_info['real_id'];
     $table_group_user = Database::get_course_table(TABLE_GROUP_USER);
     $table_group = Database::get_course_table(TABLE_GROUP);
     //condition for the session
     $session_id = api_get_session_id();
     $my_status_of_user_in_course = CourseManager::get_user_in_course_status($my_user_id, $course_info['code']);
     $is_student_in_session = false;
     if (is_null($my_status_of_user_in_course) || $my_status_of_user_in_course == '') {
         if ($session_id > 0) {
             $is_student_in_session = true;
         }
     }
     // COURSEMANAGER or STUDENT
     if ($my_status_of_user_in_course == COURSEMANAGER || api_is_allowed_to_edit(null, true) || api_is_drh()) {
         $can_see_groups = 1;
         $sql = "SELECT g.iid,\n                        g.name,\n                        g.description,\n                        g.category_id,\n                        g.max_student maximum_number_of_members,\n                        g.secret_directory,\n                        g.self_registration_allowed,\n                        g.self_unregistration_allowed,\n                        g.session_id\n                    FROM {$table_group} g ";
     } elseif ($my_status_of_user_in_course == STUDENT || $is_student_in_session === true || $_SESSION['studentview'] == 'studentview') {
         $can_see_groups = 1;
         $sql = "SELECT g.iid,\n                        g.name,\n                        g.description,\n                        g.category_id,\n                        g.max_student maximum_number_of_members,\n                        g.secret_directory,\n                        g.self_registration_allowed,\n                        g.self_unregistration_allowed,\n                        g.session_id,\n                        ug.user_id is_member\n                    FROM {$table_group} g\n                    LEFT JOIN {$table_group_user} ug\n                    ON (ug.group_id = g.iid AND ug.user_id = '" . api_get_user_id() . "' AND ug.c_id = {$course_id} AND g.c_id = {$course_id})";
     }
     $sql .= " WHERE 1=1 ";
     if ($category != null) {
         $sql .= "  AND g.category_id = '" . Database::escape_string($category) . "' ";
         $session_condition = api_get_session_condition($session_id);
         if (!empty($session_condition)) {
             $sql .= $session_condition;
         }
     } else {
         $session_condition = api_get_session_condition($session_id, true);
     }
     $sql .= " AND g.c_id = {$course_id} ";
     if (!empty($session_condition)) {
         $sql .= $session_condition;
     }
     $sql .= " GROUP BY g.iid ORDER BY UPPER(g.name)";
     if ($can_see_groups == 1) {
         $groupList = Database::query($sql);
     } else {
         return array();
     }
     $groups = array();
     while ($thisGroup = Database::fetch_array($groupList)) {
         $thisGroup['id'] = $thisGroup['iid'];
         $thisGroup['is_member'] = self::is_subscribed($my_user_id, $thisGroup['id']);
         $thisGroup['number_of_members'] = count(self::get_subscribed_users($thisGroup['id']));
         if ($thisGroup['session_id'] != 0) {
             $sql = 'SELECT name FROM ' . Database::get_main_table(TABLE_MAIN_SESSION) . '
                     WHERE id=' . $thisGroup['session_id'];
             $rs_session = Database::query($sql);
             if (Database::num_rows($rs_session) > 0) {
                 $thisGroup['session_name'] = Database::result($rs_session, 0, 0);
             }
         }
         $groups[] = $thisGroup;
     }
     return $groups;
 }
 $visibility = trim(api_utf8_decode($node_session->Visibility));
 $session_category_id = trim(api_utf8_decode($node_session->SessionCategory));
 if (!$updatesession) {
     // Always create a session.
     $unique_name = false;
     // This MUST be initializead.
     $i = 0;
     // Change session name, verify that session doesn't exist.
     while (!$unique_name) {
         if ($i > 1) {
             $suffix = ' - ' . $i;
         }
         $sql = 'SELECT 1 FROM ' . $tbl_session . '
                 WHERE name="' . Database::escape_string($session_name . $suffix) . '"';
         $rs = Database::query($sql);
         if (Database::result($rs, 0, 0)) {
             $i++;
         } else {
             $unique_name = true;
             $session_name .= $suffix;
         }
     }
     // Creating the session.
     $sql_session = "INSERT IGNORE INTO {$tbl_session} SET\n                                    name = '" . Database::escape_string($session_name) . "',\n                                    id_coach = '{$coach_id}',\n                                    date_start = '{$date_start}',\n                                    date_end = '{$date_end}',\n                                    visibility = '{$visibility}',\n                                    session_category_id = '{$session_category_id}',\n                                    session_admin_id=" . intval($_user['user_id']);
     $rs_session = Database::query($sql_session);
     $session_id = Database::insert_id();
     $session_counter++;
 } else {
     // Update the session if it is needed.
     $my_session_result = SessionManager::get_session_by_name($session_name);
     if ($my_session_result === false) {
Example #24
0
                     $message = '<br />' . get_lang('ResultIs') . ' <b>' . $result_comment . '</b><br />';
                     $message .= '<p style="color:#DC0A0A;"><b>' . get_lang('OARHit') . '</b></p>';
                 } else {
                     $message = '<p>' . get_lang('YourDelineation') . '</p>';
                     $message .= $table_resume;
                     $message .= '<br />' . get_lang('ResultIs') . ' <b>' . $result_comment . '</b><br />';
                 }
                 $message .= '<p>' . $comment . '</p>';
                 echo $message;
             } else {
                 echo '<p>' . $comment . '</p>';
             }
             //showing the score
             $queryfree = "select marks from " . $TBL_TRACK_ATTEMPT . " WHERE exe_id = " . intval($id) . " and question_id= " . intval($questionId) . "";
             $resfree = Database::query($queryfree);
             $questionScore = Database::result($resfree, 0, "marks");
             $totalScore += $questionScore;
             echo '</table></td></tr>';
             echo '<tr>
                 <td colspan="2">
                     <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=' . $questionId . '&exe_id=' . $id . '&from_db=1" width="556" height="350">
                         <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=' . $questionId . '&exe_id=' . $id . '&from_db=1" />
                     </object>
                 </td>
             </tr>
             </table>';
         }
     }
 }
 if ($show_results) {
     if ($answerType != HOT_SPOT) {
 /**
  * This function was originally found in the exercise_show.php
  * @param int       $exeId
  * @param int       $questionId
  * @param int       $choice the user selected
  * @param string    $from  function is called from 'exercise_show' or 'exercise_result'
  * @param array     $exerciseResultCoordinates the hotspot coordinates $hotspot[$question_id] = coordinates
  * @param bool      $saved_results save results in the DB or just show the reponse
  * @param bool      $from_database gets information from DB or from the current selection
  * @param bool      $show_result show results or not
  * @param int       $propagate_neg
  * @param array     $hotspot_delineation_result
  *
  * @todo    reduce parameters of this function
  * @return  string  html code
  */
 public function manage_answer($exeId, $questionId, $choice, $from = 'exercise_show', $exerciseResultCoordinates = array(), $saved_results = true, $from_database = false, $show_result = true, $propagate_neg = 0, $hotspot_delineation_result = array())
 {
     global $debug;
     //needed in order to use in the exercise_attempt() for the time
     global $learnpath_id, $learnpath_item_id;
     require_once api_get_path(LIBRARY_PATH) . 'geometry.lib.php';
     $feedback_type = $this->selectFeedbackType();
     $results_disabled = $this->selectResultsDisabled();
     if ($debug) {
         error_log("<------ manage_answer ------> ");
         error_log('exe_id: ' . $exeId);
         error_log('$from:  ' . $from);
         error_log('$saved_results: ' . intval($saved_results));
         error_log('$from_database: ' . intval($from_database));
         error_log('$show_result: ' . $show_result);
         error_log('$propagate_neg: ' . $propagate_neg);
         error_log('$exerciseResultCoordinates: ' . print_r($exerciseResultCoordinates, 1));
         error_log('$hotspot_delineation_result: ' . print_r($hotspot_delineation_result, 1));
         error_log('$learnpath_id: ' . $learnpath_id);
         error_log('$learnpath_item_id: ' . $learnpath_item_id);
         error_log('$choice: ' . print_r($choice, 1));
     }
     $extra_data = array();
     $final_overlap = 0;
     $final_missing = 0;
     $final_excess = 0;
     $overlap_color = 0;
     $missing_color = 0;
     $excess_color = 0;
     $threadhold1 = 0;
     $threadhold2 = 0;
     $threadhold3 = 0;
     $arrques = null;
     $arrans = null;
     $questionId = intval($questionId);
     $exeId = intval($exeId);
     $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
     // Creates a temporary Question object
     $course_id = $this->course_id;
     $objQuestionTmp = Question::read($questionId, $course_id);
     if ($objQuestionTmp === false) {
         return false;
     }
     $questionName = $objQuestionTmp->selectTitle();
     $questionWeighting = $objQuestionTmp->selectWeighting();
     $answerType = $objQuestionTmp->selectType();
     $quesId = $objQuestionTmp->selectId();
     $extra = $objQuestionTmp->extra;
     $next = 1;
     //not for now
     // Extra information of the question
     if (!empty($extra)) {
         $extra = explode(':', $extra);
         if ($debug) {
             error_log(print_r($extra, 1));
         }
         // Fixes problems with negatives values using intval
         $true_score = floatval(trim($extra[0]));
         $false_score = floatval(trim($extra[1]));
         $doubt_score = floatval(trim($extra[2]));
     }
     $totalWeighting = 0;
     $totalScore = 0;
     // Destruction of the Question object
     unset($objQuestionTmp);
     // Construction of the Answer object
     $objAnswerTmp = new Answer($questionId);
     $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
     if ($debug) {
         error_log('Count of answers: ' . $nbrAnswers);
         error_log('$answerType: ' . $answerType);
     }
     if ($answerType == FREE_ANSWER || $answerType == ORAL_EXPRESSION || $answerType == CALCULATED_ANSWER) {
         $nbrAnswers = 1;
     }
     $nano = null;
     if ($answerType == ORAL_EXPRESSION) {
         $exe_info = Event::get_exercise_results_by_attempt($exeId);
         $exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null;
         $params = array();
         $params['course_id'] = $course_id;
         $params['session_id'] = api_get_session_id();
         $params['user_id'] = isset($exe_info['exe_user_id']) ? $exe_info['exe_user_id'] : api_get_user_id();
         $params['exercise_id'] = isset($exe_info['exe_exo_id']) ? $exe_info['exe_exo_id'] : $this->id;
         $params['question_id'] = $questionId;
         $params['exe_id'] = isset($exe_info['exe_id']) ? $exe_info['exe_id'] : $exeId;
         $nano = new Nanogong($params);
         //probably this attempt came in an exercise all question by page
         if ($feedback_type == 0) {
             $nano->replace_with_real_exe($exeId);
         }
     }
     $user_answer = '';
     // Get answer list for matching
     $sql = "SELECT id_auto, id, answer\n                FROM {$table_ans}\n                WHERE c_id = {$course_id} AND question_id = {$questionId}";
     $res_answer = Database::query($sql);
     $answerMatching = array();
     while ($real_answer = Database::fetch_array($res_answer)) {
         $answerMatching[$real_answer['id_auto']] = $real_answer['answer'];
     }
     $real_answers = array();
     $quiz_question_options = Question::readQuestionOption($questionId, $course_id);
     $organs_at_risk_hit = 0;
     $questionScore = 0;
     if ($debug) {
         error_log('Start answer loop ');
     }
     $answer_correct_array = array();
     for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
         $answer = $objAnswerTmp->selectAnswer($answerId);
         $answerComment = $objAnswerTmp->selectComment($answerId);
         $answerCorrect = $objAnswerTmp->isCorrect($answerId);
         $answerWeighting = (double) $objAnswerTmp->selectWeighting($answerId);
         $answerAutoId = $objAnswerTmp->selectAutoId($answerId);
         $answer_correct_array[$answerId] = (bool) $answerCorrect;
         if ($debug) {
             error_log("answer auto id: {$answerAutoId} ");
             error_log("answer correct: {$answerCorrect} ");
         }
         // Delineation
         $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1);
         $answer_delineation_destination = $objAnswerTmp->selectDestination(1);
         switch ($answerType) {
             // for unique answer
             case UNIQUE_ANSWER:
             case UNIQUE_ANSWER_IMAGE:
             case UNIQUE_ANSWER_NO_OPTION:
                 if ($from_database) {
                     $sql = "SELECT answer FROM {$TBL_TRACK_ATTEMPT}\n                                WHERE\n                                    exe_id = '" . $exeId . "' AND\n                                    question_id= '" . $questionId . "'";
                     $result = Database::query($sql);
                     $choice = Database::result($result, 0, "answer");
                     $studentChoice = $choice == $answerAutoId ? 1 : 0;
                     if ($studentChoice) {
                         $questionScore += $answerWeighting;
                         $totalScore += $answerWeighting;
                     }
                 } else {
                     $studentChoice = $choice == $answerAutoId ? 1 : 0;
                     if ($studentChoice) {
                         $questionScore += $answerWeighting;
                         $totalScore += $answerWeighting;
                     }
                 }
                 break;
                 // for multiple answers
             // for multiple answers
             case MULTIPLE_ANSWER_TRUE_FALSE:
                 if ($from_database) {
                     $choice = array();
                     $sql = "SELECT answer FROM {$TBL_TRACK_ATTEMPT}\n                                WHERE\n                                    exe_id = {$exeId} AND\n                                    question_id = " . $questionId;
                     $result = Database::query($sql);
                     while ($row = Database::fetch_array($result)) {
                         $ind = $row['answer'];
                         $values = explode(':', $ind);
                         $my_answer_id = isset($values[0]) ? $values[0] : '';
                         $option = isset($values[1]) ? $values[1] : '';
                         $choice[$my_answer_id] = $option;
                     }
                 }
                 $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                 if (!empty($studentChoice)) {
                     if ($studentChoice == $answerCorrect) {
                         $questionScore += $true_score;
                     } else {
                         if ($quiz_question_options[$studentChoice]['name'] == "Don't know" || $quiz_question_options[$studentChoice]['name'] == "DoubtScore") {
                             $questionScore += $doubt_score;
                         } else {
                             $questionScore += $false_score;
                         }
                     }
                 } else {
                     // If no result then the user just hit don't know
                     $studentChoice = 3;
                     $questionScore += $doubt_score;
                 }
                 $totalScore = $questionScore;
                 break;
             case MULTIPLE_ANSWER:
                 //2
                 if ($from_database) {
                     $choice = array();
                     $sql = "SELECT answer FROM " . $TBL_TRACK_ATTEMPT . "\n                                WHERE exe_id = '" . $exeId . "' AND question_id= '" . $questionId . "'";
                     $resultans = Database::query($sql);
                     while ($row = Database::fetch_array($resultans)) {
                         $ind = $row['answer'];
                         $choice[$ind] = 1;
                     }
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                     $real_answers[$answerId] = (bool) $studentChoice;
                     if ($studentChoice) {
                         $questionScore += $answerWeighting;
                     }
                 } else {
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                     $real_answers[$answerId] = (bool) $studentChoice;
                     if (isset($studentChoice)) {
                         $questionScore += $answerWeighting;
                     }
                 }
                 $totalScore += $answerWeighting;
                 if ($debug) {
                     error_log("studentChoice: {$studentChoice}");
                 }
                 break;
             case GLOBAL_MULTIPLE_ANSWER:
                 if ($from_database) {
                     $choice = array();
                     $sql = "SELECT answer FROM {$TBL_TRACK_ATTEMPT}\n                                WHERE exe_id = '" . $exeId . "' AND question_id= '" . $questionId . "'";
                     $resultans = Database::query($sql);
                     while ($row = Database::fetch_array($resultans)) {
                         $ind = $row['answer'];
                         $choice[$ind] = 1;
                     }
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                     $real_answers[$answerId] = (bool) $studentChoice;
                     if ($studentChoice) {
                         $questionScore += $answerWeighting;
                     }
                 } else {
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                     if (isset($studentChoice)) {
                         $questionScore += $answerWeighting;
                     }
                     $real_answers[$answerId] = (bool) $studentChoice;
                 }
                 $totalScore += $answerWeighting;
                 if ($debug) {
                     error_log("studentChoice: {$studentChoice}");
                 }
                 break;
             case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
                 if ($from_database) {
                     $sql = "SELECT answer FROM " . $TBL_TRACK_ATTEMPT . "\n                                WHERE exe_id = {$exeId} AND question_id= " . $questionId;
                     $resultans = Database::query($sql);
                     while ($row = Database::fetch_array($resultans)) {
                         $ind = $row['answer'];
                         $result = explode(':', $ind);
                         if (isset($result[0])) {
                             $my_answer_id = isset($result[0]) ? $result[0] : '';
                             $option = isset($result[1]) ? $result[1] : '';
                             $choice[$my_answer_id] = $option;
                         }
                     }
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : '';
                     if ($answerCorrect == $studentChoice) {
                         //$answerCorrect = 1;
                         $real_answers[$answerId] = true;
                     } else {
                         //$answerCorrect = 0;
                         $real_answers[$answerId] = false;
                     }
                 } else {
                     $studentChoice = $choice[$answerAutoId];
                     if ($answerCorrect == $studentChoice) {
                         //$answerCorrect = 1;
                         $real_answers[$answerId] = true;
                     } else {
                         //$answerCorrect = 0;
                         $real_answers[$answerId] = false;
                     }
                 }
                 break;
             case MULTIPLE_ANSWER_COMBINATION:
                 if ($from_database) {
                     $sql = "SELECT answer FROM {$TBL_TRACK_ATTEMPT}\n                                WHERE exe_id = {$exeId} AND question_id= {$questionId}";
                     $resultans = Database::query($sql);
                     while ($row = Database::fetch_array($resultans)) {
                         $ind = $row['answer'];
                         $choice[$ind] = 1;
                     }
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                     if ($answerCorrect == 1) {
                         if ($studentChoice) {
                             $real_answers[$answerId] = true;
                         } else {
                             $real_answers[$answerId] = false;
                         }
                     } else {
                         if ($studentChoice) {
                             $real_answers[$answerId] = false;
                         } else {
                             $real_answers[$answerId] = true;
                         }
                     }
                 } else {
                     $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
                     if ($answerCorrect == 1) {
                         if ($studentChoice) {
                             $real_answers[$answerId] = true;
                         } else {
                             $real_answers[$answerId] = false;
                         }
                     } else {
                         if ($studentChoice) {
                             $real_answers[$answerId] = false;
                         } else {
                             $real_answers[$answerId] = true;
                         }
                     }
                 }
                 break;
             case FILL_IN_BLANKS:
                 $str = '';
                 if ($from_database) {
                     $sql = "SELECT answer\n                                    FROM {$TBL_TRACK_ATTEMPT}\n                                    WHERE\n                                        exe_id = {$exeId} AND\n                                        question_id= " . intval($questionId);
                     $result = Database::query($sql);
                     $str = Database::result($result, 0, 'answer');
                 }
                 if ($saved_results == false && strpos($str, 'font color') !== false) {
                     // the question is encoded like this
                     // [A] B [C] D [E] F::10,10,10@1
                     // number 1 before the "@" means that is a switchable fill in blank question
                     // [A] B [C] D [E] F::10,10,10@ or  [A] B [C] D [E] F::10,10,10
                     // means that is a normal fill blank question
                     // first we explode the "::"
                     $pre_array = explode('::', $answer);
                     // is switchable fill blank or not
                     $last = count($pre_array) - 1;
                     $is_set_switchable = explode('@', $pre_array[$last]);
                     $switchable_answer_set = false;
                     if (isset($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
                         $switchable_answer_set = true;
                     }
                     $answer = '';
                     for ($k = 0; $k < $last; $k++) {
                         $answer .= $pre_array[$k];
                     }
                     // splits weightings that are joined with a comma
                     $answerWeighting = explode(',', $is_set_switchable[0]);
                     // we save the answer because it will be modified
                     $temp = $answer;
                     $answer = '';
                     $j = 0;
                     //initialise answer tags
                     $user_tags = $correct_tags = $real_text = array();
                     // the loop will stop at the end of the text
                     while (1) {
                         // quits the loop if there are no more blanks (detect '[')
                         if (($pos = api_strpos($temp, '[')) === false) {
                             // adds the end of the text
                             $answer = $temp;
                             $real_text[] = $answer;
                             break;
                             //no more "blanks", quit the loop
                         }
                         // adds the piece of text that is before the blank
                         //and ends with '[' into a general storage array
                         $real_text[] = api_substr($temp, 0, $pos + 1);
                         $answer .= api_substr($temp, 0, $pos + 1);
                         //take the string remaining (after the last "[" we found)
                         $temp = api_substr($temp, $pos + 1);
                         // quit the loop if there are no more blanks, and update $pos to the position of next ']'
                         if (($pos = api_strpos($temp, ']')) === false) {
                             // adds the end of the text
                             $answer .= $temp;
                             break;
                         }
                         if ($from_database) {
                             $queryfill = "SELECT answer FROM " . $TBL_TRACK_ATTEMPT . "\n                                          WHERE\n                                            exe_id = '" . $exeId . "' AND\n                                            question_id= " . intval($questionId) . "";
                             $resfill = Database::query($queryfill);
                             $str = Database::result($resfill, 0, 'answer');
                             api_preg_match_all('#\\[([^[]*)\\]#', $str, $arr);
                             $str = str_replace('\\r\\n', '', $str);
                             $choice = $arr[1];
                             if (isset($choice[$j])) {
                                 $tmp = api_strrpos($choice[$j], ' / ');
                                 $choice[$j] = api_substr($choice[$j], 0, $tmp);
                                 $choice[$j] = trim($choice[$j]);
                                 // Needed to let characters ' and " to work as part of an answer
                                 $choice[$j] = stripslashes($choice[$j]);
                             } else {
                                 $choice[$j] = null;
                             }
                         } else {
                             // This value is the user input, not escaped while correct answer is escaped by fckeditor
                             $choice[$j] = api_htmlentities(trim($choice[$j]));
                         }
                         $user_tags[] = $choice[$j];
                         //put the contents of the [] answer tag into correct_tags[]
                         $correct_tags[] = api_substr($temp, 0, $pos);
                         $j++;
                         $temp = api_substr($temp, $pos + 1);
                     }
                     $answer = '';
                     $real_correct_tags = $correct_tags;
                     $chosen_list = array();
                     for ($i = 0; $i < count($real_correct_tags); $i++) {
                         if ($i == 0) {
                             $answer .= $real_text[0];
                         }
                         if (!$switchable_answer_set) {
                             // Needed to parse ' and " characters
                             $user_tags[$i] = stripslashes($user_tags[$i]);
                             if ($correct_tags[$i] == $user_tags[$i]) {
                                 // gives the related weighting to the student
                                 $questionScore += $answerWeighting[$i];
                                 // increments total score
                                 $totalScore += $answerWeighting[$i];
                                 // adds the word in green at the end of the string
                                 $answer .= $correct_tags[$i];
                             } elseif (!empty($user_tags[$i])) {
                                 // else if the word entered by the student IS NOT the same as the one defined by the professor
                                 // adds the word in red at the end of the string, and strikes it
                                 $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
                             } else {
                                 // adds a tabulation if no word has been typed by the student
                                 $answer .= '';
                                 // remove &nbsp; that causes issue
                             }
                         } else {
                             // switchable fill in the blanks
                             if (in_array($user_tags[$i], $correct_tags)) {
                                 $chosen_list[] = $user_tags[$i];
                                 $correct_tags = array_diff($correct_tags, $chosen_list);
                                 // gives the related weighting to the student
                                 $questionScore += $answerWeighting[$i];
                                 // increments total score
                                 $totalScore += $answerWeighting[$i];
                                 // adds the word in green at the end of the string
                                 $answer .= $user_tags[$i];
                             } elseif (!empty($user_tags[$i])) {
                                 // else if the word entered by the student IS NOT the same as the one defined by the professor
                                 // adds the word in red at the end of the string, and strikes it
                                 $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
                             } else {
                                 // adds a tabulation if no word has been typed by the student
                                 $answer .= '';
                                 // remove &nbsp; that causes issue
                             }
                         }
                         // adds the correct word, followed by ] to close the blank
                         $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
                         if (isset($real_text[$i + 1])) {
                             $answer .= $real_text[$i + 1];
                         }
                     }
                 } else {
                     // insert the student result in the track_e_attempt table, field answer
                     // $answer is the answer like in the c_quiz_answer table for the question
                     // student data are choice[]
                     $listCorrectAnswers = FillBlanks::getAnswerInfo($answer);
                     $switchableAnswerSet = $listCorrectAnswers["switchable"];
                     $answerWeighting = $listCorrectAnswers["tabweighting"];
                     // user choices is an array $choice
                     // get existing user data in n the BDD
                     if ($from_database) {
                         $sql = "SELECT answer\n                                    FROM {$TBL_TRACK_ATTEMPT}\n                                    WHERE\n                                        exe_id = {$exeId} AND\n                                        question_id= " . intval($questionId);
                         $result = Database::query($sql);
                         $str = Database::result($result, 0, 'answer');
                         $listStudentResults = FillBlanks::getAnswerInfo($str, true);
                         $choice = $listStudentResults['studentanswer'];
                     }
                     // loop other all blanks words
                     if (!$switchableAnswerSet) {
                         // not switchable answer, must be in the same place than teacher order
                         for ($i = 0; $i < count($listCorrectAnswers['tabwords']); $i++) {
                             $studentAnswer = isset($choice[$i]) ? trim($choice[$i]) : '';
                             // This value is the user input, not escaped while correct answer is escaped by fckeditor
                             // Works with cyrillic alphabet and when using ">" chars see #7718 #7610 #7618
                             if (!$from_database) {
                                 $studentAnswer = htmlentities(api_utf8_encode($studentAnswer));
                             }
                             $correctAnswer = $listCorrectAnswers['tabwords'][$i];
                             $isAnswerCorrect = 0;
                             if (FillBlanks::isGoodStudentAnswer($studentAnswer, $correctAnswer)) {
                                 // gives the related weighting to the student
                                 $questionScore += $answerWeighting[$i];
                                 // increments total score
                                 $totalScore += $answerWeighting[$i];
                                 $isAnswerCorrect = 1;
                             }
                             $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
                             $listCorrectAnswers['studentscore'][$i] = $isAnswerCorrect;
                         }
                     } else {
                         // switchable answer
                         $listStudentAnswerTemp = $choice;
                         $listTeacherAnswerTemp = $listCorrectAnswers['tabwords'];
                         // for every teacher answer, check if there is a student answer
                         for ($i = 0; $i < count($listStudentAnswerTemp); $i++) {
                             $studentAnswer = trim($listStudentAnswerTemp[$i]);
                             $found = false;
                             for ($j = 0; $j < count($listTeacherAnswerTemp); $j++) {
                                 $correctAnswer = $listTeacherAnswerTemp[$j];
                                 if (!$found) {
                                     if (FillBlanks::isGoodStudentAnswer($studentAnswer, $correctAnswer)) {
                                         $questionScore += $answerWeighting[$i];
                                         $totalScore += $answerWeighting[$i];
                                         $listTeacherAnswerTemp[$j] = "";
                                         $found = true;
                                     }
                                 }
                             }
                             $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
                             if (!$found) {
                                 $listCorrectAnswers['studentscore'][$i] = 0;
                             } else {
                                 $listCorrectAnswers['studentscore'][$i] = 1;
                             }
                         }
                     }
                     $answer = FillBlanks::getAnswerInStudentAttempt($listCorrectAnswers);
                 }
                 break;
                 // for calculated answer
             // for calculated answer
             case CALCULATED_ANSWER:
                 $calculatedAnswer = Session::read('calculatedAnswerId');
                 $answer = $objAnswerTmp->selectAnswer($calculatedAnswer[$questionId]);
                 $preArray = explode('@@', $answer);
                 $last = count($preArray) - 1;
                 $answer = '';
                 for ($k = 0; $k < $last; $k++) {
                     $answer .= $preArray[$k];
                 }
                 $answerWeighting = array($answerWeighting);
                 // we save the answer because it will be modified
                 $temp = $answer;
                 $answer = '';
                 $j = 0;
                 //initialise answer tags
                 $userTags = $correctTags = $realText = array();
                 // the loop will stop at the end of the text
                 while (1) {
                     // quits the loop if there are no more blanks (detect '[')
                     if (($pos = api_strpos($temp, '[')) === false) {
                         // adds the end of the text
                         $answer = $temp;
                         $realText[] = $answer;
                         break;
                         //no more "blanks", quit the loop
                     }
                     // adds the piece of text that is before the blank
                     //and ends with '[' into a general storage array
                     $realText[] = api_substr($temp, 0, $pos + 1);
                     $answer .= api_substr($temp, 0, $pos + 1);
                     //take the string remaining (after the last "[" we found)
                     $temp = api_substr($temp, $pos + 1);
                     // quit the loop if there are no more blanks, and update $pos to the position of next ']'
                     if (($pos = api_strpos($temp, ']')) === false) {
                         // adds the end of the text
                         $answer .= $temp;
                         break;
                     }
                     if ($from_database) {
                         $queryfill = "SELECT answer FROM " . $TBL_TRACK_ATTEMPT . "\n                                          WHERE\n                                            exe_id = '" . $exeId . "' AND\n                                            question_id= " . intval($questionId) . "";
                         $resfill = Database::query($queryfill);
                         $str = Database::result($resfill, 0, 'answer');
                         api_preg_match_all('#\\[([^[]*)\\]#', $str, $arr);
                         $str = str_replace('\\r\\n', '', $str);
                         $choice = $arr[1];
                         if (isset($choice[$j])) {
                             $tmp = api_strrpos($choice[$j], ' / ');
                             $choice[$j] = api_substr($choice[$j], 0, $tmp);
                             $choice[$j] = trim($choice[$j]);
                             // Needed to let characters ' and " to work as part of an answer
                             $choice[$j] = stripslashes($choice[$j]);
                         } else {
                             $choice[$j] = null;
                         }
                     } else {
                         // This value is the user input, not escaped while correct answer is escaped by fckeditor
                         $choice[$j] = api_htmlentities(trim($choice[$j]));
                     }
                     $userTags[] = $choice[$j];
                     //put the contents of the [] answer tag into correct_tags[]
                     $correctTags[] = api_substr($temp, 0, $pos);
                     $j++;
                     $temp = api_substr($temp, $pos + 1);
                 }
                 $answer = '';
                 $realCorrectTags = $correctTags;
                 for ($i = 0; $i < count($realCorrectTags); $i++) {
                     if ($i == 0) {
                         $answer .= $realText[0];
                     }
                     // Needed to parse ' and " characters
                     $userTags[$i] = stripslashes($userTags[$i]);
                     if ($correctTags[$i] == $userTags[$i]) {
                         // gives the related weighting to the student
                         $questionScore += $answerWeighting[$i];
                         // increments total score
                         $totalScore += $answerWeighting[$i];
                         // adds the word in green at the end of the string
                         $answer .= $correctTags[$i];
                     } elseif (!empty($userTags[$i])) {
                         // else if the word entered by the student IS NOT the same as the one defined by the professor
                         // adds the word in red at the end of the string, and strikes it
                         $answer .= '<font color="red"><s>' . $userTags[$i] . '</s></font>';
                     } else {
                         // adds a tabulation if no word has been typed by the student
                         $answer .= '';
                         // remove &nbsp; that causes issue
                     }
                     // adds the correct word, followed by ] to close the blank
                     $answer .= ' / <font color="green"><b>' . $realCorrectTags[$i] . '</b></font>]';
                     if (isset($realText[$i + 1])) {
                         $answer .= $realText[$i + 1];
                     }
                 }
                 break;
                 // for free answer
             // for free answer
             case FREE_ANSWER:
                 if ($from_database) {
                     $query = "SELECT answer, marks FROM " . $TBL_TRACK_ATTEMPT . "\n                                   WHERE exe_id = '" . $exeId . "' AND question_id= '" . $questionId . "'";
                     $resq = Database::query($query);
                     $data = Database::fetch_array($resq);
                     $choice = $data['answer'];
                     $choice = str_replace('\\r\\n', '', $choice);
                     $choice = stripslashes($choice);
                     $questionScore = $data['marks'];
                     if ($questionScore == -1) {
                         $totalScore += 0;
                     } else {
                         $totalScore += $questionScore;
                     }
                     if ($questionScore == '') {
                         $questionScore = 0;
                     }
                     $arrques = $questionName;
                     $arrans = $choice;
                 } else {
                     $studentChoice = $choice;
                     if ($studentChoice) {
                         //Fixing negative puntation see #2193
                         $questionScore = 0;
                         $totalScore += 0;
                     }
                 }
                 break;
             case ORAL_EXPRESSION:
                 if ($from_database) {
                     $query = "SELECT answer, marks FROM " . $TBL_TRACK_ATTEMPT . "\n                                   WHERE exe_id = '" . $exeId . "' AND question_id= '" . $questionId . "'";
                     $resq = Database::query($query);
                     $choice = Database::result($resq, 0, 'answer');
                     $choice = str_replace('\\r\\n', '', $choice);
                     $choice = stripslashes($choice);
                     $questionScore = Database::result($resq, 0, "marks");
                     if ($questionScore == -1) {
                         $totalScore += 0;
                     } else {
                         $totalScore += $questionScore;
                     }
                     $arrques = $questionName;
                     $arrans = $choice;
                 } else {
                     $studentChoice = $choice;
                     if ($studentChoice) {
                         //Fixing negative puntation see #2193
                         $questionScore = 0;
                         $totalScore += 0;
                     }
                 }
                 break;
             case DRAGGABLE:
                 //no break
             //no break
             case MATCHING_DRAGGABLE:
                 //no break
             //no break
             case MATCHING:
                 if ($from_database) {
                     $sql = 'SELECT id, answer, id_auto
                             FROM ' . $table_ans . '
                             WHERE
                                 c_id = ' . $course_id . ' AND
                                 question_id = "' . $questionId . '" AND
                                 correct = 0';
                     $res_answer = Database::query($sql);
                     // Getting the real answer
                     $real_list = array();
                     while ($real_answer = Database::fetch_array($res_answer)) {
                         $real_list[$real_answer['id_auto']] = $real_answer['answer'];
                     }
                     $sql = 'SELECT id, answer, correct, id_auto, ponderation
                             FROM ' . $table_ans . '
                             WHERE
                                 c_id = ' . $course_id . ' AND
                                 question_id="' . $questionId . '" AND
                                 correct <> 0
                             ORDER BY id_auto';
                     $res_answers = Database::query($sql);
                     $questionScore = 0;
                     while ($a_answers = Database::fetch_array($res_answers)) {
                         $i_answer_id = $a_answers['id'];
                         //3
                         $s_answer_label = $a_answers['answer'];
                         // your daddy - your mother
                         $i_answer_correct_answer = $a_answers['correct'];
                         //1 - 2
                         $i_answer_id_auto = $a_answers['id_auto'];
                         // 3 - 4
                         $sql = "SELECT answer FROM {$TBL_TRACK_ATTEMPT}\n                                    WHERE\n                                        exe_id = '{$exeId}' AND\n                                        question_id = '{$questionId}' AND\n                                        position = '{$i_answer_id_auto}'";
                         $res_user_answer = Database::query($sql);
                         if (Database::num_rows($res_user_answer) > 0) {
                             //  rich - good looking
                             $s_user_answer = Database::result($res_user_answer, 0, 0);
                         } else {
                             $s_user_answer = 0;
                         }
                         $i_answerWeighting = $a_answers['ponderation'];
                         $user_answer = '';
                         if (!empty($s_user_answer)) {
                             if ($answerType == DRAGGABLE) {
                                 if ($s_user_answer == $i_answer_correct_answer) {
                                     $questionScore += $i_answerWeighting;
                                     $totalScore += $i_answerWeighting;
                                     $user_answer = Display::label(get_lang('Correct'), 'success');
                                 } else {
                                     $user_answer = Display::label(get_lang('Incorrect'), 'danger');
                                 }
                             } else {
                                 if ($s_user_answer == $i_answer_correct_answer) {
                                     $questionScore += $i_answerWeighting;
                                     $totalScore += $i_answerWeighting;
                                     if (isset($real_list[$i_answer_id])) {
                                         $user_answer = Display::span($real_list[$i_answer_id]);
                                     }
                                 } else {
                                     $user_answer = Display::span($real_list[$s_user_answer], ['style' => 'color: #FF0000; text-decoration: line-through;']);
                                 }
                             }
                         } elseif ($answerType == DRAGGABLE) {
                             $user_answer = Display::label(get_lang('Incorrect'), 'danger');
                         }
                         if ($show_result) {
                             echo '<tr>';
                             echo '<td>' . $s_answer_label . '</td>';
                             echo '<td>' . $user_answer;
                             if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
                                 if (isset($real_list[$i_answer_correct_answer])) {
                                     echo Display::span($real_list[$i_answer_correct_answer], ['style' => 'color: #008000; font-weight: bold;']);
                                 }
                             }
                             echo '</td>';
                             echo '</tr>';
                         }
                     }
                     break 2;
                     // break the switch and the "for" condition
                 } else {
                     if ($answerCorrect) {
                         if (isset($choice[$answerAutoId]) && $answerCorrect == $choice[$answerAutoId]) {
                             $questionScore += $answerWeighting;
                             $totalScore += $answerWeighting;
                             $user_answer = Display::span($answerMatching[$choice[$answerAutoId]]);
                         } else {
                             if (isset($answerMatching[$choice[$answerAutoId]])) {
                                 $user_answer = Display::span($answerMatching[$choice[$answerAutoId]], ['style' => 'color: #FF0000; text-decoration: line-through;']);
                             }
                         }
                         $matching[$answerAutoId] = $choice[$answerAutoId];
                     }
                     break;
                 }
             case HOT_SPOT:
                 if ($from_database) {
                     $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
                     $sql = "SELECT hotspot_correct\n                                FROM {$TBL_TRACK_HOTSPOT}\n                                WHERE\n                                    hotspot_exe_id = '" . $exeId . "' AND\n                                    hotspot_question_id= '" . $questionId . "' AND\n                                    hotspot_answer_id = " . intval($answerAutoId) . "";
                     $result = Database::query($sql);
                     $studentChoice = Database::result($result, 0, "hotspot_correct");
                     if ($studentChoice) {
                         $questionScore += $answerWeighting;
                         $totalScore += $answerWeighting;
                     }
                 } else {
                     if (!isset($choice[$answerAutoId])) {
                         $choice[$answerAutoId] = 0;
                     } else {
                         $studentChoice = $choice[$answerAutoId];
                         $choiceIsValid = false;
                         if (!empty($studentChoice)) {
                             $hotspotType = $objAnswerTmp->selectHotspotType($answerId);
                             $hotspotCoordinates = $objAnswerTmp->selectHotspotCoordinates($answerId);
                             $choicePoint = Geometry::decodePoint($studentChoice);
                             switch ($hotspotType) {
                                 case 'square':
                                     $hotspotProperties = Geometry::decodeSquare($hotspotCoordinates);
                                     $choiceIsValid = Geometry::pointIsInSquare($hotspotProperties, $choicePoint);
                                     break;
                                 case 'circle':
                                     $hotspotProperties = Geometry::decodeEllipse($hotspotCoordinates);
                                     $choiceIsValid = Geometry::pointIsInEllipse($hotspotProperties, $choicePoint);
                                     break;
                                 case 'poly':
                                     $hotspotProperties = Geometry::decodePolygon($hotspotCoordinates);
                                     $choiceIsValid = Geometry::pointIsInPolygon($hotspotProperties, $choicePoint);
                                     break;
                             }
                         }
                         $choice[$answerAutoId] = 0;
                         if ($choiceIsValid) {
                             $questionScore += $answerWeighting;
                             $totalScore += $answerWeighting;
                             $choice[$answerAutoId] = 1;
                         }
                     }
                 }
                 break;
                 // @todo never added to chamilo
                 //for hotspot with fixed order
             // @todo never added to chamilo
             //for hotspot with fixed order
             case HOT_SPOT_ORDER:
                 $studentChoice = $choice['order'][$answerId];
                 if ($studentChoice == $answerId) {
                     $questionScore += $answerWeighting;
                     $totalScore += $answerWeighting;
                     $studentChoice = true;
                 } else {
                     $studentChoice = false;
                 }
                 break;
                 // for hotspot with delineation
             // for hotspot with delineation
             case HOT_SPOT_DELINEATION:
                 if ($from_database) {
                     // getting the user answer
                     $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
                     $query = "SELECT hotspot_correct, hotspot_coordinate\n                                    FROM {$TBL_TRACK_HOTSPOT}\n                                    WHERE\n                                        hotspot_exe_id = '" . $exeId . "' AND\n                                        hotspot_question_id= '" . $questionId . "' AND\n                                        hotspot_answer_id='1'";
                     //by default we take 1 because it's a delineation
                     $resq = Database::query($query);
                     $row = Database::fetch_array($resq, 'ASSOC');
                     $choice = $row['hotspot_correct'];
                     $user_answer = $row['hotspot_coordinate'];
                     // THIS is very important otherwise the poly_compile will throw an error!!
                     // round-up the coordinates
                     $coords = explode('/', $user_answer);
                     $user_array = '';
                     foreach ($coords as $coord) {
                         list($x, $y) = explode(';', $coord);
                         $user_array .= round($x) . ';' . round($y) . '/';
                     }
                     $user_array = substr($user_array, 0, -1);
                 } else {
                     if (!empty($studentChoice)) {
                         $newquestionList[] = $questionId;
                     }
                     if ($answerId === 1) {
                         $studentChoice = $choice[$answerId];
                         $questionScore += $answerWeighting;
                         if ($hotspot_delineation_result[1] == 1) {
                             $totalScore += $answerWeighting;
                             //adding the total
                         }
                     }
                 }
                 $_SESSION['hotspot_coord'][1] = $delineation_cord;
                 $_SESSION['hotspot_dest'][1] = $answer_delineation_destination;
                 break;
         }
         // end switch Answertype
         if ($show_result) {
             if ($debug) {
                 error_log('show result ' . $show_result);
             }
             if ($from == 'exercise_result') {
                 if ($debug) {
                     error_log('Showing questions $from ' . $from);
                 }
                 //display answers (if not matching type, or if the answer is correct)
                 if (!in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]) || $answerCorrect) {
                     if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, GLOBAL_MULTIPLE_ANSWER))) {
                         //if ($origin != 'learnpath') {
                         ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, 0, 0, 0, $results_disabled);
                         //}
                     } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
                         //if ($origin!='learnpath') {
                         ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, 0, $questionId, 0, $results_disabled);
                         //}
                     } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
                         //	if ($origin!='learnpath') {
                         ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, 0, 0, 0, $results_disabled);
                         //}
                     } elseif ($answerType == FILL_IN_BLANKS) {
                         //if ($origin!='learnpath') {
                         ExerciseShowFunctions::display_fill_in_blanks_answer($feedback_type, $answer, 0, 0, $results_disabled);
                         //	}
                     } elseif ($answerType == CALCULATED_ANSWER) {
                         //if ($origin!='learnpath') {
                         ExerciseShowFunctions::display_calculated_answer($feedback_type, $answer, 0, 0);
                         //  }
                     } elseif ($answerType == FREE_ANSWER) {
                         //if($origin != 'learnpath') {
                         ExerciseShowFunctions::display_free_answer($feedback_type, $choice, $exeId, $questionId, $questionScore);
                         //}
                     } elseif ($answerType == ORAL_EXPRESSION) {
                         // to store the details of open questions in an array to be used in mail
                         //if ($origin != 'learnpath') {
                         ExerciseShowFunctions::display_oral_expression_answer($feedback_type, $choice, 0, 0, $nano);
                         //}
                     } elseif ($answerType == HOT_SPOT) {
                         //if ($origin != 'learnpath') {
                         ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $results_disabled);
                         //	}
                     } elseif ($answerType == HOT_SPOT_ORDER) {
                         //if ($origin != 'learnpath') {
                         ExerciseShowFunctions::display_hotspot_order_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment);
                         //}
                     } elseif ($answerType == HOT_SPOT_DELINEATION) {
                         $user_answer = $_SESSION['exerciseResultCoordinates'][$questionId];
                         //round-up the coordinates
                         $coords = explode('/', $user_answer);
                         $user_array = '';
                         foreach ($coords as $coord) {
                             list($x, $y) = explode(';', $coord);
                             $user_array .= round($x) . ';' . round($y) . '/';
                         }
                         $user_array = substr($user_array, 0, -1);
                         if ($next) {
                             $user_answer = $user_array;
                             // we compare only the delineation not the other points
                             $answer_question = $_SESSION['hotspot_coord'][1];
                             $answerDestination = $_SESSION['hotspot_dest'][1];
                             //calculating the area
                             $poly_user = convert_coordinates($user_answer, '/');
                             $poly_answer = convert_coordinates($answer_question, '|');
                             $max_coord = poly_get_max($poly_user, $poly_answer);
                             $poly_user_compiled = poly_compile($poly_user, $max_coord);
                             $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
                             $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord);
                             $overlap = $poly_results['both'];
                             $poly_answer_area = $poly_results['s1'];
                             $poly_user_area = $poly_results['s2'];
                             $missing = $poly_results['s1Only'];
                             $excess = $poly_results['s2Only'];
                             //$overlap = round(polygons_overlap($poly_answer,$poly_user));
                             // //this is an area in pixels
                             if ($debug > 0) {
                                 error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0);
                             }
                             if ($overlap < 1) {
                                 //shortcut to avoid complicated calculations
                                 $final_overlap = 0;
                                 $final_missing = 100;
                                 $final_excess = 100;
                             } else {
                                 // the final overlap is the percentage of the initial polygon
                                 // that is overlapped by the user's polygon
                                 $final_overlap = round((double) $overlap / (double) $poly_answer_area * 100);
                                 if ($debug > 1) {
                                     error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0);
                                 }
                                 // the final missing area is the percentage of the initial polygon
                                 // that is not overlapped by the user's polygon
                                 $final_missing = 100 - $final_overlap;
                                 if ($debug > 1) {
                                     error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0);
                                 }
                                 // the final excess area is the percentage of the initial polygon's size
                                 // that is covered by the user's polygon outside of the initial polygon
                                 $final_excess = round(((double) $poly_user_area - (double) $overlap) / (double) $poly_answer_area * 100);
                                 if ($debug > 1) {
                                     error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0);
                                 }
                             }
                             //checking the destination parameters parsing the "@@"
                             $destination_items = explode('@@', $answerDestination);
                             $threadhold_total = $destination_items[0];
                             $threadhold_items = explode(';', $threadhold_total);
                             $threadhold1 = $threadhold_items[0];
                             // overlap
                             $threadhold2 = $threadhold_items[1];
                             // excess
                             $threadhold3 = $threadhold_items[2];
                             //missing
                             // if is delineation
                             if ($answerId === 1) {
                                 //setting colors
                                 if ($final_overlap >= $threadhold1) {
                                     $overlap_color = true;
                                     //echo 'a';
                                 }
                                 //echo $excess.'-'.$threadhold2;
                                 if ($final_excess <= $threadhold2) {
                                     $excess_color = true;
                                     //echo 'b';
                                 }
                                 //echo '--------'.$missing.'-'.$threadhold3;
                                 if ($final_missing <= $threadhold3) {
                                     $missing_color = true;
                                     //echo 'c';
                                 }
                                 // if pass
                                 if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) {
                                     $next = 1;
                                     //go to the oars
                                     $result_comment = get_lang('Acceptable');
                                     $final_answer = 1;
                                     // do not update with  update_exercise_attempt
                                 } else {
                                     $next = 0;
                                     $result_comment = get_lang('Unacceptable');
                                     $comment = $answerDestination = $objAnswerTmp->selectComment(1);
                                     $answerDestination = $objAnswerTmp->selectDestination(1);
                                     //checking the destination parameters parsing the "@@"
                                     $destination_items = explode('@@', $answerDestination);
                                 }
                             } elseif ($answerId > 1) {
                                 if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') {
                                     if ($debug > 0) {
                                         error_log(__LINE__ . ' - answerId is of type noerror', 0);
                                     }
                                     //type no error shouldn't be treated
                                     $next = 1;
                                     continue;
                                 }
                                 if ($debug > 0) {
                                     error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0);
                                 }
                                 //check the intersection between the oar and the user
                                 //echo 'user';	print_r($x_user_list);		print_r($y_user_list);
                                 //echo 'official';print_r($x_list);print_r($y_list);
                                 //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list);
                                 $inter = $result['success'];
                                 //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
                                 $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId);
                                 $poly_answer = convert_coordinates($delineation_cord, '|');
                                 $max_coord = poly_get_max($poly_user, $poly_answer);
                                 $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
                                 $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled, $max_coord);
                                 if ($overlap == false) {
                                     //all good, no overlap
                                     $next = 1;
                                     continue;
                                 } else {
                                     if ($debug > 0) {
                                         error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0);
                                     }
                                     $organs_at_risk_hit++;
                                     //show the feedback
                                     $next = 0;
                                     $comment = $answerDestination = $objAnswerTmp->selectComment($answerId);
                                     $answerDestination = $objAnswerTmp->selectDestination($answerId);
                                     $destination_items = explode('@@', $answerDestination);
                                     $try_hotspot = $destination_items[1];
                                     $lp_hotspot = $destination_items[2];
                                     $select_question_hotspot = $destination_items[3];
                                     $url_hotspot = $destination_items[4];
                                 }
                             }
                         } else {
                             // the first delineation feedback
                             if ($debug > 0) {
                                 error_log(__LINE__ . ' first', 0);
                             }
                         }
                     } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
                         echo '<tr>';
                         echo Display::tag('td', $answerMatching[$answerId]);
                         echo Display::tag('td', "{$user_answer} / " . Display::tag('strong', $answerMatching[$answerCorrect], ['style' => 'color: #008000; font-weight: bold;']));
                         echo '</tr>';
                     }
                 }
             } else {
                 if ($debug) {
                     error_log('Showing questions $from ' . $from);
                 }
                 switch ($answerType) {
                     case UNIQUE_ANSWER:
                     case UNIQUE_ANSWER_IMAGE:
                     case UNIQUE_ANSWER_NO_OPTION:
                     case MULTIPLE_ANSWER:
                     case GLOBAL_MULTIPLE_ANSWER:
                     case MULTIPLE_ANSWER_COMBINATION:
                         if ($answerId == 1) {
                             ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $exeId, $questionId, $answerId, $results_disabled);
                         } else {
                             ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $exeId, $questionId, "", $results_disabled);
                         }
                         break;
                     case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
                         if ($answerId == 1) {
                             ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $exeId, $questionId, $answerId, $results_disabled);
                         } else {
                             ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $exeId, $questionId, "", $results_disabled);
                         }
                         break;
                     case MULTIPLE_ANSWER_TRUE_FALSE:
                         if ($answerId == 1) {
                             ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $exeId, $questionId, $answerId, $results_disabled);
                         } else {
                             ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $exeId, $questionId, "", $results_disabled);
                         }
                         break;
                     case FILL_IN_BLANKS:
                         ExerciseShowFunctions::display_fill_in_blanks_answer($feedback_type, $answer, $exeId, $questionId, $results_disabled, $str);
                         break;
                     case CALCULATED_ANSWER:
                         ExerciseShowFunctions::display_calculated_answer($feedback_type, $answer, $exeId, $questionId);
                         break;
                     case FREE_ANSWER:
                         echo ExerciseShowFunctions::display_free_answer($feedback_type, $choice, $exeId, $questionId, $questionScore);
                         break;
                     case ORAL_EXPRESSION:
                         echo '<tr>
                             <td valign="top">' . ExerciseShowFunctions::display_oral_expression_answer($feedback_type, $choice, $exeId, $questionId, $nano) . '</td>
                             </tr>
                             </table>';
                         break;
                     case HOT_SPOT:
                         ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $results_disabled);
                         break;
                     case HOT_SPOT_DELINEATION:
                         $user_answer = $user_array;
                         if ($next) {
                             //$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
                             // Save into db
                             /*	$sql = "INSERT INTO $tbl_track_e_hotspot (
                                 * hotspot_user_id,
                                 *  hotspot_course_code,
                                 *  hotspot_exe_id,
                                 *  hotspot_question_id,
                                 *  hotspot_answer_id,
                                 *  hotspot_correct,
                                 *  hotspot_coordinate
                                 *  )
                                VALUES (
                                 * '".Database::escape_string($_user['user_id'])."',
                                 *  '".Database::escape_string($_course['id'])."',
                                 *  '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."',
                                 *  '".Database::escape_string($answerId)."',
                                 *  '".Database::escape_string($studentChoice)."',
                                 *  '".Database::escape_string($user_array)."')";
                                $result = Database::query($sql,__FILE__,__LINE__);
                                 */
                             $user_answer = $user_array;
                             // we compare only the delineation not the other points
                             $answer_question = $_SESSION['hotspot_coord'][1];
                             $answerDestination = $_SESSION['hotspot_dest'][1];
                             //calculating the area
                             $poly_user = convert_coordinates($user_answer, '/');
                             $poly_answer = convert_coordinates($answer_question, '|');
                             $max_coord = poly_get_max($poly_user, $poly_answer);
                             $poly_user_compiled = poly_compile($poly_user, $max_coord);
                             $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
                             $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord);
                             $overlap = $poly_results['both'];
                             $poly_answer_area = $poly_results['s1'];
                             $poly_user_area = $poly_results['s2'];
                             $missing = $poly_results['s1Only'];
                             $excess = $poly_results['s2Only'];
                             //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels
                             if ($debug > 0) {
                                 error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0);
                             }
                             if ($overlap < 1) {
                                 //shortcut to avoid complicated calculations
                                 $final_overlap = 0;
                                 $final_missing = 100;
                                 $final_excess = 100;
                             } else {
                                 // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon
                                 $final_overlap = round((double) $overlap / (double) $poly_answer_area * 100);
                                 if ($debug > 1) {
                                     error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0);
                                 }
                                 // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon
                                 $final_missing = 100 - $final_overlap;
                                 if ($debug > 1) {
                                     error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0);
                                 }
                                 // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon
                                 $final_excess = round(((double) $poly_user_area - (double) $overlap) / (double) $poly_answer_area * 100);
                                 if ($debug > 1) {
                                     error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0);
                                 }
                             }
                             //checking the destination parameters parsing the "@@"
                             $destination_items = explode('@@', $answerDestination);
                             $threadhold_total = $destination_items[0];
                             $threadhold_items = explode(';', $threadhold_total);
                             $threadhold1 = $threadhold_items[0];
                             // overlap
                             $threadhold2 = $threadhold_items[1];
                             // excess
                             $threadhold3 = $threadhold_items[2];
                             //missing
                             // if is delineation
                             if ($answerId === 1) {
                                 //setting colors
                                 if ($final_overlap >= $threadhold1) {
                                     $overlap_color = true;
                                     //echo 'a';
                                 }
                                 //echo $excess.'-'.$threadhold2;
                                 if ($final_excess <= $threadhold2) {
                                     $excess_color = true;
                                     //echo 'b';
                                 }
                                 //echo '--------'.$missing.'-'.$threadhold3;
                                 if ($final_missing <= $threadhold3) {
                                     $missing_color = true;
                                     //echo 'c';
                                 }
                                 // if pass
                                 if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) {
                                     $next = 1;
                                     //go to the oars
                                     $result_comment = get_lang('Acceptable');
                                     $final_answer = 1;
                                     // do not update with  update_exercise_attempt
                                 } else {
                                     $next = 0;
                                     $result_comment = get_lang('Unacceptable');
                                     $comment = $answerDestination = $objAnswerTmp->selectComment(1);
                                     $answerDestination = $objAnswerTmp->selectDestination(1);
                                     //checking the destination parameters parsing the "@@"
                                     $destination_items = explode('@@', $answerDestination);
                                 }
                             } elseif ($answerId > 1) {
                                 if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') {
                                     if ($debug > 0) {
                                         error_log(__LINE__ . ' - answerId is of type noerror', 0);
                                     }
                                     //type no error shouldn't be treated
                                     $next = 1;
                                     continue;
                                 }
                                 if ($debug > 0) {
                                     error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0);
                                 }
                                 //check the intersection between the oar and the user
                                 //echo 'user';	print_r($x_user_list);		print_r($y_user_list);
                                 //echo 'official';print_r($x_list);print_r($y_list);
                                 //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list);
                                 $inter = $result['success'];
                                 //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
                                 $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId);
                                 $poly_answer = convert_coordinates($delineation_cord, '|');
                                 $max_coord = poly_get_max($poly_user, $poly_answer);
                                 $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
                                 $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled, $max_coord);
                                 if ($overlap == false) {
                                     //all good, no overlap
                                     $next = 1;
                                     continue;
                                 } else {
                                     if ($debug > 0) {
                                         error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0);
                                     }
                                     $organs_at_risk_hit++;
                                     //show the feedback
                                     $next = 0;
                                     $comment = $answerDestination = $objAnswerTmp->selectComment($answerId);
                                     $answerDestination = $objAnswerTmp->selectDestination($answerId);
                                     $destination_items = explode('@@', $answerDestination);
                                     $try_hotspot = $destination_items[1];
                                     $lp_hotspot = $destination_items[2];
                                     $select_question_hotspot = $destination_items[3];
                                     $url_hotspot = $destination_items[4];
                                 }
                             }
                         } else {
                             // the first delineation feedback
                             if ($debug > 0) {
                                 error_log(__LINE__ . ' first', 0);
                             }
                         }
                         break;
                     case HOT_SPOT_ORDER:
                         ExerciseShowFunctions::display_hotspot_order_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment);
                         break;
                     case DRAGGABLE:
                         //no break
                     //no break
                     case MATCHING_DRAGGABLE:
                         //no break
                     //no break
                     case MATCHING:
                         echo '<tr>';
                         echo Display::tag('td', $answerMatching[$answerId]);
                         echo Display::tag('td', "{$user_answer} / " . Display::tag('strong', $answerMatching[$answerCorrect], ['style' => 'color: #008000; font-weight: bold;']));
                         echo '</tr>';
                         break;
                 }
             }
         }
         if ($debug) {
             error_log(' ------ ');
         }
     }
     // end for that loops over all answers of the current question
     if ($debug) {
         error_log('-- end answer loop --');
     }
     $final_answer = true;
     foreach ($real_answers as $my_answer) {
         if (!$my_answer) {
             $final_answer = false;
         }
     }
     //we add the total score after dealing with the answers
     if ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
         if ($final_answer) {
             //getting only the first score where we save the weight of all the question
             $answerWeighting = $objAnswerTmp->selectWeighting(1);
             $questionScore += $answerWeighting;
             $totalScore += $answerWeighting;
         }
     }
     //Fixes multiple answer question in order to be exact
     //if ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
     /* if ($answerType == GLOBAL_MULTIPLE_ANSWER) {
                 $diff = @array_diff($answer_correct_array, $real_answers);
     
                 // All good answers or nothing works like exact
     
                 $counter = 1;
                 $correct_answer = true;
                 foreach ($real_answers as $my_answer) {
                     if ($debug)
                         error_log(" my_answer: $my_answer answer_correct_array[counter]: ".$answer_correct_array[$counter]);
                     if ($my_answer != $answer_correct_array[$counter]) {
                         $correct_answer = false;
                         break;
                     }
                     $counter++;
                 }
     
                 if ($debug) error_log(" answer_correct_array: ".print_r($answer_correct_array, 1)."");
                 if ($debug) error_log(" real_answers: ".print_r($real_answers, 1)."");
                 if ($debug) error_log(" correct_answer: ".$correct_answer);
     
                 if ($correct_answer == false) {
                     $questionScore = 0;
                 }
     
                 // This makes the result non exact
                 if (!empty($diff)) {
                     $questionScore = 0;
                 }
             }*/
     $extra_data = array('final_overlap' => $final_overlap, 'final_missing' => $final_missing, 'final_excess' => $final_excess, 'overlap_color' => $overlap_color, 'missing_color' => $missing_color, 'excess_color' => $excess_color, 'threadhold1' => $threadhold1, 'threadhold2' => $threadhold2, 'threadhold3' => $threadhold3);
     if ($from == 'exercise_result') {
         // if answer is hotspot. To the difference of exercise_show.php,
         //  we use the results from the session (from_db=0)
         // TODO Change this, because it is wrong to show the user
         //  some results that haven't been stored in the database yet
         if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION) {
             if ($debug) {
                 error_log('$from AND this is a hotspot kind of question ');
             }
             $my_exe_id = 0;
             $from_database = 0;
             if ($answerType == HOT_SPOT_DELINEATION) {
                 if (0) {
                     if ($overlap_color) {
                         $overlap_color = 'green';
                     } else {
                         $overlap_color = 'red';
                     }
                     if ($missing_color) {
                         $missing_color = 'green';
                     } else {
                         $missing_color = 'red';
                     }
                     if ($excess_color) {
                         $excess_color = 'green';
                     } else {
                         $excess_color = 'red';
                     }
                     if (!is_numeric($final_overlap)) {
                         $final_overlap = 0;
                     }
                     if (!is_numeric($final_missing)) {
                         $final_missing = 0;
                     }
                     if (!is_numeric($final_excess)) {
                         $final_excess = 0;
                     }
                     if ($final_overlap > 100) {
                         $final_overlap = 100;
                     }
                     $table_resume = '<table class="data_table">
                             <tr class="row_odd" >
                                 <td></td>
                                 <td ><b>' . get_lang('Requirements') . '</b></td>
                                 <td><b>' . get_lang('YourAnswer') . '</b></td>
                             </tr>
                             <tr class="row_even">
                                 <td><b>' . get_lang('Overlap') . '</b></td>
                                 <td>' . get_lang('Min') . ' ' . $threadhold1 . '</td>
                                 <td><div style="color:' . $overlap_color . '">' . ($final_overlap < 0 ? 0 : intval($final_overlap)) . '</div></td>
                             </tr>
                             <tr>
                                 <td><b>' . get_lang('Excess') . '</b></td>
                                 <td>' . get_lang('Max') . ' ' . $threadhold2 . '</td>
                                 <td><div style="color:' . $excess_color . '">' . ($final_excess < 0 ? 0 : intval($final_excess)) . '</div></td>
                             </tr>
                             <tr class="row_even">
                                 <td><b>' . get_lang('Missing') . '</b></td>
                                 <td>' . get_lang('Max') . ' ' . $threadhold3 . '</td>
                                 <td><div style="color:' . $missing_color . '">' . ($final_missing < 0 ? 0 : intval($final_missing)) . '</div></td>
                             </tr>
                         </table>';
                     if ($next == 0) {
                         $try = $try_hotspot;
                         $lp = $lp_hotspot;
                         $destinationid = $select_question_hotspot;
                         $url = $url_hotspot;
                     } else {
                         //show if no error
                         //echo 'no error';
                         $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers);
                         $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers);
                     }
                     echo '<h1><div style="color:#333;">' . get_lang('Feedback') . '</div></h1>
                         <p style="text-align:center">';
                     $message = '<p>' . get_lang('YourDelineation') . '</p>';
                     $message .= $table_resume;
                     $message .= '<br />' . get_lang('ResultIs') . ' ' . $result_comment . '<br />';
                     if ($organs_at_risk_hit > 0) {
                         $message .= '<p><b>' . get_lang('OARHit') . '</b></p>';
                     }
                     $message .= '<p>' . $comment . '</p>';
                     echo $message;
                 } else {
                     echo $hotspot_delineation_result[0];
                     //prints message
                     $from_database = 1;
                     // the hotspot_solution.swf needs this variable
                 }
                 //save the score attempts
                 if (1) {
                     //getting the answer 1 or 0 comes from exercise_submit_modal.php
                     $final_answer = $hotspot_delineation_result[1];
                     if ($final_answer == 0) {
                         $questionScore = 0;
                     }
                     // we always insert the answer_id 1 = delineation
                     Event::saveQuestionAttempt($questionScore, 1, $quesId, $exeId, 0);
                     //in delineation mode, get the answer from $hotspot_delineation_result[1]
                     Event::saveExerciseAttemptHotspot($exeId, $quesId, 1, $hotspot_delineation_result[1], $exerciseResultCoordinates[$quesId]);
                 } else {
                     if ($final_answer == 0) {
                         $questionScore = 0;
                         $answer = 0;
                         Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0);
                         if (is_array($exerciseResultCoordinates[$quesId])) {
                             foreach ($exerciseResultCoordinates[$quesId] as $idx => $val) {
                                 Event::saveExerciseAttemptHotspot($exeId, $quesId, $idx, 0, $val);
                             }
                         }
                     } else {
                         Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0);
                         if (is_array($exerciseResultCoordinates[$quesId])) {
                             foreach ($exerciseResultCoordinates[$quesId] as $idx => $val) {
                                 Event::saveExerciseAttemptHotspot($exeId, $quesId, $idx, $choice[$idx], $val);
                             }
                         }
                     }
                 }
                 $my_exe_id = $exeId;
             }
         }
         if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
             // We made an extra table for the answers
             if ($show_result) {
                 //	if ($origin != 'learnpath') {
                 echo '</table></td></tr>';
                 echo "\n                        <tr>\n                            <td colspan=\"2\">\n                                <p><em>" . get_lang('HotSpot') . "</em></p>\n                                <div id=\"hotspot-solution-{$questionId}\"></div>\n\n                                <script>\n                                    \$(document).on('ready', function () {\n                                        new HotspotQuestion({\n                                            questionId: {$questionId},\n                                            exerciseId: {$exeId},\n                                            selector: '#hotspot-solution-{$questionId}',\n                                            for: 'solution'\n                                        });\n                                    });\n                                </script>\n                            </td>\n                        </tr>\n                    ";
                 //	}
             }
         }
         //if ($origin != 'learnpath') {
         if ($show_result) {
             echo '</table>';
         }
         //	}
     }
     unset($objAnswerTmp);
     $totalWeighting += $questionWeighting;
     // Store results directly in the database
     // For all in one page exercises, the results will be
     // stored by exercise_results.php (using the session)
     if ($saved_results) {
         if ($debug) {
             error_log("Save question results {$saved_results}");
         }
         if ($debug) {
             error_log(print_r($choice, 1));
         }
         if (empty($choice)) {
             $choice = 0;
         }
         if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
             if ($choice != 0) {
                 $reply = array_keys($choice);
                 for ($i = 0; $i < sizeof($reply); $i++) {
                     $ans = $reply[$i];
                     Event::saveQuestionAttempt($questionScore, $ans . ':' . $choice[$ans], $quesId, $exeId, $i, $this->id);
                     if ($debug) {
                         error_log('result =>' . $questionScore . ' ' . $ans . ':' . $choice[$ans]);
                     }
                 }
             } else {
                 Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
             }
         } elseif ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
             if ($choice != 0) {
                 $reply = array_keys($choice);
                 if ($debug) {
                     error_log("reply " . print_r($reply, 1) . "");
                 }
                 for ($i = 0; $i < sizeof($reply); $i++) {
                     $ans = $reply[$i];
                     Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id);
                 }
             } else {
                 Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
             }
         } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
             if ($choice != 0) {
                 $reply = array_keys($choice);
                 for ($i = 0; $i < sizeof($reply); $i++) {
                     $ans = $reply[$i];
                     Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id);
                 }
             } else {
                 Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
             }
         } elseif (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
             if (isset($matching)) {
                 foreach ($matching as $j => $val) {
                     Event::saveQuestionAttempt($questionScore, $val, $quesId, $exeId, $j, $this->id);
                 }
             }
         } elseif ($answerType == FREE_ANSWER) {
             $answer = $choice;
             Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
         } elseif ($answerType == ORAL_EXPRESSION) {
             $answer = $choice;
             Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id, $nano);
         } elseif (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION])) {
             $answer = $choice;
             Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
             //            } elseif ($answerType == HOT_SPOT || $answerType == HOT_SPOT_DELINEATION) {
         } elseif ($answerType == HOT_SPOT) {
             $answer = [];
             if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) {
                 Database::delete(Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT), ['hotspot_exe_id = ? AND hotspot_question_id = ? AND c_id = ?' => [$exeId, $questionId, api_get_course_int_id()]]);
                 foreach ($exerciseResultCoordinates[$questionId] as $idx => $val) {
                     $answer[] = $val;
                     Event::saveExerciseAttemptHotspot($exeId, $quesId, $idx, $choice[$idx], $val, false, $this->id);
                 }
             }
             Event::saveQuestionAttempt($questionScore, implode('|', $answer), $quesId, $exeId, 0, $this->id);
         } else {
             Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
         }
     }
     if ($propagate_neg == 0 && $questionScore < 0) {
         $questionScore = 0;
     }
     if ($saved_results) {
         $stat_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
         $sql = 'UPDATE ' . $stat_table . ' SET
                     exe_result = exe_result + ' . floatval($questionScore) . '
                 WHERE exe_id = ' . $exeId;
         if ($debug) {
             error_log($sql);
         }
         Database::query($sql);
     }
     $return_array = array('score' => $questionScore, 'weight' => $questionWeighting, 'extra' => $extra_data, 'open_question' => $arrques, 'open_answer' => $arrans, 'answer_type' => $answerType);
     return $return_array;
 }
Example #26
0
 /**
  * Returns the form to update or create a document
  * @param    string    Action (add/edit)
  * @param    integer    ID of the lp_item (if already exists)
  * @param    mixed    Integer if document ID, string if info ('new')
  * @return    string    HTML form
  */
 public function display_document_form($action = 'add', $id = 0, $extra_info = 'new')
 {
     $course_id = api_get_course_int_id();
     $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
     $tbl_doc = Database::get_course_table(TABLE_DOCUMENT);
     $no_display_edit_textarea = false;
     //If action==edit document
     //We don't display the document form if it's not an editable document (html or txt file)
     if ($action == "edit") {
         if (is_array($extra_info)) {
             $path_parts = pathinfo($extra_info['dir']);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_edit_textarea = true;
             }
         }
     }
     $no_display_add = false;
     // If action==add an existing document
     // We don't display the document form if it's not an editable document (html or txt file).
     if ($action == "add") {
         if (is_numeric($extra_info)) {
             $sql_doc = "SELECT path FROM " . $tbl_doc . " WHERE c_id = " . $course_id . " AND id = " . Database::escape_string($extra_info);
             $result = Database::query($sql_doc);
             $path_file = Database::result($result, 0, 0);
             $path_parts = pathinfo($path_file);
             if ($path_parts['extension'] != "txt" && $path_parts['extension'] != "html") {
                 $no_display_add = true;
             }
         }
     }
     if ($id != 0 && is_array($extra_info)) {
         $item_title = stripslashes($extra_info['title']);
         $item_description = stripslashes($extra_info['description']);
         $item_terms = stripslashes($extra_info['terms']);
         if (empty($item_title)) {
             $path_parts = pathinfo($extra_info['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } elseif (is_numeric($extra_info)) {
         $sql_doc = "SELECT path, title FROM " . $tbl_doc . "\n                        WHERE c_id = " . $course_id . " AND id = " . Database::escape_string($extra_info);
         $result = Database::query($sql_doc);
         $row = Database::fetch_array($result);
         $explode = explode('.', $row['title']);
         if (count($explode) > 1) {
             for ($i = 0; $i < count($explode) - 1; $i++) {
                 $item_title .= $explode[$i];
             }
         } else {
             $item_title = $row['title'];
         }
         $item_title = str_replace('_', ' ', $item_title);
         if (empty($item_title)) {
             $path_parts = pathinfo($row['path']);
             $item_title = stripslashes($path_parts['filename']);
         }
     } else {
         $item_title = '';
         $item_description = '';
     }
     $return = '<legend>';
     if ($id != 0 && is_array($extra_info)) {
         $parent = $extra_info['parent_item_id'];
     } else {
         $parent = 0;
     }
     $sql = "SELECT * FROM " . $tbl_lp_item . "\n                WHERE c_id = " . $course_id . " AND lp_id = " . $this->lp_id;
     $result = Database::query($sql);
     $arrLP = array();
     while ($row = Database::fetch_array($result)) {
         $arrLP[] = array('id' => $row['id'], 'item_type' => $row['item_type'], 'title' => $row['title'], 'path' => $row['path'], 'description' => $row['description'], 'parent_item_id' => $row['parent_item_id'], 'previous_item_id' => $row['previous_item_id'], 'next_item_id' => $row['next_item_id'], 'display_order' => $row['display_order'], 'max_score' => $row['max_score'], 'min_score' => $row['min_score'], 'mastery_score' => $row['mastery_score'], 'prerequisite' => $row['prerequisite']);
     }
     $this->tree_array($arrLP);
     $arrLP = null;
     if (isset($this->arrMenu)) {
         $arrLP = $this->arrMenu;
         unset($this->arrMenu);
     }
     if ($action == 'add') {
         $return .= get_lang('CreateTheDocument');
     } elseif ($action == 'move') {
         $return .= get_lang('MoveTheCurrentDocument');
     } else {
         $return .= get_lang('EditTheCurrentDocument');
     }
     $return .= '</legend>';
     if (isset($_GET['edit']) && $_GET['edit'] == 'true') {
         $return .= Display::return_warning_message('<strong>' . get_lang('Warning') . ' !</strong><br />' . get_lang('WarningEditingDocument'), false);
     }
     $form = new FormValidator('form', 'POST', api_get_self() . '?' . $_SERVER['QUERY_STRING'], '', array('enctype' => "multipart/form-data"));
     $defaults['title'] = Security::remove_XSS($item_title);
     if (empty($item_title)) {
         $defaults['title'] = Security::remove_XSS($item_title);
     }
     $defaults['description'] = $item_description;
     $form->addElement('html', $return);
     if ($action != 'move') {
         $form->addElement('text', 'title', get_lang('Title'), array('id' => 'idTitle', 'class' => 'span4'));
         $form->applyFilter('title', 'html_filter');
     }
     //$arrHide = array($id);
     $arrHide[0]['value'] = $this->name;
     $arrHide[0]['padding'] = 3;
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($action != 'add') {
             if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') && !in_array($arrLP[$i]['id'], $arrHide) && !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         } else {
             if ($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') {
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
                 $arrHide[$arrLP[$i]['id']]['padding'] = 3 + $arrLP[$i]['depth'] * 10;
                 if ($parent == $arrLP[$i]['id']) {
                     $s_selected_parent = $arrHide[$arrLP[$i]['id']];
                 }
             }
         }
     }
     $parent_select = $form->addElement('select', 'parent', get_lang('Parent'), '', 'class="learnpath_item_form" id="idParent" style="width:40%;" onchange="javascript: load_cbo(this.value);"');
     $my_count = 0;
     foreach ($arrHide as $key => $value) {
         if ($my_count != 0) {
             // The LP name is also the first section and is not in the same charset like the other sections.
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         } else {
             $value['value'] = Security::remove_XSS($value['value']);
             $parent_select->addOption($value['value'], $key, 'style="padding-left:' . $value['padding'] . 'px;"');
         }
         $my_count++;
     }
     if (!empty($id)) {
         $parent_select->setSelected($parent);
     } else {
         $parent_item_id = Session::read('parent_item_id');
         $parent_select->setSelected($parent_item_id);
     }
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     $arrHide = array();
     $s_selected_position = null;
     //POSITION
     for ($i = 0; $i < count($arrLP); $i++) {
         if ($arrLP[$i]['parent_item_id'] == $parent && $arrLP[$i]['id'] != $id) {
             if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                 $s_selected_position = $arrLP[$i]['id'];
             } elseif ($action == 'add') {
                 $s_selected_position = $arrLP[$i]['id'];
             }
             $arrHide[$arrLP[$i]['id']]['value'] = get_lang('After') . ' "' . $arrLP[$i]['title'] . '"';
         }
     }
     $position = $form->addElement('select', 'previous', get_lang('Position'), '', 'id="previous" class="learnpath_item_form" style="width:40%;"');
     $position->addOption(get_lang('FirstPosition'), 0);
     foreach ($arrHide as $key => $value) {
         $padding = isset($value['padding']) ? $value['padding'] : 0;
         $position->addOption($value['value'], $key, 'style="padding-left:' . $padding . 'px;"');
     }
     $position->setSelected($s_selected_position);
     if (is_array($arrLP)) {
         reset($arrLP);
     }
     if ($action != 'move') {
         $id_prerequisite = 0;
         if (is_array($arrLP)) {
             foreach ($arrLP as $key => $value) {
                 if ($value['id'] == $id) {
                     $id_prerequisite = $value['prerequisite'];
                     break;
                 }
             }
         }
         $arrHide = array();
         for ($i = 0; $i < count($arrLP); $i++) {
             if ($arrLP[$i]['id'] != $id && $arrLP[$i]['item_type'] != 'dokeos_chapter') {
                 if (isset($extra_info['previous_item_id']) && $extra_info['previous_item_id'] == $arrLP[$i]['id']) {
                     $s_selected_position = $arrLP[$i]['id'];
                 } elseif ($action == 'add') {
                     $s_selected_position = $arrLP[$i]['id'];
                 }
                 $arrHide[$arrLP[$i]['id']]['value'] = $arrLP[$i]['title'];
             }
         }
         if (!$no_display_add) {
             if ($extra_info == 'new' || $extra_info['item_type'] == TOOL_DOCUMENT || $_GET['edit'] == 'true') {
                 if (isset($_POST['content'])) {
                     $content = stripslashes($_POST['content']);
                 } elseif (is_array($extra_info)) {
                     //If it's an html document or a text file
                     if (!$no_display_edit_textarea) {
                         $content = $this->display_document($extra_info['path'], false, false);
                     }
                 } elseif (is_numeric($extra_info)) {
                     $content = $this->display_document($extra_info, false, false);
                 } else {
                     $content = '';
                 }
                 if (!$no_display_edit_textarea) {
                     // We need to calculate here some specific settings for the online editor.
                     // The calculated settings work for documents in the Documents tool
                     // (on the root or in subfolders).
                     // For documents in native scorm packages it is unclear whether the
                     // online editor should be activated or not.
                     // A new document, it is in the root of the repository.
                     $relative_path = '';
                     $relative_prefix = '';
                     if (is_array($extra_info) && $extra_info != 'new') {
                         // The document already exists. Whe have to determine its relative path towards the repository root.
                         $relative_path = explode('/', $extra_info['dir']);
                         $cnt = count($relative_path) - 2;
                         if ($cnt < 0) {
                             $cnt = 0;
                         }
                         $relative_prefix = str_repeat('../', $cnt);
                         $relative_path = array_slice($relative_path, 1, $cnt);
                         $relative_path = implode('/', $relative_path);
                         if (strlen($relative_path) > 0) {
                             $relative_path = $relative_path . '/';
                         }
                     } else {
                         $_course = api_get_course_info();
                         $result = $this->generate_lp_folder($_course);
                         $relative_path = api_substr($result['dir'], 1, strlen($result['dir']));
                         $relative_prefix = '../../';
                     }
                     $editor_config = array('ToolbarSet' => 'LearningPathDocuments', 'Width' => '100%', 'Height' => '500', 'FullPage' => true, 'CreateDocumentDir' => $relative_prefix, 'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/', 'BaseHref' => api_get_path(WEB_COURSE_PATH) . api_get_course_path() . '/document/' . $relative_path);
                     if ($_GET['action'] == 'add_item') {
                         $class = 'add';
                         $text = get_lang('LPCreateDocument');
                     } else {
                         if ($_GET['action'] == 'edit_item') {
                             $class = 'save';
                             $text = get_lang('SaveDocument');
                         }
                     }
                     $form->addElement('style_submit_button', 'submit_button', $text, 'class="' . $class . '"');
                     $renderer = $form->defaultRenderer();
                     $renderer->setElementTemplate('<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{label}<br />{element}', 'content_lp');
                     $form->addElement('html', '<div>');
                     $form->addElement('html_editor', 'content_lp', '', null, $editor_config);
                     $form->addElement('html', '</div>');
                     $defaults['content_lp'] = $content;
                 }
             } elseif (is_numeric($extra_info)) {
                 $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
                 $return = $this->display_document($extra_info, true, true, true);
                 $form->addElement('html', $return);
             }
         }
     }
     if ($action == 'move') {
         $form->addElement('hidden', 'title', $item_title);
         $form->addElement('hidden', 'description', $item_description);
     }
     if (is_numeric($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'value="submit_button", class="save"');
         $form->addElement('hidden', 'path', $extra_info);
     } elseif (is_array($extra_info)) {
         $form->addElement('style_submit_button', 'submit_button', get_lang('SaveDocument'), 'class="save"');
         $form->addElement('hidden', 'path', $extra_info['path']);
     }
     $form->addElement('hidden', 'type', TOOL_DOCUMENT);
     $form->addElement('hidden', 'post_time', time());
     $form->setDefaults($defaults);
     return $form->return_form();
 }
Example #27
0
$cidReset = true;
// including some necessary files
require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
$_SESSION['this_section'] = $this_section;
// Access restrictions
api_protect_admin_script(true);
// setting breadcrumbs
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
// setting the name of the tool
$tool_name = get_lang('SubscribeCoursesToSession');
$id_session = intval($_GET['id_session']);
if (!api_is_platform_admin()) {
    $sql = 'SELECT session_admin_id FROM ' . Database::get_main_table(TABLE_MAIN_SESSION) . ' WHERE id=' . $id_session;
    $rs = Database::query($sql);
    if (Database::result($rs, 0, 0) != api_get_user_id()) {
        api_not_allowed(true);
    }
}
/*
	Libraries
*/
// containing the functions for the agenda tool
require_once 'calendar.lib.php';
/*
 			TREATING THE PARAMETERS
			1. viewing month only or everything
			2. sort ascending or descending
			3. showing or hiding the send-to-specific-groups-or-users form
			4. filter user or group
*/
Example #28
0
 /**
  * Gets the path translated with title of docs and folders
  * @param string $path the real path
  * @return the path which should be displayed
  */
 public static function get_titles_of_path($path)
 {
     global $tmp_folders_titles;
     $course_id = api_get_course_int_id();
     $nb_slashes = substr_count($path, '/');
     $current_slash_pos = 0;
     $path_displayed = '';
     for ($i = 0; $i < $nb_slashes; $i++) {
         // For each folder of the path, retrieve title.
         $current_slash_pos = strpos($path, '/', $current_slash_pos + 1);
         $tmp_path = substr($path, strpos($path, '/', 0), $current_slash_pos);
         if (empty($tmp_path)) {
             // If empty, then we are in the final part of the path
             $tmp_path = $path;
         }
         if (!empty($tmp_folders_titles[$tmp_path])) {
             // If this path has soon been stored here we don't need a new query
             $path_displayed .= $tmp_folders_titles[$tmp_path];
         } else {
             $sql = 'SELECT title FROM ' . Database::get_course_table(TABLE_DOCUMENT) . '
                 WHERE c_id = ' . $course_id . ' AND path LIKE BINARY "' . $tmp_path . '"';
             $rs = Database::query($sql);
             $tmp_title = '/' . Database::result($rs, 0, 0);
             $path_displayed .= $tmp_title;
             $tmp_folders_titles[$tmp_path] = $tmp_title;
         }
     }
     return $path_displayed;
 }
Example #29
0
 /**
  * updates the question in the data base
  * if an exercise ID is provided, we add that exercise ID into the exercise list
  *
  * @author Olivier Brouckaert
  * @param integer $exerciseId - exercise ID if saving in an exercise
  */
 public function save($exerciseId = 0)
 {
     $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
     $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $id = $this->id;
     $question = $this->question;
     $description = $this->description;
     $weighting = $this->weighting;
     $position = $this->position;
     $type = $this->type;
     $picture = $this->picture;
     $level = $this->level;
     $extra = $this->extra;
     $c_id = $this->course['real_id'];
     $category_list = $this->category_list;
     // Question already exists
     if (!empty($id)) {
         $sql = "UPDATE {$TBL_QUESTIONS} SET\n                        question \t='" . Database::escape_string($question) . "',\n                        description\t='" . Database::escape_string($description) . "',\n                        ponderation\t='" . Database::escape_string($weighting) . "',\n                        position\t='" . Database::escape_string($position) . "',\n                        type\t\t='" . Database::escape_string($type) . "',\n                        picture\t\t='" . Database::escape_string($picture) . "',\n                        extra       ='" . Database::escape_string($extra) . "',\n                        level\t\t='" . Database::escape_string($level) . "',\n                        parent_id   = " . $this->parent_id . "\n                    WHERE iid = '" . Database::escape_string($id) . "'";
         //WHERE c_id = $c_id AND iid = '".Database::escape_string($id)."'";
         Database::query($sql);
         $this->saveCategories($category_list);
         if (!empty($exerciseId)) {
             api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionUpdated', api_get_user_id());
             if (api_get_setting('search_enabled') == 'true') {
                 $this->search_engine_edit($exerciseId);
             }
         }
     } else {
         // Creates a new question
         $sql = "SELECT max(position) FROM {$TBL_QUESTIONS} as question, {$TBL_EXERCICE_QUESTION} as test_question\n\t\t\t\t    WHERE \tquestion.iid\t\t\t\t\t= test_question.question_id AND\n\t\t\t\t\t        test_question.exercice_id\t= '" . Database::escape_string($exerciseId) . "' AND\n\t\t\t\t\t\t\tquestion.c_id \t\t\t\t= {$c_id} AND\n\t\t\t\t\t\t\ttest_question.c_id \t\t\t= {$c_id} ";
         $result = Database::query($sql);
         $current_position = Database::result($result, 0, 0);
         $this->updatePosition($current_position + 1);
         $position = $this->position;
         $sql = "INSERT INTO {$TBL_QUESTIONS} (c_id, question, description, ponderation, position, type, picture, extra, level, parent_id) VALUES ( " . " {$c_id}, " . " '" . Database::escape_string($question) . "', " . " '" . Database::escape_string($description) . "', " . " '" . Database::escape_string($weighting) . "', " . " '" . Database::escape_string($position) . "', " . " '" . Database::escape_string($type) . "', " . " '" . Database::escape_string($picture) . "', " . " '" . Database::escape_string($extra) . "', " . " '" . Database::escape_string($level) . "', " . " '" . $this->parent_id . "' " . " )";
         Database::query($sql);
         $this->id = Database::insert_id();
         api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'QuizQuestionAdded', api_get_user_id());
         // If hotspot, create first answer
         if ($type == HOT_SPOT || $type == HOT_SPOT_ORDER) {
             $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
             $sql = "INSERT INTO {$TBL_ANSWERS} (question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )\n\t\t\t\t\t    VALUES ('" . Database::escape_string($this->id) . "', '', NULL , '', '10' , '1', '0;0|0|0', 'square')";
             Database::query($sql);
         }
         if ($type == HOT_SPOT_DELINEATION) {
             $TBL_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
             $sql = "INSERT INTO {$TBL_ANSWERS} (question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type )\n\t\t\t\t\t    VALUES ('" . Database::escape_string($this->id) . "', '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')";
             Database::query($sql);
         }
         if (api_get_setting('search_enabled') == 'true') {
             if ($exerciseId != 0) {
                 $this->search_engine_edit($exerciseId, true);
             }
         }
     }
     // if the question is created in an exercise
     if ($exerciseId) {
         // adds the exercise into the exercise list of this question
         $this->addToList($exerciseId, true);
     }
 }
Example #30
0
while ($obj = Database::fetch_object($res)) {
    $allTeachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
    if (!array_key_exists($obj->user_id, $course_teachers)) {
        $teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
    }
    if (isset($course_teachers[$obj->user_id]) && $courseInfo['tutor_name'] == $course_teachers[$obj->user_id]) {
        $courseInfo['tutor_name'] = $obj->user_id;
    }
    // We add in the array platform teachers
    $platform_teachers[$obj->user_id] = api_get_person_name($obj->firstname, $obj->lastname);
}
// Case where there is no teacher in the course
if (count($course_teachers) == 0) {
    $sql = 'SELECT tutor_name FROM ' . $course_table . ' WHERE code="' . $course_code . '"';
    $res = Database::query($sql);
    $tutor_name = Database::result($res, 0, 0);
    $courseInfo['tutor_name'] = array_search($tutor_name, $platform_teachers);
}
// Build the form
$form = new FormValidator('update_course', 'post', api_get_self() . '?id=' . $courseId);
$form->addElement('header', get_lang('Course') . '  #' . $courseInfo['real_id'] . ' ' . $course_code);
$form->addElement('hidden', 'code', $course_code);
//title
$form->addText('title', get_lang('Title'), true);
$form->applyFilter('title', 'html_filter');
$form->applyFilter('title', 'trim');
// Code
$element = $form->addElement('text', 'real_code', array(get_lang('CourseCode'), get_lang('ThisValueCantBeChanged')));
$element->freeze();
// Visual code
$form->addText('visual_code', array(get_lang('VisualCode'), get_lang('OnlyLettersAndNumbers'), get_lang('ThisValueIsUsedInTheCourseURL')), true, ['maxlength' => CourseManager::MAX_COURSE_LENGTH_CODE, 'pattern' => '[a-zA-Z0-9]+', 'title' => get_lang('OnlyLettersAndNumbers')]);