<?
//error_reporting(E_ALL ^ E_NOTICE);
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
//***************************************************
// http://www.niadesain.com
// Solusi Hemat Script Bisnis Online Anda
// Menerima Jasa Pembuatan Website & Template Website
//***************************************************
?>
<?
	class db_layout {  
		var $classname="db_layout";  
		var $db_name;  
		var $db_user;  
		var $db_password;  
		var $db_host;  
		var $db_link_ptr;  
		var $tables;  
		var $fields;  
	}  
	class db_mysql extends db_layout {  
		var $classname="db_mysql";  
		var $db_result;  
		var $db_affected_rows;  
		var $saved_results=array();  
		var $results_saved=0;  
		function error($where="",$error,$errno) {  
			echo "$where<br>";  
			die($error."<br>".$errno);  
		}  

function error_msg() {  
			return mysql_error();  
		}  

function PushResults() {  
			$this->saved_results[$this->results_saved]=array($this->db_result,$this->db_affected_rows);  
			$this->results_saved++;  
		}  

function PopResults() {  
			$this->results_saved--;  
			$this->db_result=$this->saved_results[$this->results_saved][0];  
			$this->db_affected_rows=$this->saved_results[$this->results_saved][1];  
		}  

function db_mysql($host, $user, $passwd, $db, $create="") {  
			$this->db_name=$db;  
			$this->db_user=$user;  
			$this->db_passwd=$passwd;  
			$this->db_host=$host;  
			$this->db_link_ptr=@mysql_connect($host,$user,$passwd) or $this->error("",mysql_error(),mysql_errno());  
			$this->dbhandler=@mysql_select_db($db);  
			if (!$this->dbhandler) {  
				if ($create=="1")  {  
					@mysql_create_db($db,$this->db_link_ptr) or $this->error("imposible crear la base de datos.",mysql_error(),mysql_errno());;  
					$this->dbhandler=@mysql_select_db($db);  
				}  
			}  
		}  

function reselect_db($db){  
			$this->dbhandler=@mysql_select_db($db);  
		}  

function closeDB() {  
		@mysql_close($this->db_link_ptr);  
		}  

function create_table($tblName,$tblStruct) {  
			if (is_array($tblStruct)) $theStruct=implode(",",$tblStruct); else $theStruct=$tblStruct;  
			@mysql_query("create table $tblName ($theStruct)") or $this->error("create table $tblName ($theStruct)",mysql_error(),mysql_errno());  
		}  

function drop_table($tblName) {  
			@mysql_query("drop table if exists $tblName") or $this->error("drop table $tblName",mysql_error(),mysql_errno());  
		}  

function raw_query($sql_stat) {  
			$this->db_result=@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());  
			$this->db_affected_rows=@mysql_num_rows($this->db_result);  
		}  

function count_records($table,$filter="") {  
			$this->db_result=@mysql_query("select count(*) as num from $table".(($filter!="")?" where $filter" : ""));  
			$xx=@mysql_result($this->db_result,0,"num");  
			return $xx;  
		}  

function select($fields,$tables,$where="",$order_by="",$group_by="",$having="",$limit="") {  
			$sql_stat=" select $fields from $tables ";  
			if (!empty($where)) $sql_stat.="where $where ";  
			if (!empty($group_by)) $sql_stat.="group by $group_by ";  
			if (!empty($order_by)) $sql_stat.="order by $order_by ";  
			if (!empty($having)) $sql_stat.="having $having ";  
			if (!empty($limit)) $sql_stat.="limit $limit ";  
			$this->db_result=@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());  
			$this->db_affected_rows=@mysql_num_rows($this->db_result);  
			return $sql_stat;  
		}  
		function list_tables() {  
			$this->db_result=@mysql_list_tables($this->db_name);  
			$this->db_affected_rows=@mysql_num_rows($this->db_result);  
			return $this->db_result;  
		}  

function describe($tablename) {
                        $this->result=@mysql_query("describe $tablename");
                }

function table_exists($tablename) {
                        $this->pushresults();
                        $description=$this->describe($tablename);
                        $this->popresults();
                        if ($description) $exists=true; else $exists=false;
                        return $exists;
                }

