<?php

/*

 * The template for displaying the newsletter

 *

 * This is the template that displays the newsletter.

 * This template over-rides page-newsletter.php.

 *

 * @package IRIS OpenWebsite Version 4.0

 *

 */

?>

<?php //check_newsletter_status() ?>

<?php

/* Newsletter colours */

$plugindir=plugin_dir_path( __DIR__);

require $plugindir .'mpdf/vendor/autoload.php';



/* Newsletter colours */

$head_bg = get_field('head_bg',397);

$nav_bg = get_field('nav_bg',397);

$title_bg = get_field('title_bg',397);

$item_bg = get_field('item_bg',397);

$footer_bg = get_field('footer_bg',397);



$main_title_text = get_field('main_title_text',397);

$head_links = get_field('head_links',397);

$nav_text = get_field('nav_text',397);

$title_text = get_field('title_text',397);

$main_text = get_field('main_text',397);

$link_text = get_field('link_text',397);

$footer_text = get_field('footer_text',397);
$newsletter_theme=ow_global_var('newsletter_theme');


?>

<?php $title = get_field('newsletter_title') ? get_field('newsletter_title') : 'Tax Tips &amp; News'; ?>

<?php $content_type = get_field( 'newsletter_content' ); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title><?php echo ow_global_var( 'accountant_name' ); ?> | <?php echo $title; ?> |

<?php if ($content_type == 'tax_tips') {echo ow_tax_news_date();} else {echo date('F Y');} ?>

</title>

	<style>

		body {background-color:#dddddd;margin:0;padding:10px 0;font-family:arial;font-size:14px;color:<?php echo $main_text; ?>;}

		h1,h2,h3,h4,h5,h6,p,pre,ul,ol {margin:0 0 10px 0;}

		a {text-decoration:none;color:<?php echo $link_text; ?>;}

		address {font-style:normal;}

		blockquote {font-style:italic;}

	.download-details{

		background-image:url('<?php echo WP_PLUGIN_URL ;?>/ow-plugin/img/download-pdf.svg');  height: 225px;

    width: 50px;background-size: 100% 100%; background-color: transparent;

     padding:10px; border:0 none; cursor: pointer; float:none; margin:0 auto;display: block;margin-bottom: 10px;}

	#logo{max-width: 236px;

    max-height: 100px;}

    #pdfdownload{display: none;}

	</style>

</head>

<body>



	

<?php 

	$tables = '<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%" align="center">';
