<?php
/*-------1---------2---------3---------4---------5---------6---------7---------8---*/
// +----------------------------------------------------------------------+
// | PHP version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The YHA (Yono Hendro Arie) Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | hide@address.com so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | ISIS base class |
// +----------------------------------------------------------------------+
// | Authors: Arie Nugraha <hide@address.com> |
// | Quality Assurance: Hendro Wicaksono <hide@address.com> |
// +----------------------------------------------------------------------+
//
// $Id$
# Some method in this class needs global variable
# from coonfiguration file
class isis_base
{
# properties
var $isis_opt = '-v error -format aligned -encoding ISO8859_1';
var $isis_db = '';
var $isis_link = false;
var $isis_db_conf = array();
# class constructor
function isis_base($isisdb = '')
{
$this->_is_isis_loaded();
// if there is no database defined run the auto set method
if (!$isisdb) {
$this->_auto_set_isis_db();
} else {
$this->isis_db = $isisdb;
}
$this->_parse_db_conf();
$this->_isis_conn();
}
# private function to set ISIS database
function _auto_set_isis_db()
{
global $glb;
if (isset($_GET['dbinfo'])) {
$this->isis_db = $_GET['dbinfo'];
} else {
$this->isis_db = $glb['default_db'];
}
}
# private method to parse db specific configuration file
function _parse_db_conf()
{
global $glb;
if (file_exists($glb['dbconf_dir'].'/'.$this->isis_db.'.ini')) {
$this->isis_db_conf = parse_ini_file($glb['dbconf_dir'].'/'
.$this->isis_db.'.ini', true);
return true;
} else {
return false;
}
}
# private method to check if ISIS extension is loaded yet
function _is_isis_loaded()
{
if (extension_loaded('isis')) {
return true;
} else {
die("PHP-openisis extension is not loaded yet.<br>\n
Please check your <b>php.ini</b> and php extensions directory
for PHP-openisis library.");
}
}
# private method to to make connection to ISIS database
function _isis_conn()
{
$open = @isis_open($this->isis_db_conf['main']['location'].$this->isis_db_conf['main']['name'], $this->isis_opt);
if ($open) {
$this->isis_link = $open;
} else {
echo "<b>Can't make connection to <font color='#FF0000'>".strtoupper($this->isis_db)."</font> ISIS database</b>";
}
}
# protected function to parse ccl
function _parse_ccl($array_result, $mode = 'detail')
{
global $glb;
foreach ($array_result as $key => $value) {
if (is_array($value)) {
// if the remove_all parameter is set to 1, than remove all ISIS subfields character
if ($this->isis_db_conf["ccl_".$mode]['remove_all']) {
$value[1] = htmlentities($value[1]);
$value[1] = preg_replace("/\^[a-z]{1,1}|<|>/i", '', $value[1]);
} else {
// db conf tag checking
if (isset($this->isis_db_conf["ccl_".$mode][$value[0]])) {
if (strpos($this->isis_db_conf["ccl_".$mode][$value[0]], ',') === false) {
if (strpos($this->isis_db_conf["ccl_".$mode][$value[0]], '->')) {
$subfield_char = substr_replace($this->isis_db_conf["ccl_".$mode][$value[0]], '', 1);
$subfield_repl = substr_replace($this->isis_db_conf["ccl_".$mode][$value[0]], '', 0, 3);
$value[1] = preg_replace("/(\^".$subfield_char.")/i", $subfield_repl, $value[1]);
} else {
$value[1] = preg_replace("/(\^".$this->isis_db_conf["ccl_".$mode][$value[0]].")/i", '', $value[1]);
}
} else {
$subfield_arr = explode(',', $this->isis_db_conf["ccl_".$mode][$value[0]]);
// checking tag subfields
foreach ($subfield_arr as $subfield) {
if (strpos($subfield, '->')) {
$subfield_char = substr_replace($subfield, '', 1);
$subfield_repl = substr_replace($subfield, '', 0, 3);
$value[1] = preg_replace("/(\^".$subfield_char.")/i", $subfield_repl, $value[1]);
} else {
$value[1] = preg_replace("/(\^".$subfield.")/i", '', $value[1]);
}
}
}
}
}
$parsed_array_result[$key] = array($value[0], $value[1]);
} else {
$parsed_array_result['mfn'] = $value;
}
}
return $parsed_array_result;
}
# public function to get title word from MFN
function get_title_from_mfn($mfn, $titletag)
{
$_mfn = (integer)$mfn;
$_titletag = $titletag;
$_titleword = '';
// get the detail
$_result_detail = @isis_fetch_flat_array_from_mfn($_mfn, $this->isis_link);
if (!$_result_detail) {
// return false;
return "Can't find title for this
MFN (<b>".$this->isis_db."</b> database)";
isis_close($this->isis_link);
}
// loop the result and search for title word
foreach ($_result_detail as $key => $value) {
if (is_array($value)) {
if (!isset($i)) {
$i = "0";
} else {
$i = "0";
}
foreach ($value as $subkey => $subvalue) {
$i++;
if ($i == ($i % 2 == "1")) {
$temptag = $subvalue;
}
if ($i == ($i % 2 == "0")) {
if ($temptag == $_titletag) {
$_titleword = htmlspecialchars($subvalue);
}
}
}
}
}
isis_close($this->isis_link);
return $_titleword;
}
}
?>