<?php
$headers = array(
'Ariketa' => array('data' => 'Ariketa', 'field' => 'n.title', 'sort' => 'asc'),
'Fitxategia' => array('data' => 'Fitxategia', 'field' => 'filename', 'sort' => 'asc'),
'Akatsa' => array('data' => 'Akatsa', 'field' => 'pn.title', 'sort' => 'asc'),
'Tamaina',
);
$order = isset($_GET['order']) ? $headers[$_GET['order']]['field'] : 'n.title';
$sort = isset($_GET['sort']) ? $_GET['sort'] : 'asc';
$order_by = " ORDER BY $order $sort";
$result = db_query('SELECT n.title, filename, filesize, filepath, n.nid, pn.nid pn_nid, pn.title pn_title FROM `upload` u
LEFT JOIN files f ON u.fid = f.fid
LEFT JOIN node n ON u.vid = n.vid
LEFT JOIN node_relations nr ON n.nid = nr.nid AND nr.type = "509"
LEFT JOIN node pn ON nr.pnid = pn.nid
WHERE n.type = "ariketa" AND f.filemime = "audio/mpeg" '.$order_by);
while($row = db_fetch_object($result)){
$title = l($row->title, "node/$row->nid");
$file = l($row->filename, $row->filepath);
$akats = l($row->pn_title, "node/$row->pn_nid");
$rows[] = array($title, $file, $akats, number_format($row->filesize/(1024*8), 2) .' KB.');
}
print theme('table', $headers, $rows);
?>