function tablename($tables, $tbl) {  
			return mysql_tablename($tables,$tbl);  
		}  

function insert_id() {  
			return mysql_insert_id();  
		}  

function insert($table,$fields="",$values="") {  
			$sql_stat="insert into $table ";  
			if (is_array($fields)) $theFields=implode(",",$fields); else $theFields=$fields;  
			if (is_array($values)) $theValues="'".implode("','",$values)."'"; else $theValues=$values;  
			$theValues=str_replace("'now()'","now()",$theValues);  
			if (!empty($theFields)) $sql_stat.="($theFields) ";  
			$sql_stat.="values ($theValues)";  
			@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());  
		}  

function update($table,$newvals,$where="") {  
			if (is_array($newvals)) $theValues=implode(",",$newvals); else $theValues=$newvals;  
			$sql_stat="update $table set $theValues";  
			if (!empty($where)) $sql_stat.=" where $where";  
			@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());  
		}  

function delete($table,$where="") {  
			$sql_stat="delete from $table ";  
			if (!empty($where)) $sql_stat.="where $where ";  
			$db_result2=@mysql_query($sql_stat) or $this->error($sql_stat,mysql_error(),mysql_errno());  
			$this->db_affected_rows=@mysql_affected_rows($this->db_result2);  
		}  

function free() {  
			@mysql_free_result($this->db_result) or $this->error("",mysql_error(),mysql_errno());  
		}  

function fetch_row() {  
			$row=mysql_fetch_row($this->db_result);  
			return $row;  
		}  

function result($recno,$field) {  
			if($this->num_rows() > 0) {
				return mysql_result($this->db_result,$recno,$field);  
			}	
		}  

function num_fields(){  

			return mysql_num_fields($this->db_result);  

		}  

		  

		function fetch_array() {  

			$row=mysql_fetch_array($this->db_result);  

			return $row;  

		}  

  

		function fetch_field() {  

			$row=mysql_fetch_field($this->db_result);  

			return $row;  

		}  

		function num_rows() {  

			$row=mysql_num_rows($this->db_result);  

			return $row;  

		} 

		function dataku($field, $username) {

			$this->select($field, "banner_kanan", "username='$username'");

			if($this->num_rows() > 0) {

				$dt = $this->result(0,$field); 

			}	

			return $dt;

		}	

		function subkat($kat,$sub) {

			$this->select($kat, "katagori", "sub='$sub'");

			$dt = $this->result(0,$kat); 

			return $dt;

		}	

		function data($field, $table, $cond) {

			$this->select($field, $table, $cond);

			$dt = $this->result(0, $field);

			return $dt;

			

		}	

		function iklan_lama($username) {

	//$sql=myquery("select * from iklan where userid='$username' and status=1");

	//$j = mysql_num_rows($sql);

			$this->select("no, judul", "iklan", "userid='$username' and status=0");

			$j = $this->num_rows();

			if($j > 0) {

				$ada = $j;

			} else {

				$ada = 0;

			}

			return $ada;

		}	

		function publikasi($username) {

	//$sql=myquery("select * from iklan where userid='$username' and status=1");

	//$j = mysql_num_rows($sql);

			$this->select("no, judul", "berita", "username='$username'");

			$j = $this->num_rows();

			if($j > 0) {

				$ada = $j;

			} else {

				$ada = 0;

			}

			return $ada;

		}	

