コード例 #1
0
 public static function install($data, &$fail, &$errno, &$error)
 {
     $res = array();
     if (!$fail) {
         // die /course Befehle der LCourse auslösen
         // alle Veranstaltungen abrufen
         $multiRequestHandle = new Request_MultiRequest();
         $handler = Request_CreateRequest::createGet($data['PL']['url'] . '/DB/DBCourse/course', array(), '');
         $multiRequestHandle->addRequest($handler);
         $result = $multiRequestHandle->run();
         if (isset($result[0]['content']) && isset($result[0]['status']) && $result[0]['status'] === 200) {
             // /course ausloesen
             $courses = Course::decodeCourse($result[0]['content']);
             if (!is_array($courses)) {
                 $courses = array($courses);
             }
             $multiRequestHandle = new Request_MultiRequest();
             foreach ($courses as $course) {
                 $handler = Request_CreateRequest::createPost($data['PL']['url'] . '/logic/LCourse/course', array(), Course::encodeCourse($course));
                 $multiRequestHandle->addRequest($handler);
             }
             $answer = $multiRequestHandle->run();
             if (count($courses) != count($answer)) {
                 $fail = true;
                 $error = Language::Get('courses', 'differentAnswers') . "\n" . Language::Get('main', 'line') . ':' . __LINE__;
             }
             $i = 0;
             foreach ($courses as $course) {
                 $result = $answer[$i];
                 $res[$course->getId()] = array();
                 $res[$course->getId()]['course'] = $course;
                 if (isset($result['content']) && isset($result['status']) && $result['status'] === 201) {
                     $res[$course->getId()]['status'] = 201;
                 } else {
                     $res[$course->getId()]['status'] = 409;
                     $fail = true;
                     if (isset($result['status'])) {
                         $errno = $result['status'];
                         $res[$course->getId()]['status'] = $result['status'];
                     }
                 }
                 $i++;
                 if ($i >= count($answer)) {
                     break;
                 }
             }
         } else {
             $fail = true;
             $error = "GET /DB/DBCourse/course " . Language::Get('courses', 'operationFailed');
             if (isset($result[0]['status'])) {
                 $errno = $result[0]['status'];
             }
         }
     }
     return $res;
 }
コード例 #2
0
ファイル: LFormProcessor.php プロジェクト: sawh/ostepu-system
 /**
  * Adds the component to a course
  *
  * Called when this component receives an HTTP POST request to
  * /course(/).
  */
 public function addCourse()
 {
     Logger::Log('starts POST AddCourse', LogLevel::DEBUG);
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $courses = Course::decodeCourse($body);
     $processes = array();
     if (!is_array($courses)) {
         $courses = array($courses);
     }
     foreach ($courses as $course) {
         $process = new Process();
         $exercise = new Exercise();
         $exercise->setCourseId($course->getId());
         $process->setExercise($exercise);
         $component = new Component();
         $component->setId($this->_conf->getId());
         $process->setTarget($component);
         $processes[] = $process;
     }
     foreach ($this->_postProcess as $_link) {
         $result = Request::routeRequest('POST', '/process', $header, Process::encodeProcess($processes), $_link, 'process');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $this->app->response->setStatus(201);
             if (isset($result['headers']['Content-Type'])) {
                 $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
         } else {
             /* if ($courses->getId()!==null){
                    $this->deleteCourse($courses->getId());
                }*/
             Logger::Log('POST AddCourse failed', LogLevel::ERROR);
             $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->app->response->setBody(Course::encodeCourse($courses));
             $this->app->stop();
         }
     }
     $this->app->response->setBody(Course::encodeCourse($courses));
 }
コード例 #3
0
ファイル: LForm.php プロジェクト: sawh/ostepu-system
 /**
  * Adds the component to a course
  *
  * Called when this component receives an HTTP POST request to
  * /course(/).
  */
 public function addCourse()
 {
     Logger::Log('starts POST AddCourse', LogLevel::DEBUG);
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $course = Course::decodeCourse($body);
     foreach ($this->_createCourse as $_link) {
         $result = Request::routeRequest('POST', '/course', $header, Course::encodeCourse($course), $_link, 'course');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $this->app->response->setStatus(201);
             if (isset($result['headers']['Content-Type'])) {
                 $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
         } else {
             if ($course->getId() !== null) {
                 $this->deleteCourse($course->getId());
             }
             Logger::Log('POST AddCourse failed', LogLevel::ERROR);
             $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->app->response->setBody(Course::encodeCourse($course));
             $this->app->stop();
         }
     }
     $this->app->response->setBody(Course::encodeCourse($course));
 }
コード例 #4
0
ファイル: DBSetting.php プロジェクト: sawh/ostepu-system
 /**
  * Adds the component to a course
  */
 public function addCourse($pre = '')
 {
     $this->loadConfig($pre);
     $pre = ($pre === '' ? '' : '_') . $pre;
     Logger::Log('starts POST AddCourse', LogLevel::DEBUG);
     // decode the received course data, as an object
     $insert = Course::decodeCourse($this->_app->request->getBody());
     // always been an array
     $arr = true;
     if (!is_array($insert)) {
         $insert = array($insert);
         $arr = false;
     }
     // this array contains the indices of the inserted objects
     $res = array();
     foreach ($insert as $in) {
         // starts a query, by using a given file
         $result = DBRequest::getRoutedSqlFile($this->query, dirname(__FILE__) . '/Sql/AddCourse.sql', array('object' => $in, 'pre' => $pre));
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $queryResult = Query::decodeQuery($result['content']);
             $res[] = $in;
             $this->_app->response->setStatus(201);
             if (isset($result['headers']['Content-Type'])) {
                 $this->_app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
         } else {
             Logger::Log('POST AddCourse failed', LogLevel::ERROR);
             $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->_app->response->setBody(Course::encodeCourse($res));
             $this->_app->stop();
         }
     }
     if (!$arr && count($res) == 1) {
         $this->_app->response->setBody(Course::encodeCourse($res[0]));
     } else {
         $this->_app->response->setBody(Course::encodeCourse($res));
     }
 }
コード例 #5
0
         }
         // adds approvalConditions
         foreach ($etCreate as $exerciseType3) {
             if ($exerciseType3 === '') {
                 continue;
             }
             $newApprovalConditionSettings = ApprovalCondition::encodeApprovalCondition(ApprovalCondition::createApprovalCondition(null, $cid, $exerciseType3, 0));
             $URI = $databaseURI . "/approvalcondition";
             http_post_data($URI, $newApprovalConditionSettings, true, $message);
             if ($message != "201") {
                 $RequestError = true;
             }
         }
     }
     // create new course and edit existing one
     $newCourseSettings = Course::encodeCourse(Course::createCourse($cid, $courseName, $semester, $defaultGroupSize));
     $URI = $databaseURI . "/course/course/{$cid}";
     $courseManagement_data = http_put_data($URI, $newCourseSettings, true, $message);
     // show notification
     if ($message == "201" && $RequestError == false) {
         $courseSettingsNotifications[] = MakeNotification("success", Language::Get('main', 'successEditCourse', $langTemplate));
     } else {
         $courseSettingsNotifications[] = MakeNotification("error", Language::Get('main', 'errorEditCourse', $langTemplate));
     }
     ###########################
     ### end course_settings ###
     ###########################
     #endregion course_settings
 } else {
     $courseSettingsNotifications[] = MakeNotification("error", Language::Get('main', 'missingFields', $langTemplate));
 }
