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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
<?php
/**
* Application functions. Dependent on lib/db.php!
* @package mirror
* @subpackage lib
* @todo add transactions once innodb table types are in place
*/
/**
* Get an alpha-list of regions for select list.
* @return array $regions
*/
function mirror_get_regions_select()
{
$regions = db_get("SELECT region_id,region_name FROM mirror_regions ORDER BY region_name ASC",MYSQL_ASSOC);
foreach ($regions as $region) {
$retval[$region['region_id']]=$region['region_name'];
}
return $retval;
}
/**
* Get an priority-list of regions for select list.
* @return array $regions
*/
function mirror_get_regions_select_priority()
{
$regions = db_get("SELECT region_id,region_name FROM mirror_regions ORDER BY region_priority ASC",MYSQL_ASSOC);
foreach ($regions as $region) {
$retval[$region['region_id']]=$region['region_name'];
}
return $retval;
}
/**
* Insert region.
* @param string $name
* @param int $priority
* @return bool
*/
function mirror_insert_region($name,$priority)
{
return db_query("INSERT INTO mirror_regions(region_name,region_priority) VALUES('{$name}',{$priority})");
}
/**
* Update region.
* @param int $id
* @param string $name
* @param int $priority
* @return bool
*/
function mirror_update_region($id,$name,$priority)
{
return db_query("UPDATE mirror_regions SET region_name='{$name}',region_priority={$priority} WHERE region_id={$id}");
}
/**
* Get one region.
* @param int $id
* @return array
*/
function mirror_get_one_region($id)
{
return db_get_one("SELECT * FROM mirror_regions WHERE region_id = {$id}");
}
/**
* Delete a region.
* @param int $id
* @return bool
*/
function mirror_delete_region($id)
{
return db_query("DELETE FROM mirror_regions WHERE region_id={$id}");
}
/**
* Get an alpha-list of mirrors for select list.
* @return array $mirrors
*/
function mirror_get_mirrors_select()
{
$mirrors = db_get("SELECT mirror_id,mirror_name FROM mirror_mirrors ORDER BY mirror_name ASC",MYSQL_ASSOC);
foreach ($mirrors as $mirror) {
$retval[$mirror['mirror_id']]=$mirror['mirror_name'];
}
return $retval;
}
/**
* Get regions.
* @return array
*/
function mirror_get_regions()
{
return db_get("
SELECT
mirror_regions.*,
COUNT(mirror_id) as mirrors
FROM
mirror_regions
LEFT JOIN
mirror_mirror_region_map
ON
mirror_regions.region_id = mirror_mirror_region_map.region_id
GROUP BY
mirror_regions.region_id
",MYSQL_ASSOC);
}
/**
* Insert mirror.
* @param string $name
* @param int $region_id
* @param string $baseurl
* @param int $rating
* @return bool
*/
function mirror_insert_mirror($name,$region_id,$baseurl,$rating)
{
return (db_query("INSERT INTO mirror_mirrors(mirror_name,mirror_baseurl,mirror_rating) VALUES('{$name}','{$baseurl}','{$rating}')") && db_query("INSERT INTO mirror_mirror_region_map(mirror_id,region_id) VALUES('".db_insert_id()."','$region_id')"))?true:false;
}
/**
* Update mirror.
* @param string $name
* @param int $region_id
* @param string $baseurl
* @param int $rating
* @return bool
*/
function mirror_update_mirror($id,$name,$region_id,$baseurl,$rating)
{
return (db_query("UPDATE mirror_mirrors SET mirror_name='{$name}',mirror_baseurl='{$baseurl}',mirror_rating='{$rating}' WHERE mirror_id={$id}") && db_query("UPDATE mirror_mirror_region_map SET region_id={$region_id} WHERE mirror_id={$id}"))?true:false;
}
/**
* Delete mirror.
* @return bool
*/
function mirror_delete_mirror($mirror_id)
{
return (db_query("DELETE FROM mirror_mirrors WHERE mirror_id={$mirror_id}")&&db_query("DELETE FROM mirror_mirror_region_map WHERE mirror_id={$mirror_id}"))?true:false;
}
/**
* Get one mirror record.
* @param int $mirror_id
* @return array mirror information
*/
function mirror_get_one_mirror($mirror_id)
{
return db_get_one("SELECT mirror_mirrors.*,region_id FROM mirror_mirrors,mirror_mirror_region_map WHERE mirror_mirrors.mirror_id={$mirror_id} AND mirror_mirrors.mirror_id=mirror_mirror_region_map.mirror_id");
}
/**
* Get list of mirrors.
* @return array
*/
function mirror_get_mirrors()
{
return db_get("
SELECT
mirror_mirrors.*,
IF(mirror_mirrors.mirror_active='0','DISABLED','ok') as mirror_active,
region_name
FROM
mirror_mirrors,
mirror_regions,
mirror_mirror_region_map
WHERE
mirror_regions.region_id = mirror_mirror_region_map.region_id AND
mirror_mirrors.mirror_id = mirror_mirror_region_map.mirror_id
",MYSQL_ASSOC);
}
/**
* Insert product.
* @param string $name
* @param int $priority
* @return bool
*/
function mirror_insert_product($name,$priority)
{
return db_query("INSERT INTO mirror_products(product_name,product_priority) VALUES('{$name}',{$priority})");
}
/**
* Update product.
* @param int $id
* @param string $name
* @param int $priority
* @return bool
*/
function mirror_update_product($id,$name,$priority)
{
return db_query("UPDATE mirror_products SET product_name='{$name}',product_priority={$priority} WHERE product_id={$id}");
}
/**
* Get one product.
* @param int $id
* @return array
*/
function mirror_get_one_product($id)
{
return db_get_one("SELECT * FROM mirror_products WHERE product_id = {$id}");
}
/**
* Delete a product.
* @param int $id
* @return bool
*/
function mirror_delete_product($id)
{
return db_query("DELETE FROM mirror_products WHERE product_id={$id}");
}
/**
* Get products.
* @return array
*/
function mirror_get_products()
{
return db_get("
SELECT
*
FROM
mirror_products
",MYSQL_ASSOC);
}
/**
* Insert os.
* @param string $name
* @param int $priority
* @return bool
*/
function mirror_insert_os($name,$priority)
{
return db_query("INSERT INTO mirror_os(os_name,os_priority) VALUES('{$name}',{$priority})");
}
/**
* Update os.
* @param int $id
* @param string $name
* @param int $priority
* @return bool
*/
function mirror_update_os($id,$name,$priority)
{
return db_query("UPDATE mirror_os SET os_name='{$name}',os_priority={$priority} WHERE os_id={$id}");
}
/**
* Get one os.
* @param int $id
* @return array
*/
function mirror_get_one_os($id)
{
return db_get_one("SELECT * FROM mirror_os WHERE os_id = {$id}");
}
/**
* Delete a os.
* @param int $id
* @return bool
*/
function mirror_delete_os($id)
{
return db_query("DELETE FROM mirror_os WHERE os_id={$id}");
}
/**
* Get operating systems.
* @return array
*/
function mirror_get_oss()
{
return db_get("
SELECT
*
FROM
mirror_os
",MYSQL_ASSOC);
}
/**
* Get an alpha-list of operating systems for select list.
* @return array $oss
*/
function mirror_get_oss_select()
{
$oss = db_get("SELECT os_id,os_name FROM mirror_os ORDER BY os_name ASC",MYSQL_ASSOC);
foreach ($oss as $os) {
$retval[$os['os_id']]=$os['os_name'];
}
return $retval;
}
/**
* Get an priority-list of operating systems for select list.
* @return array $oss
*/
function mirror_get_oss_select_priority()
{
$oss = db_get("SELECT os_id,os_name FROM mirror_os ORDER BY os_priority ASC",MYSQL_ASSOC);
foreach ($oss as $os) {
$retval[$os['os_id']]=$os['os_name'];
}
return $retval;
}
/**
* Get an alpha-list of products for select list.
* @return array $products
*/
function mirror_get_products_select()
{
$products = db_get("SELECT product_id,product_name FROM mirror_products ORDER BY product_name ASC",MYSQL_ASSOC);
foreach ($products as $product) {
$retval[$product['product_id']]=$product['product_name'];
}
return $retval;
}
/**
* Get an priority-list of operating systems for select list.
* @return array $oss
*/
function mirror_get_products_select_priority()
{
$products = db_get("SELECT product_id,product_name FROM mirror_products ORDER BY product_priority ASC",MYSQL_ASSOC);
foreach ($products as $product) {
$retval[$product['product_id']]=$product['product_name'];
}
return $retval;
}
/**
* Insert a new location.
* @param int $product
* @param int $os
* @param string $path
* @return bool
*/
function mirror_insert_location($product,$os,$path)
{
return db_query("INSERT INTO mirror_locations(product_id,os_id,location_path) VALUES({$product},{$os},'{$path}')");
}
/**
* Update a location.
* @param int $location
* @param int $product
* @param int $os
* @param string $path
* @return bool
*/
function mirror_update_location($location,$product,$os,$path)
{
return db_query("UPDATE mirror_locations SET product_id={$product},os_id={$os},location_path='{$path}' WHERE location_id={$location}");
}
/**
* Delete a location.
* @param int $id
* @return bool
*/
function mirror_delete_location($id)
{
return db_query("DELETE FROM mirror_locations WHERE location_id={$id}");
}
/**
* Get locations.
* @return array $locations array containing all location information.
*/
function mirror_get_locations()
{
return db_get("
SELECT
location_id,
product_name,
os_name,
location_path
FROM
mirror_locations,
mirror_products,
mirror_os
WHERE
mirror_locations.product_id = mirror_products.product_id AND
mirror_locations.os_id = mirror_os.os_id
");
}
/**
* Get one location.
* @param int $id
* @return array
*/
function mirror_get_one_location($id)
{
return db_get_one("SELECT * FROM mirror_locations WHERE location_id = {$id}");
}
/**
* Insert a new user.
* @param string $username
* @param string $password
* @param string $rpassword (re-entered password)
* @param string $firstname
* @param string $lastname
* @param string $email
* @return bool
*/
function mirror_insert_user($username,$password,$rpassword,$firstname,$lastname,$email)
{
if ($password==$rpassword) {
return db_query("INSERT INTO mirror_users(username,password,user_firstname,user_lastname,user_email) VALUES('{$username}',MD5('{$password}'),'{$firstname}','{$lastname}','{$email}')");
} else {
set_error('User could not be added because passwords did not match.');
}
}
/**
* Update a user.
* @param int $user
* @param string $username
* @param string $password
* @param string $rpassword (re-entered password)
* @param string $firstname
* @param string $lastname
* @param string $email
* @return bool
*/
function mirror_update_user($user,$username,$password,$rpassword,$firstname,$lastname,$email)
{
$query = ($password==$rpassword&&!empty($password))?"UPDATE mirror_users SET username='{$username}',password=MD5('{$password}'),user_firstname='{$firstname}',user_lastname='{$lastname}',user_email='{$email}' WHERE user_id={$user}":"UPDATE mirror_users SET username='{$username}',user_firstname='{$firstname}',user_lastname='{$lastname}',user_email='{$email}' WHERE user_id={$user}";
return db_query($query);
}
/**
* Delete a user.
* @param int $id
* @return bool
*/
function mirror_delete_user($id)
{
return db_query("DELETE FROM mirror_users WHERE user_id={$id}");
}
/**
* Get users.
* @return array $users array containing all user information.
*/
function mirror_get_users()
{
return db_get("SELECT * FROM mirror_users");
}
/**
* Get one user.
* @param int $id
* @return array
*/
function mirror_get_one_user($id)
{
return db_get_one("SELECT * FROM mirror_users WHERE user_id = {$id}");
}
/**
* Enable or disable a mirror.
* @param int $mirror
* @return bool
*/
function mirror_toggle($mirror)
{
return (db_toggle_bool('mirror_mirrors','mirror_id','mirror_active',$mirror))?true:false;
}
/**
* Get mirror statistics.
* @return array $stats
*/
function mirror_get_mirror_stats()
{
return db_get("
SELECT
*,
COUNT(mirror_log.mirror_id) as count
FROM
mirror_mirrors,
mirror_log,
mirror_regions,
mirror_mirror_region_map
WHERE
mirror_log.mirror_id = mirror_mirrors.mirror_id AND
mirror_mirrors.mirror_id = mirror_mirror_region_map.mirror_id AND
mirror_regions.region_id = mirror_mirror_region_map.region_id
GROUP BY
mirror_log.mirror_id
");
}
/**
* Get product statistics.
* @return array $stats
*/
function mirror_get_product_stats()
{
return db_get("
SELECT
*,
COUNT(mirror_locations.product_id) as count
FROM
mirror_log,
mirror_locations,
mirror_products
WHERE
mirror_log.location_id = mirror_locations.location_id AND
mirror_locations.product_id = mirror_products.product_id
GROUP BY
mirror_locations.product_id
");
}
?>
|