Line 9... |
Line 9... |
9 |
include_once('reports.php');
|
9 |
include_once('reports.php');
|
10 |
|
10 |
|
11 |
define (SQL_SHOW_LICENSE,
|
11 |
define (SQL_SHOW_LICENSE,
|
12 |
"select
|
12 |
"select
|
13 |
client.name 'Client',
|
13 |
client.name 'Client',
|
14 |
concat('<a href=\"index.html?action=edit&license_id=',license.license_id,'\">', license.license,'</a>') 'License',
|
14 |
concat('<a href=\"edit.html?action=edit&license_id=',license.license_id,'\">', license.license,'</a>') 'License',
|
15 |
device.name 'Installed On',
|
15 |
device.name 'Installed On',
|
16 |
license_product.name 'Product',
|
16 |
license_product.name 'Product',
|
17 |
license.added_date 'Installed',
|
17 |
license.added_date 'Installed',
|
- |
|
18 |
license.removed_date 'Removed',
|
18 |
concat('<a href=\"index.html?action=move&license_id=',license.license_id,'\">', 'Move','</a>') 'Action'
|
19 |
concat('<a href=\"index.html?action=move&license_id=',license.license_id,'\">', 'Move','</a>') 'Action'
|
19 |
from
|
20 |
from
|
20 |
license join license_product using (license_product_id)
|
21 |
license join license_product using (license_product_id)
|
21 |
left outer join device using (device_id)
|
22 |
left outer join device using (device_id)
|
22 |
join client using ( client_id )
|
23 |
join client using ( client_id )
|
Line 29... |
Line 30... |
29 |
);
|
30 |
);
|
30 |
|
31 |
|
31 |
define (SQL_SHOW_LICENSE_HISTORY,
|
32 |
define (SQL_SHOW_LICENSE_HISTORY,
|
32 |
"select
|
33 |
"select
|
33 |
client.name 'Client',
|
34 |
client.name 'Client',
|
34 |
concat('<a href=\"index.html?license_id=',license.license_id,'\">', license.license,'</a>') 'License',
|
35 |
concat('<a href=\"edit.html?license_id=',license.license_id,'\">', license.license,'</a>') 'License',
|
35 |
device.name 'Installed On',
|
36 |
device.name 'Installed On',
|
36 |
license_product.name 'Product',
|
37 |
license_product.name 'Product',
|
37 |
license.added_date 'Installed',
|
38 |
license.added_date 'Installed',
|
38 |
license.removed_date 'Removed'
|
39 |
license.removed_date 'Removed'
|
39 |
from
|
40 |
from
|
Line 58... |
Line 59... |
58 |
* Othewise, Adds key and assigns to machine
|
59 |
* Othewise, Adds key and assigns to machine
|
59 |
* returns "Added"
|
60 |
* returns "Added"
|
60 |
* NOTE: $device_id may be null which indicates license owned by client but unassigned
|
61 |
* NOTE: $device_id may be null which indicates license owned by client but unassigned
|
61 |
*/
|
62 |
*/
|
62 |
function updateLicense ( $client_id, $device_id, $license_product_id, $license ) {
|
63 |
function updateLicense ( $client_id, $device_id, $license_product_id, $license ) {
|
- |
|
64 |
/*$client_id = makeSafeSQLValue( $client_id );
|
- |
|
65 |
$device_id = makeSafeSQLValue( $device_id );
|
- |
|
66 |
$license_product_id = makeSafeSQLValue( $license_product_id );
|
- |
|
67 |
$license = makeSafeSQLValue( $license );
|
- |
|
68 |
*/
|
63 |
// see if the entry already exists
|
69 |
// see if the entry already exists
|
64 |
$results = queryDatabaseExtended( "select license_id,client_id,device_id from license where license_product_id = $license_product_id and license = '$license' and removed_date is null" );
|
70 |
$results = queryDatabaseExtended( "select * from license where license_product_id = $license_product_id and license = '$license' and removed_date is null" );
|
65 |
//print "<pre>"; print_r( $results ); print "</pre>"; die;
|
71 |
//print "<pre>"; print_r( $results ); print "</pre>"; die;
|
66 |
$db_license_id = $results['data'][0]['license_id'];
|
72 |
$db_license_id = $results['data'][0]['license_id'];
|
67 |
$db_client_id = $results['data'][0]['client_id'];
|
73 |
$db_client_id = $results['data'][0]['client_id'];
|
68 |
$db_device_id = $results['data'][0]['device_id'];
|
74 |
$db_device_id = $results['data'][0]['device_id'];
|
69 |
// SQL does not understand an empty string, so we replace it with the keyword null for queries
|
75 |
// SQL does not understand an empty string, so we replace it with the keyword null for queries
|
70 |
$queryDeviceID = $device_id ? $device_id : 'null';
|
76 |
$queryDeviceID = $device_id ? $device_id : 'null';
|
71 |
if ( ! $results ) { # this was not found, so just add it
|
77 |
if ( ! $results ) { # this was not found, so just add it
|
72 |
doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date) values ( $client_id, $queryDeviceID, $license_product_id, '$license', now() )" );
|
78 |
doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date, removed_date) values ( $client_id, $queryDeviceID, $license_product_id, '$license', $now(), null )" );
|
73 |
return "Added";
|
79 |
return "Added";
|
74 |
}
|
80 |
}
|
75 |
if ( $client_id == $db_client_id && $device_id == $db_device_id or $db_device_id ) { // already done, so just leave alone
|
81 |
if ( $client_id == $db_client_id && $device_id == $db_device_id or $db_device_id ) { // already done, so just leave alone
|
76 |
return "Already Set";
|
82 |
return "Already Set";
|
77 |
}
|
83 |
}
|
Line 79... |
Line 85... |
79 |
doSQL( "update license set device_id = $queryDeviceID,added_date = now() where license_id = $db_license_id" );
|
85 |
doSQL( "update license set device_id = $queryDeviceID,added_date = now() where license_id = $db_license_id" );
|
80 |
return "Assigned";
|
86 |
return "Assigned";
|
81 |
}
|
87 |
}
|
82 |
// at this point, there is already an entry, but it is for a different machine, so we need to update it, ie remove the old, add the new
|
88 |
// at this point, there is already an entry, but it is for a different machine, so we need to update it, ie remove the old, add the new
|
83 |
doSQL( "update license set removed_date = now() where license_id = $db_license_id" );
|
89 |
doSQL( "update license set removed_date = now() where license_id = $db_license_id" );
|
84 |
doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date) values ( $client_id, $queryDeviceID, $license_product_id, '$license', now() )" );
|
90 |
doSQL( "insert into license (client_id,device_id,license_product_id,license, added_date, removed_date) values ( $client_id, $queryDeviceID, $license_product_id, '$license', $added_date, $removed_date )" );
|
85 |
return "Reassigned";
|
91 |
return "Reassigned";
|
86 |
}
|
92 |
}
|
87 |
|
93 |
|
- |
|
94 |
/*
|
- |
|
95 |
* Simply overwrites a license record. Only used for the edit.html page
|
- |
|
96 |
*/
|
- |
|
97 |
|
- |
|
98 |
function overwriteLicense ( $license_id,$client_id, $device_id, $license_product_id, $license, $added_date, $removed_date ) {
|
- |
|
99 |
$added_date = makeSafeSQLConstant( $added_date, 'D', 'now()' );
|
- |
|
100 |
$removed_date = makeSafeSQLConstant( $removed_date, 'D', 'null' );
|
- |
|
101 |
$device_id = $device_id == '-1' ? 'null' : makeSafeSQLConstant( $device_id, 'I', 'null' );
|
- |
|
102 |
doSQL( "update license set
|
- |
|
103 |
client_id=$client_id,
|
- |
|
104 |
device_id=$device_id,
|
- |
|
105 |
license_product_id=$license_product_id,
|
- |
|
106 |
license='$license',
|
- |
|
107 |
added_date=$added_date,
|
- |
|
108 |
removed_date=$removed_date
|
- |
|
109 |
where license_id=$license_id");
|
- |
|
110 |
} // overwriteLicense
|
- |
|
111 |
|
- |
|
112 |
|
- |
|
113 |
/*
|
- |
|
114 |
* function will attempt to make a constant ($value) safe for SQL depending on the type.
|
- |
|
115 |
*
|
- |
|
116 |
* if $value is empty, $default is returned, as will happen if any of the
|
- |
|
117 |
* conversions (date, datetime, etc...) fail.
|
- |
|
118 |
*
|
- |
|
119 |
* First, it will pass it through get_magic_quotes_gpc,
|
- |
|
120 |
* then will run through mysql_real_escape_string
|
- |
|
121 |
*
|
- |
|
122 |
* For strings, will encapsulate in quotes
|
- |
|
123 |
* Dates will attempt a conversion, then change to YYYY-MM-DD and encapsulate in quotes
|
- |
|
124 |
* DateTime will perform the same, but change to YYYY-MM-DD HH:MM:SS
|
- |
|
125 |
* Integer and Floats are passed through builtins intval and floatval
|
- |
|
126 |
* Boolean only checks the first character, a '0', 'f' and 'n' denoting false
|
- |
|
127 |
* all else denoting true. The result is converted based on the variable
|
- |
|
128 |
* $falsetrue, with the first char denoting false and the second denoting true
|
- |
|
129 |
*/
|
- |
|
130 |
function makeSafeSQLConstant ( $value, $type='S', $default='null', $falsetrue='10' ) {
|
- |
|
131 |
if (strlen($value) == 0) // simply set any empty values to null
|
- |
|
132 |
return $default;
|
- |
|
133 |
if ( get_magic_quotes_gpc() )
|
- |
|
134 |
$value = stripslashes($value);
|
- |
|
135 |
$value = mysql_real_escape_string( $value );
|
- |
|
136 |
|
- |
|
137 |
switch ( strtolower( $type ) ) {
|
- |
|
138 |
case 'string' :
|
- |
|
139 |
case 's' : $value = strlen( $value ) > 0 ? "'$value'" : $default;
|
- |
|
140 |
break;
|
- |
|
141 |
case 'date' :
|
- |
|
142 |
case 'd' : if ( $result = strtotime( $value ) ) {
|
- |
|
143 |
$value = Date( 'Y-m-d', $result);
|
- |
|
144 |
} else {
|
- |
|
145 |
$value = $default;
|
- |
|
146 |
}
|
- |
|
147 |
if ( $value != $default ) $value = "'$value'";
|
- |
|
148 |
break;
|
- |
|
149 |
case 'datetime':
|
- |
|
150 |
case 'timestamp':
|
- |
|
151 |
case 'dt': if ( $result = strtotime( $value ) ) {
|
- |
|
152 |
$value = Date( 'Y-m-d H:i:s', $result);
|
- |
|
153 |
} else {
|
- |
|
154 |
$value = $default;
|
- |
|
155 |
}
|
- |
|
156 |
if ( $value != $default ) $value = "'$value'";
|
- |
|
157 |
break;
|
- |
|
158 |
case 'integer':
|
- |
|
159 |
case 'i' : $value = intval( $value );
|
- |
|
160 |
break;
|
- |
|
161 |
case 'float':
|
- |
|
162 |
case 'f' : $value = floatval( $value );
|
- |
|
163 |
break;
|
- |
|
164 |
case 'bool':
|
- |
|
165 |
case 'boolean':
|
- |
|
166 |
case 'b' : // note, because of the way strpos works, you can not
|
- |
|
167 |
// simply set $value based on the output; you MUST do
|
- |
|
168 |
// as below; specifically check for false, then set the result
|
- |
|
169 |
$value = strpos( '0fn', strtolower(substr( $value, 0, 1 )) ) === false ? 0 : 1;
|
- |
|
170 |
$value = substr( $falsetrue, $value, 0, 1 );
|
- |
|
171 |
break;
|
- |
|
172 |
} // switch
|
- |
|
173 |
return $value;
|
- |
|
174 |
}
|
- |
|
175 |
|
88 |
/*
|
176 |
/*
|
89 |
* select $column from $table where $match = '$value'
|
177 |
* select $column from $table where $match = '$value'
|
90 |
* if $add is true, will add row if it does not exist.
|
178 |
* if $add is true, will add row if it does not exist.
|
91 |
* returns $column from the result (or '' if it does not exist)
|
179 |
* returns $column from the result (or '' if it does not exist)
|
92 |
* Used mainly to get an index from a table with matching value
|
180 |
* Used mainly to get an index from a table with matching value
|
93 |
*/
|
181 |
*/
|
94 |
|
182 |
|
95 |
function getValue ( $table, $column, $match, $value, $add = false ) {
|
183 |
function getValue ( $table, $column, $match, $value, $add = false ) {
|
- |
|
184 |
$value = makeSafeSQLValue( $value );
|
96 |
$return = getOneDBValue( "select $column from $table where $match = '$value'" );
|
185 |
$return = getOneDBValue( "select $column from $table where $match = $value" );
|
97 |
if ( $return === null ) {
|
186 |
if ( $return === null ) {
|
98 |
if ( $add ) {
|
187 |
if ( $add ) {
|
99 |
$return = doSQL( "insert into $table ( $match ) values ( '$value' )" );
|
188 |
$return = doSQL( "insert into $table ( $match ) values ( $value )" );
|
100 |
return $return['insert_id'];
|
189 |
return $return['insert_id'];
|
101 |
} else {
|
190 |
} else {
|
102 |
$return = '';
|
191 |
$return = '';
|
103 |
} // if..else
|
192 |
} // if..else
|
104 |
} // if
|
193 |
} // if
|
105 |
return $return;
|
194 |
return $return;
|
106 |
} // function getValue
|
195 |
} // function getValue
|
107 |
|
196 |
|
108 |
function getDescription( $license_id ) {
|
197 |
function getDescription( $license_id ) {
|
- |
|
198 |
//$license_id = makeSafeSQLValue( $license_id );
|
109 |
$result = queryDatabaseExtended(
|
199 |
$result = queryDatabaseExtended(
|
110 |
"select
|
200 |
"select
|
111 |
license_product.name 'Product',
|
201 |
license_product.name 'Product',
|
112 |
license.license 'License',
|
202 |
license.license 'License',
|
113 |
device.name 'Machine',
|
203 |
device.name 'Machine',
|
Line 129... |
Line 219... |
129 |
} else {
|
219 |
} else {
|
130 |
return "No License found for license_id $license_id";
|
220 |
return "No License found for license_id $license_id";
|
131 |
}
|
221 |
}
|
132 |
} // function getDescription
|
222 |
} // function getDescription
|
133 |
|
223 |
|
- |
|
224 |
/*
|
- |
|
225 |
* Moves a license from one machine to another (either can be null)
|
- |
|
226 |
* by setting removed_date in the origin, then duplicating that record
|
- |
|
227 |
* to a new one
|
- |
|
228 |
*/
|
- |
|
229 |
|
- |
|
230 |
function moveLicense( $license_id, $machine_id = '' ) {
|
- |
|
231 |
$machine_id = makeSafeSQLValue( $machine_id );
|
- |
|
232 |
//$license_id = makeSafeSQLValue( $license_id );
|
- |
|
233 |
doSQL(
|
- |
|
234 |
"insert into license
|
- |
|
235 |
( client_id, device_id,license,license_product_id,added_date,removed_date )
|
- |
|
236 |
select client_id, $machine_id,license,license_product_id,now(),null
|
- |
|
237 |
from license
|
- |
|
238 |
where license_id = $license_id" );
|
- |
|
239 |
doSQL( "update license set removed_date = now() where license_id = $license_id" );
|
- |
|
240 |
} // function moveLicense
|
- |
|
241 |
|
- |
|
242 |
/*
|
- |
|
243 |
* This was stolen from doAdmin in the library.php file. That library can not
|
- |
|
244 |
* be easily touched as too many other things depend on it, so I simply grabbed the
|
- |
|
245 |
* code, modified it, and put it here.
|
- |
|
246 |
* Does a very basic edit of table $tablename, based on its definition stored in
|
- |
|
247 |
* $DATABASE_DEFINITION
|
- |
|
248 |
*/
|
- |
|
249 |
function EditTable( $tablename, $allowRemove = false ) {
|
- |
|
250 |
global $DATABASE_DEFINITION;
|
- |
|
251 |
$currentDB = $tablename;
|
- |
|
252 |
$dbDisplayName = $DATABASE_DEFINITION[$currentDB]['display name'] ? $DATABASE_DEFINITION[$currentDB]['display name'] : $currentDB;
|
- |
|
253 |
// load our two global parameters, check for get, then post
|
- |
|
254 |
$id = $_REQUEST['id'];
|
- |
|
255 |
$mode = $_REQUEST['mode'];
|
- |
|
256 |
$mode = escapeshellcmd( $mode );
|
- |
|
257 |
$id = escapeshellcmd( $id );
|
- |
|
258 |
|
- |
|
259 |
if ( $mode=="add") {
|
- |
|
260 |
Print '<h2>Add $dbDisplayName</h2>';
|
- |
|
261 |
print addData( $DATABASE_DEFINITION[$currentDB] );
|
- |
|
262 |
}
|
- |
|
263 |
|
- |
|
264 |
if ( $mode=="added")
|
- |
|
265 |
{
|
- |
|
266 |
print insertData( $DATABASE_DEFINITION[$currentDB] );
|
- |
|
267 |
print "<p>Record Added</p>";
|
- |
|
268 |
}
|
- |
|
269 |
if ( $mode=="edit")
|
- |
|
270 |
{
|
- |
|
271 |
print "<h2>Edit $dbDisplayName</h2>";
|
- |
|
272 |
print editData( $DATABASE_DEFINITION[$currentDB], $id );
|
- |
|
273 |
}
|
- |
|
274 |
|
- |
|
275 |
if ( $mode=="edited") {
|
- |
|
276 |
updateData( $DATABASE_DEFINITION[$currentDB], $id );
|
- |
|
277 |
Print "<p>$currentDB Updated!</p>p>";
|
- |
|
278 |
}
|
- |
|
279 |
if ( $mode=="remove") {
|
- |
|
280 |
if ( $allowRemove ) {
|
- |
|
281 |
print deleteData( $DATABASE_DEFINITION[$currentDB], $id );
|
- |
|
282 |
Print "$currentDB has been removed <p>";
|
- |
|
283 |
} else {
|
- |
|
284 |
print "<p>Error, no deletions allowed here</p>";
|
- |
|
285 |
}
|
- |
|
286 |
}
|
- |
|
287 |
Print "<h2>$dbDisplayName</h2><p>";
|
- |
|
288 |
|
- |
|
289 |
print makeList( $currentDB, $DATABASE_DEFINITION[$currentDB]['display query'], $DATABASE_DEFINITION[$currentDB]['display columns'], $DATABASE_DEFINITION[$currentDB]['key field'] );
|
- |
|
290 |
}
|
- |
|
291 |
|
- |
|
292 |
|
134 |
?>
|
293 |
?>
|