Supply filetype when adding new file.
[mediadatabase.git] / php / index.php
blob256367d77c569951119d072c2e60c363c3ef93ad
1 <?php
2 require('inc.header.php');
4 function ShowChangeLocationForm($media_id)
6 $query = "SELECT l.id,l.description,lt.description FROM ".
7 $GLOBALS['config']['tbl_locations']." AS l, ".
8 $GLOBALS['config']['tbl_location_types']." AS lt ".
9 "WHERE l.type = lt.id AND l.id != 0 ORDER BY lt.description DESC, l.description";
10 if (!$res = mysql_query($query))
12 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
13 return;
16 if (!mysql_num_rows($res))
18 echo "No locations found.\n";
19 return;
22 echo "<form action=\"".$GLOBALS['self']."?media=".$media_id."\" method=\"post\">\n";
23 echo "Change location to\n";
24 echo " <select name=\"new_location\">\n";
26 $first = TRUE;
28 while ($row = mysql_fetch_array($res))
30 echo " <option value=\"".$row[0]."\"";
31 if ($first)
33 echo " selected=\"selected\"";
34 $first = FALSE;
36 echo ">".$row[1]." (".$row[2].")"."</option>\n";
38 echo " </select>\n";
39 echo " <input type=\"submit\" value=\"Change\">\n";
40 echo "</form>\n";
43 function ChangeMediaLocation($media_id, $new_location_id)
45 echo "<p>\n";
46 $query = "UPDATE ".$GLOBALS['config']['tbl_media'].
47 " SET location = '".$new_location_id."'".
48 " WHERE mediaid = '".$media_id."'";
49 // echo $query;
51 if (!$res = mysql_query($query))
53 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n<p>\n";
55 else if (mysql_affected_rows() != 0)
57 echo "Location changed.\n\n";
58 return;
61 echo "Could not change location.\n\n";
63 echo "</p>\n";
66 if (isset($_GET['media']))
68 if (isset($_POST['new_location']))
70 ChangeMediaLocation($_GET['media'], $_POST['new_location']);
73 echo "<p>\n";
74 $query = "SELECT m.*,l.description,l.id FROM ".
75 $config['tbl_media']." AS m, ".
76 $config['tbl_locations']." AS l ".
77 "WHERE mediaid = '".addslashes($_GET['media'])."' AND ".
78 "m.location = l.id ".
79 "ORDER BY name";
81 if (!$res = mysql_query($query))
83 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
85 else
87 if (!mysql_num_rows($res))
89 echo "Media not found.\n";
91 else
93 $row = mysql_fetch_assoc($res);
95 echo "<table class=\"ObjectParametersTable\">\n";
96 echo " <tr>\n";
97 echo " <td>Media ID</td>\n";
98 echo " <td>".$row['mediaid']."</td>";
99 echo " </tr>\n";
100 echo " <tr>\n";
101 echo " <td>Media description</td>\n";
102 echo " <td>".$row["name"]."</td>";
103 echo " </tr>\n";
104 echo " <tr>\n";
105 echo " <td>Media type</td>\n";
106 echo " <td>".mb_typetext($row['type'])."</td>";
107 echo " </tr>\n";
108 echo " <tr>\n";
109 echo " <td>Current location</td>\n";
110 echo " <td>";
111 if ($row["description"])
113 echo "<a href=locations.php?id=".$row['id'].">".$row['description']."</a>";
115 else
117 echo "Unknown.";
119 echo " </td>\n";
120 echo " <tr>\n";
121 echo "</table>\n";
122 echo "<p>\n";
123 ShowChangeLocationForm($_GET['media']);
124 echo "</p>\n";
125 echo "<p>\n";
127 if ($row['type'] == MB_T_AUDIO)
129 $query = "SELECT * FROM ".$config['tbl_tracks']." WHERE mediaid = ".$row['mediaid']." ORDER BY trackid";
130 if (!$res = mysql_query($query))
132 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
134 else
136 if (!mysql_num_rows($res))
138 echo "No tracks found in database.\n\n";
140 else
142 mb_table_start('#','Name','Length');
143 if (isset($_GET['cat']))
145 $link = "\"$self?cat=".$_GET['cat'].'"';
147 else
149 $link = "\"$self\"";
151 mb_table_widecol("<a href=$link>Back to index</a>");
152 while ($row = mysql_fetch_assoc($res))
154 mb_table_col($row['trackid']);
155 mb_table_col($row['name']);
156 mb_table_col(mb_lengthtext($row['length']));
158 mb_table_end();
162 elseif ($row['type'] == MB_T_DATA)
164 $dir = isset($_GET['dir']) ? $_GET['dir'] : '/';
165 $parentdir = mb_getparentdir($dir);
167 echo "<p>".mb_icon('__folder').$dir."<p>";
169 $query = "SELECT * FROM ".$config['tbl_files'].
170 " WHERE path = '".addslashes($dir)."' AND ".
171 "mediaid = '".addslashes($_GET['media'])."' ".
172 "ORDER BY name";
174 if (!$res = mysql_query($query))
176 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
178 else
180 if (!mysql_num_rows($res))
182 echo "No files found.\n\n";
184 else
186 $folders = array();
187 $files = array();
188 while ($row = mysql_fetch_assoc($res))
190 if (substr($row['name'],-1) == '/')
192 $folders[] = $row;
194 else
196 $files[] = $row;
199 $selflink = "$self?media=".$_GET['media'].(isset($_GET['cat'])?'&cat='.$_GET['cat']:'');
200 mb_table_start('Filename','Size','Timestamp');
201 if ($parentdir)
203 mb_table_widecol("<a href=\"$selflink&dir=".urlencode($parentdir)."\">Parent directory</a>");
205 else
207 if (isset($_GET['cat']))
209 $link = "\"$self?cat=".$_GET['cat'].'"';
211 else
213 $link = "\"$self\"";
215 mb_table_col("<a href=$link>Back to index</a>");
216 mb_table_col('&nbsp;');
217 mb_table_col('&nbsp;');
219 foreach ($folders as $folder)
221 $link = "<a href=\"$selflink&dir=".urlencode($dir.$folder['name']).'">'.$folder['name']."</a>";
222 mb_table_col(mb_icon('__folder').$link);
223 mb_table_col('&nbsp;');
224 mb_table_col(mb_datetext($folder['time']));
226 foreach ($files as $file)
228 echo " <tr>\n";
229 mb_table_col(mb_icon('__unknown').$file['name']);
230 mb_table_col(mb_sizetext($file['size']));
231 mb_table_col(mb_datetext($file['time']));
233 mb_table_end();
237 else
239 echo "<b>Error:</b> Media must be either data or audio.\n";
244 elseif (!$config['use_categories'] || isset($_GET['cat']))
246 if ($config['use_categories'])
248 $query = "SELECT m.*,c.name as category FROM ".
249 $config['tbl_media']." AS m, ".
250 $config['tbl_categories']." AS c ".
251 "WHERE m.catid = c.catid AND c.catid = ".addslashes($_GET['cat'])." ORDER BY m.name";
253 else
255 $query = "SELECT l.description,l.id,m.* FROM ".
256 $config['tbl_media']." AS m, ".
257 $config['tbl_locations']." AS l ".
258 "WHERE m.location = l.id ".
259 "ORDER BY m.mediaid DESC";
262 if (!$res = mysql_query($query))
264 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
266 else
268 if (!mysql_num_rows($res))
270 echo "No media found".($config['use_categories']?' in this category':'').".\n";
272 else
274 mb_table_start('Media ID',
275 'Name',
276 'Date Added',
277 'Location');
279 if ($config['use_categories'])
281 mb_table_widecol("<a href=\"$self\">Back to category index</a>");
284 while ($row = mysql_fetch_assoc($res))
286 $extra = ($config['use_categories']?'&cat='.$row['catid']:'');
287 $link = (($row['type'] == MB_T_AUDIO) || ($row['type'] == MB_T_DATA));
288 mb_table_col($row['mediaid']);
289 mb_table_col(mb_iconbytype($row['type']).
290 ($link?"<a href=\"$self?media=".
291 $row['mediaid'].
292 $extra.
293 '">':'').
294 truncate_ellipsis($row['name'], $config['media_title_ellipsis_limit']).
295 ($link?'</a>':''));
296 mb_table_col(mb_datetext($row['added']));
297 mb_table_col("<a href=locations.php?id=".$row['id'].">".$row['description']."</a>");
300 mb_table_end();
304 else
306 echo "<p>\n";
307 $query = "SELECT c.catid,c.name,count(m.mediaid) AS count FROM ".$config['tbl_categories']." AS c LEFT JOIN ";
308 $query .= $config['tbl_media']." AS m ON m.catid = c.catid GROUP BY c.catid ORDER BY c.name";
309 if (!$res = mysql_query($query))
311 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
313 else
315 if (!mysql_num_rows($res))
317 echo "No categories found.\n";
319 else
321 mb_table_start('Category','Media');
322 while ($row = mysql_fetch_assoc($res))
324 mb_table_col(mb_icon('__category').
325 "<a href=\"$self?cat=".
326 $row['catid'].'">'.
327 $row['name'].
328 "</a>");
329 mb_table_col($row['count']);
331 mb_table_end();
336 require('inc.footer.php');