Allow readonly mode (demo)
[mediadatabase.git] / php / locations.php
blob5a28e4646262d6728380a0ddb0987fb96949d8c0
1 <?php
3 require('inc.header.php');
5 function ShowLocations()
7 echo "<p>\n";
8 $query = "SELECT l.description,lt.description,l.id FROM ".
9 $GLOBALS['config']['tbl_locations']." AS l, ".
10 $GLOBALS['config']['tbl_location_types']." AS lt ".
11 "WHERE l.type = lt.id AND l.id != 0 ORDER BY lt.description, l.description";
12 if (!$res = mysql_query($query))
14 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
15 return;
18 if (!mysql_num_rows($res))
20 echo "No locations found.\n";
21 return;
24 mb_table_start('Location','Type');
25 while ($row = mysql_fetch_array($res))
27 mb_table_col("<a href=\"".$GLOBALS['self']."?id=".$row[2]."\">".$row[0]."</a>");
28 mb_table_col($row[1]);
30 mb_table_end();
31 echo "</p>\n";
34 function ShowAddLocationForm()
36 $query = "SELECT * FROM ".
37 $GLOBALS['config']['tbl_location_types']." AS lt ".
38 "WHERE id != 0 ORDER BY description";
39 if (!$res = mysql_query($query))
41 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
42 return;
45 echo "<p>\n";
46 echo "<form action=\"".$GLOBALS['self']."\" method=\"post\">\n";
47 echo " Add new location <input type=\"text\" class=\"input-text\" name=\"location_add\">\n";
48 echo "<select name=\"location_type\" class=\"input-select\">\n";
50 $first = TRUE;
52 while ($row = mysql_fetch_assoc($res))
54 echo " <option value=\"".$row['id']."\"";
55 if ($first)
57 echo " selected=\"selected\"";
58 $first = FALSE;
60 echo ">".$row['description']."</option>\n";
62 echo "</select>\n";
63 echo " <input type=\"submit\" class=\"input-button\" value=\"Add\">\n";
64 echo "</form>\n";
65 echo "</p>\n";
68 function AddLocation()
70 if ($GLOBALS['config']['readonly_mode'])
72 echo "<p>Cannot modify database in read-only mode.</p>\n";
74 else
76 $query = "INSERT INTO ".$GLOBALS['config']['tbl_locations'].
77 "(description,type)".
78 " VALUES ('".addslashes($_POST['location_add'])."', ".$_POST['location_type'].")";
79 if (!$res = mysql_query($query))
81 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n<p>\n";
83 else if (mysql_affected_rows() != 0)
85 echo "Location added.\n\n";
86 return;
90 echo "Could not add location.\n\n";
93 function ShowLocation($location_id)
95 $query = "SELECT l.description,lt.description FROM ".
96 $GLOBALS['config']['tbl_locations']." AS l, ".
97 $GLOBALS['config']['tbl_location_types']." AS lt ".
98 "WHERE l.type = lt.id AND l.id = ".$location_id;
99 if (!$res = mysql_query($query))
101 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
102 return;
105 if (!mysql_num_rows($res))
107 echo "No locations found.\n";
108 return;
111 $row = mysql_fetch_array($res);
112 echo "<table class=\"ObjectParametersTable\">\n";
113 echo " <tr>\n";
114 echo " <td>Location description</td>\n";
115 echo " <td>".$row[0]."</td>";
116 echo " </tr>\n";
117 echo " <tr>\n";
118 echo " <td>Location type</td>\n";
119 echo " <td>".$row[1]."</td>";
120 echo " </tr>\n";
121 echo "</table>\n";
123 $query = "SELECT l.description,m.* FROM ".
124 $GLOBALS['config']['tbl_media']." AS m, ".
125 $GLOBALS['config']['tbl_locations']." AS l ".
126 "WHERE m.location = l.id AND m.location = ".$location_id." ".
127 "ORDER BY m.mediaid DESC";
129 if (!$res = mysql_query($query))
131 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
132 return;
135 if (!mysql_num_rows($res))
137 echo "No media at this location.\n";
138 return;
141 echo "<p>\n";
143 mb_table_start('Media ID',
144 'Name');
146 while ($row = mysql_fetch_assoc($res))
148 $link = (($row['type'] == MB_T_AUDIO) || ($row['type'] == MB_T_DATA));
149 mb_table_col($row['mediaid']);
150 mb_table_col(mb_iconbytype($row['type']).
151 ($link?"<a href=\"index.php?media=".
152 $row['mediaid'].
153 '">':'').
154 $row['name'].
155 ($link?'</a>':''));
157 mb_table_end();
158 echo "</p>\n";
161 if (isset($_GET['id']))
163 ShowLocation($_GET['id']);
165 else
167 if (isset($_POST['location_add']) && strlen($_POST['location_add']) > 0)
169 AddLocation();
172 ShowLocations();
173 ShowAddLocationForm();
176 require('inc.footer.php');