public static function install($data, &$fail, &$errno, &$error)
 {
     $res = array();
     if (!$fail) {
         // die /platform Befehle auslösen
         $list = Einstellungen::getLinks('postPlatform');
         $platform = Installation::PlattformZusammenstellen($data);
         $multiRequestHandle = new Request_MultiRequest();
         for ($i = 0; $i < count($list); $i++) {
             // inits all components
             $handler = Request_CreateRequest::createPost($list[$i]->getAddress() . '/platform', array(), Platform::encodePlatform($platform));
             $multiRequestHandle->addRequest($handler);
         }
         $answer = $multiRequestHandle->run();
         for ($i = 0; $i < count($list); $i++) {
             $url = $list[$i]->getTargetName();
             $result = $answer[$i];
             $res[$url] = array();
             if (isset($result['content']) && isset($result['status']) && $result['status'] === 201) {
                 $res[$url]['status'] = 201;
             } else {
                 $res[$url]['status'] = 409;
                 $fail = true;
                 if (isset($result['status'])) {
                     $errno = $result['status'];
                     $res[$url]['status'] = $result['status'];
                 }
             }
         }
     }
     return $res;
 }
 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;
 }
Exemple #3
0
 /**
  * performs a custom request
  *
  * @param string $method the request type (POST, DELETE, PUT, GET, ...) 
  * @param string $target the taget URL
  * @param string $header an array with header informations
  * @param string $content the request content/body
  *
  * @return an array with the request result (status, header, content)
  * - ['headers'] = an array of header informations e.g. ['headers']['Content-Type']
  * - ['content'] = the response content
  * - ['status'] = the status code e.g. 200,201,404,409,...
  */
 public static function custom($method, $target, $header, $content, $authbool = true, $sessiondelete = false)
 {
     $begin = microtime(true);
     $done = false;
     if (!CConfig::$onload && strpos($target, 'http://localhost/') === 0 && file_exists(dirname(__FILE__) . '/request_cconfig.json')) {
         if (self::$components === null) {
             self::$components = CConfig::loadStaticConfig('', '', dirname(__FILE__), 'request_cconfig.json');
         }
         $coms = self::$components->getLinks();
         if ($coms != null) {
             if (!is_array($coms)) {
                 $coms = array($coms);
             }
             $e = strlen(rtrim($_SERVER['DOCUMENT_ROOT'], '/'));
             $f = substr(str_replace("\\", "/", dirname(__FILE__)), $e);
             $g = substr(str_replace("\\", "/", $_SERVER['SCRIPT_FILENAME']), $e);
             $a = 0;
             for (; $a < strlen($g) && $a < strlen($f) && $f[$a] == $g[$a]; $a++) {
             }
             $h = substr(str_replace("\\", "/", $_SERVER['PHP_SELF']), 0, $a - 1);
             foreach ($coms as $com) {
                 if ($com->getPrefix() === null || $com->getLocalPath() == null || $com->getClassFile() == null || $com->getClassName() == null) {
                     Logger::Log('nodata: ' . $method . ' ' . $target, LogLevel::DEBUG, false, dirname(__FILE__) . '/../calls.log');
                     continue;
                 }
                 $url = 'http://localhost' . $h . '/' . $com->getLocalPath();
                 if (strpos($target, $url . '/') === 0) {
                     $result = array();
                     $tar = dirname(__FILE__) . '/../' . $com->getLocalPath() . '/' . $com->getClassFile();
                     $tar = str_replace("\\", "/", $tar);
                     if (!file_exists($tar)) {
                         continue;
                     }
                     $add = substr($target, strlen($url));
                     $sid = CacheManager::getNextSid();
                     CacheManager::getTree($sid, $target, $method);
                     $cachedData = CacheManager::getCachedDataByURL($sid, $target, $method);
                     if ($cachedData !== null) {
                         $result['content'] = $cachedData->content;
                         $result['status'] = $cachedData->status;
                         ///Logger::Log('out>> '.$method.' '.$target, LogLevel::DEBUG, false, dirname(__FILE__) . '/../calls.log');
                         CacheManager::cacheData($sid, $com->getTargetName(), $target, $result['content'], $result['status'], $method);
                     } else {
                         $args = array('REQUEST_METHOD' => $method, 'PATH_INFO' => $add, 'slim.input' => $content);
                         if (isset($_SERVER['HTTP_SESSION'])) {
                             $args['HTTP_SESSION'] = $_SERVER['HTTP_SESSION'];
                         }
                         if (isset($_SERVER['HTTP_USER'])) {
                             $args['HTTP_USER'] = $_SERVER['HTTP_USER'];
                         }
                         if ($authbool) {
                             if (isset($_SESSION['UID'])) {
                                 $args['HTTP_USER'] = $_SESSION['UID'];
                                 $_SERVER['HTTP_USER'] = $_SESSION['UID'];
                             }
                             if (isset($_SESSION['SESSION'])) {
                                 $args['HTTP_SESSION'] = $_SESSION['SESSION'];
                                 $_SERVER['HTTP_SESSION'] = $_SESSION['SESSION'];
                             }
                             if ($sessiondelete) {
                                 if (isset($_SERVER['REQUEST_TIME'])) {
                                     $args['HTTP_DATE'] = $_SERVER['REQUEST_TIME'];
                                     $_SERVER['HTTP_DATE'] = $_SERVER['REQUEST_TIME'];
                                 }
                             } else {
                                 if (isset($_SESSION['LASTACTIVE'])) {
                                     $args['HTTP_DATE'] = $_SESSION['LASTACTIVE'];
                                     $_SERVER['HTTP_DATE'] = $_SESSION['LASTACTIVE'];
                                 }
                             }
                         }
                         if (isset($_SERVER['HTTP_DATE'])) {
                             $args['HTTP_DATE'] = $_SERVER['HTTP_DATE'];
                         }
                         $oldArgs = array('REQUEST_METHOD' => \Slim\Environment::getInstance()->offsetGet('REQUEST_METHOD'), 'PATH_INFO' => \Slim\Environment::getInstance()->offsetGet('PATH_INFO'), 'slim.input' => \Slim\Environment::getInstance()->offsetGet('slim.input'), 'HTTP_DATE' => \Slim\Environment::getInstance()->offsetGet('HTTP_DATE'), 'HTTP_USER' => \Slim\Environment::getInstance()->offsetGet('HTTP_USER'), 'HTTP_SESSION' => \Slim\Environment::getInstance()->offsetGet('HTTP_SESSION'), 'REQUEST_TIME' => \Slim\Environment::getInstance()->offsetGet('REQUEST_TIME'));
                         $oldRequestURI = $_SERVER['REQUEST_URI'];
                         $oldScriptName = $_SERVER['SCRIPT_NAME'];
                         ///$oldRedirectURL = $_SERVER['REDIRECT_URL'];
                         ///echo "old: ".$_SERVER['REQUEST_URI']."\n";
                         $_SERVER['REQUEST_URI'] = substr($target, strlen('http://localhost/') - 1);
                         //$tar.$add;
                         ///$_SERVER['REDIRECT_URL']= substr($target,strlen('http://localhost/')-1);
                         ///echo "mein: ".substr($target,strlen('http://localhost/')-1)."\n";
                         $_SERVER['SCRIPT_NAME'] = $h . '/' . $com->getLocalPath() . '/' . $com->getClassFile();
                         //$tar;
                         $_SERVER['QUERY_STRING'] = '';
                         $_SERVER['REQUEST_METHOD'] = $method;
                         \Slim\Environment::mock($args);
                         include_once $tar;
                         $oldStatus = http_response_code();
                         $oldHeader = array_merge(array(), headers_list());
                         header_remove();
                         http_response_code(0);
                         $name = $com->getClassName();
                         try {
                             ob_start();
                             $obj = new $name();
                             if (isset($obj)) {
                                 unset($obj);
                             }
                             $result['content'] = ob_get_contents();
                             CacheManager::setETag($result['content']);
                             $result['headers'] = array_merge(array(), self::http_parse_headers_short(headers_list()));
                             header_remove();
                             if (!isset($result['headers']['Cachesid'])) {
                                 $newSid = CacheManager::getNextSid();
                                 $result['headers']['Cachesid'] = $newSid;
                             }
                             ob_end_clean();
                             //header_remove();
                             $result['status'] = http_response_code();
                         } catch (Exception $e) {
                             error_log($e->getMessage());
                             header_remove();
                             $result['status'] = '500';
                             $result['content'] = '';
                             $result['headers'] = array();
                         }
                         $_SERVER['REQUEST_URI'] = $oldRequestURI;
                         $_SERVER['SCRIPT_NAME'] = $oldScriptName;
                         //$_SERVER['REDIRECT_URL'] = $oldRedirectURL;
                         \Slim\Environment::mock($oldArgs);
                         $_SERVER['REQUEST_METHOD'] = $oldArgs['REQUEST_METHOD'];
                         http_response_code($oldStatus);
                         header('Content-Type: text/html; charset=utf-8');
                         foreach ($oldHeader as $head) {
                             header($head);
                         }
                         CacheManager::setCacheSid($sid);
                         $targetSid = isset($result['headers']['Cachesid']) ? $result['headers']['Cachesid'] : null;
                         CacheManager::addPath($sid, $targetSid, $com->getTargetName(), $target, $method, $result['status']);
                         CacheManager::finishRequest($targetSid, $h . '/' . $com->getLocalPath(), $com->getTargetName(), $target, $result['content'], $result['status'], $method, $content);
                         CacheManager::cacheData($sid, $com->getTargetName(), $target, $result['content'], $result['status'], $method);
                         ///Logger::Log('in<< '.$method.' '.$com->getClassName().$add, LogLevel::DEBUG, false, dirname(__FILE__) . '/../calls.log');
                     }
                     $done = true;
                     break;
                 }
             }
         }
     }
     if (!$done) {
         // creates a custom request
         Logger::Log("--" . $method . ' ' . $target, LogLevel::DEBUG, false, dirname(__FILE__) . '/../calls.log');
         $ch = Request_CreateRequest::createCustom($method, $target, $header, $content, $authbool, $sessiondelete)->get();
         $content = curl_exec($ch);
         // get the request result
         $result = curl_getinfo($ch);
         $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
         // splits the received header info, to create an entry
         // in the $result['headers'] for each part of the header
         $result['headers'] = self::http_parse_headers(substr($content, 0, $header_size));
         // seperates the content part
         $result['content'] = substr($content, $header_size);
         // sets the received status code
         $result['status'] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         curl_close($ch);
     }
     Logger::Log($target . ' ' . round(microtime(true) - $begin, 2) . 's', LogLevel::DEBUG, false, dirname(__FILE__) . '/../executionTime.log');
     return $result;
 }
 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;
 }
