-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit.php
142 lines (129 loc) · 5.01 KB
/
edit.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
137
138
139
140
141
142
<?php
/**
* edit template
*/
include "views/header.php";
require_once 'classCat.php';
require_once 'classUtility.php';
require_once 'classValidation.php';
$newCat_class = new \Cat\Cat();
$approvedGenders = $newCat_class->setAllowedGenders();
$approvedColors = $newCat_class->setAllowedColorings();
$approvedMoods = $newCat_class->setApprovedMood();
$approvedHairLength = $newCat_class->checkIsHairLengthApproved();
$time = \Cat\Utility::getDateTime();
/*
* have function inside cat class called fromID
* so cat = Cat::fromID
* inside ID pass in id i am editing
*
* now we have cat object
* now we can hve function o update, Cat::uipdate(pass in post array).
*
* have another function called catSave --- updates/inserts cat in DB
* dsim - fromID, save functions -0 look how they work
*/
//get id of record from url
$catId = $_GET['id'];
$currentCatData = $newCat_class->getSingleCatByID($catId);
//var_dump($currentCatData);
//$ourCat = [];
$ourCat = \Cat\Cat::fromID($catId);
//echo 'object cat data:<p></p>';
//var_dump($ourCat);
//echo '<p></p>';
//echo '<p></p>';
$existing_cat_data = [];
if (isset($_POST['update_cat'])) {
$existingCatDatabaseRecord = [
'catName' => $_POST['cat_name'],
'age' => $_POST['cat_age'],
'gender' => $_POST['cat_gender'],
'updatedTime' => $time,
'coloring' => $_POST['cat_color'],
'hairLength' => $_POST['cat_hair_length'],
'currentMood' => $_POST['cat_mood'],
'weight' => $_POST['cat_weight'],
'hasCatittude' => $_POST['cat_has_catitude'],
];
new Validation($existingCatDatabaseRecord);
}
$newCat_class->editCatRecord($existingCatDatabaseRecord, $catId);
if (!empty($error_message)) : ?>
<div id="error"><p>Error: <?=$error_message?></p></div>
<?php endif; ?>
<h2 class="page_heading">Edit <?=$ourCat->catName?> 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="<?=$ourCat->catName?>" maxlength="30" size="8" />
</div>
<div class="entry">
<label>Age</label>
<input type="number" name="cat_age" value="<?=$ourCat->age?>" maxlength="30" size="8" />
</div>
<div class="entry">
<label>Weight</label>
<input type="number" name="cat_weight" value="<?=$ourCat->weight?>" 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 == $ourCat->gender) ? ' 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 == $ourCat->coloring) ? ' 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 == $ourCat->currentMood) ? ' 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) :
$option = '<option value="'.$val.'"';
$option .= ($val == $ourCat->hairLength) ? ' selected' : '';
$option .= ">{$val}</option>";
echo $option;
endforeach; ?>
</select>
</div>
<div class="entry">
<label>Does Cat Have Catitude?</label>
<select name="cat_has_catitude">
<option value="Select Yay or Nay">Select Yay or Nay</option>
<option value="0">Nope</option>
<option value="1">Yass</option>
</select>
</div>
<div class="entry">
<input type="submit" value="Update This Cat" id="submit" name="update_cat" />
</div>
</form>
<?php include "views/footer.php";?>