5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010 (c) FusionForge Team
8 * This file is part of FusionForge.
10 * FusionForge is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published
12 * by the Free Software Foundation; either version 2 of the License,
13 * or (at your option) any later version.
15 * FusionForge is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with FusionForge; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 * html_feedback_top() - Show the feedback output at the top of the page.
29 * @param string The feedback.
31 function html_feedback_top($feedback) {
33 echo $HTML->feedback($feedback);
37 * html_warning_top() - Show the warning output at the top of the page.
39 * @param string The warning message.
41 function html_warning_top($msg) {
43 echo $HTML->warning_msg($msg);
47 * html_error_top() - Show the error output at the top of the page.
49 * @param string The error message.
51 function html_error_top($msg) {
53 echo $HTML->error_msg($msg);
57 * make_user_link() - Make a username reference into a link to that users User page on SF.
59 * @param string The username of the user to link.
61 function make_user_link($username,$displayname='') {
62 if (empty($displayname))
63 $displayname = $username;
65 if (!strcasecmp($username,'Nobody') || !strcasecmp($username,'None')) {
68 return '<a href="/users/'.$username.'">'.$displayname.'</a>' ;
73 * html_feedback_top() - Show the feedback output at the bottom of the page.
75 * @param string The feedback.
77 function html_feedback_bottom($feedback) {
79 echo $HTML->feedback($feedback);
83 * html_blankimage() - Show the blank spacer image.
85 * @param int The height of the image
86 * @param int The width of the image
88 function html_blankimage($height,$width) {
89 return '<img src="/images/blank.png" width="' . $width . '" height="' . $height . '" alt="" />';
93 * html_abs_image() - Show an image given an absolute URL.
96 * @param int width of the image
97 * @param int height of the image
98 * @param array Any <img> tag parameters (i.e. 'border', 'alt', etc...)
100 function html_abs_image($url, $width, $height, $args) {
101 $return = ('<img src="' . $url . '"');
103 while(list($k,$v) = each($args)) {
104 $return .= ' '.$k.'="'.$v.'"';
107 if (!isset($args['alt'])) {
108 $return .= ' alt=""';
111 // ## add image dimensions
112 $return .= " width=\"" . $width . "\"";
113 $return .= " height=\"" . $height . "\"";
120 * html_image() - Build an image tag of an image contained in $src
122 * @param string The source location of the image
123 * @param int The width of the image
124 * @param int The height of the image
125 * @param array Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
126 * @param bool DEPRECATED
128 function html_image($src,$width='',$height='',$args=array(),$display=1) {
130 $s = ((session_issecure()) ? forge_get_config('images_secure_url') : forge_get_config('images_url') );
131 return html_abs_image($s.$HTML->imgroot.$src, $width, $height, $args);
135 * html_get_language_popup() - Pop up box of supported languages.
137 * @param string The title of the popup box.
138 * @param string Which element of the box is to be selected.
139 * @return string The html select box.
141 function html_get_language_popup ($title='language_id',$selected='xzxz') {
142 $res = db_query_params ('SELECT * FROM supported_languages ORDER BY name ASC',
144 return html_build_select_box ($res,$title,$selected,false);
148 * html_get_theme_popup() - Pop up box of supported themes.
150 * @param string The title of the popup box.
151 * @param string Which element of the box is to be selected.
152 * @return string The html select box.
154 function html_get_theme_popup ($title='theme_id',$selected='xzxz') {
155 $res=db_query_params ('SELECT theme_id, fullname FROM themes WHERE enabled=true',
157 $nbTheme = db_numrows($res);
162 return html_build_select_box($res,$title,$selected,false);
167 * html_get_ccode_popup() - Pop up box of supported country_codes.
169 * @param string The title of the popup box.
170 * @param string Which element of the box is to be selected.
171 * @return string The html select box.
173 function html_get_ccode_popup ($title='ccode',$selected='xzxz') {
174 $res=db_query_params ('SELECT ccode,country_name FROM country_code ORDER BY country_name',
176 return html_build_select_box ($res,$title,$selected,false);
180 * html_get_timezone_popup() - Pop up box of supported Timezones.
181 * Assumes you have included Timezones array file.
183 * @param string The title of the popup box.
184 * @param string Which element of the box is to be selected.
185 * @return string The html select box.
187 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
189 if ($selected == 'xzxzxzx') {
190 $r = file ('/etc/timezone');
191 $selected = str_replace ("\n", '', $r[0]);
193 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
198 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
200 * @param array An array of items to use.
201 * @param string The name you want assigned to this form element.
202 * @param string The value of the item that should be checked.
203 * @param boolean Whether we should swap the keys / names.
204 * @param bool Whether or not to show the '100 row'.
205 * @param string What to call the '100 row' defaults to none.
207 function html_build_select_box_from_assoc ($arr,$select_name,$checked_val='xzxz',$swap=false,$show_100=false,$text_100='None') {
209 $keys=array_values($arr);
210 $vals=array_keys($arr);
212 $vals=array_values($arr);
213 $keys=array_keys($arr);
215 return html_build_select_box_from_arrays ($keys,$vals,$select_name,$checked_val,$show_100,$text_100);
219 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
220 * or value and the array being the text you want displayed.
222 * @param array An array of items to use.
223 * @param string The name you want assigned to this form element.
224 * @param string The value of the item that should be checked.
226 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
228 <select name="'.$select_name.'">';
232 for ($i=0; $i<$rows; $i++) {
234 $return .= "\n\t\t<option value=\"" . $vals[$i] . "\"";
235 if ($vals[$i] == $checked_val) {
236 $return .= ' selected="selected"';
239 $return .= "\n\t\t<option value=\"" . $i .'"';
240 if ($i == $checked_val) {
241 $return .= ' selected="selected"';
244 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
253 * html_build_radio_buttons_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
254 * array being the text you want displayed.
256 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
257 * There must be a related row in users, categories, et , and by default that
258 * row is 100, so almost every pop-up box has 100 as the default
259 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
261 * @param array The ID or value
262 * @param array Text to be displayed
263 * @param string Name to assign to this form element
264 * @param string The item that should be checked
265 * @param bool Whether or not to show the '100 row'
266 * @param string What to call the '100 row' defaults to none
267 * @param bool Whether or not to show the 'Any row'
268 * @param string What to call the 'Any row' defaults to any
270 function html_build_radio_buttons_from_arrays ($vals,$texts,$select_name,$checked_val='xzxz',$show_100=true,$text_100='none',$show_any=false,$text_any='any') {
271 if ($text_100=='none'){
277 if (count($texts) != $rows) {
278 $return .= 'ERROR - uneven row counts';
281 //we don't always want the default Any row shown
284 <input type="radio" name="'.$select_name.'" value=""'.(($checked_val=='') ? ' checked="checked"' : '').' /> '. $text_any .'<br />';
286 //we don't always want the default 100 row shown
289 <input type="radio" name="'.$select_name.'" value="100"'.(($checked_val==100) ? ' checked="checked"' : '').' /> '. $text_100 .'<br />';
292 $checked_found=false;
294 for ($i=0; $i<$rows; $i++) {
295 // uggh - sorry - don't show the 100 row
296 // if it was shown above, otherwise do show it
297 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
299 <input type="radio" name="'.$select_name.'" value="'.$vals[$i].'"';
300 if ((string)$vals[$i] == (string)$checked_val) {
302 $return .= ' checked="checked"';
304 $return .= ' /> '.htmlspecialchars($texts[$i]).'<br />';
308 // If the passed in "checked value" was never "SELECTED"
309 // we want to preserve that value UNLESS that value was 'xzxz', the default value
311 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
313 <input type="radio" value="'.$checked_val.'" checked="checked" /> '._('No Change').'<br />';
319 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
320 * array being the text you want displayed.
322 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
323 * There must be a related row in users, categories, et , and by default that
324 * row is 100, so almost every pop-up box has 100 as the default
325 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
327 * @param array The ID or value
328 * @param array Text to be displayed
329 * @param string Name to assign to this form element
330 * @param string The item that should be checked
331 * @param bool Whether or not to show the '100 row'
332 * @param string What to call the '100 row' defaults to none
333 * @param bool Whether or not to show the 'Any row'
334 * @param string What to call the 'Any row' defaults to any
335 * @param array Array of all allowed values from the full list.
337 function html_build_select_box_from_arrays ($vals,$texts,$select_name,$checked_val='xzxz',$show_100=true,$text_100='none',$show_any=false,$text_any='any', $allowed=false) {
338 if ($text_100=='none'){
344 if (count($texts) != $rows) {
345 $return .= 'ERROR - uneven row counts';
349 <select name="'.$select_name.'">';
351 //we don't always want the default Any row shown
354 <option value=""'.(($checked_val=='') ? ' selected="selected"' : '').'>'. $text_any .'</option>';
356 //we don't always want the default 100 row shown
359 <option value="100"'.(($checked_val==100) ? ' selected="selected"' : '').'>'. $text_100 .'</option>';
362 $checked_found=false;
364 for ($i=0; $i<$rows; $i++) {
365 // uggh - sorry - don't show the 100 row
366 // if it was shown above, otherwise do show it
367 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
369 <option value="'.$vals[$i].'"';
370 if ((string)$vals[$i] == (string)$checked_val) {
372 $return .= ' selected="selected"';
374 if (is_array($allowed) && !in_array($vals[$i], $allowed)) {
375 $return .= ' disabled="disabled" class="option_disabled"';
377 $return .= '>'./*htmlspecialchars(*/$texts[$i]/*)*/.'</option>';
381 // If the passed in "checked value" was never "SELECTED"
382 // we want to preserve that value UNLESS that value was 'xzxz', the default value
384 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
386 <option value="'.$checked_val.'" selected="selected">'._('No Change').'</option>';
395 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
396 * the second column being the text you want displayed.
398 * @param int The result set
399 * @param string Text to be displayed
400 * @param string The item that should be checked
401 * @param bool Whether or not to show the '100 row'
402 * @param string What to call the '100 row'. Defaults to none.
404 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none',$show_any=false,$text_any='Select One') {
405 if ($text_100=='none'){
408 return html_build_select_box_from_arrays (util_result_column_to_array($result,0),util_result_column_to_array($result,1),$name,$checked_val,$show_100,$text_100, $show_any, $text_any);
412 * html_build_select_box_sorted() - Takes a result set, with the first column being the "id" or value and
413 * the second column being the text you want displayed.
415 * @param int The result set
416 * @param string Text to be displayed
417 * @param string The item that should be checked
418 * @param bool Whether or not to show the '100 row'
419 * @param string What to call the '100 row'. Defaults to none.
421 function html_build_select_box_sorted ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none') {
422 if ($text_100=='none'){
425 $vals = util_result_column_to_array($result, 0);
426 $texts = util_result_column_to_array($result, 1);
427 array_multisort($texts, SORT_ASC, SORT_STRING,
429 return html_build_select_box_from_arrays ($vals, $texts, $name, $checked_val, $show_100, $text_100);
433 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
434 * and the second column being the text you want displayed.
436 * @param int The result set
437 * @param string Text to be displayed
438 * @param string The item that should be checked
439 * @param int The size of this box
440 * @param bool Whether or not to show the '100 row'
442 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
443 $checked_count=count($checked_array);
445 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
448 Put in the default NONE box
451 <option value="100"';
452 for ($j=0; $j<$checked_count; $j++) {
453 if ($checked_array[$j] == '100') {
454 $return .= ' selected="selected"';
457 $return .= '>'._('None').'</option>';
460 $rows=db_numrows($result);
461 for ($i=0; $i<$rows; $i++) {
462 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
464 <option value="'.db_result($result,$i,0).'"';
466 Determine if it's checked
468 $val=db_result($result,$i,0);
469 for ($j=0; $j<$checked_count; $j++) {
470 if ($val == $checked_array[$j]) {
471 $return .= ' selected="selected"';
474 $return .= '>'. substr(db_result($result,$i,1),0,35). '</option>';
483 * html_build_multiple_select_box_from_arrays() - Takes two arrays and builds a multi-select box
485 * @param array id of the field
486 * @param array Text to be displayed
487 * @param string id of the items selected
488 * @param string The item that should be checked
489 * @param int The size of this box
490 * @param bool Whether or not to show the '100 row'
492 function html_build_multiple_select_box_from_arrays($ids,$texts,$name,$checked_array,$size='8',$show_100=true,$text_100='none') {
493 $checked_count=count($checked_array);
495 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
497 if ($text_100=='none') {
501 Put in the default NONE box
504 <option value="100"';
505 for ($j=0; $j<$checked_count; $j++) {
506 if ($checked_array[$j] == '100') {
507 $return .= ' selected="selected"';
510 $return .= '>'.$text_100.'</option>';
514 for ($i=0; $i<$rows; $i++) {
515 if (( $ids[$i] != '100') || ($ids[$i] == '100' && !$show_100)) {
517 <option value="'.$ids[$i].'"';
519 Determine if it's checked
522 for ($j=0; $j<$checked_count; $j++) {
523 if ($val == $checked_array[$j]) {
524 $return .= ' selected="selected"';
527 $return .= '>'.$texts[$i].' </option>';
536 * html_build_checkbox() - Render checkbox control
538 * @param name - name of control
539 * @param value - value of control
540 * @param checked - true if control should be checked
541 * @return html code for checkbox control
543 function html_build_checkbox($name, $value, $checked) {
544 return '<input type="checkbox" name="'.$name.'"'
545 .' value="'.$value.'"'
546 .($checked ? 'checked="checked"' : '').'>';
551 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
553 * @see html_build_priority_select_box()
555 function build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
556 echo html_build_priority_select_box ($name, $checked_val, $nochange);
560 * html_build_priority_select_box() - Return a select box of standard priorities.
561 * The name of this select box is optional and so is the default checked value.
563 * @param string Name of the select box
564 * @param string The value to be checked
565 * @param bool Whether to make 'No Change' selected.
567 function html_build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
569 <select name="<?php echo $name; ?>">
570 <?php if($nochange) { ?>
571 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo _('No Change') ?></option>
573 <option value="1"<?php if ($checked_val=="1") {echo " selected=\"selected\"";} ?>>1 - <?php echo _('Lowest') ?></option>
574 <option value="2"<?php if ($checked_val=="2") {echo " selected=\"selected\"";} ?>>2</option>
575 <option value="3"<?php if ($checked_val=="3") {echo " selected=\"selected\"";} ?>>3</option>
576 <option value="4"<?php if ($checked_val=="4") {echo " selected=\"selected\"";} ?>>4</option>
577 <option value="5"<?php if ($checked_val=="5") {echo " selected=\"selected\"";} ?>>5 - <?php echo _('Highest') ?></option>
584 * html_buildcheckboxarray() - Build an HTML checkbox array.
586 * @param array Options array
587 * @param name Checkbox name
588 * @param array Array of boxes to be pre-checked
590 function html_buildcheckboxarray($options,$name,$checked_array) {
591 $option_count=count($options);
592 $checked_count=count($checked_array);
594 for ($i=1; $i<=$option_count; $i++) {
596 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
597 for ($j=0; $j<$checked_count; $j++) {
598 if ($i == $checked_array[$j]) {
599 echo ' checked="checked"';
602 echo ' /> '.$options[$i];
607 * site_user_header() - everything required to handle security and
608 * add navigation for user pages like /my/ and /account/
610 * @param array Must contain $user_id
612 function site_header($params) {
615 Check to see if active user
616 Check to see if logged in
618 echo $HTML->header($params);
620 if(isset($GLOBALS['error_msg']) && $GLOBALS['error_msg']) {
621 echo html_error_top($GLOBALS['error_msg']);
623 if(isset($GLOBALS['warning_msg']) && $GLOBALS['warning_msg']) {
624 echo html_warning_top($GLOBALS['warning_msg']);
626 if(isset($GLOBALS['feedback']) && $GLOBALS['feedback']) {
627 echo html_feedback_top($GLOBALS['feedback']);
632 * site_footer() - Show the HTML site footer.
634 * @param array Footer params array
636 function site_footer($params) {
638 $HTML->footer($params);
642 * site_project_header() - everything required to handle
643 * security and state checks for a project web page
645 * @param params array() must contain $toptab and $group
647 function site_project_header($params) {
651 Check to see if active
652 Check to see if project rather than foundry
653 Check to see if private (if private check if user_ismember)
656 $group_id=$params['group'];
658 //get the project object
659 $project =& group_get_object($group_id);
661 if (!$project || !is_object($project)) {
663 } else if ($project->isError()) {
664 if ($project->isPermissionDeniedError()) {
665 if (!session_get_user()) {
666 $next = '/account/login.php?error_msg='.urlencode($project->getErrorMessage());
667 if (getStringFromServer('REQUEST_METHOD') != 'POST') {
668 $next .= '&return_to='.urlencode(getStringFromServer('REQUEST_URI'));
670 session_redirect($next);
673 exit_error(sprintf(_('Project access problem: %s'),$project->getErrorMessage()),'home');
675 exit_error(sprintf(_('Project Problem: %s'),$project->getErrorMessage()),'home');
679 if (!$project->isPublic()) {
680 session_require_perm ('project_read', $group_id);
683 //for dead projects must be member of admin project
684 if (!$project->isActive()) {
685 session_require_global_perm ('forge_admin');
688 if (isset($params['title'])){
689 $params['title']=$project->getPublicName().': '.$params['title'];
691 $params['title']=$project->getPublicName();
694 site_header($params);
696 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
700 * site_project_footer() - currently a simple shim
701 * that should be on every project page, rather than
702 * a direct call to site_footer() or theme_footer()
704 * @param params array() empty
706 function site_project_footer($params) {
707 site_footer($params);
711 * site_user_header() - everything required to handle security and
712 * add navigation for user pages like /my/ and /account/
714 * @param params array() must contain $user_id
716 function site_user_header($params) {
720 Check to see if active user
721 Check to see if logged in
723 echo $HTML->header($params);
724 echo "<h1>" . _('My Personal Page') . "</h1>\n";
725 if (isset($GLOBALS['error_msg'])) {
726 echo html_feedback_top($GLOBALS['error_msg']);
728 if (isset($GLOBALS['warning_msg'])) {
729 echo html_feedback_top($GLOBALS['warning_msg']);
731 if (isset($GLOBALS['feedback'])) {
732 echo html_feedback_top($GLOBALS['feedback']);
734 echo ($HTML->beginSubMenu());
735 if ($GLOBALS['sys_use_diary']) {
736 echo ($HTML->printSubMenu(
737 array(_('My Personal Page'),
738 _('Trackers dashboard'),
739 _('Diary & Notes'),
740 _('Account Maintenance'),
741 _('Register Project')),
748 echo ($HTML->printSubMenu(
749 array(_('My Personal Page'),
750 _('Account Maintenance'),
751 _('Register Project')),
756 plugin_hook ("usermenu", false) ;
757 echo ($HTML->endSubMenu());
761 * site_user_footer() - currently a simple shim that should be on every user page,
762 * rather than a direct call to site_footer() or theme_footer()
764 * @param params array() empty
766 function site_user_footer($params) {
767 site_footer($params);
771 * html_clean_hash_string() - Remove noise characters from hex hash string
773 * Thruout SourceForge, URLs with hexadecimal hash string parameters
774 * are being sent via email to request confirmation of user actions.
775 * It was found that some mail clients distort this hash, so we take
776 * special steps to encode it in the way which help to preserve its
777 * recognition. This routine
779 * @param hashstr required hash parameter as received from browser
780 * @return pure hex string
782 function html_clean_hash_string($hashstr) {
784 if (substr($hashstr,0,1)=="_") {
785 $hashstr = substr($hashstr, 1);
788 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
789 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);
797 // c-file-style: "bsd"