<?cs include:"util.cs" ?>


<?cs set:icon.new_msg = "stats_new.gif" ?>
<?cs set:icon.read_msg = "stats_read.gif" ?>
<?cs set:icon.log_in = "stats_login.gif" ?>
<?cs set:icon.send_msg = "stats_send.gif" ?>
<?cs set:icon.enter_chat = "stats_chat.gif" ?>
<?cs set:icon.took_selftest = "stats_selftest.gif" ?>


<?cs def:print_icons(data) ?>
 <div class="regheading">
   <?cs set:num_icon = #0 ?>
  <?cs each:myicon = icon ?>
   <img src="<?cs var:image_path ?><?cs var:myicon ?>"  alt="<?cs var:data.icon[name(myicon)] ?>" style="vertical-align: middle;" />=<?cs var:data.icon[name(myicon)] ?>
   <?cs if:num_icon < #5 ?>
   ,
   <?cs /if ?>
   <?cs set:num_icon = num_icon + #1 ?>
  <?cs /each ?>
 </div> 
 <br />
<?cs /def ?>


<?cs #############################
     # a macro that print week day 
     #############################
?>
<?cs def:week_day(w_day) ?>
   <td  valign="middle" align="center"  class="calendar_heading" style="width: 14%" >
   <?cs var:w_day ?>
   </td> 
<?cs /def ?>





<?cs #############################
     # a macro that print month navigation 
     #############################
?>

<?cs def:month_nav(mymonth, preurl, nexturl) ?>

<table border="0" cellpadding="2" cellspacing="1" width="75%" class="black_border">
<tr>
  <td class="calendar_heading" align="center">&nbsp;&nbsp;
    <?cs if:preurl ?>
     <?cs set:temp = #preurl -#1 ?>
     <a href="#<?cs var:temp ?>" title="<?cs var:lang.stats_ind_calendar.prev_month_title ?>">&lt;&lt;</a>
    <?cs else ?>
     &lt;&lt;
    <?cs /if ?>
    &nbsp;&nbsp;
     <?cs var:lang.stats_ind_calendar.month_name[mymonth.month] ?>   <?cs var:mymonth.year ?>
   &nbsp;&nbsp;
   <?cs if:nexturl && nexturl < max_month ?>
    <a  href="#<?cs var:nexturl ?>" title="<?cs var:lang.stats_ind_calendar.next_month_title ?>">&gt;&gt;</a>
   <?cs else ?>
    &gt;&gt;
   <?cs /if ?> 
  &nbsp;&nbsp;
 </td>
</tr>
</table>
<?cs /def ?>

<?cs #############################
     # a macro that print day 
     #############################
?>


<?cs #############################
     # a macro that print empty cell 
     #############################
?>
<?cs def:empty_cell() ?>
<td  class="cellbg">&nbsp;<br />&nbsp; <br /> &nbsp; <br />&nbsp;<br /></td>
<?cs /def ?>



<?cs def:print_table_list() ?>
  <table width="100%">
   <tr><td align="center">
    <table cellspacing="0" cellpadding="4" border="1">
     <tr class="table_heading">
       <?cs each:head = lang.stats_ind_calendar.table ?>
        <th><?cs var:head ?></th>
       <?cs /each ?>
     </tr>
     <?cs each:this = event_month ?>
       <?cs loop:x = #1, #this.days, #1 ?>
        <?cs each:my_event = event[this.year][this.month][x] ?>
      <tr>
         <td><?cs var:my_event.time ?></td>
         <td><?cs var:lang.stats_ind_calendar.icon[my_event.action] ?></td>
         <td><?cs var:lang.stats_ind_calendar.module[my_event.module] ?></td>
         <td><?cs var:my_event.detail ?></td>
      </tr>
       <?cs /each ?>
      <?cs /loop ?>
     <?cs /each ?>
    </table>
   </td></tr>
  </table>
<?cs /def ?>

