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) {
21 <h3><span style="color:red">'.$feedback.'</span></h3>';
25 * make_user_link() - Make a username reference into a link to that users User page on SF.
27 * @param string The username of the user to link.
29 function make_user_link($username) {
30 if (!strcasecmp($username,'Nobody') || !strcasecmp($username,'None')) {
33 return '<a href="/users/'.$username.'">'.$username.'</a>' ;
38 * html_feedback_top() - Show the feedback output at the bottom of the page.
40 * @param string The feedback.
42 function html_feedback_bottom($feedback) {
46 <h3><span style="color:red">'.$feedback.'</span></h3>';
50 * html_blankimage() - Show the blank spacer image.
52 * @param int The height of the image
53 * @param int The width of the image
55 function html_blankimage($height,$width) {
56 return '<img src="/images/blank.png" width="' . $width . '" height="' . $height . '" alt="" />';
60 * html_dbimage() - Show an image that is stored in the database
62 * @param int The id of the image to show
64 function html_dbimage($id, $args=0) {
71 $sql="SELECT width,height,version ".
72 "FROM db_images WHERE id='$id'";
73 $result=db_query($sql);
74 $rows=db_numrows($result);
76 if (!$result || $rows < 1) {
79 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);
84 * html_abs_image() - Show an image given an absolute URL.
87 * @param int width of the image
88 * @param int height of the image
89 * @param array Any <img> tag parameters (i.e. 'border', 'alt', etc...)
91 function html_abs_image($url, $width, $height, $args) {
92 $return = ('<img src="' . $url . '"');
94 while(list($k,$v) = each($args)) {
95 $return .= ' '.$k.'="'.$v.'"';
98 // ## insert a border tag if there isn't one
99 if (!isset($args['border'])) {
100 $return .= ' border="0"';
103 if (!isset($args['alt'])) {
104 $return .= ' alt=""';
107 // ## add image dimensions
108 $return .= " width=\"" . $width . "\"";
109 $return .= " height=\"" . $height . "\"";
116 * html_image() - Build an image tag of an image contained in $src
118 * @param string The source location of the image
119 * @param int The width of the image
120 * @param int The height of the image
121 * @param array Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
122 * @param bool DEPRECATED
124 function html_image($src,$width,$height,$args,$display=1) {
125 global $sys_images_url,$sys_images_secure_url,$HTML;
126 $s = ((session_issecure()) ? $sys_images_secure_url : $sys_images_url );
127 return html_abs_image($s.$HTML->imgroot.$src, $width, $height, $args);
131 * html_get_language_popup() - Pop up box of supported languages.
133 * @param object BaseLanguage object.
134 * @param string The title of the popup box.
135 * @param string Which element of the box is to be selected.
136 * @return string The html select box.
138 function html_get_language_popup ($Language,$title='language_id',$selected='xzxz') {
139 $res=$Language->getLanguages();
140 return html_build_select_box ($res,$title,$selected,false);
144 * html_get_theme_popup() - Pop up box of supported themes.
146 * @param string The title of the popup box.
147 * @param string Which element of the box is to be selected.
148 * @return string The html select box.
150 function html_get_theme_popup ($title='theme_id',$selected='xzxz') {
151 $res=db_query("SELECT theme_id, fullname FROM themes WHERE enabled=true");
152 return html_build_select_box($res,$title,$selected,false);
156 * html_get_ccode_popup() - Pop up box of supported country_codes.
158 * @param string The title of the popup box.
159 * @param string Which element of the box is to be selected.
160 * @return string The html select box.
162 function html_get_ccode_popup ($title='ccode',$selected='xzxz') {
163 $res=db_query("SELECT ccode,country_name FROM country_code ORDER BY country_name");
164 return html_build_select_box ($res,$title,$selected,false);
168 * html_get_timezone_popup() - Pop up box of supported Timezones.
169 * Assumes you have included Timezones array file.
171 * @param string The title of the popup box.
172 * @param string Which element of the box is to be selected.
173 * @return string The html select box.
175 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
177 if ($selected == 'xzxzxzx') {
178 $r = file ('/etc/timezone');
179 $selected = str_replace ("\n", '', $r[0]);
181 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
186 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
188 * @param array An array of items to use.
189 * @param string The name you want assigned to this form element.
190 * @param string The value of the item that should be checked.
191 * @param boolean Whether we should swap the keys / names.
192 * @param bool Whether or not to show the '100 row'.
193 * @param string What to call the '100 row' defaults to none.
195 function html_build_select_box_from_assoc ($arr,$select_name,$checked_val='xzxz',$swap=false,$show_100=false,$text_100='None') {
197 $keys=array_values($arr);
198 $vals=array_keys($arr);
200 $vals=array_values($arr);
201 $keys=array_keys($arr);
203 return html_build_select_box_from_arrays ($keys,$vals,$select_name,$checked_val,$show_100,$text_100);
207 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
208 * or value and the array being the text you want displayed.
210 * @param array An array of items to use.
211 * @param string The name you want assigned to this form element.
212 * @param string The value of the item that should be checked.
214 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
216 <select name="'.$select_name.'">';
220 for ($i=0; $i<$rows; $i++) {
222 $return .= "\n\t\t<option value=\"" . $vals[$i] . "\"";
223 if ($vals[$i] == $checked_val) {
224 $return .= ' selected="selected"';
227 $return .= "\n\t\t<option value=\"" . $i .'"';
228 if ($i == $checked_val) {
229 $return .= ' selected="selection"';
232 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
241 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
242 * array being the text you want displayed.
244 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
245 * There must be a related row in users, categories, et , and by default that
246 * row is 100, so almost every pop-up box has 100 as the default
247 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
249 * @param array The ID or value
250 * @param array Text to be displayed
251 * @param string Name to assign to this form element
252 * @param string The item that should be checked
253 * @param bool Whether or not to show the '100 row'
254 * @param string What to call the '100 row' defaults to none
256 function html_build_select_box_from_arrays ($vals,$texts,$select_name,$checked_val='xzxz',$show_100=true,$text_100='none') {
258 if ($text_100=='none'){
259 $text_100=$Language->getText('include_html','none');
264 <select name="'.$select_name.'">';
266 //we don't always want the default 100 row shown
269 <option value="100">'. $text_100 .'</option>';
273 if (count($texts) != $rows) {
274 $return .= 'ERROR - uneven row counts';
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 <option value="'.$vals[$i].'"';
285 if ($vals[$i] == $checked_val) {
287 $return .= ' selected="selected"';
289 $return .= '>'.htmlspecialchars($texts[$i]).'</option>';
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 <option value="'.$checked_val.'" selected="selected">'.$Language->getText('include_html','no_change').'</option>';
307 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
308 * the second column being the text you want displayed.
310 * @param int The result set
311 * @param string Text to be displayed
312 * @param string The item that should be checked
313 * @param bool Whether or not to show the '100 row'
314 * @param string What to call the '100 row'. Defaults to none.
316 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none') {
318 if ($text_100=='none'){
319 $text_100=$Language->getText('include_html','none');
321 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);
324 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
325 * and the second column being the text you want displayed.
327 * @param int The result set
328 * @param string Text to be displayed
329 * @param string The item that should be checked
330 * @param int The size of this box
331 * @param bool Whether or not to show the '100 row'
333 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
335 $checked_count=count($checked_array);
337 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
340 Put in the default NONE box
343 <option value="100"';
344 for ($j=0; $j<$checked_count; $j++) {
345 if ($checked_array[$j] == '100') {
346 $return .= ' selected="selected"';
349 $return .= '>'.$Language->getText('include_html','none').'</option>';
352 $rows=db_numrows($result);
353 for ($i=0; $i<$rows; $i++) {
354 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
356 <option value="'.db_result($result,$i,0).'"';
358 Determine if it's checked
360 $val=db_result($result,$i,0);
361 for ($j=0; $j<$checked_count; $j++) {
362 if ($val == $checked_array[$j]) {
363 $return .= ' selected="selected"';
366 $return .= '>'.$val.'-'. substr(db_result($result,$i,1),0,35). '</option>';
375 * html_build_multiple_select_box_from_arrays() - Takes two arrays and builds a multi-select box
377 * @param array id of the field
378 * @param array Text to be displayed
379 * @param string id of the items selected
380 * @param string The item that should be checked
381 * @param int The size of this box
382 * @param bool Whether or not to show the '100 row'
384 function html_build_multiple_select_box_from_arrays($ids,$texts,$name,$checked_array,$size='8',$show_100=true) {
386 $checked_count=count($checked_array);
388 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
391 Put in the default NONE box
394 <option value="100"';
395 for ($j=0; $j<$checked_count; $j++) {
396 if ($checked_array[$j] == '100') {
397 $return .= ' selected="selected"';
400 $return .= '>'.$Language->getText('include_html','none').'</option>';
404 for ($i=0; $i<$rows; $i++) {
405 if (( $ids[$i] != '100') || ($ids[$i] == '100' && !$show_100)) {
407 <option value="'.$ids[$i].'"';
409 Determine if it's checked
412 for ($j=0; $j<$checked_count; $j++) {
413 if ($val == $checked_array[$j]) {
414 $return .= ' selected="selected"';
417 $return .= '>'.$ids[$i].'-'.$texts[$i].' </option>';
426 * html_build_checkbox() - Render checkbox control
428 * @param name - name of control
429 * @param value - value of control
430 * @param checked - true if control should be checked
431 * @return html code for checkbox control
433 function html_build_checkbox($name, $value, $checked) {
434 return '<input type="checkbox" name="'.$name.'"'
435 .' value="'.$value.'"'
436 .($checked ? 'checked="checked"' : '').'>';
440 * html_get_priority_color() - Return the color value for the index that was passed in
441 * (defined in $sys_urlroot/themes/<selected theme>/theme.php)
445 function html_get_priority_color ($index) {
448 /* make sure that index is of appropriate type and range */
449 $index = (int)$index;
452 } else if ($index>5) {
455 //return "prior$index";
456 return $bgpri[$index];
460 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
462 * @see html_build_priority_select_box()
464 function build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
465 echo html_build_priority_select_box ($name, $checked_val, $nochange);
469 * html_build_priority_select_box() - Return a select box of standard priorities.
470 * The name of this select box is optional and so is the default checked value.
472 * @param string Name of the select box
473 * @param string The value to be checked
474 * @param bool Whether to make 'No Change' selected.
476 function html_build_priority_select_box ($name='priority', $checked_val='3', $nochange=false) {
479 <select name="<?php echo $name; ?>">
480 <?php if($nochange) { ?>
481 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo $Language->getText('include_html','no_change') ?></option>
483 <option value="1"<?php if ($checked_val=="1") {echo " selected=\"selected\"";} ?>>1 - <?php echo $Language->getText('include_html','priority_lowest') ?></option>
484 <option value="2"<?php if ($checked_val=="2") {echo " selected=\"selected\"";} ?>>2</option>
485 <option value="3"<?php if ($checked_val=="3") {echo " selected=\"selected\"";} ?>>3</option>
486 <option value="4"<?php if ($checked_val=="4") {echo " selected=\"selected\"";} ?>>4</option>
487 <option value="5"<?php if ($checked_val=="5") {echo " selected=\"selected\"";} ?>>5 - <?php echo $Language->getText('include_html','priority_highest') ?></option>
494 * html_buildcheckboxarray() - Build an HTML checkbox array.
496 * @param array Options array
497 * @param name Checkbox name
498 * @param array Array of boxes to be pre-checked
500 function html_buildcheckboxarray($options,$name,$checked_array) {
501 $option_count=count($options);
502 $checked_count=count($checked_array);
504 for ($i=1; $i<=$option_count; $i++) {
506 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
507 for ($j=0; $j<$checked_count; $j++) {
508 if ($i == $checked_array[$j]) {
509 echo ' checked="checked"';
512 echo ' /> '.$options[$i];
517 * site_user_header() - everything required to handle security and
518 * add navigation for user pages like /my/ and /account/
520 * @param array Must contain $user_id
522 function site_header($params) {
525 Check to see if active user
526 Check to see if logged in
528 echo $HTML->header($params);
529 echo html_feedback_top($GLOBALS['feedback']);
533 * site_footer() - Show the HTML site footer.
535 * @param array Footer params array
537 function site_footer($params) {
539 $HTML->footer($params);
543 * site_project_header() - everything required to handle
544 * security and state checks for a project web page
546 * @param params array() must contain $toptab and $group
548 function site_project_header($params) {
552 Check to see if active
553 Check to see if project rather than foundry
554 Check to see if private (if private check if user_ismember)
557 $group_id=$params['group'];
559 //get the project object
560 $project =& group_get_object($group_id);
562 if (!$project || !is_object($project)) {
563 exit_error("GROUP PROBLEM","PROBLEM CREATING GROUP OBJECT");
564 } else if ($project->isError()) {
565 exit_error("Group Problem",$project->getErrorMessage());
569 if (!$project->isPublic()) {
570 //if it's a private group, you must be a member of that group
571 session_require(array('group'=>$group_id));
574 //for dead projects must be member of admin project
575 if (!$project->isActive()) {
576 //only SF group can view non-active, non-holding groups
577 session_require(array('group'=>'1'));
580 $params['title']=$project->getPublicName().': '.$params['title'];
582 echo $HTML->header($params);
584 if(isset($GLOBALS['feedback'])) {
585 echo html_feedback_top($GLOBALS['feedback']);
587 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
591 * site_project_footer() - currently a simple shim
592 * that should be on every project page, rather than
593 * a direct call to site_footer() or theme_footer()
595 * @param params array() empty
597 function site_project_footer($params) {
600 if(isset($GLOBALS['feedback'])) {
601 echo html_feedback_bottom($GLOBALS['feedback']);
603 echo $HTML->footer($params);
607 * site_user_header() - everything required to handle security and
608 * add navigation for user pages like /my/ and /account/
610 * @param params array() must contain $user_id
612 function site_user_header($params) {
613 GLOBAL $HTML,$Language;
616 Check to see if active user
617 Check to see if logged in
619 echo $HTML->header($params);
620 echo html_feedback_top((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
621 echo ($HTML->BeginSubMenu());
622 echo ($HTML->PrintSubMenu(
623 array($Language->getText('menu','my_personal_page'),
624 $Language->getText('menu','diary_notes'),
625 $Language->getText('menu','account_maintenance'),
626 $Language->getText('menu','register_project')),
631 plugin_hook ("usermenu", false) ;
632 echo ($HTML->EndSubMenu());
636 * site_user_footer() - currently a simple shim that should be on every user page,
637 * rather than a direct call to site_footer() or theme_footer()
639 * @param params array() empty
641 function site_user_footer($params) {
644 echo html_feedback_bottom((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
645 echo $HTML->footer($params);
649 * html_clean_hash_string() - Remove noise characters from hex hash string
651 * Thruout SourceForge, URLs with hexadecimal hash string parameters
652 * are being sent via email to request confirmation of user actions.
653 * It was found that some mail clients distort this hash, so we take
654 * special steps to encode it in the way which help to preserve its
655 * recognition. This routine
657 * @param hashstr required hash parameter as received from browser
658 * @return pure hex string
660 function html_clean_hash_string($hashstr) {
662 if (substr($hashstr,0,1)=="_") {
663 $hashstr = substr($hashstr, 1);
666 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
667 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);