Added bike & key management.
authorLadislav Láska <laska@kam.mff.cuni.cz>
Sun, 17 Apr 2011 13:19:42 +0000 (15:19 +0200)
committerLadislav Láska <laska@kam.mff.cuni.cz>
Sun, 17 Apr 2011 13:19:42 +0000 (15:19 +0200)
29 files changed:
classes/bike.php [new file with mode: 0644]
classes/bikeroom.php
classes/href.php
classes/key.php [new file with mode: 0644]
controllers/assign.php [new file with mode: 0644]
controllers/bikedt.php [new file with mode: 0644]
controllers/bikeroom_manage.php
controllers/bikerooms.php
controllers/bikes.php [new file with mode: 0644]
controllers/keys.php [new file with mode: 0644]
controllers/newbike.php [new file with mode: 0644]
images/kolo.gif [new file with mode: 0644]
images/kolor.gif [new file with mode: 0644]
style.css
template/assign.php [new file with mode: 0644]
template/bikedt.php [new file with mode: 0644]
template/bikeroom_bikelist.php [new file with mode: 0644]
template/bikerooms_adminlist.inc [moved from template/bikerooms_adminlist.php with 77% similarity]
template/bikerooms_head.inc [moved from template/bikerooms_head.php with 100% similarity]
template/bikerooms_list.inc [moved from template/bikerooms_list.php with 100% similarity]
template/bikes.php [new file with mode: 0644]
template/bikes_admin.php [new file with mode: 0644]
template/bikes_list.css [new file with mode: 0644]
template/bikes_list.inc [new file with mode: 0644]
template/fmaker.inc
template/head.php
template/keylist.inc [new file with mode: 0644]
template/main.css
template/newbike.php [new file with mode: 0644]

