Fixed import bug that existed when Aaronic Priesthood Companion was not found in db
[eq/.git] / inc / class.eq.inc.php
index 3478b4c36014dcbbaeda88919dc97a9909b0c352..aab3ffd61d40b3792059fcc712c4cdb8d8e1d6e7 100644 (file)
@@ -23,6 +23,8 @@ class eq
   var $default_ppi_num_months;
   var $default_ppi_num_years;
   var $default_att_num_months;
+  var $current_year;
+  var $current_month;
   
   var $public_functions = array
     (
@@ -64,6 +66,12 @@ class eq
        
       $GLOBALS['phpgw_info']['flags']['app_header'] = 'Elders Quorum Tools';
       $GLOBALS['phpgw']->common->phpgw_header();
+      
+      $this->current_month = `date '+%m'`;
+      $this->current_month = $this->current_month-0; // Make it numeric
+      $this->current_year = `date '+%Y'`;
+      $this->current_year = $this->current_year-0; // Make it numeric
+
       echo parse_navbar();
       $this->display_app_header();     
     }
@@ -128,7 +136,7 @@ class eq
       
       $this->t->set_var('actionurl',$GLOBALS['phpgw']->link('/eq/index.php','menuaction=eq.eq.ht_view'));
       $this->t->set_var('title','Hometeaching'); 
-
+      
       $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
       $this->db->query($sql,__LINE__,__FILE__);
       $i=0;
@@ -216,6 +224,7 @@ class eq
          
          // Get the names of the families assigned this home teaching companionship
          $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
+         $sql = $sql . " ORDER BY name ASC";
          $this->db->query($sql,__LINE__,__FILE__);
          $k=0;
          while ($this->db->next_record())
@@ -229,10 +238,14 @@ class eq
              // in the past $num_months for this Family
              $header_row="<th width=$comp_width><font size=-2>Families</th>";
              for($m=$num_months; $m >= 0; $m--) {
-               if(`date '+%d'` == 31) { $d = 1; } else { $d = 0; }
-               $month = date('m/Y', strtotime('-'.$m.' month -'.$d.' day'));
-               $month_start = date('Y-m', strtotime('-'.$m.' month -'.$d.' day')); $month_start .= "-01";
-               $month_end = date('Y-m', strtotime('-'.$m.' month -'.$d.' day')); $month_end .= "-31";
+               $month = $this->current_month - $m;
+               $year = $this->current_year;
+               if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
+               if($month < 10) { $month = "0"."$month"; }
+               $month_start = "$year"."-"."$month"."-"."01";
+               $month_end = "$year"."-"."$month"."-"."31";
+               $month = "$month"."/"."$year";
+               //print "m: $m month: $month year: $year month_start: $month_start month_end: $month_end<br>";
                // Add this to the query to filter on only visits made by this companionship:
                // " AND companionship=" . $unique_companionships[$j]['companionship'].
                $sql = "SELECT * FROM eq_visit WHERE date >= '$month_start' AND date <= '$month_end' ".
@@ -441,6 +454,7 @@ class eq
        
        // Get the names of the families assigned this home teaching companionship
        $sql = "SELECT * from eq_family where valid=1 AND companionship=".$unique_companionships[$j]['companionship'];
+       $sql = $sql . " ORDER BY name ASC";
        $this->db->query($sql,__LINE__,__FILE__);
        while ($this->db->next_record())
          {
@@ -861,10 +875,16 @@ class eq
       $i=0;
       while ($this->db->next_record())
        {
-         $districts[$i]['district'] = $this->db->f('district');
-         $districts[$i]['name'] = $this->db->f('name');
-         $districts[$i]['supervisor'] = $this->db->f('supervisor');
-         if($eqpresppi == 0) { $i++; }
+         if($eqpresppi == 1 && $this->db->f('district') == 1) {
+           $districts[$i]['district'] = $this->db->f('district');
+           $districts[$i]['name'] = $this->db->f('name');
+           $districts[$i]['supervisor'] = $this->db->f('supervisor');
+          } else if($eqpresppi == 0) {
+            $districts[$i]['district'] = $this->db->f('district');
+           $districts[$i]['name'] = $this->db->f('name');
+            $districts[$i]['supervisor'] = $this->db->f('supervisor');
+            $i++;
+         }
        }
 
       $sql = "SELECT * FROM eq_elder where valid=1 ORDER BY elder ASC";
@@ -976,10 +996,13 @@ class eq
                  $header_row .= "<th width=150><font size=-2>$year</th>"; 
                }
                else {
-                 if(`date '+%d'` == 31) { $d = 1; } else { $d = 0; }
-                 $month = date('m/Y', strtotime('-'.$m.' month -'.$d.' day'));
-                 $month_start = date('Y-m', strtotime('-'.$m.' month -'.$d.' day')); $month_start .= "-01";
-                 $month_end = date('Y-m', strtotime('-'.$m.' month -'.$d.' day')); $month_end .= "-31";
+                 $month = $this->current_month - $m;
+                 $year = $this->current_year;
+                 if($month <= 0) { $remainder = $month; $month = 12 + $remainder; $year=$year-1; }
+                 if($month < 10) { $month = "0"."$month"; }
+                 $month_start = "$year"."-"."$month"."-"."01";
+                 $month_end = "$year"."-"."$month"."-"."31";
+                 $month = "$month"."/"."$year";
                  $sql = "SELECT * FROM eq_ppi WHERE date >= '$month_start' AND date <= '$month_end' ".
                         "AND elder=" . $elder_id . " AND aaronic=" . $aaronic_id . " AND eqpresppi=0";
                  $this->db2->query($sql,__LINE__,__FILE__);