<?php
  $emailparts = array();
  include_once('email.php');
   
  $old_weight1 = $_GET['ow1'];
  $old_weight2 = $_GET['ow2'];
  $old_price = $_GET['op'];
  $va = $_GET['va'];      
  $new_nweight = $_GET['nw'];
  $new_price = $_GET['np'];
  $old_rlp = $_GET['orl'];
  $new_rlp = $_GET['nr'];
  $rlnum_day = $_GET['rd'];
  $email1 = $_GET['em1'];
  $email2 = $_GET['em2'];
  $name1 = $_GET['na1'];
  $name2 = $_GET['na2'];
  $comp = $_GET['com'];
  $staff = $_GET['staff'];
 
  $old_nweight = $old_weight1 - $old_weight2;
  $old_nweight = round($old_nweight,3);
 
  $old_kgprice = $old_price / $old_nweight;
  $new_kgprice = $new_price / $new_nweight;
      
  $old_rlprice = round($old_kgprice * $old_rlp,3);
  $new_rlprice = round($new_kgprice * $new_rlp,3);
      
  
  $diff1 = $old_rlprice - $new_rlprice;
  
  $diff2 = $rlnum_day * $diff1;
  $diff2f = number_format($diff2,0,"."," ");
  $diff3 = number_format($diff2 * 5,0,"."," ");
  $diff4 = number_format($diff2 * 21,0,"."," ");
  $diff5 = number_format($diff2 * 253,0,"."," ");
      
  $diff6 = 100 - (($new_rlprice*100) / $old_rlprice);
  $diff6 = round($diff6);
      
  $rlnum_year = $rlnum_day * 253;
  $cost_year = number_format($rlnum_year * $old_rlprice,0,"."," ");
  
  
// Email küldés

  $emailparts['old_weight1'] = $old_weight1;
  $emailparts['old_weight2'] = $old_weight2;
  $emailparts['va'] = $va;  
  $emailparts['old_nweight'] = $old_nweight;
  $emailparts['old_price'] = $old_price;
  $emailparts['new_nweight'] = $new_nweight;  
  $emailparts['new_price'] = $new_price;
  $emailparts['old_rlp'] = $old_rlp;
  $emailparts['new_rlp'] = $new_rlp;
  $emailparts['old_rlprice'] = round($old_rlprice);
  $emailparts['new_rlprice'] = round($new_rlprice);
  $emailparts['diff1'] = round($diff1);
  $emailparts['rlnum_day'] = $rlnum_day;
  $emailparts['diff2f'] = $diff2f;
  $emailparts['diff3'] = $diff3;
  $emailparts['diff4'] = $diff4;
  $emailparts['diff5'] = $diff5;
  $emailparts['diff6'] = $diff6;
  $emailparts['cost_year'] = $cost_year;
  $emailparts['name1'] = $name1;
  $emailparts['email1'] = $email1;
  $emailparts['name2'] = $name2;
  $emailparts['email2'] = $email2;
  $emailparts['name'] = $name1;
  $emailparts['comp'] = $comp;
  
  $fromname = "Golden Pack Hungary Zrt.";
  $fromemail = "ajanlat@foliaazonnal.hu";
  if ($staff == 1) {
    $fromname = "Golden Pack Hungary Zrt. - Homolya Péter";
    $fromemail = "homolya.peter@foliaazonnal.hu";
    $emailparts['staffname'] = "Homolya Péter";
    $emailparts['staffphone'] = "06-30-92-92-327";
    $emailparts['staffemail'] = $fromemail;
  }
  if ($staff == 2) {
    $fromname = "Golden Pack Hungary Zrt. - Kassa Tamás";
    $fromemail = "kereskedelem@foliaazonnal.hu";
    $emailparts['staffname'] = "Kassa Tamás";
    $emailparts['staffphone'] = "06-30-92-92-327";
    $emailparts['staffemail'] = $fromemail;
  }  
    
  $subject = "Kézi Fólia a Golden Packtól - üzemi teszt eredmények";
  $templatefile = "../site/emailtemplate.html";
  $emailcontents = file_get_contents($templatefile);
  foreach ($emailparts as $varname => $varvalue) {
    $emailcontents = str_replace("#$varname#",$varvalue,$emailcontents);
  }
  
  $toemail = $emailparts['email1'];
  $toname = $emailparts['name1'];
  $htmlbody1 = $emailcontents;
  $textbody1 = "
Tisztelt ".$toname."!
Levelünkben a kézi strech fólia üzemi teszteredményeit és megtakarítási lehetőségeit találja!

Üdvözlettel:
Golden Pack Hungary Zrt.
Telefon: +3630-9-622-622 vagy 06-30-9-292-327
E-mail: ajanlat@foliaazonnal.hu
Web: www.foliaazonnal.hu";



  //echo "Első email küldése";
  $ok = sendEmail($fromname, $fromemail, $toname, $toemail, $subject, $textbody1, $htmlbody1);
  if ($staff == 1) {
    $ok2 = sendEmail($fromname, $fromemail, "Homolya Péter", "homolya.peter@foliaazonnal.hu", "Másolat - ".$comp." - ".$subject, $textbody1, $htmlbody1);
  }
  if ($staff == 2) {
    $ok3 = sendEmail($fromname, $fromemail, "Molnár Gábor", "molnar.gabor@foliaazonnal.hu", "Másolat - ".$comp." - ".$subject, $textbody1, $htmlbody1);
  }
  if ($staff == 3) {
    $ok4 = sendEmail($fromname, $fromemail, "Üveges Zoltán", "uveges.zoltan@foliaazonnal.hu", "Másolat - ".$comp." - ".$subject, $textbody1, $htmlbody1);
  }
  $ok5 = sendEmail($fromname, $fromemail, "Golden Pack Hungary Zrt", "ajanlat@foliaazonnal.hu", "Másolat - ".$comp." - ".$subject, $textbody1, $htmlbody1);
  if ($email2) {    
    $emailparts['name'] = $name2;
    $templatefile2 = "../site/emailtemplate.html";
    $emailcontents2 = file_get_contents($templatefile2);
    foreach ($emailparts as $varname => $varvalue) {
      $emailcontents2 = str_replace("#$varname#",$varvalue,$emailcontents2);
    }
    $fromname2 = "Golden Pack Hungary Zrt. - ".$emailparts['staffname'];
    $fromemail2 = $emailparts['staffemail'];
    $subject2 = "LW Fólia a Golden Packtól - üzemi teszt eredmények";
    $toemail2 = $email2;
    $toname2 = $name2;
    $htmlbody2 = $emailcontents2;
    //echo $htmlbody2;
    $textbody2 = "
      Tisztelt ".$toname2."!
      Levelünkben a kézi strech fólia üzemi teszteredményeit és megtakarítási lehetőségeit találja!

      Üdvözlettel:
      Golden Pack Hungary Zrt.
      Telefon: +3630-9-622-622 vagy 06-30-9-292-327
      E-mail: ajanlat@foliaazonnal.hu
      Web: www.foliaazonnal.hu";
    
    $ok2 = sendEmail($fromname2, $fromemail2, $toname2, $toemail2, $subject2, $textbody2, $htmlbody2);   
    
  }
  echo "Sikeres e-mail küldés";
  
  
  