📄 php_notes.c
字号:
/* {{{ proto string notes_copy_db(string from_database_name, string to_database_name [, string title]) Creates a note using form form_name */PHP_FUNCTION(notes_copy_db){ int argc; pval *argv[3]; STATUS error; DBHANDLE input_handle; DBHANDLE output_handle; char error_string[200]; pval **db_input; pval **db_output; pval **title; DBREPLICAINFO replica_info; /* replication info for the databases */ char output_db_info[NSF_INFO_SIZE]; /* database info buffer */ TIMEDATE start_time; /* time and date used to control what notes we copy */ TIMEDATE last_time; /* returned from NSFDbGetModifiedNoteTable */ DBID input_dbid; /* dbid of input database */ DBID output_dbid; /* dbid of output database */ HANDLE idtable_p; /* handle to id table */ DWORD num_scanned, num_entries; NOTEID note_id; NOTEHANDLE hIconNote; /* handle to the icon note */ argc = ARG_COUNT(ht); if (getParametersArray(ht, argc, argv) == FAILURE){ WRONG_PARAM_COUNT; } if (zend_get_parameters_ex(3, &db_input, &db_output, &title)==FAILURE) { RETURN_FALSE; } convert_to_string_ex(db_input); convert_to_string_ex(db_output); convert_to_string_ex(title); error = NotesInitExtended( argc, (char **) argv ); if( error ){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to initialize Lotus Notes: %s", error_string); RETURN_FALSE; } /* Open the input database. */ if (error = NSFDbOpen (Z_STRVAL_PP(db_input), &input_handle)){ NSFDbClose (input_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to open input database: %s", error_string); NotesTerm(); RETURN_FALSE; }/* Create and open the output database. */ if (error = NSFDbCreate (Z_STRVAL_PP(db_output), DBCLASS_NOTEFILE, FALSE)) { NSFDbClose (input_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to create database: %s", error_string); NotesTerm(); RETURN_FALSE; } if (error = NSFDbOpen (Z_STRVAL_PP(db_output), &output_handle)) { NSFDbClose (input_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error opening output database: %s", error_string); NotesTerm(); RETURN_FALSE; }/* Copy the replication settings (not the replication history) fromthe input database to the output database. The replication settingsinclude the database replica ID. This makes the destination databasea replica copy of the source database. */ if (error = NSFDbReplicaInfoGet (input_handle, &replica_info)) { NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error copying replication information: %s", error_string); NotesTerm(); RETURN_FALSE; }/* Copy the ACL from the input database to the output database. */ if (error = NSFDbCopyACL (input_handle, output_handle)) { NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error copying ACL: %s", error_string); NotesTerm(); RETURN_FALSE; }/* Set a time/date structure that will determine the date of the earliestnote copied in the next call. Use TimeConstant with TIMEDATE_WILDCARDspecified to indicate that we do not want any cutoff date. */ TimeConstant (TIMEDATE_WILDCARD, &start_time);/* Do not use NSFDbCopy to copy all notes in the input database to the output database. Such copies are not guaranteed to be replicas of the original notes. Instead get an IDTABLE of all notes in the database, use IDScan to obtain each NOTEID, and then call NSFDbCopyNote to copy each note from one database to the other.*/ NSFDbIDGet (input_handle, &input_dbid); NSFDbIDGet (output_handle, &output_dbid);/* Get the NoteID table for all notes in the input database */ if (error = NSFDbGetModifiedNoteTable (input_handle, NOTE_CLASS_ALL, start_time, &last_time, &idtable_p) ) if (error == ERR_NO_MODIFIED_NOTES){ NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_NOTICE,"There are no documents in the Database: %s", error_string); NotesTerm(); RETURN_TRUE; } else { NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error copying replication information: %s", error_string); NotesTerm(); RETURN_FALSE; } num_scanned = 0L; num_entries = IDEntries (idtable_p); if (num_entries) while (IDScan (idtable_p, (FLAG)(num_scanned++ == 0), ¬e_id) ) if (error = NSFDbCopyNote (input_handle, &input_dbid, &replica_info.ID, note_id, output_handle, &output_dbid, &replica_info.ID, NULL, NULL) ) { IDDestroyTable (idtable_p); NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error copying notes: %s", error_string); NotesTerm(); RETURN_FALSE; } IDDestroyTable (idtable_p); /* Now we can change the title of the output database by following these steps: - Get the info buffer of the database (NSFDbInfoGet); - Modify the title information in the buffer (NSFDbInfoModify); - Write the modified info buffer into the database (NSFDbInfoSet); - If necessary, update the ICON note with the updated database information buffer. This is required for databases created from a template.*//* Clear out the database information buffer */ output_db_info[0] = '\0';/* Get the output database information buffer. */ if (error = NSFDbInfoGet (output_handle, output_db_info)) { NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error getting output database information buffer: %s", error_string); NotesTerm(); RETURN_FALSE; }/* Add the database title to the database information buffer */ NSFDbInfoModify (output_db_info, INFOPARSE_TITLE, Z_STRVAL_PP(title)); if (error = NSFDbInfoSet (output_handle, output_db_info)) { NSFDbClose (input_handle); NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error adding the database title to the buffer: %s", error_string); NotesTerm(); RETURN_FALSE; }/* If creating a new database from a template, in order to change the database title or any other component of the database information buffer, you also need to update this information in the ICON note after updating it in the database information buffer. */ if (!NSFNoteOpen(output_handle, NOTE_ID_SPECIAL+NOTE_CLASS_ICON, 0, &hIconNote)) { /* Update the FIELD_TITLE ("$TITLE") field if present */ if (NSFItemIsPresent (hIconNote, FIELD_TITLE, (WORD) strlen (FIELD_TITLE)) ) { NSFItemSetText(hIconNote, FIELD_TITLE, output_db_info, MAXWORD); NSFNoteUpdate(hIconNote, 0); } NSFNoteClose(hIconNote); }/* Close the databases. */ if (error = NSFDbClose (input_handle)) { NSFDbClose (output_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error closing the input database: %s", error_string); NotesTerm(); RETURN_FALSE; } if (error = NSFDbClose (output_handle)){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error closing the output database: %s", error_string); NotesTerm(); RETURN_FALSE; } NotesTerm(); RETURN_TRUE;}/* }}} */STATUS LNPUBLIC ReadSummaryData ( /* called for every document */ VOID far *, SEARCH_MATCH far *, ITEM_TABLE far *);STATUS PrintSummary (char *);STATUS ExtractTextList (char *, char *);/* Constants *//* Notes imposes a 32K max summary buffer total size. Therefore, 34K will safely store the printable text rendering of any single item.*/#define MAX_ITEM_LEN 34816/* The maximum number of items in the summary buffer of a single note is limited to the number of ITEM structures that will fit in 32K.*/#define MAX_ITEMS 32768/sizeof(ITEM)#define MAX_ITEM_NAME_LEN DESIGN_NAME_MAX/* Global variables */ITEM Items[MAX_ITEMS]; /* Stores the array of ITEMs */char ItemText[MAX_ITEM_LEN]; /* Text rendering of item value */char ItemName[MAX_ITEM_NAME_LEN];/* Zero terminated item name *//* {{{ proto bool notes_list_msgs(string db) ??? */PHP_FUNCTION(notes_list_msgs){ int argc; pval *argv[1]; STATUS error; DBHANDLE db_handle; char error_string[200]; pval **db; argc = ARG_COUNT(ht); if (getParametersArray(ht, argc, argv) == FAILURE){ WRONG_PARAM_COUNT; } if (zend_get_parameters_ex(1, &db)==FAILURE) { RETURN_FALSE; } convert_to_string_ex(db); error = NotesInitExtended( argc, (char **) argv ); if( error ){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to initialize Lotus Notes: %s", error_string); RETURN_FALSE; } if (error = NSFDbOpen (Z_STRVAL_PP(db), &db_handle)){ NSFDbClose (db_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to open database: %s", error_string); NotesTerm(); RETURN_FALSE; } /* Call NSFSearch to find all data notes in the database. Specify search flag SEARCH_SUMMARY so that the action routine gets passed the summary buffer as input. */ if (error = NSFSearch ( db_handle, /* database handle */ NULLHANDLE, /* selection formula */ NULL, /* title of view in selection formula */ SEARCH_SUMMARY, /* search flags: get summary data! */ NOTE_CLASS_DATA, /* note class to find */ NULL, /* starting date (unused) */ ReadSummaryData, /* action routine for notes found */ NULL, /* argument to action routine */ NULL)) /* returned ending date (unused) */ { NSFDbClose (db_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to search database: %s", error_string); NotesTerm(); RETURN_FALSE; } if (error = NSFDbClose (db_handle)) { NSFDbClose (db_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to close database: %s", error_string); NotesTerm(); RETURN_FALSE; } RETURN_TRUE}STATUS LNPUBLIC ReadSummaryData (VOID far *optional_param, SEARCH_MATCH far *search_info, ITEM_TABLE far *summary_info){ SEARCH_MATCH SearchMatch; STATUS error; memcpy ((char*)(&SearchMatch), (char *)search_info, sizeof(SEARCH_MATCH)); if (!(SearchMatch.SERetFlags & SE_FMATCH)) return (NOERROR); /* Print the note ID. */ php_printf ("\nNote ID is: %lX.\n<br />", SearchMatch.ID.NoteID); /* Print the summary data. */ if (error = PrintSummary( (char*)summary_info )) return (error); return (NOERROR);}/************************************************************************ FUNCTION: PrintSummary PURPOSE: Print all the items in a summary buffer. INPUTS: pSummary - a pointer to the summary buffer for one note. DESCRIPTION: The information in a summary buffer consists of an ITEM_TABLE structure, followed by an array of ITEM structures, followed by a packed sequence of field names and item values. ITEM_TABLE ITEM 1 ITEM 2 ... ITEM N name of item 1 value of item 1 name of item 2 value of item 2 ... name of item N value if item N Item names are not zero terminated. Each item value starts with a data type word. The lengths of the item names and item values will vary. The NameLength member of the ITEM structure specifies the length of the corresponding name, and the ValueLength member of the ITEM structure specifies the length of the item value. The ValueLength includes the length of the data type word. Note that this summary buffer differs in format from the buffer parsed by sample program VIEWSUMM. VIEWSUMM calls NIFReadEntries specifying READ_MASK_SUMMARYVALUES, which yields a buffer with format specified by ITEM_VALUE_TABLE rather than ITEM_TABLE. This function can parse the summary buffer of any data note because it does not assume the note contains items with any particular names. If you know the item name in advance, use either NSFGetSummaryValue() or NSFLocateSummaryValue().*************************************************************************/STATUS PrintSummary (char *pSummary){ char *pSummaryPos; /* current position in pSummary */ ITEM_TABLE ItemTable; /* header at start of pSummary */ USHORT ItemCount; /* number of items in pSummary */ USHORT NameLength; /* length of item name w/out terminator*/ USHORT ValueLength; /* length of item value, incl. type */ WORD DataType; /* item data type word */ char *szDataType; /* printable data type name */ USHORT TextLen; /* length of printable item text */ NUMBER NumericItem; /* an item of type TYPE_NUMBER */ NUMBER_PAIR NumberPair; /* part of item of TYPE_NUMBER_RANGE */ RANGE Range; /* part of item of TYPE_NUMBER_RANGE */ TIMEDATE TimeItem; /* a time/date item */ TIMEDATE_PAIR TimePairItem; /* part of time/date list or range */ WORD TimeStringLen; /* length of ASCII time/date */ STATUS error; /* return code from API calls */ USHORT i; /* counter for loop over items */ USHORT j; /* " " " " multi-valued items */ /* Initialize pSummaryPos to the position of the beginning of the summary buffer. Keep pSummary unmodified. Modify pSummaryPos. */ pSummaryPos = pSummary; /* Copy the ITEM_TABLE header at the beginning of the summary buffer to a local variable. Advance pSummaryPos to point to the next byte in the summary buffer after the ITEM_TABLE. */ memcpy ((char*)(&ItemTable), pSummaryPos, sizeof(ITEM_TABLE)); pSummaryPos += sizeof(ItemTable); /* pSummaryPos now points to the first ITEM in an array of ITEM structures. Copy this array of ITEM structures into the global Items[] array. */ ItemCount = ItemTable.Items; for (i=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -