HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: /var/www/html/coreplad/sites/all/modules/corepla_user/corepla_user.module
<?php
/**
 * Implements hook_menu().
 */

function corepla_user_permission() {
  return array(
	'edit corepla user' => array(
      'title' => t('Permetti di creare il proprio profilo'),
    ),
	'accreditation corepla user' => array(
      'title' => t('Permetti di accreditare il cliente'),
    )
  ); 
}


function corepla_user_menu() {
	
	$items['customer/register/choose'] = array(
		'title' => 'Accreditamento',
		'description' => "Forma Accreditamento",
		'page callback' => 'corepla_user_choose',
		'page arguments' => array(0),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.choose.inc',
	);
	
	$items['customer/register/%'] = array(
		'title' => 'Accreditamento',
		'description' => "Forma Accreditamento",
		'page callback' => 'corepla_user_create_page',
		'page arguments' => array(2),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.create.inc',
	);
	
	$items['customer/completation'] = array(
		'title' => 'Completamento Accreditamento Cliente',
		'description' => "Accreditamento di un nuovo cliente Corepla",
		'page callback' => 'drupal_get_form',
		'page arguments' => array('corepla_user_complete_form'),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.completation.inc',
	);
	
	$items['customer/completation/accept/%'] = array(
		'title' => 'Completamento Accreditamento Cliente',
		'description' => "Accreditamento di un nuovo cliente Corepla",
		'page callback' => 'corepla_user_customer_accept',
		'page arguments' => array(3),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.accept.inc',
	);
	
	$items['customer/completation/accept-term/%'] = array(
		'title' => 'Completamento Accreditamento Cliente',
		'description' => "Accreditamento di un nuovo cliente Corepla",
		'page callback' => 'corepla_accept_term',
		'page arguments' => array(3),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
	);
	
	$items['customer/message/%'] = array(
		'title' => 'Customer Message',
		'description' => "Messaggi Cliente",
		'page callback' => 'corepla_user_customer_message',
		'page arguments' => array(2),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
	);
	
	$items['customer/pre-activate/%/%/%'] = array(
		'title' => 'Attiva Cliente',
		'description' => "Funzione per attiare il cliente",
		'page callback' => 'corepla_user_customer_pre_activate',
		'page arguments' => array(2,3,4),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.pre_activate.inc',
	);
	
	$items['customer/activate/%/%'] = array(
		'title' => 'Attiva Cliente',
		'description' => "Funzione per attiare il cliente",
		'page callback' => 'corepla_user_customer_activate',
		'page arguments' => array(2,3),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
	);
	
	/*
	$items['customer/accreditation'] = array(
		'title' => 'Accreditamento Cliente',
		'description' => "Accreditamento di un nuovo cliente Corepla",
		'page callback' => 'drupal_get_form',
		'page arguments' => array('corepla_user_accreditation_form'),
		'type' => MENU_CALLBACK,
		'access arguments' => array('accreditation corepla user'),
		'file' => 'customer.accreditation.inc',
	);
	*/
	
	$items['customer/regenerate'] = array(
		'title' => 'Reset Password',
		'description' => "Operazioni per resettare la password",
		'page callback' => 'drupal_get_form',
		'page arguments' => array('corepla_user_customer_reset_form'),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.reset.inc',
	);
	
	$items['customer/change-psw/%/%'] = array(
		'title' => 'Change Password',
		'description' => "Operazioni di cambio password",
		'page callback' => 'drupal_get_form',
		'page arguments' => array('corepla_user_customer_psw_form', 2, 3),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.reset.inc',
	);
	
	$items['customer/comuni/list'] = array(
		'title' => 'Ajax Lista Comuni',
		'description' => "Lista dei Comuni",
		'page callback' => 'corepla_user_customer_comuni_list',
		'page arguments' => array(0),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
	);
	
	
	/*
	$items['customer/register/accept/%'] = array(
		'title' => 'Completamento Accreditamento Cliente',
		'description' => "Accreditamento di un nuovo cliente Corepla",
		'page callback' => 'corepla_user_customer_register_accept',
		'page arguments' => array(3),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.accept.inc',
	);*/
	
	$items['customer/change-psw-int'] = array(
		'title' => 'Modifica Password',
		'description' => "Operazioni di cambio password",
		'page callback' => 'drupal_get_form',
		'page arguments' => array('corepla_user_customer_psw_int_form'),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.reset.inc',
	);
	/*
	$items['customer/pdf'] = array(
		'title' => 'Accreditamento',
		'description' => "Forma Accreditamento",
		'page callback' => 'generateSendAttachCGV',
		'page arguments' => array(2),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
		'file' => 'customer.completation.inc',
	);
	*/
	$items['customer/xls'] = array(
		'title' => 'Accreditamento',
		'description' => "Forma Accreditamento",
		'page callback' => 'generateXlsAttachRiepilogo',
		'page arguments' => array(2),
		'type' => MENU_CALLBACK,
		'access arguments' => array('edit corepla user'),
	);
	return $items;
}

function corepla_accept_term($idTerm){
	if(!isset($_SESSION["accreditation"])){
		drupal_goto("");
	}else{
		
		$loadUtente = $_SESSION["accreditation"];
		if($idTerm == 1){
			$_SESSION["accreditation"]["aste"] = 1;
	
		}else if($idTerm == 2){
			$_SESSION["accreditation"]["cnd"] = 1;
		}else if($idTerm == 3){
			$_SESSION["accreditation"]["1341"] = 1;
		}else if($idTerm == 4){
			$_SESSION["accreditation"]["231"] = 1;
		}
		
		drupal_goto("customer/completation");
	}
	exit;
}

function corepla_user_theme($existing, $type, $theme, $path) {
	return array(
		'customer_accept'  => array(
		  'arguments' => array(),
		  'template' => 'themes/customer_accept'
		),
		'customer_register_accept'  => array(
		  'arguments' => array(),
		  'template' => 'themes/customer_register_accept'
		)
	);
}

function corepla_user_customer_comuni_list(){
	$arrayComuni = array();
	
	$varCodiceProv = $_POST["idProvincia"];
	
	
	$result = db_query('SELECT corepla_comuni.codice_comune, corepla_comuni.comune, corepla_cap.cap FROM corepla_comuni LEFT JOIN corepla_cap ON corepla_comuni.codice_comune = corepla_cap.codice_comune WHERE codice_provincia = :codProv ORDER BY corepla_comuni.comune', array(':codProv' => $varCodiceProv));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	
	$arrayComuni[0] = array();
	$arrayComuni[0]["comune"] = "--Seleziona--";
	$arrayComuni[0]["cap"] = "";
	
	foreach ($result as $record) {
		$arrayComuni[$record->codice_comune] = array();
		$arrayComuni[$record->codice_comune]["comune"] = $record->comune;
		$arrayComuni[$record->codice_comune]["cap"] = $record->cap;
	}
	
	
	drupal_json_output($arrayComuni);
}

function corepla_user_customer_message($idMessaggio){
	
	$lblMessage = "";
	switch ($idMessaggio) {
		case 0:
			$lblMessage = t('Un errore imprevisto non ha permesso il completamento del processo. Si prega di contattare l\'amministratore del sistema.');
			break;
		case 1:
			$lblMessage = t('Il suo token per l\'attivazione del suo utente è scaduto. Si prega di riprovare la procedura.');
			break;
		case 2:
			$lblMessage = t('L\'Account è stato attivato correttamente. Adesso puoi accedere alla pagina dei Prodotti e farne richiesta. <a href="'.variable_get("site_base").'riciclare-con-corepla">Vai alla sezione</a>');
			break;
		case 3:
			$lblMessage = t('Operazione avvenuta con successo.');
			break;
		case 4:
			$lblMessage = t('La registrazione è avvenuta con successo. A breve riceverai una mail con un link per attivare l\'Account.');
			break;
		case 5:
			$lblMessage = t('È stata inviata un\'e-mail con le istruzioni necessarie per modificare la password.');
			break;
		case 6:
			$lblMessage = t('Si è verificato un errore e l\'elaborazione non è stata completata.');
			break;
		case 7:
			$lblMessage = t('Utente non trovato in archivio.');
			break;
		case 8:
			$lblMessage = t('Questo utente risulta già attivato.');
			break;	
			
		case 100:
			$lblMessage = 'Complimenti, la tua richiesta è andata a buon fine.<br >A breve riceverai alla mail che ci ha indicato il link per confermare la tua identità.<br><br>Il Team COREPLA';
			
			break;
	}
	
	return "<p>".$lblMessage."</p>";
}

function corepla_user_mail($key, &$message, $params) {
	switch ($key) {
		case 'accept':
			$message['subject'] = $params['subject'];
			$message['body'][] = $params['body'];
			if (isset($params['attachment'])) {
				$message['params']['attachments'][] = $params['attachments'];
			}
		break;
    }
}


