eGroupWare PHP Cross Reference Groupware Applications

Source: /calendar/sitemgr/class.module_calendar_month.inc.php - 315 lines - 10180 bytes - Summary - Text - Print

   1  <?php
   2  /**************************************************************************\
   3   * eGroupWare SiteMgr - Web Content Management                              *
   4   * http://www.egroupware.org                                                *
   5   * --------------------------------------------                             *
   6   *  This program is free software; you can redistribute it and/or modify it *
   7   *  under the terms of the GNU General Public License as published by the   *
   8   *  Free Software Foundation; either version 2 of the License, or (at your  *
   9   *  option) any later version.                                              *
  10   \**************************************************************************/
  11  
  12  /* $Id$ */
  13  
  14  class module_calendar_month extends Module
  15  {
  16      /**
  17       * Instance of the business object of calendar
  18       *
  19       * @var bo
  20       */
  21      var $bo;
  22      /**
  23       * Instance of the user interface object of calendar
  24       *
  25       * @var ui
  26       */
  27      var $ui;
  28      /**
  29       * Instance of the user interface object of calendar
  30       *
  31       * @var ui
  32       */
  33      var $uiviews;
  34      /**
  35       * Instance of the accounts object
  36       *
  37       * @var accounts
  38       */
  39      var $accounts;
  40      /**
  41       * Default CSS style
  42       *
  43       * @var default_css
  44       */
  45      var $default_css = '/calendar/templates/default/app.css';
  46  
  47  	function module_calendar_month()
  48      {
  49          $this->bo = new calendar_bo();
  50          $this->arguments = array(
  51              'category' => array(
  52                  'type' => 'select',
  53                  'label' => lang('Choose a category'),
  54                  'options' => array(),    // specification of options is postponed into the get_user_interface function
  55                  'multiple' => true,
  56              ),
  57              'numWeeks' => array(
  58                  'type' => 'textfield',
  59                  'label' => lang('Number of weeks to show'),
  60                  'default' => 2,
  61                  'params' => array('size' => 1)
  62              ),
  63              'showWeeks' => array(
  64                  'type' => 'checkbox',
  65                  'label' => lang('Should the number of weeks be shown on top of the calendar'),
  66                  'default' => false,
  67              ),
  68              'showTitle' => array(
  69                  'type' => 'checkbox',
  70                  'label' => lang('Show a calendar title'),
  71                  'default' => false,
  72              ),
  73              'search' => array(
  74                  'type' => 'textfield',
  75                  'label' => lang('Search string for the events'),
  76              ),
  77              'users' => array(
  78                  'type' => 'select',
  79                  'options' => array(),
  80                  'label' => lang('Group(s) or user(s) whose calendars to show (if ACL exists)'),
  81                  // 'multiple' => true, is set in the get_user_interface function.
  82              ),
  83              'grid' => array(
  84                  'type' => 'checkbox',
  85                  'label' => lang('Should the grid be shown in the calendar'),
  86                  'default' => false,
  87              ),
  88              'css' => array(
  89                  'type' => 'textfield',
  90                  'label' => lang('User selectable CSS file for the calendar setup'),
  91                  'default' => $this->default_css,
  92              ),
  93              'acceptDateParam' => array(
  94                  'type' => 'checkbox',
  95                  'label' => lang('Shall the date parameter be accepted (e.g. from calendar module)?'),
  96                  'default' => false,
  97              ),
  98          );
  99          $this->title = lang('Calendar - Multi-Weekly');
 100          $this->description = lang("This module displays a user's calendar as multiple weeks. Don't give calendar application access to the anon user!");
 101      }
 102  
 103  	function get_user_interface()
 104      {
 105          // copied from bookmarks module.
 106          $cat = createobject('phpgwapi.categories','','calendar');
 107          $cats = $cat->return_array('all',0,False,'','cat_name','',True);
 108          $cat_ids = array();
 109          while (list(,$category) = @each($cats))
 110          {
 111              $cat_ids[$category['id']] = $GLOBALS['egw']->strip_html($category['name']);
 112          }
 113          $this->arguments['category']['options'] = $cat_ids;
 114          if (count($cat_ids) > 5) {
 115              $this->arguments['category']['multiple'] = 5;
 116          }
 117  
 118          if (! isset($GLOBALS['egw']->accounts))
 119          {
 120              $GLOBALS['egw']->accounts = new accounts();
 121          }
 122          $this->accounts =& $GLOBALS['egw']->accounts;
 123          $search_params=array(
 124              'type' => 'both',
 125              'app' => 'calendar',
 126          );
 127          $accounts = $this->accounts->search($search_params);
 128          $users = array();
 129          $groups = array();
 130          // sort users and groups separately.
 131          if (isset($GLOBALS['sitemgr_info']['anonymous_user']))
 132          {
 133              $anon_user = $this->accounts->name2id($GLOBALS['sitemgr_info']['anonymous_user'],'account_lid','u');
 134          }
 135          else
 136          {
 137              // sitemgr is not in global variables. Get it.
 138              /*
 139               * Get possible sitemgr paths from the HTTP_REFERRER in order to unreveal the
 140               * anonymous user for the correct site.
 141               */
 142              $sitemgr_path = preg_replace('/^[^\/]+:\/\/[^\/]+\/([^\?]*)(\?.*)*$/',"/\$1}",$_SERVER['HTTP_REFERER']);
 143              // Remove the trailing file- / pathname if any
 144              $sitemgr_path = preg_replace('/[^\/]*$/', '', $sitemgr_path);
 145              // Add leading slash if it has been lost.
 146              if (strncmp('/', $sitemgr_path, 1) != 0)
 147              {
 148                  $sitemgr_path = '/'.$sitemgr_path;
 149              }
 150  
 151              // Code adapted from sitemgr-site/index.php
 152              $site_urls = array();
 153              $site_urls[] = $sitemgr_path;
 154              $site_urls[] = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['SERVER_ADDR'] . $sitemgr_path;
 155              $site_urls[] = $site_url = ($_SERVER['HTTPS'] ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] . $sitemgr_path;
 156  
 157              $GLOBALS['egw']->db->select('egw_sitemgr_sites','anonymous_user,anonymous_passwd,site_id',
 158                  array('site_url' => $site_urls),__LINE__,__FILE__,false,'','sitemgr');
 159  
 160              $GLOBALS['egw']->db->next_record();
 161              $anon_user = $this->accounts->name2id($GLOBALS['egw']->db->f('anonymous_user'),'account_lid','u');
 162          }
 163  
 164          $anon_groups = $this->accounts->memberships($anon_user,true);
 165          foreach ($accounts as $entry)
 166          {
 167              $is_group = false;
 168              $has_read_permissions = false;
 169              $acl = new acl($entry['account_id']);
 170              $acl->read_repository();
 171              // get the rights for each account to check whether the anon user has read permissions.
 172              $rights = $acl->get_rights($anon_user,'calendar');
 173              // also add the anon user if it's his own calendar.
 174              if (($rights & EGW_ACL_READ) || ($entry['account_id'] == $anon_user))
 175              {
 176                  $has_read_permissions = true;
 177              }
 178              else
 179              {
 180                  // scan the groups which pass on permissions to the anon user group member
 181                  // or ass permissions if this is the anon group's calendar.
 182                  foreach ($anon_groups as $parent_group)
 183                  {
 184                      $rights = $acl->get_rights($parent_group,'calendar');
 185                      if (($rights & EGW_ACL_READ) || ($entry['account_id'] == $parent_group))
 186                      {
 187                          $has_read_permissions = true;
 188                          break;
 189                      }
 190                  }
 191              }
 192              if ($has_read_permissions)
 193              {
 194                  // Separate groups from users for improved readability.
 195                  if ($is_group)
 196                  {
 197                      $groups[$entry['account_id']] = $entry['account_lid'];
 198                  }
 199                  else
 200                  {
 201                      $users[$entry['account_id']] = $GLOBALS['egw']->common->display_fullname($entry['account_lid'],$entry['account_firstname'],$entry['account_lastname']);
 202                  }
 203              }
 204          }
 205          asort($groups);
 206          asort($users);
 207          // concat users and groups to the option array.
 208          $this->arguments['users']['options'] = $groups + $users;
 209          if (count($this->arguments['users']['options']) > 10)
 210          {
 211              $this->arguments['users']['multiple'] = 10;
 212          }
 213          else if (count($this->arguments['users']['options']) > 0)
 214          {
 215              $this->arguments['users']['multiple'] = true;
 216          }
 217  
 218          return parent::get_user_interface();
 219      }
 220  
 221  	function get_content(&$arguments,$properties)
 222      {
 223          $html = "";
 224          $GLOBALS['egw']->translation->add_app('calendar');
 225          $this->ui = new calendar_uiviews();
 226          $this->ui->allowEdit = false;
 227          $this->ui->use_time_grid = isset($arguments['grid']) ? $arguments['grid'] : false;
 228  
 229          $weeks = $arguments['numWeeks'] ? (int) $arguments['numWeeks'] : 2;
 230  
 231          if (($arguments['acceptDateParam']) && (get_var('date',array('POST','GET'))))
 232          {
 233              $start = (int) (strtotime(get_var('date',array('POST','GET'))) +
 234                      (60 * 60 * 24 * 7 * $dateOffset));
 235          }
 236          else
 237          {
 238              $start = (int) ($this->bo->now_su +
 239                      (60 * 60 * 24 * 7 * $dateOffset));
 240          }
 241          $first = $this->ui->datetime->get_weekday_start(
 242                      adodb_date('Y',$start),
 243                      adodb_date('m',$start),
 244                      adodb_date('d',$start));
 245          $last = strtotime("+$weeks weeks",$first) - 1;
 246  
 247          if ($arguments['showTitle'])
 248          {
 249              $html .= '<div id="divAppboxHeader">'.$GLOBALS['egw_info']['apps']['calendar']['title'].' - '.lang('Weekview').": ";
 250              $html .= lang('After %1',$this->bo->long_date($first));
 251              $html .= "</div>";
 252          }
 253  
 254          // set the search parameters
 255          $search_params = Array
 256          (
 257              'offset' => false,
 258              'order' => 'cal_start ASC',
 259              'start' => $first,
 260              'end' => $last,
 261              'daywise' => true,
 262          );
 263          $search_string = trim($arguments['search']);
 264          if ($search_string != "")
 265          {
 266              $search_params['query'] = $search_string;
 267          }
 268          if (count($arguments['category']) > 0)
 269          {
 270              $search_params['cat_id'] = $arguments['category'];
 271          }
 272          if ((is_array($arguments['users'])) && (count($arguments['users']) > 0))
 273          {
 274              $search_params['users'] = $arguments['users'];
 275          }
 276          $rows = $this->bo->search($search_params);
 277          if ($arguments['showWeeks'])
 278          {
 279              $html .= "<div>".lang('Next')." ".lang('%1 weeks', $weeks).":</div>\n";
 280          }
 281          $css_file = isset($arguments['css']) ? $arguments['css'] : $this->default_css;
 282          $html .= '<!-- BEGIN Calendar info -->'."\n";
 283          $html .= '<style type="text/css">'."\n";
 284          $html .= '<!--'."\n";
 285          $html .= '@import url('.$GLOBALS['egw_info']['server']['webserver_url'].$css_file.");\n";
 286          $html .= '-->'."\n";
 287          $html .= '</style>'."\n";
 288          $html .= '<!-- END Calendar info -->'."\n";
 289          unset($css_file);
 290          // we add DAY_s/2 to $this->first (using 12h), to deal with daylight saving changes
 291          for ($week_start = $first; $week_start < $last; $week_start = strtotime("+1 week",$week_start))
 292          {
 293              $week = array();
 294              for ($i = 0; $i < 7; ++$i)
 295              {
 296                  $day_ymd = $this->bo->date2string($i ? strtotime("+$i days",$week_start) : $week_start);
 297                  $week[$day_ymd] = array_shift($rows);
 298              }
 299              $week_view = array(
 300                  'menuaction' => false,
 301                  'date' => $this->bo->date2string($week_start),
 302              );
 303              $title = lang('Wk').' '.adodb_date('W',$week_start);
 304              if (!isset($GLOBALS['egw']->template))
 305              {
 306                  $GLOBALS['egw']->template = new Template;
 307              }
 308              $html .= $this->ui->timeGridWidget($this->ui->tagWholeDayOnTop($week),$weeks == 2 ? 30 : 60,200,'',$title,0,$week_start+WEEK_s >= $last);
 309          }
 310          // Initialize Tooltips
 311          $html .= '<script language="JavaScript" type="text/javascript" src="'.$GLOBALS['egw_info']['server']['webserver_url'].'/phpgwapi/js/wz_tooltip/wz_tooltip.js"></script>'."\n";
 312  
 313          return $html;
 314      }
 315  }

title

Description

title

Description

title

Description

title

title

Body