Improving add_session.php page see BT#4874

skala
Julio Montoya 12 years ago
parent 393332c2fe
commit bf933d4d32
  1. 62
      main/admin/resume_session.php
  2. 620
      main/admin/session_add.php
  3. 397
      main/admin/session_edit.php
  4. 2
      main/admin/session_list.php
  5. 23
      main/inc/ajax/admin.ajax.php
  6. 2
      main/inc/lib/database.lib.php
  7. 122
      main/inc/lib/sessionmanager.lib.php

@ -23,7 +23,7 @@ $tool_name = get_lang('SessionOverview');
$interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
$session = SessionManager::get_session_info($id_session);
$session = api_get_session_info($id_session);
$session_cat_info = SessionManager::get_session_category($session['session_category_id']);
$session_category = null;
if (!empty($session_cat_info)) {
@ -64,15 +64,17 @@ if (!empty($message)) {
echo Display::page_header(Display::return_icon('session.png', get_lang('Session')).' '.$session['name']);
$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_edit.php?page=resume_session.php&id=$id_session");
$url = Display::url(Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL), "session_add.php?page=resume_session.php&id=$id_session");
echo Display::page_subheader(get_lang('GeneralProperties').$url);
$coach_info = api_get_user_info($session['id_coach']);
?>
<!-- General properties -->
<table class="data_table">
<tr>
<td><?php echo get_lang('GeneralCoach'); ?> :</td>
<td><?php echo api_get_person_name($session['firstname'], $session['lastname']).' ('.$session['username'].')' ?></td>
<td><?php echo $coach_info['complete_name'].' ('.$coach_info['username'].')' ?></td>
</tr>
<?php if(!empty($session_category)) { ?>
<tr>
@ -81,44 +83,28 @@ echo Display::page_subheader(get_lang('GeneralProperties').$url);
</tr>
<?php } ?>
<tr>
<td><?php echo get_lang('Date'); ?> :</td>
<td>
<?php
if ($session['date_start'] == '00-00-0000' && $session['date_end']== '00-00-0000' )
echo get_lang('NoTimeLimits');
else {
if ($session['date_start'] != '00-00-0000') {
//$session['date_start'] = Display::tag('i', get_lang('NoTimeLimits'));
$session['date_start'] = get_lang('From').' '.$session['date_start'];
} else {
$session['date_start'] = '';
}
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>
<td><?php echo get_lang('SessionDisplayStartDate'); ?> :</td>
<td><?php echo api_get_local_time($session['display_start_date'], null, null, true); ?></td>
</tr>
<!-- show nb_days_before and nb_days_after only if they are different from 0 -->
<tr>
<td>
<?php echo api_ucfirst(get_lang('DaysBefore')) ?> :
</td>
<td>
<?php echo intval($session['nb_days_access_before_beginning']) ?>
</td>
<td><?php echo get_lang('SessionDisplayEndDate'); ?> :</td>
<td><?php echo api_get_local_time($session['display_end_date'], null, null, true); ?></td>
</tr>
<tr>
<td>
<?php echo api_ucfirst(get_lang('DaysAfter')) ?> :
</td>
<td>
<?php echo intval($session['nb_days_access_after_end']) ?>
</td>
<tr>
<td><?php echo get_lang('SessionStartDate'); ?> :</td>
<td><?php echo api_get_local_time($session['access_start_date'], null, null, true); ?></td>
</tr>
<tr>
<td><?php echo get_lang('SessionEndDate'); ?> :</td>
<td><?php echo api_get_local_time($session['access_end_date'], null, null, true); ?></td>
</tr>
<tr>
<td><?php echo get_lang('SessionCoachStartDate'); ?> :</td>
<td><?php echo api_get_local_time($session['coach_access_start_date'], null, null, true); ?></td>
</tr>
<tr>
<td><?php echo get_lang('SessionCoachEndDate'); ?> :</td>
<td><?php echo api_get_local_time($session['coach_access_end_date'], null, null, true); ?></td>
</tr>
<tr>
<td>

@ -7,443 +7,255 @@
*/
// name of the language file that needs to be included
$language_file='admin';
$language_file = 'admin';
$cidReset=true;
$cidReset = true;
// including the global Chamilo file
require_once '../inc/global.inc.php';
// including additional libraries
require_once '../inc/lib/xajax/xajax.inc.php';
$xajax = new xajax();
//$xajax->debugOn();
$xajax -> registerFunction ('search_coachs');
// setting the section (for the tabs)
$this_section=SECTION_PLATFORM_ADMIN;
$this_section = SECTION_PLATFORM_ADMIN;
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'));
// Database Table Definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
function search_coachs($needle) {
global $tbl_user;
$xajax_response = new XajaxResponse();
$return = '';
if(!empty($needle)) {
// xajax send utf8 datas... datas in db can be non-utf8 datas
$charset = api_get_system_encoding();
$needle = api_convert_encoding($needle, $charset, 'utf-8');
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
// search users where username or firstname or lastname begins likes $needle
$sql = 'SELECT username, lastname, firstname FROM '.$tbl_user.' user
WHERE (username LIKE "'.$needle.'%"
OR firstname LIKE "'.$needle.'%"
OR lastname LIKE "'.$needle.'%")
AND status=1'.
$order_clause.
' LIMIT 10';
global $_configuration;
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();
if ($access_url_id != -1){
$sql = 'SELECT username, lastname, firstname FROM '.$tbl_user.' user
INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
WHERE access_url_id = '.$access_url_id.' AND (username LIKE "'.$needle.'%"
OR firstname LIKE "'.$needle.'%"
OR lastname LIKE "'.$needle.'%")
AND status=1'.
$order_clause.
' LIMIT 10';
}
}
$rs = Database::query($sql);
while ($user = Database :: fetch_array($rs)) {
$return .= '<a href="javascript: void(0);" onclick="javascript: fill_coach_field(\''.$user['username'].'\')">'.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')</a><br />';
}
}
$xajax_response -> addAssign('ajax_list_coachs','innerHTML', api_utf8_encode($return));
return $xajax_response;
}
$xajax -> processRequests();
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'session_list.php','name' => get_lang('SessionList'));
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = '
<script type="text/javascript">
function fill_coach_field (username) {
document.getElementById("coach_username").value = username;
document.getElementById("ajax_list_coachs").innerHTML = "";
}
</script>';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/jquery.fcbkcomplete.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/tag/style.css" rel="stylesheet" type="text/css" />';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/jquery-ui-timepicker-addon.js" type="text/javascript" language="javascript"></script>';
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/jquery-ui-timepicker-addon.css" rel="stylesheet" type="text/css" />';
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'];
$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);
if ($return == strval(intval($return))) {
// integer => no error on session creation
header('Location: add_courses_to_session.php?id_session='.$return.'&add=true&msg=');
exit();
}
}
$isocode = api_get_language_isocode();
//$isocode = 'es';
$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/datetimepicker/localization/jquery-ui-timepicker-'.$isocode.'.js" type="text/javascript" language="javascript"></script>';
$nb_days_acess_before = 0;
$nb_days_acess_after = 0;
$thisYear=date('Y');
$thisMonth=date('m');
$thisDay=date('d');
$id = null;
$url_action = api_get_self();
if (isset($_GET['id'])) {
$id = intval($_GET['id']);
$url_action = '?id='.$id;
}
$tool_name = get_lang('AddSession');
$add_coach = null;
if ($id) {
$tool_name = get_lang('EditSession');
SessionManager::protect_session_edit($id);
$session_info = api_get_session_info($id);
if (!empty($session_info['id_coach'])) {
$user_info = api_get_user_info($session_info['id_coach']);
$add_coach = '$("#coach_id").trigger("addItem", [{"title": "'.$user_info['complete_name'].'", "value": "'.$session_info['id_coach'].'"}]);';
}
$button = get_lang('Update');
} else {
$tool_name = get_lang('AddSession');
$button = get_lang('Add');
}
Display::display_header($tool_name);
if (!empty($return)) {
Display::display_error_message($return,false);
$url = api_get_path(WEB_AJAX_PATH).'admin.ajax.php?1=1';
$htmlHeadXtra[] ='
<script>
function check() {
$("#coach_id option:selected").each(function() {
var id = $(this).val();
var name = $(this).text();
if (id != "" ) {
$.ajax({
async: false,
url: "'.$url.'&a=user_exists",
data: "id="+id,
success: function(return_value) {
if (return_value == 0 ) {
alert("'.get_lang('UserDoesNotExist').'");
//Deleting select option tag
$("#coach_id").find("option").remove();
$(".holder li").each(function () {
if ($(this).attr("rel") == id) {
$(this).remove();
}
});
}
},
});
}
});
}
echo '<div class="actions">';
echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
?>
<form class="form-horizontal" method="post" name="form" action="<?php echo api_get_self(); ?>" style="margin:0px;">
<input type="hidden" name="formSent" value="1">
<div class="control-group">
<label class="control-label">
<?php echo get_lang('SessionName') ?>
</label>
<div class="controls">
<input type="text" name="name" class="span4" maxlength="50" value="<?php if($formSent) echo api_htmlentities($name,ENT_QUOTES,$charset); ?>">
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php echo get_lang('CoachName') ?>
</label>
<div class="controls">
<?php
$(function() {
$sql = 'SELECT COUNT(1) FROM '.$tbl_user.' WHERE status=1';
$rs = Database::query($sql);
$count_users = Database::result($rs, 0, 0);
if (intval($count_users)<50) {
$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;
global $_configuration;
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();
if ($access_url_id != -1){
$sql = 'SELECT user.user_id, username, lastname, firstname FROM '.$tbl_user.' user
INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
WHERE access_url_id = '.$access_url_id.' AND status=1'.$order_clause;
}
}
$result = Database::query($sql);
$Coaches = Database::store_result($result);
?>
<select id="coach_username" class="chzn-select" name="coach_username" style="width:350px;" title="<?php echo get_lang('Select'); ?>" >
<option value="0"><?php get_lang('None'); ?></option>
<?php foreach($Coaches as $enreg): ?>
<option value="<?php echo $enreg['username']; ?>"> <?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
<?php endforeach; ?>
</select>
<?php
echo Display::return_icon('synthese_view.gif',get_lang('ActivityCoach'));
} else {
?>
<input type="text" name="coach_username" id="coach_username" onkeyup="xajax_search_coachs(document.getElementById('coach_username').value)" /><div id="ajax_list_coachs"></div>
<?php
}
$Categories = SessionManager::get_all_session_category();
?>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php echo get_lang('SessionCategory') ?>
</label>
<div class="controls">
<select id="session_category" class="chzn-select" name="session_category" style="width:350px;" title="<?php echo get_lang('Select'); ?>">
<option value="0"><?php get_lang('None'); ?></option>
<?php
if (!empty($Categories)) {
foreach($Categories as $Rows) { ?>
<option value="<?php echo $Rows['id']; ?>" <?php if($Rows['id'] == $id_session_category) echo 'selected="selected"'; ?>><?php echo $Rows['name']; ?></option>
<?php }
}
?>
</select>
</div>
</div>
$("#display_end_date").datetimepicker({
dateFormat: "yy-mm-dd"
});
<div class="control-group">
<div class="controls">
<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>
</div>
</div>
$("#display_start_date").datetimepicker({
dateFormat: "yy-mm-dd",
hour: 9,
onSelect: function(selectedDateTime) {
var start = $(this).datetimepicker("getDate");
$("#display_end_date").val(selectedDateTime);
}
});
<div class="control-group">
<div class="controls">
<label for="start_limit">
<input id="start_limit" type="checkbox" name="start_limit" onchange="disable_starttime(this)" />
<?php echo get_lang('DateStartSession');?>
</label>
<div id="start_date" style="display:none">
<br />
$("#access_start_date").datetimepicker({
dateFormat: "yy-mm-dd",
hour: 9,
onSelect: function(selectedDateTime) {
var start = $(this).datetimepicker("getDate");
$("#access_end_date").val(selectedDateTime);
}
});
<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>
<option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_start == 3)) echo 'selected="selected"'; ?> >03</option>
<option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_start == 4)) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_start == 5)) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_start == 6)) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_start == 7)) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_start == 8)) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_start == 9)) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_start == 10)) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_start == 11)) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_start == 12)) echo 'selected="selected"'; ?> >12</option>
<option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_start == 13)) echo 'selected="selected"'; ?> >13</option>
<option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_start == 14)) echo 'selected="selected"'; ?> >14</option>
<option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_start == 15)) echo 'selected="selected"'; ?> >15</option>
<option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_start == 16)) echo 'selected="selected"'; ?> >16</option>
<option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_start == 17)) echo 'selected="selected"'; ?> >17</option>
<option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_start == 18)) echo 'selected="selected"'; ?> >18</option>
<option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_start == 19)) echo 'selected="selected"'; ?> >19</option>
<option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_start == 20)) echo 'selected="selected"'; ?> >20</option>
<option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_start == 21)) echo 'selected="selected"'; ?> >21</option>
<option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_start == 22)) echo 'selected="selected"'; ?> >22</option>
<option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_start == 23)) echo 'selected="selected"'; ?> >23</option>
<option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_start == 24)) echo 'selected="selected"'; ?> >24</option>
<option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_start == 25)) echo 'selected="selected"'; ?> >25</option>
<option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_start == 26)) echo 'selected="selected"'; ?> >26</option>
<option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_start == 27)) echo 'selected="selected"'; ?> >27</option>
<option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_start == 28)) echo 'selected="selected"'; ?> >28</option>
<option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_start == 29)) echo 'selected="selected"'; ?> >29</option>
<option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_start == 30)) echo 'selected="selected"'; ?> >30</option>
<option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_start == 31)) echo 'selected="selected"'; ?> >31</option>
</select>
/
<select name="month_start">
<option value="1">01</option>
<option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_start == 2)) echo 'selected="selected"'; ?> >02</option>
<option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_start == 3)) echo 'selected="selected"'; ?> >03</option>
<option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_start == 4)) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_start == 5)) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_start == 6)) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_start == 7)) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_start == 8)) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_start == 9)) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_start == 10)) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_start == 11)) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_start == 12)) echo 'selected="selected"'; ?> >12</option>
</select>
/
<select name="year_start">
<?php
for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
?>
<option value="<?php echo $i; ?>" <?php if((!$formSent && $thisYear == $i) || ($formSent && $year_start == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="control-group">
<div class="controls">
<label for="end_limit">
<input id="end_limit" type="checkbox" name="end_limit" onchange="disable_endtime(this)" />
<?php echo get_lang('DateEndSession') ?>
</label>
<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>
<option value="3" <?php if((!$formSent && $thisDay == 3) || ($formSent && $day_end == 3)) echo 'selected="selected"'; ?> >03</option>
<option value="4" <?php if((!$formSent && $thisDay == 4) || ($formSent && $day_end == 4)) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if((!$formSent && $thisDay == 5) || ($formSent && $day_end == 5)) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if((!$formSent && $thisDay == 6) || ($formSent && $day_end == 6)) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if((!$formSent && $thisDay == 7) || ($formSent && $day_end == 7)) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if((!$formSent && $thisDay == 8) || ($formSent && $day_end == 8)) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if((!$formSent && $thisDay == 9) || ($formSent && $day_end == 9)) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if((!$formSent && $thisDay == 10) || ($formSent && $day_end == 10)) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if((!$formSent && $thisDay == 11) || ($formSent && $day_end == 11)) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if((!$formSent && $thisDay == 12) || ($formSent && $day_end == 12)) echo 'selected="selected"'; ?> >12</option>
<option value="13" <?php if((!$formSent && $thisDay == 13) || ($formSent && $day_end == 13)) echo 'selected="selected"'; ?> >13</option>
<option value="14" <?php if((!$formSent && $thisDay == 14) || ($formSent && $day_end == 14)) echo 'selected="selected"'; ?> >14</option>
<option value="15" <?php if((!$formSent && $thisDay == 15) || ($formSent && $day_end == 15)) echo 'selected="selected"'; ?> >15</option>
<option value="16" <?php if((!$formSent && $thisDay == 16) || ($formSent && $day_end == 16)) echo 'selected="selected"'; ?> >16</option>
<option value="17" <?php if((!$formSent && $thisDay == 17) || ($formSent && $day_end == 17)) echo 'selected="selected"'; ?> >17</option>
<option value="18" <?php if((!$formSent && $thisDay == 18) || ($formSent && $day_end == 18)) echo 'selected="selected"'; ?> >18</option>
<option value="19" <?php if((!$formSent && $thisDay == 19) || ($formSent && $day_end == 19)) echo 'selected="selected"'; ?> >19</option>
<option value="20" <?php if((!$formSent && $thisDay == 20) || ($formSent && $day_end == 20)) echo 'selected="selected"'; ?> >20</option>
<option value="21" <?php if((!$formSent && $thisDay == 21) || ($formSent && $day_end == 21)) echo 'selected="selected"'; ?> >21</option>
<option value="22" <?php if((!$formSent && $thisDay == 22) || ($formSent && $day_end == 22)) echo 'selected="selected"'; ?> >22</option>
<option value="23" <?php if((!$formSent && $thisDay == 23) || ($formSent && $day_end == 23)) echo 'selected="selected"'; ?> >23</option>
<option value="24" <?php if((!$formSent && $thisDay == 24) || ($formSent && $day_end == 24)) echo 'selected="selected"'; ?> >24</option>
<option value="25" <?php if((!$formSent && $thisDay == 25) || ($formSent && $day_end == 25)) echo 'selected="selected"'; ?> >25</option>
<option value="26" <?php if((!$formSent && $thisDay == 26) || ($formSent && $day_end == 26)) echo 'selected="selected"'; ?> >26</option>
<option value="27" <?php if((!$formSent && $thisDay == 27) || ($formSent && $day_end == 27)) echo 'selected="selected"'; ?> >27</option>
<option value="28" <?php if((!$formSent && $thisDay == 28) || ($formSent && $day_end == 28)) echo 'selected="selected"'; ?> >28</option>
<option value="29" <?php if((!$formSent && $thisDay == 29) || ($formSent && $day_end == 29)) echo 'selected="selected"'; ?> >29</option>
<option value="30" <?php if((!$formSent && $thisDay == 30) || ($formSent && $day_end == 30)) echo 'selected="selected"'; ?> >30</option>
<option value="31" <?php if((!$formSent && $thisDay == 31) || ($formSent && $day_end == 31)) echo 'selected="selected"'; ?> >31</option>
</select>
/
<select name="month_end">
<option value="1">01</option>
<option value="2" <?php if((!$formSent && $thisMonth == 2) || ($formSent && $month_end == 2)) echo 'selected="selected"'; ?> >02</option>
<option value="3" <?php if((!$formSent && $thisMonth == 3) || ($formSent && $month_end == 3)) echo 'selected="selected"'; ?> >03</option>
<option value="4" <?php if((!$formSent && $thisMonth == 4) || ($formSent && $month_end == 4)) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if((!$formSent && $thisMonth == 5) || ($formSent && $month_end == 5)) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if((!$formSent && $thisMonth == 6) || ($formSent && $month_end == 6)) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if((!$formSent && $thisMonth == 7) || ($formSent && $month_end == 7)) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if((!$formSent && $thisMonth == 8) || ($formSent && $month_end == 8)) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if((!$formSent && $thisMonth == 9) || ($formSent && $month_end == 9)) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if((!$formSent && $thisMonth == 10) || ($formSent && $month_end == 10)) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if((!$formSent && $thisMonth == 11) || ($formSent && $month_end == 11)) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if((!$formSent && $thisMonth == 12) || ($formSent && $month_end == 12)) echo 'selected="selected"'; ?> >12</option>
</select>
/
<select name="year_end">
<?php
for ($i=$thisYear-5;$i <= ($thisYear+5);$i++) {
?>
<option value="<?php echo $i; ?>" <?php if((!$formSent && ($thisYear+1) == $i) || ($formSent && $year_end == $i)) echo 'selected="selected"'; ?> ><?php echo $i; ?></option>
<?php
}
?>
</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>
</div>
</div>
$("#access_end_date").datetimepicker({
dateFormat: "yy-mm-dd"
});
$("#coach_access_start_date").datetimepicker({
dateFormat: "yy-mm-dd",
hour: 9,
onSelect: function(selectedDateTime) {
var start = $(this).datetimepicker("getDate");
$("#coach_access_end_date").val(selectedDateTime);
}
});
<div class="control-group">
<div class="controls">
<button class="save" type="submit" value="<?php echo get_lang('NextStep') ?>"><?php echo get_lang('NextStep') ?></button>
</div>
</div>
</form>
<script type="text/javascript">
function setDisable(select){
document.form.day_start.disabled = (select.checked) ? true : false;
document.form.month_start.disabled = (select.checked) ? true : false;
document.form.year_start.disabled = (select.checked) ? true : false;
document.form.day_end.disabled = (select.checked) ? true : false;
document.form.month_end.disabled = (select.checked) ? true : false;
document.form.year_end.disabled = (select.checked) ? true : false;
document.form.session_visibility.disabled = (select.checked) ? true : false;
document.form.session_visibility.selectedIndex = 0;
$("#coach_access_end_date").datetimepicker({
dateFormat: "yy-mm-dd"
});
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';
$("#coach_id").fcbkcomplete({
json_url: "'.$url.'&a=find_coaches",
maxitems: 1,
addontab: false,
input_min_size: 0,
cache: false,
filter_case: false,
filter_hide: true,
complete_text:"'.get_lang('StartToType').'",
firstselected: true,
onselect: check,
filter_selected: true,
newel: true
});
'.$add_coach.'
var start_div = document.getElementById('start_date');
start_div.style.display = 'none';
var value = 1;
$("#advanced_parameters").on("click", function() {
$("#options").toggle(function() {
if (value == 1) {
$("#advanced_parameters").addClass("btn-hide");
value = 0;
} else {
$("#advanced_parameters").removeClass("btn-hide");
value = 1;
}
});
});
});
</script>';
$form = new FormValidator('add_session', 'post', $url_action);
$form->addElement('header', $tool_name);
//Name
$form->addElement('text', 'name', get_lang('SessionName'), array('class' => 'span6'));
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
if (empty($id)) {
$form->addRule('name', get_lang('SessionNameAlreadyExists'), 'callback', 'check_session_name');
} else {
$form->addElement('hidden', 'id', $id);
}
$categories = SessionManager::get_all_session_category();
$select_categories = array();
if (!empty($categories)) {
$select_categories = array('0' => get_lang('None'));
foreach ($categories as $row) {
$select_categories[$row['id']] = $row['name'];
}
}
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';
//Categories
$form->addElement('select', 'session_category_id', get_lang('SessionCategory'), $select_categories, array('class' => 'chzn-select'));
//Coaches
//$coaches = SessionManager::get_user_list();
$form->addElement('select', 'id_coach', get_lang('CoachName'), array(),array('id' => 'coach_id'));
$form->addRule('id_coach', get_lang('ThisFieldIsRequired'), 'required');
$form->addElement('advanced_settings','<a class="btn btn-show" id="advanced_parameters" href="javascript://">'.get_lang('AdvancedParameters').'</a>');
$form->addElement('html','<div id="options" style="display:none">');
//Dates
$form->addElement('text', 'display_start_date', array(get_lang('SessionDisplayStartDate'), get_lang('SessionDisplayStartDateComment')), array('id' => 'display_start_date'));
$form->addElement('text', 'display_end_date', array(get_lang('SessionDisplayEndDate'), get_lang('SessionDisplayEndDateComment')), array('id' => 'display_end_date'));
$form->addRule(array('display_start_date', 'display_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '<');
$form->addElement('text', 'access_start_date', array(get_lang('SessionStartDate'), get_lang('SessionStartDateComment')), array('id' => 'access_start_date'));
$form->addElement('text', 'access_end_date', array(get_lang('SessionEndDate'), get_lang('SessionEndDate')), array('id' => 'access_end_date'));
$form->addRule(array('access_start_date', 'access_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '<');
$form->addElement('text', 'coach_access_start_date', array(get_lang('SessionCoachStartDate'), get_lang('SessionCoachStartDateComment')), array('id' => 'coach_access_start_date'));
$form->addElement('text', 'coach_access_end_date', array(get_lang('SessionCoachEndDate'), get_lang('SessionCoachEndDateComment')), array('id' => 'coach_access_end_date'));
$form->addRule(array('coach_access_start_date', 'coach_access_end_date'), get_lang('StartDateMustBeBeforeTheEndDate'), 'compare_datetime_text', '<');
//Visibility
$visibility_list = array(SESSION_VISIBLE_READ_ONLY=>get_lang('SessionReadOnly'), SESSION_VISIBLE=>get_lang('SessionAccessible'), SESSION_INVISIBLE=>api_ucfirst(get_lang('SessionNotAccessible')));
$form->addElement('select', 'visibility', get_lang('SessionVisibility'), $visibility_list, array('id' => 'visibility'));
$form->addElement('html','</div>');
$form->addElement('button', 'submit', $button);
if (!empty($session_info)) {
$session_info['display_start_date'] = api_get_local_time($session_info['display_start_date'], null, null, true);
$session_info['display_end_date'] = api_get_local_time($session_info['display_end_date'], null, null, true);
$session_info['access_start_date'] = api_get_local_time($session_info['access_start_date'], null, null, true);
$session_info['access_end_date'] = api_get_local_time($session_info['access_end_date'], null, null, true);
$session_info['coach_access_start_date'] = api_get_local_time($session_info['coach_access_start_date'], null, null, true);
$session_info['coach_access_end_date'] = api_get_local_time($session_info['coach_access_end_date'], null, null, true);
$form->setDefaults($session_info);
}
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';
if ($form->validate()) {
$params = $form->getSubmitValues();
if (isset($params['id'])) {
$result = SessionManager::update($params);
header('Location: resume_session.php?id_session='.$params['id']);
exit;
} else {
$result = SessionManager::add($params);
if ($result) {
// integer => no error on session creation
header('Location: add_courses_to_session.php?id_session='.$result.'&add=true&msg=');
exit;
}
}
}
</script>
<?php
function check_session_name($name) {
$session = SessionManager::get_session_by_name($name);
return empty($session) ? true : false;
}
Display::display_header($tool_name);
echo '<div class="actions">';
echo '<a href="../admin/index.php">'.Display::return_icon('back.png', get_lang('BackTo').' '.get_lang('PlatformAdmin'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
$form->display();
Display::display_footer();

@ -1,397 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
// name of the language file that needs to be included
$language_file ='admin';
$cidReset = true;
require_once '../inc/global.inc.php';
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
$formSent = 0;
// Database Table Definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$id = intval($_GET['id']);
SessionManager::protect_session_edit($id);
$sql = "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";
$result = Database::query($sql);
if (!$infos = Database::fetch_array($result)) {
header('Location: session_list.php');
exit();
}
$id_coach = $infos['id_coach'];
$tool_name = get_lang('EditSession');
$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,"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']);
$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'];
$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();
}
}
$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 ($_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";
}
}
$result = Database::query($sql);
$Coaches = Database::store_result($result);
$thisYear = date('Y');
// display the header
Display::display_header($tool_name);
// display the tool title
// api_display_tool_title($tool_name);
if (!empty($return)) {
Display::display_error_message($return,false);
}
?>
<form class="form-horizontal" method="post" name="form" action="<?php echo api_get_self(); ?>?page=<?php echo Security::remove_XSS($_GET['page']) ?>&id=<?php echo $id; ?>" style="margin:0px;">
<fieldset>
<legend><?php echo $tool_name; ?></legend>
<input type="hidden" name="formSent" value="1">
<div class="control-group">
<label class="control-label">
<?php echo get_lang('SessionName') ?>
</label>
<div class="controls">
<input type="text" name="name" class="span4" maxlength="50" value="<?php if($formSent) echo api_htmlentities($name,ENT_QUOTES,$charset); else echo api_htmlentities($infos['name'],ENT_QUOTES,$charset); ?>">
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php echo get_lang('CoachName') ?>
</label>
<div class="controls">
<select class="chzn-select" name="id_coach" style="width:380px;" title="<?php echo get_lang('Choose'); ?>" >
<option value="">----- <?php echo get_lang('None') ?> -----</option>
<?php foreach($Coaches as $enreg) { ?>
<option value="<?php echo $enreg['user_id']; ?>" <?php if(($enreg['user_id'] == $infos['id_coach']) || ($enreg['user_id'] == $id_coach)) echo 'selected="selected"'; ?>><?php echo api_get_person_name($enreg['firstname'], $enreg['lastname']).' ('.$enreg['username'].')'; ?></option>
<?php
}
unset($Coaches);
$Categories = SessionManager::get_all_session_category();
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">
<?php echo get_lang('SessionCategory') ?>
</label>
<div class="controls">
<select class="chzn-select" id="session_category" name="session_category" style="width:380px;" title="<?php echo get_lang('Select'); ?>">
<option value="0"><?php get_lang('None'); ?></option>
<?php
if (!empty($Categories)) {
foreach($Categories as $Rows) { ?>
<option value="<?php echo $Rows['id']; ?>" <?php if($Rows['id'] == $infos['session_category_id']) echo 'selected="selected"'; ?>><?php echo $Rows['name']; ?></option>
<?php }
}
?>
</select>
</div>
</div>
<div class="control-group">
<div class="controls">
<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>
</div>
<div class="control-group">
<div class="controls">
<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">
<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') ?>
</div>
</div>
</div>
<div class="clear"></div>
<div class="control-group">
<div class="controls">
<label for="start_limit">
<input id="start_limit" type="checkbox" name="start_limit" onchange="disable_starttime(this)" <?php if ($year_start!="0000") echo "checked"; ?>/>
<?php echo get_lang('DateStartSession');?>
</label>
<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>
<option value="3" <?php if($day_start == 3) echo 'selected="selected"'; ?> >03</option>
<option value="4" <?php if($day_start == 4) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if($day_start == 5) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if($day_start == 6) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if($day_start == 7) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if($day_start == 8) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if($day_start == 9) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if($day_start == 10) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if($day_start == 11) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if($day_start == 12) echo 'selected="selected"'; ?> >12</option>
<option value="13" <?php if($day_start == 13) echo 'selected="selected"'; ?> >13</option>
<option value="14" <?php if($day_start == 14) echo 'selected="selected"'; ?> >14</option>
<option value="15" <?php if($day_start == 15) echo 'selected="selected"'; ?> >15</option>
<option value="16" <?php if($day_start == 16) echo 'selected="selected"'; ?> >16</option>
<option value="17" <?php if($day_start == 17) echo 'selected="selected"'; ?> >17</option>
<option value="18" <?php if($day_start == 18) echo 'selected="selected"'; ?> >18</option>
<option value="19" <?php if($day_start == 19) echo 'selected="selected"'; ?> >19</option>
<option value="20" <?php if($day_start == 20) echo 'selected="selected"'; ?> >20</option>
<option value="21" <?php if($day_start == 21) echo 'selected="selected"'; ?> >21</option>
<option value="22" <?php if($day_start == 22) echo 'selected="selected"'; ?> >22</option>
<option value="23" <?php if($day_start == 23) echo 'selected="selected"'; ?> >23</option>
<option value="24" <?php if($day_start == 24) echo 'selected="selected"'; ?> >24</option>
<option value="25" <?php if($day_start == 25) echo 'selected="selected"'; ?> >25</option>
<option value="26" <?php if($day_start == 26) echo 'selected="selected"'; ?> >26</option>
<option value="27" <?php if($day_start == 27) echo 'selected="selected"'; ?> >27</option>
<option value="28" <?php if($day_start == 28) echo 'selected="selected"'; ?> >28</option>
<option value="29" <?php if($day_start == 29) echo 'selected="selected"'; ?> >29</option>
<option value="30" <?php if($day_start == 30) echo 'selected="selected"'; ?> >30</option>
<option value="31" <?php if($day_start == 31) echo 'selected="selected"'; ?> >31</option>
</select>
/
<select name="month_start">
<option value="1">01</option>
<option value="2" <?php if($month_start == 2) echo 'selected="selected"'; ?> >02</option>
<option value="3" <?php if($month_start == 3) echo 'selected="selected"'; ?> >03</option>
<option value="4" <?php if($month_start == 4) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if($month_start == 5) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if($month_start == 6) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if($month_start == 7) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if($month_start == 8) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if($month_start == 9) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if($month_start == 10) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if($month_start == 11) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if($month_start == 12) echo 'selected="selected"'; ?> >12</option>
</select>
/
<select name="year_start">
<?php
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>
</div>
</div>
<div class="control-group">
<div class="controls">
<label for="end_limit">
<input id="end_limit" type="checkbox" name="end_limit" onchange="disable_endtime(this)" <?php if ($year_end!="0000") echo "checked"; ?>/>
<?php echo get_lang('DateEndSession') ?>
</label>
<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>
<option value="4" <?php if($day_end == 4) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if($day_end == 5) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if($day_end == 6) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if($day_end == 7) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if($day_end == 8) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if($day_end == 9) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if($day_end == 10) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if($day_end == 11) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if($day_end == 12) echo 'selected="selected"'; ?> >12</option>
<option value="13" <?php if($day_end == 13) echo 'selected="selected"'; ?> >13</option>
<option value="14" <?php if($day_end == 14) echo 'selected="selected"'; ?> >14</option>
<option value="15" <?php if($day_end == 15) echo 'selected="selected"'; ?> >15</option>
<option value="16" <?php if($day_end == 16) echo 'selected="selected"'; ?> >16</option>
<option value="17" <?php if($day_end == 17) echo 'selected="selected"'; ?> >17</option>
<option value="18" <?php if($day_end == 18) echo 'selected="selected"'; ?> >18</option>
<option value="19" <?php if($day_end == 19) echo 'selected="selected"'; ?> >19</option>
<option value="20" <?php if($day_end == 20) echo 'selected="selected"'; ?> >20</option>
<option value="21" <?php if($day_end == 21) echo 'selected="selected"'; ?> >21</option>
<option value="22" <?php if($day_end == 22) echo 'selected="selected"'; ?> >22</option>
<option value="23" <?php if($day_end == 23) echo 'selected="selected"'; ?> >23</option>
<option value="24" <?php if($day_end == 24) echo 'selected="selected"'; ?> >24</option>
<option value="25" <?php if($day_end == 25) echo 'selected="selected"'; ?> >25</option>
<option value="26" <?php if($day_end == 26) echo 'selected="selected"'; ?> >26</option>
<option value="27" <?php if($day_end == 27) echo 'selected="selected"'; ?> >27</option>
<option value="28" <?php if($day_end == 28) echo 'selected="selected"'; ?> >28</option>
<option value="29" <?php if($day_end == 29) echo 'selected="selected"'; ?> >29</option>
<option value="30" <?php if($day_end == 30) echo 'selected="selected"'; ?> >30</option>
<option value="31" <?php if($day_end == 31) echo 'selected="selected"'; ?> >31</option>
</select>
/
<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>
<option value="4" <?php if($month_end == 4) echo 'selected="selected"'; ?> >04</option>
<option value="5" <?php if($month_end == 5) echo 'selected="selected"'; ?> >05</option>
<option value="6" <?php if($month_end == 6) echo 'selected="selected"'; ?> >06</option>
<option value="7" <?php if($month_end == 7) echo 'selected="selected"'; ?> >07</option>
<option value="8" <?php if($month_end == 8) echo 'selected="selected"'; ?> >08</option>
<option value="9" <?php if($month_end == 9) echo 'selected="selected"'; ?> >09</option>
<option value="10" <?php if($month_end == 10) echo 'selected="selected"'; ?> >10</option>
<option value="11" <?php if($month_end == 11) echo 'selected="selected"'; ?> >11</option>
<option value="12" <?php if($month_end == 12) echo 'selected="selected"'; ?> >12</option>
</select>
/
<select name="year_end" <?php echo $end_year_disabled; ?>>
<?php
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>
<br /> <br />
<?php echo get_lang('SessionVisibility') ?> <br />
<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>
</div>
</div>
<div class="control-group">
<div class="controls">
<button class="save" type="submit" value="<?php echo get_lang('ModifyThisSession') ?>"><?php echo get_lang('ModifyThisSession') ?></button>
</div>
</div>
</fieldset>
</form>
<script type="text/javascript">
<?php if($year_start=="0000") echo "setDisable(document.form.nolimit);\r\n"; ?>
function setDisable(select){
document.form.day_start.disabled = (select.checked) ? true : false;
document.form.month_start.disabled = (select.checked) ? true : false;
document.form.year_start.disabled = (select.checked) ? true : false;
document.form.day_end.disabled = (select.checked) ? true : false;
document.form.month_end.disabled = (select.checked) ? true : false;
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();

@ -86,7 +86,7 @@ $extra_params['rowList'] = array(10, 20 ,30);
//With this function we can add actions to the jgrid (edit, delete, etc)
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
return \'<a href="session_edit.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
return \'<a href="session_add.php?page=resume_session.php&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a href="add_users_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('user_subscribe_session.png',get_lang('SubscribeUsersToSession'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a href="add_courses_to_session.php?page=session_list.php&id_session=\'+options.rowId+\'">'.Display::return_icon('courses_to_session.png',get_lang('SubscribeCoursesToSession'),'',ICON_SIZE_SMALL).'</a>'.
'&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="session_list.php?action=copy&idChecked=\'+options.rowId+\'">'.Display::return_icon('copy.png',get_lang('Copy'),'',ICON_SIZE_SMALL).'</a>'.

@ -11,9 +11,26 @@ api_protect_admin_script();
$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : null;
switch ($action) {
case 'update_changeable_setting':
$url_id = api_get_current_access_url_id();
case 'user_exists':
$user_info = api_get_user_info($_REQUEST['id']);
if (empty($user_info)) {
echo 0;
} else {
echo 1;
}
break;
case 'find_coaches':
$coaches = SessionManager::get_coaches_by_keyword($_REQUEST['tag']);
$json_coaches = array();
if (!empty($coaches)) {
foreach ($coaches as $coach) {
$json_coaches[] = array('key' => $coach['user_id'], 'value' => api_get_person_name($coach['firstname'], $coach['lastname']));
}
}
echo json_encode($json_coaches);
break;
case 'update_changeable_setting':
$url_id = api_get_current_access_url_id();
if (api_is_global_platform_admin() && $url_id == 1) {
if (isset($_GET['id']) && !empty($_GET['id'])) {
$params = array('variable = ? ' => array($_GET['id']));

@ -1159,7 +1159,7 @@ class Database {
$params = array_keys($filtred_attributes); //@todo check if the field exists in the table we should use a describe of that table
$values = array_values($filtred_attributes);
if (!empty($params) && !empty($values)) {
$sql = 'INSERT INTO '.$table_name.' ('.implode(',',$params).') VALUES ('.implode(',',$values).')';
$sql = 'INSERT INTO '.$table_name.' ('.implode(', ',$params).') VALUES ('.implode(', ',$values).')';
$result = self::query($sql);
if ($show_query) {
var_dump($sql);

@ -22,24 +22,6 @@ class SessionManager {
private function __construct() {
}
public static function get_session_info($session_id) {
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$sql = 'SELECT name, nbr_courses, nbr_users, nbr_classes,
DATE_FORMAT(date_start,"%d-%m-%Y") as date_start,
DATE_FORMAT(date_end,"%d-%m-%Y") as date_end, lastname, firstname, username, session_admin_id,
nb_days_access_before_beginning,
nb_days_access_after_end,
session_category_id,
visibility
FROM '.$tbl_session.' LEFT JOIN '.$tbl_user.' ON id_coach = user_id
WHERE '.$tbl_session.'.id='.$session_id;
$rs = Database::query($sql);
$session = Database::store_result($rs);
return $session[0];
}
/**
* Fetches a session from the database
* @param int Session ID
@ -54,6 +36,72 @@ class SessionManager {
return Database::fetch_array($r,'ASSOC');
}
public static function add($params) {
global $_configuration;
//Check portal limits
$access_url_id = 1;
if (api_get_multiple_access_url()) {
$access_url_id = api_get_current_access_url_id();
}
if (is_array($_configuration[$access_url_id]) && isset($_configuration[$access_url_id]['hosting_limit_sessions']) && $_configuration[$access_url_id]['hosting_limit_sessions'] > 0) {
$num = self::count_sessions();
if ($num >= $_configuration[$access_url_id]['hosting_limit_sessions']) {
return get_lang('PortalSessionsLimitReached');
}
}
$params = self::clean_parameters($params);
$session_id = Database::insert(Database::get_main_table(TABLE_MAIN_SESSION), $params);
if (!empty($session_id)) {
/*
Sends a message to the user_id = 1
$user_info = api_get_user_info(1);
$complete_name = $user_info['firstname'].' '.$user_info['lastname'];
$subject = api_get_setting('siteName').' - '.get_lang('ANewSessionWasCreated');
$message = get_lang('ANewSessionWasCreated')." <br /> ".get_lang('NameOfTheSession').' : '.$name;
api_mail_html($complete_name, $user_info['email'], $subject, $message);
*
*/
//Adding to the correct URL
$access_url_id = api_get_current_access_url_id();
UrlManager::add_session_to_url($session_id, $access_url_id);
// add event to system log
$user_id = api_get_user_id();
event_system(LOG_SESSION_CREATE, LOG_SESSION_ID, $session_id, api_get_utc_datetime(), $user_id);
}
return $session_id;
}
public static function update($params) {
$id = $params['id'];
if (empty($id)) {
return false;
}
unset($params['id']);
$params = self::clean_parameters($params);
$affected = Database::update(Database::get_main_table(TABLE_MAIN_SESSION), $params, array('id = ?'=>$id));
return $affected;
}
public function clean_parameters($params) {
//Convert dates
$params['display_start_date'] = api_get_utc_datetime($params['display_start_date'], true);
$params['display_end_date'] = api_get_utc_datetime($params['display_end_date'], true);
$params['access_start_date'] = api_get_utc_datetime($params['access_start_date'], true);
$params['access_end_date'] = api_get_utc_datetime($params['access_end_date'], true);
$params['coach_access_start_date'] = api_get_utc_datetime($params['coach_access_start_date'], true);
$params['coach_access_end_date'] = api_get_utc_datetime($params['coach_access_end_date'], true);
$params['id_coach'] = is_array($params['id_coach']) ? $params['id_coach'][0] : $params['id_coach'];
unset($params['submit']);
return $params;
}
/**
* Create a session
* @author Carlos Vargas from existing code
@ -822,8 +870,6 @@ class SessionManager {
Database::query("UPDATE $tbl_session_rel_course SET nbr_users=nbr_users-$nbr_affected_rows WHERE id_session='$session_id' AND course_code='".$course_code."'");
}
}
/** Subscribes courses to the given session and optionally (default) unsubscribes previous users
* @author Carlos Vargas from existing code
@ -2099,5 +2145,39 @@ class SessionManager {
$result = Database::query($sql);
$result = Database::store_result($result,'ASSOC');
return $result[0];
}
}
static function get_coaches_by_keyword($tag) {
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$order_clause = api_sort_by_first_name() ? ' ORDER BY firstname, lastname, username' : ' ORDER BY lastname, firstname, username';
$select ="SELECT user.user_id, lastname, firstname, username ";
$sql = " $select FROM $tbl_user user WHERE status='1'";
$tag = Database::escape_string($tag);
$where_condition = array();
if (!empty($tag)) {
$condition = ' LIKE "%'.$tag.'%"';
$where_condition = array( "firstname $condition",
"lastname $condition",
"username $condition"
);
$where_condition = ' AND ('.implode(' OR ', $where_condition).') ';
}
if (api_is_multiple_url_enabled()) {
$tbl_user_rel_access_url= 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.' FROM '.$tbl_user.' user
INNER JOIN '.$tbl_user_rel_access_url.' url_user ON (url_user.user_id=user.user_id)
WHERE access_url_id = '.$access_url_id.' AND status = 1';
}
}
$sql .= $where_condition.$order_clause;
$result = Database::query($sql);
return Database::store_result($result, 'ASSOC');
}
}
Loading…
Cancel
Save