-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtotalTypes.php
More file actions
178 lines (166 loc) · 4.65 KB
/
totalTypes.php
File metadata and controls
178 lines (166 loc) · 4.65 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php ob_start(); require_once (__DIR__. '/scripts/config.php');?>
<html>
<head>
</head>
<body>
<div id="title">
<h1>Totalizers</h1>
</div>
<div id="search">
<?php $user->fillDropDown('Totals_Type'); ?>
</div>
<div id="records">
<div id="title">
<h1> Results</h1>
<hr/>
</div>
<?php
try
{
/* Update */
if(isset($_GET[ 'submit']))
{
$action=$_GET[ 'submit'];
if($action=='update' )
{
$user_id=$_SESSION[ 'user_session'];
$id=$_GET[ 'totalid'];
$desc=$_GET[ 'totalDesc'];
$sql="update Totals_Type set TotalTypeName='$desc', UpdateBy=$user_id where TotalTypeID=$id;";
$updateStm=$DB_con->prepare($sql);
$updateStm->execute();
}
//Delete
else if($action=='delete')
{
$user_id = $_SESSION['user_session'];
$id=$_GET['totalid'];
$desc=$_GET['totalDesc'];
$deleteDate=date("Y-m-d h:i:s");
//Copying Record to Delete Table
$sql="Insert into Totals_Type_Del VALUES($id,'$desc','$deleteDate',$user_id);";
$updateStm=$DB_con->prepare($sql);
$updateStm->execute();
//Deleting Record from Table
$sql="Delete From Totals_Type where TotalTypeID=$id";
$updateStm=$DB_con->prepare($sql);
$updateStm->execute();
}
//Insert New Record
else if($action=='insert')
{
$user_id = $_SESSION['user_session']; //this is the userid
$desc=$_GET['totalDesc']; //this it the description
$createDate=date("Y-m-d h:i:s"); //here i get the current datetime in format YY-MM-DD HH:mm:ss
$sql="Insert into Totals_Type VALUES(NULL,'$desc','$createDate',$user_id,'$createDate',$user_id);";
//On this insert sql statement i am not specifying the fields since i will update all of them
//NULL is the totaltypeid, $desc if the descrition, $createDate no problem
$updateStm=$DB_con->prepare($sql); $updateStm->execute();
}
else if($action=='search')
{
/*Output Result Page */
$option=$_GET['soption'];
$val=$_GET['searchVal'];
if($val=="")
{
$sql="Select * from Totals_Type;";
}
else
{
$sql="Select * from Totals_Type Where $option='$val';";
}
$querystmt=$DB_con->prepare($sql);
$querystmt->execute();
while($row=$querystmt->fetchObject())
{
echo " <b><a href='totalTypes.php?viewdetails={$row->TotalTypeID}'>{$row->TotalTypeID} {$row->TotalTypeName}</a></b></li>";
echo "<br/>";
}
}
}
/* Output Result Page */
$sql="Select * from Totals_Type;";
$querystmt=$DB_con->prepare($sql);
$querystmt->execute();
while($row=$querystmt->fetchObject())
{
if ($action != 'search')
{
echo " <b><a href='totalTypes.php?viewdetails={$row->TotalTypeID}'>{$row->TotalTypeID} {$row->TotalTypeName}</a></b></li>";
echo "<br/>";
}
}
}
catch(PDOException $ex)
{
$user->redirect('error.php',$ex->getMessage());
}
?>
</br>
<form>
 <button type='submit' type='submit' name='submit' value='new'>Add New</button>
</form>
</div>
<div id="details">
<div id="title">
<h1> Details</h1>
<hr/>
</div>
<?php
try
{
if(isset($_GET[ 'viewdetails']))
{
$id=$_GET[ 'viewdetails'];
$sql="Select * from Totals_Type Where TotalTypeID=$id" ;
$querystmt=$DB_con->prepare($sql);
$querystmt->execute();
$row=$querystmt->fetchObject();
echo "
<form>
 <label>Totalizer #: {$row->TotalTypeID}</label>
<input type='hidden' name='totalid' value='{$row->TotalTypeID}' />
<br/>
 <label>Name: </label>
<input type='text' name='totalDesc' value='{$row->TotalTypeName}' />
<br/>
 <label>Created on: {$row->CreatedOn}</label>
<br/>
 <label>Updated on: {$row->UpdateOn}</label>
<br/>
</br>
 <button type='submit' type='submit' name='submit' value='update'>Update</button>
<button type='submit' type='submit' name='submit' value='delete'>Delete</button>
<button type='button'>Cancel</button>
</form>";
}
if(isset($_GET['submit']))
{
$action=$_GET['submit'];
if($action=='new')
{
$date=date("m/d/Y");
echo "
<form>
 <label>Name: </label>
<input type='text' name='totalDesc' value='' />
<br/>
</br>
 <button type='submit' type='submit' name='submit' value='insert'>Insert</button>
</form>";
}
}
}
catch(PDOException $ex)
{
$user->redirect('error.php',$ex->getMessage());
}
?>
</div>
<?php $page_Content=ob_get_contents();
ob_end_clean();
$pagetitle="Totalizers" ;
include( "master.php"); ?>
</body>
</html>