5 * SourceForge: Breaking Down the Barriers to Open Source Development
6 * Copyright 1999-2001 (c) VA Linux Systems
7 * http://sourceforge.net
13 * html_feedback_top() - Show the feedback output at the top of the page.
15 * @param string The feedback.
17 function html_feedback_top($feedback) {
19 echo $HTML->feedback($feedback);
23 * make_user_link() - Make a username reference into a link to that users User page on SF.
25 * @param string The username of the user to link.
27 function make_user_link($username) {
28 if (!strcasecmp($username,'Nobody') || !strcasecmp($username,'None')) {
31 return util_make_link ('/users/'.$username,$username);
36 * html_feedback_top() - Show the feedback output at the bottom of the page.
38 * @param string The feedback.
40 function html_feedback_bottom($feedback) {
42 echo $HTML->feedback($feedback);
46 * html_blankimage() - Show the blank spacer image.
48 * @param int The height of the image
49 * @param int The width of the image
51 function html_blankimage($height,$width) {
52 return '<img src="/images/blank.png" width="' . $width . '" height="' . $height . '" alt="" />';
56 * html_dbimage() - Show an image that is stored in the database
58 * @param int The id of the image to show
60 function html_dbimage($id, $args=0) {
67 $sql="SELECT width,height,version ".
68 "FROM db_images WHERE id='$id'";
69 $result=db_query($sql);
70 $rows=db_numrows($result);
72 if (!$result || $rows < 1) {
75 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);
80 * html_abs_image() - Show an image given an absolute URL.
83 * @param int width of the image
84 * @param int height of the image
85 * @param array Any <img> tag parameters (i.e. 'border', 'alt', etc...)
87 function html_abs_image($url, $width, $height, $args) {
88 $return = ('<img src="' . $url . '"');
90 while(list($k,$v) = each($args)) {
91 $return .= ' '.$k.'="'.$v.'"';
94 // ## insert a border tag if there isn't one
95 if (!isset($args['border'])) {
96 $return .= ' border="0"';
99 if (!isset($args['alt'])) {
100 $return .= ' alt=""';
103 // ## add image dimensions
104 $return .= " width=\"" . $width . "\"";
105 $return .= " height=\"" . $height . "\"";
112 * html_image() - Build an image tag of an image contained in $src
114 * @param string The source location of the image
115 * @param int The width of the image
116 * @param int The height of the image
117 * @param array Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
118 * @param bool DEPRECATED
120 function html_image($src,$width,$height,$args,$display=1) {
121 global $sys_images_url,$sys_images_secure_url,$HTML;
122 $s = ((session_issecure()) ? $sys_images_secure_url : $sys_images_url );
123 return html_abs_image($s.$HTML->imgroot.$src, $width, $height, $args);
127 * html_get_language_popup() - Pop up box of supported languages.
129 * @param string The title of the popup box.
130 * @param string Which element of the box is to be selected.
131 * @return string The html select box.
133 function html_get_language_popup ($title='language_id',$selected='xzxz') {
134 $res = db_query('SELECT * FROM supported_languages ORDER BY name ASC');
135 return html_build_select_box ($res,$title,$selected,false);
139 * html_get_theme_popup() - Pop up box of supported themes.
141 * @param string The title of the popup box.
142 * @param string Which element of the box is to be selected.
143 * @return string The html select box.
145 function html_get_theme_popup ($title='theme_id',$selected='xzxz') {
146 $res=db_query("SELECT theme_id, fullname FROM themes WHERE enabled=true");
147 return html_build_select_box($res,$title,$selected,false);
151 * html_get_ccode_popup() - Pop up box of supported country_codes.
153 * @param string The title of the popup box.
154 * @param string Which element of the box is to be selected.
155 * @return string The html select box.
157 function html_get_ccode_popup ($title='ccode',$selected='xzxz') {
158 $res=db_query("SELECT ccode,country_name FROM country_code ORDER BY country_name");
159 return html_build_select_box ($res,$title,$selected,false);
163 * html_get_timezone_popup() - Pop up box of supported Timezones.
164 * Assumes you have included Timezones array file.
166 * @param string The title of the popup box.
167 * @param string Which element of the box is to be selected.
168 * @return string The html select box.
170 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
172 if ($selected == 'xzxzxzx') {
173 $r = file ('/etc/timezone');
174 $selected = str_replace ("\n", '', $r[0]);
176 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
181 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
183 * @param array An array of items to use.
184 * @param string The name you want assigned to this form element.
185 * @param string The value of the item that should be checked.
186 * @param boolean Whether we should swap the keys / names.
187 * @param bool Whether or not to show the '100 row'.
188 * @param string What to call the '100 row' defaults to none.
190 function html_build_select_box_from_assoc ($arr,$select_name,$checked_val='xzxz',$swap=false,$show_100=false,$text_100='None') {
192 $keys=array_values($arr);
193 $vals=array_keys($arr);
195 $vals=array_values($arr);
196 $keys=array_keys($arr);
198 return html_build_select_box_from_arrays ($keys,$vals,$select_name,$checked_val,$show_100,$text_100);
202 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
203 * or value and the array being the text you want displayed.
205 * @param array An array of items to use.
206 * @param string The name you want assigned to this form element.
207 * @param string The value of the item that should be checked.
209 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
211 <select name="'.$select_name.'">';
215 for ($i=0; $i<$rows; $i++) {
217 $return .= "\n\t\t<option value=\"" . $vals[$i] . "\"";
218 if ($vals[$i] == $checked_val) {
219 $return .= ' selected="selected"';
222 $return .= "\n\t\t<option value=\"" . $i .'"';
223 if ($i == $checked_val) {
224 $return .= ' selected="selection"';
227 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
236 * html_build_radio_buttons_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
237 * array being the text you want displayed.
239 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
240 * There must be a related row in users, categories, et , and by default that
241 * row is 100, so almost every pop-up box has 100 as the default
242 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
244 * @param array The ID or value
245 * @param array Text to be displayed
246 * @param string Name to assign to this form element
247 * @param string The item that should be checked
248 * @param bool Whether or not to show the '100 row'
249 * @param string What to call the '100 row' defaults to none
250 * @param bool Whether or not to show the 'Any row'
251 * @param string What to call the 'Any row' defaults to any
253 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') {
254 if ($text_100=='none'){
260 if (count($texts) != $rows) {
261 $return .= 'ERROR - uneven row counts';
264 //we don't always want the default Any row shown
267 <input type="radio" name="'.$select_name.'" value=""'.(($checked_val=='') ? ' checked' : '').'> '. $text_any .'<br />';
269 //we don't always want the default 100 row shown
272 <input type="radio" name="'.$select_name.'" value="100"'.(($checked_val==100) ? ' checked' : '').'> '. $text_100 .'<br />';
275 $checked_found=false;
277 for ($i=0; $i<$rows; $i++) {
278 // uggh - sorry - don't show the 100 row
279 // if it was shown above, otherwise do show it
280 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
282 <input type="radio" name="'.$select_name.'" value="'.$vals[$i].'"';
283 if ((string)$vals[$i] == (string)$checked_val) {
285 $return .= ' checked';
287 $return .= '> '.htmlspecialchars($texts[$i]).'<br />';
291 // If the passed in "checked value" was never "SELECTED"
292 // we want to preserve that value UNLESS that value was 'xzxz', the default value
294 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
296 <input type="radio" value="'.$checked_val.'" checked> '._('No Change').'<br />';
302 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
303 * array being the text you want displayed.
305 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
306 * There must be a related row in users, categories, et , and by default that
307 * row is 100, so almost every pop-up box has 100 as the default
308 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
310 * @param array The ID or value
311 * @param array Text to be displayed
312 * @param string Name to assign to this form element
313 * @param string The item that should be checked
314 * @param bool Whether or not to show the '100 row'
315 * @param string What to call the '100 row' defaults to none
316 * @param bool Whether or not to show the 'Any row'
317 * @param string What to call the 'Any row' defaults to any
319 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') {
320 if ($text_100=='none'){
326 if (count($texts) != $rows) {
327 $return .= 'ERROR - uneven row counts';
331 <select name="'.$select_name.'">';
333 //we don't always want the default Any row shown
336 <option value=""'.(($checked_val=='') ? ' selected="selected"' : '').'>'. $text_any .'</option>';
338 //we don't always want the default 100 row shown
341 <option value="100"'.(($checked_val==100) ? ' selected="selected"' : '').'>'. $text_100 .'</option>';
344 $checked_found=false;
346 for ($i=0; $i<$rows; $i++) {
347 // uggh - sorry - don't show the 100 row
348 // if it was shown above, otherwise do show it
349 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
351 <option value="'.$vals[$i].'"';
352 if ($vals[$i] == $checked_val) {
354 $return .= ' selected="selected"';
356 $return .= '>'./*htmlspecialchars(*/$texts[$i]/*)*/.'</option>';
360 // If the passed in "checked value" was never "SELECTED"
361 // we want to preserve that value UNLESS that value was 'xzxz', the default value
363 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
365 <option value="'.$checked_val.'" selected="selected">'._('No Change').'</option>';
374 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
375 * the second column being the text you want displayed.
377 * @param int The result set
378 * @param string Text to be displayed
379 * @param string The item that should be checked
380 * @param bool Whether or not to show the '100 row'
381 * @param string What to call the '100 row'. Defaults to none.
383 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none') {
384 if ($text_100=='none'){
387 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);
390 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
391 * and the second column being the text you want displayed.
393 * @param int The result set
394 * @param string Text to be displayed
395 * @param string The item that should be checked
396 * @param int The size of this box
397 * @param bool Whether or not to show the '100 row'
399 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
400 $checked_count=count($checked_array);
402 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
405 Put in the default NONE box
408 <option value="100"';
409 for ($j=0; $j<$checked_count; $j++) {
410 if ($checked_array[$j] == '100') {
411 $return .= ' selected="selected"';
414 $return .= '>'._('None').'</option>';
417 $rows=db_numrows($result);
418 for ($i=0; $i<$rows; $i++) {
419 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
421 <option value="'.db_result($result,$i,0).'"';
423 Determine if it's checked
425 $val=db_result($result,$i,0);
426 for ($j=0; $j<$checked_count; $j++) {
427 if ($val == $checked_array[$j]) {
428 $return .= ' selected="selected"';
431 $return .= '>'. substr(db_result($result,$i,1),0,35). '</option>';
440 * html_build_multiple_select_box_from_arrays() - Takes two arrays and builds a multi-select box
442 * @param array id of the field
443 * @param array Text to be displayed
444 * @param string id of the items selected
445 * @param string The item that should be checked
446 * @param int The size of this box
447 * @param bool Whether or not to show the '100 row'
449 function html_build_multiple_select_box_from_arrays($ids,$texts,$name,$checked_array,$size='8',$show_100=true,$text_100='none') {
450 $checked_count=count($checked_array);
452 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
454 if ($text_100=='none') {
458 Put in the default NONE box
461 <option value="100"';
462 for ($j=0; $j<$checked_count; $j++) {
463 if ($checked_array[$j] == '100') {
464 $return .= ' selected="selected"';
467 $return .= '>'.$text_100.'</option>';
471 for ($i=0; $i<$rows; $i++) {
472 if (( $ids[$i] != '100') || ($ids[$i] == '100' && !$show_100)) {
474 <option value="'.$ids[$i].'"';
476 Determine if it's checked
479 for ($j=0; $j<$checked_count; $j++) {
480 if ($val == $checked_array[$j]) {
481 $return .= ' selected="selected"';
484 $return .= '>'.$texts[$i].' </option>';
493 * html_build_checkbox() - Render checkbox control
495 * @param name - name of control
496 * @param value - value of control
497 * @param checked - true if control should be checked
498 * @return html code for checkbox control
500 function html_build_checkbox($name, $value, $checked) {
501 return '<input type="checkbox" name="'.$name.'"'
502 .' value="'.$value.'"'
503 .($checked ? 'checked="checked"' : '').'>';
508 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
510 * @see html_build_priority_select_box()
512 function build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
513 echo html_build_priority_select_box ($name, $checked_val, $nochange);
517 * html_build_priority_select_box() - Return a select box of standard priorities.
518 * The name of this select box is optional and so is the default checked value.
520 * @param string Name of the select box
521 * @param string The value to be checked
522 * @param bool Whether to make 'No Change' selected.
524 function html_build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
526 <select name="<?php echo $name; ?>">
527 <?php if($nochange) { ?>
528 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo _('No Change') ?></option>
530 <option value="1"<?php if ($checked_val=="1") {echo " selected=\"selected\"";} ?>>1 - <?php echo _('Lowest') ?></option>
531 <option value="2"<?php if ($checked_val=="2") {echo " selected=\"selected\"";} ?>>2</option>
532 <option value="3"<?php if ($checked_val=="3") {echo " selected=\"selected\"";} ?>>3</option>
533 <option value="4"<?php if ($checked_val=="4") {echo " selected=\"selected\"";} ?>>4</option>
534 <option value="5"<?php if ($checked_val=="5") {echo " selected=\"selected\"";} ?>>5 - <?php echo _('Highest') ?></option>
541 * html_buildcheckboxarray() - Build an HTML checkbox array.
543 * @param array Options array
544 * @param name Checkbox name
545 * @param array Array of boxes to be pre-checked
547 function html_buildcheckboxarray($options,$name,$checked_array) {
548 $option_count=count($options);
549 $checked_count=count($checked_array);
551 for ($i=1; $i<=$option_count; $i++) {
553 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
554 for ($j=0; $j<$checked_count; $j++) {
555 if ($i == $checked_array[$j]) {
556 echo ' checked="checked"';
559 echo ' /> '.$options[$i];
564 * site_user_header() - everything required to handle security and
565 * add navigation for user pages like /my/ and /account/
567 * @param array Must contain $user_id
569 function site_header($params) {
572 Check to see if active user
573 Check to see if logged in
575 echo $HTML->header($params);
576 echo html_feedback_top($GLOBALS['feedback']);
580 * site_footer() - Show the HTML site footer.
582 * @param array Footer params array
584 function site_footer($params) {
586 $HTML->footer($params);
590 * site_project_header() - everything required to handle
591 * security and state checks for a project web page
593 * @param params array() must contain $toptab and $group
595 function site_project_header($params) {
599 Check to see if active
600 Check to see if project rather than foundry
601 Check to see if private (if private check if user_ismember)
604 $group_id=$params['group'];
606 //get the project object
607 $project =& group_get_object($group_id);
609 if (!$project || !is_object($project)) {
610 exit_error("GROUP PROBLEM","PROBLEM CREATING GROUP OBJECT");
611 } else if ($project->isError()) {
612 exit_error("Group Problem",$project->getErrorMessage());
616 if (!$project->isPublic()) {
617 //if it's a private group, you must be a member of that group
618 session_require(array('group'=>$group_id));
621 //for dead projects must be member of admin project
622 if (!$project->isActive()) {
623 //only SF group can view non-active, non-holding groups
624 session_require(array('group'=>'1'));
627 if (isset($params['title'])){
628 $params['title']=$project->getPublicName().': '.$params['title'];
630 $params['title']=$project->getPublicName();
632 echo $HTML->header($params);
634 if(isset($GLOBALS['feedback'])) {
635 echo html_feedback_top($GLOBALS['feedback']);
637 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
641 * site_project_footer() - currently a simple shim
642 * that should be on every project page, rather than
643 * a direct call to site_footer() or theme_footer()
645 * @param params array() empty
647 function site_project_footer($params) {
650 if(isset($GLOBALS['feedback'])) {
651 echo html_feedback_bottom($GLOBALS['feedback']);
653 echo $HTML->footer($params);
657 * site_user_header() - everything required to handle security and
658 * add navigation for user pages like /my/ and /account/
660 * @param params array() must contain $user_id
662 function site_user_header($params) {
666 Check to see if active user
667 Check to see if logged in
669 echo $HTML->header($params);
670 echo html_feedback_top((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
671 echo ($HTML->beginSubMenu());
672 echo ($HTML->printSubMenu(
673 array(_('My Personal Page'),
674 _('Diary & Notes'),
675 _('Account Maintenance'),
676 _('Register Project')),
681 plugin_hook ("usermenu", false) ;
682 echo ($HTML->endSubMenu());
686 * site_user_footer() - currently a simple shim that should be on every user page,
687 * rather than a direct call to site_footer() or theme_footer()
689 * @param params array() empty
691 function site_user_footer($params) {
694 echo html_feedback_bottom((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
695 echo $HTML->footer($params);
699 * html_clean_hash_string() - Remove noise characters from hex hash string
701 * Thruout SourceForge, URLs with hexadecimal hash string parameters
702 * are being sent via email to request confirmation of user actions.
703 * It was found that some mail clients distort this hash, so we take
704 * special steps to encode it in the way which help to preserve its
705 * recognition. This routine
707 * @param hashstr required hash parameter as received from browser
708 * @return pure hex string
710 function html_clean_hash_string($hashstr) {
712 if (substr($hashstr,0,1)=="_") {
713 $hashstr = substr($hashstr, 1);
716 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
717 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);
724 * html_build_rich_textarea() - Renders textarea control
726 * @param name (string) - the name for the control
727 * @param rows (int) - the rows for the control (number of visible text lines)
728 * @param cols (int) - the cols for the control (visible width in average character widths)
729 * @param text (string) - initial text to be displayed
730 * @param readonly (boolean) - if the text cannot be modified
731 * @return html code for control
733 function html_build_rich_textarea($name,$rows,$cols,$text,$readonly) {
734 return '<textarea name="'.$name.'"'
737 .($readonly ? ' readonly' : ' ').'>'
738 . $text . '</textarea>';
743 // c-file-style: "bsd"