Example #1
0
                    $notifications[] = MakeNotification("error", Language::Get('main', 'differentPasswords', $langTemplate));
                }
            } else {
                $notifications[] = MakeNotification("error", Language::Get('main', 'incorrectOldPassword', $langTemplate));
            }
        } else {
            $notifications = $notifications + $f->notifications;
        }
    } else {
        if ($_POST['action'] == "SetAccountInfo") {
            $f = new FormEvaluator($_POST);
            $f->checkStringForKey('language', FormEvaluator::OPTIONAL, 'warning', '???.');
            if ($f->evaluate(true)) {
                $foundValues = $f->foundValues;
                $language = $foundValues['language'];
                $newUserSettings = User::encodeUser(User::createUser($uid, null, null, null, null, null, null, null, null, null, null, null, null, null, $language));
                $URI = $databaseURI . "/user/" . $uid;
                http_put_data($URI, $newUserSettings, true, $message);
                if ($message == "201") {
                    $notifications[] = MakeNotification("success", Language::Get('main', 'languageChanged', $langTemplate));
                }
            } else {
                $notifications = $notifications + $f->notifications;
            }
        }
    }
}
// load user data from the database
$databaseURI = $getSiteURI . "/accountsettings/user/{$uid}";
$accountSettings_data = http_get($databaseURI, true);
$accountSettings_data = json_decode($accountSettings_data, true);
Example #2
0
     }
 } elseif ($_POST['action'] == "AddUser") {
     $f = new FormEvaluator($_POST);
     $f->checkStringForKey('userName', FormEvaluator::REQUIRED, 'warning', Language::Get('main', 'invalidUserName', $langTemplate), array('min' => 1));
     $f->checkIntegerForKey('rights', FormEvaluator::REQUIRED, 'warning', Language::Get('main', 'invalidCourseStatus', $langTemplate), array('min' => 0, 'max' => 2));
     if ($f->evaluate(true)) {
         $foundValues = $f->foundValues;
         $userName = $foundValues['userName'];
         $rights = $foundValues['rights'];
         $URL = $databaseURI . '/user/user/' . $userName;
         $user = http_get($URL, true);
         $user = json_decode($user, true);
         if (isset($user['id'])) {
             $userId = $user['id'];
             $newUser = User::createCourseStatus($userId, $cid, $rights);
             $newUser = User::encodeUser($newUser);
             $URL = $databaseURI . '/coursestatus';
             http_post_data($URL, $newUser, true, $message);
             if ($message == "201") {
                 $addUserNotifications[] = MakeNotification('success', Language::Get('main', 'successAddUser', $langTemplate));
             } else {
                 $addUserNotifications[] = MakeNotification('error', Language::Get('main', 'errorAddUser', $langTemplate));
             }
         } else {
             $addUserNotifications[] = MakeNotification('error', Language::Get('main', 'invalidUserId', $langTemplate));
         }
     } else {
         if (!isset($addUserNotifications)) {
             $addUserNotifications = array();
         }
         $addUserNotifications = $addUserNotifications + $f->notifications;
Example #3
0
 public function tutorAssignmentSiteInfo($userid, $courseid, $sheetid)
 {
     $response = array();
     $assignedSubmissionIDs = array();
     // get all users with status 1,2,3 (tutor,lecturer,admin)
     $URL = $this->_getUser->getAddress() . '/user/course/' . $courseid . '';
     $handler1 = Request_CreateRequest::createGet($URL, array(), '');
     // get markings
     $URL = $this->_getMarking->getAddress() . '/marking/exercisesheet/' . $sheetid;
     $handler4 = Request_CreateRequest::createGet($URL, array(), '');
     // Get SelectedSubmissions
     $URL = $this->_getSelectedSubmission->getAddress() . '/selectedsubmission/exercisesheet/' . $sheetid;
     $handler5 = Request_CreateRequest::createGet($URL, array(), '');
     $URL = $this->lURL . '/exercisesheet/course/' . $courseid . '/exercise';
     $handler6 = Request_CreateRequest::createGet($URL, array(), '');
     $multiRequestHandle = new Request_MultiRequest();
     $multiRequestHandle->addRequest($handler1);
     $multiRequestHandle->addRequest($handler4);
     $multiRequestHandle->addRequest($handler5);
     $multiRequestHandle->addRequest($handler6);
     $answer = $multiRequestHandle->run();
     $users = json_decode($answer[0]['content'], true);
     $markings = json_decode($answer[1]['content'], true);
     $submissions = json_decode($answer[2]['content'], true);
     $exerciseSheets = json_decode($answer[3]['content'], true);
     unset($answer);
     unset($multiRequestHandle);
     $namesOfExercises = array();
     // find the current sheet and it's exercises
     foreach ($exerciseSheets as &$sheet) {
         $thisSheetId = $sheet['id'];
         if ($thisSheetId == $sheetid) {
             $thisExerciseSheet = $sheet;
             // create exercise names
             //an array to descripe the subtasks
             $alphabet = range('a', 'z');
             $count = 0;
             $count = null;
             if (isset($sheet['exercises'])) {
                 $exercises = $sheet['exercises'];
                 foreach ($exercises as $key => $exercise) {
                     $exerciseId = $exercise['id'];
                     if ($count === null || $exercises[$count]['link'] != $exercise['link']) {
                         $count = $key;
                         $namesOfExercises[$exerciseId] = $exercise['link'];
                         $subtask = 0;
                     } else {
                         $subtask++;
                         $namesOfExercises[$exerciseId] = $exercise['link'] . $alphabet[$subtask];
                         $namesOfExercises[$exercises[$count]['id']] = $exercises[$count]['link'] . $alphabet[0];
                     }
                 }
             }
         }
         unset($sheet['exercises']);
     }
     $students = array();
     $tutors = array();
     foreach ($users as $user) {
         if ($user['courses'][0]['status'] == 0) {
             $students[] = $user;
         } elseif ($user['courses'][0]['status'] > 0) {
             $tutors[] = $user;
         }
     }
     unset($users);
     $response['tutorAssignments'] = array();
     if (!empty($tutors)) {
         foreach ($tutors as &$tutor) {
             unset($tutor['salt']);
             unset($tutor['password']);
             // create an empty marking for each tutor
             $response['tutorAssignments'][] = array('tutor' => $tutor, 'submissions' => array());
         }
     }
     $response['tutorAssignments'][] = array('tutor' => json_decode(User::encodeUser(User::createUser(null, '', '', '', '', null, null, null, null, null, null)), true), 'submissions' => array());
     // assign submissions for the markings to the right tutor
     foreach ($markings as $marking) {
         // ignore marking if submission is not selected for group
         if (isset($marking['submission']) && (!isset($marking['submission']['selectedForGroup']) || !$marking['submission']['selectedForGroup'])) {
             continue;
         }
         foreach ($response['tutorAssignments'] as &$tutorAssignment) {
             if (!isset($tutorAssignment['tutor']['id']) || $marking['tutorId'] == $tutorAssignment['tutor']['id']) {
                 // rename 'id' to 'submissionId'
                 //$marking['submission']['id'] = $marking['submission']['id'];
                 //unset($marking['submission']['id']);
                 // remove unnecessary information
                 unset($marking['submission']['file']);
                 unset($marking['submission']['comment']);
                 unset($marking['submission']['accepted']);
                 unset($marking['submission']['date']);
                 unset($marking['submission']['flag']);
                 unset($marking['submission']['selectedForGroup']);
                 $marking['submission']['user'] = null;
                 foreach ($students as $student) {
                     if ($student['id'] == $marking['submission']['leaderId']) {
                         $marking['submission']['user'] = $student;
                         break;
                     }
                 }
                 $marking['submission']['markingId'] = $marking['id'];
                 $tutorAssignment['submissions'][] = $marking['submission'];
                 // save ids of all assigned submission
                 $assignedSubmissionIDs[] = $marking['submission']['id'];
                 break;
             }
         }
     }
     // remove unknown lecturer if empty
     if (count($response['tutorAssignments'][count($response['tutorAssignments']) - 1]['submissions']) == 0) {
         unset($response['tutorAssignments'][count($response['tutorAssignments']) - 1]);
     }
     $virtualTutor = array('id' => null, 'userName' => "unassigned", 'firstName' => null, 'lastName' => null);
     $unassignedSubmissions = array();
     foreach ($submissions as &$submission) {
         $submission['id'] = $submission['submissionId'];
         unset($submission['submissionId']);
         if (!in_array($submission['id'], $assignedSubmissionIDs)) {
             $submission['unassigned'] = true;
             $submission['user'] = null;
             foreach ($students as $student) {
                 if ($student['id'] == $submission['leaderId']) {
                     $submission['user'] = $student;
                     break;
                 }
             }
             $unassignedSubmissions[] = $submission;
         }
     }
     // generate proposals for tutors by using the markings from last exercise sheet
     if (count($unassignedSubmissions) > 0) {
         $lastSid = null;
         for ($i = 0; $i < count($exerciseSheets); $i++) {
             if ($exerciseSheets[$i]['id'] == $sheetid) {
                 if ($i < count($exerciseSheets) - 1) {
                     $lastSid = $exerciseSheets[$i + 1]['id'];
                     break;
                 }
             }
         }
         if ($lastSid !== null) {
             $URL = $this->_getMarking->getAddress() . '/marking/exercisesheet/' . $lastSid;
             $handler1 = Request_CreateRequest::createGet($URL, array(), '');
             $multiRequestHandle = new Request_MultiRequest();
             $multiRequestHandle->addRequest($handler1);
             $answer = $multiRequestHandle->run();
             $lastMarkings = json_decode($answer[0]['content'], true);
             unset($answer);
             unset($multiRequestHandle);
             $lastTutorUser = array();
             foreach ($lastMarkings as $marking) {
                 ///echo $marking['submission']['id'].' '.$marking['submission']['leaderId'].' '.$marking['tutorId'].' '.(isset($marking['submission']['selectedForGroup'])?$marking['submission']['selectedForGroup']:'')."\n";
                 if (isset($marking['tutorId']) && isset($marking['submission']['leaderId']) && isset($marking['submission']['selectedForGroup']) && $marking['submission']['selectedForGroup']) {
                     $tutorId = $marking['tutorId'];
                     $leaderId = $marking['submission']['leaderId'];
                     if (!isset($lastTutorUser[$tutorId])) {
                         $lastTutorUser[$tutorId] = array();
                     }
                     if (!in_array($leaderId, $lastTutorUser[$tutorId])) {
                         $lastTutorUser[$tutorId][] = $leaderId;
                     }
                 }
             }
             unset($lastMarkings);
             foreach ($response['tutorAssignments'] as &$tutorAssignment) {
                 if (!isset($tutorAssignment['tutor']['id'])) {
                     continue;
                 }
                 if (!isset($lastTutorUser[$tutorAssignment['tutor']['id']])) {
                     continue;
                 }
                 foreach ($unassignedSubmissions as $submission) {
                     if (in_array($submission['leaderId'], $lastTutorUser[$tutorAssignment['tutor']['id']])) {
                         if (!isset($tutorAssignment['proposalSubmissions'])) {
                             $tutorAssignment['proposalSubmissions'] = array();
                         }
                         $tutorAssignment['proposalSubmissions'][] = $submission;
                         unset($submission);
                     }
                 }
             }
         }
     }
     $newTutorAssignment = array('tutor' => $virtualTutor, 'submissions' => $unassignedSubmissions);
     $response['tutorAssignments'][] = $newTutorAssignment;
     $response['namesOfExercises'] = $namesOfExercises;
     $this->flag = 1;
     $response['user'] = $this->userWithCourse($userid, $courseid);
     $this->app->response->setBody(json_encode($response));
 }
 /**
  * Add Course to an user
  *
  * @param string $userId UserID in our System (Attention: NOT the externalID)
  * @param string $courseID CourseID
  * @param string $status The Status the user wants to have in given course.
  * @return true if user is logged in
  */
 public function createCourseStatus($userId, $courseId, $status)
 {
     global $databaseURI;
     $data = User::encodeUser(User::createCourseStatus($userId, $courseId, $status));
     $url = "{$databaseURI}/coursestatus";
     $message = null;
     http_post_data($url, $data, true, $message);
     ///Logger::Log("create_user_status_url: ".$url, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
     ///Logger::Log("create_user_status_message: ".$message, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
     ///Logger::Log("create_user_status_data: ".$data, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
     return $message == "201";
 }
Example #5
0
 $f->checkStringForKey('password', FormEvaluator::REQUIRED, 'warning', Language::Get('main', 'invalidPassword', $langTemplate), array('min' => 6));
 $f->checkStringForKey('passwordRepeat', FormEvaluator::REQUIRED, 'warning', Language::Get('main', 'invalidPasswordRepeat', $langTemplate), array('min' => 6));
 if ($f->evaluate(true)) {
     $foundValues = $f->foundValues;
     $lastName = $foundValues['lastName'];
     $firstName = $foundValues['firstName'];
     $email = isset($foundValues['email']) ? $foundValues['email'] : null;
     $userName = $foundValues['userName'];
     $password = $foundValues['password'];
     $passwordRepeat = $foundValues['passwordRepeat'];
     // both passwords are equal
     if ($password == $passwordRepeat) {
         $salt = $auth->generateSalt();
         $passwordHash = $auth->hashPassword($password, $salt);
         $newUser = User::createUser(null, $userName, $email, $firstName, $lastName, null, 1, $passwordHash, $salt, 0);
         $newUserSettings = User::encodeUser($newUser);
         $URI = $databaseURI . "/user";
         $answer = http_post_data($URI, $newUserSettings, true, $message);
         if ($message == "201") {
             $user = User::decodeUser($answer);
             if ($user->getStatus() == '201') {
                 $notifications[] = MakeNotification("success", Language::Get('main', 'successCreateUser', $langTemplate));
             } else {
                 $notifications[] = MakeNotification("error", Language::Get('main', 'errorCreateUser', $langTemplate));
             }
         } else {
             $notifications[] = MakeNotification("error", Language::Get('main', 'errorCreateUser', $langTemplate));
         }
     } else {
         $notifications[] = MakeNotification("error", Language::Get('main', 'invalidPasswordRepeat', $langTemplate));
     }