5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010-2011, Franck Villaume - Capgemini
7 * http://fusionforge.org/
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 // ################################## Trove Globals
27 $TROVE_MAXPERROOT = 3;
28 $TROVE_BROWSELIMIT = 20;
29 $TROVE_HARDQUERYLIMIT = -1;
31 // ##################################
34 * trove_genfullpaths() - Regenerates full path entries for $node and all subnodes
37 * @param string The full path for this node
38 * @param int The full path IDs
40 function trove_genfullpaths($mynode,$myfullpath,$myfullpathids) {
41 // first generate own path
42 $res_update = db_query_params ('UPDATE trove_cat SET fullpath=$1,fullpath_ids=$2 WHERE trove_cat_id=$3',
46 // 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
70 * @param int The root parent node
72 function trove_updaterootparent($mynode,$rootnode) {
73 // first generate own path
74 if($mynode!=$rootnode) $res_update = db_query_params ('UPDATE trove_cat SET root_parent=$1 WHERE trove_cat_id=$2',
77 else $res_update = db_query_params ('UPDATE trove_cat SET root_parent=0 WHERE trove_cat_id=$1',
79 // now generate paths for all children by recursive call
82 $res_child = db_query_params ('
89 while ($row_child = db_fetch_array($res_child)) {
90 trove_updaterootparent($row_child['trove_cat_id'],$rootnode);
95 // #########################################
98 * trove_setnode() - Adds a group to a trove node
100 * @param int The group ID
101 * @param int The trove category ID
102 * @param int The root node
104 function trove_setnode($group_id,$trove_cat_id,$rootnode=0) {
105 // verify we were passed information
106 if ((!$group_id) || (!$trove_cat_id)) return 1;
108 // verify trove category exists
109 $res_verifycat = db_query_params ('
110 SELECT trove_cat_id,fullpath_ids
112 WHERE trove_cat_id=$1',
113 array ($trove_cat_id));
115 if (db_numrows($res_verifycat) != 1) return 1;
116 $row_verifycat = db_fetch_array($res_verifycat);
118 // if we didnt get a rootnode, find it
120 $rootnode = trove_getrootcat($trove_cat_id);
123 // must first make sure that this is not a subnode of anything current
124 $res_topnodes = db_query_params ('
125 SELECT trove_cat.trove_cat_id AS trove_cat_id,
126 trove_cat.fullpath_ids AS fullpath_ids
127 FROM trove_cat,trove_group_link
128 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
129 AND trove_group_link.group_id=$1
130 AND trove_cat.root_parent=$2',
134 while($row_topnodes = db_fetch_array($res_topnodes)) {
135 $pathids = explode(' :: ',$row_topnodes['fullpath_ids']);
136 for ($i=0;$i<count($pathids);$i++) {
137 // anything here will invalidate this setnode
138 if ($pathids[$i] == $trove_cat_id) {
144 // need to see if this one is more specific than another
145 // if so, delete the other and proceed with this insertion
146 $subnodeids = explode(' :: ',$row_verifycat['fullpath_ids']);
147 $res_checksubs = db_query_params ('
149 FROM trove_group_link
151 AND trove_cat_root=$2',
155 while ($row_checksubs = db_fetch_array($res_checksubs)) {
156 // check against all subnodeids
157 for ($i=0;$i<count($subnodeids);$i++) {
158 if ($subnodeids[$i] == $row_checksubs['trove_cat_id']) {
159 // then delete subnode
160 db_query_params ('DELETE FROM trove_group_link WHERE group_id=$1 AND trove_cat_id=$2',
167 // if we got this far, must be ok
168 db_query_params ('INSERT INTO trove_group_link (trove_cat_id,trove_cat_version,group_id,trove_cat_root) VALUES ($1,$2,$3,$4)',
169 array ($trove_cat_id,
177 * trove_getrootcat() - Get the root categegory
179 * @param int Trove category ID
181 function trove_getrootcat($trove_cat_id) {
183 $current_cat = $trove_cat_id;
185 while ($parent > 0) {
186 $res_par = db_query_params ('
189 WHERE trove_cat_id=$1',
190 array($current_cat));
192 $row_par = db_fetch_array($res_par);
193 $parent = $row_par["parent"];
194 if ($parent == 0) return $current_cat;
195 $current_cat = $parent;
202 * trove_getallroots() - Returns an associative array of all project roots
204 function trove_getallroots() {
205 $res = db_query_params ('
206 SELECT trove_cat_id,fullname
209 AND trove_cat_id!=0',
212 while ($row = db_fetch_array($res)) {
213 $tmpcatid = $row["trove_cat_id"];
214 $CATROOTS[$tmpcatid] = $row["fullname"];
220 * trove_catselectfull() - Returns full select output for a particular root
222 * @param int The node
223 * @param string The category to pre-select
224 * @param string THe select-box name
226 function trove_catselectfull($node, $selected, $name, $title='') {
227 print '<br /><select class="trove-nodes" name="'.$name.'" title="'.util_html_secure($title).'">';
228 print ' <option value="0">'._('None Selected')."</option>\n";
229 $res_cat = db_query_params('
230 SELECT trove_cat_id,fullpath
236 while ($row_cat = db_fetch_array($res_cat)) {
237 print ' <option value="'.$row_cat['trove_cat_id'].'"';
238 if ($selected == $row_cat['trove_cat_id']) print (' selected="selected"');
239 print '>'.$row_cat['fullpath']."</option>\n";
245 * trove_getcatlisting() - Gets discriminator listing for a group
247 * @param int The group ID
248 * @param bool Whether filters have already been applied
249 * @param bool Whether to print category links
252 function trove_getcatlisting($group_id,$a_filter,$a_cats,$a_complete=0) {
254 global $expl_discrim;
257 $res_trovecat = db_query_params ('
258 SELECT trove_cat.fullpath AS fullpath,
259 trove_cat.fullpath_ids AS fullpath_ids,
260 trove_cat.trove_cat_id AS trove_cat_id
261 FROM trove_cat,trove_group_link
262 WHERE trove_cat.trove_cat_id=trove_group_link.trove_cat_id
263 AND trove_group_link.group_id=$1
264 ORDER BY trove_cat.fullpath',
268 $need_close_ul_tag = 0;
269 if (db_numrows($res_trovecat) < 1) {
270 $return .= _('This project has not yet categorized itself in the').' '
271 .util_make_link ('/softwaremap/trove_list.php',_('Trove Software Map'))
275 $need_close_ul_tag = 1;
278 // first initialise the vars we're using here
279 $proj_discrim_used=array();
281 while ($row_trovecat = db_fetch_array($res_trovecat)) {
282 $folders = explode(" :: ",$row_trovecat['fullpath']);
283 $folders_ids = explode(" :: ",$row_trovecat['fullpath_ids']);
284 $folders_len = count($folders);
285 // if first in discrim print root category
286 if (!array_key_exists($folders_ids[0], $proj_discrim_used)) {
287 if (!$isfirstdiscrim) {
288 $return .= "</li>\n";
291 if ($a_complete==0) {
292 $return .= $folders[0].' : ';
296 // filter links, to add discriminators
297 // first check to see if filter is already applied
298 $filterisalreadyapplied = 0;
299 for ($i=0;$i<sizeof($expl_discrim);$i++) {
300 if ($folders_ids[$folders_len-1] == $expl_discrim[$i]) {
301 $filterisalreadyapplied = 1;
304 // then print the stuff
305 if (array_key_exists($folders_ids[0], $proj_discrim_used)) {
306 $return .= '</li><li>';
310 for ($i=0;$i<$folders_len;$i++) {
312 $return .= '<a href="'.util_make_url ('/softwaremap/trove_list.php?cat=c&form_cat='.$folders_ids[$i].$discrim_url).'">';
314 $return .= ($folders[$i]);
318 if ($i!=$folders_len-1) {
324 $return .= '<a href="'.util_make_url ('/softwaremap/trove_list.php?cat=c&form_cat='.$folders_ids[$folders_len-1].$discrim_url).'">';
326 $return .= ($folders[$folders_len-1]);
330 if ($i!=$folders_len-1) {
336 if ($filterisalreadyapplied) {
337 $return .= ' <strong>'._('(Now Filtering)').'</strong> ';
339 $return .= ' <a href="'.util_make_url ('/softwaremap/trove_list.php?cat=c&form_cat='.$form_cat);
341 $return .= $discrim_url.','.$folders_ids[$folders_len-1];
343 $return .= '&discrim='.$folders_ids[$folders_len-1];
345 $return .= '">'._('[Filter]').'</a> ';
348 $proj_discrim_used[$folders_ids[0]] = 1;
351 if ($need_close_ul_tag)
353 $return .= '</li></ul>';
359 * trove_getfullname() - Returns cat fullname
361 * @param int The node
363 function trove_getfullname($node) {
364 $res = db_query_params ('
367 WHERE trove_cat_id=$1',
369 $row = db_fetch_array($res);
370 return $row['fullname'];
374 * trove_getfullpath() - Returns a full path for a trove category
376 * @param int The node
378 function trove_getfullpath($node) {
383 while ($currentcat > 0) {
384 $res = db_query_params ('
385 SELECT trove_cat_id,parent,fullname
387 WHERE trove_cat_id=$1',
389 $row = db_fetch_array($res);
390 $return = $row["fullname"] . ($first ? "" : " :: ") . $return;
391 $currentcat = $row["parent"];
398 * trove_del_cat_id() - Delete the selected node (and its sub-nodes) in the trove tree
400 * @param int The node
402 function trove_del_cat_id($node) {
403 $res=db_query_params ('SELECT * FROM trove_cat WHERE parent=$1',
406 exit_error(sprintf(_('Error In Trove Operation : %s'),db_error()),'home');
408 if (db_numrows($res)>0) {
409 for ($i=0; $i<db_numrows($res); $i++) {
410 trove_del_cat_id(db_result($res,$i,'trove_cat_id'));
413 $res=db_query_params ('DELETE FROM trove_treesums WHERE trove_cat_id=$1',
416 exit_error(sprintf(_('Error In Trove Operation : %s'),db_error()),'home');
418 $res=db_query_params ('DELETE FROM trove_group_link WHERE trove_cat_id=$1',
421 exit_error(sprintf(_('Error In Trove Operation : %s'),db_error()),'home');
423 $res=db_query_params ('DELETE FROM trove_agg WHERE trove_cat_id=$1',
426 exit_error(sprintf(_('Error In Trove Operation : %s'),db_error()),'home');
428 $res=db_query_params ('DELETE FROM trove_cat WHERE trove_cat_id=$1',
430 if (!$res || db_affected_rows($res)<1) {
431 exit_error(sprintf(_('Error In Trove Operation : %s'),db_error()),'home');
435 function trove_html_limit_navigation_box($php_self, $querytotalcount, $trove_browselimit, $page) {
437 $html_limit = sprintf(_(' Displaying %1$s per page. Projects sorted by alphabetical order.'), $trove_browselimit).'<br/>';
439 // display all the numbers
440 for ($i=1;$i<=ceil($querytotalcount/$trove_browselimit);$i++) {
443 $html_limit .= '<a href="'.$php_self;
444 $html_limit .= '?page='.$i;
446 } else $html_limit .= '<strong>';
447 $html_limit .= '<'.$i.'>';
449 $html_limit .= '</a>';
450 } else $html_limit .= '</strong>';
459 // c-file-style: "bsd"