📄 php_notes.c
字号:
} if (error = NSFDbOpen (Z_STRVAL_PP(db), &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; } if( strcmp( Z_STRVAL_PP(type), "FORM" ) == 0 ){ if ((error = NIFFindDesignNote(db_handle, Z_STRVAL_PP(name), NOTE_CLASS_FORM, ¬e_id)) != ERR_NOT_FOUND) { RETVAL_LONG( (long) note_id ); } } else if( strcmp( Z_STRVAL_PP(type), "VIEW" ) == 0 ){ if ((error = NIFFindDesignNote(db_handle, Z_STRVAL_PP(name), NOTE_CLASS_VIEW, ¬e_id)) != ERR_NOT_FOUND) { RETVAL_LONG( (long) note_id ); } } else if( strcmp( Z_STRVAL_PP(type), "FILTER" ) == 0 ){ if ((error = NIFFindDesignNote(db_handle, Z_STRVAL_PP(name), NOTE_CLASS_FILTER, ¬e_id)) != ERR_NOT_FOUND) { RETVAL_LONG( (long) note_id ); } } else if( strcmp( Z_STRVAL_PP(type), "FIELD" ) == 0 ){ if ((error = NIFFindDesignNote(db_handle, Z_STRVAL_PP(name), NOTE_CLASS_FIELD, ¬e_id)) != ERR_NOT_FOUND) { RETVAL_LONG( (long) note_id ); } } else{ if ((error = NIFFindDesignNote(db_handle, Z_STRVAL_PP(name), NOTE_CLASS_ALL, ¬e_id)) != ERR_NOT_FOUND) { RETVAL_LONG( (long) note_id ); } } NSFDbClose(db_handle); NotesTerm();}/* }}} *//* {{{ proto bool notes_nav_create(string database_name, string name) Creates a navigator name, in database_name */PHP_FUNCTION(notes_nav_create){ int argc; pval *argv[2]; pval **db; pval **name; char error_string[200]; STATUS error = NOERROR; DBHANDLE db_handle; WORD ClassView = NOTE_CLASS_VIEW; NOTEHANDLE view_handle; /* sample navigator view handle */ char szMainView[] = "MainView"; /* title of view to be used */ VIEWMAP_HEADER_RECORD NavHeader; WORD wLayoutCount; WORD wNavLayoutBufLen; HANDLE hNavLayoutBuffer; char *pNavLayoutBuffer; char *pNLBuf; char szDFlags[3]; argc = ARG_COUNT(ht); if (getParametersArray(ht, argc, argv) == FAILURE){ WRONG_PARAM_COUNT; } if (zend_get_parameters_ex(2, &db, &name)==FAILURE) { RETURN_FALSE; } convert_to_string_ex(db); convert_to_string_ex(name); 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)){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to open database: %s", error_string); NotesTerm(); RETURN_FALSE; } error = NSFNoteCreate( db_handle, &view_handle ); if ( error ) { OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to create note in database: %s", error_string); NSFDbClose( db_handle ); NotesTerm(); RETURN_FALSE; } NSFNoteSetInfo( view_handle, _NOTE_CLASS, &ClassView );/* * Set the view name. */ error = NSFItemSetText( view_handle, VIEW_TITLE_ITEM, Z_STRVAL_PP(name), MAXWORD ); if ( error ){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to set text item '%s' in view note: %s", VIEW_TITLE_ITEM, error_string); NSFNoteClose( view_handle ); NSFDbClose( db_handle ); NotesTerm(); RETURN_FALSE; }/* * Append Design flags for the Navigator view. */ szDFlags[0] = DESIGN_FLAG_VIEWMAP; szDFlags[1] = DESIGN_FLAG_HIDE_FROM_V3; szDFlags[2] = '\0'; error = NSFItemAppend( view_handle, ITEM_SUMMARY, DESIGN_FLAGS, (WORD)strlen(DESIGN_FLAGS), TYPE_TEXT, szDFlags, (DWORD)strlen(szDFlags )); if ( error ) { OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to append item '%s' to view note: %s", DESIGN_FLAGS, error_string); NSFNoteClose( view_handle ); NSFDbClose( db_handle ); NotesTerm(); RETURN_FALSE; } wLayoutCount = 0; wNavLayoutBufLen = ODSLength( _VIEWMAP_HEADER_RECORD ); /* * Allocate and initialize the CD buffer for the entire $ViewMapLayout item. */ if ( error = OSMemAlloc( 0, wNavLayoutBufLen, &hNavLayoutBuffer )){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to allocate %d bytes memory: %s", wNavLayoutBufLen, error_string); NSFNoteClose( view_handle ); NSFDbClose( db_handle ); NotesTerm(); RETURN_FALSE; } pNavLayoutBuffer = (char*) OSLockObject( hNavLayoutBuffer ); memset( pNavLayoutBuffer, 0, (size_t) wNavLayoutBufLen ); /* * Initialize pNLBuf. pNavLayoutBuffer will remain pointing to the top * of the buffer. pNLBuf will move to point to the next available byte. */ pNLBuf = pNavLayoutBuffer; NavHeader.Header.Signature = SIG_CD_VMHEADER; NavHeader.Header.Length = (BYTE) ODSLength(_VIEWMAP_HEADER_RECORD ); NavHeader.Version = VIEWMAP_VERSION; NavHeader.NameLen = 0; ODSWriteMemory( &pNLBuf, _VIEWMAP_HEADER_RECORD, &NavHeader, 1 ); error = NSFItemAppend( view_handle, ITEM_SUMMARY, VIEWMAP_LAYOUT_ITEM, (WORD)strlen(VIEWMAP_LAYOUT_ITEM), TYPE_VIEWMAP_LAYOUT, pNavLayoutBuffer, (DWORD)wNavLayoutBufLen ); OSUnlockObject( hNavLayoutBuffer ); OSMemFree( hNavLayoutBuffer ); if ( error ) { OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to append item '%s' to view note: %s", VIEWMAP_LAYOUT_ITEM, error_string); NSFNoteClose( view_handle ); NSFDbClose( db_handle ); NotesTerm(); RETURN_FALSE; }/* * Done constructing the view note. Now store the view note * in the database. */ error = NSFNoteUpdate( view_handle, 0 ); if ( error) { OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to update note: %s", error_string); NSFNoteClose( view_handle ); NSFDbClose( db_handle ); NotesTerm(); RETURN_FALSE; } NSFNoteClose( view_handle ); NSFDbClose( db_handle ); NotesTerm(); RETURN_TRUE;}/* }}} *//* {{{ proto string notes_search(string database_name, string keywords) Finds notes that match keywords in database_name. The note(s) that are returned must be converted to base 16. Example base_convert($note_id, "10", "16") */STATUS LNPUBLIC file_action (void *, SEARCH_MATCH *, ITEM_TABLE *);STATUS LNPUBLIC print_file_summary (ITEM_TABLE *);PHP_FUNCTION(notes_search){ int argc; pval *argv[2]; STATUS error; DBHANDLE db_handle; HANDLE search_handle; /* handle to a search */ pval **db; pval **keywords; char error_string[200]; FT_INDEX_STATS Stats; /* statistics from FTIndex */ DWORD RetDocs; /* number of documents returned by the search */ HANDLE SearchResults_handle; /* handle to the results of the search */ FT_SEARCH_RESULTS *pSearchResults; /* pointer to the results of the search */ HANDLE IDTable_handle; /* handle to id table built with found NOTEIDs */ NOTEID *pNoteID; /* pointer to the NOTEIDs found */ BYTE *pScores; /* pointer to the scores */ DWORD i; argc = ARG_COUNT(ht); if (getParametersArray(ht, argc, argv) == FAILURE){ WRONG_PARAM_COUNT; } if (zend_get_parameters_ex(2, &db, &keywords)==FAILURE) { RETURN_FALSE; } convert_to_string_ex(db); convert_to_string_ex(keywords); 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)){ OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to open database: %s", error_string); NotesTerm(); RETURN_FALSE; } error = FTIndex(db_handle, FT_INDEX_AUTOOPTIONS, NULL, &Stats); if (error){ 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 = FTOpenSearch(&search_handle)){ NSFDbClose (db_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Unable to open search: %s", error_string); NotesTerm(); RETURN_FALSE; } /* do the search on the query */ error = FTSearch (db_handle, /* database handle */ &search_handle, /* pointer to previously allocated search handle */ (HCOLLECTION) NULLHANDLE, /* no collection specified - query all docs */ Z_STRVAL_PP(keywords), /* query string */ FT_SEARCH_SCORES | /* find relevancy scores */ FT_SEARCH_STEM_WORDS, /* find word variants */ 0, /* maximum number of docs to return; 0 = unlimited */ NULLHANDLE, /* no refining IDTABLE */ &RetDocs, /* returned number of docs */ NULL, /* reserved */ &SearchResults_handle); /* returned info */ if (error){ FTCloseSearch (search_handle); NSFDbClose (db_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error during searchkkk: %s", error_string); NotesTerm(); RETURN_FALSE; } /* return if no document in the result */ if (RetDocs == 0 ) { php_printf("\n0 documents returned \n"); FTCloseSearch (search_handle); NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } pSearchResults = OSLock (FT_SEARCH_RESULTS, SearchResults_handle); /* Create an IDTABLE to further refine our search */ if (error = IDCreateTable(sizeof(NOTEID), &IDTable_handle)) { FTCloseSearch (search_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error creating ID table: %s", error_string); NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } /* set up a pointer to the array of note id's that occur after the FT_SEARCH_RESULTS structure */ pNoteID = (NOTEID *) (((char *) pSearchResults) + sizeof(FT_SEARCH_RESULTS)); pScores = (BYTE *) (pNoteID + pSearchResults->NumHits); for (i = 0; i < pSearchResults->NumHits; i++, pNoteID++, pScores++) { /* save the note ids in the IDTABLE */ if (error = IDInsert (IDTable_handle, *pNoteID, NULL)) { OSUnlockObject(SearchResults_handle); OSMemFree (SearchResults_handle); FTCloseSearch (search_handle); IDDestroyTable (IDTable_handle); OSLoadString(NULLHANDLE, ERR(error), error_string, sizeof(error_string)); php_error(E_WARNING,"Error saving note to ID table: %s", error_string); NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } } OSUnlockObject(SearchResults_handle); OSMemFree (SearchResults_handle); if (error = FTCloseSearch(search_handle)) { IDDestroyTable (IDTable_handle); NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } if (error = FTOpenSearch(&search_handle)) { NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } /* do the refined search on the query with no word variants */ error = FTSearch (db_handle, /* database handle */ &search_handle, /* pointer to previously allocated search handle */ (HCOLLECTION) NULLHANDLE, /* no collection specified - query all docs */ Z_STRVAL_PP(keywords), /* query string */ FT_SEARCH_SCORES | /* find relevancy scores */ FT_SEARCH_REFINE, /* refine the search - use the * given id table */ 0, /* maximum number of docs to return; 0 = unlimited */ IDTable_handle, /* refining IDTABLE */ &RetDocs, /* returned number of docs */ NULL, /* reserved */ &SearchResults_handle); /* returned info */ if (error) { FTCloseSearch (search_handle); IDDestroyTable (IDTable_handle); NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } /* return if no document in the result */ if (RetDocs == 0 ) { php_printf("\n0 documents returned \n"); FTCloseSearch (search_handle); IDDestroyTable (IDTable_handle); NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } /* obtain a pointer to the search results */ pSearchResults = OSLock (FT_SEARCH_RESULTS, SearchResults_handle); /* set up a pointer to the array of note id's that occur after the FT_SEARCH_RESULTS structure */ pNoteID = (NOTEID *) (((char *) pSearchResults) + sizeof(FT_SEARCH_RESULTS)); /* pSearchResults->NumHits */ array_init(return_value); pScores = (BYTE *) (pNoteID + pSearchResults->NumHits); for (i = 0; i < pSearchResults->NumHits; i++, pNoteID++, pScores++){ add_next_index_long(return_value, (long) *pNoteID ); /* RETVAL_LONG( (long) *pNoteID ); */ } OSUnlockObject (SearchResults_handle); OSMemFree (SearchResults_handle); IDDestroyTable (IDTable_handle); if (error = FTCloseSearch(search_handle)) { NSFDbClose (db_handle); NotesTerm(); RETURN_FALSE; } NSFDbClose (db_handle); NotesTerm();}/* }}} */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -