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";
16 if (!mysql_num_rows($res))
18 echo "No locations found.\n";
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";
28 while ($row = mysql_fetch_array($res))
30 echo " <option value=\"".$row[0]."\"";
33 echo " selected=\"selected\"";
36 echo ">".$row[1]." (".$row[2].")"."</option>\n";
39 echo " <input type=\"submit\" value=\"Change\">\n";
43 function ChangeMediaLocation($media_id, $new_location_id)
46 $query = "UPDATE ".$GLOBALS['config']['tbl_media'].
47 " SET location = '".$new_location_id."'".
48 " WHERE mediaid = '".$media_id."'";
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";
61 echo "Could not change location.\n\n";
66 if (isset($_GET['media']))
68 if (isset($_POST['new_location']))
70 ChangeMediaLocation($_GET['media'], $_POST['new_location']);
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 ".
81 if (!$res = mysql_query($query))
83 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n\n";
87 if (!mysql_num_rows($res))
89 echo "Media not found.\n";
93 $row = mysql_fetch_assoc($res);
95 echo "<table class=\"ObjectParametersTable\">\n";
97 echo " <td>Media ID</td>\n";
98 echo " <td>".$row['mediaid']."</td>";
101 echo " <td>Media description</td>\n";
102 echo " <td>".$row["name"]."</td>";
105 echo " <td>Media type</td>\n";
106 echo " <td>".mb_typetext($row['type'])."</td>";
109 echo " <td>Current location</td>\n";
111 if ($row["description"])
113 echo "<a href=locations.php?id=".$row['id'].">".$row['description']."</a>";
123 ShowChangeLocationForm($_GET['media']);
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";
136 if (!mysql_num_rows($res))
138 echo "No tracks found in database.\n\n";
142 mb_table_start('#','Name','Length');
143 if (isset($_GET['cat']))
145 $link = "\"$self?cat=".$_GET['cat'].'"';
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']));
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'])."' ".
174 if (!$res = mysql_query($query))
176 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n\n";
180 if (!mysql_num_rows($res))
182 echo "No files found.\n\n";
188 while ($row = mysql_fetch_assoc($res))
190 if (substr($row['name'],-1) == '/')
199 $selflink = "$self?media=".$_GET['media'].(isset($_GET['cat'])?
'&cat='.$_GET['cat']:'');
200 mb_table_start('Filename','Size','Timestamp');
203 mb_table_widecol("<a href=\"$selflink&dir=".urlencode($parentdir)."\">Parent directory</a>");
207 if (isset($_GET['cat']))
209 $link = "\"$self?cat=".$_GET['cat'].'"';
215 mb_table_col("<a href=$link>Back to index</a>");
216 mb_table_col(' ');
217 mb_table_col(' ');
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(' ');
224 mb_table_col(mb_datetext($folder['time']));
226 foreach ($files as $file)
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']));
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";
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";
268 if (!mysql_num_rows($res))
270 echo "No media found".($config['use_categories']?
' in this category':'').".\n";
274 mb_table_start('Media ID',
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=".
294 truncate_ellipsis($row['name'], $config['media_title_ellipsis_limit']).
296 mb_table_col(mb_datetext($row['added']));
297 mb_table_col("<a href=locations.php?id=".$row['id'].">".$row['description']."</a>");
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";
315 if (!mysql_num_rows($res))
317 echo "No categories found.\n";
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=".
329 mb_table_col($row['count']);
336 require('inc.footer.php');