Minor - format code

pull/2487/head
jmontoyaa 9 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'])) { if (!empty($_POST['submitAuth'])) {
// The user has been already authenticated, we are now to find the last login of the user. // 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); $track_login_table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
$sql = "SELECT UNIX_TIMESTAMP(login_date) $sql = "SELECT UNIX_TIMESTAMP(login_date)
FROM $track_login_table FROM $track_login_table
@ -122,7 +122,7 @@ $useCookieValidation = api_get_setting('cookie_warning');
if ($useCookieValidation === 'true') { if ($useCookieValidation === 'true') {
if (isset($_POST['acceptCookies'])) { if (isset($_POST['acceptCookies'])) {
api_set_site_use_cookie_warning_cookie(); 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()) { if (Template::isToolBarDisplayedForUser()) {
$controller->tpl->assign('toolBarDisplayed', true); $controller->tpl->assign('toolBarDisplayed', true);
} else { } else {

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

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

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

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

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

Loading…
Cancel
Save