function datasto($field, $username) {

			$this->select($field, "stockist", "username='$username'");

			if($this->num_rows() > 0) {

				$dt = $this->result(0,$field); 

			}	

			return $dt;

		}
				

		function katiklan($no) {

			$this->select("id, title", "categories", "id='$no'");

			$kat = $this->fetch_row();

			return $kat[1];

		}

		function config($field) {

			//$this->select($field, "configuration", "id=1");

			//$kat = $this->result(0, $field);

			$sql=mysql_query("select $field from configuration where id=1");

			$row=mysql_fetch_row($sql);

			$kat = $row[0];

			return $kat;

		}		

		function setting($field) {
			$sql=mysql_query("select $field from setting where id=1");
			$row=mysql_fetch_row($sql);
			$kat = $row[0];
			return $kat;
		}


		function downline($level, $st, $username) {

			$jdl = 0;

			//$jdl = $this->count_records("member", "sponsor='$username' and status=$st");

			//$jdl = $this->num_rows();

			$sql=mysql_query("select * from banner_kanan where $level='$username' and status=$st");

			$jdl = mysql_num_rows($sql);

			return $jdl;

		}

		

		function klik($username) {

			$cl = 0;

			$this->select("*", "click", "refid='$username'");

			$cl = $this->num_rows();

			return $cl;

		}	

		function totbonus($username, $st, $sp) {

			$tb = 0;

			$sql=mysql_query("select rp1, rp2 from banner_kanan where $sp='$username' and status=$st");

			while($row = mysql_fetch_row($sql)) {

			//$this->select("username, rp1, rp2", "member", "$sp='$username' and status=$st");

				if($sp == "sponsor") {

					$tb = $tb + $row[0];

				} else {

					$tb = $tb + $row[1];

				}	

			}		

			//$acak = substr($db->dataku("rpadmin", $username);

			

			return $tb;

		}	

		//----topmenu--

		

		function topmenu() {

			$sql=$this->select("id, name, alias, link", "menu", "published=1", "ordering");

		//mysql_close();

			$n = $this->num_rows();

			echo "<ul>";

			for($i=0;$i<$n;$i++)

		 	{

				$mx = explode("=", $this->result($i, "link"));

				$ma = $mx[2];

				

				$mb = explode("&", $mx[1]);

				$catid = $mb[1];

				if($m == "contact") {

					$cl = "class=current";

				} else {

					$cl = "";

				}			

				echo "<li><a href='".$this->result($i, "link")."' $cl><span>".$this->result($i, "name")."</span>$m</a></li>";

			}

			echo "</ul>";

		}

		//----end topmenu	

		function delete_html($form_name) 

		{ 



			$form_name = str_replace("[", "", "$form_name"); 

			$form_name = str_replace("]", "", "$form_name"); 

			$not ="\"'*\abcdefghijklmnopqrstuvwxyz1234567890�����������������������=~`@#$%^&*()_{}\n\t\r\ /;:.!?,+-"; 

			$form_name = eregi_replace("(</)+[$not]+(>)", "", "$form_name"); 

			$form_name = eregi_replace("(<)+[$not]+(>)", "", "$form_name"); 

			

			$form_name = str_replace("<", "", $form_name); 

			$form_name = str_replace(">", "", $form_name); 

			$form_name = htmlspecialchars($form_name); 

			

			return $form_name; 

			} 

			//---

		function crops($teks, $jh) {

				

				$ISIBERITA = $teks;

			$b_bagianberita = $jh;

			$TMPBAGIANBERITA = array();

			$TMP = explode(" ", $ISIBERITA);

			for($i=0;$i<=$b_bagianberita;$i++)

			{

				$TMPBAGIANBERITA[$i] = $TMP[$i];

			}

			$BAGIANBERITA = implode(" ", $TMPBAGIANBERITA);	

			

  			$dt=$BAGIANBERITA;

			return $dt;

		} 



		function news($ref) {

			$this->select("id, title, maintext, created", "content", "catid=4 and published=1", "created desc", "", "", "3");

			$ada = $this->num_rows();

			for($i=0;$i<$ada;$i++) {

				$text = $this->result($i, "maintext");

				$tgcr = $this->result($i, "created");

				echo "<h6><a href='?m=news&nid=".$this->result($i, "id")."'>".$this->result($i, "title")."</a></h6>";

				echo "<div class='author'>".formatgl($tgcr)."</div>";

				$text0 = $this->crops($this->delete_html($text), 8);

				echo "$text0...<p><hr>";

			}

		}		

function marketing($ref) {

			$this->select("id, title, maintext, created", "content", "catid=55 and published=1", "created desc", "", "", "");

			$ada = $this->num_rows();

			for($i=0;$i<$ada;$i++) {

				$text = $this->result($i, "maintext");

				$tgcr = $this->result($i, "created");

				$text0 = $this->crops($this->delete_html($text), 8);

				echo "$text";

			}

		}

