@ -1,4 +1,4 @@
<?php // $Id: session_import.php,v 1.1 2006/04/20 09:58:01 elixir_inter Exp $
<?php // $Id: user_import.php,v 1.17 2005/06/22 08:00:31 bmol Exp $
/*
==============================================================================
Dokeos - elearning and course management software
@ -26,253 +26,255 @@
* @package dokeos.admin
==============================================================================
*/
// name of the language file that needs to be included
$language_file = array('admin','registration');
$cidReset=true;
include('../inc/global.inc.php');
// setting the section (for the tabs)
$this_section=SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
include(api_get_library_path().'/fileManage.lib.php');
include(api_get_library_path().'/xmllib.php');
include(api_get_path(LIBRARY_PATH).'/fileManage.lib.php');
include (api_get_path(LIBRARY_PATH)."/add_course.conf.php");
include_once (api_get_path(LIBRARY_PATH)."/add_course.lib.inc.php");
$formSent=0;
$errorMsg='';
// Database table definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER );
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_co ur se = Database::get_main_table(TABLE_MAIN_CO UR SE);
$tbl_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER );
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
$tbl_session_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$tbl_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$tool_name=get_lang('ImportSessionListXMLCSV');
$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin '));
$interbreadcrumb[]=array("url" => "index.php","name" => get_lang('AdministrationTools '));
set_time_limit(0);
if($_POST['formSent'])
{
$formSent=$_POST['formSent'];
$file_type=$_POST['file_type'];
$sendMail=$_POST['sendMail']?1:0;
if(isset($_FILES['import_file']['tmp_name']))
{
$formSent=$_POST['formSent'];
$file_type=$_POST['file_type'];
$sendMail=$_POST['sendMail']?1:0;
/*if($_FILES['import_file']['size'])
{
$content=file($_FILES['import_file']['tmp_name']);
}
else
{
$content=array('');
}*/
$sessions=array();
$sessions=array();
///////////////////////
//XML/////////////////
/////////////////////
///////////////////////
//XML/////////////////
/////////////////////
if($file_type == 'xml')
{
$xmlparser = new XmlLib_xmlParser($_FILES['import_file']['tmp_name']);
$racine = $xmlparser->getDocument();
$sessionNodes = $racine->children('Session');
foreach ($sessionNodes as $sessionNode){ // foreach session
$countCourses = 0;
$countUsers = 0;
list($SessionName) = $sessionNode->children('SessionName');
$SessionName = $SessionName->nodeValue();
list($Coach) = $sessionNode->children('Coach');
if(!empty($Coach)){
$Coach = $Coach->nodeValue();
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
$rsCoach = api_sql_query($sqlCoach);
list($Coach) = (mysql_fetch_array($rsCoach));
}
else {
$Coach = '';
}
if($file_type == 'xml')
{
list($DateStart) = $sessionNode->children('DateStart');
$DateStart = $DateStart->nodeValue();
list($DateEnd) = $sessionNode->children('DateEnd');
$DateEnd = $DateEnd->nodeValue();
$sqlSession = "INSERT IGNORE INTO $tbl_session SET
name = '$SessionName',
id_coach = '$Coach',
date_start = '$DateStart',
date_end = '$DateEnd'";
$rsSession = api_sql_query($sqlSession, __FILE__, __LINE__);
$update = false;
if(!mysql_affected_rows($rsSession)){
$update = true;
$sqlSession = "UPDATE $tbl_session SET
id_coach = '$Coach',
date_start = '$DateStart',
date_end = '$DateEnd'
WHERE name = '$SessionName'";
$rsSession = api_sql_query($sqlSession, __FILE__, __LINE__);
$racine = simplexml_load_file($_FILES['import_file']['tmp_name']);
foreach($racine->Users->User as $userNode)
{
$username = $userNode->Username;
$isCut = 0; // if the username given is too long
if(strlen($username)>20)
{
$user_name_dist = $username;
$username = substr($username,0,19);
$isCut = 1;
}
$session_id = api_sql_query("SELECT id FROM $tbl_session WHERE name='$SessionName'",__FILE__,__LINE__);
list($session_id) = mysql_fetch_array($session_id);
$sql = "SELECT 1 FROM $tbl_user WHERE username='".addslashes($username)."'";
$rs = api_sql_query($sql, __FILE__, __LINE__);
api_sql_query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'",__FILE__,__LINE__);
api_sql_query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'",__FILE__,__LINE__);
api_sql_query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'",__FILE__,__LINE__);
}
else {
$session_id = mysql_insert_id($rsSession);
}
if(mysql_affected_rows()==0)
{
if($isCut)
{
$errorMsg .= get_lang('UsernameTooLongWasCut').' '.get_lang('From').' '.$user_name_dist.' '.get_lang('To').' '.$username.' < br / > ';
}
$userNodes = $sessionNode->children('User');
foreach ($userNodes as $userNode){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$userNode->nodeValue()."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
if(!empty($user_id)){
$sql = "INSERT INTO $tbl_session_user SET
id_user='$user_id',
id_session = '$session_id'";
$rsUser = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countUsers++;
$lastname = $userNode->Lastname;
$firstname = $userNode->Firstname;
$password = $userNode->Password;
if(empty($password))
$password = base64_encode(rand(1000,10000));
$email = $userNode->Email;
$official_code = $userNode->OfficialCode;
$phone = $userNode->Phone;
$status = $userNode->Status;
switch($status)
{
case 'student' : $status = 5; break;
case 'teacher' : $status = 1; break;
default : $status = 5; $errorMsg = get_lang('StudentStatusWasGivenTo').' : '.$username.'< br / > ';
}
}
}
$courseNodes = $sessionNode->children('Course');
foreach($courseNodes as $courseNode){
list($CourseCode) = $courseNode->children('CourseCode');
$CourseCode = $CourseCode->nodeValue();
list($Coach) = $courseNode->children('Coach');
if(!empty($Coach)){
$Coach = $Coach->nodeValue();
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
$rsCoach = api_sql_query($sqlCoach,__FILE__,__LINE__);
list($Coach) = (mysql_fetch_array($rsCoach));
}
else {
$Coach = '';
}
$sql = "INSERT INTO $tbl_user SET
username = '".addslashes($username)."',
lastname = '".addslashes($lastname)."',
firstname = '".addslashes($firstname)."',
password = '".($userPasswordCrypted==true ? md5($password) : $password)."',
email = '".addslashes($email)."',
official_code = '".addslashes($official_code)."',
phone = '".addslashes($phone)."',
status = '".addslashes($status)."'";
$sqlCourse = "INSERT INTO $tbl_session_course SET
course_code = '$CourseCode',
id_coach='$Coach',
id_session='$session_id'";
$rsCourse = api_sql_query($sqlCourse,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countCourses++;
$userNodes = $courseNode->children('User');
$countUsersCourses = 0;
foreach ($userNodes as $userNode){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$userNode->nodeValue()."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
$sql = "INSERT INTO $tbl_session_course_user SET
id_user='$user_id',
course_code='$CourseCode',
id_session = '$session_id'";
$rsUsers = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows())
$countUsersCourses++;
api_sql_query($sql, __FILE__, __LINE__);
if(mysql_affected_rows()>0 & & $sendMail)
{
$emailto='"'.$firstname.' '.$lastname.'" < '.$email.'>';
$emailsubject='['.get_setting('siteName').'] '.get_lang('YourReg').' '.get_setting('siteName');
$emailbody="[NOTE:] Ceci est un e-mail automatique, veuillez ne pas y répondre.\n\n".get_lang('langDear')." $firstname $lastname,\n\n".get_lang('langYouAreReg')." ". get_setting('siteName') ." ".get_lang('langSettings')." $username\n". get_lang('langPass')." : $password\n\n".get_lang('langAddress') ." ". get_lang('langIs') ." ". $serverAddress ."\n\nVous recevrez prochainement un e-mail de votre coach responsable. Nous vous invitons à bien lire ses recommandations.\n\n". get_lang('langProblem'). "\n\n". get_lang('langFormula');
//#287 modifiée par Stéphane DEBIEVE - FOREM
$emailheaders='From: '.get_setting('administratorName').' '.get_setting('administratorSurname').' < '.get_setting('emailAdministrator').">\n";
$emailheaders.='Reply-To: '.get_setting('emailAdministrator');
@api_send_mail($emailto,$emailsubject,$emailbody,$emailheaders);
}
api_sql_query("UPDATE $tbl_session_course SET nbr_users='$countUsersCourses' WHERE course_code='$CourseCode'",__FILE__,__LINE__);
}
}
api_sql_query("UPDATE $tbl_session SET nbr_users='$countUsers', nbr_courses='$countCourses' WHERE id='$session_id'",__FILE__,__LINE__);
}
}
}
foreach($racine->Courses->Course as $courseNode)
{
$course_code = $courseNode->CourseCode;
$title = $courseNode->CourseTitle;
$description = $courseNode->CourseDescription;
$language = $courseNode->CourseLanguage;
$username = $courseNode->CourseTeacher;
$sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'";
$rs = api_sql_query($sql, __FILE__, __LINE__);
list($user_id, $lastname, $firstname) = mysql_fetch_array($rs);
$keys = define_course_keys($course_code, "", $dbNamePrefix);
if (sizeof($keys))
{
/////////////////////
// CSV /////////////
///////////////////
$currentCourseCode = $keys['visual_code'];
$currentCourseId = $keys["currentCourseId"];
if(empty($currentCourseCode))
$currentCourseCode = $currentCourseId;
$currentCourseDbName = $keys["currentCourseDbName"];
$currentCourseRepository = $keys["currentCourseRepository"];
if($currentCourseId == strtoupper($course_code))
{
if (empty ($title))
{
$title = $keys["currentCourseCode"];
}
prepare_course_repository($currentCourseRepository, $currentCourseId);
update_Db_course($currentCourseDbName);
fill_course_repository($currentCourseRepository);
fill_Db_course($currentCourseDbName, $currentCourseRepository, 'french');
//register_course($currentCourseId, $currentCourseCode, $currentCourseRepository, $currentCourseDbName, "$lastname $firstname", $course['unit_code'], addslashes($course['FR']['title']), $language, $user_id);
$sql = "INSERT INTO ".$tbl_course." SET
code = '".$currentCourseId."',
db_name = '".$currentCourseDbName."',
directory = '".$currentCourseRepository."',
course_language = '".$language."',
title = '".$title."',
description = '".lang2db($description)."',
category_code = '',
visibility = '".$defaultVisibilityForANewCourse."',
show_score = '',
disk_quota = NULL,
creation_date = now(),
expiration_date = NULL,
last_edit = now(),
last_visit = NULL,
tutor_name = '".$lastname." ".$firstname."',
visual_code = '".$currentCourseCode."'";
api_sql_query($sql, __FILE__, __LINE__);
$sql = "INSERT INTO ".$tbl_course_user." SET
course_code = '".$currentCourseId."',
user_id = '".$user_id."',
status = '1',
role = '".lang2db('Professor')."',
tutor_id='1',
sort='". ($sort +1)."',
user_course_cat='0'";
api_sql_query($sql, __FILE__, __LINE__);
}
else
{
$content=file($_FILES['import_file']['tmp_name']);
if(!strstr($content[0],';'))
{
$errorMsg=get_lang('NotCSV');
}
else
{
}
}
foreach ($racine->Session as $sessionNode){ // foreach session
$tag_names=array();
$countCourses = 0;
$countUsers = 0;
foreach($content as $key=>$enreg)
{
$enreg=explode(';',trim($enreg));
$SessionName = $sessionNode->SessionName;
$Coach = $sessionNode->Coach;
if($key)
{
foreach($tag_names as $tag_key=>$tag_name)
if(!empty($Coach)){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
$rsCoach = api_sql_query($sqlCoach);
list($CoachId) = (mysql_fetch_array($rsCoach));
if(empty($CoachId))
{
$sessions[$key-1][$tag_name]=$enreg[$tag_key];
$errorMsg .= get_lang('UserDoesNotExist').' : '.$Coach.'< br / > ' ;
}
}
else
$DateStart = $sessionNode->DateStart;
if(!empty($DateStart))
{
foreach($enreg as $tag_name)
list($YearStart,$MonthStart, $DayStart) = explode('-',$DateStart);
if(empty($YearStart) || empty($MonthStart) || empty($DayStart))
{
$tag_names[]=eregi_replace('[^a-z0-9_-]','',$tag_name);
$errorMsg .= get_lang('WrongDate').' : '.$DateStart.'< br / > ';
break;
}
if(!in_array('SessionName',$tag_names) || !in_array('DateStart',$tag_names) || !in_array('DateEnd',$tag_names))
else
{
$errorMsg=get_lang('NoNeededData');
$timeStart = mktime(0,0,0,$MonthStart,$DayStart,$YearStart);
}
break;
$DateEnd = $sessionNode->DateEnd;
if(!empty($DateStart))
{
list($YearEnd,$MonthEnd, $DayEnd) = explode('-',$DateEnd);
if(empty($YearEnd) || empty($MonthEnd) || empty($DayEnd))
{
$errorMsg .= get_lang('WrongDate').' : '.$DateEnd.'< br / > ';
break;
}
else
{
$timeEnd = mktime(0,0,0,$MonthEnd,$DayEnd,$YearEnd);
}
}
if($timeEnd - $timeStart < 0 )
{
$errorMsg .= get_lang('DateStartMoreThanDateEnd').' : '.$DateEnd.'< br / > ';
}
}
}
foreach($sessions as $enreg) {
$SessionName = $enreg['SessionName'];
$DateStart = $enreg['DateStart'];
$DateEnd = $enreg['DateEnd'];
if(!empty($enreg['Coach'])){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='".$enreg['Coach']."'";
$rsCoach = api_sql_query($sqlCoach);
list($Coach) = (mysql_fetch_array($rsCoach));
}
else {
$Coach = '';
}
$sqlSession = "INSERT IGNORE INTO $tbl_session SET
name = '$SessionName',
id_coach = '$Coach',
date_start = '$DateStart',
date_end = '$DateEnd'";
name = '$SessionName',
id_coach = '$CoachId',
date_start = '$DateStart',
date_end = '$DateEnd'";
$rsSession = api_sql_query($sqlSession, __FILE__, __LINE__);
$update = false;
if(! mysql_affected_rows($rsSession )){
if(mysql_affected_rows() == 0){
$update = true;
$sqlSession = "UPDATE $tbl_session SET
id_coach = '$Coach',
id_coach = '$CoachId ',
date_start = '$DateStart',
date_end = '$DateEnd'
WHERE name = '$SessionName'";
@ -286,75 +288,262 @@ if($_POST['formSent'])
api_sql_query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'",__FILE__,__LINE__);
}
else {
$session_id = mysql_insert_id($rsSession );
$session_id = mysql_insert_id();
}
$users = explode('|',$enreg['Users']);
foreach ($users as $user){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$user."'";
foreach ($sessionNode->User as $userNode){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".addslashes($userNode)."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
$sql = "INSERT INTO $tbl_session_user SET
id_user='$user_id',
id_session = '$session_id'";
if(!empty($user_id)){
$sql = "INSERT INTO $tbl_session_user SET
id_user='$user_id',
id_session = '$session_id'";
$rsUser = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countUsers++;
}
}
}
foreach($sessionNode->Course as $courseNode){
$CourseCode = $courseNode->CourseCode;
// verify that the course pointed by the course code node exists
$sql = 'SELECT 1 FROM '.$tbl_course.' WHERE code="'.mysql_escape_string($CourseCode).'"';
$rs = api_sql_query($sql, __FILE__, __LINE__);
if(mysql_num_rows($rs)>0)
{ // if the course exists we continue
$Coach = $courseNode->Coach;
if(!empty($Coach)){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
$rsCoach = api_sql_query($sqlCoach,__FILE__,__LINE__);
list($CoachId) = (mysql_fetch_array($rsCoach));
if(empty($CoachId))
{
$errorMsg .= get_lang('UserDoesNotExist').' : '.$Coach.'< br / > ';
}
}
else {
$Coach = '';
}
$rsUser = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countUsers++;
$sqlCourse = "INSERT INTO $tbl_session_course SET
course_code = '$CourseCode',
id_coach='$Coach',
id_session='$session_id'";
$rsCourse = api_sql_query($sqlCourse,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countCourses++;
$countUsersCourses = 0;
foreach ($courseNode->User as $userNode){
$username = substr($userNode,0,19);
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$username."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
if(!empty($user_id))
{
$sql = "INSERT IGNORE INTO $tbl_session_user SET
id_user='$user_id',
id_session = '$session_id'";
if(mysql_affected_rows())
$countUsers++;
$rsUser = api_sql_query($sql,__FILE__,__LINE__);
$sql = "INSERT IGNORE INTO $tbl_session_course_user SET
id_user='$user_id',
course_code='$CourseCode',
id_session = '$session_id'";
$rsUsers = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows())
$countUsersCourses++;
}
else
{
$errorMsg .= get_lang('UserDoesNotExist').' : '.$username.'< br / > ';
}
}
api_sql_query("UPDATE $tbl_session_course SET nbr_users='$countUsersCourses' WHERE course_code='$CourseCode'",__FILE__,__LINE__);
}
}
else
{ // if the course does not exists
$errorMsg .= get_lang('CourseDoesNotExist').' : '.$CourseCode.'< br / > ';
}
}
api_sql_query("UPDATE $tbl_session SET nbr_users='$countUsers', nbr_courses='$countCourses' WHERE id='$session_id'",__FILE__,__LINE__);
}
}
/////////////////////
// CSV /////////////
///////////////////
else
{
$content=file($_FILES['import_file']['tmp_name']);
if(!strstr($content[0],';'))
{
$errorMsg=get_lang('NotCSV');
}
else
{
$tag_names=array();
foreach($content as $key=>$enreg)
{
$enreg=explode(';',trim($enreg));
if($key)
{
foreach($tag_names as $tag_key=>$tag_name)
{
$sessions[$key-1][$tag_name]=$enreg[$tag_key];
}
}
else
{
foreach($enreg as $tag_name)
{
$tag_names[]=eregi_replace('[^a-z0-9_-]','',$tag_name);
}
$courses = explode('|',$enreg['Courses']);
foreach($courses as $course){
$CourseCode = substr($course,0,strpos($course,'['));
if(!in_array('SessionName',$tag_names) || !in_array('DateStart',$tag_names) || !in_array('DateEnd',$tag_names))
{
$errorMsg=get_lang('NoNeededData' );
$Coach = strstr($course,'[');
$Coach = substr($Coach,1,strpos($Coach,']')-1);
break;
}
}
}
if(!empty($Coach)){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
$rsCoach = api_sql_query($sqlCoach,__FILE__,__LINE__);
foreach($sessions as $enreg) {
$SessionName = $enreg['SessionName'];
$DateStart = $enreg['DateStart'];
$DateEnd = $enreg['DateEnd'];
if(!empty($enreg['Coach'])){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='".$enreg['Coach']."'";
$rsCoach = api_sql_query($sqlCoach);
list($Coach) = (mysql_fetch_array($rsCoach));
}
else {
$Coach = '';
}
$sqlCourse = "INSERT INTO $tbl_session_course SET
course_code = '$CourseCode',
id_coach='$Coach',
id_session='$session_id'";
$rsCourse = api_sql_query($sqlCourse,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countCourses++;
$users = substr($course , strpos($course,'[',1)+1 , strpos($course,']',1));
$users = explode('|',$enreg['Users']);
$countUsersCourses = 0;
foreach ($users as $user){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$user."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
$sql = "INSERT INTO $tbl_session_course_user SET
id_user='$user_id',
course_code='$CourseCode',
id_session = '$session_id'";
$rsUsers = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows())
$countUsersCourses++;
$sqlSession = "INSERT IGNORE INTO $tbl_session SET
name = '$SessionName',
id_coach = '$Coach',
date_start = '$DateStart',
date_end = '$DateEnd'";
$rsSession = api_sql_query($sqlSession, __FILE__, __LINE__);
$update = false;
if(!mysql_affected_rows($rsSession)){
$update = true;
$sqlSession = "UPDATE $tbl_session SET
id_coach = '$Coach',
date_start = '$DateStart',
date_end = '$DateEnd'
WHERE name = '$SessionName'";
$rsSession = api_sql_query($sqlSession, __FILE__, __LINE__);
$session_id = api_sql_query("SELECT id FROM $tbl_session WHERE name='$SessionName'",__FILE__,__LINE__);
list($session_id) = mysql_fetch_array($session_id);
api_sql_query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'",__FILE__,__LINE__);
api_sql_query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'",__FILE__,__LINE__);
api_sql_query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'",__FILE__,__LINE__);
}
else {
$session_id = mysql_insert_id($rsSession);
}
$users = explode('|',$enreg['Users']);
foreach ($users as $user){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$user."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
$sql = "INSERT INTO $tbl_session_user SET
id_user='$user_id',
id_session = '$session_id'";
$rsUser = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countUsers++;
}
api_sql_query("UPDATE $tbl_session_course SET nbr_users='$countUsersCourses' WHERE course_code='$CourseCode'",__FILE__,__LINE__);
}
}
api_sql_query("UPDATE $tbl_session SET nbr_users='$countUsers', nbr_courses='$countCourses' WHERE id='$session_id'",__FILE__,__LINE__);
$courses = explode('|',$enreg['Courses']);
foreach($courses as $course){
$CourseCode = substr($course,0,strpos($course,'['));
$Coach = strstr($course,'[');
$Coach = substr($Coach,1,strpos($Coach,']')-1);
if(!empty($Coach)){
$sqlCoach = "SELECT user_id FROM $tbl_user WHERE username='$Coach'";
$rsCoach = api_sql_query($sqlCoach,__FILE__,__LINE__);
list($Coach) = (mysql_fetch_array($rsCoach));
}
else {
$Coach = '';
}
$sqlCourse = "INSERT INTO $tbl_session_course SET
course_code = '$CourseCode',
id_coach='$Coach',
id_session='$session_id'";
$rsCourse = api_sql_query($sqlCourse,__FILE__,__LINE__);
if(mysql_affected_rows()){
$countCourses++;
$users = substr($course , strpos($course,'[',1)+1 , strpos($course,']',1));
$users = explode('|',$enreg['Users']);
$countUsersCourses = 0;
foreach ($users as $user){
$sqlUser = "SELECT user_id FROM $tbl_user WHERE username='".$user."'";
$rsUser = api_sql_query($sqlUser);
list($user_id) = (mysql_fetch_array($rsUser));
$sql = "INSERT INTO $tbl_session_course_user SET
id_user='$user_id',
course_code='$CourseCode',
id_session = '$session_id'";
$rsUsers = api_sql_query($sql,__FILE__,__LINE__);
if(mysql_affected_rows())
$countUsersCourses++;
}
api_sql_query("UPDATE $tbl_session_course SET nbr_users='$countUsersCourses' WHERE course_code='$CourseCode'",__FILE__,__LINE__);
}
}
api_sql_query("UPDATE $tbl_session SET nbr_users='$countUsers', nbr_courses='$countCourses' WHERE id='$session_id'",__FILE__,__LINE__);
}
}
}
if(!empty($errorMsg))
{
$errorMsg = get_lang('ButProblemsOccured').' :< br / > '.$errorMsg;
}
header('Location: session_list.php?action=show_message& message='.urlencode(get_lang('FileImported').' '.$errorMsg));
}
else
{
$errorMsg = get_lang('NoInputFile');
}
header('Location: session_list.php?action=show_message&message='.urlencode(get_lang('FileImported')));
}
Display::display_header($tool_name);
api_display_tool_title($tool_name);
@ -392,8 +581,14 @@ if(!empty($errorMsg))
< tr >
< td nowrap = "nowrap" valign = "top" > <?php echo get_lang ( 'FileType' ); ?> :</ td >
< td >
< input class = "checkbox" type = "radio" name = "file_type" id = "file_type_xml" value = "xml" <?php if ( $formSent && $file_type == 'xml' ) echo 'checked="checked"' ; ?> > < label for = "file_type_xml" > XML</ label > (< a href = "exemple.xml" target = "_blank" > <?php echo get_lang ( 'ExampleXMLFile' ); ?> </ a > )< br >
< input class = "checkbox" type = "radio" name = "file_type" id = "file_type_csv" value = "csv" <?php if ( ! $formSent || $file_type == 'csv' ) echo 'checked="checked"' ; ?> > < label for = "file_type_csv" > CSV</ label > (< a href = "exemple.csv" target = "_blank" > <?php echo get_lang ( 'ExampleCSVFile' ); ?> </ a > )< br >
< input class = "checkbox" type = "radio" name = "file_type" id = "file_type_xml" value = "xml" checked = "checked" /> < label for = "file_type_xml" > XML</ label > (< a href = "exemple.xml" target = "_blank" > <?php echo get_lang ( 'ExampleXMLFile' ); ?> </ a > )< br >
< input class = "checkbox" type = "radio" name = "file_type" id = "file_type_csv" value = "csv" <?php if ( $formSent && $file_type == 'csv' ) echo 'checked="checked"' ; ?> > < label for = "file_type_csv" > CSV</ label > (< a href = "exempleSession.csv" target = "_blank" > <?php echo get_lang ( 'ExampleCSVFile' ); ?> </ a > )< br >
< / td >
< / tr >
< tr >
< td nowrap = "nowrap" valign = "top" > <?php echo get_lang ( 'SendMailToUsers' ); ?> :</ td >
< td >
< input class = "checkbox" type = "checkbox" name = "sendMail" id = "sendMail" value = "true" / >
< / td >
< / tr >
< tr >
@ -419,6 +614,27 @@ if(!empty($errorMsg))
< pre >
< ?xml version=" 1.0" encoding=" ISO-8859-1" ?>
< Sessions>
< Users>
< User>
< Username> < b > username1< / b > < /Username>
< Lastname> xxx< /Lastname>
< Firstname> xxx< /Firstname>
< Password> xxx< /Password>
< Email> xxx@xx.xx< /Email>
< OfficialCode> xxx< /OfficialCode>
< Phone> xxx< /Phone>
< Status> student|teacher< /Status>
< /User>
< /Users>
< Courses>
< Course>
< CourseCode> < b > xxx< / b > < /CourseCode>
< CourseTeacher> xxx< /CourseTeacher>
< CourseLanguage> xxx< /CourseLanguage>
< CourseTitle> xxx< /CourseTitle>
< CourseDescription> xxx< /CourseDescription>
< /Course>
< /Courses>
< Session>
< b > < SessionName> xxx< /SessionName> < / b >
< Coach> xxx< /Coach>