/*

--------------- PHP Config ----------------

===========================================
List of default validation rules for field:
===========================================
    -----------------------------------
    field is always mandatory
    "required" => true/false
    -----------------------------------
    value should be proper email address
    "email" => true/false
    -----------------------------------
    value should be proper url
    "url" => true/false
    -----------------------------------
    value should be integer - 2, 67, -234
    "integer" => true/false
    -----------------------------------
    value should be integer or float - 2, 67.4, -234, 0.45
    "number" => true/false
    -----------------------------------
    minimal length of the value, integer
    "minlength" => 3,
    "minlength" => 10
    -----------------------------------
    maximal length of the value, integer
    "maxlength" => 3,
    "maxlength" => 10
    -----------------------------------
    range length of the value, array with two integers
    "rangelength" => array(2, 5),
    "rangelength" => array(1, 10)
    -----------------------------------
    field value should be greater than rule value, integer/float
    "minvalue" => 5,
    "minvalue" => -10.5
    -----------------------------------
    field value should be less than rule value, integer/float
    "maxvalue" => 5,
    "maxvalue" => -10.5
    -----------------------------------
    field value should be in range of values, array with two integers/floats
    "rangevalue" => array(-1, 100),
    "rangevalue" => array(5, 10.5)
    -----------------------------------
    field value should be equal to newly received other field value
    use field names from $config["rules"] as a target
    "equalTo" => "email",
    "equalTo" => "password"
    -----------------------------------
    set a quantity of required values from the listed fields
    use field names from $config["rules"] array
    "requiredFromGroup" => array( 1, array("first_name", "last_name") ),
    "requiredFromGroup" => array( 2, array("name", "email", "select") )
    -----------------------------------

==========================================
List of default validation rules for file:
==========================================
    -----------------------------------
    file is NOT mandatory, but if user adds a file - validate it
    "validate" => true/false
    ----------------------------------
    file is ALWAYS mandatory
    "required" => true/false
    -----------------------------------
    file size, Mb
    if it is not an integer - use "."(point) as a delimiter
    "size" => 1
    "size" => 0.5
    -----------------------------------
    file extension, use "|" as a delimiter
    default abbreviation for available formats:
        jpeg|jpg|tiff|png|gif|ico|xls|xlsx|docx|doc|txt|csv|zip|gzip|rar|odf|pdf|powerpoint|mpeg|mp4|ogg
    "extension" => "jpg|jpeg|png"
    -----------------------------------

==========================================
NOTE:
List of special cases:
==========================================
    -----------------------------------
    1) $config["rules"] and $config["messages"] arrays should contain ALL field names from html code.
        Fields with names from $config["rules"] and $config["messages"] arrays only will take part 
        at php data processing (email sending, database storing, etc).
        For example:
        html code contains two fields: <input name="fname"> and <input name="lname">,
        but $config["rules"] and $config["messages"] arrays contain field "fname" only.
        In this case field "lname" will be lost and will not take part at php data processing
        ---
        In case you need a field to be a part of php processing, but you do not want to apply php validation - 
        set "false" for field in $config["rules"] and leave empty $config["messages"]
        ---
        --- WRONG - "lname" field will be lost ---
        "rules" => array(
            "fname" => array(
                "required" => true
            )
        ),
        "messages" => array(
            "fname" => array(
                "required" => "Add first name"
            )
        }
        --- CORRECT ---
        "rules" => array(
            "fname" => array(
                "required" => true
            ),
            "lname" => array(
                "required" => false
            )
        ),
        "messages" => array(
            "fname" => array(
                "required" => "Add first name"
            ),
            "lname" => array()
        }
    -----------------------------------
    2) Unlike from javascript config, php config doesn't know anything about "display:none;" / "visibility:hidden;" / 
        disabled="true" settings for a field. Therefore: field will be validated and will take part
        at php data processing if:
            - $config["rules"] and $config["messages"] contain rules/messages for this field
            - $_POST array contains this field (php code gets this field from html code)
*/


