<?php

include('fonctions/config.php');
include('fonctions/common.php');
include('fonctions/mysql.php');
include('fonctions/SitoSecurity.php');


// Avant de supprimer un audio, ce script verifie si l'audio a été supprimée dans la base de données


define('PATH_ROOT','/home/media/');
define('PATH_AUDIO_ROOT','audio/fichiers/');

$path_order = PATH_ROOT.'audio/import/order/order-delete-audio/';


echo 'Start : '.date('r').'<br>'."\n";


exec('ls '.$path_order,$tab_output);

foreach($tab_output as $i => $file_order) {
   $sid_audio = trim(file_get_contents($path_order.$file_order));

   if((!empty($sid_audio))) {

      $db = db_connect();
      
      $id_audio = SitoSecurity::get_id_security($sid_audio);

      if(!empty($id_audio)) {

         $query 	 = 'SELECT * FROM `media_to_delete` WHERE `id_media`=\''.$id_audio.'\' LIMIT 1';
         $tab_media_to_delete = get_row($query);

         if(!empty($tab_media_to_delete['path_and_file_to_delete'])) {

            // delete order
            unlink($path_order.$file_order);

            // delete file
            $file_and_path = $tab_media_to_delete['path_and_file_to_delete'];
            unlink(PATH_ROOT.PATH_AUDIO_ROOT.$file_and_path);

            // trun off delete media
            $query 	 = 'DELETE FROM `media_to_delete` WHERE `id_media`=\''.$id_audio.'\' LIMIT 1';
      	   db_update($query);

            echo 'delete done '.PATH_ROOT.PATH_AUDIO_ROOT.$file_and_path."\n".'<br>';

         }
      }

   }
}


echo 'End : '.date('r').'<br>'."\n";

?>