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 '<a href="/users/'.$username.'">'.$username.'</a>' ;
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 object BaseLanguage object.
130 * @param string The title of the popup box.
131 * @param string Which element of the box is to be selected.
132 * @return string The html select box.
134 function html_get_language_popup ($Language,$title='language_id',$selected='xzxz') {
135 $res=$Language->getLanguages();
136 return html_build_select_box ($res,$title,$selected,false);
140 * html_get_theme_popup() - Pop up box of supported themes.
142 * @param string The title of the popup box.
143 * @param string Which element of the box is to be selected.
144 * @return string The html select box.
146 function html_get_theme_popup ($title='theme_id',$selected='xzxz') {
147 $res=db_query("SELECT theme_id, fullname FROM themes WHERE enabled=true");
148 return html_build_select_box($res,$title,$selected,false);
152 * html_get_ccode_popup() - Pop up box of supported country_codes.
154 * @param string The title of the popup box.
155 * @param string Which element of the box is to be selected.
156 * @return string The html select box.
158 function html_get_ccode_popup ($title='ccode',$selected='xzxz') {
159 $res=db_query("SELECT ccode,country_name FROM country_code ORDER BY country_name");
160 return html_build_select_box ($res,$title,$selected,false);
164 * html_get_timezone_popup() - Pop up box of supported Timezones.
165 * Assumes you have included Timezones array file.
167 * @param string The title of the popup box.
168 * @param string Which element of the box is to be selected.
169 * @return string The html select box.
171 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
173 if ($selected == 'xzxzxzx') {
174 $r = file ('/etc/timezone');
175 $selected = str_replace ("\n", '', $r[0]);
177 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
182 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
184 * @param array An array of items to use.
185 * @param string The name you want assigned to this form element.
186 * @param string The value of the item that should be checked.
187 * @param boolean Whether we should swap the keys / names.
188 * @param bool Whether or not to show the '100 row'.
189 * @param string What to call the '100 row' defaults to none.
191 function html_build_select_box_from_assoc ($arr,$select_name,$checked_val='xzxz',$swap=false,$show_100=false,$text_100='None') {
193 $keys=array_values($arr);
194 $vals=array_keys($arr);
196 $vals=array_values($arr);
197 $keys=array_keys($arr);
199 return html_build_select_box_from_arrays ($keys,$vals,$select_name,$checked_val,$show_100,$text_100);
203 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
204 * or value and the array being the text you want displayed.
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.
210 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
212 <select name="'.$select_name.'">';
216 for ($i=0; $i<$rows; $i++) {
218 $return .= "\n\t\t<option value=\"" . $vals[$i] . "\"";
219 if ($vals[$i] == $checked_val) {
220 $return .= ' selected="selected"';
223 $return .= "\n\t\t<option value=\"" . $i .'"';
224 if ($i == $checked_val) {
225 $return .= ' selected="selection"';
228 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
237 * html_build_radio_buttons_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
238 * array being the text you want displayed.
240 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
241 * There must be a related row in users, categories, et , and by default that
242 * row is 100, so almost every pop-up box has 100 as the default
243 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
245 * @param array The ID or value
246 * @param array Text to be displayed
247 * @param string Name to assign to this form element
248 * @param string The item that should be checked
249 * @param bool Whether or not to show the '100 row'
250 * @param string What to call the '100 row' defaults to none
251 * @param bool Whether or not to show the 'Any row'
252 * @param string What to call the 'Any row' defaults to any
254 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') {
256 if ($text_100=='none'){
257 $text_100=$Language->getText('include_html','none');
262 if (count($texts) != $rows) {
263 $return .= 'ERROR - uneven row counts';
266 //we don't always want the default Any row shown
269 <input type="radio" name="'.$select_name.'" value=""'.(($checked_val=='') ? ' checked' : '').'> '. $text_any .'<br />';
271 //we don't always want the default 100 row shown
274 <input type="radio" name="'.$select_name.'" value="100"'.(($checked_val==100) ? ' checked' : '').'> '. $text_100 .'<br />';
277 $checked_found=false;
279 for ($i=0; $i<$rows; $i++) {
280 // uggh - sorry - don't show the 100 row
281 // if it was shown above, otherwise do show it
282 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
284 <input type="radio" name="'.$select_name.'" value="'.$vals[$i].'"';
285 if ((string)$vals[$i] == (string)$checked_val) {
287 $return .= ' checked';
289 $return .= '> '.htmlspecialchars($texts[$i]).'<br />';
293 // If the passed in "checked value" was never "SELECTED"
294 // we want to preserve that value UNLESS that value was 'xzxz', the default value
296 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
298 <input type="radio" value="'.$checked_val.'" checked> '.$Language->getText('include_html','no_change').'<br />';
304 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
305 * array being the text you want displayed.
307 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
308 * There must be a related row in users, categories, et , and by default that
309 * row is 100, so almost every pop-up box has 100 as the default
310 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
312 * @param array The ID or value
313 * @param array Text to be displayed
314 * @param string Name to assign to this form element
315 * @param string The item that should be checked
316 * @param bool Whether or not to show the '100 row'
317 * @param string What to call the '100 row' defaults to none
318 * @param bool Whether or not to show the 'Any row'
319 * @param string What to call the 'Any row' defaults to any
321 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') {
323 if ($text_100=='none'){
324 $text_100=$Language->getText('include_html','none');
329 if (count($texts) != $rows) {
330 $return .= 'ERROR - uneven row counts';
334 <select name="'.$select_name.'">';
336 //we don't always want the default Any row shown
339 <option value=""'.(($checked_val=='') ? ' SELECTED' : '').'>'. $text_any .'</option>';
341 //we don't always want the default 100 row shown
344 <option value="100"'.(($checked_val==100) ? ' SELECTED' : '').'>'. $text_100 .'</option>';
347 $checked_found=false;
349 for ($i=0; $i<$rows; $i++) {
350 // uggh - sorry - don't show the 100 row
351 // if it was shown above, otherwise do show it
352 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
354 <option value="'.$vals[$i].'"';
355 if ($vals[$i] == $checked_val) {
357 $return .= ' selected="selected"';
359 $return .= '>'./*htmlspecialchars(*/$texts[$i]/*)*/.'</option>';
363 // If the passed in "checked value" was never "SELECTED"
364 // we want to preserve that value UNLESS that value was 'xzxz', the default value
366 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
368 <option value="'.$checked_val.'" selected="selected">'.$Language->getText('include_html','no_change').'</option>';
377 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
378 * the second column being the text you want displayed.
380 * @param int The result set
381 * @param string Text to be displayed
382 * @param string The item that should be checked
383 * @param bool Whether or not to show the '100 row'
384 * @param string What to call the '100 row'. Defaults to none.
386 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none') {
388 if ($text_100=='none'){
389 $text_100=$Language->getText('include_html','none');
391 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);
394 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
395 * and the second column being the text you want displayed.
397 * @param int The result set
398 * @param string Text to be displayed
399 * @param string The item that should be checked
400 * @param int The size of this box
401 * @param bool Whether or not to show the '100 row'
403 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
405 $checked_count=count($checked_array);
407 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
410 Put in the default NONE box
413 <option value="100"';
414 for ($j=0; $j<$checked_count; $j++) {
415 if ($checked_array[$j] == '100') {
416 $return .= ' selected="selected"';
419 $return .= '>'.$Language->getText('include_html','none').'</option>';
422 $rows=db_numrows($result);
423 for ($i=0; $i<$rows; $i++) {
424 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
426 <option value="'.db_result($result,$i,0).'"';
428 Determine if it's checked
430 $val=db_result($result,$i,0);
431 for ($j=0; $j<$checked_count; $j++) {
432 if ($val == $checked_array[$j]) {
433 $return .= ' selected="selected"';
436 $return .= '>'. substr(db_result($result,$i,1),0,35). '</option>';
445 * html_build_multiple_select_box_from_arrays() - Takes two arrays and builds a multi-select box
447 * @param array id of the field
448 * @param array Text to be displayed
449 * @param string id of the items selected
450 * @param string The item that should be checked
451 * @param int The size of this box
452 * @param bool Whether or not to show the '100 row'
454 function html_build_multiple_select_box_from_arrays($ids,$texts,$name,$checked_array,$size='8',$show_100=true,$text_100='none') {
456 $checked_count=count($checked_array);
458 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
460 if ($text_100=='none') {
461 $text_100=$Language->getText('include_html','none');
464 Put in the default NONE box
467 <option value="100"';
468 for ($j=0; $j<$checked_count; $j++) {
469 if ($checked_array[$j] == '100') {
470 $return .= ' selected="selected"';
473 $return .= '>'.$text_100.'</option>';
477 for ($i=0; $i<$rows; $i++) {
478 if (( $ids[$i] != '100') || ($ids[$i] == '100' && !$show_100)) {
480 <option value="'.$ids[$i].'"';
482 Determine if it's checked
485 for ($j=0; $j<$checked_count; $j++) {
486 if ($val == $checked_array[$j]) {
487 $return .= ' selected="selected"';
490 $return .= '>'.$texts[$i].' </option>';
499 * html_build_checkbox() - Render checkbox control
501 * @param name - name of control
502 * @param value - value of control
503 * @param checked - true if control should be checked
504 * @return html code for checkbox control
506 function html_build_checkbox($name, $value, $checked) {
507 return '<input type="checkbox" name="'.$name.'"'
508 .' value="'.$value.'"'
509 .($checked ? 'checked="checked"' : '').'>';
513 * html_get_priority_color() - Return the color value for the index that was passed in
514 * (defined in $sys_urlroot/themes/<selected theme>/theme.php)
518 function html_get_priority_color ($index) {
521 /* make sure that index is of appropriate type and range */
522 $index = (int)$index;
525 } else if ($index>5) {
528 //return "prior$index";
529 return $bgpri[$index];
533 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
535 * @see html_build_priority_select_box()
537 function build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
538 echo html_build_priority_select_box ($name, $checked_val, $nochange);
542 * html_build_priority_select_box() - Return a select box of standard priorities.
543 * The name of this select box is optional and so is the default checked value.
545 * @param string Name of the select box
546 * @param string The value to be checked
547 * @param bool Whether to make 'No Change' selected.
549 function html_build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
552 <select name="<?php echo $name; ?>">
553 <?php if($nochange) { ?>
554 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo $Language->getText('include_html','no_change') ?></option>
556 <option value="1"<?php if ($checked_val=="1") {echo " selected=\"selected\"";} ?>>1 - <?php echo $Language->getText('include_html','priority_lowest') ?></option>
557 <option value="2"<?php if ($checked_val=="2") {echo " selected=\"selected\"";} ?>>2</option>
558 <option value="3"<?php if ($checked_val=="3") {echo " selected=\"selected\"";} ?>>3</option>
559 <option value="4"<?php if ($checked_val=="4") {echo " selected=\"selected\"";} ?>>4</option>
560 <option value="5"<?php if ($checked_val=="5") {echo " selected=\"selected\"";} ?>>5 - <?php echo $Language->getText('include_html','priority_highest') ?></option>
567 * html_buildcheckboxarray() - Build an HTML checkbox array.
569 * @param array Options array
570 * @param name Checkbox name
571 * @param array Array of boxes to be pre-checked
573 function html_buildcheckboxarray($options,$name,$checked_array) {
574 $option_count=count($options);
575 $checked_count=count($checked_array);
577 for ($i=1; $i<=$option_count; $i++) {
579 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
580 for ($j=0; $j<$checked_count; $j++) {
581 if ($i == $checked_array[$j]) {
582 echo ' checked="checked"';
585 echo ' /> '.$options[$i];
590 * site_user_header() - everything required to handle security and
591 * add navigation for user pages like /my/ and /account/
593 * @param array Must contain $user_id
595 function site_header($params) {
598 Check to see if active user
599 Check to see if logged in
601 echo $HTML->header($params);
602 echo html_feedback_top($GLOBALS['feedback']);
606 * site_footer() - Show the HTML site footer.
608 * @param array Footer params array
610 function site_footer($params) {
612 $HTML->footer($params);
616 * site_project_header() - everything required to handle
617 * security and state checks for a project web page
619 * @param params array() must contain $toptab and $group
621 function site_project_header($params) {
625 Check to see if active
626 Check to see if project rather than foundry
627 Check to see if private (if private check if user_ismember)
630 $group_id=$params['group'];
632 //get the project object
633 $project =& group_get_object($group_id);
635 if (!$project || !is_object($project)) {
636 exit_error("GROUP PROBLEM","PROBLEM CREATING GROUP OBJECT");
637 } else if ($project->isError()) {
638 exit_error("Group Problem",$project->getErrorMessage());
642 if (!$project->isPublic()) {
643 //if it's a private group, you must be a member of that group
644 session_require(array('group'=>$group_id));
647 //for dead projects must be member of admin project
648 if (!$project->isActive()) {
649 //only SF group can view non-active, non-holding groups
650 session_require(array('group'=>'1'));
653 $params['title']=$project->getPublicName().': '.$params['title'];
655 echo $HTML->header($params);
657 if(isset($GLOBALS['feedback'])) {
658 echo html_feedback_top($GLOBALS['feedback']);
660 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
664 * site_project_footer() - currently a simple shim
665 * that should be on every project page, rather than
666 * a direct call to site_footer() or theme_footer()
668 * @param params array() empty
670 function site_project_footer($params) {
673 if(isset($GLOBALS['feedback'])) {
674 echo html_feedback_bottom($GLOBALS['feedback']);
676 echo $HTML->footer($params);
680 * site_user_header() - everything required to handle security and
681 * add navigation for user pages like /my/ and /account/
683 * @param params array() must contain $user_id
685 function site_user_header($params) {
686 GLOBAL $HTML,$Language;
689 Check to see if active user
690 Check to see if logged in
692 echo $HTML->header($params);
693 echo html_feedback_top((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
694 echo ($HTML->beginSubMenu());
695 echo ($HTML->printSubMenu(
696 array($Language->getText('menu','my_personal_page'),
697 $Language->getText('menu','diary_notes'),
698 $Language->getText('menu','account_maintenance'),
699 $Language->getText('menu','register_project')),
704 plugin_hook ("usermenu", false) ;
705 echo ($HTML->endSubMenu());
709 * site_user_footer() - currently a simple shim that should be on every user page,
710 * rather than a direct call to site_footer() or theme_footer()
712 * @param params array() empty
714 function site_user_footer($params) {
717 echo html_feedback_bottom((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
718 echo $HTML->footer($params);
722 * html_clean_hash_string() - Remove noise characters from hex hash string
724 * Thruout SourceForge, URLs with hexadecimal hash string parameters
725 * are being sent via email to request confirmation of user actions.
726 * It was found that some mail clients distort this hash, so we take
727 * special steps to encode it in the way which help to preserve its
728 * recognition. This routine
730 * @param hashstr required hash parameter as received from browser
731 * @return pure hex string
733 function html_clean_hash_string($hashstr) {
735 if (substr($hashstr,0,1)=="_") {
736 $hashstr = substr($hashstr, 1);
739 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
740 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);
747 * html_build_rich_textarea() - Renders textarea control
749 * @param name (string) - the name for the control
750 * @param rows (int) - the rows for the control (number of visible text lines)
751 * @param cols (int) - the cols for the control (visible width in average character widths)
752 * @param text (string) - initial text to be displayed
753 * @param readonly (boolean) - if the text cannot be modified
754 * @return html code for control
756 function html_build_rich_textarea($name,$rows,$cols,$text,$readonly) {
757 return '<textarea name="'.$name.'"'
760 .($readonly ? ' readonly' : ' ').'>'
761 . $text . '</textarea>';