Location: PHPKode > projects > Community Learning Network > cln/modules/phpDigSearch/phpDigSearch.php
<?php
/*
 * phpDig Search Module for the CLN Class
 *
 * Copyright (c) 2003-4 St. Christopher House
 *
 * Developed by The Working Group Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * @version $Id: phpDigSearch.php,v 1.13 2005/01/22 23:03:16 cbooth7575 Exp $
 *
 */

require_once('Cln_Module.php');
if(!defined('TABLE_KB_phpDigSearch')) define('TABLE_KB_phpDigSearch', 'modsearch');

class Cln_Module_phpDigSearch extends Cln_Module
{

	/*
	 *
	 * Class Attributes:  Cln_Module_phpDigSearch
	 *
	 * 		The attributes for this class are:
	 *
	 *		TBD
	 *
	 */
	var $phpDigSearchId;


	/***********************************************************************************
	 *
	 * Externally accessed methods
	 *
	 **********************************************************************************/

	/*
	 *
	 * Function:  Cln_Module_phpDigSearch()
	 *
	 * 		Class Constructor
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function Cln_Module_phpDigSearch($phpDigSearchId, $passedData = FALSE)
	{
		d('SearchMod: ' . $phpDigSearchId . ': Cln_Module_phpDigSearch Constructor');
		$this->phpDigSearchId = $phpDigSearchId;
	}


	/*
	 *
	 * Function:  getContent()
	 *
	 * 		Returns the search form and results from the DB
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getContent()
	{
		d('SearchMod: ' . $this->phpDigSearchId . ': getContent');
		
		$this->registerStylesheet(CLN_CLEAN_URL_BASE . MOD_CLN_MODULE_PHPDIGSEARCH_PATH . 'style/phpDigSearch.css');
		
		return $this->getSearch();
	}


	/*
	 *
	 * Function:  getEditPanelGeneral()
	 *
	 * 		Returns the general edit panel components
	 *
	 * @access public
	 * @return String 		$message
	 *
	 */
	function getEditPanelGeneral()
	{
		$generalParts = Array();

		if($_SESSION['User']->isSuperUser()) {
			$generalParts[0]['title'] = 'Configure the search';
			$generalParts[0]['description'] = 'Administer the search.  Open this in a new window.';
			$generalParts[0]['link'] = CLN_BASE_URL . MOD_CLN_MODULE_PHPDIGSEARCH_PATH . 'admin/index.php';
		}

		return $generalParts;
	}


	/*
	 *
	 * Function:  getEditPanelLanguages()
	 *
	 * 		Returns the language specific edit panel components
	 *
	 * @access public
	 * @return String 		$message
	 *
	 */
	function getEditPanelLanguages()
	{
		$specificParts = Array();
		return $specificParts;
	}


	/*
	 *
	 * Function:  getEditContent()
	 *
	 * 		Returns the edit form for this module
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getEditContent($override = FALSE)
	{
		d('SearchMod: ' . $this->phpDigSearchId . ': getEditContent');
		if (!isset($_POST['editSearchBlockFormSubmit']) || $override) {
			ob_start();
			include(MOD_CLN_MODULE_PHPDIGSEARCH_PATH . 'phpDigSearchEditForm.php'); //:TODO: Is this even called? Doesn't seem to be...look further into this....
			$content = ob_get_contents();
			ob_end_clean();
			return $content;
		}
		else {
			return FALSE;
		}
	}


	/*
	 *
	 * Function:  getPublishData()
	 *
	 * Should return an array of all the data from an object that is needed by another
	 * object to publish it.
	 *
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getPublishData()
	{
		$returnVal = Array();
		return $returnVal;
	}


	/*
	 *
	 * Function:  publish()
	 *
	 * Should take an array of all the data from an object that is needed by another
	 * object to publish it.
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function publish($publishData = FALSE)
	{
		return $this->saveModuleData();
	}

	/*
	 *
	 * Function:  saveModuleData()
	 *
	 * 		Saves the KO
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function saveModuleData()
	{
		d('SearchMod: ' . $this->phpDigSearchId . ': getEditContent');
		$db = &Cln_Db::singleton(MAIN_CLN_DSN);

		// New module
		if ($this->phpDigSearchId == 'NEW') {
			$this->phpDigSearchId = $db->nextId(TABLE_KB_phpDigSearch);
			$sql = sprintf("INSERT INTO %s SET phpDigSearchId = '%s', created = NOW();",
							TABLE_KB_phpDigSearch, $this->phpDigSearchId);
		}
		// Existing module
		else {
			$sql = sprintf('UPDATE %s SET modified = NOW() WHERE phpDigSearchId = %d',
								TABLE_KB_phpDigSearch, $this->phpDigSearchId);
		}

		$result = $db->query($sql);
		if (PEAR::isError($result))	 {
			PEAR::raiseError('ADMIN_EM_DB_ERROR_INSERT', E_USER_ERROR);
			PEAR::raiseError("Error on search ko insert/update: $sql", E_ERROR);
			return FALSE;
		}
		else {
			$this->updateModified();
			return $this->phpDigSearchId;
		}

	}


	/***********************************************************************************
	 *
	 * Internally accessed methods
	 *
	 **********************************************************************************/

	/*
	 *
	 * Function:  loadModuleData()
	 *
	 * 		Loads the Database data
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function loadModuleData()
	{
		d('SearchMod: ' . $this->phpDigSearchId . ': getEditContent');

	}


	/*
	 *
	 * Function:  getSearch()
	 *
	 * 		Returns the formatted search form and results
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function getSearch()
	{
		ob_start();

		$relative_script_path = substr(MOD_CLN_MODULE_PHPDIGSEARCH_PATH, 0, strlen(MOD_CLN_MODULE_PHPDIGSEARCH_PATH) - 1);

		if (is_file("$relative_script_path/includes/config.php")) {
			include "$relative_script_path/includes/config.php";
		}
		else {
			die("Cannot find config.php file.\n");
		}
		$GLOBALS['phpdig_words_chars'] = $phpdig_words_chars;
		$GLOBALS['viewKoId'] = $this->_super->koId;

		if (is_file("$relative_script_path/libs/search_function.php")) {
			include "$relative_script_path/libs/search_function.php";
		}
		else {
		   die("Cannot find search_function.php file.\n");
		}

		// extract vars
		extract(phpdigHttpVars(
			 array('query_string'=>'string',
				   'refine'=>'integer',
				   'refine_url'=>'string',
				   'site'=>'integer',
				   'limite'=>'integer',
				   'option'=>'string',
				   'lim_start'=>'integer',
				   'browse'=>'integer',
				   'path'=>'string'
				   )
			 ));
			 
		phpdigSearch($id_connect, $query_string, $option, $refine,
					  $refine_url, $lim_start, $limite, $browse,
					  '', '', $relative_script_path, $template);
		// :NOTE: I had to set the 9th and 10th variables above to ''
		//			instead of $site and $path because it was causing
		//			problems, $path especially.

		$searchHTML = ob_get_contents();
		ob_end_clean();
		return $searchHTML;
	}


	/*
	 *
	 * Function:  delete()
	 *
	 * 		Deletes the object
	 *
	 * @access public
	 * @return TBD
	 *
	 */
	function delete()
	{
		$sql = sprintf('DELETE FROM `%s` WHERE phpDigSearchId = %d LIMIT 1', TABLE_KB_phpDigSearch, $this->phpDigSearchId);
		$db = &Cln_Db::singleton(MAIN_CLN_DSN);
		$result = $db->query($sql);

		if (PEAR::isError($result)) {
			PEAR::raiseError("There was an error deleting the Search mod part: $sql", E_ERROR);
			return FALSE;
		}
		else {
			return TRUE;
		}
	}
}

//********************************************************************

?>
Return current item: Community Learning Network