/
functions_output.php
172 lines (105 loc) · 4.01 KB
/
functions_output.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
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
<?php
include 'tablet/second_lvl_api.php';
/*
* This functions adopted to help output data from db
*/
//ERROR RAPORTING
function non_standard_and_non_active()
{
}
//FUNCTIONS FOR COLLECTION
//FUNTIONS for OUTPUT
function show_token_trace()
{
}
function insert_new_token_trace()
{
}
function draw_token_trace_edit()
{
echo "<table>";
echo "<tr>";
echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
//FOR ADDING NEW TOKEN TRACE
function constraint_categories($cat) //checks if category really exists in category tables. Cause we lost INNDB constraints by table denormalisation
{
}
function constraint_activation($act_tuple) //this will check if there is previous active token trace
{
//extract tuple
$all=$act_tuple[1];
$act=$act_tuple[0];
if($act==1)
return 1;
else if($act==0)
{
return 2;
}
else if($act==0 AND $all==0)
{
return 3;
}
else {
echo "F: Constraint activation: More than one active weight. System stopped. Call ADMIN";
die();
}
}
function check_activation($id_c)
{
//Two variables for stoting results for how many non-active and how many active
$non_active=0;
$active=0;
$all=0;
$sql="SELECT * FROM trace WHERE sub_cat_id_c='$id_c'";
$result=query_select($sql);
//we check if there are one or more id_c - one or more traces for collected one item sub type
$counter=0;
while($rek=mysql_fetch_array($result))
{
$counter++;
}
echo "all ".$all=$counter;
$counter=0;
$sql.=" AND active=1";
$result=query_select($sql);
while($rek=mysql_fetch_array($result))
{
$counter++;
}
echo " active: ".$active=$counter;
return array($active,$all); //returning a tuple with one item type size of active trace and all active and non active
}
//This for checkin trace active
//INSERT token trace
function insert_token_trace($date_started,$weight,$cat,$id_c) //transactions
{
mysql_query("START TRANSACTION");
$IA1="INSERT INTO token_dynamic(date_started,weight_spare,category_spare) VALUES('$date_started','$weight',$cat)";
$a1=mysql_query($IA1)or mysql_error();
$last_token= mysql_insert_id() ; //here we need a backup function to check or do the collecting of last recent inserted token
echo $last_token;
$IA2="INSERT INTO trace(sub_cat_id_c,token_dynamic_idtoken,active) VALUES('$id_c','$last_token','1')"; //we will be using only trace active to differentiate them
$a2=mysql_query($IA2) or mysql_error();
//$sa4="DELETE barcode FROM barcode JOIN item ON Barcode.Item_id_item = item.id_item WHERE Barcode = ''"
if($a1 AND $a2)
{
mysql_query("COMMIT");
}
else {
mysql_query("ROLLBACK");
}
}
function deactivate_trace($idtrace,$id_c) //No checking if redundancy.Risky. We leave this for the error detecting functions for running system
{
echo "ID_TRACE ".$idtrace;
$sql="UPDATE trace SET active=0 WHERE sub_cat_id_c='$id_c' AND idtrace='$idtrace' AND active=1";
$result=query_select($sql);
if($result)
echo "Deactivated";
else
echo "Failed to deatcivate";
}