set_error(Language::Get('main', 'noExercisePeriod', $langTemplate, array('startDate' => date('d.m.Y - H:i', $sheet['startDate'])))); } } else { set_error(Language::Get('main', 'noExercisePeriod', $langTemplate)); } $leaderId = $group['leader']['id']; foreach ($_POST['exercises'] as $key => $exercise) { $exerciseId = cleanInput($exercise['exerciseID']); $fileName = "file{$exerciseId}"; #region generate form-data $formdata = array(); if (isset($exercise['choices'])) { $formtext = $exercise['choices']; foreach ($formtext as $formId => $choiceData2) { $form = new Form(); $form->setFormId($formId); $form->setExerciseId($exerciseId); $choiceText = $choiceData2; $choices = array(); foreach ($choiceText as $tempKey => $choiceData) { if (trim($choiceData) === '') { continue; } $choice = new Choice(); $choice->SetText(htmlentities(htmlentities(htmlspecialchars_decode($choiceData)))); $choice->SetFormId($formId); $choices[] = $choice; } if ($choices !== null && $choices !== array()) { $form->setChoices($choices); $formdata[] = $form;
/** * Adds a form. * * Called when this component receives an HTTP POST request to * (/$pre)/form(/). */ public function addForm() { Logger::Log('starts POST AddForm', LogLevel::DEBUG); // decode the received choice data, as an object $insert = Form::decodeForm($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/AddForm.sql', array('object' => $in)); // checks the correctness of the query if ($result['status'] >= 200 && $result['status'] <= 299) { $queryResult = Query::decodeQuery($result['content']); // sets the new auto-increment id $obj = new Form(); $course = Course::ExtractCourse($queryResult[count($queryResult) - 1]->getResponse(), true); $obj->setFormId($course->getId() . '_' . $queryResult[count($queryResult) - 2]->getInsertId()); $res[] = $obj; $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 AddForm failed', LogLevel::ERROR); $this->_app->response->setStatus(isset($result['status']) ? $result['status'] : 409); $this->_app->response->setBody(Form::encodeForm($res)); $this->_app->stop(); } } if (!$arr && count($res) == 1) { $this->_app->response->setBody(Form::encodeForm($res[0])); } else { $this->_app->response->setBody(Form::encodeForm($res)); } }