Example #1
0
 /**
  * Adds a file.
  *
  * This function handles the request to the filesystem to store the file
  * as well as the reqest to the DBFile table to store the information
  * belongs to this file.
  *
  * @param string $database The link of the database.
  * @param string $filesystem The link of the filesystem.
  * @param array $header The header of the request.
  * @param array $file The file that should being deleted.
  *
  * @return array $file A file that represents the new information
  * which belongs to the added one. If there are an error, an empty array is returned.
  */
 public static function add($database, $filesystem, $path, $header, $file)
 {
     $displayName = $file->getDisplayName();
     //request to filesystem to save the file
     if ($file->getAddress() == null || $file->getHash() == null) {
         $answer = Request::routeRequest('POST', '/file' . $path, $header, File::encodeFile($file), $filesystem, 'file');
     } else {
         $answer = array();
         $answer['status'] = 201;
         $answer['content'] = File::encodeFile($file);
     }
     // check if file has been saved
     if ($answer['status'] >= 200 && $answer['status'] <= 299 && isset($answer['content'])) {
         $file = File::decodeFile($answer['content']);
         if ($file->getFileId() != null) {
             return $file;
         }
         //request to database file table to check if the file already exists
         /*$answer = Request::routeRequest( 
            'GET',
           '/file'.$path.'/hash/'.$file->getHash(),
            $header,
            '',
            $database,
            'file'
            );*/
         $answer = array('status' => 404);
         // ĂĽberspringt das Abfragen ĂĽber den Hash der Datei
         if ($answer['status'] < 200 || $answer['status'] > 299 || !isset($answer['content'])) {
             //if file does not exists, add it to db file table
             $answer = Request::routeRequest('POST', '/file' . $path, $header, File::encodeFile($file), $database, 'file');
             ///echo File::encodeFile($file);return;
             // check if file has been saved
             if ($answer['status'] >= 200 && $answer['status'] <= 299 && isset($answer['content'])) {
                 $returnFile = File::decodeFile($answer['content']);
                 $file->setFileId($returnFile->getFileId());
                 $file->setDisplayName($displayName);
                 return $file;
             } else {
                 // if file has not been saved return an empty file
                 return null;
             }
         } else {
             $returnFile = File::decodeFile($answer['content']);
             $file->setFileId($returnFile->getFileId());
             $file->setDisplayName($displayName);
             return $file;
         }
     } else {
         // if file has not been saved return an empty file
         return null;
     }
     return null;
 }
Example #2
0
            } else {
                $text .= '</tr>';
            }
        }
        $text .= '</table>';
        $pdf = Pdf::createPdf($text, 'L');
        $file = http_post_data($filesystemURI . '/pdf', Pdf::encodePdf($pdf), true);
        $file = File::decodeFile($file);
        $file->setDisplayName('conditions.pdf');
        $file = File::encodeFile($file);
    } elseif (isset($_GET['downloadConditionCsv'])) {
        $csv = Csv::createCsv($rows);
        $file = http_post_data($filesystemURI . '/csv', Csv::encodeCsv($csv), true);
        $file = File::decodeFile($file);
        $file->setDisplayName('conditions.csv');
        $file = File::encodeFile($file);
    }
    echo $file;
    exit(0);
}
if (isset($_GET['sortby'])) {
    $condition_data['sortby'] = $_GET['sortby'];
}
if (isset($_GET['sortId'])) {
    $condition_data['sortId'] = $_GET['sortId'];
}
// construct a new header
$h = Template::WithTemplateFile('include/Header/Header.template.html');
$h->bind($user_course_data);
$h->bind(array("name" => $user_course_data['courses'][0]['course']['name'], "notificationElements" => $notifications, "navigationElement" => $menu));
// construct a content element for setting exam paper conditions
Example #3
0
 /**
  * Loads all selected submissions as a zip file.
  *
  * Called when this component receives an HTTP GET request to
  * /submissions/exercisesheet/$sheetid/user/$userid.
  *
  * @param int $sheetid The id of the sheet of which the submissions should
  * be zipped.
  * @param int $userid The id of the user whose submissions should be zipped.
  *
  * @author Till Uhlig
  * @date 2014
  */
 public function loadSubmissionAsZip($sheetid, $userid)
 {
     $result = Request::routeRequest('GET', '/submission/group/user/' . $userid . '/exercisesheet/' . $sheetid . '/selected', $this->app->request->headers->all(), '', $this->_submission, 'submission');
     if ($result['status'] >= 200 && $result['status'] <= 299) {
         $submissions = Submission::decodeSubmission($result['content']);
         $files = array();
         foreach ($submissions as $submission) {
             $file = $submission->getFile();
             $file->setDisplayName($file->getDisplayName());
             $files[] = $file;
         }
         $result = Request::routeRequest('POST', '/zip/' . $sheetid . '.zip', $this->app->request->headers->all(), File::encodeFile($files), $this->_zip, 'zip');
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $this->app->response->setBody($result['content']);
             $this->app->response->setStatus(200);
             if (isset($result['headers']['Content-Type'])) {
                 $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
             }
             if (isset($result['headers']['Content-Disposition'])) {
                 $this->app->response->headers->set('Content-Disposition', $result['headers']['Content-Disposition']);
             }
             $this->app->stop();
         }
     }
     $this->app->response->setBody('');
     $this->app->response->setStatus(404);
     $this->app->stop();
 }
