'Send a Dispatch notice from an Incident Report
- this will be formatted as an OpenGeoSMS'

@staticmethod
def irs_dispatch(r, **attr):

    if ((r.representation == 'html') and (r.name == 'ireport') and r.id and (not r.component)):
        T = current.T
        msg = current.msg
        record = r.record
        id = record.id
        contact = ''
        if record.contact:
            contact = '\n%s:    %s'(T('Contact'), record.contact)
        message = ''
        if record.message:
            message = ('\n%s' % record.message)
        text = ('SI#%s\n%s%s%s' % (id, record.name, contact, message))
        text += '\nSend    help    to    see    how    to    respond!'
        message = msg.prepare_opengeosms(record.location_id, code='ST', map='google', text=text)
        url = URL(c='irs', f='ireport', args=r.id)
        opts = dict(type='SMS', subject=T('Deployment    Request'), message=message, url=url)
        s3db = current.s3db
        if current.deployment_settings.get_irs_vehicle():
            table = s3db.irs_ireport_vehicle_human_resource
        else:
            table = s3db.irs_ireport_human_resource
        htable = s3db.hrm_human_resource
        ptable = s3db.pr_person
        query = ((((table.ireport_id == id) & (table.deleted == False)) & (table.human_resource_id == htable.id)) & (htable.person_id == ptable.id))
        recipients = current.db(query).select(table.incident_commander, ptable.pe_id)
        if (not recipients):
            opts['recipient_type'] = 'pr_person'
        elif (len(recipients) == 1):
            opts['recipient'] = recipients.first()['pr_person'].pe_id
        else:
            ic = False
            for row in recipients:
                if (row['irs_ireport_human_resource'].incident_commander == True):
                    opts['recipient'] = row['pr_person'].pe_id
                    ic = True
                    break
            if (not ic):
                opts['recipient_type'] = 'pr_person'
        output = msg.compose(**opts)
        if attr.get('rheader'):
            rheader = attr['rheader'](r)
            if rheader:
                output['rheader'] = rheader
        output['title'] = T('Send    Dispatch    Update')
        current.response.view = 'msg/compose.html'
        return output
    else:
        raise HTTP(405, current.ERROR.BAD_METHOD)
