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)
93 $return = ('<img src="' . $url . '"');
95 while(list($k,$v) = each($args)) {
96 $return .= ' '.$k.'="'.$v.'"';
99 // ## insert a border tag if there isn't one
100 if (!isset($args['border'])) {
101 $return .= ' border="0"';
104 if (!isset($args['alt'])) {
105 $return .= ' alt=""';
108 // ## add image dimensions
109 $return .= " width=\"" . $width . "\"";
110 $return .= " height=\"" . $height . "\"";
117 * html_image() - Build an image tag of an image contained in $src
119 * @param string The source location of the image
120 * @param int The width of the image
121 * @param int The height of the image
122 * @param array Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
123 * @param bool DEPRECATED
125 function html_image($src,$width,$height,$args,$display=1) {
126 global $sys_images_url,$sys_images_secure_url,$HTML;
127 $s = ((session_issecure()) ? $sys_images_secure_url : $sys_images_url );
128 return html_abs_image($s.$HTML->imgroot.$src, $width, $height, $args);
132 * html_get_language_popup() - Pop up box of supported languages.
134 * @param object BaseLanguage object.
135 * @param string The title of the popup box.
136 * @param string Which element of the box is to be selected.
137 * @return string The html select box.
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_ccode_popup() - Pop up box of supported country_codes.
147 * @param string The title of the popup box.
148 * @param string Which element of the box is to be selected.
149 * @return string The html select box.
151 function html_get_ccode_popup ($title='ccode',$selected='xzxz') {
152 $res=db_query("SELECT ccode,country_name FROM country_code ORDER BY ccode");
153 return html_build_select_box ($res,$title,$selected,false);
157 * html_get_timezone_popup() - Pop up box of supported Timezones.
158 * Assumes you have included Timezones array file.
160 * @param string The title of the popup box.
161 * @param string Which element of the box is to be selected.
162 * @return string The html select box.
164 function html_get_timezone_popup ($title='timezone',$selected='xzxz') {
166 if ($selected == 'xzxzxzx') {
167 $r = file ('/etc/timezone');
168 $selected = str_replace ("\n", '', $r[0]);
170 return html_build_select_box_from_arrays ($TZs,$TZs,$title,$selected,false);
175 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
177 * @param array An array of items to use.
178 * @param string The name you want assigned to this form element.
179 * @param string The value of the item that should be checked.
180 * @param boolean Whether we should swap the keys / names.
181 * @param bool Whether or not to show the '100 row'.
182 * @param string What to call the '100 row' defaults to none.
184 function html_build_select_box_from_assoc ($arr,$select_name,$checked_val='xzxz',$swap=false,$show_100=false,$text_100='None') {
186 $keys=array_values($arr);
187 $vals=array_keys($arr);
189 $vals=array_values($arr);
190 $keys=array_keys($arr);
192 return html_build_select_box_from_arrays ($keys,$vals,$select_name,$checked_val,$show_100,$text_100);
196 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
197 * or value and the array being the text you want displayed.
199 * @param array An array of items to use.
200 * @param string The name you want assigned to this form element.
201 * @param string The value of the item that should be checked.
203 function html_build_select_box_from_array ($vals,$select_name,$checked_val='xzxz',$samevals = 0) {
205 <select name="'.$select_name.'">';
209 for ($i=0; $i<$rows; $i++) {
211 $return .= "\n\t\t<option value=\"" . $vals[$i] . "\"";
212 if ($vals[$i] == $checked_val) {
213 $return .= ' selected="selected"';
216 $return .= "\n\t\t<option value=\"" . $i .'"';
217 if ($i == $checked_val) {
218 $return .= ' selected="selection"';
221 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
230 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
231 * array being the text you want displayed.
233 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
234 * There must be a related row in users, categories, et , and by default that
235 * row is 100, so almost every pop-up box has 100 as the default
236 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
238 * @param array The ID or value
239 * @param array Text to be displayed
240 * @param string Name to assign to this form element
241 * @param string The item that should be checked
242 * @param bool Whether or not to show the '100 row'
243 * @param string What to call the '100 row' defaults to none
245 function html_build_select_box_from_arrays ($vals,$texts,$select_name,$checked_val='xzxz',$show_100=true,$text_100='none') {
247 if ($text_100=='none'){
248 $text_100=$Language->getText('include_html','none');
253 <select name="'.$select_name.'">';
255 //we don't always want the default 100 row shown
258 <option value="100">'. $text_100 .'</option>';
262 if (count($texts) != $rows) {
263 $return .= 'ERROR - uneven row counts';
266 for ($i=0; $i<$rows; $i++) {
267 // uggh - sorry - don't show the 100 row
268 // if it was shown above, otherwise do show it
269 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
271 <option value="'.$vals[$i].'"';
272 if ($vals[$i] == $checked_val) {
274 $return .= ' selected="selected"';
276 $return .= '>'.htmlspecialchars($texts[$i]).'</option>';
280 // If the passed in "checked value" was never "SELECTED"
281 // we want to preserve that value UNLESS that value was 'xzxz', the default value
283 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
285 <option value="'.$checked_val.'" selected="selected">'.$Language->getText('include_html','no_change').'</option>';
294 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
295 * the second column being the text you want displayed.
297 * @param int The result set
298 * @param string Text to be displayed
299 * @param string The item that should be checked
300 * @param bool Whether or not to show the '100 row'
301 * @param string What to call the '100 row'. Defaults to none.
303 function html_build_select_box ($result, $name, $checked_val="xzxz",$show_100=true,$text_100='none') {
305 if ($text_100=='none'){
306 $text_100=$Language->getText('include_html','none');
308 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);
311 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
312 * and the second column being the text you want displayed.
314 * @param int The result set
315 * @param string Text to be displayed
316 * @param string The item that should be checked
317 * @param int The size of this box
318 * @param bool Whether or not to show the '100 row'
320 function html_build_multiple_select_box ($result,$name,$checked_array,$size='8',$show_100=true) {
322 $checked_count=count($checked_array);
324 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
327 Put in the default NONE box
330 <option value="100"';
331 for ($j=0; $j<$checked_count; $j++) {
332 if ($checked_array[$j] == '100') {
333 $return .= ' selected="selected"';
336 $return .= '>'.$Language->getText('include_html','none').'</option>';
339 $rows=db_numrows($result);
341 for ($i=0; $i<$rows; $i++) {
342 if ((db_result($result,$i,0) != '100') || (db_result($result,$i,0) == '100' && !$show_100)) {
344 <option value="'.db_result($result,$i,0).'"';
346 Determine if it's checked
348 $val=db_result($result,$i,0);
349 for ($j=0; $j<$checked_count; $j++) {
350 if ($val == $checked_array[$j]) {
351 $return .= ' selected="selected"';
354 $return .= '>'.$val.'-'. substr(db_result($result,$i,1),0,35). '</option>';
363 * html_build_checkbox() - Render checkbox control
365 * @param name - name of control
366 * @param value - value of control
367 * @param checked - true if control should be checked
368 * @return html code for checkbox control
370 function html_build_checkbox($name, $value, $checked) {
371 return '<input type="checkbox" name="'.$name.'"'
372 .' value="'.$value.'"'
373 .($checked ? 'checked="checked"' : '').'>';
377 * html_get_priority_color() - Return the color value for the index that was passed in
378 * (defined in $sys_urlroot/themes/<selected theme>/theme.php)
382 function html_get_priority_color ($index) {
385 /* make sure that index is of appropriate type and range */
386 $index = (int)$index;
389 } else if ($index>9) {
392 //return "prior$index";
393 return $bgpri[$index];
397 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
399 * @see html_build_priority_select_box()
401 function build_priority_select_box ($name='priority', $checked_val='5', $nochange=false) {
402 echo html_build_priority_select_box ($name, $checked_val, $nochange);
406 * html_build_priority_select_box() - Return a select box of standard priorities.
407 * The name of this select box is optional and so is the default checked value.
409 * @param string Name of the select box
410 * @param string The value to be checked
411 * @param bool Whether to make 'No Change' selected.
413 function html_build_priority_select_box ($name='priority', $checked_val='5', $nochange=false) {
416 <select name="<?php echo $name; ?>">
417 <?php if($nochange) { ?>
418 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo $Language->getText('include_html','no_change') ?></option>
420 <option value="1"<?php if ($checked_val=="1") {echo " selected=\"selected\"";} ?>>1 - <?php echo $Language->getText('include_html','priority_lowest') ?></option>
421 <option value="2"<?php if ($checked_val=="2") {echo " selected=\"selected\"";} ?>>2</option>
422 <option value="3"<?php if ($checked_val=="3") {echo " selected=\"selected\"";} ?>>3</option>
423 <option value="4"<?php if ($checked_val=="4") {echo " selected=\"selected\"";} ?>>4</option>
424 <option value="5"<?php if ($checked_val=="5") {echo " selected=\"selected\"";} ?>>5 - <?php echo $Language->getText('include_html','priority_medium') ?></option>
425 <option value="6"<?php if ($checked_val=="6") {echo " selected=\"selected\"";} ?>>6</option>
426 <option value="7"<?php if ($checked_val=="7") {echo " selected=\"selected\"";} ?>>7</option>
427 <option value="8"<?php if ($checked_val=="8") {echo " selected=\"selected\"";} ?>>8</option>
428 <option value="9"<?php if ($checked_val=="9") {echo " selected=\"selected\"";} ?>>9 - <?php echo $Language->getText('include_html','priority_highest') ?></option>
435 * html_buildcheckboxarray() - Build an HTML checkbox array.
437 * @param array Options array
438 * @param name Checkbox name
439 * @param array Array of boxes to be pre-checked
441 function html_buildcheckboxarray($options,$name,$checked_array) {
442 $option_count=count($options);
443 $checked_count=count($checked_array);
445 for ($i=1; $i<=$option_count; $i++) {
447 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
448 for ($j=0; $j<$checked_count; $j++) {
449 if ($i == $checked_array[$j]) {
450 echo ' checked="checked"';
453 echo ' /> '.$options[$i];
458 * site_user_header() - everything required to handle security and
459 * add navigation for user pages like /my/ and /account/
461 * @param array Must contain $user_id
463 function site_header($params) {
466 Check to see if active user
467 Check to see if logged in
469 echo $HTML->header($params);
470 echo html_feedback_top($GLOBALS['feedback']);
474 * site_footer() - Show the HTML site footer.
476 * @param array Footer params array
478 function site_footer($params) {
480 $HTML->footer($params);
484 * site_project_header() - everything required to handle
485 * security and state checks for a project web page
487 * @param params array() must contain $toptab and $group
489 function site_project_header($params) {
493 Check to see if active
494 Check to see if project rather than foundry
495 Check to see if private (if private check if user_ismember)
498 $group_id=$params['group'];
500 //get the project object
501 $project =& group_get_object($group_id);
503 if (!$project || !is_object($project)) {
504 exit_error("GROUP PROBLEM","PROBLEM CREATING GROUP OBJECT");
505 } else if ($project->isError()) {
506 exit_error("Group Problem",$project->getErrorMessage());
510 if (!$project->isPublic()) {
511 //if it's a private group, you must be a member of that group
512 session_require(array('group'=>$group_id));
515 //for dead projects must be member of admin project
516 if (!$project->isActive()) {
517 //only SF group can view non-active, non-holding groups
518 session_require(array('group'=>'1'));
521 echo $HTML->header($params);
523 if(isset($GLOBALS['feedback'])) {
524 echo html_feedback_top($GLOBALS['feedback']);
526 // echo $HTML->project_tabs($params['toptab'],$params['group'],$params['tabtext']);
530 * site_project_footer() - currently a simple shim
531 * that should be on every project page, rather than
532 * a direct call to site_footer() or theme_footer()
534 * @param params array() empty
536 function site_project_footer($params) {
539 if(isset($GLOBALS['feedback'])) {
540 echo html_feedback_bottom($GLOBALS['feedback']);
542 echo $HTML->footer($params);
546 * site_user_header() - everything required to handle security and
547 * add navigation for user pages like /my/ and /account/
549 * @param params array() must contain $user_id
551 function site_user_header($params) {
552 GLOBAL $HTML,$Language;
555 Check to see if active user
556 Check to see if logged in
558 echo $HTML->header($params);
559 echo html_feedback_top((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
560 echo ($HTML->BeginSubMenu());
561 echo ($HTML->PrintSubMenu(
562 array($Language->getText('menu','my_personal_page'),
563 $Language->getText('menu','diary_notes'),
564 $Language->getText('menu','account_maintenance'),
565 $Language->getText('menu','register_project')),
570 plugin_hook ("usermenu", false) ;
571 echo ($HTML->EndSubMenu());
575 * site_user_footer() - currently a simple shim that should be on every user page,
576 * rather than a direct call to site_footer() or theme_footer()
578 * @param params array() empty
580 function site_user_footer($params) {
583 echo html_feedback_bottom((isset($GLOBALS['feedback']) ? $GLOBALS['feedback'] : ''));
584 echo $HTML->footer($params);
588 * html_clean_hash_string() - Remove noise characters from hex hash string
590 * Thruout SourceForge, URLs with hexadecimal hash string parameters
591 * are being sent via email to request confirmation of user actions.
592 * It was found that some mail clients distort this hash, so we take
593 * special steps to encode it in the way which help to preserve its
594 * recognition. This routine
596 * @param hashstr required hash parameter as received from browser
597 * @return pure hex string
599 function html_clean_hash_string($hashstr) {
601 if (substr($hashstr,0,1)=="_") {
602 $hashstr = substr($hashstr, 1);
605 if (substr($hashstr, strlen($hashstr)-1, 1)==">") {
606 $hashstr = substr($hashstr, 0, strlen($hashstr)-1);