/* ** Concordance Programming Language ** ** Copyright (c) 2002 Dataflight Software, Inc. ** ALL RIGHTS RESERVED. ** 2337 Roscomare Road, Suite 11 ** Los Angeles, CA 90077 ** ** 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: ** ** ** Load_Opticon_Notes.CPL ** ** This CPL will load the text from Opticon sticky notes ** and store them to a field. The program requires an ** image key field and an optional "end image key" field. ** If an "end image key" field is provided, the CPL will ** try and load all notes from the range of images. */ text gszLoadOpticonNotes = "Load Opticon Notes"; /*****************************************************/ /* Function: Main */ /* Purpose : Entry point for all programs */ /*****************************************************/ main() { int db, nNext, bDone, i, nBeginField, nEndField, nImageNotesField; text menustring1, menustring2, menustring3, menustring4, mymenu[7], pszDatabase; /* Set up the menu */ menustring1 = "[1] Open database : "; menustring2 = "[2] Begin (image) field : "; menustring3 = "[3] End image field : "; menustring4 = "[4] Image notes field : "; mymenu[0] = gszLoadOpticonNotes; mymenu[1] = menustring1 + FileName(db.database); mymenu[2] = menustring2; mymenu[3] = menustring3; mymenu[4] = menustring4; mymenu[5] = "[G] Go"; mymenu[6] = "[Q] Quit"; /* Look for an image field. */ for (i = 1; i <= db.fields; i = i + 1) { if (db.image[i]) { nBeginField = i; break; } } if (db.database <> "") { if (nBeginField > 0) { mymenu[2] = menustring2 + db.name[nBeginField]; nNext = 3; } else nNext = 2; } /* Display the menu */ while (bDone == FALSE) { nNext = menu(5, 10, 14, 70, mymenu, nNext, "1234GQ"); switch(nNext) { /* Quit */ case 0: bDone = TRUE; break; /* Open the database */ case 1: /* Get the file name */ if (getfile("Open database", "*.DCB", pszDatabase) == CR) { /* Close the old database */ closedb(db); db = EOF; /* Reset the menus */ mymenu[1] = menustring1; nBeginField = 0; mymenu[2] = menustring2; nEndField = 0; mymenu[3] = menustring3; nImageNotesField = 0; mymenu[4] = menustring4; /* Open the database */ if ((db = opendb(pszDatabase)) <> EOF) { /* Reset the database name */ mymenu[1] = menustring1 + FileName(db.database); /* Look for an image field. */ for (i = 1; i <= db.fields; i = i + 1) { if (db.image[i]) { nBeginField = i; break; } } /* Reset the image key */ if (nBeginField > 0) { mymenu[2] = menustring2 + db.name[nBeginField]; nNext = 3; } else nNext = 2; } } break; /* Select image key field */ case 2: if ((nBeginField = GetField(db, nBeginField)) > 0) { mymenu[2] = menustring2 + db.name[nBeginField]; nNext = 3; } else nNext = 2; break; /* Select the end field */ case 3: if ((nEndField = GetField(db, nEndField)) > 0) { mymenu[3] = menustring3 + db.name[nEndField]; nNext = 4; } else nNext = 3; break; /* Get the image notes field */ case 4: if ((nImageNotesField = GetField(db, nImageNotesField)) > 0) { mymenu[4] = menustring4 + db.name[nImageNotesField]; nNext = 5; } else nNext = 4; break; case 5: if ((nNext = LoadOpticonNotes(db, nBeginField, nEndField, nImageNotesField)) == 0) nNext = 6; break; case 6: bDone = TRUE; break; } } } /*****************************************************/ /* Function: LoadOpticonNotes() */ /* Purpose : Main function to load notes. */ /*****************************************************/ LoadOpticonNotes(int db, nBeginField, nEndField, nImageNotesField) { int nError, dbNotes, fhNotes, i; text pszLastDatabase, pszEndImage, pszCurrentImage; /* Check to see if we have all the information and that the user is serious about continuing. */ if (db.database == "") { messageBox("Please open a database first.", gszLoadOpticonNotes, MB_ICONEXCLAMATION | MB_OK); nError = 1; } else { if (nBeginField == 0) { messageBox("Please specify an image field.", gszLoadOpticonNotes, MB_ICONEXCLAMATION | MB_OK); nError = 2; } else { if (nImageNotesField == 0) { messageBox("Please specify an image notes field.", gszLoadOpticonNotes, MB_ICONEXCLAMATION | MB_OK); nError = 4; } else { if (messageBox("This will overwrite all information in the " + db.name[nImageNotesField] + " field." + newline() + newline() + "Do you wish to continue?", gszLoadOpticonNotes, MB_YESNOCANCEL | MB_ICONQUESTION) <> IDYES) nError = 6; } } } if (nError == 0) { if ((dbNotes = opendb(db.database+"-REDLINES.DCB")) <> EOF) { set(dbNotes,"System fields", "Show"); search(dbNotes, "type = NOTE"); /*clear the notes field */ cycle(db) { db->nImageNotesField = ""; } cycle(dbNotes) { search(db, db.name[nBeginField]+" <= "+chr(34)+substr(dbNotes->IMAGEKEY, 1, match(dbNotes->IMAGEKEY, "|", 1)-1)+chr(34)+ " and "+db.name[nEndField]+" >= "+chr(34)+substr(dbNotes->IMAGEKEY, 1, match(dbNotes->IMAGEKEY, "|", 1)-1)+chr(34)); /* If there is no data in the field already, then just replace */ if (db->nImageNotesField== ""){ puts(0, 0, "Processing record " + str(docno(db)) + rep(" ", 50)); db->nImageNotesField = trim(dbNotes->TEXT); } else { db->nImageNotesField = db->nImageNotesField + newline() + trim(dbNotes->TEXT); } } } else messageBox("Could not open the REDLINES database", db.database+"-REDLINES.DCB", MB_OK); } /* Close files */ closedb(dbNotes); return(nError); } /**************************************************************** * Name: GetField * * Synopsis: Prompt user for field name. * ****************************************************************/ GetField(int db, next) { int i, n; text field[256]; text screen; if (db.documents >= 0) { field[0] = "Field Type "; for(i = 1; i <= db.fields; i = i +1) switch(db.type[i]) { case 'T' : field[i] = pad(db.name[i],'L',13)+ "Text "; case 'P' : field[i] = pad(db.name[i],'L',13)+ "Paragraph"; case 'N' : field[i] = pad(db.name[i],'L',13)+ "Numeric "; case 'D' : field[i] = pad(db.name[i],'L',13)+ "Date "; } i = db.fields + 1; screen = save(11,30,21,57); while(i > db.fields) i = menu(11, 30, 21, 57, field, next,""); restore(11,30,screen); if (i) next = i; } return(next); } /* GetField() */ /**************************************************************** * Name: FileName * * Synopsis: Trims the path from the file name. * ****************************************************************/ FileName(text name) { int i; while(i = match(name,"\",1)) name = substr(name,i+1); return(name); } /* FileName() */ int TEXT_BLOCK_SIZE = 124; int TEXT_SIZE = 4 + TEXT_BLOCK_SIZE; int TEXERROR = 26; int BLOCKDATA_NEXT = 1; int BLOCKDATA_OFFSET = 0;