Modification log added
[mediadatabase.git] / php / index.php
blob5f56db25ccf8feeb6a76fea5f328107d835929c4
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\" class=\"input-select\">\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\" class=\"input-button\" value=\"Change\">\n";
40 echo "</form>\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";
49 else
51 $query = "UPDATE ".$GLOBALS['config']['tbl_media'].
52 " SET location = '".$new_location_id."'".
53 " WHERE mediaid = '".$media_id."'";
54 // echo $query;
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";
63 return;
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']);
77 echo "<p>\n";
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 ".
82 "m.location = l.id ".
83 "ORDER BY name";
85 if (!$res = mysql_query($query))
87 echo "<b>Error:</b> ".mysql_error()." <i>(".basename(__FILE__).", line ".__LINE__.")</i>\n\n";
89 else
91 if (!mysql_num_rows($res))
93 echo "Media not found.\n";
95 else
97 $row = mysql_fetch_assoc($res);
99 echo "<table class=\"ObjectParametersTable\">\n";
100 echo " <tr>\n";
101 echo " <td>Media ID</td>\n";
102 echo " <td>".$row['mediaid']."</td>";
103 echo " </tr>\n";
104 echo " <tr>\n";
105 echo " <td>Media description</td>\n";
106 echo " <td>".$row["name"]."</td>";
107 echo " </tr>\n";
108 echo " <tr>\n";
109 echo " <td>Media type</td>\n";
110 echo " <td>".mb_typetext($row['type'])."</td>";
111 echo " </tr>\n";
112 echo " <tr>\n";
113 echo " <td>Current location</td>\n";
114 echo " <td>";
115 if ($row["description"])
117 echo "<a href=locations.php?id=".$row['id'].">".$row['description']."</a>";
119 else
121 echo "Unknown.";
123 echo " </td>\n";
124 echo " <tr>\n";
125 echo "</table>\n";
126 echo "<p>\n";
127 ShowChangeLocationForm($_GET['media']);
128 echo "</p>\n";
129 echo "<p>\n";
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";
138 else
140 if (!mysql_num_rows($res))
142 echo "No tracks found in database.\n\n";
144 else
146 mb_table_start('#','Name','Length');
147 if (isset($_GET['cat']))
149 $link = "\"$self?cat=".$_GET['cat'].'"';
151 else
153 $link = "\"$self\"";
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']));
162 mb_table_end();
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'])."' ".
176 "ORDER BY name";
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";
185 else
187 if (!mysql_num_rows($res))
189 echo "No files found.\n\n";
191 else
193 $folders = array();
194 $files = array();
195 while ($row = mysql_fetch_assoc($res))
197 if (substr($row['name'],-1) == '/')
199 $folders[] = $row;
201 else
203 $files[] = $row;
206 $selflink = "$self?media=".$_GET['media'].(isset($_GET['cat'])?'&cat='.$_GET['cat']:'');
207 mb_table_start('Filename','Size','Timestamp');
208 if ($parentdir)
210 mb_table_widecol(mb_icon('__folder')."<a href=\"$selflink&dir=".urlencode($parentdir)."\">Parent directory</a>");
212 else
214 if (isset($_GET['cat']))
216 $link = "\"$self?cat=".$_GET['cat'].'"';
218 else
220 $link = "\"$self\"";
222 mb_table_col("<a href=$link>Back to index</a>");
223 mb_table_col('&nbsp;');
224 mb_table_col('&nbsp;');
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('&nbsp;');
231 mb_table_col(mb_datetext($folder['time']));
233 foreach ($files as $file)
235 echo " <tr>\n";
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']));
240 mb_table_end();
244 else
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";
260 else
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";
273 else
275 if (!mysql_num_rows($res))
277 echo "No media found".($config['use_categories']?' in this category':'').".\n";
279 else
281 mb_table_start('Media ID',
282 'Name',
283 'Date Added',
284 'Location');
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=".
298 $row['mediaid'].
299 $extra.
300 '">':'').
301 truncate_ellipsis($row['name'], $config['media_title_ellipsis_limit']).
302 ($link?'</a>':''));
303 mb_table_col(mb_datetext($row['added']));
304 mb_table_col("<a href=locations.php?id=".$row['id'].">".$row['description']."</a>");
307 mb_table_end();
311 else
313 echo "<p>\n";
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";
320 else
322 if (!mysql_num_rows($res))
324 echo "No categories found.\n";
326 else
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=".
333 $row['catid'].'">'.
334 $row['name'].
335 "</a>");
336 mb_table_col($row['count']);
338 mb_table_end();
343 require('inc.footer.php');