function newshead($ref) {

			$this->select("id, title, maintext, created", "content", "catid=54 and published=1", "created desc", "", "", "");

			$ada = $this->num_rows();

			for($i=0;$i<$ada;$i++) {

				$text = $this->result($i, "maintext");

				$tgcr = $this->result($i, "created");

				$text0 = $this->crops($this->delete_html($text), 8);

				echo "$text";

			}


		}	

		function dataupline($field, $username) {

			$dup = "";

			$this->select("$field", "upline", "username='$username'");

			$dup = $this->result(0, $field);

			return $dup;

		}	

		
		function dataupline1($field, $username) {
			$dup = "";
			$this->select("$field", "upline", "username='$username'");
			$dup = $this->result(0, $field);
			return $dup;
		}

		function dataupline2($field, $username) {
			$dup = "";
			$this->select("$field", "upline", "username='$username'");
			$dup = $this->result(0, $field);
			return $dup;
		}

		function tree($username) {

			$tr = "";

			$this->select("id", "tree", "username='$username'");

			$tr = $this->result(0, "id");

			return $tr;

		}	

		

		//------------CARI LEVEL-------

		function levelmbr($username, $posisine) {

		$jlv = 0;

		//-----------cari level tertinggi-------------

			$slv="select * from upline order by level desc";

			$rlv=mysql_query($slv);

			

			$slev=mysql_fetch_array($rlv);

			//if($slev["level"] <= 20) {

				$jmlev=$slev["level"];

			//} else {

				//$jmlev = 20;

			//}

	//$jmlev=$slev["level"];

			$sqlki="select a.username, b.status from upline as a inner join banner_kanan as b on a.username=b.username where a.upline0='$username' and a.posisi='$posisine' and b.status=1";



			$rki=mysql_query($sqlki);

			

			$kir=mysql_fetch_array($rki);

			$adaki=mysql_num_rows($rki);

		

			$user=$kir[0];



				

			if ($adaki > 0)

			{

				//$user=$this->result(0, "a.username");

				for($i=0;$i<$jmlev;$i++)

				{

					$sql2="select a.username, b.status from upline as a inner join banner_kanan as b on a.username=b.username where upline$i='$user' and b.status=1";

			

				$res=mysql_query($sql2);

				

				$jml=array();

			//$levkir=array();

				$jml[$i]=mysql_num_rows($res);

			

				$lv= 1 + $i;

			

				if ($jml[$i] > 0)

					{

						$jl=$lv;			

					} 	

				

				}

				$tb = 1;

		

			

				} else {

				$jl=0;

				$tb = 0;

			}

			$jlv = $jl + $tb;

			//echo "level = $jlv";

			return $jlv;

		}

		//-------	
		
		function cocok($username) {
			$mt="";	
			$kia=memberkiri($username, "and b.status=1"); 
			$kaa=memberkanan($username, "and b.status=1"); 

			if($kia > $kaa) {
				$cocok = $kaa;
			} else {
				$cocok = $kia;
			}
			$mt= $cocok;
			return $mt;
		}

		//-----------match-------------

		function match($username) {

			$mt="";	

			//	if($dtgl == "") {

			$kia=memberkiri($username, "and b.status=1"); 

			$kaa=memberkanan($username, "and b.status=1"); 

			//} else {

			//$kia=$this->levelmbr($username, "KIRI"); 

			//$kaa=$this->levelmbr($username, "KANAN"); 

		//	}

			if($kia > $kaa) {

				$match = $kaa;

				$ki_unmatch = $kia - $kaa;

				$ka_unmatch = $kaa - $kia;

			} else {

				$match = $kia;

				$ki_unmatch = $kaa - $kia;

				$ka_unmatch = $kia - $kaa;

			}

			$mt= $match;

			return $mt;

			

		}

		

		//--------jumlah downline 

		function jumlahdl($username, $status) {
			$lev = mysql_query("select level from upline order by level desc");
			$lv = mysql_fetch_row($lev);
				$jmlev = $lv[0];
			for($i=0;$i<9;$i++) {
				$sql=mysql_query("SELECT a.username, b.status FROM upline as a INNER JOIN banner_kanan as b on a.username=b.username WHERE a.upline$i='$username' AND b.status='$status'");
				$ada = mysql_num_rows($sql);
				$td = $td + $ada;
			}
			$jdl = $td;
			return $jdl;
		}
	//----------jumlah poin
		
			function jumlahdlx($username, $status) {
			$lev = mysql_query("select level from upline order by level desc");
			$lv = mysql_fetch_row($lev);
				$jmlev = $lv[0];
				$tkt = $this->config("kedalaman");
			for($i=0;$i<$tkt;$i++) {
				$sql=mysql_query("SELECT SUM (poin) FROM upline a.username, b.poin as a INNER JOIN banner_kanan as b on a.username=b.username WHERE a.upline$i='$username' AND b.poin='$poin'");
				$res = $db->query($sql);
				$total = 0;
                $rec = $db->fetchAssoc($res);
               $total = $rec['count'];

               echo "Total: " . $total . "\n";
			}
			$jdl = $td;
			return $jdl;
		}
		
		//----------end poin	