diff --git a/classes/bike.php b/classes/bike.php
new file mode 100644 (file)
index 0000000..47ad0e2
--- /dev/null
@@ -0,0 +1,109 @@
+<?php
+
+require_once "database.php";
+
+class Bike {
+       private $data = array( 'id' => -1, 'user' => -1, 'bikeroom' => -1, 'description' => '');
+       public $lastErrorMessage;
+
+       public function __construct($id = null) {
+               if (is_null($id)) return;
+               $query = DB::query(
+                       "SELECT 
+                               `bikes`.*, 
+                               `users`.`name` as `userName`, 
+                               `users`.`login` as `userLogin`,
+                               (CONCAT(UPPER(`bikerooms`.`building`), `bikerooms`.`floor`)) as `bikeroomName`
+                       FROM `bikes` 
+                       LEFT JOIN `users` ON (`users`.`id` = `bikes`.`user`)
+                       LEFT JOIN `bikerooms` ON (`bikes`.`bikeroom` = `bikerooms`.`id`)
+                       WHERE `bikes`.`id` = ?", array($id));
+               $res = $query->commit();
+               if (mysql_num_rows($res)>0) $this->data = mysql_fetch_array($res);
+       }
+
+       public function update() {
+               if ($this->id == -1) {
+                       /* New bikeroom */
+                       $query = DB::query("INSERT INTO `bikes` (`user`, `bikeroom`, `description`) VALUES (?,?,?);",
+                       array($this->user, $this->bikeroom, $this->description));
+                       if (!$query->commit()) return false;
+                       $this->data['id'] = $query->lastId();
+               } else {
+                       $query = DB::query("UPDATE `bikes` SET `user` = ?, `bikeroom` = ?, `description` = ? WHERE `id` = ?;",
+                               array($this->user, $this->bikeroom, $this->description, $this->id));
+                       if (!$query->commit()) return false;
+               }
+               return true;
+       }
+       
+       public function assign($bikeroom) {
+               if ($bikeroom == "") {
+                       $query = DB::query("UPDATE `bikes` SET `bikeroom` = -1 WHERE `id` = ?",
+                               array($this->id));
+                       $query->commit();
+                       return true;
+               }
+               if (!is_object($bikeroom)) $bikeroom = new Bikeroom($bikeroom);
+               DB::tstart();
+               $query = DB::query("UPDATE `bikes` SET `bikeroom` = ? WHERE `id` = ?", 
+                       array($bikeroom->id, $this->id));
+               $query->commit();
+               $bikeroom = new Bikeroom($bikeroom->name);
+               if ($bikeroom->freeSpace > 0) {
+                       DB::tcommit();
+                       return true;
+               } else { 
+                       DB::trollback();
+                       $this->lastErrorMessage = tr("V kolárně není volné místo.");
+                       return false;
+               }
+       }
+
+       public static function listAll($condt = null, $cond = null) {
+               $qcond = 1;
+               if ($condt != null) {
+                       switch ($condt) {
+                               case 'bikeroom':        $qcond = "`bikeroom` = $cond->id"; break;
+                               case 'user':            $qcond = "`user` = $cond->id"; break;
+                       }
+               }
+               $query = DB::query("SELECT `id` FROM `bikes` WHERE $qcond;");
+               $res = $query->commit();
+               $array = array();
+               while ($row = mysql_fetch_array($res))
+                       $array[] = new Bike($row['id']);
+               return $array;
+       }
+
+       public function setData($data) {
+               $this->data = $data;
+               return true;
+       }
+
+       public function delete() {
+               $query = DB::query("DELETE FROM `bikes` WHERE `id` = ?", array($this->id));
+               $query->commit() or die("SQL query died in Bike::delete.");
+       }
+
+       public function setUser($value) {
+               if (is_object($value)) $this->data['user'] = $value->id;
+               else $this->data['user'] = $value;
+               return true;
+       }
+
+       public function setBikeroom($value) {
+               if (is_object($value)) $this->data['bikeroom'] = $value->id;
+               else $this->data['bikeroom'] = $value;
+               return true;
+       }
+
+       public function setDescription($value) {
+               $this->data['description'] = $value;
+               return true;
+       }
+
+       public function __get( $name ) {
+               return $this->data[$name];
+       }
+}
index 6efa719667c9f7859954a56248bf66961539cbeb..7408d9ad1f5cfb549e3651c0d462285bd92e603a 100644 (file)
@@ -45,6 +45,34 @@ class Bikeroom {
                return $array;
        }
 
+       public static function bestFor($bike) {
+               $user = new User($bike->userLogin);
+               $query = DB::query(
+                       "SELECT *,
+                               CONCAT(UPPER(building),floor) AS `name`, 
+                               (`space` - (SELECT COUNT(*) FROM `bikes` WHERE `bikeroom` = `bikerooms`.`id`)) AS `freeSpace`,
+                               (? - `floor` + (CASE WHEN `building` = ? THEN 0 ELSE 100 END) + 
+                                                               (CASE WHEN `floor` > ? AND `building` = ? THEN (20 + 2 * `floor`) ELSE 0 END)) AS `rank`
+                       FROM `bikerooms` HAVING `freeSpace` > 0 ORDER BY `rank` ASC",
+                       array($user->floor, $user->building, $user->floor, $user->building)
+               );
+               $res = $query->commit();
+               $array = array();
+               while ($row = mysql_fetch_array($res))
+                       $array[] = new Bikeroom($row['name']);
+                       /* $array[] = array ($row['rank'], new Bikeroom($row['name'])); */
+               return $array;
+       }
+
+       public function bikes() {
+               $query = DB::query("SELECT `id` FROM `bikes` WHERE `bikeroom` = ?;", array($this->id));
+               $res = $query->commit();
+               $array = array();
+               while ($row = mysql_fetch_array($res)) 
+                       $array[] = new Bike($row['id']);
+               return $array;
+       }
+
        public function setData($data) {
                $this->data = $data;
                return true;
index 6e401e2e9427c6559835d419e357c67812fdc1a1..89ca4965c3081417ec2a25c6723c06231faeb8c4 100644 (file)
@@ -9,11 +9,13 @@ function href($url, $name) {
        } else {
                $uri = $conf['http_base']."?page=$url";
        }
+       $uri = preg_replace('/&([^a][^m][^p][^;])/', '&amp;$1', $uri);
        return "<a href=\"$uri\">$name</a>";
 }
 
-function redir($url = "index") {
-       global $conf;
+function redir($url = null) {
+       global $conf, $_redir_default;
+       if (is_null($url)) $url = $_redir_default;
        if (preg_match('/^http:\/\//', $url)) {
                $uri = $url;
        } else {
@@ -24,4 +26,13 @@ function redir($url = "index") {
        die();
 }
 
+if (isset($_GET['redir']))
+       $_redir_default = $_GET['redir'];
+else $_redir_default = "index";
+
+function redir_default($default) {
+       global $_redir_default;
+       $_redir_default = $default;
+}
+
 ?>
diff --git a/classes/key.php b/classes/key.php
new file mode 100644 (file)
index 0000000..6176d3f
--- /dev/null
@@ -0,0 +1,122 @@
+<?php
+
+/* 
+ * "Keys" are of three types:
+ *   - Have -- have and should have a key
+ *   - Want -- does not have and should have a key
+ *   - Extra -- have and should not have a key
+ */
+
+define("HAVE", 0);
+define("WANT", 1);
+define("EXTRA", 2);
+
+class Key {
+       private $data;
+       public static function listKeys( $which = null ) {
+               switch ($which) {
+                       case HAVE:
+                               $query = Db::Query("SELECT * FROM `keys` WHERE `from` < NOW() AND (`to` > NOW() OR `to` IS NULL);");
+                               break;
+                       case WANT:
+                               /* User wants key if:
+                                       a) he never had it
+                                       b) he had it, but returned
+                               */
+                               $query = DB::Query(
+                               "SELECT DISTINCT `bikes`.`user`, `bikes`.`bikeroom` FROM `bikes` WHERE  `bikeroom` != -1 AND
+                                       (SELECT COUNT(*) FROM `keys` WHERE 
+                                               `keys`.`user` = `bikes`.`user` 
+                                               AND `keys`.`bikeroom` = `bikes`.`bikeroom` 
+                                               AND `from` < NOW() AND (`to` > NOW() OR `to` IS NULL)
+                                       ) = 0;"
+/*                             "SELECT DISTINCT `bikes`.`user`, `bikes`.`bikeroom` FROM `bikes` 
+                                       LEFT JOIN `keys` ON 
+                                       (`bikes`.`user` = `keys`.`user` AND `bikes`.`bikeroom` = `keys`.`bikeroom`)
+                               WHERE ( `from` IS NULL) AND `bikes`.`bikeroom` != -1;"
+*/);
+                               break;
+                       case EXTRA:
+                               /* User has extra key if he owns a key and has no bike in that bikeroom */
+                               $query = DB::Query(
+                               "SELECT `keys`.`user`, `keys`.`bikeroom` FROM `keys` 
+                                       LEFT JOIN `bikes` ON 
+                                       (`bikes`.`user` = `keys`.`user` AND `bikes`.`bikeroom` = `keys`.`bikeroom`)
+                               WHERE `bikes`.`id` IS NULL AND `to` IS NULL;");
+                               break;
+                       case null:
+                               break;
+                       default:
+                               break;
+               }
+               $res = $query->commit();
+               if (!$res) die("SQL Query failed.");
+               $ret = array();
+               while ($row = mysql_fetch_array($res))
+                       $ret[] = new Key($row['user'], $row['bikeroom']);
+               return $ret;
+       }
+
+       public function __construct($user, $bikeroom) {
+               $userId = (is_object($user) ? $user->id : $user);
+               $bikeroomId = (is_object($bikeroom) ? $bikeroom->id : $bikeroom);
+               /* In this variant, select _only_ valid keys! */
+               $query = DB::Query("SELECT `keys`.*,`users`.`login`,`users`.`name` AS `userName`,
+                       CONCAT(`bikerooms`.`building`,`bikerooms`.`floor`) AS `bikeroomName`
+                       FROM `keys` LEFT JOIN `users` ON (`keys`.`user` = `users`.`id`)
+                       LEFT JOIN `bikerooms` ON (`keys`.`bikeroom` = `bikerooms`.`id`)
+                       WHERE `user` = ? AND `bikeroom` = ? AND (`to` IS NULL);", array($userId, $bikeroomId));
+               $res = $query->commit();
+               if (!$res) die("SQL query failed.");
+               if (mysql_num_rows($res) == 1) {
+                       $this->data = mysql_fetch_array($res);
+               } else {
+                       $query = DB::Query(
+                               "SELECT *, `users`.`id` AS `user`, `users`.`login`,`users`.`name` AS `userName`,
+                           CONCAT(`bikerooms`.`building`,`bikerooms`.`floor`) AS `bikeroomName`,
+                                       `bikerooms`.`id` AS `bikeroom`, -1 AS `id`, NULL AS `to`, NULL AS `from`
+                                FROM `bikerooms` CROSS JOIN `users` WHERE `users`.`id` = ? AND `bikerooms`.`id` = ?;",
+                               array($userId, $bikeroomId));
+                       $res = $query->commit();
+                       if (!$res) die("SQL query failed.");
+               if (mysql_num_rows($res) == 1) 
+                   $this->data = mysql_fetch_array($res);
+                       else die("Invalid parameters in Key::__construct(), giving up.<br />");
+               }
+       }
+
+       public function update() {
+               if ($this->id == -1) {
+                       $query = DB::Query("INSERT INTO `keys` SET `user` = ?, `bikeroom` = ?, `from` = ?, `to` = ?",
+                               array($this->user, $this->bikeroom, $this->data['from'], $this->data['to']));
+               } else {
+                       $query = DB::Query("UPDATE `keys` SET `user` = ?, `bikeroom` = ?, `from` = ?, `to` = ? WHERE `id` = ?",
+                               array($this->user, $this->bikeroom, $this->data['from'], $this->data['to'], $this->id));
+               }
+               $query->commit() or die("Query failed.");
+               if ($this->id == -1) $this->data['id'] = $query->lastId();
+               return true;
+       }
+
+       public function grant() {
+               if ($this->id == -1) {
+                       $this->data['from'] = 'NOW()';  
+               } else if (debug) die("Cannot grant already granted key!");
+       }
+
+       public function take() {
+               if ($this->id != -1) {
+                       $this->data['to'] = 'NOW()';
+               } else if (debug) die("Cannot take not granted key!");
+       }
+
+       public function __get($key) {
+               /* Special care to `from` to `to`, which could be NOW() */
+               switch ($key) {
+                       case 'from': $d = $this->data['from'];
+                       case 'to': $d = $this->data['to']; 
+                               if ($d == 'NOW()') return strftime("%Y-%m-%d %H:%M:%S");
+                       default:        return $this->data[$key];
+               }
+       }
+}
diff --git a/controllers/assign.php b/controllers/assign.php
new file mode 100644 (file)
index 0000000..b80cbbc
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+       redir_default("bikes");
+       if (!isset($_GET['bike'])) die("Invalid arguments.");
+
+       $bike = new Bike($_GET['bike']);
+       if (($bike->user != $auth->id) && (!$auth->verify(P_BIKEMOD))) 
+               redir(403);
+
+       if (isset($_GET['target']))
+               $target = $_GET['target'];
+       
+       if (isset($_POST['bikeroom'])) {
+               if ($_POST['bikeroom'] != 'other')
+               $target = $_POST['bikeroom'];
+               else $target = $_POST['other'];
+       }
+
+       if (isset($target)) {
+               if ($bike->assign($target))
+                       redir();
+               else box_fail(tr("Nebylo možné umístit kolo do požadované kolárny: ").$bike->lastErrorMessage);
+       }
+
+
+       include "template/assign.php";
+?>
diff --git a/controllers/bikedt.php b/controllers/bikedt.php
new file mode 100644 (file)
index 0000000..808b1e0
--- /dev/null
@@ -0,0 +1,27 @@
+<?php
+       require_once "bike.php";
+       require_once "bikeroom.php";
+       require_once "msgbox.php";
+
+       if (isset($_GET['del'])) {
+               $bike = new Bike($_GET['del']);
+               if ($auth->verify(P_BIKEMOD) || ($auth->id == $bike->user)) {
+                       $bike->delete();
+                       redir("bikes");
+               }
+               redir(403);
+       } else if (isset($_GET['mod'])) {
+               $bike = new Bike($_GET['mod']);
+               if ($auth->verify(P_BIKEMOD) || ($auth->id == $bike->user)) {
+                       if (isset($_POST['description'])) {
+                               $bike->setDescription($_POST['description']);
+                               if ($auth->verify(P_BIKEMOD))
+                                       $bike->setBikeroom($_POST['bikeroom']);
+                               $bike->update() or box_fail(tr("Nelze uložit informace o kolu."));
+                               box_succ(tr("Data byla uložena."));
+                       }
+                       $datamine = $bike;
+                       include "template/bikedt.php";
+               }
+       } else die("Invalid argument.");
+?>
index d2bb7cf74cd81974776d3ec9fde49a85bd074fb9..65ca9005f724279bb07caadc16df15ebc11e02df 100644 (file)
@@ -21,5 +21,7 @@ include "template/bikeroom_manage.php";
 
 if ($auth->verify(P_GROUNDSMAN)) {
 /* Tohle smí i s právce kolárny */
+$bikeroom = $b;
+include "template/bikeroom_bikelist.php";
 }
 ?>
index 46a96322fb41ead1f31407abda25c69a85888e7a..2bc2ee199a6e0a0be38f00f388ab539e9352fa1e 100644 (file)
@@ -3,8 +3,8 @@
 require_once "bikeroom.php";
 
 if ($auth->verify(P_ADMIN))
-include "template/bikerooms_adminlist.php";
-include "template/bikerooms_head.php";
+include "template/bikerooms_adminlist.inc";
+include "template/bikerooms_head.inc";
 $bikerooms = Bikeroom::listAll();
-include "template/bikerooms_list.php";
+include "template/bikerooms_list.inc";
 ?>
diff --git a/controllers/bikes.php b/controllers/bikes.php
new file mode 100644 (file)
index 0000000..677efc1
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+
+if (!$auth->verify()) redir("login");
+
+require_once "bike.php";
+
+include "template/bikes.php";
+if ($auth->verify(P_ADMIN))
+include "template/bikes_admin.php";
+?>
diff --git a/controllers/keys.php b/controllers/keys.php
new file mode 100644 (file)
index 0000000..61c47f6
--- /dev/null
@@ -0,0 +1,25 @@
+<?php
+       if (!$auth->verify(P_ADMIN)) redir(403);
+
+       if (isset($_GET['action'])) {
+               $key = new Key($_GET['user'], $_GET['bikeroom']);
+               switch ($_GET['action']) {
+                       case 'take':
+                               $key->take();
+                               break;
+                       case 'grant':
+                               $key->grant();
+                               break;
+                       default:
+                               die("Invalid action in controller 'keys'. You deserve to die!");
+               }
+               $key->update();
+               redir("keys");
+       }
+
+       $have_list = Key::listKeys(HAVE);
+       $want_list = Key::listKeys(WANT);
+       $extra_list = Key::listKeys(EXTRA);
+
+       include "template/keylist.inc";
+?>
diff --git a/controllers/newbike.php b/controllers/newbike.php
new file mode 100644 (file)
index 0000000..591b408
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+       require_once "bike.php";
+
+       if (!$auth->verify()) redir("403");
+
+       if (isset($_POST['description'])) {
+               $b = new Bike();
+               $b->setDescription($_POST['description']);
+               $b->setUser($auth->user);
+               if ($b->update()) redir("bikes");
+       }
+
+       include "template/newbike.php";
+?>
diff --git a/images/kolo.gif b/images/kolo.gif
new file mode 100644 (file)
index 0000000..794cd3b
Binary files /dev/null and b/images/kolo.gif differ
diff --git a/images/kolor.gif b/images/kolor.gif
new file mode 100644 (file)
index 0000000..ecc284a
Binary files /dev/null and b/images/kolor.gif differ
index 55b4b95a30eb24b4d9cd8ce6093ac16856a80188..80e2d15680c2638c24d69d93c0b676f0efeb0b78 100644 (file)
--- a/style.css
+++ b/style.css
@@ -13,6 +13,17 @@ table#bikeroomlist tr td, table#bikeroomlist tr th {
 
 table#bikeroomlist td.full { color: red; }
 table#bikeroomlist td.free { color: green; }
+table.bikeslist, table.bikeslist tr, table.bikeslist tr td, table.bikeslist tr th {
+       border-collapse: collapse;
+       border: 1px solid grey;
+}
+
+table.bikeslist tr td, table.bikeslist tr th {
+       padding: 2px 0.5em 2px 0.5em;
+}
+
+table.bikeslist td.full { color: red; }
+table.bikeslist td.free { color: green; }
 div.msgbox_outer {
        text-align: center;
 }
@@ -33,7 +44,14 @@ div.msgbox_green {
 }
 div#head {
        padding: 1em;
-       text-align: right;
+       text-align: center;
+       font-size: 180%;
+}
+
+div#head img {
+       vertical-align: middle;
+       margin-left: 1em;
+       margin-right: 1em;
 }
 
 div#menu {
@@ -41,9 +59,20 @@ div#menu {
        border: 2px solid #eee;
 }
 
+div#menu .left {
+       float: left;
+}
+
 div#menu .right {
        text-align: right;
-       float:right;
+       float: right;
+}
+
+div#menu .rule {
+       clear: both;
+       height: 0.1px;
+       border: 0;
+       font-size: 1%;
 }
 
 div#menu .right a {
