示例#1
0
 /**
  * @param FormValidator $form
  * @param int $group_id
  * @param array $to
  */
 public static function addGroupMultiSelect($form, $group_id, $to = array())
 {
     $group_users = GroupManager::get_subscribed_users($group_id);
     $array = self::buildSelectOptions(null, $group_users, $to);
     $result = array();
     foreach ($array as $content) {
         $result[$content['value']] = $content['content'];
     }
     $form->addElement('advmultiselect', 'users', get_lang('Users'), $result);
 }
        $groups = $userGroup->getUserGroupListByUser($user['user_id']);
        $groupNameListToString = '';
        if (!empty($groups)) {
            $groupNameList = array_column($groups, 'name');
            $groupNameListToString = ' - [' . implode(', ', $groupNameList) . ']';
        }
        $name = api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ')' . $officialCode;
        if ($orderUserListByOfficialCode === 'true') {
            $officialCode = !empty($user['official_code']) ? $user['official_code'] . " - " : '? - ';
            $name = $officialCode . " " . api_get_person_name($user['firstname'], $user['lastname']) . ' (' . $user['username'] . ')';
        }
        $possible_users[$user['user_id']] = $name . $groupNameListToString;
    }
}
// Group members
$group_member_list = GroupManager::get_subscribed_users($current_group['id']);
$selected_users = array();
if (!empty($group_member_list)) {
    foreach ($group_member_list as $index => $user) {
        $selected_users[] = $user['user_id'];
    }
}
$group_members_element = $form->addElement('advmultiselect', 'group_members', get_lang('GroupMembers'), $possible_users, 'style="width: 280px;"');
$form->addFormRule('check_group_members');
// submit button
$form->addButtonSave(get_lang('SaveSettings'));
if ($form->validate()) {
    $values = $form->exportValues();
    // Storing the users (we first remove all users and then add only those who were selected)
    GroupManager::unsubscribe_all_users($current_group['id']);
    if (isset($_POST['group_members']) && count($_POST['group_members']) > 0) {
示例#3
0
 /**
  * Function wizard individual assignment
  * @author Juan Carlos Raña <*****@*****.**>
  */
 public function auto_add_page_users($values)
 {
     $assignment_type = $values['assignment'];
     $session_id = $this->session_id;
     $groupId = api_get_group_id();
     if ($groupId == 0) {
         //extract course members
         if (!empty($session_id)) {
             $a_users_to_add = CourseManager::get_user_list_from_course_code(api_get_course_id(), $session_id);
         } else {
             $a_users_to_add = CourseManager::get_user_list_from_course_code(api_get_course_id(), 0);
         }
     } else {
         //extract group members
         $subscribed_users = GroupManager::get_subscribed_users($groupId);
         $subscribed_tutors = GroupManager::get_subscribed_tutors($groupId);
         $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);'));
     }
     $all_students_pages = array();
     // Data about teacher
     $userId = api_get_user_id();
     $userinfo = api_get_user_info($userId);
     $username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username'], ENT_QUOTES));
     $name = $userinfo['complete_name'] . " - " . $username;
     $photo = '<img src="' . $userinfo['avatar'] . '" alt="' . $name . '"  width="40" height="50" align="top" title="' . $name . '"  />';
     // teacher assignment title
     $title_orig = $values['title'];
     // teacher assignment reflink
     $link2teacher = $values['title'] = $title_orig . "_uass" . $userId;
     // first: teacher name, photo, and assignment description (original content)
     $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', api_get_person_name($userinfo['firstname'], $userinfo['lastname']), array('title' => $username)) . '</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 $o_user_to_add) {
         if ($o_user_to_add['user_id'] != $userId) {
             // except that puts the task
             $assig_user_id = $o_user_to_add['user_id'];
             // identifies each page as created by the student, not by teacher
             $userPicture = UserManager::getUserPicture($assig_user_id);
             $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="' . $userPicture . '" alt="' . $name . '"  width="40" height="50" align="bottom" title="' . $name . '"  />';
             $is_tutor_of_group = GroupManager::is_tutor_of_group($assig_user_id, $groupId);
             //student is tutor
             $is_tutor_and_member = GroupManager::is_tutor_of_group($assig_user_id, $groupId) && GroupManager::is_subscribed($assig_user_id, $groupId);
             // 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) {
                 $values['title'] = $title_orig;
                 $values['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)
                 $values['assignment'] = 2;
             }
             $this->assig_user_id = $assig_user_id;
             self::save_new_wiki($values);
         }
     }
     foreach ($a_users_to_add as $o_user_to_add) {
         if ($o_user_to_add['user_id'] == $userId) {
             $assig_user_id = $o_user_to_add['user_id'];
             if ($assignment_type == 1) {
                 $values['title'] = $title_orig;
                 $values['comment'] = get_lang('AssignmentDesc');
                 sort($all_students_pages);
                 $values['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/>';
                 $values['assignment'] = 1;
             }
             $this->assig_user_id = $assig_user_id;
             self::save_new_wiki($values);
         }
     }
 }
示例#4
0
/**
 * Get list of users who have not given the task
 * @param int
 * @param int
 * @return array
 * @author cvargas
 * @author Julio Montoya <*****@*****.**> Fixing query
 */
function get_list_users_without_publication($task_id, $studentId = null)
{
    $work_table              = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $table_course_user       = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    $table_user              = Database::get_main_table(TABLE_MAIN_USER);
    $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);

    //condition for the session
    $session_id    = api_get_session_id();
    $course_id     = api_get_course_int_id();

    $task_id = intval($task_id);

    if ($session_id == 0) {
        $sql = "SELECT user_id as id FROM $work_table
                WHERE
                    c_id = $course_id AND
                    parent_id='$task_id' AND
                    active IN (0, 1)";
    } else {
        $sql = "SELECT user_id as id FROM $work_table
                WHERE
                    c_id = $course_id AND
                    parent_id='$task_id' AND
                    session_id='".$session_id."' AND
                    active IN (0, 1)";
    }

    $result = Database::query($sql);
    $users_with_tasks = array();
    while($row = Database::fetch_array($result)) {
        $users_with_tasks[] = $row['id'];
    }

    if ($session_id == 0) {
        $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email FROM $table_course_user AS cu, $table_user AS u
                      WHERE u.status != 1 and cu.course_code='".api_get_course_id()."' AND u.user_id = cu.user_id";
    } else {
        $sql_users = "SELECT cu.id_user, u.lastname, u.firstname, u.email FROM $session_course_rel_user AS cu, $table_user AS u
                      WHERE u.status != 1 and cu.course_code='".api_get_course_id()."' AND u.user_id = cu.id_user and cu.id_session = '".$session_id."'";
    }

    if (!empty($studentId)) {
        $sql_users.= " AND u.user_id = ".intval($studentId);
    }

    $group_id = api_get_group_id();

    $new_group_user_list = array();

    if ($group_id) {
        $group_user_list = GroupManager::get_subscribed_users($group_id);
        if (!empty($group_user_list)) {
            foreach($group_user_list as $group_user) {
                $new_group_user_list[] = $group_user['user_id'];
            }
        }
    }

    $result_users = Database::query($sql_users);
    $users_without_tasks = array();
    while ($row_users = Database::fetch_row($result_users)) {

        if (in_array($row_users[0], $users_with_tasks)) {
            continue;
        }

        if ($group_id && !in_array($row_users[0], $new_group_user_list)) {
            continue;
        }
        $userId = $row_users[0];
        $row_users[0] = $row_users[1];
        $row_users[1] = $row_users[2];
        $row_users[2] = Display::encrypted_mailto_link($row_users[3]);
        $row_users[3] = $userId;
        $users_without_tasks[] = $row_users;
    }
    return $users_without_tasks;
}
/**
 * @return array|null|string
 */
