Example #1
0
 /**
  * Wizard finished: we can create the course now. First store an empty,
  * invisible course for getting an ID. Then, iterate through steps and
  * set values from each step.
  * @return Course
  * @throws Exception
  */
 private function createCourse()
 {
     // Create a new (empty) course so that we get an ID.
     $course = new Course();
     $course->visible = 0;
     $course->store();
     // Each (required) step stores its own values at the course object.
     for ($i = 0; $i < sizeof($this->steps); $i++) {
         $step = $this->getStep($i);
         if ($step->isRequired($this->getValues())) {
             if ($stored = $step->storeValues($course, $this->getValues())) {
                 $course = $stored;
             } else {
                 $course = false;
                 break;
                 //throw new Exception(_('Die Daten aus Schritt ' . $i . ' konnten nicht gespeichert werden, breche ab.'));
             }
         }
     }
     // Check if "documents" module is activated and create "General" folder.
     $m = new Modules();
     if ($m->getStatus('documents', $course->id)) {
         $f = new DocumentFolder();
         $f->name = _('Allgemeiner Dateiordner');
         $f->description = _('Ablage für allgemeine Ordner und Dokumente der Veranstaltung');
         $f->range_id = $course->id;
         $f->seminar_id = $course->id;
         $f->user_id = $GLOBALS['user']->id;
         $f->permission = 7;
         $f->store();
     }
     // Cleanup session data.
     unset($_SESSION['coursewizard'][$this->temp_id]);
     return $course;
 }
Example #2
0
 /**
  * Create file or folder. To create a file just attach a file as multipart request.
  * If no file is attached, this will create a folder.
  *
  * @post /file/:folder_id
  * @param string $file_id : id of the folder to insert the file or folder to.
  *
  * @param string name : if set the document will have this name instead of the filename. For folders this attribute is mandatory.
  * @param string description : sets the description of the document or folder.
  */
 public function addFile($folder_id)
 {
     $parentFolder = $this->loadFolder($folder_id);
     if (!$parentFolder) {
         $this->error(404, 'folder does not exist');
     }
     if (is_array($this->data['_FILES']) && count($this->data['_FILES'])) {
         //fileupload
         $file = current($this->data['_FILES']);
         $GLOBALS['msg'] = '';
         validate_upload($file);
         if ($GLOBALS['msg']) {
             $this->error(400, decodeHTML(trim(substr($GLOBALS['msg'], 6), '§')));
         }
         if ($file['size']) {
             $document = array();
             foreach (words('name description protected') as $c) {
                 if (isset($this->data[$c])) {
                     $document[$c] = $this->data[$c];
                 }
             }
             $document['filename'] = strtolower($file['name']);
             $document['name'] = $document['name'] ?: $document['filename'];
             $document['user_id'] = $GLOBALS['user']->id;
             $document['author_name'] = get_fullname();
             $document['filesize'] = $file['size'];
             $document['autor_host'] = $_SERVER['REMOTE_ADDR'];
             $document['range_id'] = $parentFolder->id;
             $document['seminar_id'] = $parentFolder->seminar_id;
             $document = \StudipDocument::createWithFile($file['tmp_name'], $document);
             @unlink($file['tmp_name']);
         }
         if (!$document) {
             $this->error(400, 'could not create file');
         } else {
             $this->redirect('file/' . $document->getId(), 201, "ok");
         }
     } elseif ($this->data['name']) {
         //create folder
         $newFolder = new \DocumentFolder();
         $newFolder['range_id'] = $parentFolder['folder_id'];
         $newFolder['seminar_id'] = $parentFolder['seminar_id'];
         $newFolder['name'] = $this->data['name'];
         $newFolder['description'] = $this->data['description'];
         $newFolder['user_id'] = $GLOBALS['user']->id;
         $newFolder->store();
         $this->redirect('file/' . $newFolder->getId(), 201, "ok");
     } else {
         $this->error(400, 'name is missing');
     }
 }