Location: PHPKode > scripts > CISVC > cisvc/cisvcclass.inc.php
<?php

class CISVC {
	/*	Class to use MS Content Index Server COM Object
	* 	v0.1	First attempt.
	* 	By Eric Chipko, Houston, Texas USA (hide@address.com)
	* 	tested on Windows 2000 with SP3 and IIS 5.0
	* 	Purpose : Query Content Index Service default catalog (WEB if IIS is installed) and return a Record set with hits.
	* 	This record set can then be displayed using provided methods 
	* 	HTMLShowPage()
	* 	HTMLNavBar()
	* 	HTMLPageSummary()
	* 	Future version will include additional methods for other types of display like XML.
	*/
	var $strSearchString;
	var $oQ;				// ixsso.Query
	var $oUtil;				// ixsso.util		Not currently used for anything.
	var $RS;				// Record Set from Query
	var $strColumns; 		// Columns in RecordSet
	var $iRecordCount;		// Total hits in Record Set
	var $iPageCount;		// total number of pages in record set
	var $iPageSize;			// total number of documents in page
	var $iCurrPage;
	var $iFirstDocinPage;	// Item number of the first document in the page within the entire recordset
	var $iLastDocinPage;	// Item number of the last document in the page within the entire recordset
	var $bOutofDate;		// Shows whether the Query is out of date.
	var $bIncomplete;		// Shows whether the Query is incomplete.
	var $bTimedOut;			// Shows whether the Query Timed Out.


	function cisvc ($strSearchString, $iCurrPage = 0, $iPageSize=10, $strColumns="doctitle, vpath, path, filename, characterization, size, write")
	{	/*	$strSearchString = String to seek.
		* 	$iCurrPage		 = page offset in the record set (0 indexed)
		* 	$iPageSize		 = no of items in a page set.  If specified at non-default value, it must be specified on every call and the same on every call.
		*   $strColumns		 = entries to seek from the database 
		* 						doctitle, vpath, path, and  filename are mandatory for the HTMLShowPageMethod to be used.
		* 						characterization, size, write are optional.
		*/
		$this->strSearchString = $strSearchString;
		$this->oQ = new COM("ixsso.Query");
		$this->oUtil = new COM ("ixsso.Util");
		$this->oQ->Query = $strSearchString;
		$this->oQ->SortBy = "rank[d]";
		$this->oQ->Columns = $strColumns;
		$this->strColumns = $strColumns;
		$this->RS = $this->oQ->CreateRecordSet ("nonsequential");
		

		$this->iRecordCount = $this->RS->RecordCount;
		if ($this->iRecordCount > 0 ) {
			$this->iCurrPage = $iCurrPage;
			$this->iPageSize = $iPageSize;
			$this->RS->PageSize=$iPageSize;
			$this->iPageCount = ceil($this->iRecordCount / $iPageSize);
			$this->iFirstDocinPage = ($this->iCurrPage * $iPageSize) + 1;
			$this->RS->AbsolutePage = $this->iCurrPage+1;				// Absolute Position is 1 based?
			if ($this->iRecordCount < $this->iPageSize ) {
				$this->iLastDocinPage = $this->iRecordCount;
			} else {
				$this->iLastDocinPage = $iPageSize*($iCurrPage+1);
			}  // end if iRecordCount < iPageSize
			$this->bOutofDate = $this->oQ->OutofDate;
			$this->bIncomplete = $this->oQ->QueryIncomplete;
			$this->bTimedOut = $this->oQ->QueryTimedOut;
		}  // end if iRecordCount > 0
		
	} // end function cisvc ** Constructor
	
	
	function HTMLShowPage()
	{	// Output the results of the RS in a suitable fashion.  Mininimal use of formatting is used in favor of CSS to give caller maximal display control.
	    // Hoping to find a way to use CSS instead of <dl><dt><dd> to get suitable indentation.
		$iRecordNum = $this->iFirstDocinPage;
		echo "<dl>";
		while (!$this->RS->EOF and $iRecordNum <= $this->iLastDocinPage ) {
			echo "<dt>".$iRecordNum.". ";
			if ( empty ($this->RS->Fields["doctitle"]->value) or 
				        $this->RS->Fields["doctitle"]->value == "" or
						$this->RS->Fields["doctitle"]->value == "0") {
				echo ("<a href=\"".$this->RS->Fields["vpath"]->value."\" class=\"doctitle\">".htmlentities($this->RS->Fields["filename"]->value)."</a>\n");
			} else {
				echo ("<a href=\"".$this->RS->Fields["vpath"]->value."\" class=\"doctitle\">".htmlentities($this->RS->Fields["doctitle"]->value)."</a>\n");
			}  // end if doctitle Empty
			echo "<br/><dd>";
			if ( stristr($this->strColumns,"characterization") ) {
    			if (is_string($this->RS->Fields["characterization"]->value) and $this->RS->Fields["characterization"]->value <> "") {
    				echo ("<span class=\"wdAbstract\">Abstract:  </span>");
    				echo ("<span class=\"characterization\">".htmlentities($this->RS->Fields["characterization"]->value)."</span><br>\n");
    			}  // end if has characterization
			}  // end if stristr
			
			echo "<span class=\"url\">.<a href=\"".$this->RS->Fields["vpath"]->value."\">http://".$_SERVER['SERVER_NAME'].$this->RS->Fields["vpath"]->value."</a></span>";
			//													Want to figure out how to capture when this server is indexing others. To correct link above.
			if ( stristr($this->strColumns,"size") ) {
				echo "<span class=\"filesize\">"." - ";
				if ($this->RS->Fields["size"]->value == "") {
					echo "(size unknown)</span>";
				 } else {
					echo "size ".$this->RS->Fields["size"]->value." bytes</span>";
				 }
			}  // end if stristr

			if ( stristr($this->strColumns,"write") ) {
				echo "<span class=\"filetime\">"." - ";
				if ($this->RS->Fields["write"]->value == "" or (int)$this->RS->Fields["write"]->value < 100 ) {
					echo "(time unknown)</span>";
				 } else {
					echo " ".date("Y-m-d g:i:s A",$this->RS->Fields["write"]->value)." GMT</span>";
				 }
			}  // end if stristr

			echo "</dd>";
			$this->RS->MoveNext();
			++$iRecordNum;
		} 	// end while
		echo "</dl>";
	}	// end function HTMLShowPage
	
	function HTMLShowMessages () 
	{
		if ($this->bOutOfDate) { 	echo ("<p class=\"qmessage\">The index is out of date</p>"); }
		if ($this->bIncomplete) {	echo ("<p class=\"qfail\">The query is too expensive to complte</p>"); }
		if ($this->bTimedOut) {		echo ("<p class=\"qfail\">The query took to long to complte</p>");	}
	}  // end function HTMLShowMessages

	function HTMLNavBar ()
	{
		echo "\n<table border=\"0\"><tr>\n";
		if ($this->iCurrPage > 0 ) {
			// Optional previous button if not on first page.
			echo "<td align=\"left\">"."<form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"post\"/>\n";
			echo "<input type=\"hidden\" name=\"SearchString\" value=\"".$this->strSearchString."\"/>\n";
			echo "<input type=\"hidden\" name=\"pg\" value=\"".((int)$this->iCurrPage -1)."\"/>\n";
			echo "<input type=\"submit\" value=\"Previous ".$this->iPageSize." documents\"/>";
			echo "</form></td>\n";
		}  // end if $iCurrPage > 0
		if (!$this->RS->EOF) {
			// Optional Next button if not on last page.
			echo "<td align=\"right\"><form action=\"".$_SERVER['SCRIPT_NAME']."\" method=\"post\">\n";
			echo "<input type=\"hidden\" name=\"SearchString\" value=\"".$this->strSearchString."\"/>";
			echo "<input type=\"hidden\" name=\"pg\" value=\"".((int)$this->iCurrPage+1)."\"/>";
			$strButtonText = "Next ";
			if ($this->iRecordCount - $this->iLastDocinPage < $this->iPageSize) {
				$strButtonText .= $this->iRecordCount - $this->iLastDocinPage. " documents";
			} else {
				$strButtonText .= " page of documents";
			}
			echo "<input type=\"submit\" value=\"".$strButtonText."\"";
			echo "</form></td>\n";
		}  // end if not RS-EOF
		
		echo "</tr></table>\n";
	}  // end function HTMLNavBar
	
	function HTMLPageSummary ()
	{
		echo "Page ".((int)$this->iCurrPage+1);
		if ($this->iPageCount > 1 ) { echo " of ".$this->iPageCount;}
		
	}  // end function HTMLPageSummary
	
} // end class cisvc

?>
Return current item: CISVC