We can create a session with a "start date" and without an "end date" and viceversa. See BT#1911

skala
Julio Montoya 15 years ago
parent e33b2f05f1
commit e0154c8565
  1. 40
      main/admin/resume_session.php
  2. 181
      main/admin/session_add.php
  3. 251
      main/admin/session_edit.php
  4. 6
      main/admin/session_list.php
  5. 24
      main/inc/lib/display.lib.php
  6. 91
      main/inc/lib/sessionmanager.lib.php
  7. 4
      user_portal.php

@ -1,12 +1,10 @@
<?php
/* For licensing terms, see /license.txt */
/**
* @author Bart Mollet
* @author Bart Mollet, Julio Montoya lot of fixes
* @package chamilo.admin
*/
/*
INIT SECTION
*/
/* INIT SECTION */
// name of the language file that needs to be included
$language_file = 'admin';
@ -36,9 +34,7 @@ $tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY)
$id_session = (int)$_GET['id_session'];
$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
FROM '.$tbl_session.' LEFT JOIN '.$tbl_user.' ON id_coach = user_id
WHERE '.$tbl_session.'.id='.$id_session;
$rs = Database::query($sql);
@ -80,11 +76,8 @@ if($_GET['action'] == 'delete') {
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'");
}
if (!empty($_GET['user'])) {
@ -94,13 +87,12 @@ if($_GET['action'] == 'delete') {
Database::query("DELETE FROM $tbl_session_rel_course_rel_user WHERE id_session='$id_session' AND id_user=".intval($_GET['user']));
$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'");
}
}
Display::display_header($tool_name);
if (!empty($_GET['warn'])) {
Display::display_warning_message(urldecode($_GET['warn']));
@ -123,21 +115,33 @@ api_display_tool_title($tool_name);
<td><?php echo get_lang('GeneralCoach'); ?> :</td>
<td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
</tr>
<?php if(!empty($session_category)): ?>
<?php if(!empty($session_category)) { ?>
<tr>
<td><?php echo get_lang('SessionCategory') ?></td>
<td><?php echo $session_category; ?></td>
</tr>
<?php endif; ?>
<?php } ?>
<tr>
<td><?php echo get_lang('Date'); ?> :</td>
<td>
<?php
if($session['date_start']=='00-00-0000')
if ($session['date_start'] == '00-00-0000' && $session['date_end']== '00-00-0000' )
echo get_lang('NoTimeLimits');
else
echo get_lang('From').' '.$session['date_start'].' '.get_lang('To').' '.$session['date_end'];
?>
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'] = '';
}
if ($session['date_end'] == '00-00-0000') {
$session['date_end'] ='';
} else {
$session['date_end'] = get_lang('Until').' '.$session['date_end'];
}
echo $session['date_start'].' '.$session['date_end'];
}
?>
</td>
</tr>

@ -30,8 +30,8 @@ api_protect_admin_script(true);
$formSent=0;
$errorMsg='';
$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('SessionList'));
$interbreadcrumb[]=array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => 'session_list.php','name' => get_lang('SessionList'));
// Database Table Definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
@ -101,34 +101,42 @@ function fill_coach_field (username) {
if ($_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_acess_before'];
$nb_days_acess_after = $_POST['nb_days_acess_after'];
$nolimit=$_POST['nolimit'];
$coach_username=$_POST['coach_username'];
$id_session_category = $_POST['session_category'];
$id_visibility = $_POST['session_visibility'];
$return = SessionManager::create_session($name,$year_start,$month_start,$day_start,$year_end,$month_end,$day_end,$nb_days_acess_before,$nb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility);
$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_acess_before'];
$nb_days_acess_after = $_POST['nb_days_acess_after'];
//$nolimit = $_POST['nolimit'];
$coach_username = $_POST['coach_username'];
$id_session_category = $_POST['session_category'];
$id_visibility = $_POST['session_visibility'];
$end_limit = $_POST['end_limit'];
$start_limit = $_POST['start_limit'];
if (empty($end_limit) && empty($start_limit)) {
$nolimit = 1;
} else {
$nolimit = null;
}
$return = SessionManager::create_session($name,$year_start,$month_start,$day_start,$year_end,$month_end,$day_end,$nb_days_acess_before,$nb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit, $end_limit);
global $_configuration;
require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
if ($_configuration['multiple_access_urls']) {
$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$access_url_id = api_get_current_access_url_id();
UrlManager::add_session_to_url($return,$access_url_id);
} else {
// we are filling by default the access_url_rel_session table
UrlManager::add_session_to_url($return,1);
}
require_once (api_get_path(LIBRARY_PATH).'urlmanager.lib.php');
if ($_configuration['multiple_access_urls']) {
$tbl_user_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$access_url_id = api_get_current_access_url_id();
UrlManager::add_session_to_url($return,$access_url_id);
} else {
// we are filling by default the access_url_rel_session table
UrlManager::add_session_to_url($return,1);
}
if ($return == strval(intval($return))) {
// integer => no error on session creation
header('Location: add_courses_to_session.php?id_session='.$return.'&add=true&msg=');
@ -228,14 +236,32 @@ if (intval($count_users)<50) {
</select>
</td>
</tr>
<tr>
<td width="40%"><?php echo get_lang('NoTimeLimits') ?></td>
<td width="60%">
<input type="checkbox" name="nolimit" onChange="setDisable(this)" />
</td>
<tr>
<td width="40%"><?php echo get_lang('DateStartSession') ?>&nbsp;&nbsp;</td>
<td>
&nbsp;
</td>
<td>
<a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('DefineSessionOptions') ?></a>
<div style="display: <?php if($formSent && ($nb_days_acess_before!=0 || $nb_days_acess_after!=0)) echo 'block'; else echo 'none'; ?>;" id="options">
<br />
<input type="text" name="nb_days_acess_before" value="<?php echo $nb_days_acess_before; ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br /><br />
<input type="text" name="nb_days_acess_after" value="<?php echo $nb_days_acess_after; ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
<br />
</div>
</td>
</tr>
<td width="40%"></td>
<td width="60%">
<input type="checkbox" name="start_limit" onchange="disable_starttime(this)" <?php if ($year_start=="0000") echo "checked"; ?>/>
<?php echo get_lang('DateStartSession');?>
<div id="start_date" style="display:none">
<br />
<select name="day_start">
<option value="1">01</option>
<option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_start == 2)) echo 'selected="selected"'; ?> >02</option>
@ -286,7 +312,6 @@ if (intval($count_users)<50) {
</select>
/
<select name="year_start">
<?php
for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
?>
@ -294,13 +319,24 @@ for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
<?php
}
?>
</select>
</div>
</td>
</tr>
<tr>
<td width="40%"><?php echo get_lang('DateEndSession') ?>&nbsp;&nbsp;</td>
<td width="40%">&nbsp;&nbsp;</td>
<td width="60%">
<input type="checkbox" name="end_limit" onchange="disable_endtime(this)" <?php if ($year_end=="0000") echo "checked"; ?>/>
<?php echo get_lang('DateEndSession') ?>
<div id="end_date" style="display:none">
<br />
<select name="day_end">
<option value="1">01</option>
<option value="2" <?php if((!$formSent && $thisDay == 2) || ($formSent && $day_end == 2)) echo 'selected="selected"'; ?> >02</option>
@ -359,38 +395,19 @@ for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
<?php
}
?>
</select>
</select>
<br /> <br />
<?php echo get_lang('SessionVisibility') ?>
<select name="session_visibility" style="width:250px;">
<?php
$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
foreach($visibility_list as $key=>$item): ?>
<option value="<?php echo $key; ?>" <?php if($item == $visibility_id) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
<?php endforeach; ?>
</select>
</div>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('DefineSessionOptions') ?></a>
<div style="display: <?php if($formSent && ($nb_days_acess_before!=0 || $nb_days_acess_after!=0)) echo 'block'; else echo 'none'; ?>;" id="options">
<br>
<input type="text" name="nb_days_acess_before" value="<?php echo $nb_days_acess_before; ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br>
<input type="text" name="nb_days_acess_after" value="<?php echo $nb_days_acess_after; ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
<br>
</div>
</td>
</tr>
<tr>
<td width="40%"><?php echo get_lang('SessionVisibility') ?></td>
<td width="60%">
<select name="session_visibility" style="width:250px;">
<?php
$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
foreach($visibility_list as $key=>$item): ?>
<option value="<?php echo $key; ?>" <?php if($item == $visibility_id) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
<?php endforeach; ?>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
@ -414,8 +431,34 @@ function setDisable(select){
document.form.session_visibility.disabled = (select.checked) ? true : false;
document.form.session_visibility.selectedIndex = 0;
document.form.start_limit.disabled = (select.checked) ? true : false;
document.form.start_limit.checked = false;
document.form.end_limit.disabled = (select.checked) ? true : false;
document.form.end_limit.checked = false;
var end_div = document.getElementById('end_date');
end_div.style.display = 'none';
var start_div = document.getElementById('start_date');
start_div.style.display = 'none';
}
function disable_endtime(select) {
var end_div = document.getElementById('end_date');
if (end_div.style.display == 'none')
end_div.style.display = 'block';
else
end_div.style.display = 'none';
}
function disable_starttime(select) {
var start_div = document.getElementById('start_date');
if (start_div.style.display == 'none')
start_div.style.display = 'block';
else
start_div.style.display = 'none';
}
</script>
<?php
Display::display_footer();
?>
Display::display_footer();

@ -12,51 +12,65 @@ $this_section=SECTION_PLATFORM_ADMIN;
api_protect_admin_script(true);
$id=intval($_GET['id']);
$id = intval($_GET['id']);
$formSent=0;
$errorMsg='';
// Database Table Definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$result=Database::query("SELECT name,date_start,date_end,id_coach, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility FROM $tbl_session WHERE id= $id");
if (!$infos=Database::fetch_array($result)) {
header('Location: session_list.php');
exit();
}
if (!api_is_platform_admin() && $infos['session_admin_id']!=api_get_user_id()) {
api_not_allowed(true);
}
$tool_name = get_lang('EditSession');
$interbreadcrumb[]=array('url' => 'index.php',"name" => get_lang('PlatformAdmin'));
$interbreadcrumb[]=array('url' => "session_list.php","name" => get_lang('SessionList'));
$result=Database::query("SELECT name,date_start,date_end,id_coach, session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id, visibility FROM $tbl_session WHERE id='$id'");
if (!$infos=Database::fetch_array($result)) {
header('Location: session_list.php');
exit();
}
list($year_start,$month_start,$day_start)=explode('-',$infos['date_start']);
list($year_end,$month_end,$day_end)=explode('-',$infos['date_end']);
list($year_start,$month_start,$day_start) = explode('-',$infos['date_start']);
list($year_end,$month_end,$day_end) = explode('-',$infos['date_end']);
if (!api_is_platform_admin() && $infos['session_admin_id']!=$_user['user_id']) {
api_not_allowed(true);
}
$end_year_disabled = $end_month_disabled = $end_day_disabled = '';
if ($_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'];
$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);
$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'];
$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);
if ($return == strval(intval($return))) {
header('Location: resume_session.php?id_session='.$return);
exit();
@ -70,16 +84,14 @@ if ($_configuration['multiple_access_urls']) {
$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";
$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');
$result = Database::query($sql);
$Coaches = Database::store_result($result);
$thisYear = date('Y');
// display the header
Display::display_header($tool_name);
@ -111,15 +123,11 @@ if (!empty($return)) {
<?php
foreach($Coaches as $enreg) {
?>
<option value="<?php echo $enreg['user_id']; ?>" <?php if((!$sent && $enreg['user_id'] == $infos['id_coach']) || ($sent && $enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
<?php
}
unset($Coaches);
?>
</select></td>
</tr>
<?php
@ -141,15 +149,46 @@ unset($Coaches);
</td>
</tr>
<tr>
<td width="30%"><?php echo get_lang('NoTimeLimits') ?></td>
<td width="70%">
<input type="checkbox" name="nolimit" onChange="setDisable(this)" <?php if($year_start=="0000") echo "checked"; ?>/>
</td>
<tr>
<td>
&nbsp;
</td>
<td>
<a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('DefineSessionOptions') ?></a>
<div style="display:
<?php
if($formSent){
if($nb_days_access_before!=0 || $nb_days_access_after!=0)
echo 'block';
else echo 'none';
}
else{
if($infos['nb_days_access_before_beginning']!=0 || $infos['nb_days_access_after_end']!=0)
echo 'block';
else
echo 'none';
}
?>
;" id="options">
<br>
<input type="text" name="nb_days_access_before" value="<?php if($formSent) echo api_htmlentities($nb_days_access_before,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_before_beginning'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br /><br />
<input type="text" name="nb_days_access_after" value="<?php if($formSent) echo api_htmlentities($nb_days_access_after,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_after_end'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
<br>
</div>
</td>
</tr>
<tr>
<td width="30%"><?php echo get_lang('DateStartSession') ?>&nbsp;&nbsp;</td>
<td width="30%"></td>
<td width="70%">
<input type="checkbox" name="start_limit" onchange="disable_starttime(this)" <?php if ($year_start!="0000") echo "checked"; ?>/>
<?php echo get_lang('DateStartSession');?>
<div id="start_date" style="<?php echo ($year_start=="0000") ? "display:none" : "display:block" ; ?>">
<br />
<select name="day_start">
<option value="1">01</option>
<option value="2" <?php if($day_start == 2) echo 'selected="selected"'; ?> >02</option>
@ -202,23 +241,25 @@ unset($Coaches);
<select name="year_start">
<?php
for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
{
?>
for($i=$thisYear-5;$i <= ($thisYear+5);$i++) { ?>
<option value="<?php echo $i; ?>" <?php if($year_start == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
<?php
}
?>
</select>
</div>
</td>
</tr>
<tr>
<td width="30%"><?php echo get_lang('DateEndSession') ?>&nbsp;&nbsp;</td>
<td width="30%"></td>
<td width="70%">
<select name="day_end">
<input type="checkbox" name="end_limit" onchange="disable_endtime(this)" <?php if ($year_end!="0000") echo "checked"; ?>/>
<?php echo get_lang('DateEndSession') ?>
<div id="end_date" style="<?php echo ($year_end=="0000") ? "display:none" : "display:block" ; ?>">
<br />
<select name="day_end" <?php echo $end_day_disabled; ?> >
<option value="1">01</option>
<option value="2" <?php if($day_end == 2) echo 'selected="selected"'; ?> >02</option>
<option value="3" <?php if($day_end == 3) echo 'selected="selected"'; ?> >03</option>
@ -252,7 +293,7 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
<option value="31" <?php if($day_end == 31) echo 'selected="selected"'; ?> >31</option>
</select>
/
<select name="month_end">
<select name="month_end" <?php echo $end_month_disabled; ?> >
<option value="1">01</option>
<option value="2" <?php if($month_end == 2) echo 'selected="selected"'; ?> >02</option>
<option value="3" <?php if($month_end == 3) echo 'selected="selected"'; ?> >03</option>
@ -267,71 +308,37 @@ for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
<option value="12" <?php if($month_end == 12) echo 'selected="selected"'; ?> >12</option>
</select>
/
<select name="year_end">
<select name="year_end" <?php echo $end_year_disabled; ?>>
<?php
for($i=$thisYear-5;$i <= ($thisYear+5);$i++)
{
for($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
?>
<option value="<?php echo $i; ?>" <?php if($year_end == $i) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>
&nbsp;
</td>
<td>
<a href="javascript://" onclick="if(document.getElementById('options').style.display == 'none'){document.getElementById('options').style.display = 'block';}else{document.getElementById('options').style.display = 'none';}"><?php echo get_lang('DefineSessionOptions') ?></a>
<div style="display:
<?php
if($formSent){
if($nb_days_access_before!=0 || $nb_days_access_after!=0)
echo 'block';
else echo 'none';
}
else{
if($infos['nb_days_access_before_beginning']!=0 || $infos['nb_days_access_after_end']!=0)
echo 'block';
else
echo 'none';
}
?>
;" id="options">
<br>
<input type="text" name="nb_days_access_before" value="<?php if($formSent) echo api_htmlentities($nb_days_access_before,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_before_beginning'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysBefore') ?><br>
<input type="text" name="nb_days_access_after" value="<?php if($formSent) echo api_htmlentities($nb_days_access_after,ENT_QUOTES,$charset); else echo api_htmlentities($infos['nb_days_access_after_end'],ENT_QUOTES,$charset); ?>" style="width: 30px;">&nbsp;<?php echo get_lang('DaysAfter') ?>
<br>
</div>
</td>
</tr>
<tr>
<td width="30%"><?php echo get_lang('SessionVisibility') ?></td>
<td width="70%">
<select name="session_visibility" style="width:250px;">
<?php
$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
foreach($visibility_list as $key=>$item): ?>
<option value="<?php echo $key; ?>" <?php if($key == $infos['visibility']) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
<?php endforeach; ?>
</select>
<br /> <br />
<?php echo get_lang('SessionVisibility') ?>
<select name="session_visibility" style="width:250px;">
<?php
$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
foreach($visibility_list as $key=>$item): ?>
<option value="<?php echo $key; ?>" <?php if($key == $infos['visibility']) echo 'selected="selected"'; ?>><?php echo $item; ?></option>
<?php endforeach; ?>
</select>
</div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<button class="save" type="submit" value="<?php echo get_lang('ModifyThisSession') ?>"><?php echo get_lang('ModifyThisSession') ?></button>
</td>
<td>&nbsp;</td>
<td>
<button class="save" type="submit" value="<?php echo get_lang('ModifyThisSession') ?>"><?php echo get_lang('ModifyThisSession') ?></button>
</td>
</tr>
</table>
@ -352,10 +359,38 @@ function setDisable(select){
document.form.year_end.disabled = (select.checked) ? true : false;
document.form.session_visibility.disabled = (select.checked) ? true : false;
document.form.session_visibility.selectedIndex = 0;
document.form.start_limit.disabled = (select.checked) ? true : false;
document.form.start_limit.checked = false;
document.form.end_limit.disabled = (select.checked) ? true : false;
document.form.end_limit.checked = false;
var end_div = document.getElementById('end_date');
end_div.style.display = 'none';
var start_div = document.getElementById('start_date');
start_div.style.display = 'none';
}
function disable_endtime(select) {
var end_div = document.getElementById('end_date');
if (end_div.style.display == 'none')
end_div.style.display = 'block';
else
end_div.style.display = 'none';
}
function disable_starttime(select) {
var start_div = document.getElementById('start_date');
if (start_div.style.display == 'none')
start_div.style.display = 'block';
else
start_div.style.display = 'none';
}
</script>
<?php
Display::display_footer();

@ -1,6 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
//@todo fix sort in this table or use jqgrid
$language_file = 'admin';
$cidReset = true;
@ -283,8 +285,8 @@ if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
<td><a href="resume_session.php?id_session=<?php echo $enreg['id']; ?>"><?php echo api_htmlentities($enreg['name'],ENT_QUOTES,$charset); ?></a></td>
<td><a href="session_course_list.php?id_session=<?php echo $enreg['id']; ?>"><?php echo $nb_courses.' '.get_lang('Course'); ?></a></td>
<td><?php echo api_htmlentities($enreg['category_name'],ENT_QUOTES,$charset); ?></td>
<td><?php echo api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset); ?></td>
<td><?php echo api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset); ?></td>
<td><?php echo ($enreg['date_start'] != '0000-00-00')? api_htmlentities($enreg['date_start'],ENT_QUOTES,$charset): '-'; ?></td>
<td><?php echo ($enreg['date_end'] != '0000-00-00')?api_htmlentities($enreg['date_end'],ENT_QUOTES,$charset): '-'; ?></td>
<td><?php echo $user_link; ?></td>
<td><?php

@ -1183,9 +1183,7 @@ class Display {
$active = false;
// Request for the name of the general coach
$sql ='SELECT tu.lastname, tu.firstname, ts.name, ts.date_start, ts.date_end, ts.session_category_id
FROM '.$tbl_session.' ts
LEFT JOIN '.$main_user_table .' tu
ON ts.id_coach = tu.user_id
FROM '.$tbl_session.' ts LEFT JOIN '.$main_user_table .' tu ON ts.id_coach = tu.user_id
WHERE ts.id='.intval($session_id);
$rs = Database::query($sql);
$session_info = Database::store_result($rs);
@ -1194,14 +1192,26 @@ class Display {
$session['title'] = $session_info[2];
$session['coach'] = '';
if ($session_info[3] == '0000-00-00') {
$session['dates'] = get_lang('WithoutTimeLimits');
if ($session_info['date_end'] == '0000-00-00' && $session_info['date_start'] == '0000-00-00') {
$session['dates'] = Display::tag('i', get_lang('WithoutTimeLimits'));
if (api_get_setting('show_session_coach') === 'true') {
$session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
}
$active = true;
} else {
$session ['dates'] = get_lang('From').' '.$session_info[3].' '.get_lang('Until').' '.$session_info[4];
if ($session_info['date_start'] == '0000-00-00') {
$session_info['date_start'] = '';
} else {
$session_info['date_start'] = get_lang('From').' '.$session_info['date_start'];
}
if ($session_info['date_end'] == '0000-00-00') {
$session_info['date_end'] = '';
} else {
$session_info['date_end'] = get_lang('Until').' '.$session_info['date_end'];
}
$session['dates'] = Display::tag('i', $session_info['date_start'].' '.$session_info['date_end']);
if ( api_get_setting('show_session_coach') === 'true' ) {
$session['coach'] = get_lang('GeneralCoach').': '.api_get_person_name($session_info[1], $session_info[0]);
}
@ -1213,4 +1223,4 @@ class Display {
}
return $output;
}
} //end class Display
} //end class Display

@ -35,7 +35,7 @@ class SessionManager {
}
/**
* Create a session
* @author Carlos Vargas <carlos.vargas@dokeos.com>,from existing code
* @author Carlos Vargas from existing code
* @param string name
* @param integer year_start
* @param integer month_start
@ -50,9 +50,8 @@ class SessionManager {
* @param integer id_session_category
* @return $id_session;
**/
public static function create_session ($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility) {
global $_user;
$name= trim($sname);
public static function create_session($sname,$syear_start,$smonth_start,$sday_start,$syear_end,$smonth_end,$sday_end,$snb_days_acess_before,$snb_days_acess_after,$nolimit,$coach_username, $id_session_category,$id_visibility, $start_limit = true, $end_limit = true) {
$name= Database::escape_string(trim($sname));
$year_start= intval($syear_start);
$month_start=intval($smonth_start);
$day_start=intval($sday_start);
@ -62,10 +61,11 @@ class SessionManager {
$nb_days_acess_before = intval($snb_days_acess_before);
$nb_days_acess_after = intval($snb_days_acess_after);
$id_session_category = intval($id_session_category);
$id_visibility = intval($id_visibility);
$id_visibility = intval($id_visibility);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
if(is_int($coach_username)) {
$id_coach = $coach_username;
} else {
@ -75,36 +75,47 @@ class SessionManager {
}
if (empty($nolimit)) {
$date_start="$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
$date_end="$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
$date_start ="$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
$date_end ="$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
} else {
$id_visibility = 1; // by default is read only
$date_start="0000-00-00";
$date_end="0000-00-00";
$id_visibility = 1; // by default session visibility is read only
$date_start ="0000-00-00";
$date_end ="0000-00-00";
}
if (empty($end_limit)) {
$date_end ="0000-00-00";
$id_visibility = 1; // by default session visibility is read only
}
if (empty($start_limit)) {
$date_start ="0000-00-00";
}
if (empty($name)) {
$msg=get_lang('SessionNameIsRequired');
return $msg;
} elseif (empty($coach_username)) {
$msg=get_lang('CoachIsRequired');
return $msg;
} elseif (empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start))) {
} elseif (!empty($start_limit) && empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start))) {
$msg=get_lang('InvalidStartDate');
return $msg;
} elseif (empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) {
} elseif (!empty($end_limit) && empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) {
$msg=get_lang('InvalidEndDate');
return $msg;
} elseif(empty($nolimit) && $date_start >= $date_end) {
} elseif(!empty($start_limit) && !empty($end_limit) && empty($nolimit) && $date_start >= $date_end) {
$msg=get_lang('StartDateShouldBeBeforeEndDate');
return $msg;
} else {
$rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".addslashes($name)."'");
if(Database::num_rows($rs)) {
$rs = Database::query("SELECT 1 FROM $tbl_session WHERE name='".$name."'");
if (Database::num_rows($rs)) {
$msg=get_lang('SessionNameAlreadyExists');
return $msg;
} else {
$sql_insert = "INSERT INTO $tbl_session(name,date_start,date_end,id_coach,session_admin_id, nb_days_access_before_beginning, nb_days_access_after_end, session_category_id,visibility)
VALUES('".Database::escape_string($name)."','$date_start','$date_end','$id_coach',".intval($_user['user_id']).",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")";
VALUES('".$name."','$date_start','$date_end','$id_coach',".api_get_user_id().",".$nb_days_acess_before.", ".$nb_days_acess_after.", ".$id_session_category.", ".$id_visibility.")";
Database::query($sql_insert);
$id_session=Database::insert_id();
@ -117,9 +128,10 @@ class SessionManager {
}
}
}
/**
* Edit a session
* @author Carlos Vargas <carlos.vargas@dokeos.com>,from existing code
* @author Carlos Vargas from existing code
* @param integer id
* @param string name
* @param integer year_start
@ -136,7 +148,7 @@ class SessionManager {
* @return $id;
* The parameter id is a primary key
**/
public static function 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) {
public static function 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 = true, $end_limit = true) {
global $_user;
$name=trim(stripslashes($name));
$year_start=intval($year_start);
@ -154,29 +166,42 @@ class SessionManager {
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
if (empty($nolimit)) {
$date_start="$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
$date_end="$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
$date_start = "$year_start-".(($month_start < 10)?"0$month_start":$month_start)."-".(($day_start < 10)?"0$day_start":$day_start);
$date_end = "$year_end-".(($month_end < 10)?"0$month_end":$month_end)."-".(($day_end < 10)?"0$day_end":$day_end);
} else {
$date_start="000-00-00";
$date_end="000-00-00";
$date_start = "0000-00-00";
$date_end = "0000-00-00";
$id_visibility = 1;//force read only
}
if (!empty($no_end_limit)) {
$date_end = "0000-00-00";
}
if (empty($end_limit)) {
$date_end ="0000-00-00";
$id_visibility = 1;//force read only
}
if (empty($start_limit)) {
$date_start ="0000-00-00";
}
if (empty($name)) {
$msg=get_lang('SessionNameIsRequired');
return $msg;
} elseif (empty($id_coach)) {
$msg=get_lang('CoachIsRequired');
return $msg;
} elseif (empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start))) {
} elseif (!empty($start_limit) && empty($nolimit) && (!$month_start || !$day_start || !$year_start || !checkdate($month_start,$day_start,$year_start))) {
$msg=get_lang('InvalidStartDate');
return $msg;
} elseif (empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) {
} elseif (!empty($end_limit) && empty($nolimit) && (!$month_end || !$day_end || !$year_end || !checkdate($month_end,$day_end,$year_end))) {
$msg=get_lang('InvalidEndDate');
return $msg;
} elseif (empty($nolimit) && $date_start >= $date_end) {
} elseif (!empty($start_limit) && !empty($end_limit) && empty($nolimit) && $date_start >= $date_end) {
$msg=get_lang('StartDateShouldBeBeforeEndDate');
return $msg;
} else {
@ -201,17 +226,13 @@ class SessionManager {
visibility= ".$id_visibility."
WHERE id='$id'";
Database::query($sql);
/*$sqlu = "UPDATE $tbl_session_rel_course " .
" SET id_coach='$id_coach'" .
" WHERE id_session='$id'";
Database::query($sqlu);*/
return $id;
}
}
}
/**
* Delete session
* @author Carlos Vargas <carlos.vargas@dokeos.com>, from existing code
* @author Carlos Vargas from existing code
* @param array id_checked
* @param boolean optional, true if the function is called by a webservice, false otherwise.
* @return void Nothing, or false on error
@ -313,7 +334,7 @@ class SessionManager {
/**
* Subscribes users to the given session and optionally (default) unsubscribes previous users
* @author Carlos Vargas <carlos.vargas@dokeos.com>,from existing code
* @author Carlos Vargas from existing code
* @param integer Session ID
* @param array List of user IDs
* @param bool Whether to unsubscribe existing users (true, default) or not (false)
@ -503,7 +524,7 @@ class SessionManager {
}
/** Subscribes courses to the given session and optionally (default) unsubscribes previous users
* @author Carlos Vargas <carlos.vargas@dokeos.com>,from existing code
* @author Carlos Vargas from existing code
* @param int Session ID
* @param array List of courses IDs
* @param bool Whether to unsubscribe existing users (true, default) or not (false)

@ -360,10 +360,8 @@ if (is_array($courses_tree)) {
$s = Display :: get_session_title_box($session['details']['id']);
$extra_info = (!empty($s['coach']) ? $s['coach'].' | ' : '').$s['dates'];
//var_dump($s);
//echo get_lang('SessionName') . ': ' . $s['title']. ' - '.(!empty($s['coach']) ? $s['coach'].' - ' : '').$s['dates'];
$session_link = Display::tag('a',$s['title'], array('href'=>api_get_path(WEB_CODE_PATH).'session/?session_id='.$session['details']['id']));
echo '<span>' . $session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info.'</span>';
echo Display::tag('span',$session_link. ' </span> <span style="padding-left: 10px; font-size: 90%; font-weight: normal;">'.$extra_info);
if (api_is_platform_admin()) {
echo '<div style="float:right;"><a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session['details']['id'].'">'.Display::return_icon('edit.gif', get_lang('Edit'), array('align' => 'absmiddle')).'</a></div>';
}

Loading…
Cancel
Save