Example #4
0
 /**
  * Adds a process.
  *
  * Called when this component receives an HTTP POST request to
  * /process(/).
  */
 public function AddProcess()
 {
     $this->app->response->setStatus(201);
     $body = $this->app->request->getBody();
     $processes = Process::decodeProcess($body);
     // always been an array
     $arr = true;
     if (!is_array($processes)) {
         $processes = array($processes);
         $arr = false;
     }
     $res = array();
     foreach ($processes as $process) {
         // create process
         $method = 'POST';
         $URL = '/process';
         if ($process->getProcessId() !== null) {
             $method = 'PUT';
             $URL = '/process/' . $process->getProcessId();
         }
         $result = Request::routeRequest($method, $URL, array(), Process::encodeProcess($process), $this->_processorDb, 'process');
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             $queryResult = Process::decodeProcess($result['content']);
             if ($process->getProcessId() === null) {
                 $process->setProcessId($queryResult->getProcessId());
             }
             $res[] = $process;
         } else {
             $res[] = null;
             $this->app->response->setStatus(409);
             continue;
         }
         // create attachment
         $attachments = $process->getAttachment();
         $process->setAttachment(array());
         foreach ($attachments as $attachment) {
             if ($attachment->getId() === null) {
                 $attachment->setExerciseId($process->getExercise()->getId());
                 $attachment->setProcessId($process->getProcessId());
                 // upload file
                 $result = Request::routeRequest('POST', '/file', array(), File::encodeFile($attachment->getFile()), $this->_file, 'file');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = File::decodeFile($result['content']);
                     $attachment->setFile($queryResult);
                 } else {
                     $attachment->setFile(null);
                     $this->app->response->setStatus(409);
                     continue;
                 }
                 // upload attachment
                 $attachment->setProcessId($process->getProcessId());
                 $result = Request::routeRequest('POST', '/attachment', array(), Attachment::encodeAttachment($attachment), $this->_attachment, 'attachment');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = Attachment::decodeAttachment($result['content']);
                     $attachment->setId($queryResult->getId());
                     $process->getAttachment()[] = $attachment;
                 } else {
                     $process->getAttachment()[] = null;
                     $this->app->response->setStatus(409);
                     continue;
                 }
             }
         }
         // create workFiles
         $workFiles = $process->getWorkFiles();
         $process->setWorkFiles(array());
         foreach ($workFiles as $workFile) {
             if ($workFile->getId() === null) {
                 $workFile->setExerciseId($process->getExercise()->getId());
                 $workFile->setProcessId($process->getProcessId());
                 // upload file
                 $result = Request::routeRequest('POST', '/file', array(), File::encodeFile($workFile->getFile()), $this->_file, 'file');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = File::decodeFile($result['content']);
                     $workFile->setFile($queryResult);
                 } else {
                     $workFile->setFile(null);
                     $this->app->response->setStatus(409);
                     continue;
                 }
                 // upload attachment
                 $workFile->setProcessId($process->getProcessId());
                 $result = Request::routeRequest('POST', '/attachment', array(), Attachment::encodeAttachment($workFile), $this->_workFiles, 'attachment');
                 if ($result['status'] >= 200 && $result['status'] <= 299) {
                     $queryResult = Attachment::decodeAttachment($result['content']);
                     $workFile->setId($queryResult->getId());
                     $process->getWorkFiles()[] = $workFile;
                 } else {
                     $process->getWorkFiles()[] = null;
                     $this->app->response->setStatus(409);
                     continue;
                 }
             }
         }
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Process::encodeProcess($res[0]));
     } else {
         $this->app->response->setBody(Process::encodeProcess($res));
     }
 }
Example #5
0
            }
            // attachments
            if (isset($attachments[$exerciseId])) {
                foreach ($attachments[$exerciseId] as $attachment) {
                    if (isset($attachment['file']['address'])) {
                        $attachment['file']['displayName'] = "{$namesOfExercises[$exerciseId]}/A_{$attachment['file']['hash']}_{$attachment['file']['displayName']}";
                        $files[] = $attachment['file'];
                    }
                }
            }
        }
    }
    unset($attachments, $markings, $exercises);
    // sheetFile
    if (isset($sheet['sheetFile']['address'])) {
        $sheet['sheetFile']['displayName'] = "{$sheet['sheetFile']['displayName']}";
        $files[] = $sheet['sheetFile'];
    }
    // sampleSolution
    if (isset($sheet['sampleSolution']['address'])) {
        $sheet['sampleSolution']['displayName'] = "{$sheet['sampleSolution']['displayName']}";
        $files[] = $sheet['sampleSolution'];
    }
    $fileString = json_encode($files);
    $zipfile = http_post_data($filesystemURI . '/zip', $fileString, true);
    $zipfile = File::decodeFile($zipfile);
    $zipfile->setDisplayName('markings.zip');
    $zipfile = File::encodeFile($zipfile);
    echo $zipfile;
    exit(0);
}
Example #6
0
 /**
  * Adds a new marking.
  *
  * Called when this component receives an HTTP POST request to
  * /marking(/).
  * The request body should contain a JSON object representing the new marking.
  *
  * @author Till Uhlig
  * @date 2014
  */
 public function addMarking()
 {
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $markings = Marking::decodeMarking($body);
     $this->app->response->setStatus(201);
     // always been an array
     $arr = true;
     if (!is_array($markings)) {
         $markings = array($markings);
         $arr = false;
     }
     // this array contains the inserted objects
     $res = array();
     foreach ($markings as $marking) {
         if ($marking->getDate() === null) {
             $marking->setDate(time());
         }
         $file = $marking->getFile();
         if (!isset($file)) {
             $file = new File();
         }
         if ($file->getTimeStamp() === null) {
             $file->setTimeStamp(time());
         }
         // upload file to filesystem
         $result = Request::routeRequest('POST', '/file', $this->app->request->headers->all(), File::encodeFile($file), $this->_file, 'file');
         // checks the correctness of the query
         if ($result['status'] >= 200 && $result['status'] <= 299) {
             // file is uploaded
             $newFile = File::decodeFile($result['content']);
             $file->setAddress($newFile->getAddress());
             $file->setHash($newFile->getHash());
             $file->setFileId($newFile->getFileId());
             $file->setBody(null);
             $marking->setFile($file);
             // upload marking to database
             if ($marking->getId() === null) {
                 $result = Request::routeRequest('POST', '/marking', $this->app->request->headers->all(), Marking::encodeMarking($marking), $this->_marking, 'marking');
             } else {
                 $result = Request::routeRequest('PUT', '/marking/marking/' . $marking->getId(), $this->app->request->headers->all(), Marking::encodeMarking($marking), $this->_marking, 'marking');
             }
             if ($result['status'] >= 200 && $result['status'] <= 299) {
                 // marking is uploaded
                 $newmarking = Marking::decodeMarking($result['content']);
                 if (is_array($newmarking)) {
                     $newmarking = $newmarking[0];
                 }
                 if ($newmarking->getId() !== null) {
                     $marking->setId($newmarking->getId());
                 }
                 $res[] = $marking;
                 if (isset($result['headers']['Content-Type'])) {
                     $this->app->response->headers->set('Content-Type', $result['headers']['Content-Type']);
                 }
             } else {
                 Logger::Log('POST AddMarking failed', LogLevel::ERROR);
                 $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
                 $this->app->response->setBody(Marking::encodeMarking($res));
                 $this->app->stop();
             }
         } else {
             Logger::Log('POST AddMarking failed', LogLevel::ERROR);
             $this->app->response->setStatus(isset($result['status']) ? $result['status'] : 409);
             $this->app->response->setBody(Marking::encodeMarking($res));
             $this->app->stop();
         }
     }
     if (!$arr && count($res) == 1) {
         $this->app->response->setBody(Marking::encodeMarking($res[0]));
     } else {
         $this->app->response->setBody(Marking::encodeMarking($res));
     }
 }
