5 * Copyright 1999-2001 (c) VA Linux Systems
6 * http://fusionforge.org/
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 // ################################## Trove Globals
26 $TROVE_MAXPERROOT = 3;
27 $TROVE_BROWSELIMIT = 20;
28 $TROVE_HARDQUERYLIMIT = -1;
30 // ##################################
33 * trove_genfullpaths() - Regenerates full path entries for $node and all subnodes
36 * @param string The full path for this node
37 * @param int The full path IDs
39 function trove_genfullpaths($mynode,$myfullpath,$myfullpathids) {
40 // first generate own path
41 $res_update = db_query_params("UPDATE trove_cat SET fullpath=$1,
43 WHERE trove_cat_id=$3", array($myfullpath, $myfullpathids, $mynode));
44 // now generate paths for all children by recursive call
47 $res_child = db_query_params("
48 SELECT trove_cat_id,fullname
51 AND trove_cat_id!=0;", array($mynode), -1, 0, 'SYS_DB_TROVE');
53 while ($row_child = db_fetch_array($res_child)) {
54 trove_genfullpaths($row_child['trove_cat_id'],
55 addslashes(quotemeta($myfullpath)) . ' :: ' . addslashes(quotemeta($row_child['fullname'])),
56 $myfullpathids.' :: '.$row_child['trove_cat_id']);
61 // ##################################
64 * trove_updaterootparent() - Regenerates full path entries for $node and all subnodes
67 * @param int The root parent node
69 function trove_updaterootparent($mynode,$rootnode) {
70 // first generate own path
71 if($mynode!=$rootnode) $res_update = db_query_params("UPDATE trove_cat SET root_parent=$1 WHERE trove_cat_id=$2", array($rootnode, $mynode));
72 else $res_update = db_query_params("UPDATE trove_cat SET root_parent=0 WHERE trove_cat_id=$1", array($mynode));
73 // now generate paths for all children by recursive call
76 $res_child = db_query_params("
80 AND trove_cat_id!=0;", array($mynode), -1, 0, 'SYS_DB_TROVE');
82 while ($row_child = db_fetch_array($res_child)) {
83 trove_updaterootparent($row_child['trove_cat_id'],$rootnode);
88 // #########################################
91 * trove_setnode() - Adds a group to a trove node
93 * @param int The group ID
94 * @param int The trove category ID
95 * @param int The root node
97 function trove_setnode($group_id,$trove_cat_id,$rootnode=0) {
98 // verify we were passed information
99 if ((!$group_id) || (!$trove_cat_id)) return 1;
101 // verify trove category exists
102 $res_verifycat = db_query_params("
103 SELECT trove_cat_id,fullpath_ids
105 WHERE trove_cat_id=$1", array($trove_cat_id), -1, 0, 'SYS_DB_TROVE');
107 if (db_numrows($res_verifycat) != 1) return 1;
108 $row_verifycat = db_fetch_array($res_verifycat);
110 // if we didnt get a rootnode, find it
112 $rootnode = trove_getrootcat($trove_cat_id);
115 // must first make sure that this is not a subnode of anything current
116 $res_topnodes = db_query_params("
117 SELECT trove_cat.trove_cat_id AS trove_cat_id,
118 trove_cat.fullpath_ids AS fullpath_ids
119 FROM trove_cat,trove_group_link
120 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
121 AND trove_group_link.group_id=$1
122 AND trove_cat.root_parent=$2", array($group_id, $rootnode));
124 while($row_topnodes = db_fetch_array($res_topnodes)) {
125 $pathids = explode(' :: ',$row_topnodes['fullpath_ids']);
126 for ($i=0;$i<count($pathids);$i++) {
127 // anything here will invalidate this setnode
128 if ($pathids[$i] == $trove_cat_id) {
134 // need to see if this one is more specific than another
135 // if so, delete the other and proceed with this insertion
136 $subnodeids = explode(' :: ',$row_verifycat['fullpath_ids']);
137 $res_checksubs = db_query_params ('
139 FROM trove_group_link
141 AND trove_cat_root=$2',
145 while ($row_checksubs = db_fetch_array($res_checksubs)) {
146 // check against all subnodeids
147 for ($i=0;$i<count($subnodeids);$i++) {
148 if ($subnodeids[$i] == $row_checksubs['trove_cat_id']) {
149 // then delete subnode
150 db_query_params("DELETE FROM trove_group_link WHERE
151 group_id=$1 AND trove_cat_id=$2",
152 array($group_id, $subnodeids[$i]));
157 // if we got this far, must be ok
158 db_query_params("INSERT INTO trove_group_link (trove_cat_id,trove_cat_version,
159 group_id,trove_cat_root) VALUES ($1, $2, $3, $4)",
160 array($trove_cat_id, time(), $group_id, $rootnode));
165 * trove_getrootcat() - Get the root categegory
167 * @param int Trove category ID
170 function trove_getrootcat($trove_cat_id) {
172 $current_cat = $trove_cat_id;
174 while ($parent > 0) {
175 $res_par = db_query_params ('
178 WHERE trove_cat_id=$1',
179 array($current_cat));
181 $row_par = db_fetch_array($res_par);
182 $parent = $row_par["parent"];
183 if ($parent == 0) return $current_cat;
184 $current_cat = $parent;
191 * trove_getallroots() - Returns an associative array of all project roots
193 function trove_getallroots() {
194 $res = db_query_params ('
195 SELECT trove_cat_id,fullname
198 AND trove_cat_id!=0',
201 while ($row = db_fetch_array($res)) {
202 $tmpcatid = $row["trove_cat_id"];
203 $CATROOTS[$tmpcatid] = $row["fullname"];
209 * trove_catselectfull() - Returns full select output for a particular root
211 * @param int The node
212 * @param string The category to pre-select
213 * @param string THe select-box name
215 function trove_catselectfull($node,$selected,$name) {
216 print "<br /><select name=\"$name\">";
217 print ' <option value="0">None Selected'."</option>\n";
218 $res_cat = db_query_params ('
219 SELECT trove_cat_id,fullpath
225 while ($row_cat = db_fetch_array($res_cat)) {
226 print ' <option value="'.$row_cat['trove_cat_id'].'"';
227 if ($selected == $row_cat['trove_cat_id']) print (' selected="selected"');
228 print '>'.$row_cat['fullpath']."</option>\n";
234 * trove_getcatlisting() - Gets discriminator listing for a group
236 * @param int The group ID
237 * @param bool Whether filters have already been applied
238 * @param bool Whether to print category links
241 function trove_getcatlisting($group_id,$a_filter,$a_cats) {
243 global $expl_discrim;
246 $res_trovecat = db_query_params ('
247 SELECT trove_cat.fullpath AS fullpath,
248 trove_cat.fullpath_ids AS fullpath_ids,
249 trove_cat.trove_cat_id AS trove_cat_id
250 FROM trove_cat,trove_group_link
251 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
252 AND trove_group_link.group_id=$1
253 ORDER BY trove_cat.fullpath',
257 if (db_numrows($res_trovecat) < 1) {
258 $return .= '<p>' . sprintf (_('This project has not yet categorized itself in the <a href="%s">Trove Software Map</a>.'), util_make_url ('/softwaremap/trove_list.php'))
262 $need_close_ul_tag = 1;
265 // first unset the vars were using here
266 $proj_discrim_used='';
268 while ($row_trovecat = db_fetch_array($res_trovecat)) {
269 $folders = explode(" :: ",$row_trovecat['fullpath']);
270 $folders_ids = explode(" :: ",$row_trovecat['fullpath_ids']);
271 $folders_len = count($folders);
272 // if first in discrim print root category
273 if (!$proj_discrim_used[$folders_ids[0]]) {
274 if (!$isfirstdiscrim) {
275 $return .= "</li>\n";
277 $return .= ('<li> '.$folders[0].': ');
280 // filter links, to add discriminators
281 // first check to see if filter is already applied
282 $filterisalreadyapplied = 0;
283 for ($i=0;$i<sizeof($expl_discrim);$i++) {
284 if ($folders_ids[$folders_len-1] == $expl_discrim[$i]) {
285 $filterisalreadyapplied = 1;
288 // then print the stuff
289 if ($proj_discrim_used[$folders_ids[0]]) {
294 $return .= util_make_link ('/softwaremap/trove_list.php?form_cat='.$folders_ids[$folders_len-1].$discrim_url,
295 $folders[$folders_len-1]) ;
297 $return .= ($folders[$folders_len-1]);
301 if ($filterisalreadyapplied) {
302 $return .= ' <strong>'. _('(Now Filtering)') .'</strong> ';
304 $tmp_url = '/softwaremap/trove_list.php?form_cat='.$form_cat ;
306 $tmp_url .= $discrim_url.','.$folders_ids[$folders_len-1];
308 $tmp_url .= '&discrim='.$folders_ids[$folders_len-1];
310 $return .= util_make_link ($tmp_url,
311 _('[Filter]')) . ' ' ;
314 $proj_discrim_used[$folders_ids[0]] = 1;
317 if ($need_close_ul_tag)
319 $return .= '</li></ul>';
325 * trove_getfullname() - Returns cat fullname
327 * @param int The node
329 function trove_getfullname($node) {
330 $res = db_query_params ('
333 WHERE trove_cat_id=$1',
335 $row = db_fetch_array($res);
336 return $row['fullname'];
340 * trove_getfullpath() - Returns a full path for a trove category
342 * @param int The node
344 function trove_getfullpath($node) {
349 while ($currentcat > 0) {
350 $res = db_query_params ('
351 SELECT trove_cat_id,parent,fullname
353 WHERE trove_cat_id=$1',
355 $row = db_fetch_array($res);
356 $return = $row["fullname"] . ($first ? "" : " :: ") . $return;
357 $currentcat = $row["parent"];