diff --git a/main/exercise/showinframes.php b/main/exercise/showinframes.php index c137ab1dd9..23784e5164 100755 --- a/main/exercise/showinframes.php +++ b/main/exercise/showinframes.php @@ -74,19 +74,38 @@ if ($title == '') { $title = basename($my_file); } $nameTools = $title; -$htmlHeadXtra[] = /** @lang HTML */<< + function setHeight() + { + var iframe = document.getElementById('hotpotatoe'); + iframe.height = 800; + var maxheight = $(iframe.contentDocument.body).outerHeight(true); + iframe.height = maxheight + $(iframe.contentDocument.body).children().each(function() { + // If this elements height is bigger than the biggestHeight + var tempheight = $(this)["0"].offsetHeight + $(this)["0"].offsetTop; + if (tempheight > maxheight) { + // Set the maxheight to this Height + maxheight = tempheight; + } + }); + iframe.height = maxheight; + } + $(document).on('ready', function () { var iframe = document.getElementById('hotpotatoe'); - iframe.onload = function () { - this.height = $(this.contentDocument.body).outerHeight(true) + // this.height = $(this.contentDocument.body).outerHeight(true) + setTimeout(function(){ + setHeight(); + }, 1750); }; }); HTML; -$interbreadcrumb[] = ["url" => "./exercise.php", "name" => get_lang('Exercises')]; +$interbreadcrumb[] = ["url" => './exercise.php?'.api_get_cidreq(), 'name' => get_lang('Exercises')]; if ($origin == 'learnpath') { Display::display_reduced_header($nameTools, "Exercise"); } else { diff --git a/main/extra/userInfo.php b/main/extra/userInfo.php new file mode 100644 index 0000000000..e6faa21a6b --- /dev/null +++ b/main/extra/userInfo.php @@ -0,0 +1,621 @@ + +function show_image(image,width,height) { + width = parseInt(width) + 20; + height = parseInt(height) + 20; + window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\'); +} + +'; + +$editMainUserInfo = Security::remove_XSS($_REQUEST['editMainUserInfo']); +$uInfo = $editMainUserInfo; +$this_section = SECTION_COURSES; + +$nameTools = get_lang('Users'); +api_protect_course_script(true); +$tool_info = api_get_tool_information_by_name(TOOL_USER); + +if (api_is_anonymous()) { + api_not_allowed(true); +} + +//prepare variables used in userInfoLib.php functions +$TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); +$TBL_USERINFO_CONTENT = Database :: get_course_table(userinfo_content); + +if ($tool_info['visibility'] == 1 ) { + $interbreadcrumb[] = array ('url' => 'user.php', 'name' => get_lang('Users')); +} + +if ($origin != 'learnpath') { //so we are not in learnpath tool + Display :: display_header($nameTools, "User"); + $origin = Security::remove_XSS($_GET['origin']); +} else { + ?> '; + if($origin=='users'){ + echo ''.Display::return_icon('back.png',get_lang('BackUser'),'',ICON_SIZE_MEDIUM).''; + } + else{ + echo ''.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).''; + } + + if (!is_numeric($_GET['editMainUserInfo'])) { + if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') { + echo ''.Display::return_icon('edit.png',get_lang('EditUser'),'',ICON_SIZE_MEDIUM).get_lang('EditUser').''; + } + } else { + if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') { + echo ''.Display::return_icon('user.png',get_lang('ViewUser'),'',ICON_SIZE_MEDIUM).get_lang('ViewUser').''; + } + } + echo ''.Display::return_icon('stats.png',get_lang('UserStatistics'),'',ICON_SIZE_MEDIUM).get_lang('UserStatistics').''; + echo ''; +} else { + if ($tool_info['visibility'] == 1 ) { + echo '
'; + if($origin=='users'){ + echo ''.Display::return_icon('back.png',get_lang('BackUser'),'',ICON_SIZE_MEDIUM).''; + } + else{ + echo ''.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).''; + } + echo '
'; + } +} + +// get information about user id viewed +$user_info_viewed = api_get_user_info($userIdViewed); +$is_session_course_coach = UserManager::is_session_course_coach($userIdViewed, $_course['sysCode'], $current_session_id); + +if ($displayMode == "viewDefEdit") { + /* CATEGORIES DEFINITIONS : EDIT */ + + $catToEdit = get_cat_def($_GET['editDef']); + $edit_heading_form = new FormValidator('edit_heading_form'); + $edit_heading_form->addElement('hidden', 'id'); + $edit_heading_form->add_textfield('title', get_lang('Title')); + $edit_heading_form->addElement('textarea', 'comment', get_lang('Comment'), array ('cols' => 60, 'rows' => 4)); + $possible_line_nrs[1] = '1 '.get_lang('Line'); + $possible_line_nrs[3] = '3 '.get_lang('Lines'); + $possible_line_nrs[5] = '5 '.get_lang('Lines'); + $possible_line_nrs[10] = '10 '.get_lang('Lines'); + $possible_line_nrs[15] = '15 '.get_lang('Lines'); + $edit_heading_form->addElement('select', 'nbline', get_lang('LineNumber'), $possible_line_nrs); + $edit_heading_form->addElement('submit', 'submitDef', get_lang('Ok')); + $edit_heading_form->setDefaults($catToEdit); + $edit_heading_form->display(); + +} elseif ($displayMode == "viewDefList") { + /*CATEGORIES DEFINITIONS : LIST */ + + $catList = get_cat_def_list(); + + if ($catList) { + foreach ($catList as $thisCat) { + // displays Title and comments + echo "

", "".htmlize($thisCat['title'])."
\n", "".htmlize($thisCat['comment'])."\n", "

"; + + // displays lines + echo "
\n", "\n"; + + for ($i = 1; $i <= $thisCat['nbline']; $i ++) { + echo "
__________________________________________\n"; + } + echo "
\n", "
\n"; + + // displays commands + echo "", "\"".get_lang('Remove')."\"", "", "", "\"".get_lang('Edit')."\"", "", "", "\"".get_lang('MoveUp')."\"", "", "", "\"".get_lang('MoveDown')."\"", "\n"; + } // end for each + } // end if ($catList) + + echo "
\n", + "
", + "", + "
\n", + "
\n"; +} +elseif ($displayMode == "viewContentEdit") { + /* CATEGORIES CONTENTS : EDIT */ + + $catToEdit = get_cat_content($userIdViewed, $_GET['editContent']); + $content_heading_form = new FormValidator('content_heading_form'); + $content_heading_form->addElement('hidden', 'cntId'); + $content_heading_form->addElement('hidden', 'catId'); + $content_heading_form->addElement('hidden', 'uInfo'); + $content_heading_form->addElement('static', null, $catToEdit['title'], htmlize($catToEdit['comment'])); + if ($catToEdit['nbline'] == 1) { + $content_heading_form->addElement('text', 'content', null, array ('size' => 80)); + } else { + $content_heading_form->addElement('textarea', 'content', null, array ('cols' => 60, 'rows' => $catToEdit['nbline'])); + } + $content_heading_form->addElement('submit', 'submitContent', get_lang('Ok')); + $defaults = $catToEdit; + $defaults['cntId'] = $catToEdit['contentId']; + $defaults['uInfo'] = $userIdViewed; + $content_heading_form->setDefaults($defaults); + $content_heading_form->display(); +} elseif ($displayMode == "viewMainInfoEdit") { + + /* CATEGORIES MAIN INFO : EDIT */ + +// $mainUserInfo = get_main_user_info($userIdViewed, $courseCode); + $mainUserInfo = api_get_user_info($userIdViewed); + if ($mainUserInfo) { + ($mainUserInfo['status'] == COURSEMANAGER) ? $courseAdminChecked = "checked" : $courseAdminChecked = ""; + + if ($current_session_id) { +// ($is_session_course_coach)? $tutorChecked = "checked" : $tutorChecked = ""; + } else { +// ($mainUserInfo['tutor_id'] == 1) ? $tutorChecked = "checked" : $tutorChecked = ""; + } + + $image_array=UserManager::get_user_picture_path_by_id($userIdViewed,'web',false,true); + // get the path,width and height from original picture + $big_image = $image_array['dir'].'big_'.$image_array['file']; + $big_image_size = api_getimagesize($big_image); + $big_image_width= $big_image_size['width']; + $big_image_height= $big_image_size['height']; + $url_big_image = $big_image.'?rnd='.time(); + + if ($image_array['file']=='unknown.jpg') { + echo ''; + } else { + echo ''; + } + + echo "
\n", + "\n", + "", + "\n", + "\n", + "\n"; + if ($current_session_id) { + if ($user_info_viewed['status'] == COURSEMANAGER) { + //echo "\n"; + } + } else { + if ($user_info_viewed['status'] == STUDENT) { + //echo "\n"; + } else { + //echo "\n"; + } + } + echo "\n", + "", + "\n", + //"", + + "" ; +$course_id = $_course['real_id']; +//$course_id = $c_id; +//récupérer horaire de l'élève + ?> + + + +

'; + + if (!($is_courseAdmin && $_user['user_id'] == $userIdViewed)) { + if ($current_session_id) { + if ($user_info_viewed['status'] == COURSEMANAGER) { + // echo ""; + } + } else { + if ($user_info_viewed['status'] == STUDENT) { + // echo ""; + } else { + // echo "\n"; + } + } + } else { + echo "\n"; + + + } + + + echo "\n", "", "
", get_lang('Name'), "", get_lang('Horaire'), "", get_lang('Tutor'), "", get_lang('CourseAssistant'), "", get_lang('CourseManager'), "
", htmlize(api_get_person_name($mainUserInfo['firstName'], $mainUserInfo['lastName'])), "", $mainUserInfo['official_code'], "" . ' ' . Display::return_icon('synthese_view.gif',get_lang('TheTutorOnlyCanKeepTrackOfStudentsRegisteredInTheCourse')),$checked,"" . ' ' . Display::return_icon('synthese_view.gif',get_lang('TheTeacherCanQualifyEvaluateAndKeepTrackOfAllStudentsEnrolledInTheCourse')),$checked,"", get_lang('CourseManager'), "
", "
\n"; + + if (api_get_setting('show_email_addresses') == 'true') { + echo "

".Display :: encrypted_mailto_link($mainUserInfo['email'], $mainUserInfo['email'])."

"; + } + + if (api_get_setting('extended_profile') == 'true') { + if (!empty($mainUserInfo['competences'])) + echo '
'.get_lang('MyCompetences').'
'.$mainUserInfo['competences'].'
'; + if (!empty($mainUserInfo['diplomas'])) + echo '
'.get_lang('MyDiplomas').'
'.$mainUserInfo['diplomas'].'
'; + if (!empty($mainUserInfo['teach'])) + echo '
'.get_lang('MyTeach').'
'.$mainUserInfo['teach'].'
'; + if (!empty($mainUserInfo['openarea'])) + echo '
'.get_lang('MyPersonalOpenArea').'
'.$mainUserInfo['openarea'].'
'; + if (!empty($mainUserInfo['competences'])) + echo '
'.get_lang('MyProductions').'
'.UserManager::build_production_list($mainUserInfo['user_id']).'
'; + } + } else { + Display :: display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession')); + } +} elseif ($displayMode == "viewContentList") { + // default display + $virtual_course_code = $_GET["virtual_course"]; + if (isset ($virtual_course_code)) { + $courseCode = $virtual_course_code; + //not supported yet: editing users of virtual courses + $allowedToEditDef = false; + } + +// $mainUserInfo = get_main_user_info($userIdViewed, $courseCode); + $mainUserInfo = api_get_user_info($userIdViewed); + if ($mainUserInfo) { + $image_array=UserManager::get_user_picture_path_by_id($userIdViewed,'web',false,true); + // get the path,width and height from original picture + $big_image = $image_array['dir'].'big_'.$image_array['file']; + $big_image_size = api_getimagesize($big_image); + $big_image_width= $big_image_size['width']; + $big_image_height= $big_image_size['height']; + $url_big_image = $big_image.'?rnd='.time(); + + if ($image_array['file']=='unknown.jpg') { + echo ''; + } else { + echo ''; + } + + // is the user online? + $online =''; + if (user_is_online($userIdViewed)) { + $online = Display::return_icon('online.gif', get_lang('OnLine'),array('style'=>'with="8"; height="8"')); + } + + //DISPLAY TABLE HEADING + if ($origin == 'learnpath') { $allowedToEditDef=false; $is_allowedToTrack=false; } + + //"",get_lang('Tutor'),"\n", + echo "", + + "\n", + "\n", + "\n", + "\n"; + + if ($current_session_id) { + if ($user_info_viewed['status'] == COURSEMANAGER) { + // echo "\n"; + } + } else { + if ($user_info_viewed['status'] == STUDENT) { + // echo "\n"; + } else { + // echo "\n"; + } + } + //echo ($allowedToEditDef && api_get_setting('allow_user_course_subscription_by_course_admin') == 'true'?"\n":""); + //echo ($is_allowedToTrack?"\n":""); + + echo "\n", + "\n", + + "\n", + // "", + ""; + //DISPLAY TABLE CONTENT + + if ($current_session_id) { + if ($user_info_viewed['status'] == COURSEMANAGER) { +// if ($is_session_course_coach) { +// echo "\n"; +// } else { + echo "\n"; +// } + } + } else { + if ($user_info_viewed['status'] == STUDENT) { + // if ($mainUserInfo['tutor_id'] == 1) { + // echo "\n"; + // } else { + echo "\n"; + // } + } else { + // if ($mainUserInfo['status'] == 1) { + // echo ""; + // } else { + echo "\n"; + // } + } + } + + if ($allowedToEditDef && api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') { + //echo ""; + } + if ($is_allowedToTrack) { + //echo ""; + } + echo "
".get_lang('Name')."".get_lang('Description')."", get_lang('OfficialCode'), "".get_lang('Tutor')."".get_lang('Tutor')."".get_lang('CourseManager')."".get_lang('Edit')."".get_lang('Tracking')."
".$online.' '.htmlize(api_get_person_name($mainUserInfo['firstName'], $mainUserInfo['lastName']))."".htmlize($mainUserInfo['role'])."", $mainUserInfo['official_code'], "",get_lang('Tutor')," - ",get_lang('Tutor')," - ",get_lang('CourseManager')," - "; + //echo "\"\""; + //echo ""; + //echo "\"".get_lang('Tracking').""; + //echo "
"; + + if (api_get_setting("show_email_addresses") == "true") { + echo "

". Display::encrypted_mailto_link($mainUserInfo['email'],$mainUserInfo['email']). "

"; + } + + if (api_get_setting('extended_profile') == 'true') { + if (!empty($mainUserInfo['competences'])) + echo '
'.get_lang('MyCompetences').'
'.$mainUserInfo['competences'].'
'; + if (!empty($mainUserInfo['diplomas'])) + echo '
'.get_lang('MyDiplomas').'
'.$mainUserInfo['diplomas'].'
'; + if (!empty($mainUserInfo['teach'])) + echo '
'.get_lang('MyTeach').'
'.$mainUserInfo['teach'].'
'; + if (!empty($mainUserInfo['openarea'])) + echo '
'.get_lang('MyPersonalOpenArea').'
'.$mainUserInfo['openarea'].'
'; + if (!empty($mainUserInfo['competences'])) + echo '
'.get_lang('MyProductions').'
'.UserManager::build_production_list($mainUserInfo['user_id']).'
'; + } + } else { + Display :: display_normal_message(get_lang('ThisStudentIsSubscribeThroughASession')); + } + + if (api_get_setting('allow_user_headings') == 'true' && $allowedToEditDef) // only course administrators see this line + { + echo "
", + "
", + get_lang('CourseAdministratorOnly')," : ", + "", + "
", + "
", + "
\n"; + } + + $catList = get_course_user_info($userIdViewed); + + if ($catList) + { + foreach ($catList as $thisCat) + { + // Category title + + echo "

",$thisCat['title'],"

\n"; + + // Category content + + echo "
\n"; + + if ($thisCat['content']) + { + echo htmlize($thisCat['content'])."\n"; + } + else + { + echo "...."; + } + + // Edit command + + if ($allowedToEditContent) + { + echo "

\n", + "", + "\"edit\"", + "\n"; + } + + echo "
\n"; + } + } +} + +// Back button for each display mode (bottom) +//echo "\n"; +/* FOOTER */ +Display :: display_footer(); diff --git a/main/extra/userInfoLib.php b/main/extra/userInfoLib.php new file mode 100644 index 0000000000..2d4aa58f36 --- /dev/null +++ b/main/extra/userInfoLib.php @@ -0,0 +1,686 @@ + + * @author - Christophe Gesch� + * @param - string $title - category title + * @param - string $comment - title comment + * @param - int$nbline - lines number for the field the user will fill. + * @return - bollean true if succeed, else bolean false + */ + +function create_cat_def($title="", $comment="", $nbline="5") +{ + global $TBL_USERINFO_DEF; //taken from userInfo.php + + $title = Database::escape_string(trim($title)); + $comment = Database::escape_string(trim($comment)); + $nbline = strval(intval($nbline)); + + if ( 0 == (int) $nbline || empty($title)) + { + return false; + } + + $sql = "SELECT MAX(rank) as maxRank FROM ".$TBL_USERINFO_DEF; + $result = Database::query($sql); + if ($result) $maxRank = Database::fetch_array($result); + + $maxRank = $maxRank['maxRank']; + + $thisRank = $maxRank + 1; + + $sql = "INSERT INTO $TBL_USERINFO_DEF SET + title = '$title', + comment = '$comment', + line_count = '$nbline', + rank = '$thisRank'"; + + Database::query($sql); + + return true; +} + +/** + * modify the definition of a user information category + * + * @author - Hugues peeters + * @author - Christophe Gesch� + * @param - int $id - id of the category + * @param - string $title - category title + * @param - string $comment - title comment + * @param - int$nbline - lines number for the field the user will fill. + * @return - boolean true if succeed, else otherwise + */ + +function edit_cat_def($id, $title, $comment, $nbline) +{ + global $TBL_USERINFO_DEF; + + if ( 0 == $nbline || 0 == $id ) + { + return false; + } + $id = strval(intval($id)); //make sure id is integer + $title = Database::escape_string(trim($title)); + $comment = Database::escape_string(trim($comment)); + $nbline = strval(intval($nbline)); + + $sql = "UPDATE ".$TBL_USERINFO_DEF." SET + title = '$title', + comment = '$comment', + line_count = '$nbline' + WHERE id = '$id'"; + Database::query($sql); + + return true; +} + +/** + * remove a category from the category list + * + * @author - Hugues peeters + * @author - Christophe Gesche + * + * @param - int $id - id of the category + * or "ALL" for all category + * @param - boolean $force - FALSE (default) : prevents removal if users have + * already fill this category + * TRUE : bypass user content existence check + * @param - int $nbline - lines number for the field the user will fill. + * @return - bollean - TRUE if succeed, ELSE otherwise + */ + +function remove_cat_def($id, $force = false) +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + $TBL_USERINFO_CONTENT = Database :: get_course_table(userinfo_content); + + $id = strval(intval($id)); + + if ( (0 == (int) $id || $id == "ALL") || ! is_bool($force)) + { + return false; + } + $sqlCondition = " WHERE id = '$id'"; + if (!$force) + { + $sql = "SELECT * FROM $TBL_USERINFO_CONTENT $sqlCondition"; + $result = Database::query($sql); + + if ( Database::num_rows($result) > 0) + { + return false; + } + } + $sql = "DELETE FROM $TBL_USERINFO_DEF $sqlCondition"; + Database::query($sql); +} + +/** + * move a category in the category list + * + * @author - Hugues peeters + * @author - Christophe Gesch� + * + * @param - int $id - id of the category + * @param - direction "up" or "down" : + * "up" decrease the rank of gived $id by switching rank with the just lower + * "down" increase the rank of gived $id by switching rank with the just upper + * + * @return - boolean true if succeed, else bolean false + */ + +function move_cat_rank($id, $direction) // up & down. +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + $id = strval(intval($id)); + + if ( 0 == (int) $id || ! ($direction == "up" || $direction == "down") ) + { + return false; + } + + $sql = "SELECT rank FROM $TBL_USERINFO_DEF WHERE id = '$id'"; + $result = Database::query($sql); + + if (Database::num_rows($result) < 1) + { + return false; + } + + $cat = Database::fetch_array($result); + $rank = (int) $cat['rank']; + return move_cat_rank_by_rank($rank, $direction); +} + +/** + * move a category in the category list + * + * @author - Hugues peeters + * @author - Christophe Gesche + * + * @param - int $rank - actual rank of the category + * @param - direction "up" or "down" : + * "up" decrease the rank of gived $rank by switching rank with the just lower + * "down" increase the rank of gived $rank by switching rank with the just upper + * + * @return - boolean true if succeed, else bolean false + */ + +function move_cat_rank_by_rank($rank, $direction) // up & down. +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + + if ( 0 == (int) $rank || ! ($direction == "up" || $direction == "down") ) + { + return false; + } + + if ($direction == "down") // thus increase rank ... + { + $sort = "ASC"; + $compOp = ">="; + } + else // thus decrease rank ... + { + $sort = "DESC"; + $compOp = "<="; + } + + // this request find the 2 line to be switched (on rank value) + $sql = "SELECT id, rank FROM ".$TBL_USERINFO_DEF." WHERE rank $compOp $rank + ORDER BY rank $sort LIMIT 2"; + + $result = Database::query($sql); + + if (Database::num_rows($result) < 2) + { + return false; + } + + $thisCat = Database::fetch_array($result); + $nextCat = Database::fetch_array($result); + + $sql1 = "UPDATE ".$TBL_USERINFO_DEF." SET rank ='".$nextCat['rank']. + "' WHERE id = '".$thisCat['id']."'"; + $sql2 = "UPDATE ".$TBL_USERINFO_DEF." SET rank ='".$thisCat['rank']. + "' WHERE id = '".$nextCat['id']."'"; + + Database::query($sql1); + Database::query($sql2); + + return true; +} + + +/** + * @author Hugues Peeters - peeters@ipm.ucl.ac.be + * @param int $user_id + * @param string $course_code + * @param array $properties - should contain 'role', 'status', 'tutor_id' + * @return boolean true if succeed false otherwise + */ + +function update_user_course_properties($user_id, $course_code, $properties, $horaire_name, $course_id) +{ + global $tbl_coursUser,$_user; + $sqlChangeStatus = ""; + $user_id = strval(intval($user_id));//filter integer + $course_code = Database::escape_string($course_code); + if ($user_id != $_user['user_id']) + { + $sqlChangeStatus = "status = '".Database::escape_string($properties['status'])."',"; + } + + //feature deprecated tutor_id = '".Database::escape_string($properties['tutor'])."' + $sql = "UPDATE $tbl_coursUser + SET ".$sqlChangeStatus." + is_tutor = '".Database::escape_string($properties['tutor'])."' + WHERE user_id = '".$user_id."' + AND c_id = '".$course_id."'"; + $result = Database::query($sql); + //update official-code: Horaire + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $sql2 = "UPDATE $table_user + SET official_code = '".$horaire_name."' + WHERE user_id = '".$user_id."' + "; + + $result2 = api_sql_query($sql2,__FILE__,__LINE__); + +//on récupère l'horaire + +$tbl_personal_agenda = Database :: get_main_table(TABLE_PERSONAL_AGENDA); +$TABLECALDATES = Database :: get_course_table(cal_dates); +$jour= 0 ; + $sql3 = "SELECT date FROM $TABLECALDATES + WHERE horaire_name = '".$horaire_name."' AND status = 'C' + AND c_id = '".$course_id."' + ORDER BY date + "; + + $result3 = api_sql_query($sql3,__FILE__,__LINE__); + + if (Database::num_rows($result3) == '0') + { + return false; + } + //on efface ce qui est déjà inscrit + +$sql4 = "DELETE FROM ".$tbl_personal_agenda." + WHERE user = '".$user_id."' + AND text = 'Pour le calendrier, ne pas effacer' + + "; +api_sql_query($sql4,__FILE__,__LINE__); + +$sql = "DELETE FROM ".$tbl_personal_agenda." + WHERE user = '".$user_id."' AND title = 'Examen*' + "; +api_sql_query($sql,__FILE__,__LINE__); + //à chaque date dans l'horaire + while($res3 = Database::fetch_array($result3)) { + $date=$res3['date']; + +//on incrémente les jours de cours +$date = api_get_utc_datetime($date); + +$jour= $jour+1; +//on réinsère le nouvel horaire +$sql = "INSERT ".$tbl_personal_agenda." (user,title,text,date) + VALUES ('".$user_id."','".$jour."','Pour le calendrier, ne pas effacer','".$date."') + "; + api_sql_query($sql,__FILE__,__LINE__); + + // pour les inscrire examens dans agenda + + $sql5 = "SELECT date FROM $TABLECALDATES + WHERE horaire_name = '".$horaire_name."' AND status = 'E' + AND c_id = '".$course_id."' + ORDER BY date + "; + + $result5 = api_sql_query($sql5,__FILE__,__LINE__); + + } + +//à chaque date dans l'horaire + while($res5 = Database::fetch_array($result5)) { + $date=$res5['date']; +$date = api_get_utc_datetime($date); + +//on réinsère le nouvel horaire +$sql7 = "INSERT ".$tbl_personal_agenda." (user,title,date) + VALUES ('".$user_id."','Examen*','".$date."') + "; + api_sql_query($sql7,__FILE__,__LINE__); + } + +// fin horaire + + ///// Francois Belisle Kezber + // The only calling location does not process a result, so there is no need to return a value + // Moreover, the Database:affectedrows() needs a parameter to work properly. + // The code used to crash here because of the Database::affected_rows() call + + /* + if (Database::affected_rows() > 0) + { + die('TRUE'); + return true; + } + else + { + die('FALSE'); + return false; + }*/ + +} + + + + + +/*---------------------------------------- + CATEGORIES CONTENT TREATMENT + --------------------------------------*/ + + + + + +/** + * fill a bloc for information category + * + * @author - Hugues peeters + * @author - Christophe Gesche + * @param - $definition_id, + * @param - $user_id, + * @param - $user_ip, + * @param - $content + * @return - boolean true if succeed, else bolean false + */ + +function fill_new_cat_content($definition_id, $user_id, $content="", $user_ip="") +{ + global $TBL_USERINFO_CONTENT; + + if (empty($user_ip)) + { + $user_ip = $_SERVER['REMOTE_ADDR']; + } + $definition_id = strval(intval($definition_id)); + $user_id = strval(intval($user_id)); + $content = Database::escape_string(trim($content)); + $user_ip = Database::escape_string(trim($user_ip)); + + if ( 0 == $definition_id || 0 == $user_id || $content == "") + { + // Here we should introduce an error handling system... + + return false; + } + + // Do not create if already exist + + $sql = "SELECT id FROM ".$TBL_USERINFO_CONTENT." + WHERE definition_id = '$definition_id' + AND user_id = '$user_id'"; + + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) + { + return false; + } + + $sql = "INSERT INTO ".$TBL_USERINFO_CONTENT." SET + content = '$content', + definition_id = '$definition_id', + user_id = '$user_id', + editor_ip = '$user_ip', + edition_time = now()"; + + Database::query($sql); + return true; +} + +/** + * Edit a bloc for information category + * + * @author - Hugues peeters + * @author - Christophe Gesche + * @param - $definition_id, + * @param - $user_id, + * @param - $user_ip, DEFAULT $REMOTE_ADDR + * @param - $content ; if empty call delete the bloc + * @return - boolean true if succeed, else bolean false + */ +function edit_cat_content($definition_id, $user_id, $content ="", $user_ip="") +{ + global $TBL_USERINFO_CONTENT; + $definition_id = strval(intval($definition_id)); + $user_id = strval(intval($user_id)); + $content = Database::escape_string(trim($content)); + if (empty($user_ip)) + { + $user_ip = $_SERVER['REMOTE_ADDR']; + } + $user_ip = Database::escape_string($user_ip); + + if (0 == $user_id || 0 == $definition_id) + { + return false; + } + + if ( $content == "") + { + return cleanout_cat_content($user_id, $definition_id); + } + + + $sql= "UPDATE ".$TBL_USERINFO_CONTENT." SET + content = '$content', + editor_ip = '$user_ip', + edition_time = now() + WHERE definition_id = '$definition_id' AND user_id = '$user_id'"; + + Database::query($sql); + + return true; +} + +/** + * clean the content of a bloc for information category + * + * @author - Hugues peeters + * @author - Christophe Gesche + * @param - $definition_id, + * @param - $user_id + * @return - boolean true if succeed, else bolean false + */ + +function cleanout_cat_content($user_id, $definition_id) +{ + global $TBL_USERINFO_CONTENT; + $user_id = strval(intval($user_id)); + $definition_id = strval(intval($definition_id)); + + if (0 == $user_id || 0 == $definition_id) + { + return false; + } + + $sql = "DELETE FROM ".$TBL_USERINFO_CONTENT." + WHERE user_id = '$user_id' AND definition_id = '$definition_id'"; + + Database::query($sql); + + return true; +} + + + +/*---------------------------------------- + SHOW USER INFORMATION TREATMENT + --------------------------------------*/ + +/** + * get the user info from the user id + * @author - Hugues Peeters + * @author - Christophe Gesche + * @param - int $user_id user id as stored in the Dokeos main db + * @return - array containg user info sort by categories rank + * each rank contains 'title', 'comment', 'content', 'cat_id' + */ + + +function get_course_user_info($user_id) +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + $TBL_USERINFO_CONTENT = Database :: get_course_table(userinfo_content); + + $sql = "SELECT cat.id catId, cat.title, + cat.comment , content.content + FROM ".$TBL_USERINFO_DEF." cat LEFT JOIN ".$TBL_USERINFO_CONTENT." content + ON cat.id = content.definition_id AND content.user_id = '$user_id' + ORDER BY cat.rank, content.id"; + + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) + { + while ($userInfo = Database::fetch_array($result, 'ASSOC')) + { + $userInfos[]=$userInfo; + } + + return $userInfos; + } + + return false; +} + + + +/** + * get the main user information + * @author - Hugues Peeters + * @author - Christophe Gesche + * @param - int $user_id user id as stored in the Dokeos main db + * @return - array containing user info as 'lastName', 'firstName' + * 'email', 'role' + */ + +function get_main_user_info($user_id, $courseCode) +{ + $user_id = strval(intval($user_id)); + $courseCode = Database::escape_string($courseCode); + if (0 == $user_id) + { + return false; + } + + + $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER); + $table_user = Database::get_main_table(TABLE_MAIN_USER); + $sql = "SELECT u.*, u.lastname lastName, u.firstname firstName, + u.email, u.picture_uri picture, + cu.status status, cu.is_tutor as tutor_id + FROM $table_user u, $table_course_user cu + WHERE u.user_id = cu.user_id AND cu.relation_type<>".COURSE_RELATION_TYPE_RRHH." + AND u.user_id = '$user_id' + AND cu.c_id = '$c_id'"; + + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) + { + $userInfo = Database::fetch_array($result, 'ASSOC'); + $userInfo['password']=''; + return $userInfo; + } + + return false; +} + + + + +/** + * get the user content of a categories plus the categories definition + * @author - Hugues Peeters + * @author - Christophe Gesche + * @param - int $userId - id of the user + * @param - int $catId - id of the categories + * @return - array containing 'catId', 'title', 'comment', + * 'nbline', 'contentId' and 'content' + */ + +function get_cat_content($userId, $catId) +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + $TBL_USERINFO_CONTENT = Database :: get_course_table(userinfo_content); + + $userId = strval(intval($userId)); + $catId = strval(intval($catId)); + $sql = "SELECT cat.id catId, cat.title, + cat.comment , cat.line_count, + content.id contentId, content.content + FROM ".$TBL_USERINFO_DEF." cat LEFT JOIN ".$TBL_USERINFO_CONTENT." content + ON cat.id = content.definition_id + AND content.user_id = '$userId' + WHERE cat.id = '$catId' "; + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) + { + $catContent = Database::fetch_array($result, 'ASSOC'); + $catContent['nbline'] = $catContent['line_count']; + return $catContent; + } + + return false; +} + + +/** + * get the definition of a category + * + * @author - Christophe Gesche + * @author - Hugues Peeters + * @param - int $catId - id of the categories + * @return - array containing 'id', 'title', 'comment', and 'nbline', + */ +function get_cat_def($catId) +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + + $catId = strval(intval($catId)); + $sql = "SELECT id, title, comment, line_count, rank FROM ".$TBL_USERINFO_DEF." WHERE id = '$catId'"; + + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) + { + $catDef = Database::fetch_array($result, 'ASSOC'); + $catDef['nbline'] = $catDef['line_count']; + return $catDef; + } + + return false; +} + + +/** + * get list of all this course categories + * + * @author - Christophe Gesche + * @author - Hugues Peeters + * @return - array containing a list of arrays. + * And each of these arrays contains + * 'catId', 'title', 'comment', and 'nbline', + */ +function get_cat_def_list() +{ + $TBL_USERINFO_DEF = Database :: get_course_table(userinfo_def); + + $sql = "SELECT id catId, title, comment , line_count + FROM ".$TBL_USERINFO_DEF." + ORDER BY rank"; + + $result = Database::query($sql); + + if (Database::num_rows($result) > 0) + { + while ($cat_def = Database::fetch_array($result, 'ASSOC')) + { + $cat_def_list[]=$cat_def; + } + + return $cat_def_list; + } + + return false; +} + +/** + * transform content in a html display + * @author - Hugues Peeters + * @param - string $string string to htmlize + * @ return - string htmlized + */ + +function htmlize($phrase) +{ + global $charset; + return nl2br(htmlspecialchars($phrase,ENT_QUOTES,$charset)); +} \ No newline at end of file diff --git a/main/user/user.php b/main/user/user.php index ebbe0ea0c9..cec77c295e 100755 --- a/main/user/user.php +++ b/main/user/user.php @@ -1026,6 +1026,14 @@ function modify_filter($user_id, $row, $data) $disabled = ''; } + $allow = api_get_configuration_value('extra'); + if ($allow) { + $result .= ''. + Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL). + ' '; + } + if ($data['user_status_in_course'] == STUDENT) { $result .= Display::url( $text,