コード例 #6
0
ファイル: Upload.php プロジェクト: sawh/ostepu-system
    $group = http_get($URL, true);
    $group = json_decode($group, true);
    $upload_data['group'] = $group;
}
$user_course_data = $upload_data['user'];
$isExpired = null;
$hasStarted = null;
if (isset($upload_data['exerciseSheet']['endDate']) && isset($upload_data['exerciseSheet']['startDate'])) {
    // bool if endDate of sheet is greater than the actual date
    $isExpired = date('U') > date('U', $upload_data['exerciseSheet']['endDate']);
    // bool if startDate of sheet is greater than the actual date
    $hasStarted = date('U') > date('U', $upload_data['exerciseSheet']['startDate']);
    if ($isExpired) {
        $allowed = 0;
        if (isset($user_course_data['courses'][0]['course'])) {
            $obj = Course::decodeCourse(Course::encodeCourse($user_course_data['courses'][0]['course']));
            $allowed = Course::containsSetting($obj, 'AllowLateSubmissions');
        }
        ///set_error("Der Übungszeitraum ist am ".date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['endDate'])." abgelaufen!");
        if ($allowed === null || $allowed == 1) {
            $msg = Language::Get('main', 'expiredExercisePerionDesc', $langTemplate, array('endDate' => date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['endDate'])));
            $notifications[] = MakeNotification('warning', $msg);
        } else {
            set_error(Language::Get('main', 'expiredExercisePerion', $langTemplate, array('endDate' => date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['endDate']))));
        }
    } elseif (!$hasStarted) {
        set_error(Language::Get('main', 'noStartedExercisePeriod', $langTemplate, array('startDate' => date('d.m.Y  -  H:i', $upload_data['exerciseSheet']['startDate']))));
    }
} else {
    set_error(Language::Get('main', 'noExercisePeriod', $langTemplate));
}
コード例 #7
0
ファイル: LExtension.php プロジェクト: sawh/ostepu-system
 /**
  * Install the given component to a course.
  *
  * Called when this component receives an HTTP POST request to
  * /link/course/$courseid/extension/$name(/).
  *
  * @param int $courseid The id of the course.
  * @param int $name The name of the component
  */
 public function addCourseExtension($courseid, $name)
 {
     foreach ($this->_extension as $link) {
         if ($link->getTargetName() === $name || $link->getTarget() === $name) {
             // TODO: hier eventuell alle Course Daten verwenden (vorher Abrufen)
             $courseObject = Course::createCourse($courseid, null, null, null);
             $result = Request::routeRequest('POST', '/course', $this->app->request->headers->all(), Course::encodeCourse($courseObject), $link, 'course');
             // checks the correctness of the query
             if ($result['status'] >= 200 && $result['status'] <= 299) {
                 $this->app->response->setStatus(201);
                 $this->app->response->setBody(null);
                 if (isset($result['headers']['Content-Type'])) {
                     $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
                 }
                 $this->app->stop();
             } else {
                 Logger::Log('POST AddCourseExtension failed', LogLevel::ERROR);
                 $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
                 $this->app->stop();
             }
         }
     }
     $this->app->response->setStatus(404);
     $this->app->response->setBody(null);
 }
コード例 #8
0
ファイル: LOOP.php プロジェクト: sawh/ostepu-system
 /**
  * Adds the component to a course
  *
  * Called when this component receives an HTTP POST request to
  * /course(/).
  */
 public function addCourse()
 {
     Logger::Log('starts POST AddCourse', LogLevel::DEBUG);
     $body = $this->app->request->getBody();
     // die Daten der Veranstaltung kommen über den Aufrufkörper rein
     $courses = Course::decodeCourse($body);
     $processes = array();
     if (!is_array($courses)) {
         $courses = array($courses);
     }
     // wenn die Komponente direkt in mehrere Veranstaltungen eingetragen werden soll,
     // wird das Eintragen für alle vorgenommen
     foreach ($courses as $course) {
         // ab hier wird der neue Eintrag zusammengestellt
         $process = new Process();
         $exercise = new Exercise();
         $exercise->setCourseId($course->getId());
         $process->setExercise($exercise);
         $component = new Component();
         $component->setId($this->_conf->getId());
         $process->setTarget($component);
         // und nun wird gesammelt
         $processes[] = $process;
     }
     // die erstellten Einträge können nun an den Zuständigen geschickt werden
     foreach ($this->_postProcess as $_link) {
         $result = Request::routeRequest('POST', '/process', array(), Process::encodeProcess($processes), $_link, 'process');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             // wenn der Erstellvorgang erfolgreich war, können wir dies melden
             $this->app->response->setStatus(201);
             if (isset($result['headers']['Content-Type'])) {
                 $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
         } else {
             // der Eintrag konnte nicht erstellt werden
             /* if ($courses->getId()!==null){
                    $this->deleteCourse($courses->getId());
                }*/
             Logger::Log('POST AddCourse failed', LogLevel::ERROR);
             // gibt den Status der "Erstellanfrage" zurück oder eine 409 und zusätzlich
             // das eingehende Veranstaltungsobjekt
             $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->app->response->setBody(Course::encodeCourse($courses));
             $this->app->stop();
         }
     }
     // die bearbeiteten Veranstaltungen können nun zur Ausgabe hinzugefügt werden
     $this->app->response->setBody(Course::encodeCourse($courses));
 }
