PageRenderTime 51ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/wwwroot/mantis/core/html_api.php

https://github.com/spring/spring-website
PHP | 1756 lines | 1083 code | 230 blank | 443 comment | 222 complexity | b48537547052176ace43f8c2e35a67e7 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, LGPL-3.0, BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. # MantisBT - a php based bugtracking system
  3. # MantisBT is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # MantisBT is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  15. /**
  16. * These functions control the display of each page
  17. *
  18. * This is the call order of these functions, should you need to figure out
  19. * which to modify or which to leave out.
  20. *
  21. * html_page_top1
  22. * html_begin
  23. * html_head_begin
  24. * html_css
  25. * html_content_type
  26. * html_rss_link
  27. * (html_meta_redirect)
  28. * html_title
  29. * html_page_top2
  30. * html_page_top2a
  31. * html_head_end
  32. * html_body_begin
  33. * html_header
  34. * html_top_banner
  35. * html_login_info
  36. * (print_project_menu_bar)
  37. * print_menu
  38. *
  39. * ...Page content here...
  40. *
  41. * html_page_bottom1
  42. * (print_menu)
  43. * html_page_bottom1a
  44. * html_bottom_banner
  45. * html_footer
  46. * html_body_end
  47. * html_end
  48. *
  49. * @package CoreAPI
  50. * @subpackage HTMLAPI
  51. * @copyright Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  52. * @copyright Copyright (C) 2002 - 2014 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  53. * @link http://www.mantisbt.org
  54. * @uses lang_api.php
  55. */
  56. /**
  57. * requires current_user_api
  58. */
  59. require_once( 'current_user_api.php' );
  60. /**
  61. * requires string_api
  62. */
  63. require_once( 'string_api.php' );
  64. /**
  65. * requires bug_api
  66. */
  67. require_once( 'bug_api.php' );
  68. /**
  69. * requires project_api
  70. */
  71. require_once( 'project_api.php' );
  72. /**
  73. * requires helper_api
  74. */
  75. require_once( 'helper_api.php' );
  76. /**
  77. * requires authentication_api
  78. */
  79. require_once( 'authentication_api.php' );
  80. /**
  81. * requires user_api
  82. */
  83. require_once( 'user_api.php' );
  84. /**
  85. * requires rss_api
  86. */
  87. require_once( 'rss_api.php' );
  88. /**
  89. * requires php_api
  90. */
  91. require_once( 'php_api.php' );
  92. $g_rss_feed_url = null;
  93. $g_robots_meta = '';
  94. # flag for error handler to skip header menus
  95. $g_error_send_page_header = true;
  96. # Projax library disabled by default. It will be enabled if projax_api.php
  97. # is included. But it must be included after html_api.php
  98. $g_enable_projax = false;
  99. /**
  100. * Sets the url for the rss link associated with the current page.
  101. * null: means no feed (default).
  102. * @param string $p_rss_feed_url rss feed url
  103. * @return null
  104. */
  105. function html_set_rss_link( $p_rss_feed_url ) {
  106. if( OFF != config_get( 'rss_enabled' ) ) {
  107. global $g_rss_feed_url;
  108. $g_rss_feed_url = $p_rss_feed_url;
  109. }
  110. }
  111. /**
  112. * This method must be called before the html_page_top* methods. It marks the page as not
  113. * for indexing.
  114. * @return null
  115. */
  116. function html_robots_noindex() {
  117. global $g_robots_meta;
  118. $g_robots_meta = 'noindex,follow';
  119. }
  120. /**
  121. * Prints the link that allows auto-detection of the associated feed.
  122. * @return null
  123. */
  124. function html_rss_link() {
  125. global $g_rss_feed_url;
  126. if( $g_rss_feed_url !== null ) {
  127. echo '<link rel="alternate" type="application/rss+xml" title="RSS" href="', $g_rss_feed_url, '" />';
  128. }
  129. }
  130. /**
  131. * Prints a <script> tag to include a javascript file.
  132. * This includes either minimal or development file from /javascript depending on whether mantis is set for debug/production use
  133. * @param string $p_filename
  134. * @return null
  135. */
  136. function html_javascript_link( $p_filename) {
  137. if( config_get_global( 'minimal_jscss' ) ) {
  138. echo '<script type="text/javascript" src="', helper_mantis_url( 'javascript/min/' . $p_filename ), '"></script>' . "\n";
  139. } else {
  140. echo '<script type="text/javascript" src="', helper_mantis_url( 'javascript/dev/' . $p_filename ), '"></script>' . "\n";
  141. }
  142. }
  143. /**
  144. * Defines the top of a HTML page
  145. * @param string $p_page_title html page title
  146. * @param string $p_redirect_url url to redirect to if necessary
  147. * @return null
  148. */
  149. function html_page_top( $p_page_title = null, $p_redirect_url = null ) {
  150. html_page_top1( $p_page_title );
  151. if ( $p_redirect_url !== null ) {
  152. html_meta_redirect( $p_redirect_url );
  153. }
  154. html_page_top2();
  155. }
  156. /**
  157. * Print the part of the page that comes before meta redirect tags should be inserted
  158. * @param string $p_page_title page title
  159. * @return null
  160. */
  161. function html_page_top1( $p_page_title = null ) {
  162. html_begin();
  163. html_head_begin();
  164. html_css();
  165. html_content_type();
  166. include( config_get( 'meta_include_file' ) );
  167. global $g_robots_meta;
  168. if ( !is_blank( $g_robots_meta ) ) {
  169. echo "\t", '<meta name="robots" content="', $g_robots_meta, '" />', "\n";
  170. }
  171. html_rss_link();
  172. $t_favicon_image = config_get( 'favicon_image' );
  173. if( !is_blank( $t_favicon_image ) ) {
  174. echo "\t", '<link rel="shortcut icon" href="', helper_mantis_url( $t_favicon_image ), '" type="image/x-icon" />', "\n";
  175. }
  176. // Advertise the availability of the browser search plug-ins.
  177. echo "\t", '<link rel="search" type="application/opensearchdescription+xml" title="MantisBT: Text Search" href="' . string_sanitize_url( 'browser_search_plugin.php?type=text', true) . '" />';
  178. echo "\t", '<link rel="search" type="application/opensearchdescription+xml" title="MantisBT: Issue Id" href="' . string_sanitize_url( 'browser_search_plugin.php?type=id', true) . '" />';
  179. html_title( $p_page_title );
  180. html_head_javascript();
  181. }
  182. /**
  183. * Print the part of the page that comes after meta tags, but before the actual page content
  184. * @return null
  185. */
  186. function html_page_top2() {
  187. html_page_top2a();
  188. if( !db_is_connected() ) {
  189. return;
  190. }
  191. if( auth_is_user_authenticated() ) {
  192. html_login_info();
  193. if( ON == config_get( 'show_project_menu_bar' ) ) {
  194. print_project_menu_bar();
  195. echo '<br />';
  196. }
  197. }
  198. print_menu();
  199. event_signal( 'EVENT_LAYOUT_CONTENT_BEGIN' );
  200. }
  201. /**
  202. * Print the part of the page that comes after meta tags and before the
  203. * actual page content, but without login info or menus. This is used
  204. * directly during the login process and other times when the user may
  205. * not be authenticated
  206. * @return null
  207. */
  208. function html_page_top2a() {
  209. global $g_error_send_page_header;
  210. html_head_end();
  211. html_body_begin();
  212. $g_error_send_page_header = false;
  213. html_header();
  214. html_top_banner();
  215. }
  216. /**
  217. * Print the part of the page that comes below the page content
  218. * $p_file should always be the __FILE__ variable. This is passed to show source
  219. * @param string $p_file should always be the __FILE__ variable. This is passed to show source
  220. * @return null
  221. */
  222. function html_page_bottom( $p_file = null ) {
  223. html_page_bottom1( $p_file );
  224. }
  225. /**
  226. * Print the part of the page that comes below the page content
  227. * $p_file should always be the __FILE__ variable. This is passed to show source
  228. * @param string $p_file should always be the __FILE__ variable. This is passed to show source
  229. * @return null
  230. */
  231. function html_page_bottom1( $p_file = null ) {
  232. if( !db_is_connected() ) {
  233. return;
  234. }
  235. event_signal( 'EVENT_LAYOUT_CONTENT_END' );
  236. if( config_get( 'show_footer_menu' ) ) {
  237. echo '<br />';
  238. print_menu();
  239. }
  240. html_page_bottom1a( $p_file );
  241. }
  242. /**
  243. * Print the part of the page that comes below the page content but leave off
  244. * the menu. This is used during the login process and other times when the
  245. * user may not be authenticated.
  246. * @param string $p_file should always be the __FILE__ variable.
  247. * @return null
  248. */
  249. function html_page_bottom1a( $p_file = null ) {
  250. if( null === $p_file ) {
  251. $p_file = basename( $_SERVER['SCRIPT_NAME'] );
  252. }
  253. html_bottom_banner();
  254. html_footer();
  255. html_body_end();
  256. html_end();
  257. }
  258. /**
  259. * (1) Print the document type and the opening <html> tag
  260. * @return null
  261. */
  262. function html_begin() {
  263. echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n";
  264. echo '<html>', "\n";
  265. }
  266. /**
  267. * (2) Begin the <head> section
  268. * @return null
  269. */
  270. function html_head_begin() {
  271. echo '<head>', "\n";
  272. }
  273. /**
  274. * (3) Print the content-type
  275. * @return null
  276. */
  277. function html_content_type() {
  278. echo "\t", '<meta http-equiv="Content-type" content="text/html; charset=utf-8" />', "\n";
  279. }
  280. /**
  281. * (4) Print the window title
  282. * @param string $p_page_title window title
  283. * @return null
  284. */
  285. function html_title( $p_page_title = null ) {
  286. $t_page_title = string_html_specialchars( $p_page_title );
  287. $t_title = string_html_specialchars( config_get( 'window_title' ) );
  288. echo "\t", '<title>';
  289. if( empty( $t_page_title ) ) {
  290. echo $t_title;
  291. } else {
  292. if( empty( $t_title ) ) {
  293. echo $t_page_title;
  294. } else {
  295. echo $t_page_title . ' - ' . $t_title;
  296. }
  297. }
  298. echo '</title>', "\n";
  299. }
  300. /**
  301. * (5) Print the link to include the css file
  302. * @return null
  303. */
  304. function html_css() {
  305. $t_css_url = config_get( 'css_include_file' );
  306. echo "\t", '<link rel="stylesheet" type="text/css" href="', string_sanitize_url( helper_mantis_url( $t_css_url ), true ), '" />', "\n";
  307. # Add right-to-left css if needed
  308. if( lang_get( 'directionality' ) == 'rtl' ) {
  309. $t_css_rtl_url = config_get( 'css_rtl_include_file' );
  310. echo "\t", '<link rel="stylesheet" type="text/css" href="', string_sanitize_url( helper_mantis_url( $t_css_rtl_url ), true ), '" />', "\n";
  311. }
  312. # fix for NS 4.x css
  313. echo "\t", '<script type="text/javascript"><!--', "\n";
  314. echo "\t\t", 'if(document.layers) {document.write("<style>td{padding:0px;}<\/style>")}', "\n";
  315. echo "\t", '// --></script>', "\n";
  316. }
  317. /**
  318. * (6) Print an HTML meta tag to redirect to another page
  319. * This function is optional and may be called by pages that need a redirect.
  320. * $p_time is the number of seconds to wait before redirecting.
  321. * If we have handled any errors on this page and the 'stop_on_errors' config
  322. * option is turned on, return false and don't redirect.
  323. *
  324. * @param string $p_url The page to redirect: has to be a relative path
  325. * @param integer $p_time seconds to wait for before redirecting
  326. * @param boolean $p_sanitize apply string_sanitize_url to passed url
  327. * @return boolean
  328. */
  329. function html_meta_redirect( $p_url, $p_time = null, $p_sanitize = true ) {
  330. if( ON == config_get_global( 'stop_on_errors' ) && error_handled() ) {
  331. return false;
  332. }
  333. if( null === $p_time ) {
  334. $p_time = current_user_get_pref( 'redirect_delay' );
  335. }
  336. $t_url = config_get( 'path' );
  337. if( $p_sanitize ) {
  338. $t_url .= string_sanitize_url( $p_url );
  339. } else {
  340. $t_url .= $p_url;
  341. }
  342. $t_url = htmlspecialchars( $t_url );
  343. echo "\t<meta http-equiv=\"Refresh\" content=\"$p_time;URL=$t_url\" />\n";
  344. return true;
  345. }
  346. /**
  347. * (6a) Javascript...
  348. * @return null
  349. */
  350. function html_head_javascript() {
  351. if( ON == config_get( 'use_javascript' ) ) {
  352. html_javascript_link( 'common.js' );
  353. echo '<script type="text/javascript">var loading_lang = "' . lang_get( 'loading' ) . '";</script>';
  354. html_javascript_link( 'ajax.js' );
  355. global $g_enable_projax;
  356. if( $g_enable_projax ) {
  357. html_javascript_link( 'projax/prototype.js' );
  358. html_javascript_link( 'projax/scriptaculous.js' );
  359. }
  360. }
  361. }
  362. /**
  363. * (7) End the <head> section
  364. * @return null
  365. */
  366. function html_head_end() {
  367. event_signal( 'EVENT_LAYOUT_RESOURCES' );
  368. echo '</head>', "\n";
  369. }
  370. /**
  371. * (8) Begin the <body> section
  372. * @return null
  373. */
  374. function html_body_begin() {
  375. echo '<body>', "\n";
  376. event_signal( 'EVENT_LAYOUT_BODY_BEGIN' );
  377. }
  378. /**
  379. * (9) Print the title displayed at the top of the page
  380. * @return null
  381. */
  382. function html_header() {
  383. $t_title = config_get( 'page_title' );
  384. if( !is_blank( $t_title ) ) {
  385. echo '<div class="center"><span class="pagetitle">', string_display( $t_title ), '</span></div>', "\n";
  386. }
  387. }
  388. /**
  389. * (10) Print a user-defined banner at the top of the page if there is one.
  390. * @return null
  391. */
  392. function html_top_banner() {
  393. $t_page = config_get( 'top_include_page' );
  394. $t_logo_image = config_get( 'logo_image' );
  395. $t_logo_url = config_get( 'logo_url' );
  396. if( is_blank( $t_logo_image ) ) {
  397. $t_show_logo = false;
  398. } else {
  399. $t_show_logo = true;
  400. if( is_blank( $t_logo_url ) ) {
  401. $t_show_url = false;
  402. } else {
  403. $t_show_url = true;
  404. }
  405. }
  406. if( !is_blank( $t_page ) && file_exists( $t_page ) && !is_dir( $t_page ) ) {
  407. include( $t_page );
  408. } else if( $t_show_logo ) {
  409. $t_align = should_center_logo() ? 'center' : 'left';
  410. echo '<div align="', $t_align, '">';
  411. if( $t_show_url ) {
  412. echo '<a href="', config_get( 'logo_url' ), '">';
  413. }
  414. $t_alternate_text = string_html_specialchars( config_get( 'window_title' ) );
  415. echo '<img border="0" alt="', $t_alternate_text, '" src="' . helper_mantis_url( $t_logo_image ) . '" />';
  416. if( $t_show_url ) {
  417. echo '</a>';
  418. }
  419. echo '</div>';
  420. }
  421. event_signal( 'EVENT_LAYOUT_PAGE_HEADER' );
  422. }
  423. /**
  424. * (11) Print the user's account information
  425. * Also print the select box where users can switch projects
  426. * @return null
  427. */
  428. function html_login_info() {
  429. $t_username = current_user_get_field( 'username' );
  430. $t_access_level = get_enum_element( 'access_levels', current_user_get_access_level() );
  431. $t_now = date( config_get( 'complete_date_format' ) );
  432. $t_realname = current_user_get_field( 'realname' );
  433. echo '<table class="hide">';
  434. echo '<tr>';
  435. echo '<td class="login-info-left">';
  436. if( current_user_is_anonymous() ) {
  437. $t_return_page = $_SERVER['SCRIPT_NAME'];
  438. if( isset( $_SERVER['QUERY_STRING'] ) ) {
  439. $t_return_page .= '?' . $_SERVER['QUERY_STRING'];
  440. }
  441. $t_return_page = string_url( $t_return_page );
  442. echo lang_get( 'anonymous' ) . ' | <a href="' . helper_mantis_url( 'login_page.php?return=' . $t_return_page ) . '">' . lang_get( 'login_link' ) . '</a>';
  443. if( config_get_global( 'allow_signup' ) == ON ) {
  444. echo ' | <a href="' . helper_mantis_url( 'signup_page.php' ) . '">' . lang_get( 'signup_link' ) . '</a>';
  445. }
  446. } else {
  447. echo lang_get( 'logged_in_as' ), ": <span class=\"italic\">", string_html_specialchars( $t_username ), "</span> <span class=\"small\">";
  448. echo is_blank( $t_realname ) ? "($t_access_level)" : "(" . string_html_specialchars( $t_realname ) . " - $t_access_level)";
  449. echo "</span>";
  450. }
  451. echo '</td>';
  452. echo '<td class="login-info-middle">';
  453. echo "<span class=\"italic\">$t_now</span>";
  454. echo '</td>';
  455. echo '<td class="login-info-right">';
  456. # Project Selector hidden if only one project visisble to user
  457. $t_show_project_selector = true;
  458. $t_project_ids = current_user_get_accessible_projects();
  459. if( count( $t_project_ids ) == 1 ) {
  460. $t_project_id = (int) $t_project_ids[0];
  461. if( count( current_user_get_accessible_subprojects( $t_project_id ) ) == 0 ) {
  462. $t_show_project_selector = false;
  463. }
  464. }
  465. if( $t_show_project_selector ) {
  466. echo '<form method="post" name="form_set_project" action="' . helper_mantis_url( 'set_project.php' ) . '">';
  467. # CSRF protection not required here - form does not result in modifications
  468. echo lang_get( 'email_project' ), ': ';
  469. if( ON == config_get( 'show_extended_project_browser' ) ) {
  470. print_extended_project_browser( helper_get_current_project_trace() );
  471. } else {
  472. if( ON == config_get( 'use_javascript' ) ) {
  473. echo '<select name="project_id" class="small" onchange="document.forms.form_set_project.submit();">';
  474. } else {
  475. echo '<select name="project_id" class="small">';
  476. }
  477. print_project_option_list( join( ';', helper_get_current_project_trace() ), true, null, true );
  478. echo '</select> ';
  479. }
  480. echo '<input type="submit" class="button-small" value="' . lang_get( 'switch' ) . '" />';
  481. echo '</form>';
  482. } else {
  483. # User has only one project, set it as both current and default
  484. if( ALL_PROJECTS == helper_get_current_project() ) {
  485. helper_set_current_project( $t_project_id );
  486. if ( !current_user_is_protected() ) {
  487. current_user_set_default_project( $t_project_id );
  488. }
  489. # Force reload of current page, except if we got here after
  490. # creating the first project
  491. $t_redirect_url = str_replace( config_get( 'short_path' ), '', $_SERVER['REQUEST_URI'] );
  492. if( 'manage_proj_create.php' != $t_redirect_url ) {
  493. html_meta_redirect( $t_redirect_url, 0, false );
  494. }
  495. }
  496. }
  497. if( OFF != config_get( 'rss_enabled' ) ) {
  498. # Link to RSS issues feed for the selected project, including authentication details.
  499. echo '<a href="' . htmlspecialchars( rss_get_issues_feed_url() ) . '">';
  500. echo '<img src="' . helper_mantis_url( 'images/rss.png' ) . '" alt="' . lang_get( 'rss' ) . '" style="border-style: none; margin: 5px; vertical-align: middle;" />';
  501. echo '</a>';
  502. }
  503. echo '</td>';
  504. echo '</tr>';
  505. echo '</table>';
  506. }
  507. /**
  508. * (12) Print a user-defined banner at the bottom of the page if there is one.
  509. * @return null
  510. */
  511. function html_bottom_banner() {
  512. $t_page = config_get( 'bottom_include_page' );
  513. if( !is_blank( $t_page ) && file_exists( $t_page ) && !is_dir( $t_page ) ) {
  514. include( $t_page );
  515. }
  516. }
  517. /**
  518. * (13) Print the page footer information
  519. * @param string $p_file
  520. * @return null
  521. */
  522. function html_footer( $p_file = null ) {
  523. global $g_queries_array, $g_request_time;
  524. # If a user is logged in, update their last visit time.
  525. # We do this at the end of the page so that:
  526. # 1) we can display the user's last visit time on a page before updating it
  527. # 2) we don't invalidate the user cache immediately after fetching it
  528. # 3) don't do this on the password verification or update page, as it causes the
  529. # verification comparison to fail
  530. if ( auth_is_user_authenticated() && !current_user_is_anonymous() && !( is_page_name( 'verify.php' ) || is_page_name( 'account_update.php' ) ) ) {
  531. $t_user_id = auth_get_current_user_id();
  532. user_update_last_visit( $t_user_id );
  533. }
  534. echo "\t", '<br />', "\n";
  535. echo "\t", '<hr size="1" />', "\n";
  536. echo '<table border="0" width="100%" cellspacing="0" cellpadding="0"><tr valign="top"><td>';
  537. if( ON == config_get( 'show_version' ) ) {
  538. $t_version_suffix = config_get_global( 'version_suffix' );
  539. $t_mantis_version = MANTIS_VERSION . ( $t_version_suffix ? " $t_version_suffix" : '' );
  540. $t_mantis_href = '<a href="http://www.mantisbt.org/" title="Free Web-Based Bug Tracker"';
  541. echo
  542. "\t", '<span class="timer">',
  543. "$t_mantis_href>MantisBT $t_mantis_version</a> ",
  544. "[$t_mantis_href ", 'target="_blank">^</a>]',
  545. "</span>\n";
  546. }
  547. echo "\t<address>Copyright &copy; 2000 - ", date( 'Y' ), " MantisBT Team</address>\n";
  548. # only display webmaster email is current user is not the anonymous user
  549. if( !is_page_name( 'login_page.php' ) && auth_is_user_authenticated() && !current_user_is_anonymous() ) {
  550. echo "\t", '<address><a href="mailto:', config_get( 'webmaster_email' ), '">', config_get( 'webmaster_email' ), '</a></address>', "\n";
  551. }
  552. event_signal( 'EVENT_LAYOUT_PAGE_FOOTER' );
  553. # print timings
  554. if( ON == config_get( 'show_timer' ) ) {
  555. echo '<span class="italic">Time: ' . number_format( microtime(true) - $g_request_time, 4 ) . ' seconds.</span><br />';
  556. echo sprintf( lang_get( 'memory_usage_in_kb' ), number_format( memory_get_peak_usage() / 1024 ) ), '<br />';
  557. }
  558. # print db queries that were run
  559. if( helper_show_queries() ) {
  560. $t_count = count( $g_queries_array );
  561. echo "\t";
  562. echo sprintf( lang_get( 'total_queries_executed' ), $t_count );
  563. echo "<br />\n";
  564. if( ON == config_get( 'show_queries_list' ) ) {
  565. $t_unique_queries = 0;
  566. $t_shown_queries = array();
  567. for( $i = 0;$i < $t_count;$i++ ) {
  568. if( !in_array( $g_queries_array[$i][0], $t_shown_queries ) ) {
  569. $t_unique_queries++;
  570. $g_queries_array[$i][3] = false;
  571. array_push( $t_shown_queries, $g_queries_array[$i][0] );
  572. } else {
  573. $g_queries_array[$i][3] = true;
  574. }
  575. }
  576. echo "\t";
  577. echo sprintf( lang_get( 'unique_queries_executed' ), $t_unique_queries );
  578. echo "\t", '<table>', "\n";
  579. $t_total = 0;
  580. for( $i = 0;$i < $t_count;$i++ ) {
  581. $t_time = $g_queries_array[$i][1];
  582. $t_caller = $g_queries_array[$i][2];
  583. $t_total += $t_time;
  584. $t_style_tag = '';
  585. if( true == $g_queries_array[$i][3] ) {
  586. $t_style_tag = ' style="color: red;"';
  587. }
  588. echo "\t", '<tr valign="top"><td', $t_style_tag, '>', ( $i + 1 ), '</td>';
  589. echo '<td', $t_style_tag, '>', $t_time, '</td>';
  590. echo '<td', $t_style_tag, '><span style="color: gray;">', $t_caller, '</span><br />', string_html_specialchars( $g_queries_array[$i][0] ), '</td></tr>', "\n";
  591. }
  592. # @@@ Note sure if we should localize them given that they are debug info. Will add if requested by users.
  593. echo "\t", '<tr><td></td><td>', $t_total, '</td><td>SQL Queries Total Time</td></tr>', "\n";
  594. echo "\t", '<tr><td></td><td>', round( microtime(true) - $g_request_time, 4 ), '</td><td>Page Request Total Time</td></tr>', "\n";
  595. echo "\t", '</table>', "\n";
  596. }
  597. }
  598. echo '</td><td>', "\n\t";
  599. # We don't have a button anymore, so for now we will only show the resized version of the logo when not on login page.
  600. if ( !is_page_name( 'login_page' ) ) {
  601. echo '<div align="right">';
  602. echo '<a href="http://www.mantisbt.org" title="Free Web Based Bug Tracker"><img src="' . helper_mantis_url( 'images/mantis_logo.png' ) . '" width="145" height="50" alt="Powered by Mantis Bugtracker" border="0" /></a>';
  603. echo '</div>', "\n";
  604. }
  605. echo '</td></tr></table>', "\n";
  606. }
  607. /**
  608. * (14) End the <body> section
  609. * @return null
  610. */
  611. function html_body_end() {
  612. event_signal( 'EVENT_LAYOUT_BODY_END' );
  613. echo '</body>', "\n";
  614. }
  615. /**
  616. * (15) Print the closing <html> tag
  617. * @return null
  618. */
  619. function html_end() {
  620. echo '</html>', "\n";
  621. }
  622. /**
  623. * Prepare an array of additional menu options from a config variable
  624. * @param string $p_config config name
  625. * @return array
  626. */
  627. function prepare_custom_menu_options( $p_config ) {
  628. $t_custom_menu_options = config_get( $p_config );
  629. $t_options = array();
  630. foreach( $t_custom_menu_options as $t_custom_option ) {
  631. $t_access_level = $t_custom_option[1];
  632. if( access_has_project_level( $t_access_level ) ) {
  633. $t_caption = string_html_specialchars( lang_get_defaulted( $t_custom_option[0] ) );
  634. $t_link = string_attribute( $t_custom_option[2] );
  635. $t_options[] = "<a href=\"$t_link\">$t_caption</a>";
  636. }
  637. }
  638. return $t_options;
  639. }
  640. /**
  641. * Print the main menu
  642. * @return null
  643. */
  644. function print_menu() {
  645. if( auth_is_user_authenticated() ) {
  646. $t_protected = current_user_get_field( 'protected' );
  647. $t_current_project = helper_get_current_project();
  648. echo '<table class="width100" cellspacing="0">';
  649. echo '<tr>';
  650. echo '<td class="menu">';
  651. $t_menu_options = array();
  652. # Main Page
  653. if ( config_get( 'news_enabled' ) == ON ) {
  654. $t_menu_options[] = '<a href="' . helper_mantis_url( 'main_page.php' ) . '">' . lang_get( 'main_link' ) . '</a>';
  655. }
  656. # Plugin / Event added options
  657. $t_event_menu_options = event_signal( 'EVENT_MENU_MAIN_FRONT' );
  658. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  659. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  660. if( is_array( $t_callback_menu_options ) ) {
  661. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  662. } else {
  663. if ( !is_null( $t_callback_menu_options ) ) {
  664. $t_menu_options[] = $t_callback_menu_options;
  665. }
  666. }
  667. }
  668. }
  669. # My View
  670. $t_menu_options[] = '<a href="' . helper_mantis_url( 'my_view_page.php">' ) . lang_get( 'my_view_link' ) . '</a>';
  671. # View Bugs
  672. $t_menu_options[] = '<a href="' . helper_mantis_url( 'view_all_bug_page.php">' ) . lang_get( 'view_bugs_link' ) . '</a>';
  673. # Report Bugs
  674. if( access_has_project_level( config_get( 'report_bug_threshold' ) ) ) {
  675. $t_menu_options[] = string_get_bug_report_link();
  676. }
  677. # Changelog Page
  678. if( access_has_project_level( config_get( 'view_changelog_threshold' ) ) ) {
  679. $t_menu_options[] = '<a href="' . helper_mantis_url( 'changelog_page.php">' ) . lang_get( 'changelog_link' ) . '</a>';
  680. }
  681. # Roadmap Page
  682. if( access_has_project_level( config_get( 'roadmap_view_threshold' ) ) ) {
  683. $t_menu_options[] = '<a href="' . helper_mantis_url( 'roadmap_page.php">' ) . lang_get( 'roadmap_link' ) . '</a>';
  684. }
  685. # Summary Page
  686. if( access_has_project_level( config_get( 'view_summary_threshold' ) ) ) {
  687. $t_menu_options[] = '<a href="' . helper_mantis_url( 'summary_page.php">' ) . lang_get( 'summary_link' ) . '</a>';
  688. }
  689. # Project Documentation Page
  690. if( ON == config_get( 'enable_project_documentation' ) ) {
  691. $t_menu_options[] = '<a href="' . helper_mantis_url( 'proj_doc_page.php">' ) . lang_get( 'docs_link' ) . '</a>';
  692. }
  693. # Project Wiki
  694. if( config_get_global( 'wiki_enable' ) == ON ) {
  695. $t_menu_options[] = '<a href="' . helper_mantis_url( 'wiki.php?type=project&amp;id=' ) . $t_current_project . '">' . lang_get( 'wiki' ) . '</a>';
  696. }
  697. # Plugin / Event added options
  698. $t_event_menu_options = event_signal( 'EVENT_MENU_MAIN' );
  699. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  700. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  701. if( is_array( $t_callback_menu_options ) ) {
  702. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  703. } else {
  704. if ( !is_null( $t_callback_menu_options ) ) {
  705. $t_menu_options[] = $t_callback_menu_options;
  706. }
  707. }
  708. }
  709. }
  710. # Manage Users (admins) or Manage Project (managers) or Manage Custom Fields
  711. if( access_has_global_level( config_get( 'manage_site_threshold' ) ) ) {
  712. $t_link = helper_mantis_url( 'manage_overview_page.php' );
  713. $t_menu_options[] = "<a href=\"$t_link\">" . lang_get( 'manage_link' ) . '</a>';
  714. } else {
  715. $t_show_access = min( config_get( 'manage_user_threshold' ), config_get( 'manage_project_threshold' ), config_get( 'manage_custom_fields_threshold' ) );
  716. if( access_has_global_level( $t_show_access ) || access_has_any_project( $t_show_access ) ) {
  717. $t_current_project = helper_get_current_project();
  718. if( access_has_global_level( config_get( 'manage_user_threshold' ) ) ) {
  719. $t_link = helper_mantis_url( 'manage_user_page.php' );
  720. } else {
  721. if( access_has_project_level( config_get( 'manage_project_threshold' ), $t_current_project ) && ( $t_current_project <> ALL_PROJECTS ) ) {
  722. $t_link = helper_mantis_url( 'manage_proj_edit_page.php?project_id=' ) . $t_current_project;
  723. } else {
  724. $t_link = helper_mantis_url( 'manage_proj_page.php' );
  725. }
  726. }
  727. $t_menu_options[] = "<a href=\"$t_link\">" . lang_get( 'manage_link' ) . '</a>';
  728. }
  729. }
  730. # News Page
  731. if ( news_is_enabled() && access_has_project_level( config_get( 'manage_news_threshold' ) ) ) {
  732. # Admin can edit news for All Projects (site-wide)
  733. if( ALL_PROJECTS != helper_get_current_project() || current_user_is_administrator() ) {
  734. $t_menu_options[] = '<a href="' . helper_mantis_url( 'news_menu_page.php">' ) . lang_get( 'edit_news_link' ) . '</a>';
  735. } else {
  736. $t_menu_options[] = '<a href="' . helper_mantis_url( 'login_select_proj_page.php">' ) . lang_get( 'edit_news_link' ) . '</a>';
  737. }
  738. }
  739. # Account Page (only show accounts that are NOT protected)
  740. if( OFF == $t_protected ) {
  741. $t_menu_options[] = '<a href="' . helper_mantis_url( 'account_page.php">' ) . lang_get( 'account_link' ) . '</a>';
  742. }
  743. # Add custom options
  744. $t_custom_options = prepare_custom_menu_options( 'main_menu_custom_options' );
  745. $t_menu_options = array_merge( $t_menu_options, $t_custom_options );
  746. # Time Tracking / Billing
  747. if( config_get( 'time_tracking_enabled' ) && access_has_global_level( config_get( 'time_tracking_reporting_threshold' ) ) ) {
  748. $t_menu_options[] = '<a href="' . helper_mantis_url( 'billing_page.php">' ) . lang_get( 'time_tracking_billing_link' ) . '</a>';
  749. }
  750. # Logout (no if anonymously logged in)
  751. if( !current_user_is_anonymous() ) {
  752. $t_menu_options[] = '<a href="' . helper_mantis_url( 'logout_page.php">' ) . lang_get( 'logout_link' ) . '</a>';
  753. }
  754. echo implode( $t_menu_options, ' | ' );
  755. echo '</td>';
  756. echo '<td class="menu right nowrap">';
  757. echo '<form method="post" action="' . helper_mantis_url( 'jump_to_bug.php">' );
  758. # CSRF protection not required here - form does not result in modifications
  759. if( ON == config_get( 'use_javascript' ) ) {
  760. $t_bug_label = lang_get( 'issue_id' );
  761. echo "<input type=\"text\" name=\"bug_id\" size=\"10\" class=\"small\" value=\"$t_bug_label\" onfocus=\"if (this.value == '$t_bug_label') this.value = ''\" onblur=\"if (this.value == '') this.value = '$t_bug_label'\" />&#160;";
  762. } else {
  763. echo "<input type=\"text\" name=\"bug_id\" size=\"10\" class=\"small\" />&#160;";
  764. }
  765. echo '<input type="submit" class="button-small" value="' . lang_get( 'jump' ) . '" />&#160;';
  766. echo '</form>';
  767. echo '</td>';
  768. echo '</tr>';
  769. echo '</table>';
  770. }
  771. }
  772. /**
  773. * Print the menu bar with a list of projects to which the user has access
  774. * @return null
  775. */
  776. function print_project_menu_bar() {
  777. $t_project_ids = current_user_get_accessible_projects();
  778. echo '<table class="width100" cellspacing="0">';
  779. echo '<tr>';
  780. echo '<td class="menu">';
  781. echo '<a href="' . helper_mantis_url( 'set_project.php?project_id=' . ALL_PROJECTS ) . '">' . lang_get( 'all_projects' ) . '</a>';
  782. foreach( $t_project_ids as $t_id ) {
  783. echo ' | <a href="' . helper_mantis_url( 'set_project.php?project_id=' . $t_id ) . '">' . string_html_specialchars( project_get_field( $t_id, 'name' ) ) . '</a>';
  784. print_subproject_menu_bar( $t_id, $t_id . ';' );
  785. }
  786. echo '</td>';
  787. echo '</tr>';
  788. echo '</table>';
  789. }
  790. /**
  791. * Print the menu bar with a list of projects to which the user has access
  792. * @return null
  793. */
  794. function print_subproject_menu_bar( $p_project_id, $p_parents = '' ) {
  795. $t_subprojects = current_user_get_accessible_subprojects( $p_project_id );
  796. $t_char = ':';
  797. foreach( $t_subprojects as $t_subproject ) {
  798. echo $t_char . ' <a href="' . helper_mantis_url( 'set_project.php?project_id=' . $p_parents . $t_subproject ) . '">' . string_html_specialchars( project_get_field( $t_subproject, 'name' ) ) . '</a>';
  799. print_subproject_menu_bar( $t_subproject, $p_parents . $t_subproject . ';' );
  800. $t_char = ',';
  801. }
  802. }
  803. /**
  804. * Print the menu for the graph summary section
  805. * @return null
  806. */
  807. function print_summary_submenu() {
  808. echo '<div align="center">';
  809. # Plugin / Event added options
  810. $t_event_menu_options = event_signal( 'EVENT_SUBMENU_SUMMARY' );
  811. $t_menu_options = array();
  812. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  813. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  814. if( is_array( $t_callback_menu_options ) ) {
  815. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  816. } else {
  817. if ( !is_null( $t_callback_menu_options ) ) {
  818. $t_menu_options[] = $t_callback_menu_options;
  819. }
  820. }
  821. }
  822. }
  823. // Plugins menu items
  824. // TODO: this would be a call to print_pracket_link but the events returns cooked links so we cant
  825. foreach( $t_menu_options as $t_menu_item ) {
  826. echo '<span class="bracket-link">[&#160;';
  827. echo $t_menu_item;
  828. echo '&#160;]</span> ';
  829. }
  830. echo '</div>';
  831. }
  832. /**
  833. * Print the menu for the manage section
  834. *
  835. * @param string $p_page specifies the current page name so it's link can be disabled
  836. * @return null
  837. */
  838. function print_manage_menu( $p_page = '' ) {
  839. $t_manage_user_page = 'manage_user_page.php';
  840. $t_manage_project_menu_page = 'manage_proj_page.php';
  841. $t_manage_custom_field_page = 'manage_custom_field_page.php';
  842. $t_manage_plugin_page = 'manage_plugin_page.php';
  843. $t_manage_config_page = 'adm_config_report.php';
  844. $t_manage_prof_menu_page = 'manage_prof_menu_page.php';
  845. $t_manage_tags_page = 'manage_tags_page.php';
  846. switch( $p_page ) {
  847. case $t_manage_user_page:
  848. $t_manage_user_page = '';
  849. break;
  850. case $t_manage_project_menu_page:
  851. $t_manage_project_menu_page = '';
  852. break;
  853. case $t_manage_custom_field_page:
  854. $t_manage_custom_field_page = '';
  855. break;
  856. case $t_manage_config_page:
  857. $t_manage_config_page = '';
  858. break;
  859. case $t_manage_plugin_page:
  860. $t_manage_plugin_page = '';
  861. break;
  862. case $t_manage_prof_menu_page:
  863. $t_manage_prof_menu_page = '';
  864. break;
  865. case $t_manage_tags_page:
  866. $t_manage_tags_page = '';
  867. break;
  868. }
  869. echo '<div align="center"><p>';
  870. if( access_has_global_level( config_get( 'manage_user_threshold' ) ) ) {
  871. print_bracket_link( helper_mantis_url( $t_manage_user_page ), lang_get( 'manage_users_link' ) );
  872. }
  873. if( access_has_project_level( config_get( 'manage_project_threshold' ) ) ) {
  874. print_bracket_link( helper_mantis_url( $t_manage_project_menu_page ), lang_get( 'manage_projects_link' ) );
  875. }
  876. if( access_has_global_level( config_get( 'tag_edit_threshold' ) ) ) {
  877. print_bracket_link( helper_mantis_url( $t_manage_tags_page ), lang_get( 'manage_tags_link' ) );
  878. }
  879. if( access_has_global_level( config_get( 'manage_custom_fields_threshold' ) ) ) {
  880. print_bracket_link( helper_mantis_url( $t_manage_custom_field_page ), lang_get( 'manage_custom_field_link' ) );
  881. }
  882. if( access_has_global_level( config_get( 'manage_global_profile_threshold' ) ) ) {
  883. print_bracket_link( helper_mantis_url( $t_manage_prof_menu_page ), lang_get( 'manage_global_profiles_link' ) );
  884. }
  885. if( access_has_global_level( config_get( 'manage_plugin_threshold' ) ) ) {
  886. print_bracket_link( helper_mantis_url( $t_manage_plugin_page ), lang_get( 'manage_plugin_link' ) );
  887. }
  888. if( access_has_project_level( config_get( 'view_configuration_threshold' ) ) ) {
  889. print_bracket_link( helper_mantis_url( $t_manage_config_page ), lang_get( 'manage_config_link' ) );
  890. }
  891. # Plugin / Event added options
  892. $t_event_menu_options = event_signal( 'EVENT_MENU_MANAGE' );
  893. $t_menu_options = array();
  894. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  895. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  896. if( is_array( $t_callback_menu_options ) ) {
  897. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  898. } else {
  899. if ( !is_null( $t_callback_menu_options ) ) {
  900. $t_menu_options[] = $t_callback_menu_options;
  901. }
  902. }
  903. }
  904. }
  905. // Plugins menu items
  906. foreach( $t_menu_options as $t_menu_item ) {
  907. print_bracket_link_prepared( $t_menu_item );
  908. }
  909. echo '</p></div>';
  910. }
  911. /**
  912. * Print the menu for the manage configuration section
  913. * @param string $p_page specifies the current page name so it's link can be disabled
  914. * @return null
  915. */
  916. function print_manage_config_menu( $p_page = '' ) {
  917. $t_configuration_report = 'adm_config_report.php';
  918. $t_permissions_summary_report = 'adm_permissions_report.php';
  919. $t_manage_work_threshold = 'manage_config_work_threshold_page.php';
  920. $t_manage_email = 'manage_config_email_page.php';
  921. $t_manage_workflow = 'manage_config_workflow_page.php';
  922. $t_manage_columns = 'manage_config_columns_page.php';
  923. switch( $p_page ) {
  924. case $t_configuration_report:
  925. $t_configuration_report = '';
  926. break;
  927. case $t_permissions_summary_report:
  928. $t_permissions_summary_report = '';
  929. break;
  930. case $t_manage_work_threshold:
  931. $t_manage_work_threshold = '';
  932. break;
  933. case $t_manage_email:
  934. $t_manage_email = '';
  935. break;
  936. case $t_manage_workflow:
  937. $t_manage_workflow = '';
  938. break;
  939. case $t_manage_columns:
  940. $t_manage_columns = '';
  941. break;
  942. }
  943. echo '<br /><div align="center">';
  944. if( access_has_project_level( config_get( 'view_configuration_threshold' ) ) ) {
  945. print_bracket_link( helper_mantis_url( $t_configuration_report ), lang_get_defaulted( 'configuration_report' ) );
  946. print_bracket_link( helper_mantis_url( $t_permissions_summary_report ), lang_get( 'permissions_summary_report' ) );
  947. print_bracket_link( helper_mantis_url( $t_manage_work_threshold ), lang_get( 'manage_threshold_config' ) );
  948. print_bracket_link( helper_mantis_url( $t_manage_workflow ), lang_get( 'manage_workflow_config' ) );
  949. print_bracket_link( helper_mantis_url( $t_manage_email ), lang_get( 'manage_email_config' ) );
  950. print_bracket_link( $t_manage_columns, lang_get( 'manage_columns_config' ) );
  951. }
  952. # Plugin / Event added options
  953. $t_event_menu_options = event_signal( 'EVENT_MENU_MANAGE_CONFIG' );
  954. $t_menu_options = array();
  955. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  956. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  957. if( is_array( $t_callback_menu_options ) ) {
  958. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  959. } else {
  960. if ( !is_null( $t_callback_menu_options ) ) {
  961. $t_menu_options[] = $t_callback_menu_options;
  962. }
  963. }
  964. }
  965. }
  966. // Plugins menu items
  967. foreach( $t_menu_options as $t_menu_item ) {
  968. print_bracket_link_prepared( $t_menu_item );
  969. }
  970. echo '</div>';
  971. }
  972. /**
  973. * Print the menu for the account section
  974. * @param string $p_page specifies the current page name so it's link can be disabled
  975. * @return null
  976. */
  977. function print_account_menu( $p_page = '' ) {
  978. $t_account_page = 'account_page.php';
  979. $t_account_prefs_page = 'account_prefs_page.php';
  980. $t_account_profile_menu_page = 'account_prof_menu_page.php';
  981. $t_account_sponsor_page = 'account_sponsor_page.php';
  982. $t_account_manage_columns_page = 'account_manage_columns_page.php';
  983. switch( $p_page ) {
  984. case $t_account_page:
  985. $t_account_page = '';
  986. break;
  987. case $t_account_prefs_page:
  988. $t_account_prefs_page = '';
  989. break;
  990. case $t_account_profile_menu_page:
  991. $t_account_profile_menu_page = '';
  992. break;
  993. case $t_account_sponsor_page:
  994. $t_account_sponsor_page = '';
  995. break;
  996. case $t_account_manage_columns_page:
  997. $t_account_manage_columns_page = '';
  998. break;
  999. }
  1000. print_bracket_link( $t_account_page, lang_get( 'account_link' ) );
  1001. print_bracket_link( $t_account_prefs_page, lang_get( 'change_preferences_link' ) );
  1002. print_bracket_link( $t_account_manage_columns_page, lang_get( 'manage_columns_config' ) );
  1003. if( config_get ( 'enable_profiles' ) == ON && access_has_project_level( config_get( 'add_profile_threshold' ) ) ) {
  1004. print_bracket_link( helper_mantis_url( $t_account_profile_menu_page ), lang_get( 'manage_profiles_link' ) );
  1005. }
  1006. if( config_get( 'enable_sponsorship' ) == ON && access_has_project_level( config_get( 'view_sponsorship_total_threshold' ) ) && !current_user_is_anonymous() ) {
  1007. print_bracket_link( helper_mantis_url( $t_account_sponsor_page ), lang_get( 'my_sponsorship' ) );
  1008. }
  1009. # Plugin / Event added options
  1010. $t_event_menu_options = event_signal( 'EVENT_MENU_ACCOUNT' );
  1011. $t_menu_options = array();
  1012. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  1013. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  1014. if( is_array( $t_callback_menu_options ) ) {
  1015. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  1016. } else {
  1017. if ( !is_null( $t_callback_menu_options ) ) {
  1018. $t_menu_options[] = $t_callback_menu_options;
  1019. }
  1020. }
  1021. }
  1022. }
  1023. // Plugins menu items
  1024. // TODO: this would be a call to print_pracket_link but the events returns cooked links so we cant
  1025. foreach( $t_menu_options as $t_menu_item ) {
  1026. echo '<span class="bracket-link">[&#160;';
  1027. echo $t_menu_item;
  1028. echo '&#160;]</span> ';
  1029. }
  1030. }
  1031. /**
  1032. * Print the menu for the docs section
  1033. * @param string $p_page specifies the current page name so it's link can be disabled
  1034. * @return null
  1035. */
  1036. function print_doc_menu( $p_page = '' ) {
  1037. $t_documentation_html = config_get( 'manual_url' );
  1038. $t_proj_doc_page = 'proj_doc_page.php';
  1039. $t_proj_doc_add_page = 'proj_doc_add_page.php';
  1040. switch( $p_page ) {
  1041. case $t_documentation_html:
  1042. $t_documentation_html = '';
  1043. break;
  1044. case $t_proj_doc_page:
  1045. $t_proj_doc_page = '';
  1046. break;
  1047. case $t_proj_doc_add_page:
  1048. $t_proj_doc_add_page = '';
  1049. break;
  1050. }
  1051. print_bracket_link( $t_documentation_html, lang_get( 'user_documentation' ) );
  1052. print_bracket_link( helper_mantis_url( $t_proj_doc_page ), lang_get( 'project_documentation' ) );
  1053. if( file_allow_project_upload() ) {
  1054. print_bracket_link( helper_mantis_url( $t_proj_doc_add_page ), lang_get( 'add_file' ) );
  1055. }
  1056. }
  1057. /**
  1058. * Print the menu for the summary section
  1059. * @param string $p_page specifies the current page name so it's link can be disabled
  1060. * @return null
  1061. */
  1062. function print_summary_menu( $p_page = '' ) {
  1063. echo '<div align="center">';
  1064. print_bracket_link( 'print_all_bug_page.php', lang_get( 'print_all_bug_page_link' ) );
  1065. print_bracket_link( helper_mantis_url( 'summary_page.php' ), lang_get( 'summary_link' ) );
  1066. # Plugin / Event added options
  1067. $t_event_menu_options = event_signal( 'EVENT_MENU_SUMMARY' );
  1068. $t_menu_options = array();
  1069. foreach( $t_event_menu_options as $t_plugin => $t_plugin_menu_options ) {
  1070. foreach( $t_plugin_menu_options as $t_callback => $t_callback_menu_options ) {
  1071. if( is_array( $t_callback_menu_options ) ) {
  1072. $t_menu_options = array_merge( $t_menu_options, $t_callback_menu_options );
  1073. } else {
  1074. if ( !is_null( $t_callback_menu_options ) ) {
  1075. $t_menu_options[] = $t_callback_menu_options;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. // Plugins menu items
  1081. // TODO: this would be a call to print_pracket_link but the events returns cooked links so we cant
  1082. foreach( $t_menu_options as $t_menu_item ) {
  1083. echo '<span class="bracket-link">[&#160;';
  1084. echo $t_menu_item;
  1085. echo '&#160;]</span> ';
  1086. }
  1087. echo '</div>';
  1088. }
  1089. /**
  1090. * Print the color legend for the status colors
  1091. * @param string
  1092. * @return null
  1093. */
  1094. function html_status_legend() {
  1095. echo '<br />';
  1096. echo '<table class="width100" cellspacing="1">';
  1097. echo '<tr>';
  1098. $t_status_array = MantisEnum::getAssocArrayIndexedByValues( config_get( 'status_enum_string' ) );
  1099. $t_status_names = MantisEnum::getAssocArrayIndexedByValues( lang_get( 'status_enum_string' ) );
  1100. $enum_count = count( $t_status_array );
  1101. # read through the list and eliminate unused ones for the selected project
  1102. # assumes that all status are are in the enum array
  1103. $t_workflow = config_get( 'status_enum_workflow' );
  1104. if( !empty( $t_workflow ) ) {
  1105. foreach( $t_status_array as $t_status => $t_name ) {
  1106. if( !isset( $t_workflow[$t_status] ) ) {
  1107. # drop elements that are not in the workflow
  1108. unset( $t_status_array[$t_status] );
  1109. }
  1110. }
  1111. }
  1112. # draw the status bar
  1113. $width = (int)( 100 / count( $t_status_array ) );
  1114. foreach( $t_status_array as $t_status => $t_name ) {
  1115. $t_val = isset( $t_status_names[$t_status] ) ? $t_status_names[$t_status] : $t_status_array[$t_status];
  1116. $t_color = get_status_color( $t_status );
  1117. echo "<td class=\"small-caption\" width=\"$width%\" bgcolor=\"$t_color\">$t_val</td>";
  1118. }
  1119. echo '</tr>';
  1120. echo '</table>';
  1121. if( ON == config_get( 'status_percentage_legend' ) ) {
  1122. html_status_percentage_legend();
  1123. }
  1124. }
  1125. /**
  1126. * Print the legend for the status percentage
  1127. * @return null
  1128. */
  1129. function html_status_percentage_legend() {
  1130. $t_mantis_bug_table = db_get_table( 'mantis_bug_table' );
  1131. $t_project_id = helper_get_current_project();
  1132. $t_user_id = auth_get_current_user_id();
  1133. # checking if it's a per project statistic or all projects
  1134. $t_specific_where = helper_project_specific_where( $t_project_id, $t_user_id );
  1135. $query = "SELECT status, COUNT(*) AS number
  1136. FROM $t_mantis_bug_table
  1137. WHERE $t_specific_where";
  1138. if ( !access_has_project_level( config_get( 'private_bug_threshold' ) ) ) {
  1139. $query .= ' AND view_state < ' . VS_PRIVATE;
  1140. }
  1141. $query .= ' GROUP BY status';
  1142. $result = db_query_bound( $query );
  1143. $t_bug_count = 0;
  1144. $t_status_count_array = array();
  1145. while( $row = db_fetch_array( $result ) ) {
  1146. $t_status_count_array[$row['status']] = $row['number'];
  1147. $t_bug_count += $row['number'];
  1148. }
  1149. $t_enum_values = MantisEnum::getValues( config_get( 'status_enum_string' ) );
  1150. $enum_count = count( $t_enum_values );
  1151. if( $t_bug_count > 0 ) {
  1152. echo '<br />';
  1153. echo '<table class="width100" cellspacing="1">';
  1154. echo '<tr>';
  1155. echo '<td class="form-title" colspan="' . $enum_count . '">' . lang_get( 'issue_status_percentage' ) . '</td>';
  1156. echo '</tr>';
  1157. echo '<tr>';
  1158. foreach ( $t_enum_values as $t_status ) {
  1159. $t_color = get_status_color( $t_status );
  1160. if ( !isset( $t_status_count_array[$t_status] ) ) {
  1161. $t_status_count_array[$t_status] = 0;
  1162. }
  1163. $width = round(( $t_status_count_array[$t_status] / $t_bug_count ) * 100 );
  1164. if( $width > 0 ) {
  1165. echo "<td class=\"small-caption-center\" width=\"$width%\" bgcolor=\"$t_color\">$width%</td>";
  1166. }
  1167. }
  1168. echo '</tr>';
  1169. echo '</table>';
  1170. }
  1171. }
  1172. /**
  1173. * Print an html button inside a form
  1174. * @param string $p_action
  1175. * @param string $p_button_text
  1176. * @param array $p_fields
  1177. * @param string $p_method
  1178. * @return null
  1179. */
  1180. function html_button( $p_action, $p_button_text, $p_fields = null, $p_method = 'post' ) {
  1181. $t_form_name = explode( '.php', $p_action, 2 );
  1182. $p_action = urlencode( $p_action );
  1183. $p_button_text = string_attribute( $p_button_text );
  1184. if( null === $p_fields ) {
  1185. $p_fields = array();
  1186. }
  1187. if( utf8_strtolower( $p_method ) == 'get' ) {
  1188. $t_method = 'get';
  1189. } else {
  1190. $t_method = 'post';
  1191. }
  1192. echo "<form method=\"$t_method\" action=\"$p_action\">\n";
  1193. # Add a CSRF token only when the form is being sent via the POST method
  1194. if ( $t_method == 'post' ) {
  1195. echo form_security_field( $t_form_name[0] );
  1196. }
  1197. foreach( $p_fields as $key => $val ) {
  1198. $key = string_attribute( $key );
  1199. $val = string_attribute( $val );
  1200. echo " <input type=\"hidden\" name=\"$key\" value=\"$val\" />\n";
  1201. }
  1202. echo " <input type=\"submit\" class=\"button\" value=\"$p_button_text\" />\n";
  1203. echo "</form>\n";
  1204. }
  1205. /**
  1206. * Print a button to update the given bug
  1207. * @param int $p_bug_id
  1208. * @return null
  1209. */
  1210. function html_button_bug_update( $p_bug_id ) {
  1211. if( access_has_bug_level( config_get( 'update_bug_threshold' ), $p_bug_id ) ) {
  1212. html_button( string_get_bug_update_page(), lang_get( 'update_bug_button' ), array( 'bug_id' => $p_bug_id ) );
  1213. }
  1214. }
  1215. /**
  1216. * Print Change Status to: button
  1217. * This code is similar to print_status_option_list except
  1218. * there is no masking, except for the current state
  1219. *
  1220. * @param BugData $p_bug Bug object
  1221. * @return null
  1222. */
  1223. function html_button_bug_change_status( $p_bug ) {
  1224. $t_current_access = access_get_project_level( $p_bug->project_id );
  1225. # User must have rights to change status to use this button
  1226. if( !access_has_bug_level( config_get( 'update_bug_status_threshold' ), $p_bug->id ) ) {
  1227. return;
  1228. }
  1229. $t_enum_list = get_status_option_list(
  1230. $t_current_access,
  1231. $p_bug->status,
  1232. false,
  1233. # Add close if user is bug's reporter, still has rights to report issues
  1234. # (to prevent users downgraded to viewers from updating issues) and
  1235. # reporters are allowed to close their own issues
  1236. ( bug_is_user_reporter( $p_bug->id, auth_get_current_user_id() )
  1237. && access_has_bug_level( config_get( 'report_bug_threshold' ), $p_bug->id )
  1238. && ON == config_get( 'allow_reporter_close' )
  1239. ),
  1240. $p_bug->project_id );
  1241. if( count( $t_enum_list ) > 0 ) {
  1242. # resort the list into ascending order after noting the key from the first element (the default)
  1243. $t_default_arr = each( $t_enum_list );
  1244. $t_default = $t_default_arr['key'];
  1245. ksort( $t_enum_list );
  1246. reset( $t_enum_list );
  1247. echo "<form method=\"post\" action=\"bug_change_status_page.php\">";
  1248. # CSRF protection not required here - form does not result in modifications
  1249. $t_button_text = lang_get( 'bug_status_to_button' );
  1250. echo "<input type=\"submit\" class=\"button\" value=\"$t_button_text\" />";
  1251. echo " <select name=\"new_status\">";
  1252. # space at beginning of line is important
  1253. foreach( $t_enum_list as $key => $val ) {
  1254. echo "<option value=\"$key\" ";
  1255. check_selected( $key, $t_default );
  1256. echo ">$val</option>";
  1257. }
  1258. echo '</select>';
  1259. $t_bug_id = string_attribute( $p_bug->id );
  1260. echo "<input type=\"hidden\" name=\"id\" value=\"$t_bug_id\" />\n";
  1261. echo "</form>\n";
  1262. }
  1263. }
  1264. /**
  1265. * Print Assign To: combo box of possible handlers
  1266. * @param BugData $p_bug Bug object
  1267. * @return null
  1268. */
  1269. function html_button_bug_assign_to( $p_bug ) {
  1270. # make sure status is allowed of assign would cause auto-set-status
  1271. # workflow implementation
  1272. if( ON == config_get( 'auto_set_status_to_assigned' )
  1273. && !bug_check_workflow( $p_bug->status, config_get( 'bug_assigned_status' ) )
  1274. ) {
  1275. return;
  1276. }
  1277. # make sure current user has access to modify bugs.
  1278. if( !access_has_bug_level( config_get( 'update_bug_assign_threshold', config_get( 'update_bug_threshold' ) ), $p_bug->id ) ) {
  1279. return;
  1280. }
  1281. $t_current_user_id = auth_get_current_user_id();
  1282. $t_new_status = ( ON == config_get( 'auto_set_status_to_assigned' ) ) ? config_get( 'bug_assigned_status' ) : $p_bug->status;
  1283. $t_options = array();
  1284. $t_default_assign_to = null;
  1285. if( ( $p_bug->handler_id != $t_current_user_id )
  1286. && access_has_bug_level( config_get( 'handle_bug_threshold' ), $p_bug->id, $t_current_user_id )
  1287. ) {
  1288. $t_options[] = array(
  1289. $t_current_user_id,
  1290. '[' . lang_get( 'myself' ) . ']',
  1291. );
  1292. $t_default_assign_to = $t_current_user_id;
  1293. }
  1294. if( ( $p_bug->handler_id != $p_bug->reporter_id )
  1295. && user_exists( $p_bug->reporter_id )
  1296. && access_has_bug_level( config_get( 'handle_bug_threshold' ), $p_bug->id, $p_bug->reporter_id )
  1297. ) {
  1298. $t_options[] = array(
  1299. $p_bug->reporter_id,
  1300. '[' . lang_get( 'reporter' ) . ']',
  1301. );
  1302. if( $t_default_assign_to === null ) {
  1303. $t_default_assign_to = $p_bug->reporter_id;
  1304. }
  1305. }
  1306. echo "<form method=\"post\" action=\"bug_assign.php\">";
  1307. echo form_security_field( 'bug_assign' );
  1308. $t_button_text = lang_get( 'bug_assign_to_button' );
  1309. echo "<input type=\"submit\" class=\"button\" value=\"$t_button_text\" />";
  1310. echo " <select name=\"handler_id\">";
  1311. # space at beginning of line is important
  1312. $t_already_selected = false;
  1313. foreach( $t_options as $t_entry ) {
  1314. $t_id = string_attribute( $t_entry[0] );
  1315. $t_caption = string_attribute( $t_entry[1] );
  1316. # if current user and reporter can't be selected, then select the first
  1317. # user in the list.
  1318. if( $t_default_assign_to === null ) {
  1319. $t_default_assign_to = $t_id;
  1320. }
  1321. echo '<option value="' . $t_id . '" ';
  1322. if(( $t_id == $t_default_assign_to ) && !$t_already_selected ) {
  1323. check_selected( $t_id, $t_default_assign_to );
  1324. $t_already_selected = true;
  1325. }
  1326. echo '>' . $t_caption . '</option>';
  1327. }
  1328. # allow un-assigning if already assigned.
  1329. if( $p_bug->handler_id != 0 ) {
  1330. echo "<option value=\"0\"></option>";
  1331. }
  1332. # 0

Large files files are truncated, but you can click here to view the full file