Miscellaneous Code

  Home arrow Miscellaneous Code arrow classKurs
MISCELLANEOUS CODE

classKurs
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2002-11-11

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    classKurs is a PHP class that lets you grab Bank Indonesia's content of kurs, then put the content on a single file. The grabber can be set as cron job. There is also the function to show the grabbed file in formated html tags, ready to go.

    By : hermawan

    <?php
    /***********************************************
    * Class Name : classKurs *
    * Scripted By : Hermawan Haryanto *
    * Website : http://hermawan.com *
    * Email : hermawan@codewalkers.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 Homepage\n";
    $message.= "Kurs Module (".$_SERVER["SERVER_NAME"].")is generating this Error.\n";
    $message.= "Please check!.\n\n";
    $message.= "[MalFunction]";
    $headers.= "From: Hermawan Haryanto <hermawan@dmonster.com>\r\n";
    $headers.= "Reply-To: Hermawan Haryanto <hermawan@haryan.to>\r\n";
    $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);
    ?>

    Click to Download File



    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

    More Miscellaneous Code Articles
    More By Codewalkers

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap