@ -1,7 +1,7 @@
<?php
/* For licensing terms, see /license.txt */
use \ ChamiloSession as Session;
use ChamiloSession as Session;
/**
* Class learnpath
@ -388,7 +388,8 @@ class learnpath
Database::query($sql);
$insertId = Database::insert_id();
$sql = "UPDATE $lp_item_view_table SET id = iid WHERE iid = $insertId";
$sql = "UPDATE $lp_item_view_table SET id = iid
WHERE iid = $insertId";
Database::query($sql);
}
}
@ -748,7 +749,6 @@ class learnpath
$i++;
$name = $name . ' - ' . $i;
$check_name = "SELECT * FROM $tbl_lp WHERE c_id = $course_id AND name = '$name'";
//if ($this->debug > 2) { error_log('New LP - Checking the name for new LP: '.$check_name, 0); }
$res_name = Database::query($check_name);
}
// New name does not exist yet; keep it.
@ -972,8 +972,8 @@ class learnpath
}
$this->current_time_stop = time();
if ($this->save) {
$learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
/*
$learnpath_view_table = Database :: get_course_table(TABLE_LP_VIEW);
$sql = "UPDATE $learnpath_view_table " .
"SET " .
"stop_time = ".$this->current_time_stop.", " .
@ -1307,14 +1307,14 @@ class learnpath
// TODO: htmlspecialchars to be checked for encoding related problems.
if ($same_parent & & $same_previous) {
// Only update title and description.
$sql_update = " UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET title = '" . Database::escape_string($title) . "',
prerequisite = '" . $prerequisites . "',
description = '" . Database::escape_string($description) . "'
" . $audio_update_sql . ",
max_time_allowed = '" . Database::escape_string($max_time_allowed) . "'
WHERE c_id = ".$course_id." AND id = " . $id;
Database::query($sql_update );
Database::query($sql);
} else {
$old_parent = $row_select['parent_item_id'];
$old_previous = $row_select['previous_item_id'];
@ -1327,49 +1327,46 @@ class learnpath
/* for the next and previous item it is like the current item doesn't exist anymore */
if ($old_previous != 0) {
$sql_update_next = "
UPDATE " . $tbl_lp_item . "
// Next
$sql = " UPDATE " . $tbl_lp_item . "
SET next_item_id = " . $old_next . "
WHERE c_id = ".$course_id." AND id = " . $old_previous;
Database::query($sql_update_next);
//echo '< p > ' . $sql_update_next . '< / p > ';
Database::query($sql);
}
if ($old_next != 0) {
$sql_update_previous = "
UPDATE " . $tbl_lp_item . "
// Previous
$sql = " UPDATE " . $tbl_lp_item . "
SET previous_item_id = " . $old_previous . "
WHERE c_id = ".$course_id." AND id = " . $old_next;
Database::query($sql_update_previous );
Database::query($sql);
}
// display_order - 1 for every item with a display_order bigger then the display_order of the current item.
$sql_update_order = "
UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET display_order = display_order - 1
WHERE
c_id = ".$course_id." AND
display_order > " . $old_order . " AND lp_id = " . $this->lp_id . " AND
display_order > " . $old_order . " AND
lp_id = " . $this->lp_id . " AND
parent_item_id = " . $old_parent;
Database::query($sql_update_order );
Database::query($sql);
/* END -- virtually remove the current item id */
/* BEGIN -- update the current item id to his new location */
if ($previous == 0) {
// Select the data of the item that should come after the current item.
$sql_select_old = "SELECT id, display_order
$sql = "SELECT id, display_order
FROM " . $tbl_lp_item . "
WHERE
c_id = ".$course_id." AND
lp_id = " . $this->lp_id . " AND
parent_item_id = " . $parent . " AND
previous_item_id = " . $previous;
$res_select_old = Database::query($sql_select_old );
$res_select_old = Database::query($sql);
$row_select_old = Database::fetch_array($res_select_old);
//echo '< p > ' . $sql_select_old . '< / p > ';
// If the new parent didn't have children before.
if (Database :: num_rows($res_select_old) == 0) {
$new_next = 0;
@ -1380,10 +1377,10 @@ class learnpath
}
} else {
// Select the data of the item that should come before the current item.
$sql_select_old = " SELECT next_item_id, display_order
$sql = "SELECT next_item_id, display_order
FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND id = " . $previous;
$res_select_old = Database::query($sql_select_old );
$res_select_old = Database::query($sql);
$row_select_old = Database :: fetch_array($res_select_old);
$new_next = $row_select_old['next_item_id'];
$new_order = $row_select_old['display_order'] + 1;
@ -1391,7 +1388,7 @@ class learnpath
// TODO: htmlspecialchars to be checked for encoding related problems.
// Update the current item with the new data.
$sql_update = "UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET
title = '" . Database::escape_string($title) . "',
description = '" . Database::escape_string($description) . "',
@ -1401,45 +1398,41 @@ class learnpath
display_order = " . $new_order . "
" . $audio_update_sql . "
WHERE c_id = ".$course_id." AND id = " . $id;
Database::query($sql_update );
Database::query($sql);
if ($previous != 0) {
// Update the previous item's next_item_id.
$sql_update_previous = "
UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET next_item_id = " . $id . "
WHERE c_id = ".$course_id." AND id = " . $previous;
Database::query($sql_update_previous );
Database::query($sql);
}
if ($new_next != 0) {
// Update the next item's previous_item_id.
$sql_update_next = "
UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET previous_item_id = " . $id . "
WHERE c_id = ".$course_id." AND id = " . $new_next;
Database::query($sql_update_next );
Database::query($sql);
}
if ($old_prerequisite != $prerequisites) {
$sql_update_next = "
UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET prerequisite = " . $prerequisites . "
WHERE c_id = ".$course_id." AND id = " . $id;
Database::query($sql_update_next );
Database::query($sql);
}
if ($old_max_time_allowed != $max_time_allowed) {
$sql_update_max_time_allowed = "
UPDATE " . $tbl_lp_item . "
// update max time allowed
$sql = " UPDATE " . $tbl_lp_item . "
SET max_time_allowed = " . $max_time_allowed . "
WHERE c_id = ".$course_id." AND id = " . $id;
Database::query($sql_update_max_time_allowed );
Database::query($sql);
}
// Update all the items with the same or a bigger display_order than the current item.
$sql_update_order = "
UPDATE " . $tbl_lp_item . "
$sql = "UPDATE " . $tbl_lp_item . "
SET display_order = display_order + 1
WHERE
c_id = ".$course_id." AND
@ -1448,7 +1441,7 @@ class learnpath
parent_item_id = " . $parent . " AND
display_order >= " . $new_order;
Database::query($sql_update_order );
Database::query($sql);
}
if ($row_select['item_type'] == 'link') {
@ -2234,7 +2227,7 @@ class learnpath
WHERE
item_view.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')";
$res = Database::query($sql);
$row = Database :: fetch_array($res);
@ -2265,7 +2258,8 @@ class learnpath
// Getting all the information about the item.
$sql = "SELECT * FROM ".$tbl_lp_item." as lp
INNER JOIN ".$tbl_lp_item_view." as lp_view on lp.id = lp_view.lp_item_id
INNER JOIN ".$tbl_lp_item_view." as lp_view
ON lp.id = lp_view.lp_item_id
WHERE
lp.id = '".$_SESSION['oLP']->current."' AND
lp.c_id = $course_id AND
@ -2323,6 +2317,7 @@ class learnpath
$output .= $player;
$output .= '< / div > ';
}
return $output;
}
@ -2668,6 +2663,7 @@ class learnpath
return '';
}
}
/**
* Gets the learnpath author
* @return string LP's author
@ -2757,7 +2753,8 @@ class learnpath
$prereq = preg_replace('/[^a-zA-Z_0-9](' . $id . ')[^a-zA-Z_0-9]/', 'ITEM_' . $this->refs_list[$id], $prereq);
}
}
error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
//error_log('New LP - In learnpath::get_scorm_prereq_string(): returning modified string: ' . $prereq, 0);
return $prereq;
}
}
@ -2957,7 +2954,8 @@ class learnpath
$table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
$course_id = intval($course_id);
$lp_iv_id = intval($lp_iv_id);
$sql = "SELECT count(*) FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
$sql = "SELECT count(*) FROM $table
WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id";
//@todo seems that this always returns 0
$res = Database::query($sql);
$num = 0;
@ -2965,6 +2963,7 @@ class learnpath
$row = Database :: fetch_array($res);
$num = $row[0];
}
return $num;
}
@ -2979,7 +2978,9 @@ class learnpath
{
$course_id = api_get_course_int_id();
$table = Database :: get_course_table(TABLE_LP_IV_OBJECTIVE);
$sql = "SELECT * FROM $table WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id ORDER BY order_id ASC";
$sql = "SELECT * FROM $table
WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id
ORDER BY order_id ASC";
$res = Database::query($sql);
$num = Database :: num_rows($res);
$list = array();
@ -3050,7 +3051,6 @@ class learnpath
error_log('New LP - In learnpath::get_items_details_as_js()', 0);
}
$toc = $varname.' = new Array();';
//echo "< pre > ".print_r($this->items,true)."< / pre > ";
foreach ($this->ordered_items as $item_id) {
$toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';";
}
@ -3094,7 +3094,8 @@ class learnpath
$course_id = api_get_course_int_id();
$tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = intval($lp_id);
$sql = "SELECT lp_type FROM $tbl_lp WHERE c_id = $course_id AND id = '" . $lp_id . "'";
$sql = "SELECT lp_type FROM $tbl_lp
WHERE c_id = $course_id AND id = '" . $lp_id . "'";
$res = Database::query($sql);
if ($res === false) {
return null;
@ -3854,7 +3855,6 @@ class learnpath
$display = $display -1;
}
break;
case 'down':
if ($this->debug > 2) {
error_log('Movement down detected', 0);
@ -3965,7 +3965,9 @@ class learnpath
{
$course_id = api_get_course_int_id();
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." ORDER BY display_order";
$sql = "SELECT * FROM $lp_table
WHERE c_id = ".$course_id."
ORDER BY display_order";
$res = Database::query($sql);
if ($res === false)
return false;
@ -4170,7 +4172,8 @@ class learnpath
$course_id = api_get_course_int_id();
$tbl_lp = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = intval($lp_id);
$sql = "SELECT * FROM $tbl_lp where c_id = ".$course_id." AND id=$lp_id";
$sql = "SELECT * FROM $tbl_lp
WHERE c_id = ".$course_id." AND id = $lp_id";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$row = Database :: fetch_array($result);
@ -4271,10 +4274,11 @@ class learnpath
$res = Database::query($sql);
$view_id = Database::insert_id();
if ($view_id) {
$sql = "UPDATE $lp_view_table SET id = iid WHERE iid = $view_id";
Database::query($sql);
if ($view_id) {
$this->lp_view_id = $view_id;
$this->attempt = $this->attempt + 1;
} else {
@ -4525,7 +4529,8 @@ class learnpath
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$course_id = api_get_course_int_id();
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET content_maker = '" . Database::escape_string($this->maker) . "'
$sql = "UPDATE $lp_table SET
content_maker = '" . Database::escape_string($this->maker) . "'
WHERE c_id = ".$course_id." AND id = '$lp_id'";
if ($this->debug > 2) {
error_log('New LP - lp updated with new content_maker : ' . $this->maker, 0);
@ -4551,7 +4556,8 @@ class learnpath
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$course_id = api_get_course_int_id();
$sql = "UPDATE $lp_table SET name = '" . Database::escape_string($this->name). "'
$sql = "UPDATE $lp_table SET
name = '" . Database::escape_string($this->name). "'
WHERE c_id = ".$course_id." AND id = '$lp_id'";
if ($this->debug > 2) {
error_log('New LP - lp updated with new name : ' . $this->name, 0);
@ -4564,7 +4570,9 @@ class learnpath
$tbl_tool = Database :: get_course_table(TABLE_TOOL_LIST);
$link = 'newscorm/lp_controller.php?action=view& lp_id=' . $lp_id.'&id_session='.$session_id;
$sql = "UPDATE $tbl_tool SET name = '$this->name'
WHERE c_id = ".$course_id." AND (link='$link' and image='scormbuilder.gif' $session_condition)";
WHERE
c_id = $course_id AND
(link='$link' AND image='scormbuilder.gif' $session_condition)";
Database::query($sql);
return true;
} else {
@ -4613,7 +4621,9 @@ class learnpath
while ($lp_item = Database :: fetch_array($result)) {
// Get search_did.
$tbl_se_ref = Database :: get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
$sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d LIMIT 1';
$sql = 'SELECT * FROM %s
WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%d
LIMIT 1';
$sql = sprintf($sql, $tbl_se_ref, $this->cc, TOOL_LEARNPATH, $lp_id, $lp_item['id']);
//echo $sql; echo '< br > ';
@ -4670,6 +4680,7 @@ class learnpath
error_log('New LP - lp updated with new theme : ' . $this->theme, 0);
}
Database::query($sql);
return true;
}
@ -4703,7 +4714,8 @@ class learnpath
* @param string Optional string giving the new author of this learnpath
* @return bool Returns true if author's name is not empty
*/
public function set_author($name = '') {
public function set_author($name = '')
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_author()', 0);
@ -4717,6 +4729,7 @@ class learnpath
error_log('New LP - lp updated with new preview author : ' . $this->author, 0);
}
Database::query($sql);
return true;
}
@ -4735,12 +4748,14 @@ class learnpath
$this->hide_toc_frame = $hide;
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$lp_id = $this->get_id();
$sql = "UPDATE $lp_table SET hide_toc_frame = '" . $this->hide_toc_frame . "'
$sql = "UPDATE $lp_table SET
hide_toc_frame = '" . $this->hide_toc_frame . "'
WHERE c_id = ".$course_id." AND id = '$lp_id'";
if ($this->debug > 2) {
error_log('New LP - lp updated with new preview hide_toc_frame : ' . $this->author, 0);
}
Database::query($sql);
return true;
} else {
return false;
@ -4832,6 +4847,7 @@ class learnpath
error_log('New LP - lp updated with new use_max_score : ' . $this->use_max_score, 0);
}
Database::query($sql);
return true;
}
@ -4861,6 +4877,7 @@ class learnpath
error_log('New LP - lp updated with new expired_on : ' . $this->expired_on, 0);
}
Database::query($sql);
return true;
}
@ -4889,6 +4906,7 @@ class learnpath
error_log('New LP - lp updated with new publicated_on : ' . $this->publicated_on, 0);
}
Database::query($sql);
return true;
}
@ -5099,6 +5117,7 @@ class learnpath
WHERE c_id = ".$course_id." AND id = " . $this->get_id();
Database::query($sql);
$this->force_commit = $force_return;
return $force_return;
} else {
if ($this->debug > 2) {
@ -5130,9 +5149,9 @@ class learnpath
while ($row = Database :: fetch_array($res)) {
if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
$need_fix = true;
$sql_u = "UPDATE $lp_table SET display_order = $i
$sql = "UPDATE $lp_table SET display_order = $i
WHERE c_id = ".$course_id." AND id = " . $row['id'];
Database::query($sql_u );
Database::query($sql);
}
$i++;
}
@ -5209,7 +5228,8 @@ class learnpath
* @return boolean
* @author ndiechburg < noel @ cblue . be >
**/
public function set_attempt_mode($mode) {
public function set_attempt_mode($mode)
{
$course_id = api_get_course_int_id();
switch ($mode) {
case 'seriousgame' :
@ -5232,7 +5252,9 @@ class learnpath
$this->prevent_reinit = $prevent_reinit;
$this->seriousgame_mode = $sg_mode;
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$sql = "UPDATE $lp_table SET prevent_reinit = $prevent_reinit , seriousgame_mode = $sg_mode
$sql = "UPDATE $lp_table SET
prevent_reinit = $prevent_reinit ,
seriousgame_mode = $sg_mode
WHERE c_id = ".$course_id." AND id = " . $this->get_id();
$res = Database::query($sql);
if ($res) {
@ -5248,7 +5270,8 @@ class learnpath
* @return boolean
* @author ndiechburg < noel @ cblue . be >
**/
public function switch_attempt_mode() {
public function switch_attempt_mode()
{
if ($this->debug > 0) {
error_log('New LP - In learnpath::switch_attempt_mode()', 0);
}
@ -5275,9 +5298,11 @@ class learnpath
* but possibility to do again a completed item.
*
* @return boolean true if seriousgame_mode has been set to 1, false otherwise
* @deprecated seems not to be used
* @author ndiechburg < noel @ cblue . be >
**/
public function set_seriousgame_mode() {
public function set_seriousgame_mode()
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
@ -5317,7 +5342,8 @@ class learnpath
error_log('New LP - In learnpath::update_scorm_debug()', 0);
}
$lp_table = Database :: get_course_table(TABLE_LP_MAIN);
$sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
$sql = "SELECT * FROM $lp_table
WHERE c_id = ".$course_id." AND id = " . $this->get_id();
$res = Database::query($sql);
if (Database :: num_rows($res) > 0) {
$row = Database :: fetch_array($res);
@ -5327,7 +5353,8 @@ class learnpath
} elseif ($force == 0) {
$force = 1;
}
$sql = "UPDATE $lp_table SET debug = $force WHERE c_id = ".$course_id." AND id = " . $this->get_id();
$sql = "UPDATE $lp_table SET debug = $force
WHERE c_id = ".$course_id." AND id = " . $this->get_id();
$res = Database::query($sql);
$this->scorm_debug = $force;
return $force;
@ -5745,6 +5772,7 @@ class learnpath
$return .= Display::tag('li', Display::div($item['data'], array('class'=>'item_data')).$sub_list, array('id'=>$key, 'class'=>'record li_container'));
}
}
return $return;
}
@ -5870,7 +5898,8 @@ class learnpath
* @param array $course
* @return bool
*/
public static function generate_learning_path_folder($course) {
public static function generate_learning_path_folder($course)
{
// Creating learning_path folder
$dir = '/learning_path';
$filepath = api_get_path(SYS_COURSE_PATH).$course['path'] . '/document';
@ -5952,7 +5981,8 @@ class learnpath
* @param array $_course
* @return string
*/
public function create_document($_course) {
public function create_document($_course)
{
$course_id = api_get_course_int_id();
global $charset;
$dir = isset ($_GET['dir']) ? $_GET['dir'] : $_POST['dir']; // Please, do not modify this dirname formatting.
@ -6184,6 +6214,7 @@ class learnpath
$return .= '< / div > ';
}
}
return $return;
}
@ -6217,14 +6248,15 @@ class learnpath
break;
case TOOL_DOCUMENT :
$tbl_doc = Database :: get_course_table(TABLE_DOCUMENT);
$sql_step = " SELECT lp.*, doc.path as dir
$sql = "SELECT lp.*, doc.path as dir
FROM " . $tbl_lp_item . " as lp
LEFT JOIN " . $tbl_doc . " as doc ON doc.id = lp.path
LEFT JOIN " . $tbl_doc . " as doc
ON doc.id = lp.path
WHERE
lp.c_id = $course_id AND
doc.c_id = $course_id AND
lp.id = " . intval($item_id);
$res_step = Database::query($sql_step );
$res_step = Database::query($sql);
$row_step = Database :: fetch_array($res_step);
$return .= $this->display_manipulate($item_id, $row['item_type']);
$return .= $this->display_document_form('edit', $item_id, $row_step);
@ -6274,6 +6306,7 @@ class learnpath
break;
}
}
return $return;
}
@ -6309,12 +6342,14 @@ class learnpath
Display::return_icon('forum.png', get_lang('Forums'), array(), ICON_SIZE_BIG),
Display::return_icon('add_learnpath_section.png', get_lang('NewChapter'), array(), ICON_SIZE_BIG)
);
echo Display::display_normal_message(get_lang('ClickOnTheLearnerViewToSeeYourLearningPath'));
$chapter = $_SESSION['oLP']->display_item_form('chapter', get_lang('EnterDataNewChapter'), 'add_item');
echo Display::tabs(
$headers,
array($documents, $exercises, $links, $works, $forums, $chapter), 'resource_tab'
);
return true;
}
@ -6373,9 +6408,11 @@ class learnpath
$item_title = $extra_info['title'];
$item_description = $extra_info['description'];
} elseif (is_numeric($extra_info)) {
$sql_quiz = "SELECT title, description FROM " . $tbl_quiz . " WHERE c_id = ".$course_id." AND id = " . $extra_info;
$sql = "SELECT title, description
FROM " . $tbl_quiz . "
WHERE c_id = ".$course_id." AND id = " . $extra_info;
$result = Database::query($sql_quiz);
$result = Database::query($sql);
$row = Database::fetch_array($result);
$item_title = $row['title'];
$item_description = $row['description'];
@ -6392,7 +6429,8 @@ class learnpath
else
$parent = 0;
$sql = "SELECT * FROM " . $tbl_lp_item . " WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
$sql = "SELECT * FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
$result = Database::query($sql);
$arrLP = array ();
@ -6459,7 +6497,6 @@ class learnpath
$arrHide = array (
$id
);
//$parent_item_id = $_SESSION['parent_item_id'];
for ($i = 0; $i < count ( $ arrLP ) ; $ i + + ) {
if ($action != 'add') {
if (($arrLP[$i]['item_type'] == 'dokeos_module' || $arrLP[$i]['item_type'] == 'dokeos_chapter' || $arrLP[$i]['item_type'] == 'dir') & & !in_array($arrLP[$i]['id'], $arrHide) & & !in_array($arrLP[$i]['parent_item_id'], $arrHide)) {
@ -6576,6 +6613,7 @@ class learnpath
$return .= '< / form > ';
$return .= '< / div > ';
return $return;
}
@ -6586,7 +6624,8 @@ class learnpath
* @param mixed Extra information - can be an array with title and description indexes
* @return string HTML structure to display the hotpotatoes addition formular
*/
public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '') {
public function display_hotpotatoes_form($action = 'add', $id = 0, $extra_info = '')
{
$course_id = api_get_course_int_id();
global $charset;
$uploadPath = DIR_HOTPOTATOES; //defined in main_api
@ -6598,14 +6637,14 @@ class learnpath
} elseif (is_numeric($extra_info)) {
$TBL_DOCUMENT = Database :: get_course_table(TABLE_DOCUMENT);
$sql_hot = "SELECT * FROM " . $TBL_DOCUMENT . "
WHERE c_id = ".$course_id." AND
$sql = "SELECT * FROM " . $TBL_DOCUMENT . "
WHERE
c_id = ".$course_id." AND
path LIKE '" . $uploadPath . "/%/%htm%' AND
id = " . (int) $extra_info . "
ORDER BY id ASC";
$res_hot = Database::query($sql_hot);
$res_hot = Database::query($sql);
$row = Database::fetch_array($res_hot);
$item_title = $row['title'];
@ -6619,10 +6658,11 @@ class learnpath
$item_description = '';
}
if ($id != 0 & & is_array($extra_info))
if ($id != 0 & & is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
else
} else {
$parent = 0;
}
$sql = "SELECT * FROM $tbl_lp_item
WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
@ -6757,6 +6797,7 @@ class learnpath
$return .= '< input name = "type" type = "hidden" value = "' . TOOL_HOTPOTATOES . '" / > ';
$return .= '< input name = "post_time" type = "hidden" value = "' . time() . '" / > ';
$return .= '< / form > ';
return $return;
}
@ -6776,11 +6817,11 @@ class learnpath
if ($id != 0 & & is_array($extra_info)) {
$item_title = stripslashes($extra_info['title']);
} elseif (is_numeric($extra_info)) {
$sql_forum = "SELECT forum_title as title, forum_comment as comment
$sql = "SELECT forum_title as title, forum_comment as comment
FROM " . $tbl_forum . "
WHERE c_id = ".$course_id." AND forum_id = " . $extra_info;
$result = Database::query($sql_forum );
$result = Database::query($sql);
$row = Database :: fetch_array($result);
$item_title = $row['title'];
@ -6792,13 +6833,15 @@ class learnpath
$legend = '< legend > ';
if ($id != 0 & & is_array($extra_info))
if ($id != 0 & & is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
else
} else {
$parent = 0;
}
$sql = "SELECT * FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND
WHERE
c_id = ".$course_id." AND
lp_id = " . $this->lp_id;
$result = Database::query($sql);
$arrLP = array();
@ -6870,13 +6913,13 @@ class learnpath
reset($arrLP);
}
$return .= "\t\t\t\t" . ' < / select > ';
$return .= ' < / select > ';
$return .= '< / td > ';
$return .= '< / tr > ';
$return .= '< tr > ';
$return .= '< td class = "label" > < label for = "previous" > ' . get_lang('Position') . '< / label > < / td > ';
$return .= '< td class = "input" > ';
$return .= "\t\t\t\t" . ' < select id = "previous" name = "previous" style = "width:100%;" size = "1" class = "learnpath_item_form" > ';
$return .= ' < select id = "previous" name = "previous" style = "width:100%;" size = "1" class = "learnpath_item_form" > ';
$return .= '< option class = "top" value = "0" > ' . get_lang('FirstPosition') . '< / option > ';
for ($i = 0; $i < count ( $ arrLP ) ; $ i + + ) {
@ -6887,11 +6930,12 @@ class learnpath
else
$selected = '';
$return .= '< option ' . $ selected . ' value = "' . $arrLP[$i]['id'] . '" > ' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"< / option > ';
$return .= '< option ' . $ selected . ' value = "' . $arrLP[$i]['id'] . '" > ' .
get_lang('After') . ' "' . $arrLP[$i]['title'] . '"< / option > ';
}
}
$return .= "\t\t\t\t" . ' < / select > ';
$return .= ' < / select > ';
$return .= '< / td > ';
$return .= '< / tr > ';
if ($action != 'move') {
@ -6935,14 +6979,14 @@ class learnpath
if (is_numeric($extra_info)) {
$return .= '< input name = "path" type = "hidden" value = "' . $extra_info . '" / > ';
}
elseif (is_array($extra_info)) {
} elseif (is_array($extra_info)) {
$return .= '< input name = "path" type = "hidden" value = "' . $extra_info['path'] . '" / > ';
}
$return .= '< input name = "type" type = "hidden" value = "' . TOOL_FORUM . '" / > ';
$return .= '< input name = "post_time" type = "hidden" value = "' . time() . '" / > ';
$return .= '< / form > ';
$return .= '< / div > ';
return $return;
}
@ -6965,10 +7009,10 @@ class learnpath
if ($id != 0 & & is_array($extra_info)) {
$item_title = stripslashes($extra_info['title']);
} elseif (is_numeric($extra_info)) {
$sql_forum = "SELECT thread_title as title FROM $tbl_forum
$sql = "SELECT thread_title as title FROM $tbl_forum
WHERE c_id = $course_id AND thread_id = " . $extra_info;
$result = Database::query($sql_forum );
$result = Database::query($sql);
$row = Database :: fetch_array($result);
$item_title = $row['title'];
@ -6980,10 +7024,11 @@ class learnpath
$return = null;
if ($id != 0 & & is_array($extra_info))
if ($id != 0 & & is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
else
} else {
$parent = 0;
}
$sql = "SELECT * FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
@ -7043,6 +7088,7 @@ class learnpath
$return .= '< option ' . ( ( $ parent = = $ arrLP [ $ i ] [ ' id ' ] ) ? ' selected = "selected" ' : ' ' ) . ' style = "padding-left:' . ($arrLP[$i]['depth'] * 10) . 'px;" value = "' . $arrLP[$i]['id'] . '" > ' . $arrLP[$i]['title'] . '< / option > ';
}
}
if ($arrLP != null) {
reset($arrLP);
}
@ -7066,7 +7112,7 @@ class learnpath
$return .= '< option ' . $ selected . ' value = "' . $arrLP[$i]['id'] . '" > ' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"< / option > ';
}
}
$return .= "\t\t\t\t" . ' < / select > ';
$return .= ' < / select > ';
$return .= '< / td > ';
$return .= '< / tr > ';
if ($action != 'move') {
@ -7138,6 +7184,7 @@ class learnpath
$return .= '< input name = "post_time" type = "hidden" value = "' . time() . '" / > ';
$return .= '< / form > ';
$return .= '< / div > ';
return $return;
}
@ -7153,7 +7200,8 @@ class learnpath
public function display_item_form($item_type, $title = '', $action = 'add_item', $id = 0, $extra_info = 'new')
{
$course_id = api_get_course_int_id();
global $_course;
$_course = api_get_course_info();
global $charset;
$tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
@ -7169,14 +7217,18 @@ class learnpath
$item_path_fck = '';
}
if ($id != 0 & & is_array($extra_info))
if ($id != 0 & & is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
else
} else {
$parent = 0;
}
$id = intval($id);
$sql = "SELECT * FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id . " AND id != $id";
WHERE
c_id = ".$course_id." AND
lp_id = " . $this->lp_id . " AND
id != $id";
if ($item_type == 'module')
$sql .= " AND parent_item_id = 0";
@ -7416,13 +7468,15 @@ class learnpath
}
$return = '< legend > ';
if ($id != 0 & & is_array($extra_info))
if ($id != 0 & & is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
else
} else {
$parent = 0;
}
$sql = "SELECT * FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
$result = Database::query($sql);
$arrLP = array ();
while ($row = Database :: fetch_array($result)) {
@ -7689,9 +7743,9 @@ class learnpath
$item_url = stripslashes($extra_info['url']);
} elseif (is_numeric($extra_info)) {
$extra_info = intval($extra_info);
$sql_link = "SELECT title, description, url FROM " . $tbl_link . "
$sql = "SELECT title, description, url FROM " . $tbl_link . "
WHERE c_id = ".$course_id." AND id = " . $extra_info;
$result = Database::query($sql_link );
$result = Database::query($sql);
$row = Database :: fetch_array($result);
$item_title = $row['title'];
$item_description = $row['description'];
@ -7861,6 +7915,7 @@ class learnpath
$return .= '< input name = "post_time" type = "hidden" value = "' . time() . '" / > ';
$return .= '< / form > ';
$return .= '< / div > ';
return $return;
}
@ -7882,10 +7937,11 @@ class learnpath
$item_description = stripslashes($extra_info['description']);
} elseif (is_numeric($extra_info)) {
$extra_info = intval($extra_info);
$sql_publication = "SELECT title, description FROM " . $tbl_publication . "
$sql = "SELECT title, description
FROM " . $tbl_publication . "
WHERE c_id = ".$course_id." AND id = " . $extra_info;
$result = Database::query($sql_publication );
$result = Database::query($sql);
$row = Database :: fetch_array($result);
$item_title = $row['title'];
@ -7895,10 +7951,11 @@ class learnpath
$legend = '< legend > ';
if ($id != 0 & & is_array($extra_info))
if ($id != 0 & & is_array($extra_info)) {
$parent = $extra_info['parent_item_id'];
else
} else {
$parent = 0;
}
$sql = "SELECT * FROM " . $tbl_lp_item . "
WHERE c_id = ".$course_id." AND lp_id = " . $this->lp_id;
@ -7972,13 +8029,13 @@ class learnpath
if (is_array($arrLP)) {
reset($arrLP);
}
$return .= "\t\t\t\t" . ' < / select > ';
$return .= ' < / select > ';
$return .= '< / td > ';
$return .= '< / tr > ';
$return .= '< tr > ';
$return .= '< td class = "label" > < label for = "previous" > ' . get_lang('Position') . '< / label > < / td > ';
$return .= '< td class = "input" > ';
$return .= "\t\t\t\t" . ' < select id = "previous" name = "previous" style = "width:100%;" size = "1" class = "learnpath_item_form" > ';
$return .= ' < select id = "previous" name = "previous" style = "width:100%;" size = "1" class = "learnpath_item_form" > ';
$return .= '< option class = "top" value = "0" > ' . get_lang('FirstPosition') . '< / option > ';
for ($i = 0; $i < count ( $ arrLP ) ; $ i + + ) {
if ($arrLP[$i]['parent_item_id'] == $parent & & $arrLP[$i]['id'] != $id) {
@ -7991,7 +8048,7 @@ class learnpath
$return .= '< option ' . $ selected . ' value = "' . $arrLP[$i]['id'] . '" > ' . get_lang('After') . ' "' . $arrLP[$i]['title'] . '"< / option > ';
}
}
$return .= "\t\t\t\t" . ' < / select > ';
$return .= ' < / select > ';
$return .= '< / td > ';
$return .= '< / tr > ';
if ($action != 'move') {
@ -8061,6 +8118,7 @@ class learnpath
$return .= '< input name = "post_time" type = "hidden" value = "' . time() . '" / > ';
$return .= '< / form > ';
$return .= '< / div > ';
return $return;
}
@ -8226,6 +8284,7 @@ class learnpath
}
$return .= "\n";
}
return $return;
}
@ -8237,7 +8296,7 @@ class learnpath
public function display_move_item($item_id)
{
$course_id = api_get_course_int_id();
global $_course; //will disappear
$_course = api_get_course_info();
global $charset;
$return = '';
@ -8521,7 +8580,8 @@ class learnpath
* Creates a list with all the exercises (quiz) in it
* @return string
*/
public function get_exercises() {
public function get_exercises()
{
$course_id = api_get_course_int_id();
// New for hotpotatoes.
@ -9665,6 +9725,7 @@ EOD;
$result = $pdf->html_to_pdf($files_to_export, $this->name, $this->cc, true);
return $result;
}
return false;
}
@ -9777,6 +9838,7 @@ EOD;
}
}
}
return false;
}
@ -9808,7 +9870,7 @@ EOD;
* @author Isaac flores paz
* @return integer Previous item ID
*/
function select_previous_item_id()
public function select_previous_item_id()
{
$course_id = api_get_course_int_id();
if ($this->debug > 0) {
@ -9861,7 +9923,7 @@ EOD;
$course_restorer->restore(api_get_course_id(), api_get_session_id(), false, false);
}
function verify_document_size($s)
public function verify_document_size($s)
{
$post_max = ini_get('post_max_size');
$upl_max = ini_get('upload_max_filesize');
@ -9878,7 +9940,7 @@ EOD;
/**
* Clear LP prerequisites
*/
function clear_prerequisites()
public function clear_prerequisites()
{
$course_id = $this->get_course_int_id();
if ($this->debug > 0) {
@ -9897,7 +9959,7 @@ EOD;
Database::query($sql);
}
function set_previous_step_as_prerequisite_for_all_items()
public function set_previous_step_as_prerequisite_for_all_items()
{
$tbl_lp_item = Database :: get_course_table(TABLE_LP_ITEM);
$course_id = $this->get_course_int_id();
@ -9918,11 +9980,13 @@ EOD;
// Current item is not a folder, so it qualifies to get a prerequisites
if ($last_item_not_chapter_type == 'quiz') {
// if previous is quiz, mark its max score as default score to be achieved
$sql = "UPDATE $tbl_lp_item SET mastery_score = '$last_item_not_chapter_max' WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND id = '$last_item_not_chapter'";
$sql = "UPDATE $tbl_lp_item SET mastery_score = '$last_item_not_chapter_max'
WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND id = '$last_item_not_chapter'";
Database::query($sql);
}
// now simply update the prerequisite to set it to the last non-chapter item
$sql = "UPDATE $tbl_lp_item SET prerequisite = '$last_item_not_chapter' WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND id = '$current_item_id'";
$sql = "UPDATE $tbl_lp_item SET prerequisite = '$last_item_not_chapter'
WHERE c_id = ".$course_id." AND lp_id = '$lp_id' AND id = '$current_item_id'";
Database::query($sql);
// record item as 'non-chapter' reference
$last_item_not_chapter = $item->get_id();