Revision: 1298
          http://mrbs.svn.sourceforge.net/mrbs/?rev=1298&view=rev
Author:   cimorrison
Date:     2010-02-17 20:59:15 +0000 (Wed, 17 Feb 2010)

Log Message:
-----------
Replaced magic numbers used for values of rep_type with constants.

Modified Paths:
--------------
    mrbs/trunk/web/edit_entry.php
    mrbs/trunk/web/edit_entry_handler.php
    mrbs/trunk/web/functions_mail.inc
    mrbs/trunk/web/mrbs_sql.inc
    mrbs/trunk/web/systemdefaults.inc.php
    mrbs/trunk/web/view_entry.php

Modified: mrbs/trunk/web/edit_entry.php
===================================================================
--- mrbs/trunk/web/edit_entry.php       2010-02-17 17:40:29 UTC (rev 1297)
+++ mrbs/trunk/web/edit_entry.php       2010-02-17 20:59:15 UTC (rev 1298)
@@ -147,7 +147,7 @@
    
     $rep_type = $row['rep_type'];
 
-    if (!empty($rep_type))
+    if (isset($rep_type) && ($rep_type != REP_NONE))
     {
       $start_day   = (int)strftime('%d', $row['start_time']);
       $start_month = (int)strftime('%m', $row['start_time']);
@@ -176,7 +176,7 @@
           // when the input is disabled
           $rep_opt = $row['rep_opt'];
 
-          if ($rep_type == 6)
+          if ($rep_type == REP_N_WEEKLY)
           {
             $rep_num_weeks = $row['rep_num_weeks'];
           }
@@ -212,7 +212,7 @@
   unset($id);
 
   $rep_id        = 0;
-  $rep_type      = 0;
+  $rep_type      = REP_NONE;
   $rep_end_day   = $day;
   $rep_end_month = $month;
   $rep_end_year  = $year;
@@ -311,8 +311,8 @@
   }
   if ((!i1 || (i1 && i2)) &&
       form.rep_type &&
-      (form.rep_type.value != 0) && 
-      form.rep_type[6].checked && 
+      (form.rep_type.value != <?php echo REP_NONE ?>) && 
+      form.rep_type[<?php echo REP_N_WEEKLY ?>].checked && 
       (!n || n < 2))
   {
     alert("<?php echo get_vocab("you_have_not_entered") . '\n' . 
get_vocab("useful_n-weekly_value") ?>");
@@ -793,18 +793,18 @@
       // But we have to cater for the possibility because it could happen if 
(a) the
       // series was created before the policy was introduced or (b) the user 
has
       // been demoted since the series was created).
-      $key = "rep_type_" . (isset($rep_type) ? $rep_type : "0");
+      $key = "rep_type_" . (isset($rep_type) ? $rep_type : REP_NONE);
       echo "<fieldset id=\"rep_info\">\n";
       echo "<legend></legend>\n";
       echo "<div>\n";
       echo "<label>" . get_vocab("rep_type") . ":</label>\n";
       echo "<input type=\"text\" value =\"" . get_vocab($key) . "\" 
disabled=\"disabled\">\n";
-      echo "<input type=\"hidden\" name=\"rep_type\" value=\"0\">\n";
+      echo "<input type=\"hidden\" name=\"rep_type\" value=\"" . REP_NONE . 
"\">\n";
       echo "</div>\n";
-      if (isset($rep_type) && ($rep_type != 0))
+      if (isset($rep_type) && ($rep_type != REP_NONE))
       {
         $opt = "";
-        if (($rep_type == 2) || ($rep_type == 6))
+        if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
         {
           // Display day names according to language and preferred weekday 
start.
           for ($i = 0; $i < 7; $i++)
@@ -821,7 +821,7 @@
           echo "  <div><label>".get_vocab("rep_rep_day").":</label><input 
type=\"text\" value=\"$opt\" disabled=\"disabled\"></div>\n";
         }
         echo "  <div><label>".get_vocab("rep_end_date").":</label><input 
type=\"text\" value=\"$rep_end_date\" disabled=\"disabled\"></div>\n";
-        if ($rep_type == 6)
+        if ($rep_type == REP_N_WEEKLY)
         {
           echo "<div>\n";
           echo "<label for=\"rep_num_weeks\">" . get_vocab("rep_num_weeks") . 
":<br>" . get_vocab("rep_for_nweekly") . "</label>\n";

Modified: mrbs/trunk/web/edit_entry_handler.php
===================================================================
--- mrbs/trunk/web/edit_entry_handler.php       2010-02-17 17:40:29 UTC (rev 
1297)
+++ mrbs/trunk/web/edit_entry_handler.php       2010-02-17 20:59:15 UTC (rev 
1298)
@@ -157,7 +157,7 @@
 // is allowed to make/edit repeat bookings.   (The edit_entry form should
 // prevent you ever getting here, but this check is here as a safeguard in 
 // case someone has spoofed the HTML)
-if (!empty($rep_type) &&
+if (isset($rep_type) && ($rep_type != REP_NONE) &&
     !$is_admin &&
     !empty($auth['only_admin_can_book_repeat']))
 {
@@ -212,7 +212,7 @@
 }       
 
 
-if (($rep_type == 6) && ($rep_num_weeks < 2))
+if (($rep_type == REP_N_WEEKLY) && ($rep_num_weeks < 2))
 {
   print_header($day, $month, $year, $area, isset($room) ? $room : "");
 ?>
@@ -307,7 +307,7 @@
   $endtime += cross_dst( $starttime, $endtime );
 }
 
-if (isset($rep_type) && ($rep_type > 0) &&
+if (isset($rep_type) && ($rep_type != REP_NONE) &&
     isset($rep_end_month) && isset($rep_end_day) && isset($rep_end_year))
 {
   // Get the repeat entry settings
@@ -316,7 +316,7 @@
 }
 else
 {
-  $rep_type = 0;
+  $rep_type = REP_NONE;
   $rep_enddate = 0;  // to avoid an undefined variable notice
 }
 
@@ -328,7 +328,7 @@
 // If there's a weekly or n-weekly repeat and no repeat day has
 // been set, then set a default repeat day as the day of
 // the week of the start of the period
-if (isset($rep_type) && (($rep_type == 2) || ($rep_type == 6)))
+if (isset($rep_type) && (($rep_type == REP_WEEKLY) || ($rep_type == 
REP_N_WEEKLY)))
 {
   if (count($rep_day) == 0)
   {
@@ -337,9 +337,9 @@
   }
 }
 
-// For weekly repeat(2), build string of weekdays to repeat on:
+// For weekly and n-weekly repeats, build string of weekdays to repeat on:
 $rep_opt = "";
-if (($rep_type == 2) || ($rep_type == 6))
+if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
 {
   for ($i = 0; $i < 7; $i++)
   {
@@ -348,7 +348,7 @@
 }
 
 // Expand a series into a list of start times:
-if ($rep_type != 0)
+if ($rep_type != REP_NONE)
 {
   $reps = mrbsGetRepeatEntryList($starttime,
                                  isset($rep_enddate) ? $rep_enddate : 0,
@@ -387,7 +387,7 @@
 // book in;  also check that the booking conforms to the policy
 foreach ( $rooms as $room_id )
 {
-  if ($rep_type != 0 && !empty($reps))
+  if ($rep_type != REP_NONE && !empty($reps))
   {
     if(count($reps) < $max_rep_entrys)
     {

Modified: mrbs/trunk/web/functions_mail.inc
===================================================================
--- mrbs/trunk/web/functions_mail.inc   2010-02-17 17:40:29 UTC (rev 1297)
+++ mrbs/trunk/web/functions_mail.inc   2010-02-17 20:59:15 UTC (rev 1298)
@@ -249,7 +249,7 @@
     $recipients[] = get_approvers_email($room_id);
   }
   
-  $id_table = ($rep_type > 0) ? "rep" : "e";
+  $id_table = ($rep_type != REP_NONE) ? "rep" : "e";
   ($mail_settings['admin_on_bookings']) ? $recipients[] = 
$mail_settings['recipients'] : '';
   if ($mail_settings['area_admin_on_bookings'])
   {
@@ -501,10 +501,10 @@
     }
         
     // Details if a series
-    if ($rep_type > 0)
+    if ($rep_type != REP_NONE)
     {
       $opt = "";
-      if (($rep_type == 2) || ($rep_type == 6))
+      if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
       {
         // Display day names according to language and preferred weekday start.
         for ($i = 0; $i < 7; $i++)
@@ -516,7 +516,7 @@
           }
         }
       }
-      if ($rep_type == 6)
+      if ($rep_type == REP_N_WEEKLY)
       {
         $body .= "\n" . get_mail_vocab("rep_num_weeks");
         $body .=  ": " . compareEntries($rep_num_weeks,
@@ -690,9 +690,9 @@
   $body .= "\n" . get_mail_vocab("rep_type");
   $temp = $mail_previous['rep_type'];
   $body .=  ": " . get_mail_vocab("rep_type_$temp");
-  if ($mail_previous['rep_type'] > 0)
+  if ($mail_previous['rep_type'] != REP_NONE)
   {
-    if ($mail_previous['rep_type'] == 6)
+    if ($mail_previous['rep_type'] == REP_N_WEEKLY)
     {
       $body .= "\n" . get_mail_vocab("rep_num_weeks");
       $body .=  ": " . $mail_previous["rep_num_weeks"];
@@ -853,7 +853,7 @@
   // a series, we still need to set rep_type to show that it's not a series)
   if (1 != $series)
   {
-    $mail_previous['rep_type'] = 0;
+    $mail_previous['rep_type'] = REP_NONE;
   }
   else
   {
@@ -885,7 +885,7 @@
         $mail_previous['rep_opt'] .= day_name($wday) . " ";
     }
     
-    if ($row['rep_type'] == 6)
+    if ($row['rep_type'] == REP_N_WEEKLY)
     {
       $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
     }

Modified: mrbs/trunk/web/mrbs_sql.inc
===================================================================
--- mrbs/trunk/web/mrbs_sql.inc 2010-02-17 17:40:29 UTC (rev 1297)
+++ mrbs/trunk/web/mrbs_sql.inc 2010-02-17 20:59:15 UTC (rev 1298)
@@ -426,15 +426,13 @@
 
     switch($rep_type)
     {
-      // Daily repeat
-      case 1:
+      case REP_DAILY:
         $day += 1;
         break;
       
-      // Weekly (2) and n-Weekly (6) repeats
-      case 2:
+      case REP_WEEKLY:
         $rep_num_weeks = 1;
-      case 6:
+      case REP_N_WEEKLY:
         $j = $cur_day = date("w", $entrys[$i]);
         // Skip over days of the week which are not enabled:
         while (($j = ($j + 1) % 7) != $cur_day && !$rep_opt[$j])
@@ -445,10 +443,9 @@
         $day += 1 + (7 * ($rep_num_weeks - 1));
         break;
       
-      // Monthly (3) and Yearly (4) repeats
-      case 3:
-      case 4:
-        if ($rep_type == 3)
+      case REP_MONTHLY:
+      case REP_YEARLY:
+        if ($rep_type == REP_MONTHLY)
         {
           $month += 1;
         }
@@ -479,8 +476,7 @@
         }
         break;
    
-      // Monthly repeat on same week number and day of week
-      case 5:
+      case REP_MONTHLY_SAMEDAY:
         $day += same_day_next_month($time);
         break;
 
@@ -495,7 +491,7 @@
   // start of the period is not one of the repeat days.  (We are
   // allowed to assume that at least one repeat day is set in this
   // function)
-  if (($rep_type == 2) || ($rep_type == 6))
+  if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
   {
     if (!$rep_opt[$start_day])
     {
@@ -779,7 +775,7 @@
     // Get the repeat information
     if (empty($row['repeat_id']))
     {
-      $row['rep_type'] = 0;   // just as a precaution
+      $row['rep_type'] = REP_NONE;   // just as a precaution
     }
     else
     {

Modified: mrbs/trunk/web/systemdefaults.inc.php
===================================================================
--- mrbs/trunk/web/systemdefaults.inc.php       2010-02-17 17:40:29 UTC (rev 
1297)
+++ mrbs/trunk/web/systemdefaults.inc.php       2010-02-17 20:59:15 UTC (rev 
1298)
@@ -831,7 +831,19 @@
 
 define('STATUS_PROVISIONAL', 0);
 define('STATUS_CONFIRMED',   1);
+
+ /*************************************************
+ * REPEAT TYPE CODES - internal use, do not change
+ **************************************************/
  
+define('REP_NONE',            0);
+define('REP_DAILY',           1);
+define('REP_WEEKLY',          2);
+define('REP_MONTHLY',         3);
+define('REP_YEARLY',          4);
+define('REP_MONTHLY_SAMEDAY', 5);
+define('REP_N_WEEKLY',        6);
+ 
 /********************************************************
  * PHP System Configuration - internal use, do not change
  ********************************************************/

Modified: mrbs/trunk/web/view_entry.php
===================================================================
--- mrbs/trunk/web/view_entry.php       2010-02-17 17:40:29 UTC (rev 1297)
+++ mrbs/trunk/web/view_entry.php       2010-02-17 20:59:15 UTC (rev 1298)
@@ -211,7 +211,7 @@
 }
 
 
-$rep_type = 0;
+$rep_type = REP_NONE;
 
 if ($series == 1)
 {
@@ -421,10 +421,10 @@
   </tr>
 <?php
 
-if($rep_type != 0)
+if($rep_type != REP_NONE)
 {
   $opt = "";
-  if (($rep_type == 2) || ($rep_type == 6))
+  if (($rep_type == REP_WEEKLY) || ($rep_type == REP_N_WEEKLY))
   {
     // Display day names according to language and preferred weekday start.
     for ($i = 0; $i < 7; $i++)
@@ -436,7 +436,7 @@
       }
     }
   }
-  if ($rep_type == 6)
+  if ($rep_type == REP_N_WEEKLY)
   {
     echo "<tr><td>".get_vocab("rep_num_weeks")." 
".get_vocab("rep_for_nweekly").":</td><td>$rep_num_weeks</td></tr>\n";
   }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to