ソースを参照

Monsters in storage filter working. Team deletion button.

Iñigo Valentin 5 年 前
コミット
406b7eec83

+ 1 - 1
application/Constant.php

@@ -1816,7 +1816,7 @@
          * Default values for the monster filters.
          */
         const MONSTER = [
-            "ELEMENT" => 0,
+            "ELEMENT" => -1,
             "NAME" => "",
             "MIN_STARS" => 1,
             "MAX_STARS" => 6,

+ 5 - 0
application/Controller.php

@@ -110,6 +110,11 @@
                         action();
                         return;
                         break;
+                    case "DELETE_TEAM":
+                        require_once(PATH::ACTION . "delete_team.php");
+                        action();
+                        return;
+                        break;
                     case "SAVE_RUN_TEAM":
                         require_once(PATH::ACTION . "save_run_team.php");
                         action();

+ 45 - 0
application/action/delete_team.php

@@ -0,0 +1,45 @@
+<?php
+
+    /**
+     * File for the team creation action.
+     *
+     * Implements an action function to be called from the {@see Controller}.
+     * 
+     * @category Action
+     */
+
+    /**
+     * Logs the user out and redirects to the login page.
+     *
+     * Reads the POST parameters looking for the following KEYS:
+     *  uid
+     *  area_type
+     *  area
+     *  stage
+     *  difficulty
+     *  ids
+     *  name
+     *  description
+     * Validates the data and creates the team in the database.
+     * 
+     * @return int 0 on success, negative values on error.
+     * @category Action
+     * @global resource Database connection.
+     */
+    function action(){
+
+        global $db;
+
+        $player = filter_input(INPUT_POST, 'uid');
+        $id = filter_input(INPUT_POST, 'id');
+        $statement = $db->prepare('DELETE FROM team WHERE uid = :uid AND id = :id;');
+        $statement->bindValue(':uid', $player);
+        $statement->bindValue(':id', $id);
+        $res = $statement->execute();
+        $statement = $db->prepare('DELETE FROM team_unit WHERE team = :id;');
+        $statement->bindValue(':uid', $player);
+        $statement->bindValue(':id', $id);
+        $res = $statement->execute();
+        return 0;
+    }
+?>

+ 2 - 2
application/action/new_team.php

@@ -67,10 +67,10 @@
                 if ($stage < 0){
                     return -35;
                 }
-                if ($stage > 12 && ($stage == DUNGEON_ID::GIANTS_KEEP || $stage == DUNGEON_ID::DRAGONS_LAIR || $stage == DUNGEON_ID::NECROPOLIS)){
+                if ($stage > 12 && (DUNGEON_ID::GIANTS_KEEP == $area || DUNGEON_ID::DRAGONS_LAIR == $area || DUNGEON_ID::NECROPOLIS == $area)){
                     return -35;
                 }
-                if ($stage > 10 && $stage =! DUNGEON_ID::GIANTS_KEEP && $stage =! DUNGEON_ID::DRAGONS_LAIR && $stage != DUNGEON_ID::NECROPOLIS){
+                if ($stage > 10 && ($area != DUNGEON_ID::GIANTS_KEEP && $area != DUNGEON_ID::DRAGONS_LAIR && $area != DUNGEON_ID::NECROPOLIS)){
                     return -35;
                 }
                 $difficulty = null;

+ 5 - 2
application/page/Monsters_Page.php

@@ -86,6 +86,9 @@
             if (isset($_GET["in_storage"]) && $_GET["in_storage"] == "on"){
                 $this->filters["IN_STORAGE"] = true;
             }
+            else{
+                $this->filters["IN_STORAGE"] = false;
+            }
             if (isset($_GET["without_runes"]) && $_GET["without_runes"] == "on"){
                 $this->filters["WITHOUT_RUNES"] = true;
             }
@@ -119,8 +122,8 @@
             if ($this->filters["NAME"] != ""){
                 $s = $s . " AND unit IN (SELECT id FROM k_unit WHERE upper(name) LIKE '%" . strtoupper($this->filters["NAME"]) . "%') ";
             }
-            if ($this->filters["IN_STORAGE"]){
-                $s = $s . " AND building = " . BUILDING_ID::MONSTER_STORAGE;
+            if (!$this->filters["IN_STORAGE"]){
+                $s = $s . " AND building NOT IN (SELECT id FROM building WHERE building = " . BUILDING_ID::MONSTER_STORAGE . ") ";
             }
             if (!$this->filters["WITHOUT_RUNES"]){
                 $s = $s . " AND unit.id IN (SELECT DISTINCT assigned_to FROM rune) ";

+ 0 - 1
application/page/Report_Skillup_Page.php

@@ -190,7 +190,6 @@
                 CAST(lvl AS FLOAT) / CAST(max_lvl AS FLOAT),
                 max_lvl - lvl DESC
             ";
-            error_log($s);
             return $s;
         }
     }

+ 4 - 4
application/view/inc/filter_monsters.php

@@ -16,15 +16,15 @@
                 <span>Element:</span>
 <?php
                 $selected = Array("", "", "", "", "");
-                $selected[$filters["ELEMENT"]] = "selected";
+                $selected[$filters["ELEMENT"] - 1] = "selected";
 ?>
                 <select name='element'>
                     <option> </option>
                     <option value='<?=ELEMENT_ID::FIRE?>' <?=$selected[0]?>>Fire</option>
                     <option value='<?=ELEMENT_ID::WATER?>' <?=$selected[1]?>>Water</option>
-                    <option value='<?=ELEMENT_ID::WIND?>' <?=$selected[2]?>>Rare</option>
-                    <option value='<?=ELEMENT_ID::LIGHT?>' <?=$selected[3]?>>Hero</option>
-                    <option value='<?=ELEMENT_ID::DARK?>' <?=$selected[4]?>>Legend</option>
+                    <option value='<?=ELEMENT_ID::WIND?>' <?=$selected[2]?>>Wind</option>
+                    <option value='<?=ELEMENT_ID::LIGHT?>' <?=$selected[3]?>>Light</option>
+                    <option value='<?=ELEMENT_ID::DARK?>' <?=$selected[4]?>>Dark</option>
                 </select>
             </td>
             <td class='filter' id='filter_stars'>

+ 51 - 0
application/view/teams.php

@@ -78,6 +78,9 @@
                 }
             }
 
+            /**
+             * Parses the form data and generates the request to save a team.
+             */
             function saveTeam(){
                 if (selected_units > max_units){
                     alert('Too many units selected.');
@@ -193,6 +196,42 @@
                 xhttp.send(request);
 
             }
+            
+            /**
+             * Generates the request to delete a team.
+             *
+             * @param id Team id.
+             */
+            function deleteTeam(id){
+                if (!confirm("Permanently delete team?")){
+                    return
+                }
+                var request = 'uid=<?=$UID?>&id=' + id;
+                var xhttp = new XMLHttpRequest();
+                xhttp.onreadystatechange = function() {
+                    if (this.readyState == 4){ 
+                        if (this.status == 200){
+                            location.reload(); 
+                        }
+                        else{
+                            showError('Error deleting team. HTTP status ' + this.status)
+                        }
+                    }
+                };
+                xhttp.open("POST", "/action/delete_team/", true);
+                xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
+                xhttp.send(request);
+            }
+
+            /**
+             * GOpens the team edit for with the selected team.
+             *
+             * @param id Team id.
+             */
+            function editTeam(id){
+                // TODO
+                alert("Function not implemented yet. Please delete the team and recreate it.");
+            }
 
             /**
              * Searches a unit with the pattern entered in the 'new_unit_id'
@@ -682,6 +721,9 @@
                         <th>
                             Units
                         </th>
+                        <th>
+                            Actions
+                        </th>
                     </tr>
 <?php
                     $odd = "odd";
@@ -733,6 +775,15 @@
                                 }
 ?>
                             </td>
+                            <td class='action <?=$odd?>'>
+                                <a title='Edit team' class='a_button' onclick='editTeam(<?=$team->id?>)'>
+                                    <img alt='Edit team' src='<?=URL::IMG["ICON"]?>edit.png'/>
+                                </a>
+                                <a title='Remove team' class='a_button' onclick='deleteTeam(<?=$team->id?>)'>
+                                    <img alt='Remove team' src='<?=URL::IMG["ICON"]?>nok.png'/>
+                                </a>
+                                
+                            </td>
                         </tr>
 <?php
                         if ($odd == ""){

+ 17 - 0
public/css/teams.css

@@ -74,6 +74,23 @@ table#teams td.units div.monster_panel img.leader{
     left: -0.7em;
 }
 
+table#teams td.action{
+    text-align: center;
+}
+table#teams td.action a{
+    display: inline-block;
+    width: 1.5em;
+    height: 1.5em;
+}
+
+table#teams td.action a img{
+    display: inline-block;
+    width: 1em;
+    margin-top: 0.25em;
+    margin-left: 0.25em;
+    height: 1em;
+}
+
 section#new_team{
     z-index: 1;
     display: none;

+ 9 - 3
public/css/ui.css

@@ -298,9 +298,9 @@ footer table#footer_table td{
 }
 input, select, a.a_button, textarea{
     font-size: 100%;
+    
     text-transform: capitalize;
     font-variant: small-caps;
-    cursor: pointer;
     color: var(--input-color);
     font-weight: var(--input-font-weight);
     padding: var(--input-padding);
@@ -310,6 +310,14 @@ input, select, a.a_button, textarea{
     text-shadow: var(--input-text-shadow);
     box-shadow: var(--input-box-shadow);
 }
+a.a_button, input[type=button]{
+    cursor: pointer;
+}
+input[type=text], textarea{
+    text-transform: initial;
+    font-variant: initial;
+}
+
 input[type=button], input[type=submit]{padding: var(--input-button-padding);}
 input[type=text], input[type=number], input[type=date], input[type=password], select{font-size: 80%;}
 input[type=number]{width: 3em;}
@@ -654,7 +662,6 @@ div.monster_panel span.badges{
     bottom: 0.6em;
     left: 0.1em;
     z-index: 1;
-    /* pointer-events: none; */
     display: block;
     transform: rotate(180deg);
 }
@@ -662,7 +669,6 @@ div.monster_panel span.badges{
 div.monster_panel span.badges img{
     width: 1em;
     height: 1em;
-    /* filter: drop-shadow(0 0 0.3em #ffffff) drop-shadow(0 0 0.1em #ffffff); */
     border-radius: 50%;
     border: 0.15em solid #000000;
     background-color: #ffffff;

BIN
public/img/icon/edit.png