//
//	Legato Code Examples
//	--------------------
//
//	EDGAR Submit File Hook Example
//
//	Group:		Hooks
//	Title:		EDGAR Submit File Hook Example
//	Description:	Example of setting a hook on a menu function.
//	Revised:	12/16/2014
//
//	(c) Novaworks, LLC
//

//#pragma disable		(uncomment to disbale the script while in the folder)


							/********************************************************/
							/* Persisent Data					*/
                                                        /* --------------					*/
                                                        /* Global data is persistent after the hook is first	*/
                                                        /* called from the menu.				*/
							/********************************************************/

								/************************************************/

									/****************************************/
    int			f_live, f_test;					/* Function IDs				*/


									/****************************************/
									/* ** Prototypes			*/
    int 		submit_query(int f_id); 			/* Query Function			*/



							/********************************************************/
							/* Menu Hook Setup					*/
                                                        /* ---------------					*/
							/********************************************************/

								/************************************************/
								/* Set Hook					*/
                                                                /* --------					*/
                                                                /* All globals are thrown away after this func-	*/
                                                                /* tion is run.					*/
								/************************************************/

									/****************************************/
int setup() {								/* Called from Application Startup	*/
									/****************************************/
    string		fnScript;					/* Us					*/
									/*					*/    
    fnScript = GetScriptFilename();					/* Get the script filename		*/
    MenuSetHook("EDGAR_SUBMIT_TEST", fnScript, "submit_test");		/* Set the Test Hook			*/
    MenuSetHook("EDGAR_SUBMIT_LIVE", fnScript, "submit_live");		/* Set the Live Hook			*/
    return ERROR_NONE;							/* Return value (does not matter)	*/
    }									/* end setup				*/
    
								/************************************************/
								/* First Run from Menu Hook			*/
								/* ------------------------			*/
								/************************************************/

									/****************************************/
int main() {								/* Call from Hook Processor		*/
									/****************************************/
    f_live = MenuGetFunctionID("EDGAR_SUBMIT_LIVE");			/* Get the menu id 			*/
    f_test = MenuGetFunctionID("EDGAR_SUBMIT_TEST");			/* Get the menu id 			*/
    
		    							// add in any additional setup here
    return ERROR_NONE;							/* Return value (does not matter)	*/
    }									/* end setup				*/


							/********************************************************/
							/* Actual Hooks						*/
                                                        /* ------------						*/
							/* The hook comes in with the menu ID and the mode. The	*/
                                                        /* ID can be  used  to  differentiate  the calls if the	*/
                                                        /* same hook is shared by multiple hooks.   The mode is	*/
                                                        /* type  of  entry.   For menus, it is  "preprocess" or	*/
                                                        /* "postprocess".					*/
							/********************************************************/

								/************************************************/
								/* Submit Test Hook				*/
                                                                /* ----------------				*/
								/************************************************/

									/****************************************/
int submit_test(int f_id, string mode) {				/* Hook for Test			*/
									/****************************************/
    int			rc;						/* Return Code				*/
    									/*					*/
    if (mode != "preprocess") {						/* Filter out all but preprocess	*/
      return ERROR_NONE;						/* Just leave				*/
      }									/* end not preporcess			*/
    rc = submit_query(f_id);						/* Perform the query			*/
    if (IsCancel(rc)) {							/* No good				*/
      return ERROR_EXIT;						/* Do not allow continue		*/
      }									/* end cancel				*/
    return ERROR_NONE;							/* Return value (does not matter)	*/
    }									/* end setup				*/


								/************************************************/
								/* Submit Live Hook				*/
                                                                /* ----------------				*/
								/************************************************/

									/****************************************/
int submit_live(int f_id, string mode) {				/* Hook for Live			*/
									/****************************************/
    int			rc;						/* Return Code				*/
    									/*					*/
    if (mode != "preprocess") {						/* Filter out all but preprocess	*/
      return ERROR_NONE;						/* Just leave				*/
      }									/* end not preporcess			*/
    rc = submit_query(f_id);						/* Perform the query			*/
    if (IsCancel(rc)) {							/* No good				*/
      return ERROR_EXIT;						/* Do not allow continue		*/
      }									/* end cancel				*/
    return ERROR_NONE;							/* Return value (does not matter)	*/
    }									/* end setup				*/


							/********************************************************/
							/* Query Dialog						*/
                                                        /* ------------						*/
							/********************************************************/

								/************************************************/
								/* Dialog Data					*/

									/****************************************/