$tablesp = '<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="5" width="100%" align="center" style="padding:0 10px;">';
$tablessp = '<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="100%" align="center" style="padding:10px;">';
$tables50 = '<table bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="50%" align="left">';
$tablend = '</table>';

 /* ------------------------------------------------------------------------------------------------

  Header & Logo

  ------------------------------------------------------------------------------------------------ */

	$header=$tables.'<tr bgcolor="'.$head_bg.'">

    <th colspan="2" align="center"> <table autosize="0" width="100%" cellspacing="0">

        <tr>

          <td align="left" width="50%" style="vertical-align:top;padding: 10px; page-break-inside: avoid;" class="logo"><img src="'.get_template_directory_uri().'/img/logo.png" alt="'.ow_global_var( 'accountant_name' ).' Logo" id="logo" class="logo" ></td>

          <td align="right" width="50%" style="vertical-align:top;padding: 10px; page-break-inside: avoid;"><h1 style="color:'.$main_title_text.';font-weight:400;">'.$title.'</h1>

            <p><span style="color:'.$head_links.';font-size:16px;font-weight:400;" >'.ow_global_var('accountant_phone').'</span></p>

            <p><a style="color:'.$head_links.';font-size:16px;font-weight:400;" href="http://www.'.ow_global_var( 'accountant_website' ).'">'.ow_global_var( 'accountant_website' ).'</a></p></td>

        </tr>

      </table>

    </th>

  </tr>

 '.$tablend;

 

  /* ------------------------------------------------------------------------------------------------

  Navigation

  ------------------------------------------------------------------------------------------------ */

  

	if(get_field('show_navigation') === true) : $header.=$tables.'

  <tr bgcolor="'.$nav_bg.'">

    <td colspan="2" align="center" style="padding: 10px; page-break-inside: avoid;">

    <table autosize="0" width="100%" cellspacing="0">

        <tr>';?>

          <?php

          $menu = wp_get_nav_menu_items( 'main navigation' );

          foreach ( $menu as $item ) {

              if ( $item->post_parent == 0 ) {

                  $header.='<td align="center"><a href="' . $item->url . '" style="color:' . $nav_text . ';">' . $item->title . '</a></td>';

              }

          }

        $header.='</tr>

      </table></td>

  </tr>'.$tablend; endif; 

	/* ------------------------------------------------------------------------------------------------

  Header Image.

  ------------------------------------------------------------------------------------------------ */

  ?>

  <?php if((get_field('show_header_image') === true) && ($image = get_field('head_image'))) :$header.=$tables.'

  <tr>

    <td colspan="4" align="center" style="padding: 0">'.wp_get_attachment_image( $image, 'newsletter-header').'</td>

  </tr>

 '.$tablend; endif; ?>

	

	<?php

  /* ------------------------------------------------------------------------------------------------

  Welcome Message

  ------------------------------------------------------------------------------------------------ */

  if(isset($_REQUEST['issue'])){

	  

	  $header.=$tables.'

  <tr>

    <td style="padding:20px 20px 0 0;;width:100%" align="right" valign="top" class="date">

    <table autosize="0" width="100%" cellspacing="0">

    <tr>

    <td style="text-align:right">'.date('d/m/Y',strtotime($_REQUEST['issue'])).'</td>

    </tr>

    </table>

    </td>

  </tr>';

  }else if(isset($_REQUEST['budget'])){

	  

	  $header.=$tables.'

  <tr>

  <td></td>

    <td style="padding:20px 20px 0 0" align="right" valign="top" class="date"></td>

  </tr>';

  }else{

	  $header.=$tables.'

  <tr>

  <td></td>

    <td style="padding:20px 20px 0 0" align="right" valign="top" class="date">'.date('d/m/Y').'</td>

  </tr>';}?>

  <?php if(get_field('show_welcome_message') === true) : $header.='

  <tr>

    <td colspan="4"><table autosize="0" width="100%" cellspacing="0">

        <tr>';

		if(isset($_REQUEST['issue'])){		

			$monthname=date('F',strtotime($_REQUEST['issue']));

			$header.='<td colspan="2" style="vertical-align:top;padding: 20px">

				<h1>'.$monthname.' Tax Tips &amp; News</h1>

				<p>Welcome to the '.ow_global_var('accountant_name').' Tax Tips &amp; News monthly newsletter, bringing you the latest news to keep you one step ahead of the taxman.</p>

				<p>If you need further assistance just let us know or send us a question for our Question and Answer Section.</p>

				<p>We’re committed to ensuring none of our clients pay a penny more in tax than is necessary and they receive useful tax and business advice and support throughout the year.</p>

				<p>Please contact us for advice on your own specific circumstances. We’re here to help!</p>

			</td>';

	}else if(isset($_REQUEST['budget'])){}else{

          $header.='<td colspan="2" style="vertical-align:top;padding: 20px">'.ow_newsletter_merge_tags( get_field('welcome_message') ).'</td>';

		}

        $header.='</tr>

      </table></td>

  </tr>

  '; endif; $header.=$tablend;?>

	<?php

  /* ------------------------------------------------------------------------------------------------

  Main Content

  ------------------------------------------------------------------------------------------------ */

  ?>

  <?php

	$content='';

	$fullcontent='';

  if ( $content_type == 'tax_tips' ):

      global $iris_db_old;

	if(isset($_REQUEST['issue'])){

		$monthold=date('Y-m-01',strtotime($_REQUEST['issue']));

		$tax_news_list = $iris_db_old->get_results( "SELECT * FROM t_news WHERE month_id = (SELECT newsMonthId FROM t_news_months WHERE newsMonthName = '".$monthold."')" );

	}

	else if(isset($_REQUEST['budget'])){

		if($_REQUEST['budget']!='recent_budget'){$monthold=date('M_y',strtotime($_REQUEST['budget']));}else{$monthold=$_REQUEST['budget'];}

		$tax_news_list = $iris_db_old->get_results( "SELECT * FROM t_budgets WHERE id = '".strtolower($monthold)."'" );

		

		if($tax_news_list[0]->budgetId== NULL){

			$monthold=date('M_Y',strtotime($_REQUEST['budget']));

			$tax_news_list = $iris_db_old->get_results( "SELECT * FROM t_budgets WHERE id = '".strtolower($monthold)."'" );

		}

	}else{

  $tax_news_list = $iris_db_old->get_results( "SELECT * FROM t_news WHERE month_id = (SELECT newsMonthId FROM t_news_months WHERE newsMonthCurrent = 'yes')" );

	}
if ( $newsletter_theme == 'theme1' ) {
    foreach ( $tax_news_list as $item ):
        $content .= $tables . '
  <tr>
    <td style="padding:0 10px;"><table width="100%" cellspacing="0">
        <tr>
          <td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding:5px 10px;font-size:20px;">' . $item->title . '</td>
        </tr>
        <tr>
          <td bgcolor="' . $item_bg . '" style="padding:10px;">';
    if ( isset( $_REQUEST[ 'budget' ] ) ) {
        $content .= $item->details;
    } else {
        $content .= $item->nlsummary;
    }
    $content .= ' <a href="'.site_url().'/news/tax-news/article/' . $item->id . '/">Read More...</a></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  ' . $tablend;
    $fullcontent .= $tables . '
  <tr>
    <td style="padding:0 10px;"><table width="100%" cellspacing="0">
        <tr>
          <td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding:5px 10px;font-size:20px;">' . $item->title . '</td>
        </tr>
        <tr>
          <td bgcolor="' . $item_bg . '" style="padding:10px;">' . $item->details . '</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  ' . $tablend;
    endforeach;
} 
	
	// ----------------- THEME 2 - With images 2 column
	else if ( $newsletter_theme == 'theme2' ) {
    $qnda = str_replace('{SITE_URL}', site_url(),  $tax_news_list[ 4 ]->questions);
     //Content 0
        $content .= $tables . '<tr>';

        $content .= '<td width="50%" ><img src="' . $tax_news_list[ 0 ]->img . '" width="100%" height="250"></td>';


        $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;"><h2>' . $tax_news_list[ 0 ]->title . '</h2></br>' . $tax_news_list[ 0 ]->nlsummary . '.. </br>
		<a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 0 ]->id . '/">Read More...</a>
		</td>';

        $content .= '</tr>' . $tablend;
   //Content 1
        $content .= $tables . '<tr>';

         $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;"><h2>' . $tax_news_list[ 1 ]->title . '</h2></br>' . $tax_news_list[ 1 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 1 ]->id . '/">Read More...</a></td>';
		$content .= '<td width="50%" ><img src="' . $tax_news_list[ 1 ]->img . '" width="100%" height="250"></td>';
        $content .= '</tr>' . $tablend;
		
		//Content 2
        $content .= $tables . '<tr>';
		 $content .= '<td width="50%" ><img src="' . $tax_news_list[ 2 ]->img . '" width="100%" height="250"></td>';
		
        $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;"><h2>' . $tax_news_list[ 1 ]->title . '</h2></br>' . $tax_news_list[ 2 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 2 ]->id . '/">Read More...</a></td>';
        $content .= '</tr>' . $tablend;

    if ( count( $tax_news_list ) > 6 ) {
        //Content 3 and 4
        $content .= $tablesp . '<tr>';

        $content .= '<td width="50%" bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;"><img src="' . $tax_news_list[ 3 ]->img . '" width="100%">' . $tax_news_list[ 3 ]->title . '</td>';
        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;"><img src="' . $tax_news_list[ 4 ]->img . '" width="100%">' . $tax_news_list[ 4 ]->title . '</td>';

        $content .= '</tr><tr>';

        $content .= '<td width="50%" bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 3 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 3 ]->id . '/">Read More...</a></td>';
        $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 4 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 4 ]->id . '/">Read More...</a></td>';

        $content .= '</tr>' . $tablend;
        //Content 5 and 6
        $content .= $tablesp . '<tr>';

        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;"><img src="' . $tax_news_list[ 5 ]->img . '" width="100%">' . $tax_news_list[ 5 ]->title . '</td>';
        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;"><img src="' . $tax_news_list[ 6 ]->img . '" width="100%">' . $tax_news_list[ 6 ]->title . '</td>';

        $content .= '</tr><tr>';

        $content .= '<td width="50%" valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' .  $qnda  . '</td>';
        $content .= '<td valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 6 ]->details . ' </td>';

        $content .= '</tr>' . $tablend;
		
    } else {
        //Content 3
        $content .= $tables . '<tr>';
        $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;"><h2>' . $tax_news_list[ 3 ]->title . '</h2></br>' . $tax_news_list[ 3 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 3 ]->id . '/">Read More...</a></td>';
		$content .= '<td width="50%" ><img src="' . $tax_news_list[ 3 ]->img . '" width="100%" height="250"></td>';

        $content .= '</tr>' . $tablend;
        //Content 5 and 6
        $content .= $tablesp . '<tr>';

        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 4 ]->title . '</td>';
        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 5 ]->title . '</td>';

        $content .= '</tr><tr>';

        $content .= '<td width="50%" valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 4 ]->questions . '</td>';
        $content .= '<td width="50%" valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 5 ]->details . ' </td>';

        $content .= '</tr>' . $tablend;
    }
    foreach ( $tax_news_list as $item ):
        ////////////////////////////


        $fullcontent .= $tables . '
  <tr>
    <td style="padding:0 10px;"><table width="100%" cellspacing="0">
        <tr>
          <td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding:5px 10px;font-size:20px;">' . $item->title . '</td>
        </tr>
        <tr>
          <td bgcolor="' . $item_bg . '" style="padding:10px;">' . $item->details . '</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  ' . $tablend;

    endforeach;
}
	// ----------------- THEME 3 - Without images 2 column
	else if ( $newsletter_theme == 'theme3' ) {
    $content .= $tables . '
  <tr>
    <td style="padding:0 10px;"><table width="100%" cellspacing="0">
        <tr>
          <td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding:5px 10px;font-size:20px;">' . $tax_news_list[ 0 ]->title . '</td>
        </tr>
        <tr>
          <td bgcolor="' . $item_bg . '" style="padding:10px;">';
    if ( isset( $_REQUEST[ 'budget' ] ) ) {
        $content .= $item->details;
    } else {
        $content .= $tax_news_list[ 0 ]->nlsummary;
    }
    $content .= ' <a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 0 ]->id . '/">Read More...</a></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  ' . $tablend;
    //Content 1 and 2
    $content .= $tablesp . '<tr>';

    $content .= '<td width="50%" bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 1 ]->title . '</td>';
    $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 2 ]->title . '</td>';

    $content .= '</tr><tr>';

    $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 1 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 1 ]->id . '/">Read More...</a></td>';
    $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 2 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 2 ]->id . '/">Read More...</a></td>';

    $content .= '</tr>' . $tablend;
    if ( count( $tax_news_list ) > 6 ) {
        //Content 3 and 4
        $content .= $tablesp . '<tr>';

        $content .= '<td width="50%" bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 3 ]->title . '</td>';
        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 4 ]->title . '</td>';

        $content .= '</tr><tr>';

        $content .= '<td width="50%" bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 3 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 3 ]->id . '/">Read More...</a></td>';
        $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 4 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 4 ]->id . '/">Read More...</a></td>';

        $content .= '</tr>' . $tablend;
        //Content 5 and 6
        $content .= $tablesp . '<tr>';

        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 5 ]->title . '</td>';
        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 6 ]->title . '</td>';

        $content .= '</tr><tr>';

        $content .= '<td width="50%" valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 5 ]->questions . '</td>';
        $content .= '<td valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 6 ]->details . ' </td>';

        $content .= '</tr>' . $tablend;
    } else {
        //Content 3 and 4
        $content .= $tablessp . '<tr>';

        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 3 ]->title . '</td>';


        $content .= '</tr><tr>';

        $content .= '<td bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 3 ]->nlsummary . '.. </br><a href="'.site_url().'/news/tax-news/article/' . $tax_news_list[ 3 ]->id . '/">Read More...</a></td>';

        $content .= '</tr>' . $tablend;
        //Content 5 and 6
        $content .= $tablesp . '<tr>';

        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 4 ]->title . '</td>';
        $content .= '<td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding: 10px;font-size:20px;">' . $tax_news_list[ 5 ]->title . '</td>';

        $content .= '</tr><tr>';

        $content .= '<td width="50%" valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 4 ]->questions . '</td>';
        $content .= '<td width="50%" valign="top"  bgcolor="' . $item_bg . '" style="padding:10px;">' . $tax_news_list[ 5 ]->details . ' </td>';

        $content .= '</tr>' . $tablend;
    }
    foreach ( $tax_news_list as $item ):
        ////////////////////////////


        $fullcontent .= $tables . '
  <tr>
    <td style="padding:0 10px;"><table width="100%" cellspacing="0">
        <tr>
          <td bgcolor="' . $title_bg . '" style="color:' . $title_text . ';padding:5px 10px;font-size:20px;">' . $item->title . '</td>
        </tr>
        <tr>
          <td bgcolor="' . $item_bg . '" style="padding:10px;">' . $item->details . '</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  ' . $tablend;

    endforeach;
}
	
	
?>

	<?php

  /* ------------------------------------------------------------------------------------------------

  BUDGET

  ------------------------------------------------------------------------------------------------ */

  ?>

  <?php

  elseif ( $content_type == 'budget' ):

      global $iris_db_old;

  $budget = $iris_db_old->get_row( "SELECT * FROM t_budgets ORDER BY id DESC LIMIT 1" );

  $content.=$tables.'

  <tr>

    <td style="padding:0 10px;"><table autosize="0" width="100%" cellspacing="0"  colspan="2">

        <tr>

          <td bgcolor="'.$title_bg.'" style="color:'.$title_text.';padding:5px 10px;font-size:20px;">'.$budget->title.'</td>

        </tr>

        <tr>

          <td bgcolor="'.$item_bg.'" style="padding:10px;word-break: break-word;">'.str_replace( ['[[',']]'], '"', $budget->details ).'</td>

        </tr>

        <tr>

          <td>&nbsp;</td>

        </tr>

      </table></td>

  </tr>'.$tablend;

	$fullcontent.=$tables.'

  <tr>

    <td style="padding:0 10px;"><table autosize="0" width="100%" cellspacing="0"  colspan="2">

        <tr>

          <td bgcolor="'.$title_bg.'" style="color:'.$title_text.';padding:5px 10px;font-size:20px;">'.$budget->title.'</td>

        </tr>

        <tr>

          <td bgcolor="'.$item_bg.'" style="padding:10px;word-break: break-word;">'.str_replace( ['[[',']]'], '"', $budget->details ).'</td>

        </tr>

        <tr>

          <td>&nbsp;</td>

        </tr>

      </table></td>

  </tr>'.$tablend;

  elseif ($content_type == 'custom') : 

	$content.=$tables.'

  <tr>

    <td style="padding:0 10px"><table autosize="0" width="100%" cellspacing="0" colspan="2">

        <tr>

          <td style="padding: 10px;"  colspan="2">'.ow_newsletter_merge_tags( get_field( 'custom_content' ) ).'</td>

        </tr>

        <tr>

          <td  colspan="2">&nbsp;</td>

        </tr>

      </table></td>

  </tr>

 '.$tablend;

	$fullcontent.=$tables.'

  <tr>

    <td style="padding:0 10px; page-break-inside: avoid;">

    <table autosize="0" width="100%" cellspacing="0" colspan="2" style="page-break-inside: auto;">

        <tr>

          <td style="padding: 10px;"  colspan="2">'.ow_newsletter_merge_tags( get_field( 'custom_content' ) ).'</td>

        </tr>

        <tr>

          <td  colspan="2">&nbsp;</td>

        </tr>

      </table></td>

  </tr>

 '.$tablend;endif; ?>

  <?php

  /* ------------------------------------------------------------------------------------------------

  About Us

  ------------------------------------------------------------------------------------------------ */

  ?>

  <?php $footer='';if(get_field('show_about_us') === true) : $footer.=$tables.'

  <tr>

    <td style="padding:0 10px"><table autosize="0" width="100%" cellspacing="0">

        <tr bgcolor="'.$title_bg.'" style="color:'.$title_text.';font-size:20px;">

          <td style="padding:5px 10px;">About Us</td>

        </tr>

        <tr bgcolor="'.$item_bg.'">

          <td style="padding: 10px;">'.ow_newsletter_merge_tags( get_field('about_us') ).'</td>

        </tr>

        <tr>

          <td>&nbsp;</td>

        </tr>

      </table></td>

  </tr>

  '.$tablend; endif;?>

  <?php

  /* ------------------------------------------------------------------------------------------------

  Social Icons

  ------------------------------------------------------------------------------------------------ */

  ?>

  <?php if($social = get_field('social_icons')) : $footer.=$tables.'

  <tr>

    <td colspan="2" align="center">';

	if($facebook = ow_social_icon_png('facebook')) {$footer.=$facebook;};

      if($twitter = ow_social_icon_png('twitter')) {$footer.=$twitter;};

      if($linkedin = ow_social_icon_png('linkedin')) {$footer.=$linkedin;};

      if($googleplus = ow_social_icon_png('googleplus')) {$footer.=$googleplus;}

  $footer.='</td></tr>

  <tr>

    <td>&nbsp;</td>

  </tr>

  '.$tablend; endif; ?>

  <?php

  /* ------------------------------------------------------------------------------------------------

  Copyright Information

  ------------------------------------------------------------------------------------------------ */

  $footer.=$tables.'

  <tr align="center" bgcolor="'.$footer_bg.'" style="font-size:10px;">

    <td colspan="2" style="padding:15px 10px;color:'.$footer_text.';"><p>'.'Copyright &copy; '.date('Y').' '.ow_global_var('accountant_name').'. All rights reserved.

      <p>

      <p>'.ow_global_var('accountant_address').'</p>

      <p>'.ow_global_var('accountant_name').' is a trading name of '.ow_global_var('accountant_full_name').'

      <p>

       ';

	

        if ( ow_global_var( 'accountant_reg' ) != NULL ) {

             $footer.='<p>' . ow_global_var( 'accountant_reg' ) . ', Registered in England and Wales' . '</p>';

        }

        

     $footer.='</td>

  </tr>'.$tablend;?>

	<?php $pdfcontent=$header.$fullcontent.$footer.'<style>

		body {background-color:#fff;margin:0;padding:0;font-family:arial;font-size:16px;color:'.$main_text.';}

		h1,h2,h3,h4,h5,h6,p,pre,ul,ol {margin:0 0 10px 0;}

		a {text-decoration:none;color:'.$link_text.';}

		address {font-style:normal;}

		blockquote {font-style:italic;}

		img{width:100%;}

		.logo img{width:auto;}

		.date{text-align:right;}

	#logo{max-width: 236px;

    max-height: 100px;}

@page { margin: 20px; }

.fff{display:none;}

        td {

            word-wrap: break-word; /* Allows text to break in long words */

            white-space: normal;   /* Ensures content wraps inside the cell */

            overflow: visible;     /* Ensures no content gets cut off */

        }

</style> ';?>

	<?php

	if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "generate-one-sheet" ) { 

//echo $content;exit();



// instantiate and use the dompdf class

/*$options = new Options();

$options->set('isRemoteEnabled', true);

$dompdf = new Dompdf($options);

$dompdf->loadHtml($pdfcontent);*/



$mpdf = new \Mpdf\Mpdf([

  'margin_left' => 10,

  'margin_right' => 10,

  'margin_top' => 10,

  'margin_bottom' => 10,

  'margin_header' => 5,

  'margin_footer' => 5

]);



// Allow table rows to break across pages

$mpdf->shrink_tables_to_fit = 0; // Disable automatic shrinking



// Write HTML content to PDF

$mpdf->WriteHTML($pdfcontent);

 

$doctitle = 'Newsletter_'.ow_global_var('accountant_name');

 

// (Optional) Setup the paper size and orientation

/*$dompdf->set_paper( 'a4' , 'portrait' );*/

// Render the HTML as PDF

/*$dompdf->render();*/

 /*?>//-------------------------WATERMARK Start

 // Instantiate canvas instance 

$canvas = $dompdf->getCanvas(); 

 

// Instantiate font metrics class 

$fontMetrics = new FontMetrics($canvas, $options); 

 

// Get height and width of page 

$w = $canvas->get_width(); 

$h = $canvas->get_height(); 

// Get font family file 

$font = $fontMetrics->getFont('times'); 

 

// Specify watermark text 

$text = "Maintained by IRIS WebPortal"; 

 

// Get height and width of text 

$txtHeight = $fontMetrics->getFontHeight($font, 10); 

$textWidth = $fontMetrics->getTextWidth($text, $font, 10); 

 

// Set text opacity 

$canvas->set_opacity(.2); 

 

// Specify horizontal and vertical position 

$x = (($w-$textWidth)/2); 

$y = (($h-$txtHeight)/2); 

 

// Writes text at the specified x and y coordinates 

$canvas->text($x, $y, $text, $font, 75); 

//------------------------WATERMARK END */

ob_end_clean();

$mpdf->Output($doctitle.'.pdf', 'D');

 

exit();

}?>

		<?php if ( $content_type == 'tax_tips' ):?>

	<div id="pdfdownload" style="display:none; position: absolute;   right: calc(100vw - ((100vw - 644px) / 2));z-index:0;  top: 13%;"><form class="form-horizontal"  role="form" action="" method="post" >

    <button type="submit" class="download-details"></button>

    <input type="hidden" name="action" value="generate-one-sheet" />

