[ Index ]
 

Code source de WebCalendar 1.0.5

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables | Statistiques

title

Body

[fermer]

/ -> view_v.php (source)

   1  <?php
   2  /*
   3   * $Id: view_v.php,v 1.33 2005/03/06 23:26:35 umcesrjones Exp $
   4   *
   5   * Page Description:
   6   * This page will display the month "view" with all users's events
   7   * on the same calendar.  (The other month "view" displays each user
   8   * calendar in a separate column, side-by-side.)  This view gives you
   9   * the same effect as enabling layers, but with layers you can only
  10   * have one configuration of users.
  11   *
  12   * Input Parameters:
  13   * id (*) - specify view id in webcal_view table
  14   * date - specify the starting date of the view.
  15   *   If not specified, current date will be used.
  16   * friendly - if set to 1, then page does not include links or
  17   *   trailer navigation.
  18   * (*) required field
  19   *
  20   * Security:
  21   * Must have "allow view others" enabled ($allow_view_other) in
  22   *   System Settings unless the user is an admin user ($is_admin).
  23   * If the view is not global, the user must be owner of the view.
  24   * If the view is global, then and user_sees_only_his_groups is
  25   * enabled, then we remove users not in this user's groups
  26   * (except for nonuser calendars... which we allow regardless of group).
  27   */
  28  include_once  'includes/init.php';
  29  
  30  $error = "";
  31  $DAYS_PER_TABLE = 7;
  32  
  33  if ( $allow_view_other == "N" && ! $is_admin ) {
  34    // not allowed...
  35    send_to_preferred_view ();
  36  }
  37  if ( empty ( $id ) ) {
  38    do_redirect ( "views.php" );
  39  }
  40  
  41  // Find view name in $views[]
  42  $view_name = "";
  43  for ( $i = 0; $i < count ( $views ); $i++ ) {
  44    if ( $views[$i]['cal_view_id'] == $id ) {
  45      $view_name = $views[$i]['cal_name'];
  46    }
  47  }
  48  
  49  // If view_name not found, then the specified view id does not
  50  // belong to current user. 
  51  if ( empty( $view_name ) ) {
  52    $error = translate ( "You are not authorized" );
  53  }
  54  
  55  $INC = array('js/popups.php');
  56  print_header($INC);
  57  
  58  set_today($date);
  59  
  60  $next = mktime ( 3, 0, 0, $thismonth, $thisday + 7, $thisyear );
  61  $nextyear = date ( "Y", $next );
  62  $nextmonth = date ( "m", $next );
  63  $nextday = date ( "d", $next );
  64  $nextdate = sprintf ( "%04d%02d%02d", $nextyear, $nextmonth, $nextday );
  65  
  66  $prev = mktime ( 3, 0, 0, $thismonth, $thisday - 7, $thisyear );
  67  $prevyear = date ( "Y", $prev );
  68  $prevmonth = date ( "m", $prev );
  69  $prevday = date ( "d", $prev );
  70  $prevdate = sprintf ( "%04d%02d%02d", $prevyear, $prevmonth, $prevday );
  71  
  72  // We add 2 hours on to the time so that the switch to DST doesn't
  73  // throw us off.  So, all our dates are 2AM for that day.
  74  if ( $WEEK_START == 1 ) {
  75    $wkstart = get_monday_before ( $thisyear, $thismonth, $thisday );
  76  } else {
  77    $wkstart = get_sunday_before ( $thisyear, $thismonth, $thisday );
  78  }
  79  $wkend = $wkstart + ( 3600 * 24 * 6 );
  80  $startdate = date ( "Ymd", $wkstart );
  81  $enddate = date ( "Ymd", $wkend );
  82  
  83  $thisdate = $startdate;
  84  
  85  for ( $i = 0; $i < 7; $i++ ) {
  86    $days[$i] = $wkstart + ( 24 * 3600 ) * $i;
  87    $weekdays[$i] = weekday_short_name ( ( $i + $WEEK_START ) % 7 );
  88    $header[$i] = $weekdays[$i] . "<br />" .
  89       month_short_name ( date ( "m", $days[$i] ) - 1 ) .
  90       " " . date ( "d", $days[$i] );
  91  }
  92  ?>
  93  
  94  <div style="border-width:0px; width:99%;">
  95  <a title="<?php etranslate("Previous")?>" class="prev" 
  96    href="view_v.php?id=<?php echo $id?>&amp;date=<?php echo $prevdate?>">
  97    <img src="leftarrow.gif" alt="<?php etranslate("Previous")?>" /></a>
  98  
  99  <a title="<?php etranslate("Next")?>" class="next" 
 100    href="view_v.php?id=<?php echo $id?>&amp;date=<?php echo $nextdate?>">
 101    <img src="rightarrow.gif" class="prevnext" alt="<?php etranslate("Next")?>" /></a>
 102  <div class="title">
 103  <span class="date"><?php
 104    echo date_to_str ( date ( "Ymd", $wkstart ), false ) .
 105      "&nbsp;&nbsp;&nbsp; - &nbsp;&nbsp;&nbsp;" .
 106      date_to_str ( date ( "Ymd", $wkend ), false );
 107  ?></span><br />
 108  <span class="viewname"><?php echo $view_name ?></span>
 109  </div></div><br />
 110  
 111  <?php
 112  // The table has names across the top and dates for rows.  Since we need
 113  // to spit out an entire row before we can move to the next date, we'll
 114  // save up all the HTML for each cell and then print it out when we're
 115  // done..
 116  // Additionally, we only want to put at most 6 users in one table since
 117  // any more than that doesn't really fit in the page.
 118  
 119  // get users in this view
 120  $res = dbi_query (
 121    "SELECT cal_login FROM webcal_view_user WHERE cal_view_id = $id" );
 122  $viewusers = array ();
 123  $all_users = false;
 124  if ( $res ) {
 125    while ( $row = dbi_fetch_row ( $res ) ) {
 126      $viewusers[] = $row[0];
 127      if ( $row[0] == "__all__" ) {
 128        $all_users = true;
 129      }
 130    }
 131    dbi_free_result ( $res );
 132  } else {
 133    $error = translate ( "Database error" ) . ": " . dbi_error ();
 134  }
 135  
 136  if ( $all_users ) {
 137    $viewusers = array ();
 138    $users = get_my_users ();
 139    for ( $i = 0; $i < count ( $users ); $i++ ) {
 140      $viewusers[] = $users[$i]['cal_login'];
 141    }
 142  } else {
 143    // Make sure this user is allowed to see all users in this view
 144    // If this is a global view, it may include users that this user
 145    // is not allowed to see.
 146    if ( ! empty ( $user_sees_only_his_groups ) &&
 147      $user_sees_only_his_groups == 'Y' ) {
 148      $myusers = get_my_users ();
 149      if ( ! empty ( $nonuser_enabled ) && $nonuser_enabled == "Y" ) {
 150        $myusers = array_merge ( $myusers, get_nonuser_cals () );
 151      }
 152      $userlookup = array ();
 153      for ( $i = 0; $i < count ( $myusers ); $i++ ) {
 154        $userlookup[$myusers[$i]['cal_login']] = 1;
 155      }
 156      $newlist = array ();
 157      for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
 158        if ( ! empty ( $userlookup[$viewusers[$i]] ) ) {
 159          $newlist[] = $viewusers[$i];
 160        }
 161      }
 162      $viewusers = $newlist;
 163    }
 164  }
 165  if ( count ( $viewusers ) == 0 ) {
 166    // This could happen if user_sees_only_his_groups  = Y and
 167    // this user is not a member of any  group assigned to this view
 168    $error = translate ( "No users for this view" );
 169  }
 170  
 171  if ( ! empty ( $error ) ) {
 172    echo "<h2>" . translate ( "Error" ) .
 173      "</h2>\n" . $error;
 174    print_trailer ();
 175    exit;
 176  }
 177  
 178  $e_save = array ();
 179  $re_save = array ();
 180  for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
 181    /* Pre-Load the repeated events for quckier access */
 182    $repeated_events = read_repeated_events ( $viewusers[$i], "", $startdate );
 183    $re_save[$i] = $repeated_events;
 184    /* Pre-load the non-repeating events for quicker access */
 185    $events = read_events ( $viewusers[$i], $startdate, $enddate );
 186    $e_save[$i] = $events;
 187  }
 188  
 189  for ( $j = 0; $j < 7; $j += $DAYS_PER_TABLE ) {
 190    // since print_date_entries is rather stupid, we can swap the event data
 191    // around for users by changing what $events points to.
 192  
 193    $tdw = 12; // column width percent
 194  ?>
 195  
 196  <table class="main" cellspacing="0" cellpadding="0">
 197  <tr><th class="empty">&nbsp;</th>
 198  <?php
 199    for ( $date = $wkstart, $h = 0;
 200      date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
 201      $date += ( 24 * 3600 ), $h++ ) {
 202      $wday = strftime ( "%w", $date );
 203      $weekday = weekday_short_name ( $wday );
 204      if ( date ( "Ymd", $date ) == date ( "Ymd", $today ) ) {
 205        echo "<th class=\"today\" style=\"width:$tdw%;\">";
 206      } else {
 207        echo "<th style=\"width:$tdw%;\">";
 208      }
 209      echo $weekday . " " .
 210      round ( date ( "d", $date ) ) . "</th>\n";
 211    }
 212    echo "</tr>\n";
 213    for ( $i = 0; $i < count ( $viewusers ); $i++ ) {
 214      echo "\n<tr>\n";
 215      $user = $viewusers[$i];
 216      user_load_variables ( $user, "temp" );
 217      echo "<th class=\"row\" style=\"width:$tdw%;\">$tempfullname</th>";
 218      for ( $date = $wkstart, $h = 0;
 219        date ( "Ymd", $date ) <= date ( "Ymd", $wkend );
 220        $date += ( 24 * 3600 ), $h++ ) {
 221        $wday = strftime ( "%w", $date );
 222        if ( $wday == 0 || $wday == 6 ) {
 223          echo "<td class=\"weekend\" style=\"width:$tdw%;\">";
 224        } else {
 225          echo "<td style=\"width:$tdw%;\">";
 226        }
 227        $events = $e_save[$i];
 228        $repeated_events = $re_save[$i];
 229        if ( empty ( $add_link_in_views ) || $add_link_in_views != "N" ) {
 230          echo html_for_add_icon ( date ( "Ymd", $date ), "", "", $user );
 231        }
 232        print_date_entries ( date ( "Ymd", $date ), $user, true );
 233        echo "</td>";
 234      }
 235      echo "</tr>\n";
 236    }
 237    echo "</table>\n<br /><br />\n";
 238  }
 239  
 240  $user = ""; // reset
 241  
 242  if ( ! empty ( $eventinfo ) ) {
 243    echo $eventinfo;
 244  }
 245  
 246  echo "<a title=\"" . translate("Generate printer-friendly version") . 
 247    "\" class=\"printer\" href=\"view_v.php?id=$id&amp;date=" .
 248    "$thisdate&amp;friendly=1\" " .
 249    "target=\"cal_printer_friendly\" onmouseover=\"window.status='" .
 250    translate("Generate printer-friendly version") .
 251    "'\">[" . translate("Printer Friendly") . "]</a>\n";
 252  
 253  print_trailer ();
 254  ?>
 255  </body>
 256  </html>


Généré le : Fri Nov 30 19:09:19 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics