<?php

    require_once("{$sitepath}autentificare.php");
    require_once("{$sitepath}pagecomponents.php");
    require_once("{$sitepath}scripts/httpdownload.php");

    check_auth();
    
    if (!isset($run_from_service))
    {
        $id = getuserdata('id', 0);
        $v = getuserdata('v', 0);
    }
    
    $errorMessage = "";
    
    $sql = "\nSELECT ".
           "\n    f.* ".
           "\nFROM fisiere f ".
           "\nWHERE f.id_fisier = $id";
    $q = mysql_query($sql);
    echo mysql_error();
    while ($r = mysql_fetch_assoc($q))
    {
        $download = new HTTP_Download();
        $download->setContentType($r['tip_fisier']);
        $download->setFile($filespath.$r['id_utilizator_sursa'].substr($filespath, strlen($filespath) - 1).
                           $r['nume_fisier']);
        $download->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $r['nume_original']);
        $download->send();
        if ( ($v == 1) && ($r['stare'] == 1) )
            mysql_query("UPDATE fisiere SET stare = 2 WHERE id_fisier = $id AND stare = 1");
    }
   
?>