Subversion Repositories computer_asset_manager_v1

Rev

Rev 61 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

<?php

   function filesView( $parameters ) {
      if ( isset( $parameters['device_id'] ) ) {
         $where = "owner_type = 'd' and owner_id = $parameters[device_id]";
         $join = 'join device on (device.device_id = file.owner_id)';
      } elseif ( isset( $parameters['site_id'] ) ) {
         $where = "owner_type = 's' and owner_id = $parameters[site_id]";
         $join = 'join site on (site.site_id = file.owner_id)';
      } elseif ( isset( $parameters['client_id'] ) ) {
         $where = "owner_type = 'c' and owner_id = $parameters[client_id]";
         $join = 'join client on (client.client_id = file.owner_id)';
      } else {
         return null;
      }
      $nameField = queryHTMLLink( 'modules/file/display.php?file_id=', 'file.file_id', 'file.name', true );
      $deleteField = queryHTMLLink( 'modules/file/delete.php?file_id=', 'file.file_id', "'Delete'" );
      $editField = queryHTMLLink( 'modules/file/upload_file.html?file_id=', 'file.file_id', "'Edit'" );
      //concat( '<a href=\"', file.file_id, '\"', 'target=\"_blank\">', file.name, '</a>')      
      $query = "select 
                   file.file_id 'ID',\n
                   $nameField 'Name', 
                   file.description 'Description', 
                   file_mime_type.mime_type 'MIME', 
                   file.added_date 'Added',
                   concat( $deleteField, ' ', $editField ) 'Action'
                from file 
                     left outer join file_mime_type using (file_mime_type_id)
                     $join
                where
                   $where
                   and file.removed_date is null
                order by file.name, file.added_date";
      //file_put_contents( '/home/rodolico/www/web/computer_asset_manager_v1/modules/file/queryout.sql', $query );
      //print '<pre>' . print_r($query) . '</pre>';
      //file_put_contents( '/home/rodolico/www/web/computer_asset_manager_v1/modules/file/table.html', queryToTable( $query ) );
      return queryToTable( $query );
   }
   
   function queryHTMLLink ( $url, $hrefLink, $hrefDisplay, $newPage = false ) {
      return "concat( '<a href=\"', '$url', $hrefLink, '\"'," . ( $newPage ? " 'target=\"_blank\"', " : '' ) . "'>', $hrefDisplay, '</a>')";
   }

?>