Location: PHPKode > projects > ConPortal > conportal/inc/announcements/display.php
<?php
/*
 *  ConPortal - Pomona College ITS scheduling appplication
 *  Copyright (C) 2005-2006  Pomona College
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of version 2 of the GNU General Public License
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

//prints out a form to manage appointments
//has sections for making new announcements, adjusting current ones, and 
//viewing expired ones
//returns void
function print_manage_announcments_form()
{
    echo '<div id="announcements">';
    print_new_announcement_form();
    echo '<hr />';
    print_existing_announcement_form();
    echo '<hr />';
    print_view_expired_announcement_form();
    echo '</div>';
}

//prints a form to create a new announcement
//returns void
function print_new_announcement_form()
{
    ?>
    <div id="newAnnouncement">
    <h3>Create New Announcement</h3>
      <form action="redirects/new_announcements.php" method="post">
      <table>
        <tr><td>Subject:</td>
            <td><?php print_text_input_field('subject',
                         "",'size="40" maxlength="200"'); ?></td></tr>
        <tr><td>Message:</td><td><?php print_textarea_field('message',"",'cols="40" rows="5"') ?></td></tr>
        <tr><td>Expiration Date:</td><td><?php
          //generate timestamp for +14 days for default expiration
          $twoWeeksLater = strtotime("+14 days");
          echo '<select name="year">';
          print_year_options(date('Y',$twoWeeksLater));
          echo '</select><select name="month">';
          print_month_options(date('n',$twoWeeksLater));
          echo '</select><select name="day">';
          print_day_options(date('j',$twoWeeksLater));
          echo '</select>';
          ?></td></tr>
        <tr><td>Visible to Group:</td><td><select name="group">
          <option value="-1">Select a group</option>
          <?php
          //Get list of groups and present them here
          $groupIds=getAllGroups();
		echo "<option value=\"99\"> All groups</option>";  
          foreach ($groupIds as $tempId)
          {
            $details=getGroupDetails($tempId);
            echo '<option value="'.$tempId.'">'.$details['name'].'</option>';
          }
          ?>
      </select></td></tr>
      </table>
      <div><?php print_submit_field('Create New Announcement'); ?></div>
      </form>
    </div>
    <?php
}

//prints a list of current announcements along with a button to edit/expire
//each one
//returns void
function print_existing_announcement_form()
{
    ?>
    <div id="existingAnnouncements">
    <h3>Existing Announcements</h3>
    <?php
    $announcements = getAllUnexpiredAnnouncments();
    //print out the announcements along with edit buttons
    if (is_array($announcements) && count($announcements))
    {
        print_announcements_table($announcements);
    }
    else
    {
        echo 'No current announcements.';
    }
    ?>
    </div>
    <?php
}

//prints a form with a start/end date to show expired appointments
//returns void
function print_view_expired_announcement_form()
{
    ?>
    <div id="expiredAnnouncements">
    <h3>View Expired Announcements</h3>
    <p>View announcements that expired between:</p>
    <form action="expired_announcements.php" method="post"><div><?php
      //Start Date Range
      //generate timestamp for -14 days for default expiration
      $twoWeeksAgo = strtotime("-14 days");
      echo '<select name="startYear">';
      print_year_options(date('Y',$twoWeeksAgo));
      echo '</select><select name="startMonth">';
      print_month_options(date('n',$twoWeeksAgo));
      echo '</select><select name="startDay">';
      print_day_options(date('j',$twoWeeksAgo));
      echo '</select>&lt;-&gt;';
      //End Date Range
      echo '<select name="endYear">';
      print_year_options(date('Y',time()));
      echo '</select><select name="endMonth">';
      print_month_options(date('n',time()));
      echo '</select><select name="endDay">';
      print_day_options(date('j',time()));
      echo '</select>';
    ?><br /><?php print_submit_field('Show expired announcements...'); ?></div></form>
    </div>
    <?php
}

function print_extend_announcments_form($pid)
{
    $details=getAnnouncmentDetails($pid);
    $group = getGroupDetails($details['targetGroup']);
    ?>
    <div id="extendAnnouncement">
    <?php
    echo '<p class="announcementSubject">'.$details['subject'].'</p>';
    echo '<p class="announcementMessage">'.$details['message'].'</p>';
    echo '<p>Current Expiration: '.timestamp_to_prettydate($details['expiration']).
         '</p>';
    echo '<p>Visible to group: '.$group['name'].'</p>';
    ?>
    <hr />
    <form action="redirects/extend_announcement.php" method="post">
    <div>
    Extend this announcement to:
    <?php
        //generate timestamp for +7 days for default expiration
        $oneWeekLater = strtotime("+7 days",$details['expiration']);
        echo '<select name="year">';
        print_year_options(date('Y',$oneWeekLater));
        echo '</select><select name="month">';
        print_month_options(date('n',$oneWeekLater));
        echo '</select><select name="day">';
        print_day_options(date('j',$oneWeekLater));
        echo '</select>';
        echo '<input type="hidden" value="'.$pid.'" name="pid" />';
        print_submit_field('Extend...');
    ?>
    <br />(Default is 7 days after current expiration)
    </div>
    </form>
    </div>
    <?php
}

function print_expired_announcements($startDate,$endDate)
{
    $announcements = getExpiredAnnouncements($startDate,$endDate);
    echo '<div id="expiredAnnouncements">';
    if (is_array($announcements) && count($announcements))
    {
        print_announcements_table($announcements,false,true);
    }
    else
    {
        echo 'No current announcements.';
    }
    echo '</div>';
}

function print_announcements_table($announcements,$expireColumn = true, $extendColumn = true)
{
    ?>
    <table>
    <tr><td>Subject</td><td>Message</td><td>Expiration</td><td>Group</td>
    <?php
    if ($expireColumn)
    {
        echo '<td>Expire Now</td>';
    }
    if ($extendColumn)
    {
        echo '<td>Extend Expiration</td>';
    }
    echo '</tr>';
    $i = 0;
    foreach ($announcements as $tempAnnouncement)
    {
        $details = getAnnouncmentDetails($tempAnnouncement);
        $group = getGroupDetails($details['targetGroup']);
        echo '<tr class="d'.($i++ % 2).'">'.
             '<td>'.$details['subject'].'</td>'.
             '<td>'.$details['message'].'</td>'.
             '<td>'.timestamp_to_prettydate($details['expiration']).'</td>'.
             '<td>'.$group['name'].'</td>';
        if ($expireColumn)
        {
            echo '<td><a href="redirects/expire_announcement.php?pid='.
                      $tempAnnouncement.'">Expire Now</a></td>';
        }
        if ($extendColumn)
        {
            echo '<td><a href="extend_announcement.php?pid='.
                      $tempAnnouncement.'">Extend Announcement</a></td>';
        }
        echo '</tr>';
    }
    echo '</table>';
}

?>
Return current item: ConPortal