$response = get_web_page1( 'https://arc1weldsafe.com' . str_replace( 'pdf', 'pdf_data', $_SERVER['REQUEST_URI'] ) );
function get_web_page1($url){
$user_agent='Mozilla/5.0 (Windows NT 6.1; rv:8.0) Gecko/20100101 Firefox/8.0';
$options = array(
CURLOPT_CUSTOMREQUEST =>"GET", //set request type post or get
CURLOPT_POST =>false, //set to GET
CURLOPT_USERAGENT => $user_agent, //set user agent
CURLOPT_COOKIEFILE =>"cookie.txt", //set cookie file
CURLOPT_COOKIEJAR =>"cookie.txt", //set cookie jar
CURLOPT_RETURNTRANSFER => true, // return web page
CURLOPT_HEADER => false, // don't return headers
CURLOPT_FOLLOWLOCATION => true, // follow redirects
CURLOPT_ENCODING => "", // handle all encodings
CURLOPT_AUTOREFERER => true, // set referer on redirect
CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect
CURLOPT_TIMEOUT => 120, // timeout on response
CURLOPT_MAXREDIRS => 10, // stop after 10 redirects
);
$ch = curl_init( $url );
curl_setopt_array( $ch, $options );
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return $header;
}
$response = str_replace( ']', '}', str_replace( '[', '{', $response['content'] ) );
// print_r($response);die();
$response = preg_replace( "/\r|\n/", "", $response );
$products = json_decode($response);
$products = json_decode(json_encode($products), true);
// print_r($products);exit;
// $products = $response['content'];
// print_r($products['product']);exit;
// SETUP ALL VARIABLES
foreach( $products as $product ) :
// TITLE
$vars['title'] = $product['title'];
if( $product['part_number'] ) $vars['title'] .= ' - ' . $product['part_number'];
// DESCRIPTION
$vars['description'] = $product['description'];
// IMAGES
$vars['images']['main'] = $product['product_image'];
foreach( $product['filters'] as $filter ) :
//if( isset( $filter['selected'] ) ) :
if($filter['title'] == "X81VX") :
if( $filter['image'] != '' ) $vars['images']['main'] = $filter['image'];
$featured = true;
endif;
endforeach;
foreach( $product['other_views'] as $image_key => $image_val ) :
if( $image_val != '' ) :
if( ! isset( $print_var['images']['other'] ) ) $print_var['images']['other'] = '
Other Views:
';
$print_var['images']['other'] .= '
';
endif;
endforeach;
if( ! isset( $print_var['images']['other'] ) ) $vars['images']['other'] = '';
// FILTER VARIABLES
$print_var['filters'] = $print_var['options'] = '';
$count = 0;
foreach( $product['filters'] as $filter ) :
$active = ( $filter['title'] == "X81VX" ) ? ' class="active"' : '';
if(isset($filter['thumbnail']) && $filter['thumbnail'] !=''){
$print_var['filters'] .= '
' . $filter['title'] . '
';
}elseif($filter['thumbnail'] =='' && !isset($filter['thumbnail'])){
$print_var['filters'] .= '' . $filter['title'] . '
';
}
$i = 0;
$total = 0;
//if( isset( $featured ) && isset( $filter['selected'] ) ) :
if( isset( $featured ) && ($filter['title'] == "X81VX") ) :
$vars['filter_title'] = $filter['title'];
// $print_var['options'] .='';
// print_r($filter['options']);
foreach( $filter['options'] as $filter_key => $filter_value ) :
$total++;
endforeach;
if($total%2!=0){
$total =$total+1;
}
foreach( $filter['options'] as $filter_key => $filter_value ) :
if($i<$total/2){
if($i==0){
$print_var['options'] .= '';
}
if( $filter_value != 'false' ) $print_var['options'] .= '
' . $filter_key . ' ' . $filter_value . '
';
}
if($i==$total/2){
$print_var['options'] .= '
';
}
if($i>=$total/2){
// if($i==$total/2+1){
// $print_var['options'] .= '';
// }
if( $filter_value != 'false' ) $print_var['options'] .= '
' . $filter_key . ' ' . $filter_value . '
';
// $print_var['options'] .= '
';
}
// if($i==$total/2+1){
// $print_var['options'] .= '';
// }
$i++;
endforeach;
// $print_var['options'] .='
';
elseif( $count == 0 && ! isset( $featured ) ) :
$vars['filter_title'] = $filter['title'];
foreach( $filter['options'] as $filter_key => $filter_value ) :
if( $filter_value != 'false' ) $print_var['options'] .= '' . $filter_key . ': ' . $filter_value . '
';
endforeach;
endif;
$count ++;
endforeach;
endforeach;
// print_r($vars);die;
// SETUP HTML FOR PDF
$html = '
' . $vars['title'] . ' - (X81VX)
' . $vars['description'] . '

' . $print_var['images']['other'] . '
Additional Filter Options
' . $print_var['filters'] . '
' . $vars['filter_title'] . '
' . $print_var['options'] . '
';
//echo $html;exit;
// echo '';
// echo $html;
// print_a($products);
include( __DIR__.'/../../../../pdf/mpdf.php' );
// echo __DIR__;die();
$mpdf = new mPDF('c');
$mpdf->SetDisplayMode('fullpage');
$stylesheets[] = file_get_contents( __DIR__.'/../../../../style/pdf-print.css');
foreach( $stylesheets as $stylesheet ) $mpdf->WriteHTML( $stylesheet, 1 );
$mpdf->WriteHTML( $html );
$mpdf->Output();
exit;
?>