func UpdateIgnoreSent(entity *models.Ignore_List, db gorp.SqlExecutor) bool {
	entity.Sent = true
	entity.Last_modified_date = time.Now().String()
	_, err := db.Update(entity)
	checkErr(err, "ERROR UpdateWarningSent ERROR")
	return err == nil
}
// opens the template, parse the variables sets the email struct and Send the confirmation code to confirm the ignored contact.
func SendEmailIgnoreme(entity *models.Ignore_List, db gorp.SqlExecutor) {
	//reads the e-mail template from a local file
	wab_email_template := wab_root + "/resource/ignoreme.html"
	template_byte, err := ioutil.ReadFile(wab_email_template)
	checkErr(err, "Ignore-me Email File Opening ERROR")
	template_email_string := string(template_byte[:])

	email_content := sendIgnoreMeSetup(template_email_string, entity, db)

	email := &models.Email{
		TemplatePath: wab_email_template,
		Content:      email_content,
		Subject:      messages.GetLocaleMessage(entity.Lang_key, "MSG_EMAIL_SUBJECT_ADD_IGNORE_LIST"),
		ToAddress:    entity.Contact,
		FromName:     models.WARN_A_BRODA,
		LangKey:      entity.Lang_key,
		Async:        false,
		UseContent:   true,
		HTMLContent:  true,
	}

	sent, response := SendMail(email)
	if sent {
		entity.Message = response
		UpdateIgnoreList(entity, db)
	}
}
// send a SMS with the confirmation code to confirm the ignored contact
func sendSMSIgnoreme(entity *models.Ignore_List, db gorp.SqlExecutor) {

	sms := &models.SMS{
		CredencialKey: os.Getenv("WARNACREDENCIAL"),
		Content:       strings.Replace(messages.GetLocaleMessage(entity.Lang_key, "MSG_SMS_IGNORE_CONFIRMATION_REQUEST"), "{{url}}", models.URL_IGNORE_REQUEST, 1) + entity.Confirmation_code,
		URLPath:       models.URL_MAIN_MOBILE_PRONTO,
		Scheme:        "http",
		Host:          models.URL_DOMAIN_MOBILE_PRONTO,
		Project:       os.Getenv("WARNAPROJECT"),
		AuxUser:       "******",
		MobileNumber:  strings.Replace(entity.Contact, "+", "", 1),
		SendProject:   "N",
	}

	sent, response := SendSMS(sms)

	if sent {
		entity.Message = response
		UpdateIgnoreList(entity, db)
	}
}
// Add the request to be ignored for future warnings, it requires further confimation
func AddIgnoreList(entity models.Ignore_List, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {

	if isInvalidIgnoreList(&entity) {
		return http.StatusBadRequest, Must(enc.EncodeOne(entity))
	}

	status := &models.DefaultStruct{
		Id:       http.StatusOK,
		Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_CONFIRM_IGNOREME"),
		Lang_key: entity.Lang_key,
		Type:     models.MSG_TYPE_IGNORE,
	}

	if MoreThanTwoRequestByIp(db, &entity) {
		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_TOO_MANY_IGNOREME_REQUESTS"),
			Lang_key: entity.Lang_key,
			Type:     models.MSG_TYPE_IGNORE,
		}
		return http.StatusUnauthorized, Must(enc.EncodeOne(status))
	}

	ingnored := InIgnoreList(db, entity.Contact)

	if ingnored != nil && ingnored.Confirmed {

		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_CONTACT_ALREADY_IGNORED"),
			Lang_key: entity.Lang_key,
		}

		return http.StatusUnauthorized, Must(enc.EncodeOne(status))

	} else if ingnored != nil {
		status = &models.DefaultStruct{
			Id:       http.StatusBadRequest,
			Name:     messages.GetLocaleMessage(entity.Lang_key, "MSG_IGNORE_REQUEST_EXISTS"),
			Lang_key: entity.Lang_key,
		}

		return http.StatusUnauthorized, Must(enc.EncodeOne(status))
	}

	rand.Seed(time.Now().UTC().UnixNano())
	entity.Created_by = "user"
	entity.Confirmed = false
	entity.Confirmation_code = randomString(6)

	errIns := db.Insert(&entity)
	checkErr(errIns, "INSERT IGNORE FAIL")

	if strings.Contains(entity.Contact, "@") {
		status.Name += " via e-mail."
		go SendEmailIgnoreme(&entity, db)
	} else if strings.Contains(entity.Contact, "+55") {
		status.Name += " via SMS."
		go sendSMSIgnoreme(&entity, db)
	}

	//w.Header().Set("Location", fmt.Sprintf("/warnabroda/ignore-list/%d", entity.Id))
	return http.StatusCreated, Must(enc.EncodeOne(status))
}