Re: CLASS/Object lifetime - > Here is the code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



roger helgesen wrote:
 Hi!

I'v got 2 classes. CLASS1 makes a array of instanses of class2.

I need thees classes 2 live for the duration of the session so I serialize class1 to a _session var.

I submit the form and the page is reloaded. I unserialize class1 back 2 same instanse var.
class1 I works. The instanses of class2 almost work.
I can read all data from the class/object, I can run functions off class2 BUT I can't change the data in objects og class2.

Is this at all possible.

ps.I do not serialize/unserialize object of CLASS2, these are instanses of CLASS1.

regard
Roger Helgesen


<?PHP
CLASS kontoplan{
	var $kontoer=array();
	function kontoplan(){
		$SQL="SELECT kontonummer,navn,paslag FROM kontoer ORDER BY kontonummer";
		$SQL=mysql_query($SQL);
		$teller=1;
		while($konto=mysql_fetch_array($SQL)){
//			echo "<b>vi er n&aring; $teller gang<br>\n";
// echo "array(\"kontonummer\"=>$konto[0],\"navn\"=>$konto[1],\"paslag\"=>$konto[2])<br>\n"; $this->kontoer[$konto[0]]=array("kontonummer"=>$konto[0],"navn"=>$konto[1],"paslag"=>$konto[2]);
//			$teller++;
		}
// echo "------------ Kontoplan(".count($this->kontoer).") -------------\n";
//	print_r($this->kontoer);
	
//	foreach($this->kontoer as $konto=>$rekke){
//		echo "$konto(".count($this->kontoer).")<br>\n";
// echo "0=".$rekke['kontonummer']." 1=".$rekke['navn']." 2=".$rekke['paslag']."<br>\n";
//	}
	}
	
}
CLASS sammendrag{
        var $prosjektnummer;
        var $prosjektnavn;
	var $kalk_id;
        var $hovedposter=array();
	var $subposter=array();
	var $vinduer=array();
	var $dorer=array();
	var $porter=array();
        var $antall=0;
        var $a=0;
	var $kplan;
        function sammendrag($nummer,$navn){
//		echo "<h2>I sammandrag</h2>\n";
                $this->prosjektnummer=$nummer;
$this->prosjektnavn=sql_return("SELECT ProsjektNavn FROM prosjektnr where ProsjektNummer=$nummer");
		$this->kplan=&new kontoplan();
$this->kalk_id=sql_return("SELECT id FROM kalk_opl WHERE prosjekt='$this->prosjektnummer'"); $SQL="SELECT left(konto,4) AS hkonto,ROUND(SUM(s4)) FROM kalkyler WHERE id_kalk='$this->kalk_id' GROUP BY hkonto";
//                echo "sql=$SQL<br>\n";
$knavn="SELECT kontonummer,navn FROM kontoer WHERE right(kontonummer,2)=00";
		$knavn=mysql_query($knavn);
		$kn=array();
		while($k=mysql_fetch_array($knavn)){
//			$k[0]=$k[0].'00';
			$kn[$k[0]]=$k[1];
		}
		mysql_free_result($knavn);
                $SQL=mysql_query($SQL);
		$tpost=array();
		$npost=array();
                while($hkonto=mysql_fetch_array($SQL)){
			$hkonto[0]=$hkonto[0].'00';
//			echo "hkonto0[$hkonto[0]], knr=$knr<br>\n";
//			array_unshift($hkonto,$kn[$hkonto[0]]);
			$tpost[]=array($hkonto[0],$kn[$hkonto[0]],$hkonto[1]);
                }
		// Fyller pa med underentrepenorer
$SQL="SELECT kontonummer,navn FROM kontoer WHERE (kontonummer >=450000 AND kontonummer < 451000) AND right(kontonummer,2)='00'";
		$SQL=mysql_query($SQL);
		while($hkonto=mysql_fetch_array($SQL)){
			$hkonto[2]=0;
			array_push($tpost,$hkonto);
                }
		$this->fyll_poster($tpost);
		$this->fyll_vinduer();
		$this->lag_hkontoer();
        }
	function fyll_poster($rekke){
		while($post=current($rekke)){
                        $this->ny_hovedpost($post);
			next($rekke);
                }

	}
        function ny_hovedpost($hovedpost){
// echo "Sette hovedposter[".$hovedpost[0]."]=$hovedpost<br>\n";
                $this->hovedposter[$hovedpost[0]]=$hovedpost;
                $this->antall++;
        }
	function hpostnavn($post){
//echo "hpostnavn=".$this->hovedposter[$post][1]."\n";
		return $this->hovedposter[$post][1];
		
	}
	function lag_hkontoer(){
		foreach($this->hovedposter AS $hkonto=>$verd){
			$hn='t'.$hkonto;
			$hnnavn=$hn;
			$hn=new gruppe($hkonto,$this,$this->kplan);
			$this->subposter[$hnnavn]=$hn;
//			$hn->skriv($this,$hkonto);		
		}
	}

	function skriv_kontoer(){
	// Skrive ut alle konto sider
		foreach($this->subposter AS $konto){
			$konto->skriv($this);
		}
	}
	function fyll_sub_konto($pv){
		foreach($this->subposter AS $konto=>$kontoen){
			//echo "$konto($kontoen->navn) = ".get_class($kontoen) ."<br>\n";
			$kontoen->fyll_fra_post($pv);
//			$kontoen->endret='jadda';
//echo "$kontoen->navn er obj(".is_object($kontoen).")er endre($kontoen->endret)<br>\n";
		}
		$d=$this->subposter['t431100'];
echo $d->navn. "(".$d->hkonto.") best=".$d->poster['431112']['bestilt']."<br>\n";
	}
//	function ut_hkonto(){
	function fyll_vinduer(){
$SQL="SELECT vdp_std.navn,v.stk,v.bredde,v.hoyde FROM vdp v left join vdp_std ON v.id_std=vdp_std.id where v.id_kalk='$this->kalk_id'and (v.id_std=5 OR v.id_std=6 OR v.id_std=1 OR v.id_std=2) AND v.stk<>0";
//		echo "Vinduer SQL=$SQL <br>\n";
		$SQL=mysql_query($SQL);
		while($post=mysql_fetch_array($SQL)){
//			echo "this->vinduer[]=$post<br>\n";
			$this->vinduer[]=$post;
		}
	}
		
}
CLASS sammendragHTML extends sammendrag{
//		var $hovedposter=parent->hovedposter;
	var $sider=3;
	var $ofsett=5;	
	function post_out(){
		echo "<DIV onClick=\"sv(klasse,'s1')\" CLASS=\"konto\">Totaler</DIV>\n";
		echo "<DIV CLASS=\"sider1\" id=\"s1\" STYLE=\"z-index:30\">\n";
		echo "<TABLE CLASS=\"hovedposter\">\n";
		echo "<TR>\n
		<TH style=\"width:50px\" >nr
		<TH width=\"250mm\">Hovedpost
		<TH width=\"70mm\">Budsjett
		<TH width=\"70mm\">Bestilt
		<TH width=\"70mm\">Avik
		<TH width=\"70mm\">Fakturert
		<TH width=\"*\">Kommentar\n";
		$farge="#c8c8c8";
		foreach($this->hovedposter AS $post=>$rekke){
		        $farge=farge($farge);
		        echo "<TR STYLE=\"background-color:$farge\">\n";
		        echo "
		        <TD CLASS=\"hovedposter\">$post
		        <TD CLASS=\"hovedposter\">$rekke[1]\n";
			if($rekke[0]=='431411'){
				echo "print vinduer\n";
				$this->vinduer_out();
			}	
			echo "
		        <TD CLASS=\"hovedposter\">$rekke[2]
<TD CLASS=\"hovedposter\"><input id=\"hp_bestilt_$post\" value=\"0\" size=\"5\" readonly> <TD CLASS=\"hovedposter\"><input id=\"hp_avvik_$post\" value=\"0\" size=\"5\" readonly> <TD CLASS=\"hovedposter\"><input id=\"hp_faktura_$post\" value=\"0\" size=\"5\" readonly>
	       		<TD CLASS=\"hovedposter\">ingen\n";
		}
		echo "</TABLE>\n</DIV>\n";
	}
	function vinduer_out(){
		echo "<br>\n";
                foreach($this->vinduer AS $post){
//                        $farge=farge($farge);
echo "<span style=\"color:".$_SESSION['farger']['nedtonet']."\"> $post[0] = $post[1]stk a $post[2]<sub>m</sub>x$post[3]<sub>m</sub><br></span>\n";
                }
        }
	function sett_marginer($sider=3,$offsett=5){
		$this->sider=$sider;
		$this->offsett=$offsett;
	}


}
CLASS gruppe{
	var $hkonto;
	var $navn;
	var $poster=array();
	var $antall=0;
	var $sum=array('budsjett'=>0,'bestilt'=>0,'avvik'=>0,'faktura'=>0);
	var $sa;
	var $endret="nei";
//	var $kontoplan;
	function gruppe($hk,&$sd,&$kplan){
		$this->hkonto=$hk;
		$this->navn=$sd->hpostnavn($hk);
//		$this->sa=$sd->navn;
//		$this->kontoplan=new kontoplan();
// $SQL="SELECT ka.konto,ka.navn2,ka.s4,ko.paslag FROM kalkyler ka,kontoer ko WHERE (ka.id_kalk='$sd->kalk_id' AND left(ka.konto,4)='".substr($this->hkonto,0,4)."') AND (ka.konto=ko.kontonummer)"; $SQL="SELECT ka.konto,ka.navn2,ka.s4 AS budsjett,sa.paslag,sa.avvik,sa.bestilt,sa.faktura,sa.tillegg FROM kalkyler ka,kontoer ko
		LEFT JOIN sammendrag sa ON ka.konto=sa.konto AND ka.id_kalk=sa.kalk_id
WHERE (ka.id_kalk='$sd->kalk_id' AND left(ka.konto,4)='".substr($this->hkonto,0,4)."')AND (ka.konto=ko.kontonummer) AND ka.vis='on'";
//		echo "gruppeSQL=$SQL<br>\n";
		$SQL=mysql_query($SQL);
		while($t=mysql_fetch_array($SQL)){
//			echo "paslag er ".$t['paslag']."<br>\n";
			$t=$this->kontroll($t,$kplan);
//			echo "paslag etter er ".$t['paslag']."<br>\n";
			$this->poster[$t[0]]=$t;
		}
		$this->antall=count($this->poster);
		$this->sett_sum();
	}
	function kontroll($rekke,&$kplan){
		// Sett pa standard paslag om ikke egnet paslag
		if(empty($rekke['paslag'])){
			$rekke['paslag']=$kplan->kontoer[$rekke['konto']]['paslag'];
			$rekke['bestilt']=$rekke['bestilt']+1;
		}
		return $rekke;	
	}
	function sett_sum(){
		foreach($this->poster AS $k=>$poster){
			$this->sum['budsjett']+=$poster['budsjett'];
			$this->sum['bestilt']+=$poster['bestilt'];
			$this->sum['avvik']+=$poster['avvik'];
			$this->sum['faktura']+=$poster['faktura'];
		}
		//$this-sum=array_sum($this->poster[
//		print_r($this->sum);
	}
	function fyll_fra_post($post_vars){
		 echo "(gruppe)class = ".get_class($this) ."<br>\n";
		$teller=0;
		foreach($this->poster AS $post=>$verd){
//			echo "hpost($post)<br>\n";
//			foreach($verdier AS $navn=>$verd){
				$best="bestilt_".$post;
				$avik="avvik_".$post;
				$fakt="faktura_".$post;
//				$best="bestilt_".$post;
				echo "----for----<br>($teller)navn(".$this->poster[$post]['konto'].")=
$post budsjett(".$this->poster[$post]['budsjett'].") $post bestilt(".$this->poster[$post]['bestilt'].")(".$post_vars[$best].") $post avvik(".$this->poster[$post]['avvik'].")(".$post_vars[$avik].")
                                endret(".$this->endret.")
                                -----------<br>\n";

				$this->poster[$post]['bestilt']=$post_vars[$best];
				$this->poster[$post]['avvik']=$post_vars[$avik];
				$this->poster[$post]['faktura']=$post_vars[$fakt];
// echo "Setter this->poster[$post]['bestilt']=$post_vars[$form_navn]<br>\n"; /* echo "-----etter-----<br>($teller)navn(".$this->poster[$post]['konto'].")=
				budsjett(".$this->poster[$post]['budsjett'].")
				bestilt(".$this->poster[$post]['bestilt'].")
				avvik(".$this->poster[$post]['avvik'].")
				endret(".$this->endret.")
				<br>\n";*/
				$teller++;
//			}
		}
		$this->endret='ja';
		$this->sett_sum();
		//echo "Hei jeg heter $this->navn, og har konto $this->hkonto<br>\n";
	}
	function skriv(&$p){
echo "<DIV onClick=\"sv(klasse,'$this->navn')\" CLASS=\"konto\" STYLE=\"margin-top:".$p->sider*$p->ofsett ."mm\">$this->navn</DIV>\n"; echo "<DIV CLASS=\"sider\" name=\"$this->navn\" id=\"$this->navn\" STYLE=\"z-index:".$p->sider.";\">\n"; // echo "<img onClick=\"window.print()\" src=\"iconer/print/inkjet-64-gnome2-small-networked.png\">\n"; // echo "<DIV onClick=\"sv(klasse,'$this->navn')\" CLASS=\"konto\" STYLE=\"margin-top:".$p->sider*$p->ofsett ."mm\">$this->navn</DIV>\n"; echo "<center><h2>$this->navn($this->hkonto)($this->endret)</h2></center>\n";
		echo "<TABLE CLASS=\"$this->navn.tt\">\n";
		$pnam="paslag".$this->hkonto;
		echo "<col id=\"nr\" width=\"50px\">
		<col id=\"Konto\" width=\"250px\">
		<col id=\"$pnam\" CLASS=\"paslagcol\" width=\"70px\">
		<COL id=\"budsjett\" width=\"70px\">
		<col id=\"Bestilt\" width=\"70px\">
		<col id=\"Avik\" width=\"70px\">
		<col id=\"Faktura\" width=\"70px\">
		<col id=\"kommentar\" width=\"*\">\n";
                echo "<TR><TH>nr
		<TH width=\"350px\" onClick=\"paslag('$pnam','$this->hkonto')\">Konto
		<TH>P&aring;slag
		<TH>Budsjett
		<TH>Bestilt
		<TH>Avik
		<TH>Faktura
		<TH>Kommentar\n";
			$jsrekke="";
		$farge='#c8c8c8';
		foreach($this->poster AS $konto=>$verdier){
			$farge=farge($farge);
			$avvik=0;
			// Bergen avvik om det er bestilt
			if(!empty($verdier['bestilt'])){
				$avvik=$verdier['budsjett']-$verdier['bestilt'];
			}
			$jsrekke=$jsrekke.$verdier[0].",";
// <input name=\"paslag_".$verdier[0]."\" id=\"paslag_".$verdier[0]."\" value=\"".$verdier['paslag']."\">
			echo "<TR STYLE=\"background-color:$farge\">
			<TD class=\"nr\">$verdier[0]
			<TD>$verdier[1]($konto)\n";
			if($konto=='431411'){
//                                echo "print vinduer\n";
                                $p->vinduer_out();
                        }
			echo "
<TD><input type=\"text\" size=\"5\" name=\"paslag_".$verdier[0]."\" id=\"paslag_".$verdier[0]."\" value=\"".$verdier['paslag']."\" CLASS=\"paslag\"> <TD><input size=\"5\" type=\"text\" name=\"budsjett_".$verdier[0]."\" id=\"budsjett_".$verdier[0]."\" value=\"".round($verdier['budsjett'])."\" valign=right readonly style=\"border-color:red\"> <TD><input size=\"5\" onChange=\"summer(".$this->hkonto.",'bestilt')\" name=\"bestilt_".$verdier[0]."\" id=\"bestilt_".$verdier[0]."\" value=\"".$verdier['bestilt']."\"> <TD><input size=\"5\" name=\"avvik_".$verdier[0]."\" id=\"avvik_".$verdier[0]."\" value=\"".round($avvik)."\" valign=right> <TD><input size=\"5\" onChange=\"summer(".$this->hkonto.",'faktura')\" name=\"faktura_".$verdier[0]."\" id=\"faktura_".$verdier[0]."\" value=\"".$verdier['faktura']."\"></TD>
			$verdier[6]\n
			<TD>Kommentar\n";
		}
		echo "</TR><TR><td><TD><TD>
<TD><input size=\"5\" id=\"budsjett_".$this->hkonto."\" value=\"".round($this->sum['budsjett'])."\"> <TD><input size=\"5\" id=\"bestilt_".$this->hkonto."\" value=\"".round($this->sum['bestilt'])."\"> <TD><input size=\"5\" id=\"avvik_".$this->hkonto."\" value=\"".round($this->sum['avvik'])."\"> <TD><input size=\"5\" id=\"faktura_".$this->hkonto."\" value=\"" .round($this->sum['faktura'])."\">\n";
		echo "<TD></TR></TABLE></DIV>\n";
		$jsrekke=substr($jsrekke,0,strlen($jsrekke)-1);
		echo "<script language=\"JavaScript\" type=\"text/javascript\">\n
		var t".$this->hkonto."=new Array($jsrekke);\n
		</SCRIPT>\n";
//		echo "document.getElementById('".$hkonto."').value=
	$p->sider+=1;
	}
}
CLASS bruker {
	var $bruker;
	var $passord;
	var $fornavn;
	var $etternavn;
	var $rett=array();
	function bruker(){
		$this->bruker=$_SERVER['PHP_AUTH_USER'];
		$this->passord=$_SERVER['PHP_AUTH_PW'];
$SQL="SELECT Fornavn,Etternavn FROM Ansatte WHERE brukernavn='".$this->bruker."'";
//		echo $SQL;
//		echo $this->bruker;
mysql_connect("arne","www","Yfw98ah1") or die("Ingen kontakt") . mysql_error ;
//select which database you want to edit
		mysql_select_db("dbhtb");
		$SQL=mysql_query($SQL);
		$SQL=mysql_fetch_assoc($SQL);
		if($SQL['Fornavn'])$this->fornavn=$SQL['Fornavn'];
		if($SQL['Etternavn'])$this->etternavn=$SQL['Etternavn'];
//		$this->etternavn=$e;
		$SQL="SELECT * FROM rettigheter WHERE bruker='".$this->bruker."'";
		$SQL=mysql_query($SQL);
		$rettighet=mysql_fetch_assoc($SQL);
		$felter="SHOW COLUMNS FROM rettigheter";
		$felter=mysql_query($felter);
		$rr=array();
		while($r=mysql_fetch_array($felter)){
			if($r['Field']!='id' && $r['Field']!='bruker'){
				$this->rett[$r['Field']]=$rettighet[$r['Field']];
//				echo $r['Field']."=".$rettighet[$r['Field']]."<br>\n";
			}
		}
		
	}
}
CLASS tlf_mld {
	var $meldinger=array();
	function tlf_mld(){
		$SQL="SELECT * FROM tlf_mld WHERE til='".$_SERVER['PHP_AUTH_USER']."'";
//		echo $SQL;
		$SQL=mysql_query($SQL);
		while($r=mysql_fetch_assoc($SQL)){
			$this->meldinger[]=$r;
		}
	}
	function skriv(){
		$teller=0;
echo "<FORM id=\"tlf\" name=\"tlf\" ACTION=\"". $_SERVER['PHP_SELF']."\" METHOD=\"POST\">\n"; echo "<input type=\"submit\" value=\"lagre\" class=\"noprint\" style=\"display:none;\">\n";

		foreach($this->meldinger as $r){
//			echo count($this->meldinger);
			$margin=$teller*210;
			$teller++;
			echo "<DIV style=\"margin-left:".$margin."px\" CLASS=\"tlf_mld_box\">\n";
echo "<center>Tlf. Melding</center><input class=\"sett\" name=\"sett".$r['id']."\" id=\"sett".$r['id']."\" type=\"checkbox\">\n";
			echo "fra:<b>".$r['fra']."</b> tlf:<b>".$r['fra_tlf']."</b>\n";
// echo "<input rows=\"5\" id=\"mld\" type=\"textarea\" value=\"".$r['melding']."\"> </input>\n";
			echo "<DIV class=\"mld\">".$r['melding']."</DIV>\n";
			echo "</DIV>\n";
		}
// echo "<input type=\"submit\" value=\"lagre\" class=\"noprint\" style=\"margin-left:10px;\">\n";
		echo "</FORM>\n";
	}
}
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux