public function clearDebtors()
 {
     // exclusion
     if ($recovery = Model_Debt_Recovery::find_by_id($this->DebtRecoveryId)) {
         foreach (Model_Debt_Recovery_Run::find_all_by_debt_recovery_id($recovery->id) as $run) {
             // find message count
             if (Model_Message_Log::count(array('conditions' => array('debt_recovery_id = ?', $run->id)) == 0)) {
                 $run->delete();
             }
         }
     }
     $this->Debtors = array();
     return $this;
 }
" target="_blank"><?php 
            echo $debt->file();
            ?>
</a>
                      <?php 
        } else {
            ?>
                      <?php 
            echo $debt->file();
            ?>
                      <?php 
        }
        ?>
                  </td>
                  <td><?php 
        echo Model_Debt_Recovery_Run::count(array('conditions' => array('debt_recovery_id = ?', $debt->id)));
        ?>
</td>   
                  
                  <td nowrap align="center">
                      <?php 
        $sms_onclick = 'window.open("admin-debt-recovery-message-template-popup.php?message_id=' . $debt->sms_template_id . '", "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=200, left=200, width=800, height=600");';
        ?>
                      <a href="#" onclick='<?php 
        echo $sms_onclick;
        ?>
'>SMS</a> | 
                      <?php 
        $email_onclick = 'window.open("admin-debt-recovery-message-template-popup.php?message_id=' . $debt->email_template_id . '", "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=200, left=200, width=800, height=600");';
        ?>
                      <a href="#" onclick='<?php 
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

  </head>
  <body>

    <div class="container">

      <b>Tracetec Debt Recovery - Debtors</b>

      <p>Display a list of all your debtors for the specified month.</p>

      <p>&nbsp;</p>
      
      <?php 
$debtors = Model_Debt_Recovery_Run::all(array('conditions' => array('debt_recovery_id = ?', $debt_recovery->id)));
if (!empty($debtors)) {
    ?>
      
      <br>
      
      <p>
          <?php 
    if ($debt_recovery->email_sent == 0) {
        ?>
          <a href="?debt_recovery_id=<?php 
        echo $debt_recovery->id;
        ?>
&option=send-email-to-all" onclick="return confirm('You are about to send debt notification emails to all the debtors listed below. Are you sure?');">Send Email Notifications</a> &nbsp; 
          <?php 
    } else {
if ($debt_id > 0) {
    switch ($message_type) {
        case 'sms':
            $messages = Model_Message_Log::find_all_by_debt_recovery_id_and_module_name($debt_id, array('higate'));
            break;
        case 'email':
            $messages = Model_Message_Log::find_all_by_debt_recovery_id_and_module_name($debt_id, array('phpmailer'));
            break;
        default:
            $messages = Model_Message_Log::find_all_by_debt_recovery_id($debt_id);
            break;
    }
} else {
    $recovery_id = isset($_REQUEST['debt_recovery_id']) ? trim(strtolower($_REQUEST['debt_recovery_id'])) : 0;
    if ($recovery_id > 0) {
        $ids = Model_Debt_Recovery_Run::find_all_by_debt_recovery_id($recovery_id);
        switch ($message_type) {
            case 'sms':
                $messages = Model_Message_Log::all(array('conditions' => array('debt_recovery_id in (?) and module_name in (?) ', ActiveRecord\collect($ids, 'id'), array('higate'))));
                break;
            case 'email':
                $messages = Model_Message_Log::all(array('conditions' => array('debt_recovery_id in (?) and module_name in (?) ', ActiveRecord\collect($ids, 'id'), array('phpmailer'))));
                break;
            default:
                $messages = Model_Message_Log::all(array('order' => 'created_at desc', 'limit' => 100, 'offset' => 0, 'conditions' => array('debt_recovery_id in (?) ', ActiveRecord\collect($ids, 'id'))));
                break;
        }
    } else {
        $messages = Model_Message_Log::all(array('order' => 'created_at desc', 'limit' => 100, 'offset' => 0));
    }
}