/** * Function wizard individual assignment * @author Juan Carlos Raña <*****@*****.**> */ function auto_add_page_users($assignment_type) { global $assig_user_id, $session_id; //$assig_user_id is need to identify end reflinks $_clean['group_id'] = (int) $_SESSION['_gid']; if ($_clean['group_id'] == 0) { //extract course members if (!empty($session_id)) { $a_users_to_add = CourseManager::get_user_list_from_course_code($_SESSION['_course']['id'], $session_id); } else { $a_users_to_add = CourseManager::get_user_list_from_course_code($_SESSION['_course']['id'], 0); } } else { //extract group members $subscribed_users = GroupManager::get_subscribed_users($_clean['group_id']); $subscribed_tutors = GroupManager::get_subscribed_tutors($_clean['group_id']); $a_users_to_add_with_duplicates = array_merge($subscribed_users, $subscribed_tutors); //remove duplicates $a_users_to_add = $a_users_to_add_with_duplicates; //array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_encode($value);')); $a_users_to_add = array_unique($a_users_to_add); //array_walk($a_users_to_add, create_function('&$value,$key', '$value = json_decode($value, true);')); } //echo print_r($a_users_to_add); $all_students_pages = array(); //data about teacher $userinfo = api_get_user_info(api_get_user_id()); $name = $userinfo['complete_name_login_as']; if (api_get_user_id() != 0) { $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $photo = '<img src="' . $image_repository . $existing_image . '" alt="' . $name . '" width="40" height="50" align="top" title="' . $name . '" />'; } else { $photo = '<img src="' . api_get_path(WEB_CODE_PATH) . "img/unknown.jpg" . '" alt="' . $name . '" width="40" height="50" align="top" title="' . $name . '" />'; } //teacher assignment title $title_orig = $_POST['title']; //teacher assignment reflink $link2teacher = $_POST['title'] = $title_orig . "_uass" . api_get_user_id(); //first: teacher name, photo, and assignment description (original content) // $content_orig_A='<div align="center" style="background-color: #F5F8FB; border:double">'.$photo.'<br />'.api_get_person_name($userinfo['firstname'], $userinfo['lastname']).'<br />('.get_lang('Teacher').')</div><br/><div>'; $content_orig_A = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6"><table border="0"><tr><td style="font-size:24px">' . get_lang('AssignmentDesc') . '</td></tr><tr><td>' . $photo . '<br />' . Display::tag('span', $name) . '</td></tr></table></div>'; $content_orig_B = '<br/><div align="center" style="font-size:24px">' . get_lang('AssignmentDescription') . ': ' . $title_orig . '</div><br/>' . $_POST['content']; //Second: student list (names, photo and links to their works). //Third: Create Students work pages. foreach ($a_users_to_add as $user_id => $o_user_to_add) { if ($o_user_to_add['user_id'] != api_get_user_id()) { $assig_user_id = $o_user_to_add['user_id']; //identifies each page as created by the student, not by teacher $image_path = UserManager::get_user_picture_path_by_id($assig_user_id, 'web', false, true); $image_repository = $image_path['dir']; $existing_image = $image_path['file']; $username = api_htmlentities(sprintf(get_lang('LoginX'), $o_user_to_add['username'], ENT_QUOTES)); $name = api_get_person_name($o_user_to_add['firstname'], $o_user_to_add['lastname']) . " . " . $username; $photo = '<img src="' . $image_repository . $existing_image . '" alt="' . $name . '" width="40" height="50" align="bottom" title="' . $name . '" />'; $is_tutor_of_group = GroupManager::is_tutor_of_group($assig_user_id, $_clean['group_id']); //student is tutor $is_tutor_and_member = GroupManager::is_tutor_of_group($assig_user_id, $_clean['group_id']) && GroupManager::is_subscribed($assig_user_id, $_clean['group_id']); //student is tutor and member if ($is_tutor_and_member) { $status_in_group = get_lang('GroupTutorAndMember'); } else { if ($is_tutor_of_group) { $status_in_group = get_lang('GroupTutor'); } else { $status_in_group = " "; //get_lang('GroupStandardMember') } } if ($assignment_type == 1) { $_POST['title'] = $title_orig; $_POST['comment'] = get_lang('AssignmentFirstComToStudent'); $_POST['content'] = '<div align="center" style="background-color: #F5F8FB; border:solid; border-color: #E6E6E6"><table border="0"><tr><td style="font-size:24px">' . get_lang('AssignmentWork') . '</td></tr><tr><td>' . $photo . '<br />' . $name . '</td></tr></table></div>[[' . $link2teacher . ' | ' . get_lang('AssignmentLinktoTeacherPage') . ']] '; //If $content_orig_B is added here, the task written by the professor was copied to the page of each student. TODO: config options //AssignmentLinktoTeacherPage $all_students_pages[] = '<li>' . Display::tag('span', strtoupper($o_user_to_add['lastname']) . ', ' . $o_user_to_add['firstname'], array('title' => $username)) . ' [[' . $_POST['title'] . "_uass" . $assig_user_id . ' | ' . $photo . ']] ' . $status_in_group . '</li>'; //don't change this line without guaranteeing that users will be ordered by last names in the following format (surname, name) //$all_students_pages[] = '<li><table border="0"><tr><td width="200">'.api_get_person_name($o_user_to_add['lastname'], $o_user_to_add['firstname']).'</td><td>[['.$_POST['title']."_uass".$assig_user_id.' | '.$photo.']] '.$status_in_group.'</td></tr></table></li>'; $_POST['assignment'] = 2; } save_new_wiki(); } } //end foreach for each user foreach ($a_users_to_add as $user_id => $o_user_to_add) { if ($o_user_to_add['user_id'] == api_get_user_id()) { $assig_user_id = $o_user_to_add['user_id']; if ($assignment_type == 1) { $_POST['title'] = $title_orig; $_POST['comment'] = get_lang('AssignmentDesc'); sort($all_students_pages); $_POST['content'] = $content_orig_A . $content_orig_B . '<br/><div align="center" style="font-size:18px; background-color: #F5F8FB; border:solid; border-color:#E6E6E6">' . get_lang('AssignmentLinkstoStudentsPage') . '</div><br/><div style="background-color: #F5F8FB; border:solid; border-color:#E6E6E6"><ol>' . implode($all_students_pages) . '</ol></div><br/>'; $_POST['assignment'] = 1; } save_new_wiki(); } } //end foreach to teacher }
//saving a new wiki entry echo '<div style="overflow:hidden">'; if (isset($_POST['SaveWikiNew'])) { if (empty($_POST['title'])) { Display::display_error_message(get_lang("NoWikiPageTitle")); } elseif (strtotime(get_date_from_select('startdate_assig')) > strtotime(get_date_from_select('enddate_assig'))) { Display::display_error_message(get_lang("EndDateCannotBeBeforeTheStartDate")); } elseif (!double_post($_POST['wpost_id'])) { //double post } else { $_clean['assignment'] = Database::escape_string($_POST['assignment']); // for mode assignment if ($_clean['assignment'] == 1) { auto_add_page_users($_clean['assignment']); } else { $return_message = save_new_wiki(); if ($return_message == false) { Display::display_error_message(get_lang('NoWikiPageTitle'), false); } else { Display::display_confirmation_message($return_message, false); } } } } echo '</div>'; // check last version if ($_GET['view']) { $sql = 'SELECT * FROM ' . $tbl_wiki . ' WHERE c_id = ' . $course_id . ' AND id="' . Database::escape_string($_GET['view']) . '"'; //current view $result = Database::query($sql); $current_row = Database::fetch_array($result);