<?php
/***********************************************
* Class Name : classKurs *
* Scripted By : Hermawan Haryanto *
* Website : http://hermawan.dmonster.com *
* Email : hermawan@dmonster.com *
* License : GPL (General Public License) *
* Created Date : 09/08/2001 *
* Last Update : 11/11/2002 *
* Instruction : Read INSTALL *
***********************************************/
class kurs {
var $admin;
var $file;
var $graburl;
var $chop;
var $choptitle;
var $jual = Array ();
var $beli = Array ();
var $titles = Array ();
var $temp;
function kurs() {
global $conf;
$this->admin = $conf["admin"];
$this->file = $conf["file"];
$this->graburl = $conf["graburl"];
$this->chop = $conf["chop"];
$this->choptitle = $conf["choptitle"];
$this->textTitle = $conf["textTitle"];
$this->textKurs = $conf["textKurs"];
$this->textBuy = $conf["textBuy"];
$this->textSell = $conf["textSell"];
}
function writeToFile() {
$fp = fopen($this->file,"w+");
@fwrite($fp,$this->temp);
@fclose($fp);
}
function grab() {
$fp = fopen ($this->graburl,"r");
$fp2 = fopen ($this->graburl,"r");
if (!$fp) {
$this->sendAdminError();
exit();
}
$this->getKurs ($fp);
$this->getTitles ($fp2);
$this->formatText();
$this->writeToFile();
}
function formatText() {
for ($i=0;$i<count($this->titles);$i++) {
$this->temp .= $this->titles[$i]."|".$this->jual[$i]."|".$this->beli[$i]."|".time()."n";
}
}
function getTitles ($fp) {
while(!feof($fp)){
$data = fgets($fp, 4096);
if(ereg($this->choptitle,$data,$arr)) $this->titles[] = trim($arr[1]);
}
}
function getKurs($fp) {
while(!feof($fp)){
$data = fgets($fp, 4096);
if(ereg($this->chop,$data,$arr)){
if ($i%2==0) $this->jual[] = str_replace(",","",trim($arr[1]));
else $this->beli[] = str_replace(",","",trim($arr[1]));
$i++;
}
}
}
function sendAdminError() {
$to = $this->admin;
$subject = "Kurs::Error";
$message = "Your Homepagen";
$message.= "Kurs Module (".$_SERVER["SERVER_NAME"].")is generating this Error.n";
$message.= "Please check!.nn";
$message.= "[MalFunction]";
$headers.= "From: Hermawan Haryanto <hermawan@dmonster.com>rn";
$headers.= "Reply-To: Hermawan Haryanto <hermawan@haryan.to>rn";
$headers.= "X-Mailer: Hermawan Haryanto";
@mail($to,$subject,$message,$headers);
}
function show() {
$fp = @file($this->file);
$rtn .= "<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td><table width=100% border=0 cellpadding=2 cellspacing=1 bgcolor=#EEEEEE><tr class=header><td align=center valign=middle>$this->textTitle</td></tr><tr><td align=center valign=middle bgcolor=#FFFFFF><table width=100% border=0 cellspacing=1 cellpadding=2><tr align=center valign=top bgcolor=#CCCCCC class=subtitle><td>$this->textKurs</td><td width=100>$this->textSell</td><td width=100>$this->textBuy</td></tr>";
for ($i=0;$i<count($fp);$i++) {
list ($mtu, $jual, $beli, $lastupdate) = explode("|", $fp[$i]);
$rtn .= "<tr align=left valign=top class=body><td>$mtu</td><td>Rp.".number_format($jual,2,",",".")."</td><td>Rp.".number_format($beli,2,",",".")."</td></tr>";
}
$rtn .= "</table></td></tr><tr><td align=center valign=middle class=body>Update : ".date("j/n/Y H:i:s",$lastupdate)."</td></tr></table>";
$rtn .= "</td></tr><tr><td align=center>";
$rtn .= "<a href="http://www.bi.go.id/bank_indonesia2/moneter/kurs_valuta/default.asp">Bank Indonesia</a>";
$rtn .= "</td></tr></table>";
return $rtn;
}
}; $fixpath = dirname(__FILE__);
require_once ($fixpath."/ckConfig.php"); $kurs = new kurs($conf); ?>
|
|