#include "SubmitHookExample.rc"						/* Dialog Resrouces & Defines		*/
									/*					*/
    string		cf_cik;						/* Filing CIK				*/
    string		cf_form;					/* Form Type				*/
    string		cf_name;					/* Registrant Name			*/	
    int			cf_check_01;					/* A Check to Sign-off On		*/
    int			cf_check_02;					/* A Check to Sign-off On		*/
    int			cf_check_03;					/* A Check to Sign-off On		*/
    int			cf_check_04;					/* A Check to Sign-off On		*/
    string		cf_verified;					/* Initialize of Sign-off Person	*/


								/************************************************/
								/* Query Control				*/
                                                                /* -------------				*/
								/************************************************/

									/****************************************/
int submit_query(int f_id) { 						/* Query Function			*/
									/****************************************/
    int			rc;						/* Return Code				*/
    									/*					*/
									/* ** Perform Confirmation of Filing	*/
									/*  * Gather Data			*/

    cf_cik = "0123456789";			// just dump in some data
    cf_form = "8-K";
    cf_name = "ZZZ Corporation";
                                                                        
                                                                        /*  * Query External Systems		*/
                                                                        
						// add this

                                                                        /*  * Query User on Check List		*/
    rc = DialogBox("ConfirmFiling", "submit_dialog_");			/* Perform the query			*/
    if (IsError(rc)) {							/* Error processing (cancel)		*/
      return rc;							/* Exit w/error				*/
      }									/* end error				*/
									/*  * Update External Systems		*/

						// add this
                                                                        
    return ERROR_NONE;							/* Return with OK or not		*/
    }									/* end query				*/


								/************************************************/
								/* Dialog Procedured				*/
                                                                /* -----------------				*/
								/************************************************/

									/****************************************/
int submit_dialog_load() {						/* Load the Dialog			*/
									/****************************************/
    EditSetText(CF_CIK,  cf_cik);                                       /* Filing CIK                           */
    EditSetText(CF_FORM, cf_form);                                      /* Form Type                            */
    EditSetText(CF_NAME, cf_name);                                      /* Registrant Name                      */      
    }									/* end load				*/

									/****************************************/
int submit_dialog_validate() {						/* Validate Dialog			*/
									/****************************************/
									/*					*/
									/* ** Validate the Controls		*/
									/*  * Check Box Sample #1		*/
    cf_check_01 = CheckboxGetState(CF_CHECK_01);			/* A Check to Sign-off On		*/
    if (cf_check_01 == 0) {						/* Not checked				*/
      MessageBox('X', "Failure to check item #1");			/* Display error			*/
      return ERROR_SOFT | CF_CHECK_01;					/* Exit w/error control			*/
      }									/* end checkbox failure			*/
									/*  * Check Box Sample #1		*/
    cf_check_02 = CheckboxGetState(CF_CHECK_02);			/* A Check to Sign-off On		*/
    if (cf_check_02 == 0) {						/* Not checked				*/
      MessageBox('X', "Failure to check item #2");			/* Display error			*/
      return ERROR_SOFT | CF_CHECK_02;					/* Exit w/error control			*/
      }									/* end checkbox failure			*/
									/*  * Check Box Sample #1		*/
    cf_check_03 = CheckboxGetState(CF_CHECK_03);			/* A Check to Sign-off On		*/
    if (cf_check_03 == 0) {						/* Not checked				*/
      MessageBox('X', "Failure to check item #3");			/* Display error			*/
      return ERROR_SOFT | CF_CHECK_03;					/* Exit w/error control			*/
      }									/* end checkbox failure			*/
									/*  * Check Box Sample #1		*/
    cf_check_04 = CheckboxGetState(CF_CHECK_04);			/* A Check to Sign-off On		*/
    if (cf_check_04 == 0) {						/* Not checked				*/
      MessageBox('X', "Failure to check item #4");			/* Display error			*/
      return ERROR_SOFT | CF_CHECK_04;					/* Exit w/error control			*/
      }									/* end checkbox failure			*/
									/*  * Verify				*/
    cf_verified = EditGetText(CF_VERIFIED);				/* Get the Sign-off Person		*/
    if (cf_verified == "") {						/* Not checked				*/
      MessageBox('X', "Please sign-off to proceed.");			/* Display error			*/
      return ERROR_SOFT | CF_VERIFIED;					/* Exit w/error control			*/
      }									/* end checkbox failure			*/
    return ERROR_NONE;							/* Ok to exit dialog			*/
    }									/* end load				*/



