-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.php
114 lines (105 loc) · 3.97 KB
/
home.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
<?php
/**
* home template
*/
include "views/header.php";
require_once 'classCat.php';
require_once 'classUtility.php';
require_once 'classValidation.php';
$newCat_class = new \Cat\Cat('12');//@todo remove need to pass in name
$approvedGenders = $newCat_class->setAllowedGenders();
$approvedColors = $newCat_class->setAllowedColorings();
$approvedMoods = $newCat_class->setApprovedMood();
$approvedHairLength = $newCat_class->checkIsHairLengthApproved();
$time = \Cat\Utility::getDateTime();
if (isset($_POST['create_cat'])) {
$newCatData[1] = $_POST['cat_name'];
$newCatData[2] = $_POST['cat_age'];
$newCatData[3] = $_POST['cat_weight'];
$newCatData[4] = $_POST['cat_gender'];
$newCatData[5] = $_POST['cat_color'];
$newCatData[6] = $_POST['cat_mood'];
$newCatData[7] = $_POST['cat_hair_length'];
$newCatData[8] = $_POST['cat_has_catitude'];
$newCatDatabaseRecord = [
'catName' => $_POST['cat_name'],
'age' => $_POST['cat_age'],
'gender' => $_POST['cat_gender'],
'createTime' => $time,
'updatedTime' => $time,
'coloring' => $_POST['cat_color'],
'hairLength' => $_POST['cat_hair_length'],
'currentMood' => $_POST['cat_mood'],
'weight' => $_POST['cat_weight'],
'hasCatittude' => '0'
];
new Validation($newCatDatabaseRecord);
}
$newCat_class->addCatRecord($newCatDatabaseRecord);
if (!empty($error_message)) : ?>
<div id="error"><p>Error: <?=$error_message?></p></div>
<?php endif; ?>
<h2 class="page_heading">Create Your New Cat</h2>
<form id="new_cat_form" name="cat_creation" method="post">
<div class="entry">
<label>Cat Name</label>
<input type="text" name="cat_name" value="<?=$newCatData[1]?>" maxlength="30" size="8" />
</div>
<div class="entry">
<label>Age</label>
<input type="number" name="cat_age" value="<?=$newCatData[2]?>" maxlength="30" size="8" />
</div>
<div class="entry">
<label>Weight</label>
<input type="number" name="cat_weight" value="<?=$newCatData[3]?>" maxlength="30" size="8" />
</div>
<div class="entry">
<label>Gender</label>
<select name="cat_gender">
<option value="Select A Gender">Select A Gender</option>
<?php foreach ($approvedGenders as $key => $val) :
$option = '<option value="'.$key.'"';
$option .= ($key == $newCatData[4]) ? ' selected' : '';
$option .= ">{$key}</option>";
echo $option;
endforeach; ?>
</select>
</div>
<div class="entry">
<label>Color</label>
<select name="cat_color">
<option value="Select A Color">Select A Color</option>
<?php foreach ($approvedColors as $key => $val) :
$option = '<option value="'.$key.'"';
$option .= ($key == $newCatData[5]) ? ' selected' : '';
$option .= ">{$key}</option>";
echo $option;
endforeach; ?>
</select>
</div>
<div class="entry">
<label>Current Mood</label>
<select name="cat_mood">
<option value="Select A Mood">Select A Mood</option>
<?php foreach ($approvedMoods as $key => $val) :
$option = '<option value="'.$key.'"';
$option .= ($key == $newCatData[6]) ? ' selected' : '';
$option .= ">{$key}</option>";
echo $option;
endforeach; ?>
</select>
</div>
<div class="entry">
<label>Hair Length</label>
<select name="cat_hair_length">
<option value="Select A Hair Length">Select A Hair Length</option>
<?php foreach ($approvedHairLength as $key => $val) :
echo "<option value='".$val."'>".$val."</option>";
endforeach; ?>
</select>
</div>
<div class="entry">
<input type="submit" value="Create Cat Now" id="submit" name="create_cat" />
</div>
</form>
<?php include "views/footer.php";?>