Fixing get_progress_bar() calls see BT#8904 #7342

1.9.x
Julio Montoya 11 years ago
parent c3d575b6ad
commit e6a82dca85
  1. 6
      main/document/document.php
  2. 42
      main/document/edit_document.php
  3. 91
      main/newscorm/learnpath.class.php
  4. 15
      main/newscorm/lp_list.php
  5. 2
      main/newscorm/lp_nav.php
  6. 2
      main/newscorm/lp_view.php

@ -1108,8 +1108,6 @@ if ($is_allowed_to_edit ||
$dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name); $dir_name = $curdirpath.$added_slash.replace_dangerous_char($post_dir_name);
$dir_name = disable_dangerous_file($dir_name); $dir_name = disable_dangerous_file($dir_name);
$dir_check = $base_work_dir.$dir_name; $dir_check = $base_work_dir.$dir_name;
if (!is_dir($dir_check)) {
$visibility = empty($groupId) ? null : 1; $visibility = empty($groupId) ? null : 1;
$created_dir = create_unexisting_directory( $created_dir = create_unexisting_directory(
@ -1129,9 +1127,7 @@ if ($is_allowed_to_edit ||
} else { } else {
$message = Display::return_message(get_lang('CannotCreateDir'), 'error'); $message = Display::return_message(get_lang('CannotCreateDir'), 'error');
} }
} else {
$message = Display::return_message(get_lang('CannotCreateDir'), 'error');
}
} }
Session::write('message', $message); Session::write('message', $message);
} }

@ -24,9 +24,6 @@
* @todo improve script structure (FormValidator is used to display form, but * @todo improve script structure (FormValidator is used to display form, but
* not for validation at the moment) * not for validation at the moment)
*/ */
/**
* Code
*/
// Name of the language file that needs to be included // Name of the language file that needs to be included
$language_file = array('document', 'gradebook'); $language_file = array('document', 'gradebook');
@ -243,7 +240,7 @@ if ($is_allowed_to_edit) {
$filename = stripslashes($_POST['filename']); $filename = stripslashes($_POST['filename']);
$extension = $_POST['extension']; $extension = $_POST['extension'];
$content = trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))); $content = isset($_POST['content']) ? trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))) : null;
$content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY); $content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY);
if (!strstr($content, '/css/frames.css')) { if (!strstr($content, '/css/frames.css')) {
@ -255,7 +252,7 @@ if ($is_allowed_to_edit) {
} }
$file = $dir.'/'.$filename.'.'.$extension; $file = $dir.'/'.$filename.'.'.$extension;
$read_only_flag = $_POST['readonly']; $read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null;
$read_only_flag = empty($read_only_flag) ? 0 : 1; $read_only_flag = empty($read_only_flag) ? 0 : 1;
if (empty($filename)) { if (empty($filename)) {
@ -267,17 +264,8 @@ if ($is_allowed_to_edit) {
if ($read_only_flag == 0) { if ($read_only_flag == 0) {
if (!empty($content)) { if (!empty($content)) {
if ($fp = @fopen($document_data['absolute_path'], 'w')) { if ($fp = @fopen($document_data['absolute_path'], 'w')) {
// For flv player, change absolute paht temporarely to prevent from erasing it in the following lines // For flv player, change absolute path temporarily to prevent from erasing it in the following lines
$content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content); $content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content);
// Change the path of mp3 to absolute
// The first regexp deals with ../../../ urls
// Disabled by Ivan Tcholakov.
//$content = preg_replace("|(flashvars=\"file=)(\.+/)+|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/',$content);
// The second regexp deals with audio/ urls
// Disabled by Ivan Tcholakov.
//$content = preg_replace("|(flashvars=\"file=)([^/]+)/|","$1".api_get_path(REL_COURSE_PATH).$_course['path'].'/document/$2/',$content);
fputs($fp, $content); fputs($fp, $content);
fclose($fp); fclose($fp);
@ -331,15 +319,21 @@ if ($is_allowed_to_edit) {
} }
// Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/') // Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/')
$content = null;
$extension = null;
$filename = null;
if (file_exists($document_data['absolute_path'])) { if (file_exists($document_data['absolute_path'])) {
$path_info = pathinfo($document_data['absolute_path']); $path_info = pathinfo($document_data['absolute_path']);
$filename = $path_info['filename']; $filename = $path_info['filename'];
if (is_file($document_data['absolute_path'])) {
$extension = $path_info['extension']; $extension = $path_info['extension'];
if (in_array($extension, array('html', 'htm'))) { if (in_array($extension, array('html', 'htm'))) {
$content = file($document_data['absolute_path']); $content = file($document_data['absolute_path']);
$content = implode('', $content); $content = implode('', $content);
} }
}
} }
/* Display user interface */ /* Display user interface */
@ -365,7 +359,13 @@ $document_info = api_get_item_property_info(api_get_course_int_id(),'document',
$owner_id = $document_info['insert_user_id']; $owner_id = $document_info['insert_user_id'];
$last_edit_date = $document_info['lastedit_date']; $last_edit_date = $document_info['lastedit_date'];
if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_edit || GroupManager :: is_user_in_group(api_get_user_id(), api_get_group_id() )) { if ($owner_id == api_get_user_id() ||
api_is_platform_admin() ||
$is_allowed_to_edit || GroupManager:: is_user_in_group(
api_get_user_id(),
api_get_group_id()
)
) {
$action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq(); $action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq();
$form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical')); $form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical'));
@ -470,16 +470,6 @@ if ($owner_id == api_get_user_id() || api_is_platform_admin() || $is_allowed_to_
Display::display_footer(); Display::display_footer();
/* General functions */
/*
Workhorse functions
These do the actual work that is expected from of this tool, other functions
are only there to support these ones.
*/
/** /**
This function changes the name of a certain file. This function changes the name of a certain file.
It needs no global variables, it takes all info from parameters. It needs no global variables, it takes all info from parameters.

@ -1623,7 +1623,8 @@ class learnpath
'dokeos_chapter', 'dokeos_chapter',
'chapter', 'chapter',
'dir' 'dir'
))) ))
)
$total++; $total++;
} }
return $total; return $total;
@ -1638,8 +1639,6 @@ class learnpath
if ($this->debug > 0) { if ($this->debug > 0) {
error_log('New LP - In learnpath::first()', 0); error_log('New LP - In learnpath::first()', 0);
error_log('$this->last_item_seen '.$this->last_item_seen); error_log('$this->last_item_seen '.$this->last_item_seen);
//error_log('$this->items '.print_r($this->items, 1));
//error_log('$this->ordered_items '.print_r($this->ordered_items, 1));
} }
// Test if the last_item_seen exists and is not a dir. // Test if the last_item_seen exists and is not a dir.
@ -2031,22 +2030,33 @@ class learnpath
/** /**
* Gets the progress value from the progress field in the database (allows use as abstract method) * Gets the progress value from the progress field in the database (allows use as abstract method)
* @param integer Learnpath ID * @param integer $lp_id Learnpath ID
* @param integer User ID * @param integer $user_id User ID
* @param string Mode of display ('%','abs' or 'both') * @param string $mode Mode of display ('%','abs' or 'both')
* @param string Course database name (optional, defaults to '') * @param string $course_code Course code (optional, defaults to '')
* @param boolean Whether to return null if no record was found (true), or 0 (false) (optional, defaults to false) * @param boolean $sincere Whether to return null if no record
* was found (true), or 0 (false) (optional, defaults to false)
* @param int $session_id
* @return integer Current progress value as found in the database * @return integer Current progress value as found in the database
*/ */
public static function get_db_progress($lp_id, $user_id, $mode = '%', $course_code = '', $sincere = false,$session_id = 0) { public static function get_db_progress(
$lp_id,
//if ($this->debug > 0) { error_log('New LP - In learnpath::get_db_progress()', 0); } $user_id,
$mode = '%',
$course_code = '',
$sincere = false,
$session_id = 0
) {
$table = Database :: get_course_table(TABLE_LP_VIEW);
$lp_id = intval($lp_id);
$session_id = intval($session_id); $session_id = intval($session_id);
$user_id = intval($user_id);
$course_info = api_get_course_info($course_code); $course_info = api_get_course_info($course_code);
$session_condition = api_get_session_condition($session_id); $session_condition = api_get_session_condition($session_id);
$course_id = $course_info['real_id']; $course_id = $course_info['real_id'];
$table = Database :: get_course_table(TABLE_LP_VIEW);
$sql = "SELECT * FROM $table WHERE c_id = ".$course_id." AND lp_id = $lp_id AND user_id = $user_id $session_condition"; $sql = "SELECT * FROM $table
WHERE c_id = ".$course_id." AND lp_id = $lp_id AND user_id = $user_id $session_condition";
$res = Database::query($sql); $res = Database::query($sql);
$view_id = 0; $view_id = 0;
if (Database :: num_rows($res) > 0) { if (Database :: num_rows($res) > 0) {
@ -2059,7 +2069,7 @@ class learnpath
} }
} }
if (empty ($progress)) { if (empty($progress)) {
$progress = '0'; $progress = '0';
} }
@ -2069,25 +2079,29 @@ class learnpath
// Get the number of items completed and the number of items total. // Get the number of items completed and the number of items total.
$tbl = Database :: get_course_table(TABLE_LP_ITEM); $tbl = Database :: get_course_table(TABLE_LP_ITEM);
$sql = "SELECT count(*) FROM $tbl $sql = "SELECT count(*) FROM $tbl
WHERE c_id = $course_id AND c_id = ".$course_id." AND lp_id = " . $lp_id . " AND item_type NOT IN('dokeos_chapter','chapter','dir')"; WHERE
c_id = $course_id AND
c_id = ".$course_id." AND
lp_id = " . $lp_id . " AND
item_type NOT IN('dokeos_chapter','chapter','dir')";
$res = Database::query($sql); $res = Database::query($sql);
$row = Database :: fetch_array($res); $row = Database :: fetch_array($res);
$total = $row[0]; $total = $row[0];
$tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW); $tbl_item_view = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
$tbl_item = Database :: get_course_table(TABLE_LP_ITEM); $tbl_item = Database :: get_course_table(TABLE_LP_ITEM);
//$sql = "SELECT count(distinct(lp_item_id)) FROM $tbl WHERE lp_view_id = ".$view_id." AND status IN ('passed','completed','succeeded')";
// Trying as also counting browsed and failed items. // Trying as also counting browsed and failed items.
$sql = "SELECT count(distinct(lp_item_id)) $sql = "SELECT count(distinct(lp_item_id))
FROM $tbl_item_view as item_view FROM $tbl_item_view as item_view
INNER JOIN $tbl_item as item INNER JOIN $tbl_item as item
ON item.id = item_view.lp_item_id ON
AND item_type NOT IN('dokeos_chapter','chapter','dir') item.id = item_view.lp_item_id AND
item_type NOT IN('dokeos_chapter','chapter','dir')
WHERE WHERE
item_view.c_id = $course_id AND item_view.c_id = $course_id AND
item.c_id = $course_id AND item.c_id = $course_id AND
lp_view_id = " . $view_id . " AND lp_view_id = " . $view_id . " AND
status IN ('passed','completed','succeeded','browsed','failed')"; //echo '<br />'; status IN ('passed','completed','succeeded','browsed','failed')";
$res = Database::query($sql); $res = Database::query($sql);
$row = Database :: fetch_array($res); $row = Database :: fetch_array($res);
$completed = $row[0]; $completed = $row[0];
@ -2100,6 +2114,7 @@ class learnpath
return $progress . '% (' . $completed . '/' . $total . ')'; return $progress . '% (' . $completed . '/' . $total . ')';
} }
} }
return $progress; return $progress;
} }
@ -2279,21 +2294,11 @@ class learnpath
* @param boolean true if it comes from a Diplay LP view * @param boolean true if it comes from a Diplay LP view
* @return string HTML string containing the progress bar * @return string HTML string containing the progress bar
*/ */
public function get_progress_bar($mode = '', $percentage = -1, $text_add = '', $from_lp = false) { public static function get_progress_bar($percentage = -1, $text_add = '')
//if ($this->debug > 0) {error_log('New LP - In learnpath::get_progress_bar('.$mode.','.$percentage.','.$text_add.','.$from_lp.')', 0); } {
global $lp_theme_css; /*if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
// Setting up the CSS path of the current style if exists.
if (!empty ($lp_theme_css)) {
$css_path = api_get_path(WEB_CODE_PATH) . 'css/' . $lp_theme_css . '/images/';
} else {
$css_path = '../img/';
}
//if ($this->debug > 0) { error_log('New LP - In learnpath::get_progress_bar()', 0); }
if (isset($this) && is_object($this) && ($percentage == '-1' OR $text_add == '')) {
list($percentage, $text_add) = $this->get_progress_bar_text($mode); list($percentage, $text_add) = $this->get_progress_bar_text($mode);
} }*/
$text = $percentage . $text_add; $text = $percentage . $text_add;
//@todo use Display::display_progress(); //@todo use Display::display_progress();
$output = '<div class="progress progress-striped"> $output = '<div class="progress progress-striped">
@ -2305,9 +2310,21 @@ class learnpath
} }
/** /**
* Gets the progress bar info to display inside the progress bar. Also used by scorm_api.php * @param string $mode
* @param string Mode of display (can be '%' or 'abs').abs means we display a number of completed elements per total elements * @return string
* @param integer Additional steps to fake as completed */
public function getProgressBar($mode)
{
list($percentage, $text_add) = $this->get_progress_bar_text($mode);
return self::get_progress_bar($percentage, $text_add);
}
/**
* Gets the progress bar info to display inside the progress bar.
* Also used by scorm_api.php
* @param string $mode Mode of display (can be '%' or 'abs').abs means
* we display a number of completed elements per total elements
* @param integer $add Additional steps to fake as completed
* @return list Percentage or number and symbol (% or /xx) * @return list Percentage or number and symbol (% or /xx)
*/ */
public function get_progress_bar_text($mode = '', $add = 0) public function get_progress_bar_text($mode = '', $add = 0)
@ -2336,6 +2353,7 @@ class learnpath
if ($i > $total_items) { if ($i > $total_items) {
$i = $total_items; $i = $total_items;
} }
$percentage = 0;
if ($mode == '%') { if ($mode == '%') {
if ($total_items > 0) { if ($total_items > 0) {
$percentage = ((float) $i / (float) $total_items) * 100; $percentage = ((float) $i / (float) $total_items) * 100;
@ -2348,6 +2366,7 @@ class learnpath
$percentage = $i; $percentage = $i;
$text = '/' . $total_items; $text = '/' . $total_items;
} }
return array( return array(
$percentage, $percentage,
$text $text

@ -2,8 +2,8 @@
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* This file was origially the copy of document.php, but many modifications happened since then ; * This file was originally the copy of document.php, but many modifications happened since then ;
* the direct file view is not any more needed, if the user uploads a scorm zip file, a directory * the direct file view is not any more needed, if the user uploads a SCORM zip file, a directory
* will be automatically created for it, and the files will be uncompressed there for example ; * will be automatically created for it, and the files will be uncompressed there for example ;
* *
* @package chamilo.learnpath * @package chamilo.learnpath
@ -234,7 +234,16 @@ if (!empty($flat_list)) {
if ($is_allowed_to_edit) { if ($is_allowed_to_edit) {
$dsp_progress = '<td><center>'.$progress.'</center></td>'; $dsp_progress = '<td><center>'.$progress.'</center></td>';
} else { } else {
$dsp_progress = '<td>'.learnpath::get_progress_bar('%', learnpath::get_db_progress($id, $userId, '%', '', false, api_get_session_id())).'</td>'; $dsp_progress = '<td>'.learnpath::get_progress_bar(
learnpath::get_db_progress(
$id,
$userId,
'%',
'',
false,
api_get_session_id()
)
).'</td>';
} }
$dsp_edit = '<td class="td_actions">'; $dsp_edit = '<td class="td_actions">';

@ -55,7 +55,7 @@ if (isset($_SESSION['lpobject'])) {
$lp_theme_css = $my_style; $lp_theme_css = $my_style;
} }
$progress_bar = $_SESSION['oLP']->get_progress_bar('', -1, '', true); $progress_bar = $_SESSION['oLP']->getProgressBar();
$navigation_bar = $_SESSION['oLP']->get_navigation_bar(); $navigation_bar = $_SESSION['oLP']->get_navigation_bar();
$mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart); $mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart);
} }

@ -311,7 +311,7 @@ if (!empty ($lp_theme_css) && !empty ($mycourselptheme) && $mycourselptheme != -
$lp_theme_css = $my_style; $lp_theme_css = $my_style;
} }
$progress_bar = $_SESSION['oLP']->get_progress_bar('', -1, '', true); $progress_bar = $_SESSION['oLP']->getProgressBar();
$navigation_bar = $_SESSION['oLP']->get_navigation_bar(); $navigation_bar = $_SESSION['oLP']->get_navigation_bar();
$mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart); $mediaplayer = $_SESSION['oLP']->get_mediaplayer($autostart);

Loading…
Cancel
Save