5 * Copyright 1999-2001 (c) VA Linux Systems
6 * Copyright 2010 (c) FusionForge Team
7 * Copyright (C) 2010-2012 Alain Peyrat - Alcatel-Lucent
8 * Copyright 2011, Franck Villaume - Capgemini
9 * Copyright 2011-2013, Franck Villaume - TrivialDev
10 * Copyright © 2011, 2012
11 * Thorsten “mirabilos” Glaser <t.glaser@tarent.de>
13 * This file is part of FusionForge. FusionForge is free software;
14 * you can redistribute it and/or modify it under the terms of the
15 * GNU General Public License as published by the Free Software
16 * Foundation; either version 2 of the Licence, or (at your option)
19 * FusionForge is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License along
25 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 require_once $gfcommon.'include/minijson.php';
32 * html_generic_fileheader() - Output <html><head> and <meta/> inside.
34 * @param $title string
35 * Mandatory content of <title> attribute, will be HTML-secured
38 function html_generic_fileheader($title) {
42 throw new Exception('A title is mandatory in XHTML!');
45 $HTML->headerHTMLDeclaration();
47 echo '<meta http-equiv="Content-Type" ' .
48 'content="text/html; charset=utf-8" />' . "\n";
49 echo '<script type="text/javascript">//<![CDATA[' .
50 "\n\tvar sys_url_base = " . minijson_encode(util_make_url("/"),
53 $HTML->headerForgepluckerMeta();
54 echo html_e('title', array(), util_html_secure($title)) . "\n";
58 * html_feedback_top() - Show the feedback output at the top of the page.
60 * @param string $feedback The feedback.
62 function html_feedback_top($feedback) {
64 echo $HTML->feedback($feedback);
68 * html_warning_top() - Show the warning output at the top of the page.
70 * @param string $msg The warning message.
72 function html_warning_top($msg) {
74 echo $HTML->warning_msg($msg);
78 * html_error_top() - Show the error output at the top of the page.
80 * @param string $msg The error message.
82 function html_error_top($msg) {
84 echo $HTML->error_msg($msg);
88 * make_user_link() - Make a username reference into a link to that users User page on SF.
90 * @param string $username The username of the user to link.
91 * @param string $displayname The name to display.
94 function make_user_link($username, $displayname = '') {
95 if (empty($displayname))
96 $displayname = $username;
98 if (!strcasecmp($username, 'Nobody') || !strcasecmp($username, 'None')) {
101 return '<a href="/users/'.$username.'">'.$displayname.'</a>';
106 * html_feedback_bottom() - Show the feedback output at the bottom of the page.
108 * @param string $feedback The feedback.
110 function html_feedback_bottom($feedback) {
112 echo $HTML->feedback($feedback);
116 * html_blankimage() - Show the blank spacer image.
118 * @param int $height The height of the image
119 * @param int $width The width of the image
122 function html_blankimage($height, $width) {
123 return '<img src="/images/blank.png" width="'.$width.'" height="'.$height.'" alt="" />';
127 * html_abs_image() - Show an image given an absolute URL.
129 * @param string $url URL
130 * @param int $width width of the image
131 * @param int $height height of the image
132 * @param array $args Any <img> tag parameters (i.e. 'border', 'alt', etc...)
135 function html_abs_image($url, $width, $height, $args) {
136 $return = ('<img src="'.$url.'"');
138 while (list($k, $v) = each($args)) {
139 $return .= ' '.$k.'="'.$v.'"';
142 if (!isset($args['alt'])) {
143 $return .= ' alt=""';
146 // Add image dimensions (if given)
147 $return .= $width ? " width=\"".$width."\"" : '';
148 $return .= $height ? " height=\"".$height."\"" : '';
155 * html_image() - Build an image tag of an image contained in $src
157 * @param string $src The source location of the image
158 * @param int $width The width of the image
159 * @param int $height The height of the image
160 * @param array $args Any IMG tag parameters associated with this image (i.e. 'border', 'alt', etc...)
161 * @param bool $display DEPRECATED
164 function html_image($src, $width = '', $height = '', $args = array(), $display = 1) {
167 if (method_exists($HTML, 'html_image')) {
168 $HTML->html_image($src, $width, $height, $args);
170 $s = ((session_issecure()) ? forge_get_config('images_secure_url') : forge_get_config('images_url') );
171 return html_abs_image($s.$HTML->imgroot.$src, $width, $height, $args);
175 * html_get_language_popup() - Pop up box of supported languages.
177 * @param string $title The title of the popup box.
178 * @param string $selected Which element of the box is to be selected.
179 * @return string The html select box.
181 function html_get_language_popup($title = 'language_id', $selected = 'xzxz') {
182 $res = db_query_params('SELECT * FROM supported_languages ORDER BY name ASC',
184 return html_build_select_box($res, $title, $selected, false);
188 * html_get_theme_popup() - Pop up box of supported themes.
190 * @param string $title The title of the popup box.
191 * @param string $selected Which element of the box is to be selected.
192 * @return string The html select box.
194 function html_get_theme_popup($title = 'theme_id', $selected = 'xzxz') {
195 $res = db_query_params('SELECT theme_id, fullname FROM themes WHERE enabled=true',
197 $nbTheme = db_numrows($res);
199 $thetheme = db_result($res, 0, 'fullname');
200 return util_html_secure($thetheme) . html_e('input', array(
203 'value' => db_result($res, 0, 'theme_id'),
205 } elseif ($nbTheme < 1) {
208 return html_build_select_box($res, $title, $selected, false);
213 * html_get_ccode_popup() - Pop up box of supported country_codes.
215 * @param string $title The title of the popup box.
216 * @param string $selected Which element of the box is to be selected.
217 * @return string The html select box.
219 function html_get_ccode_popup($title = 'ccode', $selected = 'xzxz') {
220 $res = db_query_params('SELECT ccode,country_name FROM country_code ORDER BY country_name',
222 return html_build_select_box($res, $title, $selected, false);
226 * html_get_timezone_popup() - Pop up box of supported Timezones.
227 * Assumes you have included Timezones array file.
229 * @param string $title The title of the popup box.
230 * @param string $selected Which element of the box is to be selected.
231 * @return string The html select box.
233 function html_get_timezone_popup($title = 'timezone', $selected = 'xzxz') {
235 if ($selected == 'xzxzxzx') {
236 $r = file('/etc/timezone');
237 $selected = str_replace("\n", '', $r[0]);
239 return html_build_select_box_from_arrays($TZs, $TZs, $title, $selected, false);
243 * html_build_select_box_from_assoc() - Takes one assoc array and returns a pop-up box.
245 * @param array $arr An array of items to use.
246 * @param string $select_name The name you want assigned to this form element.
247 * @param string $checked_val The value of the item that should be checked.
248 * @param bool $swap Whether we should swap the keys / names.
249 * @param bool $show_100 Whether or not to show the '100 row'.
250 * @param string $text_100 What to call the '100 row' defaults to none.
253 function html_build_select_box_from_assoc($arr, $select_name, $checked_val = 'xzxz', $swap = false, $show_100 = false, $text_100 = 'None') {
255 $keys = array_values($arr);
256 $vals = array_keys($arr);
258 $vals = array_values($arr);
259 $keys = array_keys($arr);
261 return html_build_select_box_from_arrays($keys, $vals, $select_name, $checked_val, $show_100, $text_100);
265 * html_build_select_box_from_array() - Takes one array, with the first array being the "id"
266 * or value and the array being the text you want displayed.
268 * @param array An array of items to use.
269 * @param string The name you want assigned to this form element.
270 * @param string The value of the item that should be checked.
273 function html_build_select_box_from_array($vals, $select_name, $checked_val = 'xzxz', $samevals = 0) {
275 <select name="'.$select_name.'">';
277 $rows = count($vals);
279 for ($i = 0; $i < $rows; $i++) {
281 $return .= "\n\t\t<option value=\"".$vals[$i]."\"";
282 if ($vals[$i] == $checked_val) {
283 $return .= ' selected="selected"';
286 $return .= "\n\t\t<option value=\"".$i.'"';
287 if ($i == $checked_val) {
288 $return .= ' selected="selected"';
291 $return .= '>'.htmlspecialchars($vals[$i]).'</option>';
300 * html_build_radio_buttons_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
301 * array being the text you want displayed.
303 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
304 * There must be a related row in users, categories, et , and by default that
305 * row is 100, so almost every pop-up box has 100 as the default
306 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
308 * @param array The ID or value
309 * @param array Text to be displayed
310 * @param string Name to assign to this form element
311 * @param string The item that should be checked
312 * @param bool Whether or not to show the '100 row'
313 * @param string What to call the '100 row' defaults to none
314 * @param bool Whether or not to show the 'Any row'
315 * @param string What to call the 'Any row' defaults to any
318 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') {
319 if ($text_100 == 'none') {
320 $text_100 = _('None');
324 $rows = count($vals);
325 if (count($texts) != $rows) {
326 $return .= 'Error: uneven row counts';
329 //we don't always want the default Any row shown
332 <input type="radio" name="'.$select_name.'" value=""'.(($checked_val == '')? ' checked="checked"' : '').' /> '.$text_any.'<br />';
334 //we don't always want the default 100 row shown
337 <input type="radio" name="'.$select_name.'" value="100"'.(($checked_val == 100)? ' checked="checked"' : '').' /> '.$text_100.'<br />';
340 $checked_found = false;
342 for ($i = 0; $i < $rows; $i++) {
343 // uggh - sorry - don't show the 100 row
344 // if it was shown above, otherwise do show it
345 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
347 <input type="radio" id="'.$select_name.'_'.$vals[$i].'" name="'.$select_name.'" value="'.$vals[$i].'"';
348 if ((string)$vals[$i] == (string)$checked_val) {
349 $checked_found = true;
350 $return .= ' checked="checked"';
352 $return .= ' /> '.htmlspecialchars($texts[$i]).'<br />';
356 // If the passed in "checked value" was never "SELECTED"
357 // we want to preserve that value UNLESS that value was 'xzxz', the default value
359 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
361 <input type="radio" value="'.$checked_val.'" checked="checked" /> '._('No Change').'<br />';
368 * html_get_tooltip_description() - Get the tooltip description of the element
370 * @param string element name
374 function html_get_tooltip_description($element_name) {
375 global $use_tooltips;
376 if (!$use_tooltips) {
379 switch ($element_name) {
381 return _('This drop-down box represents the person to which a tracker item is assigned.');
383 return _('This drop-down box represents the current status of a tracker item.')
385 ._('You can set the status to “Pending” if you are waiting for a response from the tracker item author. When the author responds the status is automatically reset to that of “Open”. Otherwise, if the author does not respond with an admin-defined amount of time (default is 14 days) then the item is given a status of “Deleted”.');
387 return _('Tracker category');
389 return _('Tracker group');
391 return _('The Sort By option allows you to determine how the browse results are sorted.')
393 ._('You can sort by ID, Priority, Summary, Open Date, Close Date, Submitter, or Assignee. You can also have the results sorted in Ascending or Descending order.');
394 case 'new_artifact_type_id':
395 return _('The Data Type option determines the type of tracker item this is. Since the tracker rolls into one the bug, patch, support, etc... managers you need to be able to determine which one of these an item should belong.')
397 ._('This has the added benefit of enabling an admin to turn a support request into a bug.');
399 return _('The priority option allows a user to define a tracker item priority (ranging from 1-Lowest to 5-Highest).')
401 ._('This is especially helpful for bugs and support requests where a user might find a critical problem with a project.');
403 return _('Resolution');
405 return _('The summary text-box represents a short tracker item summary. Useful when browsing through several tracker items.');
406 case 'canned_response':
407 return _('The canned response drop-down represents a list of project admin-defined canned responses to common support or bug submission.')
409 ._('If you are a project admin you can click the “Manage Canned Responses” link to define your own canned responses');
411 return _('Anyone can add here comments to give additional information, answers and solutions. Please, be as precise as possible to avoid misunderstanding. If relevant, screenshots or documents can be added as attached files.');
413 return _('Enter the complete description.')
415 .'<div align="left">'
416 ._("<b>Editing tips:</b><br/><strong>http,https or ftp</strong>: Hyperlinks.<br/><strong>[#NNN]</strong>: Tracker id NNN.<br/><strong>[TNNN]</strong>: Task id NNN.<br/><strong>[wiki:<pagename>]</strong>: Wiki page.<br/><strong>[forum:<msg_id>]</strong>: Forum post.")
419 return _('When you wish to attach a file to a tracker item you must check this checkbox before submitting changes.');
421 return _('You can monitor or un-monitor this item by clicking the “Monitor” button.')
423 ._('<strong>Note!</strong> this will send you additional email. If you add comments to this item, or submitted, or are assigned this item, you will also get emails for those reasons as well!');
429 function html_use_jquery() {
430 use_javascript('/scripts/jquery/jquery-1.8.3.js');
433 function html_use_tooltips() {
435 use_javascript('/scripts/jquery-tipsy/src/javascripts/jquery.tipsy.js');
436 use_javascript('/js/jquery-common.js');
437 use_stylesheet('/scripts/jquery-tipsy/src/stylesheets/tipsy.css');
440 function html_use_storage() {
442 use_javascript('/scripts/jquery-storage/jquery.Storage.js');
445 function html_use_simplemenu() {
447 use_javascript('/scripts/jquery-simpletreemenu/js/jquery-simpleTreeMenu-1.5.0.js');
448 use_stylesheet('/scripts/jquery-simpletreemenu/css/jquery-simpleTreeMenu-1.5.0.css');
451 function html_use_coolfieldset() {
453 use_javascript('/scripts/coolfieldset/js/jquery.coolfieldset.js');
454 use_javascript('/js/jquery-common.js');
455 use_stylesheet('/scripts/coolfieldset/css/jquery.coolfieldset.css');
458 function html_use_jqueryui() {
460 use_javascript('/scripts/jquery-ui/js/jquery-ui-1.9.2.custom.js');
461 use_stylesheet('/scripts/jquery-ui/css/overcast/jquery-ui-1.9.2.custom.css');
464 function html_use_jqueryjqplot() {
466 use_javascript('/scripts/jquery-jqplot/jquery.jqplot.js');
467 use_stylesheet('/scripts/jquery-jqplot/jquery.jqplot.css');
470 function html_use_jqueryjqplotpluginCanvas() {
471 html_use_jqueryjqplot();
472 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.canvasTextRenderer.js');
473 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.canvasAxisLabelRenderer.js');
474 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.canvasAxisTickRenderer.js');
475 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.categoryAxisRenderer.js');
478 function html_use_jqueryjqplotpluginBar() {
479 html_use_jqueryjqplot();
480 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.barRenderer.js');
481 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.pointLabels.js');
482 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.categoryAxisRenderer.js');
485 function html_use_jqueryjqplotpluginPie() {
486 html_use_jqueryjqplot();
487 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.pieRenderer.js');
490 function html_use_jqueryjqplotpluginhighlighter() {
491 html_use_jqueryjqplot();
492 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.highlighter.js');
495 function html_use_jqueryjqplotplugindateAxisRenderer() {
496 html_use_jqueryjqplot();
497 use_javascript('/scripts/jquery-jqplot/plugins/jqplot.dateAxisRenderer.js');
500 function html_use_jqueryteamworkgantt() {
502 use_javascript('/scripts/jquery-teamwork-gantt/libs/jquery.livequery.min.js');
503 use_javascript('/scripts/jquery-teamwork-gantt/libs/jquery.timers.js');
504 use_javascript('/scripts/jquery-teamwork-gantt/libs/platform.js');
505 use_javascript('/scripts/jquery-teamwork-gantt/libs/date.js');
506 use_javascript('/scripts/jquery-teamwork-gantt/libs/date.js');
507 use_javascript('/scripts/jquery-teamwork-gantt/libs/i18nJs.js');
508 use_javascript('/scripts/jquery-teamwork-gantt/libs/dateField/jquery.dateField.js');
509 use_javascript('/scripts/jquery-teamwork-gantt/libs/JST/jquery.JST.js');
510 use_javascript('/scripts/jquery-teamwork-gantt/ganttUtilities.js');
511 use_javascript('/scripts/jquery-teamwork-gantt/ganttTask.js');
512 use_javascript('/scripts/jquery-teamwork-gantt/ganttDrawer.js');
513 use_javascript('/scripts/jquery-teamwork-gantt/ganttGridEditor.js');
514 use_javascript('/scripts/jquery-teamwork-gantt/ganttMaster.js');
515 use_stylesheet('/scripts/jquery-teamwork-gantt/platform.css');
516 use_stylesheet('/scripts/jquery-teamwork-gantt/libs/dateField/jquery.dateField.css');
517 use_stylesheet('/scripts/jquery-teamwork-gantt/gantt.css');
520 function html_use_jquerysplitter() {
522 use_javascript('/scripts/jquery-splitter/js/jquery.splitter-0.8.0.js');
523 use_stylesheet('/scripts/jquery-splitter/css/jquery.splitter.css');
527 * html_build_select_box_from_arrays() - Takes two arrays, with the first array being the "id" or value and the other
528 * array being the text you want displayed.
530 * The infamous '100 row' has to do with the SQL Table joins done throughout all this code.
531 * There must be a related row in users, categories, et , and by default that
532 * row is 100, so almost every pop-up box has 100 as the default
533 * Most tables in the database should therefore have a row with an id of 100 in it so that joins are successful
535 * @param array The ID or value
536 * @param array Text to be displayed
537 * @param string Name to assign to this form element
538 * @param string The item that should be checked
539 * @param bool Whether or not to show the '100 row'
540 * @param string What to call the '100 row' defaults to none
541 * @param bool Whether or not to show the 'Any row'
542 * @param string What to call the 'Any row' defaults to any
543 * @param array Array of all allowed values from the full list.
546 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', $allowed = false) {
547 $have_a_subelement = false;
549 if ($text_100 == 'none') {
550 $text_100 = _('None');
554 $rows = count($vals);
555 if (count($texts) != $rows) {
556 $return .= _('Error: uneven row counts');
559 //TODO: remove this ugly ack to get something more generic...
560 $title = html_get_tooltip_description($select_name);
563 $id = ' id="tracker-'.$select_name.'"';
564 if (preg_match('/\[\]/', $id)) {
570 <select'.$id.' name="'.$select_name.'" title="'.util_html_secure($title).'">';
572 //we don't always want the default Any row shown
575 <option value=""'.(($checked_val == '') ? ' selected="selected"' : '').'>'. util_html_secure($text_any) .'</option>';
576 $have_a_subelement = true;
578 //we don't always want the default 100 row shown
581 <option value="100"'.(($checked_val == 100) ? ' selected="selected"' : '').'>'. util_html_secure($text_100) .'</option>';
582 $have_a_subelement = true;
585 $checked_found = false;
587 for ($i = 0; $i < $rows; $i++) {
588 // uggh - sorry - don't show the 100 row
589 // if it was shown above, otherwise do show it
590 if (($vals[$i] != '100') || ($vals[$i] == '100' && !$show_100)) {
592 <option value="'.util_html_secure($vals[$i]).'"';
593 if ((string)$vals[$i] == (string)$checked_val) {
594 $checked_found = true;
595 $return .= ' selected="selected"';
597 if (is_array($allowed) && !in_array($vals[$i], $allowed)) {
598 $return .= ' disabled="disabled" class="option_disabled"';
600 $return .= '>'.util_html_secure($texts[$i]).'</option>';
601 $have_a_subelement = true;
605 // If the passed in "checked value" was never "SELECTED"
606 // we want to preserve that value UNLESS that value was 'xzxz', the default value
608 if (!$checked_found && $checked_val != 'xzxz' && $checked_val && $checked_val != 100) {
610 <option value="'.util_html_secure($checked_val).'" selected="selected">'._('No Change').'</option>';
611 $have_a_subelement = true;
614 if (!$have_a_subelement) {
615 /* <select></select> without <option/> in between is invalid */
616 return '<!-- select without options -->';
625 * html_build_select_box() - Takes a result set, with the first column being the "id" or value and
626 * the second column being the text you want displayed.
628 * @param resource $result The result set
629 * @param string $name Text to be displayed
630 * @param string $checked_val The item that should be checked
631 * @param bool $show_100 Whether or not to show the '100 row'
632 * @param string $text_100 What to call the '100 row'. Defaults to none.
634 function html_build_select_box($result, $name, $checked_val = "xzxz", $show_100 = true, $text_100 = 'none', $show_any = false, $text_any = 'Select One', $allowed = false) {
635 if ($text_100 == 'none') {
636 $text_100 = _('None');
638 if ($text_any == 'Select One') {
639 $text_any = _('Select One');
641 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, $show_any, $text_any);
645 * html_build_select_box_sorted() - Takes a result set, with the first column being the "id" or value and
646 * the second column being the text you want displayed.
648 * @param int The result set
649 * @param string Text to be displayed
650 * @param string The item that should be checked
651 * @param bool Whether or not to show the '100 row'
652 * @param string What to call the '100 row'. Defaults to none.
655 function html_build_select_box_sorted($result, $name, $checked_val = "xzxz", $show_100 = true, $text_100 = 'none') {
656 if ($text_100 == 'none') {
657 $text_100 = _('None');
659 $vals = util_result_column_to_array($result, 0);
660 $texts = util_result_column_to_array($result, 1);
661 array_multisort($texts, SORT_ASC, SORT_STRING,
663 return html_build_select_box_from_arrays ($vals, $texts, $name, $checked_val, $show_100, $text_100);
667 * html_build_multiple_select_box() - Takes a result set, with the first column being the "id" or value
668 * and the second column being the text you want displayed.
670 * @param int The result set
671 * @param string Text to be displayed
672 * @param string The item that should be checked
673 * @param int The size of this box
674 * @param bool Whether or not to show the '100 row'
677 function html_build_multiple_select_box($result, $name, $checked_array, $size = '8', $show_100 = true) {
678 $checked_count = count($checked_array);
680 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
683 Put in the default NONE box
686 <option value="100"';
687 for ($j = 0; $j < $checked_count; $j++) {
688 if ($checked_array[$j] == '100') {
689 $return .= ' selected="selected"';
692 $return .= '>'._('None').'</option>';
695 $rows = db_numrows($result);
696 for ($i = 0; $i < $rows; $i++) {
697 if ((db_result($result, $i, 0) != '100') || (db_result($result, $i, 0) == '100' && !$show_100)) {
699 <option value="'.db_result($result, $i, 0).'"';
701 Determine if it's checked
703 $val = db_result($result, $i, 0);
704 for ($j = 0; $j < $checked_count; $j++) {
705 if ($val == $checked_array[$j]) {
706 $return .= ' selected="selected"';
709 $return .= '>'.substr(db_result($result, $i, 1), 0, 35).'</option>';
718 * html_build_multiple_select_box_from_arrays() - Takes two arrays and builds a multi-select box
720 * @param array id of the field
721 * @param array Text to be displayed
722 * @param string id of the items selected
723 * @param string The item that should be checked
724 * @param int The size of this box
725 * @param bool Whether or not to show the '100 row'
728 function html_build_multiple_select_box_from_arrays($ids, $texts, $name, $checked_array, $size = '8', $show_100 = true, $text_100 = 'none') {
729 $checked_count = count($checked_array);
731 <select name="'.$name.'" multiple="multiple" size="'.$size.'">';
733 if ($text_100 == 'none') {
734 $text_100 = _('None');
737 Put in the default NONE box
740 <option value="100"';
741 for ($j = 0; $j < $checked_count; $j++) {
742 if ($checked_array[$j] == '100') {
743 $return .= ' selected="selected"';
746 $return .= '>'.$text_100.'</option>';
750 for ($i = 0; $i < $rows; $i++) {
751 if (($ids[$i] != '100') || ($ids[$i] == '100' && !$show_100)) {
753 <option value="'.$ids[$i].'"';
755 Determine if it's checked
758 for ($j = 0; $j < $checked_count; $j++) {
759 if ($val == $checked_array[$j]) {
760 $return .= ' selected="selected"';
763 $return .= '>'.$texts[$i].' </option>';
772 * html_build_checkbox() - Render checkbox control
774 * @param name - name of control
775 * @param value - value of control
776 * @param checked - true if control should be checked
777 * @return html code for checkbox control
779 function html_build_checkbox($name, $value, $checked) {
780 return '<input type="checkbox" id="'.$name.'" name="'.$name.'"'
781 .' value="'.$value.'"'
782 .($checked ? 'checked="checked"' : '').'>';
786 * build_priority_select_box() - Wrapper for html_build_priority_select_box()
788 * @see html_build_priority_select_box()
790 function build_priority_select_box($name = 'priority', $checked_val = '3', $nochange = false) {
791 html_build_priority_select_box($name, $checked_val, $nochange);
795 * html_build_priority_select_box() - Return a select box of standard priorities.
796 * The name of this select box is optional and so is the default checked value.
798 * @param string $name Name of the select box
799 * @param string $checked_val The value to be checked
800 * @param bool $nochange Whether to make 'No Change' selected.
802 function html_build_priority_select_box($name = 'priority', $checked_val = '3', $nochange = false) {
804 <select id="tracker-<?php echo $name ?>" name="<?php echo $name; ?>"
805 title="<?php echo util_html_secure(html_get_tooltip_description($name)) ?>">
806 <?php if ($nochange) { ?>
807 <option value="100"<?php if ($nochange) {echo " selected=\"selected\"";} ?>><?php echo _('No Change') ?></option>
809 <option value="1"<?php if ($checked_val == "1") {echo " selected=\"selected\"";} ?>>1 - <?php echo _('Lowest') ?></option>
810 <option value="2"<?php if ($checked_val == "2") {echo " selected=\"selected\"";} ?>>2</option>
811 <option value="3"<?php if ($checked_val == "3") {echo " selected=\"selected\"";} ?>>3</option>
812 <option value="4"<?php if ($checked_val == "4") {echo " selected=\"selected\"";} ?>>4</option>
813 <option value="5"<?php if ($checked_val == "5") {echo " selected=\"selected\"";} ?>>5 - <?php echo _('Highest') ?></option>
820 * html_buildcheckboxarray() - Build an HTML checkbox array.
822 * @param array Options array
823 * @param name Checkbox name
824 * @param array Array of boxes to be pre-checked
826 function html_buildcheckboxarray($options, $name, $checked_array) {
827 $option_count = count($options);
828 $checked_count = count($checked_array);
830 for ($i = 1; $i <= $option_count; $i++) {
832 <br /><input type="checkbox" name="'.$name.'" value="'.$i.'"';
833 for ($j = 0; $j < $checked_count; $j++) {
834 if ($i == $checked_array[$j]) {
835 echo ' checked="checked"';
838 echo ' /> '.$options[$i];
843 * site_header() - everything required to handle security and
844 * add navigation for user pages like /my/ and /account/
846 * @param array Must contain $user_id
848 function site_header($params) {
851 Check to see if active user
852 Check to see if logged in
854 $HTML->header($params);
858 * site_footer() - Show the HTML site footer.
860 * @param array Footer params array
862 function site_footer($params) {
864 $HTML->footer($params);
868 * site_project_header() - everything required to handle
869 * security and state checks for a project web page
871 * @param params array() must contain $toptab and $group
873 function site_project_header($params) {
876 Check to see if active
877 Check to see if project rather than foundry
878 Check to see if private (if private check if user_ismember)
881 $group_id = $params['group'];
883 //get the project object
884 $project = group_get_object($group_id);
886 if (!$project || !is_object($project)) {
888 } elseif ($project->isError()) {
889 if ($project->isPermissionDeniedError()) {
890 if (!session_get_user()) {
891 $next = '/account/login.php?error_msg='.urlencode($project->getErrorMessage());
892 if (getStringFromServer('REQUEST_METHOD') != 'POST') {
893 $next .= '&return_to='.urlencode(getStringFromServer('REQUEST_URI'));
895 session_redirect($next);
897 exit_error(sprintf(_('Project access problem: %s'), $project->getErrorMessage()), 'home');
899 exit_error(sprintf(_('Project Problem: %s'), $project->getErrorMessage()), 'home');
902 // Check permissions in case of restricted access
903 session_require_perm('project_read', $group_id);
905 //for dead projects must be member of admin project
906 if (!$project->isActive()) {
907 session_require_global_perm('forge_admin');
910 if (isset($params['title'])) {
911 $h1 = $params['title'];
912 $params['title'] = $project->getPublicName().': '.$params['title'];
914 $h1 = $project->getPublicName();
915 $params['title'] = $project->getPublicName();
917 if (!isset($params['h1'])) {
921 if ($project->getDescription()) {
922 $params['meta-description'] = $project->getDescription();
925 if (forge_get_config('use_project_tags')) {
926 $res = db_query_params('SELECT name FROM project_tags WHERE group_id = $1', array($group_id));
927 if ($res && db_numrows($res) > 0) {
928 while ($row = db_fetch_array($res)) {
929 $array[] = $row['name'];
931 $params['meta-keywords'] = htmlspecialchars(join(', ', $array));
935 site_header($params);
939 * site_project_footer() - currently a simple shim
940 * that should be on every project page, rather than
941 * a direct call to site_footer() or theme_footer()
943 * @param params array() empty
945 function site_project_footer($params) {
946 site_footer($params);
950 * site_user_header() - everything required to handle security and
951 * add navigation for user pages like /my/ and /account/
953 * @param params array() must contain $user_id
955 function site_user_header($params) {
959 Check to see if active user
960 Check to see if logged in
962 site_header($params);
963 echo $HTML->beginSubMenu();
968 $arr_t[] = _('My Personal Page');
970 $arr_attr[] = array('title' => _('View your personal page, a selection of widgets to follow the informations from projects.'), 'class' => 'tabtitle-nw');
972 if (forge_get_config('use_tracker')) {
973 $arr_t[] = _('My Trackers Dashboard');
974 $arr_l[] = '/my/dashboard.php';
975 $arr_attr[] = array('title' => _('View your tasks and artifacts.'), 'class' => 'tabtitle');
978 if (forge_get_config('use_diary')) {
979 $arr_t[] = _('My Diary and Notes');
980 $arr_l[] = '/my/diary.php';
981 $arr_attr[] = array('title' => _('Manage your diary. Add, modify or delete your notes.'), 'class' => 'tabtitle');
984 $arr_t[] = _('My Account');
985 $arr_l[] = '/account/';
986 $arr_attr[] = array('title' => _('Manage your account. Change your password, select your preferences.'), 'class' => 'tabtitle');
988 if (!forge_get_config('project_registration_restricted')
989 || forge_check_global_perm('approve_projects', '')) {
990 $arr_t[] = _('Register Project');
991 $arr_l[] = '/register/';
992 $arr_attr[] = array('title' => _('Register a new project in forge, following the workflow.'), 'class' => 'tabtitle');
995 echo ($HTML->printSubMenu($arr_t, $arr_l, $arr_attr));
996 if (plugin_hook_listeners("usermenu") > 0) {
997 echo $HTML->subMenuSeparator();
999 plugin_hook("usermenu", false);
1000 echo $HTML->endSubMenu();
1004 * site_user_footer() - currently a simple shim that should be on every user page,
1005 * rather than a direct call to site_footer() or theme_footer()
1007 * @param params array() empty
1009 function site_user_footer($params) {
1010 site_footer($params);
1014 * html_clean_hash_string() - Remove noise characters from hex hash string
1016 * Thruout SourceForge, URLs with hexadecimal hash string parameters
1017 * are being sent via email to request confirmation of user actions.
1018 * It was found that some mail clients distort this hash, so we take
1019 * special steps to encode it in the way which help to preserve its
1020 * recognition. This routine
1022 * @param hashstr required hash parameter as received from browser
1023 * @return pure hex string
1025 function html_clean_hash_string($hashstr) {
1027 if (substr($hashstr, 0, 1) == "_") {
1028 $hashstr = substr($hashstr, 1);
1031 if (substr($hashstr, strlen($hashstr) - 1, 1) == ">") {
1032 $hashstr = substr($hashstr, 0, strlen($hashstr) - 1);
1038 function relative_date($date) {
1039 $delta = max(time() - $date, 0);
1041 return sprintf(ngettext('%d second ago', '%d seconds ago', $delta), $delta);
1043 $delta = round($delta / 60);
1045 return sprintf(ngettext('%d minute ago', '%d minutes ago', $delta), $delta);
1047 $delta = round($delta / 60);
1049 return sprintf(ngettext('%d hour ago', '%d hours ago', $delta), $delta);
1051 $delta = round($delta / 24);
1053 return sprintf(ngettext('%d day ago', '%d days ago', $delta), $delta);
1055 $delta = round($delta / 7);
1057 return sprintf(ngettext('%d week ago', '%d weeks ago', $delta), $delta);
1059 return date(_('Y-m-d H:i'), $date);
1062 /* TODO: think about beautifying output */
1065 * html_eo() - Return proper element XHTML start tag
1067 * @param string $name
1069 * @param array $attrs
1070 * (optional) associative array of element attributes
1071 * values: arrays are space-imploded;
1072 * false values and empty arrays ignored
1074 * XHTML string suitable for echo'ing
1076 function html_eo($name, $attrs = array()) {
1078 foreach ($attrs as $key => $value) {
1079 if (is_array($value)) {
1080 $value = count($value) ? implode(" ", $value) : false;
1082 if ($value === false) {
1085 $rv .= ' '.$key.'="'.htmlspecialchars($value).'"';
1092 * html_e() - Return proper element XHTML start/end sequence
1094 * @param string $name
1096 * @param array $attrs
1097 * (optional) associative array of element attributes
1098 * values: arrays are space-imploded;
1099 * false values and empty arrays ignored
1100 * @param string $content
1101 * (optional) XHTML to be placed inside
1102 * @param bool $shortform
1103 * (optional) allow short open-close form
1106 * XHTML string suitable for echo'ing
1108 function html_e($name, $attrs = array(), $content = "", $shortform = true) {
1110 foreach ($attrs as $key => $value) {
1111 if (is_array($value)) {
1112 $value = count($value) ? implode(" ", $value) : false;
1114 if ($value === false) {
1117 $rv .= ' '.$key.'="'.htmlspecialchars($value).'"';
1119 if ($content === "" && $shortform) {
1122 $rv .= '>'.$content.'</'.$name.'>';
1127 $html_autoclose_stack = array();
1128 $html_autoclose_pos = 0;
1131 * html_ap() - Return XHTML element autoclose stack position
1135 function html_ap() {
1136 global $html_autoclose_pos;
1138 return $html_autoclose_pos;
1142 * html_ao() - Return proper element XHTML start tag, with autoclose
1144 * @param string $name
1146 * @param array $attrs
1147 * (optional) associative array of element attributes
1148 * values: arrays are space-imploded;
1149 * false values and empty arrays ignored
1151 * XHTML string suitable for echo'ing
1153 function html_ao($name, $attrs = array()) {
1154 global $html_autoclose_pos, $html_autoclose_stack;
1156 $html_autoclose_stack[$html_autoclose_pos++] = array(
1160 return html_eo($name, $attrs);
1164 * html_aonce() - Return once proper element XHTML start tag, with autoclose
1167 initialise this to false; will be modified
1168 * @param string $name
1170 * @param array $attrs
1171 * (optional) associative array of element attributes
1172 * values: arrays are space-imploded;
1173 * false values and empty arrays ignored
1175 * XHTML string suitable for echo'ing
1177 function html_aonce(&$sptr, $name, $attrs = array()) {
1178 if ($sptr !== false) {
1183 return html_ao($name, $attrs);
1187 * html_ac() - Return proper element XHTML end tags, autoclosing
1189 * @param $spos integer
1190 * stack position to return to (nothing is done if === false)
1192 * @return string XHTML string suitable for echo'ing
1194 function html_ac($spos) {
1195 global $html_autoclose_pos, $html_autoclose_stack;
1197 if ($spos === false) {
1198 /* support for html_aonce() */
1202 if ($html_autoclose_pos < $spos) {
1203 $e = "html_autoclose stack underflow; closing down to ".
1204 $spos." but we're down to ".$html_autoclose_pos.
1206 throw new Exception($e);
1210 while ($html_autoclose_pos > $spos) {
1211 --$html_autoclose_pos;
1212 $rv .= '</'.$html_autoclose_stack[$html_autoclose_pos]['name'].'>';
1213 unset($html_autoclose_stack[$html_autoclose_pos]);
1219 * html_a_copy() - Return a copy of part of the autoclose stack
1221 * @param $spos integer
1222 * stack position caller will return to
1225 * argument suitable for html_a_apply()
1227 function html_a_copy($spos) {
1228 global $html_autoclose_pos, $html_autoclose_stack;
1230 if ($spos === false) {
1234 if ($spos > $html_autoclose_pos) {
1235 $e = "html_autoclose stack underflow; closing down to ".
1236 $spos." but we're down to ".$html_autoclose_pos.
1238 throw new Exception($e);
1242 while ($spos < $html_autoclose_pos) {
1243 $rv[] = $html_autoclose_stack[$spos++];
1249 * html_a_apply() - Reopen tags based on an autoclose stack copy
1251 * @param opaque $scopy
1252 * return value from html_a_copy()
1254 * XHTML string suitable for echo'ing
1256 function html_a_apply($scopy) {
1257 /* array_reduce() would be useful here... IF IT WORKED, FFS! */
1259 foreach ($scopy as $value) {
1260 $rv .= html_ao($value['name'], $value['attr']);
1266 * html_trove_limit_navigation_box() - displays the navigation links for paging browsing
1268 * @param string URL of the very same script
1269 * @param int total number of results
1270 * @param int the maximum number displayed on a single page
1271 * @param int current page number (starting at 1)
1273 function html_trove_limit_navigation_box($php_self, $querytotalcount, $trove_browselimit, $page) {
1275 $html_limit = sprintf(_(' Displaying %1$s per page. Projects sorted by alphabetical order.'), $trove_browselimit).'<br/>';
1277 // display all the numbers
1278 for ($i=1;$i<=ceil($querytotalcount/$trove_browselimit);$i++) {
1281 $html_limit .= '<a href="'.$php_self;
1282 $html_limit .= '?page='.$i;
1283 $html_limit .= '">';
1284 } else $html_limit .= '<strong>';
1285 $html_limit .= '<'.$i.'>';
1287 $html_limit .= '</a>';
1288 } else $html_limit .= '</strong>';
1296 // c-file-style: "bsd"