"index.php","name" => get_lang('AdministrationTools')); set_time_limit(0); if($_POST['formSent'] ) { $formSent=$_POST['formSent']; $file_type=($_POST['file_type'] == 'csv')?'csv':'xml'; $session_id=$_POST['session_id']; if(empty($session_id)) { $result=api_sql_query("SELECT id,name,id_coach,date_start,date_end FROM $tbl_session ORDER BY id",__FILE__,__LINE__); } else { $sql = "SELECT id,name,username,date_start,date_end FROM $tbl_session INNER JOIN $tbl_user ON $tbl_user.user_id = $tbl_session.id_coach WHERE id='$session_id'"; $result = api_sql_query($sql,__FILE__,__LINE__); } if(mysql_num_rows($result)) { if(!file_exists($archivePath)) { mkpath($archivePath); } if(!file_exists($archivePath.'index.html')) { $fp=fopen($archivePath.'index.html','w'); fputs($fp,''); fclose($fp); } $archiveFile='export_sessions_'.$session_id.'_'.date('Y-m-d_H-i-s').'.'.$file_type; while( file_exists($archivePath.$archiveFile)) { $archiveFile='export_users_'.$session_id.'_'.date('Y-m-d_H-i-s').'_'.uniqid('').'.'.$file_type; } $fp=fopen($archivePath.$archiveFile,'w'); if($file_type == 'csv') { $cvs = true; fputs($fp,"SessionName;Coach;DateStart;DateEnd;Users;Courses;\n"); } else { $cvs = false; fputs($fp,"\n\n"); } while($row=mysql_fetch_array($result)) { $add = ''; $row['name'] = str_replace(';',',',$row['name']); $row['username'] = str_replace(';',',',$row['username']); $row['date_start'] = str_replace(';',',',$row['date_start']); $row['date_end'] = str_replace(';',',',$row['date_end']); if($cvs){ $add.= $row['name'].';'.$row['username'].';'.$row['date_start'].';'.$row['date_end'].';'; } else { $add = "\t\n" ."\t\t$row[name]\n" ."\t\t$row[username]\n" ."\t\t$row[date_start]\n" ."\t\t$row[date_end]\n"; } //users $sql = "SELECT DISTINCT $tbl_user.username FROM $tbl_user INNER JOIN $tbl_session_user ON $tbl_user.user_id = $tbl_session_user.id_user AND $tbl_session_user.id_session = '".$row['id']."'"; $rsUsers = api_sql_query($sql,__FILE__,__LINE__); $users = ''; while($rowUsers = mysql_fetch_array($rsUsers)){ if($cvs){ $users .= str_replace(';',',',$rowUsers['username']).'|'; } else { $users .= "\t\t$rowUsers[username]\n"; } } if(!empty($users) && $cvs) $users = substr($users , 0, strlen($users)-1); if($cvs) $users .= ';'; $add .= $users; //courses $sql = "SELECT DISTINCT $tbl_course.code, $tbl_user.username FROM $tbl_course INNER JOIN $tbl_session_course ON $tbl_course.code = $tbl_session_course.course_code AND $tbl_session_course.id_session = '".$row['id']."' LEFT JOIN $tbl_user ON $tbl_user.user_id = $tbl_session_course.id_coach"; $rsCourses = api_sql_query($sql,__FILE__,__LINE__); $courses = ''; while($rowCourses = mysql_fetch_array($rsCourses)){ if($cvs){ $courses .= str_replace(';',',',$rowCourses['code']); $courses .= '['.str_replace(';',',',$rowCourses['username']).']['; } else { $courses .= "\t\t\n"; $courses .= "\t\t\t$rowCourses[code]\n"; $courses .= "\t\t\t$rowCourses[username]\n"; } // rel user courses $sql = "SELECT DISTINCT username FROM $tbl_user INNER JOIN $tbl_session_course_user ON $tbl_session_course_user.id_user = $tbl_user.user_id AND $tbl_session_course_user.course_code='".$rowCourses['code']."' AND id_session='".$row['id']."'"; $rsUsersCourse = api_sql_query($sql,__FILE__,__LINE__); while($rowUsersCourse = mysql_fetch_array($rsUsersCourse)){ if($cvs){ $userscourse .= str_replace(';',',',$rowUsersCourse['username']).','; } else { $courses .= "\t\t\t$rowUsersCourse[username]\n"; } } if($cvs){ if(!empty($userscourse)) $userscourse = substr($userscourse , 0, strlen($userscourse)-1); $courses .= $userscourse.']|'; } else { $courses .= "\t\t\n"; } } if(!empty($courses) && $cvs) $courses = substr($courses , 0, strlen($courses)-1); $add .= $courses; if($cvs) $add .= ';'; else $add .= "\t\n"; fputs($fp, $add); } if(!$cvs) fputs($fp,"\n"); fclose($fp); $errorMsg=get_lang('UserListHasBeenExported').'
'.get_lang('ClickHereToDownloadTheFile').''; } } Display::display_header($tool_name); api_display_tool_title($tool_name); //select of sessions $sql = "SELECT id, name FROM $tbl_session ORDER BY name"; $result=api_sql_query($sql,__FILE__,__LINE__); $Sessions=api_store_result($result); ?>
: >
>
: