<commit_before>---
layout: default
product: certCapture
nav: apis
doctype: overview
---
<!-- TODO: consistent naming -->
<!-- TODO: move inline CSS to cert-demo.scss -->
<script language="php" src="">
    // TODO: translate to JS
    // TODO: move to diff file
    function callapi() {
        $headers = apache_request_headers();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $headers['api-url']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "x-client-id: " . $headers['x-client-id'],
            "x-customer-number: " . $headers['x-customer-number'],        
            "Authorization: Basic " . base64_encode( $headers['api-user'] . ":" . $headers['api-password'] ),
            "Content-Length: 0"
        ));
    
        $response = curl_exec($ch);
        curl_close($ch);
        echo $response
    } 
</script>
<!-- TODO: jquery -->
<!-- TODO: move to different file -->
<script language="javascript">
    // TODO: works
    function init_api()
{

    if ( document.getElementById( 'gencert_url' ).value == "" ) {
        alert( 'Enter a GenCert URL.' );
        return;
    }

    var sel  = document.getElementById( "set_zone" );
    var zone = sel.options[ sel.selectedIndex ].text;
    var form_element = document.getElementById( 'form_container' );
    form_element.className = "";
    var randomString = Math.random().toString(36).substring(7);

    if ( document.getElementById( 'client_id' ).value != "" ) {

        if ( document.getElementById( 'key' ).value == "" ) {
            alert( 'Enter a gencert key.' );
            return;
        }

        if ( document.getElementById( 'customer_number' ).value == "" ) {
            alert( 'Enter a customer number.' );
            return;
        }

        var script = document.createElement( 'script' );
        script.onload = function () {

            GenCert.init(form_element,
                {
                    customer_number: document.getElementById( 'customer_number' ).value,
                    ship_zone: zone
                });
            set_options();

        };
        script.src = document.getElementById( 'gencert_url' ).value + "/Gencert2/js?cid=" + document.getElementById( 'client_id' ).value + "&key=" + document.getElementById( 'key' ).value+'&'+randomString;
        document.head.appendChild( script );
    }
    else if ( document.getElementById( 'token' ).value != "" ) {
        var script = document.createElement( 'script' );
        script.onload = function () {

            GenCert.init(form_element,
                {
                    token: document.getElementById( 'token' ).value,
                    ship_zone: zone
                });
            set_options();

        };
        script.src = document.getElementById( 'gencert_url' ).value + "/Gencert2/js"+'&'+randomString;
        document.head.appendChild( script );
    }
    else {
        alert( 'Please provide some information to get started.' );
    }

    // TODO: rework
    function set_options() {
        GenCert.__setOption( 'edit_purchaser', document.getElementById( 'edit_purchaser' ).checked );
        GenCert.__setOption( 'show_files', document.getElementById( 'show_files' ).checked );
        GenCert.__setOption( 'submit_to_stack', document.getElementById( 'submit_to_stack' ).checked );
        GenCert.__setOption( 'preview', document.getElementById( 'preview' ).checked );
        GenCert.__setOption( 'upload_only', document.getElementById( 'upload_only' ).checked );
        GenCert.__setOption( 'fill_only', document.getElementById( 'fill_only' ).checked );
        GenCert.__setOption( 'customer_list', document.getElementById( 'customer_list' ).checked );
        GenCert.__setOption( 'append_barcode', document.getElementById( 'append_barcode' ).checked );
        GenCert.__setOption( 'upload_form_unavailable', document.getElementById( 'upload_form_unavailable' ).checked );

        GenCert.show();
        document.getElementById( 'gencert_test' ).style.display = 'none';
        document.getElementById( 'divider' ).style.display = 'none';
        document.getElementById( 'script_test' ).style.display = 'none';
    }
}
//TODO: works
function init_script() {

    if ( document.getElementById( 'gencert_url_script' ).value == "" ) {
        alert( 'Enter a GenCert URL.' );
        return;
    }

    if ( document.getElementById( 'sample_script' ).value == "" ) {
        alert( 'Enter some valid javascript.' );
        return;
    }

    var script = document.createElement( 'script') ;
    script.onload = function () {
      
        try {
            eval( document.getElementById( 'sample_script' ).value );<commit_msg>dc-3345: removed init_api, not needed cuz was for v2<commit_after>---
layout: default
product: certCapture
nav: apis
doctype: overview
---
<!-- TODO: consistent naming -->
<!-- TODO: move inline CSS to cert-demo.scss -->
<script language="php" src="">
    // TODO: translate to JS
    // TODO: move to diff file
    function callapi() {
        $headers = apache_request_headers();
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $headers['api-url']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_HEADER, FALSE);
        curl_setopt($ch, CURLOPT_POST, TRUE);
        curl_setopt($ch, CURLOPT_VERBOSE, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            "x-client-id: " . $headers['x-client-id'],
            "x-customer-number: " . $headers['x-customer-number'],        
            "Authorization: Basic " . base64_encode( $headers['api-user'] . ":" . $headers['api-password'] ),
            "Content-Length: 0"
        ));
    
        $response = curl_exec($ch);
        curl_close($ch);
        echo $response
    } 
</script>
<!-- TODO: jquery -->
<!-- TODO: move to different file -->
<script language="javascript">
//TODO: works
function init_script() {

    if ( document.getElementById( 'gencert_url_script' ).value == "" ) {
        alert( 'Enter a GenCert URL.' );
        return;
    }

    if ( document.getElementById( 'sample_script' ).value == "" ) {
        alert( 'Enter some valid javascript.' );
        return;
    }

    var script = document.createElement( 'script') ;
    script.onload = function () {
      
        try {
            eval( document.getElementById( 'sample_script' ).value );
{'fraction_non_alphanumeric': 0.14683014354066987, 'fraction_numerical': 0.0026913875598086126, 'mean_word_length': 2.4693983402489628, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1647158', 'n_tokens_mistral': 1972, 'n_tokens_neox': 1893, 'n_words': 424}