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
| <?
/* Import libraries */
lib('auth');
lib('db');
/* Import variables we need in the script */
global $cOrder, $x, $rid;
/* Export variables we need for output */
global $list, $js, $catSelect;
/* Verify the user */
$A = new auth();
$A->verify();
/* Check if the user is allowed to be here */
$A->checkPerms(10);
/* Get db connection */
$D = $A->db;
/* Add category pop up */
$js .= "addPopup('category');\n";
$js .= "addPopupLine('category', 'details', '\"go(\'catDet.php?id=\"+v[0]+\"\')\"');\n";
if($A->checkPerms(12, true)) { // Edit a category
$js .= "addPopupLine('category', 'bewerk', '\"go(\'catEdit.php?id=\"+v[0]+\"\')\"');\n";
}
if(empty($rid) || $rid == 0) {
$js .= "addPopupLine('category', 'startpunt', '\"go(\'catList.php?rid=\"+v[0]+\"&cOrder=$cOrder&x=$x\')\"');\n";
} else {
$js .= "addPopupLine('category', 'hele lijst', '\"go(\'catList.php?cOrder=$cOrder&x=$x\')\"');\n";
}
if($A->checkPerms(11, true) || $A->checkPerms(16, true)) { // Add pro or cat
$js .= "addPopupLine('category', 'line');\n";
}
if($A->checkPerms(11, true)) { // Add a category
$js .= "addPopupLine('category', '+ subcategorie', '\"go(\'catAdd.php?pid=\"+v[0]+\"\')\"');\n";
}
if($A->checkPerms(16, true)) { // Add a product to the current category
$js .= "addPopupLine('category', '+ produkt', '\"go(\'prodAdd.php?cid=\"+v[0]+\"&exit=prodDet\')\"');\n";
}
if($A->checkPerms(14, true)) { // Move a category
$js .= "addPopupLine('category', 'line');\n";
$js .= "addPopupLine('category', 'verplaats', '\"Move(\"+v[0]+\")\"');\n";
}
if($A->checkPerms(13, true)) { // Delete a category
$js .= "addPopupLine('category', 'line');\n";
$js .= "addPopupLine('category', 'verwijder', '\"Delete(\"+v[0]+\",\'\"+v[1]+\"\')\"');\n";
}
/* Array containing all categories */
global $cats;
$cats = Array();
/* Code for sorting the table */
if(empty($cOrder)) $cOrder = "name";
if(strlen($x) < 1) $x = 1;
if($x == 0) { $cOrder .= " desc"; $x = 1; }
else $x = 0;
function getCat( $A, $cid, $spacing = 0) {
global $list, $row, $cats, $cOrder;
$db = $A->db;
/* Define row colors */
$color1 = "#efefef";
$color2 = "#ffffff";
/* Get category and child group data from database */
$category = $db->query("select * from prod_cat where id=$cid");
$thisCat = $db->fetch("a", $category);
$childCats = $db->query("select id, pid from prod_cat where pid=$cid order by $cOrder");
$numProds = $db->fetch("r", $db->query("select count(id) from prod_list where cid=$cid"));
/* Save some cat info to the array */
$cats[$cid] = $thisCat[name];
/* Display this category */
$icon = ($thisCat[visible])?'enabled.gif':'disabled.gif';
$color = ($row%2 > 0)?$color2:$color1;
$vis = 'visible';
$list .= "<tr id=\"row$row\" bgcolor='$color' style='visibility:$vis'>".
"<td align=center valign=top>".
"[img]'../../images/icons/$icon'[/img]</td>".
"<td>";
if($spacing > 0) {
if($spacing > 1) {
$list .= "<img src='../images/lines/blank.gif' align=absmiddle height=16 width=".
(($spacing-1) * 18).">";
}
$list .= "[img]'../../images/lines/joinbottom.gif'[/img]\n";
}
$list .= "<a href='#' class=listing title=\"$thisCat[description]\" ".
"onMouseDown=\"setCurrRow(this);drawPopup(event,'category',Array('$thisCat[id]','$thisCat[name]'))\">".
"<font size=2><b>$thisCat[name]</b></font></a>".
"</td>".
"<td align=center><span>$numProds[0]</span></td>".
"<td></td>".
"</tr>";
/* Increment row counter */
$row++;
/* Display it's child categories, if there are any */
while($child = $db->fetch("a", $childCats)) {
/* If so, recursively run this function */
getCat($A, $child[id], $spacing+1);
}
}
/* Keep track of the row number for bgColor setting */
global $row;
$row = 0;
/* Fetch all main parents, starting from $rid */
if(empty($rid)) {
$parents = $D->query("select id from prod_cat where pid<1 order by $cOrder");
while($parent = $D->fetch("a", $parents)) {
getCat($A, $parent[id]);
}
} else {
getCat($A, $rid);
}
/* Add some JS code for hiding the popup */
$js .= "document.onmousemove = popupTrackMouse";
/* Sort the cat list, and generate a selectbox options */
natcasesort($cats);
foreach(array_keys($cats) as $key) {
$catSelect .= "<option value='$key'>$cats[$key]\n";
}
?> |