[ 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_w.php (source)

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


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