Minor - format code.

1.9.x
Julio Montoya 11 years ago
parent 6139f9d2c6
commit fc22975709
  1. 94
      main/admin/add_courses_to_session.php
  2. 91
      main/admin/resume_session.php

@ -20,7 +20,7 @@ $add = isset($_GET['add']) ? Security::remove_XSS($_GET['add']) : null;
SessionManager::protect_session_edit($id_session);
$xajax = new xajax();
$xajax->registerFunction (array('search_courses', 'AddCourseToSession', 'search_courses'));
$xajax->registerFunction(array('search_courses', 'AddCourseToSession', 'search_courses'));
// Setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
@ -47,29 +47,25 @@ if(isset($_GET['add_type']) && $_GET['add_type']!=''){
$page = isset($_GET['page']) ? Security::remove_XSS($_GET['page']) : null;
$xajax -> processRequests();
$xajax->processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = '
<script type="text/javascript">
function add_course_to_session (code, content) {
$htmlHeadXtra[] = '<script>
function add_course_to_session(code, content) {
document.getElementById("course_to_add").value = "";
document.getElementById("ajax_list_courses_single").innerHTML = "";
destination = document.getElementById("destination");
for (i=0;i<destination.length;i++) {
if(destination.options[i].text == content) {
return false;
return false;
}
}
destination.options[destination.length] = new Option(content,code);
destination.selectedIndex = -1;
sortOptions(destination.options);
}
function remove_item(origin)
{
for(var i = 0 ; i<origin.options.length ; i++) {
@ -81,17 +77,17 @@ function remove_item(origin)
}
</script>';
$formSent=0;
$errorMsg=$firstLetterCourse=$firstLetterSession='';
$CourseList=$SessionList=array();
$courses=$sessions=array();
$noPHP_SELF=true;
$formSent = 0;
$errorMsg = $firstLetterCourse = $firstLetterSession = '';
$CourseList = $SessionList = array();
$courses = $sessions = array();
$noPHP_SELF = true;
if (isset($_POST['formSent']) && $_POST['formSent']) {
$formSent = $_POST['formSent'];
$firstLetterCourse = $_POST['firstLetterCourse'];
$firstLetterSession = $_POST['firstLetterSession'];
$CourseList = $_POST['SessionCoursesList'];
$formSent = $_POST['formSent'];
$firstLetterCourse = $_POST['firstLetterCourse'];
$firstLetterSession = $_POST['firstLetterSession'];
$CourseList = $_POST['SessionCoursesList'];
if (!is_array($CourseList)) {
$CourseList = array();
}
@ -105,21 +101,20 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$existingCourses = Database::store_result($rs);
// Updating only the RRHH users?? why?
//$sql="SELECT id_user FROM $tbl_session_rel_user WHERE id_session = $id_session AND relation_type=".COURSE_RELATION_TYPE_RRHH." ";
$sql = "SELECT id_user FROM $tbl_session_rel_user WHERE id_session = $id_session ";
$result = Database::query($sql);
$UserList = Database::store_result($result);
$sql = "SELECT id_user FROM $tbl_session_rel_user WHERE id_session = $id_session ";
$result = Database::query($sql);
$UserList = Database::store_result($result);
foreach($CourseList as $enreg_course) {
foreach ($CourseList as $enreg_course) {
$enreg_course = Database::escape_string($enreg_course);
$exists = false;
foreach($existingCourses as $existingCourse) {
if($enreg_course == $existingCourse['course_code']) {
$exists=true;
}
}
if(!$exists) {
foreach ($existingCourses as $existingCourse) {
if ($enreg_course == $existingCourse['course_code']) {
$exists = true;
}
}
if (!$exists) {
$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code) VALUES('$id_session','$enreg_course')";
Database::query($sql_insert_rel_course);
@ -131,7 +126,8 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
$nbr_users=0;
foreach ($UserList as $enreg_user) {
$enreg_user = Database::escape_string($enreg_user['id_user']);
$sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$enreg_course','$enreg_user')";
$sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user)
VALUES('$id_session','$enreg_course','$enreg_user')";
Database::query($sql_insert);
if(Database::affected_rows()) {
$nbr_users++;
@ -149,7 +145,6 @@ if (isset($_POST['formSent']) && $_POST['formSent']) {
Database::query("DELETE FROM $tbl_session_rel_course WHERE course_code='".$existingCourse['course_code']."' AND id_session=$id_session");
Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE course_code='".$existingCourse['course_code']."' AND id_session=$id_session");
SessionManager::unInstallCourse($id_session, $course_info['real_id']);
}
}
$nbr_courses=count($CourseList);
@ -168,12 +163,12 @@ Display::display_header($tool_name);
if ($add_type == 'multiple') {
$link_add_type_unique = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.$add.'&add_type=unique">'.
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'</a>';
$link_add_type_multiple = Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').' ';
} else {
$link_add_type_unique = Display::return_icon('single.gif').get_lang('SessionAddTypeUnique').'&nbsp;&nbsp;&nbsp;';
$link_add_type_multiple = '<a href="'.api_get_self().'?id_session='.$id_session.'&add='.$add.'&add_type=multiple">'.
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
Display::return_icon('multiple.gif').get_lang('SessionAddTypeMultiple').'</a>';
}
// the form header
@ -205,7 +200,6 @@ if ($ajax_search) {
INNER JOIN $tbl_course_rel_access_url url_course ON (url_course.course_code=course.code)
WHERE access_url_id = $access_url_id
ORDER BY ".(sizeof($courses)?"(code IN(".implode(',',$courses).")) DESC,":"")." title";
}
}
@ -239,7 +233,7 @@ if ($ajax_search) {
}
$result = Database::query($sql);
$Courses = Database::store_result($result);
foreach($Courses as $course) {
foreach ($Courses as $course) {
if ($course['id_session'] == $id_session) {
$sessionCourses[$course['code']] = $course ;
} else {
@ -254,8 +248,7 @@ unset($Courses);
<input type="hidden" name="formSent" value="1" />
<?php
if(!empty($errorMsg))
{
if (!empty($errorMsg)) {
Display::display_normal_message($errorMsg); //main API
}
?>
@ -295,10 +288,11 @@ if (!($add_type == 'multiple')) {
?>
<div id="ajax_list_courses_multiple">
<select id="origin" name="NoSessionCoursesList[]" multiple="multiple" size="20" style="width:360px;"> <?php
foreach($nosessionCourses as $enreg)
{
foreach($nosessionCourses as $enreg) {
?>
<option value="<?php echo $enreg['code']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
<option value="<?php echo $enreg['code']; ?>" <?php echo 'title="'.htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES).'"'; if(in_array($enreg['code'],$CourseList)) echo 'selected="selected"'; ?>>
<?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?>
</option>
<?php
}
?></select>
@ -324,7 +318,7 @@ unset($nosessionCourses);
?>
<br /><br /><br /><br /><br /><br />
<?php
if(isset($_GET['add'])) {
if (isset($_GET['add'])) {
echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('NextStep').'</button>';
} else {
echo '<button class="save" type="button" value="" onclick="valide()" >'.get_lang('SubscribeCoursesToSession').'</button>';
@ -334,11 +328,11 @@ unset($nosessionCourses);
<td width="45%" align="center"><select id='destination' name="SessionCoursesList[]" multiple="multiple" size="20" style="width:360px;">
<?php
foreach($sessionCourses as $enreg)
{
foreach($sessionCourses as $enreg) {
?>
<option value="<?php echo $enreg['code']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>"><?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?></option>
<option value="<?php echo $enreg['code']; ?>" title="<?php echo htmlspecialchars($enreg['title'].' ('.$enreg['visual_code'].')',ENT_QUOTES); ?>">
<?php echo $enreg['title'].' ('.$enreg['visual_code'].')'; ?>
</option>
<?php
}
unset($sessionCourses);
@ -347,7 +341,7 @@ unset($sessionCourses);
</tr>
</table>
</form>
<script type="text/javascript">
<script>
function moveItem(origin , destination) {
for(var i = 0 ; i<origin.options.length ; i++) {
if(origin.options[i].selected) {
@ -374,7 +368,7 @@ function sortOptions(options) {
}
}
function mysort(a, b){
function mysort(a, b) {
if(a.text.toLowerCase() > b.text.toLowerCase()){
return 1;
}
@ -384,7 +378,7 @@ function mysort(a, b){
return 0;
}
function valide(){
function valide() {
var options = document.getElementById('destination').options;
for (i = 0 ; i<options.length ; i++)
options[i].selected = true;

@ -35,15 +35,32 @@ $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY)
$table_access_url_user = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes, DATE_FORMAT(date_start,"%d-%m-%Y") as date_start, DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility
FROM '.$tbl_session.' LEFT JOIN '.$tbl_user.' ON id_coach = user_id
$sql = 'SELECT
name,
nbr_courses,
nbr_users,
nbr_classes,
DATE_FORMAT(date_start,"%d-%m-%Y") as date_start,
DATE_FORMAT(date_end,"%d-%m-%Y") as date_end,
lastname,
firstname,
username,
session_admin_id,
nb_days_access_before_beginning,
nb_days_access_after_end,
session_category_id,
visibility
FROM '.$tbl_session.'
LEFT JOIN '.$tbl_user.'
ON id_coach = user_id
WHERE '.$tbl_session.'.id='.$id_session;
$rs = Database::query($sql);
$session = Database::store_result($rs);
$session = $session[0];
$sql = 'SELECT name FROM '.$tbl_session_category.' WHERE id = "'.intval($session['session_category_id']).'"';
$sql = 'SELECT name FROM '.$tbl_session_category.'
WHERE id = "'.intval($session['session_category_id']).'"';
$rs = Database::query($sql);
$session_category = '';
@ -63,12 +80,15 @@ switch($action) {
$result = UrlManager::add_user_to_url($user_id, $url_id);
$user_info = api_get_user_info($user_id);
if ($result) {
$message = Display::return_message(get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']), 'confirm');
$message = Display::return_message(
get_lang('UserAdded').' '.api_get_person_name($user_info['firstname'], $user_info['lastname']),
'confirm'
);
}
break;
case 'delete':
$idChecked = $_GET['idChecked'];
if(is_array($idChecked)) {
if (is_array($idChecked)) {
$my_temp = array();
foreach ($idChecked as $id){
$my_temp[]= Database::escape_string($id);// forcing the escape_string
@ -84,7 +104,7 @@ switch($action) {
Database::query("UPDATE $tbl_session SET nbr_courses=nbr_courses-$nbr_affected_rows WHERE id='$id_session'");
}
if(!empty($_GET['class'])){
if (!empty($_GET['class'])){
Database::query("DELETE FROM $tbl_session_rel_class WHERE session_id='$id_session' AND class_id=".Database::escape_string($_GET['class']));
$nbr_affected_rows=Database::affected_rows();
Database::query("UPDATE $tbl_session SET nbr_classes=nbr_classes-$nbr_affected_rows WHERE id='$id_session'");
@ -115,7 +135,10 @@ if (!empty($message)) {
echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']);
$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_edit.php?page=resume_session.php&id=$id_session");
$url = Display::url(
Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
"session_edit.php?page=resume_session.php&id=$id_session"
);
echo Display::page_subheader(get_lang('GeneralProperties').$url);
?>
@ -139,7 +162,6 @@ echo Display::page_subheader(get_lang('GeneralProperties').$url);
echo get_lang('NoTimeLimits');
else {
if ($session['date_start'] != '00-00-0000') {
//$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
$session['date_start'] = get_lang('From').' '.$session['date_start'];
} else {
$session['date_start'] = '';
@ -176,7 +198,14 @@ echo Display::page_subheader(get_lang('GeneralProperties').$url);
<?php echo api_ucfirst(get_lang('SessionVisibility')) ?> :
</td>
<td>
<?php if ($session['visibility']==1) echo get_lang('ReadOnly'); elseif($session['visibility']==2) echo get_lang('Visible');elseif($session['visibility']==3) echo api_ucfirst(get_lang('Invisible')) ?>
<?php
if ($session['visibility']==1)
echo get_lang('ReadOnly');
elseif($session['visibility']==2)
echo get_lang('Visible');
elseif($session['visibility']==3)
echo api_ucfirst(get_lang('Invisible'));
?>
</td>
</tr>
@ -201,7 +230,10 @@ if ($multiple_url_is_on) {
<?php
$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "add_courses_to_session.php?page=resume_session.php&id_session=$id_session");
$url = Display::url(
Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
"add_courses_to_session.php?page=resume_session.php&id_session=$id_session"
);
echo Display::page_subheader(get_lang('CourseList').$url);
?>
@ -215,7 +247,7 @@ echo Display::page_subheader(get_lang('CourseList').$url);
<th width="15%"><?php echo get_lang('Actions'); ?></th>
</tr>
<?php
if ($session['nbr_courses'] == 0){
if ($session['nbr_courses'] == 0) {
echo '<tr>
<td colspan="4">'.get_lang('NoCoursesForThisSession').'</td>
</tr>';
@ -223,25 +255,36 @@ if ($session['nbr_courses'] == 0){
// select the courses
$sql = "SELECT code,title,visual_code, nbr_users
FROM $tbl_course,$tbl_session_rel_course
WHERE course_code = code
AND id_session='$id_session'
WHERE
course_code = code AND
id_session='$id_session'
ORDER BY title";
$result=Database::query($sql);
$courses=Database::store_result($result);
foreach ($courses as $course) {
//select the number of users
$sql = " SELECT count(*) FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
WHERE srcru.id_user = sru.id_user AND srcru.id_session = sru.id_session AND srcru.course_code = '".Database::escape_string($course['code'])."'
AND sru.relation_type<>".SESSION_RELATION_TYPE_RRHH." AND srcru.id_session = '".intval($id_session)."'";
$sql = "SELECT count(*)
FROM $tbl_session_rel_user sru, $tbl_session_rel_course_rel_user srcru
WHERE
srcru.id_user = sru.id_user AND
srcru.id_session = sru.id_session AND
srcru.course_code = '".Database::escape_string($course['code'])."' AND
sru.relation_type <> ".SESSION_RELATION_TYPE_RRHH." AND
srcru.id_session = '".intval($id_session)."'";
$rs = Database::query($sql);
$course['nbr_users'] = Database::result($rs,0,0);
// Get coachs of the courses in session
$sql = "SELECT user.lastname,user.firstname,user.username FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
WHERE session_rcru.id_user = user.user_id AND session_rcru.id_session = '".intval($id_session)."' AND session_rcru.course_code ='".Database::escape_string($course['code'])."' AND session_rcru.status=2";
$sql = "SELECT user.lastname,user.firstname,user.username
FROM $tbl_session_rel_course_rel_user session_rcru, $tbl_user user
WHERE
session_rcru.id_user = user.user_id AND
session_rcru.id_session = '".intval($id_session)."' AND
session_rcru.course_code ='".Database::escape_string($course['code'])."' AND
session_rcru.status=2";
$rs = Database::query($sql);
$coachs = array();
@ -283,8 +326,14 @@ if ($session['nbr_courses'] == 0){
<?php
$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "add_users_to_session.php?page=resume_session.php&id_session=$id_session");
$url .= Display::url(Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL), "session_user_import.php?id_session=$id_session");
$url = Display::url(
Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL),
"add_users_to_session.php?page=resume_session.php&id_session=$id_session"
);
$url .= Display::url(
Display::return_icon('import_csv.png', get_lang('ImportUsers'), array(), ICON_SIZE_SMALL),
"session_user_import.php?id_session=$id_session"
);
echo Display::page_subheader(get_lang('UserList').$url);
?>
@ -360,4 +409,4 @@ if ($session['nbr_users']==0) {
</table>
<?php
// footer
Display :: display_footer();
Display :: display_footer();

Loading…
Cancel
Save