5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010-2011, Franck Villaume - Capgemini
7 * Copyright 2014, Franck Villaume - TrivialDev
8 * http://fusionforge.org/
10 * This file is part of FusionForge. FusionForge is free software;
11 * you can redistribute it and/or modify it under the terms of the
12 * GNU General Public License as published by the Free Software
13 * Foundation; either version 2 of the Licence, or (at your option)
16 * FusionForge is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License along
22 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 // ################################## Trove Globals
28 $TROVE_MAXPERROOT = 3;
29 $TROVE_BROWSELIMIT = 20;
30 $TROVE_HARDQUERYLIMIT = -1;
32 // ##################################
35 * trove_genfullpaths() - Regenerates full path entries for $node and all subnodes
37 * @param int $mynode The node
38 * @param string $myfullpath The full path for this node
39 * @param int $myfullpathids The full path IDs
41 function trove_genfullpaths($mynode, $myfullpath, $myfullpathids) {
42 // first generate own path
43 db_query_params('UPDATE trove_cat SET fullpath=$1,fullpath_ids=$2 WHERE trove_cat_id=$3',
47 // now generate paths for all children by recursive call
49 $res_child = db_query_params('
50 SELECT trove_cat_id,fullname
53 AND trove_cat_id != 0',
56 while ($row_child = db_fetch_array($res_child)) {
57 trove_genfullpaths($row_child['trove_cat_id'],
58 $myfullpath . ' :: ' . $row_child['fullname'],
59 $myfullpathids.' :: '.$row_child['trove_cat_id']);
64 // ##################################
67 * trove_updaterootparent() - Regenerates full path entries for $node and all subnodes
69 * @param int $mynode The node
70 * @param int $rootnode The root parent node
72 function trove_updaterootparent($mynode, $rootnode) {
73 // first generate own path
74 if($mynode!=$rootnode) {
75 db_query_params('UPDATE trove_cat SET root_parent=$1 WHERE trove_cat_id=$2',
76 array ($rootnode, $mynode));
78 db_query_params('UPDATE trove_cat SET root_parent=0 WHERE trove_cat_id=$1',
81 // now generate paths for all children by recursive call
83 $res_child = db_query_params('
90 while ($row_child = db_fetch_array($res_child)) {
91 trove_updaterootparent($row_child['trove_cat_id'],$rootnode);
96 // #########################################
99 * trove_setnode() - Adds a group to a trove node
101 * @param int $group_id The group ID
102 * @param int $trove_cat_id The trove category ID
103 * @param int $rootnode The root node
106 function trove_setnode($group_id, $trove_cat_id, $rootnode=0) {
107 // verify we were passed information
108 if ((!$group_id) || (!$trove_cat_id)) {
111 // verify trove category exists
112 $res_verifycat = db_query_params('SELECT trove_cat_id,fullpath_ids
114 WHERE trove_cat_id=$1',
115 array ($trove_cat_id));
117 if (db_numrows($res_verifycat) != 1) {
120 $row_verifycat = db_fetch_array($res_verifycat);
122 // if we didnt get a rootnode, find it
124 $rootnode = trove_getrootcat($trove_cat_id);
127 // must first make sure that this is not a subnode of anything current
128 $res_topnodes = db_query_params('SELECT trove_cat.trove_cat_id AS trove_cat_id,
129 trove_cat.fullpath_ids AS fullpath_ids
130 FROM trove_cat,trove_group_link
131 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
132 AND trove_group_link.group_id=$1
133 AND trove_cat.root_parent=$2',
137 while($row_topnodes = db_fetch_array($res_topnodes)) {
138 $pathids = explode(' :: ',$row_topnodes['fullpath_ids']);
139 for ($i=0;$i<count($pathids);$i++) {
140 // anything here will invalidate this setnode
141 if ($pathids[$i] == $trove_cat_id) {
147 // need to see if this one is more specific than another
148 // if so, delete the other and proceed with this insertion
149 $subnodeids = explode(' :: ',$row_verifycat['fullpath_ids']);
150 $res_checksubs = db_query_params('SELECT trove_cat_id
151 FROM trove_group_link
153 AND trove_cat_root=$2',
157 while ($row_checksubs = db_fetch_array($res_checksubs)) {
158 // check against all subnodeids
159 for ($i=0;$i<count($subnodeids);$i++) {
160 if ($subnodeids[$i] == $row_checksubs['trove_cat_id']) {
161 // then delete subnode
162 db_query_params('DELETE FROM trove_group_link WHERE group_id=$1 AND trove_cat_id=$2',
169 // if we got this far, must be ok
170 db_query_params('INSERT INTO trove_group_link (trove_cat_id,trove_cat_version,group_id,trove_cat_root) VALUES ($1,$2,$3,$4)',
171 array ($trove_cat_id,
179 * trove_getrootcat() - Get the root categegory
181 * @param int $trove_cat_id Trove category ID
184 function trove_getrootcat($trove_cat_id) {
186 $current_cat = $trove_cat_id;
188 while ($parent > 0) {
189 $res_par = db_query_params('
192 WHERE trove_cat_id=$1',
193 array($current_cat));
195 $row_par = db_fetch_array($res_par);
196 $parent = $row_par["parent"];
200 $current_cat = $parent;
207 * trove_getallroots() - Returns an associative array of all project roots
209 function trove_getallroots() {
210 $res = db_query_params('
211 SELECT trove_cat_id,fullname
214 AND trove_cat_id!=0',
217 while ($row = db_fetch_array($res)) {
218 $tmpcatid = $row["trove_cat_id"];
219 $CATROOTS[$tmpcatid] = $row["fullname"];
225 * trove_catselectfull() - Returns full select output for a particular root
227 * @param int $node The node
228 * @param string $selected The category to pre-select
229 * @param string $name The select-box name
230 * @param string $title
232 function trove_catselectfull($node, $selected, $name, $title='') {
233 print '<br /><select class="trove-nodes" name="'.$name.'" title="'.util_html_secure($title).'">';
234 print ' <option value="0">'._('None Selected')."</option>\n";
235 $res_cat = db_query_params('
236 SELECT trove_cat_id,fullpath
242 while ($row_cat = db_fetch_array($res_cat)) {
243 print ' <option value="'.$row_cat['trove_cat_id'].'"';
244 if ($selected == $row_cat['trove_cat_id']) {
245 print (' selected="selected"');
247 print '>'.$row_cat['fullpath']."</option>\n";
253 * trove_getcatlisting() - Gets discriminator listing for a group
255 * @param int $group_id The group ID
256 * @param bool $a_filter Whether filters have already been applied
257 * @param bool $a_cats Whether to print category links
258 * @param int $a_complete
261 function trove_getcatlisting($group_id, $a_filter, $a_cats, $a_complete = 0) {
263 global $expl_discrim;
266 $res_trovecat = db_query_params('
267 SELECT trove_cat.fullpath AS fullpath,
268 trove_cat.fullpath_ids AS fullpath_ids,
269 trove_cat.trove_cat_id AS trove_cat_id
270 FROM trove_cat,trove_group_link
271 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
272 AND trove_group_link.group_id=$1
273 ORDER BY trove_cat.fullpath',
277 $need_close_ul_tag = 0;
278 if (db_numrows($res_trovecat) < 1) {
279 $return .= _('This project has not yet categorized itself in the').' '.
280 util_make_link('/softwaremap/trove_list.php',_('Trove Software Map'));
283 $need_close_ul_tag = true;
286 // first initialise the vars we're using here
287 $proj_discrim_used = array();
289 while ($row_trovecat = db_fetch_array($res_trovecat)) {
290 $folders = explode(" :: ",$row_trovecat['fullpath']);
291 $folders_ids = explode(" :: ",$row_trovecat['fullpath_ids']);
292 $folders_len = count($folders);
293 // if first in discrim print root category
294 if (!array_key_exists($folders_ids[0], $proj_discrim_used)) {
295 if (!$isfirstdiscrim) {
296 $return .= "</li>\n";
299 if ($a_complete == 0) {
300 $return .= $folders[0];
304 // filter links, to add discriminators
305 // first check to see if filter is already applied
306 $filterisalreadyapplied = 0;
307 if (is_array($expl_discrim)) { // in Widget_ProjectInfo class, $expl_discrim is null.
308 for ($i=0;$i < count($expl_discrim); $i++) {
309 if ($folders_ids[$folders_len-1] == $expl_discrim[$i]) {
310 $filterisalreadyapplied = 1;
314 // then print the stuff
315 if (! $a_complete == 0) {
316 if (array_key_exists($folders_ids[0], $proj_discrim_used)) {
317 $return .= '</li><li>';
324 for ($i=0;$i<$folders_len;$i++) {
326 $return .= util_make_link('/softwaremap/trove_list.php?cat=c&form_cat='.$folders_ids[$i].$discrim_url, $folders[$i]);
328 $return .= ($folders[$i]);
330 if ($i!=$folders_len-1) {
336 $return .= util_make_link('/softwaremap/trove_list.php?cat=c&form_cat='.$folders_ids[$folders_len-1].$discrim_url, $folders[$folders_len-1]);
338 $return .= ($folders[$folders_len-1]);
343 if ($filterisalreadyapplied) {
344 $return .= ' <strong>'._('(Now Filtering)').'</strong> ';
347 $extraurlparam = $discrim_url.','.$folders_ids[$folders_len-1];
349 $extraurlparam = '&discrim='.$folders_ids[$folders_len-1];
351 $return .= util_make_link('/softwaremap/trove_list.php?cat=c&form_cat='.$form_cat.$extraurlparam, _('[Filter]'));
354 $proj_discrim_used[$folders_ids[0]] = 1;
357 if ($need_close_ul_tag) {
358 $return .= '</li></ul>';
364 * trove_getfullname() - Returns cat fullname
366 * @param int $node The node
368 function trove_getfullname($node) {
369 $res = db_query_params('
372 WHERE trove_cat_id=$1',
374 $row = db_fetch_array($res);
375 return $row['fullname'];
379 * trove_getfullpath() - Returns a full path for a trove category
381 * @param int $node The node
384 function trove_getfullpath($node) {
389 while ($currentcat > 0) {
390 $res = db_query_params('
391 SELECT trove_cat_id,parent,fullname
393 WHERE trove_cat_id=$1',
395 $row = db_fetch_array($res);
396 $return = $row["fullname"] . ($first ? "" : " :: ") . $return;
397 $currentcat = $row["parent"];
404 * trove_del_cat_id() - Delete the selected node (and its sub-nodes) in the trove tree
406 * @param int $node The node
408 function trove_del_cat_id($node) {
409 $res=db_query_params('SELECT * FROM trove_cat WHERE parent=$1', array($node));
411 exit_error(sprintf(_('Error in Trove Operation: %s'), db_error()), 'home');
413 if (db_numrows($res)>0) {
414 for ($i=0; $i<db_numrows($res); $i++) {
415 trove_del_cat_id(db_result($res,$i,'trove_cat_id'));
418 $res=db_query_params('DELETE FROM trove_treesums WHERE trove_cat_id=$1', array($node));
420 exit_error(sprintf(_('Error in Trove Operation: %s'), db_error()),'home');
422 $res=db_query_params('DELETE FROM trove_group_link WHERE trove_cat_id=$1', array($node));
424 exit_error(sprintf(_('Error in Trove Operation: %s'), db_error()), 'home');
426 $res=db_query_params('DELETE FROM trove_agg WHERE trove_cat_id=$1', array($node));
428 exit_error(sprintf(_('Error in Trove Operation: %s'), db_error()), 'home');
430 $res=db_query_params('DELETE FROM trove_cat WHERE trove_cat_id=$1', array($node));
431 if (!$res || db_affected_rows($res)<1) {
432 exit_error(sprintf(_('Error in Trove Operation: %s'), db_error()), 'home');
438 // c-file-style: "bsd"