Fixed bug in the PPI tool where the interviewer wasn't being
[eq/.git] / inc / class.eq.inc.php
index b0a9fd016dbe352e263c79904f91fcaed6dbf817..053996cca9b912d04ecc52af336a596715ff4af7 100644 (file)
@@ -763,7 +763,7 @@ class eq
             . " AND date='".$activity['date']."' AND notes='".$activity['notes']."'";
          $this->db->query($sql,__LINE__,__FILE__);
          if($this->db->next_record()) {
-           print "activity: " . $this->db->f('activity') . "<br>";
+           //print "activity: " . $this->db->f('activity') . "<br>";
            $activity['activity'] = $this->db->f('activity');
          }
          
@@ -2407,25 +2407,14 @@ class eq
       $notes = get_var('notes',array('GET','POST'));
       $eqpresppi = get_var('eqpresppi',array('GET','POST'));
       
-      $sql = "SELECT * FROM eq_district where valid=1 ORDER BY district ASC";
-      $this->db->query($sql,__LINE__,__FILE__);
-      while ($this->db->next_record())
-       {
-         $supervisor = $this->db->f('supervisor');
-         $sql = "SELECT * FROM eq_elder WHERE elder=" . $supervisor;
-         $this->db2->query($sql,__LINE__,__FILE__);
-         $this->db2->next_record();
-         $interviewer_name = $this->db2->f('name');
-         
-         if($supervisor == $interviewer) { 
-           $this->t->set_var('interviewer',$supervisor . ' selected');
-         } else {
-           $this->t->set_var('interviewer',$interviewer);
-         }
-         $this->t->set_var('interviewer_name',$interviewer_name);
-         $this->t->fp('int_list','interviewer_list',True);
-       }
-      
+      $sql = "SELECT * FROM eq_elder WHERE elder=" . $interviewer;
+      $this->db2->query($sql,__LINE__,__FILE__);
+      $this->db2->next_record();
+      $interviewer_name = $this->db2->f('name');
+      $this->t->set_var('interviewer',$interviewer . ' selected');
+      $this->t->set_var('interviewer_name',$interviewer_name);
+      $this->t->fp('int_list','interviewer_list',True);
+    
       if($action == 'save')
        {
          $notes = get_var('notes',array('POST'));
@@ -3524,40 +3513,64 @@ class eq
                 $time = $hour.':'.$minute.':'.'00';
                 $uid = 0;
 
+                // Zero out the family or elder if date = NULL
+                if($date == "") {
+                  $elder = 0;
+                  $family = 0;
+                }
+                
                 // Update an existing appointment
                 if($appointment < $this->max_appointments)
                   {
                     //Only perform a database update if we have made a change to this appointment
                     $sql = "SELECT * FROM eq_appointment where " .
                        "appointment='$appointment'" .
-                       "and elder='$elder'" .
-                       "and family='$family'" .
-                       "and date='$date'" .
-                       "and time='$time'";
+                       " and presidency='$presidency'" .
+                       " and elder='$elder'" .
+                       " and family='$family'" .
+                       " and date='$date'" .
+                       " and time='$time'";
                     $this->db->query($sql,__LINE__,__FILE__);
                     if(!$this->db->next_record()) {
-                      $this->db->query("UPDATE eq_appointment set" .
+                      $old_date = $this->db->f('date');
+                      $old_time = $this->db->f('time');
+                      $this->db2->query("UPDATE eq_appointment set" .
                                        " family=" . $family . 
                                        " ,elder=" . $elder . 
                                        " ,date='" . $date . "'" .
                                        " ,time='" . $time . "'" .
+                                       " ,presidency='" . $presidency . "'" .
                                        " WHERE appointment=" . $appointment,__LINE__,__FILE__);
                       
                       // Email the appointment
-                      if(($date != "") && ($time != "")) { 
-                        $this->email_appt($appointment);
-                      }
+                      $this->email_appt($appointment);
                     }
                   }
                 
                 // Add a new appointment
                 else if(($appointment >= $this->max_appointments) && ($date != "") && ($time != ""))
                   {
-                    $this->db->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time,uid) "
+                    //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";
+                    $this->db2->query("INSERT INTO eq_appointment (appointment,presidency,family,elder,date,time,uid) "
                           . "VALUES (NULL,'" . $presidency . "','" . $family . "','"
                           . $elder . "','" . $date . "','" . $time  . "','" . $uid ."')",__LINE__,__FILE__);
-                    
-                    //print "adding entry: appt=$appointment date: $date time: $time elder: $elder family: $family<br>";                    
+
+                    // Now reselect this entry from the database to see if we need
+                    // to send an appointment out for it.
+                    $sql = "SELECT * FROM eq_appointment where " .
+                       "elder='$elder'" .
+                       " and family='$family'" .
+                       " and presidency='$presidency'" .
+                       " and date='$date'" .
+                       " and time='$time'" .
+                       " and uid='$uid'";
+                    $this->db3->query($sql,__LINE__,__FILE__);
+                    if($this->db3->next_record()) {
+                      // Email the appointment if warranted
+                      if(($date != "") && ($time != "") && (($elder > 0) || $family > 0)) { 
+                        $this->email_appt($this->db3->f('appointment'));
+                      }
+                    }
                   }
               }
           }