diff --git a/main/admin/course_intro_pdf_import.php b/main/admin/course_intro_pdf_import.php new file mode 100644 index 0000000000..b11a197903 --- /dev/null +++ b/main/admin/course_intro_pdf_import.php @@ -0,0 +1,161 @@ + 'index.php', 'name' => get_lang('PlatformAdmin')); + +set_time_limit(0); +Display :: display_header($tool_name); + +if ($_POST['formSent']) { + if (empty($_FILES['import_file']['tmp_name'])) { + $error_message = get_lang('UplUploadFailed'); + Display :: display_error_message($error_message, false); + } else { + $allowed_file_mimetype = array('zip'); + + $ext_import_file = substr($_FILES['import_file']['name'], (strrpos($_FILES['import_file']['name'], '.') + 1)); + + if (!in_array($ext_import_file, $allowed_file_mimetype)) { + Display :: display_error_message(get_lang('YouMustImportAZipFile')); + } else { + $errors = import_pdfs($courses, $subDir); + if (count($errors) == 0) { + error_log('Course intros imported successfully in '.__FILE__.', line '.__LINE__); + } + } + } +} + +if (count($errors) != 0) { + $error_message = ''; + Display :: display_normal_message($error_message, false); +} elseif ($_POST['formSent']) { + Display :: display_confirmation_message('CourseIntroductionsAllImportesSuccessfully', false); +} +?> +
+ +
+ +
+ +
+
+
+
+ +
+
+ +
+
+

+ +
+
+CourseCode_NameOfDocument_CourseName.pdf
+e.g.
+MAT101_Introduction_Mathematics-101.pdf
+MAT102_Introduction_Mathematics-102.pdf
+ENG101_Introduction_English-101.pdf
+
+
+ + 0) { + // Build file info because handle_uploaded_document() needs it (name, type, size, tmp_name) + $fileSize = filesize($baseDir.$uploadPath.$file); + $docId = add_document($course, $subDir.'/'.$file, 'file', $fileSize, $parts[1].' '.substr($parts[2],0,-4)); + if ($docId > 0) { + if (!is_file($baseDir.$uploadPath.$file)) { + error_log($baseDir.$uploadPath.$file.' does not exists in '.__FILE__); + } + if (is_file(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file)) { + error_log(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file.' exists at destination in '.__FILE__); + } + if (!is_writeable(api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir)) { + error_log('Destination '.api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.' is NOT writeable in '.__FILE__); + } + // Place each file in its folder in each course + $move = rename($baseDir.$uploadPath.$file, api_get_path(SYS_COURSE_PATH).$course['path'].'/document'.$subDir.'/'.$file); + api_item_property_update($course, TOOL_DOCUMENT, $docId, 'DocumentAdded', api_get_user_id()); + // Redo visibility + api_set_default_visibility(TOOL_DOCUMENT, $docId); + $errors[] = array('Line' => 0, 'Code' => $course['code'], 'Title' => $course['title']); + // Now add a link to the file from the Course description tool + $link = '

Sílabo de la asignatura

'; + $course_description = new CourseDescription(); + $session_id = api_get_session_id(); + $course_description->set_course_id($course['real_id']); + $course_description->set_session_id($session_id); + $course_description->set_title('Presentación de la asignatura'); + $course_description->set_content($link); + $course_description->set_description_type(1); + $course_description->insert(); + } + } else { + error_log($parts[0].' is not a course, apparently'); + $errors[] = array('Line' => 0, 'Code' => $parts[0], 'Title' => $parts[0].' - '.get_lang('CodeDoesNotExists')); + } + $i++; //found at least one entry that is not a dir or a . + } + if ($i == 0) { + $errors[] = array('Line' => 0, 'Code' => '.', 'Title' => get_lang('NoPDFFoundAtRoot')); + } + return $errors; +} diff --git a/main/admin/session_course_edit.php b/main/admin/session_course_edit.php new file mode 100644 index 0000000000..28d2ce767c --- /dev/null +++ b/main/admin/session_course_edit.php @@ -0,0 +1,160 @@ + 'index.php',"name" => get_lang('PlatformAdmin')); +$interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang("SessionList")); +$interbreadcrumb[]=array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview')); +$interbreadcrumb[]=array('url' => "session_course_list.php?id_session=$id_session","name" =>api_htmlentities($session_name,ENT_QUOTES,$charset)); + +$result = Database::query("SELECT s.name, c.title FROM $tbl_session_course sc,$tbl_session s,$tbl_course c WHERE sc.id_session=s.id AND sc.course_code=c.code AND sc.id_session='$id_session' AND sc.course_code='".addslashes($course_code)."'"); + +if (!list($session_name,$course_title)=Database::fetch_row($result)) { + header('Location: session_course_list.php?id_session='.$id_session); + exit(); +} + +$arr_infos = array(); +if ($_POST['formSent']) { + $formSent=1; + + // get all tutor by course_code in the session + $sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user + WHERE id_session = '$id_session' AND course_code = '$course_code' AND status = 2"; + $rs_coachs = Database::query($sql); + + $coachs_course_session = array(); + if (Database::num_rows($rs_coachs) > 0){ + while ($row_coachs = Database::fetch_row($rs_coachs)) { + $coachs_course_session[] = $row_coachs[0]; + } + } + + $id_coachs= $_POST['id_coach']; + + if (is_array($id_coachs) && count($id_coachs) > 0) { + + foreach ($id_coachs as $id_coach) { + $id_coach = intval($id_coach); + $rs1 = SessionManager::set_coach_to_course_session($id_coach, $id_session, $course_code); + } + + // set status to 0 other tutors from multiple list + $array_intersect = array_diff($coachs_course_session,$id_coachs); + + foreach ($array_intersect as $nocoach_user_id) { + $rs2 = SessionManager::set_coach_to_course_session($nocoach_user_id, $id_session, $course_code,true); + } + + header('Location: '.Security::remove_XSS($_GET['page']).'?id_session='.$id_session); + exit(); + + } +} else { + $sql = "SELECT id_user FROM $tbl_session_rel_course_rel_user + WHERE id_session = '$id_session' AND course_code = '$course_code' AND status = 2 "; + $rs = Database::query($sql); + + if (Database::num_rows($rs) > 0) { + while ($infos = Database::fetch_array($rs)) { + $arr_infos[] = $infos['id_user']; + } + } +} + +$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; +global $_configuration; +if ($_configuration['multiple_access_urls']) { + $tbl_access_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + $sql="SELECT u.user_id,lastname,firstname,username + FROM $tbl_user u LEFT JOIN $tbl_access_rel_user a ON(u.user_id= a.user_id) + WHERE status='1' AND active = 1 AND access_url_id = $access_url_id ".$order_clause; +} else { + $sql="SELECT user_id,lastname,firstname,username + FROM $tbl_user + WHERE status='1' AND active = 1 ".$order_clause; +} + +$result = Database::query($sql); +$coaches = Database::store_result($result); +Display::display_header($tool_name); + +$tool_name = get_lang('ModifySessionCourse'); +api_display_tool_title($tool_name); +?> +
+ + + + + + + + + + + + + + + + +
+ +
   + +
  + +
+
+ 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList')); +$interbreadcrumb[] = array('url' => 'resume_session.php?id_session='.Security::remove_XSS($_GET['id_session']),'name' => get_lang('SessionOverview')); + +// Database Table Definitions +$tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); +$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); +$tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); +$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); +$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); + +// setting the name of the tool +$tool_name = get_lang('EditSessionCoursesByUser'); + +$id_user = intval($_GET['id_user']); + +if (empty($id_user) || empty($id_session)) { + header('Location: resume_session.php?id_session='.$id_session); +} + +if (!api_is_platform_admin()) { + $sql = 'SELECT session_admin_id FROM '.Database :: get_main_table(TABLE_MAIN_SESSION).' WHERE id='.$id_session; + $rs = Database::query($sql); + if (Database::result($rs,0,0)!=$_user['user_id']) { + api_not_allowed(true); + } +} + +$formSent=0; +$errorMsg=$firstLetterCourse=$firstLetterSession=''; +$CourseList=$SessionList=array(); +$courses=$sessions=array(); +$noPHP_SELF=true; + +if ($_POST['formSent']) { + $formSent = $_POST['formSent']; + $CourseList = $_POST['SessionCoursesList']; + + if (!is_array($CourseList)) { + $CourseList=array(); + } + + $sql="SELECT distinct code + FROM $tbl_course course LEFT JOIN $tbl_session_rel_course session_rel_course + ON course.code = session_rel_course.course_code inner join $tbl_session_rel_course_rel_user as srcru + ON (srcru.id_session = session_rel_course.id_session) + WHERE id_user = $id_user and session_rel_course.id_session = $id_session"; + + $rs = Database::query($sql); + $existingCourses = Database::store_result($rs); + if (count($CourseList) == count($existingCourses)) { + header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('MaybeYouWantToDeleteThisUserFromSession')); + exit; + } + foreach($CourseList as $enreg_course) { + $exists = false; + foreach($existingCourses as $existingCourse) { + if($enreg_course == $existingCourse['course_code']) { + $exists=true; + } + } + if(!$exists) { + $enreg_course = Database::escape_string($enreg_course); + $sql_delete = "DELETE FROM $tbl_session_rel_course_rel_user + WHERE id_user='".$id_user."' AND course_code='".$enreg_course."' AND id_session=$id_session"; + Database::query($sql_delete); + if (Database::affected_rows()) { + //update session rel course table + $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users - 1 WHERE id_session='$id_session' AND course_code='$enreg_course'"; + Database::query($sql_update); + } + } + } + foreach($existingCourses as $existingCourse) { + //$sql_insert_rel_course= "INSERT INTO $tbl_session_rel_course(id_session,course_code, id_coach) VALUES('$id_session','$enreg_course','$id_coach')"; + if(!in_array($existingCourse['code'], $CourseList)){ + $existingCourse = Database::escape_string($existingCourse['code']); + $sql_insert = "INSERT IGNORE INTO $tbl_session_rel_course_rel_user(id_session,course_code,id_user) VALUES('$id_session','$existingCourse','$id_user')"; + Database::query($sql_insert); + if(Database::affected_rows()) { + //update session rel course table + $sql_update = "UPDATE $tbl_session_rel_course SET nbr_users= nbr_users + 1 WHERE id_session='$id_session' AND course_code='$existingCourse'"; + Database::query($sql_update); + } + + } + } + header('Location: session_course_user.php?id_session='.$id_session.'&id_user='.$id_user.'&msg='.get_lang('CoursesUpdated')); + exit; +} + +// display the dokeos header +Display::display_header($tool_name); + +if (!empty($_GET['msg'])) { + Display::display_normal_message(urldecode($_GET['msg'])); +} + +// the form header +$session_info = SessionManager::fetch($id_session); +$user_info = api_get_user_info($id_user); +echo ''.$tool_name.': '.$session_info['name'].' - '.$user_info['complete_name'].''; + +$nosessionCourses = $sessionCourses = array(); +// actual user +$sql = "SELECT code, title, visual_code, srcru.id_session + FROM $tbl_course course inner JOIN $tbl_session_rel_course_rel_user as srcru + ON course.code = srcru.course_code WHERE srcru.id_user = $id_user AND id_session = $id_session"; + +//all +$sql_all="SELECT code, title, visual_code, src.id_session " . + "FROM $tbl_course course inner JOIN $tbl_session_rel_course as src " . + "ON course.code = src.course_code AND id_session = $id_session"; +$result=Database::query($sql); +$Courses=Database::store_result($result); + +$result=Database::query($sql_all); +$CoursesAll=Database::store_result($result); + +$course_temp = array(); +foreach($Courses as $course) { + $course_temp[] = $course['code']; +} +foreach($CoursesAll as $course) { + if (in_array($course['code'], $course_temp)) { + $nosessionCourses[$course['code']] = $course ; + } else { + $sessionCourses[$course['code']] = $course ; + } +} + +unset($Courses); +?> + +
+ + + + + + + + + + + + + + + +
:  :
+
+
+ +
+ +

+ +





+ '.get_lang('EditSessionCourses').''; + ?> +
+ +
+ +0) { + array_map('intval', $idChecked); + $idChecked = implode(',',$idChecked); + } + if (!empty($idChecked)) { + Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND course_code='".$course_code."' AND id_user IN($idChecked)"); + $nbr_affected_rows = Database::affected_rows(); + Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$id_session' AND course_code='".$course_code."'"); + } + header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort); + exit(); + break; + case 'add': + SessionManager::subscribe_users_to_session_course($idChecked, $id_session, $course_code); + header('Location: '.api_get_self().'?id_session='.$id_session.'&course_code='.urlencode($course_code).'&sort='.$sort); + exit; + break; +} + + +$limit = 20; +$from = $page * $limit; +$is_western_name_order = api_is_western_name_order(); + +//scru.status<>2 scru.course_code='".$course_code."' +/*$sql = "SELECT DISTINCT + u.user_id,".($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname').", u.username, scru.id_user as is_subscribed + FROM $tbl_session_rel_user s + INNER JOIN $tbl_user u ON (u.user_id=s.id_user) + LEFT JOIN $tbl_session_rel_course_rel_user scru ON (u.user_id=scru.id_user AND scru.course_code = '".$course_code."' ) + WHERE s.id_session='$id_session' + ORDER BY $sort $direction + LIMIT $from,".($limit+1);*/ + +$sql = "SELECT DISTINCT + u.user_id,".($is_western_name_order ? 'u.firstname, u.lastname' : 'u.lastname, u.firstname').", u.username, scru.id_user as is_subscribed + FROM $tbl_session_rel_user s + INNER JOIN $tbl_user u ON (u.user_id=s.id_user) + LEFT JOIN $tbl_session_rel_course_rel_user scru + ON (s.id_session = scru.id_session AND s.id_user = scru.id_user AND scru.course_code = '".$course_code."' ) + WHERE s.id_session='$id_session' + ORDER BY $sort $direction + LIMIT $from,".($limit+1); + +if ($direction == 'desc') { + $direction = 'asc'; +} else { + $direction = 'desc'; +} + +$result = Database::query($sql); +$users = Database::store_result($result); + +$nbr_results = sizeof($users); + +$tool_name = get_lang('Session').': '.$session_name.' - '.get_lang('Course').': '.$course_title; + +$interbreadcrumb[] = array("url" => "index.php","name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array("url" => "session_list.php","name" => get_lang('SessionList')); +$interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id_session,"name" => get_lang('SessionOverview')); + +Display::display_header($tool_name); + +echo Display::page_header($tool_name); +?> +
+
+ + + +| + $limit) { +?> + + +
+
+ + + + + + + + + + + + + + $enreg) { + + if ($key == $limit) { + break; + } + ?> + + + + + + + + + + + + + +
 
+ + + + + + + + + + +
+
+
+ + + + | + $limit) { + ?> + + +
+
+ + +
+ 'index.php',"name" => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array('url' => "session_list.php","name" => get_lang('SessionList')); +$interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$id,"name" => get_lang('SessionOverview')); + +list($year_start,$month_start,$day_start) = explode('-', $infos['date_start']); +list($year_end,$month_end,$day_end) = explode('-', $infos['date_end']); + +$showDescriptionChecked = null; +if (isset($infos['show_description']) && !empty($infos['show_description'])) { + $showDescriptionChecked = 'checked'; +} + +$end_year_disabled = $end_month_disabled = $end_day_disabled = ''; + +if (isset($_POST['formSent']) && $_POST['formSent']) { + $formSent = 1; + + $name = $_POST['name']; + $year_start = $_POST['year_start']; + $month_start = $_POST['month_start']; + $day_start = $_POST['day_start']; + $year_end = $_POST['year_end']; + $month_end = $_POST['month_end']; + $day_end = $_POST['day_end']; + $nb_days_acess_before = $_POST['nb_days_access_before']; + $nb_days_acess_after = $_POST['nb_days_access_after']; + //$nolimit = $_POST['nolimit']; + $id_coach = $_POST['id_coach']; + $id_session_category = $_POST['session_category']; + $id_visibility = $_POST['session_visibility']; + $duration = isset($_POST['duration']) ? $_POST['duration'] : null; + $description = isset($_POST['description']) ? $_POST['description'] : null; + $showDescription = isset($_POST['show_description']) ? 1 : 0; + + $end_limit = $_POST['end_limit']; + $start_limit = $_POST['start_limit']; + + if (empty($end_limit) && empty($start_limit)) { + $nolimit = 1; + } else { + $nolimit = null; + } + + $return = SessionManager::edit_session( + $id, + $name, + $year_start, + $month_start, + $day_start, + $year_end, + $month_end, + $day_end, + $nb_days_acess_before, + $nb_days_acess_after, + $nolimit, + $id_coach, + $id_session_category, + $id_visibility, + $start_limit, + $end_limit, + $description, + $showDescription, + $duration + ); + + if ($return == strval(intval($return))) { + header('Location: resume_session.php?id_session='.$return); + exit(); + } +} + +$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username'; +$sql="SELECT user_id,lastname,firstname,username FROM $tbl_user WHERE status='1'".$order_clause; + +if (api_is_multiple_url_enabled()) { + $table_access_url_rel_user= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + $access_url_id = api_get_current_access_url_id(); + if ($access_url_id != -1) { + $sql="SELECT DISTINCT u.user_id,lastname,firstname,username FROM $tbl_user u INNER JOIN $table_access_url_rel_user url_rel_user ON (url_rel_user.user_id = u.user_id) + WHERE status='1' AND access_url_id = '$access_url_id' $order_clause"; + } +} + +$result = Database::query($sql); +$Coaches = Database::store_result($result); +$thisYear = date('Y'); + +// display the header +Display::display_header($tool_name); + +if (!empty($return)) { + Display::display_error_message($return,false); +} +?> + +
+
+ + + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+ +
+
+
+
+
+ +   +
+
+   + +
+
+
+ +
+
+
+ +
"> +
+ + / + + / + +
+
+
+ +
+
+ +
"> +
+ + + / + + / + +

+ +
+ +
+
+
+ + + +
+
+
+ +
+
+ +
+
+ +
+
+ + + + +
+ +
+ +
+ +
+
+ + + +
+
+ +
+
+
+
+ + + 'index.php',"name" => get_lang('PlatformAdmin')); + +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)) { + $sql = "SELECT id,name,id_coach,username,date_start,date_end,visibility,session_category_id FROM $tbl_session INNER JOIN $tbl_user + ON $tbl_user.user_id = $tbl_session.id_coach ORDER BY id"; + + + if ($_configuration['multiple_access_urls']) { + $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 id, name,id_coach,username,date_start,date_end,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 id,name,username,date_start,date_end,visibility,session_category_id + FROM $tbl_session + INNER JOIN $tbl_user + ON $tbl_user.user_id = $tbl_session.id_coach + WHERE id='$session_id'"; + + $result = Database::query($sql); + + } + + if(Database::num_rows($result)) + { + 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,''); + + 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;Visibility;SessionCategory;Users;Courses;\n"); + } + else + { + $cvs = false; + fputs($fp, "\n\n"); + } + + while($row=Database::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']); + $row['visibility'] = str_replace(';',',',$row['visibility']); + $row['session_category'] = str_replace(';',',',$row['session_category_id']); + if($cvs){ + $add.= $row['name'].';'.$row['username'].';'.$row['date_start'].';'.$row['date_end'].';'.$row['visibility'].';'.$row['session_category'].';'; + } + 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" + ."\t\t$row[visibility]\n" + ."\t\t$row[session_category]\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.relation_type<>".SESSION_RELATION_TYPE_RRHH." + AND $tbl_session_user.id_session = '".$row['id']."'"; + + $rsUsers = Database::query($sql); + $users = ''; + while($rowUsers = Database::fetch_array($rsUsers)){ + if($cvs){ + $users .= str_replace(';',',',$rowUsers['username']).'|'; + } + else { + $users .= "\t\t$rowUsers[username]\n"; + } + } + if(!empty($users) && $cvs) + $users = api_substr($users , 0, api_strlen($users)-1); + + if($cvs) + $users .= ';'; + + $add .= $users; + + //courses + $sql = "SELECT DISTINCT $tbl_course.code + FROM $tbl_course + INNER JOIN $tbl_session_course_user + ON $tbl_course.code = $tbl_session_course_user.course_code + AND $tbl_session_course_user.id_session = '".$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.id_user + WHERE scu.course_code = '{$rowCourses['code']}' + AND scu.id_session = '".$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\n"; + $courses .= "\t\t\t$rowCourses[code]\n"; + $courses .= "\t\t\t$coachs\n"; + } + + // rel user courses + $sql = "SELECT DISTINCT u.username + FROM $tbl_session_course_user scu + INNER JOIN $tbl_session_user su ON scu.id_user = su.id_user AND scu.id_session = su.id_session AND su.relation_type<>".SESSION_RELATION_TYPE_RRHH." + INNER JOIN $tbl_user u + ON scu.id_user = u.user_id + AND scu.course_code='".$rowCourses['code']."' + AND scu.id_session='".$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$rowUsersCourse[username]\n"; + } + } + if($cvs){ + if(!empty($userscourse)) + $userscourse = api_substr($userscourse , 0, api_strlen($userscourse)-1); + + $courses .= $userscourse.']|'; + } + else { + $courses .= "\t\t\n"; + } + } + + if(!empty($courses) && $cvs) + $courses = api_substr($courses , 0, api_strlen($courses)-1); + $add .= $courses; + + if($cvs) { + $breakline = api_is_windows_os()?"\r\n":"\n"; + $add .= ";$breakline"; + } else { + $add .= "\t\n"; + } + + fputs($fp, $add); + } + + if(!$cvs) + fputs($fp,"\n"); + fclose($fp); + + $errorMsg=get_lang('UserListHasBeenExported').'
'.get_lang('ClickHereToDownloadTheFile').''; + } +} + +// display the header +Display::display_header($tool_name); + +//select of sessions +$sql = "SELECT id, name FROM $tbl_session ORDER BY name"; + +if ($_configuration['multiple_access_urls']) { + $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 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 '
'; +echo ''.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).''; +echo '
'; + +if (!empty($errorMsg)) { + Display::display_normal_message($errorMsg, false); //main API +} + +$form = new FormValidator('session_export', 'post', api_get_self()); +$form->addElement('hidden', 'formSent', 1); +$form->addElement('radio', 'file_type', get_lang('OutputFileType'), 'CSV' , 'csv', null, array('id' => 'file_type_csv')); +$form->addElement('radio', 'file_type', null, 'XML', 'xml', null, array('id' => 'file_type_xml')); + +$options = array(); +$options['0'] = get_lang('AllSessions'); +foreach ($Sessions as $enreg) { + $options[$enreg['id']] = $enreg['name']; +} + +$form->addElement('select', 'session_id', get_lang('WhichSessionToExport'), $options); +$form->addElement('button', 'submit', get_lang('ExportSession')); + +$defaults = array(); +$defaults['file_type'] = 'csv'; +$form->setDefaults($defaults); +$form->display(); +unset($Courses); +Display::display_footer(); \ No newline at end of file diff --git a/main/admin/session_import.php b/main/admin/session_import.php new file mode 100644 index 0000000000..0ff75a12a8 --- /dev/null +++ b/main/admin/session_import.php @@ -0,0 +1,622 @@ + 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList')); + +set_time_limit(0); + +// Set this option to true to enforce strict purification for usenames. +$purification_option_for_usernames = false; + +$inserted_in_course = array(); + +global $_configuration; + +if (isset($_POST['formSent']) && $_POST['formSent']) { + if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) { + $form_sent = $_POST['formSent']; + $file_type = $_POST['file_type']; + $send_mail = $_POST['sendMail'] ? 1 : 0; + $isOverwrite = $_POST['overwrite'] ? true: false; + $deleteUsersNotInList = isset($_POST['delete_users_not_in_list']) ? true : false; + $sessions = array(); + + $session_counter = 0; + + if ($file_type == 'xml') { + + // XML + + // SimpleXML for PHP5 deals with various encodings, but how many they are, what are version issues, do we need to waste time with configuration options? + // For avoiding complications we go some sort of "PHP4 way" - we convert the input xml-file into UTF-8 before passing it to the parser. + // Instead of: + // $root = @simplexml_load_file($_FILES['import_file']['tmp_name']); + // we may use the following construct: + // $root = @simplexml_load_string(api_utf8_encode_xml(file_get_contents($_FILES['import_file']['tmp_name']))); + // To ease debugging let us use: + $content = file_get_contents($_FILES['import_file']['tmp_name']); + + $content = api_utf8_encode_xml($content); + $root = @simplexml_load_string($content); + unset($content); + + if (is_object($root)) { + if (count($root->Users->User) > 0) { + + // Creating/updating users from base node. + foreach ($root->Users->User as $node_user) { + $username = $username_old = trim(api_utf8_decode($node_user->Username)); + if (UserManager::is_username_available($username)) { + $password = api_utf8_decode($node_user->Password); + if (empty($password)) { + $password = api_generate_password(); + } + switch ($node_user->Status) { + case 'student' : + $status = 5; + break; + case 'teacher' : + $status = 1; + break; + default : + $status = 5; + $error_message .= get_lang('StudentStatusWasGivenTo').' : '.$username.'
'; + } + + $result = UserManager::create_user( + api_utf8_decode($node_user->Firstname), + api_utf8_decode($node_user->Lastname), + $status, + api_utf8_decode($node_user->Email), + $username, + $password, + api_utf8_decode($node_user->OfficialCode), + null, + api_utf8_decode($node_user->Phone), + null, + PLATFORM_AUTH_SOURCE, + null, + 1, + 0, + null, + null, + $send_mail + ); + } else { + $lastname = trim(api_utf8_decode($node_user->Lastname)); + $firstname = trim(api_utf8_decode($node_user->Firstname)); + $password = api_utf8_decode($node_user->Password); + $email = trim(api_utf8_decode($node_user->Email)); + $official_code = trim(api_utf8_decode($node_user->OfficialCode)); + $phone = trim(api_utf8_decode($node_user->Phone)); + $status = trim(api_utf8_decode($node_user->Status)); + switch ($status) { + case 'student' : $status = 5; break; + case 'teacher' : $status = 1; break; + default : $status = 5; $error_message .= get_lang('StudentStatusWasGivenTo').' : '.$username.'
'; + } + + $sql = "UPDATE $tbl_user SET + lastname = '".Database::escape_string($lastname)."', + firstname = '".Database::escape_string($firstname)."', + ".(empty($password) ? "" : "password = '".(api_get_encrypted_password($password))."',")." + email = '".Database::escape_string($email)."', + official_code = '".Database::escape_string($official_code)."', + phone = '".Database::escape_string($phone)."', + status = '".Database::escape_string($status)."' + WHERE username = '".Database::escape_string($username)."'"; + + Database::query($sql); + } + } + } + + // Creating courses from base node. + + if (count($root->Courses->Course) > 0) { + foreach ($root->Courses->Course as $courseNode) { + + $params = array(); + if (empty($courseNode->CourseTitle)) { + $params['title'] = api_utf8_decode($courseNode->CourseCode); + } else { + $params['title'] = api_utf8_decode($courseNode->CourseTitle); + } + $params['wanted_code'] = api_utf8_decode($courseNode->CourseCode); + $params['tutor_name'] = null; + $params['course_category'] = null; + $params['course_language'] = api_get_valid_language(api_utf8_decode($courseNode->CourseLanguage)); + $params['user_id'] = api_get_user_id(); + + // Looking up for the teacher. + $username = trim(api_utf8_decode($courseNode->CourseTeacher)); + $sql = "SELECT user_id, lastname, firstname FROM $tbl_user WHERE username='$username'"; + $rs = Database::query($sql); + list($user_id, $lastname, $firstname) = Database::fetch_array($rs); + + $params['teachers'] = $user_id; + CourseManager::create_course($params); + } + } + + // Creating sessions from base node. + if (count($root->Session) > 0) { + foreach ($root->Session as $node_session) { + $course_counter = 0; + $user_counter = 0; + + $session_name = trim(api_utf8_decode($node_session->SessionName)); + $coach = UserManager::purify_username(api_utf8_decode($node_session->Coach), $purification_option_for_usernames); + + if (!empty($coach)) { + $coach_id = UserManager::get_user_id_from_username($coach); + if ($coach_id === false) { + $error_message .= get_lang('UserDoesNotExist').' : '.$coach.'
'; + // Forcing the coach id if user does not exist. + $coach_id = api_get_user_id(); + } + } else { + // Forcing the coach id. + $coach_id = api_get_user_id(); + } + + $date_start = trim(api_utf8_decode($node_session->DateStart)); // Just in case - encoding conversion. + + if (!empty($date_start)) { + list($year_start, $month_start, $day_start) = explode('/', $date_start); + if(empty($year_start) || empty($month_start) || empty($day_start)) { + $error_message .= get_lang('WrongDate').' : '.$date_start.'
'; + break; + } else { + $time_start = mktime(0, 0, 0, $month_start, $day_start, $year_start); + } + + $date_end = trim(api_utf8_decode($node_session->DateEnd)); + if (!empty($date_start)) { + list($year_end, $month_end, $day_end) = explode('/', $date_end); + if (empty($year_end) || empty($month_end) || empty($day_end)) { + $error_message .= get_lang('Error').' : '.$date_end.'
'; + break; + } else { + $time_end = mktime(0, 0, 0, $month_end, $day_end, $year_end); + } + } + if ($time_end - $time_start < 0) { + $error_message .= get_lang('StartDateShouldBeBeforeEndDate').' : '.$date_end.'
'; + } + } + + $visibility = trim(api_utf8_decode($node_session->Visibility)); + $session_category_id = trim(api_utf8_decode($node_session->SessionCategory)); + + if (!$updatesession) { + // Always create a session. + $unique_name = false; // This MUST be initializead. + $i = 0; + // Change session name, verify that session doesn't exist. + while (!$unique_name) { + if ($i > 1) { + $suffix = ' - '.$i; + } + $sql = 'SELECT 1 FROM '.$tbl_session.' WHERE name="'.Database::escape_string($session_name.$suffix).'"'; + $rs = Database::query($sql); + if (Database::result($rs, 0, 0)) { + $i++; + } else { + $unique_name = true; + $session_name .= $suffix; + } + } + // Creating the session. + $sql_session = "INSERT IGNORE INTO $tbl_session SET + name = '".Database::escape_string($session_name)."', + id_coach = '$coach_id', + date_start = '$date_start', + date_end = '$date_end', + visibility = '$visibility', + session_category_id = '$session_category_id', + session_admin_id=".intval($_user['user_id']); + $rs_session = Database::query($sql_session); + $session_id = Database::insert_id(); + $session_counter++; + + } else { + // Update the session if it is needed. + $my_session_result = SessionManager::get_session_by_name($session_name); + if ($my_session_result === false) { + // Creating the session. + $sql_session = "INSERT IGNORE INTO $tbl_session SET + name = '".Database::escape_string($session_name)."', + id_coach = '$coach_id', + date_start = '$date_start', + date_end = '$date_end', + visibility = '$visibility', + session_category_id = '$session_category_id', + session_admin_id=".intval($_user['user_id']); + $rs_session = Database::query($sql_session); + $session_id = Database::insert_id(); + $session_counter++; + } else { + // if the session already exists - update it. + $sql_session = "UPDATE $tbl_session SET + id_coach = '$coach_id', + date_start = '$date_start', + date_end = '$date_end', + visibility = '$visibility', + session_category_id = '$session_category_id' + WHERE name = '$session_name'"; + $rs_session = Database::query($sql_session); + $session_id = Database::query("SELECT id FROM $tbl_session WHERE name='$session_name'"); + list($session_id) = Database::fetch_array($session_id); + Database::query("DELETE FROM $tbl_session_user WHERE id_session='$session_id'"); + Database::query("DELETE FROM $tbl_session_course WHERE id_session='$session_id'"); + Database::query("DELETE FROM $tbl_session_course_user WHERE id_session='$session_id'"); + } + } + + // Associate the session with access_url. + global $_configuration; + if ($_configuration['multiple_access_urls']) { + $access_url_id = api_get_current_access_url_id(); + UrlManager::add_session_to_url($session_id, $access_url_id); + } else { + // We fill by default the access_url_rel_session table. + UrlManager::add_session_to_url($session_id, 1); + } + + + // Adding users to the new session. + foreach ($node_session->User as $node_user) { + $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames); + $user_id = UserManager::get_user_id_from_username($username); + if ($user_id !== false) { + $sql = "INSERT IGNORE INTO $tbl_session_user SET + id_user='$user_id', + id_session = '$session_id'"; + $rs_user = Database::query($sql); + $user_counter++; + } + } + + // Adding courses to a session. + foreach ($node_session->Course as $node_course) { + $course_code = Database::escape_string(trim(api_utf8_decode($node_course->CourseCode))); + // Verify that the course pointed by the course code node exists. + if (CourseManager::course_exists($course_code)) { + // If the course exists we continue. + $course_info = CourseManager::get_course_information($course_code); + + $session_course_relation = SessionManager::relation_session_course_exist($session_id, $course_code); + if (!$session_course_relation) { + $sql_course = "INSERT INTO $tbl_session_course SET + course_code = '$course_code', + id_session='$session_id'"; + $rs_course = Database::query($sql_course); + $course_info = api_get_course_info($course['code']); + SessionManager::installCourse($id_session, $course_info['real_id']); + } + + $course_coaches = explode(',', $node_course->Coach); + + // Adding coachs to session course user + foreach ($course_coaches as $course_coach) { + $coach_id = UserManager::purify_username(api_utf8_decode($course_coach), $purification_option_for_usernames); + $coach_id = UserManager::get_user_id_from_username($course_coach); + if ($coach_id !== false) { + $sql = "INSERT IGNORE INTO $tbl_session_course_user SET + id_user='$coach_id', + course_code='$course_code', + id_session = '$session_id', + status = 2 "; + $rs_coachs = Database::query($sql); + } else { + $error_message .= get_lang('UserDoesNotExist').' : '.$user.'
'; + } + } + + // Adding users. + $course_counter++; + $users_in_course_counter = 0; + foreach ($node_course->User as $node_user) { + $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames); + $user_id = UserManager::get_user_id_from_username($username); + if ($user_id !== false) { + // Adding to session_rel_user table. + $sql = "INSERT IGNORE INTO $tbl_session_user SET + id_user='$user_id', + id_session = '$session_id'"; + $rs_user = Database::query($sql); + $user_counter++; + // Adding to session_rel_user_rel_course table. + $sql = "INSERT IGNORE INTO $tbl_session_course_user SET + id_user='$user_id', + course_code='$course_code', + id_session = '$session_id'"; + $rs_users = Database::query($sql); + $users_in_course_counter++; + } else { + $error_message .= get_lang('UserDoesNotExist').' : '.$username.'
'; + } + } + $update_session_course = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE course_code='$course_code'"; + Database::query($update_session_course); + $inserted_in_course[$course_code] = $course_info['title']; + + } + + if (CourseManager::course_exists($course_code, true)) { + // If the course exists we continue. + // Also subscribe to virtual courses through check on visual code. + $list = CourseManager :: get_courses_info_from_visual_code($course_code); + foreach ($list as $vcourse) { + if ($vcourse['code'] == $course_code) { + // Ignore, this has already been inserted. + } else { + + $sql_course = "INSERT INTO $tbl_session_course SET + course_code = '".$vcourse['code']."', + id_session='$session_id'"; + $rs_course = Database::query($sql_course); + $course_info = api_get_course_info($course['code']); + SessionManager::installCourse($id_session, $course_info['real_id']); + + $course_coaches = explode(",",$node_course->Coach); + + // adding coachs to session course user + foreach ($course_coaches as $course_coach) { + $coach_id = UserManager::purify_username(api_utf8_decode($course_coach), $purification_option_for_usernames); + $coach_id = UserManager::get_user_id_from_username($course_coach); + if ($coach_id !== false) { + $sql = "INSERT IGNORE INTO $tbl_session_course_user SET + id_user='$coach_id', + course_code='{$vcourse['code']}', + id_session = '$session_id', + status = 2 "; + $rs_coachs = Database::query($sql); + } else { + $error_message .= get_lang('UserDoesNotExist').' : '.$user.'
'; + } + } + + // adding users + $course_counter++; + $users_in_course_counter = 0; + foreach ($node_course->User as $node_user) { + $username = UserManager::purify_username(api_utf8_decode($node_user), $purification_option_for_usernames); + $user_id = UserManager::get_user_id_from_username($username); + if ($user_id !== false) { + // Adding to session_rel_user table. + $sql = "INSERT IGNORE INTO $tbl_session_user SET + id_user='$user_id', + id_session = '$session_id'"; + $rs_user = Database::query($sql); + $user_counter++; + // Adding to session_rel_user_rel_course table. + $sql = "INSERT IGNORE INTO $tbl_session_course_user SET + id_user='$user_id', + course_code='{$vcourse['code']}', + id_session = '$session_id'"; + $rs_users = Database::query($sql); + $users_in_course_counter++; + } else { + $error_message .= get_lang('UserDoesNotExist').' : '.$username.'
'; + } + } + $update_session_course = "UPDATE $tbl_session_course SET nbr_users='$users_in_course_counter' WHERE course_code='$course_code'"; + Database::query($update_session_course); + $inserted_in_course[$course_code] = $course_info['title']; + + } + $inserted_in_course[$vcourse['code']] = $vcourse['title']; + } + + } else { + // The course does not exist. + $error_message .= get_lang('CourseDoesNotExist').' : '.$course_code.'
'; + } + } + Database::query("UPDATE $tbl_session SET nbr_users='$user_counter', nbr_courses='$course_counter' WHERE id='$session_id'"); + } + + } + if (empty($root->Users->User) && empty($root->Courses->Course) && empty($root->Session)) { + $error_message = get_lang('NoNeededData'); + } + } else { + $error_message .= get_lang('XMLNotValid'); + } + } else { + // CSV + $updateCourseCoaches = isset($_POST['update_course_coaches']) ? true : false; + $result = SessionManager::importCSV( + $_FILES['import_file']['tmp_name'], + $isOverwrite, + api_get_user_id(), + null, + array(), + null, + null, + null, + 1, + array(), + $deleteUsersNotInList, + $updateCourseCoaches + ); + $sessionList = $result['session_list']; + $error_message = $result['error_message']; + + $session_counter = $result['session_counter']; + } + + if (!empty($error_message)) { + $error_message = get_lang('ButProblemsOccured').' :
'.$error_message; + } + + if (count($inserted_in_course) > 1) { + $warn = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': '; + foreach ($inserted_in_course as $code => $title) { + $warn .= ' '.$title.' ('.$code.'),'; + } + $warn = substr($warn, 0, -1); + } + if ($session_counter == 1) { + if ($file_type == 'csv') { + $session_id = current($sessionList); + } + header('Location: resume_session.php?id_session='.$session_id.'&warn='.urlencode($warn)); + exit; + } else { + header('Location: session_list.php?action=show_message&message='.urlencode(get_lang('FileImported').' '.$error_message).'&warn='.urlencode($warn)); + exit; + } + } else { + $error_message = get_lang('NoInputFile'); + } +} + +// Display the header. +Display::display_header($tool_name); + +if (count($inserted_in_course) > 1) { + $msg = get_lang('SeveralCoursesSubscribedToSessionBecauseOfSameVisualCode').': '; + foreach ($inserted_in_course as $code => $title) { + $msg .= ' '.$title.' ('.$title.'),'; + } + $msg = substr($msg, 0, -1); + Display::display_warning_message($msg); +} + +echo ''; + +if (!empty($error_message)) { + Display::display_normal_message($error_message, false); +} + +$form = new FormValidator('import_sessions', 'post', api_get_self(), null, array('enctype' => 'multipart/form-data')); +$form->addElement('hidden', 'formSent', 1); +$form->addElement('file', 'import_file', get_lang('ImportFileLocation')); +$form->addElement('radio', 'file_type', array(get_lang('FileType'), ''.get_lang('ExampleCSVFile').''), 'CSV', 'csv'); +$form->addElement('radio', 'file_type', array(null, ''.get_lang('ExampleXMLFile').''), 'XML', 'xml'); + +$form->addElement('checkbox', 'overwrite', null, get_lang('IfSessionExistsUpdate')); +$form->addElement('checkbox', 'delete_users_not_in_list', null, get_lang('DeleteUsersNotInList')); +$form->addElement('checkbox', 'update_course_coaches', null, get_lang('CleanAndUpdateCourseCoaches')); +$form->addElement('checkbox', 'sendMail', null, get_lang('SendMailToUsers')); +$form->addElement('button', 'submit', get_lang('ImportSession')); + +$defaults = array('sendMail' => 'true','file_type' => 'csv'); +$form->setDefaults($defaults); + +Display::display_normal_message(get_lang('TheXMLImportLetYouAddMoreInfoAndCreateResources')); +$form->display(); + +?> + +

