Enabled extra entry in the report form for "Keine Bewertung". See ticket #61.
authorphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 26 Oct 2010 20:03:54 +0000 (20:03 +0000)
committerphilipp <philipp@7aebc617-e5e2-0310-91dc-80fb5f6d2477>
Tue, 26 Oct 2010 20:03:54 +0000 (20:03 +0000)
git-svn-id: http://www.winterrodeln.org/svn/servermediawiki/trunk/extensions/wrreport@606 7aebc617-e5e2-0310-91dc-80fb5f6d2477

wrreport.body.php

index c94651cb3bc151bafa5ef564dc21e3770dab79c5..8df260245a2dbde5dfe36d523df9de7b1e89be4b 100644 (file)
@@ -40,6 +40,7 @@ function wrRecacheRegions() {
 ///
 /// All parameters have to be UTF-8 encoded.
 /// \param $page_title Name of the sledding run.
+/// \param $condition 1 to 5 for normal condition, 0 or NULL for missing condition and -1 for intentionally no condition.
 /// \return UTF-8 encoded HTML form
 function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_report = NULL, $condition = NULL, $description = NULL, $author_name = NULL, $page_title_list = NULL) {
        if ($page_title) $page_title = htmlspecialchars($page_title);
@@ -65,12 +66,15 @@ function wrReportFormRender($hide_save_button = TRUE, $page_title = NULL, $date_
        // Condition options
        $condition_options = '';
        global $wrConditions; // $wrConditions = array(1 => 'Sehr gut', 2 => 'Gut', 3 => utf8_encode('Mittelmäßig'), 4 => 'Schlecht', 5 => 'Geht nicht');
-       $condition_options .= utf8_encode('<option value="">(keine Beurteilung)</option>') . "\n";
+       $condition_options .= utf8_encode('<option value="0">(bitte auswählen)</option>') . "\n";
        foreach ($wrConditions as $condition_num => $condition_text) {
                $condition_options .= "<option value=\"$condition_num\"";
                if ($condition == $condition_num) $condition_options .= ' selected="selected"';
                $condition_options .= '>' . htmlspecialchars($condition_text) . "</option>\n";
        }
+       $condition_options .= utf8_encode('<option value="-1"');
+       if ($condition == -1) $condition_options .= ' selected="selected"';
+       $condition_options .= utf8_encode('>keine Beurteilung</option>') . "\n";
        $description_html = htmlspecialchars($description);
 
        // Buttons
@@ -640,6 +644,13 @@ class WrReport extends SpecialPage {
                        $condition = $wgRequest->getText('condition');
                        $description = $wgRequest->getText('description');
                        $author_name = $wgRequest->getText('author_name');
+                       
+                       // condition
+                       $condition = (int) $condition; // force to be nummeric. -1 ... "keine Bewertung", 0 ... "Bitte eingeben", 1 to 5 ... "Sehr gut" to "Geht nicht"
+                       if ($condition < -1 or $condition > 5) $condition = 0; // invalid condition: Tread like 0.
+                       $condition_sql = NULL;
+                       if ($condition >= 1 and $condition <= 5) $condition_sql = $condition;
+
                        if ($action == 'store') {
                                // page_id
                                $title = Title::newFromText($page_title);
@@ -652,11 +663,6 @@ class WrReport extends SpecialPage {
                                if ($author_userid == 0) $author_userid = NULL; // to store a NULL value in the database if no user is logged in instead of 0.
                                $author_username = $wgUser->getName();
 
-                               // condition
-                               $condition_int = (int) $condition;
-                               if ($condition_int >= 1 and $condition_int <= 5) $condition = $condition_int;
-                               else $condition = NULL;
-
                                // description
                                $description_html = wrCommonSandboxParse($description); // this variable is used for checks of the created code (below)
                                
@@ -671,7 +677,8 @@ class WrReport extends SpecialPage {
                                elseif (!$page_id) $errorMsg = utf8_encode('Die angegebene Seite wurde nicht gefunden.');
                                elseif (in_array($page_title, $wgWrReportBlackListAll)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit keine Rodelbahnberichte abgegeben werden.');
                                elseif (!$wgUser->isLoggedIn() && in_array($page_title, $wgWrReportBlackListStrangers)) $errorMsg = utf8_encode('Bei der angegebenen Rodelbahn dürfen derzeit nur angemeldete Benutzer Rodelbahnberichte abgebe.');
-                               elseif (!$condition && !$description) $errorMsg = utf8_encode('Es sind sowohl die Beschreibung als auch die Bewertung leer/nicht vergeben.');
+                               elseif ($condition == 0) $errorMsg = utf8_encode('Bitte einen Bahnzustand aus der Liste auswählen.');
+                               elseif ($condition <= 0 && !$description) $errorMsg = utf8_encode('Es sind sowohl die Beschreibung als auch die Bewertung sind leer.');
                                elseif (!$wgUser->isLoggedIn()) {
                                        if (!$description) $errorMsg = utf8_encode('Bitte bei der Beschreibung eine kurze Begründung für die Bewertung abgeben.');
                                        elseif (!(stripos($description, 'http') === FALSE)) $errorMsg = utf8_encode('Der Text "http" ist leider für nicht-angemeldete Benutzer nicht erlaubt, weil wir in der Vergangenheit Fälle hatten, bei denen externe Werbelinks automatisiert eingetragen wurden.');
@@ -686,7 +693,7 @@ class WrReport extends SpecialPage {
                                        $cond = 'condition';
                                        global $wgDBtype;
                                        if ($wgDBtype == "mysql") $cond = "`$cond`"; // "condition" is a reserved word in mysql
-                                       $sqlConditions = array('page_id' => $page_id, 'date_report' => $date_report, $cond => $condition, 'description' => $description, 'author_name' => $author_name);
+                                       $sqlConditions = array('page_id' => $page_id, 'date_report' => $date_report, $cond => $condition_sql, 'description' => $description, 'author_name' => $author_name);
                                        $res = $dbr->select('wrreport', 'id', $sqlConditions);
                                        if ($res->numRows() == 1) $errorMsg = utf8_encode('Der Rodelbahnbericht wurde bereits früher gespeichert.');
                                        $dbr->freeResult($res);
@@ -708,7 +715,7 @@ class WrReport extends SpecialPage {
                                                'date_report' => $date_report, 
                                                'date_entry' => date('c'),
                                                'date_invalid' => date('c', strtotime('+9 days')),
-                                               $cond => $condition,
+                                               $cond => $condition_sql,
                                                'description' => $description,
                                                'author_name' => $author_name,
                                                'author_ip' => $_SERVER['REMOTE_ADDR'],
@@ -734,7 +741,7 @@ class WrReport extends SpecialPage {
                                $row = array_fill_keys(wrReportGetColumnNames(), NULL);
                                $row['page_title'] = $page_title;
                                $row['date_report'] = $date_report;
-                               $row['condition'] = $condition;
+                               $row['condition'] = $condition_sql;
                                $row['description'] = $description;
                                $row['author_name'] = $author_name;
                                $wgOut->addHTML(wrReportTableRender2(array($row), $format, FALSE));