5 * SourceForge: Breaking Down the Barriers to Open Source Development
6 * Copyright 1999-2001 (c) VA Linux Systems
7 * http://sourceforge.net
12 * html_feedback_top() - Show the feedback output at the top of the page.
14 * @param string The feedback.
16 function html_feedback_top($feedback) {
18 echo $HTML->feedback($feedback);
22 * html_warning_top() - Show the warning output at the top of the page.
24 * @param string The warning message.
26 function html_warning_top($msg) {
28 echo $HTML->warning_msg($msg);
32 * html_error_top() - Show the error output at the top of the page.
34 * @param string The error message.
36 function html_error_top($msg) {
38 echo $HTML->error_msg($msg);
42 * make_user_link() - Make a username reference into a link to that users User page on SF.
44 * @param string The username of the user to link.
46 function make_user_link($username) {
47 if (!strcasecmp($username,'Nobody') || !strcasecmp($username,'None')) {
50 return '<a href="/users/'.$username.'">'.$username.'</a>' ;
55 * html_feedback_top() - Show the feedback output at the bottom of the page.
57 * @param string The feedback.
59 function html_feedback_bottom($feedback) {
61 echo $HTML->feedback($feedback);
65 * html_blankimage() - Show the blank spacer image.
67 * @param int The height of the image
68 * @param int The width of the image
70 function html_blankimage($height,$width) {
71 return '<img src="/images/blank.png" width="' . $width . '" height="' . $height . '" alt="" />';
75 * html_dbimage() - Show an image that is stored in the database
77 * @param int The id of the image to show
79 function html_dbimage($id, $args=0) {
86 $result = db_query_params ('SELECT width,height,version
87 FROM db_images WHERE id=$1',
89 $rows=db_numrows($result);
91 if (!$result || $rows < 1) {
94 return html_abs_image('/dbimage.php?id='.$id.'&v='.db_result($result,0,'version'),db_result($result,0,'width'),db_result($result,0,'height'),$args);
99 * html_abs_image() - Show an image given an absolute URL.
102 * @param int width of the image
103 * @param int height of the image
104 * @param array Any <img> tag parameters (i.e. 'border', 'alt', etc...)
106 function html_abs_image($url, $width, $height, $args) {
107 $return = ('<img src="' . $url . '"');
109 while(list($k,$v) = each($args)) {
110 $return .= ' '.$k.'="'.$v.'"';
113 if (!isset($args['alt'])) {
114 $return .= ' alt=""';
117 // ## add image dimensions
118 $return .= " width=\"" . $width . "\"";
119 $return .= " height=\"" . $height . "\"";
126 * html_image() - Build an image tag of an image contained in $src
128 * @param string The source location of the image
129 * @param int The width of the image
130 * @param int The height of the image
131 * @param array Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
132 * @param bool DEPRECATED
134 function html_image($src,$width,$height,$args,$display=1) {
135 global $sys_images_url,$sys_images_secure_url,$HTML;
136 $s = ((session_issecure()) ? $sys_images_secure_url : $sys_images_url );
137 return html_abs_image($s.$HTML->imgroot.$src, $width, $height, $args);
141 * html_get_language_popup() - Pop up box of supported languages.
143 * @param string The title of the popup box.
144 * @param string Which element of the box is to be selected.
145 * @return string The html select box.
147 function html_get_language_popup ($title='language_id',$selected='xzxz') {
148 $res = db_query_params ('SELECT * FROM supported_languages ORDER BY name ASC',
150 return html_build_select_box ($res,$title,$selected,false);
154 * html_get_theme_popup() - Pop up box of supported themes.
156 * @param string The title of the popup box.
157 * @param string Which element of the box is to be selected.
158 * @return string The html select box.
160 function html_get_theme_popup ($title='theme_id',$selected='xzxz') {
161 $res=db_query_params ('SELECT theme_id, fullname FROM themes WHERE enabled=true',
163 $nbTheme = db_numrows($res);
168 return html_build_select_box($res,$title,$selected,false);
173 * html_get_ccode_popup() - Pop up box of supported country_codes.
175 * @param string The title of the popup box.
176 * @param string Which element of the box is to be selected.
177 * @return string The html select box.
179 function html_get_ccode_popup ($title='ccode',$selected='xzxz') {
180 $res=db_query_params ('SELECT ccode,country_name FROM country_code ORDER BY country_name',
182 return html_build_select_box ($res,$title,$selected,false);
186 * html_get_timezone_popup() - Pop up box of supported Timezones.
187 * Assumes you have included Timezones array file.
189 * @param string The title of the popup box.
190 * @param string Which element of the box is to be selected.
191 * @return string The html select box.
193 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
195 if ($selected == 'xzxzxzx') {
196 $r = file ('/etc/timezone');
197 $selected = str_replace ("\n", '', $r[0]);
199 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
204 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
206 * @param array An array of items to use.
207 * @param string The name you want assigned to this form element.
208 * @param string The value of the item that should be checked.
209 * @param boolean Whether we should swap the keys / names.
210 * @param bool Whether or not to show the '100 row'.
211 * @param string What to call the '100 row' defaults to none.
213 function html_build_select_box_from_assoc ($arr,$select_name,$checked_val='xzxz',$swap=false,$show_100=false,$text_100='None') {
215 $keys=array_values($arr);
216 $vals=array_keys($arr);
218 $vals=array_values($arr);
219 $keys=array_keys($arr);
221 return html_build_select_box_from_arrays ($keys,$vals,$select_name,$checked_val,$show_100,$text_100);
225 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
226 * or value and the array being the text you want displayed.
228 * @param array An array of items to use.
229 * @param string The name you want assigned to this form element.
230 * @param string The value of the item that should be checked.
232 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
234 <select name="'.$select_name.'">';
238 for ($i=0; $i<$rows; $i++) {
240 $return .= "\n\t\t<option value=\"" . $vals[$i] . "\"";
241 if ($vals[$i] == $checked_val) {
242 $return .= ' selected="selected"';
245 $return .= "\n\t\t<option value=\"" . $i .'"';
246 if ($i == $checked_val) {
247 $return .= ' selected="selected"';
250 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
259 * html_build_radio_buttons_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
260 * array being the text you want displayed.
262 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
263 * There must be a related row in users, categories, et , and by default that
264 * row is 100, so almost every pop-up box has 100 as the default
265 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
267 * @param array The ID or value
268 * @param array Text to be displayed
269 * @param string Name to assign to this form element
270 * @param string The item that should be checked
271 * @param bool Whether or not to show the '100 row'
272 * @param string What to call the '100 row' defaults to none
273 * @param bool Whether or not to show the 'Any row'
274 * @param string What to call the 'Any row' defaults to any
276 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') {
277 if ($text_100=='none'){
283 if (count($texts) != $rows) {
284 $return .= 'ERROR - uneven row counts';
287 //we don't always want the default Any row shown
290 <input type="radio" name="'.$select_name.'" value=""'.(($checked_val=='') ? ' checked="checked"' : '').' /> '. $text_any .'<br />';
292 //we don't always want the default 100 row shown
295 <input type="radio" name="'.$select_name.'" value="100"'.(($checked_val==100) ? ' checked="checked"' : '').' /> '. $text_100 .'<br />';
298 $checked_found=false;
300 for ($i=0; $i<$rows; $i++) {
301 // uggh - sorry - don't show the 100 row
302 // if it was shown above, otherwise do show it
303 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
305 <input type="radio" name="'.$select_name.'" value="'.$vals[$i].'"';
306 if ((string)$vals[$i] == (string)$checked_val) {
308 $return .= ' checked="checked"';
310 $return .= ' /> '.htmlspecialchars($texts[$i]).'<br />';
314 // If the passed in "checked value" was never "SELECTED"
315 // we want to preserve that value UNLESS that value was 'xzxz', the default value
317 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
319 <input type="radio" value="'.$checked_val.'" checked="checked" /> '._('No Change').'<br />';
325 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
326 * array being the text you want displayed.
328 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
329 * There must be a related row in users, categories, et , and by default that
330 * row is 100, so almost every pop-up box has 100 as the default
331 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
333 * @param array The ID or value
334 * @param array Text to be displayed
335 * @param string Name to assign to this form element
336 * @param string The item that should be checked
337 * @param bool Whether or not to show the '100 row'
338 * @param string What to call the '100 row' defaults to none
339 * @param bool Whether or not to show the 'Any row'
340 * @param string What to call the 'Any row' defaults to any
341 * @param array Array of all allowed values from the full list.
343 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) {
344 if ($text_100=='none'){
350 if (count($texts) != $rows) {
351 $return .= 'ERROR - uneven row counts';
355 <select name="'.$select_name.'">';
357 //we don't always want the default Any row shown
360 <option value=""'.(($checked_val=='') ? ' selected="selected"' : '').'>'. $text_any .'</option>';
362 //we don't always want the default 100 row shown
365 <option value="100"'.(($checked_val==100) ? ' selected="selected"' : '').'>'. $text_100 .'</option>';
368 $checked_found=false;
370 for ($i=0; $i<$rows; $i++) {
371 // uggh - sorry - don't show the 100 row
372 // if it was shown above, otherwise do show it
373 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
375 <option value="'.$vals[$i].'"';
376 if ((string)$vals[$i] == (string)$checked_val) {
378 $return .= ' selected="selected"';
380 if (is_array($allowed) && !in_array($vals[$i], $allowed)) {
381 $return .= ' disabled="disabled" class="option_disabled"';
383 $return .= '>'./*htmlspecialchars(*/$texts[$i]/*)*/.'</option>';
387 // If the passed in "checked value" was never "SELECTED"
388 // we want to preserve that value UNLESS that value was 'xzxz', the default value
390 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
392 <option value="'.$checked_val.'" selected="selected">'._('No Change').'</option>';
401 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
402 * the second column being the text you want displayed.
404 * @param int The result set
405 * @param string Text to be displayed
406 * @param string The item that should be checked
407 * @param bool Whether or not to show the '100 row'
408 * @param string What to call the '100 row'. Defaults to none.
410 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none',$show_any=false,$text_any='Select One') {
411 if ($text_100=='none'){
414 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);
418 * html_build_select_box_sorted() - Takes a result set, with the first column being the "id" or value and
419 * the second column being the text you want displayed.
421 * @param int The result set
422 * @param string Text to be displayed
423 * @param string The item that should be checked
424 * @param bool Whether or not to show the '100 row'
425 * @param string What to call the '100 row'. Defaults to none.
427 function html_build_select_box_sorted ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none') {
428 if ($text_100=='none'){
431 $vals = util_result_column_to_array($result, 0);
432 $texts = util_result_column_to_array($result, 1);
433 array_multisort($texts, SORT_ASC, SORT_STRING,
435 return html_build_select_box_from_arrays ($vals, $texts, $name, $checked_val, $show_100, $text_100);
439 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
440 * and the second column being the text you want displayed.
442 * @param int The result set
443 * @param string Text to be displayed
444 * @param string The item that should be checked
445 * @param int The size of this box
446 * @param bool Whether or not to show the '100 row'
448 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
449 $checked_count=count($checked_array);
451 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
454 Put in the default NONE box
457 <option value="100"';
458 for ($j=0; $j<$checked_count; $j++) {
459 if ($checked_array[$j] == '100') {
460 $return .= ' selected="selected"';
463 $return .= '>'._('None').'</option>';
466 $rows=db_numrows($result);
467 for ($i=0; $i<$rows; $i++) {
468 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
470 <option value="'.db_result($result,$i,0).'"';
472 Determine if it's checked
474 $val=db_result($result,$i,0);
475 for ($j=0; $j<$checked_count; $j++) {
476 if ($val == $checked_array[$j]) {
477 $return .= ' selected="selected"';
480 $return .= '>'. substr(db_result($result,$i,1),0,35). '</option>';
489 * html_build_multiple_select_box_from_arrays() - Takes two arrays and builds a multi-select box
491 * @param array id of the field
492 * @param array Text to be displayed
493 * @param string id of the items selected
494 * @param string The item that should be checked
495 * @param int The size of this box
496 * @param bool Whether or not to show the '100 row'
498 function html_build_multiple_select_box_from_arrays($ids,$texts,$name,$checked_array,$size='8',$show_100=true,$text_100='none') {
499 $checked_count=count($checked_array);
501 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
503 if ($text_100=='none') {
507 Put in the default NONE box
510 <option value="100"';
511 for ($j=0; $j<$checked_count; $j++) {
512 if ($checked_array[$j] == '100') {
513 $return .= ' selected="selected"';
516 $return .= '>'.$text_100.'</option>';
520 for ($i=0; $i<$rows; $i++) {
521 if (( $ids[$i] != '100') || ($ids[$i] == '100' && !$show_100)) {
523 <option value="'.$ids[$i].'"';
525 Determine if it's checked
528 for ($j=0; $j<$checked_count; $j++) {
529 if ($val == $checked_array[$j]) {
530 $return .= ' selected="selected"';
533 $return .= '>'.$texts[$i].' </option>';
542 * html_build_checkbox() - Render checkbox control
544 * @param name - name of control
545 * @param value - value of control
546 * @param checked - true if control should be checked
547 * @return html code for checkbox control
549 function html_build_checkbox($name, $value, $checked) {
550 return '<input type="checkbox" name="'.$name.'"'
551 .' value="'.$value.'"'
552 .($checked ? 'checked="checked"' : '').'>';
557 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
559 * @see html_build_priority_select_box()
561 function build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
562 echo html_build_priority_select_box ($name, $checked_val, $nochange);
566 * html_build_priority_select_box() - Return a select box of standard priorities.
567 * The name of this select box is optional and so is the default checked value.
569 * @param string Name of the select box
570 * @param string The value to be checked
571 * @param bool Whether to make 'No Change' selected.
573 function html_build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
575 <select name="<?php echo $name; ?>">
576 <?php if($nochange) { ?>
577 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo _('No Change') ?></option>
579 <option value="1"<?php if ($checked_val=="1") {echo " selected=\"selected\"";} ?>>1 - <?php echo _('Lowest') ?></option>
580 <option value="2"<?php if ($checked_val=="2") {echo " selected=\"selected\"";} ?>>2</option>
581 <option value="3"<?php if ($checked_val=="3") {echo " selected=\"selected\"";} ?>>3</option>
582 <option value="4"<?php if ($checked_val=="4") {echo " selected=\"selected\"";} ?>>4</option>
583 <option value="5"<?php if ($checked_val=="5") {echo " selected=\"selected\"";} ?>>5 - <?php echo _('Highest') ?></option>
590 * html_buildcheckboxarray() - Build an HTML checkbox array.
592 * @param array Options array
593 * @param name Checkbox name
594 * @param array Array of boxes to be pre-checked
596 function html_buildcheckboxarray($options,$name,$checked_array) {
597 $option_count=count($options);
598 $checked_count=count($checked_array);
600 for ($i=1; $i<=$option_count; $i++) {
602 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
603 for ($j=0; $j<$checked_count; $j++) {
604 if ($i == $checked_array[$j]) {
605 echo ' checked="checked"';
608 echo ' /> '.$options[$i];
613 * site_user_header() - everything required to handle security and
614 * add navigation for user pages like /my/ and /account/
616 * @param array Must contain $user_id
618 function site_header($params) {
621 Check to see if active user
622 Check to see if logged in
624 echo $HTML->header($params);
625 echo html_feedback_top($GLOBALS['feedback']);
629 * site_footer() - Show the HTML site footer.
631 * @param array Footer params array
633 function site_footer($params) {
635 $HTML->footer($params);
639 * site_project_header() - everything required to handle
640 * security and state checks for a project web page
642 * @param params array() must contain $toptab and $group
644 function site_project_header($params) {
648 Check to see if active
649 Check to see if project rather than foundry
650 Check to see if private (if private check if user_ismember)
653 $group_id=$params['group'];
655 //get the project object
656 $project =& group_get_object($group_id);
658 if (!$project || !is_object($project)) {
659 exit_error("GROUP PROBLEM","PROBLEM CREATING GROUP OBJECT");
660 } else if ($project->isError()) {
661 if ($project->isPermissionDeniedError() && !session_get_user()) {
662 $next = '/account/login.php?feedback='.urlencode($project->getErrorMessage());
663 if (getStringFromServer('REQUEST_METHOD') != 'POST') {
664 $next .= '&return_to='.urlencode(getStringFromServer('REQUEST_URI'));
667 header("Location: $next");
670 exit_error("Group Problem",$project->getErrorMessage());
674 if (!$project->isPublic()) {
675 //if it's a private group, you must be a member of that group
676 session_require(array('group'=>$group_id));
679 //for dead projects must be member of admin project
680 if (!$project->isActive()) {
681 //only SF group can view non-active, non-holding groups
682 session_require(array('group'=>'1'));
685 if (isset($params['title'])){
686 $params['title']=$project->getPublicName().': '.$params['title'];
688 $params['title']=$project->getPublicName();
690 echo $HTML->header($params);
692 if(isset($GLOBALS['error_msg']) && $GLOBALS['error_msg']) {
693 echo html_error_top($GLOBALS['error_msg']);
695 if(isset($GLOBALS['warning_msg']) && $GLOBALS['warning_msg']) {
696 echo html_warning_top($GLOBALS['warning_msg']);
698 if(isset($GLOBALS['feedback']) && $GLOBALS['feedback']) {
699 echo html_feedback_top($GLOBALS['feedback']);
701 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
705 * site_project_footer() - currently a simple shim
706 * that should be on every project page, rather than
707 * a direct call to site_footer() or theme_footer()
709 * @param params array() empty
711 function site_project_footer($params) {
713 echo $HTML->footer($params);
717 * site_user_header() - everything required to handle security and
718 * add navigation for user pages like /my/ and /account/
720 * @param params array() must contain $user_id
722 function site_user_header($params) {
726 Check to see if active user
727 Check to see if logged in
729 echo $HTML->header($params);
730 echo "<h1>" . _('My Personal Page') . "</h1>\n";
731 echo html_feedback_top((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
732 echo ($HTML->beginSubMenu());
733 if ($GLOBALS['sys_use_diary']) {
734 echo ($HTML->printSubMenu(
735 array(_('My Personal Page'),
736 _('Trackers dashboard'),
737 _('Diary & Notes'),
738 _('Account Maintenance'),
739 _('Register Project')),
746 echo ($HTML->printSubMenu(
747 array(_('My Personal Page'),
748 _('Account Maintenance'),
749 _('Register Project')),
754 plugin_hook ("usermenu", false) ;
755 echo ($HTML->endSubMenu());
759 * site_user_footer() - currently a simple shim that should be on every user page,
760 * rather than a direct call to site_footer() or theme_footer()
762 * @param params array() empty
764 function site_user_footer($params) {
765 site_footer($params);
769 * html_clean_hash_string() - Remove noise characters from hex hash string
771 * Thruout SourceForge, URLs with hexadecimal hash string parameters
772 * are being sent via email to request confirmation of user actions.
773 * It was found that some mail clients distort this hash, so we take
774 * special steps to encode it in the way which help to preserve its
775 * recognition. This routine
777 * @param hashstr required hash parameter as received from browser
778 * @return pure hex string
780 function html_clean_hash_string($hashstr) {
782 if (substr($hashstr,0,1)=="_") {
783 $hashstr = substr($hashstr, 1);
786 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
787 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);
794 * html_build_rich_textarea() - Renders textarea control
796 * @param name (string) - the name for the control
797 * @param rows (int) - the rows for the control (number of visible text lines)
798 * @param cols (int) - the cols for the control (visible width in average character widths)
799 * @param text (string) - initial text to be displayed
800 * @param readonly (boolean) - if the text cannot be modified
801 * @return html code for control
803 function html_build_rich_textarea($name,$rows,$cols,$text,$readonly) {
804 return '<textarea name="'.$name.'"'
807 .($readonly ? ' readonly' : ' ').'>'
808 . $text . '</textarea>';
813 // c-file-style: "bsd"