Minor - format code

remotes/angel/1.11.x
jmontoyaa 8 years ago
parent f7b24a3e1f
commit e5aa8199bf
  1. 276
      main/admin/ldap_users_list.php
  2. 28
      main/inc/lib/attendance.lib.php
  3. 63
      main/inc/lib/myspace.lib.php
  4. 493
      main/session/session_export.php

@ -1,11 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @author Mustapha Alouani
* @package chamilo.admin
*/
/**
* Init
* @author Mustapha Alouani
* @package chamilo.admin
*/
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
@ -20,13 +17,13 @@ $login_as_user_id = @$_GET["user_id"] ?: null;
// Login as ...
if ($action == "login_as" && !empty ($login_as_user_id))
{
login_user($login_as_user_id);
login_user($login_as_user_id);
}
//if we already have a session id and a user...
/*
if (($_GET['action']=="add_user") && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && $_GET['id_session']>0 ){
header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']);
header('Location: ldap_import_students_to_session.php?id_session='.$_GET['id_session'].'&ldap_user='.$_GET['id']);
}
*/
@ -37,151 +34,126 @@ $tool_name = get_lang('SearchLDAPUsers');
if (isset ($_GET['action']))
{
$check = Security::check_token('get');
if ($check)
{
switch ($_GET['action'])
{
case 'show_message' :
Display::addFlash(Display::return_message($_GET['message'], 'normal'));
$check = Security::check_token('get');
if ($check) {
switch ($_GET['action']) {
case 'show_message':
Display::addFlash(Display::return_message($_GET['message'], 'normal'));
Display::display_header($tool_name);
break;
case 'delete_user' :
if ($user_id != $_user['user_id'] && UserManager::delete_user($_GET['user_id']))
{
Display::addFlash(Display::return_message(get_lang('UserDeleted'), 'normal'));
}
else
{
Display::addFlash(Display::return_message(get_lang('CannotDeleteUser'), 'error'));
}
break;
case 'delete_user':
if ($user_id != $_user['user_id'] && UserManager::delete_user($_GET['user_id'])) {
Display::addFlash(Display::return_message(get_lang('UserDeleted'), 'normal'));
} else {
Display::addFlash(Display::return_message(get_lang('CannotDeleteUser'), 'error'));
}
Display::display_header($tool_name);
break;
case 'lock' :
$message = lock_unlock_user('lock', $_GET['user_id']);
Display::addFlash(Display::return_message($message, 'normal'));
break;
case 'lock':
$message = lock_unlock_user('lock', $_GET['user_id']);
Display::addFlash(Display::return_message($message, 'normal'));
Display::display_header($tool_name);
break;
case 'unlock':
$message = lock_unlock_user('unlock', $_GET['user_id']);
Display::addFlash(Display::return_message($message, 'normal'));
break;
case 'unlock':
$message = lock_unlock_user('unlock', $_GET['user_id']);
Display::addFlash(Display::return_message($message, 'normal'));
Display::display_header($tool_name);
break;
break;
case 'add_user':
$id = $_GET['id'];
$UserList = array();
$userid_match_login = array();
foreach ($id as $user_id) {
$tmp = ldap_add_user($user_id);
$UserList[] = $tmp;
$userid_match_login[$tmp] = $user_id;
}
if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session'] > 0)) {
ldap_add_user_to_session($UserList, $_GET['id_session']);
header('Location: resume_session.php?id_session='.intval($_GET['id_session']));
} else {
Display::display_header($tool_name);
if (count($userid_match_login) > 0)
{
$message = get_lang('LDAPUsersAddedOrUpdated').':<br />';
foreach ($userid_match_login as $user_id => $login)
{
$message .= '- '.$login.'<br />';
}
}
else
{
$message = get_lang('NoUserAdded');
}
Display::addFlash(Display::return_message($message, 'normal', false));
$id = $_GET['id'];
$UserList = array();
$userid_match_login = array();
foreach ($id as $user_id) {
$tmp = ldap_add_user($user_id);
$UserList[] = $tmp;
$userid_match_login[$tmp] = $user_id;
}
if (isset($_GET['id_session']) && ($_GET['id_session'] == strval(intval($_GET['id_session']))) && ($_GET['id_session'] > 0)) {
ldap_add_user_to_session($UserList, $_GET['id_session']);
header('Location: resume_session.php?id_session='.intval($_GET['id_session']));
} else {
Display::display_header($tool_name);
}
break;
default:
Display::display_header($tool_name);
}
Security::clear_token();
}
else
{
Display::display_header($tool_name);
}
}
else
{
Display::display_header($tool_name);
if (count($userid_match_login) > 0) {
$message = get_lang('LDAPUsersAddedOrUpdated').':<br />';
foreach ($userid_match_login as $user_id => $login) {
$message .= '- '.$login.'<br />';
}
} else {
$message = get_lang('NoUserAdded');
}
Display::addFlash(Display::return_message($message, 'normal', false));
Display::display_header($tool_name);
}
break;
default:
Display::display_header($tool_name);
}
Security::clear_token();
} else {
Display::display_header($tool_name);
}
} else {
Display::display_header($tool_name);
}
if (isset ($_POST['action']))
{
$check = Security::check_token('get');
if ($check)
{
switch ($_POST['action'])
{
case 'delete' :
$number_of_selected_users = count($_POST['id']);
$number_of_deleted_users = 0;
foreach ($_POST['id'] as $index => $user_id)
{
if ($user_id != $_user['user_id'])
{
if (UserManager::delete_user($user_id))
{
$number_of_deleted_users++;
}
}
}
if ($number_of_selected_users == $number_of_deleted_users)
{
echo Display::return_message(get_lang('SelectedUsersDeleted'), 'normal');
}
else
{
echo Display::return_message(get_lang('SomeUsersNotDeleted'), 'error');
}
break;
case 'add_user' :
$number_of_selected_users = count($_POST['id']);
$number_of_added_users = 0;
$UserList = array();
foreach ($_POST['id'] as $index => $user_id)
{
if ($user_id != $_user['user_id'])
{
$UserList[] = ldap_add_user($user_id);
}
}
if (isset($_GET['id_session']) && (trim($_GET['id_session']) != ""))
addUserToSession($UserList, $_GET['id_session']);
if (count($UserList) > 0)
{
echo Display::return_message(count($UserList)." ".get_lang('LDAPUsersAdded'));
}
else
{
echo Display::return_message(get_lang('NoUserAdded'));
}
break;
}
Security::clear_token();
}
if (isset($_POST['action'])) {
$check = Security::check_token('get');
if ($check) {
switch ($_POST['action']) {
case 'delete':
$number_of_selected_users = count($_POST['id']);
$number_of_deleted_users = 0;
foreach ($_POST['id'] as $index => $user_id) {
if ($user_id != $_user['user_id']) {
if (UserManager::delete_user($user_id)) {
$number_of_deleted_users++;
}
}
}
if ($number_of_selected_users == $number_of_deleted_users) {
echo Display::return_message(get_lang('SelectedUsersDeleted'), 'normal');
} else {
echo Display::return_message(get_lang('SomeUsersNotDeleted'), 'error');
}
break;
case 'add_user':
$number_of_selected_users = count($_POST['id']);
$number_of_added_users = 0;
$UserList = array();
foreach ($_POST['id'] as $index => $user_id) {
if ($user_id != $_user['user_id']) {
$UserList[] = ldap_add_user($user_id);
}
}
if (isset($_GET['id_session']) && (trim($_GET['id_session']) != "")) {
addUserToSession($UserList, $_GET['id_session']);
}
if (count($UserList) > 0) {
echo Display::return_message(
count($UserList)." ".get_lang('LDAPUsersAdded')
);
} else {
echo Display::return_message(get_lang('NoUserAdded'));
}
break;
}
Security::clear_token();
}
}
$form = new FormValidator('advanced_search', 'get');
$form->addText('keyword_username', get_lang('LoginName'), false);
if (api_is_western_name_order())
{
$form->addText('keyword_firstname', get_lang('FirstName'), false);
$form->addText('keyword_lastname', get_lang('LastName'), false);
if (api_is_western_name_order()) {
$form->addText('keyword_firstname', get_lang('FirstName'), false);
$form->addText('keyword_lastname', get_lang('LastName'), false);
} else {
$form->addText('keyword_lastname', get_lang('LastName'), false);
$form->addText('keyword_firstname', get_lang('FirstName'), false);
}
else
{
$form->addText('keyword_lastname', get_lang('LastName'), false);
$form->addText('keyword_firstname', get_lang('FirstName'), false);
if (isset($_GET['id_session'])) {
$form->addElement('hidden', 'id_session', $_GET['id_session']);
}
if (isset($_GET['id_session']))
$form->addElement('hidden', 'id_session', $_GET['id_session']);
$type = array();
$type["all"] = get_lang('All');
@ -195,28 +167,31 @@ $form->addElement('submit', 'submit', get_lang('Ok'));
//$defaults['keyword_inactive'] = 1;
//$form->setDefaults($defaults);
$form->display();
$parameters['keyword_username'] = @$_GET['keyword_username'] ?: null;
$parameters['keyword_firstname'] = @$_GET['keyword_firstname'] ?: null;
$parameters['keyword_lastname'] = @$_GET['keyword_lastname'] ?: null;
$parameters['keyword_email'] = @$_GET['keyword_email'] ?: null;
if (isset($_GET['id_session']))
$parameters['id_session'] = $_GET['id_session'];
if (isset($_GET['id_session'])) {
$parameters['id_session'] = $_GET['id_session'];
}
// Create a sortable table with user-data
$parameters['sec_token'] = Security::get_token();
$table = new SortableTable('users', 'ldap_get_number_of_users', 'ldap_get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
$table = new SortableTable(
'users',
'ldap_get_number_of_users',
'ldap_get_user_data',
(api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
);
$table->set_additional_parameters($parameters);
$table->set_header(0, '', false);
$table->set_header(1, get_lang('LoginName'));
if (api_is_western_name_order()) {
$table->set_header(2, get_lang('FirstName'));
$table->set_header(3, get_lang('LastName'));
$table->set_header(2, get_lang('FirstName'));
$table->set_header(3, get_lang('LastName'));
} else {
$table->set_header(2, get_lang('LastName'));
$table->set_header(3, get_lang('FirstName'));
$table->set_header(2, get_lang('LastName'));
$table->set_header(3, get_lang('FirstName'));
}
$table->set_header(4, get_lang('Email'));
$table->set_header(5, get_lang('Actions'));
@ -226,9 +201,4 @@ $table->set_column_filter(5, 'modify_filter');
$table->set_form_actions(array('add_user' => get_lang('AddLDAPUsers')));
$table->display();
/*
==============================================================================
FOOTER
==============================================================================
*/
Display::display_footer();

@ -91,12 +91,13 @@ class Attendance
}
/**
* Get the attendaces to display on the current page (fill the sortable-table)
* Get the attendances to display on the current page (fill the sortable-table)
* @param int offset of first user to recover
* @param int Number of users to get
* @param int Column to sort on
* @param string Order (ASC,DESC)
* @see SortableTable#get_table_data($from)
* @return array
*/
public static function get_attendance_data($from, $number_of_items, $column, $direction)
{
@ -306,7 +307,6 @@ class Attendance
$last_id = Database::insert($tbl_attendance, $params);
if (!empty($last_id)) {
$sql = "UPDATE $tbl_attendance SET id = iid WHERE iid = $last_id";
Database::query($sql);
@ -699,7 +699,7 @@ class Attendance
if (!empty($attendance_id)) {
$user_faults = $this->get_faults_of_user($uid, $attendance_id, $groupId);
$value['attendance_result'] = $user_faults['faults'].'/'.$user_faults['total'].' ('.$user_faults['faults_porcent'].'%)';
$value['result_color_bar'] = $user_faults['color_bar'];
$value['result_color_bar'] = $user_faults['color_bar'];
}
$photo = Display::img($userInfo['avatar_small'], $userInfo['complete_name'], [], false);
@ -1002,10 +1002,24 @@ class Attendance
$user_id = intval($user_id);
$attendance_id = intval($attendance_id);
$results = array();
$calendar_count = self::get_number_of_attendance_calendar($attendance_id, $groupId, NULL, $user_id);
$calendar_count = self::get_number_of_attendance_calendar(
$attendance_id,
$groupId,
null,
$user_id
);
// $total_done_attendance = $attendance_data['attendance_qualify_max'];
$total_done_attendance = self::get_number_of_attendance_calendar($attendance_id, $groupId, true, $user_id);
$attendance_user_score = $this->get_user_score($user_id, $attendance_id, $groupId);
$total_done_attendance = self::get_number_of_attendance_calendar(
$attendance_id,
$groupId,
true,
$user_id
);
$attendance_user_score = $this->get_user_score(
$user_id,
$attendance_id,
$groupId
);
//This is the main change of the BT#1381
//$total_done_attendance = $calendar_count;
@ -1053,7 +1067,6 @@ class Attendance
//$course_info = api_get_course_info($course_code);
$course_id = $course['real_id'];
$tbl_attendance_result = Database::get_course_table(TABLE_ATTENDANCE_RESULT);
$attendances_by_course = $this->get_attendances_list($course_id);
foreach ($attendances_by_course as $attendance) {
@ -1513,7 +1526,6 @@ class Attendance
return $count;
}
/**
* Get count dates inside attendance calendar by attendance id
* @param int $attendance_id

@ -355,18 +355,18 @@ class MySpace
$parameters['view'] = 'admin';
$table->set_additional_parameters($parameters);
if ($is_western_name_order) {
$table -> set_header(0, get_lang('FirstName'), true);
$table -> set_header(1, get_lang('LastName'), true);
$table->set_header(0, get_lang('FirstName'), true);
$table->set_header(1, get_lang('LastName'), true);
} else {
$table -> set_header(0, get_lang('LastName'), true);
$table -> set_header(1, get_lang('FirstName'), true);
$table->set_header(0, get_lang('LastName'), true);
$table->set_header(1, get_lang('FirstName'), true);
}
$table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
$table -> set_header(3, get_lang('LastConnexion'), false);
$table -> set_header(4, get_lang('NbStudents'), false);
$table -> set_header(5, get_lang('CountCours'), false);
$table -> set_header(6, get_lang('NumberOfSessions'), false);
$table -> set_header(7, get_lang('Sessions'), false);
$table->set_header(2, get_lang('TimeSpentOnThePlatform'), false);
$table->set_header(3, get_lang('LastConnexion'), false);
$table->set_header(4, get_lang('NbStudents'), false);
$table->set_header(5, get_lang('CountCours'), false);
$table->set_header(6, get_lang('NumberOfSessions'), false);
$table->set_header(7, get_lang('Sessions'), false);
if ($is_western_name_order) {
$csv_header[] = array(
@ -1052,7 +1052,12 @@ class MySpace
$direction = 'ASC';
}
$course_data = self::get_course_data_tracking_overview($from, 1000, $orderby, $direction);
$course_data = self::get_course_data_tracking_overview(
$from,
1000,
$orderby,
$direction
);
$csv_content = array();
@ -1745,9 +1750,9 @@ class MySpace
global $courses, $csv_content, $charset, $session_id;
// definition database tables
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$course_data = array();
$courses_code = array_keys($courses);
@ -1798,19 +1803,18 @@ class MySpace
if (count($users) > 0) {
$nb_students_in_course = count($users);
$avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code, $session_id);
$avg_messages_in_course = Tracking::count_student_messages($users, $course_code, $session_id);
$avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code, array(), $session_id);
$avg_score_in_course = Tracking::get_avg_student_score($users, $course_code, array(), $session_id);
$avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code, 0, $session_id);
$avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $courseInfo['real_id'], $session_id);
$avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code, $session_id);
$avg_messages_in_course = Tracking::count_student_messages($users, $course_code, $session_id);
$avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code, array(), $session_id);
$avg_score_in_course = Tracking::get_avg_student_score($users, $course_code, array(), $session_id);
$avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code, 0, $session_id);
$avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $courseInfo['real_id'], $session_id);
$avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2);
if (is_numeric($avg_score_in_course)) {
$avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2);
}
$avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
} else {
$avg_time_spent_in_course = null;
$avg_progress_in_course = null;
@ -1868,6 +1872,7 @@ class MySpace
* @param int $numberItems
* @param int $column
* @param string $direction
* @return array
*/
public static function get_user_data_tracking_overview($from, $numberItems, $column, $direction)
{
@ -1934,6 +1939,7 @@ class MySpace
$extra_data = UserManager::get_extra_user_data($user_id, true);
return $extra_data;
}
/**
* Checks if a username exist in the DB otherwise it create a "double"
* i.e. if we look into for jmontoya but the user's name already exist we create the user jmontoya2
@ -2116,7 +2122,7 @@ class MySpace
/**
* Validates imported data.
* @param list of users
* @param $users list of users
*/
function validate_data($users, $id_session = null)
{
@ -2356,7 +2362,8 @@ class MySpace
/**
* XML-parser: the handler at the end of element.
*/
function element_end($parser, $data) {
function element_end($parser, $data)
{
$data = api_utf8_decode($data);
global $user;
global $users;
@ -2377,7 +2384,8 @@ class MySpace
/**
* XML-parser: the handler for character data.
*/
function character_data($parser, $data) {
function character_data($parser, $data)
{
$data = trim(api_utf8_decode($data));
global $current_value;
$current_value = $data;
@ -2388,7 +2396,8 @@ class MySpace
* @param string $file Path to the XML-file
* @return array All userinformation read from the file
*/
function parse_xml_data($file) {
function parse_xml_data($file)
{
global $current_tag;
global $current_value;
global $user;
@ -2537,7 +2546,9 @@ class MySpace
$table->set_header(6, get_lang('TimeLoggedIn'), false);
}
$template = new Template(null, false, false, false, false, false, false);
$template = new Template(
null, false, false, false, false, false, false
);
$template->assign('form', $form->returnForm());
$template->assign('table', $table ? $table->return_table() : null);

@ -2,7 +2,7 @@
/* For licensing terms, see /license.txt */
/**
* @package chamilo.admin
* @package chamilo.admin
*/
$cidReset = true;
@ -31,245 +31,242 @@ $archivePath = api_get_path(SYS_ARCHIVE_PATH);
$archiveURL = api_get_path(WEB_CODE_PATH).'course_info/download.php?archive_path=&archive=';
$tool_name = get_lang('ExportSessionListXMLCSV');
$interbreadcrumb[] = array('url' => 'session_list.php', 'name' => get_lang('SessionList'));
set_time_limit(0);
if (isset($_POST['formSent'])) {
$formSent = $_POST['formSent'];
$file_type = isset($_POST['file_type']) ? $_POST['file_type'] : 'csv';
$session_id = $_POST['session_id'];
if (empty($session_id)) {
$sql = "SELECT
s.id,
name,
id_coach,
username,
access_start_date,
access_end_date,
visibility,
session_category_id
FROM $tbl_session s
INNER JOIN $tbl_user
ON $tbl_user.user_id = s.id_coach
ORDER BY id";
if (api_is_multiple_url_enabled()) {
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = "SELECT s.id, name,id_coach,username,access_start_date,access_end_date,visibility,session_category_id
FROM $tbl_session s
INNER JOIN $tbl_session_rel_access_url as session_rel_url
ON (s.id= session_rel_url.session_id)
INNER JOIN $tbl_user u ON (u.user_id = s.id_coach)
WHERE access_url_id = $access_url_id
ORDER BY id";
}
}
$result = Database::query($sql);
} else {
$sql = "SELECT s.id,name,username,access_start_date,access_end_date,visibility,session_category_id
FROM $tbl_session s
INNER JOIN $tbl_user
ON $tbl_user.user_id = s.id_coach
WHERE s.id='$session_id'";
$result = Database::query($sql);
}
if (Database::num_rows($result)) {
$sessionListToExport = [];
if (in_array($file_type, ['csv', 'xls'])) {
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time();
$cvs = true;
$sessionListToExport[] = [
'SessionName',
'Coach',
'DateStart',
'DateEnd',
'Visibility',
'SessionCategory',
'Users',
'Courses'
];
} else {
if (!file_exists($archivePath)) {
mkdir($archivePath, api_get_permissions_for_new_directories(), true);
}
if (!file_exists($archivePath.'index.html')) {
$fp = fopen($archivePath.'index.html', 'w');
fputs($fp, '<html><head></head><body></body></html>');
fclose($fp);
}
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time().'.'.$file_type;
while (file_exists($archivePath.$archiveFile)) {
$archiveFile = 'export_users_'.$session_id.'_'.api_get_local_time().'_'.uniqid('').'.'.$file_type;
}
$cvs = false;
$fp = fopen($archivePath.$archiveFile, 'w');
fputs($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Sessions>\n");
}
while ($row = Database::fetch_array($result)) {
$row['name'] = str_replace(';', ',', $row['name']);
$row['username'] = str_replace(';', ',', $row['username']);
$row['access_start_date'] = str_replace(';', ',', $row['access_start_date']);
$row['access_end_date'] = str_replace(';', ',', $row['access_end_date']);
$row['visibility'] = str_replace(';', ',', $row['visibility']);
$row['session_category'] = str_replace(';', ',', $row['session_category_id']);
// users
$sql = "SELECT DISTINCT $tbl_user.username
FROM $tbl_user
INNER JOIN $tbl_session_user
ON
$tbl_user.user_id = $tbl_session_user.user_id AND
$tbl_session_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
$tbl_session_user.session_id = '".$row['id']."'";
$rsUsers = Database::query($sql);
$users = '';
while ($rowUsers = Database::fetch_array($rsUsers)) {
if ($cvs) {
$users .= str_replace(';', ',', $rowUsers['username']).'|';
} else {
$users .= "\t\t<User>$rowUsers[username]</User>\n";
}
}
if (!empty($users) && $cvs) {
$users = api_substr($users, 0, api_strlen($users) - 1);
}
// Courses
$sql = "SELECT DISTINCT c.code, sc.id, c_id
FROM $tbl_course c
INNER JOIN $tbl_session_course_user sc
ON c.id = sc.c_id
AND sc.session_id = '".$row['id']."'";
$rsCourses = Database::query($sql);
$courses = '';
while ($rowCourses = Database::fetch_array($rsCourses)) {
// get coachs from a course
$sql = "SELECT u.username
FROM $tbl_session_course_user scu
INNER JOIN $tbl_user u
ON u.user_id = scu.user_id
WHERE
scu.c_id = '{$rowCourses['c_id']}' AND
scu.session_id = '".$row['id']."' AND
scu.status = 2 ";
$rs_coachs = Database::query($sql);
$coachs = array();
while ($row_coachs = Database::fetch_array($rs_coachs)) {
$coachs[] = $row_coachs['username'];
}
$coachs = implode(",", $coachs);
if ($cvs) {
$courses .= str_replace(';', ',', $rowCourses['code']);
$courses .= '['.str_replace(';', ',', $coachs).'][';
} else {
$courses .= "\t\t<Course>\n";
$courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n";
$courses .= "\t\t\t<Coach>$coachs</Coach>\n";
}
// rel user courses
$sql = "SELECT DISTINCT u.username
FROM $tbl_session_course_user scu
INNER JOIN $tbl_session_user su
ON
scu.user_id = su.user_id AND
scu.session_id = su.session_id AND
su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
INNER JOIN $tbl_user u
ON
scu.user_id = u.user_id AND
scu.c_id='".$rowCourses['c_id']."' AND
scu.session_id='".$row['id']."'";
$rsUsersCourse = Database::query($sql);
$userscourse = '';
while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)) {
if ($cvs) {
$userscourse .= str_replace(';', ',', $rowUsersCourse['username']).',';
} else {
$courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n";
}
}
if ($cvs) {
if (!empty($userscourse)) {
$userscourse = api_substr(
$userscourse,
0,
api_strlen($userscourse) - 1
);
}
$courses .= $userscourse.']|';
} else {
$courses .= "\t\t</Course>\n";
}
}
if (!empty($courses) && $cvs) {
$courses = api_substr($courses, 0, api_strlen($courses) - 1);
}
$add = $courses;
if (in_array($file_type, ['csv', 'xls'])) {
$sessionListToExport[] = [
$row['name'],
$row['username'],
$row['access_start_date'],
$row['access_end_date'],
$row['visibility'],
$row['session_category'],
$users,
$courses
];
} else {
$add = "\t<Session>\n"
."\t\t<SessionName>$row[name]</SessionName>\n"
."\t\t<Coach>$row[username]</Coach>\n"
."\t\t<DateStart>$row[access_start_date]</DateStart>\n"
."\t\t<DateEnd>$row[access_end_date]</DateEnd>\n"
."\t\t<Visibility>$row[visibility]</Visibility>\n"
."\t\t<SessionCategory>$row[session_category]</SessionCategory>\n";
}
if (!$cvs) {
$add .= "\t</Session>\n";
fputs($fp, $add);
}
}
switch ($file_type) {
case 'xml':
fputs($fp, "</Sessions>\n");
fclose($fp);
$errorMsg = get_lang('UserListHasBeenExported').'<br/>
<a class="btn btn-default" href="'.$archiveURL.$archiveFile.'">'.get_lang('ClickHereToDownloadTheFile').'</a>';
break;
case 'csv':
Export::arrayToCsv($sessionListToExport, $archiveFile);
exit;
case 'xls':
Export::arrayToXls($sessionListToExport, $archiveFile);
exit;
break;
}
}
$formSent = $_POST['formSent'];
$file_type = isset($_POST['file_type']) ? $_POST['file_type'] : 'csv';
$session_id = $_POST['session_id'];
if (empty($session_id)) {
$sql = "SELECT
s.id,
name,
id_coach,
username,
access_start_date,
access_end_date,
visibility,
session_category_id
FROM $tbl_session s
INNER JOIN $tbl_user
ON $tbl_user.user_id = s.id_coach
ORDER BY id";
if (api_is_multiple_url_enabled()) {
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = "SELECT s.id, name,id_coach,username,access_start_date,access_end_date,visibility,session_category_id
FROM $tbl_session s
INNER JOIN $tbl_session_rel_access_url as session_rel_url
ON (s.id= session_rel_url.session_id)
INNER JOIN $tbl_user u ON (u.user_id = s.id_coach)
WHERE access_url_id = $access_url_id
ORDER BY id";
}
}
$result = Database::query($sql);
} else {
$sql = "SELECT s.id,name,username,access_start_date,access_end_date,visibility,session_category_id
FROM $tbl_session s
INNER JOIN $tbl_user
ON $tbl_user.user_id = s.id_coach
WHERE s.id='$session_id'";
$result = Database::query($sql);
}
if (Database::num_rows($result)) {
$sessionListToExport = [];
if (in_array($file_type, ['csv', 'xls'])) {
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time();
$cvs = true;
$sessionListToExport[] = [
'SessionName',
'Coach',
'DateStart',
'DateEnd',
'Visibility',
'SessionCategory',
'Users',
'Courses'
];
} else {
if (!file_exists($archivePath)) {
mkdir($archivePath, api_get_permissions_for_new_directories(), true);
}
if (!file_exists($archivePath.'index.html')) {
$fp = fopen($archivePath.'index.html', 'w');
fputs($fp, '<html><head></head><body></body></html>');
fclose($fp);
}
$archiveFile = 'export_sessions_'.$session_id.'_'.api_get_local_time().'.'.$file_type;
while (file_exists($archivePath.$archiveFile)) {
$archiveFile = 'export_users_'.$session_id.'_'.api_get_local_time().'_'.uniqid('').'.'.$file_type;
}
$cvs = false;
$fp = fopen($archivePath.$archiveFile, 'w');
fputs($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Sessions>\n");
}
while ($row = Database::fetch_array($result)) {
$row['name'] = str_replace(';', ',', $row['name']);
$row['username'] = str_replace(';', ',', $row['username']);
$row['access_start_date'] = str_replace(';', ',', $row['access_start_date']);
$row['access_end_date'] = str_replace(';', ',', $row['access_end_date']);
$row['visibility'] = str_replace(';', ',', $row['visibility']);
$row['session_category'] = str_replace(';', ',', $row['session_category_id']);
// users
$sql = "SELECT DISTINCT $tbl_user.username
FROM $tbl_user
INNER JOIN $tbl_session_user
ON
$tbl_user.user_id = $tbl_session_user.user_id AND
$tbl_session_user.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND
$tbl_session_user.session_id = '".$row['id']."'";
$rsUsers = Database::query($sql);
$users = '';
while ($rowUsers = Database::fetch_array($rsUsers)) {
if ($cvs) {
$users .= str_replace(';', ',', $rowUsers['username']).'|';
} else {
$users .= "\t\t<User>$rowUsers[username]</User>\n";
}
}
if (!empty($users) && $cvs) {
$users = api_substr($users, 0, api_strlen($users) - 1);
}
// Courses
$sql = "SELECT DISTINCT c.code, sc.id, c_id
FROM $tbl_course c
INNER JOIN $tbl_session_course_user sc
ON c.id = sc.c_id
AND sc.session_id = '".$row['id']."'";
$rsCourses = Database::query($sql);
$courses = '';
while ($rowCourses = Database::fetch_array($rsCourses)) {
// get coachs from a course
$sql = "SELECT u.username
FROM $tbl_session_course_user scu
INNER JOIN $tbl_user u
ON u.user_id = scu.user_id
WHERE
scu.c_id = '{$rowCourses['c_id']}' AND
scu.session_id = '".$row['id']."' AND
scu.status = 2 ";
$rs_coachs = Database::query($sql);
$coachs = array();
while ($row_coachs = Database::fetch_array($rs_coachs)) {
$coachs[] = $row_coachs['username'];
}
$coachs = implode(",", $coachs);
if ($cvs) {
$courses .= str_replace(';', ',', $rowCourses['code']);
$courses .= '['.str_replace(';', ',', $coachs).'][';
} else {
$courses .= "\t\t<Course>\n";
$courses .= "\t\t\t<CourseCode>$rowCourses[code]</CourseCode>\n";
$courses .= "\t\t\t<Coach>$coachs</Coach>\n";
}
// rel user courses
$sql = "SELECT DISTINCT u.username
FROM $tbl_session_course_user scu
INNER JOIN $tbl_session_user su
ON
scu.user_id = su.user_id AND
scu.session_id = su.session_id AND
su.relation_type<>".SESSION_RELATION_TYPE_RRHH."
INNER JOIN $tbl_user u
ON
scu.user_id = u.user_id AND
scu.c_id='".$rowCourses['c_id']."' AND
scu.session_id='".$row['id']."'";
$rsUsersCourse = Database::query($sql);
$userscourse = '';
while ($rowUsersCourse = Database::fetch_array($rsUsersCourse)) {
if ($cvs) {
$userscourse .= str_replace(';', ',', $rowUsersCourse['username']).',';
} else {
$courses .= "\t\t\t<User>$rowUsersCourse[username]</User>\n";
}
}
if ($cvs) {
if (!empty($userscourse)) {
$userscourse = api_substr(
$userscourse,
0,
api_strlen($userscourse) - 1
);
}
$courses .= $userscourse.']|';
} else {
$courses .= "\t\t</Course>\n";
}
}
if (!empty($courses) && $cvs) {
$courses = api_substr($courses, 0, api_strlen($courses) - 1);
}
$add = $courses;
if (in_array($file_type, ['csv', 'xls'])) {
$sessionListToExport[] = [
$row['name'],
$row['username'],
$row['access_start_date'],
$row['access_end_date'],
$row['visibility'],
$row['session_category'],
$users,
$courses
];
} else {
$add = "\t<Session>\n"
."\t\t<SessionName>$row[name]</SessionName>\n"
."\t\t<Coach>$row[username]</Coach>\n"
."\t\t<DateStart>$row[access_start_date]</DateStart>\n"
."\t\t<DateEnd>$row[access_end_date]</DateEnd>\n"
."\t\t<Visibility>$row[visibility]</Visibility>\n"
."\t\t<SessionCategory>$row[session_category]</SessionCategory>\n";
}
if (!$cvs) {
$add .= "\t</Session>\n";
fputs($fp, $add);
}
}
switch ($file_type) {
case 'xml':
fputs($fp, "</Sessions>\n");
fclose($fp);
$errorMsg = get_lang('UserListHasBeenExported').'<br/>
<a class="btn btn-default" href="'.$archiveURL.$archiveFile.'">'.get_lang('ClickHereToDownloadTheFile').'</a>';
break;
case 'csv':
Export::arrayToCsv($sessionListToExport, $archiveFile);
exit;
case 'xls':
Export::arrayToXls($sessionListToExport, $archiveFile);
exit;
break;
}
}
}
// display the header
@ -279,26 +276,26 @@ Display::display_header($tool_name);
$sql = "SELECT id, name FROM $tbl_session ORDER BY name";
if (api_is_multiple_url_enabled()) {
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = "SELECT s.id, name FROM $tbl_session s
INNER JOIN $tbl_session_rel_access_url as session_rel_url
ON (s.id = session_rel_url.session_id)
WHERE access_url_id = $access_url_id
ORDER BY name";
}
$tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
$access_url_id = api_get_current_access_url_id();
if ($access_url_id != -1) {
$sql = "SELECT s.id, name FROM $tbl_session s
INNER JOIN $tbl_session_rel_access_url as session_rel_url
ON (s.id = session_rel_url.session_id)
WHERE access_url_id = $access_url_id
ORDER BY name";
}
}
$result = Database::query($sql);
$Sessions = Database::store_result($result);
echo '<div class="actions">';
echo '<a href="../session/session_list.php">'.
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('SessionList'), '', ICON_SIZE_MEDIUM).'</a>';
Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('SessionList'), '', ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
if (!empty($errorMsg)) {
echo Display::return_message($errorMsg, 'normal', false); //main API
echo Display::return_message($errorMsg, 'normal', false); //main API
}
$form = new FormValidator('session_export', 'post', api_get_self());

Loading…
Cancel
Save