Remove $_configuration calls and use functions, format code.

1.10.x
Julio Montoya 10 years ago
parent bf9f7fd603
commit 74ca0d17bc
  1. 26
      main/admin/configure_homepage.php
  2. 14
      main/admin/course_add.php
  3. 12
      main/admin/course_request_rejected.php
  4. 11
      main/admin/dashboard_add_users_to_user.php
  5. 9
      main/exercice/exercise.class.php
  6. 3
      main/exercice/hotpotatoes.lib.php
  7. 4
      main/exercice/savescores.php
  8. 2
      main/inc/lib/access_url_edit_courses_to_url_functions.lib.php
  9. 2
      main/inc/lib/access_url_edit_sessions_to_url_functions.lib.php
  10. 2
      main/inc/lib/access_url_edit_users_to_url_functions.lib.php
  11. 2
      main/inc/lib/add_course.lib.inc.php
  12. 3
      main/inc/lib/add_courses_to_session_functions.lib.php
  13. 6
      main/inc/lib/add_many_session_to_category_functions.lib.php
  14. 9
      main/inc/lib/api.lib.php
  15. 36
      main/inc/lib/link.lib.php
  16. 19
      main/inc/lib/sessionmanager.lib.php
  17. 5
      main/inc/lib/template.lib.php
  18. 3
      main/newscorm/learnpath.class.php
  19. 1
      main/newscorm/resourcelinker.inc.php
  20. 13
      main/session/add_users_to_session.php
  21. 6
      main/session/session_add.php
  22. 2
      main/session/session_export.php
  23. 6
      main/user/add_users_to_session.php
  24. 31
      tests/main/inc/banner.inc.test.php

@ -70,8 +70,6 @@ $(function() {
});
</script>';
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');
@ -1007,7 +1005,7 @@ switch ($action) {
<section id="page-home">
<div class="row">
<div class="col-md-3">
<!-- login block -->
<div id="login_block" class="panel panel-default">
<div class="panel-body">
@ -1029,10 +1027,10 @@ switch ($action) {
</ul>
</div>
</div>
<!-- notice block -->
<div class="panel-group" id="notice-block" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
@ -1062,8 +1060,8 @@ switch ($action) {
</div>
</div>
<!-- insert link block -->
<div class="panel-group" id="links-block" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
@ -1077,7 +1075,7 @@ switch ($action) {
<div class="panel-body">
<a href="<?php echo api_get_self(); ?>?action=insert_link"><?php Display::display_icon('addd.gif', get_lang('InsertLink')); ?>
<?php echo get_lang('InsertLink'); ?>
</a>
</a>
<ul class="menulist">
<?php
$home_menu = '';
@ -1110,7 +1108,7 @@ switch ($action) {
</div>
</div>
</div>
</div>
<div class="col-md-9">
<div class="actions">
@ -1132,14 +1130,14 @@ switch ($action) {
echo $open;
?>
</section>
<?php
$access_url_id = 1;
// we only show the category options for the main chamilo installation
if (api_is_multiple_url_enabled()) {
$access_url_id = api_get_current_access_url_id();
}
if ($access_url_id == 1) {
echo '<div class="actions">';
echo '<a href="course_category.php">'.Display::return_icon('edit.png', get_lang('Edit')).get_lang('EditCategories').'</a>';
@ -1158,7 +1156,7 @@ switch ($action) {
}
echo '</ul>';
?>
<?php
if (file_exists($homep.$newsf.'_'.$lang.$ext)) {
$open = @(string)file_get_contents($homep.$newsf.'_'.$lang.$ext);
@ -1170,7 +1168,7 @@ switch ($action) {
echo $open;
}
?>
<?php
// Add new page
$home_menu = '';

@ -14,19 +14,21 @@ $tool_name = get_lang('AddCourse');
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
/* MAIN CODE */
global $_configuration;
// Get all possible teachers.
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
$table_user = Database :: get_main_table(TABLE_MAIN_USER);
$sql = "SELECT user_id,lastname,firstname FROM $table_user WHERE status=1".$order_clause;
$sql = "SELECT user_id,lastname,firstname
FROM $table_user
WHERE status=1".$order_clause;
// Filtering teachers when creating a course.
if (api_is_multiple_url_enabled()) {
$access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql = "SELECT u.user_id,lastname,firstname FROM $table_user as u
$sql = "SELECT u.user_id,lastname,firstname
FROM $table_user as u
INNER JOIN $access_url_rel_user_table url_rel_user
ON (u.user_id=url_rel_user.user_id) WHERE url_rel_user.access_url_id=".api_get_current_access_url_id()." AND status=1".$order_clause;
ON (u.user_id=url_rel_user.user_id)
WHERE url_rel_user.access_url_id=".api_get_current_access_url_id()." AND status=1".$order_clause;
}
$res = Database::query($sql);
@ -117,7 +119,7 @@ $form->addGroup($group,'', get_lang('Subscription'), '<br />');
$group = array();
$group[]= $form->createElement('radio', 'unsubscribe', get_lang('Unsubscription'), get_lang('AllowedToUnsubscribe'), 1);
$group[]= $form->createElement('radio', 'unsubscribe', null, get_lang('NotAllowedToUnsubscribe'), 0);
$form->addGroup($group,'', get_lang('Unsubscription'), '<br />');
$form->addGroup($group, '', get_lang('Unsubscription'), '<br />');
$form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB')));
$form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');

@ -28,7 +28,6 @@ $delete_course_request = isset($_GET['delete_course_request']) ? intval($_GET['d
$request_info = isset($_GET['request_info']) ? intval($_GET['request_info']) : '';
$message = isset($_GET['message']) ? trim(Security::remove_XSS(stripslashes(urldecode($_GET['message'])))) : '';
$is_error_message = !empty($_GET['is_error_message']);
$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
if ($course_validation_feature) {
@ -107,8 +106,9 @@ function get_number_of_requests() {
/**
* Get course data to display
*/
function get_request_data($from, $number_of_items, $column, $direction) {
global $keyword;
function get_request_data($from, $number_of_items, $column, $direction)
{
$keyword = isset($_GET['keyword']) ? Database::escape_string(trim($_GET['keyword'])) : '';
$course_request_table = Database :: get_main_table(TABLE_MAIN_COURSE_REQUEST);
$from = intval($from);
@ -128,7 +128,11 @@ function get_request_data($from, $number_of_items, $column, $direction) {
WHERE status = ".COURSE_REQUEST_REJECTED;
if ($keyword != '') {
$sql .= " AND (title LIKE '%".$keyword."%' OR code LIKE '%".$keyword."%' OR visual_code LIKE '%".$keyword."%')";
$sql .= " AND (
title LIKE '%".$keyword."%' OR
code LIKE '%".$keyword."%' OR
visual_code LIKE '%".$keyword."%'
)";
}
$sql .= " ORDER BY col$column $direction ";
$sql .= " LIMIT $from,$number_of_items";

@ -10,7 +10,6 @@ $cidReset = true;
require_once '../inc/global.inc.php';
global $_configuration;
$ajax_search = false;
// create an ajax object
$xajax = new xajax();
@ -409,12 +408,12 @@ if(!empty($msg)) {
</select>
</div>
</div>
<!-- <div class="form-group">
<input type="text" id="user_to_add" onkeyup="xajax_search_users(this.value,'single')" onclick="moveItem(document.getElementById('user_to_add'), document.getElementById('destination'))" />
<div id="ajax_list_users_single"></div>
</div> -->
<?php } ?>
<div class="form-group">
<div class="col-sm-12">
@ -430,8 +429,8 @@ if(!empty($msg)) {
</div>
</div>
</div>
</div>
<div class="col-md-4">
<?php if ($ajax_search) { ?>
@ -479,7 +478,7 @@ if(!empty($msg)) {
}?>
</select>
</div>
</div>
</div>
</div>
</div>

@ -94,7 +94,6 @@ class Exercise
*/
public function read($id)
{
global $_configuration;
$TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
$table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
@ -146,7 +145,7 @@ class Exercise
$this->lpList = Database::store_result($result, 'ASSOC');
}
$this->force_edit_exercise_in_lp = isset($_configuration['force_edit_exercise_in_lp']) ? $_configuration['force_edit_exercise_in_lp'] : false;
$this->force_edit_exercise_in_lp = api_get_configuration_value('force_edit_exercise_in_lp');
if ($this->exercise_was_added_in_lp) {
$this->edit_exercise_in_lp = $this->force_edit_exercise_in_lp == true;
@ -1032,10 +1031,8 @@ class Exercise
*/
public function createForm($form, $type='full')
{
global $id;
if (empty($type)){
$type='full';
if (empty($type)) {
$type = 'full';
}
// form title

@ -98,13 +98,14 @@ function GetComment($path, $course_code = '')
*/
function SetComment($path, $comment)
{
global $dbTable;
$dbTable = Database::get_course_table(TABLE_DOCUMENT);
$path = Database::escape_string($path);
$comment = Database::escape_string($comment);
$course_id = api_get_course_int_id();
$query = "UPDATE $dbTable SET comment='$comment'
WHERE $course_id AND path='$path'";
$result = Database::query($query);
return $result;
}

@ -38,7 +38,9 @@ $jscript2run = '';
*/
function save_scores($file, $score)
{
global $origin, $_user, $TABLETRACK_HOTPOTATOES;
global $origin;
$TABLETRACK_HOTPOTATOES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
$_user = api_get_user_info();
// if tracking is disabled record nothing
$weighting = 100; // 100%
$date = api_get_utc_datetime();

@ -27,7 +27,7 @@ class Accessurleditcoursestourl
*/
function search_courses($needle, $id)
{
global $tbl_course;
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$xajax_response = new xajaxResponse();
$return = '';

@ -29,7 +29,7 @@ class Accessurleditsessionstourl
*/
function search_sessions($needle, $id)
{
global $tbl_session;
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$xajax_response = new xajaxResponse();
$return = '';

@ -28,7 +28,7 @@ class Accessurledituserstourl
*/
function search_users($needle, $id)
{
global $tbl_user;
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$xajax_response = new xajaxResponse();
$return = '';

@ -20,7 +20,6 @@ class AddCourse
*/
public static function define_course_keys($wanted_code, $prefix_for_all = '', $prefix_for_base_name = '', $prefix_for_path = '', $add_unique_prefix = false, $use_code_indepedent_keys = true)
{
global $prefixAntiNumber, $_configuration;
$course_table = Database :: get_main_table(TABLE_MAIN_COURSE);
$wanted_code = CourseManager::generate_course_code($wanted_code);
$keys_course_code = $wanted_code;
@ -425,7 +424,6 @@ class AddCourse
'example_material_course_creation'
) != 'false';
}
global $_configuration;
$course_id = intval($course_id);
if (empty($course_id)) {

@ -16,7 +16,8 @@ class AddCourseToSession
*/
public static function search_courses($needle, $type)
{
global $tbl_course, $tbl_session_rel_course, $id_session;
global $tbl_session_rel_course, $id_session;
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$course_title = null;
$xajax_response = new xajaxResponse();
$return = '';

@ -21,9 +21,9 @@ class AddManySessionToCategoryFunctions
* @assert () !== ''
* @assert ('abc','single') !== ''
*/
function search_courses($needle,$type) {
global $tbl_course, $tbl_session, $id_session;
function search_courses($needle,$type)
{
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$xajax_response = new xajaxResponse();
$return = '';
if(!empty($needle) && !empty($type)) {

@ -4937,9 +4937,9 @@ function api_get_version() {
* @return string
*/
function api_get_software_name() {
global $_configuration;
if (isset($_configuration['software_name']) && !empty($_configuration['software_name'])) {
return $_configuration['software_name'];
$name = api_get_configuration_value('software_name');
if (!empty($name)) {
return $name;
} else {
return 'Chamilo';
}
@ -6907,8 +6907,7 @@ function api_set_default_visibility($item_id, $tool_id, $group_id = 0, $courseIn
* @return string
*/
function api_get_security_key() {
global $_configuration;
return $_configuration['security_key'];
return api_get_configuration_value('security_key');
}
/**

@ -918,11 +918,11 @@ class Link extends Model
'class' => 'check-link'
)
);
}
if (api_is_allowed_to_edit(null, true)) {
if ($session_id == $myrow['session_id']) {
$url = api_get_self() . '?' . api_get_cidreq() .
'&action=editlink&category=' . (!empty ($category) ? $category : '') .
@ -934,7 +934,7 @@ class Link extends Model
'pencil',
'default btn-sm'
);
// DISPLAY MOVE UP COMMAND only if it is not the top link.
/* commented at least since 2014-10-11
if ($i != 1) {
@ -961,7 +961,7 @@ class Link extends Model
'eye',
'default btn-sm'
);
}
if ($myrow['visibility'] == '0') {
$url .= 'link.php?' . api_get_cidreq() .'&sec_token=' . $token .'&action=visible&id=' . $myrow['id'] .'&scope=link&category_id=' . $myrow['category_id'];
@ -970,13 +970,13 @@ class Link extends Model
$url,
'eye-slash',
'primary btn-sm'
);
);
}
$url .= api_get_self() . '?' . api_get_cidreq() .'&sec_token=' . $token .'&action=deletelink&id=' . $myrow['id'] .'&category_id=' . $myrow['category_id'];
$event = "javascript: if(!confirm('" . get_lang('LinkDelconfirm') . "'))return false;";
$title = get_lang('Delete');
$toolbar .= Display::toolbarButton(
'',
$url,
@ -986,8 +986,8 @@ class Link extends Model
'onclick' => $event,
'title' => $title
)
);
);
} else {
$title = get_lang('EditionNotAvailableFromSession');
@ -999,9 +999,9 @@ class Link extends Model
array(
'title' => $title
)
);
);
}
}
$iconLink = Display::return_icon(
'url.png',
@ -1009,7 +1009,7 @@ class Link extends Model
null,
ICON_SIZE_SMALL
);
if ($myrow['visibility'] == '1') {
$content .= '<div class="list-group-item">';
$content .= '<div class="pull-right"><div class="btn-group">'.$toolbar.'</div></div>';
@ -1027,7 +1027,7 @@ class Link extends Model
$content .= $link_validator;
$content .= $session_img;
$content .= '</h4>';
$content .= '<p class="list-group-item-text">' . $myrow['description'] . '</p>';
$content .= '</div>';
} else {
@ -1270,14 +1270,17 @@ class Link extends Model
*/
public static function put_link($url, $cat, $title, $description, $on_homepage, $hidden)
{
$_course = api_get_course_info();
$_user = api_get_user_info();
$tbl_link = Database:: get_course_table(TABLE_LINK);
$course_id = api_get_course_int_id();
$urleq = "url='" . Database:: escape_string($url) . "'";
$cateq = "category_id=" . intval($cat);
$result = Database:: query(
"SELECT id FROM $tbl_link
$result = Database:: query("
SELECT id FROM $tbl_link
WHERE c_id = $course_id AND " . $urleq . ' AND ' . $cateq
);
@ -1321,7 +1324,6 @@ class Link extends Model
$ipu = 'LinkAdded';
$rv = 2; // 2 = new
}
global $_course, $_user;
api_item_property_update(
$_course,
TOOL_LINK,

@ -1154,8 +1154,6 @@ class SessionManager
$date_to = '',
$options
) {
global $_configuration;
//escaping variables
$sessionId = intval($sessionId);
$courseId = intval($courseId);
@ -3116,19 +3114,19 @@ class SessionManager
$imageFieldId = Database::fetch_assoc($resultField);
while ($row = Database::fetch_array($result)) {
$row['image'] = null;
$sessionImage = $sysUploadPath . $imageFieldId['id'] . '_' . $row['id'] . '.png';
if (is_file($sessionImage)) {
$sessionImage = $webUploadPath . $imageFieldId['id'] . '_' . $row['id'] . '.png';
$row['image'] = $sessionImage;
} else {
$row['image'] = $imgPath;
}
$sessions[$row['id']] = $row;
}
}
@ -5506,14 +5504,7 @@ class SessionManager
*/
public static function durationPerUserIsEnabled()
{
global $_configuration;
if (isset($_configuration['session_duration_feature']) &&
$_configuration['session_duration_feature']
) {
return true;
}
return false;
return api_get_configuration_value('session_duration_feature');
}
/**

@ -728,7 +728,8 @@ class Template
*/
private function set_header_parameters($sendHeaders)
{
global $httpHeadXtra, $_course, $interbreadcrumb, $language_file, $_configuration, $this_section;
global $httpHeadXtra, $interbreadcrumb, $language_file, $_configuration, $this_section;
$_course = api_get_course_info();
$help = $this->help;
$nameTools = $this->title;
$navigation = return_navigation_array();
@ -810,7 +811,7 @@ class Template
//If exist pick the current chamilo theme favicon
if (is_file($favicoThemeUrl . 'favicon.ico')) {
$favico = '<link rel="shortcut icon" href="' . api_get_path(WEB_CSS_PATH)
. 'themes/' . $this->theme . '/images/favicon.ico" type="image/x-icon" />';
. 'themes/' . $this->theme . '/images/favicon.ico" type="image/x-icon" />';
}
if (api_is_multiple_url_enabled()) {

@ -3100,7 +3100,6 @@ class learnpath
*/
public function get_html_toc($toc_list = null)
{
global $_configuration;
$is_allowed_to_edit = api_is_allowed_to_edit(null, true, false, false);
if ($this->debug > 0) {
@ -3111,7 +3110,7 @@ class learnpath
}
//$html = '<div id="scorm_title" class="scorm-heading">'.Security::remove_XSS($this->get_name()) . '</div>';
$html = '<div class="scorm-body">';
$hide_teacher_icons_lp = isset($_configuration['hide_teacher_icons_lp']) ? $_configuration['hide_teacher_icons_lp'] : true;
$hide_teacher_icons_lp = api_get_configuration_value('hide_teacher_icons_lp');
if ($is_allowed_to_edit && $hide_teacher_icons_lp == false) {
$gradebook = Security :: remove_XSS($_GET['gradebook']);

@ -61,7 +61,6 @@ function show_folder_up() {
* @param $folder
*/
function show_documents($folder) {
global $_course;
global $source_id, $action, $learnpath_id, $chapter_id, $originalresource;
// Documents are a special case: The teacher can add an invisible document (it will be viewable by the user)

@ -63,7 +63,10 @@ if (is_array($extra_field_list)) {
function search_users($needle, $type)
{
global $tbl_user, $tbl_session_rel_user, $id_session;
global $id_session;
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$xajax_response = new xajaxResponse();
$return = '';
@ -539,11 +542,11 @@ $link_add_group = Display::url(
);
$newLinks = Display::url(
Display::return_icon('teacher.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
Display::return_icon('teacher.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
get_lang('EnrollTrainersFromExistingSessions'), api_get_path(WEB_CODE_PATH).'session/add_teachers_to_session.php?id='.$id_session
);
$newLinks .= Display::url(
Display::return_icon('user.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
Display::return_icon('user.png', get_lang('EnrollTrainersFromExistingSessions'), null, ICON_SIZE_TINY).
get_lang('EnrollStudentsFromExistingSessions'), api_get_path(WEB_CODE_PATH).'session/add_students_to_session.php?id='.$id_session
);
?>
@ -656,7 +659,7 @@ if (!empty($errorMsg)) {
<i class="fa fa-chevron-left"></i>
</button>
</div>
<?php
} else {
?>
@ -670,7 +673,7 @@ if (!empty($errorMsg)) {
<i class="fa fa-chevron-left"></i>
</button>
</div>
<?php
}
if (!empty($addProcess)) {

@ -33,9 +33,9 @@ $interbreadcrumb[] = array(
);
function search_coachs($needle) {
global $tbl_user;
function search_coachs($needle)
{
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$xajax_response = new xajaxResponse();
$return = '';

@ -32,8 +32,6 @@ $archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive=';
$tool_name = get_lang('ExportSessionListXMLCSV');
global $_configuration;
$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
set_time_limit(0);

@ -62,7 +62,11 @@ if($allowTutors == 'true') {
function search_users($needle, $type)
{
global $tbl_user,$tbl_session_rel_user,$id_session;
global $id_session;
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$xajax_response = new xajaxResponse();
$return = '';

@ -1,20 +1,21 @@
<?php
class TestBanner extends UnitTestCase{
class TestBanner extends UnitTestCase
{
public function TestBanner(){
$this->UnitTestCase('Banners library - main/inc/banner.inc.test.php');
}
public function testGetTabs(){
global $_course, $_user;
ob_start();
require_once(api_get_path(SYS_CODE_PATH).'inc/banner.inc.php');
ob_end_clean();
$res = get_tabs();
$this->assertTrue(is_array($res));
$this->assertTrue($res);
//var_dump($res);
}
public function TestBanner()
{
$this->UnitTestCase('Banners library - main/inc/banner.inc.test.php');
}
public function testGetTabs()
{
ob_start();
require_once(api_get_path(SYS_CODE_PATH).'inc/banner.inc.php');
ob_end_clean();
$res = get_tabs();
$this->assertTrue(is_array($res));
$this->assertTrue($res);
//var_dump($res);
}
}
?>

Loading…
Cancel
Save