Group-Office PHP Cross Reference Groupware Applications

Source: /modules/calendar/print.php - 200 lines - 7046 bytes - Summary - Text - Print

   1  <?php
   2  
   3  require_once ("../../Group-Office.php");
   4  $GLOBALS['GO_SECURITY']->html_authenticate('calendar');
   5  
   6  require_once ($GO_MODULES->modules['calendar']['class_path'] . "calendar.class.inc.php");
   7  require_once ($GO_MODULES->modules['calendar']['class_path'] . "go_ical.class.inc");
   8  require_once ($GO_MODULES->modules['calendar']['class_path'] . 'pdf.class.inc.php');
   9  
  10  
  11  require($GLOBALS['GO_LANGUAGE']->get_language_file('calendar'));
  12  $cal = new calendar();
  13  $cal2 = new calendar();
  14  
  15  //$date = getdate();
  16  
  17  /*
  18    $calendar_id=1;
  19    $start_time = mktime(0,0,0,$date['mon'], $date['mday']-$date['wday']+1,$date['year']);
  20    $end_time = Date::date_add($start_time,7);
  21   */
  22  
  23  $start_time = strtotime($_REQUEST['start_time']);
  24  $end_time = strtotime($_REQUEST['end_time']);
  25  
  26  $pdf = new PDF();
  27  
  28  $calendars = isset($_REQUEST['calendars']) ? json_decode($_REQUEST['calendars']) : array();
  29  
  30  function insert_events($calendars, $start_time, $end_time) {
  31      global $cal, $cal2, $lang, $pdf, $calendar_names, $view, $GO_SECURITY;
  32      require_once ('../../classes/base/users.class.inc.php');
  33      $GO_USERS = new GO_USERS();
  34  
  35      $events = $cal->get_events_in_array($calendars, 0, $start_time, $end_time);
  36  
  37      if (empty($_REQUEST['view_id']) || !empty($view['owncolor'])) {
  38          /* Default colors for merged calendars */
  39          $default_colors = array('F0AE67', 'FFCC00', 'FFFF00', 'CCFF00', '66FF00',
  40                  '00FFCC', '00CCFF', '0066FF', '95C5D3', '6704FB',
  41                  'CC00FF', 'FF00CC', 'CC99FF', 'FB0404', 'FF6600',
  42                  'C43B3B', '996600', '66FF99', '999999', '00FFFF');
  43          //$default_bg = array();
  44  
  45          $default_colors_count = count($default_colors);
  46          $i = 0;
  47          foreach ($calendars as $k => $v) {
  48              $color = $cal2->getCalendarColor($v, $GO_SECURITY->user_id);
  49  
  50              if (!$color) {
  51                  $color = $default_colors[$i];
  52                  $i++;
  53                  if($i > $default_colors_count)
  54                      $i = 0;
  55              }
  56  
  57              $default_bg[$v] = $color;
  58          }
  59          //$default_bg[$v] = $default_colors[$k];
  60          //$output_events[$event_nr]['background'] =
  61          //$default_bg[$event['calendar_id']];
  62      }
  63      //require_once('merge_events.php');
  64      $output_events = array();
  65      $event_nr = 0;
  66      $uuid_array = array();
  67      foreach ($events as $event) {
  68          if ($cal->merge_events($output_events, $event, $uuid_array, $event_nr, $calendar_names, $GO_USERS))
  69              continue;
  70  
  71          if ($event['all_day_event'] == '1') {
  72              $date_format = $_SESSION['GO_SESSION']['date_format'];
  73          } else {
  74              if (date($_SESSION['GO_SESSION']['date_format'], $event['start_time']) != date($_SESSION['GO_SESSION']['date_format'], $event['end_time'])) {
  75                  $date_format = $_SESSION['GO_SESSION']['date_format'] . ' ' . $_SESSION['GO_SESSION']['time_format'];
  76              } else {
  77                  $date_format = $_SESSION['GO_SESSION']['time_format'];
  78              }
  79          }
  80  
  81          // If background is empty then select the default color.
  82          if(empty($event['background']))
  83              $event['background'] = 'FFFFCC';
  84          
  85          $background = $event['background'];
  86          
  87          if(!empty($default_bg) && count($default_bg) > 1 && !empty($default_bg[$event['calendar_id']])) {
  88              $background = $default_bg[$event['calendar_id']];
  89          }
  90  
  91          //$background = !empty($default_bg) && !empty($default_bg[$event['calendar_id']]) ? $default_bg[$event['calendar_id']] : $event['background'];
  92  
  93          $name = $event['name'];
  94  
  95          $username = $GO_USERS->get_user_realname($event['user_id']);
  96  
  97  
  98          if (count($calendars) > 1) {
  99              $name .= ' (' . String::get_first_letters($calendar_names[$event['calendar_id']]) . ')';
 100          }
 101  
 102          $output_events[] = array(
 103                  'id' => $event_nr++,
 104                  'event_id' => $event['id'],
 105                  //'link_count'=>$GO_LINKS->count_links($event['id'], 1),
 106                  'name' => $name,
 107                  'time' => date($date_format, $event['start_time']),
 108                  'calendar_id' => $event['calendar_id'],
 109                  'calendar_name' => isset($calendar_names[$event['calendar_id']]) ? $calendar_names[$event['calendar_id']] : '',
 110                  'start_time' => $event['start_time'], //date('Y-m-d H:i', $event['start_time']),
 111                  'end_time' => $event['end_time'], //date('Y-m-d H:i', $event['end_time']),
 112                  'location' => $event['location'],
 113                  'description' => $event['description'],
 114                  'background' => $background,
 115                  //'background'=>$default_colors[$response['count']-1],
 116                  'private' => ($event['private'] == '1' && $GO_SECURITY->user_id != $event['user_id']),
 117                  'repeats' => !empty($event['rrule']),
 118                  'all_day_event' => $event['all_day_event'],
 119                  'day' => $lang['common']['full_days'][date('w', $event['start_time'])] . ' ' . date($_SESSION['GO_SESSION']['date_format'], $event['start_time']),
 120                  'read_only' => $event['read_only'] ? true : false,
 121                  'username' => $username,
 122                  //'duration' => $duration,
 123                  'has_other_participants' => 1
 124          );
 125      }
 126      $pdf->addCalendar($output_events);
 127  }
 128  
 129  if (!empty($_REQUEST['view_id'])) {//!empty($_REQUEST['view_id'])){
 130      $view = $cal->get_view($_REQUEST['view_id']);
 131      $title = $view['name'];
 132      $pdf->setParams($title, $start_time, $end_time);
 133  
 134      $cal->get_view_calendars($view['id']);
 135      if (empty($view['merge'])) {
 136          $cal2 = new calendar();
 137          $first = true;
 138          $even = false;
 139          while ($calendar = $cal->next_record()) {
 140              $pdf->setCurrentCalendar($calendar);
 141              $events = $cal2->get_events_in_array(array($cal->f('id')), 0, $start_time, $end_time);
 142              $pdf->addCalendar($events, false, $first, $cal->f('name'));
 143              $first = false;
 144          }
 145      } else {
 146          // Calendar.js doesn't pass $_POST['calendars'] if $_POST['view_id'] is passed
 147          $calendars = array();
 148          $calendar_names = array();
 149          while ($calendar = $cal->next_record()) {
 150              $calendars[] = $calendar['id'];
 151              $calendar_names[$calendar['id']] = $calendar['name'];
 152          }
 153  
 154          insert_events($calendars, $start_time, $end_time);
 155      }
 156  } elseif (count($calendars) > 1) {
 157      $calendar_names = array();
 158      foreach ($calendars as $calendar_id) {
 159          $calendar = $cal->get_calendar($calendar_id);
 160          $calendar_names[$calendar_id] = $calendar['name'];
 161      }
 162      $title = 'Multiple calendars: ' . implode(', ', $calendar_names);
 163      $pdf->setParams($title, $start_time, $end_time);
 164  
 165      insert_events($calendars, $start_time, $end_time);
 166  } else {
 167      $calendar = $cal->get_calendar($calendars[0]);
 168      $pdf->setCurrentCalendar($calendar);
 169      $title = $calendar['name'];
 170      $pdf->setParams($calendar['name'], $start_time, $end_time);
 171      //$events = $cal->get_events_in_array(array($calendars[0]), 0, $start_time, $end_time);
 172      //go_debug($events);
 173  
 174      insert_events($calendars, $start_time, $end_time);
 175  
 176      //$pdf->addCalendar($events);
 177  }
 178  
 179  $filename = File::strip_invalid_chars($lang['calendar']['name'] . ' ' . $title);
 180  
 181  
 182  $browser = detect_browser();
 183  
 184  
 185  //header('Content-Length: '.strlen($file));
 186  header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
 187  if ($browser['name'] == 'MSIE') {
 188      header('Content-Type: application/download');
 189      header('Content-Disposition: attachment; filename="' . rawurlencode($filename) . '.pdf";');
 190      header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
 191      header('Pragma: public');
 192  } else {
 193      header('Content-Type: application/pdf');
 194      header('Pragma: no-cache');
 195      header('Content-Disposition: attachment; filename="' . $filename . '.pdf"');
 196  }
 197  header('Content-Transfer-Encoding: binary');
 198  
 199  echo $pdf->Output($filename . '.pdf', 'S');
 200  ?>

title

Description

title

Description

title

Description

title

title

Body