function corepla_user_customer_activate($uid, $token){
	//generateXlsAttachRiepilogo(6);
	
	//exit;
	$result = db_query('SELECT * FROM {users} WHERE uid = :uid', array(':uid' => $uid));
	$recordU = $result->fetchObject();  
	if(!isset($recordU->name)){
		drupal_goto("customer/message/0");
	}else if ((isset($recordU->name))&& ($recordU->status == 1)){
		drupal_goto("customer/message/8");
	}else if ((isset($recordU->name)) && ($recordU->status == 0)){
	//if(1==1){
		//esiste
		$tokenGen = md5(date("Y-m-d")."@".$recordU->name);
		

		if($tokenGen != $token) {
		//if(1==2){
			//drupal_goto("error-page-expiration");
			corepla_user_customer_message(1);
		}else{
			
			$loadUser = user_load($uid);
			
			$resultUser = db_query('SELECT * FROM {corepla_user} WHERE username=:username', array(':username' => $loadUser->name));
			//$resultUser = db_query('SELECT * FROM {corepla_user} WHERE username=:username', array(':username' => 'rfalchi'));
			$record = $resultUser->fetchObject(); 
			
			//ATTIVAZIONE UTENTE
			
			$loadUser->status = 1;
			
			user_save($loadUser);
			
			$num_updated = db_update('corepla_user') // Table name no longer needs {}
			  ->fields(array(
				'stato' => 1,
			  ))
			  ->condition('username', $recordU->name, '=')
			  ->execute();
			if ($record->sono == 3){
				$varRagSocL = $record->rag_soc3;
			}else{
				$varRagSocL = $record->rag_soc;
			}
			
			$msgBody = 'Spett.le '.$varRagSocL.',<br /><br />				
			ti confermiamo che la tua utenza è stata correttamente abilitata. I dati e la documentazione inviati verranno elaborati internamente.<br><br>
			Sarete contattati dal Team COREPLA per eventuali richieste aggiuntive e per definire tempi e modalità dell\'auditing qualora la richiesta rispondesse ai requisiti previsti.<br /><br />
			Per qualsiasi chiarimento potete contattarci all\'indirizzo <a href="mailto:marketing@corepla.it">marketing@corepla.it</a><br /><br />
			A presto!<br /><br />
			Il Team COREPLA';
			
			$msgBody2 = 'In data odierna la società '.$varRagSocL.' ha avviato una richiesta di accreditamento per la quale sono allegate le accettazioni dei documenti preliminari.';	
			//MANDA EMAIL	
			$params = array();
			$params['subject'] = "Corepla - Registrazione Completata - Tipologia ".$record->sono;
			$params['body'] = $msgBody;
			
			$params2 = array();
			$params2['subject'] = "Corepla - Registrazione Completata - Tipologia ".$record->sono;
			$params2['body'] = $msgBody2;
			
			$arrayPdfRet = array();
			$arrayPdfRet = generatePdfAttachment($record->id);
	
			$attachments = array();
			
			
			if(isset($record->fid_cgv) && ($record->fid_cgv > 0)){
				$loadFileCGV = file_load($record->fid_cgv);
			
				$file_cgv = file_get_contents(file_create_url($loadFileCGV->uri));
				$attachments[0] = array(
				  'filecontent' => $file_cgv,
				  'filename' => $loadFileCGV->filename,
				  'filemime' => $loadFileCGV->filemime
				);
			}
			
				
			$file_content4 = file_get_contents(variable_get("site_base").'sites/all/themes/corepla/doc/PrivacyPolicy.pdf');
			$attachments[1] = array(
			  'filecontent' => $file_content4,
			  'filename' => 'PrivacyPolicy.pdf',
			  'filemime' => 'application/pdf'
			);

			$countAttach = 2;
			//Autorizzazione
			if(isset($record->fid) && ($record->fid > 0)){
				$loadFile = file_load($record->fid);
			
				$file_contentA = file_get_contents(file_create_url($loadFile->uri));
				$attachments[$countAttach] = array(
				  'filecontent' => $file_contentA,
				  'filename' => $loadFile->filename,
				  'filemime' => $loadFile->filemime
				);
				
				$countAttach++;
			}
			
			
			//Certificazione EuCertPlast
			if(isset($record->fid_eucertplast) && ($record->fid_eucertplast > 0)){
				$loadFile = file_load($record->fid_eucertplast);
			
				$file_content5 = file_get_contents(file_create_url($loadFile->uri));
				$attachments[$countAttach] = array(
				  'filecontent' => $file_content5,
				  'filename' => $loadFile->filename,
				  'filemime' => $loadFile->filemime
				);
				
				$countAttach++;
			}

			//Certificazione 9001
			if(isset($record->fid_90012015) && ($record->fid_90012015 > 0)){
				$loadFile = file_load($record->fid_90012015);
			
				$file_contentY = file_get_contents(file_create_url($loadFile->uri));
				$attachments[$countAttach] = array(
				  'filecontent' => $file_contentY,
				  'filename' => $loadFile->filename,
				  'filemime' => $loadFile->filemime
				);
				
				$countAttach++;
			}

			//Certificazione 140012015
			if(isset($record->fid_140012015) && ($record->fid_140012015 > 0)){
				$loadFile = file_load($record->fid_140012015);
			
				$file_contentZ = file_get_contents(file_create_url($loadFile->uri));
				$attachments[$countAttach] = array(
				  'filecontent' => $file_contentZ,
				  'filename' => $loadFile->filename,
				  'filemime' => $loadFile->filemime
				);
				
				$countAttach++;
			}
			//Iscrizione categoria 8
			if(isset($record->fid_cat8) && ($record->fid_cat8 > 0)){
				$loadFile = file_load($record->fid_cat8);
			
				$file_contentAA = file_get_contents(file_create_url($loadFile->uri));
				$attachments[$countAttach] = array(
				  'filecontent' => $file_contentAA,
				  'filename' => $loadFile->filename,
				  'filemime' => $loadFile->filemime
				);
				
				$countAttach++;
			}
			
			if(isset($record->fid_prod) && ($record->fid_prod > 0)){
				$loadFile = file_load($record->fid_prod);
			
				$file_contentW = file_get_contents(file_create_url($loadFile->uri));
				$attachments[$countAttach] = array(
				  'filecontent' => $file_contentW,
				  'filename' => $loadFile->filename,
				  'filemime' => $loadFile->filemime
				);
				
				$countAttach++;
			}
			
			
			$params['attachments'] = $attachments;
			$file_contentX = file_get_contents(variable_get("site_base").'sites/default/files/accreditamento/'.$arrayPdfRet['riepilogo'].'.xlsx');
			
			/*watchdog("FILE_XLS", $arrayPdfRet['riepilogo']);
			$keyAttach = 2;
			if(array_key_exists(2, $attachments)){
				$keyAttach = 3;
			}*/
			
			$attachments[$countAttach] = array(
			  'filecontent' => $file_contentX,
			  'filename' => 'Riepilogo.xlsx',
			  'filemime' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
			);
			
			
			//$params['attachments'] = $attachments;
			
			//attachment solo per corepla
			$attachments2 = array();
			$attachments2 = $attachments;
	
			$params2['attachments'] = $attachments2;
			//$params2['attachments'] = $attachments;

			//to
			drupal_mail("corepla_user", "accept", variable_get("email_accreditamento"), "it", $params, NULL);
			//ccn
			if ($record->sono==3){
				drupal_mail("corepla_user", "accept", $record->email3, "it", $params, NULL);
			}else{
				drupal_mail("corepla_user", "accept", $record->sede_leg_email, "it", $params, NULL);
			}
			drupal_mail("corepla_user", "accept", 'marketing@corepla.it', "it", $params2, NULL);
			drupal_mail("corepla_user", "accept", "vendite@corepla.it", "it", $params2, NULL);
			drupal_mail("corepla_user", "accept", "falchi.roberto@gmail.com", "it", $params2, NULL);


			//SCRIVI A VIDEO
			return $msgBody;
			
		}
	}
	
	
}

function generatePdfAttachment($user_id){
	//$CGV = generatePdfAttachCGV($user_id);
	//$Regolamento = generatePdfAttachment2($user_id);
	//$Legge231 = generatePdfAttach231($user_id);
	//$Legge1341 = generatePdfAttach1341($user_id);
	//$riepilogo = generatePdfAttachRiepilogo($user_id);
	$riepilogo = generateXlsAttachRiepilogo($user_id);
	
	$arrayRet = array();
	//$arrayRet["cgv"] = $CGV;
	//$arrayRet["reg"] = $Regolamento;
	//$arrayRet["231"] = $Legge231;
	//$arrayRet["1341"] = $Legge1341;
	$arrayRet["riepilogo"] = $riepilogo;
	
	return $arrayRet;
}

function generatePdfAttachCGV($user_id){
	//LIBRERIA MPDF
	require_once drupal_get_path('module', 'corepla_user') . '/mpdf/vendor/autoload.php';
	

	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
			
	// Create an instance of the class:
	//$mpdf = new \Mpdf\Mpdf();
	$mpdf = new \Mpdf\Mpdf(['tempDir' => '/var/www/html/tmp']);
	
	$pathTemplate = drupal_get_path('module', 'corepla_user') . '/template/allegato_standard.html';
	$htmlTemplate = file_get_contents($pathTemplate);
	
	//CSS
	$pathStyle = drupal_get_path('module', 'corepla_user') . '/template/style.css';
	$stylesheet = file_get_contents($pathStyle);
	
	//DICHIARO MPDF
	$mpdf->SetTitle('COREPLA');
	
    $mpdf->WriteHTML($stylesheet,1);
	
		
	$result = db_query('SELECT * FROM {corepla_user} WHERE id = :id', array(':id' => $user_id));
	$record = $result->fetchObject(); 
	
	$htmlTemplate = str_replace("-TXT_DATA-", date("d.m.Y"), $htmlTemplate);
	
	$htmlTemplate = str_replace("-TXT_TITOLO-", "Condizioni Generali di Vendita all’Asta", $htmlTemplate);
	
	$varNomeCitta  = "";
	if(isset($record->sede_leg_citta) && ($record->sede_leg_citta !="")){
		
		if($record->sede_leg_stato == "I"){
			$varNomeCitta = $arrayComuni[$record->sede_leg_citta];
		}else{
			$varNomeCitta = $record->sede_leg_citta;
		}
	}
	$testo1 = 'La sottoscritta Società <strong>'.$record->rag_soc.'</strong> con sede legale in <strong>'.$varNomeCitta.'</strong> via <strong>'.$record->sede_leg_ind.'</strong>, iscritta nel registro delle Imprese di <strong>'.$varNomeCitta.'</strong> con numero di iscrizione e codice fiscale <strong>'.$record->piva.'</strong>, in persona del proprio legale rappresentante Sig. <strong>'.$record->sede_leg_contatto.'</strong>, ha richiesto tramite l\'apposita sezione disponibile sul sito www.corepla.it di essere accreditata per la vendita/fornitura di prodotti COREPLA e dichiara di aver preso visione e accettato le Condizioni Generali di Vendita all\'Asta revisione n. 15 del 01 Marzo 2022.';
	
	$htmlTemplate = str_replace("-TXT_BODY-", $testo1, $htmlTemplate);
		
	$mpdf->ignore_invalid_utf8 = true;
	
	$mpdf->WriteHTML($htmlTemplate,2);
        
	$namefile = "CGV_".$user_id."_".date("YmdHis");
	//$mpdf->Output('/var/www/vhosts/coreplatest.releax.it/httpdocs/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	$mpdf->Output('/var/www/html/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	return $namefile;
	exit;
}