Exemple #5
0
 /**
  * creates an DELETE curl request object 
  *
  * @param $target the taget URL
  * @param $header an array with header informations
  * @param $content the request content/body
  *
  * @return an curl request object 
  */
 public static function createDelete($target, $header, $content, $authbool = true, $sessiondelete = false)
 {
     return Request_CreateRequest::createCustom("DELETE", $target, $header, $content, $authbool, $sessiondelete);
 }
Exemple #6
0
    }
    $fileString = json_encode($files);
    $zipfile = http_post_data($filesystemURI . '/zip', $fileString, true);
    $zipfile = File::decodeFile($zipfile);
    $zipfile->setDisplayName('attachments.zip');
    $zipfile = File::encodeFile($zipfile);
    echo $zipfile;
    exit(0);
} elseif (isset($_GET['downloadMarkings'])) {
    checkPermission(PRIVILEGE_LEVEL::STUDENT);
    $sid = $_GET['downloadMarkings'];
    $multiRequestHandle = new Request_MultiRequest();
    //request to database to get the markings
    $handler = Request_CreateRequest::createCustom('GET', "{$logicURI}/DB/marking/exercisesheet/{$sid}/user/{$uid}", array(), '');
    $multiRequestHandle->addRequest($handler);
    $handler = Request_CreateRequest::createCustom('GET', "{$logicURI}/DB/exercisesheet/exercisesheet/{$sid}/exercise", array(), '');
    $multiRequestHandle->addRequest($handler);
    $answer = $multiRequestHandle->run();
    $markings = json_decode($answer[0]['content'], true);
    $sheet = json_decode($answer[1]['content'], true);
    $exercises = $sheet['exercises'];
    //an array to descripe the subtasks
    $alphabet = range('a', 'z');
    $count = 0;
    $namesOfExercises = array();
    $attachments = array();
    $count = null;
    foreach ($exercises as $key => $exercise) {
        $exerciseId = $exercise['id'];
        if (isset($exercise['attachments'])) {
            $attachments[$exerciseId] = $exercise['attachments'];
Exemple #7
0
 /**
  * Initializes all components, with the data, which can be found in database.
  */
 public function sendComponentDefinitions()
 {
     $this->_app->response->setStatus(200);
     // starts a query
     ob_start();
     eval("?>" . file_get_contents(dirname(__FILE__) . '/Sql/GetComponentDefinitions.sql'));
     $sql = ob_get_contents();
     ob_end_clean();
     $result = DBRequest::request($sql, false, parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE));
     // checks the correctness of the query
     if ((!isset($result['errno']) || !$result['errno']) && $result['content']) {
         $data = DBJson::getRows($result['content']);
         $Components = DBJson::getObjectsByAttributes($data, Component::getDBPrimaryKey(), Component::getDBConvert());
         $Links = DBJson::getObjectsByAttributes($data, Link::getDBPrimaryKey(), Link::getDBConvert());
         $objects = DBJson::concatResultObjectLists($data, $Components, Component::getDBPrimaryKey(), Component::getDBConvert()['CO_links'], $Links, Link::getDBPrimaryKey());
         $request = new Request_MultiRequest();
         $data = parse_ini_file(dirname(__FILE__) . '/config.ini', TRUE);
         $tempObjects = array();
         foreach ($objects as $object) {
             $object = Component::decodeComponent(json_encode($object));
             // prüfen, welche Komponente auf diesem Server ist
             if (strpos($object->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) {
                 continue;
             }
             $object->setAddress($data['PL']['url'] . substr($object->getAddress(), strlen($data['PL']['urlExtern'])));
             $links = $object->getLinks();
             foreach ($links as &$link) {
                 if (strpos($link->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) {
                     continue;
                 }
                 $link->setAddress($data['PL']['url'] . substr($link->getAddress(), strlen($data['PL']['urlExtern'])));
             }
             $object->setLinks($links);
             $result = Request_CreateRequest::createPost($object->getAddress() . '/control', array(), Component::encodeComponent($object));
             $tempObjects[] = $object;
             $request->addRequest($result);
         }
         $results = $request->run();
         $objects = $tempObjects;
         $i = 0;
         $res = array();
         foreach ($objects as $object) {
             $object = Component::decodeComponent(Component::encodeComponent($object));
             $result = $results[$i++];
             $newObject = new Component();
             $newObject->setId($object->getId());
             $newObject->setName($object->getName());
             $newObject->setAddress($object->getAddress());
             $newObject->setDef($object->getDef());
             $newObject->setStatus($result['status']);
             $res[] = $newObject;
             if ($result['status'] != 201) {
                 $add = '';
                 $this->_app->response->setStatus(409);
                 if (isset($result['content'])) {
                     $add = $result['content'];
                 }
                 Logger::Log($result['status'] . '--' . $object->getName() . '--' . $object->getAddress() . "\n" . $add . "\n", LogLevel::ERROR);
             }
         }
         $this->_app->response->setBody(json_encode($res));
     } else {
         Logger::Log('GET SendComponentDefinitions failed', LogLevel::ERROR);
         $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
     }
 }
Exemple #8
0
 public static function install($data, &$fail, &$errno, &$error)
 {
     $fail = false;
     $url = $data['PL']['init'];
     $components = array();
     // inits all components
     $result = Request::get($data['PL']['url'] . '/' . $url . '/definition/send', array(), '');
     //echo $result['content'];
     if (isset($result['content']) && isset($result['status'])) {
         // component routers
         $router = array();
         $results = Component::decodeComponent($result['content']);
         $results = Installation::orderBy(json_decode(Component::encodeComponent($results), true), 'name', SORT_ASC);
         $results = Component::decodeComponent(json_encode($results));
         if (!is_array($results)) {
             $results = array($results);
         }
         if (count($results) == 0) {
             $fail = true;
             $error = Language::Get('components', 'noComponents');
         }
         foreach ($results as $res) {
             $components[$res->getName()] = array();
             $components[$res->getName()]['init'] = $res;
         }
         // get component definitions from database
         $result4 = Request::get($data['PL']['url'] . '/' . $url . '/definition', array(), '');
         if (isset($result4['content']) && isset($result4['status']) && $result4['status'] === 200) {
             $definitions = Component::decodeComponent($result4['content']);
             if (!is_array($definitions)) {
                 $definitions = array($definitions);
             }
             if (count($definitions) == 0) {
                 $fail = true;
                 $error = Language::Get('components', 'noDefinitions');
             }
             $result2 = new Request_MultiRequest();
             $result3 = new Request_MultiRequest();
             $tempDef = array();
             foreach ($definitions as $definition) {
                 if (strpos($definition->getAddress() . '/', $data['PL']['urlExtern'] . '/') === false) {
                     continue;
                 }
                 $components[$definition->getName()]['definition'] = $definition;
                 $tempDef[] = $definition;
                 $request = Request_CreateRequest::createGet($definition->getAddress() . '/info/commands', array(), '');
                 $result2->addRequest($request);
                 $request = Request_CreateRequest::createGet($definition->getAddress() . '/info/links', array(), '');
                 $result3->addRequest($request);
             }
             $definitions = $tempDef;
             $result2 = $result2->run();
             $result3 = $result3->run();
             foreach ($results as $res) {
                 if ($res === null) {
                     $fail = true;
                     continue;
                 }
                 $countLinks = 0;
                 $resultCounter = -1;
                 foreach ($definitions as $definition) {
                     //if (strpos($definition->getAddress().'/', $data['PL']['urlExtern'].'/')===false) continue;
                     $resultCounter++;
                     if ($definition->getId() === $res->getId()) {
                         $links = $definition->getLinks();
                         $links = Installation::orderBy(json_decode(Link::encodeLink($links), true), 'name', SORT_ASC);
                         $links = Link::decodeLink(json_encode($links));
                         if (!is_array($links)) {
                             $links = array($links);
                         }
                         $components[$definition->getName()]['links'] = $links;
                         if (isset($result2[$resultCounter]['content']) && isset($result2[$resultCounter]['status']) && $result2[$resultCounter]['status'] === 200) {
                             $commands = json_decode($result2[$resultCounter]['content'], true);
                             if ($commands !== null) {
                                 $components[$definition->getName()]['commands'] = $commands;
                             }
                         }
                         if (isset($result3[$resultCounter]['content']) && isset($result3[$resultCounter]['status']) && $result3[$resultCounter]['status'] === 200) {
                             $calls = json_decode($result3[$resultCounter]['content'], true);
                             $components[$definition->getName()]['call'] = $calls;
                         }
                         break;
                     }
                 }
                 if ($res->getStatus() !== 201) {
                     $fail = true;
                 }
             }
         } else {
             $fail = true;
             $error = Language::Get('components', 'noDefinitions');
         }
     } else {
         $fail = true;
         $error = Language::Get('components', 'operationFailed');
     }
     if (isset($result['status']) && $result['status'] !== 200) {
         $fail = true;
         $error = Language::Get('components', 'operationFailed');
         $errno = $result['status'];
     }
     return $components;
 }
Exemple #9
0
 public function getZip($userid, $sheetid, $status = null)
 {
     $multiRequestHandle = new Request_MultiRequest();
     $filesList = array();
     //request to database to get the markings
     $handler = Request_CreateRequest::createCustom('GET', $this->_getMarking[0]->getAddress() . '/marking/exercisesheet/' . $sheetid . '/tutor/' . $userid, array(), "");
     $multiRequestHandle->addRequest($handler);
     $answer = $multiRequestHandle->run();
     if (count($answer) < 1 || !isset($answer[0]['status']) || $answer[0]['status'] != 200 || !isset($answer[0]['content'])) {
         $this->app->response->setStatus(404);
         $this->app->response->setBody('');
         $this->app->stop();
     }
     $markings = json_decode($answer[0]['content'], true);
     if (isset($status)) {
         $marks = array();
         foreach ($markings as $marking) {
             if (isset($marking['status']) && $marking['status'] == $status) {
                 $marks[] = $marking;
             }
         }
         $markings = $marks;
     }
     $answer = $this->generateTutorArchive($userid, $sheetid, $markings);
     $this->app->response->setStatus($answer['status']);
     $this->app->response->setBody($answer['content']);
 }
Exemple #10
0
 /**
  * Compiles data for the Condition site.
  *
  * @warning If there is more than one condition assigned to the same
  * exercise type it is undefined which condition will be evaluated. This
  * might even change per user!.
  *
  * @author Florian Lücke
  */
 public function checkCondition($userid, $courseid)
 {
     // load all the data
     $multiRequestHandle = new Request_MultiRequest();
     $URL = $this->_getExerciseType->getAddress() . '/exercisetype';
     $handler = Request_CreateRequest::createCustom('GET', $URL, array(), '');
     $multiRequestHandle->addRequest($handler);
     $URL = $this->_getExercise->getAddress() . '/exercise/course/' . $courseid . '/nosubmission';
     $handler = Request_CreateRequest::createCustom('GET', $URL, array(), '');
     $multiRequestHandle->addRequest($handler);
     $URL = $this->_getApprovalCondition->getAddress() . '/approvalcondition/course/' . $courseid;
     $handler = Request_CreateRequest::createCustom('GET', $URL, array(), '');
     $multiRequestHandle->addRequest($handler);
     $URL = $this->_getUser->getAddress() . '/user/course/' . $courseid . '/status/0';
     $handler = Request_CreateRequest::createCustom('GET', $URL, array(), '');
     $multiRequestHandle->addRequest($handler);
     $URL = $this->_getGroup->getAddress() . '/group/course/' . $courseid;
     $handler = Request_CreateRequest::createGet($URL, array(), '');
     $multiRequestHandle->addRequest($handler);
     $answer = $multiRequestHandle->run();
     $possibleExerciseTypes = json_decode($answer[0]['content'], true);
     $exercises = json_decode($answer[1]['content'], true);
     $approvalconditions = json_decode($answer[2]['content'], true);
     $students = json_decode($answer[3]['content'], true);
     $groups = json_decode($answer[4]['content'], true);
     // preprocess the data to make it quicker to get specific values
     $exerciseTypes = array();
     foreach ($possibleExerciseTypes as $exerciseType) {
         $exerciseTypes[$exerciseType['id']] = $exerciseType;
     }
     $exercisesById = array();
     foreach ($exercises as $exercise) {
         $exercisesById[$exercise['id']] = $exercise;
     }
     $exercisesByType = array();
     foreach ($exercises as $exercise) {
         if (!isset($exercisesByType[$exercise['type']])) {
             $exercisesByType[$exercise['type']] = array();
         }
         unset($exercise['submissions']);
         $exercisesByType[$exercise['type']][] = $exercise;
     }
     // calculate the maximum number of points that a user could get
     // for each exercise type
     $maxPointsByType = array();
     foreach ($exercisesByType as $type => $exercises) {
         $maxPointsByType[$type] = array_reduce($exercises, function ($value, $exercise) {
             if ($exercise['bonus'] == null || $exercise['bonus'] == '0') {
                 // only count the
                 $value += $exercise['maxPoints'];
             }
             return $value;
         }, 0);
     }
     $approvalconditionsByType = array();
     foreach ($approvalconditions as &$condition) {
         // add the name of the exercise type to the approvalcondition
         $typeID = $condition['exerciseTypeId'];
         $condition['exerciseType'] = $exerciseTypes[$typeID]['name'];
         // prepare percenteages for the UI
         $condition['minimumPercentage'] = $condition['percentage'] * 100;
         $condition['approvalConditionId'] = $condition['id'];
         unset($condition['id']);
         // sort approvalconditions by exercise type
         /**
          * @warning this implies that there is *only one* approval
          * condition per exercise type!
          */
         $exerciseTypeID = $condition['exerciseTypeId'];
         if (isset($maxPointsByType[$exerciseTypeID])) {
             $condition['maxPoints'] = $maxPointsByType[$exerciseTypeID];
         } else {
             $condition['maxPoints'] = 0;
         }
         $approvalconditionsByType[$exerciseTypeID] = $condition;
     }
     // get all markings
     $allMarkings = array();
     $URL = $this->_getMarking->getAddress() . '/marking/course/' . $courseid;
     $answer = Request::custom('GET', $URL, array(), '');
     $markings = json_decode($answer['content'], true);
     foreach ($markings as $marking) {
         if (isset($marking['submission']['selectedForGroup']) && $marking['submission']['selectedForGroup'] == 1) {
             $allMarkings[] = $marking;
         }
     }
     unset($markings);
     $allGroups = array();
     foreach ($groups as $group) {
         if (!isset($allGroups[$group['sheetId']])) {
             $allGroups[$group['sheetId']] = array();
         }
         $allGroups[$group['sheetId']][$group['leader']['id']] = $group;
     }
     unset($groups);
     // done preprocessing
     // actual computation starts here
     // add up points that each student reached in a specific exercise type
     $studentMarkings = array();
     foreach ($allMarkings as $marking) {
         $studentID = $marking['submission']['studentId'];
         $leaderID = $marking['submission']['leaderId'];
         if (!isset($studentMarkings[$studentID])) {
             $studentMarkings[$studentID] = array();
         }
         if (!isset($marking['submission']['accepted']) || $marking['submission']['accepted'] == 0) {
             continue;
         }
         $exerciseID = $marking['submission']['exerciseId'];
         $sheetID = $marking['submission']['exerciseSheetId'];
         $exerciseType = $exercisesById[$exerciseID]['type'];
         if (!isset($studentMarkings[$studentID][$exerciseType])) {
             $studentMarkings[$studentID][$exerciseType] = 0;
         }
         $studentMarkings[$leaderID][$exerciseType] += isset($marking['points']) ? $marking['points'] : 0;
         if (isset($allGroups[$sheetID][$leaderID])) {
             $group = $allGroups[$sheetID][$leaderID];
             if (isset($group['members'])) {
                 foreach ($group['members'] as $member) {
                     if (!isset($studentMarkings[$member['id']])) {
                         $studentMarkings[$member['id']] = array();
                     }
                     if (!isset($studentMarkings[$member['id']][$exerciseType])) {
                         $studentMarkings[$member['id']][$exerciseType] = 0;
                     }
                     $studentMarkings[$member['id']][$exerciseType] += isset($marking['points']) ? $marking['points'] : 0;
                 }
             }
         }
     }
     $resultStudents = array();
     foreach ($students as $student) {
         if (!isset($student['id'])) {
             continue;
         }
         if (isset($student['courses'])) {
             unset($student['courses']);
         }
         if (isset($student['attachments'])) {
             unset($student['attachments']);
         }
         $student['percentages'] = array();
         $allApproved = true;
         // iteraterate over all conditions, this will also filter out the
         // exercisetypes that are not needed for this course
         foreach ($approvalconditionsByType as $typeID => $condition) {
             $thisPercentage = array();
             $thisPercentage['exerciseTypeID'] = $typeID;
             $thisPercentage['exerciseType'] = $exerciseTypes[$typeID]['name'];
             // check if it was possible to get points for this exercisetype
             if (!isset($maxPointsByType[$typeID])) {
                 Logger::Log("Unmatchable condition: " . $condition['approvalConditionId'] . "in course: " . $courseid, LogLevel::WARNING);
                 $maxPointsByType[$typeID] = 0;
             }
             if ($maxPointsByType[$typeID] == 0) {
                 $thisPercentage['percentage'] = '100';
                 $thisPercentage['isApproved'] = true;
                 $thisPercentage['maxPoints'] = 0;
                 if (isset($student['id']) && isset($studentMarkings[$student['id']]) && isset($studentMarkings[$student['id']][$typeID])) {
                     $points = $studentMarkings[$student['id']][$typeID];
                     $thisPercentage['points'] = $points;
                 } elseif (isset($student['id'])) {
                     $thisPercentage['points'] = 0;
                 }
             } else {
                 // check if there are points for this
                 // student-exerciseType combination
                 if (isset($student['id']) && isset($studentMarkings[$student['id']]) && isset($studentMarkings[$student['id']][$typeID])) {
                     // the user has points for this exercise type
                     $points = $studentMarkings[$student['id']][$typeID];
                     $maxPoints = $maxPointsByType[$typeID];
                     $percentage = $points / $maxPoints;
                     $percentageNeeded = $condition['percentage'];
                     $thisPercentage['points'] = $points;
                     $thisPercentage['maxPoints'] = $maxPoints;
                     $typeApproved = $percentage >= $percentageNeeded;
                     $allApproved = $allApproved && $typeApproved;
                     $thisPercentage['isApproved'] = $typeApproved;
                     $thisPercentage['percentage'] = round($percentage * 100, 2);
                 } elseif (isset($student['id'])) {
                     // there are no points for the user for this
                     // exercise type
                     $thisPercentage['percentage'] = 0;
                     $thisPercentage['points'] = 0;
                     $maxPoints = $maxPointsByType[$typeID];
                     $thisPercentage['maxPoints'] = $maxPoints;
                     $typeApproved = $maxPoints == 0;
                     $thisPercentage['isApproved'] = $typeApproved;
                     $allApproved = $allApproved && $typeApproved;
                 }
             }
             $student['percentages'][] = $thisPercentage;
         }
         $student['isApproved'] = $allApproved;
         $resultStudents[] = $student;
     }
     $students = $resultStudents;
     $this->flag = 1;
     $response['user'] = $this->userWithCourse($userid, $courseid);
     if (isset($students)) {
         $response['users'] = $students;
     }
     $response['minimumPercentages'] = array_values($approvalconditionsByType);
     $this->app->response->setBody(json_encode($response));
 }