Fix queries and PHP warnings.

1.10.x
Julio Montoya 10 years ago
parent 42d122a451
commit 760a5f9373
  1. 8
      main/admin/access_url_edit_courses_to_url.php
  2. 35
      main/inc/lib/add_course.lib.inc.php
  3. 21
      main/inc/lib/urlmanager.lib.php

@ -87,13 +87,13 @@ if (isset($_POST['form_sent']) && $_POST['form_sent']) {
$course_list = $_POST['course_list'];
if (!is_array($course_list)) {
$course_list=array();
$course_list = array();
}
if ($form_sent == 1) {
if ($access_url_id==0) {
header('Location: access_url_edit_users_to_url.php?action=show_message&message='.get_lang('SelectURL'));
} elseif(is_array($course_list) ) {
} elseif (is_array($course_list)) {
UrlManager::update_urls_rel_course($course_list, $access_url_id);
header('Location: access_urls.php?action=show_message&message='.get_lang('CoursesWereEdited'));
}
@ -117,14 +117,14 @@ $ajax_search = $add_type == 'unique' ? true : false;
if($ajax_search) {
$courses = UrlManager::get_url_rel_course_data($access_url_id);
foreach ($courses as $course) {
$course_list[$course['c_id']] = $course ;
$course_list[$course['c_id']] = $course;
}
} else {
$courses = UrlManager::get_url_rel_course_data();
foreach ($courses as $course) {
if ($course['access_url_id'] == $access_url_id) {
$course_list[$course['c_id']] = $course ;
$course_list[$course['c_id']] = $course;
}
}

@ -688,10 +688,10 @@ class AddCourse
];
$counter = 1;
foreach ($settings as $setting) {
foreach ($settings as $variable => $setting) {
Database::query(
"INSERT INTO $TABLESETTING (id, c_id, variable,value,category)
VALUES ($counter, $course_id, '".$setting."', '".$setting['default']."', '".$setting['category']."')"
"INSERT INTO $TABLESETTING (id, c_id, variable, value, category)
VALUES ($counter, $course_id, '".$variable."', '".$setting['default']."', '".$setting['category']."')"
);
$counter++;
}
@ -1132,20 +1132,33 @@ class AddCourse
* @param int $counter
* @param array $file
*/
function insertDocument($course_id, $counter, $file)
public static function insertDocument($course_id, $counter, $file)
{
$TABLEITEMPROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
$TABLETOOLDOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
$tableItem = Database::get_course_table(TABLE_ITEM_PROPERTY);
$tableDocument = Database::get_course_table(TABLE_DOCUMENT);
$now = api_get_utc_datetime();
$sql = "INSERT INTO $TABLETOOLDOCUMENT (id, c_id, path,title,filetype,size)
$sql = "INSERT INTO $tableDocument (id, c_id, path,title,filetype,size)
VALUES ($counter, $course_id, '".$file['path']."', '".$file['title']."', '".$file['filetype']."', '".$file['size']."')";
Database::query($sql);
$docId = Database:: insert_id();
Database::query(
"INSERT INTO $TABLEITEMPROPERTY (id, c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
VALUES ($counter, $course_id,'document',1,'$now', '$now', $docId, 'DocumentAdded', 1, 0, NULL, 0)"
);
if ($docId) {
$sql = "UPDATE $tableDocument SET id = iid WHERE iid = $docId";
Database::query($sql);
Database::query(
"INSERT INTO $tableItem (id, c_id, tool,insert_user_id,insert_date,lastedit_date,ref,lastedit_type,lastedit_user_id,to_group_id,to_user_id,visibility)
VALUES ($counter, $course_id,'document',1,'$now', '$now', $docId, 'DocumentAdded', 1, 0, NULL, 0)"
);
$id = Database:: insert_id();
$sql = "UPDATE $tableItem SET id = iid WHERE iid = $id";
Database::query($sql);
}
}
/**

@ -369,8 +369,9 @@ class UrlManager
{
$table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$sql= "SELECT c_id FROM $table_url_rel_course
WHERE access_url_id = ".intval($urlId)." AND
c_id = '".intval($courseId)."'";
WHERE
access_url_id = ".intval($urlId)." AND
c_id = '".intval($courseId)."'";
$result = Database::query($sql);
$num = Database::num_rows($result);
@ -385,7 +386,7 @@ class UrlManager
* @param int $urlId
* @return boolean true if success
* */
public static function relation_url_usergroup_exist($userGroupId, $urlId)
public static function relationUrlUsergroupExist($userGroupId, $urlId)
{
$table = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP);
$sql= "SELECT usergroup_id FROM $table
@ -479,6 +480,7 @@ class UrlManager
}
}
}
return $result_array;
}
@ -495,7 +497,7 @@ class UrlManager
if (is_array($userGroupList) && is_array($urlList)) {
foreach ($urlList as $urlId) {
foreach ($userGroupList as $userGroupId) {
$count = self::relation_url_usergroup_exist($userGroupId, $urlId);
$count = self::relationUrlUsergroupExist($userGroupId, $urlId);
if ($count == 0) {
$result = self::addUserGroupToUrl($userGroupId, $urlId);
if ($result) {
@ -657,17 +659,17 @@ class UrlManager
}
/**
* @param string $courseId
* @param int $courseId
* @param int $url_id
* @return resource
*/
public static function add_course_to_url($courseId, $url_id=1)
public static function add_course_to_url($courseId, $url_id = 1)
{
$table_url_rel_course= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$table_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
if (empty($url_id)) {
$url_id = 1;
}
$count = UrlManager::relation_url_course_exist($course_code,$url_id);
$count = UrlManager::relation_url_course_exist($courseId, $url_id);
if (empty($count)) {
$sql = "INSERT INTO $table_url_rel_course
SET c_id = '".intval($courseId)."', access_url_id = ".intval($url_id);
@ -848,7 +850,8 @@ class UrlManager
{
$table_url_rel_course = Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$sql = "SELECT c_id FROM $table_url_rel_course WHERE access_url_id=".intval($access_url_id);
$sql = "SELECT c_id FROM $table_url_rel_course
WHERE access_url_id=".intval($access_url_id);
$result = Database::query($sql);
$existing_courses = array();

Loading…
Cancel
Save