diff --git a/locale/de_DE/LC_MESSAGES/The Legend of Z.mo b/locale/de_DE/LC_MESSAGES/The Legend of Z.mo index adab17a1..5a65b956 100644 Binary files a/locale/de_DE/LC_MESSAGES/The Legend of Z.mo and b/locale/de_DE/LC_MESSAGES/The Legend of Z.mo differ diff --git a/locale/de_DE/LC_MESSAGES/The Legend of Z.po b/locale/de_DE/LC_MESSAGES/The Legend of Z.po index 36ed23e0..c8f9d2b4 100644 --- a/locale/de_DE/LC_MESSAGES/The Legend of Z.po +++ b/locale/de_DE/LC_MESSAGES/The Legend of Z.po @@ -1,8 +1,8 @@ msgid "" msgstr "" "Project-Id-Version: The Legend of Z\n" -"POT-Creation-Date: 2014-07-11 11:53+0100\n" -"PO-Revision-Date: 2014-07-11 11:57+0100\n" +"POT-Creation-Date: 2014-07-31 10:52+0100\n" +"PO-Revision-Date: 2014-07-31 11:00+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: de_DE\n" @@ -63,7 +63,7 @@ msgstr "Neuer Lösungsvorschlag" msgid "Character submission approved" msgstr "Lösungsvorschlag bewertet" -#: controllers/QuestsController.inc:1227 +#: controllers/QuestsController.inc:1284 #: questtypes/submit/html/submission.tpl:30 #: views/html/achievements/conditions.tpl:54 #: views/html/achievements/conditions.tpl:121 views/html/quests/quest.tpl:54 @@ -206,6 +206,54 @@ msgstr "Kommentar" msgid "unsolved" msgstr "Leider falsch!" +#: questtypes/textinput/html/edittask (Kopie).tpl:3 +#: questtypes/textinput/html/edittask.tpl:24 +msgid "Text" +msgstr "Text" + +#: questtypes/textinput/html/edittask (Kopie).tpl:6 +#, php-format +msgid "Use %s for marking field positions" +msgstr "Benutze %s zum Markieren von Feldpositionen" + +#: questtypes/textinput/html/edittask (Kopie).tpl:8 +msgid "edit text" +msgstr "Text bearbeiten" + +#: questtypes/textinput/html/edittask (Kopie).tpl:12 +#: questtypes/textinput/html/edittask.tpl:29 +msgid "Fields" +msgstr "Felder" + +#: questtypes/textinput/html/edittask (Kopie).tpl:37 +msgid "edit fields" +msgstr "Felder bearbeiten" + +#: questtypes/textinput/html/edittask (Kopie).tpl:41 +#: questtypes/textinput/html/edittask.tpl:44 +#: views/html/achievements/conditions.tpl:151 +#: views/html/achievements/create.tpl:109 views/html/achievements/edit.tpl:112 +#: views/html/charactergroupsquests/manage.tpl:66 +#: views/html/charactertypes/edit.tpl:124 views/html/library/edit.tpl:46 +#: views/html/library/edit.tpl:86 views/html/quests/edit.tpl:112 +#: views/html/users/edit.tpl:105 views/html/xplevels/manage.tpl:49 +msgid "save" +msgstr "speichern" + +#: questtypes/textinput/html/edittask.tpl:10 +#: questtypes/textinput/html/edittask.tpl:12 +msgid "Regex invalid" +msgstr "Der reguläre Ausdruck ist ungültig" + +#: questtypes/textinput/html/edittask.tpl:25 +msgid "Add field" +msgstr "Feld hinzufügen" + +#: questtypes/textinput/html/edittask.tpl:43 +#: questtypes/textinput/html/edittask.tpl:46 +msgid "Preview" +msgstr "Vorschau" + #: views/ajax/quests/index.tpl:9 views/html/quests/create.tpl:79 #: views/html/quests/edit.tpl:82 views/html/quests/index.tpl:27 #: views/html/quests/index.tpl:59 @@ -374,7 +422,7 @@ msgid "Group by" msgstr "Gruppiert über" #: views/html/achievements/conditions.tpl:69 -#: views/html/achievements/conditions.tpl:136 views/html/html.tpl:79 +#: views/html/achievements/conditions.tpl:136 views/html/html.tpl:80 msgid "Achievement" msgstr "Achievement" @@ -399,15 +447,6 @@ msgstr "löschen" msgid "New condition" msgstr "Neue Bedingung" -#: views/html/achievements/conditions.tpl:151 -#: views/html/achievements/create.tpl:109 views/html/achievements/edit.tpl:112 -#: views/html/charactergroupsquests/manage.tpl:66 -#: views/html/charactertypes/edit.tpl:124 views/html/library/edit.tpl:46 -#: views/html/library/edit.tpl:86 views/html/users/edit.tpl:105 -#: views/html/xplevels/manage.tpl:49 -msgid "save" -msgstr "speichern" - #: views/html/achievements/create.tpl:11 msgid "Create Achievement" msgstr "Achievement erstellen" @@ -694,7 +733,7 @@ msgstr "Spiele weiter, um diesen geheimen Erfolg freizuschalten" #: views/html/charactergroupsquests/edit.tpl:94 #: views/html/characters/edit.tpl:108 views/html/charactertypes/index.tpl:24 #: views/html/questgroups/edit.tpl:64 views/html/questgroups/edittexts.tpl:24 -#: views/html/questgroupshierarchy/edit.tpl:57 views/html/quests/edit.tpl:111 +#: views/html/questgroupshierarchy/edit.tpl:57 #: views/html/quests/edittexts.tpl:63 views/html/seminaries/edit.tpl:77 msgid "edit" msgstr "bearbeiten" @@ -1331,11 +1370,11 @@ msgstr "oder" msgid "register yourself" msgstr "registriere dich" -#: views/html/html.tpl:89 +#: views/html/html.tpl:90 msgid "Level-up" msgstr "Levelaufstieg" -#: views/html/html.tpl:91 views/html/html.tpl:93 +#: views/html/html.tpl:92 views/html/html.tpl:94 #, php-format msgid "You have reached level %d" msgstr "Du hast Level %d erreicht" @@ -1634,6 +1673,14 @@ msgstr "Soll die Quest „%s“ wirklich gelöscht werden?" msgid "Edit Quest" msgstr "Quest bearbeiten" +#: views/html/quests/edit.tpl:111 +msgid "edit task" +msgstr "Aufgabe bearbeiten" + +#: views/html/quests/edittask.tpl:8 +msgid "Edit Quest task" +msgstr "Questaufgabe bearbeiten" + #: views/html/quests/edittexts.tpl:8 views/html/quests/quest.tpl:12 msgid "Edit Quest texts" msgstr "Questtexte bearbeiten" @@ -2015,9 +2062,6 @@ msgstr "Hallo %s" #~ msgid "Character Groups Quests" #~ msgstr "Gruppenquests" -#~ msgid "Skip task" -#~ msgstr "Aufgabe überspringen" - #~ msgid "continue" #~ msgstr "fortfahren" diff --git a/questtypes/textinput/TextinputQuesttypeController.inc b/questtypes/textinput/TextinputQuesttypeController.inc index d073b162..aa139b46 100644 --- a/questtypes/textinput/TextinputQuesttypeController.inc +++ b/questtypes/textinput/TextinputQuesttypeController.inc @@ -19,6 +19,12 @@ */ class TextinputQuesttypeController extends \hhu\z\controllers\QuesttypeController { + /** + * Required components + * + * @var array + */ + public $components = array('validation'); @@ -163,6 +169,125 @@ $this->set('task', $task); $this->set('fields', $fields); } + + + /** + * Action: edittask. + * + * Edit the task of a Quest. + * + * @param array $seminary Current Seminary data + * @param array $questgroup Current Questgroup data + * @param array $quest Current Quest data + */ + public function edittask($seminary, $questgroup, $quest) + { + // Get Task + $task = $this->Textinput->getTextinputQuest($quest['id']); + $text = $task['text']; + + // Get fields + $fields = $this->Textinput->getTextinputFields($quest['id']); + + // Get field sizes + $fieldSizes = $this->Textinput->getFieldSizes(); + + // Values + $validations = array(); + + // Save data + if($this->request->getRequestMethod() == 'POST') + { + if(!is_null($this->request->getPostParam('preview')) || !is_null($this->request->getPostParam('save'))) + { + // Get params and validate them + if(is_null($this->request->getPostParam('text'))) { + throw new \nre\exceptions\ParamsNotValidException('text'); + } + $text = $this->request->getPostParam('text'); + if(is_null($this->request->getPostParam('fields'))) { + throw new \nre\exceptions\ParamsNotValidException('fields'); + } + $fields = $this->request->getPostParam('fields'); + $fields = array_values($fields); + $fieldIndex = 0; + foreach($fields as &$field) + { + // Validate regex + $regex = $field['regex']; + //$fieldValidation = $this->Validation->validate($regex, \nre\configs\AppConfig::$validation['regex']); + $fieldValidation = @preg_match($regex, '') !== false; + if($fieldValidation !== true) + { + if(!array_key_exists($fieldIndex, $validations) || !is_array($validations[$fieldIndex])) { + $validations[$fieldIndex] = array(); + } + $validations[$fieldIndex] = $this->Validation->addValidationResults($validations[$fieldIndex], 'regex', $fieldValidation); + } + + // Validate size + foreach($fieldSizes as $sizeIndex => &$size) + { + if($size['size'] == $field['size']) + { + $field['sizeIndex'] = $sizeIndex; + break; + } + } + if(!array_key_exists('sizeIndex', $field)) { + throw new \nre\exceptions\ParamsNotValidException($fieldIndex); + } + + $fieldIndex++; + } + + // Save and redirect + if(!is_null($this->request->getPostParam('save')) && empty($validations)) + { + // Save text + $this->Textinput->setTextForQuest( + $this->Auth->getUserId(), + $quest['id'], + $text + ); + + // Save field + foreach($fields as $index => &$field) + { + // Add regex modifiers + $modifiers = substr($field['regex'], strrpos($field['regex'], $field['regex'][0]) + 1); + if(strpos($modifiers, 'u') === false) { + $field['regex'] .= 'u'; + } + + // Save field + $this->Textinput->setFieldForText( + $quest['id'], + $index + 1, + $fieldSizes[$field['sizeIndex']]['id'], + $field['regex'] + ); + } + + // Redirect + $this->redirect($this->linker->link(array('quest', $seminary['url'], $questgroup['url'], $quest['url']), 1)); + } + } + } + + // Set colors for fields + foreach($fields as &$field) { + $field['color'] = str_pad(sprintf('%x%x%x', rand(0,255), rand(0,255), rand(0,255)), 6, 9); + } + + + // Pass data to view + $this->set('task', $task); + $this->set('text', $text); + $this->set('fields', $fields); + $this->set('fieldSizes', $fieldSizes); + $this->set('validations', $validations); + } diff --git a/questtypes/textinput/TextinputQuesttypeModel.inc b/questtypes/textinput/TextinputQuesttypeModel.inc index 0960fb3f..daf0edde 100644 --- a/questtypes/textinput/TextinputQuesttypeModel.inc +++ b/questtypes/textinput/TextinputQuesttypeModel.inc @@ -112,6 +112,109 @@ return ''; } + + + /** + * Set the text for a Quest and correct fields count. + * + * @param int $userId ID of user setting text + * @param int $questId ID of Quest to set text for + * @param string $text Text for Quset + */ + public function setTextForQuest($userId, $questId, $text) + { + $this->db->setAutocommit(false); + try { + // Set text + $this->db->query( + 'INSERT INTO questtypes_textinput '. + '(quest_id, created_user_id, text) '. + 'VALUES '. + '(?, ?, ?) '. + 'ON DUPLICATE KEY UPDATE '. + 'text = ?', + 'iiss', + $questId, + $userId, + $text, + $text + ); + + // Count fields + $fieldCount = substr_count($text, '[textinput]'); + + // Remove fields + $this->db->query( + 'DELETE FROM questtypes_textinput_fields '. + 'WHERE questtypes_textinput_quest_id = ? AND number > ?', + 'ii', + $questId, + $fieldCount + ); + + // Add fields + for($i=1; $i<=$fieldCount; $i++) + { + $this->db->query( + 'INSERT IGNORE INTO questtypes_textinput_fields '. + '(questtypes_textinput_quest_id, number, regex) '. + 'VALUES '. + '(?, ?, ?) ', + 'iis', + $questId, + $i, + '' + ); + } + + $this->db->commit(); + } + catch(\Exception $e) { + $this->db->rollback(); + $this->db->setAutocommit(true); + throw $e; + } + + $this->db->setAutocommit(true); + } + + + /** + * Set values for a field of a text. + * + * @param int $questId ID of Quest to set field for + * @param int $number Field number + * @param int $sizeId ID of field size + * @param string $regex RegEx for field + */ + public function setFieldForText($questId, $number, $sizeId, $regex) + { + $this->db->query( + 'UPDATE questtypes_textinput_fields '. + 'SET questtypes_textinput_fieldsize_id = ?, regex = ? '. + 'WHERE questtypes_textinput_quest_id = ? AND number = ?', + 'isii', + $sizeId, + $regex, + $questId, + $number + ); + } + + + /** + * Get all registered field sizes. + * + * @return List of field sizes + */ + public function getFieldSizes() + { + return $this->db->query( + 'SELECT id, size '. + 'FROM questtypes_textinput_fieldsizes '. + 'ORDER BY size' + ); + } } diff --git a/questtypes/textinput/html/edittask.tpl b/questtypes/textinput/html/edittask.tpl new file mode 100644 index 00000000..e8413333 --- /dev/null +++ b/questtypes/textinput/html/edittask.tpl @@ -0,0 +1,105 @@ + + + +
+
+ +
+ +
+
+ + +
+ + +
+

