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

/Branch_4_6dev/gforge/plugins/webcalendar/www/includes/functions.php

https://gitlab.com/oslc-cm-server/olbergers-ff5-oslc
PHP | 5204 lines | 3337 code | 381 blank | 1486 comment | 1142 complexity | 9d32c58484ced9b4a4a052d06ed5e590 MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception

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

  1. <?php
  2. /**
  3. * All of WebCalendar's functions
  4. *
  5. * @author Craig Knudsen <cknudsen@cknudsen.com>
  6. * @copyright Craig Knudsen, <cknudsen@cknudsen.com>, http://www.k5n.us/cknudsen
  7. * @license http://www.gnu.org/licenses/gpl.html GNU GPL
  8. * @package WebCalendar
  9. */
  10. if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER ) &&
  11. ! empty ( $_SERVER['PHP_SELF'] ) ) {
  12. $PHP_SELF = $_SERVER['PHP_SELF'];
  13. }
  14. if ( ! empty ( $PHP_SELF ) && preg_match ( "/\/includes\//", $PHP_SELF ) ) {
  15. die ( "You can't access this file directly!" );
  16. }
  17. /**#@+
  18. * Used for activity log
  19. * @global string
  20. */
  21. $LOG_CREATE = "C";
  22. $LOG_APPROVE = "A";
  23. $LOG_REJECT = "X";
  24. $LOG_UPDATE = "U";
  25. $LOG_DELETE = "D";
  26. $LOG_NOTIFICATION = "N";
  27. $LOG_REMINDER = "R";
  28. /**#@-*/
  29. /**
  30. *File to log
  31. *
  32. */
  33. global $log_file;
  34. $log_file="/var/lib/gforge/chroot/home/users/placoste/webcalendar/webcalendar.txt";
  35. /**
  36. * Number of seconds in a day
  37. *
  38. * @global int $ONE_DAY
  39. */
  40. $ONE_DAY = 86400;
  41. /**
  42. * Array containing the number of days in each month in a non-leap year
  43. *
  44. * @global array $days_per_month
  45. */
  46. $days_per_month = array ( 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
  47. /**
  48. * Array containing the number of days in each month in a leap year
  49. *
  50. * @global array $ldays_per_month
  51. */
  52. $ldays_per_month = array ( 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 );
  53. /**
  54. * Array of global variables which are not allowed to by set via HTTP GET/POST
  55. *
  56. * This is a security precaution to prevent users from overriding any global
  57. * variables
  58. *
  59. * @global array $noSet
  60. */
  61. $noSet = array (
  62. "is_admin" => 1,
  63. "db_type" => 1,
  64. "db_host" => 1,
  65. "db_login" => 1,
  66. "db_password" => 1,
  67. "db_persistent" => 1,
  68. "PROGRAM_NAME" => 1,
  69. "PROGRAM_URL" => 1,
  70. "readonly" => 1,
  71. "single_user" => 1,
  72. "single_user_login" => 1,
  73. "use_http_auth" => 1,
  74. "user_inc" => 1,
  75. "includedir" => 1,
  76. "NONUSER_PREFIX" => 1,
  77. "languages" => 1,
  78. "browser_languages" => 1,
  79. "pub_acc_enabled" => 1,
  80. "user_can_update_password" => 1,
  81. "admin_can_add_user" => 1,
  82. "admin_can_delete_user" => 1,
  83. );
  84. // This code is a temporary hack to make the application work when
  85. // register_globals is set to Off in php.ini (the default setting in
  86. // PHP 4.2.0 and after).
  87. if ( empty ( $HTTP_GET_VARS ) ) $HTTP_GET_VARS = $_GET;
  88. if ( ! empty ( $HTTP_GET_VARS ) ) {
  89. while (list($key, $val) = @each($HTTP_GET_VARS)) {
  90. // don't allow anything to have <script> in it...
  91. if ( ! is_array ( $val ) ) {
  92. if ( preg_match ( "/<\s*script/i", $val ) ) {
  93. echo "Security violation!"; exit;
  94. }
  95. }
  96. if ( $key == "login" ) {
  97. if ( strstr ( $PHP_SELF, "login.php" ) ) {
  98. //$GLOBALS[$key] = $val;
  99. $GLOBALS[$key] = $val;
  100. }
  101. } else {
  102. if ( empty ( $noSet[$key] ) ) {
  103. $GLOBALS[$key] = $val;
  104. //echo "XXX $key<br />\n";
  105. }
  106. }
  107. //echo "GET var '$key' = '$val' <br />\n";
  108. }
  109. reset ( $HTTP_GET_VARS );
  110. }
  111. if ( empty ( $HTTP_POST_VARS ) ) $HTTP_POST_VARS = $_POST;
  112. if ( ! empty ( $HTTP_POST_VARS ) ) {
  113. while (list($key, $val) = @each($HTTP_POST_VARS)) {
  114. // don't allow anything to have <script> in it... except 'template'
  115. if ( ! is_array ( $val ) && $key != 'template' ) {
  116. if ( preg_match ( "/<\s*script/i", $val ) ) {
  117. echo "Security violation!"; exit;
  118. }
  119. }
  120. if ( empty ( $noSet[$key] ) ) {
  121. $GLOBALS[$key] = $val;
  122. }
  123. }
  124. reset ( $HTTP_POST_VARS );
  125. }
  126. //while (list($key, $val) = @each($HTTP_POST_FILES)) {
  127. // $GLOBALS[$key] = $val;
  128. //}
  129. //while (list($key, $val) = @each($HTTP_SESSION_VARS)) {
  130. // $GLOBALS[$key] = $val;
  131. //}
  132. if ( empty ( $HTTP_COOKIE_VARS ) ) $HTTP_COOKIE_VARS = $_COOKIE;
  133. if ( ! empty ( $HTTP_COOKIE_VARS ) ) {
  134. while (list($key, $val) = @each($HTTP_COOKIE_VARS)) {
  135. if ( empty ( $noSet[$key] ) && substr($key,0,12) == "webcalendar_" ) {
  136. $GLOBALS[$key] = $val;
  137. }
  138. //echo "COOKIE var '$key' = '$val' <br />\n";
  139. }
  140. reset ( $HTTP_COOKIE_VARS );
  141. }
  142. // Don't allow a user to put "login=XXX" in the URL if they are not
  143. // coming from the login.php page.
  144. if ( empty ( $PHP_SELF ) && ! empty ( $_SERVER['PHP_SELF'] ) )
  145. $PHP_SELF = $_SERVER['PHP_SELF']; // backward compatibility
  146. if ( empty ( $PHP_SELF ) )
  147. $PHP_SELF = ''; // this happens when running send_reminders.php from CL
  148. if ( ! strstr ( $PHP_SELF, "login.php" ) && ! empty ( $GLOBALS["login"] ) ) {
  149. $GLOBALS["login"] = "";
  150. }
  151. // Define an array to use to jumble up the key: $offsets
  152. // We define a unique key to scramble the cookie we generate.
  153. // We use the admin install password that the user set to make
  154. // the salt unique for each WebCalendar install.
  155. if ( ! empty ( $settings ) && ! empty ( $settings['install_password'] ) ) {
  156. $salt = $settings['install_password'];
  157. } else {
  158. $salt = md5 ( $db_login );
  159. }
  160. $salt_len = strlen ( $salt );
  161. if ( ! empty ( $db_password ) ) {
  162. $salt2 = md5 ( $db_password );
  163. } else {
  164. $salt2 = md5 ( "oogabooga" );
  165. }
  166. $salt2_len = strlen ( $salt2 );
  167. $offsets = array ();
  168. for ( $i = 0; $i < $salt_len || $i < $salt2_len; $i++ ) {
  169. $offsets[$i] = 0;
  170. if ( $i < $salt_len )
  171. $offsets[$i] += ord ( substr ( $salt, $i, 1 ) );
  172. if ( $i < $salt2_len )
  173. $offsets[$i] += ord ( substr ( $salt2, $i, 1 ) );
  174. $offsets[$i] %= 128;
  175. }
  176. /* debugging code...
  177. for ( $i = 0; $i < count ( $offsets ); $i++ ) {
  178. echo "offset $i: $offsets[$i] <br />\n";
  179. }
  180. */
  181. function logs($logs_file, $msg){
  182. /*$log=fopen($logs_file,"a+");
  183. fputs($log,$msg."\n");
  184. fclose($log);*/
  185. }
  186. /*
  187. * Functions start here. All non-function code should be above this
  188. *
  189. * Note to developers:
  190. * Documentation is generated from the function comments below.
  191. * When adding/updating functions, please follow the following conventions
  192. * seen below. Your cooperation in this matter is appreciated :-)
  193. *
  194. * If you want your documentation to link to the db documentation,
  195. * just make sure you mention the db table name followed by "table"
  196. * on the same line. Here's an example:
  197. * Retrieve preferences from the webcal_user_pref table.
  198. *
  199. */
  200. /**
  201. * Gets the value resulting from an HTTP POST method.
  202. *
  203. * <b>Note:</b> The return value will be affected by the value of
  204. * <var>magic_quotes_gpc</var> in the php.ini file.
  205. *
  206. * @param string $name Name used in the HTML form
  207. *
  208. * @return string The value used in the HTML form
  209. *
  210. * @see getGetValue
  211. */
  212. function getPostValue ( $name ) {
  213. global $HTTP_POST_VARS;
  214. if ( isset ( $_POST ) && is_array ( $_POST ) && ! empty ( $_POST[$name] ) ) {
  215. $HTTP_POST_VARS[$name] = $_POST[$name];
  216. return $_POST[$name];
  217. } else if ( ! isset ( $HTTP_POST_VARS ) ) {
  218. return null;
  219. } else if ( ! isset ( $HTTP_POST_VARS[$name] ) ) {
  220. return null;
  221. }
  222. return ( $HTTP_POST_VARS[$name] );
  223. }
  224. /**
  225. * Gets the value resulting from an HTTP GET method.
  226. *
  227. * <b>Note:</b> The return value will be affected by the value of
  228. * <var>magic_quotes_gpc</var> in the php.ini file.
  229. *
  230. * If you need to enforce a specific input format (such as numeric input), then
  231. * use the {@link getValue()} function.
  232. *
  233. * @param string $name Name used in the HTML form or found in the URL
  234. *
  235. * @return string The value used in the HTML form (or URL)
  236. *
  237. * @see getPostValue
  238. */
  239. function getGetValue ( $name ) {
  240. global $HTTP_GET_VARS;
  241. if ( isset ( $_GET ) && is_array ( $_GET ) && ! empty ( $_GET[$name] ) ) {
  242. $HTTP_GET_VARS[$name] = $_GET[$name];
  243. return $_GET[$name];
  244. } else if ( ! isset ( $HTTP_GET_VARS ) ) {
  245. return null;
  246. } else if ( ! isset ( $HTTP_GET_VARS[$name] ) ) {
  247. return null;
  248. }
  249. return ( $HTTP_GET_VARS[$name] );
  250. }
  251. /**
  252. * Gets the value resulting from either HTTP GET method or HTTP POST method.
  253. *
  254. * <b>Note:</b> The return value will be affected by the value of
  255. * <var>magic_quotes_gpc</var> in the php.ini file.
  256. *
  257. * <b>Note:</b> If you need to get an integer value, yuou can use the
  258. * getIntValue function.
  259. *
  260. * @param string $name Name used in the HTML form or found in the URL
  261. * @param string $format A regular expression format that the input must match.
  262. * If the input does not match, an empty string is
  263. * returned and a warning is sent to the browser. If The
  264. * <var>$fatal</var> parameter is true, then execution
  265. * will also stop when the input does not match the
  266. * format.
  267. * @param bool $fatal Is it considered a fatal error requiring execution to
  268. * stop if the value retrieved does not match the format
  269. * regular expression?
  270. *
  271. * @return string The value used in the HTML form (or URL)
  272. *
  273. * @uses getGetValue
  274. * @uses getPostValue
  275. */
  276. function getValue ( $name, $format="", $fatal=false ) {
  277. $val = getPostValue ( $name );
  278. if ( ! isset ( $val ) )
  279. $val = getGetValue ( $name );
  280. // for older PHP versions...
  281. if ( ! isset ( $val ) && get_magic_quotes_gpc () == 1 &&
  282. ! empty ( $GLOBALS[$name] ) )
  283. $val = $GLOBALS[$name];
  284. if ( ! isset ( $val ) )
  285. return "";
  286. if ( ! empty ( $format ) && ! preg_match ( "/^" . $format . "$/", $val ) ) {
  287. // does not match
  288. if ( $fatal ) {
  289. die_miserable_death ( "Fatal Error: Invalid data format for $name" );
  290. }
  291. // ignore value
  292. return "";
  293. }
  294. return $val;
  295. }
  296. /**
  297. * Gets an integer value resulting from an HTTP GET or HTTP POST method.
  298. *
  299. * <b>Note:</b> The return value will be affected by the value of
  300. * <var>magic_quotes_gpc</var> in the php.ini file.
  301. *
  302. * @param string $name Name used in the HTML form or found in the URL
  303. * @param bool $fatal Is it considered a fatal error requiring execution to
  304. * stop if the value retrieved does not match the format
  305. * regular expression?
  306. *
  307. * @return string The value used in the HTML form (or URL)
  308. *
  309. * @uses getValue
  310. */
  311. function getIntValue ( $name, $fatal=false ) {
  312. $val = getValue ( $name, "-?[0-9]+", $fatal );
  313. return $val;
  314. }
  315. /**
  316. * Loads default system settings (which can be updated via admin.php).
  317. *
  318. * System settings are stored in the webcal_config table.
  319. *
  320. * <b>Note:</b> If the setting for <var>server_url</var> is not set, the value
  321. * will be calculated and stored in the database.
  322. *
  323. * @global string User's login name
  324. * @global bool Readonly
  325. * @global string HTTP hostname
  326. * @global int Server's port number
  327. * @global string Request string
  328. * @global array Server variables
  329. */
  330. function load_global_settings () {
  331. global $login, $readonly, $HTTP_HOST, $SERVER_PORT, $REQUEST_URI, $_SERVER;
  332. // Note: when running from the command line (send_reminders.php),
  333. // these variables are (obviously) not set.
  334. // TODO: This type of checking should be moved to a central locationm
  335. // like init.php.
  336. if ( isset ( $_SERVER ) && is_array ( $_SERVER ) ) {
  337. if ( empty ( $HTTP_HOST ) && isset ( $_SERVER["HTTP_POST"] ) )
  338. $HTTP_HOST = $_SERVER["HTTP_HOST"];
  339. if ( empty ( $SERVER_PORT ) && isset ( $_SERVER["SERVER_PORT"] ) )
  340. $SERVER_PORT = $_SERVER["SERVER_PORT"];
  341. if ( empty ( $REQUEST_URI ) && isset ( $_SERVER["REQUEST_URI"] ) )
  342. $REQUEST_URI = $_SERVER["REQUEST_URI"];
  343. }
  344. $res = dbi_query ( "SELECT cal_setting, cal_value FROM webcal_config" );
  345. if ( $res ) {
  346. while ( $row = dbi_fetch_row ( $res ) ) {
  347. $setting = $row[0];
  348. $value = $row[1];
  349. //echo "Setting '$setting' to '$value' <br />\n";
  350. $GLOBALS[$setting] = $value;
  351. }
  352. dbi_free_result ( $res );
  353. }
  354. // If app name not set.... default to "Title". This gets translated
  355. // later since this function is typically called before translate.php
  356. // is included.
  357. // Note: We usually use translate($application_name) instead of
  358. // translate("Title").
  359. if ( empty ( $GLOBALS["application_name"] ) )
  360. $GLOBALS["application_name"] = "Title";
  361. // If $server_url not set, then calculate one for them, then store it
  362. // in the database.
  363. if ( empty ( $GLOBALS["server_url"] ) ) {
  364. if ( ! empty ( $HTTP_HOST ) && ! empty ( $REQUEST_URI ) ) {
  365. $ptr = strrpos ( $REQUEST_URI, "/" );
  366. if ( $ptr > 0 ) {
  367. $uri = substr ( $REQUEST_URI, 0, $ptr + 1 );
  368. $server_url = "http://" . $HTTP_HOST;
  369. if ( ! empty ( $SERVER_PORT ) && $SERVER_PORT != 80 )
  370. $server_url .= ":" . $SERVER_PORT;
  371. $server_url .= $uri;
  372. dbi_query ( "INSERT INTO webcal_config ( cal_setting, cal_value ) ".
  373. "VALUES ( 'server_url', '$server_url' )" );
  374. $GLOBALS["server_url"] = $server_url;
  375. }
  376. }
  377. }
  378. // If no font settings, then set some
  379. if ( empty ( $GLOBALS["FONTS"] ) ) {
  380. if ( $GLOBALS["LANGUAGE"] == "Japanese" )
  381. $GLOBALS["FONTS"] = "Osaka, Arial, Helvetica, sans-serif";
  382. else
  383. $GLOBALS["FONTS"] = "Arial, Helvetica, sans-serif";
  384. }
  385. }
  386. /**
  387. * Gets the list of active plugins.
  388. *
  389. * Should be called after {@link load_global_settings()} and {@link load_user_preferences()}.
  390. *
  391. * @internal cek: ignored since I am not sure this will ever be used...
  392. *
  393. * @return array Active plugins
  394. *
  395. * @ignore
  396. */
  397. function get_plugin_list ( $include_disabled=false ) {
  398. // first get list of available plugins
  399. $sql = "SELECT cal_setting FROM webcal_config " .
  400. "WHERE cal_setting LIKE '%.plugin_status'";
  401. if ( ! $include_disabled )
  402. $sql .= " AND cal_value = 'Y'";
  403. $sql .= " ORDER BY cal_setting";
  404. $res = dbi_query ( $sql );
  405. $plugins = array ();
  406. if ( $res ) {
  407. while ( $row = dbi_fetch_row ( $res ) ) {
  408. $e = explode ( ".", $row[0] );
  409. if ( $e[0] != "" ) {
  410. $plugins[] = $e[0];
  411. }
  412. }
  413. dbi_free_result ( $res );
  414. } else {
  415. echo translate("Database error") . ": " . dbi_error (); exit;
  416. }
  417. if ( count ( $plugins ) == 0 ) {
  418. $plugins[] = "webcalendar";
  419. }
  420. return $plugins;
  421. }
  422. /**
  423. * Get plugins available to the current user.
  424. *
  425. * Do this by getting a list of all plugins that are not disabled by the
  426. * administrator and make sure this user has not disabled any of them.
  427. *
  428. * It's done this was so that when an admin adds a new plugin, it shows up on
  429. * each users system automatically (until they disable it).
  430. *
  431. * @return array Plugins available to current user
  432. *
  433. * @ignore
  434. */
  435. function get_user_plugin_list () {
  436. $ret = array ();
  437. $all_plugins = get_plugin_list ();
  438. for ( $i = 0; $i < count ( $all_plugins ); $i++ ) {
  439. if ( $GLOBALS[$all_plugins[$i] . ".disabled"] != "N" )
  440. $ret[] = $all_plugins[$i];
  441. }
  442. return $ret;
  443. }
  444. /**
  445. * Identify user's browser.
  446. *
  447. * Returned value will be one of:
  448. * - "Mozilla/5" = Mozilla (open source Mozilla 5.0)
  449. * - "Mozilla/[3,4]" = Netscape (3.X, 4.X)
  450. * - "MSIE 4" = MSIE (4.X)
  451. *
  452. * @return string String identifying browser
  453. *
  454. * @ignore
  455. */
  456. function get_web_browser () {
  457. if ( ereg ( "MSIE [0-9]", getenv ( "HTTP_USER_AGENT" ) ) )
  458. return "MSIE";
  459. if ( ereg ( "Mozilla/[234]", getenv ( "HTTP_USER_AGENT" ) ) )
  460. return "Netscape";
  461. if ( ereg ( "Mozilla/[5678]", getenv ( "HTTP_USER_AGENT" ) ) )
  462. return "Mozilla";
  463. return "Unknown";
  464. }
  465. /**
  466. * Logs a debug message.
  467. *
  468. * Generally, we do not leave calls to this function in the code. It is used
  469. * for debugging only.
  470. *
  471. * @param string $msg Text to be logged
  472. */
  473. function do_debug ( $msg ) {
  474. // log to /tmp/webcal-debug.log
  475. //error_log ( date ( "Y-m-d H:i:s" ) . "> $msg\n",
  476. // 3, "/tmp/webcal-debug.log" );
  477. //error_log ( date ( "Y-m-d H:i:s" ) . "> $msg\n",
  478. // 2, "sockieman:2000" );
  479. }
  480. /**
  481. * Gets user's preferred view.
  482. *
  483. * The user's preferred view is stored in the $STARTVIEW global variable. This
  484. * is loaded from the user preferences (or system settings if there are no user
  485. * prefererences.)
  486. *
  487. * @param string $indate Date to pass to preferred view in YYYYMMDD format
  488. * @param string $args Arguments to include in the URL (such as "user=joe")
  489. *
  490. * @return string URL of the user's preferred view
  491. */
  492. function get_preferred_view ( $indate="", $args="" ) {
  493. global $STARTVIEW, $thisdate;
  494. $url = empty ( $STARTVIEW ) ? "month.php" : $STARTVIEW;
  495. // We used to just store "month" in $STARTVIEW without the ".php"
  496. // This is just to prevent users from getting a "404 not found" if
  497. // they have not updated their preferences.
  498. if ( $url == "month" || $url == "day" || $url == "week" || $url == "year" )
  499. $url .= ".php";
  500. $url = str_replace ( '&amp;', '&', $url );
  501. $url = str_replace ( '&', '&amp;', $url );
  502. $xdate = empty ( $indate ) ? $thisdate : $indate;
  503. if ( ! empty ( $xdate ) ) {
  504. if ( strstr ( $url, "?" ) )
  505. $url .= '&amp;' . "date=$xdate";
  506. else
  507. $url .= '?' . "date=$xdate";
  508. }
  509. if ( ! empty ( $args ) ) {
  510. if ( strstr ( $url, "?" ) )
  511. $url .= '&amp;' . $args;
  512. else
  513. $url .= '?' . $args;
  514. }
  515. return $url;
  516. }
  517. /**
  518. * Sends a redirect to the user's preferred view.
  519. *
  520. * The user's preferred view is stored in the $STARTVIEW global variable. This
  521. * is loaded from the user preferences (or system settings if there are no user
  522. * prefererences.)
  523. *
  524. * @param string $indate Date to pass to preferred view in YYYYMMDD format
  525. * @param string $args Arguments to include in the URL (such as "user=joe")
  526. */
  527. function send_to_preferred_view ( $indate="", $args="" ) {
  528. $url = get_preferred_view ( $indate, $args );
  529. do_redirect ( $url );
  530. }
  531. /** Sends a redirect to the specified page.
  532. *
  533. * The database connection is closed and execution terminates in this function.
  534. *
  535. * <b>Note:</b> MS IIS/PWS has a bug in which it does not allow us to send a
  536. * cookie and a redirect in the same HTTP header. When we detect that the web
  537. * server is IIS, we accomplish the redirect using meta-refresh. See the
  538. * following for more info on the IIS bug:
  539. *
  540. * {@link http://www.faqts.com/knowledge_base/view.phtml/aid/9316/fid/4}
  541. *
  542. * @param string $url The page to redirect to. In theory, this should be an
  543. * absolute URL, but all browsers accept relative URLs (like
  544. * "month.php").
  545. *
  546. * @global string Type of webserver
  547. * @global array Server variables
  548. * @global resource Database connection
  549. */
  550. function do_redirect ( $url ) {
  551. //Debug
  552. //$log=fopen("/var/lib/gforge/chroot/home/users/placoste/webcalendar/webcalendar.txt","a+");
  553. //fputs($log,"####### functions.php #######\n------- do_redirect -------\n");
  554. //fclose($log);
  555. //Debug
  556. //Debug
  557. //$log=fopen("/var/lib/gforge/chroot/home/users/placoste/webcalendar/webcalendar.txt","a+");
  558. //fputs($log,"url : ".$url."\n");
  559. //fclose($log);
  560. //Debug
  561. global $SERVER_SOFTWARE, $_SERVER, $c;
  562. // Replace any '&amp;' with '&' since we don't want that in the HTTP
  563. // header.
  564. $url = str_replace ( '&amp;', '&', $url );
  565. if ( empty ( $SERVER_SOFTWARE ) )
  566. $SERVER_SOFTWARE = $_SERVER["SERVER_SOFTWARE"];
  567. //echo "SERVER_SOFTWARE = $SERVER_SOFTWARE <br />\n"; exit;
  568. if ( ( substr ( $SERVER_SOFTWARE, 0, 5 ) == "Micro" ) || ( substr ( $SERVER_SOFTWARE, 0, 3 ) == "WN/" ) ) {
  569. echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n
  570. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"DTD/xhtml1-transitional.dtd\">
  571. <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
  572. <head>\n
  573. <title>Redirect</title>\n
  574. <meta http-equiv=\"refresh\" content=\"0; url=\"".$url."\" />\n
  575. </head>\n
  576. <body>\n
  577. Redirecting to.. <a href=\"".$url."\">here</a>
  578. </body>\n
  579. </html>";
  580. }else {
  581. Header ( "Location: ".$url );
  582. print "<script>window.location.href=\"".$url."\";</script>" ;
  583. echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n
  584. <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">
  585. <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
  586. <head>\n
  587. <title>Redirect</title>\n
  588. </head>\n
  589. <body>\n
  590. Redirecting to ... <a href=\"".$url."\">here</a>.
  591. </body>\n
  592. </html>";
  593. }
  594. dbi_close ( $c );
  595. exit;
  596. }
  597. /**
  598. * Sends an HTTP login request to the browser and stops execution.
  599. */
  600. function send_http_login () {
  601. global $lang_file, $application_name;
  602. if ( strlen ( $lang_file ) ) {
  603. Header ( "WWW-Authenticate: Basic realm=\"" . translate("Title") . "\"");
  604. Header ( "HTTP/1.0 401 Unauthorized" );
  605. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html
  606. PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
  607. \"DTD/xhtml1-transitional.dtd\">
  608. <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
  609. <head>\n<title>Unauthorized</title>\n</head>\n<body>\n" .
  610. "<h2>" . translate("Title") . "</h2>\n" .
  611. translate("You are not authorized") .
  612. "\n</body>\n</html>";
  613. } else {
  614. Header ( "WWW-Authenticate: Basic realm=\"WebCalendar\"");
  615. Header ( "HTTP/1.0 401 Unauthorized" );
  616. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!DOCTYPE html
  617. PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
  618. \"DTD/xhtml1-transitional.dtd\">
  619. <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
  620. <head>\n<title>Unauthorized</title>\n</head>\n<body>\n" .
  621. "<h2>WebCalendar</h2>\n" .
  622. "You are not authorized" .
  623. "\n</body>\n</html>";
  624. }
  625. exit;
  626. }
  627. /**
  628. * Generates a cookie that saves the last calendar view.
  629. *
  630. * Cookie is based on the current <var>$REQUEST_URI</var>.
  631. *
  632. * We save this cookie so we can return to this same page after a user
  633. * edits/deletes/etc an event.
  634. *
  635. * @global string Request string
  636. */
  637. function remember_this_view () {
  638. global $REQUEST_URI;
  639. if ( empty ( $REQUEST_URI ) )
  640. $REQUEST_URI = $_SERVER["REQUEST_URI"];
  641. // do not use anything with friendly in the URI
  642. if ( strstr ( $REQUEST_URI, "friendly=" ) )
  643. return;
  644. SetCookie ( "webcalendar_last_view", $REQUEST_URI );
  645. }
  646. /**
  647. * Gets the last page stored using {@link remember_this_view()}.
  648. *
  649. * @return string The URL of the last view or an empty string if it cannot be
  650. * determined.
  651. *
  652. * @global array Cookies
  653. */
  654. function get_last_view () {
  655. global $HTTP_COOKIE_VARS;
  656. $val = '';
  657. if ( isset ( $_COOKIE["webcalendar_last_view"] ) ) {
  658. $HTTP_COOKIE_VARS["webcalendar_last_view"] = $_COOKIE["webcalendar_last_view"];
  659. $val = $_COOKIE["webcalendar_last_view"];
  660. } else if ( isset ( $HTTP_COOKIE_VARS["webcalendar_last_view"] ) ) {
  661. $val = $HTTP_COOKIE_VARS["webcalendar_last_view"];
  662. }
  663. $val = str_replace ( "&", "&amp;", $val );
  664. return $val;
  665. }
  666. /**
  667. * Sends HTTP headers that tell the browser not to cache this page.
  668. *
  669. * Different browser use different mechanisms for this, so a series of HTTP
  670. * header directives are sent.
  671. *
  672. * <b>Note:</b> This function needs to be called before any HTML output is sent
  673. * to the browser.
  674. */
  675. function send_no_cache_header () {
  676. header ( "Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
  677. header ( "Last-Modified: " . gmdate ( "D, d M Y H:i:s" ) . " GMT" );
  678. header ( "Cache-Control: no-store, no-cache, must-revalidate" );
  679. header ( "Cache-Control: post-check=0, pre-check=0", false );
  680. header ( "Pragma: no-cache" );
  681. }
  682. /**
  683. * Loads the current user's preferences as global variables from the webcal_user_pref table.
  684. *
  685. * Also loads the list of views for this user (not really a preference, but
  686. * this is a convenient place to put this...)
  687. *
  688. * <b>Notes:</b>
  689. * - If <var>$allow_color_customization</var> is set to 'N', then we ignore any
  690. * color preferences.
  691. * - Other default values will also be set if the user has not saved a
  692. * preference and no global value has been set by the administrator in the
  693. * system settings.
  694. */
  695. function load_user_preferences () {
  696. global $login, $browser, $views, $prefarray, $is_assistant,
  697. $has_boss, $user, $is_nonuser_admin, $allow_color_customization;
  698. $lang_found = false;
  699. $colors = array (
  700. "BGCOLOR" => 1,
  701. "H2COLOR" => 1,
  702. "THBG" => 1,
  703. "THFG" => 1,
  704. "CELLBG" => 1,
  705. "TODAYCELLBG" => 1,
  706. "WEEKENDBG" => 1,
  707. "POPUP_BG" => 1,
  708. "POPUP_FG" => 1,
  709. );
  710. $browser = get_web_browser ();
  711. $browser_lang = get_browser_language ();
  712. $prefarray = array ();
  713. // Note: default values are set in config.php
  714. $res = dbi_query (
  715. "SELECT cal_setting, cal_value FROM webcal_user_pref " .
  716. "WHERE cal_login = '$login'" );
  717. if ( $res ) {
  718. while ( $row = dbi_fetch_row ( $res ) ) {
  719. $setting = $row[0];
  720. $value = $row[1];
  721. if ( $allow_color_customization == 'N' ) {
  722. if ( isset ( $colors[$setting] ) )
  723. continue;
  724. }
  725. $sys_setting = "sys_" . $setting;
  726. // save system defaults
  727. if ( ! empty ( $GLOBALS[$setting] ) )
  728. $GLOBALS["sys_" . $setting] = $GLOBALS[$setting];
  729. $GLOBALS[$setting] = $value;
  730. $prefarray[$setting] = $value;
  731. if ( $setting == "LANGUAGE" )
  732. $lang_found = true;
  733. }
  734. dbi_free_result ( $res );
  735. }
  736. // get views for this user and global views
  737. $res = dbi_query (
  738. "SELECT cal_view_id, cal_name, cal_view_type, cal_is_global " .
  739. "FROM webcal_view " .
  740. "WHERE cal_owner = '$login' OR cal_is_global = 'Y' " .
  741. "ORDER BY cal_name" );
  742. if ( $res ) {
  743. $views = array ();
  744. while ( $row = dbi_fetch_row ( $res ) ) {
  745. if ( $row[2] == 'S' )
  746. $url = "view_t.php?timeb=1&amp;id=$row[0]";
  747. else if ( $row[2] == 'T' )
  748. $url = "view_t.php?timeb=0&amp;id=$row[0]";
  749. else
  750. $url = "view_" . strtolower ( $row[2] ) . ".php?id=$row[0]";
  751. $v = array (
  752. "cal_view_id" => $row[0],
  753. "cal_name" => $row[1],
  754. "cal_view_type" => $row[2],
  755. "cal_is_global" => $row[3],
  756. "url" => $url
  757. );
  758. $views[] = $v;
  759. }
  760. dbi_free_result ( $res );
  761. }
  762. // If user has not set a language preference, then use their browser
  763. // settings to figure it out, and save it in the database for future
  764. // use (email reminders).
  765. if ( ! $lang_found && strlen ( $login ) && $login != "__public__" ) {
  766. $LANGUAGE = $browser_lang;
  767. dbi_query ( "INSERT INTO webcal_user_pref " .
  768. "( cal_login, cal_setting, cal_value ) VALUES " .
  769. "( '$login', 'LANGUAGE', '$LANGUAGE' )" );
  770. }
  771. if ( empty ( $GLOBALS["DATE_FORMAT_MY"] ) )
  772. $GLOBALS["DATE_FORMAT_MY"] = "__month__ __yyyy__";
  773. if ( empty ( $GLOBALS["DATE_FORMAT_MD"] ) )
  774. $GLOBALS["DATE_FORMAT_MD"] = "__month__ __dd__";
  775. $is_assistant = empty ( $user ) ? false :
  776. user_is_assistant ( $login, $user );
  777. $has_boss = user_has_boss ( $login );
  778. $is_nonuser_admin = ($user) ? user_is_nonuser_admin ( $login, $user ) : false;
  779. if ( $is_nonuser_admin ) load_nonuser_preferences ($user);
  780. }
  781. /**
  782. * Gets the list of external users for an event from the webcal_entry_ext_user table in an HTML format.
  783. *
  784. * @param int $event_id Event ID
  785. * @param int $use_mailto When set to 1, email address will contain an href
  786. * link with a mailto URL.
  787. *
  788. * @return string The list of external users for an event formatte in HTML.
  789. */
  790. function event_get_external_users ( $event_id, $use_mailto=0 ) {
  791. global $error;
  792. $ret = "";
  793. $res = dbi_query ( "SELECT cal_fullname, cal_email " .
  794. "FROM webcal_entry_ext_user " .
  795. "WHERE cal_id = $event_id " .
  796. "ORDER by cal_fullname" );
  797. if ( $res ) {
  798. while ( $row = dbi_fetch_row ( $res ) ) {
  799. if ( strlen ( $ret ) )
  800. $ret .= "\n";
  801. // Remove [\d] if duplicate name
  802. $trow = trim( preg_replace( '/\[[\d]]/' , "", $row[0] ) );
  803. $ret .= $trow;
  804. if ( strlen ( $row[1] ) ) {
  805. if ( $use_mailto ) {
  806. $ret .= " <a href=\"mailto:$row[1]\">&lt;" .
  807. htmlentities ( $row[1] ) . "&gt;</a>";
  808. } else {
  809. $ret .= " &lt;". htmlentities ( $row[1] ) . "&gt;";
  810. }
  811. }
  812. }
  813. dbi_free_result ( $res );
  814. } else {
  815. echo translate("Database error") .": " . dbi_error ();
  816. echo "<br />\nSQL:<br />\n$sql";
  817. exit;
  818. }
  819. return $ret;
  820. }
  821. /**
  822. * Adds something to the activity log for an event.
  823. *
  824. * The information will be saved to the webcal_entry_log table.
  825. *
  826. * @param int $event_id Event ID
  827. * @param string $user Username of user doing this
  828. * @param string $user_cal Username of user whose calendar is affected
  829. * @param string $type Type of activity we are logging:
  830. * - $LOG_CREATE
  831. * - $LOG_APPROVE
  832. * - $LOG_REJECT
  833. * - $LOG_UPDATE
  834. * - $LOG_DELETE
  835. * - $LOG_NOTIFICATION
  836. * - $LOG_REMINDER
  837. * @param string $text Text comment to add with activity log entry
  838. */
  839. function activity_log ( $event_id, $user, $user_cal, $type, $text ) {
  840. $next_id = 1;
  841. if ( empty ( $type ) ) {
  842. echo "Error: type not set for activity log!";
  843. // but don't exit since we may be in mid-transaction
  844. return;
  845. }
  846. $res = dbi_query ( "SELECT MAX(cal_log_id) FROM webcal_entry_log" );
  847. if ( $res ) {
  848. if ( $row = dbi_fetch_row ( $res ) ) {
  849. $next_id = $row[0] + 1;
  850. }
  851. dbi_free_result ( $res );
  852. }
  853. $date = date ( "Ymd" );
  854. $time = date ( "Gis" );
  855. $sql_text = empty ( $text ) ? "NULL" : "'$text'";
  856. $sql_user_cal = empty ( $user_cal ) ? "NULL" : "'$user_cal'";
  857. $sql = "INSERT INTO webcal_entry_log ( " .
  858. "cal_log_id, cal_entry_id, cal_login, cal_user_cal, cal_type, " .
  859. "cal_date, cal_time, cal_text ) VALUES ( $next_id, $event_id, " .
  860. "'$user', $sql_user_cal, '$type', $date, $time, $sql_text )";
  861. if ( ! dbi_query ( $sql ) ) {
  862. echo "Database error: " . dbi_error ();
  863. echo "<br />\nSQL:<br />\n$sql";
  864. exit;
  865. }
  866. }
  867. /**
  868. * Gets a list of users.
  869. *
  870. * If groups are enabled, this will restrict the list of users to only those
  871. * users who are in the same group(s) as the user (unless the user is an admin
  872. * user). We allow admin users to see all users because they can also edit
  873. * someone else's events (so they may need access to users who are not in the
  874. * same groups that they are in).
  875. *
  876. * @return array Array of users, where each element in the array is an array
  877. * with the following keys:
  878. * - cal_login
  879. * - cal_lastname
  880. * - cal_firstname
  881. * - cal_is_admin
  882. * - cal_is_admin
  883. * - cal_email
  884. * - cal_password
  885. * - cal_fullname
  886. */
  887. function get_my_users () {
  888. global $login, $is_admin, $groups_enabled, $user_sees_only_his_groups;
  889. if ( $groups_enabled == "Y" && $user_sees_only_his_groups == "Y" &&
  890. ! $is_admin ) {
  891. // get groups that current user is in
  892. $res = dbi_query ( "SELECT cal_group_id FROM webcal_group_user " .
  893. "WHERE cal_login = '$login'" );
  894. $groups = array ();
  895. if ( $res ) {
  896. while ( $row = dbi_fetch_row ( $res ) ) {
  897. $groups[] = $row[0];
  898. }
  899. dbi_fetch_row ( $res );
  900. }
  901. $u = user_get_users ();
  902. $u_byname = array ();
  903. for ( $i = 0; $i < count ( $u ); $i++ ) {
  904. $name = $u[$i]['cal_login'];
  905. $u_byname[$name] = $u[$i];
  906. }
  907. $ret = array ();
  908. if ( count ( $groups ) == 0 ) {
  909. // Eek. User is in no groups... Return only themselves
  910. $ret[] = $u_byname[$login];
  911. return $ret;
  912. }
  913. // get list of users in the same groups as current user
  914. $sql = "SELECT DISTINCT(webcal_group_user.cal_login), cal_lastname, cal_firstname from webcal_group_user " .
  915. "LEFT JOIN webcal_user ON webcal_group_user.cal_login = webcal_user.cal_login " .
  916. "WHERE cal_group_id ";
  917. if ( count ( $groups ) == 1 )
  918. $sql .= "= " . $groups[0];
  919. else {
  920. $sql .= "IN ( " . implode ( ", ", $groups ) . " )";
  921. }
  922. $sql .= " ORDER BY cal_lastname, cal_firstname, webcal_group_user.cal_login";
  923. //echo "SQL: $sql <br />\n";
  924. $res = dbi_query ( $sql );
  925. if ( $res ) {
  926. while ( $row = dbi_fetch_row ( $res ) ) {
  927. $ret[] = $u_byname[$row[0]];
  928. }
  929. dbi_free_result ( $res );
  930. }
  931. return $ret;
  932. } else {
  933. // groups not enabled... return all users
  934. //echo "No groups. ";
  935. return user_get_users ();
  936. }
  937. }
  938. /**
  939. * Gets a preference setting for the specified user.
  940. *
  941. * If no value is found in the database, then the system default setting will
  942. * be returned.
  943. *
  944. * @param string $user User login we are getting preference for
  945. * @param string $setting Name of the setting
  946. *
  947. * @return string The value found in the webcal_user_pref table for the
  948. * specified setting or the sytem default if no user settings
  949. * was found.
  950. */
  951. function get_pref_setting ( $user, $setting ) {
  952. $ret = '';
  953. // set default
  954. if ( ! isset ( $GLOBALS["sys_" .$setting] ) ) {
  955. // this could happen if the current user has not saved any pref. yet
  956. if ( ! empty ( $GLOBALS[$setting] ) )
  957. $ret = $GLOBALS[$setting];
  958. } else {
  959. $ret = $GLOBALS["sys_" .$setting];
  960. }
  961. $sql = "SELECT cal_value FROM webcal_user_pref " .
  962. "WHERE cal_login = '" . $user . "' AND " .
  963. "cal_setting = '" . $setting . "'";
  964. //echo "SQL: $sql <br />\n";
  965. $res = dbi_query ( $sql );
  966. if ( $res ) {
  967. if ( $row = dbi_fetch_row ( $res ) )
  968. $ret = $row[0];
  969. dbi_free_result ( $res );
  970. }
  971. return $ret;
  972. }
  973. /**
  974. * Gets browser-specified language preference.
  975. *
  976. * @return string Preferred language
  977. *
  978. * @ignore
  979. */
  980. function get_browser_language () {
  981. global $HTTP_ACCEPT_LANGUAGE, $browser_languages;
  982. $ret = "";
  983. if ( empty ( $HTTP_ACCEPT_LANGUAGE ) &&
  984. isset ( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
  985. $HTTP_ACCEPT_LANGUAGE = $_SERVER["HTTP_ACCEPT_LANGUAGE"];
  986. if ( empty ( $HTTP_ACCEPT_LANGUAGE ) ) {
  987. return "none";
  988. } else {
  989. $langs = explode ( ",", $HTTP_ACCEPT_LANGUAGE );
  990. for ( $i = 0; $i < count ( $langs ); $i++ ) {
  991. $l = strtolower ( trim ( ereg_replace(';.*', '', $langs[$i] ) ) );
  992. $ret .= "\"$l\" ";
  993. if ( ! empty ( $browser_languages[$l] ) ) {
  994. return $browser_languages[$l];
  995. }
  996. }
  997. }
  998. //if ( strlen ( $HTTP_ACCEPT_LANGUAGE ) )
  999. // return "none ($HTTP_ACCEPT_LANGUAGE not supported)";
  1000. //else
  1001. return "none";
  1002. }
  1003. /**
  1004. * Loads current user's layer info into layer global variable.
  1005. *
  1006. * If the system setting <var>$allow_view_other</var> is not set to 'Y', then
  1007. * we ignore all layer functionality. If <var>$force</var> is 0, we only load
  1008. * layers if the current user preferences have layers turned on.
  1009. *
  1010. * @param string $user Username of user to load layers for
  1011. * @param int $force If set to 1, then load layers for this user even if
  1012. * user preferences have layers turned off.
  1013. */
  1014. function load_user_layers ($user="",$force=0) {
  1015. global $login;
  1016. global $layers;
  1017. global $LAYERS_STATUS, $allow_view_other;
  1018. if ( $user == "" )
  1019. $user = $login;
  1020. $layers = array ();
  1021. if ( empty ( $allow_view_other ) || $allow_view_other != 'Y' )
  1022. return; // not allowed to view others' calendars, so cannot use layers
  1023. if ( $force || ( ! empty ( $LAYERS_STATUS ) && $LAYERS_STATUS != "N" ) ) {
  1024. $res = dbi_query (
  1025. "SELECT cal_layerid, cal_layeruser, cal_color, cal_dups " .
  1026. "FROM webcal_user_layers " .
  1027. "WHERE cal_login = '$user' ORDER BY cal_layerid" );
  1028. if ( $res ) {
  1029. $count = 1;
  1030. while ( $row = dbi_fetch_row ( $res ) ) {
  1031. $layers[$row[0]] = array (
  1032. "cal_layerid" => $row[0],
  1033. "cal_layeruser" => $row[1],
  1034. "cal_color" => $row[2],
  1035. "cal_dups" => $row[3]
  1036. );
  1037. $count++;
  1038. }
  1039. dbi_free_result ( $res );
  1040. }
  1041. } else {
  1042. //echo "Not loading!";
  1043. }
  1044. }
  1045. /**
  1046. * Generates the HTML used in an event popup for the site_extras fields of an event.
  1047. *
  1048. * @param int $id Event ID
  1049. *
  1050. * @return string The HTML to be used within the event popup for any site_extra
  1051. * fields found for the specified event
  1052. */
  1053. function site_extras_for_popup ( $id ) {
  1054. global $site_extras_in_popup, $site_extras;
  1055. // These are needed in case the site_extras.php file was already
  1056. // included.
  1057. global $EXTRA_TEXT, $EXTRA_MULTILINETEXT, $EXTRA_URL, $EXTRA_DATE,
  1058. $EXTRA_EMAIL, $EXTRA_USER, $EXTRA_REMINDER, $EXTRA_SELECTLIST;
  1059. global $EXTRA_REMINDER_WITH_DATE, $EXTRA_REMINDER_WITH_OFFSET,
  1060. $EXTRA_REMINDER_DEFAULT_YES;
  1061. $ret = '';
  1062. if ( $site_extras_in_popup != 'Y' )
  1063. return '';
  1064. include_once 'includes/site_extras.php';
  1065. $extras = get_site_extra_fields ( $id );
  1066. for ( $i = 0; $i < count ( $site_extras ); $i++ ) {
  1067. $extra_name = $site_extras[$i][0];
  1068. $extra_type = $site_extras[$i][2];
  1069. $extra_arg1 = $site_extras[$i][3];
  1070. $extra_arg2 = $site_extras[$i][4];
  1071. if ( ! empty ( $extras[$extra_name]['cal_name'] ) ) {
  1072. $ret .= "<dt>" . translate ( $site_extras[$i][1] ) . ":</dt>\n<dd>";
  1073. if ( $extra_type == $EXTRA_DATE ) {
  1074. if ( $extras[$extra_name]['cal_date'] > 0 )
  1075. $ret .= date_to_str ( $extras[$extra_name]['cal_date'] );
  1076. } else if ( $extra_type == $EXTRA_TEXT ||
  1077. $extra_type == $EXTRA_MULTILINETEXT ) {
  1078. $ret .= nl2br ( $extras[$extra_name]['cal_data'] );
  1079. } else if ( $extra_type == $EXTRA_REMINDER ) {
  1080. if ( $extras[$extra_name]['cal_remind'] <= 0 )
  1081. $ret .= translate ( "No" );
  1082. else {
  1083. $ret .= translate ( "Yes" );
  1084. if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_DATE ) > 0 ) {
  1085. $ret .= "&nbsp;&nbsp;-&nbsp;&nbsp;";
  1086. $ret .= date_to_str ( $extras[$extra_name]['cal_date'] );
  1087. } else if ( ( $extra_arg2 & $EXTRA_REMINDER_WITH_OFFSET ) > 0 ) {
  1088. $ret .= "&nbsp;&nbsp;-&nbsp;&nbsp;";
  1089. $minutes = $extras[$extra_name]['cal_data'];
  1090. $d = (int) ( $minutes / ( 24 * 60 ) );
  1091. $minutes -= ( $d * 24 * 60 );
  1092. $h = (int) ( $minutes / 60 );
  1093. $minutes -= ( $h * 60 );
  1094. if ( $d > 0 )
  1095. $ret .= $d . "&nbsp;" . translate("days") . "&nbsp;";
  1096. if ( $h > 0 )
  1097. $ret .= $h . "&nbsp;" . translate("hours") . "&nbsp;";
  1098. if ( $minutes > 0 )
  1099. $ret .= $minutes . "&nbsp;" . translate("minutes");
  1100. $ret .= "&nbsp;" . translate("before event" );
  1101. }
  1102. }
  1103. } else {
  1104. $ret .= $extras[$extra_name]['cal_data'];
  1105. }
  1106. $ret .= "</dd>\n";
  1107. }
  1108. }
  1109. return $ret;
  1110. }
  1111. /**
  1112. * Builds the HTML for the event popup.
  1113. *
  1114. * @param string $popupid CSS id to use for event popup
  1115. * @param string $user Username of user the event pertains to
  1116. * @param string $description Event description
  1117. * @param string $time Time of the event (already formatted in a display format)
  1118. * @param string $site_extras HTML for any site_extras for this event
  1119. *
  1120. * @return string The HTML for the event popup
  1121. */
  1122. function build_event_popup ( $popupid, $user, $description, $time, $site_extras='' ) {
  1123. global $login, $popup_fullnames, $popuptemp_fullname;
  1124. $ret = "<dl id=\"$popupid\" class=\"popup\">\n";
  1125. if ( empty ( $popup_fullnames ) )
  1126. $popup_fullnames = array ();
  1127. if ( $user != $login ) {
  1128. if ( empty ( $popup_fullnames[$user] ) ) {
  1129. user_load_variables ( $user, "popuptemp_" );
  1130. $popup_fullnames[$user] = $popuptemp_fullname;
  1131. }
  1132. $ret .= "<dt>" . translate ("User") .
  1133. ":</dt>\n<dd>$popup_fullnames[$user]</dd>\n";
  1134. }
  1135. if ( strlen ( $time ) )
  1136. $ret .= "<dt>" . translate ("Time") . ":</dt>\n<dd>$time</dd>\n";
  1137. $ret .= "<dt>" . translate ("Description") . ":</dt>\n<dd>";
  1138. if ( ! empty ( $GLOBALS['allow_html_description'] ) &&
  1139. $GLOBALS['allow_html_description'] == 'Y' ) {
  1140. $str = str_replace ( "&", "&amp;", $description );
  1141. $str = str_replace ( "&amp;amp;", "&amp;", $str );
  1142. // If there is no html found, then go ahead and replace
  1143. // the line breaks ("\n") with the html break.
  1144. if ( strstr ( $str, "<" ) && strstr ( $str, ">" ) ) {
  1145. // found some html...
  1146. $ret .= $str;
  1147. } else {
  1148. // no html, replace line breaks
  1149. $ret .= nl2br ( $str );
  1150. }
  1151. } else {
  1152. // html not allowed in description, escape everything
  1153. $ret .= nl2br ( htmlspecialchars ( $description ) );
  1154. }
  1155. $ret .= "</dd>\n";
  1156. if ( ! empty ( $site_extras ) )
  1157. $ret .= $site_extras;
  1158. $ret .= "</dl>\n";
  1159. return $ret;
  1160. }
  1161. /**
  1162. * Prints out a date selection box for use in a form.
  1163. *
  1164. * @param string $prefix Prefix to use in front of form element names
  1165. * @param int $date Currently selected date (in YYYYMMDD format)
  1166. *
  1167. * @uses date_selection_html
  1168. */
  1169. function print_date_selection ( $prefix, $date ) {
  1170. print date_selection_html ( $prefix, $date );
  1171. }
  1172. /**
  1173. * Generate HTML for a date selection for use in a form.
  1174. *
  1175. * @param string $prefix Prefix to use in front of form element names
  1176. * @param int $date Currently selected date (in YYYYMMDD format)
  1177. *
  1178. * @return string HTML for the selection box
  1179. */
  1180. function date_selection_html ( $prefix, $date ) {
  1181. $ret = "";
  1182. $num_years = 20;
  1183. if ( strlen ( $date ) != 8 )
  1184. $date = date ( "Ymd" );
  1185. $thisyear = $year = substr ( $date, 0, 4 );
  1186. $thismonth = $month = substr ( $date, 4, 2 );
  1187. $thisday = $day = substr ( $date, 6, 2 );
  1188. if ( $thisyear - date ( "Y" ) >= ( $num_years - 1 ) )
  1189. $num_years = $thisyear - date ( "Y" ) + 2;
  1190. $ret .= "<select name=\"" . $prefix . "day\">\n";
  1191. for ( $i = 1; $i <= 31; $i++ )
  1192. $ret .= "<option value=\"$i\"" .
  1193. ( $i == $thisday ? " selected=\"selected\"" : "" ) . ">$i</option>\n";
  1194. $ret .= "</select>\n<select name=\"" . $prefix . "month\">\n";
  1195. for ( $i = 1; $i <= 12; $i++ ) {
  1196. $m = month_short_name ( $i - 1 );
  1197. $ret .= "<option value=\"$i\"" .
  1198. ( $i == $thismonth ? " selected=\"selected\"" : "" ) . ">$m</option>\n";
  1199. }
  1200. $ret .= "</select>\n<select name=\"" . $prefix . "year\">\n";
  1201. for ( $i = -10; $i < $num_years; $i++ ) {
  1202. $y = $thisyear + $i;
  1203. $ret .= "<option value=\"$y\"" .
  1204. ( $y == $thisyear ? " selected=\"selected\"" : "" ) . ">$y</option>\n";
  1205. }
  1206. $ret .= "</select>\n";
  1207. $ret .= "<input type=\"button\" onclick=\"selectDate( '" .
  1208. $prefix . "day','" . $prefix . "month','" . $prefix . "year',$date, event)\" value=\"" .
  1209. translate("Select") . "...\" />\n";
  1210. return $ret;
  1211. }
  1212. /**
  1213. * Prints out a minicalendar for a month.
  1214. *
  1215. * @todo Make day.php NOT be a special case
  1216. *
  1217. * @param int $thismonth Number of the month to print
  1218. * @param int $thisyear Number of the year
  1219. * @param bool $showyear Show the year in the calendar's title?
  1220. * @param bool $show_weeknums Show week numbers to the left of each row?
  1221. * @param string $minical_id id attribute for the minical table
  1222. * @param string $month_link URL and query string for month link that should
  1223. * come before the date specification (e.g.
  1224. * month.php? or view_l.php?id=7&amp;)
  1225. */
  1226. function display_small_month ( $thismonth, $thisyear, $showyear,
  1227. $show_weeknums=false, $minical_id='', $month_link='month.php?', $info_type='&type_param=user' ) {
  1228. global $WEEK_START, $user, $login, $boldDays, $get_unapproved;
  1229. global $DISPLAY_WEEKNUMBER;
  1230. global $SCRIPT, $thisday; // Needed for day.php
  1231. global $caturl, $today;
  1232. global $log_file;
  1233. //Debug
  1234. logs($log_file,"####### function.php #######\n------- display_small_month -------\n");
  1235. if(isset($get_unapproved)){
  1236. logs($log_file, "1\n");
  1237. }else{
  1238. logs($log_file, "0\n");
  1239. }
  1240. //Debug
  1241. //Debug
  1242. logs($log_file, "UNAPPROVED : ".$GLOBALS['DISPLAY_UNAPPROVED']." get_unapproved : ".($get_unapproved?"1":"0")."\n");
  1243. //Debug
  1244. if ( $user != $login && ! empty ( $user ) ) {
  1245. $u_url = "user=$user" . "&amp;";
  1246. } else {
  1247. $u_url = '';
  1248. }
  1249. $u_url .= $info_type."&";
  1250. //start the minical table for each month
  1251. echo "\n<table class=\"minical\"";
  1252. if ( $minical_id != '' ) {
  1253. echo " id=\"$minical_id\"";
  1254. }
  1255. echo ">\n";
  1256. $monthstart = mktime(2,0,0,$thismonth,1,$thisyear);
  1257. $monthend = mktime(2,0,0,$thismonth + 1,0,$thisyear);
  1258. if ( $SCRIPT == 'day.php' ) {
  1259. $month_ago = date ( "Ymd",
  1260. mktime ( 3, 0, 0, $thismonth - 1, $thisday, $thisyear ) );
  1261. $month_ahead = date ( "Ymd",
  1262. mktime ( 3, 0, 0, $thismonth + 1, $thisday, $thisyear ) );
  1263. echo "<caption>$thisday</caption>\n";
  1264. echo "<thead>\n";
  1265. echo "<tr class=\"monthnav\"><th colspan=\"7\">\n";
  1266. echo "<a title=\"" .
  1267. translate("Previous") . "\" class=\"prev\" href=\"day.php?" . $u_url .
  1268. "date=$month_ago$caturl\"><img src=\"leftarrowsmall.gif\" alt=\"" .
  1269. translate("Previous") . "\" /></a>\n";
  1270. echo "<a title=\"" .
  1271. translate("Next") . "\" class=\"next\" href=\"day.php?" . $u_url .
  1272. "date=$month_ahead$caturl\"><img src=\"rightarrowsmall.gif\" alt=\"" .
  1273. translate("Next") . "\" /></a>\n";
  1274. echo month_name ( $thismonth - 1 );
  1275. if ( $showyear != '' ) {
  1276. echo " $thisyear";
  1277. }
  1278. echo "</th></tr>\n<tr>\n";
  1279. } else { //not day script
  1280. //print the month name
  1281. echo "<caption><a href=\"{$month_link}{$u_url}year=$thisyear&amp;month=$thismonth\">";
  1282. echo month_name ( $thismonth - 1 ) .
  1283. ( $showyear ? " $thisyear" : "" );
  1284. echo "</a></caption>\n";
  1285. echo "<thead>\n<tr>\n";
  1286. }
  1287. //determine if the week starts on sunday or monday
  1288. if ( $WEEK_START == "1" ) {
  1289. $wkstart = get_monday_before ( $thisyear, $thismonth, 1 );
  1290. } else {
  1291. $wkstart = get_sunday_before ( $thisyear, $thismonth, 1 );
  1292. }
  1293. //print the headers to display the day of the week (sun, mon, tues, etc.)
  1294. // if we're showing week numbers we need an extra column
  1295. if ( $show_weeknums && $DISPLAY_WEEKNUMBER == 'Y' )
  1296. echo "<th class=\"empty\">&nbsp;</th>\n";
  1297. //if the week doesn't start on monday, print the day
  1298. if ( $WEEK_START == 0 ) echo "<th>" .
  1299. weekday_short_name ( 0 ) . "</th>\n";
  1300. //cycle through each day of the week until gone
  1301. for ( $i = 1; $i < 7; $i++ ) {
  1302. echo "<th>" . weekday_short_name ( $i ) . "</th>\n";
  1303. }
  1304. //if the week DOES start on monday, print sunday
  1305. if ( $WEEK_START == 1 )
  1306. echo "<th>" . weekday_short_name ( 0 ) . "</th>\n";
  1307. //end the header row
  1308. echo "</tr>\n</thead>\n<tbody>\n";
  1309. for ($i = $wkstart; date("Ymd",$i) <= date ("Ymd",$monthend);
  1310. $i += (24 * 3600 * 7) ) {
  1311. echo "<tr>\n";
  1312. if ( $show_weeknums && $DISPLAY_WEEKNUMBER == 'Y' ) {
  1313. echo "<td class=\"weeknumber\"><a href=\"week.php?" . $u_url .
  1314. "date=".date("Ymd", $i)."\">(" . week_number($i) . ")</a></td>\n";
  1315. }
  1316. for ($j = 0; $j < 7; $j++) {
  1317. $date = $i + ($j * 24 * 3600);
  1318. $dateYmd = date ( "Ymd", $date );
  1319. $hasEvents = false;
  1320. if ( $boldDays ) {
  1321. $ev = get_entries ( $user, $dateYmd, $get_unapproved );
  1322. if ( count ( $ev ) > 0 ) {
  1323. $hasEvents = true;
  1324. } else {
  1325. $rep = get_repeating_entries ( $user, $dateYmd, $get_unapproved );
  1326. if ( count ( $rep ) > 0 )
  1327. $hasEvents = true;
  1328. }
  1329. }
  1330. if ( $dateYmd >= date ("Ymd",$monthstart) &&
  1331. $dateYmd <= date ("Ymd",$monthend) ) {
  1332. echo "<td";
  1333. $wday = date ( 'w', $date );
  1334. $class = '';
  1335. //add class="weekend" if it's saturday or sunday
  1336. if ( $wday == 0 || $wday == 6 ) {
  1337. $class = "weekend";
  1338. }
  1339. //if the day being viewed is today's date AND script = day.php
  1340. if ( $dateYmd == $thisyear . $thismonth . $thisday &&
  1341. $SCRIPT == 'day.php' ) {
  1342. //if it's also a weekend, add a space between class names to combine styles
  1343. if ( $class != '' ) {
  1344. $class .= ' ';
  1345. }
  1346. $class .= "selectedday";
  1347. }
  1348. if ( $hasEvents ) {
  1349. if ( $class != '' ) {
  1350. $class .= ' ';
  1351. }
  1352. $class .= "hasevents";
  1353. }
  1354. if ( $class != '' ) {
  1355. echo " class=\"$class\"";
  1356. }
  1357. if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ){
  1358. echo " id=\"today\"";
  1359. }
  1360. echo "><a href=\"day.php?" .$u_url . "date=" . $dateYmd .
  1361. "\">";
  1362. echo date ( "d", $date ) . "</a></td>\n";
  1363. } else {
  1364. echo "<td class=\"empty\">&nbsp;</td>\n";
  1365. }
  1366. } // end for $j
  1367. echo "</tr>\n";
  1368. } // end for $i
  1369. echo "</tbody>\n</table>\n";
  1370. }
  1371. /**
  1372. * Prints the HTML for one day's events in the month view.
  1373. *
  1374. * @param int $id Event ID
  1375. * @param int $date Date of event (relevant in repeating events) in
  1376. * YYYYMMDD format
  1377. * @param int $time Time (in HHMMSS format)
  1378. * @param int $duration Event duration in minutes
  1379. * @param string $name Event name
  1380. * @param string $description Long description of event
  1381. * @param string $status Event status
  1382. * @param int $pri Event priority
  1383. * @param string $access Event access
  1384. * @param string $event_owner Username of user associated with this event
  1385. * @param int $event_cat Category of event for <var>$event_owner</var>
  1386. *
  1387. * @staticvar int Used to ensure all event popups have a unique id
  1388. *
  1389. * @uses build_event_popup
  1390. */
  1391. function print_entry ( $id, $date, $time, $duration,
  1392. $name, $description, $status,
  1393. $pri, $access, $event_owner, $event_cat=-1 ) {
  1394. global $eventinfo, $login, $user, $PHP_SELF, $TZ_OFFSET;
  1395. static $key = 0;
  1396. global $layers;
  1397. if ( $login != $event_owner && strlen ( $event_owner ) ) {
  1398. $class = "layerentry";
  1399. } else {
  1400. $class = "entry";
  1401. if ( $status == "W" ) $class = "unapprovedentry";
  1402. }
  1403. // if we are looking at a view, then always use "entry"
  1404. if ( strstr ( $PHP_SELF, "view_m.php" ) ||
  1405. strstr ( $PHP_SELF, "view_w.php" ) ||
  1406. strstr ( $PHP_SELF, "view_v.php" ) ||
  1407. strstr ( $PHP_SELF, "view_t.php" ) )
  1408. $class = "entry";
  1409. if($GLOBALS['type_param'] == 'group'){
  1410. $info_type = "&type_param=group&group_param=".$GLOBALS['group_param'];
  1411. }else{
  1412. $info_type = "&type_param=user";
  1413. }
  1414. if ( $pri == 3 ) echo "<strong>";
  1415. $popupid = "eventinfo-$id-$key";
  1416. $key++;
  1417. echo "<a title=\"" .
  1418. translate("View this entry") . "\" class=\"$class\" href=\"view_entry.php?id=$id&amp;date=$date".$info_type;
  1419. if ( strlen ( $user ) > 0 )
  1420. echo "&amp;user=" . $user;
  1421. echo "\" onmouseover=\"window.status='" .
  1422. translate("View this entry") .
  1423. "'; show(event, '$popupid'); return true;\" onmouseout=\"window.status=''; hide('$popupid'); return true;\">";
  1424. $icon = "circle.gif";
  1425. $catIcon = '';
  1426. if ( $event_cat > 0 ) {
  1427. $catIcon = "icons/cat-" . $event_cat . ".gif";
  1428. if ( ! file_exists ( $catIcon ) )
  1429. $c

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