Minor - format code

pull/2487/head
jmontoyaa 8 years ago
parent b82ac83a39
commit ed4321b2cb
  1. 4
      index.php
  2. 432
      main/admin/sub_language.php
  3. 506
      main/document/edit_document.php
  4. 34
      main/inc/lib/myspace.lib.php
  5. 423
      main/mySpace/current_courses.php
  6. 595
      main/user/subscribe_user.php

@ -76,7 +76,7 @@ if (!api_get_user_id() && CustomPages::enabled()) {
if (!empty($_POST['submitAuth'])) {
// The user has been already authenticated, we are now to find the last login of the user.
if (isset ($_user['user_id'])) {
if (isset($_user['user_id'])) {
$track_login_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = "SELECT UNIX_TIMESTAMP(login_date)
FROM $track_login_table
@ -122,7 +122,7 @@ $useCookieValidation = api_get_setting('cookie_warning');
if ($useCookieValidation === 'true') {
if (isset($_POST['acceptCookies'])) {
api_set_site_use_cookie_warning_cookie();
} else if (!api_site_use_cookie_warning_cookie_exist()) {
} elseif (!api_site_use_cookie_warning_cookie_exist()) {
if (Template::isToolBarDisplayedForUser()) {
$controller->tpl->assign('toolBarDisplayed', true);
} else {

@ -13,47 +13,48 @@ $this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
$htmlHeadXtra[] ='<script>
$(document).ready(function() {
$(".save").click(function() {
var button_name=$(this).attr("name");
var button_array=button_name.split("|");
var button_name=button_array[1];
var file_id=button_array[2];
var is_variable_language="$"+button_name;
$(".save").click(function() {
var button_name=$(this).attr("name");
var button_array=button_name.split("|");
var button_name=button_array[1];
var file_id=button_array[2];
var is_variable_language="$"+button_name;
var is_new_language = $("#txtid_"+file_id+"_"+button_name).val();
if (is_new_language == undefined) {
is_new_language="_";
}
if (is_new_language.length>0 && is_new_language!="_" && file_id!="" && button_name!="") {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
$("#div_message_information_id").html("<div class=\"alert alert-info\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
},
type: "POST",
url: "../admin/sub_language_ajax.inc.php",
data: {
\'new_language\': is_new_language,
\'variable_language\': is_variable_language,
\'file_id\': file_id,
\'id\': ' . intval($_REQUEST['id']) . ',
var is_new_language = $("#txtid_"+file_id+"_"+button_name).val();
if (is_new_language == undefined) {
is_new_language="_";
}
if (is_new_language.length>0 && is_new_language!="_" && file_id!="" && button_name!="") {
$.ajax({
contentType: "application/x-www-form-urlencoded",
beforeSend: function(objeto) {
$("#div_message_information_id").html("<div class=\"alert alert-info\"><img src=\'../inc/lib/javascript/indicator.gif\' /></div>");
},
type: "POST",
url: "../admin/sub_language_ajax.inc.php",
data: {
\'new_language\': is_new_language,
\'variable_language\': is_variable_language,
\'file_id\': file_id,
\'id\': ' . intval($_REQUEST['id']) . ',
\'sub\': ' . intval($_REQUEST['sub_language_id']) . ',
\'sub_language_id\': ' . intval($_REQUEST['sub_language_id']) . '
},
success: function(datos) {
if (datos == "1") {
$("#div_message_information_id").html(\'' . Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success') . '\');
} else {
$("#div_message_information_id").html("<div class=\"alert alert-warning\">" + datos +"</div>");
}
}
});
} else {
$("#div_message_information_id").html(\'' . Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error') . '\');
}
});
},
success: function(datos) {
if (datos == "1") {
$("#div_message_information_id").html(\'' . Display::return_message(get_lang('TheNewWordHasBeenAdded'), 'success') . '\');
} else {
$("#div_message_information_id").html("<div class=\"alert alert-warning\">" + datos +"</div>");
}
}
});
} else {
$("#div_message_information_id").html(\'' . Display::return_message(get_lang('FormHasErrorsPleaseComplete'), 'error') . '\');
}
});
});
</script>';
/**
* Main code
*/
@ -65,31 +66,31 @@ $interbreadcrumb[] = array ('url' => 'languages.php', 'name' => get_lang('Platfo
$sublanguage_folder_error = false;
if (isset($_GET['id']) && $_GET['id']==strval(intval($_GET['id']))) {
$language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['id']);
$sub_language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['sub_language_id']);
$all_data_of_language = SubLanguageManager::get_all_information_of_language($_GET['id']);
$all_data_of_sublanguage = SubLanguageManager::get_all_information_of_language($_GET['sub_language_id']);
$sub_language_file = api_get_path(SYS_LANG_PATH).$all_data_of_sublanguage['dokeos_folder'];
if (isset($_GET['id']) && $_GET['id'] == strval(intval($_GET['id']))) {
$language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['id']);
$sub_language_name = SubLanguageManager::get_name_of_language_by_id ($_GET['sub_language_id']);
$all_data_of_language = SubLanguageManager::get_all_information_of_language($_GET['id']);
$all_data_of_sublanguage = SubLanguageManager::get_all_information_of_language($_GET['sub_language_id']);
$sub_language_file = api_get_path(SYS_LANG_PATH).$all_data_of_sublanguage['dokeos_folder'];
if (!file_exists($sub_language_file) || !is_writable($sub_language_file)) {
$sublanguage_folder_error = $sub_language_file.' '.get_lang('IsNotWritable');
}
if (SubLanguageManager::check_if_exist_language_by_id($_GET['id'])===true) {
$language_id_exist = true;
} else {
$language_id_exist = false;
}
if (!file_exists($sub_language_file) || !is_writable($sub_language_file)) {
$sublanguage_folder_error = $sub_language_file.' '.get_lang('IsNotWritable');
}
if (SubLanguageManager::check_if_exist_language_by_id($_GET['id'])===true) {
$language_id_exist = true;
} else {
$language_id_exist = false;
}
} else {
$language_name='';
$language_id_exist=false;
$language_name='';
$language_id_exist=false;
}
$intro = sprintf(get_lang('RegisterTermsOfSubLanguageForX'), strtolower($sub_language_name));
$path_folder = api_get_path(SYS_LANG_PATH).$all_data_of_language['dokeos_folder'];
if (!is_dir($path_folder) || strlen($all_data_of_language['dokeos_folder'])==0) {
api_not_allowed(true);
api_not_allowed(true);
}
Display :: display_header($language_name);
@ -114,7 +115,7 @@ $html.='</div>';
echo $html;
echo '<br /><br /><br />';
if (!empty($sublanguage_folder_error)) {
Display::display_warning_message($sublanguage_folder_error);
Display::display_warning_message($sublanguage_folder_error);
}
echo '<div id="div_message_information_id">&nbsp;</div>';
@ -128,195 +129,196 @@ echo '<div id="div_message_information_id">&nbsp;</div>';
* @return array
*/
function search_language_term(
$term,
$search_in_variable = true,
$search_in_english = true,
$search_in_parent = true,
$search_in_sub_language = true
$term,
$search_in_variable = true,
$search_in_english = true,
$search_in_parent = true,
$search_in_sub_language = true
) {
//These the $_REQUEST['id'] and the $_REQUEST['sub_language_id'] variables are process in global.inc.php (LOAD LANGUAGE FILES SECTION)
/*
These 4 arrays are set in global.inc.php with the condition that will be load from sub_language.php or sub_language_ajax.inc.php
$english_language_array
$parent_language_array
$sub_language_array
$language_files_to_load
*/
global $language_files_to_load, $sub_language_array, $english_language_array, $parent_language_array;
$language_files_to_load_keys = array_flip($language_files_to_load);
$array_to_search = $parent_language_array;
$list_info = array();
$term='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
//@todo optimize this foreach
foreach ($language_files_to_load as $lang_file) {
//searching in parent language of the sub language
if ($search_in_parent) {
$variables = $parent_language_array[$lang_file];
foreach ($variables as $parent_name_variable =>$parent_variable_value) {
//arrays are avoided
if (is_array($parent_variable_value)) {
continue;
}
$founded = false;
// searching the item in the parent tool
if (preg_match($term,$parent_variable_value)!==0) {
$founded = true;
}
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable];
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
//These the $_REQUEST['id'] and the $_REQUEST['sub_language_id'] variables are process in global.inc.php (LOAD LANGUAGE FILES SECTION)
/*
These 4 arrays are set in global.inc.php with the condition that will be load from sub_language.php or sub_language_ajax.inc.php
$english_language_array
$parent_language_array
$sub_language_array
$language_files_to_load
*/
global $language_files_to_load, $sub_language_array, $english_language_array, $parent_language_array;
$language_files_to_load_keys = array_flip($language_files_to_load);
$array_to_search = $parent_language_array;
$list_info = array();
$term='/'.Security::remove_XSS(trim($_REQUEST['txt_search_word'])).'/i';
//@todo optimize this foreach
foreach ($language_files_to_load as $lang_file) {
//searching in parent language of the sub language
if ($search_in_parent) {
$variables = $parent_language_array[$lang_file];
foreach ($variables as $parent_name_variable => $parent_variable_value) {
//arrays are avoided
if (is_array($parent_variable_value)) {
continue;
}
$founded = false;
// searching the item in the parent tool
if (preg_match($term, $parent_variable_value) !== 0) {
$founded = true;
}
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = $sub_language_array[$lang_file][$parent_name_variable];
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$parent_name_variable];
//config buttons
/*if (strlen($english_name_variable)>1500) {
$size =20;
} else {
$size =4;
}*/
//config buttons
/*if (strlen($english_name_variable)>1500) {
$size =20;
} else {
$size =4;
}*/
$obj_text='<textarea rows="10" cols="40" name="txt|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$language_files_to_load_keys[$lang_file].'_'.$parent_name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$parent_name_variable.'" />'.get_lang('Save').'</button>';
$obj_text='<textarea rows="10" cols="40" name="txt|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$language_files_to_load_keys[$lang_file].'_'.$parent_name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$parent_name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$parent_name_variable.'" />'.get_lang('Save').'</button>';
$list_info[] = array(
$lang_file . '.inc.php',
$parent_name_variable,
$english_name_variable,
$parent_variable_value,
$obj_text,
$obj_button
);
}
}
}
$list_info[] = array(
$lang_file . '.inc.php',
$parent_name_variable,
$english_name_variable,
$parent_variable_value,
$obj_text,
$obj_button
);
}
}
}
//search in english
if ($search_in_english || $search_in_variable) {
$variables = $english_language_array[$lang_file];
foreach ($variables as $name_variable =>$variable_value) {
if (is_array($variable_value)) {
continue;
}
//search in english
if ($search_in_english || $search_in_variable) {
$variables = $english_language_array[$lang_file];
foreach ($variables as $name_variable => $variable_value) {
if (is_array($variable_value)) {
continue;
}
if (is_array($variable_value))
echo $lang_file;
$founded = false;
if ($search_in_english && $search_in_variable) {
// searching the item in the parent tool
if (preg_match($term,$variable_value)!==0 || preg_match($term,$name_variable)!==0 ) {
$founded = true;
}
} else {
if ($search_in_english) {
if (preg_match($term,$variable_value)!==0) {
$founded = true;
}
} else {
if (preg_match($term,$name_variable)!==0) {
$founded = true;
}
}
}
if (is_array($variable_value)) {
echo $lang_file;
}
$founded = false;
if ($search_in_english && $search_in_variable) {
// searching the item in the parent tool
if (preg_match($term, $variable_value) !== 0 || preg_match($term, $name_variable) !== 0) {
$founded = true;
}
} else {
if ($search_in_english) {
if (preg_match($term, $variable_value) !== 0) {
$founded = true;
}
} else {
if (preg_match($term, $name_variable) !== 0) {
$founded = true;
}
}
}
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = null;
if (isset($sub_language_array[$lang_file][$name_variable])) {
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
}
$parent_variable_value = null;
if (isset($parent_language_array[$lang_file][$name_variable])) {
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
}
//config buttons
$obj_text='<textarea rows="10" cols="40" name="txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$language_files_to_load_keys[$lang_file].'_'.$name_variable.'" >'.
$sub_language_name_variable.'
</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$name_variable.'" />'.get_lang('Save').'</button>';
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = null;
if (isset($sub_language_array[$lang_file][$name_variable])) {
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
}
$parent_variable_value = null;
if (isset($parent_language_array[$lang_file][$name_variable])) {
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
}
//config buttons
$obj_text='<textarea rows="10" cols="40" name="txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$language_files_to_load_keys[$lang_file].'_'.$name_variable.'" >'.
$sub_language_name_variable.'
</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$name_variable.'" />'.get_lang('Save').'</button>';
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$name_variable];
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$name_variable];
$list_info[] = array(
$lang_file . '.inc.php',
$name_variable,
$english_name_variable,
$parent_variable_value,
$obj_text,
$obj_button
);
}
}
}
$list_info[] = array(
$lang_file . '.inc.php',
$name_variable,
$english_name_variable,
$parent_variable_value,
$obj_text,
$obj_button
);
}
}
}
// Search in sub language
if ($search_in_sub_language) {
$variables = $sub_language_array[$lang_file];
foreach ($variables as $name_variable =>$variable_value) {
if (is_array($parent_variable_value)) {
continue;
}
// Search in sub language
if ($search_in_sub_language) {
$variables = $sub_language_array[$lang_file];
foreach ($variables as $name_variable => $variable_value) {
if (is_array($parent_variable_value)) {
continue;
}
if (is_array($variable_value)) {
continue;
}
if (is_array($variable_value)) {
continue;
}
$founded = false;
// searching the item in the parent tool
if (preg_match($term,$variable_value)!==0) {
$founded = true;
}
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
//config buttons
$obj_text='<textarea rows="10" cols="40" name="txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$language_files_to_load_keys[$lang_file].'_'.$name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$name_variable.'" />'.get_lang('Save').'</button>';
$founded = false;
// searching the item in the parent tool
if (preg_match($term, $variable_value) !== 0) {
$founded = true;
}
if ($founded) {
//loading variable from the english array
$sub_language_name_variable = $sub_language_array[$lang_file][$name_variable];
$parent_variable_value = $parent_language_array[$lang_file][$name_variable];
//config buttons
$obj_text='<textarea rows="10" cols="40" name="txt|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="txtid_'.$language_files_to_load_keys[$lang_file].'_'.$name_variable.'" >'.$sub_language_name_variable.'</textarea>';
$obj_button='<button class="save" type="button" name="btn|'.$name_variable.'|'.$language_files_to_load_keys[$lang_file].'" id="btnid_'.$name_variable.'" />'.get_lang('Save').'</button>';
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$name_variable];
$list_info[]=array($lang_file.'.inc.php',
$name_variable,
$english_name_variable,
$parent_variable_value,$obj_text,$obj_button);
}
}
}
}
//loading variable from the english array
$english_name_variable = $english_language_array[$lang_file][$name_variable];
$list_info[]=array($lang_file.'.inc.php',
$name_variable,
$english_name_variable,
$parent_variable_value,$obj_text,$obj_button);
}
}
}
}
$list_info = array_unique_dimensional($list_info);
return $list_info;
$list_info = array_unique_dimensional($list_info);
return $list_info;
}
// Allow see data in sort table
$list_info = array();
if (isset($_REQUEST['txt_search_word'])) {
//@todo fix to accept a char with 1 char
if (strlen(trim($_REQUEST['txt_search_word']))>2) {
$list_info = search_language_term(
$_REQUEST['txt_search_word'],
true,
true,
true,
true
);
}
//@todo fix to accept a char with 1 char
if (strlen(trim($_REQUEST['txt_search_word']))>2) {
$list_info = search_language_term(
$_REQUEST['txt_search_word'],
true,
true,
true,
true
);
}
}
$parameters = array(
'id' => intval($_GET['id']),
'sub_language_id' => intval($_GET['sub_language_id']),
'txt_search_word' => $txt_search_word
'id' => intval($_GET['id']),
'sub_language_id' => intval($_GET['sub_language_id']),
'txt_search_word' => $txt_search_word
);
$table = new SortableTableFromArrayConfig($list_info, 1,20,'data_info');
$table = new SortableTableFromArrayConfig($list_info, 1, 20, 'data_info');
$table->set_additional_parameters($parameters);
$table->set_header(0, get_lang('LanguageFile'));
$table->set_header(1, get_lang('LanguageVariable'));
$table->set_header(2, get_lang('EnglishName'));
$table->set_header(3, get_lang('OriginalName'));
$table->set_header(4, get_lang('Translation'),false);
$table->set_header(5, get_lang('Action'),false);
$table->set_header(4, get_lang('Translation'), false);
$table->set_header(5, get_lang('Action'), false);
$table->display();
Display :: display_footer();

