PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/WebCalendar-1.2.5/includes/trailer.php

#
PHP | 335 lines | 317 code | 10 blank | 8 comment | 26 complexity | a5ae9839e4740678dea7a619db0f1199 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /* $Id: trailer.php,v 1.128.2.3 2008/02/27 00:33:40 cknudsen Exp $*/
  3. defined ( '_ISVALID' ) or die ( 'You cannot access this file directly!' );
  4. // NOTE: This file is included within the print_trailer function found in
  5. // includes/init.php. If you add a global variable somewhere in this file, be
  6. // sure to declare it global in the print_trailer function or use $GLOBALS[].
  7. $tret = '';
  8. if ( access_can_access_function ( ACCESS_TRAILER ) ) {
  9. $tret .= '
  10. <div id="trailer">
  11. <div id="menu">' . "\n";
  12. $goto_link = $manage_calendar_link = $reports_link = $views_link = array ();
  13. $myCalStr = translate ( 'My Calendar' );
  14. $todayStr = translate ( 'Today' );
  15. $adminStr = translate ( 'Admin' );
  16. $unapprovedStr = translate ( 'Unapproved Entries' );
  17. $searchStr = translate ( 'Search' );
  18. $importStr = translate ( 'Import' );
  19. $exportStr = translate ( 'Export' );
  20. $addNewEntryStr = translate ( 'Add New Entry' );
  21. $addNewTaskStr = translate ( 'Add New Task' );
  22. $loginStr = translate ( 'Login' );
  23. $logoutStr = translate ( 'Logout' );
  24. $currentUserStr = translate ( 'Current User' );
  25. $helpStr = translate ( 'Help' );
  26. $publicStr = $PUBLIC_ACCESS_FULLNAME;
  27. if ( empty ( $readonly ) || $readonly != 'Y' )
  28. $readonly = 'N';
  29. // Go To links.
  30. $can_add = true;
  31. if ( $readonly == 'Y' )
  32. $can_add = false;
  33. else
  34. if ( access_is_enabled () )
  35. $can_add = access_can_access_function ( ACCESS_EVENT_EDIT );
  36. else {
  37. if ( $login == '__public__' )
  38. $can_add = ( $GLOBALS['PUBLIC_ACCESS_CAN_ADD'] == 'Y' );
  39. if ( $is_nonuser )
  40. $can_add = false;
  41. }
  42. // Get HOME URL and text.
  43. if ( ! empty ( $GLOBALS['HOME_LINK'] ) ) {
  44. $home = $GLOBALS['HOME_LINK'];
  45. $homeStr = translate ( 'Home' );
  46. $goto_link[] = '<a title="' . $homeStr . '" class="bold" href=" '
  47. . "$home\">$homeStr" . '</a>';
  48. }
  49. $mycal = ( empty ( $GLOBALS['STARTVIEW'] )
  50. ? 'index.php' : $GLOBALS['STARTVIEW'] );
  51. $mycal .= ( strpos ( $mycal, '.php' )? '' : '.php' );
  52. // Calc URL to today.
  53. $reqURI = 'month.php';
  54. if ( ! empty ( $GLOBALS['SCRIPT_NAME'] ) )
  55. $reqURI = $GLOBALS['SCRIPT_NAME'];
  56. else
  57. if ( ! empty ( $_SERVER['SCRIPT_NAME'] ) )
  58. $reqURI = $_SERVER['SCRIPT_NAME'];
  59. $todayURL = ( ! strstr ( $reqURI, 'day.php' ) && !
  60. strstr ( $reqURI, 'month.php' ) && ! strstr ( $reqURI, 'week.php' )
  61. ? 'day.php' : $reqURI );
  62. if ( ! access_can_view_page ( $todayURL ) )
  63. $todayURL = '';
  64. if ( $single_user != 'Y' ) {
  65. $goto_link[] = '<a title="' . $myCalStr . '" class="bold" href="'
  66. . "$mycal\">" . ( ! empty ( $user ) && $user != $login
  67. ? translate ( 'Back to My Calendar' ) : $myCalStr ) . '</a>';
  68. if ( ! empty ( $todayURL ) ) {
  69. if ( ! empty ( $user ) && $user != $login )
  70. $todayURL .= '?user=' . $user;
  71. $goto_link[] = '<a title="' . $todayStr . '" class="bold" href="'
  72. . "$todayURL\">$todayStr" . '</a>';
  73. }
  74. if ( $login != '__public__' ) {
  75. if ( ! $is_nonuser && $readonly == 'N' ) {
  76. if ( ( ! access_is_enabled () ||
  77. access_can_access_function ( ACCESS_ADMIN_HOME ) ||
  78. access_can_access_function ( ACCESS_PREFERENCES ) ) )
  79. $goto_link[] = '<a title="' . $adminStr
  80. . '" class="bold" href="adminhome.php'
  81. . ( $is_nonuser_admin ? '?user=' . $user : '' )
  82. . "\">$adminStr" . '</a>';
  83. if ( $REQUIRE_APPROVALS == 'Y' || $PUBLIC_ACCESS == 'Y' )
  84. $goto_link[] = '<a title="' . $unapprovedStr
  85. . '" href="list_unapproved.php'
  86. . ( $is_nonuser_admin ? '?user=' . getValue ( 'user' ) : '' )
  87. . "\">$unapprovedStr" . '</a>';
  88. }
  89. }
  90. if ( $login == '__public__' && $PUBLIC_ACCESS_OTHERS != 'Y' ||
  91. ( $is_nonuser && ! access_is_enabled () ) ) {
  92. // Don't allow them to see other people's calendar.
  93. } else
  94. if ( ( $ALLOW_VIEW_OTHER == 'Y' || $is_admin ) &&
  95. // Also, make sure they able to access either day/week/month/year view.
  96. // If not, the only way to view another user's calendar is a custom view.
  97. ( ! access_is_enabled () ||
  98. access_can_access_function ( ACCESS_ANOTHER_CALENDAR ) ) ) {
  99. // Get count of users this user can see. If > 1, then...
  100. $ulist = array_merge ( get_my_users (), get_my_nonusers ( $login, true ) );
  101. if ( count ( $ulist ) > 1 ) {
  102. $calStr = translate ( 'Another Users Calendar' );
  103. $goto_link[] = '<a title="' . $calStr . '" href="select_user.php">'
  104. . $calStr . '</a>';
  105. }
  106. }
  107. } else {
  108. $goto_link[] = '<a title="' . $myCalStr . '" class="bold" href="'
  109. . "$mycal\">$myCalStr" . '</a>';
  110. $goto_link[] = '<a title="' . $todayStr . '" class="bold" href="'
  111. . "$todayURL\">$todayStr" . '</a>';
  112. if ( $readonly == 'N' )
  113. $goto_link[] = '<a title="' . $adminStr
  114. . '" class="bold" href="adminhome.php">' . $adminStr . '</a>';
  115. }
  116. // Only display some links if we're viewing our own calendar.
  117. if ( empty ( $user ) || $user == $login ) {
  118. if ( access_can_access_function ( ACCESS_SEARCH ) )
  119. $goto_link[] = '<a title="' . $searchStr . '" href="search.php">'
  120. . $searchStr . '</a>';
  121. if ( $login != '__public__' && ! $is_nonuser && $readonly != 'Y' ) {
  122. if ( access_can_access_function ( ACCESS_IMPORT ) )
  123. $goto_link[] = '<a title="' . $importStr . '" href="import.php">'
  124. . $importStr . '</a>';
  125. if ( access_can_access_function ( ACCESS_EXPORT ) )
  126. $goto_link[] = '<a title="' . $exportStr . '" href="export.php">'
  127. . $exportStr . '</a>';
  128. }
  129. if ( $can_add ) {
  130. if ( ! empty ( $thisyear ) )
  131. $tmpYrStr = 'year=' . $thisyear
  132. . ( ! empty ( $thismonth ) ? '&amp;month=' . $thismonth : '' )
  133. . ( ! empty ( $thisday ) ? '&amp;day=' . $thisday : '' );
  134. $goto_link[] = '<a title="' . $addNewEntryStr . '" href="edit_entry.php'
  135. . ( ! empty ( $thisyear ) ? '?' . $tmpYrStr : '' )
  136. . '">' . $addNewEntryStr . '</a>';
  137. if ( $DISPLAY_TASKS_IN_GRID == 'Y' || $DISPLAY_TASKS == 'Y' )
  138. $goto_link[] = '<a title="' . $addNewTaskStr
  139. . '" href="edit_entry.php?eType=task'
  140. . ( ! empty ( $thisyear ) ? '&amp;' . $tmpYrStr : '' )
  141. . '">' . $addNewTaskStr . '</a>';
  142. }
  143. }
  144. $showHelp = ( access_is_enabled ()
  145. ? access_can_access_function ( ACCESS_HELP )
  146. : ( $login != '__public__' && ! $is_nonuser ) );
  147. if ( $showHelp )
  148. $goto_link[] = '<a title="' . $helpStr
  149. . '" href="#" onclick="javascript:openHelp()" '
  150. . 'onmouseover="window.status=\'\'; return true">' . $helpStr . '</a>';
  151. if ( count ( $goto_link ) > 0 ) {
  152. $tret .= '<span class="prefix">' . translate ( 'Go to' ) . ':</span>' . "\n";
  153. $gotocnt = count ( $goto_link );
  154. for ( $i = 0; $i < $gotocnt; $i++ ) {
  155. $tret .= ( $i > 0 ? ' | ' : '' ) . $goto_link[$i] . "\n";
  156. }
  157. }
  158. $tret .= '<!-- VIEWS -->' . "\n";
  159. $viewcnt = count ( $views );
  160. if ( ( access_can_access_function ( ACCESS_VIEW ) && $ALLOW_VIEW_OTHER != 'N' ) && $viewcnt > 0 ) {
  161. for ( $i = 0; $i < $viewcnt; $i++ ) {
  162. $views_link[] = '<a title="' . htmlspecialchars ( $views[$i]['cal_name'] )
  163. . '" href="' . $views[$i]['url']
  164. . ( ! empty ( $thisdate ) ? '&amp;date=' . $thisdate : '' )
  165. . '">' . htmlspecialchars ( $views[$i]['cal_name'] ) . "</a>\n";
  166. }
  167. }
  168. $views_linkcnt = count ( $views_link );
  169. if ( $views_linkcnt > 0 ) {
  170. $tret .= '<br /><span class="prefix">' . translate ( 'Views' )
  171. . ':</span>&nbsp;' . "\n";
  172. for ( $i = 0; $i < $views_linkcnt; $i++ ) {
  173. $tret .= ( $i > 0 ? ' | ' : '' ) . $views_link[$i];
  174. }
  175. }
  176. $tret .= '<!-- REPORTS -->' . "\n";
  177. if ( ! empty ( $REPORTS_ENABLED ) && $REPORTS_ENABLED == 'Y' &&
  178. access_can_access_function ( ACCESS_REPORT ) ) {
  179. $reports_link = array ();
  180. $rows = dbi_get_cached_rows ( 'SELECT cal_report_name, cal_report_id
  181. FROM webcal_report WHERE cal_login = ? OR ( cal_is_global = \'Y\'
  182. AND cal_show_in_trailer = \'Y\' ) ORDER BY cal_report_id',
  183. array ( $login ) );
  184. if ( $rows ) {
  185. for ( $i = 0, $cnt = count ( $rows ); $i < $cnt; $i++ ) {
  186. $row = $rows[$i];
  187. $reports_link[] = '<a title="' . htmlspecialchars ( $row[0] )
  188. . '" href="report.php?report_id=' . $row[1]
  189. . ( ! empty ( $user ) && $user != $login ? '&amp;user=' . $user : '' )
  190. . '">' . htmlspecialchars ( $row[0] ) . '</a>';
  191. }
  192. }
  193. $reports_linkcnt = count ( $reports_link );
  194. if ( $reports_linkcnt > 0 ) {
  195. $tret .= '<br /><span class="prefix">' . translate ( 'Reports' )
  196. . ':</span>&nbsp;' . "\n";
  197. for ( $i = 0; $i < $reports_linkcnt; $i++ ) {
  198. $tret .= ( $i > 0 ? ' | ' : '' ) . $reports_link[$i] . "\n";
  199. }
  200. }
  201. }
  202. $tret .= '<!-- CURRENT USER -->' . "\n";
  203. if ( ! $use_http_auth ) {
  204. $login_url = $logout_url = 'login.php';
  205. if ( empty ( $login_return_path ) )
  206. $logout_url .= '?action=logout';
  207. else {
  208. $login_url .= '?return_path=' . $login_return_path;
  209. $logout_url .= $login_url . '&action=logout';
  210. }
  211. // Should we use another application's login/logout pages?
  212. if ( substr ( $GLOBALS['user_inc'], 0, 9 ) == 'user-app-' ) {
  213. global $app_login_page, $app_logout_page;
  214. $logout_url = $app_logout_page;
  215. $login_url = 'login-app.php'
  216. . ( $login_return_path != '' && $app_login_page['return'] != ''
  217. ? '?return_path=' . $login_return_path : '' );
  218. }
  219. if ( $readonly != 'Y' )
  220. $tret .= '<br /><span class="prefix">' . $currentUserStr . ':</span>&nbsp;'
  221. . ( strlen ( $login ) && $login != '__public__'
  222. ? $fullname . '&nbsp;(<a title="' . $logoutStr . '" href="'
  223. . $logout_url . '">' . $logoutStr
  224. : // For public user (who did not actually login).
  225. $publicStr . '&nbsp;(<a title="' . $loginStr . '" href="' . $login_url
  226. . '">' . $loginStr ) . "</a>)\n" ;
  227. }
  228. // Manage Calendar links.
  229. if ( ! empty ( $NONUSER_ENABLED ) && $NONUSER_ENABLED == 'Y' )
  230. $admincals = get_nonuser_cals ( $login );
  231. // Make sure they have access to either month/week/day view. If they do not,
  232. // then we cannot create a URL that shows just the boss' events. So, we
  233. // would not include any of the "manage calendar of" links.
  234. $have_boss_url = true;
  235. if ( ! access_can_access_function ( ACCESS_MONTH ) && !
  236. access_can_access_function ( ACCESS_WEEK ) && !
  237. access_can_access_function ( ACCESS_DAY ) )
  238. $have_boss_url = false;
  239. if ( $have_boss_url && ( $has_boss || ! empty ( $admincals[0] ) ||
  240. ( $is_admin && $PUBLIC_ACCESS ) ) ) {
  241. $grouplist = user_get_boss_list ( $login );
  242. if ( ! empty ( $admincals[0] ) )
  243. $grouplist = array_merge ( $admincals, $grouplist );
  244. if ( $is_admin && $PUBLIC_ACCESS == 'Y' ) {
  245. $public = array (
  246. 'cal_login' => '__public__',
  247. 'cal_fullname' => $publicStr
  248. );
  249. array_unshift ( $grouplist, $public );
  250. }
  251. $groups = '';
  252. for ( $i = 0, $cnt = count ( $grouplist ); $i < $cnt; $i++ ) {
  253. $l = $grouplist[$i]['cal_login'];
  254. $f = $grouplist[$i]['cal_fullname'];
  255. // don't display current $user in group list
  256. if ( ! empty ( $user ) && $user == $l )
  257. continue;
  258. // Use the preferred view if it is day/week/month/year.php. Try not to
  259. // use a user-created view because it might not display the proper user's
  260. // events. (Fallback to month.php if this is true.) Of course, if this
  261. // user cannot view any of the standard D/W/M/Y pages, that will force us
  262. // to use the view.
  263. $xurl = get_preferred_view ( '', 'user=' . $l );
  264. if ( strstr ( $xurl, 'view_' ) ) {
  265. if ( access_can_access_function ( ACCESS_MONTH ) )
  266. $xurl = 'month.php?user=' . $l;
  267. elseif ( access_can_access_function ( ACCESS_WEEK ) )
  268. $xurl = 'week.php?user=' . $l;
  269. elseif ( access_can_access_function ( ACCESS_DAY ) )
  270. $xurl = 'day.php?user=' . $l;
  271. // Year does not show events, so you cannot manage someone's cal.
  272. }
  273. $groups .= ( $i > 0 && $groups != '' ? ", \n" : '' )
  274. . '<a title="' . "$f\" href=\"$xurl\">$f".'</a>';
  275. }
  276. if ( ! empty ( $groups ) )
  277. $tret .= '<br /><span class="prefix">'
  278. . translate ( 'Manage calendar of' ) . ':</span>&nbsp;' . $groups;
  279. }
  280. // WebCalendar Info...
  281. $tret .= '<br /><br />
  282. <a title="' . $GLOBALS['PROGRAM_NAME'] . '" id="programname" href="'
  283. . $GLOBALS['PROGRAM_URL'] . '" target="_blank">' . $GLOBALS['PROGRAM_NAME']
  284. . "</a>\n" . '</div></div>
  285. <!-- /TRAILER -->' . "\n";
  286. }
  287. $tret .= '<!-- Db queries: ' . dbi_num_queries () . ' Cached queries: '
  288. . dbi_num_cached_queries () . " -->\n";
  289. if ( dbi_get_debug () ) {
  290. $tret .= '<blockquote style="border:1px solid #ccc; background:#eee;">
  291. <b>Executed queries:' . dbi_num_queries ()
  292. . '&nbsp;&nbsp; <b>Cached queries:</b>' . dbi_num_cached_queries ()
  293. . "<br /><ol>\n";
  294. $log = $GLOBALS['SQLLOG'];
  295. // $log=0;
  296. $logcnt = count ( $log );
  297. for ( $i = 0; $i < $logcnt; $i++ ) {
  298. $tret .= '<li>' . $log[$i] . '</li>';
  299. }
  300. $tret .= "</ol>\n</blockquote>\n";
  301. }
  302. ?>