forked from atutor/ATutor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
move_module.php
79 lines (67 loc) · 2.99 KB
/
move_module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/************************************************************************/
/* ATutor */
/************************************************************************/
/* Copyright (c) 2002 - 2009 */
/* Inclusive Design Institute */
/* */
/* This program is free software. You can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation. */
/************************************************************************/
define('AT_INCLUDE_PATH', 'include/');
require(AT_INCLUDE_PATH.'vitals.inc.php');
authenticate(AT_PRIV_STYLES);
global $addslashes;
// handle ajax post request from course index page and student tools index page
if (isset($_POST['from']))
{
$from = $_POST['from'];
if ($_POST['moved_modules'] <> '') $final_home_links = $addslashes(str_replace('-', '/', $_POST['moved_modules']));
// when pretty url is turned on, revert the pretty urls back to regular urls
if ($_config['pretty_url'] > 0)
{
$home_links = explode('|', $final_home_links);
$final_home_links = '';
if (is_array($home_links))
{
foreach ($home_links as $link)
{
$url_parser = new UrlParser($link);
$pathinfo = $url_parser->getPathArray();
$final_home_links .= $pathinfo[1]->getPath(). $pathinfo[1]->getFileName(). '|';
}
$final_home_links = substr($final_home_links, 0, -1);
}
}
}
// handle ajax post request to remove module from course index page and student tools index page
if ($_POST['remove'] <> '')
{
$remove_module = $_POST['remove'];
// when pretty url is turned on, revert the pretty url back to regular url
if ($_config['pretty_url'] > 0)
{
if (substr($remove_module, 0, 6) == 'go.php') $remove_module = substr($remove_module, 6);
$url_parser = new UrlParser($remove_module);
$pathinfo = $url_parser->getPathArray();
$remove_module = $pathinfo[1]->getPath(). $pathinfo[1]->getFileName();
}
if ($from == 'course_index'){
$sql = "SELECT home_links links FROM %scourses WHERE course_id=%d";
}else if ($from == 'student_tools'){
$sql = "SELECT links FROM %sfha_student_tools WHERE course_id=%d";
}
$row= queryDB($sql, array(TABLE_PREFIX,$_SESSION['course_id']), TRUE);
if (substr($row['links'], 0, strlen($remove_module)) == $remove_module)
$final_home_links = substr($row['links'], strlen($remove_module)+1);
else
$final_home_links = preg_replace('/\|'.preg_quote($remove_module, '/').'/', '', $row['links']);
}
// save the module display order into db
if ($from == 'course_index')
$sql = "UPDATE %scourses SET home_links='%s' WHERE course_id=%d";
else if ($from == 'student_tools')
$sql = "UPDATE %sfha_student_tools SET links='%s' WHERE course_id=%d";
$result = queryDB($sql, array(TABLE_PREFIX, $final_home_links, $_SESSION['course_id']));
?>