コード例 #9
0
 /**
  * Logs in a user.
  *
  * @param string $username
  * @param string $password
  * @return true if login is successful
  */
 public function loginUser($username, $password)
 {
     global $databaseURI;
     global $logicURI;
     // check if logged in in studip
     $studip = $this->checkUserInStudip($this->uid, $this->sid);
     $studipStatus = null;
     if ($studip == true) {
         ///Logger::Log("inStudip", LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         $url = "{$databaseURI}/user/user/{$username}";
         $message = null;
         $this->userData = http_get($url, false, $message);
         ///Logger::Log("ostepuUser_url: ".$url, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         ///Logger::Log("ostepuUser_message: ".$message, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         ///Logger::Log("ostepuUser_data: ".$this->userData, LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
         $this->userData = json_decode($this->userData, true);
         // check if user exists in our system
         if ($message != "404" && empty($this->userData) == false) {
             // save logged in uid
             $_SESSION['UID'] = $this->userData['id'];
             // refresh Session in UI and DB
             $refresh = $this->refreshSession();
             if (isset($_GET['vid']) && (!isset($_GET['cid']) || $this->cid === null)) {
                 // convert vid to cid
                 // create course if does not exist
                 $this->cid = $this->convertVidToCid($_GET['vid']);
                 ///Logger::Log("cid: ".$this->cid , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
                 if ($this->cid === null) {
                     // create course
                     $studipStatus = $this->getUserStatusInStudip($this->uid, $this->vid);
                     if ($studipStatus === CourseStatus::getStatusDefinition(true)['administrator']) {
                         ///Logger::Log("createCourse>>".$_GET['vid'] , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
                         $courseObject = $this->getCourseInStudip($this->vid);
                         if ($courseObject !== null) {
                             $url = "{$logicURI}/course";
                             $courseObject = http_post_data($url, Course::encodeCourse($courseObject), false, $message);
                             if ($message === 201) {
                                 // new course was created
                                 $courseObject = Course::decodeCourse($courseObject);
                                 if ($courseObject !== null) {
                                     $this->cid = $courseObject->getId();
                                     $url = "{$databaseURI}/externalid";
                                     $externalId = ExternalId::createExternalId('S_' . $_GET['vid'], $this->cid);
                                     $externalId = http_post_data($url, ExternalId::encodeExternalId($externalId), false, $message);
                                     if ($message !== 201) {
                                         // create externalId fails, remove course
                                         $url = "{$logicURI}/course/course/" . $this->cid;
                                         http_delete($url, false, $message);
                                         $this->cid = null;
                                     }
                                     if ($this->cid !== null && $studipStatus === CourseStatus::getStatusDefinition(true)['administrator']) {
                                         // redirect user to course settings
                                         /// ???
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if (!isset($this->cid) || $this->cid === null) {
                 set_error("unbekannte Veranstaltung!!!");
                 exit;
             }
             // get the courseStatus for given course
             $this->courseStatus = $this->findCourseStatus();
             ///Logger::Log("courseStatus: ".$this->courseStatus , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
             // if user has no status in course create it
             if (!isset($this->courseStatus)) {
                 if ($studipStatus === null) {
                     $studipStatus = $this->getUserStatusInStudip($this->uid, $this->vid);
                 }
                 if ($studipStatus !== null) {
                     ///Logger::Log("createCourseStatus" , LogLevel::DEBUG, false, dirname(__FILE__) . '/../../auth.log');
                     // check whether an registration is allowed
                     $courseData = $this->getCourseData($this->cid);
                     if ($courseData === null) {
                         // no course data
                         set_error("Keine Veranstaltung gefunden!");
                         exit;
                     }
                     if ($courseData->getSettings() !== null) {
                         $end = Course::containsSetting($courseData, 'RegistrationPeriodEnd');
                         if ($end !== null && $end != 0 && $end < time()) {
                             // no registration allowed
                             set_error("Eine Anmeldung ist nicht möglich!!! Ablaufdatum: " . date('d.m.Y - H:i', $end));
                             exit;
                         }
                     }
                     $CourseStatusResponse = $this->createCourseStatus($this->userData['id'], $this->cid, $studipStatus);
                     // set courseStatus to studipStatus only if status is created in DB successfully
                     if ($CourseStatusResponse == true) {
                         $this->courseStatus = $studipStatus;
                     }
                 }
             }
             return $refresh;
         } else {
             // get new user from studIP
             $newUser = $this->getUserInStudip($username);
             // if user is a valid user
             if ($newUser != "not found") {
                 ///Logger::Log("creatUser: "******"");
                 }
             }
         }
     }
     return false;
 }
コード例 #10
0
ファイル: MainSettings.php プロジェクト: sawh/ostepu-system
 $f->checkIntegerForKey('defaultGroupSize', FormEvaluator::REQUIRED, 'warning', Language::Get('main', 'invalidGroupSize', $langTemplate), array('min' => 0));
 $f->checkArrayOfIntegersForKey('exerciseTypes', FormEvaluator::OPTIONAL, 'warning', Language::Get('main', 'invalidExerciseType', $langTemplate));
 $f->checkArrayOfIntegersForKey('plugins', FormEvaluator::OPTIONAL, 'warning', Language::Get('main', 'noSelectedExtensions', $langTemplate));
 if ($f->evaluate(true)) {
     // bool which is true if any error occured
     $RequestError = false;
     $foundValues = $f->foundValues;
     // extracts the php POST data
     $courseName = $foundValues['courseName'];
     $semester = $foundValues['semester'];
     $defaultGroupSize = $foundValues['defaultGroupSize'];
     $plugins = $foundValues['plugins'];
     $exerciseTypes = $foundValues['exerciseTypes'];
     // creates a new course
     $newCourse = Course::createCourse(null, $courseName, $semester, $defaultGroupSize);
     $newCourseSettings = Course::encodeCourse($newCourse);
     $URI = $logicURI . "/course";
     $newCourse = http_post_data($URI, $newCourseSettings, true, $messageNewCourse);
     // extracts the id of the new course
     $newCourse = json_decode($newCourse, true);
     $newCourseId = $newCourse['id'];
     // creates a new approvalCondition for every selected exerciseType
     if (isset($exerciseTypes) && !empty($exerciseTypes)) {
         foreach ($exerciseTypes as $exerciseType) {
             $newApprovalCondition = ApprovalCondition::createApprovalCondition(null, $newCourseId, $exerciseType, 0);
             $newApprovalConditionSettings = ApprovalCondition::encodeApprovalCondition($newApprovalCondition);
             $URI = $databaseURI . "/approvalcondition";
             http_post_data($URI, $newApprovalConditionSettings, true, $messageNewAc);
             if ($messageNewAc != "201") {
                 $RequestError = true;
                 break;