5 * SourceForge: Breaking Down the Barriers to Open Source Development
6 * Copyright 1999-2001 (c) VA Linux Systems
7 * http://sourceforge.net
12 // ################################## Trove Globals
14 $TROVE_MAXPERROOT = 3;
15 $TROVE_BROWSELIMIT = 20;
16 $TROVE_HARDQUERYLIMIT = -1;
18 // ##################################
21 * trove_genfullpaths() - Regenerates full path entries for $node and all subnodes
24 * @param string The full path for this node
25 * @param int The full path IDs
27 function trove_genfullpaths($mynode,$myfullpath,$myfullpathids) {
28 // first generate own path
29 $res_update = db_query('UPDATE trove_cat SET fullpath=\''
30 .$myfullpath.'\',fullpath_ids=\''
31 .$myfullpathids.'\' WHERE trove_cat_id='.$mynode);
32 // now generate paths for all children by recursive call
35 $res_child = db_query("
36 SELECT trove_cat_id,fullname
38 WHERE parent='$mynode'
40 ", -1, 0, SYS_DB_TROVE);
42 while ($row_child = db_fetch_array($res_child)) {
43 trove_genfullpaths($row_child['trove_cat_id'],
44 addslashes(quotemeta($myfullpath)) . ' :: ' . addslashes(quotemeta($row_child['fullname'])),
45 $myfullpathids.' :: '.$row_child['trove_cat_id']);
50 // ##################################
53 * trove_updaterootparent() - Regenerates full path entries for $node and all subnodes
56 * @param int The root parent node
58 function trove_updaterootparent($mynode,$rootnode) {
59 // first generate own path
60 if($mynode!=$rootnode) $res_update = db_query('UPDATE trove_cat SET root_parent=' .$rootnode. ' WHERE trove_cat_id='.$mynode);
61 else $res_update = db_query('UPDATE trove_cat SET root_parent=0 WHERE trove_cat_id='.$mynode);
62 // now generate paths for all children by recursive call
65 $res_child = db_query("
68 WHERE parent='$mynode'
70 ", -1, 0, SYS_DB_TROVE);
72 while ($row_child = db_fetch_array($res_child)) {
73 trove_updaterootparent($row_child['trove_cat_id'],$rootnode);
78 // #########################################
81 * trove_setnode() - Adds a group to a trove node
83 * @param int The group ID
84 * @param int The trove category ID
85 * @param int The root node
87 function trove_setnode($group_id,$trove_cat_id,$rootnode=0) {
88 // verify we were passed information
89 if ((!$group_id) || (!$trove_cat_id)) return 1;
91 // verify trove category exists
92 $res_verifycat = db_query("
93 SELECT trove_cat_id,fullpath_ids
95 WHERE trove_cat_id='$trove_cat_id'
96 ", -1, 0, SYS_DB_TROVE);
98 if (db_numrows($res_verifycat) != 1) return 1;
99 $row_verifycat = db_fetch_array($res_verifycat);
101 // if we didnt get a rootnode, find it
103 $rootnode = trove_getrootcat($trove_cat_id);
106 // must first make sure that this is not a subnode of anything current
107 $res_topnodes = db_query("
108 SELECT trove_cat.trove_cat_id AS trove_cat_id,
109 trove_cat.fullpath_ids AS fullpath_ids
110 FROM trove_cat,trove_group_link
111 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
112 AND trove_group_link.group_id='$group_id'
113 AND trove_cat.root_parent='$rootnode'");
115 while($row_topnodes = db_fetch_array($res_topnodes)) {
116 $pathids = explode(' :: ',$row_topnodes['fullpath_ids']);
117 for ($i=0;$i<count($pathids);$i++) {
118 // anything here will invalidate this setnode
119 if ($pathids[$i] == $trove_cat_id) {
125 // need to see if this one is more specific than another
126 // if so, delete the other and proceed with this insertion
127 $subnodeids = explode(' :: ',$row_verifycat['fullpath_ids']);
128 $res_checksubs = db_query("
130 FROM trove_group_link
131 WHERE group_id='$group_id'
132 AND trove_cat_root='$rootnode'");
134 while ($row_checksubs = db_fetch_array($res_checksubs)) {
135 // check against all subnodeids
136 for ($i=0;$i<count($subnodeids);$i++) {
137 if ($subnodeids[$i] == $row_checksubs['trove_cat_id']) {
138 // then delete subnode
139 db_query('DELETE FROM trove_group_link WHERE '
140 .'group_id='.$group_id.' AND trove_cat_id='
146 // if we got this far, must be ok
147 db_query('INSERT INTO trove_group_link (trove_cat_id,trove_cat_version,'
148 .'group_id,trove_cat_root) VALUES ('.$trove_cat_id.','
149 .time().','.$group_id.','.$rootnode.')');
154 * trove_getrootcat() - Get the root categegory
156 * @param int Trove category ID
158 function trove_getrootcat($trove_cat_id) {
160 $current_cat = $trove_cat_id;
162 while ($parent > 0) {
163 $res_par = db_query("
166 WHERE trove_cat_id='$current_cat'");
168 $row_par = db_fetch_array($res_par);
169 $parent = $row_par["parent"];
170 if ($parent == 0) return $current_cat;
171 $current_cat = $parent;
178 * trove_getallroots() - Returns an associative array of all project roots
180 function trove_getallroots() {
182 SELECT trove_cat_id,fullname
185 AND trove_cat_id!=0");
187 while ($row = db_fetch_array($res)) {
188 $tmpcatid = $row["trove_cat_id"];
189 $CATROOTS[$tmpcatid] = $row["fullname"];
195 * trove_catselectfull() - Returns full select output for a particular root
197 * @param int The node
198 * @param string The category to pre-select
199 * @param string THe select-box name
201 function trove_catselectfull($node,$selected,$name) {
202 print "<br /><select name=\"$name\">";
203 print ' <option value="0">'._('None Selected')."</option>\n";
204 $res_cat = db_query("
205 SELECT trove_cat_id,fullpath
207 WHERE root_parent='$node'
210 while ($row_cat = db_fetch_array($res_cat)) {
211 print ' <option value="'.$row_cat['trove_cat_id'].'"';
212 if ($selected == $row_cat['trove_cat_id']) print (' selected="selected"');
213 print '>'.$row_cat['fullpath']."</option>\n";
219 * trove_getcatlisting() - Gets discriminator listing for a group
221 * @param int The group ID
222 * @param bool Whether filters have already been applied
223 * @param bool Whether to print category links
225 function trove_getcatlisting($group_id,$a_filter,$a_cats) {
227 global $expl_discrim;
230 $res_trovecat = db_query("
231 SELECT trove_cat.fullpath AS fullpath,
232 trove_cat.fullpath_ids AS fullpath_ids,
233 trove_cat.trove_cat_id AS trove_cat_id
234 FROM trove_cat,trove_group_link
235 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
236 AND trove_group_link.group_id='$group_id'
237 ORDER BY trove_cat.fullpath");
240 $need_close_ul_tag = 0;
241 if (db_numrows($res_trovecat) < 1) {
242 $return .= _('This project has not yet categorized itself in the')
243 .util_make_link ('/softwaremap/trove_list.php',_('Trove Software Map'))
247 $need_close_ul_tag = 1;
250 // first initialise the vars we're using here
251 $proj_discrim_used=array();
253 while ($row_trovecat = db_fetch_array($res_trovecat)) {
254 $folders = explode(" :: ",$row_trovecat['fullpath']);
255 $folders_ids = explode(" :: ",$row_trovecat['fullpath_ids']);
256 $folders_len = count($folders);
257 // if first in discrim print root category
258 if (!array_key_exists($folders_ids[0], $proj_discrim_used)) {
259 if (!$isfirstdiscrim) {
260 $return .= "</li>\n";
262 $return .= ('<li> '.$folders[0].': ');
265 // filter links, to add discriminators
266 // first check to see if filter is already applied
267 $filterisalreadyapplied = 0;
268 for ($i=0;$i<sizeof($expl_discrim);$i++) {
269 if ($folders_ids[$folders_len-1] == $expl_discrim[$i]) {
270 $filterisalreadyapplied = 1;
273 // then print the stuff
274 if (array_key_exists($folders_ids[0], $proj_discrim_used)) {
279 $return .= '<a href="'
280 .util_make_url ('/softwaremap/trove_list.php?form_cat='.$folders_ids[$folders_len-1].$discrim_url).'">';
282 $return .= ($folders[$folders_len-1]);
288 if ($filterisalreadyapplied) {
289 $return .= ' <strong>'._('(Now Filtering)').'</strong> ';
291 $return .= ' <a href="'.util_make_url ('/softwaremap/trove_list.php?form_cat='.$form_cat);
293 $return .= $discrim_url.','.$folders_ids[$folders_len-1];
295 $return .= '&discrim='.$folders_ids[$folders_len-1];
297 $return .= '">'._('[Filter]').'</a> ';
300 $proj_discrim_used[$folders_ids[0]] = 1;
303 if ($need_close_ul_tag)
305 $return .= '</li></ul>';
311 * trove_getfullname() - Returns cat fullname
313 * @param int The node
315 function trove_getfullname($node) {
319 WHERE trove_cat_id='$node'");
320 $row = db_fetch_array($res);
321 return $row['fullname'];
325 * trove_getfullpath() - Returns a full path for a trove category
327 * @param int The node
329 function trove_getfullpath($node) {
334 while ($currentcat > 0) {
336 SELECT trove_cat_id,parent,fullname
338 WHERE trove_cat_id='$currentcat'");
339 $row = db_fetch_array($res);
340 $return = $row["fullname"] . ($first ? "" : " :: ") . $return;
341 $currentcat = $row["parent"];
349 // c-file-style: "bsd"