$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));
    }
}
if (count($messages) > 0) {
    ?>
<table width="100%" border="1">
    <thead>
        <tr>
            <th>Billing ID</th>
            <th>Customer</th>
            <th>Date Sent</th>
            <th>Cell Number</th>
            <th>Email</th>
            <th>Status</th>
            <th>Reference</th>
            <th>Module</th>