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;
 }
Esempio n. 2
0
 /**
  * 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));
 }
Esempio n. 3
0
 /**
  * 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));
 }
Esempio n. 4
0
 /**
  * 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));
     }
 }
 public static function cleanCourses($data, &$fail, &$errno, &$error)
 {
     $res = array();
     if (!$fail) {
         $cleanLinks = Einstellungen::getLinks('deleteClean');
         // 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);
             }
             $offset = count($courses) - 50;
             // nur die letzten 50 Veranstaltungen werden bereinigt
             $offset = $offset < 0 ? 0 : $offset;
             $courses = array_slice($courses, $offset);
             foreach ($courses as $course) {
                 $multiRequestHandle = new Request_MultiRequest();
                 $answer = array();
                 for ($i = 0; $i < count($cleanLinks); $i++) {
                     // inits all components
                     $handler = Request_CreateRequest::createDelete($cleanLinks[$i]->getAddress() . '/clean/clean/course/' . $course->getId(), array(), '');
                     $multiRequestHandle->addRequest($handler);
                 }
                 $answer = $multiRequestHandle->run();
             }
             $res['status'] = 201;
         } else {
             $fail = true;
             $error = "GET /DB/DBCourse/course " . Language::Get('courses', 'operationFailed');
             if (isset($result[0]['status'])) {
                 $errno = $result[0]['status'];
             }
         }
     }
     return $res;
 }
Esempio n. 6
0
 public static function ExtractCourse($data, $singleResult = false, $CourseExtension = '', $SheetExtension = '', $isResult = true)
 {
     // generates an assoc array of courses by using a defined list of
     // its attributes
     $courses = DBJson::getObjectsByAttributes($data, Course::getDBPrimaryKey(), Course::getDBConvert(), $CourseExtension);
     // generates an assoc array of settings by using a defined list of
     // its attributes
     $settings = DBJson::getObjectsByAttributes($data, Setting::getDBPrimaryKey(), Setting::getDBConvert());
     // generates an assoc array of exercise sheets by using a defined list of
     // its attributes
     $exerciseSheets = DBJson::getObjectsByAttributes($data, ExerciseSheet::getDBPrimaryKey(), array(ExerciseSheet::getDBPrimaryKey() => ExerciseSheet::getDBConvert()[ExerciseSheet::getDBPrimaryKey()]), $SheetExtension);
     // concatenates the courses and the associated settings
     $res = DBJson::concatObjectListResult($data, $courses, Course::getDBPrimaryKey(), Course::getDBConvert()['C_settings'], $settings, Setting::getDBPrimaryKey());
     // concatenates the courses and the associated exercise sheet IDs
     $res = DBJson::concatResultObjectListAsArray($data, $res, Course::getDBPrimaryKey(), Course::getDBConvert()['C_exerciseSheets'], $exerciseSheets, ExerciseSheet::getDBPrimaryKey(), $SheetExtension, $CourseExtension);
     if ($isResult) {
         $res = Course::decodeCourse($res, false);
         if ($singleResult == true) {
             // only one object as result
             if (count($res) > 0) {
                 $res = $res[0];
             }
         }
     }
     return $res;
 }
Esempio n. 7
0
    $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));
}
Esempio n. 8
0
 /**
  * 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));
 }
 /**
  * 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;
 }
Esempio n. 10
0
 /**
  * the constructor
  *
  * @param $data an assoc array with the object informations
  */
 public function __construct($data = array())
 {
     if ($data === null) {
         $data = array();
     }
     foreach ($data as $key => $value) {
         if (isset($key)) {
             if ($key == 'course') {
                 $this->{$key} = Course::decodeCourse($value, false);
             } else {
                 $func = 'set' . strtoupper($key[0]) . substr($key, 1);
                 $methodVariable = array($this, $func);
                 if (is_callable($methodVariable)) {
                     $this->{$func}($value);
                 } else {
                     $this->{$key} = $value;
                 }
             }
         }
     }
 }