Report a comment/review for inappropriate content.

    Will send an email to the administrator if number of reports is a multiple
    of CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN

    :param cmt_id: comment id
    :return: integer 1 if successful, integer 0 if not. -2 if comment does not exist

def perform_request_report(cmt_id, client_ip_address, uid=-1):
    """
    Report a comment/review for inappropriate content.

    Will send an email to the administrator if number of reports is a multiple
    of CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN

    :param cmt_id: comment id
    :return: integer 1 if successful, integer 0 if not. -2 if comment does not exist
    """
    cmt_id = wash_url_argument(cmt_id, 'int')
    if cmt_id <= 0:
        return 0
    (query_res, nb_abuse_reports) = query_record_report_this(cmt_id)
    if query_res == 0:
        return 0
    elif query_res == -2:
        return -2
    if not(check_user_can_report(cmt_id, client_ip_address, uid)):
        return 0
    action_date = convert_datestruct_to_datetext(time.localtime())
    action_code = CFG_WEBCOMMENT_ACTION_CODE['REPORT_ABUSE']
    query = """INSERT INTO "cmtACTIONHISTORY" ("id_cmtRECORDCOMMENT", id_bibrec,
                  id_user, client_host, action_time, action_code)
               VALUES (%s, NULL, %s, inet_aton(%s), %s, %s)"""
    params = (cmt_id, uid, client_ip_address, action_date, action_code)
    run_sql(query, params)
    if nb_abuse_reports % CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN == 0:
        (cmt_id2,
         id_bibrec,
         id_user,
         cmt_body,
         cmt_date,
         cmt_star,
         cmt_vote, cmt_nb_votes_total,
         cmt_title,
         cmt_reported,
         round_name,
         restriction) = query_get_comment(cmt_id)
        (user_nb_abuse_reports,
         user_votes,
         user_nb_votes_total) = query_get_user_reports_and_votes(int(id_user))
        (nickname,
         user_email,
         last_login) = query_get_user_contact_info(id_user)
        from_addr = '%s Alert Engine <%s>' % (
            CFG_SITE_NAME, CFG_WEBALERT_ALERT_ENGINE_EMAIL)
        comment_collection = get_comment_collection(cmt_id)
        to_addrs = get_collection_moderators(comment_collection)
        subject = "A comment has been reported as inappropriate by a user"
        body = '''
The following comment has been reported a total of %(cmt_reported)s times.

Author:     nickname    = %(nickname)s
            email       = %(user_email)s
            user_id     = %(uid)s
            This user has:
                total number of reports         = %(user_nb_abuse_reports)s
                %(votes)s
Comment:    comment_id      = %(cmt_id)s
            record_id       = %(id_bibrec)s
            date written    = %(cmt_date)s
            nb reports      = %(cmt_reported)s
            %(review_stuff)s
            body            =
---start body---
%(cmt_body)s
---end body---

Please go to the record page %(comment_admin_link)s to delete this message if necessary. A warning will be sent to the user in question.''' % \
            {'cfg-report_max': CFG_WEBCOMMENT_NB_REPORTS_BEFORE_SEND_EMAIL_TO_ADMIN,
             'nickname': nickname,
             'user_email': user_email,
             'uid': id_user,
             'user_nb_abuse_reports': user_nb_abuse_reports,
             'user_votes': user_votes,
             'votes': CFG_WEBCOMMENT_ALLOW_REVIEWS and
             "total number of positive votes\t= %s\n\t\ttotal number of negative votes\t= %s" %
             (user_votes,
              (user_nb_votes_total - user_votes)) or "\n",
                'cmt_id': cmt_id,
                'id_bibrec': id_bibrec,
                'cmt_date': cmt_date,
             'cmt_reported': cmt_reported,
             'review_stuff': CFG_WEBCOMMENT_ALLOW_REVIEWS and
             "star score\t= %s\n\treview title\t= %s" % (
                 cmt_star,
                 cmt_title) or "",
                'cmt_body': cmt_body,
             'comment_admin_link': CFG_SITE_URL + "/" + CFG_SITE_RECORD + "/" + str(id_bibrec) + '/comments#' + str(cmt_id),
             'user_admin_link': "user_admin_link"  # ! FIXME
             }

        # FIXME to be added to email when websession module is over:
        # If you wish to ban the user, you can do so via the User Admin Panel
        # %(user_admin_link)s.

        send_email(from_addr, to_addrs, subject, body)
    return 1