-
Notifications
You must be signed in to change notification settings - Fork 0
/
instrPost.php
97 lines (86 loc) · 3.23 KB
/
instrPost.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
require_once "mail.php";
require_once "dbase_connection.php";
$connection = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
mysqli_set_charset($connection,'utf8mb4_general_ci');
// Get the posted data.
$postdata = file_get_contents("php://input");
if(!$postdata)exit;
$request = json_decode($postdata);
// test for connection
if (mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" ( " . mysqli_connect_errno() . ")");
}
$status = 1;
$fullName = mysqli_real_escape_string($connection, trim($request->fullname));
$email = mysqli_real_escape_string($connection, trim($request->email));
$account = mysqli_real_escape_string($connection, trim($request->account));
$supervisor = mysqli_real_escape_string($connection, trim($request->supervisor));
$dates = $request->selectedDays;
$le=count($dates);
for($i=0;$i<$le;$i++){
$dates[$i]=date('d-n-Y', $dates[$i]);
}
$unit=$request->unit;
$slide27=$request->slide27;
$slide27coated=$request->slide27Coated;
$oneround=$request->oneRound;
$onepolished=$request->onePolished;
$mountcoated=$request->mountCoated;
$oneseven=$request->oneSeven;
$carbon=$request->carbon;
$repolish=$request->repolish;
$comments = mysqli_real_escape_string($connection, trim($request->comments));
$tablename = $request->table;
$query = "SELECT * FROM inits WHERE unit = '$tablename' ";
$result = mysqli_query( $connection, $query );
if ( !$result ) {
die( "Database query failed" );
} else {
while ( $row = mysqli_fetch_assoc( $result ) ) {
$secondEmail= $row[ 'emailOne' ];
$thirdEmail= $row[ 'emailTwo' ];
$message=$row['message'];
}
}
if($tablename == 'thin_sections'){
foreach ($dates as $date) {
$query = "INSERT INTO $tablename (";
$query .= "status,fullName,email,account,";
$query .= "supervisor, date, comments,";
$query .= "slide27, slide27coated,oneround,onepolished,";
$query .= " mountcoated, oneseven, carbon, repolish";
$query .= ") VALUES (";
$query .= "'${status}','${fullName}','${email}', '${account}',";
$query .= "'${supervisor}','${date}','${comments}',";
$query .= "'${slide27}','${slide27coated}','${oneround}','${onepolished}',";
$query .= "'${mountcoated}','${oneseven}','${carbon}','${repolish}'";
$query .= ")";
$result = (mysqli_query($connection, $query));
}
// send thin section email
mysqli_close($connection);
$datesImpl= implode(", ", $dates);
require "emailItems/emailitemThin.php";
sendMail($fullName,$account,$email,$secondEmail,$thirdEmail,$html);
}else{
foreach ($dates as $date) {
$query = "INSERT INTO $tablename (";
$query .= "status,fullName,email,account,";
$query .= "supervisor, date, comments";
$query .= ") VALUES (";
$query .= "'${status}','${fullName}','${email}', '${account}',";
$query .= "'${supervisor}','${date}','${comments}' ";
$query .= ")";
$result = (mysqli_query($connection, $query));
}
// send regular instrument email
mysqli_close($connection);
$datesImpl= implode(", ", $dates);
require "emailItems/emailitem.php";
$message = sendMail($fullName,$account,$email,$secondEmail,$thirdEmail,$html);
echo $message;
}
?>