<?cs def:print_events_of_month(month) ?>
  <tr>
  <?cs if:month.start_day ?>
     <?cs loop:x = #0, #month.start_day - #1, #1 ?>
       <?cs call:empty_cell() ?>
     <?cs /loop ?>
  <?cs /if ?> 
  <?cs set:count = #month.start_day ?>
  <?cs loop:x = #1, #month.days, #1 ?>
    <?cs if:count % #7 == #0 ?>
        </tr><tr>
       <?cs set:count = #0 ?>
    <?cs /if ?>
    <td valign="top" class="cellbg" >
       <table width="100%"><tr><td align="right"><?cs var:x ?></td></tr></table>
       <?cs set:icon_count = #0 ?>
       <?cs set:row_count = #0 ?>
       <?cs each:myevent = event[month.year][month.month][x] ?>
       <?cs if:icon_count == #3 ?>
         <br />
         <?cs set:row_count = #row_count + #1  ?>
       <?cs /if ?>
        <a href="javascript:alert('<?cs var:lang.stats_ind_calendar.module[myevent.module] ?>: <?cs var:myevent.detail ?>')" title="<?cs var:lang.stats_ind_calendar.module[myevent.module] ?>: <?cs var:myevent.detail ?>">
     <img src="<?cs var:image_path ?><?cs var:icon[myevent.action] ?>" alt="<?cs var:lang.stats_ind_calendar.module[myevent.module]
?>: <?cs var:myevent.detail ?>" /></a>
  
       <?cs set:icon_count = #icon_count + #1 ?>
       <?cs /each ?> 
       <?cs if:row_count < #3 ?>
         <?cs set:spaces = #3 - #row_count ?>
         <?cs loop:y = #1, #spaces, #1 ?>
           &nbsp;<br />
          <?cs /loop ?> 
        <?cs /if ?>
    </td>
    <?cs set:count = #count + #1 ?>
  <?cs /loop ?>
  <?cs if:count < #7 ?>
  <?cs loop:x = #1, #7 - #count, #1 ?>
       <?cs call:empty_cell() ?>
  <?cs /loop ?> 
  <?cs /if ?>
  </tr> 
<?cs /def ?>

<?cs def:print_calendar() ?>
<table  width="100%">
     <tr><td align="center">
       <?cs call:print_icons(lang.stats_ind_calendar) ?>
       <?cs set:num_month = #0 ?>
       <?cs each:my_month = event_month ?> 
       <a name="<?cs var:num_month ?>"></a>
        <?cs call:month_nav(my_month, num_month, #num_month + #1) ?>
        <table border="0" cellpadding="2" cellspacing="1"  width="75%" class="black_border">
        <tr>
           <?cs each:item = lang.stats_ind_calendar.day ?>
           <?cs call:week_day(item) ?>
           <?cs /each ?>
        </tr>
        <?cs call:print_events_of_month(my_month) ?>
       </table>
      <br />
        <?cs set:num_month = #num_month + #1 ?>
        <?cs /each ?> 
    <br />
 </td></tr>
</table>

<?cs /def ?>

<?cs ###########################
     # HTML starts here
     ###########################
?>

<?cs call:html_heading() ?>
   <head>
      <title><?cs var:lang.stats_ind_calendar.title ?> <?cs var:realname ?></title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
   <link rel="StyleSheet" href="<?cs var:image_path ?>common.css" type="text/css"  />
   <script type="text/javascript">
  function openwindow(some_url,winname)
  {
  var new_window = window.open(some_url, winname,'menubar=yes,toolbar=yes,status=yes,scrollbars=yes,resizable=yes,width=760,height=500');
  new_window.focus();
  }
  </script>

</head>
<?cs call:define_body() ?> 
<?cs call:print_course_heading(back_url, lang.stats_ind_calendar.goback) ?>
   <div class="center_msg">
    <span class="alert_color">
    <?cs if:show_list == #1 ?>
     <?cs var:lang.stats_ind_calendar.title2 ?> 
    <?cs else ?>
     <?cs var:lang.stats_ind_calendar.title ?> 
   <?cs /if ?>
  
    <?cs if:user.0.url ?>
      <a href="javascript:openwindow('<?cs var:user.0.url ?>', 'bio_win')" title="<?cs var:lang.stats_ind_calendar.bio_help ?> <?cs var:user.0.realname ?>" class="normal">
      <?cs var:user.0.realname ?><?cs if:!hide_manhattan_username ?>(<?cs var:user.0.username ?>)<?cs /if ?></a></span>
    <?cs else ?>
      <?cs var:user.0.realname ?><?cs if:!hide_manhattan_username ?>(<?cs var:user.0.username ?>)<?cs /if ?></span>
    <?cs /if ?>
    <div class="regheading">
     (<?cs var:lang.stats_ind_calendar.note ?>)
    </div>
   </div>
<?cs if:show_list ?>
 <?cs call:print_table_list() ?>
<?cs else ?>
 <?cs call:print_calendar() ?>
<?cs /if ?>
</body>
</html>
<?cs call:runtime() ?>
