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><FONT COLOR="RED">'.$feedback.'</FONT></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><FONT COLOR="RED">'.$feedback.'</FONT></H3>';
50 * html_a_group() - Turn a group name into a link to that groups summary page.
52 * @param string The group name.
54 function html_a_group($grp) {
55 print '<A /project/?group_id='.$grp.'>' . group_getname($grp) . '</A>';
59 * html_blankimage() - Show the blank spacer image.
61 * @param int The height of the image
62 * @param int The width of the image
64 function html_blankimage($height,$width) {
65 return '<img src="/images/blank.png" width="' . $width . '" height="' . $height . '" alt="">';
69 * html_dbimage() - Show an image that is stored in the database
71 * @param int The id of the image to show
73 function html_dbimage($id, $args=0) {
80 $sql="SELECT width,height,version ".
81 "FROM db_images WHERE id='$id'";
82 $result=db_query($sql);
83 $rows=db_numrows($result);
85 if (!$result || $rows < 1) {
88 return html_image('/dbimage.php?id='.$id.'&v='.db_result($result,0,'version'),db_result($result,0,'width'),db_result($result,0,'height'),$args);
93 * html_image() - Build an image tag of an image contained in $src
95 * @param string The source location of the image
96 * @param int The width of the image
97 * @param int The height of the image
98 * @param array Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
99 * @param bool DEPRECATED
101 function html_image($src,$width,$height,$args,$display=1) {
102 global $sys_images_url,$sys_images_secure_url,$HTML;
103 $s = ((session_issecure()) ? $sys_images_secure_url : $sys_images_url );
104 $return = ('<IMG src="' . $s . $HTML->imgroot . $src .'"');
106 while(list($k,$v) = each($args)) {
107 $return .= ' '.$k.'="'.$v.'"';
110 // ## insert a border tag if there isn't one
111 if (!$args['border']) $return .= (" border=0");
113 // ## add image dimensions
114 $return .= " width=" . $width;
115 $return .= " height=" . $height;
122 * url_image() - Build an image url of an image contained in $src
124 * @param string The source location of the image
126 function url_image($src) {
127 global $sys_images_url;
128 $s = ((session_issecure()) ? 's' : '' );
129 return ('"http'. $s .':' . $sys_images_url . $src .'"');
133 * html_get_language_popup() - Pop up box of supported languages
135 * @param object BaseLanguage object
136 * @param string The title of the popup box
137 * @param string Which element of the box is to be selected
139 function html_get_language_popup ($Language,$title='language_id',$selected='xzxzxz') {
140 $res=$Language->getLanguages();
141 return html_build_select_box ($res,$title,$selected,false);
145 * html_get_timezone_popup() - Pop up box of supported Timezones
146 * Assumes you have included Timezones array file
148 * @param string The title of the popup box
149 * @param string Which element of the box is to be selected
151 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
153 if ($selected == 'xzxzxzx') {
154 $r = file ('/etc/timezone');
155 $selected = str_replace ("\n", '', $r[0]);
157 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
161 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
162 * or value and the array being the text you want displayed.
164 * @param string The name you want assigned to this form element
165 * @param string The value of the item that should be checked
167 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
169 <SELECT NAME="'.$select_name.'">';
173 for ($i=0; $i<$rows; $i++) {
175 $return .= "\n\t\t<OPTION VALUE=\"" . $vals[$i] . "\"";
176 if ($vals[$i] == $checked_val) {
177 $return .= ' SELECTED';
180 $return .= "\n\t\t<OPTION VALUE=\"" . $i .'"';
181 if ($i == $checked_val) {
182 $return .= ' SELECTED';
185 $return .= '>'.$vals[$i].'</OPTION>';
194 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
195 * array being the text you want displayed.
197 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
198 * There must be a related row in users, categories, et , and by default that
199 * row is 100, so almost every pop-up box has 100 as the default
200 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
202 * @param array The ID or value
203 * @param array Text to be displayed
204 * @param string Name to assign to this form element
205 * @param string The item that should be checked
206 * @param bool Whether or not to show the '100 row'
207 * @param string What to call the '100 row' defaults to none
209 function html_build_select_box_from_arrays ($vals,$texts,$select_name,$checked_val='xzxz',$show_100=true,$text_100='None') {
211 <SELECT NAME="'.$select_name.'">';
213 //we don't always want the default 100 row shown
216 <OPTION VALUE="100">'. $text_100 .'</OPTION>';
220 if (count($texts) != $rows) {
221 $return .= 'ERROR - uneven row counts';
224 for ($i=0; $i<$rows; $i++) {
225 // uggh - sorry - don't show the 100 row
226 // if it was shown above, otherwise do show it
227 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
229 <OPTION VALUE="'.$vals[$i].'"';
230 if ($vals[$i] == $checked_val) {
232 $return .= ' SELECTED';
234 $return .= '>'.$texts[$i].'</OPTION>';
238 // If the passed in "checked value" was never "SELECTED"
239 // we want to preserve that value UNLESS that value was 'xzxz', the default value
241 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
243 <OPTION VALUE="'.$checked_val.'" SELECTED>No Change</OPTION>';
251 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
252 * the second column being the text you want displayed.
254 * @param int The result set
255 * @param string Text to be displayed
256 * @param string The item that should be checked
257 * @param bool Whether or not to show the '100 row'
258 * @param string What to call the '100 row'. Defaults to none.
260 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='None') {
261 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);
264 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
265 * and the second column being the text you want displayed.
267 * @param int The result set
268 * @param string Text to be displayed
269 * @param string The item that should be checked
270 * @param int The size of this box
271 * @param bool Whether or not to show the '100 row'
273 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
274 $checked_count=count($checked_array);
276 <SELECT NAME="'.$name.'" MULTIPLE SIZE="'.$size.'">';
279 Put in the default NONE box
282 <OPTION VALUE="100"';
283 for ($j=0; $j<$checked_count; $j++) {
284 if ($checked_array[$j] == '100') {
285 $return .= ' SELECTED';
288 $return .= '>None</OPTION>';
291 $rows=db_numrows($result);
293 for ($i=0; $i<$rows; $i++) {
294 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
296 <OPTION VALUE="'.db_result($result,$i,0).'"';
298 Determine if it's checked
300 $val=db_result($result,$i,0);
301 for ($j=0; $j<$checked_count; $j++) {
302 if ($val == $checked_array[$j]) {
303 $return .= ' SELECTED';
306 $return .= '>'.$val.'-'. substr(db_result($result,$i,1),0,35). '</OPTION>';
315 * html_build_checkbox() - Render checkbox control
317 * @param name - name of control
318 * @param value - value of control
319 * @param checked - true if control should be checked
320 * @return html code for checkbox control
322 function html_build_checkbox($name, $value, $checked) {
323 return '<input type="checkbox" name="'.$name.'"'
324 .' value="'.$value.'"'
325 .($checked ? 'checked' : '').'>';
329 * get_priority_color() - Wrapper for html_get_priority_color().
331 * @see html_get_priority_color()
333 function get_priority_color ($index) {
334 return html_get_priority_color ($index);
338 * html_get_priority_color() - Return the color value for the index that was passed in
339 * (defined in $sys_urlroot/themes/<selected theme>/theme.php)
343 function html_get_priority_color ($index) {
346 /* make sure that index is of appropriate type and range */
347 $index = (int)$index;
350 } else if ($index>9) {
353 //return "prior$index";
354 return $bgpri[$index];
358 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
360 * @see html_build_priority_select_box()
362 function build_priority_select_box ($name='priority', $checked_val='5', $nochange=false) {
363 echo html_build_priority_select_box ($name, $checked_val, $nochange);
367 * html_build_priority_select_box() - Return a select box of standard priorities.
368 * The name of this select box is optional and so is the default checked value.
370 * @param string Name of the select box
371 * @param string The value to be checked
372 * @param bool Whether to make 'No Change' selected.
374 function html_build_priority_select_box ($name='priority', $checked_val='5', $nochange=false) {
376 <SELECT NAME="<?php echo $name; ?>">
377 <?php if($nochange) { ?>
378 <OPTION VALUE="100"<?php if ($nochange) {echo " SELECTED";} ?>>No Change</OPTION>
380 <OPTION VALUE="1"<?php if ($checked_val=="1") {echo " SELECTED";} ?>>1 - Lowest</OPTION>
381 <OPTION VALUE="2"<?php if ($checked_val=="2") {echo " SELECTED";} ?>>2</OPTION>
382 <OPTION VALUE="3"<?php if ($checked_val=="3") {echo " SELECTED";} ?>>3</OPTION>
383 <OPTION VALUE="4"<?php if ($checked_val=="4") {echo " SELECTED";} ?>>4</OPTION>
384 <OPTION VALUE="5"<?php if ($checked_val=="5") {echo " SELECTED";} ?>>5 - Medium</OPTION>
385 <OPTION VALUE="6"<?php if ($checked_val=="6") {echo " SELECTED";} ?>>6</OPTION>
386 <OPTION VALUE="7"<?php if ($checked_val=="7") {echo " SELECTED";} ?>>7</OPTION>
387 <OPTION VALUE="8"<?php if ($checked_val=="8") {echo " SELECTED";} ?>>8</OPTION>
388 <OPTION VALUE="9"<?php if ($checked_val=="9") {echo " SELECTED";} ?>>9 - Highest</OPTION>
395 * html_buildcheckboxarray() - Build an HTML checkbox array.
397 * @param array Options array
398 * @param name Checkbox name
399 * @param array Array of boxes to be pre-checked
401 function html_buildcheckboxarray($options,$name,$checked_array) {
402 $option_count=count($options);
403 $checked_count=count($checked_array);
405 for ($i=1; $i<=$option_count; $i++) {
407 <BR><INPUT type="checkbox" name="'.$name.'" value="'.$i.'"';
408 for ($j=0; $j<$checked_count; $j++) {
409 if ($i == $checked_array[$j]) {
413 echo '> '.$options[$i];
418 * site_user_header() - everything required to handle security and
419 * add navigation for user pages like /my/ and /account/
421 * @param array Must contain $user_id
423 function site_header($params) {
426 Check to see if active user
427 Check to see if logged in
429 echo $HTML->header($params);
430 echo html_feedback_top($GLOBALS['feedback']);
434 * site_footer() - Show the HTML site footer.
436 * @param array Footer params array
438 function site_footer($params) {
440 $HTML->footer($params);
444 * site_project_header() - everything required to handle
445 * security and state checks for a project web page
447 * @param params array() must contain $toptab and $group
449 function site_project_header($params) {
453 Check to see if active
454 Check to see if project rather than foundry
455 Check to see if private (if private check if user_ismember)
458 $group_id=$params['group'];
460 //get the project object
461 $project =& group_get_object($group_id);
463 if (!$project || !is_object($project)) {
464 exit_error("GROUP PROBLEM","PROBLEM CREATING GROUP OBJECT");
465 } else if ($project->isError()) {
466 exit_error("Group Problem",$project->getErrorMessage());
470 if (!$project->isPublic()) {
471 //if it's a private group, you must be a member of that group
472 session_require(array('group'=>$group_id));
475 //for dead projects must be member of admin project
476 if (!$project->isActive()) {
477 //only SF group can view non-active, non-holding groups
478 session_require(array('group'=>'1'));
481 echo $HTML->header($params);
482 echo html_feedback_top($GLOBALS['feedback']);
483 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
487 * site_project_footer() - currently a simple shim
488 * that should be on every project page, rather than
489 * a direct call to site_footer() or theme_footer()
491 * @param params array() empty
493 function site_project_footer($params) {
496 echo html_feedback_bottom($GLOBALS['feedback']);
497 echo $HTML->footer($params);
501 * site_user_header() - everything required to handle security and
502 * add navigation for user pages like /my/ and /account/
504 * @param params array() must contain $user_id
506 function site_user_header($params) {
507 GLOBAL $HTML,$Language;
510 Check to see if active user
511 Check to see if logged in
513 echo $HTML->header($params);
514 echo html_feedback_top($GLOBALS['feedback']);
515 echo ($HTML->subMenu(
516 array($Language->getText('menu','my_personal_page'),
517 $Language->getText('menu','diary_notes'),$Language->getText('menu','account_maintenance')),
518 array('/my/','/my/diary.php','/account/')));
523 * site_user_footer() - currently a simple shim that should be on every user page,
524 * rather than a direct call to site_footer() or theme_footer()
526 * @param params array() empty
528 function site_user_footer($params) {
531 echo html_feedback_bottom($GLOBALS['feedback']);
532 echo $HTML->footer($params);
536 * html_clean_hash_string() - Remove noise characters from hex hash string
538 * Thruout SourceForge, URLs with hexadecimal hash string parameters
539 * are being sent via email to request confirmation of user actions.
540 * It was found that some mail clients distort this hash, so we take
541 * special steps to encode it in the way which help to preserve its
542 * recognition. This routine
544 * @param hashstr required hash parameter as received from browser
545 * @return pure hex string
547 function html_clean_hash_string($hashstr) {
549 if (substr($hashstr,0,1)=="_") {
550 $hashstr = substr($hashstr, 1);
553 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
554 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);