@@ -73,7 +102,7 @@ table.table_nostyle, table.table_nostyle tr, table.table_nostyle tr td {
        text-align: left;
 }
 
-div.adminlist {
+div.menulist {
        float: right;
        width: 200px;
        border: 1px solid black;
diff --git a/template/assign.php b/template/assign.php
new file mode 100644 (file)
index 0000000..884cca4
--- /dev/null
@@ -0,0 +1,35 @@
+<?php require_once "fmaker.inc"; ?>
+<h1><?=tr("Umístit kolo do kolárny")?></h1>
+<form action="#" method="post">
+       <?php 
+               $best = Bikeroom::bestFor($bike);
+               $first = array_shift($best);
+               $l = array();
+               foreach ($best as $b) {
+                       if ($b->freeSpace > 0) $l[$b->name] = $b->name;
+               }
+       ?>
+<table>
+       <tr>
+       <td><input type="radio" id="radio_best" name="bikeroom" value="<?=$first->name?>"
+       <?php if (!isset($_POST['bikeroom']) || $_POST['bikeroom'] != 'other') echo 'checked="checked"'; ?>
+       /></td>
+       <td colspan="2"><label for="radio_best"><?=$first->name?></label></td></tr>
+       <tr>
+       <td><input type="radio" id="radio_other" name="bikeroom" value="other" 
+       <?php if (isset($_POST['bikeroom']) && $_POST['bikeroom'] == 'other') echo 'checked="checked"'; ?>
+       /></td>
+       <td><label for="radio_other"><?=tr("Jiná: ")?></label></td>
+       <td>
+       <select name="other" onfocus="document.getElementById('radio_other').checked=true">
+       <?php
+               foreach ($best as $b) {
+                       if (isset($_POST['bikeroom']) && $_POST['other'] == $b->name) $selected='selected="selected"';
+                       else $selected = '';
+       ?>
+               <option value="<?=$b->name?>" <?=$selected?>><?=$b->name?></option>
+       <? } ?>
+       </select></td></tr>
+       <tr><td colspan="2">&nbsp;</td><td><input type="submit" name="submit" value="<?=tr("Uložit kolo")?>" /></td></tr>
+</table>
+</form>
diff --git a/template/bikedt.php b/template/bikedt.php
new file mode 100644 (file)
index 0000000..aa36d5b
--- /dev/null
@@ -0,0 +1,21 @@
+<?php require_once "fmaker.inc"; ?>
+
+<h1><?=tr("Upravit kolo")?></h1>
+
+<form action="#" method="post">
+<table>
+<?php
+       field("Popis", "text", "description", "validateSomething");
+       if ($auth->verify(P_BIKEMOD)) {
+               $l = array(-1 => "---");
+               foreach (Bikeroom::listAll() as $k) {
+                       $l[$k->id] = "$k->name ($k->freeSpace/$k->space)";
+               }
+               select("Kolárna", "bikeroom", $l, $datamine->bikeroom);
+       }
+
+?>
+<tr><th colspan="2"><div class="center"><input type="submit" value="<?=tr("Změnit")?>" /></div></th><td>&nbsp;</td></tr>
+</table>
+
+</form>
diff --git a/template/bikeroom_bikelist.php b/template/bikeroom_bikelist.php
new file mode 100644 (file)
index 0000000..eb0ef1a
--- /dev/null
@@ -0,0 +1,8 @@
+<?php if (!$auth->verify(P_ADMIN)) { ?>
+<h1><?=tr("Správa kolárny").' '.$bikeroom->name?></h1>
+<?php } ?>
+<h2><?=tr("Kola v kolárně")?></h2>
+<?php
+       $bikes = $bikeroom->bikes();
+       include "bikes_list.inc";
+?>
similarity index 77%
rename from template/bikerooms_adminlist.php
rename to template/bikerooms_adminlist.inc
index 4c3f051e80d8a7c05845153f62539845aa0a9151..47900462f9b1443d5b588cf8563cfc506dd63a82 100644 (file)
@@ -1,4 +1,4 @@
-<div class="adminlist">
+<div class="menulist">
 <h2><?=tr("Úlohy správy")?></h2>
 <?=href("newbikeroom", "Nová kolárna")?>
 </div>
diff --git a/template/bikes.php b/template/bikes.php
new file mode 100644 (file)
index 0000000..35d9047
--- /dev/null
@@ -0,0 +1,13 @@
+<div class="menulist">
+<h2><?=tr("Akce")?></h2>
+<?=href("newbike", "Nové kolo")?>
+</div>
+<h1>Moje kola</h1>
+<?php
+       $bikes = Bike::listAll('user', $auth->user);
+       if (count($bikes) == 0) {
+               echo tr("Nemáte žádná kola.");
+       } else  
+       include "bikes_list.inc";
+?>
+
diff --git a/template/bikes_admin.php b/template/bikes_admin.php
new file mode 100644 (file)
index 0000000..d13b5ce
--- /dev/null
@@ -0,0 +1,6 @@
+<h1>Všechna kola</h1>
+<?php
+       $bikes = Bike::listAll();
+       include "bikes_list.inc";
+?>
+
diff --git a/template/bikes_list.css b/template/bikes_list.css
new file mode 100644 (file)
index 0000000..49c065b
--- /dev/null
@@ -0,0 +1,11 @@
+table.bikeslist, table.bikeslist tr, table.bikeslist tr td, table.bikeslist tr th {
+       border-collapse: collapse;
+       border: 1px solid grey;
+}
+
+table.bikeslist tr td, table.bikeslist tr th {
+       padding: 2px 0.5em 2px 0.5em;
+}
+
+table.bikeslist td.full { color: red; }
+table.bikeslist td.free { color: green; }
diff --git a/template/bikes_list.inc b/template/bikes_list.inc
new file mode 100644 (file)
index 0000000..f3533b3
--- /dev/null
@@ -0,0 +1,30 @@
+<table class="bikeslist">
+       <tr>
+               <th><?=tr("Popis")?></th>
+               <th><?=tr("Vlastník")?></th>
+               <th><?=tr("Kolárna")?></th>
+               <th><?=tr("Akce")?></th>
+       </tr>
+<?php
+       /* Expects $bikes to be an array of Bike */
+       foreach ($bikes as $bike) {
+?>
+       <tr>
+               <td><?=$bike->description?></td>
+               <td><?=$bike->userName?></td>
+               <td><?php
+                               if ($bike->bikeroomName == "") {
+                                       echo href("assign&bike=$bike->id", "Do kolárny");
+                               } else {
+                                       echo $bike->bikeroomName;
+                                       echo " ( ".href("assign&bike=$bike->id&target=", "Vyřadit")." )";
+                               }
+                       ?>
+               </td>
+               <td>
+                       <?=href("bikedt&mod=$bike->id", "Upravit")?>,
+                       <?=href("bikedt&del=$bike->id", "Smazat")?>
+               </td>
+       </tr>
+<? } ?>
+</table>
index 55fef4934c323ab4dbe8f806168e5b40e21bb9c5..4e15bd47f356ec5f640a261b5d1730bac8946d60 100644 (file)
@@ -25,7 +25,7 @@
                global $formmsg;
                global $datamine;
                if (!is_null($hook)) {
-                       $hook= "oninput=\"$hook(this)\"";
+                       $hook= "onkeypress=\"$hook(this)\"";
                }
 
                $val = "";
@@ -61,7 +61,8 @@
 
 ?>
 
-<script language="JavaScript">
+<script type="text/javascript">
+/* <![CDATA[ */
 /* Display message on element */
 function display(field, message) {
        document.getElementById("repbox"+field.name).firstChild.nodeValue = message;
@@ -96,4 +97,5 @@ function validateEmail(field) {
        if (!field.value.match(/^.+@.+\..+$/)) display(field, "<?=tr("Toto není platná emailová adresa.")?>");
        else display(field, "");
 }
+/* ]]> */
 </script>
index d673277003a54394a0d52d2b663c47dc3f897bb3..9ce0e915b13ca15e534acd6c31b25d625f4116c9 100644 (file)
@@ -9,32 +9,43 @@
 
 </head>
 
+<body>
 <div id="head">
-Správa koláren VŠK 17. listopadu
+<img src="images/kolor.gif" alt="KoloR" />
+       <span>Správa koláren VŠK 17. listopadu</span>
+<img src="images/kolo.gif" alt="Kolo"/>
 </div>
 
 <div id="menu">
+<div class="left">
 Přihlášený uživatel: <?=$auth->login?> | <? if ($auth->id==-1) echo href("login", tr("Přihlásit se"))." | ".href("register", tr("Registrovat se")); else echo href("logout", tr("Odhlásit se")); ?>
+</div>
 <div class="right">
 <?php 
        switch ($auth->privileges) {
                case 0:
                        echo href("bikerooms", tr("Kolárny"));
                        echo href("bikes", tr("Moje kola"));
+                       echo href("useredt&mod=$auth->login", tr("Osobní údaje"));
                        break;
                case 1:
                        echo href("bikerooms", tr("Kolárny"));
+                       echo href("keys", tr("Klíče"));
                        echo href("bikes", tr("Kola"));
+                       echo href("useredt&mod=$auth->login", tr("Osobní údaje"));
                        break;
                case 2:
                        echo href("bikerooms", tr("Kolárny"));
+                       echo href("keys", tr("Klíče"));
                        echo href("bikes", tr("Kola"));
                        echo href("usermod", tr("Správa uživatelů"));
+                       echo href("useredt&mod=$auth->login", tr("Osobní údaje"));
                        echo href("summaries", tr("Sestavy"));
                        break;
        }
 ?>
 </div>
+<div class="rule">&nbsp;</div>
 </div>
 
 <div id="content">
diff --git a/template/keylist.inc b/template/keylist.inc
new file mode 100644 (file)
index 0000000..e364991
--- /dev/null
@@ -0,0 +1,34 @@
+<h1><?=tr("Přidělené klíče")?></h1>
+<table>
+       <th>Vlastník<th><th>Kolárna</th><th>Od</th><th>Akce</th>
+       <?php foreach ($have_list as $key) { ?>
+               <tr>
+                       <td><?=$key->userName?></td>
+                       <td><?=$key->bikeroomName?></td>
+                       <td><?=$key->from?></td>
+                       <td><?=href("keys&action=take&user=".urlencode($key->user)."&bikeroom=$key->bikeroom", tr("Odebrat"))?></td>
+               </tr>           
+       <?php } ?>
+</table>
+<h1><?=tr("Čekající na přidělení")?></h1>
+<table>
+       <th>Čekatel<th><th>Kolárna</th><th>Akce</th>
+       <?php foreach ($want_list as $key) { ?>
+               <tr>
+                       <td><?=$key->userName?></td>
+                       <td><?=$key->bikeroomName?></td>
+                       <td><?=href("keys&action=grant&user=".urlencode($key->user)."&bikeroom=$key->bikeroom", tr("Přidělit"))?></td>
+               </tr>           
+       <?php } ?>
+</table>
+<h1><?=tr("Čekající na vrácení")?></h1>
+<table>
+       <th>Vlastník<th><th>Kolárna</th><th>Akce</th>
+       <?php foreach ($extra_list as $key) { ?>
+               <tr>
+                       <td><?=$key->userName?></td>
+                       <td><?=$key->bikeroomName?></td>
+                       <td><?=href("keys&action=take&user=".urlencode($key->user)."&bikeroom=$key->bikeroom", tr("Vrátit"))?></td>
+               </tr>           
+       <?php } ?>
+</table>
index d0811c5ae5bfdae97e826b9ca2c978a96d813fb7..005e547e79aeb4738f42439b2748a1eec77da1cc 100644 (file)
@@ -1,6 +1,13 @@
 div#head {
        padding: 1em;
-       text-align: right;
+       text-align: center;
+       font-size: 180%;
+}
+
+div#head img {
+       vertical-align: middle;
+       margin-left: 1em;
+       margin-right: 1em;
 }
 
 div#menu {
@@ -8,9 +15,20 @@ div#menu {
        border: 2px solid #eee;
 }
 
+div#menu .left {
+       float: left;
+}
+
 div#menu .right {
        text-align: right;
-       float:right;
+       float: right;
+}
+
+div#menu .rule {
+       clear: both;
+       height: 0.1px;
+       border: 0;
+       font-size: 1%;
 }
 
 div#menu .right a {
@@ -40,7 +58,7 @@ table.table_nostyle, table.table_nostyle tr, table.table_nostyle tr td {
        text-align: left;
 }
 
-div.adminlist {
+div.menulist {
        float: right;
        width: 200px;
        border: 1px solid black;
diff --git a/template/newbike.php b/template/newbike.php
new file mode 100644 (file)
index 0000000..02f9e6a
--- /dev/null
@@ -0,0 +1,13 @@
+<?php require_once "fmaker.inc"; ?>
+
+<h1><?=tr("Nové kolo")?></h1>
+
+<form action="#" method="post">
+<table>
+<?php
+       field("Popis", "text", "description", "validateSomething");
+?>
+<tr><th colspan="2"><div class="center"><input type="submit" value="<?=tr("Založit")?>" /></div></th><td>&nbsp;</td></tr>
+</table>
+
+</form>