Fix queries.

1.10.x
Julio Montoya 10 years ago
parent de374ceb99
commit 81cfe89573
  1. 71
      main/inc/lib/api.lib.php
  2. 170
      main/inc/lib/course_description.lib.php
  3. 19
      main/inc/lib/glossary.lib.php

@ -3614,8 +3614,8 @@ function api_item_property_update(
$to_user_id = intval($to_user_id);
$start_visible = Database::escape_string($start_visible);
$end_visible = Database::escape_string($end_visible);
$start_visible = ($start_visible == 0) ? '0000-00-00 00:00:00' : $start_visible;
$end_visible = ($end_visible == 0) ? '0000-00-00 00:00:00' : $end_visible;
$start_visible = $start_visible == 0 ? '0000-00-00 00:00:00' : $start_visible;
$end_visible = $end_visible == 0 ? '0000-00-00 00:00:00' : $end_visible;
$to_filter = '';
$time = api_get_utc_datetime();
@ -3696,9 +3696,15 @@ function api_item_property_update(
visibility = '$visibility',
session_id = '$session_id' $set_type
WHERE $filter";
$result = Database::query($sql);
} else {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool','$item_id','$time', '$user_id', '$time', '$lastedit_type','$user_id', '$to_value', '$visibility', '$start_visible','$end_visible', '$session_id')";
$result = Database::query($sql);
$id = Database::insert_id();
$sql = "UPDATE $TABLE_ITEMPROPERTY SET id = $id WHERE iid = $id";
Database::query($sql);
}
} else {
$sql = "UPDATE $TABLE_ITEMPROPERTY
@ -3708,6 +3714,7 @@ function api_item_property_update(
lastedit_user_id = '$user_id',
visibility='$visibility' $set_type
WHERE $filter";
$result = Database::query($sql);
}
break;
case 'visible' : // Change item to visible.
@ -3733,6 +3740,11 @@ function api_item_property_update(
} else {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_value', '$visibility', '$start_visible', '$end_visible', '$session_id')";
$result = Database::query($sql);
$id = Database::insert_id();
$sql = "UPDATE $TABLE_ITEMPROPERTY SET id = $id WHERE iid = $id";
Database::query($sql);
}
} else {
$sql = "UPDATE $TABLE_ITEMPROPERTY
@ -3742,6 +3754,7 @@ function api_item_property_update(
lastedit_user_id='$user_id',
visibility='$visibility' $set_type
WHERE $filter";
$result = Database::query($sql);
}
break;
case 'invisible' : // Change item to invisible.
@ -3764,9 +3777,15 @@ function api_item_property_update(
visibility = '$visibility',
session_id = '$session_id' $set_type
WHERE $filter";
$result = Database::query($sql);
} else {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool, ref, insert_date, insert_user_id, lastedit_date, lastedit_type, lastedit_user_id,$to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_value', '$visibility', '$start_visible', '$end_visible', '$session_id')";
$result = Database::query($sql);
$id = Database::insert_id();
$sql = "UPDATE $TABLE_ITEMPROPERTY SET id = $id WHERE iid = $id";
Database::query($sql);
}
} else {
$sql = "UPDATE $TABLE_ITEMPROPERTY
@ -3776,6 +3795,7 @@ function api_item_property_update(
lastedit_user_id = '$user_id',
visibility = '$visibility' $set_type
WHERE $filter";
$result = Database::query($sql);
}
break;
default : // The item will be added or updated.
@ -3787,14 +3807,18 @@ function api_item_property_update(
lastedit_date = '$time',
lastedit_user_id='$user_id' $set_type
WHERE $filter";
$result = Database::query($sql);
}
$result = Database::query($sql);
// Insert if no entries are found (can only happen in case of $lastedit_type switch is 'default').
if (Database::affected_rows($result) == 0) {
$sql = "INSERT INTO $TABLE_ITEMPROPERTY (c_id, tool,ref,insert_date,insert_user_id,lastedit_date,lastedit_type, lastedit_user_id, $to_field, visibility, start_visible, end_visible, session_id)
VALUES ($course_id, '$tool', '$item_id', '$time', '$user_id', '$time', '$lastedit_type', '$user_id', '$to_value', '$visibility', '$start_visible', '$end_visible', '$session_id')";
$res = Database::query($sql);
if (!$res) {
$id = Database::insert_id();
$sql = "UPDATE $TABLE_ITEMPROPERTY SET id = $id WHERE iid = $id";
Database::query($sql);
return false;
}
}
@ -4632,7 +4656,22 @@ function copy_folder_course_session(
session_id = '$session_id'";
Database::query($sql);
$document_id = Database::insert_id();
api_item_property_update($course_info,TOOL_DOCUMENT,$document_id,'FolderCreated',api_get_user_id(),0,0,null,null,$session_id);
$sql = "UPDATE $tbl_course_description SET id = $document_id WHERE iid = $document_id";
Database::query($sql);
api_item_property_update(
$course_info,
TOOL_DOCUMENT,
$document_id,
'FolderCreated',
api_get_user_id(),
0,
0,
null,
null,
$session_id
);
}
}
@ -4960,14 +4999,9 @@ function api_set_setting($var, $value, $subvar = null, $cat = null, $access_url
if (Database::num_rows($res) > 0) {
// We have a setting for access_url 1, but none for the current one, so create one.
$row = Database::fetch_array($res);
$insert = "INSERT INTO $t_settings " .
"(variable,subkey," .
"type,category," .
"selected_value,title," .
"comment,scope," .
"subkeytext,access_url)" .
" VALUES " .
"('".$row['variable']."',".(!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
$insert = "INSERT INTO $t_settings (variable, subkey, type,category, selected_value, title, comment, scope, subkeytext, access_url)
VALUES
('".$row['variable']."',".(!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
"'".$row['type']."','".$row['category']."'," .
"'$value','".$row['title']."'," .
"".(!empty($row['comment']) ? "'".$row['comment']."'" : "NULL").",".(!empty($row['scope']) ? "'".$row['scope']."'" : "NULL")."," .
@ -4989,14 +5023,8 @@ function api_set_setting($var, $value, $subvar = null, $cat = null, $access_url
if (Database::num_rows($res) > 0) { // We have a setting for access_url 1, but none for the current one, so create one.
$row = Database::fetch_array($res);
if ($row['access_url_changeable'] == 1) {
$insert = "INSERT INTO $t_settings " .
"(variable,subkey," .
"type,category," .
"selected_value,title," .
"comment,scope," .
"subkeytext,access_url, access_url_changeable)" .
" VALUES " .
"('".$row['variable']."',".
$insert = "INSERT INTO $t_settings (variable,subkey, type,category, selected_value,title, comment,scope, subkeytext,access_url, access_url_changeable) VALUES
('".$row['variable']."',".
(!empty($row['subkey']) ? "'".$row['subkey']."'" : "NULL")."," .
"'".$row['type']."','".$row['category']."'," .
"'$value','".$row['title']."'," .
@ -5048,7 +5076,8 @@ function api_set_settings_category($category, $value = null, $access_url = 1, $f
$res = Database::query($sql);
return $res !== false;
} else {
$sql = "UPDATE $t_s SET selected_value = NULL WHERE category = '$category' AND access_url = $access_url";
$sql = "UPDATE $t_s SET selected_value = NULL
WHERE category = '$category' AND access_url = $access_url";
if (is_array($fieldtype) && count($fieldtype)>0) {
$sql .= " AND ( ";
$i = 0;

@ -31,12 +31,14 @@ class CourseDescription
}
/**
* Returns an array of objects of type CourseDescription corresponding to a specific course, without session ids (session id = 0)
* Returns an array of objects of type CourseDescription corresponding to
* a specific course, without session ids (session id = 0)
*
* @param int Course id
* @return array Array of CourseDescriptions
*/
public static function get_descriptions($course_id) {
public static function get_descriptions($course_id)
{
// Get course code
$course_info = api_get_course_info_by_id($course_id);
if (!empty($course_info)) {
@ -45,7 +47,8 @@ class CourseDescription
return array();
}
$t_course_desc = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = "SELECT * FROM $t_course_desc WHERE c_id = $course_id AND session_id = '0';";
$sql = "SELECT * FROM $t_course_desc
WHERE c_id = $course_id AND session_id = '0'";
$sql_result = Database::query($sql);
$results = array();
while($row = Database::fetch_array($sql_result)) {
@ -72,7 +75,9 @@ class CourseDescription
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$condition_session = api_get_session_condition($this->session_id, true, true);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $tbl_course_description WHERE c_id = $course_id $condition_session ORDER BY id ";
$sql = "SELECT * FROM $tbl_course_description
WHERE c_id = $course_id $condition_session
ORDER BY id ";
$rs = Database::query($sql);
$data = array();
while ($description = Database::fetch_array($rs)) {
@ -86,9 +91,11 @@ class CourseDescription
/**
* Get all data of course description by session id,
* first you must set session_id property with the object CourseDescription
* @deprecated
* @return array
*/
public function get_description_history($description_type) {
public function get_description_history($description_type)
{
$tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
$tbl_item_property = Database::get_course_table(TABLE_ITEM_PROPERTY);
@ -119,7 +126,8 @@ class CourseDescription
* @param int session id (optional)
* @return array
*/
public function get_data_by_description_type($description_type, $course_code = '', $session_id = null) {
public function get_data_by_description_type($description_type, $course_code = '', $session_id = null)
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
@ -132,7 +140,8 @@ class CourseDescription
$course_id = $course_info['real_id'];
}
$description_type = intval($description_type);
$sql = "SELECT * FROM $tbl_course_description WHERE c_id = $course_id AND description_type='$description_type' $condition_session ";
$sql = "SELECT * FROM $tbl_course_description
WHERE c_id = $course_id AND description_type='$description_type' $condition_session ";
$rs = Database::query($sql);
$data = array();
if ($description = Database::fetch_array($rs)) {
@ -143,7 +152,14 @@ class CourseDescription
return $data;
}
public function get_data_by_id($id, $course_code = '', $session_id = null) {
/**
* @param int $id
* @param string $course_code
* @param int $session_id
* @return array
*/
public function get_data_by_id($id, $course_code = '', $session_id = null)
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
@ -156,7 +172,8 @@ class CourseDescription
$course_id = $course_info['real_id'];
}
$id = intval($id);
$sql = "SELECT * FROM $tbl_course_description WHERE c_id = $course_id AND id='$id' $condition_session ";
$sql = "SELECT * FROM $tbl_course_description
WHERE c_id = $course_id AND id='$id' $condition_session ";
$rs = Database::query($sql);
$data = array();
if ($description = Database::fetch_array($rs)) {
@ -165,19 +182,23 @@ class CourseDescription
$data['description_content'] = $description['content'];
$data['progress'] = $description['progress'];
}
return $data;
}
/**
* Get maximum description type by session id, first you must set session_id properties with the object CourseDescription
* Get maximum description type by session id,
* first you must set session_id properties with the object CourseDescription
* @return int maximum description time adding one
*/
public function get_max_description_type() {
public function get_max_description_type()
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "SELECT MAX(description_type) as MAX FROM $tbl_course_description WHERE c_id = $course_id AND session_id='".$this->session_id."'";
$sql = "SELECT MAX(description_type) as MAX FROM $tbl_course_description
WHERE c_id = $course_id AND session_id='".$this->session_id."'";
$rs = Database::query($sql);
$max = Database::fetch_array($rs);
$description_type = $max['MAX']+1;
@ -189,7 +210,8 @@ class CourseDescription
/**
* Insert a description to the course_description table,
* first you must set description_type, title, content, progress and session_id properties with the object CourseDescription
* first you must set description_type, title, content, progress and
* session_id properties with the object CourseDescription
* @return int affected rows
*/
public function insert()
@ -211,16 +233,26 @@ class CourseDescription
$last_id = Database::insert_id();
$affected_rows = Database::affected_rows($result);
if ($last_id > 0) {
$sql = "UPDATE $tbl_course_description SET id = $last_id WHERE iid = $last_id";
Database::query($sql);
//insert into item_property
api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $last_id, 'CourseDescriptionAdded', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_COURSE_DESCRIPTION,
$last_id,
'CourseDescriptionAdded',
api_get_user_id()
);
}
return $affected_rows;
return $affected_rows;
}
/**
* Insert a row like history inside track_e_item_property table
* first you must set description_type, title, content, progress and session_id properties with the object CourseDescription
* first you must set description_type, title, content, progress and
* session_id properties with the object CourseDescription
* @param int description type
* @return int affected rows
*/
@ -243,6 +275,10 @@ class CourseDescription
session_id = '".intval($this->session_id)."'";
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
$sql = "UPDATE $tbl_course_description SET id = $last_id WHERE iid = $last_id";
Database::query($sql);
return $affected_rows;
}
@ -255,25 +291,32 @@ class CourseDescription
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = "UPDATE $tbl_course_description SET
title = '".Database::escape_string($this->title)."',
content = '".Database::escape_string($this->content)."',
progress = '".$this->progress."'
WHERE id = '".intval($this->id)."' AND
session_id = '".$this->session_id."' AND
c_id = ".api_get_course_int_id()."
";
title = '".Database::escape_string($this->title)."',
content = '".Database::escape_string($this->content)."',
progress = '".$this->progress."'
WHERE
id = '".intval($this->id)."' AND
session_id = '".$this->session_id."' AND
c_id = ".api_get_course_int_id();
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
if ($this->id > 0) {
//insert into item_property
api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $this->id, 'CourseDescriptionUpdated', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_COURSE_DESCRIPTION,
$this->id,
'CourseDescriptionUpdated',
api_get_user_id()
);
}
return $affected_rows;
}
/**
* Delete a description, first you must set description_type and session_id properties with the object CourseDescription
* Delete a description, first you must set description_type and session_id
* properties with the object CourseDescription
* @return int affected rows
*/
public function delete()
@ -281,13 +324,23 @@ class CourseDescription
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "DELETE FROM $tbl_course_description
WHERE c_id = $course_id AND id = '".intval($this->id)."' AND session_id = '".intval($this->session_id)."'";
WHERE
c_id = $course_id AND
id = '".intval($this->id)."' AND
session_id = '".intval($this->session_id)."'";
$result = Database::query($sql);
$affected_rows = Database::affected_rows($result);
if ($this->id > 0) {
//insert into item_property
api_item_property_update(api_get_course_info(), TOOL_COURSE_DESCRIPTION, $this->id, 'CourseDescriptionDeleted', api_get_user_id());
api_item_property_update(
api_get_course_info(),
TOOL_COURSE_DESCRIPTION,
$this->id,
'CourseDescriptionDeleted',
api_get_user_id()
);
}
return $affected_rows;
}
@ -301,7 +354,8 @@ class CourseDescription
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "SELECT id FROM $tbl_course_description WHERE c_id = $course_id AND description_type = '".intval($description_type)."'";
$sql = "SELECT id FROM $tbl_course_description
WHERE c_id = $course_id AND description_type = '".intval($description_type)."'";
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
$description_id = $row['id'];
@ -315,12 +369,17 @@ class CourseDescription
* @param int Description type (optional)
* @return string img html
*/
public function get_progress_porcent($with_icon = false, $description_type = THEMATIC_ADVANCE) {
public function get_progress_porcent($with_icon = false, $description_type = THEMATIC_ADVANCE)
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$session_id = intval($session_id);
$course_id = api_get_course_int_id();
$sql = "SELECT progress FROM $tbl_course_description WHERE c_id = $course_id AND description_type = '".intval($description_type)."' AND session_id = '".intval($this->session_id)."' ";
$sql = "SELECT progress FROM $tbl_course_description
WHERE
c_id = $course_id AND
description_type = '".intval($description_type)."' AND
session_id = '".intval($this->session_id)."' ";
$rs = Database::query($sql);
$progress = '';
$img = '';
@ -361,7 +420,8 @@ class CourseDescription
* Get description titles editable by default
* @return array
*/
public function get_default_description_title_editable() {
public function get_default_description_title_editable()
{
$default_description_title_editable = array();
$default_description_title_editable[1] = true;
$default_description_title_editable[2] = true;
@ -378,7 +438,8 @@ class CourseDescription
* Get description icons by default
* @return array
*/
public function get_default_description_icon() {
public function get_default_description_icon()
{
$default_description_icon = array();
$default_description_icon[1]= 'info.png';
$default_description_icon[2]= 'objective.png';
@ -396,7 +457,8 @@ class CourseDescription
* Get questions by default for help
* @return array
*/
public function get_default_question() {
public function get_default_question()
{
$question = array();
$question[1]= get_lang('GeneralDescriptionQuestions');
$question[2]= get_lang('ObjectivesQuestions');
@ -413,7 +475,8 @@ class CourseDescription
* Get informations by default for help
* @return array
*/
public function get_default_information() {
public function get_default_information()
{
$information = array();
$information[1]= get_lang('GeneralDescriptionInformation');
$information[2]= get_lang('ObjectivesInformation');
@ -430,7 +493,8 @@ class CourseDescription
* Set description id
* @return void
*/
public function set_id($id) {
public function set_id($id)
{
$this->id = $id;
}
@ -439,7 +503,8 @@ class CourseDescription
* @param int Course ID
* @return void
*/
public function set_course_id($id) {
public function set_course_id($id)
{
$this->course_id = intval($id);
}
@ -447,7 +512,8 @@ class CourseDescription
* Set description title
* @return void
*/
public function set_title($title) {
public function set_title($title)
{
$this->title = $title;
}
@ -455,7 +521,8 @@ class CourseDescription
* Set description content
* @return void
*/
public function set_content($content) {
public function set_content($content)
{
$this->content = $content;
}
@ -463,7 +530,8 @@ class CourseDescription
* Set description session id
* @return void
*/
public function set_session_id($session_id) {
public function set_session_id($session_id)
{
$this->session_id = $session_id;
}
@ -471,7 +539,8 @@ class CourseDescription
* Set description type
* @return void
*/
public function set_description_type($description_type) {
public function set_description_type($description_type)
{
$this->description_type = $description_type;
}
@ -479,7 +548,8 @@ class CourseDescription
* Set progress of a description
* @return void
*/
public function set_progress($progress) {
public function set_progress($progress)
{
$this->progress = $progress;
}
@ -487,7 +557,8 @@ class CourseDescription
* get description id
* @return int
*/
public function get_id() {
public function get_id()
{
return $this->id;
}
@ -495,7 +566,8 @@ class CourseDescription
* get description title
* @return string
*/
public function get_title() {
public function get_title()
{
return $this->title;
}
@ -503,7 +575,8 @@ class CourseDescription
* get description content
* @return string
*/
public function get_content() {
public function get_content()
{
return $this->content;
}
@ -511,7 +584,8 @@ class CourseDescription
* get session id
* @return int
*/
public function get_session_id() {
public function get_session_id()
{
return $this->session_id;
}
@ -519,7 +593,8 @@ class CourseDescription
* get description type
* @return int
*/
public function get_description_type() {
public function get_description_type()
{
return $this->description_type;
}
@ -527,7 +602,8 @@ class CourseDescription
* get progress of a description
* @return int
*/
public function get_progress() {
public function get_progress()
{
return $this->progress;
}
}

@ -126,12 +126,21 @@ class GlossaryManager
}
$id = Database::insert_id();
if ($id) {
$sql = "UPDATE $t_glossary SET glossary_id = $id WHERE iid = $id";
Database::query($sql);
//insert into item_property
api_item_property_update(
api_get_course_info(),
TOOL_GLOSSARY,
$id,
'GlossaryAdded',
api_get_user_id()
);
}
$sql = "UPDATE $t_glossary SET glossary_id = $id WHERE iid = $id";
Database::query($sql);
//insert into item_property
api_item_property_update(api_get_course_info(), TOOL_GLOSSARY, $id, 'GlossaryAdded', api_get_user_id());
$_SESSION['max_glossary_display'] = GlossaryManager::get_max_glossary_item();
// display the feedback message
if ($message) {

Loading…
Cancel
Save