-
Notifications
You must be signed in to change notification settings - Fork 0
/
clients.class.php
144 lines (130 loc) · 5.34 KB
/
clients.class.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
143
144
<?
class Clients
{
function __construct()
{
}
public function getClients($db,$page){
$offset=paginate($db,$page,"all");
$results = $db->getData("SELECT * FROM clients ORDER BY lastname ASC LIMIT $offset,10");
if($results){
$template = new Template;
$template->load("templates/client_list_all.php");
$template->replace("data", $results);
$template->publish();
}
}
public function searchClients($db,$word){
$results = $db->getData("SELECT * FROM clients WHERE ( lastname LIKE '%".$word."%' OR name LIKE '%".$word."%' OR phone LIKE '%".$word."%' ) ORDER BY lastname ASC");
if($results){
$template = new Template;
$template->load("templates/client_list_all.php");
$template->replace("data", $results);
$template->publish();
}
}
public function formAddClients(){
$template = new Template;
$template->load("templates/client_form_add.php");
$data=array(
'op'=>'adding',
'cid'=>'',
'name'=>'',
'lastname'=>'',
'yearborn'=>'',
'sex'=>'',
'address'=>'',
'phone'=>'',
'email'=>'',
'coloreyes'=>'',
'colorhair'=>'',
'skintype'=>'',
'other'=>''
);
$template->replace("data", $data);
$template->publish();
}
public function addClients($db,$name,$lastname,$yearborn,$sex,$address,$phone,$email,$coloreyes,$colorhair,$skintype,$other){
$result = $db->executeInstruction("
INSERT INTO `clients` (`name`, `lastname`, `yearborn`, `sex`, `address`, `phone`, `email`, `coloreyes`, `colorhair`, `skintype`, `other`, `dateadded`)
VALUES ('".$name."', '".$lastname."', '".$yearborn."', '".$sex."', '".$address."', '".$phone."', '".$email."', '".$coloreyes."', '".$colorhair."', '".$skintype."', '".$other."', '".date("Y-m-d")."');
");
$template = new Template;
$template->load("templates/alert_message.php");
if($result){
$data=array(
'type'=>'alert-success',
'message'=>'Datos de cliente insertados con éxito en la base de datos.'
);
}else{
$data=array(
'type'=>'alert-danger',
'message'=>'Error. No fue posible insertar los datos de cliente en la base de datos.'
);
}
$template->replace("data", $data);
$template->publish();
}
public function formEditClients($db,$id){
$result = $db->getDataSingle("SELECT * FROM `clients` WHERE `id` = '".$id."'");
if($result){
$template = new Template;
$template->load("templates/client_form_edit.php");
$result['op']='editing';
$template->replace("data", $result);
$template->publish();
}
}
public function editClients($db,$name,$lastname,$yearborn,$sex,$address,$phone,$email,$coloreyes,$colorhair,$skintype,$other,$cid){
$result = $db->executeInstruction("UPDATE `clients` SET `name`='".$name."', `lastname`='".$lastname."', `yearborn`='".$yearborn."', `sex`='".$sex."', `address`='".$address."', `phone`='".$phone."', `email`='".$email."', `coloreyes`='".$coloreyes."', `colorhair`='".$colorhair."', `skintype`='".$skintype."', `other`='".$other."' WHERE `id` = '".$cid."'");
if($result){
$template = new Template;
$template->load("templates/alert_message.php");
$data=array(
'type'=>'alert-success',
'message'=>'Datos de cliente modificados con éxito.<br><br> <a href=orders.php?op=view&cid='.sanitize($_POST['cid']).'&name='.sanitize($_POST['name']).'&lastname='.sanitize($_POST['lastname']).'><b>Volver a ficha de cliente</b></a>'
);
$template->replace("data", $data);
$template->publish();
}
}
public function uploadClients(){
$template = new Template;
$template->load("templates/client_form_edit.php");
$result['op']='uploading';
$template->replace("data", $result);
$template->publish();
}
public function formRemoveClients($cid,$name,$lastname) {
$template = new Template;
$template->load("templates/client_form_remove.php");
$data=array(
'op'=>'removing',
'cid'=>$cid,
'name'=>$name,
'lastname'=>$lastname
);
$template->replace("data", $data);
$template->publish();
}
public function removeClients($db,$cid) {
$result = $db->executeInstruction("DELETE FROM `clients` WHERE `id` = '".$cid."'");
$template = new Template;
$template->load("templates/alert_message.php");
if($result){
$data=array(
'type'=>'alert-success',
'message'=>'Datos de cliente eliminados con éxito.'
);
}
else{
$data=array(
'type'=>'alert-danger',
'message'=>'Error. No fue posible eliminar los datos de cliente.'
);
}
$template->replace("data", $data);
$template->publish();
}
}
?>