debugOn();
$xajax -> registerFunction ('search_coachs');
// setting the section (for the tabs)
$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';
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 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 .= ''.api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].')
';
}
}
$xajax_response -> addAssign('ajax_list_coachs','innerHTML', api_utf8_encode($return));
return $xajax_response;
}
$xajax -> processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = "
";
if (isset($_POST['formSent']) && $_POST['formSent']) {
$formSent = 1;
}
global $_configuration;
$defaultBeforeDays = isset($_configuration['session_days_before_coach_access']) ?
$_configuration['session_days_before_coach_access'] : 0;
$defaultAfterDays = isset($_configuration['session_days_after_coach_access'])
? $_configuration['session_days_after_coach_access'] : 0;
$nb_days_acess_before = $defaultBeforeDays;
$nb_days_acess_after = $defaultAfterDays;
$thisYear=date('Y');
$thisMonth=date('m');
$thisDay=date('d');
$dayList = array();
for ($i = 1; $i <= 31; $i++) {
$day = sprintf("%02d", $i);
$dayList[$day] = $day;
}
$monthList = array();
for ($i = 1; $i <= 12; $i++) {
$month = sprintf("%02d", $i);
$monthList[$month] = $month;
}
$yearList = array();
for ($i = $thisYear - 5; $i <= ($thisYear + 5); $i++) {
$yearList[$i] = $i;
}
$tool_name = get_lang('AddSession');
$urlAction = api_get_self();
$categoriesList = SessionManager::get_all_session_category();
$categoriesOptions = array(
'0' => get_lang('None')
);
if ($categoriesList != false) {
foreach ($categoriesList as $categoryItem) {
$categoriesOptions[$categoryItem['id']] = $categoryItem['name'];
}
}
function check_session_name($name) {
$session = SessionManager::get_session_by_name($name);
return empty($session) ? true : false;
}
$form = new FormValidator('add_session', 'post', $urlAction);
$form->addElement('header', $tool_name);
$form->addElement('text', 'name', get_lang('SessionName'), array(
'class' => 'span4',
'maxlength' => 50,
'value' => $formSent ? api_htmlentities($name,ENT_QUOTES,$charset) : ''
));
$form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
$form->addRule('name', get_lang('SessionNameAlreadyExists'), 'callback', 'check_session_name');
$sql = "SELECT COUNT(1) FROM $tbl_user WHERE status = 1";
$rs = Database::query($sql);
$countUsers = Database::result($rs, 0, 0);
if (intval($countUsers) < 50) {
$orderClause = "ORDER BY ";
$orderClause .= api_sort_by_first_name() ? "firstname, lastname, username" : "lastname, firstname, username";
$sql="SELECT user_id, lastname, firstname, username FROM $tbl_user "
. "WHERE status = '1' "
. $orderClause;
if (api_is_multiple_url_enabled()) {
$userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
$accessUrlId = api_get_current_access_url_id();
if ($accessUrlId != -1) {
$sql = "SELECT user.user_id, username, lastname, firstname FROM $tbl_user user "
. "INNER JOIN $userRelAccessUrlTable url_user ON (url_user.user_id = user.user_id) "
. "WHERE access_url_id = $accessUrlId AND status = 1 "
. $orderClause;
}
}
$result = Database::query($sql);
$coachesList = Database::store_result($result);
$coachesOptions = array();
foreach($coachesList as $coachItem){
$coachesOptions[$coachItem['username']] = api_get_person_name(
$coachItem['firstname'],
$coachItem['lastname']
).' ('.$coachItem['username'].')';
}
$form->addElement('select', 'coach_username', get_lang('CoachName'), $coachesOptions, array(
'id' => 'coach_username',
'class' => 'chzn-select',
'style' => 'width:370px;'
));
$form->addElement('advanced_settings', Display::return_icon('synthese_view.gif') . ' ' . get_lang('ActivityCoach'));
} else {
$form->addElement('text', 'coach_username', get_lang('CoachName'), array(
'class' => 'span4',
'maxlength' => 50,
'onkeyup' => "xajax_search_coachs(document.getElementById('coach_username').value)",
'id' => 'coach_username'
));
}
$form->addRule('coach_username', get_lang('ThisFieldIsRequired'), 'required');
$form->addHtml('