/* * Concordance Programming Language Print-With-Attachments Program * * Program to print documents and their attachments. It uses * shellExecute() to ask the operating system to use the program * associated with the file type to print it. If no program is * associated with the file type, then it will not print. Errors * are logged to a file called Print-With-Attachments Error.log. * * NOTE: You must create and save a print format file to the same * directory as this program. Call the print format file: * Print-With-Attachments.fmt. It is used to specify the print * formatting options. * * Copyright (c) 2001 Dataflight Software, Inc. * ALL RIGHTS RESERVED. * 2337 Roscomare Road, Suite 11 * Los Angeles, CA 90077-1851 * * Unauthorized distribution, adaptation or use may be * subject to civil and criminal penalties. * * You may incorporate this program into your own programs * ONLY if you incorporate the following copyright notice: * * Copyright (c) 2001 YOUR NAME. ALL RIGHTS RESERVED. * Portions copyright (c) 2001 Dataflight Software, Inc. * */ int SLEEP_TIME = 5000; /* NOTE: 1 second = 1000 */ main() { int db, i, rc, fh, error; text szAttachment, NULL, szFile; text szError; rc = messageBox("This program prints documents and their attachments. It requests the operating system "+ newline() + "to print the attachment. If no program is associated with the attachment's file type,"+ newline() + "then it will not print. Errors are logged to a file called Print-With-Attachments Error.log."+ newline() + newline() + "NOTE: You must create and save a print format file to the same directory as this program."+ newline() + "Call the print format file: Print-With-Attachments.fmt. It is used to specify the print "+ newline() + "formatting options. Use Documents/Print Documents/Save to create the print format file.", capitalize(FileName(program())), MB_ICONINFORMATION | MB_OKCANCEL); if (rc == IDCANCEL) return; /* Create the error log file name and open the file. */ szFile = Path(program())+"Print-With-Attachments.fmt"; fh = open(capitalize(program()) + " Error.log", "a"); /* Initialize loop values and print the records. */ rc = IDYES; cycle(db) { Message("Printing "+trim(str(docno(db), 10, 0, ',')) + " of " + trim(str(count(db), 10, 0, ',')), FALSE); print(db, 0, docno(db), docno(db), szFile); for(i = 1; (rc <> IDCANCEL) and (i <= annotationCount(db)); i = i + 1) { annotationGoto(db, i); if (annotationRetrieve(db, "ATTACHTYPE") == "External") { szAttachment = annotationRetrieve(db, "NOTEATTACHED"); /* rc = messageBox("Do you want to print"+ newline() + szAttachment, program(), MB_YESNOCANCEL); */ if (rc == IDYES) { if ((error = shellExecute("print", szAttachment, NULL, NULL, SW_SHOWMINNOACTIVE)) <= 32) writeln(fh, szError = dtoc(today())+" "+db.database+": Error "+ str(error) + " on record " + str(docno(db)) + " [" + str(recno(db)) +"] while printing "+szAttachment, len(szError)); } sleep(SLEEP_TIME); } } if (rc == IDCANCEL) break; } if (fh <> EOF) close(fh); } /* main() */ /**************************************************************** * Name: Message * * Synopsis: Displays error message and waits for key. * ****************************************************************/ Message(text message; int wait) { text screen; int key; cursoroff(); if (wait) screen = save(5,13,8,69); box(5,13,8,69, "3D", MenuColor_); puts(6,14,pad(message,'C',53),MenuColor_); if (wait) { key = getkey(); restore(5,13,screen); } return(asc(upper(chr(key)))); } /* Message() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; if (i = match(name,":",1)) name = substr(name,i+1); while(i = match(name,"\",1)) name = substr(name,i+1); return(name); } /* FileName() */ /**************************************************************** * Name: Path * * Synopsis: Trims the file name from the path. * ****************************************************************/ Path(text name) { int i, j; char string[257]; string = name; if (i = match(name,":",1)) j = i; else i = j = 1; while(j = match(name,"\", i)) i = j + 1; string[i - 1] = 0; return(string); } /* Path() */ RGB(char red, grn, blu) { return(((blu & 255) * 65536) | ((grn & 255) * 256) | (red & 255)); }