/************************************************************************
 * Title:        !BatchPrintNativeFiles.cpl                             *
 * Description:  Batch print native files in the current query          *
 *                                                                      *
 * Author:       Calvin Smith                                           *
 * Email:        JobForCalvin@Yahoo.com                                 *
 * Web:          www.CalvinSmithSoftware.com                            * 
 * Compiler:     Concordance                                            *
 * Accepts:      Nothing                                                *
 * CPL Version:  1.0                                                    *
 ************************************************************************
 *                                                                      *
 * NOTE: Contact me if you need a custom CPL developed for other needs. *
 *                                                                      *
 ************************************************************************/



char ESC = 27;
text NULL;

/* NOTE: Change NATIVEFILE on the next line to match the native file field name in your DB */
text NATIVEFIELDNAME = "NATIVEFILE";

main()
{
   int db;
   text UserPrompt;

    
      UserPrompt = "This program will print all native files "+
                 "in the current query excluding attachments. "+
                 chr(CR)+chr(LF)+ chr(CR)+chr(LF)+
                 "         Press any key to continue...";

      cursoroff();
      Status(db);
      puts(0,0,program(),MenuColor_);
      scroll(07,15,15,62,0,0,MenuColor_);
      box(07,14,13,65,"3D",MenuColor_);
      edit(UserPrompt,08,16,13,61,-1,1,1,MenuColor_);
      
      if (getkey() == ESC)
        return;
      else
        cursor(0,0);
   	cursoroff();
   	puts(0,0,pad("Blank Field",'C',80),MenuHighlight_);


   	if (messageBox("Print all documents in current query?","Confirm batch print job",MB_OKCANCEL) == IDOK)
   	{
   		Handle(db);
   		return;
   	}
   	else
   	{
   		UserPrompt = "Print job cancelled."+ chr(CR)+chr(LF)+ chr(CR)+chr(LF)+ " Press any key to continue...";
   		Message (UserPrompt);
   	}
}

Message(text message)
{
text screen;
int key;
   cursoroff();
   screen = save(8,13,11,69);
   box(8,13,11,69,"3D", MenuColor_);
   puts(9,14,pad(message,'C',53),MenuColor_);
   key = getkey();
   restore(8,13,screen);
   return(asc(upper(chr(key))));
} /* Message() */

Handle(int db)
{
	cycle(db)

	{
	puts(0,0, "Now processing document " + str(docno(db),8,0,',') + " of " + str(count(db),8,0,','));

	shellExecute("print",db->NATIVEFIELDNAME,NULL,NULL,SW_SHOW);
	}

	return(0);
} /* Handle() */

Status(int db)
{
   puts(0,0,rep('_',80),MenuColor_);
   puts(MaxRow_,0,rep(' ',80),MenuColor_);
   puts(MaxRow_,0,"Concordance CPL To Batch Print Native Files",MenuColor_);
   if (db.documents >= 0)
   puts(0,0,db.database,MenuColor_);
} /* Status() */