$config = array(
    /************************************************/
    /* User settings */
    /************************************************/
    /* your name or your company's name */
    "your_name" => "Your Name",

    /* your email */
    "your_email" => "your_email@domain.com",

    /* subject of the message */
    "your_subject" => "Contact Us",

    /* Validation rules for fields */
    "rules" => array(

        /* php security token */
        /* this field should always have name "token" */
        "token" => array(
            "required" => true,
            /* unique prefix for token */
            /* be sure the same prefix is used at html code for token creation - $token = new CSRF("contact"); */
            /* Note: this rule should not have an error message in "messages" array */
            "prefix" => "contact"
        ),

        /* google reCaptcha field */
        /* if your form contains google reCapthca:
            - this field should always have name "recaptcha"
            - do not forget to add html code for reCaptcha to the html form
            - do not forget to connect recaptcha API script to the html form
            - do not forget to add reCaptcha server secret key to the "constants.php" file */
        "recaptcha" => array(
            "required" => false,

            /* this rule is not required and may not be included to config array */
            /* use it and set to "true" only if default mode for google reCaptcha doesn"t work for you */
            /* Note: this rule should not have an error message in "messages" array */
            "alternative_mode" => true
        ),

        /* user field name */
        /* field name should be the same as at html "name" attribute at html form code */
        /* example - <input name="user_field_name" /> */
        /* detailed description of every rule - at the top of this file */
        "user_field_name" => array(
            "required" => true,
            "email" => true,
            "url" => true,
            "integer" => true,
            "number" => true,
            "minlength" => 3,
            "maxlength" => 8,
            "rangelength" => array(2, 12),
            "minvalue" => 5.5,
            "maxvalue" => 10,
            "rangevalue" => array(5, 10),
            "equalTo" => "email",
            "requiredFromGroup" => array(1, array("name", "email", "select"))
        ),

        /* NOTE: */
        /* unlike from javascript config, at php config
            to validate a field which may have several values - group of checkboxes, multiple dropdown
            you DO NOT have to add [] to the field name in "rules" and "messages" arrays */
        "multiple_dropdown" => array(
            "required" => true
        ),
        "checkbox_group" => array(
            "required" => true
        ),

        /* user file name */
        /* field name should be the same as at html "name" attribute at html form code */
        /* example - <input type="file" name="file_name_1" /> */
        /* detailed description of every rule - at the top of this file */
        "file_name_1" => array(
            /* file is NOT mandatory, but if user adds a file - validate it */
            "validate" => false,

            /* file is ALWAYS mandatory */
            "required" => false,

            /* file size, Mb (if less than 1 - delimiter should be ".") */
            "size" => 1,

            /* file extension, use "|" as a delimiter */
            "extension" => "jpg|jpeg|png",
        ),
        "file_name_2" => array(
            /* file is NOT mandatory, but if user adds a file - validate it */
            "validate" => false,

            /* file is ALWAYS mandatory */
            "required" => false,

            /* file size, Mb (if less than 1 - delimiter should be ".") */
            "size" => 1,

            /* file extension, use "|" as a delimiter */
            "extension" => "jpg|jpeg|png",
        )
    ),

    /* Error messages for fields */
    "messages" => array(
        "token" => array(
            "required" => "Incorrect token. Please reload this webpage"
        ),
        "recaptcha" => array(
            "required" => "reCaptcha is required"
        ),

        "user_field_name" => array(
            "required" => "Field is required",
            "email" => "Incorrect email format",
            "url" => "Incorrect url format",
            "integer" => "Field only integer allowed",
            "number" => "Field only numbers allowed",
            "minlength" => "Field min lengtn 3 chars",
            "maxlength" => "Field max lengtn 8 chars",
            "rangelength" => "Field range length from 2 to 12",
            "minvalue" => "Field value not less than 5.5",
            "maxvalue" => "Field value not greater than 10",
            "rangevalue" => "Field range value from 5 to 10",
            "equalTo" => "Field value should be equial to email",
            "requiredFromGroup" => "One field is required from 'name', 'select', 'email'"
        ),

        "multiple_dropdown" => array(
            "required" => "Dropdown is required"
        ),
        "checkbox_group" => array(
            "required" => "At least one checkbox is required"
        ),

        /* pay attention - one error message for both rules: file size and file extension */
        /* the name of this rule should be "size_extension" */
        "file_name_1" => array(
            "required" => "file_name_1 is required",
            "size_extension" => "file_name_1 types: jpg, png. Size: 1Mb",
        ),
        "file_name_2" => array(
            "required" => "file_name_2 is required",
            "size_extension" => "file_name_2 types: jpg, png. Size: 1Mb",
        )
    ),
    /************************************************/
    /* end user settings */
    /************************************************/

    /************************************************/
    /* Form settings */
    /************************************************/
    /* Debug mode */
    /* script's php errors(email sending, database, config, etc) will be shown */
    "debug" => true,

    /* Data processing */
    "data" => array(
        /* send letter with form data */
        "send" => true,

        /* Set method for email sending */
        "method" => array(
            /* use mail() function */
            "mail"=> true,

            /* use sendmail() function */
            "sendmail"=> false,

            "smtp" => array(
                "use_smtp"  => false,                               // use SMTP() function
                "auth"      => true,                                // enable SMTP authentication
                "username"  => "your username",                     // smtp username
                "password"  => "your-password",                     // smtp password
                "secure"    => "tls",                               // enable encryption, 'ssl' also accepted
                "port"      => 465,                                 // smtp port number e.g. smtp.gmail.com uses port 465
                "host" => "smtp1.example.com;smtp2.example.com",    // specify main and backup server
                "debug" => 0                                        // set "2" to enable SMTP debug mode
            ),
        ),

        /* Recipients for letter */
        /* send message to recipients */
        "recipient" => false,

        /* add email address and name of recipients */
        "recipient_data" => array(
            /* you may add as many data pairs as you want */
            /* you may use newly received email and name from $config["rules"] array- "user_email" => "user_name" */
            "user_email" => "user_name",

            /* you may manually add recipient\'s email and name */
            "email@domain.com" => "name of recipient",
        ),


        /* Autoresponse to the user */
        /* send autoresponse message to user */
        "autoresponse" => false,

        /* add email address and name for autoresponse message recipient */
        "autoresponse_data" => array(
            /* NOTE */
            /* !!! you may add one pair of data only !!! */
            /* you may use newly received email and name from $config["rules"] array- "user_email" => "user_name" */
            /* you may manually add recipient's email and name - "email@domain.com" => "User Name" */
            "user_email" => "user_name"
        ),

        /* you may spot files to be sent as an attachments within autoresponse */
        /* you may specify as many files as you want */
        /* use names of newly uploaded files from config["file"] array - file_name_1, file_name_2,... */
        /* for newly created PDF/CSV files, with form data, use aliases:
                - pdf, csv - if for every form submission new PDF/CSV file is created
                - file_name.pdf, file_name.csv - if for every form submission general PDF/CSV file is used
                file name may be found in the "general_file_name" rule of appropriate section */
        /* "example_autoresponse_attachment" => array("thank_you.html", "file_name_1", "csv", "file_name.pdf") */
        "autoresponse_attachment" => array(),
    ),

    /* File processing */
    "file" => array(
        /* directory on server inside "j-pro" directory in which files should be uploaded */
        "directory" => "form_files",

        /* file name from the html "name" attribute */
        "file_name_1" => array(

            /* upload file to server when form is submitted */
            "upload" => false,
            
            /* sending file as an attachment within letter to admin and recipients */
            "attachment" => false,

            /* delete file from server after sending a letter */
            "delete" => false,
        ),

        /* file name from the html "name" attribute */
        "file_name_2" => array(
            
            /* upload file to server when form is submitted */
            "upload" => false,
            
            /* sending file as an attachment within letter to admin and recipients */
            "attachment" => false,

            /* delete file from server after sending a letter */
            "delete" => false,
        ),
    ),

    /* CSV processing */
    "csv" => array(
        /* save form data to a CSV file */
        "save" => false,

        /* directory on server inside "j-pro" directory in which CSV file should be placed */
        "directory" => "form_files",

        /* create new CSV file for every form submission */
        /* file name will be generated automatically */
        "new_file" => true,

        /* use one CSV file for every form submission */
        "general_file" => false,
        /* set CSV file name for general file*/
        "general_file_name" => "form_data",

        /* sending CSV file as an attachment within letter to admin and recipients */
        "attachment" => false,

        /* delete CSV file from server after sending a letter */
        "delete" => false,
    ),

    /* PDF processing */
    "pdf" => array(
        /* save form data to a PDF file */
        "save" => false,

        /* directory in which PDF file should be placed */
        "directory" => "form_files",

        /* create new PDF file for every form submission */
        /* file name will be generated automatically */
        "new_file" => true,

        /* use one PDF file for every form submission */
        "general_file" => false,
        /* set PDF file name for general file */
        "general_file_name" => "form_data",

        /* sending PDF file as an attachment within letter to admin and recipients */
        "attachment" => false,

        /* delete PDF file from server after sending a letter */
        "delete" => false,
    ),

    /* Database processing */
    /* Do not forget to create a table in database */
    /* Do not forget to define database settings in the "constants.php" to access to a MySQL database */
    "database" => array(
        /* save form data to a database */
        "save" => false,

        /* use PDO for database connection */
        "pdo" => false,

        /* use MySQLi for database connection */
        "mysqli" => false,
    )
    /************************************************/
    /* end Form settings */
    /************************************************/
);