Example #7
0
 /**
  * Adds an attachment.
  *
  * Called when this component receives an HTTP POST request to
  * /attachment(/).
  * The request body should contain a JSON object representing the
  * attachment's attributes.
  */
 public function addAttachment()
 {
     $header = $this->app->request->headers->all();
     $body = $this->app->request->getBody();
     $fileObjects = Attachment::decodeAttachment($body);
     // always been an array
     $arr = true;
     if (!is_array($fileObjects)) {
         $fileObjects = array($fileObjects);
         $arr = false;
     }
     $res = array();
     $files = array();
     foreach ($fileObjects as $fileObject) {
         $files[] = $fileObject->getFile();
     }
     //add the Files
     $result = Request::routeRequest('POST', '/file', array(), File::encodeFile($files), $this->_postFile, 'file');
     $tempFiles = File::decodeFile($result['content']);
     // checks the correctness of the query
     if ($result['status'] === 201 && isset($result['content'])) {
         // upload files
         $countObjects = count($fileObjects);
         for ($i = 0; $i < $countObjects; $i++) {
             if ($tempFiles[$i]->getStatus() === 201) {
                 $fileObjects[$i]->setFile($tempFiles[$i]);
                 if ($files[$i] !== null) {
                     $files[$i]->setStatus(201);
                 }
             } else {
                 $fileObjects[$i]->setStatus(409);
                 $fileObjects[$i]->addMessage("Die Datei konnte nicht gespeichert werden.");
                 if ($files[$i] !== null) {
                     $files[$i]->setBody();
                 }
             }
         }
     } else {
         $this->app->response->setStatus(409);
         $this->app->response->setBody(Attachment::encodeAttachment(new Attachment()));
         $this->app->stop();
     }
     // upload attachments
     $result = Request::routeRequest('POST', '/attachment', array(), Attachment::encodeAttachment($fileObjects), $this->_postAttachment, 'attachment');
     if ($result['status'] === 201 && isset($result['content'])) {
         $tempAttachments = Attachment::decodeAttachment($result['content']);
         $countObjects = count($fileObjects);
         for ($i = 0; $i < $countObjects; $i++) {
             $fileObjects[$i]->setStatus($tempAttachments[$i]->getStatus());
             $fileObjects[$i]->addMessages($tempAttachments[$i]->getMessages());
             if ($tempAttachments[$i]->getStatus() !== 201) {
                 $fileObjects[$i]->addMessage('Anhang konnte nicht erstellt werden.');
                 $fileObjects[$i]->getFile()->setBody();
             } else {
                 $fileObjects[$i]->setId($tempAttachments[$i]->getId());
             }
             $res[] = $fileObjects[$i];
         }
     } else {
         $this->app->response->setStatus(409);
         $this->app->response->setBody(Attachment::encodeAttachment(new Attachment()));
         $this->app->stop();
     }
     if (!$arr && count($res) == 1) {
         $res = $res[0];
     }
     $this->app->response->setBody(Attachment::encodeAttachment($res));
     $this->app->response->setStatus(201);
 }