function jumlahsp($username) {
			$j=0;
			$sql=mysql_query("select username from banner_kanan where sponsor='$username' and status=1");
			$j=mysql_num_rows($sql);
			return $j;
		}
		
		//-----aktivasi--
			function aktivasi($username) {
			$clientdate    = (date ("Y-m-d H:i:s")); //--tgl skr
			$tgl_skr = (date("Y-m-d"));
			$dtfrom = "$tgl_skr 00:00:00";
			$dtto = "$tgl_skr 23:59:59";
			$this->update("banner_kanan", "status=1, tglaktif='$clientdate'", "username='$username'");
			$this->select("username", "komisi", "dari='$username'");
			if($this->num_rows() == 0) {
				$sponsore = $this->dataku("sponsor", $username);
				$k_spon = $this->config("komisi_sponsor");
				$k_gen = explode("|", $this->config("komgenerasi"));
				if($sponsore) {
					$this->insert("komisi", "", "'', '$sponsore', '$k_spon', '$clientdate', '0', '', 'komsponsor', '$username'");
				}
				//---komisi level---
				$tkt = $this->config("kedalaman");
				$kolev = $this->config("komlev");
				for($i=0;$i<$tkt;$i++) {
					$j = $i + 1;
					$komlev = explode("|", $kolev);
					$upli = $this->dataupline("upline$i", $username);
					if($upli) {
						$this->insert("komisi", "", "'', '$upli', '$komlev[$i]', '$clientdate', '0', '', 'komlev$j', '$username'");
						}
						
				}
 
			}		
			
 	
					$jdl = $this->jumlahdl($upli, "1");
					$this->update("upline", "dl='$jdl'", "username='$upli'");
					$jsp = $this->jumlahsp($sponsore, "1");
					$this->update("upline", "sp='$jsp'", "username='$sponsore'");
						

		}
		
		function orderaktivasi($username) {
			$clientdate    = (date ("Y-m-d H:i:s")); //--tgl skr
			$tgl_skr = (date("Y-m-d"));
			$dtfrom = "$tgl_skr 00:00:00";
			$dtto = "$tgl_skr 23:59:59";
				$this->update("ordmember", "status=1, tglaktif='$clientdate'", "username='$username'");
				$sponsore = $this->dataku("sponsor", $username);
				$by = $this->datakuewalet("adminrp", $username);
				$k_spon_ewalet = $this->config("komisi_sponsor_ewalet");
				$k_spon_ewalet_ok = ($k_spon_ewalet*$by)/100;
				if($sponsore) {
				$this->insert("komisi", "", "'', '$sponsore', '$k_spon_ewalet_ok', '$clientdate', '0', '', 'komsponsorro', '$username'");
				$tktewalet = $this->config("kedalamanewalet");
				$kolev = $this->config("komlevewalet");
				for($i=0;$i<$tktewalet;$i++) {
					$j = $i + 1;
					$komlev = explode("|", $kolev);
					$by = $this->datakuewalet("adminrp", $username);
					$bonlev = ($komlev[$i]*$by)/100;
					$upli = $this->dataupline("upline$i", $username);
					if($upli) {
						$this->insert("komisi", "", "'', '$upli', '$bonlev', '$clientdate', '0', '', 'komisilevelro$j', '$username'");
						}
				}
			}		
		}
		
		function aktivasibatal($username) {
			$this->update("banner_kanan", "ket='Pending'", "username='$username'");
			$this->select("username", "komisi", "dari='$username'");
			if($this->num_rows() > 0) {
			$this->update("komisi", "ket='Pending'", "dari='$username'");
			}
		}
		

		function insertkomjual($username, $harga) {
			$clientdate    = (date ("Y-m-d H:i:s"));
			$tkt = $this->config("kedalaman1");
			$level = $this->dataupline("level", $username);
			$kdlm = explode("|", $tkt);
			$kd = $kdlm[1];
			$kolev = $this->config("komjual");
				for($i=0;$i<$level;$i++) {
					if($level <= 15) { //---sd levl 10
						$j = $i + 1;
						$komlev = explode("|", $kolev);
						$upli = $this->dataupline("upline$i", $username);
						$tj = ($komlev[$i] * $harga)/100;
						if($upli) {
							$this->insert("komisi", "", "'', '$upli', '$tj', '$clientdate', '0', '', 'komjual$j', '$username'");
						}
					} //--end if level	
				}
			}	
			//----INSERT KOMISI RO
			function insertkomro($username, $harga) {
			$clientdate    = (date ("Y-m-d H:i:s"));
			$komroz = $this->config("komrox");
						$uplix = $username;
						$tjx = ($komroz * $harga)/100;
						if($uplix) {
							$this->insert("komisi", "", "NULL, '$uplix', '$tjx', '$clientdate', '0', '', 'komisiro', '$username'");
						}
//--end if level	
				}
			//---END KOMISI RO

		
		
		//-------total KOMISI-------
		
		function totalkomisi($username, $dtgl) {
			$kom="";
			$skom="SELECT * FROM komisi WHERE username='$username' $dtgl";
			$dkom=mysql_query($skom);
			$ada=mysql_num_rows($dkom);
			if($ada > 0) {
				$komi = 0;
				while($rkom=mysql_fetch_row($dkom)) {
					$komi = $komi + $rkom[2];
				}
				$kom = $komi;
			} else {
				$kom = 0;
			}
			return $kom;
		}	

		function bayarkomisi($username, $dtgl) {

			$kom="";

			$skom="SELECT rp FROM transfer WHERE userid='$username' AND status=1 $dtgl";

			$dkom=mysql_query($skom);

			$ada=mysql_num_rows($dkom);

			if($ada > 0) {

				$komi = 0;

				while($rkom=mysql_fetch_row($dkom)) {

					$komi = $komi + $rkom[0];

				}

				$kom = $komi;

			} else {

				$kom = 0;

			}

			return $kom;

		}	



		//----cari jml perlevel--

		function jmlmember($username, $field) {

			$jm = 0;

			$this->select("a.username, a.status, a.blokir, b.sponsor", "banner_kanan as a inner join upline as b on a.username=b.username", $field);

			$jm = $this->num_rows();

			return $jm;

		}		

		

		//----ewalet---

		function myewalet($username) {

			$te = 0;

			

			$te = $this->myewaletdone($username);

			return $te;

		}	

		function myewaletpending($username) {

			$te = 0;

			//--ngitung kredit--

			$sql = mysql_query("select username, jumlah, tujuan from dataewalet where tujuan='$username' and status=0");

			$a = mysql_num_rows($sql);

			$ted = 0;

			while($row=mysql_fetch_row($sql)) {

			//for($i=0;$i<$a;$i++) {

				$ted = $ted + $row[1];

			}

			//---ngitung debet--

			$sqla = mysql_query("select username, jumlah, tujuan from dataewalet where username='$username' and status=0");

			//$a = mysql_num_rows($sql);

			$tek = 0;

			while($rowa=mysql_fetch_row($sqla)) {

				$tek = $tek + $rowa[1];

			}	

			$te = $ted + $tek;

			return $te;

		}	

		

		function myewaletdone($username) {

			$te = 0;

			//--ngitung kredit--

			$sql = mysql_query("select username, jumlah, tujuan from dataewalet where tujuan='$username' and status=1");

			$a = mysql_num_rows($sql);

			$ted = 0;

			while($row=mysql_fetch_row($sql)) {

			//for($i=0;$i<$a;$i++) {

				$ted = $ted + $row[1];

			}

			//---ngitung debet--

			$sqla = mysql_query("select username, jumlah, tujuan from dataewalet where username='$username' and status=1");

			//$a = mysql_num_rows($sql);

			$tek = 0;

			while($rowa=mysql_fetch_row($sqla)) {

				$tek = $tek + $rowa[1];

			}	

			$te = $ted - $tek;

			return $te;

		}	

		

		//---saldo admin--

		function saldoadmin($dtgl) {

			$this->select("jumlah, status", "transaksi", $dtgl);

			$sa = 0;

			while($row=$this->fetch_row()) {

				if($row[1] > 0) { //---status 1 = kredit. status 0 = debet

					$ja = $row[0];

				} else {

					$ja = -($row[0]);

				}		

				$sa = $sa + $ja;

			}

			return $sa;

		}	

		

		//----banner-----

		function banner() {

			//$bn = "";

			$this->select("id, nama, banner, url", "banner", "published=1", "ordering");

			while($row=$this->fetch_row()) {

				echo "<a href='banner.php?bid=$row[0]' target='_blank'><img src='images/banner/$row[2]' title='$row[1]' border=0 /></a><br>";

			}

			//return $bn;	

		}	

		

		function komisipaket($username, $dtgl) {

			$kom=0;

			$spk = mysql_query("select paket from upline where username='$username'");

			$row=mysql_fetch_row($spk);

			$pk = $row[0];

			$tkm = 0;

			for($i=0;$i<$pk;$i++) {

				if($i == 0) {

					$user = $username;

				} else {

					$user = "$username-0$i";

				}

						

				$skom="SELECT * FROM komisi WHERE username='$user' $dtgl";

				$dkom=mysql_query($skom);

				$ada=mysql_num_rows($dkom);

				

					$komi = 0;

					while($rkom=mysql_fetch_row($dkom)) {

						$komi = $komi + $rkom[2];

					}

					$tkm = $tkm + $komi;

				}	

					$kom = $tkm;

			

				return $kom;

		}	

		

		//----ym---

	function ym($i, $n) {

		$ym = "";

		$ymn = explode(",", $this->config("ym"));

		//$y = array();

		$cn = count($ymn);

		//for($i=0;$i<$cn;$i++) {

			echo "<a href='ymsgr:sendIM?$ymn[$i]'><img src='http://opi.yahoo.com/online?u=$ymn[$i]&m=g&t=1' border='0' title='$n'></a>";

		//}

	}	