function generatePdfAttach231($user_id){
	//LIBRERIA MPDF
	require_once drupal_get_path('module', 'corepla_user') . '/mpdf/vendor/autoload.php';
	

	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
			
	// Create an instance of the class:
	//$mpdf = new \Mpdf\Mpdf();
	$mpdf = new \Mpdf\Mpdf(['tempDir' => '/var/www/html/tmp']);
	
	$pathTemplate = drupal_get_path('module', 'corepla_user') . '/template/allegato_standard.html';
	$htmlTemplate = file_get_contents($pathTemplate);
	
	//CSS
	$pathStyle = drupal_get_path('module', 'corepla_user') . '/template/style.css';
	$stylesheet = file_get_contents($pathStyle);
	
	//DICHIARO MPDF
	$mpdf->SetTitle('COREPLA');
	
    $mpdf->WriteHTML($stylesheet,1);
	
		
	$result = db_query('SELECT * FROM {corepla_user} WHERE id = :id', array(':id' => $user_id));
	$record = $result->fetchObject(); 
	
	$htmlTemplate = str_replace("-TXT_DATA-", date("d.m.Y"), $htmlTemplate);
	
	$htmlTemplate = str_replace("-TXT_TITOLO-", "D. Lgs. 231/2001", $htmlTemplate);
	
	$varNomeCitta  = "";
	if(isset($record->sede_leg_citta) && ($record->sede_leg_citta !="")){
		if($record->sede_leg_stato == "I"){
			$varNomeCitta = $arrayComuni[$record->sede_leg_citta];
		}else{
			$varNomeCitta = $record->sede_leg_citta;
		}
	}
	
	$testo1 = 'La sottoscritta Società <strong>'.$record->rag_soc.'</strong> con sede legale in <strong>'.$varNomeCitta.'</strong> via <strong>'.$record->sede_leg_ind.'</strong>, iscritta nel registro delle Imprese di <strong>'.$varNomeCitta.'</strong> con numero di iscrizione e codice fiscale <strong>'.$record->piva.'</strong>, in persona del proprio legale rappresentante Sig. <strong>'.$record->sede_leg_contatto.'</strong>, dichiara che non è mai stata sanzionata ai sensi del D.Lgs. 231/2001<br><br>';
	
	$testo1 .= 'Nel caso vengano effettuate attività per le quali è prevista l\'erogazione di un contributo da parte di COREPLA, in aggiunta a quanto sopra, dichiara inoltre che nello svolgimento delle attività oggetto di contratto con COREPLA non sono impiegate terze parti il cui ente stesso non sia già stato sottoposto a sanzioni ai sensi del D.Lgs. 231/2001, come risulta dalla documentazione da queste presentata e conservata a proprio carico';
		
	$htmlTemplate = str_replace("-TXT_BODY-", $testo1, $htmlTemplate);
		
	$mpdf->ignore_invalid_utf8 = true;
	
	$mpdf->WriteHTML($htmlTemplate,2);
        
	$namefile = "231_".$user_id."_".date("YmdHis");
	//$mpdf->Output('/var/www/vhosts/coreplatest.releax.it/httpdocs/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	$mpdf->Output('/var/www/html/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	return $namefile;
	exit;
}

function generatePdfAttach1341($user_id){
	//LIBRERIA MPDF
	require_once drupal_get_path('module', 'corepla_user') . '/mpdf/vendor/autoload.php';
	

	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
			
	// Create an instance of the class:
	//$mpdf = new \Mpdf\Mpdf();
	$mpdf = new \Mpdf\Mpdf(['tempDir' => '/var/www/html/tmp']);
	
	$pathTemplate = drupal_get_path('module', 'corepla_user') . '/template/allegato_standard.html';
	$htmlTemplate = file_get_contents($pathTemplate);
	
	//CSS
	$pathStyle = drupal_get_path('module', 'corepla_user') . '/template/style.css';
	$stylesheet = file_get_contents($pathStyle);
	
	//DICHIARO MPDF
	$mpdf->SetTitle('COREPLA');
	
    $mpdf->WriteHTML($stylesheet,1);
	
		
	$result = db_query('SELECT * FROM {corepla_user} WHERE id = :id', array(':id' => $user_id));
	$record = $result->fetchObject(); 
	
	$htmlTemplate = str_replace("-TXT_DATA-", date("d.m.Y"), $htmlTemplate);
	
	$htmlTemplate = str_replace("-TXT_TITOLO-", "Accettazione espressa ai sensi degli art. 1341 e ss. del C.C.", $htmlTemplate);
	
	$varNomeCitta  = "";
	if(isset($record->sede_leg_citta) && ($record->sede_leg_citta !="")){
		if($record->sede_leg_stato == "I"){
			$varNomeCitta = $arrayComuni[$record->sede_leg_citta];
		}else{
			$varNomeCitta = $record->sede_leg_citta;
		}
	}
		
	$testo1 = 'Ai sensi degli art. 1341 e ss. C.C. la sottoscritta Società <strong>'.$record->rag_soc.'</strong> con sede legale in <strong>'.$varNomeCitta.'</strong> via <strong>'.$record->sede_leg_ind.'</strong>, iscritta nel registro delle Imprese di <strong>'.$varNomeCitta.'</strong> con numero di iscrizione e codice fiscale <strong>'.$record->piva.'</strong>, in persona del proprio legale rappresentante Sig. <strong>'.$record->sede_leg_contatto.'</strong>, accetta espressamente gli artt. delle Condizioni Generali di Vendita all\'Asta revisione n. 15 del 1 Marzo 2022:';
	
	$testo1 .= '<ul>3. Ritiro, trasporto e trasferimento dei rischi;
	<li>4. Qualità e reclami;</li>
	<li>5. Garanzia di risultato e limitazioni di responsabilità;</li>
	<li>6. Garanzie fornite dall’Aggiudicatario;</li>
	<li>7.2 Imballaggi;</li>
	<li>8. Prezzo;</li>
	<li>9. Pagamento e fatturazione;</li>
	<li>10. Cessione;</li>
	<li>12. Clausola risolutiva espressa;</li>
	<li>13. Forza maggiore;</li>
	<li>16. Foro competente;</li>
	<li>17. Codice Etico – Modello di Organizzazione e di Gestione ai sensi del D.Lgs. 231/2001.</li></ul>';
	
	$htmlTemplate = str_replace("-TXT_BODY-", $testo1, $htmlTemplate);
		
	$mpdf->ignore_invalid_utf8 = true;
	
	$mpdf->WriteHTML($htmlTemplate,2);
        
	$namefile = "1341_".$user_id."_".date("YmdHis");
	//$mpdf->Output('/var/www/vhosts/coreplatest.releax.it/httpdocs/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	$mpdf->Output('/var/www/html/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	return $namefile;
	exit;
}

