<?PHP
function show_form() {
$data = new Data();
$id = ($_SESSION['user']['id']) ? $_SESSION['user']['id'] : $_COOKIE['user_id'];
$result = $data->showProfile($id);
?>
<form action="" method="post" class="pure-form">
<script>
function show() {
document.getElementById('info').style.display='block';
}
function hide() {
document.getElementById('info').style.display='none';
}
</script>
<div >
<div style="float: left;"> Фамилия *</div>
<div style="float: center; width: 49%;"> <input type="text" name="familiya" size="30" required value="<?=$result->familiya;?>" ></div><div class="clear">
<div style="float: left;"> Имя *</div>
<div style="float: center; width: 49%;"><input type="text" name="imya" size="30" value="<?=$result->imya;?>"></div><div class="clear">
<div style="float: left;"> Отчество </div>
<div style="float: center; width: 49%;"><input type="text" name="otchestvo" size="30" value="<?=$result->otchestvo;?>"></div><div class="clear">
<div style="float: left;"> Улица * </div>
<div style="float: center; width: 49%;"><input type="text" name="ylica" size="30" value="<?=$result->ylica;?>"></div><div class="clear">
<div style="float: left;"> Дом * </div>
<div style="float: center; width: 49%;"><input type="text" name="Dom" size="30" value="<?=$result->Dom;?>"></div><div class="clear">
<div style="float: left;"> Квартира *</div>
<div style="float: center; width: 49%;"><input type="text" name="Kvartira" size="30" value="<?=$result->Kvartira;?>"></div><div class="clear">
<div style="float: left;"> Корпус</div>
<div style="float: center; width: 49%;"><input type="text" name="Korpus" size="30" value="<?=$result->Korpus;?>"></div><div class="clear">
<div style="float: left;"> Номер договора </div>
<div style="float: center; width: 49%;"><input type="text" name="Dogovor" size="30" value="<?=$result->Dogovor;?>"></div><div class="clear">
<div style="float: left;"> Лицевой Счет * </div>
<div style="float: center; width: 49%;"><input type="text" name="Licevoj" size="30" value="<?=$result->Licevoj;?>"></div><div class="clear">
<div style="float: left;"> Контактный телефон</div>
<div style="float: center; width: 40%;"><input type="text" name="Tel" size="30"value="<?=$result->Tel;?>"> </div><div class="clear">
<div style="float: left;"> email </div>
<div style="float: center; width: 49%;"><input type="text" name="email" size="30" value="<?=$result->email;?>"> </div><div class="clear">
<div style="float: left;"> Номер карточки *</div>
<div style="float: center; width: 49%;"><input type="text" name="Kart" size="30" value="<?=$result->Kart;?>"></div><div class="clear">
<br />Наш Футбол*<p><input type="radio" name="foot1" value="V"> Подключить
<input type="radio" name="foot2" value="V"> Отключить</p>
<br />Ночной*<p><input type="radio" name="noch" value="V" onChange="show()"> Подключить <input type="radio" name="noch" value="V2" onChange="hide()"> Отключить</p>
<div id="info" style="display:none">
<label><input name="radio_sure" type="checkbox" value="Абонент " />Мне есть 18+</label>
</div>
<br /> Изменения вступят в силу с 01.<input type="month" name="Mesuc" size="30">
Поля помеченные * необходимы для заполнения
<p><input type="checkbox" name="Soglashenie" value="V"> <a href="http://norbi-tv.ru/soglashenie" target="_blank">С дополнительным соглашением ознакомлен</a></p><br />=
<br /><input type="submit" value="Отправить" name="submit">
</div>
</form> <?PHP
}
$Z= Zajuvlenie;
require_once 'PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$shablon = $phpWord->loadTemplate(realpath('files/AnketaTemplate.docx')); $anketaFile = 'files/' . $anketaFileName;
$shablon->setValue('date', date("d.m.y H:i:s"));
$shablon->setValue('familiya', $familiya);
$shablon->setValue('imya', $imya);
$shablon->setValue('otchestvo', $otchestvo);
$shablon->setValue('Ylica', $Ylica);
$shablon->setValue('Dom', $Dom);
$shablon->setValue('Kvartira', $Kvartira);
$shablon->setValue('Korpus', $Korpus);
$shablon->setValue('Podjezd', $Podjezd);
$shablon->setValue('Itaj', $Itaj);
$shablon->setValue('Dogovor', $Dogovor);
$shablon->setValue('Licevoj', $Licevoj);
$shablon->setValue('Tel', $Tel);
$shablon->setValue('foot1', $foot1);
$shablon->setValue('foot2', $foot2);
$shablon->setValue('noch1', $noch1);
$shablon->setValue('noch2', $noch2);
$shablon->setValue('Kart', $Kart);
$shablon->setValue('Mesuc', $Mesuc);
$shablon->saveAs($anketaFile);
/////////////////////////////////////
// пример использования
$file = "./files/Zajuvlenie.docx"; // файл
$mailTo = "norbitest@rambler.ru"; // кому
$from = "sajt@norbi.ru"; // от кого
$subject = "Заявление"; // тема письма
$message = "Заявление о изменение подписки абонента $familiya"; // текст письма
$r = sendMailAttachment($mailTo, $from, $subject, $message, $file); // отправка письма c вложением
echo ($r)? ' ':'Ошибка. Письмо не отправлено!';
//$r = sendMailAttachment($mailTo, $from, $subject, $message); // отправка письма без вложения
//echo ($r)?'Письмо отправлено':'Ошибка. Письмо не отправлено!';
/**
* Отправка письма с вложением
* @param string $mailTo
* @param string $from
* @param string $subject
* @param string $message
* @param string|bool $file - не обязательный параметр, путь до файла
*
* @return bool - результат отправки
*/
function sendMailAttachment($mailTo, $from, $subject, $message, $file = false){
$separator = "---"; // разделитель в письме
// Заголовки для письма
$headers = "MIME-Version: 1.0\r\n";
$headers .= "From: $from\nReply-To: $from\n"; // задаем от кого письмо
$headers .= "Content-Type: multipart/mixed; boundary=\"$separator\""; // в заголовке указываем разделитель
// если письмо с вложением
if($file){
$bodyMail = "--$separator\n"; // начало тела письма, выводим разделитель
$bodyMail .= "Content-type: text/html; charset='utf-8'\n"; // кодировка письма
$bodyMail .= "Content-Transfer-Encoding: quoted-printable"; // задаем конвертацию письма
$bodyMail .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode(basename($file))."?=\n\n"; // задаем название файла $bodyMail .= $message."\n"; // добавляем текст письма
$bodyMail .= "--$separator\n";
$fileRead = fopen($file, "r"); // открываем файл $contentFile = fread($fileRead, filesize($file)); // считываем его до конца fclose($fileRead); // закрываем файл $bodyMail .= "Content-Type: application/octet-stream; name==?utf-8?B?".base64_encode(basename($file))."?=\n"; $bodyMail .= "Content-Transfer-Encoding: base64\n"; // кодировка файла
$bodyMail .= "Content-Disposition: attachment; filename==?utf-8?B?".base64_encode(basename($file))."?=\n\n"; $bodyMail .= "--".$separator ."--\n";
// письмо без вложения
}else{
$bodyMail = $message;
}
$result = mail($mailTo, $subject, $bodyMail, $headers); // отправка письма return $result;
}
if (!empty($_POST['submit'])); else show_form();
?>