function depan($ref) {



			$this->select("id, title, maintext, created", "content", "catid=1 and published=1", "created desc", "", "", "");



			$ada = $this->num_rows();



			for($i=0;$i<$ada;$i++) {



				$text = $this->result($i, "maintext");



				$tgcr = $this->result($i, "created");



				$text0 = $this->crops($this->delete_html($text), 8);



				echo "$text";



			}



		}



function company($ref) {



			$this->select("id, title, maintext, created", "content", "catid=56 and published=1", "created desc", "", "", "");



			$ada = $this->num_rows();



			for($i=0;$i<$ada;$i++) {



				$text = $this->result($i, "maintext");



				$tgcr = $this->result($i, "created");



				$text0 = $this->crops($this->delete_html($text), 8);



				echo "$text";



			}



		}



function plan($ref) {



			$this->select("id, title, maintext, created", "content", "catid=23 and published=1", "created desc", "", "", "");



			$ada = $this->num_rows();



			for($i=0;$i<$ada;$i++) {



				$text = $this->result($i, "maintext");



				$tgcr = $this->result($i, "created");



				$text0 = $this->crops($this->delete_html($text), 8);



				echo "$text";



			}



		}



	function freemember($status) {
//ket : AW - marque jalan (user,nama,paket,kota)
		$this->select("username, nama, profit, kota", "banner_kanan", "status=$status and paket=1", "tglaktif desc", "", "", "10");
//ket : AW - marque jalan (user,nama,hp,kota)
//		$this->select("username, nama, hp, kota", "member", "status=$status and paket=1", "tglaktif desc", "", "", "10");

		while($data=$this->fetch_row()) {
			echo "<div class=berita><center><table cellpadding=\"0\" cellspacing=\"0\" width=\"50px\" height=\"50px\" border=\"0\" align=\"left\" bgcolor=\"#F9F9F9\"><tr><td width=\"100%\" align=\"center\"><img src=\"images/no_avatar.gif\" width=\"50px\" height=\"50px\"></td></tr></table>$data[1]<br /> $data[2] <br />($data[3])<br /></center></div>";
		}
	}

	function newmember($status, $from) {
//ket : AW - marque jalan (user,nama,paket,kota)
		$this->select("username, nama, kota, propinsi, hp, foto", "banner_kanan", "status=$status and username<>'banner_kanan'", "id desc", "", "", "5");
//		$this->select("username, nama, profit, kota, foto", "member", "status=$status", "id desc", "", "", "10");
//ket : AW - marque jalan (user,nama,hp,kota)
//		$this->select("username, nama, hp, kota, foto", "member", "status=$status", "id desc", "", "", "10");

		if($from == "home") {
			$folder = "../images/";
			$folder2 = "../member/images/";
		} else {
			$folder = "../images/";
			$folder2 = "images/";
		}

		while($data=$this->fetch_row()) {
//			 if(!$data[4]) {
			 if(!$data[6]) {
					$foto = $folder."noimage.png";

				} else {
					$foto =	$folder2.$data[6];

				}
		$hape=substr($data[2],0,9);
		$x="XXX";
//			echo "<center><table cellpadding=\"0\" cellspacing=\"0\" width=\"50px\" height=\"50px\" border=\"0\" align=\"left\" bgcolor=\"#F9F9F9\"><tr><td width=\"100%\" align=\"center\"><img src=\"images/no_avatar.gif\" width=\"50px\" height=\"50px\"></td></tr></table>$data[0]<br /> $data[1] <br /> $data[2] <br />($data[3])<br /></center>";
//			echo "<center><table cellpadding=\"0\" cellspacing=\"0\" width=\"50px\" height=\"50px\" border=\"0\" align=\"left\" bgcolor=\"#F9F9F9\"><tr><td width=\"100%\" align=\"center\"><img src=\"images/$foto\" width=\"50px\" height=\"50px\"></td></tr></table>$data[0]<br /> $data[1] <br /> $data[2] <br />($data[3])<br /></center><div align=\"left\"><img src=\"images/zbatas.png\" width=\"236px\" height=\"5px\"></div>";
// AW
			echo "
			
<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"\">
  <tr>
    <td height=\"5\"></td>
  </tr>
</table>

			
			<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
			  <tr>
    			<td class=\"awstylenormal2\">
					<div align=\"left\">
						
						<!-- $data[1]<br /> -->
                                                 <font color=#fffff>" .substr($data[1],0,18). "...</font> <br />
						 <font color=#fffff>$data[2]</font> <br /> 
						<!--  $data[3] - $folder2<br /> -->
						<font color=#fffff> " .substr($data[4],0,8). "xxxx</font> <br />
						</div></left>
				    </div>
				</td>
			  </tr>
			</table>			


<table width=\"300\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"\">
  <tr>
    <td height=\"5\"></td>
  </tr>
  <tr> 
    <td height=\"0\" bgcolor=\"#cccccc\"></td>
  </tr>
</table>			
			
			";
		}
	}

	

	function newmember1($status) {
		//$nm = "";
		$this->select("username, nama, kota, hp", "banner_kanan", "status=$status and paket=1", "tglaktif desc", "", "", "10");
		while($data=$this->fetch_row()) {
			echo "<center>$data[0]<br /> $data[1] <br /> $data[2] <br />($data[3])<br /></center>";
		}
		//return $nm;
	}		
}  
?>