-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditcriteria.php
85 lines (81 loc) · 3.02 KB
/
editcriteria.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
<?php
function calcode($postvars)
{
foreach($postvars as $key=>$val)
{
$$key = $val;
}
$link = mysql_connect('localhost', 'wizard', 'g10gg') or die('could not connect to sql server');
mysql_select_db("wizard", $link);
$query = "select * from attributes";
$result = mysql_query($query, $link) or die("could not execute query $query");
$code = 0;
while ($row = mysql_fetch_array($result))
{
$aid = $row['attributeid'];
if (isset($$aid)) {$code += pow(2, $aid);}
}
return $code;
}
function calcode2($num)
{
$result = $num - pow(2, floor(log(2, $num)));
if ($result == 0)
{
$att[log(2, $num)] = log(2, $num);
}
else
{
$att = calcode2($result);
$att[floor(log(2, $num))] = floor(log(2, $num));
}
return $att;
}
if(empty($_POST['Submit']))
{
$link = mysql_connect('localhost', 'wizard', 'g10gg') or die('could not connect to sql server');
mysql_select_db("wizard", $link);
$query = "select * from licenses where licenseid = ".$_GET['lid'];
$result = mysql_query($query, $link) or die("could not execute query $query");
$row = mysql_fetch_array($result);
?>
<h3>Edit Criteria</h3>
<form name="data" method="post" action="editcriteria.php">
<h3>Please choose the attributes associated with this license from the following table:</h3>
<table align="center" border="0" cellpadding="0" cellspacing="0">
<tr><td align="left"><strong>Attributes</strong></td>
<td align="left"><strong>Check</strong></td>
<tr><td align="left"><hr size=1 align=left width=100% style='border: dotted;'></td></tr>
<?php
$atts = calcode2($row['licensecode']);
$query2 = "select * from attributes";
$result2 = mysql_query($query2, $link) or die("could not execute query $query2");
$g = 0;
while($row2 = mysql_fetch_array($result2))
{
$aid = $row2['attributeid']; ?>
<tr><td align="left" valign="bottom" width="550" bgcolor="<?php if ($g%2 == 0){ printf("#CCCCCC");} else {printf("#FFFFFF");}?>"><ul><li><?php printf($row2['attributetext']);?></li></ul></td><td align="center" valign="top" bgcolor="<?php if ($g%2 == 0){ printf("#CCCCCC");} else {printf("#FFFFFF");}?>"><input type="checkbox" name="<?php printf($aid);?>" value="1"
<?php if (!empty($atts[$aid])) {printf("checked");}?>></td>
</tr>
<?php $g++; }
?>
<tr>
<td align="center" colspan="2"><input type="submit" name="Submit" value="Submit">
</td></tr></table>
<input type="hidden" name="lid" value="<?php printf($_GET['lid']);?>">
</form>
<?php
}
else
{
$code = calcode($_POST);
$link = mysql_connect('localhost', 'wizard', 'g10gg') or die('could not connect to sql server');
mysql_select_db("wizard", $link);
$query = "update licenses set licensecode = ".$code." where licenseid = ".$_POST['lid'];
$result = mysql_query($query, $link) or die("could not execute query $query");
?>
<h3 align="center">Update successful!</h3>
<h3 align="center">Please click <a href="managewizard.php">here</a> to go back to the main menu</h3>
<?php
}
?>