/[drupal]/contributions/modules/rsvp/rsvp.functions.inc
ViewVC logotype

Diff of /contributions/modules/rsvp/rsvp.functions.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.3.2.15, Tue Oct 27 18:32:21 2009 UTC revision 1.3.2.16, Thu Nov 5 22:36:47 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: rsvp.functions.inc,v 1.3.2.14 2009/07/08 18:55:52 ulf1 Exp $  // $Id: rsvp.functions.inc,v 1.3.2.15 2009/10/27 18:32:21 ulf1 Exp $
4    
5  /**  /**
6   * @module rsvp_functions   * @module rsvp_functions
# Line 146  define('RSVP_VAR_CONTENT_TYPES', 'rsvp_c Line 146  define('RSVP_VAR_CONTENT_TYPES', 'rsvp_c
146  define('RSVP_VAR_CONNECTOR', 'rsvp_connector');  define('RSVP_VAR_CONNECTOR', 'rsvp_connector');
147    
148    
149    define('RSVP_OPTION_OPENINVITATION',           0x00000001); //Can other registered users signup to the invitation
150    define('RSVP_OPTION_DISABLE_MAYBE',            0x00000002); //Allow maybe as answer or not.
151    define('RSVP_OPTION_REPLY_STARTDATE_ENABLED',  0x00000004); //is reply startdate enabled.
152    define('RSVP_OPTION_REPLY_ENDDATE_ENABLED',    0x00000008); //is reply enddate enabled.
153    define('RSVP_OPTION_SEND_PRIVATEMSG',          0x00000010); //Send emails by privatemsg for registered users.
154    define('RSVP_OPTION_SEND_CONF_OWNER',          0x00000020); //Send confirmation emails to owner when guest replies.
155    define('RSVP_OPTION_SEND_CONF_GUEST',          0x00000040); //Send confirmation emails to guest when he replies.
156    
157    
158  /**  /**
159   * RSVP SELECT Query statements that we use for all types of queries   * RSVP SELECT Query statements that we use for all types of queries
160   */   */
# Line 173  function rsvp_function_create_rsvp($rsvp Line 182  function rsvp_function_create_rsvp($rsvp
182    $vals[] = $user->uid;    $vals[] = $user->uid;
183    $markers[] = "%d";    $markers[] = "%d";
184    
185    foreach (array('nid', 'uid_moderator', 'reply_startdate', 'reply_enddate', 'max_guests', 'open_invitation', 'disable_maybe', 'send_privatemsg', 'send_conf_guest', 'send_conf_owner', 'invite_filterformat') as $key) {    foreach (array('nid', 'uid_moderator', 'reply_startdate', 'reply_enddate', 'max_guests', 'option_enabled', 'invite_filterformat') as $key) {
186      $fields[] = $key;      $fields[] = $key;
187      $vals[] = $rsvp->$key;      $vals[] = $rsvp->$key;
188      $markers[] = "%d";      $markers[] = "%d";
# Line 219  function rsvp_function_update_rsvp($rsvp Line 228  function rsvp_function_update_rsvp($rsvp
228    $fields[] = 'timestamp = %d';    $fields[] = 'timestamp = %d';
229    $vals[] = time();    $vals[] = time();
230    
231    foreach (array('nid', 'uid', 'uid_moderator', 'reply_startdate', 'reply_enddate', 'max_guests', 'open_invitation', 'disable_maybe', 'send_privatemsg', 'send_conf_guest', 'send_conf_owner','invite_filterformat') as $key) {    foreach (array('nid', 'uid', 'uid_moderator', 'reply_startdate', 'reply_enddate', 'max_guests', 'option_enabled', 'invite_filterformat') as $key) {
232      $fields[] = $key ." = %d";      $fields[] = $key ." = %d";
233      $vals[] = $rsvp->$key;      $vals[] = $rsvp->$key;
234    }    }
# Line 603  function rsvp_function_initialize_defaul Line 612  function rsvp_function_initialize_defaul
612    $rsvp->list_email = variable_get('rsvp_default_list_email', RSVP_SEND_NONE);    $rsvp->list_email = variable_get('rsvp_default_list_email', RSVP_SEND_NONE);
613    $rsvp->allow_invite = variable_get('rsvp_default_allow_invite', RSVP_INVITE_NONE);    $rsvp->allow_invite = variable_get('rsvp_default_allow_invite', RSVP_INVITE_NONE);
614    
   $rsvp->send_conf_owner = variable_get('rsvp_default_send_conf_owner', RSVP_OPTION_NO);  
   $rsvp->send_conf_guest = variable_get('rsvp_default_send_conf_guest', RSVP_OPTION_NO);  
   $rsvp->send_privatemsg = variable_get('rsvp_default_send_privatemsg', RSVP_OPTION_NO);  
   $rsvp->disable_maybe = variable_get('rsvp_default_disable_maybe', RSVP_OPTION_NO);  
   $rsvp->open_invitation = variable_get('rsvp_default_open_invitation', RSVP_OPTION_NO);  
615    $rsvp->max_guests = variable_get('rsvp_default_max_guests', 0);    $rsvp->max_guests = variable_get('rsvp_default_max_guests', 0);
616    $rsvp->theme = variable_get('rsvp_default_theme', RSVP_THEME_DEFAULT);    $rsvp->theme = variable_get('rsvp_default_theme', RSVP_THEME_DEFAULT);
617    $rsvp->stylesheet = variable_get('rsvp_default_stylesheet', RSVP_STYLESHEET_DEFAULT);    $rsvp->stylesheet = variable_get('rsvp_default_stylesheet', RSVP_STYLESHEET_DEFAULT);
618    $rsvp->iconset = variable_get('rsvp_default_iconset', RSVP_ICONSET_DEFAULT);    $rsvp->iconset = variable_get('rsvp_default_iconset', RSVP_ICONSET_DEFAULT);
619    $rsvp->backgroundimage = variable_get('rsvp_default_backgroundimage', RSVP_BACKGROUNDIMAGE_DEFAULT);    $rsvp->backgroundimage = variable_get('rsvp_default_backgroundimage', RSVP_BACKGROUNDIMAGE_DEFAULT);
620    $rsvp->image = variable_get('rsvp_default_image', RSVP_IMAGE_DEFAULT);    $rsvp->image = variable_get('rsvp_default_image', RSVP_IMAGE_DEFAULT);
621      $rsvp->option_enabled = variable_get('rsvp_default_option_enabled', 0);
622    
623      $rsvp->reply_startdate = 0;
624      $rsvp->reply_enddate = 0;
625    
626    $rsvp->invite_filterformat = FILTER_FORMAT_DEFAULT;    $rsvp->invite_filterformat = FILTER_FORMAT_DEFAULT;
627    
628    return $rsvp;    return $rsvp;
629  }  }
630    
631    /**
632     * Internal function
633     *
634     * Sets a bit on a int field based on the passed information
635     *
636     * Permission check needs to be done outside.
637     *
638     * @ingroup rsvp_functions
639     *
640     * @param &$variable reference to an int variable.
641     * @param $option_bit  The bit we want to work with.
642     * @param $value  can be either RSVP_OPTION_NO or RSVP_OPTION_YES (we test for != 0 internally
643     *
644     */
645    function _rsvp_function_setbit(&$variable, $option_bit, $value) {
646    
647      if (($value == 0) || ($value == RSVP_OPTION_NO)) {
648        $variable = $variable & ~$option_bit;
649      }
650      else if (($value > 0) || ($value == RSVP_OPTION_YES)) {
651        $variable = $variable | $option_bit;
652      }
653    
654    
655    }
656    
657    /**
658     * Internal function
659     *
660     * Checks a bit on a int field based on the passed information
661     *
662     * Permission check needs to be done outside.
663     *
664     * @ingroup rsvp_functions
665     *
666     * @param $variable int variable.
667     * @param $option_bit  The bit we want to work with.
668     *
669     * @return RSVP_OPTION_NO or RSVP_OPTION_YES
670     */
671    function _rsvp_function_checkbit($variable, $option_bit) {
672    
673      if (($variable & $option_bit) > 0)
674        return RSVP_OPTION_YES;
675      else
676        return RSVP_OPTION_NO;
677    }
678    
679  /**  /**
680   * Internal function   * Internal function
# Line 1613  function rsvp_function_is_expired($node, Line 1668  function rsvp_function_is_expired($node,
1668    if (is_null($node))    if (is_null($node))
1669      return true;      return true;
1670    
1671      if (variable_get('rsvp_for_expired_event', RSVP_OPTION_NO) == RSVP_OPTION_YES)
1672        return false;
1673    
1674    $now = time();    $now = time();
1675    
1676    $field = $connector->get_event_field($node->type);    $field = $connector->get_event_field($node->type);
# Line 1621  function rsvp_function_is_expired($node, Line 1679  function rsvp_function_is_expired($node,
1679      $allExpired = true;      $allExpired = true;
1680      //debug $end_dates = array();      //debug $end_dates = array();
1681      $count = $connector->get_datecount($node, $field);      $count = $connector->get_datecount($node, $field);
1682      //iterate through all specified enddates (in case of repeating dates)      //iterate through all specified enddates (in case of repeating dates) to find at least one with enddate.
1683      //debug $end_dates[] = array('current time stamp' => $time, 'current time readable' => date('r', $time) );      //debug $end_dates[] = array('current time stamp' => $time, 'current time readable' => date('r', $time) );
1684      for ($i = 0; $i < $count; $i++) {      for ($i = 0; $i < $count; $i++) {
1685        $t2 = $connector->get_enddate($node, $field, $i);        if ($connector->has_enddate($node, $field, $i)) {
1686        //debug $end_dates[] = array('field' => $field, 'stamp' => $t2, 'readable' => date('r', $t2) );          $t2 = $connector->get_enddateAsUTC($node, $field, $i);
1687            //debug $end_dates[] = array('field' => $field, 'stamp' => $t2, 'readable' => date('r', $t2) );
1688    
1689        if ($t2 > $now) {          if ($t2 > $now) {
1690          $allExpired = false;            $allExpired = false;
1691          break;            break;
1692            }
1693          }
1694          else {
1695              $allExpired = false;
1696              break;
1697        }        }
1698      }      }
1699      //debug var_dump($allExpired, $end_dates);      //debug var_dump($allExpired, $end_dates);
# Line 1639  function rsvp_function_is_expired($node, Line 1703  function rsvp_function_is_expired($node,
1703    }    }
1704    else {    else {
1705      $pos = $connector->get_posByHash($node, $field, $rsvp->startdate);      $pos = $connector->get_posByHash($node, $field, $rsvp->startdate);
1706        if ($connector->has_enddate($node, $field, $pos))
1707      return ($now > $connector->get_enddate($node, $field, $pos));        return ($now > $connector->get_enddateAsUTC($node, $field, $pos));
1708        else
1709          return false;
1710    }    }
1711    
1712  }  }
1713    
1714  /**  /**
1715   * Verifies if a user can reply to a rsvp at this time or not.   * Verifies if a user can reply to a rsvp at this time or not.
1716   *   * We use the highest bit to determine if we use the reply dates at this point or not.
1717   * @ingroup rsvp_functions   * @ingroup rsvp_functions
1718   *   *
1719   * Permission check needs to be done outside.   * Permission check needs to be done outside.
# Line 1659  function rsvp_function_is_expired($node, Line 1724  function rsvp_function_is_expired($node,
1724   */   */
1725  function rsvp_function_is_replypermitted($rsvp) {  function rsvp_function_is_replypermitted($rsvp) {
1726    
   $connector = new RsvpConnector();  
   
1727    $now = time();    $now = time();
1728    
1729    if (($now >= $rsvp->reply_startdate) &&    if (_rsvp_function_checkbit($rsvp->option_enabled, RSVP_OPTION_REPLY_STARTDATE_ENABLED) == RSVP_OPTION_YES) {
1730        ($now <= $rsvp->reply_enddate))      if ($now < $rsvp->reply_startdate) {
1731      return true;        return false;
1732        }
1733    return false;    }
1734    
1735      if (_rsvp_function_checkbit($rsvp->option_enabled, RSVP_OPTION_REPLY_ENDDATE_ENABLED) == RSVP_OPTION_YES) {
1736          if ($now > $rsvp->reply_enddate) {
1737            return false;
1738        }
1739      }
1740    
1741      return true;
1742  }  }
1743    
   
1744  /**  /**
1745   * Verifies if a user (by role) is entitled to view an invitation or not.   * Verifies if a user (by role) is entitled to view an invitation or not.
1746   *   *
# Line 2107  function rsvp_function_create_invitation Line 2177  function rsvp_function_create_invitation
2177      return false;      return false;
2178    
2179    $allExpired = rsvp_function_is_expired($node);    $allExpired = rsvp_function_is_expired($node);
   if (variable_get('rsvp_for_expired_event', RSVP_OPTION_NO) == RSVP_OPTION_YES) {  
     $allExpired = false;  
   }  
2180    
2181    if (!is_null($addtlparam)) {    if (!is_null($addtlparam)) {
2182      $addtlperm = user_access($addtlparam);      $addtlperm = user_access($addtlparam);

Legend:
Removed from v.1.3.2.15  
changed lines
  Added in v.1.3.2.16

  ViewVC Help
Powered by ViewVC 1.1.2