:

+ +
+
+SessionName;Coach;DateStart;DateEnd;Users;Courses
+xxx1;xxx;xxx;xxx;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...]
+xxx2;xxx;xxx;xxx;username1|username2;course1[coach1][username1,username2,...]|course2[coach1][username1,username2,...]
+
+
+ +

:

+ +
+
+<?xml version="1.0" encoding=""?>
+<Sessions>
+    <Users>
+        <User>
+            <Username>username1</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>xxx</CourseCode>
+            <CourseTeacher>teacher_username</CourseTeacher>
+            <CourseLanguage>xxx</CourseLanguage>
+            <CourseTitle>xxx</CourseTitle>
+            <CourseDescription>xxx</CourseDescription>
+        </Course>
+    </Courses>
+    <Session>
+        <SessionName>xxx</SessionName>
+        <Coach>xxx</Coach>
+        <DateStart>xxx</DateStart>
+        <DateEnd>xxx</DateEnd>
+        <User>xxx</User>
+        <User>xxx</User>
+        <Course>
+            <CourseCode>coursecode1</CourseCode>
+            <Coach>coach1</Coach>
+        <User>username1</User>
+        <User>username2</User>
+        </Course>
+    </Session>
+
+    <Session>
+        <SessionName>xxx</SessionName>
+        <Coach>xxx</Coach>
+        <DateStart>xxx</DateStart>
+        <DateEnd>xxx</DateEnd>
+        <User>xxx</User>
+        <User>xxx</User>
+        <Course>
+            <CourseCode>coursecode1</CourseCode>
+            <Coach>coach1</Coach>
+        <User>username1</User>
+        <User>username2</User>
+        </Course>
+    </Session>
+</Sessions>
+
+
+
+ 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('SessionList')); + +set_time_limit(0); + +$inserted_in_course = array(); + +// Display the header. +Display::display_header($tool_name); + +echo ''; + +if (!empty($error_message)) { + Display::display_normal_message($error_message, false); +} + +$form = new FormValidator('import_sessions', 'post', api_get_self(), null, array('enctype' => 'multipart/form-data')); +$form->addElement('file', 'import_file', get_lang('ImportFileLocation')); +$form->addElement('checkbox', 'remove_old_relationships', null, get_lang('RemoveOldRelationships')); +//$form->addElement('checkbox', 'send_email', null, get_lang('SendMailToUsers')); +$form->addElement('button', 'submit', get_lang('ImportSession')); + +if ($form->validate()) { + if (isset($_FILES['import_file']['tmp_name']) && !empty($_FILES['import_file']['tmp_name'])) { + $values = $form->exportValues(); + $sendMail = isset($values['send_email']) ? true : false; + $removeOldRelationships = isset($values['remove_old_relationships']) ? true : false; + + $result = SessionManager::importSessionDrhCSV( + $_FILES['import_file']['tmp_name'], + $sendMail, + $removeOldRelationships + ); + echo Display::return_message($result, 'info', false); + } else { + $error_message = get_lang('NoInputFile'); + } +} + +$form->display(); + +?> +

:

+ +
+
+Username;SessionName;
+drh1;Session 1;
+drh2;Session 2;
+
+
+ "index.php","name" => get_lang('PlatformAdmin')); + +$tool_name = get_lang('SessionList'); +Display::display_header($tool_name); + +$error_message = ''; // Avoid conflict with the global variable $error_msg (array type) in add_course.conf.php. +if (isset($_GET['action']) && $_GET['action'] == 'show_message') { + $error_message = Security::remove_XSS($_GET['message']); +} + +if (!empty($error_message)) { + Display::display_normal_message($error_message, false); +} + +$sessionFilter = new FormValidator('course_filter', 'get', '', '', array('class'=> 'form-search'), false); +$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=search_course'; +$courseList = array(); +$courseId = isset($_GET['course_id']) ? $_GET['course_id'] : null; +if (!empty($courseId)) { + require_once api_get_path(LIBRARY_PATH).'course_category.lib.php'; + $courseInfo = api_get_course_info_by_id($courseId); + $parents = getParentsToString($courseInfo['categoryCode']); + $courseList[] = array('id' => $courseInfo['id'], 'text' => $parents.$courseInfo['title']); +} +$sessionFilter->addElement('select_ajax', 'course_name', get_lang('SearchCourse'), null, array('url' => $url, 'defaults' => $courseList)); +$url = api_get_self(); +$actions = ' +'; + +// jqgrid will use this URL to do the selects +if (!empty($courseId)) { + $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&course_id='.$courseId; +} else { + $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions'; +} + + +if (isset($_REQUEST['keyword'])) { + //Begin with see the searchOper param + $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=s.name&searchString='.Security::remove_XSS($_REQUEST['keyword']).'&searchOper=bw'; +} + +if (isset($_REQUEST['id_category'])) { + $sessionCategory = SessionManager::get_session_category($_REQUEST['id_category']); + if (!empty($sessionCategory)) { + //Begin with see the searchOper param + $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_sessions&_force_search=true&rows=20&page=1&sidx=&sord=asc&filters=&searchField=sc.name&searchString='.Security::remove_XSS($sessionCategory['name']).'&searchOper=bw'; + } +} + +//The order is important you need to check the the $column variable in the model.ajax.php file +$columns = array( + get_lang('Name'), + get_lang('NumberOfCourses'), + get_lang('NumberOfUsers'), + get_lang('SessionCategoryName'), + get_lang('StartDate'), + get_lang('EndDate'), + get_lang('Coach'), + get_lang('Status'), + get_lang('Visibility'), + get_lang('Actions') +); + +//Column config +$column_model = array( + array('name'=>'name', 'index'=>'s.name', 'width'=>'160', 'align'=>'left', 'search' => 'true', 'wrap_cell' => "true"), + array('name'=>'nbr_courses', 'index'=>'nbr_courses', 'width'=>'30', 'align'=>'left', 'search' => 'true'), + array('name'=>'nbr_users', 'index'=>'nbr_users', 'width'=>'30', 'align'=>'left', 'search' => 'true'), + array('name'=>'category_name', 'index'=>'sc.name', 'width'=>'70', 'align'=>'left', 'search' => 'true'), + array('name'=>'date_start', 'index'=>'s.date_start', 'width'=>'40', 'align'=>'left', 'search' => 'true'), + array('name'=>'date_end', 'index'=>'s.date_end', 'width'=>'40', 'align'=>'left', 'search' => 'true'), + array('name'=>'coach_name', 'index'=>'coach_name', 'width'=>'80', 'align'=>'left', 'search' => 'false'), + array('name'=>'status', 'index'=>'session_active','width'=>'50', 'align'=>'left', 'search' => 'true', 'stype'=>'select', + //for the bottom bar + 'searchoptions' => array( + 'defaultValue' => ':', + 'value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive') + ), + //for the top bar + 'editoptions' => array( + 'value' => ':'.get_lang('All').';1:'.get_lang('Active').';0:'.get_lang('Inactive') + ) + ), + array('name'=>'visibility', 'index'=>'visibility', 'width'=>'40', 'align'=>'left', 'search' => 'false'), + array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false', 'search' => 'false') +); +//Autowidth +$extra_params['autowidth'] = 'true'; + +//height auto +$extra_params['height'] = 'auto'; + +//With this function we can add actions to the jgrid (edit, delete, etc) +$action_links = 'function action_formatter(cellvalue, options, rowObject) { + return \''.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).''. + ' '.Display::return_icon('user_subscribe_session.png',get_lang('SubscribeUsersToSession'),'',ICON_SIZE_SMALL).''. + ' '.Display::return_icon('courses_to_session.png',get_lang('SubscribeCoursesToSession'),'',ICON_SIZE_SMALL).''. + ' '.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).''. + ' '.Display::return_icon('delete.png',get_lang('Delete'),'',ICON_SIZE_SMALL).''. + '\'; +}'; +?> + +
+'.Display::return_icon('new_session.png',get_lang('AddSession'),'',ICON_SIZE_MEDIUM).''; +echo ''.Display::return_icon('session_to_category.png',get_lang('AddSessionsInCategories'),'',ICON_SIZE_MEDIUM).''; +echo ''.Display::return_icon('folder.png',get_lang('ListSessionCategory'),'',ICON_SIZE_MEDIUM).''; + +echo $actions; +echo '
'; +echo $sessionFilter->return_form(); +echo '
'; +echo '
'; +echo Display::grid_html('sessions'); +Display::display_footer(); + + diff --git a/main/admin/session_user_edit.php b/main/admin/session_user_edit.php new file mode 100644 index 0000000000..2cd748ff76 --- /dev/null +++ b/main/admin/session_user_edit.php @@ -0,0 +1,97 @@ + 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList')); +$interbreadcrumb[] = array('url' => "resume_session.php?id_session=".$sessionId, "name" => get_lang('SessionOverview')); + +$form = new FormValidator('edit', 'post', api_get_self().'?session_id='.$sessionId.'&user_id='.$userId); +$form->add_header(get_lang('EditUserSessionDuration')); +$data = SessionManager::getUserSession($userId, $sessionId); +$userInfo = api_get_user_info($userId); + +// Show current end date for the session for this user, if any +$userAccess = CourseManager::getFirstCourseAccessPerSessionAndUser( + $sessionId, + $userId +); +if (count($userAccess) == 0) { + // User never accessed the session. End date is still open + $msg = sprintf(get_lang('UserNeverAccessedSessionDefaultDurationIsX'), $sessionInfo['duration']); +} else { + // The user already accessed the session. Show a clear detail of the days count. + $duration = $sessionInfo['duration']; + if (!empty($data['duration'])) { + $duration = $duration + $data['duration']; + } + $days = SessionManager::getDayLeftInSession($sessionId, $userId, $duration); + $firstAccess = api_strtotime($userAccess['login_course_date'], 'UTC'); + $firstAccessString = api_convert_and_format_date($userAccess['login_course_date'], DATE_FORMAT_SHORT, 'UTC'); + if ($days > 0) { + $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateInZDays'), $firstAccessString, $duration, $days); + } else { + $endDateInSeconds = $firstAccess + $duration*24*60*60; + $last = api_convert_and_format_date($endDateInSeconds, DATE_FORMAT_SHORT); + $msg = sprintf(get_lang('FirstAccessWasXSessionDurationYEndDateWasZ'), $firstAccessString, $duration, $last); + } +} +$form->addElement('html', sprintf(get_lang('UserXSessionY'), $userInfo['complete_name'], $sessionInfo['name'])); +$form->addElement('html', '
'); +$form->addElement('html', $msg); + +$form->addElement('text', 'duration', array(get_lang('ExtraDurationForUser'), null, get_lang('Days'))); +$form->addElement('button', 'submit', get_lang('Send')); + +if (empty($data['duration'])) { + $data['duration'] = 0; +} +$form->setDefaults($data); +$message = null; +if ($form->validate()) { + $duration = $form->getSubmitValue('duration'); + // Only update if the duration is different from the default duration + if ($duration != 0) { + SessionManager::editUserSessionDuration($duration, $userId, $sessionId); + $message = Display::return_message(get_lang('ItemUpdated'), 'confirmation'); + } else { + $message = Display::return_message(get_lang('DurationIsSameAsDefault'), 'warning'); + } +} + +// display the header +Display::display_header(get_lang('Edit')); + +echo $message; +$form->display(); + +Display :: display_footer();