diff options
| -rw-r--r-- | index.php | 82 | 
1 files changed, 82 insertions, 0 deletions
diff --git a/index.php b/index.php new file mode 100644 index 0000000..cccb320 --- /dev/null +++ b/index.php @@ -0,0 +1,82 @@ +<?php +  $ARGS = $_POST; + +  if(count($ARGS) == 0) { +    $ARGS = json_decode($_COOKIE["tasks"], true); +  } else if($ARGS["clear"] == "t") { +    setcookie("tasks", "", time() - 1, "/"); +  } else { +    setcookie("tasks", json_encode($ARGS), time() + (86400 * 30 * 12), "/"); // 1 day * 30 * 12 +  } +?> + +<html> +  <head> +    <style> +      .text { +        margin: 5px; +      } +      .done_t { +        text-decoration-line: line-through; +      } +      .hidden { +        display: none; +      } +    </style> +  </head> +  <body> +    <form action="index.php" method="post"> +      <?php +        $tasks = $ARGS["tasks"] ?? "0"; + +        if($ARGS["task_text"] != "") { +           $ARGS["task_". $tasks ."_text"] = $ARGS["task_text"]; +          $tasks++; +        } + +        $delete = $ARGS["task_delete"] ?? -1; +        $edit   = $ARGS["task_edit"] ?? -1; + +        echo "Task: <input type=\"text\" name=\"task_text\">"; +        echo "<input type=\"submit\" value=\"Add Task\"> <br>"; + +        echo "<ul>"; +        for($i = 0, $j = 0; $i < $tasks; $i++, $j++) +        { +          if($i == $delete) { +            $j--; +            continue; +          } + +          if($j == $edit) { +            $editing   = true; +          } else { +            $editing   = false; +          } + +          $task_text = $ARGS["task_". $i ."_text"] ?? "ERROR: No Task"; +          $done = $ARGS["task_". $i ."_done"] ?? "f"; +          $isdone = $done == "t"; + +          echo "<li> <p>"; +          echo "<button type=\"submit\" name=\"task_". $j ."_done\"   value=\"". ($isdone ? "f" : "t") ."\">". ($isdone ? "Not Done" : "Done" ) ."</button>"; +          echo "<button type=\"submit\" name=\"task_delete\" value=\"". $j ."\">Delete</button>"; +          echo "<button type=\"submit\" name=\"task_edit\" value=\"". ($editing ? "" : $j) ."\">". ($editing ? "Save" : "Edit") ."</button>"; + +          echo "<input class=\"". ($editing ? "" : "hidden") ."\" name=\"task_". $j ."_text\" value=\"". $task_text ."\">"; +          echo "<span class=\"". ($editing ? "hidden" : "") ." text done_". $done ."\">". $task_text ."</span>"; + +          echo "<input type=\"hidden\" name=\"task_". $j ."_done\" value=\"". $done ."\">"; +          echo "</p> </li>"; +        } +        echo "</ul>"; + +        if($delete != -1) $tasks--; +        echo "<input type=\"hidden\" name=\"tasks\" value=\"". $tasks ."\">"; +      ?> +    </form> +    <form action="index.php" method="post"> +      <button type="submit" name="clear" value="t">Delete Everything</button> +   </form> +  </body> +</html>  | 