+

+ + + + t(mb_substr($text, $posStart, $posEnd-$posStart, 'UTF-8'))?> + class="" /> + + + t(mb_substr($text, $posStart, mb_strlen($text, 'UTF-8')-$posStart, 'UTF-8'))?> +

+ + diff --git a/views/html/html.tpl b/views/html/html.tpl index 085111ea..40b021db 100644 --- a/views/html/html.tpl +++ b/views/html/html.tpl @@ -34,6 +34,7 @@ + diff --git a/www/js/misc.js b/www/js/misc.js new file mode 100644 index 00000000..8bc8a0dd --- /dev/null +++ b/www/js/misc.js @@ -0,0 +1,52 @@ +/** + * http://stackoverflow.com/questions/1064089/inserting-a-text-where-cursor-is-using-javascript-jquery/1064139#1064139 + */ +function getCaret(textareaId) +{ + var textarea = document.getElementById(textareaId); + var strPos = 0; + if(textarea.selectionStart || textarea.selectionStart == '0') { + strPos = textarea.selectionStart + } + else if(document.selection) + { + textarea.focus(); + var range = document.selection.createRange(); + range.moveStart('character', -textarea.value.length); + strPos = range.text.length; + } + else { + strPos = -1; + } + + return strPos; +} + + +function insertAtCaret(textareaId, caret, text) +{ + var textarea = document.getElementById(textareaId); + var scrollPos = textarea.scrollTop; + + var front = (textarea.value).substring(0, caret); + var back = (textarea.value).substring(caret, textarea.value.length); + textarea.value = front + text + back; + caret = caret + text.length; + + if(textarea.selectionStart || textarea.selectionStart == '0') + { + textarea.selectionStart = caret; + textarea.selectionEnd = caret; + textarea.focus(); + } + else if(document.selection) + { + textarea.focus(); + var range = document.selection.createRange(); + range.moveStart('character', -textarea.value.length); + range.moveStart('character', caret); + range.moveEnd('character', 0); + range.select(); + } + textarea.scrollTop = scrollPos; +}