/**
  * @param int $exe_id
  * @return array|mixed
  */
 public function get_stat_track_exercise_info_by_exe_id($exe_id)
 {
     $track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $exe_id = intval($exe_id);
     $sql_track = "SELECT * FROM {$track_exercises} WHERE exe_id = {$exe_id} ";
     $result = Database::query($sql_track);
     $new_array = array();
     if (Database::num_rows($result) > 0) {
         $new_array = Database::fetch_array($result, 'ASSOC');
         $new_array['duration'] = null;
         $start_date = api_get_utc_datetime($new_array['start_date'], true);
         $end_date = api_get_utc_datetime($new_array['exe_date'], true);
         if (!empty($start_date) && !empty($end_date)) {
             $start_date = api_strtotime($start_date, 'UTC');
             $end_date = api_strtotime($end_date, 'UTC');
             if ($start_date && $end_date) {
                 $mytime = $end_date - $start_date;
                 $new_learnpath_item = new learnpathItem(null);
                 $time_attemp = $new_learnpath_item->get_scorm_time('js', $mytime);
                 $h = get_lang('h');
                 $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
                 $new_array['duration'] = $time_attemp;
             }
         }
     }
     return $new_array;
 }
 /**
  * Gets the list of included resources as a list of absolute or relative paths of
  * resources included in the current item. This allows for a better SCORM export.
  * The list will generally include pictures, flash objects, java applets, or any other
  * stuff included in the source of the current item. The current item is expected
  * to be an HTML file. If it is not, then the function will return and empty list.
  * @param    string    type (one of the Chamilo tools) - optional (otherwise takes the current item's type)
  * @param    string    path (absolute file path) - optional (otherwise takes the current item's path)
  * @param    int        level of recursivity we're in
  * @return    array    List of file paths. An additional field containing 'local' or 'remote' helps determine if the file should be copied into the zip or just linked
  */
 public function get_resources_from_source($type = null, $abs_path = null, $recursivity = 1)
 {
     $max = 5;
     if ($recursivity > $max) {
         return array();
     }
     if (!isset($type)) {
         $type = $this->get_type();
     }
     if (!isset($abs_path)) {
         $path = $this->get_file_path();
         $abs_path = api_get_path(SYS_COURSE_PATH) . api_get_course_path() . '/' . $path;
         //echo "Abs path coming from item : ".$abs_path."<br />\n";
     }
     /*
      else {
      echo "Abs path coming from param: ".$abs_path."<br />\n";
      }
     */
     //error_log(str_repeat(' ',$recursivity).'Analyse file '.$abs_path, 0);
     $files_list = array();
     $type = $this->get_type();
     switch ($type) {
         case TOOL_DOCUMENT:
         case TOOL_QUIZ:
         case 'sco':
             // Get the document and, if HTML, open it.
             if (is_file($abs_path)) {
                 // for now, read the whole file in one go (that's gonna be a problem when the file is too big).
                 $info = pathinfo($abs_path);
                 $ext = $info['extension'];
                 switch (strtolower($ext)) {
                     case 'html':
                     case 'htm':
                     case 'shtml':
                     case 'css':
                         $wanted_attributes = array('src', 'url', '@import', 'href', 'value');
                         // Parse it for included resources.
                         $file_content = file_get_contents($abs_path);
                         // Get an array of attributes from the HTML source.
                         $attributes = DocumentManager::parse_HTML_attributes($file_content, $wanted_attributes);
                         // Look at 'src' attributes in this file
                         foreach ($wanted_attributes as $attr) {
                             if (isset($attributes[$attr])) {
                                 // Find which kind of path these are (local or remote).
                                 $sources = $attributes[$attr];
                                 foreach ($sources as $source) {
                                     // Skip what is obviously not a resource.
                                     if (strpos($source, "+this.")) {
                                         continue;
                                     }
                                     // javascript code - will still work unaltered.
                                     if (strpos($source, '.') === false) {
                                         continue;
                                     }
                                     // No dot, should not be an external file anyway.
                                     if (strpos($source, 'mailto:')) {
                                         continue;
                                     }
                                     // mailto link.
                                     if (strpos($source, ';') && !strpos($source, '&amp;')) {
                                         continue;
                                     }
                                     // Avoid code - that should help.
                                     if ($attr == 'value') {
                                         if (strpos($source, 'mp3file')) {
                                             $files_list[] = array(substr($source, 0, strpos($source, '.swf') + 4), 'local', 'abs');
                                             $mp3file = substr($source, strpos($source, 'mp3file=') + 8);
                                             if (substr($mp3file, 0, 1) == '/') {
                                                 $files_list[] = array($mp3file, 'local', 'abs');
                                             } else {
                                                 $files_list[] = array($mp3file, 'local', 'rel');
                                             }
                                         } elseif (strpos($source, 'flv=') === 0) {
                                             $source = substr($source, 4);
                                             if (strpos($source, '&') > 0) {
                                                 $source = substr($source, 0, strpos($source, '&'));
                                             }
                                             if (strpos($source, '://') > 0) {
                                                 if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($source, 'local', 'url');
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($source, 'remote', 'url');
                                                 }
                                             } else {
                                                 $files_list[] = array($source, 'local', 'abs');
                                             }
                                             continue;
                                             // Skipping anything else to avoid two entries (while the others can have sub-files in their url, flv's can't).
                                         }
                                     }
                                     if (strpos($source, '://') > 0) {
                                         // Cut at '?' in a URL with params.
                                         if (strpos($source, '?') > 0) {
                                             $second_part = substr($source, strpos($source, '?'));
                                             if (strpos($second_part, '://') > 0) {
                                                 // If the second part of the url contains a url too, treat the second one before cutting.
                                                 $pos1 = strpos($second_part, '=');
                                                 $pos2 = strpos($second_part, '&');
                                                 $second_part = substr($second_part, $pos1 + 1, $pos2 - ($pos1 + 1));
                                                 if (strpos($second_part, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($second_part, 'local', 'url');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $second_part, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($second_part, 'remote', 'url');
                                                 }
                                             } elseif (strpos($second_part, '=') > 0) {
                                                 if (substr($second_part, 0, 1) === '/') {
                                                     // Link starts with a /, making it absolute (relative to DocumentRoot).
                                                     $files_list[] = array($second_part, 'local', 'abs');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $second_part, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } elseif (strstr($second_part, '..') === 0) {
                                                     // Link is relative but going back in the hierarchy.
                                                     $files_list[] = array($second_part, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $second_part);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // No starting '/', making it relative to current document's path.
                                                     if (substr($second_part, 0, 2) == './') {
                                                         $second_part = substr($second_part, 2);
                                                     }
                                                     $files_list[] = array($second_part, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $second_part);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 }
                                             }
                                             // Leave that second part behind now.
                                             $source = substr($source, 0, strpos($source, '?'));
                                             if (strpos($source, '://') > 0) {
                                                 if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                                     // We found the current portal url.
                                                     $files_list[] = array($source, 'local', 'url');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // We didn't find any trace of current portal.
                                                     $files_list[] = array($source, 'remote', 'url');
                                                 }
                                             } else {
                                                 // No protocol found, make link local.
                                                 if (substr($source, 0, 1) === '/') {
                                                     // Link starts with a /, making it absolute (relative to DocumentRoot).
                                                     $files_list[] = array($source, 'local', 'abs');
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } elseif (strstr($source, '..') === 0) {
                                                     // Link is relative but going back in the hierarchy.
                                                     $files_list[] = array($source, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $source);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 } else {
                                                     // No starting '/', making it relative to current document's path.
                                                     if (substr($source, 0, 2) == './') {
                                                         $source = substr($source, 2);
                                                     }
                                                     $files_list[] = array($source, 'local', 'rel');
                                                     $dir = dirname($abs_path);
                                                     $new_abs_path = realpath($dir . '/' . $source);
                                                     $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                                     if (count($in_files_list) > 0) {
                                                         $files_list = array_merge($files_list, $in_files_list);
                                                     }
                                                 }
                                             }
                                         }
                                         // Found some protocol there.
                                         if (strpos($source, api_get_path(WEB_PATH)) !== false) {
                                             // We found the current portal url.
                                             $files_list[] = array($source, 'local', 'url');
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         } else {
                                             // We didn't find any trace of current portal.
                                             $files_list[] = array($source, 'remote', 'url');
                                         }
                                     } else {
                                         // No protocol found, make link local.
                                         if (substr($source, 0, 1) === '/') {
                                             // Link starts with a /, making it absolute (relative to DocumentRoot).
                                             $files_list[] = array($source, 'local', 'abs');
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $source, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         } elseif (strstr($source, '..') === 0) {
                                             // Link is relative but going back in the hierarchy.
                                             $files_list[] = array($source, 'local', 'rel');
                                             $dir = dirname($abs_path);
                                             $new_abs_path = realpath($dir . '/' . $source);
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         } else {
                                             // No starting '/', making it relative to current document's path.
                                             if (strpos($source, 'width=') || strpos($source, 'autostart=')) {
                                                 continue;
                                             }
                                             if (substr($source, 0, 2) == './') {
                                                 $source = substr($source, 2);
                                             }
                                             $files_list[] = array($source, 'local', 'rel');
                                             $dir = dirname($abs_path);
                                             $new_abs_path = realpath($dir . '/' . $source);
                                             $in_files_list[] = learnpathItem::get_resources_from_source(TOOL_DOCUMENT, $new_abs_path, $recursivity + 1);
                                             if (count($in_files_list) > 0) {
                                                 $files_list = array_merge($files_list, $in_files_list);
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         break;
                     default:
                         break;
                 }
             } else {
                 // The file could not be found.
                 return false;
             }
             break;
         default:
             // Ignore.
             break;
     }
     //error_log(str_repeat(' ', $recursivity), 'found files '.print_r($files_list, true), 0);
     //return $files_list;
     $checked_files_list = array();
     $checked_array_list = array();
     foreach ($files_list as $idx => $file) {
         if (!empty($file[0])) {
             if (!in_array($file[0], $checked_files_list)) {
                 $checked_files_list[] = $files_list[$idx][0];
                 $checked_array_list[] = $files_list[$idx];
             }
         }
     }
     return $checked_array_list;
 }
    $newMp3DocumentId = DocumentManager::addAndConvertWavToMp3(
        $documentData,
        $courseInfo,
        api_get_session_id(),
        api_get_user_id(),
        'overwrite',
        true
    );

    if ($newMp3DocumentId) {
        $newDocId = $newMp3DocumentId;
    }

    if (isset($_REQUEST['lp_item_id']) && !empty($_REQUEST['lp_item_id'])) {
        $lpItemId = $_REQUEST['lp_item_id'];
        /** @var learnpath $lp */
        $lp = isset($_SESSION['oLP']) ? $_SESSION['oLP'] : null;

        if (!empty($lp)) {
            $lp->set_modified_on();
            $lpItem = new learnpathItem($lpItemId);
            $lpItem->add_audio_from_documents($newDocId);
            Display::addFlash(
                Display::return_message(get_lang('Updated'), 'info')
            );
        }
    }
} else {
    Display::addFlash($contents);
}
Beispiel #4
0
 /**
  * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem
  * object from database records or from the DOM element given as parameter
  * @param	string	Type of construction needed ('db' or 'manifest', default = 'manifest')
  * @param	mixed	Depending on the type given, DB id for the lp_item or reference to the DOM element
  */
 function scormItem($type = 'manifest', &$element)
 {
     if (isset($element)) {
         $v = substr(phpversion(), 0, 1);
         if ($v == 4) {
             switch ($type) {
                 case 'db':
                     parent::learnpathItem($element, api_get_user_id());
                     $this->scorm_contact = false;
                     //TODO implement this way of metadata object creation
                     return false;
                 case 'manifest':
                     //do the same as the default
                 //do the same as the default
                 default:
                     //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
                     $children = $element->children();
                     foreach ($children as $a => $dummy) {
                         $child =& $children[$a];
                         switch ($child->type) {
                             case XML_ELEMENT_NODE:
                                 switch ($child->tagname) {
                                     case 'title':
                                         $tmp_children = $child->children();
                                         if (count($tmp_children) == 1 and $tmp_children[0]->content != '') {
                                             $this->title = $tmp_children[0]->content;
                                         }
                                         break;
                                     case 'maxtimeallowed':
                                         $tmp_children = $child->children();
                                         if (count($tmp_children) == 1 and $tmp_children[0]->content != '') {
                                             $this->max_time_allowed = $tmp_children[0]->content;
                                         }
                                         break;
                                     case 'prerequisites':
                                         $tmp_children = $child->children();
                                         if (count($tmp_children) == 1 and $tmp_children[0]->content != '') {
                                             $this->prereq_string = $tmp_children[0]->content;
                                         }
                                         break;
                                     case 'timelimitaction':
                                         $tmp_children = $child->children();
                                         if (count($tmp_children) == 1 and $tmp_children[0]->content != '') {
                                             $this->timelimitaction = $tmp_children[0]->content;
                                         }
                                         break;
                                     case 'datafromlms':
                                         $tmp_children = $child->children();
                                         if (count($tmp_children) == 1 and $tmp_children[0]->content != '') {
                                             $this->datafromlms = $tmp_children[0]->content;
                                         }
                                         break;
                                     case 'masteryscore':
                                         $tmp_children = $child->children();
                                         if (count($tmp_children) == 1 and $tmp_children[0]->content != '') {
                                             $this->mastery_score = $tmp_children[0]->content;
                                         }
                                         break;
                                     case 'item':
                                         $oItem = new scormItem('manifest', $child);
                                         if ($oItem->identifier != '') {
                                             $this->sub_items[$oItem->identifier] = $oItem;
                                         }
                                         break;
                                     case 'metadata':
                                         $this->metadata = new scormMetadata('manifest', $child);
                                         break;
                                 }
                                 break;
                             case XML_TEXT_NODE:
                                 //this case is actually treated by looking into ELEMENT_NODEs above
                                 break;
                         }
                     }
                     $attributes = $element->attributes();
                     //$keep_href = '';
                     foreach ($attributes as $a1 => $dummy) {
                         $attrib =& $attributes[$a1];
                         switch ($attrib->name) {
                             case 'identifier':
                                 $this->identifier = $attrib->value;
                                 break;
                             case 'identifierref':
                                 $this->identifierref = $attrib->value;
                                 break;
                             case 'isvisible':
                                 $this->isvisible = $attrib->value;
                                 break;
                             case 'parameters':
                                 $this->parameters = $attrib->value;
                                 break;
                         }
                     }
                     return true;
             }
         } elseif ($v == 5) {
             //parsing using PHP5 DOMXML methods
             switch ($type) {
                 case 'db':
                     parent::learnpathItem($element, api_get_user_id());
                     $this->scorm_contact = false;
                     //TODO implement this way of metadata object creation
                     return false;
                 case 'manifest':
                     //do the same as the default
                 //do the same as the default
                 default:
                     //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function
                     $children = $element->childNodes;
                     foreach ($children as $child) {
                         switch ($child->nodeType) {
                             case XML_ELEMENT_NODE:
                                 switch ($child->tagName) {
                                     case 'title':
                                         $tmp_children = $child->childNodes;
                                         //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->title = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'max_score':
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->max_score = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'maxtimeallowed':
                                     case 'adlcp:maxtimeallowed':
                                         $tmp_children = $child->childNodes;
                                         //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->max_time_allowed = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'prerequisites':
                                     case 'adlcp:prerequisites':
                                         $tmp_children = $child->childNodes;
                                         //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->prereq_string = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'timelimitaction':
                                     case 'adlcp:timelimitaction':
                                         $tmp_children = $child->childNodes;
                                         //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->timelimitaction = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'datafromlms':
                                     case 'adlcp:datafromlms':
                                     case 'adlcp:launchdata':
                                         //in some cases (Wouters)
                                         $tmp_children = $child->childNodes;
                                         //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->datafromlms = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'masteryscore':
                                     case 'adlcp:masteryscore':
                                         $tmp_children = $child->childNodes;
                                         //if(count($tmp_children)==1 and $tmp_children[0]->textContent!='' )
                                         if ($tmp_children->length == 1 and $child->firstChild->nodeValue != '') {
                                             $this->mastery_score = $child->firstChild->nodeValue;
                                         }
                                         break;
                                     case 'item':
                                         $oItem = new scormItem('manifest', $child);
                                         if ($oItem->identifier != '') {
                                             $this->sub_items[$oItem->identifier] = $oItem;
                                         }
                                         break;
                                     case 'metadata':
                                         $this->metadata = new scormMetadata('manifest', $child);
                                         break;
                                 }
                                 break;
                             case XML_TEXT_NODE:
                                 //this case is actually treated by looking into ELEMENT_NODEs above
                                 break;
                         }
                     }
                     if ($element->hasAttributes()) {
                         $attributes = $element->attributes;
                         //$keep_href = '';
                         foreach ($attributes as $attrib) {
                             switch ($attrib->name) {
                                 case 'identifier':
                                     $this->identifier = $attrib->value;
                                     break;
                                 case 'identifierref':
                                     $this->identifierref = $attrib->value;
                                     break;
                                 case 'isvisible':
                                     $this->isvisible = $attrib->value;
                                     break;
                                 case 'parameters':
                                     $this->parameters = $attrib->value;
                                     break;
                             }
                         }
                     }
                     return true;
             }
         } else {
             //cannot parse because not PHP4 nor PHP5... We should not even be here anyway...
             return false;
         }
     }
     return false;
 }
        break;
    default:
        $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewStep'));
        break;
}
if ($action == 'add_item' && $type == 'document') {
    $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewDocumentCreated'));
}
// Theme calls.
$show_learn_path = true;
$lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
if (empty($lp_item_id)) {
    api_not_allowed();
}
$courseInfo = api_get_course_info();
$lp_item = new learnpathItem($lp_item_id);
$form = new FormValidator('add_audio', 'post', api_get_self() . '?action=add_audio&id=' . $lp_item_id . '&' . api_get_cidreq() . '&lp_id=' . $learnpath_id, null, array('enctype' => 'multipart/form-data'));
$suredel = trim(get_lang('AreYouSureToDeleteJS'));
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = null;
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
    $file = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document/audio/' . $lp_item->audio;
    $urlFile = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document/audio/' . $lp_item->audio . '?' . api_get_cidreq();
    if (!file_exists($file)) {
        $file = api_get_path(SYS_COURSE_PATH) . $courseInfo['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio;
        $urlFile = api_get_path(WEB_COURSE_PATH) . $courseInfo['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio . '?' . api_get_cidreq();
    }
}
$page = $_SESSION['oLP']->build_action_menu(true);
$page .= '<div class="row" style="overflow:hidden">';
$page .= '<div id="lp_sidebar" class="col-md-4">';
        break;
    case 'add_audio':
        if (!$is_allowed_to_edit) {
            api_not_allowed(true);
        }
        if ($debug > 0) error_log('New LP - add audio action triggered', 0);

        if (!$lp_found) {
            //check if the learnpath ID was defined, otherwise send back to list
            if ($debug > 0) error_log('New LP - No learnpath given for add audio', 0);
            require 'lp_list.php';
        } else {
            $_SESSION['refresh'] = 1;

            if (isset($_REQUEST['id'])) {
                $lp_item_obj = new learnpathItem($_REQUEST['id']);

                // Remove audio
                if (isset($_GET['delete_file']) && $_GET['delete_file'] == 1) {
                    $lp_item_obj->remove_audio();

                    $url = api_get_self().'?action=add_audio&lp_id='.intval($_SESSION['oLP']->lp_id).'&id='.$lp_item_obj->get_id().'&'.api_get_cidreq();
                    header('Location: '.$url);
                    exit;
                }

                // Upload audio
                if (isset($_FILES['file']) && !empty($_FILES['file'])) {
                    // Updating the lp.modified_on
                    $_SESSION['oLP']->set_modified_on();
                    $lp_item_obj->add_audio();
Beispiel #7
0
 /**
  * Gets the information about an item in a format usable as JavaScript to update
  * the JS API by just printing this content into the <head> section of the message frame
  * @param	integer		Item ID
  * @return	string
  */
 function get_js_info($item_id = '')
 {
     if ($this->debug > 0) {
         error_log('New LP - In learnpath::get_js_info(' . $item_id . ')', 0);
     }
     $info = '';
     $item_id = $this->escape_string($item_id);
     if (!empty($item_id) && is_object($this->items[$item_id])) {
         //if item is defined, return values from DB
         $oItem = $this->items[$item_id];
         $info .= '<script language="javascript">';
         $info .= "top.set_score(" . $oItem->get_score() . ");\n";
         $info .= "top.set_max(" . $oItem->get_max() . ");\n";
         $info .= "top.set_min(" . $oItem->get_min() . ");\n";
         $info .= "top.set_lesson_status('" . $oItem->get_status() . "');";
         $info .= "top.set_session_time('" . $oItem->get_scorm_time('js') . "');";
         $info .= "top.set_suspend_data('" . $oItem->get_suspend_data() . "');";
         $info .= "top.set_saved_lesson_status('" . $oItem->get_status() . "');";
         $info .= "top.set_flag_synchronized();";
         $info .= '</script>';
         if ($this->debug > 2) {
             error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
         }
         return $info;
     } else {
         //if item_id is empty, just update to default SCORM data
         $info .= '<script language="javascript">';
         $info .= "top.set_score(" . learnpathItem::get_score() . ");\n";
         $info .= "top.set_max(" . learnpathItem::get_max() . ");\n";
         $info .= "top.set_min(" . learnpathItem::get_min() . ");\n";
         $info .= "top.set_lesson_status('" . learnpathItem::get_status() . "');";
         $info .= "top.set_session_time('" . learnpathItem::get_scorm_time('js') . "');";
         $info .= "top.set_suspend_data('" . learnpathItem::get_suspend_data() . "');";
         $info .= "top.set_saved_lesson_status('" . learnpathItem::get_status() . "');";
         $info .= "top.set_flag_synchronized();";
         $info .= '</script>';
         if ($this->debug > 2) {
             error_log('New LP - in learnpath::get_js_info(' . $item_id . ') - returning: ' . $info, 0);
         }
         return $info;
     }
 }
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item) {
    $debug = 0;
    $return = '';
    if ($debug > 0) { error_log('In xajax_switch_item_toc('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')', 0); }
    require_once 'learnpath.class.php';
    require_once 'scorm.class.php';
    require_once 'aicc.class.php';
    require_once 'learnpathItem.class.php';
    require_once 'scormItem.class.php';
    require_once 'aiccItem.class.php';
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {next} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {previous} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {first} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked
            if($next_item == $current_item){
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) { error_log('In {default} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit) {
        $mylp->save_current();
    }
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) { error_log('In switch_item_details - generating new item object', 0); }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') { $mymax = "''"; }
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    /*
    if ($mylpi->get_type() == 'asset') {
        // Temporary measure to save completion of an asset. Later on, Chamilo should trigger something on unload, maybe... (even though that would mean the last item cannot be completed)
        $mylesson_status = 'completed';
        $mylpi->set_status('completed');
        $mylpi->save();
    }
    */
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[".$i.",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();

    $return .=
        //"saved_lesson_status='not attempted';" .
        "olms.lms_lp_id=".$lp_id.";" .
        "olms.lms_item_id=".$new_item_id.";" .
        "olms.lms_old_item_id=0;" .
        //"lms_been_synchronized=0;" .
        "olms.lms_initialized=0;" .
        //"lms_total_lessons=".$mytotal.";" .
        //"lms_complete_lessons=".$mycomplete.";" .
        //"lms_progress_bar_mode='".$myprogress_mode."';" .
        "olms.lms_view_id=".$view_id.";" .
        "olms.lms_user_id=".$user_id.";" .
        "olms.next_item=".$new_item_id.";" . // This one is very important to replace possible literal strings.
        "olms.lms_next_item=".$mynext.";" .
        "olms.lms_previous_item=".$myprevious.";" .
        "olms.lms_item_type = '".$myitemtype."';" .
        "olms.lms_item_credit = '".$mycredit."';" .
        "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
        "olms.lms_item_launch_data = '".$mylaunch_data."';" .
        "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
        "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
        "olms.lms_item_core_exit = '".$mycore_exit."';" .
        "olms.asset_timer = 0;";

    $return .= "update_toc('unhighlight','".$current_item."');".
        "update_toc('highlight','".$new_item_id."');".
        "update_toc('$mylesson_status','".$new_item_id."');".
        "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";

    $mylp->set_error_msg('');
    $mylp->prerequisites_match(); // Check the prerequisites are all complete.
    if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
    $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($mylp);
    return $return;
}
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item)
{
    $debug = 0;
    $return = '';
    if ($debug > 0) {
        error_log('In xajax_switch_item_toc(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $current_item . ',' . $next_item . ')', 0);
    }
    require_once 'learnpath.class.php';
    require_once 'scorm.class.php';
    require_once 'aicc.class.php';
    require_once 'learnpathItem.class.php';
    require_once 'scormItem.class.php';
    require_once 'aiccItem.class.php';
    $mylp = '';
    if (isset($_SESSION['lpobject'])) {
        if ($debug > 1) {
            error_log('$_SESSION[lpobject] is set', 0);
        }
        $oLP = unserialize($_SESSION['lpobject']);
        if (!is_object($oLP)) {
            if ($debug > 1) {
                error_log(print_r($oLP, true), 0);
            }
            if ($debug > 2) {
                error_log('Building new lp', 0);
            }
            unset($oLP);
            $code = api_get_course_id();
            $mylp = new learnpath($code, $lp_id, $user_id);
        } else {
            if ($debug > 1) {
                error_log('Reusing session lp', 0);
            }
            $mylp = $oLP;
        }
    }
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {next} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {previous} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {first} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked
            if ($next_item == $current_item) {
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) {
                error_log('In {default} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit) {
        $mylp->save_current();
    }
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) {
            error_log('In switch_item_details - generating new item object', 0);
        }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') {
        $mymax = "''";
    }
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[" . $i . ",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = $myprogress_mode == '' ? '%' : $myprogress_mode;
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();
    $return .= "olms.lms_lp_id=" . $lp_id . ";" . "olms.lms_item_id=" . $new_item_id . ";" . "olms.lms_old_item_id=0;" . "olms.lms_initialized=0;" . "olms.lms_view_id=" . $view_id . ";" . "olms.lms_user_id=" . $user_id . ";" . "olms.next_item=" . $new_item_id . ";" . "olms.lms_next_item=" . $mynext . ";" . "olms.lms_previous_item=" . $myprevious . ";" . "olms.lms_item_type = '" . $myitemtype . "';" . "olms.lms_item_credit = '" . $mycredit . "';" . "olms.lms_item_lesson_mode = '" . $mylesson_mode . "';" . "olms.lms_item_launch_data = '" . $mylaunch_data . "';" . "olms.lms_item_interactions_count = '" . $myinteractions_count . "';" . "olms.lms_item_objectives_count = '" . $myinteractions_count . "';" . "olms.lms_item_core_exit = '" . $mycore_exit . "';" . "olms.asset_timer = 0;";
    $return .= "update_toc('unhighlight','" . $current_item . "');" . "update_toc('highlight','" . $new_item_id . "');" . "update_toc('{$mylesson_status}','" . $new_item_id . "');" . "update_progress_bar('{$mycomplete}','{$mytotal}','{$myprogress_mode}');";
    $mylp->set_error_msg('');
    $mylp->prerequisites_match();
    // Check the prerequisites are all complete.
    if ($debug > 1) {
        error_log('Prereq_match() returned ' . htmlentities($mylp->error), 0);
    }
    $_SESSION['scorm_item_id'] = $new_item_id;
    // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($mylp);
    return $return;
}
/**
 * Get one item's details
 * @param	integer	LP ID
 * @param	integer	user ID
 * @param	integer	View ID
 * @param	integer	Current item ID
 * @param	integer New item ID
 */
function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_item)
{
    global $charset;
    $debug = 0;
    if ($debug > 0) {
        error_log('In xajax_switch_item_details(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $current_item . ',' . $next_item . ')', 0);
    }
    $objResponse = new xajaxResponse();
    /*$item_id may be one of:
     * -'next'
     * -'previous'
     * -'first'
     * -'last'
     * - a real item ID
     */
    require_once 'learnpath.class.php';
    require_once 'scorm.class.php';
    require_once 'aicc.class.php';
    require_once 'learnpathItem.class.php';
    require_once 'scormItem.class.php';
    require_once 'aiccItem.class.php';
    $mylp = '';
    if (isset($_SESSION['lpobject'])) {
        if ($debug > 1) {
            error_log('$_SESSION[lpobject] is set', 0);
        }
        $oLP = unserialize($_SESSION['lpobject']);
        if (!is_object($oLP)) {
            if ($debug > 1) {
                error_log(print_r($oLP, true), 0);
            }
            if ($debug > 2) {
                error_log('Building new lp', 0);
            }
            unset($oLP);
            $code = api_get_course_id();
            $mylp = new learnpath($code, $lp_id, $user_id);
        } else {
            if ($debug > 1) {
                error_log('Reusing session lp', 0);
            }
            $mylp = $oLP;
        }
    }
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {next} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {previous} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {first} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked.
            if ($next_item == $current_item) {
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) {
                error_log('In {default} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit) {
        $mylp->save_current();
    }
    //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php');
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) {
            error_log('In switch_item_details - generating new item object', 0);
        }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $objResponse->addScript("score=" . $myscore . ";" . "max=" . $mymax . ";" . "min=" . $mymin . ";" . "lesson_status='" . $mylesson_status . "';" . "lesson_location='" . $mylesson_location . "';" . "session_time='" . $mysession_time . "';" . "suspend_data='" . $mysuspend_data . "';" . "lesson_location='" . $mylesson_location . "';" . "total_time = '" . $mytotal_time . "';" . "mastery_score = '" . $mymastery_score . "';" . "max_time_allowed = '" . $mymax_time_allowed . "';" . "launch_data = '" . $mylaunch_data . "';" . "interactions = new Array();" . "item_objectives = new Array();" . "G_lastError = 0;" . "G_LastErrorMessage = 'No error';");
    /*
     * and re-initialise the rest
     * -saved_lesson_status = 'not attempted'
     * -lms_lp_id
     * -lms_item_id
     * -lms_old_item_id
     * -lms_new_item_id
     * -lms_been_synchronized
     * -lms_initialized
     * -lms_total_lessons
     * -lms_complete_lessons
     * -lms_progress_bar_mode
     * -lms_view_id
     * -lms_user_id
     */
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = $myprogress_mode == '' ? '%' : $myprogress_mode;
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();
    $objResponse->addScript("saved_lesson_status='not attempted';" . "lms_lp_id=" . $lp_id . ";" . "lms_item_id=" . $new_item_id . ";" . "lms_old_item_id=0;" . "lms_been_synchronized=0;" . "lms_initialized=0;" . "lms_total_lessons=" . $mytotal . ";" . "lms_complete_lessons=" . $mycomplete . ";" . "lms_progress_bar_mod='" . $myprogress_mode . "';" . "lms_view_id=" . $view_id . ";" . "lms_user_id=" . $user_id . ";" . "next_item=" . $new_item_id . ";" . "lms_next_item=" . $mynext . ";" . "lms_previous_item=" . $myprevious . ";" . "lms_item_type = '" . $myitemtype . "';" . "lms_item_credit = '" . $mycredit . "';" . "lms_item_lesson_mode = '" . $mylesson_mode . "';" . "lms_item_launch_data = '" . $mylaunch_data . "';" . "lms_item_interactions_count = '" . $myinteractions_count . "';" . "lms_item_objectives_count = '" . $myinteractions_count . "';" . "lms_item_core_exit = '" . $mycore_exit . "';" . "asset_timer = 0;");
    $objResponse->addScript("update_toc('unhighlight','" . $current_item . "');");
    $objResponse->addScript("update_toc('highlight','" . $new_item_id . "');");
    $objResponse->addScript("update_toc('{$mylesson_status}','" . $new_item_id . "');");
    $objResponse->addScript("update_progress_bar('{$mycomplete}','{$mytotal}','{$myprogress_mode}');");
    $mylp->set_error_msg('');
    $mylp->prerequisites_match();
    // Check the prerequisites are all complete.
    if ($debug > 1) {
        error_log('Prereq_match() returned ' . api_htmlentities($mylp->error, ENT_QUOTES, $charset), 0);
    }
    $objResponse->addScript("update_message_frame('" . str_replace("'", "\\'", api_htmlentities($mylp->error, ENT_QUOTES, $charset)) . "');");
    $_SESSION['scorm_item_id'] = $new_item_id;
    // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($mylp);
    return $objResponse;
}
/**
 * Get one item's details
 * @param   integer $lpId LP ID
 * @param   integer $userId user ID
 * @param   integer $viewId View ID
 * @param   integer $currentItem Current item ID
 * @param   integer $nextItem New item ID
 * @return  string  JavaScript commands to be executed in scorm_api.php
 */
function switch_item_toc($lpId, $userId, $viewId, $currentItem, $nextItem)
{
    $debug = 0;
    $return = '';
    if ($debug > 0) {
        error_log('In switch_item_toc(' . $lpId . ',' . $userId . ',' . $viewId . ',' . $currentItem . ',' . $nextItem . ')', 0);
    }
    $myLP = learnpath::getLpFromSession(api_get_course_id(), $lpId, $userId);
    $newItemId = 0;
    $oldItemId = 0;
    switch ($nextItem) {
        case 'next':
            $myLP->set_current_item($currentItem);
            $myLP->next();
            $newItemId = $myLP->get_current_item_id();
            if ($debug > 1) {
                error_log('In {next} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
        case 'previous':
            $myLP->set_current_item($currentItem);
            $myLP->previous();
            $newItemId = $myLP->get_current_item_id();
            if ($debug > 1) {
                error_log('In {previous} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
        case 'first':
            $myLP->set_current_item($currentItem);
            $myLP->first();
            $newItemId = $myLP->get_current_item_id();
            if ($debug > 1) {
                error_log('In {first} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked
            if ($nextItem == $currentItem) {
                // If we're opening the same item again.
                $myLP->items[$currentItem]->restart();
            } else {
                $oldItemId = $currentItem;
            }
            $newItemId = $nextItem;
            $myLP->set_current_item($newItemId);
            if ($debug > 1) {
                error_log('In {default} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
    }
    $myLP->start_current_item(true);
    if ($myLP->force_commit) {
        $myLP->save_current();
    }
    if (is_object($myLP->items[$newItemId])) {
        $myLPI = $myLP->items[$newItemId];
    } else {
        if ($debug > 1) {
            error_log('In switch_item_details - generating new item object', 0);
        }
        $myLPI = new learnpathItem($newItemId, $userId);
        $myLPI->set_lp_view($viewId);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $lessonStatus = $myLPI->get_status();
    $interactionsCount = $myLPI->get_interactions_count();
    /**
     * Interactions are not returned by switch_item at the moment, but please
     * leave commented code to allow for the addition of these in the future
     */
    /*
    $interactionsString = '';
    for ($i = 0; $i < $interactionsCount; $i++) {
        $interactionsString .= ",[".$i.",'','','','','','','']";
    }
    if (!empty($interactionsString)) {
        $interactionsString = substr($interactionsString, 1);
    }
    */
    $totalItems = $myLP->get_total_items_count_without_chapters();
    $completedItems = $myLP->get_complete_items_count();
    $progressMode = $myLP->get_progress_bar_mode();
    $progressMode = $progressMode == '' ? '%' : $progressMode;
    $nextItemId = $myLP->get_next_item_id();
    $previousItemId = $myLP->get_previous_item_id();
    $itemType = $myLPI->get_type();
    $lessonMode = $myLPI->get_lesson_mode();
    $credit = $myLPI->get_credit();
    $launchData = $myLPI->get_launch_data();
    $objectivesCount = $myLPI->get_objectives_count();
    $coreExit = $myLPI->get_core_exit();
    $return .= "olms.lms_lp_id=" . $lpId . ";" . "olms.lms_item_id=" . $newItemId . ";" . "olms.lms_old_item_id=" . $oldItemId . ";" . "olms.lms_initialized=0;" . "olms.lms_view_id=" . $viewId . ";" . "olms.lms_user_id=" . $userId . ";" . "olms.next_item=" . $newItemId . ";" . "olms.lms_next_item=" . $nextItemId . ";" . "olms.lms_previous_item=" . $previousItemId . ";" . "olms.lms_item_type = '" . $itemType . "';" . "olms.lms_item_credit = '" . $credit . "';" . "olms.lms_item_lesson_mode = '" . $lessonMode . "';" . "olms.lms_item_launch_data = '" . $launchData . "';" . "olms.lms_item_interactions_count = '" . $interactionsCount . "';" . "olms.lms_item_objectives_count = '" . $objectivesCount . "';" . "olms.lms_item_core_exit = '" . $coreExit . "';" . "olms.asset_timer = 0;";
    $return .= "update_toc('unhighlight','" . $currentItem . "');" . "update_toc('highlight','" . $newItemId . "');" . "update_toc('{$lessonStatus}','" . $newItemId . "');" . "update_progress_bar('{$completedItems}','{$totalItems}','{$progressMode}');";
    $myLP->set_error_msg('');
    $myLP->prerequisites_match();
    // Check the prerequisites are all complete.
    if ($debug > 1) {
        error_log('prerequisites_match() returned ' . htmlentities($myLP->error), 0);
    }
    $_SESSION['scorm_item_id'] = $newItemId;
    // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($myLP);
    return $return;
}
Beispiel #12
0
/**
 * @param array $params
 * @return int|string
 */
function WSDeleteLp($params)
{
    global $debug;
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathList.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpath.class.php';
    require_once api_get_path(SYS_CODE_PATH) . 'newscorm/learnpathItem.class.php';
    $courseIdName = $params['course_id_name'];
    $courseIdValue = $params['course_id_value'];
    $lpId = $params['lp_id'];
    $sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
    $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
    $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseIdValue, $courseIdName);
    if (empty($courseInfo)) {
        if ($debug) {
            error_log("Course not found: {$courseIdName} : {$courseIdValue}");
        }
        return 'Course not found';
    }
    $courseId = $courseInfo['real_id'];
    $courseCode = $courseInfo['code'];
    $sessionId = 0;
    /*
    if (!empty($sessionIdName) && !empty($sessionIdValue)) {
        $sessionId = SessionManager::get_session_id_from_original_id(
            $sessionIdValue,
            $sessionIdName
        );
    
        if (empty($sessionId)) {
    
            if ($debug) error_log('Session not found');
            return 'Session not found';
        }
    }
    */
    $lp = new learnpath($courseCode, $lpId, null);
    if ($lp) {
        if ($debug) {
            error_log("LP deleted {$lpId}");
        }
        $course_dir = $courseInfo['directory'] . '/document';
        $sys_course_path = api_get_path(SYS_COURSE_PATH);
        $base_work_dir = $sys_course_path . $course_dir;
        $items = $lp->get_flat_ordered_items_list($lpId, 0, $courseId);
        if (!empty($items)) {
            /** @var $item learnpathItem */
            foreach ($items as $itemId) {
                $item = new learnpathItem($itemId, null, $courseId);
                if ($item) {
                    $documentId = $item->get_path();
                    if ($debug) {
                        error_log("lp item id found #{$itemId}");
                    }
                    $documentInfo = DocumentManager::get_document_data_by_id($documentId, $courseInfo['code'], false, $sessionId);
                    if (!empty($documentInfo)) {
                        if ($debug) {
                            error_log("Document id deleted #{$documentId}");
                        }
                        DocumentManager::delete_document($courseInfo, null, $base_work_dir, $sessionId, $documentId);
                    } else {
                        if ($debug) {
                            error_log("No document found for id #{$documentId}");
                        }
                    }
                } else {
                    if ($debug) {
                        error_log("Document not found #{$itemId}");
                    }
                }
            }
        }
        $lp->delete($courseInfo, $lpId, 'remove');
        return 1;
    }
    return 0;
}
$show_learn_path = true;
$lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
if (empty($lp_item_id)) {
    api_not_allowed();
}
Display::display_header(null, 'Path');
$suredel = trim(get_lang('AreYouSureToDelete'));
/* DISPLAY SECTION */
echo $_SESSION['oLP']->build_action_menu();
echo '<div class="row" style="overflow:hidden">';
echo '<div id="lp_sidebar" class="col-md-4">';
echo $_SESSION['oLP']->return_new_tree(null, true);
// Show the template list.
echo '</div>';
echo '<div id="doc_form" class="col-md-8">';
$lp_item = new learnpathItem($lp_item_id);
$form = new FormValidator('add_audio', 'post', api_get_self() . '?action=add_audio&id=' . $lp_item_id, null, array('enctype' => 'multipart/form-data'));
$form->addElement('header', get_lang('UplUpload'));
$form->addElement('html', $lp_item->get_title());
$form->addElement('file', 'file', get_lang('AudioFile'), 'style="width: 250px"');
$form->addElement('hidden', 'id', $lp_item_id);
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
    $form->addElement('checkbox', 'delete_file', null, get_lang('RemoveAudio'));
    $player = '<script type="text/javascript" src="../inc/lib/mediaplayer/swfobject.js"></script>';
    $player .= '<div id="preview"></div><script type="text/javascript">
                    var s1 = new SWFObject("../inc/lib/mediaplayer/player.swf","ply","250","20","9","#FFFFFF");
                    s1.addParam("allowscriptaccess","always");
                    s1.addParam("flashvars","file=../../courses/' . $_course['path'] . '/document/audio/' . $lp_item->audio . '");
                    s1.write("preview");
                </script>';
    $form->addElement('label', get_lang('Preview'), $player);
Beispiel #14
0
} else {
    // Extend all "left green cross"
    if ($origin == 'tracking') {
        $my_course_id = Database::escape_string($_GET['course']);
        $courseInfo = api_get_course_info($my_course_id);
        $courseId = $courseInfo['real_id'];
        if (!empty($student_id) && !empty($courseId)) {
            $total_score = Tracking::get_avg_student_score($student_id, $courseId, array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
        } else {
            $total_score = 0;
        }
    } else {
        $total_score = Tracking::get_avg_student_score(api_get_user_id(), api_get_course_int_id(), array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
    }
}
$total_time = learnpathItem::get_scorm_time('js', $total_time);
$total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
if (!$is_allowed_to_edit && $result_disabled_ext_all) {
    $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
} else {
    if (is_numeric($total_score)) {
        $final_score = $total_score . '%';
    } else {
        $final_score = $total_score;
    }
}
if ($counter % 2 == 0) {
    $oddclass = 'row_odd';
} else {
    $oddclass = 'row_even';
}
Beispiel #15
0
 /**
  * @param int $user_id
  * @param array $courseInfo
  * @param int $session_id
  * @param string $origin
  * @param bool $export_csv
  * @param int $lp_id
  * @param int $lp_item_id
  * @param int $extendId
  * @param int $extendAttemptId
  * @param string $extendedAttempt
  * @param string $extendedAll
  * @param string $type classic or simple
  * @param boolean $allowExtend Optional. Allow or not extend te results
  * @return null|string
  */
 public static function getLpStats($user_id, $courseInfo, $session_id, $origin, $export_csv, $lp_id, $lp_item_id = null, $extendId = null, $extendAttemptId = null, $extendedAttempt = null, $extendedAll = null, $type = 'classic', $allowExtend = true)
 {
     if (empty($courseInfo) || empty($lp_id)) {
         return null;
     }
     $lp_id = intval($lp_id);
     $lp_item_id = intval($lp_item_id);
     $user_id = intval($user_id);
     $session_id = intval($session_id);
     $origin = Security::remove_XSS($origin);
     $list = learnpath::get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']);
     $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
     $course_id = $courseInfo['real_id'];
     $courseCode = $courseInfo['code'];
     $session_condition = api_get_session_condition($session_id);
     // Extend all button
     $output = null;
     $extend_all = 0;
     if ($origin == 'tracking') {
         $url_suffix = '&session_id=' . $session_id . '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . $lp_id . '&origin=' . $origin;
     } else {
         $url_suffix = '&lp_id=' . $lp_id;
     }
     if (!empty($extendedAll)) {
         $extend_all_link = Display::url(Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), api_get_self() . '?action=stats' . $url_suffix);
         $extend_all = 1;
     } else {
         $extend_all_link = Display::url(Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttempts')), api_get_self() . '?action=stats&extend_all=1' . $url_suffix);
     }
     if ($origin != 'tracking') {
         $output .= '<div class="section-status">';
         $output .= Display::page_header(get_lang('ScormMystatus'));
         $output .= '</div>';
     }
     $actionColumn = null;
     if ($type == 'classic') {
         $actionColumn = ' <th>' . get_lang('Actions') . '</th>';
     }
     $output .= '<div class="table-responsive">';
     $output .= '<table class="table tracking">
         <thead>
         <tr class="table-header">
             <th width="16">' . ($allowExtend == true ? $extend_all_link : '&nbsp;') . '</th>
             <th colspan="4">
                 ' . get_lang('ScormLessonTitle') . '
             </th>
             <th colspan="2">
                 ' . get_lang('ScormStatus') . '
             </th>
             <th colspan="2">
                 ' . get_lang('ScormScore') . '
             </th>
             <th colspan="2">
                 ' . get_lang('ScormTime') . '
             </th>
             ' . $actionColumn . '
             </tr>
         </thead>
         <tbody>
     ';
     // Going through the items using the $items[] array instead of the database order ensures
     // we get them in the same order as in the imsmanifest file, which is rather random when using
     // the database table.
     $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
     $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
     $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW);
     $tbl_quiz_questions = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
     $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $tbl_stats_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $sql = "SELECT max(view_count)\n                FROM {$TBL_LP_VIEW}\n                WHERE\n                    c_id = {$course_id} AND\n                    lp_id = {$lp_id} AND\n                    user_id = {$user_id}\n                    {$session_condition}";
     $res = Database::query($sql);
     $view = '';
     if (Database::num_rows($res) > 0) {
         $myrow = Database::fetch_array($res);
         $view = $myrow[0];
     }
     $counter = 0;
     $total_time = 0;
     $h = get_lang('h');
     if (!empty($export_csv)) {
         $csv_content[] = array(get_lang('ScormLessonTitle'), get_lang('ScormStatus'), get_lang('ScormScore'), get_lang('ScormTime'));
     }
     $result_disabled_ext_all = true;
     $chapterTypes = learnpath::getChapterTypes();
     // Show lp items
     if (is_array($list) && count($list) > 0) {
         foreach ($list as $my_item_id) {
             $extend_this = 0;
             $order = 'DESC';
             if (!empty($extendId) && $extendId == $my_item_id || $extend_all) {
                 $extend_this = 1;
                 $order = 'ASC';
             }
             // Prepare statement to go through each attempt.
             $viewCondition = null;
             if (!empty($view)) {
                 $viewCondition = " AND v.view_count = {$view}  ";
             }
             $sql = "SELECT\n                    iv.status as mystatus,\n                    v.view_count as mycount,\n                    iv.score as myscore,\n                    iv.total_time as mytime,\n                    i.id as myid,\n                    i.lp_id as mylpid,\n                    iv.lp_view_id as mylpviewid,\n                    i.title as mytitle,\n                    i.max_score as mymaxscore,\n                    iv.max_score as myviewmaxscore,\n                    i.item_type as item_type,\n                    iv.view_count as iv_view_count,\n                    iv.id as iv_id,\n                    path\n                FROM {$TBL_LP_ITEM} as i\n                INNER JOIN {$TBL_LP_ITEM_VIEW} as iv\n                ON (i.id = iv.lp_item_id AND i.c_id = iv.c_id)\n                INNER JOIN {$TBL_LP_VIEW} as v\n                ON (iv.lp_view_id = v.id AND v.c_id = iv.c_id)\n                WHERE\n                    v.c_id = {$course_id} AND\n                    i.id = {$my_item_id} AND\n                    i.lp_id = {$lp_id}  AND\n                    v.user_id = {$user_id} AND\n                    v.session_id = {$session_id}\n                    {$viewCondition}\n                ORDER BY iv.view_count {$order} ";
             $result = Database::query($sql);
             $num = Database::num_rows($result);
             $time_for_total = 'NaN';
             // Extend all
             if (($extend_this || $extend_all) && $num > 0) {
                 $row = Database::fetch_array($result);
                 $result_disabled_ext_all = false;
                 if ($row['item_type'] == 'quiz') {
                     // Check results_disabled in quiz table.
                     $my_path = Database::escape_string($row['path']);
                     $sql = "SELECT results_disabled\n                                FROM {$TBL_QUIZ}\n                                WHERE\n                                    c_id = {$course_id} AND\n                                    id ='" . $my_path . "'";
                     $res_result_disabled = Database::query($sql);
                     $row_result_disabled = Database::fetch_row($res_result_disabled);
                     if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
                         $result_disabled_ext_all = true;
                     }
                 }
                 // If there are several attempts, and the link to extend has been clicked, show each attempt...
                 if ($counter % 2 == 0) {
                     $oddclass = 'row_odd';
                 } else {
                     $oddclass = 'row_even';
                 }
                 $extend_link = '';
                 if (!empty($inter_num)) {
                     $extend_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix);
                 }
                 $title = $row['mytitle'];
                 if (empty($title)) {
                     $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
                 }
                 if (in_array($row['item_type'], $chapterTypes)) {
                     $title = "<h4> {$title} </h4>";
                 }
                 $lesson_status = $row['mystatus'];
                 $title = Security::remove_XSS($title);
                 $counter++;
                 $action = null;
                 if ($type == 'classic') {
                     $action = '<td></td>';
                 }
                 if (in_array($row['item_type'], $chapterTypes)) {
                     $output .= '<tr class="' . $oddclass . '">
                             <td>' . $extend_link . '</td>
                             <td colspan="4">
                                ' . $title . '
                             </td>
                             <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             ' . $action . '
                         </tr>';
                     continue;
                 } else {
                     $output .= '<tr class="' . $oddclass . '">
                             <td>' . $extend_link . '</td>
                             <td colspan="4">
                                ' . $title . '
                             </td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             ' . $action . '
                         </tr>';
                 }
                 $attemptCount = 1;
                 do {
                     // Check if there are interactions below.
                     $extend_attempt_link = '';
                     $extend_this_attempt = 0;
                     if ((learnpath::get_interactions_count_from_db($row['iv_id'], $course_id) > 0 || learnpath::get_objectives_count_from_db($row['iv_id'], $course_id) > 0) && !$extend_all) {
                         if ($extendAttemptId == $row['iv_id']) {
                             // The extend button for this attempt has been clicked.
                             $extend_this_attempt = 1;
                             $extend_attempt_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix);
                         } else {
                             // Same case if fold_attempt_id is set, so not implemented explicitly.
                             // The extend button for this attempt has not been clicked.
                             $extend_attempt_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix);
                         }
                     }
                     if ($counter % 2 == 0) {
                         $oddclass = 'row_odd';
                     } else {
                         $oddclass = 'row_even';
                     }
                     $lesson_status = $row['mystatus'];
                     $score = $row['myscore'];
                     $time_for_total = $row['mytime'];
                     $time = learnpathItem::getScormTimeFromParameter('js', $row['mytime']);
                     if ($score == 0) {
                         $maxscore = $row['mymaxscore'];
                     } else {
                         if ($row['item_type'] == 'sco') {
                             if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
                                 $maxscore = $row['myviewmaxscore'];
                             } elseif ($row['myviewmaxscore'] === '') {
                                 $maxscore = 0;
                             } else {
                                 $maxscore = $row['mymaxscore'];
                             }
                         } else {
                             $maxscore = $row['mymaxscore'];
                         }
                     }
                     // Remove "NaN" if any (@todo: locate the source of these NaN)
                     $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
                     if ($row['item_type'] != 'dokeos_chapter') {
                         if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                             $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                         } else {
                             switch ($row['item_type']) {
                                 case 'sco':
                                     if ($maxscore == 0) {
                                         $view_score = $score;
                                     } else {
                                         $view_score = ExerciseLib::show_score($score, $maxscore, false);
                                     }
                                     break;
                                 case 'document':
                                     $view_score = $score == 0 ? '/' : ExerciseLib::show_score($score, $maxscore, false);
                                     break;
                                 default:
                                     $view_score = ExerciseLib::show_score($score, $maxscore, false);
                                     break;
                             }
                         }
                         $action = null;
                         if ($type == 'classic') {
                             $action = '<td></td>';
                         }
                         $output .= '<tr class="' . $oddclass . '">
                                 <td></td>
                                 <td>' . $extend_attempt_link . '</td>
                                 <td colspan="3">' . get_lang('Attempt') . ' ' . $attemptCount . '</td>
                                 <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td>
                                 <td colspan="2">' . $view_score . '</td>
                                 <td colspan="2">' . $time . '</td>
                                 ' . $action . '
                             </tr>';
                         $attemptCount++;
                         if (!empty($export_csv)) {
                             $temp = array();
                             $temp[] = $title = Security::remove_XSS($title);
                             $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false, $type));
                             if ($row['item_type'] == 'quiz') {
                                 if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                     $temp[] = '/';
                                 } else {
                                     $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                                 }
                             } else {
                                 $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                             }
                             $temp[] = $time;
                             $csv_content[] = $temp;
                         }
                     }
                     $counter++;
                     $action = null;
                     if ($type == 'classic') {
                         $action = '<td></td>';
                     }
                     if ($extend_this_attempt || $extend_all) {
                         $list1 = learnpath::get_iv_interactions_array($row['iv_id']);
                         foreach ($list1 as $id => $interaction) {
                             if ($counter % 2 == 0) {
                                 $oddclass = 'row_odd';
                             } else {
                                 $oddclass = 'row_even';
                             }
                             $student_response = urldecode($interaction['student_response']);
                             $content_student_response = explode('__|', $student_response);
                             if (count($content_student_response) > 0) {
                                 if (count($content_student_response) >= 3) {
                                     // Pop the element off the end of array.
                                     array_pop($content_student_response);
                                 }
                                 $student_response = implode(',', $content_student_response);
                             }
                             $output .= '<tr class="' . $oddclass . '">
                                     <td></td>
                                     <td></td>
                                     <td></td>
                                     <td>' . $interaction['order_id'] . '</td>
                                     <td>' . $interaction['id'] . '</td>
                                     <td colspan="2">' . $interaction['type'] . '</td>
                                     <td>' . $student_response . '</td>
                                     <td>' . $interaction['result'] . '</td>
                                     <td>' . $interaction['latency'] . '</td>
                                     <td>' . $interaction['time'] . '</td>
                                     ' . $action . '
                                 </tr>';
                             $counter++;
                         }
                         $list2 = learnpath::get_iv_objectives_array($row['iv_id']);
                         foreach ($list2 as $id => $interaction) {
                             if ($counter % 2 == 0) {
                                 $oddclass = 'row_odd';
                             } else {
                                 $oddclass = 'row_even';
                             }
                             $output .= '<tr class="' . $oddclass . '">
                                     <td></td>
                                     <td></td>
                                     <td></td>
                                     <td>' . $interaction['order_id'] . '</td>
                                     <td colspan="2">' . $interaction['objective_id'] . '</td>
                                     <td colspan="2">' . $interaction['status'] . '</td>
                                     <td>' . $interaction['score_raw'] . '</td>
                                     <td>' . $interaction['score_max'] . '</td>
                                     <td>' . $interaction['score_min'] . '</td>
                                     ' . $action . '
                                  </tr>';
                             $counter++;
                         }
                     }
                 } while ($row = Database::fetch_array($result));
             } elseif ($num > 0) {
                 // Not extended.
                 $row = Database::fetch_array($result, 'ASSOC');
                 $my_id = $row['myid'];
                 $my_lp_id = $row['mylpid'];
                 $my_lp_view_id = $row['mylpviewid'];
                 $my_path = $row['path'];
                 $result_disabled_ext_all = false;
                 if ($row['item_type'] == 'quiz') {
                     // Check results_disabled in quiz table.
                     $my_path = Database::escape_string($my_path);
                     $sql = "SELECT results_disabled\n                                FROM {$TBL_QUIZ}\n                                WHERE c_id = {$course_id} AND id ='" . $my_path . "'";
                     $res_result_disabled = Database::query($sql);
                     $row_result_disabled = Database::fetch_row($res_result_disabled);
                     if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
                         $result_disabled_ext_all = true;
                     }
                 }
                 // Check if there are interactions below
                 $extend_this_attempt = 0;
                 $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id);
                 $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
                 $extend_attempt_link = '';
                 if ($inter_num > 0 || $objec_num > 0) {
                     if (!empty($extendAttemptId) && $extendAttemptId == $row['iv_id']) {
                         // The extend button for this attempt has been clicked.
                         $extend_this_attempt = 1;
                         $extend_attempt_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix);
                     } else {
                         // Same case if fold_attempt_id is set, so not implemented explicitly.
                         // The extend button for this attempt has not been clicked.
                         $extend_attempt_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix);
                     }
                 }
                 if ($counter % 2 == 0) {
                     $oddclass = 'row_odd';
                 } else {
                     $oddclass = 'row_even';
                 }
                 $extend_link = '';
                 if ($inter_num > 1) {
                     $extend_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix);
                 }
                 $lesson_status = $row['mystatus'];
                 $score = $row['myscore'];
                 $subtotal_time = $row['mytime'];
                 while ($tmp_row = Database::fetch_array($result)) {
                     $subtotal_time += $tmp_row['mytime'];
                 }
                 $title = $row['mytitle'];
                 // Selecting the exe_id from stats attempts tables in order to look the max score value.
                 $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                          WHERE
                             exe_exo_id="' . $row['path'] . '" AND
                             exe_user_id="' . $user_id . '" AND
                             orig_lp_id = "' . $lp_id . '" AND
                             orig_lp_item_id = "' . $row['myid'] . '" AND
                             c_id = ' . $course_id . ' AND
                             status <> "incomplete" AND
                             session_id = ' . $session_id . '
                          ORDER BY exe_date DESC
                          LIMIT 1';
                 $resultLastAttempt = Database::query($sql);
                 $num = Database::num_rows($resultLastAttempt);
                 $id_last_attempt = null;
                 if ($num > 0) {
                     while ($rowLA = Database::fetch_array($resultLastAttempt)) {
                         $id_last_attempt = $rowLA['exe_id'];
                     }
                 }
                 if ($score == 0) {
                     $maxscore = $row['mymaxscore'];
                 } else {
                     if ($row['item_type'] == 'sco') {
                         if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
                             $maxscore = $row['myviewmaxscore'];
                         } elseif ($row['myviewmaxscore'] === '') {
                             $maxscore = 0;
                         } else {
                             $maxscore = $row['mymaxscore'];
                         }
                     } else {
                         if ($row['item_type'] == 'quiz') {
                             // Get score and total time from last attempt of a exercise en lp.
                             $sql = "SELECT score\n                                        FROM {$TBL_LP_ITEM_VIEW}\n                                        WHERE\n                                            c_id = {$course_id} AND\n                                            lp_item_id = '" . (int) $my_id . "' AND\n                                            lp_view_id = '" . (int) $my_lp_view_id . "'\n                                        ORDER BY view_count DESC limit 1";
                             $res_score = Database::query($sql);
                             $row_score = Database::fetch_array($res_score);
                             $sql = "SELECT SUM(total_time) as total_time\n                                        FROM {$TBL_LP_ITEM_VIEW}\n                                        WHERE\n                                            c_id = {$course_id} AND\n                                            lp_item_id = '" . (int) $my_id . "' AND\n                                            lp_view_id = '" . (int) $my_lp_view_id . "'";
                             $res_time = Database::query($sql);
                             $row_time = Database::fetch_array($res_time);
                             if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) {
                                 $score = (double) $row_score['score'];
                                 $subtotal_time = (int) $row_time['total_time'];
                             } else {
                                 $score = 0;
                                 $subtotal_time = 0;
                             }
                             // Selecting the max score from an attempt.
                             $sql = "SELECT SUM(t.ponderation) as maxscore\n                                        FROM (\n                                            SELECT DISTINCT\n                                                question_id, marks, ponderation\n                                            FROM {$tbl_stats_attempts} as at\n                                            INNER JOIN  {$tbl_quiz_questions} as q\n                                            ON (q.id = at.question_id AND q.c_id = {$course_id})\n                                            WHERE exe_id ='{$id_last_attempt}'\n                                        ) as t";
                             $result = Database::query($sql);
                             $row_max_score = Database::fetch_array($result);
                             $maxscore = $row_max_score['maxscore'];
                         } else {
                             $maxscore = $row['mymaxscore'];
                         }
                     }
                 }
                 $time_for_total = $subtotal_time;
                 $time = learnpathItem::getScormTimeFromParameter('js', $subtotal_time);
                 if (empty($title)) {
                     $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
                 }
                 $action = null;
                 if ($type == 'classic') {
                     $action = '<td></td>';
                 }
                 if (in_array($row['item_type'], $chapterTypes)) {
                     $title = Security::remove_XSS($title);
                     $output .= '<tr class="' . $oddclass . '">
                             <td>' . $extend_link . '</td>
                             <td colspan="4">
                             <h4>' . $title . '</h4>
                             </td>
                             <td colspan="2">' . learnpathitem::humanize_status($lesson_status) . '</td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             ' . $action . '
                         </tr>';
                 } else {
                     $correct_test_link = '-';
                     if ($row['item_type'] == 'quiz') {
                         $my_url_suffix = '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . intval($row['mylpid']) . '&origin=' . $origin;
                         $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                                  WHERE
                                     exe_exo_id="' . $row['path'] . '" AND
                                     exe_user_id="' . $user_id . '" AND
                                     orig_lp_id = "' . $lp_id . '" AND
                                     orig_lp_item_id = "' . $row['myid'] . '" AND
                                     c_id = ' . $course_id . ' AND
                                     status <> "incomplete" AND
                                     session_id = ' . $session_id . '
                                  ORDER BY exe_date DESC ';
                         $resultLastAttempt = Database::query($sql);
                         $num = Database::num_rows($resultLastAttempt);
                         if ($num > 0) {
                             if ($extendedAttempt == 1 && $lp_id == $my_lp_id && $lp_item_id == $my_id) {
                                 $correct_test_link = Display::url(Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id);
                             } else {
                                 $correct_test_link = Display::url(Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttemptsByExercise')), api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id);
                             }
                         }
                     }
                     $title = Security::remove_XSS($title);
                     $action = null;
                     if ($type == 'classic') {
                         $action = '<td>' . $correct_test_link . '</td>';
                     }
                     if ($lp_id == $my_lp_id && false) {
                         $output .= '<tr class =' . $oddclass . '>
                                 <td>' . $extend_link . '</td>
                                 <td colspan="4">' . $title . '</td>
                                 <td colspan="2">&nbsp;</td>
                                 <td colspan="2">&nbsp;</td>
                                 <td colspan="2">&nbsp;</td>
                                 ' . $action . '
                             </tr>';
                         $output .= '</tr>';
                     } else {
                         if ($lp_id == $my_lp_id && $lp_item_id == $my_id) {
                             $output .= "<tr class='{$oddclass}'>";
                         } else {
                             $output .= "<tr class='{$oddclass}'>";
                         }
                         $scoreItem = null;
                         if ($row['item_type'] == 'quiz') {
                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                 $scoreItem .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                             } else {
                                 $scoreItem .= ExerciseLib::show_score($score, $maxscore, false);
                             }
                         } else {
                             $scoreItem .= $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore);
                         }
                         $output .= '
                             <td>' . $extend_link . '</td>
                             <td colspan="4">' . $title . '</td>
                             <td colspan="2">' . learnpathitem::humanize_status($lesson_status) . '</td>
                             <td colspan="2">' . $scoreItem . '</td>
                             <td colspan="2">' . $time . '</td>
                             ' . $action . '
                          ';
                         $output .= '</tr>';
                     }
                     if (!empty($export_csv)) {
                         $temp = array();
                         $temp[] = api_html_entity_decode($title, ENT_QUOTES);
                         $temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES);
                         if ($row['item_type'] == 'quiz') {
                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                 $temp[] = '/';
                             } else {
                                 $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                             }
                         } else {
                             $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                         }
                         $temp[] = $time;
                         $csv_content[] = $temp;
                     }
                 }
                 $counter++;
                 $action = null;
                 if ($type == 'classic') {
                     $action = '<td></td>';
                 }
                 if ($extend_this_attempt || $extend_all) {
                     $list1 = learnpath::get_iv_interactions_array($row['iv_id']);
                     foreach ($list1 as $id => $interaction) {
                         if ($counter % 2 == 0) {
                             $oddclass = 'row_odd';
                         } else {
                             $oddclass = 'row_even';
                         }
                         $output .= '<tr class="' . $oddclass . '">
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td>' . $interaction['order_id'] . '</td>
                                 <td>' . $interaction['id'] . '</td>
                                 <td colspan="2">' . $interaction['type'] . '</td>
                                 <td>' . urldecode($interaction['student_response']) . '</td>
                                 <td>' . $interaction['result'] . '</td>
                                 <td>' . $interaction['latency'] . '</td>
                                 <td>' . $interaction['time'] . '</td>
                                 ' . $action . '
                            </tr>';
                         $counter++;
                     }
                     $list2 = learnpath::get_iv_objectives_array($row['iv_id']);
                     foreach ($list2 as $id => $interaction) {
                         if ($counter % 2 == 0) {
                             $oddclass = 'row_odd';
                         } else {
                             $oddclass = 'row_even';
                         }
                         $output .= '<tr class="' . $oddclass . '">
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td>' . $interaction['order_id'] . '</td>
                                 <td colspan="2">' . $interaction['objective_id'] . '</td>
                                 <td colspan="2">' . $interaction['status'] . '</td>
                                 <td>' . $interaction['score_raw'] . '</td>
                                 <td>' . $interaction['score_max'] . '</td>
                                 <td>' . $interaction['score_min'] . '</td>
                                 ' . $action . '
                            </tr>';
                         $counter++;
                     }
                 }
                 // Attempts listing by exercise.
                 if ($lp_id == $my_lp_id && $lp_item_id == $my_id && $extendedAttempt) {
                     // Get attempts of a exercise.
                     if (!empty($lp_id) && !empty($lp_item_id) && $row['item_type'] === 'quiz') {
                         $sql = "SELECT path FROM {$TBL_LP_ITEM}\n                                    WHERE\n                                        c_id = {$course_id} AND\n                                        id = '{$lp_item_id}' AND\n                                        lp_id = '{$lp_id}'";
                         $res_path = Database::query($sql);
                         $row_path = Database::fetch_array($res_path);
                         if (Database::num_rows($res_path) > 0) {
                             $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                                     WHERE
                                         exe_exo_id="' . (int) $row_path['path'] . '" AND
                                         status <> "incomplete" AND
                                         exe_user_id="' . $user_id . '" AND
                                         orig_lp_id = "' . (int) $lp_id . '" AND
                                         orig_lp_item_id = "' . (int) $lp_item_id . '" AND
                                         c_id = ' . $course_id . '  AND
                                         session_id = ' . $session_id . '
                                     ORDER BY exe_date';
                             $res_attempts = Database::query($sql);
                             $num_attempts = Database::num_rows($res_attempts);
                             if ($num_attempts > 0) {
                                 $n = 1;
                                 while ($row_attempts = Database::fetch_array($res_attempts)) {
                                     $my_score = $row_attempts['exe_result'];
                                     $my_maxscore = $row_attempts['exe_weighting'];
                                     $my_exe_id = $row_attempts['exe_id'];
                                     $my_orig_lp = $row_attempts['orig_lp_id'];
                                     $my_orig_lp_item = $row_attempts['orig_lp_item_id'];
                                     $my_exo_exe_id = $row_attempts['exe_exo_id'];
                                     $mktime_start_date = api_strtotime($row_attempts['start_date'], 'UTC');
                                     $mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC');
                                     if ($mktime_start_date && $mktime_exe_date) {
                                         $mytime = (int) $mktime_exe_date - (int) $mktime_start_date;
                                         $time_attemp = learnpathItem::getScormTimeFromParameter('js', $mytime);
                                         $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
                                     } else {
                                         $time_attemp = ' - ';
                                     }
                                     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                         $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                                     } else {
                                         // Show only float when need it
                                         if ($my_score == 0) {
                                             $view_score = ExerciseLib::show_score(0, $my_maxscore, false);
                                         } else {
                                             if ($my_maxscore == 0) {
                                                 $view_score = $my_score;
                                             } else {
                                                 $view_score = ExerciseLib::show_score($my_score, $my_maxscore, false);
                                             }
                                         }
                                     }
                                     $my_lesson_status = $row_attempts['status'];
                                     if ($my_lesson_status == '') {
                                         $my_lesson_status = learnpathitem::humanize_status('completed');
                                     } elseif ($my_lesson_status == 'incomplete') {
                                         $my_lesson_status = learnpathitem::humanize_status('incomplete');
                                     }
                                     $output .= '<tr class="' . $oddclass . '" >
                                     <td></td>
                                     <td>' . $extend_attempt_link . '</td>
                                     <td colspan="3">' . get_lang('Attempt') . ' ' . $n . '</td>
                                     <td colspan="2">' . $my_lesson_status . '</td>
                                     <td colspan="2">' . $view_score . '</td>
                                     <td colspan="2">' . $time_attemp . '</td>';
                                     if ($action == 'classic') {
                                         if ($origin != 'tracking') {
                                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                                 $output .= '<td>
                                                         <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '">
                                                         </td>';
                                             } else {
                                                 $output .= '<td>
                                                         <a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $courseCode . '" target="_parent">
                                                         <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '">
                                                         </a></td>';
                                             }
                                         } else {
                                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                                 $output .= '<td>
                                                             <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></td>';
                                             } else {
                                                 $output .= '<td>
                                                                 <a href="../exercice/exercise_show.php?cidReq=' . $courseCode . '&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent">
                                                                 <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>';
                                             }
                                         }
                                     }
                                     $output .= '</tr>';
                                     $n++;
                                 }
                             }
                             $output .= '<tr><td colspan="12">&nbsp;</td></tr>';
                         }
                     }
                 }
             }
             $total_time += $time_for_total;
             // QUIZZ IN LP
             $a_my_id = array();
             if (!empty($my_lp_id)) {
                 $a_my_id[] = $my_lp_id;
             }
         }
     }
     // NOT Extend all "left green cross"
     if (!empty($a_my_id)) {
         if ($extendedAttempt) {
             // "Right green cross" extended
             $total_score = self::get_avg_student_score($user_id, $course_id, $a_my_id, $session_id, false, false);
         } else {
             // "Left green cross" extended
             $total_score = self::get_avg_student_score($user_id, $course_id, $a_my_id, $session_id, false, true);
         }
     } else {
         // Extend all "left green cross"
         $total_score = self::get_avg_student_score($user_id, $course_id, array($lp_id), $session_id, false, false);
     }
     $total_time = learnpathItem::getScormTimeFromParameter('js', $total_time);
     $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
         $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
     } else {
         if (is_numeric($total_score)) {
             $final_score = $total_score . '%';
         } else {
             $final_score = $total_score;
         }
     }
     $progress = learnpath::getProgress($lp_id, $user_id, $course_id, $session_id);
     if ($counter % 2 == 0) {
         $oddclass = 'row_odd';
     } else {
         $oddclass = 'row_even';
     }
     $action = null;
     if ($type == 'classic') {
         $action = '<td></td>';
     }
     $output .= '<tr class="' . $oddclass . '">
             <td></td>
             <td colspan="4">
                 <i>' . get_lang('AccomplishedStepsTotal') . '</i>
             </td>
             <td colspan="2">' . $progress . '%</td>
             <td colspan="2">
                 ' . $final_score . '
             </td>
             <td colspan="2">' . $total_time . '</div>
             ' . $action . '
        </tr>';
     $output .= '
                 </tbody>
             </table>
         </div>
     ';
     if (!empty($export_csv)) {
         $temp = array('', '', '', '');
         $csv_content[] = $temp;
         $temp = array(get_lang('AccomplishedStepsTotal'), '', $final_score, $total_time);
         $csv_content[] = $temp;
         ob_end_clean();
         Export::arrayToCsv($csv_content, 'reporting_learning_path_details');
         exit;
     }
     return $output;
 }
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function initialize_item($lp_id, $user_id, $view_id, $next_item) {
    global $debug;
    $return = '';
    if ($debug > 0) { error_log('In initialize_item('.$lp_id.','.$user_id.','.$view_id.','.$next_item.')', 0); }
    /*$item_id may be one of:
     * -'next'
     * -'previous'
     * -'first'
     * -'last'
     * - a real item ID
     */
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $mylp->set_current_item($next_item);
    if ($debug > 1) { error_log('In initialize_item() - new item is '.$next_item, 0); }
    $mylp->start_current_item(true);

    if (is_object($mylp->items[$next_item])) {
        if ($debug > 1) { error_log('In initialize_item - recovering existing item object '.$next_item, 0); }
        $mylpi = $mylp->items[$next_item];
    } else {
        if ($debug > 1) { error_log('In initialize_item - generating new item object '.$next_item, 0); }
        $mylpi = new learnpathItem($next_item, $user_id);
    }

    if ($mylpi) {
        $mylpi->set_lp_view($view_id);
    }

    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') { $mymax = "''"; }
    $mymin = $mylpi->get_min();

    $mylesson_status = $mylpi->get_status();
    $mytotal_time = $mylpi->get_scorm_time('js', null, true);
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[".$i.",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
	// Obtention des donnees d'objectifs

	$mycoursedb = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
    $course_id = api_get_course_int_id();
	$mylp_iv_id = $mylpi->db_item_view_id;

    $phpobjectives = array();

    if (!empty($mylp_iv_id)) {
        $sql = "SELECT objective_id, status, score_raw, score_max, score_min
            FROM $mycoursedb
            WHERE lp_iv_id = $mylp_iv_id AND c_id = $course_id
            ORDER BY id ASC;";
        $res = Database::query($sql);
        while ($row = Database::fetch_row($res)) {
            $phpobjectives[] = $row;
        }
    }
	$myobjectives = json_encode($phpobjectives);

    $return .=
            "olms.score=".$myscore.";" .
            "olms.max=".$mymax.";" .
            "olms.min=".$mymin.";" .
            "olms.lesson_status='".$mylesson_status."';" .
            "olms.lesson_location='".$mylesson_location."';" .
            "olms.session_time='".$mysession_time."';" .
            "olms.suspend_data='".$mysuspend_data."';" .
            "olms.total_time = '".$mytotal_time."';" .
            "olms.mastery_score = '".$mymastery_score."';" .
            "olms.max_time_allowed = '".$mymax_time_allowed."';" .
            "olms.launch_data = '".$mylaunch_data."';" .
            "olms.interactions = new Array(".$myistring.");" .
            //"olms.item_objectives = new Array();" .
            "olms.item_objectives = ".$myobjectives.";" .
            "olms.G_lastError = 0;" .
            "olms.G_LastErrorMessage = 'No error';".
            "olms.finishSignalReceived = 0;";
    /*
     * and re-initialise the rest (proper to the LMS)
     * -lms_lp_id
     * -lms_item_id
     * -lms_old_item_id
     * -lms_new_item_id
     * -lms_initialized
     * -lms_progress_bar_mode
     * -lms_view_id
     * -lms_user_id
     */
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();

    $return .=
            "olms.lms_lp_id=".$lp_id.";" .
            "olms.lms_item_id=".$next_item.";" .
            "olms.lms_old_item_id=0;" .
            "olms.lms_initialized=0;" .
            "olms.lms_view_id=".$view_id.";" .
            "olms.lms_user_id=".$user_id.";" .
            "olms.next_item=".$next_item.";" . // This one is very important to replace possible literal strings.
            "olms.lms_next_item=".$mynext.";" .
            "olms.lms_previous_item=".$myprevious.";" .
            "olms.lms_item_type = '".$myitemtype."';" .
            "olms.lms_item_credit = '".$mycredit."';" .
            "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
            "olms.lms_item_launch_data = '".$mylaunch_data."';" .
            "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
            "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
            "olms.lms_item_core_exit = '".$mycore_exit."';" .
            "olms.asset_timer = 0;";

    $mylp->set_error_msg('');
    $mylp->prerequisites_match(); // Check the prerequisites are all complete.
    if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
    if ($debug > 1) { error_log("return = $return "); }
    return $return;
}
Beispiel #17
0
 /**
  * Save function. Uses the parent save function and adds a layer for AICC.
  * @param	boolean	Save from URL params (1) or from object attributes (0)
  */
 function save($from_outside = true, $prereqs_complete = false)
 {
     parent::save($from_outside, $prereqs_complete = false);
     //under certain conditions, the scorm_contact should not be set, because no scorm signal was sent
     $this->aicc_contact = true;
     if (!$this->aicc_contact) {
         //error_log('New LP - was expecting SCORM message but none received',0);
     }
 }
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_item)
{
    $debug = 0;
    $return = '';
    if ($debug > 0) {
        error_log('In xajax_switch_item_details(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $current_item . ',' . $next_item . ')', 0);
    }
    //$objResponse = new xajaxResponse();
    /*$item_id may be one of:
     * -'next'
     * -'previous'
     * -'first'
     * -'last'
     * - a real item ID
     */
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {next} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {previous} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {first} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked.
            if ($next_item == $current_item) {
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) {
                error_log('In {default} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit) {
        $mylp->save_current();
    }
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) {
            error_log('In switch_item_details - generating new item object', 0);
        }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') {
        $mymax = "''";
    }
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    /*
    if ($mylpi->get_type() == 'asset') {
        // Temporary measure to save completion of an asset. Later on, Chamilo should trigger something on unload, maybe... (even though that would mean the last item cannot be completed)
        $mylesson_status = 'completed';
        $mylpi->set_status('completed');
        $mylpi->save();
    }
    */
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[" . $i . ",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
    /*
     * The following lines should reinitialize the values for the SCO
     * However, due to many complications, we are now relying more on the
     * LMSInitialize() call and its underlying lp_ajax_initialize.php call
     * so this code is technically deprecated (but the change of item_id should
     * remain). However, due to numerous technical issues with SCORM, we prefer
     * leaving it as a double-lock security. If removing, please test carefully
     * with both SCORM and proper learning path tracking.
     */
    $return .= "olms.score=" . $myscore . ";" . "olms.max=" . $mymax . ";" . "olms.min=" . $mymin . ";" . "olms.lesson_status='" . $mylesson_status . "';" . "olms.lesson_location='" . $mylesson_location . "';" . "olms.session_time='" . $mysession_time . "';" . "olms.suspend_data='" . $mysuspend_data . "';" . "olms.total_time = '" . $mytotal_time . "';" . "olms.mastery_score = '" . $mymastery_score . "';" . "olms.max_time_allowed = '" . $mymax_time_allowed . "';" . "olms.launch_data = '" . $mylaunch_data . "';" . "olms.interactions = new Array(" . $myistring . ");" . "olms.item_objectives = new Array();" . "olms.G_lastError = 0;" . "olms.G_LastErrorMessage = 'No error';" . "olms.finishSignalReceived = 0;";
    /*
     * and re-initialise the rest
     * -lms_lp_id
     * -lms_item_id
     * -lms_old_item_id
     * -lms_new_item_id
     * -lms_initialized
     * -lms_progress_bar_mode
     * -lms_view_id
     * -lms_user_id
     */
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = $myprogress_mode == '' ? '%' : $myprogress_mode;
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();
    $return .= "olms.lms_lp_id=" . $lp_id . ";" . "olms.lms_item_id=" . $new_item_id . ";" . "olms.lms_old_item_id=0;" . "olms.lms_initialized=0;" . "olms.lms_view_id=" . $view_id . ";" . "olms.lms_user_id=" . $user_id . ";" . "olms.next_item=" . $new_item_id . ";" . "olms.lms_next_item=" . $mynext . ";" . "olms.lms_previous_item=" . $myprevious . ";" . "olms.lms_item_type = '" . $myitemtype . "';" . "olms.lms_item_credit = '" . $mycredit . "';" . "olms.lms_item_lesson_mode = '" . $mylesson_mode . "';" . "olms.lms_item_launch_data = '" . $mylaunch_data . "';" . "olms.lms_item_interactions_count = '" . $myinteractions_count . "';" . "olms.lms_item_objectives_count = '" . $myinteractions_count . "';" . "olms.lms_item_core_exit = '" . $mycore_exit . "';" . "olms.asset_timer = 0;";
    $return .= "update_toc('unhighlight','" . $current_item . "');" . "update_toc('highlight','" . $new_item_id . "');" . "update_toc('{$mylesson_status}','" . $new_item_id . "');" . "update_progress_bar('{$mycomplete}','{$mytotal}','{$myprogress_mode}');";
    $return .= 'updateGamificationValues(); ';
    $mylp->set_error_msg('');
    $mylp->prerequisites_match();
    // Check the prerequisites are all complete.
    if ($debug > 1) {
        error_log('Prereq_match() returned ' . htmlentities($mylp->error), 0);
    }
    // Save the new item ID for the exercise tool to use.
    Session::write('scorm_item_id', $new_item_id);
    Session::write('lpobject', serialize($mylp));
    return $return;
}
 if (!$is_allowed_to_edit) {
     api_not_allowed(true);
 }
 if ($debug > 0) {
     error_log('New LP - add audio action triggered', 0);
 }
 if (!$lp_found) {
     //check if the learnpath ID was defined, otherwise send back to list
     if ($debug > 0) {
         error_log('New LP - No learnpath given for add audio', 0);
     }
     require 'lp_list.php';
 } else {
     $_SESSION['refresh'] = 1;
     if (isset($_REQUEST['id'])) {
         $lp_item_obj = new learnpathItem($_REQUEST['id']);
         //Remove audio
         if (isset($_POST['delete_file']) && $_POST['delete_file'] == 1) {
             $lp_item_obj->remove_audio();
         }
         //Upload audio
         if (isset($_FILES['file']) && !empty($_FILES['file'])) {
             //Updating the lp.modified_on
             $_SESSION['oLP']->set_modified_on();
             $lp_item_obj->add_audio();
         }
         //Add audio file from documents
         if (isset($_REQUEST['document_id']) && !empty($_REQUEST['document_id'])) {
             $_SESSION['oLP']->set_modified_on();
             $lp_item_obj->add_audio_from_documents($_REQUEST['document_id']);
         }
                     $ar2 = Database::fetch_array($result2);
                     while ($ar2 != '') {
                         if (isset($_REQUEST["scormstudentopen"]) && $ar2['user_id'] == $scormstudentopen) {
                             $line .= $ar['id'] . " " . $ar2['user_id'] . " " . api_get_person_name($ar2['firstname'], $ar2['lastname']);
                         } else {
                             $line .= $ar['id'] . " " . $ar2['user_id'] . " " . api_get_person_name($ar2['firstname'], $ar2['lastname']);
                         }
                         if ($ar2['user_id'] == $scormstudentopen) {
                             //have to list the student's results
                             $studentId = $ar2['user_id'];
                             $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " . "FROM {$tbl_learnpath_item} i " . "INNER JOIN {$tbl_learnpath_item_view} iv ON i.id=iv.lp_item_id " . "INNER JOIN {$tbl_learnpath_view} v ON iv.lp_view_id=v.id " . "WHERE \ti.c_id = {$course_id} AND\n                                        \t\tiv.c_id = {$course_id} AND\n                                        \t\tv.c_id = {$course_id} AND\n                                \t\t\t\tv.user_id={$studentId} and v.lp_id={$contentId} ORDER BY v.id, i.id";
                             $result3 = Database::query($sql3);
                             $ar3 = Database::fetch_array($result3);
                             $title_line .= get_lang('ScormTitleColumn') . ";" . get_lang('ScormStatusColumn') . ";" . get_lang('ScormScoreColumn') . ";" . get_lang('ScormTimeColumn');
                             while ($ar3['status'] != '') {
                                 $time = learnpathItem::get_scorm_time('php', $ar3['total_time']);
                                 $line .= $title . ";" . $ar3['status'] . ";" . $ar3['score'] . ";" . $time;
                                 $ar3 = Database::fetch_array($result3);
                             }
                         }
                         $line .= "\n";
                         $ar2 = Database::fetch_array($result2);
                     }
                     $title_line .= "\n";
                 }
             }
             $ar = Database::fetch_array($result);
         }
     }
 }
 /*
Beispiel #21
0
                     while ($ar2 != '') {
                         if (isset($_REQUEST["scormstudentopen"]) && $ar2['user_id'] == $scormstudentopen) {
                             $line .= $ar['id'] . " " . $ar2['user_id'] . " " . api_get_person_name($ar2['firstname'], $ar2['lastname']);
                         } else {
                             $line .= $ar['id'] . " " . $ar2['user_id'] . " " . api_get_person_name($ar2['firstname'], $ar2['lastname']);
                         }
                         if ($ar2['user_id'] == $scormstudentopen) {
                             //have to list the student's results
                             $studentId = $ar2['user_id'];
                             $sql3 = "SELECT iv.status, iv.score, i.title, iv.total_time " . "FROM {$tbl_learnpath_item} i " . "INNER JOIN {$tbl_learnpath_item_view} iv ON i.id=iv.lp_item_id " . "INNER JOIN {$tbl_learnpath_view} v ON iv.lp_view_id=v.id " . "WHERE \ti.c_id = {$course_id} AND\n                                        \t\tiv.c_id = {$course_id} AND\n                                        \t\tv.c_id = {$course_id} AND\n                                \t\t\t\tv.user_id={$studentId} and v.lp_id={$contentId} ORDER BY v.id, i.id";
                             $result3 = Database::query($sql3);
                             $ar3 = Database::fetch_array($result3);
                             $title_line .= get_lang('ScormTitleColumn') . ";" . get_lang('ScormStatusColumn') . ";" . get_lang('ScormScoreColumn') . ";" . get_lang('ScormTimeColumn');
                             while ($ar3['status'] != '') {
                                 require_once '../newscorm/learnpathItem.class.php';
                                 $time = learnpathItem::getScormTimeFromParameter('php', $ar3['total_time']);
                                 $line .= $title . ";" . $ar3['status'] . ";" . $ar3['score'] . ";" . $time;
                                 $ar3 = Database::fetch_array($result3);
                             }
                         }
                         $line .= "\n";
                         $ar2 = Database::fetch_array($result2);
                     }
                     $title_line .= "\n";
                 }
             }
             $ar = Database::fetch_array($result);
         }
     }
 }
 /*
Beispiel #22
0
        $interbreadcrumb[] = array('url' => 'lp_controller.php?action=add_item&type=step&lp_id=' . $_SESSION['oLP']->get_id(), 'name' => get_lang('NewStep'));
        break;
    default:
        $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewStep'));
        break;
}
if ($action == 'add_item' && $type == 'document') {
    $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('NewDocumentCreated'));
}
// Theme calls.
$show_learn_path = true;
$lp_item_id = isset($_GET['id']) ? intval($_GET['id']) : null;
if (empty($lp_item_id)) {
    api_not_allowed();
}
$lp_item = new learnpathItem($lp_item_id);
/** @var Template $tpl */
$tpl = $app['template'];
$form = new FormValidator('add_audio', 'post', api_get_self() . '?action=add_audio&id=' . $lp_item_id, null, array('enctype' => 'multipart/form-data'));
$suredel = trim(get_lang('AreYouSureToDelete'));
$lpPathInfo = $_SESSION['oLP']->generate_lp_folder(api_get_course_info());
$file = null;
if (isset($lp_item->audio) && !empty($lp_item->audio)) {
    $file = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document/audio/' . $lp_item->audio;
    $urlFile = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document/audio/' . $lp_item->audio;
    if (!file_exists($file)) {
        $file = api_get_path(SYS_COURSE_PATH) . $_course['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio;
        $urlFile = api_get_path(WEB_COURSE_PATH) . $_course['path'] . '/document' . $lpPathInfo['dir'] . $lp_item->audio;
    }
}
$page = $_SESSION['oLP']->build_action_menu(true);