function save1($myuserid) { $mineexists = 0; /*Existiert Question/Template schon?*/ $qdb = new EvaluationQuestionDB(); if (!$template_id) { $template_id = Request::option("template_id"); } if ($qdb->exists($template_id)) { $question = new EvaluationQuestion($template_id, NULL, EVAL_LOAD_ALL_CHILDREN); if ($question->getParentID() != $myuserid) { $foreign = TRUE; $question = new EvaluationQuestion(); $question->setParentID($myuserid); } else { $overwrite = 1; //$question->delete(); //$question = new EvaluationQuestion(); //$template_id=$question->getObjectID(); } } else { $question = new EvaluationQuestion(); } /*Get Vars ----------------------------------------------------*/ $template_name = Request::get("template_name"); $template_type = Request::get("template_type"); $template_multiple = Request::get("template_multiple"); $template_add_num_answers = Request::option("template_add_num_answers"); $template_residual = Request::get("template_residual"); $template_residual_text = Request::get("template_residual_text"); $template_answers = Request::getArray("template_answers"); /*end: Get Vars -----------------------------------------------*/ $question->setParentID($myuserid); $question->setMultiplechoice($template_multiple); $question->setText(trim($template_name), YES); $question->setType($template_type); while ($answerrem = $question->getChild()) { $id = $answerrem->getObjectID(); $answerrem->delete(); $question->removeChildID($id); } $controlnumber = count($template_answers); $ausgleich = 0; for ($i = 0; $i < $controlnumber; $i++) { $text = $template_answers[$i]['text']; $answerID = $template_answers[$i]['answer_id']; $answer = new EvaluationAnswer(); if (!$foreign) { $answer->setObjectID($answerID); } $answer->setText(trim($text), YES); $question->addChild($answer); /*Anzahl der Antworten bei Polskalen anpassen ------------------------*/ if ($template_type == EVALQUESTION_TYPE_POL && $i == 0) { $answerdiff = $controlnumber - $template_add_num_answers; if ($template_residual) { //echo "Hust<br>"; //$answerdiff; } if ($answerdiff > 0) { /*differenz abziehen => answers überspringen*/ $i = $i + $answerdiff; $ausgleich = $ausgleich - $answerdiff; } while ($answerdiff < 0) { $ausgleich = $ausgleich + 1; $answer = new EvaluationAnswer(); $answer->setText(""); $answer->setParentID($question->getObjectID()); $answer->setPosition($i + $ausgleich); $answer->setValue($i + 1 + $ausgleich); $question->addChild($answer); $answerdiff++; } } /*end: Polskala antworten angleichen ----------------------------------*/ } /*create residual category-----------------------------------------------*/ if ($template_residual) { $answer = new EvaluationAnswer(); $answer->setResidual($template_residual); $answer->setText(trim($template_residual_text), QUOTED); $answer->setParentID($question->getObjectID()); $answer->setPosition($i + $ausgleich + 1); $answer->setValue(-1); $question->addChild($answer); } /*object HIER NOCH NICHT in db speichern! */ // $question->save(); if (!$overwrite) { $db = new EvaluationQuestionDB(); $lib = new EvalTemplateGUI(); $lib->setUniqueName($question, $db, $myuserid, YES); } if ($question->isError()) { EvalCommon::showErrorReport($question, _("Fehler beim Speichern.")); } return $question; }