</form></div><?php endif;?>

<table autosize="0" bgcolor="#ffffff" border="0" cellpadding="0" cellspacing="0" width="660" align="center">

  <?php

 

  ?>

  <tr bgcolor="<?php echo $head_bg; ?>">

    

          <td align="left" width="50%" style="vertical-align:top;" id="pdfcontent"><?php echo $header.$content.$footer;?></td>

        

  </tr>

  

  

  

</table>

</body>

</html>

<?php

/*

 * This is an extra text area. If the customer wants to add a new text area/article, paste this code above, and add the required text area to the Newsletter field group using the Custom Fields plugin

 *

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------

<tr>

	<td style="vertical-align:top;" colspan="2">

		<table width="100%">

			<tr bgcolor="<?php echo $title_bg; ?>" style="color:<?php echo $title_text; ?>;">

				<td style="padding:5px 10px;">NEW SECTION</td>

			</tr>

			<tr>

				<td style="padding: 10px;"><?php echo get_field('NEW_SECTION'); ?></td>

			</tr>

		</table>

	</td>

</tr>

------------------------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------	

*/



?><script src="https://code.jquery.com/jquery-3.7.0.min.js" ></script>

<script>

  $(document).ready(function(){

        $("#pdfdownload").delay(3000).fadeIn();

    });

</script>