function generateXlsAttachRiepilogo($user_id){
	
	/* rfalchi start */
	//$user_id = 27;
	/* end start */
	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
			
		
	$result = db_query('SELECT * FROM {corepla_user} WHERE id = :id', array(':id' => $user_id));
	$record = $result->fetchObject(); 
	
	$arrayProv = array();
	$result2 = db_query('SELECT codice_provincia, provincia FROM {corepla_comuni} WHERE 1=:one GROUP BY codice_provincia  ORDER BY provincia', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayProv["0"] = "--Seleziona--";
	foreach ($result2 as $record2) {
		$arrayProv[$record2->codice_provincia] = $record2->provincia;
	}
	
	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
	
	$tipoSono = array(0 => t('Riciclatore'), 1 => t('Intermediario'));
	
	$tipoPaese = array();
	$tipoPaese["A"] = "Austria";
	$tipoPaese["B"] = "Belgio";
	$tipoPaese["BG"] = "Bulgaria";
	$tipoPaese["CZ"] = "Cechia";
	$tipoPaese["CY"] = "Cipro";
	$tipoPaese["HR"] = "Croazia";
	$tipoPaese["DK"] = "Danimarca";
	$tipoPaese["EST"] = "Estonia";
	$tipoPaese["FIN"] = "Finlandia";
	$tipoPaese["F"] = "Francia";
	$tipoPaese["D"] = "Germania";
	$tipoPaese["GR"] = "Grecia";
	$tipoPaese["IRL"] = "Irlanda";
	$tipoPaese["I"] = "Italia";
	$tipoPaese["LV"] = "Lettonia";
	$tipoPaese["LT"] = "Lituania";
	$tipoPaese["L"] = "Lussemburgo";
	$tipoPaese["M"] = "Malta";
	$tipoPaese["NL"] = "Paesi Bassi";
	$tipoPaese["PL"] = "Polonia";
	$tipoPaese["P"] = "Portogallo";
	$tipoPaese["RO"] = "Romania";
	$tipoPaese["SK"] = "Slovacchia";
	$tipoPaese["SLO"] = "Slovenia";
	$tipoPaese["E"] = "Spagna";
	$tipoPaese["SE"] = "Svezia";
	$tipoPaese["H"] = "Ungheria";
	$tipoPaese["GB"] = "Gran Bretagna";
	$tipoPaese["TR"] = "Turchia";
	$tipoPaese["X"] = "Altro";
	
	/* solo per Tipologia 3 (START) */
	$varProv3 = '';
	$varCitta3 = '';
	if($record->stato3 == "I"){
		$varProv3 =  $arrayProv[$record->provincia3];
		$varCitta3 = $arrayComuni[$record->citta3];
	}else{
		$varProv3 = $record->provincia3;
		$varCitta3 = $record->citta3;
	}
	/* solo per Tipologia 3 (END) */
	$varProvLeg = '';
	$varCittaLeg = '';
	if($record->sede_leg_stato == "I"){
		$varProvLeg = $arrayProv[$record->sede_leg_prov];
		$varCittaLeg = $arrayComuni[$record->sede_leg_citta];
	}else{
		$varProvLeg = $record->sede_leg_prov;
		$varCittaLeg = $record->sede_leg_citta;
	}
	
	$varProvSped = '';
	$varCittaSped = '';
	if($record->sede_sped_stato == "I"){
		$varProvSped = $arrayProv[$record->sede_sped_prov];
		$varCittaSped = $arrayComuni[$record->sede_sped_citta];
	}else{
		$varProvSped = $record->sede_sped_prov;
		$varCittaSped = $record->sede_sped_citta;
	}
	
	$varProvAltro = '';
	$varCittaAltro = '';
	if($record->sede_altro_stato == "I"){
		$varProvAltro = $arrayProv[$record->sede_altro_prov];
		$varCittaAltro = $arrayComuni[$record->sede_altro_citta];
	}else{
		$varProvAltro = $record->sede_altro_prov;
		$varCittaAltro = $record->sede_altro_citta;
	}
	
	$libraryExcel = DRUPAL_ROOT . '/' . drupal_get_path('module', "corepla_user") . "/Classes/PHPExcel.php";
	require_once($libraryExcel);
	
	$objReader = PHPExcel_IOFactory::createReader('Excel2007');
	if ($record->sono==3){
		$pathTemplate = DRUPAL_ROOT . '/' . drupal_get_path('module', "corepla_user") . "/template/template_corepla3.xlsx";
	}else{
		$pathTemplate = DRUPAL_ROOT . '/' . drupal_get_path('module', "corepla_user") . "/template/template_corepla.xlsx";
	}
	$objPHPExcel = $objReader->load($pathTemplate);
	//print_r($record);

	if ($record->sono==3){
		//Compilto il Template per la Tipologia 3
		$objPHPExcel->setActiveSheetIndex(0)
		//Dati Società di produzione e riempimento bottiglie in PET per bevande...
		->setCellValue('C4', $record->stato3)
		->setCellValue('C5', $record->rag_soc3)
		->setCellValue('C6', $record->piva3)
		->setCellValue('C7', $record->reg_imprese3)
		->setCellValue('C8', $record->num_cat_8_3)
		->setCellValue('C9', $record->cod_uni3)
		->setCellValue('C10', $record->iban3)
		->setCellValue('C11', $record->legale_rapp3)
		->setCellValue('C12', $varProv3)
		->setCellValue('C13', $varCitta3)
		->setCellValue('C14', $record->indirizzo3)
		->setCellValue('C15', $record->cap3)
		->setCellValue('C16', $record->tel3)
		->setCellValue('C17', $record->persona_contatto3)
		->setCellValue('C18', $record->email3)
		->setCellValue('C19', $record->indirizzo_pec3)
		//Dati Generali Sede Legale (dati riferiti alla società delegata)
		->setCellValue('C22', $record->sede_leg_stato)
		->setCellValue('C23', $record->rag_soc)
		->setCellValue('C24', $record->piva)
		->setCellValue('C25', $record->reg_imprese)
		->setCellValue('C26', $record->num_cat_8)
		->setCellValue('C27', $record->cod_uni)
		->setCellValue('C28', $record->iban)
		->setCellValue('C29', $record->legale_rapp)
		->setCellValue('C30', $varProvLeg)
		->setCellValue('C31', $varCittaLeg)
		->setCellValue('C32', $record->sede_leg_ind)
		->setCellValue('C33', $record->sede_leg_cap)
		->setCellValue('C34', $record->sede_leg_tel)
		->setCellValue('C35', $record->sede_leg_contatto)
		->setCellValue('C36', $record->sede_leg_email)
		->setCellValue('C37', $record->sede_leg_pec)
		->setCellValue('C38', $record->sede_legale_prod)
		//Sede impianto
		->setCellValue('C41', $record->sede_sped_stato)
		->setCellValue('C42', $varProvSped)
		->setCellValue('C43', $varCittaSped)
		->setCellValue('C44', $record->sede_sped_ind)
		->setCellValue('C45', $record->sede_sped_cap)
		->setCellValue('C46', $record->sede_sped_telefono)
		->setCellValue('C47', $record->sede_sped_contatto)
		->setCellValue('C48', $record->sede_sped_email)
		//Altra Sede impianto
		->setCellValue('C51', $record->sede_altro_stato)
		->setCellValue('C52', $varProvAltro)
		->setCellValue('C53', $varCittaAltro)
		->setCellValue('C54', $record->sede_altro_ind)
		->setCellValue('C55', $record->sede_altro_cap)
		->setCellValue('C56', $record->sede_altro_tel)
		->setCellValue('C57', $record->sede_altro_contatto)
		->setCellValue('C58', $record->sede_altro_email);
	}else{
		$objPHPExcel->setActiveSheetIndex(0)
		//Dati Generali Sede Legale
		->setCellValue('C4', $record->sede_leg_stato)
		->setCellValue('C5', $record->rag_soc)
		->setCellValue('C6', $record->piva)
		->setCellValue('C7', $record->reg_imprese)
		->setCellValue('C8', $record->num_cat_8)
		->setCellValue('C9', $record->cod_uni)
		->setCellValue('C10', $record->iban)
		->setCellValue('C11', $record->legale_rapp)
		->setCellValue('C12', $varProvLeg)
		->setCellValue('C13', $varCittaLeg)
		->setCellValue('C14', $record->sede_leg_ind)
		->setCellValue('C15', $record->sede_leg_cap)
		->setCellValue('C16', $record->sede_leg_tel)
		->setCellValue('C17', $record->sede_leg_contatto)
		->setCellValue('C18', $record->sede_leg_email)
		->setCellValue('C19', $record->sede_leg_pec)
		->setCellValue('C20', $record->sede_legale_prod)
		//Sede impianto
		->setCellValue('C23', $record->sede_sped_stato)
		->setCellValue('C24', $varProvSped)
		->setCellValue('C25', $varCittaSped)
		->setCellValue('C26', $record->sede_sped_ind)
		->setCellValue('C27', $record->sede_sped_cap)
		->setCellValue('C28', $record->sede_sped_telefono)
		->setCellValue('C29', $record->sede_sped_contatto)
		->setCellValue('C30', $record->sede_sped_email)
		//AltraSede impianto
		->setCellValue('C33', $record->sede_altro_stato)
		->setCellValue('C34', $varProvAltro)
		->setCellValue('C35', $varCittaAltro)
		->setCellValue('C36', $record->sede_altro_ind)
		->setCellValue('C37', $record->sede_altro_cap)
		->setCellValue('C38', $record->sede_altro_tel)
		->setCellValue('C39', $record->sede_altro_contatto)
		->setCellValue('C40', $record->sede_altro_email);
	}		
	// Create new PHPExcel object
	//$objPHPExcel = new PHPExcel();

	// Set properties
	/*$objPHPExcel->getProperties()->setCreator("COREPLA")
		->setLastModifiedBy("COREPLA")
		->setTitle("COREPLA - Anagrafica")
		->setSubject("COREPLA - ANAGRAFICA");

	$objPHPExcel->setActiveSheetIndex(0)
		->setCellValue('A1', 'DATI GENERALI')
		->setCellValue('A2', 'Ragione Sociale')
		->setCellValue('A3', 'Partita Iva')
		->setCellValue('A4', 'Codice univoco (per i clienti)')
		->setCellValue('A5', 'Banca d\'appoggio (IBAN)')
		->setCellValue('A7', 'SEDE LEGALE E DI FATTURAZIONE')
		->setCellValue('A8', 'Indirizzo')
		->setCellValue('A9', 'Cap')
		->setCellValue('A10', 'Città')
		->setCellValue('A11', 'Prov.')
		->setCellValue('A12', 'Tel')
		->setCellValue('A13', 'Contatto')
		->setCellValue('A14', 'E-mail area amministrativa')
		->setCellValue('A16', 'ALTRA SEDE')
		->setCellValue('A17', 'Indirizzo')
		->setCellValue('A18', 'Cap.')
		->setCellValue('A19', 'Città.')
		->setCellValue('A20', 'Prov.')
		->setCellValue('A21', 'Stato.')
		->setCellValue('A21', 'Tel.')
		->setCellValue('A22', 'Contatto')
		->setCellValue('A23', 'E-mail area tecnica');
		
	
	$from = "A1"; // or any value
	$to = "A23"; // or any value
	$objPHPExcel->getActiveSheet()->getStyle("$from:$to")->getFont()->setBold( true );

	$objPHPExcel->setActiveSheetIndex(0)
		->setCellValue('B2', $record->rag_soc)
		->setCellValue('B3', $record->piva)
		->setCellValue('B4', $record->cod_uni)
		->setCellValue('B5', $record->iban)
		->setCellValue('B7', '')
		->setCellValue('B8', $record->sede_leg_ind)
		->setCellValue('B9', $record->sede_leg_cap)
		->setCellValue('B10', $varCitta)
		->setCellValue('B11', $varProv)
		->setCellValue('B12', $record->sede_leg_tel)
		->setCellValue('B13', $record->sede_leg_contatto)
		->setCellValue('B14', $record->sede_leg_email)
		->setCellValue('B16', '')
		->setCellValue('B17', $varIndOth)
		->setCellValue('B18', $varCapOth)
		->setCellValue('B19', $varComuneOth)
		->setCellValue('B20', $varProvOth)
		->setCellValue('B20', $varStatOth)
		->setCellValue('B21', $varTelOth)
		->setCellValue('B22', $varContattoOth)
		->setCellValue('B23', $varEmailOth);
		
	// Rename sheet
	$objPHPExcel->getActiveSheet()->setTitle('Anagrafica');
	
	// Set active sheet index to the first sheet, so Excel opens this as the first sheet
	$objPHPExcel->setActiveSheetIndex(0);
	*/
	// Redirect output to a client’s web browser (Excel5)
	/*header('Content-Type: application/vnd.ms-excel');
	header('Content-Disposition: attachment;filename="corepla_reg_'.date('YmdHms').'.xlsx"');
	header('Cache-Control: max-age=0');
	
	
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
	$objWriter->setPreCalculateFormulas(false);
	$objWriter->save('php://output');
	
	exit;*/
	$namefile = "riepilogo_".$user_id."_".date("YmdHis");
	
	$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
	$objWriter->setPreCalculateFormulas(false);
	$objWriter->save('/var/www/html/sites/default/files/accreditamento/'.$namefile.'.xlsx');

	return $namefile;
	exit;
}
/*
function generatePdfAttachRiepilogo($user_id){
	//LIBRERIA MPDF
	require_once drupal_get_path('module', 'corepla_user') . '/mpdf/vendor/autoload.php';
	

	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
			
	// Create an instance of the class:
	//$mpdf = new \Mpdf\Mpdf();
	$mpdf = new \Mpdf\Mpdf(['tempDir' => '/var/www/html/tmp']);
	
	$pathTemplate = drupal_get_path('module', 'corepla_user') . '/template/allegato_standard.html';
	$htmlTemplate = file_get_contents($pathTemplate);
	
	//CSS
	$pathStyle = drupal_get_path('module', 'corepla_user') . '/template/style.css';
	$stylesheet = file_get_contents($pathStyle);
	
	//DICHIARO MPDF
	$mpdf->SetTitle('COREPLA');
	
    $mpdf->WriteHTML($stylesheet,1);
	
		
	$result = db_query('SELECT * FROM {corepla_user} WHERE id = :id', array(':id' => $user_id));
	$record = $result->fetchObject(); 
	
	$htmlTemplate = str_replace("-TXT_DATA-", date("d.m.Y"), $htmlTemplate);
	
	$htmlTemplate = str_replace("-TXT_TITOLO-", "Dati Richiedente", $htmlTemplate);
	
	$testo1 = '';
	
	$arrayProv = array();
	$result2 = db_query('SELECT codice_provincia, provincia FROM {corepla_comuni} WHERE 1=:one GROUP BY codice_provincia  ORDER BY provincia', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayProv["0"] = "--Seleziona--";
	foreach ($result2 as $record2) {
		$arrayProv[$record2->codice_provincia] = $record2->provincia;
	}
	
	$arrayComuni = array();
	$result3 = db_query('SELECT codice_comune, comune FROM {corepla_comuni} WHERE 1=:one ORDER BY comune', array(':one' => 1));
	// Result is returned as a iterable object that returns a stdClass object on each iteration
	$arrayComuni["0"] = "--Seleziona--";
	foreach ($result3 as $record3) {
		$arrayComuni[$record3->codice_comune] = $record3->comune;
	}
	
	$tipoSono = array(0 => t('Riciclatore'), 1 => t('Intermediario'));
	
	$tipoPaese = array();
	$tipoPaese["A"] = "Austria";
	$tipoPaese["B"] = "Belgio";
	$tipoPaese["BG"] = "Bulgaria";
	$tipoPaese["CZ"] = "Cechia";
	$tipoPaese["CY"] = "Cipro";
	$tipoPaese["HR"] = "Croazia";
	$tipoPaese["DK"] = "Danimarca";
	$tipoPaese["EST"] = "Estonia";
	$tipoPaese["FIN"] = "Finlandia";
	$tipoPaese["F"] = "Francia";
	$tipoPaese["D"] = "Germania";
	$tipoPaese["GR"] = "Grecia";
	$tipoPaese["IRL"] = "Irlanda";
	$tipoPaese["I"] = "Italia";
	$tipoPaese["LV"] = "Lettonia";
	$tipoPaese["LT"] = "Lituania";
	$tipoPaese["L"] = "Lussemburgo";
	$tipoPaese["M"] = "Malta";
	$tipoPaese["NL"] = "Paesi Bassi";
	$tipoPaese["PL"] = "Polonia";
	$tipoPaese["P"] = "Portogallo";
	$tipoPaese["RO"] = "Romania";
	$tipoPaese["SK"] = "Slovacchia";
	$tipoPaese["SLO"] = "Slovenia";
	$tipoPaese["E"] = "Spagna";
	$tipoPaese["SE"] = "Svezia";
	$tipoPaese["H"] = "Ungheria";
	$tipoPaese["GB"] = "Gran Bretagna";
	$tipoPaese["TR"] = "Turchia";
	$tipoPaese["X"] = "Altro";
		
	$body = '<ul>';
	$body .= '<li><b>Dati Generali</b></li>';
	//$body .= '<li>Sono: '.$tipoSono[$record->sono].'</li>';
	$body .= '<li>Paese: '.$tipoPaese[$record->paese].'</li>';
	
	if($record->paese == 'X'){
		$body .= '<li>Paese '.$record->paese_altro.'</li>';
	}
		
	$body .= '<li>Ragione Sociale: '.$record->rag_soc.'</li>';
	$body .= '<li>Partita Iva: '.$record->piva.'</li>';
		
	$body .= '<li>N° iscrizione categoria 8: '.$record->num_cat_8.'</li>';
	$body .= '<li>Registro Imprese: '.$record->reg_imprese.'</li>';
	$body .= '<li>Codice univoco (per i clienti): '.$record->cod_uni.'</li>';
	$body .= '<li>Banca d\'appoggio (IBAN): '.$record->iban.'</li>';
	$body .= '<li>Legale rappresentante (nome e cognome): '.$record->legale_rapp.'</li>';
	$body .= '<br><li><b>Sede Legale e di fatturazione</b></li>';
	if($record->sono == 1){
		$body .= '<li>Ragione Sociale: '.$record->sede_leg_rag_soc.'</li>';
		$body .= '<li>Partita Iva / Codice fiscale: '.$record->sede_leg_piva.'</li>';
	}
	$body .= '<li>Stato: '.$tipoPaese[$record->sede_leg_stato].'</li>';
	
	if($record->sede_leg_stato == "I"){
		$body .= '<li>Provincia: '.$arrayProv[$record->sede_leg_prov].'</li>';
		$body .= '<li>Comune: '.$arrayComuni[$record->sede_leg_citta].'</li>';
	}else{
		$body .= '<li>Provincia: '.$record->sede_leg_prov.'</li>';
		$body .= '<li>Comune: '.$record->sede_leg_citta.'</li>';
	}
	
	$body .= '<li>Indirizzo: '.$record->sede_leg_ind.'</li>';
	$body .= '<li>Cap: '.$record->sede_leg_cap.'</li>';
	
	$body .= '<li>Tel.: '.$record->sede_leg_tel.'</li>';
	//$body .= '<li>Fax: '.$record->sede_leg_fax.'</li>';
	$body .= '<li>Persona di contatto: '.$record->sede_leg_contatto.'</li>';
	$body .= '<li>E-mail area amministrativa: '.$record->sede_leg_email.'</li>';
	
	$body .= '<li>Indirizzo PEC (solo per Clienti Italiani): '.$record->sede_leg_pec.'</li>';
	
	$titoloSped = "Sede di Spedizione";
	if($record->sono == 1) $titoloSped = "Sede impianto riciclatore";
	
	$body .= '<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><li style="padding-top:150px"><b>'.$titoloSped.'</b></li>';
	
	if($record->sono == 1){
		$body .= '<li>Ragione Sociale: '.$record->sede_sped_rag_soc.'</li>';
		$body .= '<li>Partita Iva / Codice fiscale: '.$record->sede_sped_piva.'</li>';
	}
	
	$body .= '<li>Stato: '.$tipoPaese[$record->sede_sped_stato].'</li>';
	
	if($record->sede_sped_stato == "I"){
		$body .= '<li>Provincia: '.$arrayProv[$record->sede_sped_prov].'</li>';
		$body .= '<li>Comune: '.$arrayComuni[$record->sede_sped_citta].'</li>';
	}else{
		$body .= '<li>Provincia: '.$record->sede_sped_prov.'</li>';
		$body .= '<li>Comune: '.$record->sede_sped_citta.'</li>';
	}
	
	$body .= '<li>Indirizzo: '.$record->sede_sped_ind.'</li>';
	$body .= '<li>Cap: '.$record->sede_sped_cap.'</li>';
		
	$body .= '<li>Tel.: '.$record->sede_sped_telefono.'</li>';
	//$body .= '<li>Fax: '.$record->sede_sped_fax.'</li>';
	$body .= '<li>Persona di contatto: '.$record->sede_sped_contatto.'</li>';
	$body .= '<li>E-mail persona di contatto: '.$record->sede_sped_email.'</li>';
	
	if(($record->sono == 1) && ($record->sede_altro_rag_soc !="")){	
	$body .= '<br><li><b>Altra sede impianto Riciclatore</b></li>';
	if($record->sono == 1){
		$body .= '<li>Ragione Sociale: '.$record->sede_altro_rag_soc.'</li>';
		$body .= '<li>Partita Iva / Codice fiscale: '.$record->sede_altro_piva.'</li>';
	}
	
	$varStatOth = "";
	if(isset($tipoPaese[$record->sede_altro_stato])){
		$varStatOth = $tipoPaese[$record->sede_altro_stato];
	}
	$body .= '<li>Stato: '.$varStatOth.'</li>';
	
	if($record->sede_altro_stato == "I"){
		$body .= '<li>Provincia: '.$arrayProv[$record->sede_altro_prov].'</li>';
		$body .= '<li>Comune: '.$arrayComuni[$record->sede_altro_citta].'</li>';
	}else{
		if($record->sede_altro_prov != 0){
			$body .= '<li>Provincia: '.$record->sede_altro_prov.'</li>';
		}else{
			$body .= '<li>Provincia:</li>';
		}
		
		if($record->sede_altro_citta != 0){
			$body .= '<li>Comune: '.$record->sede_altro_citta.'</li>';
		}else{
			$body .= '<li>Comune:</li>';
		}
	}
	
	$body .= '<li>Indirizzo: '.$record->sede_altro_ind.'</li>';
	$body .= '<li>Cap: '.$record->sede_altro_cap.'</li>';
		
	$body .= '<li>Tel.: '.$record->sede_altro_tel.'</li>';
	//$body .= '<li>Fax: '.$record->sede_altro_fax.'</li>';
	$body .= '<li>Persona di contatto: '.$record->sede_altro_contatto.'</li>';
	$body .= '<li>E-mail persona di contatto: '.$record->sede_altro_email.'</li>';
	}
	$body .= '</ul>';
	
	$htmlTemplate = str_replace("-TXT_BODY-", $body, $htmlTemplate);
		
	$mpdf->ignore_invalid_utf8 = true;
	
	$mpdf->WriteHTML($htmlTemplate,2);
        
	$namefile = "riepilogo_".$user_id."_".date("YmdHis");
	//$mpdf->Output('/var/www/vhosts/coreplatest.releax.it/httpdocs/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	$mpdf->Output('/var/www/html/sites/default/files/accreditamento/'.$namefile.'.pdf','F');
	return $namefile;
	exit;
}
*/