function store_add_dropbox()
{
    $_course = api_get_course_info();
    $_user = api_get_user_info();
    $dropbox_cnf = getDropboxConf();
    // Validating the form data
    // there are no recipients selected
    if (!isset($_POST['recipients']) || count($_POST['recipients']) <= 0) {
        return get_lang('YouMustSelectAtLeastOneDestinee');
    } else {
        // Check if all the recipients are valid
        $thisIsAMailing = false;
        $thisIsJustUpload = false;
        foreach ($_POST['recipients'] as $rec) {
            if ($rec == 'mailing') {
                $thisIsAMailing = true;
            } elseif ($rec == 'upload') {
                $thisIsJustUpload = true;
            } elseif (strpos($rec, 'user_') === 0 && !isCourseMember(substr($rec, strlen('user_')))) {
                return get_lang('InvalideUserDetected');
            } elseif (strpos($rec, 'group_') !== 0 && strpos($rec, 'user_') !== 0) {
                return get_lang('InvalideGroupDetected');
            }
        }
    }
    // we are doing a mailing but an additional recipient is selected
    if ($thisIsAMailing && count($_POST['recipients']) != 1) {
        return get_lang('MailingSelectNoOther');
    }
    // we are doing a just upload but an additional recipient is selected.
    // note: why can't this be valid? It is like sending a document to yourself AND to a different person (I do this quite often with my e-mails)
    if ($thisIsJustUpload && count($_POST['recipients']) != 1) {
        return get_lang('MailingJustUploadSelectNoOther');
    }
    if (empty($_FILES['file']['name'])) {
        $error = true;
        return get_lang('NoFileSpecified');
    }
    // are we overwriting a previous file or sending a new one
    $dropbox_overwrite = false;
    if (isset($_POST['cb_overwrite']) && $_POST['cb_overwrite']) {
        $dropbox_overwrite = true;
    }
    // doing the upload
    $dropbox_filename = $_FILES['file']['name'];
    $dropbox_filesize = $_FILES['file']['size'];
    $dropbox_filetype = $_FILES['file']['type'];
    $dropbox_filetmpname = $_FILES['file']['tmp_name'];
    // check if the filesize does not exceed the allowed size.
    if ($dropbox_filesize <= 0 || $dropbox_filesize > $dropbox_cnf['maxFilesize']) {
        return get_lang('DropboxFileTooBig');
        // TODO: The "too big" message does not fit in the case of uploading zero-sized file.
    }
    // check if the file is actually uploaded
    if (!is_uploaded_file($dropbox_filetmpname)) {
        // check user fraud : no clean error msg.
        return get_lang('TheFileIsNotUploaded');
    }
    $upload_ok = process_uploaded_file($_FILES['file'], true);
    if (!$upload_ok) {
        return null;
    }
    // Try to add an extension to the file if it hasn't got one
    $dropbox_filename = add_ext_on_mime($dropbox_filename, $dropbox_filetype);
    // Replace dangerous characters
    $dropbox_filename = replace_dangerous_char($dropbox_filename);
    // Transform any .php file in .phps fo security
    $dropbox_filename = php2phps($dropbox_filename);
    //filter extension
    if (!filter_extension($dropbox_filename)) {
        return get_lang('UplUnableToSaveFileFilteredExtension');
    }
    // set title
    $dropbox_title = $dropbox_filename;
    // set author
    if (!isset($_POST['authors'])) {
        $_POST['authors'] = getUserNameFromId($_user['user_id']);
    }
    // note: I think we could better migrate everything from here on to separate functions: store_new_dropbox, store_new_mailing, store_just_upload
    if ($dropbox_overwrite) {
        $dropbox_person = new Dropbox_Person($_user['user_id'], api_is_course_admin(), api_is_course_tutor());
        foreach ($dropbox_person->sentWork as $w) {
            if ($w->title == $dropbox_filename) {
                if ($w->recipients[0]['id'] > dropbox_cnf('mailingIdBase') xor $thisIsAMailing) {
                    return get_lang('MailingNonMailingError');
                }
                if ($w->recipients[0]['id'] == $_user['user_id'] xor $thisIsJustUpload) {
                    return get_lang('MailingJustUploadSelectNoOther');
                }
                $dropbox_filename = $w->filename;
                $found = true;
                // note: do we still need this?
                break;
            }
        }
    } else {
        // rename file to login_filename_uniqueId format
        $dropbox_filename = getLoginFromId($_user['user_id']) . "_" . $dropbox_filename . "_" . uniqid('');
    }
    // creating the array that contains all the users who will receive the file
    $new_work_recipients = array();
    foreach ($_POST['recipients'] as $rec) {
        if (strpos($rec, 'user_') === 0) {
            $new_work_recipients[] = substr($rec, strlen('user_'));
        } elseif (strpos($rec, 'group_') === 0) {
            $userList = GroupManager::get_subscribed_users(substr($rec, strlen('group_')));
            foreach ($userList as $usr) {
                if (!in_array($usr['user_id'], $new_work_recipients) && $usr['user_id'] != $_user['user_id']) {
                    $new_work_recipients[] = $usr['user_id'];
                }
            }
        }
    }
    @move_uploaded_file($dropbox_filetmpname, dropbox_cnf('sysPath') . '/' . $dropbox_filename);
    $b_send_mail = api_get_course_setting('email_alert_on_new_doc_dropbox');
    if ($b_send_mail) {
        foreach ($new_work_recipients as $recipient_id) {
            $recipent_temp = UserManager::get_user_info_by_id($recipient_id);
            $additionalParameters = array('smsType' => ClockworksmsPlugin::NEW_FILE_SHARED_COURSE_BY, 'userId' => $recipient_id, 'courseTitle' => $_course['title'], 'userUsername' => $recipent_temp['username']);
            api_mail_html(api_get_person_name($recipent_temp['firstname'] . ' ' . $recipent_temp['lastname'], null, PERSON_NAME_EMAIL_ADDRESS), $recipent_temp['email'], get_lang('NewDropboxFileUploaded'), get_lang('NewDropboxFileUploadedContent') . ' ' . api_get_path(WEB_CODE_PATH) . 'dropbox/index.php?cidReq=' . $_course['sysCode'] . "\n\n" . api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS) . "\n" . get_lang('Email') . " : " . $_user['mail'], api_get_person_name($_user['firstName'], $_user['lastName'], null, PERSON_NAME_EMAIL_ADDRESS), $_user['mail'], null, null, null, $additionalParameters);
        }
    }
    new Dropbox_SentWork($_user['user_id'], $dropbox_title, $_POST['description'], strip_tags($_POST['authors']), $dropbox_filename, $dropbox_filesize, $new_work_recipients);
    Security::clear_token();
    return get_lang('FileUploadSucces');
}
示例#6
0
             if (preg_match(dropbox_cnf('mailingZipRegexp'), $dropbox_title)) {
                 $newWorkRecipients = dropbox_cnf('mailingIdBase');
             } else {
                 $error = true;
                 $errormsg = $dropbox_title . ': ' . get_lang('MailingWrongZipfile');
             }
         } elseif ($thisIsJustUpload) {
             $newWorkRecipients = array();
         } else {
             // Creating the array that contains all the users who will receive the file
             $newWorkRecipients = array();
             foreach ($_POST['recipients'] as $rec) {
                 if (strpos($rec, 'user_') === 0) {
                     $newWorkRecipients[] = substr($rec, strlen('user_'));
                 } elseif (strpos($rec, 'group_') === 0) {
                     $userList = GroupManager::get_subscribed_users(substr($rec, strlen('group_')));
                     foreach ($userList as $usr) {
                         if (!in_array($usr['user_id'], $newWorkRecipients) && $usr['user_id'] != $_user['user_id']) {
                             $newWorkRecipients[] = $usr['user_id'];
                         }
                     }
                 }
             }
         }
         // After uploading the file, create the db entries
         if (!$error) {
             @move_uploaded_file($dropbox_filetmpname, dropbox_cnf('sysPath') . '/' . $dropbox_filename) or die(get_lang('UploadError') . ' (code 407)');
             new Dropbox_SentWork($_user['user_id'], $dropbox_title, $_POST['description'], strip_tags($_POST['authors']), $dropbox_filename, $dropbox_filesize, $newWorkRecipients);
         }
     }
 }
