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\" class=\"input-select\">\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\" class=\"input-button\" value=\"Change\">\n";
43 function ChangeMediaLocation($media_id, $new_location_id)
45 if ($GLOBALS['config']['readonly_mode'])
47 echo "<p>Cannot modify database in read-only mode.</p>\n";
51 $query = "UPDATE ".$GLOBALS['config']['tbl_media'].
52 " SET location = '".$new_location_id."'".
53 " WHERE mediaid = '".$media_id."'";
56 if (!$res = mysql_query($query))
58 echo "<p><b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n</p>\n";
60 else if (mysql_affected_rows() != 0)
62 echo "<p>Location changed.</p>\n";
67 echo "<p>Could not change location.</p>\n";
70 if (isset($_GET['media']))
72 if (isset($_POST['new_location']))
74 ChangeMediaLocation($_GET['media'], $_POST['new_location']);
78 $query = "SELECT m.*,l.description,l.id FROM ".
79 $config['tbl_media']." AS m, ".
80 $config['tbl_locations']." AS l ".
81 "WHERE mediaid = '".addslashes($_GET['media'])."' AND ".
85 if (!$res = mysql_query($query))
87 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n\n";
91 if (!mysql_num_rows($res))
93 echo "Media not found.\n";
97 $row = mysql_fetch_assoc($res);
99 echo "<table class=\"ObjectParametersTable\">\n";
101 echo " <td>Media ID</td>\n";
102 echo " <td>".$row['mediaid']."</td>";
105 echo " <td>Media description</td>\n";
106 echo " <td>".$row["name"]."</td>";
109 echo " <td>Media type</td>\n";
110 echo " <td>".mb_typetext($row['type'])."</td>";
113 echo " <td>Current location</td>\n";
115 if ($row["description"])
117 echo "<a href=locations.php?id=".$row['id'].">".$row['description']."</a>";
127 ShowChangeLocationForm($_GET['media']);
131 if ($row['type'] == MB_T_AUDIO
)
133 $query = "SELECT * FROM ".$config['tbl_tracks']." WHERE mediaid = ".$row['mediaid']." ORDER BY trackid";
134 if (!$res = mysql_query($query))
136 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n\n";
140 if (!mysql_num_rows($res))
142 echo "No tracks found in database.\n\n";
146 mb_table_start('#','Name','Length');
147 if (isset($_GET['cat']))
149 $link = "\"$self?cat=".$_GET['cat'].'"';
155 mb_table_widecol("<a href=$link>Back to index</a>");
156 while ($row = mysql_fetch_assoc($res))
158 mb_table_col($row['trackid']);
159 mb_table_col($row['name']);
160 mb_table_col(mb_lengthtext($row['length']));
166 elseif ($row['type'] == MB_T_DATA
)
168 $dir = isset($_GET['dir']) ?
$_GET['dir'] : '/';
169 $parentdir = mb_getparentdir($dir);
171 echo "<p>".mb_icon('__folder').$dir."<p>";
173 $query = "SELECT * FROM ".$config['tbl_files'].
174 " WHERE path = '".addslashes($dir)."' AND ".
175 "mediaid = '".addslashes($_GET['media'])."' ".
178 if (!$res = mysql_query($query))
180 echo "<b>MySQL error at ".basename(__FILE__
).", line ".__LINE__
."<br>";
181 echo "<b>Error:</b> ".mysql_error()."<br>";
182 echo "<b>Error description :</b> " . mysql_errno() . "<br>";
183 echo "<b>SQL request:</b> ".$query."\n\n";
187 if (!mysql_num_rows($res))
189 echo "No files found.\n\n";
195 while ($row = mysql_fetch_assoc($res))
197 if (substr($row['name'],-1) == '/')
206 $selflink = "$self?media=".$_GET['media'].(isset($_GET['cat'])?
'&cat='.$_GET['cat']:'');
207 mb_table_start('Filename','Size','Timestamp');
210 mb_table_widecol(mb_icon('__folder')."<a href=\"$selflink&dir=".urlencode($parentdir)."\">Parent directory</a>");
214 if (isset($_GET['cat']))
216 $link = "\"$self?cat=".$_GET['cat'].'"';
222 mb_table_col("<a href=$link>Back to index</a>");
223 mb_table_col(' ');
224 mb_table_col(' ');
226 foreach ($folders as $folder)
228 $link = "<a href=\"$selflink&dir=".urlencode($dir.$folder['name']).'">'.$folder['name']."</a>";
229 mb_table_col(mb_icon('__folder').$link);
230 mb_table_col(' ');
231 mb_table_col(mb_datetext($folder['time']));
233 foreach ($files as $file)
236 mb_table_col(mb_icon('__unknown').$file['name']);
237 mb_table_col(mb_sizetext($file['size']));
238 mb_table_col(mb_datetext($file['time']));
246 echo "<b>Error:</b> Media must be either data or audio.\n";
251 elseif (!$config['use_categories'] ||
isset($_GET['cat']))
253 if ($config['use_categories'])
255 $query = "SELECT m.*,c.name as category FROM ".
256 $config['tbl_media']." AS m, ".
257 $config['tbl_categories']." AS c ".
258 "WHERE m.catid = c.catid AND c.catid = ".addslashes($_GET['cat'])." ORDER BY m.name";
262 $query = "SELECT l.description,l.id,m.* FROM ".
263 $config['tbl_media']." AS m, ".
264 $config['tbl_locations']." AS l ".
265 "WHERE m.location = l.id ".
266 "ORDER BY m.mediaid DESC";
269 if (!$res = mysql_query($query))
271 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n\n";
275 if (!mysql_num_rows($res))
277 echo "No media found".($config['use_categories']?
' in this category':'').".\n";
281 mb_table_start('Media ID',
286 if ($config['use_categories'])
288 mb_table_widecol("<a href=\"$self\">Back to category index</a>");
291 while ($row = mysql_fetch_assoc($res))
293 $extra = ($config['use_categories']?
'&cat='.$row['catid']:'');
294 $link = (($row['type'] == MB_T_AUDIO
) ||
($row['type'] == MB_T_DATA
));
295 mb_table_col($row['mediaid']);
296 mb_table_col(mb_iconbytype($row['type']).
297 ($link?
"<a href=\"$self?media=".
301 truncate_ellipsis($row['name'], $config['media_title_ellipsis_limit']).
303 mb_table_col(mb_datetext($row['added']));
304 mb_table_col("<a href=locations.php?id=".$row['id'].">".$row['description']."</a>");
314 $query = "SELECT c.catid,c.name,count(m.mediaid) AS count FROM ".$config['tbl_categories']." AS c LEFT JOIN ";
315 $query .= $config['tbl_media']." AS m ON m.catid = c.catid GROUP BY c.catid ORDER BY c.name";
316 if (!$res = mysql_query($query))
318 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__
).", line ".__LINE__
.")</i>\n\n";
322 if (!mysql_num_rows($res))
324 echo "No categories found.\n";
328 mb_table_start('Category','Media');
329 while ($row = mysql_fetch_assoc($res))
331 mb_table_col(mb_icon('__category').
332 "<a href=\"$self?cat=".
336 mb_table_col($row['count']);
343 require('inc.footer.php');