def send_sms():
    title = u'Send SMS'
    if request.method == "POST":
        leaderno = request.form.getlist('leaderno')
        body = request.form.get('msg')
        if body:
            msgs = []
            if 'all' in leaderno:
                for i in LEADER_SMS.values():
                    msgs.append({'to': i, 'body': body})
                    flash(u'{0} {1}'.format(i, body))

                sqs.add(QUEUE_NAME_SMSLEADER, msgs)
            else:
                if leaderno:
                    for i in leaderno:
                        msgs.append({'to': LEADER_SMS[i], 'body': body})
                        flash(u'{0} {1}'.format(LEADER_SMS[i], body))

                    sqs.add(QUEUE_NAME_SMSLEADER, msgs)
                else:
                    flash(u'沒有選擇組別!')
        else:
            flash(u'沒有內容!')

        return redirect(url_for('send_sms'))
    else:
        return make_response(render_template('t_sendsms.htm', title=title,
                                             send_sms=1))
def send_sms_coll():
    title = u'Send SMS by Coll'
    if request.method == "POST":
        cno = request.form.getlist('cno')
        body = request.form.get('msg')
        cno = STAFF_SMS if 'all' in cno else cno

        if body:
            for i in cno:
                msgs = []
                for u in STAFF_SMS[i]:
                    msgs.append({'to': u['phone'], 'body': body})
                    flash(u'{0} {1}'.format(u['phone'], body))

                sqs.add(QUEUE_NAME_SMSLEADER, msgs)
        else:
            flash(u'沒有內容!')

        return redirect(url_for('send_sms_coll'))
    else:
        coll = []
        for i in STAFF_SMS:
            coll.append({'CNO': i,
                         'CNO_NAME': STAFF_CNO[i], })

        return make_response(render_template('t_sendsmscoll.htm', coll=coll,
                                             title=title, send_sms_coll=1))
def awssqs():
    title = u'AWS SQS'
    if request.method == "POST":
        f = request.files.get('file')
        if f and allowed_file(f.filename):
            sendby = request.form.get('sendby')
            if sendby:
                sqs.add(sendby, read_csv(f))
                flash(u'丟到 AWS SQS {0}'.format(sendby))
            else:
                flash(u'錯誤選擇!')

        return redirect(url_for('awssqs'))
    else:
        return make_response(render_template('t_awssqs.htm', title=title,
                                             qlist=QUEUE_NAME_LIST, awssqs=1))
def send_all_first():
    title = u'Send All People First'
    if request.method == "POST":
        f = request.files.get('file')
        if f and allowed_file(f.filename):
            if request.form.get('sendby') == 'sqs':
                sqs.add(QUEUE_NAME_SENDFIRST, read_csv(f))
                flash(u'丟到 AWS SQS')

            elif request.form.get('sendby') == 'mail':
                #t.template = t.env.get_template('./coscup_first.htm')
                #t.sendall(read_csv(f), t.send_first)
                flash(u'寄送大量登錄信')

            else:
                flash(u'錯誤選擇!')

        return redirect(url_for('send_all_first'))
    else:
        return make_response(render_template('t_sendallfirst.htm',
                                             title=title, send_all_first=1))