function send_email_revision_cp($revision, $cp) { require_once 'include/PHPMailer/PHPMailerAutoload.php'; $email_to_kraf = def_value("default_email", "hodnota"); mysql_query("BEGIN"); $data = sql_query("SELECT id_obj, meno, adresa, ico_icdph, telefon, email, id_material as material,\r\n id_vyrobca as vyrobca, id_dekor as dekor, dekor_vlastny, komentar,\r\n DATE_FORMAT(datum, '%d. %m. %Y, %H:%i') AS datum\r\n FROM revizia \r\n WHERE id={$revision} \r\n LIMIT 1"); $data_narez = sql_query("SELECT ks, dlzka, sirka, nazov, poznamka, hrubka, orientacia,\r\n hrana1, hrana2, hrana3, hrana4\r\n FROM porez \r\n WHERE id_revizia={$revision}"); $data = $data[0]; $fieldsets_c = count($data_narez); for ($i = 0; $i < $fieldsets_c; $i++) { $ks[$i] = $data_narez[$i][ks]; $dlzka[$i] = $data_narez[$i][dlzka]; $sirka[$i] = $data_narez[$i][sirka]; $nazov[$i] = $data_narez[$i][nazov]; $poznamka[$i] = $data_narez[$i][poznamka]; $hrubka[$i] = $data_narez[$i][hrubka]; $orientacia[$i] = $data_narez[$i][orientacia]; $hrana1[$i] = $data_narez[$i][hrana1]; $hrana2[$i] = $data_narez[$i][hrana2]; $hrana3[$i] = $data_narez[$i][hrana3]; $hrana4[$i] = $data_narez[$i][hrana4]; } $data[ks_all] = $ks; $data[dlzka_all] = $dlzka; $data[sirka_all] = $sirka; $data[nazov_all] = $nazov; $data[poznamka_all] = $poznamka; $data[hrubka_all] = $hrubka; $data[orientacia_all] = $orientacia; $data[hrana1_all] = $hrana1; $data[hrana2_all] = $hrana2; $data[hrana3_all] = $hrana3; $data[hrana4_all] = $hrana4; $files = sql_query("SELECT meno, meno_old, pripona \r\n FROM subor\r\n WHERE id_obj=" . $data["id_obj"] . ""); //var_dump($data); $data_obj = sql_query("SELECT DATE_FORMAT(datum, '%d. %m. %Y, %H:%i') AS datum, c_obj,\r\n DATE_FORMAT(datum, '%Y') AS rok\r\n FROM objednavka \r\n WHERE id=" . $data["id_obj"] . " LIMIT 1"); $data_obj = $data_obj[0]; $message = "<html><body>"; $message .= "<img src=\"http://" . def_value("default_url", "hodnota") . "/assets/images/logo.jpg\">"; $message .= "<h1>Cenová ponuka k objednávke č. " . $data_obj["c_obj"] . " / " . $data_obj["rok"] . "</h1>"; $message .= "zo dňa: " . $data_obj["datum"] . "<br><br>"; $message .= "<table><tr>"; $message .= "<td style=\"width: 400px;\"><strong>Dodávateľ</strong><br>"; $message .= "<table><tr><td>" . def_value("default_firma", "hodnota") . "</td></tr>"; $message .= "<tr><td>" . def_value("default_adresa", "hodnota") . "<br>" . def_value("default_mesto", "hodnota") . "</td></tr>"; $message .= "<tr><td>IČO: " . def_value("default_ico", "hodnota") . "<br> DIČ: " . def_value("default_dic", "hodnota") . "</td></tr>"; $message .= "<tr><td>" . def_value("default_telefon", "hodnota") . "<br> " . def_value("default_mobil", "hodnota") . "</td></tr>"; $message .= "<tr><td>" . def_value("default_email", "hodnota") . "<br> " . def_value("default_email_2", "hodnota") . "</td></tr>"; $message .= "</table><br><br></td>"; $message .= "<td style=\"width: 50%;\"><strong>Objednávateľ:</strong>"; $message .= "<table><tr><td>" . $data["meno"] . "</td></tr>"; $message .= "<tr><td>" . $data["adresa"] . "</td></tr>"; $message .= "<tr><td>" . $data["ico_icdph"] . "</td></tr>"; $message .= "<tr><td>" . $data["telefon"] . "</td></tr>"; $message .= "<tr><td>" . $data["email"] . "</td></tr>"; $message .= "</table><br><br></td>"; $message .= "</tr></table>"; $message .= "<strong>Materiál:</strong>"; $material = sql_query("SELECT meno FROM material WHERE id=" . sec_sql(sec_input($data["material"])) . " LIMIT 1"); $material = $material[0]; $message .= "<table><tr><td>" . $material["meno"] . "</td></tr>"; $vyrobca = sql_query("SELECT meno FROM vyrobca WHERE id=" . sec_sql(sec_input($data["vyrobca"])) . " LIMIT 1"); $vyrobca = $vyrobca[0]; $dekor = sql_query("SELECT meno FROM dekor WHERE id=" . sec_sql(sec_input($data["dekor"])) . " LIMIT 1"); $dekor = $dekor[0]; $message .= "<tr><td>" . $vyrobca["meno"] . " " . $dekor["meno"] . "</td></tr>"; $message .= "<tr><td>" . $data["dekor_vlastny"] . "</td></tr>"; $message .= "</table><br><br>"; $message .= "<div class=\"print_hlavicka3\">\r\n <table style=\"font-size: 100%;\">\r\n <tr style=\"background-color: #efefef; font-size: 9pt;\">\r\n \r\n <th style=\"width: 350px;\">položka</th>\r\n <th style=\"width: 80px;\">množstvo</th>\r\n <th style=\"width: 80px;\">jedn. cena</th>\r\n <th style=\"width: 80px;\">Celkom</th>\r\n </tr>"; //var_dump(sql_query("SELECT * from cp WHERE id=$cp")); $data_narez = sql_query("SELECT c.vlastna_cena, c.dekor_ks, d.cena dekor_ks_cena, c.dekor_ks_sum,\r\n c.dekor_m2, c.dekor_m2_jedn dekor_m2_cena, c.dekor_m2_sum,\r\n c.porez, p.cena porez_cena, c.porez_sum,\r\n c.lepenie, l.cena lepenie_cena, round(lepenie_sum, 2) lepenie_sum,\r\n c.cnc_priprava, c1.cena cnc_priprava_cena, c.cnc_priprava_sum,\r\n c.cnc_praca, c2.cena cnc_praca_cena, c.cnc_praca_sum,\r\n c.olep_obluk, o.cena olep_obluk_cena, c.olep_obluk_sum\r\n FROM cp c\r\n LEFT JOIN cp_dekor_ks d ON c.id_dekor_ks = d.id \r\n LEFT JOIN cp_porez p ON c.id_porez = p.id\r\n LEFT JOIN cp_lepenie l ON c.id_lepenie = l.id\r\n LEFT JOIN cp_cnc_opracovanie c1 ON c.id_cnc_priprava = c1.id\r\n LEFT JOIN cp_cnc_praca c2 ON c.id_cnc_praca = c2.id\r\n LEFT JOIN cp_olep_obluk o ON c.id_olep_obluk = o.id\r\n \r\n WHERE c.id={$cp} LIMIT 1"); $data_narez = $data_narez[0]; $fieldsets_c = count($data_narez); for ($i = 0; $i < $fieldsets_c; $i++) { $ks[$i] = $data_narez[$i][ks]; $dlzka[$i] = $data_narez[$i][dlzka]; $sirka[$i] = $data_narez[$i][sirka]; } $data[ks_all] = $ks; $data[dlzka_all] = $dlzka; //var_dump($data_narez); if ($data_narez[dekor_ks_cena] <= 0) { $data_narez[dekor_ks_cena] = $data_narez[vlastna_cena]; } $full_sum = 0; $message .= riadok_print_cp($data_narez[dekor_ks], $data_narez[dekor_ks_cena], $data_narez[dekor_ks_sum], "Material ks"); $full_sum += $data_narez[dekor_ks_sum]; $message .= riadok_print_cp($data_narez[dekor_m2], $data_narez[dekor_m2_cena], $data_narez[dekor_m2_sum], "Material m2"); $full_sum += $data_narez[dekor_m2_sum]; $message .= riadok_print_cp($data_narez[porez], $data_narez[porez_cena], $data_narez[porez_sum], "Porez"); $full_sum += $data_narez[porez_sum]; $num_hrana = sql_query("SELECT id, hodnota FROM hrana WHERE vymaz=0 ORDER BY id"); foreach ($num_hrana as $hrana) { $hrana_abs = sql_query("SELECT a.cena abs, b.cena, a.sum, c.hodnota from cp_hrana a \r\n LEFT JOIN cp_abs b\r\n ON a.id_abs = b.id\r\n LEFT JOIN hrana c\r\n ON b.id_hrana = c.id\r\n WHERE a.id_cp={$cp} AND c.id={$hrana['id']}"); $hrana_abs = $hrana_abs[0]; //var_dump($hrana); if (!empty($hrana_abs[hodnota])) { $message .= riadok_print_cp($hrana_abs[abs], $hrana_abs[cena], $hrana_abs[sum], $hrana_abs[hodnota]); $full_sum += $hrana_abs[sum]; } $hrana_sluzba = sql_query("SELECT a.cena abs, b.cena, a.sum, c.hodnota from cp_hrana_sluzba a \r\n LEFT JOIN cp_abs_sluzba b\r\n ON a.id_abs = b.id\r\n LEFT JOIN hrana c\r\n ON b.id_hrana = c.id\r\n WHERE a.id_cp={$cp} AND c.id={$hrana['id']}"); $hrana_sluzba = $hrana_sluzba[0]; //var_dump($hrana); if (!empty($hrana_sluzba[hodnota])) { $message .= riadok_print_cp($hrana_sluzba[abs], $hrana_sluzba[cena], $hrana_sluzba[sum], "- olepenie " . $hrana_sluzba[hodnota]); $full_sum += $hrana_sluzba[sum]; } } $message .= riadok_print_cp($data_narez[lepenie], $data_narez[lepenie_cena], $data_narez[lepenie_sum], "Lepenie"); $full_sum += $data_narez[lepenie_sum]; $message .= riadok_print_cp($data_narez[cnc_priprava], $data_narez[cnc_priprava_cena], $data_narez[cnc_priprava_sum], "CNC programovanie"); $full_sum += $data_narez[cnc_priprava_sum]; $message .= riadok_print_cp($data_narez[cnc_praca], $data_narez[cnc_praca_cena], $data_narez[cnc_praca_sum], "CNC práca"); $full_sum += $data_narez[cnc_praca_sum]; $message .= riadok_print_cp($data_narez[olep_obluk], $data_narez[olep_obluk_cena], $data_narez[olep_obluk_sum], "Olep oblúkov"); $full_sum += $data_narez[olep_obluk_sum]; $num_sluzba = sql_query("SELECT popis, hodnota, cena, sum FROM cp_sluzba WHERE id_cp={$cp} ORDER BY id"); foreach ($num_sluzba as $sluzba) { //var_dump($sluzba); if (!empty($sluzba[popis])) { $message .= riadok_print_cp($sluzba[hodnota], $sluzba[cena], $sluzba[sum], $sluzba[popis]); //var_dump($hrana[sum]); $full_sum = $full_sum + $sluzba[sum]; } } $full_sum = ceil($full_sum * 100) / 100; $message .= "</table><br><br>"; $message .= "<div style=\"margin: 1em; font-size: 130%;\"><strong>Cena spolu: </strong>{$full_sum} €</div><br><br>"; $message .= "email vytvorený: " . date("j. n. Y - H:i") . "<br>"; $message .= "</body></html>"; mysql_query("COMMIT"); //echo $message; if ($data["email"] != $email_to) { $email_to = $data["email"]; $email_subject = "Cenová ponuka k objednávke č. " . $data_obj["c_obj"] . " / " . $data_obj["rok"] . " - " . def_value("default_firma", "hodnota") . ""; $headers = "From: \"" . def_value("default_firma", "hodnota") . "\" <" . def_value("default_email", "hodnota") . ">\r\n"; $headers .= "Reply-To: " . def_value("default_email", "hodnota") . "\r\n"; //$headers .= "CC: scooti@stonline.sk\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $mail = new PHPMailer(); //$mail->IsSMTP(); $mail->CharSet = "UTF-8"; $mail->SMTPDebug = 0; $mail->SMTPAuth = true; //$mail->SMTPSecure = 'ssl'; $mail->Host = def_value("default_email_host", "hodnota"); $mail->Port = def_value("default_email_port", "hodnota"); $mail->Username = def_value("default_email_username", "hodnota"); $mail->Password = def_value("default_email_password", "hodnota"); $mail->isHTML(true); $mail->setLanguage('sk', 'language/'); $mail->SetFrom(def_value("default_email", "hodnota"), def_value("default_firma", "hodnota")); $mail->Subject = $email_subject; $mail->Body = $message; $mail->AddAddress($email_to); $mail->Send(); //mail($email_to, $email_subject, $message, $headers); //var_dump($email_to); //var_dump($data["email"]); } echo "Email bol úspešne odoslaný na adresu: {$email_to}"; }
function print_revision_cp($cp, $revision) { $data = sql_query("SELECT id_obj, meno, adresa, ico_icdph, telefon, email, id_material as material,\r\n id_vyrobca as vyrobca, id_dekor as dekor, dekor_vlastny, komentar,\r\n DATE_FORMAT(datum, '%d. %m. %Y, %H:%i') AS datum\r\n FROM revizia \r\n WHERE id={$revision} \r\n LIMIT 1"); //var_dump($data); $data = $data[0]; $data_obj = sql_query("SELECT DATE_FORMAT(datum, '%d. %m. %Y, %H:%i') AS datum, c_obj, id_zakaznik,\r\n DATE_FORMAT(datum, '%Y') AS rok\r\n FROM objednavka \r\n WHERE id=" . $data["id_obj"] . " LIMIT 1"); $data_obj = $data_obj[0]; $message = ""; $message .= "<h1>Cenová ponuka k obj č. " . $data_obj["c_obj"] . " / " . $data_obj["rok"] . " rev. " . $revision . " </h1>"; $message .= "<h5>zo dňa: " . $data_obj["datum"] . "</h5>"; $message .= "<div class=\"print_hlavicka\">"; $message .= "<table class=\"print_dodavatel\"><tr><td></td><td><strong>Dodávateľ</strong></td></tr>"; $message .= "<tr><td></td><td>" . def_value("default_firma", "hodnota") . "</td></tr>"; $message .= "<tr><td></td><td>" . def_value("default_adresa", "hodnota") . "</td></tr>"; $message .= "<tr><td></td><td>" . def_value("default_mesto", "hodnota") . "</td></tr>"; $message .= "<tr><td>IČO:</td><td>" . def_value("default_ico", "hodnota") . "</td></tr>"; $message .= "<tr><td>DIČ:</td><td>" . def_value("default_dic", "hodnota") . "</td></tr>"; $message .= "<tr><td>tel.:</td><td>" . def_value("default_telefon", "hodnota") . "</td></tr>"; $message .= "<tr><td>mobil:</td><td>" . def_value("default_mobil", "hodnota") . "</td></tr>"; $message .= "<tr><td>email:</td><td>" . def_value("default_email", "hodnota") . ", " . def_value("default_email_2", "hodnota") . "</td></tr>"; $message .= "</table>"; if ($data_obj[id_zakaznik] > 0) { $meno_zakaznika = sql_query("SELECT meno, adresa, ico_icdph, telefon, email FROM uzivatel WHERE id={$data_obj['id_zakaznik']} LIMIT 1"); $meno_zakaznika = $meno_zakaznika[0]; $data[meno] = $meno_zakaznika[meno]; $data[adresa] = $meno_zakaznika[adresa]; $data[ico_icdph] = $meno_zakaznika[ico_icdph]; $data[telefon] = $meno_zakaznika[telefon]; $data[email] = $meno_zakaznika[email]; } $message .= "<div class=\"print_odberatel\"><table class=\"print_odberatel\"><tr><td></td><td>Objednávateľ:</td></tr>"; $message .= "<tr><td></td><td class=\"print_bigger\">" . $data["meno"] . "</td></tr>"; $message .= "<tr><td></td><td>" . $data["adresa"] . "</td></tr>"; $message .= "<tr><td>IČO:</td><td>" . $data["ico_icdph"] . "</td></tr>"; $message .= "<tr><td>tel.:</td><td>" . $data["telefon"] . "</td></tr>"; $message .= "<tr><td>email:</td><td>" . $data["email"] . "</td></tr>"; $message .= "</table>"; $message .= "</div>"; $message .= "<div class=\"print_hlavicka2\">"; $material = sql_query("SELECT meno FROM material WHERE id=" . sec_sql(sec_input($data["material"])) . " LIMIT 1"); $material = $material[0]; $message .= "<table><tr><td>materiál:</td><td class=\"print_bigger\">" . $material["meno"] . "</td></tr>"; $vyrobca = sql_query("SELECT meno FROM vyrobca WHERE id=\"" . sec_sql(sec_input($data["vyrobca"])) . "\" LIMIT 1"); $vyrobca = $vyrobca[0]; $dekor = sql_query("SELECT meno FROM dekor WHERE id=" . sec_sql(sec_input($data["dekor"])) . " LIMIT 1"); $dekor = $dekor[0]; $message .= "<tr><td>dekor:</td><td class=\"print_bigger\">" . $vyrobca["meno"] . " " . $dekor["meno"] . "</td></tr>"; $message .= "<tr><td>vlastný dekor:</td><td>" . $data["dekor_vlastny"] . "</td></tr>"; $message .= "</table><br></div>"; $message .= "<div class=\"print_hlavicka3\">\r\n <table class=\"c_ponuka\">\r\n <tr>\r\n \r\n <th style=\"width: 270px;\">položka CP</th>\r\n <th style=\"width: 60px;\">množstvo</th>\r\n <th style=\"width: 70px;\">jedn. cena</th>\r\n <th style=\"width: 70px;\">Celkom</th>\r\n </tr>"; //var_dump(sql_query("SELECT * from cp WHERE id=$cp")); $data_narez = sql_query("SELECT c.vlastna_cena, c.dekor_ks, d.cena dekor_ks_cena, c.dekor_ks_sum,\r\n c.dekor_m2, c.dekor_m2_jedn dekor_m2_cena, c.dekor_m2_sum,\r\n c.porez, p.cena porez_cena, c.porez_sum,\r\n c.lepenie, l.cena lepenie_cena, c.lepenie_sum,\r\n c.cnc_priprava, c1.cena cnc_priprava_cena, c.cnc_priprava_sum,\r\n c.cnc_praca, c2.cena cnc_praca_cena, c.cnc_praca_sum,\r\n c.olep_obluk, o.cena olep_obluk_cena, c.olep_obluk_sum\r\n FROM cp c\r\n LEFT JOIN cp_dekor_ks d ON c.id_dekor_ks = d.id \r\n LEFT JOIN cp_porez p ON c.id_porez = p.id\r\n LEFT JOIN cp_lepenie l ON c.id_lepenie = l.id\r\n LEFT JOIN cp_cnc_opracovanie c1 ON c.id_cnc_priprava = c1.id\r\n LEFT JOIN cp_cnc_praca c2 ON c.id_cnc_praca = c2.id\r\n LEFT JOIN cp_olep_obluk o ON c.id_olep_obluk = o.id\r\n \r\n WHERE c.id={$cp} LIMIT 1"); $data_narez = $data_narez[0]; $fieldsets_c = count($data_narez); for ($i = 0; $i < $fieldsets_c; $i++) { $ks[$i] = $data_narez[$i][ks]; $dlzka[$i] = $data_narez[$i][dlzka]; $sirka[$i] = $data_narez[$i][sirka]; } $data[ks_all] = $ks; $data[dlzka_all] = $dlzka; //var_dump($data_narez); if ($data_narez[dekor_ks_cena] <= 0) { $data_narez[dekor_ks_cena] = $data_narez[vlastna_cena]; } $full_sum = 0; $message .= riadok_print_cp($data_narez[dekor_ks], $data_narez[dekor_ks_cena], $data_narez[dekor_ks_sum], "Material ks"); $full_sum += $data_narez[dekor_ks_sum]; $message .= riadok_print_cp($data_narez[dekor_m2], $data_narez[dekor_m2_cena], $data_narez[dekor_m2_sum], "Material m2"); $full_sum += $data_narez[dekor_m2_sum]; $message .= riadok_print_cp($data_narez[porez], $data_narez[porez_cena], $data_narez[porez_sum], "Porez"); $full_sum += $data_narez[porez_sum]; $num_hrana = sql_query("SELECT id, hodnota FROM hrana WHERE vymaz=0 ORDER BY id"); foreach ($num_hrana as $hrana) { $hrana_abs = sql_query("SELECT a.cena abs, b.cena, a.sum, c.hodnota from cp_hrana a \r\n LEFT JOIN cp_abs b\r\n ON a.id_abs = b.id\r\n LEFT JOIN hrana c\r\n ON b.id_hrana = c.id\r\n WHERE a.id_cp={$cp} AND c.id={$hrana['id']}"); $hrana_abs = $hrana_abs[0]; //var_dump($hrana); if (!empty($hrana_abs[hodnota])) { $message .= riadok_print_cp($hrana_abs[abs], $hrana_abs[cena], $hrana_abs[sum], $hrana_abs[hodnota]); $full_sum += $hrana_abs[sum]; } $hrana_sluzba = sql_query("SELECT a.cena abs, b.cena, a.sum, c.hodnota from cp_hrana_sluzba a \r\n LEFT JOIN cp_abs_sluzba b\r\n ON a.id_abs = b.id\r\n LEFT JOIN hrana c\r\n ON b.id_hrana = c.id\r\n WHERE a.id_cp={$cp} AND c.id={$hrana['id']}"); $hrana_sluzba = $hrana_sluzba[0]; //var_dump($hrana); if (!empty($hrana_sluzba[hodnota])) { $message .= riadok_print_cp($hrana_sluzba[abs], $hrana_sluzba[cena], $hrana_sluzba[sum], "- olepenie " . $hrana_sluzba[hodnota]); $full_sum += $hrana_sluzba[sum]; } } $message .= riadok_print_cp($data_narez[lepenie], $data_narez[lepenie_cena], $data_narez[lepenie_sum], "Lepenie"); $full_sum += $data_narez[lepenie_sum]; $message .= riadok_print_cp($data_narez[cnc_priprava], $data_narez[cnc_priprava_cena], $data_narez[cnc_priprava_sum], "CNC programovanie"); $full_sum += $data_narez[cnc_priprava_sum]; $message .= riadok_print_cp($data_narez[cnc_praca], $data_narez[cnc_praca_cena], $data_narez[cnc_praca_sum], "CNC práca"); $full_sum += $data_narez[cnc_praca_sum]; $message .= riadok_print_cp($data_narez[olep_obluk], $data_narez[olep_obluk_cena], $data_narez[olep_obluk_sum], "Olep oblúkov"); $full_sum += $data_narez[olep_obluk_sum]; $num_sluzba = sql_query("SELECT popis, hodnota, cena, sum FROM cp_sluzba WHERE id_cp={$cp} ORDER BY id"); foreach ($num_sluzba as $sluzba) { //var_dump($sluzba); if (!empty($sluzba[popis])) { $message .= riadok_print_cp($sluzba[hodnota], $sluzba[cena], $sluzba[sum], $sluzba[popis]); //var_dump($hrana[sum]); $full_sum = $full_sum + $sluzba[sum]; } } $full_sum = ceil(($full_sum + $full_sum * 0.2) * 100) / 100; $message .= "</table>"; $message .= "<div class=\"cp_spolu\"><strong>Cena spolu: </strong>{$full_sum} €</div>"; $message .= "dokument vytvorený: " . date("j. n. Y - H:i") . "<br>\r\n Ceny sú uvádzané s DPH<br>"; return $message; }