diff --git a/main/admin/configure_homepage.php b/main/admin/configure_homepage.php
index 324deadfd3..2a39a437ad 100644
--- a/main/admin/configure_homepage.php
+++ b/main/admin/configure_homepage.php
@@ -19,11 +19,11 @@ api_protect_admin_script();
require_once api_get_path(LIBRARY_PATH).'WCAG/WCAG_rendering.php';
require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
+require_once api_get_path(LIBRARY_PATH).'course_category.lib.php';
global $_configuration;
$action = isset($_GET['action']) ? Security::remove_XSS($_GET['action']) : null;
-$tbl_category = Database::get_main_table(TABLE_MAIN_CATEGORY);
$tool_name = get_lang('ConfigureHomePage');
$_languages = api_get_languages();
@@ -198,7 +198,7 @@ if (!empty($action)) {
$fp = fopen($homep.$topf.'_'.$lang_name.$ext, 'w');
fputs($fp, $home_top);
fclose($fp);
-
+
}
}
}
@@ -234,7 +234,7 @@ if (!empty($action)) {
}
}
}
-
+
} else {
fputs($fp, '');
if ($_POST['all_langs']) {
@@ -460,9 +460,9 @@ if (!empty($action)) {
$fp = fopen($homep.$menuf.'_'.$lang_name.$ext, 'w');
fputs($fp, $home_menu);
fclose($fp);
-
+
}
- }
+ }
}
}
}
@@ -687,7 +687,7 @@ if (!empty($action)) {
}// end of "else" in if($_POST['formSent']) condition
} else {
//if $action is empty, then prepare a list of the course categories to display (?)
- $Categories = Database::store_result(Database::query("SELECT name FROM $tbl_category WHERE parent_id IS NULL ORDER BY tree_pos"));
+ $Categories = getCategoriesToDisplayInHomePage();
}
// Display section
@@ -896,7 +896,7 @@ switch ($action) {
,
- *
- * @param string The URL of the site
- * @param string The description of the site
- * @param int is active or not
- * @return boolean if success
- */
+ /**
+ * Creates a new url access
+ *
+ * @author Julio Montoya ,
+ *
+ * @param string The URL of the site
+ * @param string The description of the site
+ * @param int is active or not
+ * @return boolean if success
+ */
public static function add($url, $description, $active)
{
$tms = time();
@@ -407,7 +407,7 @@ class UrlManager
if (is_array($course_list) && is_array($url_list)){
foreach ($url_list as $url_id) {
foreach ($course_list as $course_code) {
- $count = UrlManager::relation_url_course_exist($course_code,$url_id);
+ $count = self::relation_url_course_exist($course_code,$url_id);
if ($count==0) {
$sql = "INSERT INTO $table_url_rel_course
SET course_code = '".Database::escape_string($course_code)."', access_url_id = ".Database::escape_string($url_id);
@@ -436,7 +436,7 @@ class UrlManager
if (is_array($userGroupList) && is_array($urlList)) {
foreach ($urlList as $urlId) {
foreach ($userGroupList as $userGroupId) {
- $count = UrlManager::relation_url_usergroup_exist($userGroupId, $urlId);
+ $count = self::relation_url_usergroup_exist($userGroupId, $urlId);
if ($count == 0) {
$result = self::addUserGroupToUrl($userGroupId, $urlId);
if ($result) {
@@ -452,6 +452,71 @@ class UrlManager
return $resultArray;
}
+ /**
+ * Add a group of user group into a group of URLs
+ * @author Julio Montoya
+ * @param array of course ids
+ * @param array of url_ids
+ * @return array
+ **/
+ public static function addCourseCategoryListToUrl($courseCategoryList, $urlList)
+ {
+ $resultArray = array();
+ if (is_array($courseCategoryList) && is_array($urlList)) {
+ foreach ($urlList as $urlId) {
+ foreach ($courseCategoryList as $categoryCourseId) {
+ $count = self::relationUrlCourseCategoryExist($categoryCourseId, $urlId);
+ if ($count == 0) {
+ $result = self::addCourseCategoryToUrl($categoryCourseId, $urlId);
+ if ($result) {
+ $resultArray[$urlId][$categoryCourseId] = 1;
+ } else {
+ $resultArray[$urlId][$categoryCourseId] = 0;
+ }
+ }
+ }
+ }
+ }
+
+ return $resultArray;
+ }
+
+ /**
+ * Checks the relationship between an URL and a UserGr
+ * oup (return the num_rows)
+ * @author Julio Montoya
+ * @param int $categoryCourseId
+ * @param int $urlId
+ * @return boolean true if success
+ * */
+ public static function relationUrlCourseCategoryExist($categoryCourseId, $urlId)
+ {
+ $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
+ $sql= "SELECT course_category_id FROM $table
+ WHERE access_url_id = ".Database::escape_string($urlId)." AND
+ course_category_id = ".Database::escape_string($categoryCourseId);
+ $result = Database::query($sql);
+ $num = Database::num_rows($result);
+ return $num;
+ }
+
+ /**
+ * @param int $categoryCourseId
+ * @param int $urlId
+ * @return int
+ */
+ public static function addCourseCategoryToUrl($categoryCourseId, $urlId)
+ {
+ $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
+ $sql = "INSERT INTO $table
+ SET
+ course_category_id = '".intval($categoryCourseId)."',
+ access_url_id = ".intval($urlId);
+ Database::query($sql);
+ return Database::insert_id();
+ }
+
+
/**
* @param int $userGroupId
* @param int $urlId
@@ -778,7 +843,7 @@ class UrlManager
// Deleting old users
foreach($existing_sessions as $existing_session) {
- if(!in_array($existing_session, $session_list)) {
+ if (!in_array($existing_session, $session_list)) {
if (!empty($existing_session) && !empty($access_url_id)) {
UrlManager::delete_url_rel_session($existing_session,$access_url_id);
}