示例#7
0
/**
 * Get list of users who have not given the task
 * @param int
 * @param int
 * @return array
 * @author cvargas
 * @author Julio Montoya <*****@*****.**> Fixing query
 */
function get_list_users_without_publication($task_id, $studentId = null)
{
    $work_table = Database::get_course_table(TABLE_STUDENT_PUBLICATION);
    $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
    $table_user = Database::get_main_table(TABLE_MAIN_USER);
    $session_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
    $users = getAllUserToWork($task_id, api_get_course_int_id());
    $users = array_column($users, 'user_id');
    // Condition for the session
    $session_id = api_get_session_id();
    $course_id = api_get_course_int_id();
    $task_id = intval($task_id);
    if ($session_id == 0) {
        $sql = "SELECT user_id as id FROM {$work_table}\n                WHERE\n                    c_id = {$course_id} AND\n                    parent_id = '{$task_id}' AND\n                    active IN (0, 1)";
    } else {
        $sql = "SELECT user_id as id FROM {$work_table}\n                WHERE\n                    c_id = {$course_id} AND\n                    parent_id = '{$task_id}' AND\n                    session_id = '" . $session_id . "' AND\n                    active IN (0, 1)";
    }
    $result = Database::query($sql);
    $users_with_tasks = array();
    while ($row = Database::fetch_array($result)) {
        $users_with_tasks[] = $row['id'];
    }
    if ($session_id == 0) {
        $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email\n                      FROM {$table_course_user} AS cu, {$table_user} AS u\n                      WHERE u.status != 1 and cu.c_id='" . $course_id . "' AND u.user_id = cu.user_id";
    } else {
        $sql_users = "SELECT cu.user_id, u.lastname, u.firstname, u.email\n                      FROM {$session_course_rel_user} AS cu, {$table_user} AS u\n                      WHERE\n                        u.status != 1 AND\n                        cu.c_id='" . $course_id . "' AND\n                        u.user_id = cu.user_id AND\n                        cu.session_id = '" . $session_id . "'";
    }
    if (!empty($studentId)) {
        $sql_users .= " AND u.user_id = " . intval($studentId);
    }
    $group_id = api_get_group_id();
    $new_group_user_list = array();
    if ($group_id) {
        $group_user_list = GroupManager::get_subscribed_users($group_id);
        if (!empty($group_user_list)) {
            foreach ($group_user_list as $group_user) {
                $new_group_user_list[] = $group_user['user_id'];
            }
        }
    }
    $result_users = Database::query($sql_users);
    $users_without_tasks = array();
    while ($rowUsers = Database::fetch_array($result_users)) {
        $userId = $rowUsers['user_id'];
        if (in_array($userId, $users_with_tasks)) {
            continue;
        }
        if ($group_id && !in_array($userId, $new_group_user_list)) {
            continue;
        }
        if (!empty($users)) {
            if (!in_array($userId, $users)) {
                continue;
            }
        }
        $row_users = [];
        $row_users[0] = $rowUsers['lastname'];
        $row_users[1] = $rowUsers['firstname'];
        $row_users[2] = Display::encrypted_mailto_link($rowUsers['email']);
        $row_users[3] = $userId;
        $users_without_tasks[] = $row_users;
    }
    return $users_without_tasks;
}
示例#8
0
    $user_id = $_GET['user_id'];
    $agenda_ajax_url = api_get_path(WEB_AJAX_PATH) . 'agenda.ajax.php?user_id=' . $user_id . '&type=' . $type;
} else {
    $agenda_ajax_url = api_get_path(WEB_AJAX_PATH) . 'agenda.ajax.php?type=' . $type;
}
$tpl->assign('web_agenda_ajax_url', $agenda_ajax_url);
$course_code = api_get_course_id();
$select = null;
if ((api_is_allowed_to_edit() || $is_group_tutor) && $course_code != '-1' && $type == 'course') {
    $order = 'lastname';
    if (api_is_western_name_order()) {
        $order = 'firstname';
    }
    if (!empty($group_id)) {
        $group_list = array($group_id => $group_properties);
        $user_list = GroupManager::get_subscribed_users($group_id);
    } else {
        $user_list = CourseManager::get_user_list_from_course_code(api_get_course_id(), api_get_session_id(), null, $order);
        $group_list = CourseManager::get_group_list_of_course(api_get_course_id(), api_get_session_id());
    }
    $agenda = new Agenda();
    //This will fill the select called #users_to_send_id
    $select = $agenda->construct_not_selected_select_form($group_list, $user_list, array());
    $tpl->assign('visible_to', $select);
}
$form = new FormValidator('form-simple', '', null);
$form->addElement('label', get_lang('Date'), '<span id="simple_start_date"></span><span id="simple_end_date"></span>');
$form->addElement('label', get_lang('Title'), '<div id="simple_title"></div>');
$form->addElement('label', get_lang('Description'), '<div id="simple_content"></div>');
$tpl->assign('form_simple', $form->return_form());
$form = new FormValidator('add_event_form', null, null);
示例#9
0
/**
 * 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
}