Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Лабораторная_1.doc
Скачиваний:
8
Добавлен:
31.01.2023
Размер:
3.39 Mб
Скачать

GetApplicantData.Php

<?php

if(isset($_POST['studentPhone'])) {

class MyDB extends SQLite3 {

function __construct() {

$this->open('db/applicant.sqlite');

}

}

$db = new MyDB();

if (!$db) {

echo $db->lastErrorMsg();

}

$sql =

'INSERT INTO students (ID, Surname, Name, SecondName, Phone, profession, Birthday, Country, City, Street, StreetNumber, SchoolCountry, SchoolCity, SchoolName, SchoolNumber, SchoolDate, achievements, docNumber, docDate)'

. 'VALUES (:id, :surname, :name, :secondName, :phone, :profession, :birthday, :country, :city, :street, :streetNumber, :schoolCountry, :schoolCity, :schoolName, :schoolNumber, :schoolDate, :achievements, :docNumber, :docDate)';

$stmt = $db->prepare($sql);

$stmt->bindValue(':id', md5($_POST['studentPhone']));

$stmt->bindValue(':surname', $_POST['studentSurname']);

$stmt->bindValue(':name', $_POST['studentName']);

$stmt->bindValue(':secondName', $_POST['studentSecondName']);

$stmt->bindValue(':birthday', $_POST['studentBirthday']);

$stmt->bindValue(':phone', $_POST['studentPhone']);

$stmt->bindValue(':profession', $_POST['profession']);

$stmt->bindValue(':country', $_POST['studentCountry']);

$stmt->bindValue(':city', $_POST['studentCity']);

$stmt->bindValue(':street', $_POST['studentStreet']);

$stmt->bindValue(':streetNumber', $_POST['studentStreetNumber']);

$stmt->bindValue(':schoolCountry', $_POST['schoolCountry']);

$stmt->bindValue(':schoolCity', $_POST['schoolCity']);

$stmt->bindValue(':schoolName', $_POST['schoolName']);

$stmt->bindValue(':schoolNumber', $_POST['schoolNumber']);

$stmt->bindValue(':schoolDate', $_POST['schoolDate']);

$stmt->bindValue(':achievements', $_POST['studentAchievements']);

$stmt->bindValue(':docNumber', $_POST['docNumber']);

$stmt->bindValue(':docDate', $_POST['docDate']);

$stmt->execute();

$db->close();

}

?>

Util.Php

<?php

function randomLine ($path) {

$FILENAME = $path;

$LINE_DELIMITER = "\n";

$MAX_LINE_LEN = 255 + strlen($LINE_DELIMITER);

$TRIPLE_BUFFER = $MAX_LINE_LEN * 3;

$fileLen = filesize($FILENAME);

if (empty($fileLen) || $fileLen < $TRIPLE_BUFFER) {

throw new \ErrorException("Файл слишком мал");

}

$rnd = rand(0, $fileLen - $TRIPLE_BUFFER);

$handle = fopen($FILENAME, "r");

fseek($handle, $rnd);

$stream = fread($handle, $TRIPLE_BUFFER);

$lines = explode($LINE_DELIMITER, $stream);

$lineCount = count($lines);

$randomLine = "";

$startAtLine = ($rnd !== 0) ? 1 : 0;

for ($i = $startAtLine; $i < $lineCount; $i++) {

if (!empty($lines[$i])) {

$randomLine = $lines[$i];

break;

}

}

return $randomLine;

}

function addNullBefore ($num) {

if ($num < 10) $num = '0' . $num;

else $num = $num;

return $num;

}

function dateRand() {

$y = rand(2002, 2006);

$m = rand(1, 12);

if ($m = 2) {

if ($y % 4) $d = rand(1, 29);

else $d = rand(1, 28);

} else if ($m = 1 || $m = 3 || $m = 5 || $m = 7 || $m = 8 || $m = 10 || $m = 12) {

$d = rand(1, 31);

} else {

$d = rand(1, 30);

}

return $y.'-'.addNullBefore($m).'-'.addNullBefore($d);

}

function phoneNumber () {

return '+7 ('. rand(910, 999) .') '. rand(100, 999) .'-'. addNullBefore(rand(0, 99)) .'-'. addNullBefore(rand(0, 99));

}

$countries = array('Казахстан', 'Россия', 'Беларусь');

$cities = array(

'Казахстан' => array('Алматы', 'Нур-Султан', 'Шымкент', 'Байконур', 'Актау'),

'Россия' => array('Москва', 'Санкт-Петербург', 'Тула', 'Сочи', 'Воронеж'),

'Беларусь' => array('Минск', 'Брест', 'Витебск', 'Гомель', 'Гродно'),

);

$currentCountry = rand(0, 2);

$schoolFirst = array('МКОУ', 'МБОУ', 'МОУ', 'ГБОУ', 'МКШ', 'МАОУ');

$schoolSecond = array('СОШ', 'СШ', 'Лицей', 'Гимназия');

$achieve = array(

'Отстуствуют',

'Золотая медаль',

'Сереберянная медаль',

'Победитель олимпиады',

'Призер олимпиады',

'Наличие ГТО',

);

?>

Соседние файлы в предмете Технология программирования