-
Notifications
You must be signed in to change notification settings - Fork 1
/
answer.php
136 lines (120 loc) · 3.15 KB
/
answer.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
session_start();
echo "<pre>";
print_r($_POST);
//print_r($_FILES);
print_r($_SESSION);
$group = array();
$user_ip = array();
$fname = urldecode(basename($_SERVER['HTTP_REFERER']));
$fname = substr($fname,0,strpos($fname,"."));
for($i=0;$i<count($_SESSION['total-ip']);$i++){
if(isset($_POST['input'][$i+1])){
echo $_SESSION['total-ip'][$i]." = ".$_POST['input'][$i+1];
echo "<br>";
if($_POST['input'][$i+1]!==""){
array_push($user_ip,$_POST['input'][$i+1]);
}
else{
array_push($user_ip,"NULL");
}
}
else{
array_push($group,$_SESSION['total-ip'][$i]);
}
}
//print_r($group);
if(isset($_FILES)){
if(!empty($_FILES)){
$target = 'Forms/Images/'.$fname;
foreach($_FILES as $key =>$values){
foreach($values as $id=>$faname){
if($id=='name'){
if(is_array($faname)){
$ket = array_keys($faname);
$tp = $faname[$ket[0]];
}
else{
$tp = $faname;
}
//$ket = array_keys($faname);
//print_r($tp = $faname[$ket[0]]);
}
if($id=='tmp_name'){
$ket = array_keys($faname);
$faname = $faname[$ket[0]];
move_uploaded_file($faname, $target.$tp);
$dest = $target.$tp;
//echo $dest;
}
}
}
array_push($user_ip,$dest);
}
}
foreach($_POST as $key => $value){
if($key!=='input'){
for($j=0;$j<count($_SESSION['extra']);$j++){
if($key == $_SESSION['extra'][$j]){
if(is_array($value)){
//echo $group[$j]." = ";
$empty = "";
foreach($value as $check){
//echo $check." ,";
$empty .= $check.",";
}
array_push($user_ip,$empty);
}
else{
//echo $group[$j]." = ";
array_push($user_ip,$value);
//echo $value;
}
//echo "<br/>";
break;
}
}
}
}
if(count($_SESSION['total-ip']) !== count($user_ip)){
array_push($user_ip,"NULL");
}
print_r($user_ip);
echo "<pre>";
$fname = "Forms/".$fname.".xlsx";
//echo $fname;
//($_SERVER);
//exit;
require 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx();
$spreadsheet = $reader->load($fname);
for($k=1;$k<=10;$k++){
$cellValue = $spreadsheet->getActiveSheet()->getCellByColumnAndRow(1, $k)->getValue();
if(empty($cellValue)){
$last = $k;
break;
}
//echo $cellValue;
}
//echo $last;
/*
for($i=0;$i<count($_SESSION['total-ip']);$i++){
$char = chr(65+$i);
$sheet->setCellValue($char.'1', $_SESSION['total-ip'][$i]);
}*/
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$sheet = $spreadsheet->getActiveSheet();
$spreadsheet->getActiveSheet()->getDefaultColumnDimension()->setWidth(30);
for($j=0;$j<count($user_ip);$j++){
$char = chr(65+$j);
$sheet->setCellValue($char.$last, $user_ip[$j]);
}
$writer->save($fname);
header('Location: '.$_SERVER['HTTP_REFERER']."?Status=Succesfully Sent Your Response");
/*
$writer = new Xlsx($spreadsheet);
$writer->save('hello world.xlsx');
$writer->save('hello world.xlsx');*/
?>