@ -61,7 +61,7 @@ $group_id = api_get_group_id();
$sessionId = api_get_session_id();
if (api_is_in_group()) {
$group_properties = GroupManager::get_group_properties($group_id);
$group_properties = GroupManager::get_group_properties($group_id);
}
$dir = '/';
@ -73,7 +73,7 @@ if (isset($_GET['id'])) {
$_GET['id'],
api_get_course_id(),
true,
0
0
);
if (!empty($sessionId) && empty($document_data)) {
@ -85,13 +85,13 @@ if (isset($_GET['id'])) {
);
}
$document_id = $document_data['id'];
$file = $document_data['path'];
$parent_id = DocumentManager::get_document_id($course_info, dirname($file));
$dir = dirname($document_data['path']);
$dir_original = $dir;
$doc = basename($file);
$readonly = $document_data['readonly'];
$document_id = $document_data['id'];
$file = $document_data['path'];
$parent_id = DocumentManager::get_document_id($course_info, dirname($file));
$dir = dirname($document_data['path']);
$dir_original = $dir;
$doc = basename($file);
$readonly = $document_data['readonly'];
}
if (empty($document_data)) {
@ -113,7 +113,7 @@ $count_dir = count($doc_tree) - 2; // "2" because at the begin and end there are
// Level correction for group documents.
if (!empty($group_properties['directory'])) {
$count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
$count_dir = $count_dir > 0 ? $count_dir - 1 : 0;
}
$relative_url = '';
for ($i = 0; $i < ($count_dir); $i++) {
@ -135,13 +135,13 @@ $editorConfig = array(
);
if ($is_certificate_mode) {
$editorConfig['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/';
$editorConfig['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/';
$editorConfig['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir;
$editorConfig['CreateDocumentDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/';
$editorConfig['CreateDocumentWebDir'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document/';
$editorConfig['BaseHref'] = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.$dir;
}
$is_allowed_to_edit = api_is_allowed_to_edit(null, true) || $groupRights ||
DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $sessionId);
DocumentManager::is_my_shared_folder(api_get_user_id(), $dir, $sessionId);
$noPHP_SELF = true;
/* Other initialization code */
@ -154,8 +154,8 @@ if (!empty($group_id)) {
'url' => api_get_path(WEB_CODE_PATH).'group/group_space.php?'.api_get_cidreq(),
'name' => get_lang('GroupSpace'),
);
$group_document = true;
$noPHP_SELF = true;
$group_document = true;
$noPHP_SELF = true;
}
if (!$is_certificate_mode) {
@ -189,9 +189,9 @@ Event::event_access_tool(TOOL_DOCUMENT);
//TODO:check the below code and his funcionality
if (!api_is_allowed_to_edit()) {
if (DocumentManager::check_readonly($course_info, $user_id, $file)) {
api_not_allowed();
}
if (DocumentManager::check_readonly($course_info, $user_id, $file)) {
api_not_allowed();
}
}
/* MAIN TOOL CODE */
@ -199,18 +199,18 @@ if (!api_is_allowed_to_edit()) {
/* Code to change the comment */
if (isset($_POST['comment'])) {
// Fixing the path if it is wrong
$comment = trim($_POST['comment']);
$title = trim($_POST['title']);
// Fixing the path if it is wrong
$comment = trim($_POST['comment']);
$title = trim($_POST['title']);
// Just in case see BT#3525
if (empty($title)) {
$title = $document_data['title'];
}
$title = $document_data['title'];
}
if (empty($title)) {
$title = get_document_title($_POST['filename']);
}
if (empty($title)) {
$title = get_document_title($_POST['filename']);
}
if (!empty($document_id)) {
$params = [
@ -222,158 +222,156 @@ if (isset($_POST['comment'])) {
$params,
['c_id = ? AND id = ?' => [$course_id, $document_id]]
);
Display::addFlash(Display::return_message(get_lang('fileModified')));
Display::addFlash(Display::return_message(get_lang('fileModified')));
}
}
/* WYSIWYG HTML EDITOR - Program Logic */
if ($is_allowed_to_edit) {
if (isset($_POST['formSent']) && $_POST['formSent'] == 1) {
$filename = stripslashes($_POST['filename']);
if (isset($_POST['formSent']) && $_POST['formSent'] == 1) {
$filename = stripslashes($_POST['filename']);
$extension = $_POST['extension'];
$content = isset($_POST['content']) ? trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))) : null;
$content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY);
$content = isset($_POST['content']) ? trim(str_replace(array("\r", "\n"), '', stripslashes($_POST['content']))) : null;
$content = Security::remove_XSS($content, COURSEMANAGERLOWSECURITY);
if ($dir == '/') {
$dir = '';
}
$file = $dir.'/'.$filename.'.'.$extension;
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null;
$read_only_flag = empty($read_only_flag) ? 0 : 1;
$file = $dir.'/'.$filename.'.'.$extension;
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null;
$read_only_flag = empty($read_only_flag) ? 0 : 1;
if (empty($filename)) {
if (empty($filename)) {
Display::addFlash(Display::return_message(get_lang('NoFileName'), 'warning'));
} else {
} else {
$file_size = filesize($document_data['absolute_path']);
$file_size = filesize($document_data['absolute_path']);
if ($read_only_flag == 0) {
if (!empty($content)) {
if ($fp = @fopen($document_data['absolute_path'], 'w')) {
// For flv player, change absolute path temporarily to prevent from erasing it in the following lines
$content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content);
fputs($fp, $content);
fclose($fp);
if ($read_only_flag == 0) {
if (!empty($content)) {
if ($fp = @fopen($document_data['absolute_path'], 'w')) {
// For flv player, change absolute path temporarily to prevent from erasing it in the following lines
$content = str_replace(array('flv=h', 'flv=/'), array('flv=h|', 'flv=/|'), $content);
fputs($fp, $content);
fclose($fp);
$filepath = $document_data['absolute_parent_path'];
/*
if (!is_dir($filepath.'css')) {
mkdir($filepath.'css', api_get_permissions_for_new_directories());
$doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'FolderCreated',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'invisible',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
}*/
/*if (!is_file($filepath.'css/frames.css')) {
$platform_theme = api_get_setting('stylesheets');
if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css', $filepath.'css/frames.css');
$doc_id = add_document(
$_course,
$dir . 'css/frames.css',
'file',
filesize($filepath . 'css/frames.css'),
'frames.css'
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'DocumentAdded',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'invisible',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
}
}*/
// "WHAT'S NEW" notification: update table item_property
$document_id = DocumentManager::get_document_id($_course, $file);
if ($document_id) {
update_existing_document(
$_course,
$document_id,
$file_size,
$read_only_flag
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$document_id,
'DocumentUpdated',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
// Update parent folders
item_property_update_on_folder(
$_course,
$dir,
api_get_user_id()
);
header('Location: document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''));
exit;
} else {
/*
if (!is_dir($filepath.'css')) {
mkdir($filepath.'css', api_get_permissions_for_new_directories());
$doc_id = add_document($_course, $dir.'css', 'folder', 0, 'css');
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'FolderCreated',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'invisible',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
}*/
/*if (!is_file($filepath.'css/frames.css')) {
$platform_theme = api_get_setting('stylesheets');
if (file_exists(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css')) {
copy(api_get_path(SYS_CODE_PATH).'css/'.$platform_theme.'/frames.css', $filepath.'css/frames.css');
$doc_id = add_document(
$_course,
$dir . 'css/frames.css',
'file',
filesize($filepath . 'css/frames.css'),
'frames.css'
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'DocumentAdded',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$doc_id,
'invisible',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
}
}*/
// "WHAT'S NEW" notification: update table item_property
$document_id = DocumentManager::get_document_id($_course, $file);
if ($document_id) {
update_existing_document(
$_course,
$document_id,
$file_size,
$read_only_flag
);
api_item_property_update(
$_course,
TOOL_DOCUMENT,
$document_id,
'DocumentUpdated',
api_get_user_id(),
null,
null,
null,
null,
$sessionId
);
// Update parent folders
item_property_update_on_folder(
$_course,
$dir,
api_get_user_id()
);
header('Location: document.php?id='.$document_data['parent_id'].'&'.api_get_cidreq().($is_certificate_mode ? '&curdirpath=/certificates&selectcat=1' : ''));
exit;
} else {
Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning'));
}
} else {
}
} else {
Display::addFlash(Display::return_message(get_lang('Impossible'), 'warning'));
}
} else {
if ($document_id) {
}
} else {
if ($document_id) {
update_existing_document($_course, $document_id, $file_size, $read_only_flag);
}
}
} else {
}
}
} else {
if ($document_id) {
update_existing_document($_course, $document_id, $file_size, $read_only_flag);
}
}
}
}
}
}
}
}
// Replace relative paths by absolute web paths (e.g. './' => 'http://www.chamilo.org/courses/ABC/document/')
@ -428,35 +426,35 @@ if ($owner_id == api_get_user_id() ||
$groupInfo
)
) {
$action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq();
$action = api_get_self().'?id='.$document_data['id'].'&'.api_get_cidreq();
if ($is_certificate_mode) {
$action .= '&curdirpath=/certificates&selectcat=1';
}
$form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical'));
// Form title
$form->addElement('header', $nameTools);
$form->addElement('hidden', 'filename');
$form->addElement('hidden', 'extension');
$form->addElement('hidden', 'file_path');
$form->addElement('hidden', 'commentPath');
$form->addElement('hidden', 'showedit');
$form->addElement('hidden', 'origin');
$form->addElement('hidden', 'origin_opt');
$form = new FormValidator('formEdit', 'post', $action, null, array('class' => 'form-vertical'));
// Form title
$form->addElement('header', $nameTools);
$form->addElement('hidden', 'filename');
$form->addElement('hidden', 'extension');
$form->addElement('hidden', 'file_path');
$form->addElement('hidden', 'commentPath');
$form->addElement('hidden', 'showedit');
$form->addElement('hidden', 'origin');
$form->addElement('hidden', 'origin_opt');
$form->addText('title', get_lang('Title'), true, array('cols-size' => [2, 10, 0], 'autofocus'));
$defaults['title'] = $document_data['title'];
$defaults['title'] = $document_data['title'];
$form->addElement('hidden', 'formSent');
$defaults['formSent'] = 1;
$form->addElement('hidden', 'formSent');
$defaults['formSent'] = 1;
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null;
$read_only_flag = isset($_POST['readonly']) ? $_POST['readonly'] : null;
// Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor.
// This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573
$defaults['content'] = str_replace('<!--[', '<!-- [', $content);
// Desactivation of IE proprietary commenting tags inside the text before loading it on the online editor.
// This fix has been proposed by Hubert Borderiou, see Bug #573, http://support.chamilo.org/issues/573
$defaults['content'] = str_replace('<!--[', '<!-- [', $content);
// HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved.
// HotPotatoes tests are html files, but they should not be edited in order their functionality to be preserved.
$showSystemFolders = api_get_course_setting('show_system_folders');
$condition = stripos($dir, '/HotPotatoes_files') === false;
@ -464,44 +462,44 @@ if ($owner_id == api_get_user_id() ||
$condition = true;
}
if (($extension == 'htm' || $extension == 'html') && $condition) {
if (empty($readonly) && $readonly == 0) {
if (($extension == 'htm' || $extension == 'html') && $condition) {
if (empty($readonly) && $readonly == 0) {
$form->addHtmlEditor('content', '', true, true, $editorConfig);
}
}
}
}
if (!$group_document && !DocumentManager::is_my_shared_folder(api_get_user_id(), $currentDirPath, $sessionId)) {
// Updated on field
if (!$group_document && !DocumentManager::is_my_shared_folder(api_get_user_id(), $currentDirPath, $sessionId)) {
// Updated on field
$display_date = date_to_str_ago($last_edit_date).
' <span class="dropbox_date">'.api_format_date(api_get_local_time($last_edit_date)).'</span>';
$form->addElement('static', null, get_lang('UpdatedOn'), $display_date);
}
' <span class="dropbox_date">'.api_format_date(api_get_local_time($last_edit_date)).'</span>';
$form->addElement('static', null, get_lang('UpdatedOn'), $display_date);
}
$form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]);
$form->addElement('textarea', 'comment', get_lang('Comment'), ['cols-size' => [2, 10, 0]]);
if ($owner_id == api_get_user_id() || api_is_platform_admin()) {
$checked = & $form->addElement('checkbox', 'readonly', null, get_lang('ReadOnly'));
if ($readonly == 1) {
$checked->setChecked(true);
}
}
if ($owner_id == api_get_user_id() || api_is_platform_admin()) {
$checked = & $form->addElement('checkbox', 'readonly', null, get_lang('ReadOnly'));
if ($readonly == 1) {
$checked->setChecked(true);
}
}
if ($is_certificate_mode) {
$form->addButtonUpdate(get_lang('SaveCertificate'));
if ($is_certificate_mode) {
$form->addButtonUpdate(get_lang('SaveCertificate'));
} else {
$form->addButtonUpdate(get_lang('SaveDocument'));
$form->addButtonUpdate(get_lang('SaveDocument'));
}
$defaults['filename'] = $filename;
$defaults['extension'] = $extension;
$defaults['file_path'] = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
$defaults['commentPath'] = $file;
$defaults['renameTo'] = $file_name;
$defaults['comment'] = $document_data['comment'];
$defaults['origin'] = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
$defaults['origin_opt'] = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null;
$defaults['filename'] = $filename;
$defaults['extension'] = $extension;
$defaults['file_path'] = isset($_GET['file']) ? Security::remove_XSS($_GET['file']) : null;
$defaults['commentPath'] = $file;
$defaults['renameTo'] = $file_name;
$defaults['comment'] = $document_data['comment'];
$defaults['origin'] = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : null;
$defaults['origin_opt'] = isset($_GET['origin_opt']) ? Security::remove_XSS($_GET['origin_opt']) : null;
$form->setDefaults($defaults);
$form->setDefaults($defaults);
show_return(
$parent_id,
@ -511,26 +509,26 @@ if ($owner_id == api_get_user_id() ||
$is_certificate_mode
);
if ($is_certificate_mode) {
$all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(
api_get_user_id(),
api_get_course_id()
);
$str_info = '';
foreach ($all_information_by_create_certificate[0] as $info_value) {
$str_info .= $info_value.'<br/>';
}
$create_certificate = get_lang('CreateCertificateWithTags');
Display::addFlash(Display::return_message(
$create_certificate.': <br /><br />'.$str_info,
if ($is_certificate_mode) {
$all_information_by_create_certificate = DocumentManager::get_all_info_to_certificate(
api_get_user_id(),
api_get_course_id()
);
$str_info = '';
foreach ($all_information_by_create_certificate[0] as $info_value) {
$str_info .= $info_value.'<br/>';
}
$create_certificate = get_lang('CreateCertificateWithTags');
Display::addFlash(Display::return_message(
$create_certificate.': <br /><br />'.$str_info,
'normal',
false
));
}
}
if ($extension == 'svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
Display::addFlash(Display::return_message(get_lang('BrowserDontSupportsSVG'), 'warning'));
}
if ($extension == 'svg' && !api_browser_support('svg') && api_get_setting('enabled_support_svg') == 'true') {
Display::addFlash(Display::return_message(get_lang('BrowserDontSupportsSVG'), 'warning'));
}
// HTML-editor
echo '<div class="page-create">
<div class="row" style="overflow:hidden">
@ -550,33 +548,33 @@ if ($owner_id == api_get_user_id() ||
Display::display_footer();
/**
This function changes the name of a certain file.
It needs no global variables, it takes all info from parameters.
It returns nothing.
This function changes the name of a certain file.
It needs no global variables, it takes all info from parameters.
It returns nothing.
@todo check if this function is used
*/
function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc)
{
$file_name_for_change = $base_work_dir.$dir.$source_file;
$file_name_for_change = $base_work_dir.$dir.$source_file;
$rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file
$rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API
if ($rename_to) {
if (isset($dir) && $dir != '') {
$source_file = $dir.$source_file;
$new_full_file_name = dirname($source_file).'/'.$rename_to;
} else {
$source_file = '/'.$source_file;
$new_full_file_name = '/'.$rename_to;
}
update_db_info('update', $source_file, $new_full_file_name); // fileManage API
$rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API
if ($rename_to) {
if (isset($dir) && $dir != '') {
$source_file = $dir.$source_file;
$new_full_file_name = dirname($source_file).'/'.$rename_to;
} else {
$source_file = '/'.$source_file;
$new_full_file_name = '/'.$rename_to;
}
update_db_info('update', $source_file, $new_full_file_name); // fileManage API
Display::addFlash(Display::return_message(get_lang('fileModified')));
return true;
} else {
return true;
} else {
Display::addFlash(Display::return_message(get_lang('FileExists')));
}
}
}
//return button back to
@ -587,32 +585,32 @@ function show_return($document_id, $path, $call_from_tool = '', $slide_id = 0, $
global $parent_id;
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id='.$parent_id;
if ($is_certificate_mode) {
$selectedCategory = (isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : '');
$actionsLeft .= '<a href="document.php?curdirpath='.$selectedCategory.'&selectcat='.$selectedCategory.'">'.
if ($is_certificate_mode) {
$selectedCategory = (isset($_GET['curdirpath']) ? Security::remove_XSS($_GET['curdirpath']) : '');
$actionsLeft .= '<a href="document.php?curdirpath='.$selectedCategory.'&selectcat='.$selectedCategory.'">'.
Display::return_icon('back.png', get_lang('Back').' '.get_lang('To').' '.get_lang('CertificateOverview'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.Display::return_icon('expand.png', get_lang('Expand'), array('id'=>'expand'), ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Collapse'), array('id'=>'contract', 'class'=>'hide'), ICON_SIZE_MEDIUM).'</a>';
} elseif ($call_from_tool == 'slideshow') {
$actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'.
} elseif ($call_from_tool == 'slideshow') {
$actionsLeft .= '<a href="'.api_get_path(WEB_PATH).'main/document/slideshow.php?slide_id='.$slide_id.'&curdirpath='.Security::remove_XSS(urlencode($_GET['curdirpath'])).'">'.
Display::return_icon('slideshow.png', get_lang('BackTo').' '.get_lang('ViewSlideshow'), '', ICON_SIZE_MEDIUM).'</a>';
} elseif ($call_from_tool == 'editdraw') {
$actionsLeft .= '<a href="'.$url.'">'.
} elseif ($call_from_tool == 'editdraw') {
$actionsLeft .= '<a href="'.$url.'">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Draw'), array(), 32).'</a>';
} elseif ($call_from_tool == 'editodf') {
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Draw'), array(), 32).'</a>';
} elseif ($call_from_tool == 'editodf') {
$actionsLeft .= '<a href="'.$url.'">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('draw.png', get_lang('BackTo').' '.get_lang('Write'), array(), 32).'</a>';
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.Display::return_icon('expand.png', get_lang('Expand'), array('id'=>'expand'), ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Collapse'), array('id'=>'contract', 'class'=>'hide'), ICON_SIZE_MEDIUM).'</a>';
} elseif ($call_from_tool == 'editpaint') {
$actionsLeft .= '<a href="'.$url.'">'.
$actionsLeft .= '<a href="'.$url.'">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), array(), ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('paint.png', get_lang('BackTo').' '.get_lang('Paint'), array(), 32).'</a>';
} else {
$actionsLeft .= '<a href="'.$url.'">'.
$actionsLeft .= '<a href="javascript:history.back(1)">'.Display::return_icon('paint.png', get_lang('BackTo').' '.get_lang('Paint'), array(), 32).'</a>';
} else {
$actionsLeft .= '<a href="'.$url.'">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('DocumentsOverview'), '', ICON_SIZE_MEDIUM).'</a>';
$actionsLeft .= '<a id="hide_bar_template" href="#" role="button">'.Display::return_icon('expand.png', get_lang('Expand'), array('id'=>'expand'), ICON_SIZE_MEDIUM).Display::return_icon('contract.png', get_lang('Collapse'), array('id'=>'contract', 'class'=>'hide'), ICON_SIZE_MEDIUM).'</a>';
}
}
echo $toolbar = Display::toolbarAction('actions-documents', array($actionsLeft));
}

@ -538,16 +538,19 @@ class MySpace
$table -> display();
}
public static function count_coaches() {
public static function count_coaches()
{
global $total_no_coaches;
return $total_no_coaches;
}
public static function sort_users($a, $b) {
public static function sort_users($a, $b)
{
return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
}
public static function rsort_users($a, $b) {
public static function rsort_users($a, $b)
{
return api_strcmp(trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']])));
}
@ -1613,7 +1616,6 @@ class MySpace
{
// database table definitions
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
// the values of the sortable table
@ -1921,6 +1923,7 @@ class MySpace
* Get all information that the user with user_id = $user_data has
* entered in the additionally defined profile fields
* @param integer $user_id the id of the user
* @return array
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
* @version Dokeos 1.8.6
* @since November 2008
@ -2038,6 +2041,7 @@ class MySpace
* Of course, if in the database there is a user with the name jmontoya,
* the newly created two users registered would be jmontoya2 and jmontoya3.
* @param $users list of users
* @return array
* @author Julio Montoya Armas
*/
function check_all_usernames($users, $course_list, $id_session)
@ -2083,8 +2087,8 @@ class MySpace
* This functions checks whether there are users that are already
* registered in the DB by different creator than the current coach.
* @param string a given username
* @param array the array with the course list ids
* @param the session id
* @param array $users the array with the course list ids
* @return array
* @author Julio Montoya Armas
*/
public function get_user_creator($users)
@ -2151,7 +2155,8 @@ class MySpace
/**
* Adds missing user-information (which isn't required, like password, etc).
*/
function complete_missing_data($user) {
function complete_missing_data($user)
{
// 1. Generate a password if it is necessary.
if (!isset ($user['Password']) || strlen($user['Password']) == 0) {
$user['Password'] = api_generate_password();
@ -2319,7 +2324,8 @@ class MySpace
* @param string $file Path to the CSV-file
* @return array All userinformation read from the file
*/
function parse_csv_data($file) {
function parse_csv_data($file)
{
$users = Import::csvToArray($file);
foreach ($users as $index => $user) {
if (isset ($user['Courses'])) {
@ -2333,7 +2339,8 @@ class MySpace
/**
* XML-parser: the handler at the beginning of element.
*/
function element_start($parser, $data) {
function element_start($parser, $data)
{
$data = api_utf8_decode($data);
global $user;
global $current_tag;
@ -2605,13 +2612,11 @@ class MySpace
//$clicks = Tracking::get_total_clicks_by_session();
$data = array();
while ($user = Database::fetch_assoc($result)) {
$data[] = $user;
}
$return = [];
//TODO: Dont use numeric index
foreach ($data as $key => $info) {
$start_date = $info['col0'];
@ -2745,14 +2750,14 @@ function add_day_to($end_date) {
}
/**
*
*
* @param array
* @author Jorge Frisancho Jibaja
* @version OCT-22- 2010
* @return array
*/
function convert_to_array($sql_result){
function convert_to_array($sql_result)
{
$result_to_print = '<table>';
foreach ($sql_result as $key => $data) {
$result_to_print .= '<tr><td>'.date('d-m-Y (H:i:s)', $data['login']).'</td><td>'.api_time_to_hms($data['logout'] - $data['login']).'</tr></td>'."\n";
@ -2771,7 +2776,8 @@ function convert_to_array($sql_result){
* @version OCT-22- 2010
* @return string
*/
function convert_to_string($sql_result){
function convert_to_string($sql_result)
{
$result_to_print = '<table>';
if (!empty($sql_result)) {
foreach ($sql_result as $key => $data) {

@ -12,7 +12,7 @@ $this_section = SECTION_TRACKING;
$filename = 'reporting.xlsx';
if (!api_is_allowed_to_create_course()) {
api_not_allowed(true);
api_not_allowed(true);
}
$user_id = api_get_user_id();
@ -23,250 +23,249 @@ $i = 0;
$session_id = 0;
if (!empty($my_courses)) {
foreach ($my_courses as $course) {
$course_code = $course['code'];
$course_id = $course['real_id'];
$course_info = api_get_course_info($course_code);
//Only show open courses
if ($course_info['visibility'] == 0) {
continue;
}
$teachers = CourseManager::get_teacher_list_from_course_code($course_code);
$teacher_list = array();
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
$teacher_list[] = $teacher['firstname'].' '.$teacher['lastname'];
}
}
$tmp_students = CourseManager :: get_student_list_from_course_code($course_code, false);
//Cleaning students only REAL students
$students = array();
foreach ($tmp_students as $student) {
$user_info = api_get_user_info($student['user_id']);
if ($user_info['status'] != STUDENT) {
continue;
}
$students[] = $student['user_id'];
}
$t_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql_lp = "SELECT lp.name, lp.id FROM $t_lp lp
WHERE c_id = $course_id AND lp.session_id = 0";
$rs_lp = Database::query($sql_lp);
$t_lpi = Database::get_course_table(TABLE_LP_ITEM);
$t_news = Database::get_course_table(TABLE_ANNOUNCEMENT);
$total_tools_list = Tracking::get_tools_most_used_by_course(
$course_id,
$session_id
);
$total_tools = 0;
foreach ($total_tools_list as $tool) {
$total_tools += $tool['count_access_tool'];
}
if (Database :: num_rows($rs_lp) > 0) {
while ($learnpath = Database :: fetch_array($rs_lp)) {
$lp_id = $learnpath['id'];
$lp_items =
$array[$i]['lp'] = '<a href="'.api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?cidReq='.$course_code.'&amp;action=view&amp;lp_id='.$lp_id.'" target="_blank">'.$learnpath['name'].'</a>';
$array[$i]['teachers'] = '';
if (!empty($teacher_list)) {
$array[$i]['teachers'] = implode(', ', $teacher_list);
}
$array[$i]['course_name'] = $course['title'];
$count_students_accessing = 0;
$count_students_complete_all_activities = 0;
$count_students_complete_all_activities_at_50 = 0;
$total_time_spent = 0;
$total_average_progress = 0;
if (!empty($students)) {
foreach ($students as $student_id) {
$avg_student_progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
$myavg_temp = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id), $session_id);
$avg_progress_in_course = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
if (intval($avg_progress_in_course) == 100) {
$count_students_complete_all_activities++;
}
if (intval($avg_progress_in_course) > 0 && intval($avg_progress_in_course) <= 50) {
$count_students_complete_all_activities_at_50++;
}
$total_average_progress += $avg_progress_in_course;
$time_spent = Tracking::get_time_spent_on_the_course($student_id, $course_id, $session_id);
$total_time_spent += $time_spent;
if (!empty($time_spent)) {
$count_students_accessing++;
}
}
//$total_tools += $nb_assignments + $messages + $links + $chat_last_connection + $documents;
}
$student_count = count($students);
$array[$i]['count_students'] = $student_count;
$array[$i]['count_students_accessing'] = 0;
$array[$i]['count_students_accessing_percentage'] = 0;
$array[$i]['count_students_complete_all_activities_at_50'] = 0;
$array[$i]['count_students_complete_all_activities'] = 0;
$array[$i]['average_percentage_activities_completed_per_student'] = 0;
$array[$i]['total_time_spent'] = 0;
$array[$i]['average_time_spent_per_student'] = 0;
$array[$i]['total_time_spent'] = 0;
$array[$i]['average_time_spent_per_student'] = 0;
//$array[$i]['tools_used'] = 0;
$array[$i]['learnpath_docs'] = 0;
$array[$i]['learnpath_exercises'] = 0;
$array[$i]['learnpath_links'] = 0;
$array[$i]['learnpath_forums'] = 0;
$array[$i]['learnpath_assignments'] = 0;
//registering the number of each category of
//items in learning path
$sql_lpi = "SELECT lpi.item_type FROM $t_lpi lpi
WHERE c_id = $course_id AND lpi.lp_id = $lp_id
ORDER BY item_type";
$res_lpi = Database::query($sql_lpi);
while ($row_lpi = Database::fetch_array($res_lpi)) {
switch ($row_lpi['item_type']) {
case 'document':
$array[$i]['learnpath_docs']++;
break;
case 'quiz':
$array[$i]['learnpath_exercises']++;
break;
case 'link':
$array[$i]['learnpath_links']++;
break;
case 'forum':
case 'thread':
$array[$i]['learnpath_forums']++;
break;
case 'student_publication':
$array[$i]['learnpath_assignments']++;
break;
}
}
// Count announcements
$array[$i]['total_announcements'] = 0;
$sql_news = "SELECT count(id) FROM $t_news WHERE c_id = $course_id ";
$res_news = Database::query($sql_news);
while ($row_news = Database::fetch_array($res_news)) {
$array[$i]['total_announcements'] = $row_news[0];
}
//@todo don't know what means this value
$count_students_complete_all_activities_at_50 = 0;
if (!empty($student_count)) {
$array[$i]['count_students_accessing'] = $count_students_accessing;
$array[$i]['count_students_accessing_percentage'] = round($count_students_accessing / $student_count * 100, 0);
$array[$i]['count_students_complete_all_activities_at_50'] = $count_students_complete_all_activities;
$array[$i]['count_students_complete_all_activities'] = round($count_students_complete_all_activities / $student_count * 100, 0); ;
$array[$i]['average_percentage_activities_completed_per_student'] = round($count_students_complete_all_activities / $student_count * 100, 2);
$array[$i]['total_time_spent'] = 0;
$array[$i]['average_time_spent_per_student'] = 0;
if (!empty($total_time_spent)) {
$array[$i]['total_time_spent'] = api_time_to_hms($total_time_spent);
$array[$i]['average_time_spent_per_student'] = api_time_to_hms($total_time_spent / $student_count);
}
//$array[$i]['tools_used'] = $total_tools;
}
$i++;
}
}
}
foreach ($my_courses as $course) {
$course_code = $course['code'];
$course_id = $course['real_id'];
$course_info = api_get_course_info($course_code);
//Only show open courses
if ($course_info['visibility'] == 0) {
continue;
}
$teachers = CourseManager::get_teacher_list_from_course_code($course_code);
$teacher_list = array();
if (!empty($teachers)) {
foreach ($teachers as $teacher) {
$teacher_list[] = $teacher['firstname'].' '.$teacher['lastname'];
}
}
$tmp_students = CourseManager :: get_student_list_from_course_code($course_code, false);
//Cleaning students only REAL students
$students = array();
foreach ($tmp_students as $student) {
$user_info = api_get_user_info($student['user_id']);
if ($user_info['status'] != STUDENT) {
continue;
}
$students[] = $student['user_id'];
}
$t_lp = Database::get_course_table(TABLE_LP_MAIN);
$sql_lp = "SELECT lp.name, lp.id FROM $t_lp lp
WHERE c_id = $course_id AND lp.session_id = 0";
$rs_lp = Database::query($sql_lp);
$t_lpi = Database::get_course_table(TABLE_LP_ITEM);
$t_news = Database::get_course_table(TABLE_ANNOUNCEMENT);
$total_tools_list = Tracking::get_tools_most_used_by_course(
$course_id,
$session_id
);
$total_tools = 0;
foreach ($total_tools_list as $tool) {
$total_tools += $tool['count_access_tool'];
}
if (Database :: num_rows($rs_lp) > 0) {
while ($learnpath = Database :: fetch_array($rs_lp)) {
$lp_id = $learnpath['id'];
$lp_items =
$array[$i]['lp'] = '<a href="'.api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?cidReq='.$course_code.'&amp;action=view&amp;lp_id='.$lp_id.'" target="_blank">'.$learnpath['name'].'</a>';
$array[$i]['teachers'] = '';
if (!empty($teacher_list)) {
$array[$i]['teachers'] = implode(', ', $teacher_list);
}
$array[$i]['course_name'] = $course['title'];
$count_students_accessing = 0;
$count_students_complete_all_activities = 0;
$count_students_complete_all_activities_at_50 = 0;
$total_time_spent = 0;
$total_average_progress = 0;
if (!empty($students)) {
foreach ($students as $student_id) {
$avg_student_progress = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
$myavg_temp = Tracking::get_avg_student_score($student_id, $course_code, array($lp_id), $session_id);
$avg_progress_in_course = Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
if (intval($avg_progress_in_course) == 100) {
$count_students_complete_all_activities++;
}
if (intval($avg_progress_in_course) > 0 && intval($avg_progress_in_course) <= 50) {
$count_students_complete_all_activities_at_50++;
}
$total_average_progress += $avg_progress_in_course;
$time_spent = Tracking::get_time_spent_on_the_course($student_id, $course_id, $session_id);
$total_time_spent += $time_spent;
if (!empty($time_spent)) {
$count_students_accessing++;
}
}
//$total_tools += $nb_assignments + $messages + $links + $chat_last_connection + $documents;
}
$student_count = count($students);
$array[$i]['count_students'] = $student_count;
$array[$i]['count_students_accessing'] = 0;
$array[$i]['count_students_accessing_percentage'] = 0;
$array[$i]['count_students_complete_all_activities_at_50'] = 0;
$array[$i]['count_students_complete_all_activities'] = 0;
$array[$i]['average_percentage_activities_completed_per_student'] = 0;
$array[$i]['total_time_spent'] = 0;
$array[$i]['average_time_spent_per_student'] = 0;
$array[$i]['total_time_spent'] = 0;
$array[$i]['average_time_spent_per_student'] = 0;
//$array[$i]['tools_used'] = 0;
$array[$i]['learnpath_docs'] = 0;
$array[$i]['learnpath_exercises'] = 0;
$array[$i]['learnpath_links'] = 0;
$array[$i]['learnpath_forums'] = 0;
$array[$i]['learnpath_assignments'] = 0;
//registering the number of each category of
//items in learning path
$sql_lpi = "SELECT lpi.item_type FROM $t_lpi lpi
WHERE c_id = $course_id AND lpi.lp_id = $lp_id
ORDER BY item_type";
$res_lpi = Database::query($sql_lpi);
while ($row_lpi = Database::fetch_array($res_lpi)) {
switch ($row_lpi['item_type']) {
case 'document':
$array[$i]['learnpath_docs']++;
break;
case 'quiz':
$array[$i]['learnpath_exercises']++;
break;
case 'link':
$array[$i]['learnpath_links']++;
break;
case 'forum':
case 'thread':
$array[$i]['learnpath_forums']++;
break;
case 'student_publication':
$array[$i]['learnpath_assignments']++;
break;
}
}
// Count announcements
$array[$i]['total_announcements'] = 0;
$sql_news = "SELECT count(id) FROM $t_news WHERE c_id = $course_id ";
$res_news = Database::query($sql_news);
while ($row_news = Database::fetch_array($res_news)) {
$array[$i]['total_announcements'] = $row_news[0];
}
//@todo don't know what means this value
$count_students_complete_all_activities_at_50 = 0;
if (!empty($student_count)) {
$array[$i]['count_students_accessing'] = $count_students_accessing;
$array[$i]['count_students_accessing_percentage'] = round($count_students_accessing / $student_count * 100, 0);
$array[$i]['count_students_complete_all_activities_at_50'] = $count_students_complete_all_activities;
$array[$i]['count_students_complete_all_activities'] = round($count_students_complete_all_activities / $student_count * 100, 0); ;
$array[$i]['average_percentage_activities_completed_per_student'] = round($count_students_complete_all_activities / $student_count * 100, 2);
$array[$i]['total_time_spent'] = 0;
$array[$i]['average_time_spent_per_student'] = 0;
if (!empty($total_time_spent)) {
$array[$i]['total_time_spent'] = api_time_to_hms($total_time_spent);
$array[$i]['average_time_spent_per_student'] = api_time_to_hms($total_time_spent / $student_count);
}
//$array[$i]['tools_used'] = $total_tools;
}
$i++;
}
}
}
}
$headers = array(
get_lang('LearningPath'),
get_lang('Teachers'),
get_lang('Courses'),
get_lang('NumberOfStudents'),
get_lang('NumberStudentsAccessingCourse'),
get_lang('PercentageStudentsAccessingCourse'),
get_lang('NumberStudentsCompleteAllActivities'),
get_lang('PercentageStudentsCompleteAllActivities'),
get_lang('AverageOfActivitiesCompletedPerStudent'),
get_lang('TotalTimeSpentInTheCourse'),
get_lang('AverageTimePerStudentInCourse'),
get_lang('NumberOfDocumentsInLearnpath'),
get_lang('NumberOfExercisesInLearnpath'),
get_lang('NumberOfLinksInLearnpath'),
get_lang('NumberOfForumsInLearnpath'),
get_lang('NumberOfAssignmentsInLearnpath'),
get_lang('NumberOfAnnouncementsInCourse'),
get_lang('LearningPath'),
get_lang('Teachers'),
get_lang('Courses'),
get_lang('NumberOfStudents'),
get_lang('NumberStudentsAccessingCourse'),
get_lang('PercentageStudentsAccessingCourse'),
get_lang('NumberStudentsCompleteAllActivities'),
get_lang('PercentageStudentsCompleteAllActivities'),
get_lang('AverageOfActivitiesCompletedPerStudent'),
get_lang('TotalTimeSpentInTheCourse'),
get_lang('AverageTimePerStudentInCourse'),
get_lang('NumberOfDocumentsInLearnpath'),
get_lang('NumberOfExercisesInLearnpath'),
get_lang('NumberOfLinksInLearnpath'),
get_lang('NumberOfForumsInLearnpath'),
get_lang('NumberOfAssignmentsInLearnpath'),
get_lang('NumberOfAnnouncementsInCourse'),
);
if (isset($_GET['export'])) {
global $charset;
global $charset;
$spreadsheet = new PHPExcel();
$spreadsheet->setActiveSheetIndex(0);
$worksheet = $spreadsheet->getActiveSheet();
$line = 0;
$column = 0; //skip the first column (row titles)
foreach ($headers as $header) {
$worksheet->setCellValueByColumnAndRow($column, $line, $header);
$column++;
}
$line++;
foreach ($array as $row) {
$column = 0;
foreach ($row as $item) {
$line = 0;
$column = 0; //skip the first column (row titles)
foreach ($headers as $header) {
$worksheet->setCellValueByColumnAndRow($column, $line, $header);
$column++;
}
$line++;
foreach ($array as $row) {
$column = 0;
foreach ($row as $item) {
$worksheet->setCellValueByColumnAndRow(
$column,
$line,
html_entity_decode(strip_tags($item))
);
$column++;
}
$line++;
}
$line++;
$column++;
}
$line++;
}
$line++;
$file = api_get_path(SYS_ARCHIVE_PATH).api_replace_dangerous_char($filename);
$writer = new PHPExcel_Writer_Excel2007($spreadsheet);
$writer->save($file);
DocumentManager::file_send_for_download($file, true, $filename);
exit;
exit;
}
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('MySpace'));
Display::display_header(get_lang('CurrentCourses'));
$table = new HTML_Table(array('class' => 'data_table'));
$row = 0;
$column = 0;
foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header);
$column++;
$table->setHeaderContents($row, $column, $header);
$column++;
}
$row++;
foreach ($array as $row_table) {
$column = 0;
foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell);
//$table->updateCellAttributes($row, $column, 'align="center"');
$column++;
}
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++;
$column = 0;
foreach ($row_table as $cell) {
$table->setCellContents($row, $column, $cell);
//$table->updateCellAttributes($row, $column, 'align="center"');
$column++;
}
$table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
$row++;
}
echo '<div class="actions">';

@ -27,7 +27,7 @@ if (api_get_setting('allow_user_course_subscription_by_course_admin') === 'false
// Access restriction
if (!api_is_allowed_to_edit()) {
api_not_allowed(true);
api_not_allowed(true);
}
$tool_name = get_lang("SubscribeUserToCourse");
@ -37,7 +37,7 @@ $keyword = isset($_REQUEST['keyword']) ? Security::remove_XSS($_REQUEST['keyword
$courseInfo = api_get_course_info();
if ($type == COURSEMANAGER) {
$tool_name = get_lang("SubscribeUserToCourseAsTeacher");
$tool_name = get_lang("SubscribeUserToCourseAsTeacher");
}
//extra entries in breadcrumb
@ -50,7 +50,7 @@ if ($keyword) {
"url" => "subscribe_user.php?type=".$type.'&'.api_get_cidreq(),
"name" => $tool_name
);
$tool_name = get_lang('SearchResults');
$tool_name = get_lang('SearchResults');
}
$sessionId = api_get_session_id();
@ -130,10 +130,10 @@ $sort_by_first_name = api_sort_by_first_name();
// Build table
$table = new SortableTable(
'subscribe_users',
'get_number_of_users',
'get_user_data',
($is_western_name_order xor $sort_by_first_name) ? 3 : 2
'subscribe_users',
'get_number_of_users',
'get_user_data',
($is_western_name_order xor $sort_by_first_name) ? 3 : 2
);
$parameters['keyword'] = $keyword;
$parameters['type'] = $type;
@ -220,28 +220,28 @@ Display::display_footer();
*/
function get_number_of_users()
{
// Database table definition
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
// Database table definition
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$courseCode = api_get_course_id();
$sessionId = api_get_session_id();
if (isset($_REQUEST['type']) && $_REQUEST['type'] === 'teacher') {
if (api_get_session_id() != 0) {
$sql = "SELECT COUNT(u.id)
FROM $user_table u
LEFT JOIN $tbl_session_rel_course_user cu
ON
u.user_id = cu.user_id AND
c_id = '".api_get_course_int_id()."' AND
session_id ='".$sessionId."'
WHERE
cu.user_id IS NULL AND
u.status = 1 AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
if (isset($_REQUEST['type']) && $_REQUEST['type'] === 'teacher') {
if (api_get_session_id() != 0) {
$sql = "SELECT COUNT(u.id)
FROM $user_table u
LEFT JOIN $tbl_session_rel_course_user cu
ON
u.user_id = cu.user_id AND
c_id = '".api_get_course_int_id()."' AND
session_id ='".$sessionId."'
WHERE
cu.user_id IS NULL AND
u.status = 1 AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
if (api_is_multiple_url_enabled()) {
$url_access_id = api_get_current_access_url_id();
@ -399,11 +399,11 @@ function get_number_of_users()
$count_user = 0;
if ($res) {
$row = Database::fetch_row($res);
$count_user = $row[0];
$row = Database::fetch_row($res);
$count_user = $row[0];
}
return $count_user;
return $count_user;
}
/**
* Get the users to display on the current page.
@ -413,17 +413,17 @@ function get_user_data($from, $number_of_items, $column, $direction)
$url_access_id = api_get_current_access_url_id();
$course_code = api_get_course_id();
$sessionId = api_get_session_id();
$courseId = api_get_course_int_id();
$courseId = api_get_course_int_id();
// Database table definitions
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
// Database table definitions
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_rel_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$tbl_url_rel_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
// adding teachers
$is_western_name_order = api_is_western_name_order();
$is_western_name_order = api_is_western_name_order();
if (api_get_setting('show_email_addresses') === 'true') {
$select_fields = "u.id AS col0,
@ -447,234 +447,230 @@ function get_user_data($from, $number_of_items, $column, $direction)
u.active AS col4,
u.user_id AS col5";
}
if (isset($_REQUEST['type']) && $_REQUEST['type'] == COURSEMANAGER) {
// adding a teacher through a session
if (!empty($sessionId)) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $tbl_session_rel_course_user cu
ON
u.user_id = cu.user_id AND
c_id ='".$courseId."' AND
session_id ='".$sessionId."'
if (isset($_REQUEST['type']) && $_REQUEST['type'] == COURSEMANAGER) {
// adding a teacher through a session
if (!empty($sessionId)) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $tbl_session_rel_course_user cu
ON
u.user_id = cu.user_id AND
c_id ='".$courseId."' AND
session_id ='".$sessionId."'
INNER JOIN $tbl_url_rel_user as url_rel_user
ON (url_rel_user.user_id = u.user_id) ";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status = 1 AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status = 1 AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status=1 AND (u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
}
$sql .= " AND access_url_id = $url_access_id";
} else {
// adding a teacher NOT through a session
$sql = "SELECT $select_fields
} else {
// adding a teacher NOT through a session
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $course_user_table cu
ON u.user_id = cu.user_id AND c_id = '".$courseId."'";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." ";
}
// adding a teacher NOT trough a session on a portal with multiple URLs
if (api_is_multiple_url_enabled()) {
if ($url_access_id != -1) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $course_user_table cu
ON u.user_id = cu.user_id and c_id='".$courseId."'
INNER JOIN $tbl_url_rel_user as url_rel_user
ON (url_rel_user.user_id = u.user_id) ";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." ";
}
// adding a teacher NOT trough a session on a portal with multiple URLs
if (api_is_multiple_url_enabled()) {
if ($url_access_id != -1) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $course_user_table cu
ON u.user_id = cu.user_id and c_id='".$courseId."'
INNER JOIN $tbl_url_rel_user as url_rel_user
ON (url_rel_user.user_id = u.user_id) ";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." AND access_url_id= $url_access_id ";
}
}
}
}
} else {
// adding a student
if (!empty($sessionId)) {
$sql = "SELECT $select_fields
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." AND access_url_id= $url_access_id ";
}
}
}
}
} else {
// adding a student
if (!empty($sessionId)) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $tbl_session_rel_course_user cu
ON
u.user_id = cu.user_id AND
c_id ='".$courseId."' AND
session_id ='".$sessionId."' ";
u.user_id = cu.user_id AND
c_id ='".$courseId."' AND
session_id ='".$sessionId."' ";
if (api_is_multiple_url_enabled()) {
$sql .= " INNER JOIN $tbl_url_rel_user as url_rel_user ON (url_rel_user.user_id = u.user_id) ";
}
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) AND !empty($_GET['subscribe_user_filter_value'])) {
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value'])
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
cu.user_id IS NULL AND
u.status<>".DRH." AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
cu.user_id IS NULL AND
u.status<>".DRH." AND
(u.official_code <> 'ADMIN' OR u.official_code IS NULL) ";
}
if (api_is_multiple_url_enabled()) {
$sql .= "AND access_url_id = $url_access_id";
}
} else {
} else {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $course_user_table cu
ON
u.user_id = cu.user_id AND
c_id ='".$courseId."'";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) && !empty($_GET['subscribe_user_filter_value'])) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." ";
}
//showing only the courses of the current Chamilo access_url_id
if (api_is_multiple_url_enabled()) {
if ($url_access_id != -1) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $course_user_table cu
ON u.user_id = cu.user_id AND c_id='".$courseId."'
INNER JOIN $tbl_url_rel_user as url_rel_user
ON (url_rel_user.user_id = u.user_id) ";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."' AND
access_url_id = $url_access_id
u.user_id = cu.user_id AND
c_id ='".$courseId."'";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) && !empty($_GET['subscribe_user_filter_value'])) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."'";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." ";
}
//showing only the courses of the current Chamilo access_url_id
if (api_is_multiple_url_enabled()) {
if ($url_access_id != -1) {
$sql = "SELECT $select_fields
FROM $user_table u
LEFT JOIN $course_user_table cu
ON u.user_id = cu.user_id AND c_id='".$courseId."'
INNER JOIN $tbl_url_rel_user as url_rel_user
ON (url_rel_user.user_id = u.user_id) ";
// applying the filter of the additional user profile fields
if (isset($_GET['subscribe_user_filter_value']) &&
!empty($_GET['subscribe_user_filter_value']) &&
api_get_setting('ProfilingFilterAddingUsers') == 'true'
) {
$field_identification = explode('*', $_GET['subscribe_user_filter_value']);
$sql .= "
LEFT JOIN $table_user_field_values field_values
ON field_values.item_id = u.user_id
WHERE
cu.user_id IS NULL AND
u.status<>".DRH." AND
field_values.field_id = '".intval($field_identification[0])."' AND
field_values.value = '".Database::escape_string($field_identification[1])."' AND
access_url_id = $url_access_id
";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." AND access_url_id= $url_access_id ";
}
}
}
}
}
// adding additional WHERE statements to the SQL for the search functionality
if (isset($_REQUEST['keyword'])) {
$keyword = Database::escape_string(trim($_REQUEST['keyword']));
$sql .= " AND (
firstname LIKE '%".$keyword."%' OR
lastname LIKE '%".$keyword."%' OR
email LIKE '%".$keyword."%' OR
username LIKE '%".$keyword."%' OR
official_code LIKE '%".$keyword."%'
)
";
if (api_get_setting('ProfilingFilterAddingUsers') === 'true') {
// we also want to search for users who have something in
// their profile fields that matches the keyword
$additional_users = search_additional_profile_fields($keyword);
}
// getting all the users of the course (to make sure that we do not
// display users that are already in the course)
if (!empty($sessionId)) {
$a_course_users = CourseManager :: get_user_list_from_course_code($course_code, $sessionId);
} else {
$a_course_users = CourseManager :: get_user_list_from_course_code($course_code, 0);
}
foreach ($a_course_users as $user_id=>$course_user) {
$users_of_course[] = $course_user['user_id'];
}
}
$sql .= " AND u.status != ".ANONYMOUS." ";
// Sorting and pagination (used by the sortable table)
$sql .= " ORDER BY col$column $direction ";
} else {
$sql .= "WHERE cu.user_id IS NULL AND u.status<>".DRH." AND access_url_id= $url_access_id ";
}
}
}
}
}
// adding additional WHERE statements to the SQL for the search functionality
if (isset($_REQUEST['keyword'])) {
$keyword = Database::escape_string(trim($_REQUEST['keyword']));
$sql .= " AND (
firstname LIKE '%".$keyword."%' OR
lastname LIKE '%".$keyword."%' OR
email LIKE '%".$keyword."%' OR
username LIKE '%".$keyword."%' OR
official_code LIKE '%".$keyword."%'
)
";
if (api_get_setting('ProfilingFilterAddingUsers') === 'true') {
// we also want to search for users who have something in
// their profile fields that matches the keyword
$additional_users = search_additional_profile_fields($keyword);
}
// getting all the users of the course (to make sure that we do not
// display users that are already in the course)
if (!empty($sessionId)) {
$a_course_users = CourseManager :: get_user_list_from_course_code($course_code, $sessionId);
} else {
$a_course_users = CourseManager :: get_user_list_from_course_code($course_code, 0);
}
foreach ($a_course_users as $user_id => $course_user) {
$users_of_course[] = $course_user['user_id'];
}
}
$sql .= " AND u.status != ".ANONYMOUS." ";
// Sorting and pagination (used by the sortable table)
$sql .= " ORDER BY col$column $direction ";
$from = (int) $from;
$number_of_items = (int) $number_of_items;
$sql .= " LIMIT $from, $number_of_items";
$sql .= " LIMIT $from, $number_of_items";
$res = Database::query($sql);
$users = array();
while ($user = Database::fetch_row($res)) {
$users[] = $user;
}
$res = Database::query($sql);
$users = array();
while ($user = Database::fetch_row($res)) {
$users[] = $user;
}
return $users;
return $users;
}
/**
* Returns a mailto-link
@ -683,7 +679,7 @@ function get_user_data($from, $number_of_items, $column, $direction)
*/
function email_filter($email)
{
return Display :: encrypted_mailto_link($email, $email);
return Display :: encrypted_mailto_link($email, $email);
}
/**
* Build the reg-column of the table
@ -699,10 +695,10 @@ function reg_filter($user_id)
}
$user_id = (int) $user_id;
$result = '<a class="btn btn-small btn-primary" href="'.api_get_self().'?'.api_get_cidreq().'&register=yes&type='.$type.'&user_id='.$user_id.'">'.
$result = '<a class="btn btn-small btn-primary" href="'.api_get_self().'?'.api_get_cidreq().'&register=yes&type='.$type.'&user_id='.$user_id.'">'.
get_lang("reg").'</a>';
return $result;
return $result;
}
/**
@ -715,7 +711,7 @@ function reg_filter($user_id)
*/
function active_filter($active, $url_params, $row)
{
$_user = api_get_user_info();
$_user = api_get_user_info();
if ($active == '1') {
$action = 'AccountActive';
$image = 'accept';
@ -724,15 +720,20 @@ function active_filter($active, $url_params, $row)
if ($active == '0') {
$action = 'AccountInactive';
$image = 'error';
}
}
$result = '';
if ($row['0'] <> $_user['user_id']) {
// you cannot lock yourself out otherwise you could disable all the accounts
// including your own => everybody is locked out and nobody can change it anymore.
$result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array(), ICON_SIZE_TINY);
}
// you cannot lock yourself out otherwise you could disable all the accounts
// including your own => everybody is locked out and nobody can change it anymore.
$result = Display::return_icon(
$image.'.png',
get_lang(ucfirst($action)),
array(),
ICON_SIZE_TINY
);
}
return $result;
return $result;
}
/**
@ -750,50 +751,50 @@ function active_filter($active, $url_params, $row)
*/
function search_additional_profile_fields($keyword)
{
// database table definitions
$table_user_field_options = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS);
$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
// database table definitions
$table_user_field_options = Database::get_main_table(TABLE_EXTRA_FIELD_OPTIONS);
$table_user_field_values = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$tableExtraField = Database::get_main_table(TABLE_EXTRA_FIELD);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$table_user = Database::get_main_table(TABLE_MAIN_USER);
$keyword = Database::escape_string($keyword);
// getting the field option text that match this keyword (for radio buttons and checkboxes)
$sql = "SELECT * FROM $table_user_field_options
WHERE display_text LIKE '%".$keyword."%'";
$result_profiling = Database::query($sql);
while ($profiling_field_options = Database::fetch_array($result_profiling)) {
$profiling_field_options_exact_values[] = $profiling_field_options;
}
// getting the field option text that match this keyword (for radio buttons and checkboxes)
$sql = "SELECT * FROM $table_user_field_options
WHERE display_text LIKE '%".$keyword."%'";
$result_profiling = Database::query($sql);
while ($profiling_field_options = Database::fetch_array($result_profiling)) {
$profiling_field_options_exact_values[] = $profiling_field_options;
}
$profiling_field_options_exact_values_sql = '';
foreach ($profiling_field_options_exact_values as $profilingkey => $profilingvalue) {
$profiling_field_options_exact_values_sql .= " OR (field_id = '".$profilingvalue['field_id']."' AND value='".$profilingvalue['option_value']."') ";
}
foreach ($profiling_field_options_exact_values as $profilingkey => $profilingvalue) {
$profiling_field_options_exact_values_sql .= " OR (field_id = '".$profilingvalue['field_id']."' AND value='".$profilingvalue['option_value']."') ";
}
$extraFieldType = ExtraField::USER_FIELD_TYPE;
// getting all the user ids of the users who have chosen on of the predefined fields that contain the keyword
// or all the users who have entered the keyword in a free-form field
$sql = "SELECT
user.user_id as col0,
user.official_code as col1,
user.lastname as col2,
user.firstname as col3,
user.email as col4,
user.active as col5,
user.user_id as col6
// getting all the user ids of the users who have chosen on of the predefined fields that contain the keyword
// or all the users who have entered the keyword in a free-form field
$sql = "SELECT
user.user_id as col0,
user.official_code as col1,
user.lastname as col2,
user.firstname as col3,
user.email as col4,
user.active as col5,
user.user_id as col6
FROM $table_user user, $table_user_field_values user_values, $tableExtraField e
WHERE
user.user_id = user_values.item_id AND
user_values.field_id = e.id AND
e.extra_field_type = $extraFieldType AND
(value LIKE '%".$keyword."%'".$profiling_field_options_exact_values_sql.")";
$result = Database::query($sql);
$result = Database::query($sql);
$additional_users = array();
while ($profiled_users = Database::fetch_array($result)) {
$additional_users[$profiled_users['col0']] = $profiled_users;
}
while ($profiled_users = Database::fetch_array($result)) {
$additional_users[$profiled_users['col0']] = $profiled_users;
}
return $additional_users;
return $additional_users;
}
/**
@ -805,44 +806,44 @@ function search_additional_profile_fields($keyword)
*/
function display_extra_profile_fields_filter()
{
// getting all the additional user profile fields
// getting all the additional user profile fields
$extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
$return = '<option value="">'.get_lang('SelectFilter').'</option>';
// looping through the additional user profile fields
foreach ($extra as $id => $field_details) {
// $field_details[2] contains the type of the additional user profile field
switch ($field_details[2]) {
// text fields cannot be used as a filter
case ExtraFieldModel::FIELD_TYPE_TEXT:
break;
// text area fields cannot be used as a filter
case ExtraFieldModel::FIELD_TYPE_TEXTAREA:
break;
case ExtraFieldModel::FIELD_TYPE_RADIO:
case ExtraFieldModel::FIELD_TYPE_SELECT:
case ExtraFieldModel::FIELD_TYPE_SELECT_MULTIPLE:
$return .= '<optgroup label="'.$field_details[3].'">';
foreach ($field_details[9] as $option_id => $option_details) {
if (isset($_GET['subscribe_user_filter_value']) &&
$return = '<option value="">'.get_lang('SelectFilter').'</option>';
// looping through the additional user profile fields
foreach ($extra as $id => $field_details) {
// $field_details[2] contains the type of the additional user profile field
switch ($field_details[2]) {
// text fields cannot be used as a filter
case ExtraFieldModel::FIELD_TYPE_TEXT:
break;
// text area fields cannot be used as a filter
case ExtraFieldModel::FIELD_TYPE_TEXTAREA:
break;
case ExtraFieldModel::FIELD_TYPE_RADIO:
case ExtraFieldModel::FIELD_TYPE_SELECT:
case ExtraFieldModel::FIELD_TYPE_SELECT_MULTIPLE:
$return .= '<optgroup label="'.$field_details[3].'">';
foreach ($field_details[9] as $option_id => $option_details) {
if (isset($_GET['subscribe_user_filter_value']) &&
$_GET['subscribe_user_filter_value'] == $field_details[0].'*'.$option_details[1]
) {
$selected = 'selected="selected"';
} else {
$selected = false;
}
$return .= '<option value="'.$field_details[0].'*'.$option_details[1].'" '.$selected.'>'.$option_details[2].'</option>';
}
$return .= '</optgroup>';
break;
}
}
$html = '<form class="form-inline" id="subscribe_user_filter" name="subscribe_user_filter" method="get" action="'.api_get_self().'?'.api_get_cidreq().'">';
$html .= '<input type="hidden" name="type" id="type" value="'.Security::remove_XSS($_REQUEST['type']).'" />';
$html .= '<select name="subscribe_user_filter_value" id="subscribe_user_filter_value">'.$return.'</select>';
$html .= '<button type="submit" name="submit_filter" id="submit_filter" value="" class="search">'.get_lang('Filter').'</button>';
$html .= '</form>';
$selected = 'selected="selected"';
} else {
$selected = false;
}
$return .= '<option value="'.$field_details[0].'*'.$option_details[1].'" '.$selected.'>'.$option_details[2].'</option>';
}
$return .= '</optgroup>';
break;
}
}
$html = '<form class="form-inline" id="subscribe_user_filter" name="subscribe_user_filter" method="get" action="'.api_get_self().'?'.api_get_cidreq().'">';
$html .= '<input type="hidden" name="type" id="type" value="'.Security::remove_XSS($_REQUEST['type']).'" />';
$html .= '<select name="subscribe_user_filter_value" id="subscribe_user_filter_value">'.$return.'</select>';
$html .= '<button type="submit" name="submit_filter" id="submit_filter" value="" class="search">'.get_lang('Filter').'</button>';
$html .= '</form>';
return $html;
}

Loading…
Cancel
Save