Example #8
0
 public function generateTutorArchive($userid, $sheetid, $markings, $withNames = false)
 {
     $multiRequestHandle = new Request_MultiRequest();
     //request to database to get the exercise sheets
     $handler = Request_CreateRequest::createCustom('GET', $this->_getExercise[0]->getAddress() . '/exercise/exercisesheet/' . $sheetid, array(), "");
     $multiRequestHandle->addRequest($handler);
     $handler = Request_CreateRequest::createCustom('GET', $this->_getGroup[0]->getAddress() . '/group/exercisesheet/' . $sheetid, array(), "");
     $multiRequestHandle->addRequest($handler);
     $answer = $multiRequestHandle->run();
     if (count($answer) < 2 || !isset($answer[0]['status']) || $answer[0]['status'] != 200 || !isset($answer[0]['content']) || !isset($answer[1]['status']) || $answer[1]['status'] != 200 || !isset($answer[1]['content'])) {
         return array('status' => 404, 'content' => '');
     }
     $exercises = json_decode($answer[0]['content'], true);
     $groups = json_decode($answer[1]['content'], true);
     $count = 0;
     //an array to descripe the subtasks
     $alphabet = range('a', 'z');
     $secondRow = array();
     $sortedMarkings = array();
     $rows = array();
     $exerciseIdWithExistingMarkings = array();
     $namesOfExercises = array();
     $ExerciseData = array();
     $ExerciseData['userId'] = $userid;
     $ExerciseData['markings'] = array();
     //exercises with informations of marking and submissions
     //sorted by exercise ID and checked of existence
     foreach ($markings as $marking) {
         if (!isset($marking['submission']['selectedForGroup']) || !$marking['submission']['selectedForGroup']) {
             continue;
         }
         $submission = $marking['submission'];
         $id = $submission['exerciseId'];
         $sortedMarkings[$id][] = $marking;
         if (!in_array($id, $exerciseIdWithExistingMarkings)) {
             $exerciseIdWithExistingMarkings[] = $id;
         }
     }
     $defaultOrder = array('ID', 'NAME', 'USERNAME', 'POINTS', 'MAXPOINTS', 'OUTSTANDING', 'STATUS', 'TUTORCOMMENT', 'STUDENTCOMMENT', 'FILE');
     $courseid = null;
     $count = null;
     foreach ($exercises as $key => $exercise) {
         if ($courseid === null) {
             $courseid = $exercise['courseId'];
         }
         $exerciseId = $exercise['id'];
         if ($count === null || $exercises[$count]['link'] != $exercise['link']) {
             $count = $key;
             $namesOfExercises[$exerciseId] = 'Aufgabe_' . $exercise['link'];
             $subtask = 0;
         } else {
             $subtask++;
             $namesOfExercises[$exerciseId] = 'Aufgabe_' . $exercise['link'] . $alphabet[$subtask];
             $namesOfExercises[$exercises[$count]['id']] = 'Aufgabe_' . $exercises[$count]['link'] . $alphabet[0];
         }
     }
     //formating, create the layout of the CSV-file for the tutor
     //first two rows of an exercise are the heads of the table
     foreach ($exercises as $exercise) {
         if (!isset($exercise['id'])) {
             continue;
         }
         $exerciseId = $exercise['id'];
         // adds the exercise name
         $firstRow = array();
         $firstRow[] = '--' . $namesOfExercises[$exerciseId];
         //formating, write known informations of the markings in the CSV-file
         //after the second row to each exercise
         if (in_array($exerciseId, $exerciseIdWithExistingMarkings)) {
             $tempRows = array();
             $collumns = array('ID', 'POINTS', 'MAXPOINTS', 'OUTSTANDING', 'STATUS', 'TUTORCOMMENT', 'STUDENTCOMMENT', 'FILE');
             foreach ($sortedMarkings[$exerciseId] as $key => $marking) {
                 $row = array();
                 //MarkingId
                 if (!isset($marking['id'])) {
                     continue;
                 }
                 $row['ID'] = isset($marking['id']) ? $marking['id'] : null;
                 $ExerciseData['markings'][$marking['id']] = array();
                 $ExerciseData['markings'][$marking['id']]['sheetId'] = $exercise['sheetId'];
                 $ExerciseData['markings'][$marking['id']]['courseId'] = $exercise['courseId'];
                 $ExerciseData['markings'][$marking['id']]['exerciseId'] = $exerciseId;
                 // Username + Name
                 if ($withNames && isset($marking['submission']['studentId'])) {
                     foreach ($groups as $group) {
                         $user = array_merge(array($group['leader']), isset($group['members']) ? $group['members'] : array());
                         $found = false;
                         foreach ($user as $us) {
                             if ($us['id'] == $marking['submission']['studentId']) {
                                 $member = $us;
                                 $row['NAME'] = (isset($member['firstName']) ? $member['firstName'] : '-') . ' ' . (isset($member['lastName']) ? $member['lastName'] : '');
                                 $collumns[] = 'NAME';
                                 $row['USERNAME'] = isset($member['userName']) ? $member['userName'] : '';
                                 $collumns[] = 'USERNAME';
                                 $row['STUDENTID'] = isset($member['id']) ? $member['id'] : null;
                                 $ExerciseData['markings'][$marking['id']]['studentId'] = isset($member['id']) ? $member['id'] : null;
                                 $ExerciseData['markings'][$marking['id']]['leaderId'] = isset($group['leader']['id']) ? $group['leader']['id'] : null;
                                 $found = true;
                                 break;
                             }
                         }
                         if ($found) {
                             break;
                         }
                     }
                 }
                 //Points
                 $row['POINTS'] = isset($marking['points']) ? $marking['points'] : '0';
                 //MaxPoints
                 $row['MAXPOINTS'] = isset($exercise['maxPoints']) ? $exercise['maxPoints'] : '0';
                 $ExerciseData['markings'][$marking['id']]['maxPoints'] = isset($exercise['maxPoints']) ? $exercise['maxPoints'] : '0';
                 $ExerciseData['markings'][$marking['id']]['submissionId'] = $marking['submission']['id'];
                 //Outstanding
                 $row['OUTSTANDING'] = isset($marking['outstanding']) ? $marking['outstanding'] : '';
                 //Status
                 $row['STATUS'] = isset($marking['status']) ? $marking['status'] : '0';
                 //TutorComment
                 $row['TUTORCOMMENT'] = isset($marking['tutorComment']) ? $marking['tutorComment'] : '';
                 //StudentComment
                 if (isset($marking['submission'])) {
                     $submission = $marking['submission'];
                     $row['STUDENTCOMMENT'] = isset($submission['comment']) ? $submission['comment'] : '';
                 }
                 // file
                 $newFile = null;
                 $selectedFile = null;
                 if (isset($marking['submission']['file']['displayName'])) {
                     $fileInfo = pathinfo($marking['submission']['file']['displayName']);
                     $newFile = array_merge(array(), $marking['submission']['file']);
                     $selectedFile = 'submission';
                 }
                 $converted = false;
                 if (isset($marking['file']) && $marking['file'] !== array()) {
                     $newFile = array_merge(array(), $marking['file']);
                     $selectedFile = 'marking';
                 }
                 if ($selectedFile == 'submission') {
                     if (!isset($newFile['mimeType']) || strpos($newFile['mimeType'], 'text/') !== false) {
                         // convert file to pdf
                         $newFileSend = array();
                         $newFileData = new File();
                         $data = "<h1>" . str_replace('_', ' ', strtoupper($namesOfExercises[$exerciseId])) . "</h1><hr><p></p>";
                         if (isset($marking['submission']['id'])) {
                             $data .= "Einsendungsnummer: {$marking['submission']['id']}\n";
                         }
                         /*if (isset($marking['id']))
                           $data.="Korrekturnummer: {$marking['id']}\n";*/
                         foreach ($groups as $group) {
                             $user = array_merge(array($group['leader']), isset($group['members']) ? $group['members'] : array());
                             $found = false;
                             foreach ($user as $us) {
                                 if ($us['id'] == $marking['submission']['studentId']) {
                                     $namen = array();
                                     foreach ($user as $member) {
                                         $namen[] = (isset($member['firstName']) ? $member['firstName'] : '-') . ' ' . (isset($member['lastName']) ? $member['lastName'] : '') . ' (' . (isset($member['userName']) ? $member['userName'] : '') . ')';
                                     }
                                     $namen = implode(', ', $namen);
                                     $data .= "Studenten: {$namen}\n";
                                     $found = true;
                                     break;
                                 }
                             }
                             if ($found) {
                                 break;
                             }
                         }
                         if (isset($marking['submission']['comment'])) {
                             $data .= "Kommentar: {$marking['submission']['comment']}\n";
                         }
                         $data .= "<pre>";
                         $newFileData->setBody($data, true);
                         $newFileSend[] = $newFileData;
                         if (isset($newFile)) {
                             $newFileSend[] = $newFile;
                             $newFileData = new File();
                             $newFileData->setBody("</pre>", true);
                             $newFileSend[] = $newFileData;
                             //echo File::encodeFile($newFileSend);//return;
                             $answer = Request::routeRequest('POST', '/temppdf/file/merge', array(), File::encodeFile($newFileSend), $this->_postPdf, 'pdf');
                             unset($newFileSend);
                             if ($answer['status'] == 201 && isset($answer['content'])) {
                                 $file = json_decode($answer['content'], true);
                                 /*$a = json_decode($answer['content'],true);
                                   $a['inp'] = htmlspecialchars($data);
                                   $a['submissionId'] = $marking['submission']['id'];
                                   $filesList[]=$a;*/
                                 $address = $file['address'];
                                 $newFile['address'] = $address;
                                 $newFile['displayName'] = $fileInfo['filename'] . '.pdf';
                                 $selectedFile = 'converted';
                                 $sortedMarkings[$exerciseId][$key]['submission']['file']['conv'] = $newFile;
                                 $converted = true;
                             }
                             unset($answer);
                         }
                     }
                 }
                 //$row[] = $namesOfExercises[$exerciseId].'/'.($converted ? 'K_' :'').$marking['id'].($fileInfo['extension']!='' ? '.'.$fileInfo['extension']:'');
                 //if (!$converted)
                 if (isset($newFile['displayName'])) {
                     if (isset($selectedFile) && isset($marking['submission']['file']['displayName']) && ($selectedFile == 'marking' || $selectedFile == 'converted') && $newFile['displayName'] == $marking['submission']['file']['displayName']) {
                         $newFile['displayName'] = 'K_' . $newFile['displayName'];
                     }
                     $row['FILE'] = $namesOfExercises[$exerciseId] . '/' . $marking['id'] . '/' . $newFile['displayName'];
                 }
                 unset($newFile);
                 $tempRows[] = $row;
             }
             //an empty row after an exercise
             $rows[] = $firstRow;
             $secondRow = array();
             $i = 0;
             foreach ($defaultOrder as $coll) {
                 if (in_array($coll, $collumns)) {
                     $secondRow[] = ($i == 0 ? '--' : '') . strtoupper($coll);
                     $i++;
                 }
             }
             $rows[] = $secondRow;
             foreach ($tempRows as $rr) {
                 $row = array();
                 foreach ($defaultOrder as $coll) {
                     if (in_array($coll, $collumns) && isset($rr[$coll])) {
                         $row[] = $rr[$coll];
                     } elseif (in_array($coll, $collumns)) {
                         $row[] = '';
                     }
                 }
                 $rows[] = $row;
             }
             $rows[] = array();
         }
     }
     //request to database to get the user name of the tutor for the
     //name of the CSV-file
     // create transaction ticket
     $transaction = Transaction::createTransaction(null, time() + 30 * 24 * 60 * 60, 'TutorCSV_' . $userid . '_' . $courseid, json_encode($ExerciseData));
     $result = Request::routeRequest('POST', '/transaction/exercisesheet/' . $sheetid, array(), Transaction::encodeTransaction($transaction), $this->_postTransaction, 'transaction');
     // checks the correctness of the query
     if (isset($result['status']) && isset($result['content']) && $result['status'] == 201) {
         $transaction = Transaction::decodeTransaction($result['content']);
         LTutor::generatepath($this->config['DIR']['temp']);
         $tempDir = $this->tempdir($this->config['DIR']['temp'], 'createCSV', $mode = 0775);
         ///$this->deleteDir($tempDir);
         $transactionRow = array($transaction->getTransactionId());
         array_unshift($rows, $transactionRow);
         //this is the true writing of the CSV-file named [tutorname]_[sheetid].csv
         $CSV = fopen($tempDir . '/Liste.csv', 'w');
         // $user['lastName'].'_'.
         foreach ($rows as $row) {
             fputcsv($CSV, $row, ';', '"');
         }
         fclose($CSV);
         //Create Zip
         $filesToZip = array();
         //Push all SubmissionFiles to an array in order of exercises
         foreach ($exercises as $exercise) {
             $exerciseId = $exercise['id'];
             if (in_array($exerciseId, $exerciseIdWithExistingMarkings)) {
                 $markings = $sortedMarkings[$exerciseId];
                 foreach ($markings as $marking) {
                     if (!isset($marking['submission']['selectedForGroup']) || !$marking['submission']['selectedForGroup']) {
                         continue;
                     }
                     $submission = $marking['submission'];
                     $newfile = isset($submission['file']) ? $submission['file'] : null;
                     if (isset($marking['file']['displayName'])) {
                         $newfile3 = $marking['file'];
                         $fileInfo = pathinfo($newfile3['displayName']);
                         if (isset($newfile['displayName']) && $newfile['displayName'] == $newfile3['displayName']) {
                             $newfile3['displayName'] = 'K_' . $newfile3['displayName'];
                         }
                         //$newfile3['displayName'] = $namesOfExercises[$exerciseId].'/K_'.$marking['id'].($fileInfo['extension']!='' ? '.'.$fileInfo['extension']:'');
                         $newfile3['displayName'] = $namesOfExercises[$exerciseId] . '/' . $marking['id'] . '/' . $newfile3['displayName'];
                         $filesToZip[] = $newfile3;
                     } elseif (isset($newfile['conv']['displayName'])) {
                         $newfile2 = $newfile['conv'];
                         $fileInfo = pathinfo($newfile2['displayName']);
                         if (isset($newfile['displayName']) && $newfile['displayName'] == $newfile2['displayName']) {
                             $newfile2['displayName'] = 'K_' . $newfile2['displayName'];
                         }
                         //$newfile2['displayName'] = $namesOfExercises[$exerciseId].'/K_'.$marking['id'].($fileInfo['extension']!='' ? '.'.$fileInfo['extension']:'');
                         $newfile2['displayName'] = $namesOfExercises[$exerciseId] . '/' . $marking['id'] . '/' . $newfile2['displayName'];
                         $filesToZip[] = $newfile2;
                     }
                     if (isset($newfile['displayName'])) {
                         $fileInfo = pathinfo($newfile['displayName']);
                         //$newfile['displayName'] = $namesOfExercises[$exerciseId].'/'.$marking['id'].($fileInfo['extension']!='' ? '.'.$fileInfo['extension']:'');
                         $newfile['displayName'] = $namesOfExercises[$exerciseId] . '/' . $marking['id'] . '/' . $newfile['displayName'];
                         $filesToZip[] = $newfile;
                     }
                 }
             }
         }
         //push the .csv-file to the array
         $path = $tempDir . '/Liste.csv';
         //$user['lastName'].'_'.
         $csvFile = new File();
         $csvFile->setDisplayName('Liste.csv');
         $csvFile->setBody(Reference::createReference($path));
         $filesToZip[] = $csvFile;
         ///unlink($path);
         ///$this->deleteDir(dirname($path));
         //request to filesystem to create the Zip-File
         $result = Request::routeRequest('POST', '/zip', array(), json_encode($filesToZip), $this->_postZip, 'zip');
         // checks the correctness of the query
         if ($result['status'] == 201) {
             $ff = File::decodeFile($result['content']);
             $ff->setDisplayName($transaction->getTransactionId() . '.zip');
             return array('status' => 201, 'content' => File::encodeFile($ff));
         } else {
             return array('status' => 409, 'content' => '');
         }
     } else {
         return array('status' => 409, 'content' => '');
     }
 }
Example #9
0
 /**
  * Deletes a file.
  *
  * Called when this component receives an HTTP DELETE request to
  * /file(/)
  */
 public function deleteFile($fileid)
 {
     Logger::Log('starts Delete deleteFile', LogLevel::DEBUG);
     $this->_app->response->setStatus(201);
     $fileObject = new File();
     $fileObject->setFileId($fileid);
     $res = null;
     if ($fileObject !== null && $fileObject !== array()) {
         $result = LFileHandler2::delete($this->_db, $this->_fs, array(), $fileObject);
     } else {
         $result = null;
     }
     if ($result !== null) {
         if (is_array($result)) {
             $result = $result[0];
         }
         $result->setStatus(201);
         $res = $result;
     } else {
         $result = new File();
         $result->getMessages()[] = "Die Datei konnte nicht gelöscht werden.";
         $result->setStatus(409);
         $res = $result;
         $this->_app->response->setStatus(409);
     }
     $this->_app->response->setBody(File::encodeFile($res));
 }