Fixed some bugs in the scheduling appointment email logic.
[eq/.git] / inc / class.eq.inc.php
index 1c25d7ace95cfcfcc977fe99cdac21f5ff65a44c..850129bf5ea7f2df04d6b382ba1a6d9794f188ff 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');
          }
          
@@ -1683,6 +1683,7 @@ class eq
             $elder_name = $entry['elder_name'];
             $int_pri = $entry['pri'];
             $aaronic = $entry['aaronic'];
+            //print "int_notes: $int_notes elder_name: $elder_name aaronic: $aaronic <Br>";
             if($aaronic == 0) { 
               // Perform database save actions here
               $this->db->query("UPDATE eq_elder set " .
@@ -1886,20 +1887,24 @@ class eq
                $table_data.= "<tr bgcolor=". $this->t->get_var('tr_color') ."><td title=\"$phone\"><a href=$link>$name</a></td>";
                $table_data.= "<td align=center>$phone</td>";
                $table_data.= "<td align=center>";
-               $table_data.= '<select name=int_notes['.$i.'][pri]>';
-               foreach(range(0,6) as $num) {
-                 if($num == 0) { $num = 1; } else {$num = $num*5; }
-                 if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
-                 $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
+               if($aaronic == 0) { 
+                 $table_data.= '<select name=int_notes['.$i.'][pri]>';
+                 foreach(range(0,6) as $num) {
+                   if($num == 0) { $num = 1; } else {$num = $num*5; }
+                   if($int_pri == $num) { $selected[$num] = 'selected="selected"'; } else { $selected[$num] = ''; }
+                   $table_data.= '<option value='.$num.' '.$selected[$num].'>'.$num.'</option>';
+                 }
+                 $table_data.= '</select></td>';
                }
-               $table_data.= '</select></td>';
                $table_data.= "<td align=center>$date</td>";
-               $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
+               if($aaronic == 0) { 
+                 $table_data.= '<td><input type=text size="50" maxlength="128" name="int_notes['.$i.'][notes]" value="'.$int_notes.'">';
+               }
                $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_id]" value="'.$id.'">';
                $table_data.= '<input type=hidden name="int_notes['.$i.'][elder_name]" value="'.$name.'">';
                $table_data.= '<input type=hidden name="int_notes['.$i.'][aaronic]" value="'.$aaronic.'">';
                $table_data.= '</td>';
-               $table_data.= '</tr>';
+               $table_data.= '</tr>'."\n";
                $i++;
              } else {
                $link_data['menuaction'] = 'eq.eq.int_update';
@@ -2212,7 +2217,7 @@ class eq
          }
       }
 
-      $name_width=175; $phone_width=100; $date_width=100; $notes_width=300;
+      $name_width=190; $phone_width=100; $date_width=100; $notes_width=300;
       $completed_table_width=$name_width + $phone_width + $date_width + $notes_width;
       $completed_header_row = "<th width=$name_width><font size=-2>Family Name</th>";
       $completed_header_row.= "<th width=$phone_width><font size=-2>Phone</th>";      
@@ -3519,40 +3524,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'));
+                      }
+                    }
                   }
               }
           }