[Solved] PHP Script within CMS Made Simple?

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

[Solved] PHP Script within CMS Made Simple?

Post by Keithb »

We have a simple script that I wrote that performs an estimate bill calculation.  Is there a way to get this snippet of PHP in a page in CMS Made Simple?

Example can be found at:  http://wcecnet.net/viewpage.php?page_id=6

The code is below:

Code: Select all

<?PHP 
include("rate_factors.php");
  $beginrdg = isset($_POST['begin_rdg']) ? $_POST['begin_rdg'] : ""; 
  $endrdg = isset($_POST['end_rdg']) ? $_POST['end_rdg'] : ""; 
?>
<style type="text/css">
<!--
.style2 {font-size: 10px}
-->
</style>
<br><br>
<table width=650 align=center><tr><td colspan=2 class=style2><b><font color=red>The following form is used to give an estimated bill based on meter readings you provide.  It will present to you an estimate of what your bill may be, and should not be used as an actual statement.  The calculation factors for upcoming months are normally updated near the 15th of each month. If you are receiving any additional services you must add these as well as any applicable taxes.</font> </b><br><br></td></tr><tr><td valign=top class=style2><a href=viewpage.php?page_id=7> Click here to Calculate Small General Service Rates</a><br><br><br><br>
 <b>Residential Rates: </b> Current as of <? $today_month1 = date ("n-d-Y", mktime(0, 0, 0, date("m"), date("d"), date("Y")));
echo $today_month1; ?>:<br>
<form action="<? echo $_SERVER['../PHP_SELF'] ?>" method="POST" class="style2"> 
Current Reading: &nbsp <input type="text" name="end_rdg" value ="<?PHP echo $endrdg; ?>"><br><br>

Previous Reading: <input type="text" name="begin_rdg" value="<?PHP echo $beginrdg; ?>"> 
<br><br>
<input name="securitylight" type="checkbox" id="securitylight" value="<?php echo $sl; ?>">
Security Light
<br>
<input name="lmwh" type="checkbox" id="lmwh" value="<?php echo $lmwh; ?>">
Load Management (Water Heater)
<br>
<input name="lmac" type="checkbox" id="lmac" value="<?php echo $lmac; ?>">
Load Management (Air Conditioning or Heat)
<br><br>
<input type="submit" name="submit" value="submit"> 
<input type="reset"> 
</form> 
</td>

<td class="style2" align=center>


<?php     



if (isset($_POST['submit']))     
{     
    	$res_kwh = $endrdg - $beginrdg;
	$lmwh = $_REQUEST['lmwh'];
	$lmac = $_REQUEST['lmac'];
	$totallm = $lmwh + $lmac;
        $res_gcrf = $res_kwh * $res_gcrfvalue;
	$res_gen = $res_kwh * $res_generation;
	$res_totalgen = $res_gen + $res_gcrf + $totallm;
        $res_genkwh = $res_totalgen / $res_kwh;
	$sl = $_REQUEST['securitylight'];
	$res_totaltdcrf = $res_kwh * $res_tdcrf;
	$res_trans = $res_kwh * $res_transmission;	
	$res_totaltrans = $res_trans + $res_totaltdcrf;
        $res_transkwh = $res_trans / $res_kwh;
	$res_netkwh = $res_kwh - $res_kwhgiven;
	$res_overkwh = $res_netkwh * $res_wcecover;
	$res_underkwh = $res_kwhgiven * $res_wcecunder;
	$res_totalwcec = $res_overkwh + $res_underkwh + $res_customercharge;
	$res_total = $res_totalgen + $res_totaltrans + $res_totalwcec + $sl;
        $res_lesssl = $res_totalgen + $res_totaltrans + $res_totalwcec;
        $res_kwhcost = $res_lesssl / $res_kwh;
        $res_wceckwh = $res_totalwcec / $res_kwh;
?>	
<div id=billingblock style="display:">
<?
echo "Your total KWH:<b>\n ". sprintf("%.02f", $res_kwh) . "<br><br></b>\n";
echo "GCRF:    \$  ". sprintf("%.02f", $res_gcrf) . "<br>\n";
echo "Generation:    \$  ". sprintf("%.02f", $res_gen) . "<br>\n";
echo "Load Management Credit:    \$  ". sprintf("%.02f", $totallm) . "<br>\n";
echo "<u>Generation / kwh:  \n  $  ". sprintf("%.03f", $res_genkwh) . "<br></u>\n";
echo "Total Generation:  <b>\n  $  ". sprintf("%.02f", $res_totalgen) . "<br></b><br><br>\n";
echo "TDCRF:    \$  ". sprintf("%.02f", $res_totaltdcrf) . "<br>\n";
echo "Transmission:    \$  ". sprintf("%.02f", $res_trans) . "<br>\n";
echo "<u>Transmission / kwh:  \n  $  ". sprintf("%.03f", $res_transkwh) . "<br></u>\n";
echo "Total Transmission:   <b>\n  \$  ". sprintf("%.02f", $res_totaltrans) . "<br><br></b>\n";
echo "Charge for 475 kwh:    \$  ". sprintf("%.02f", $res_underkwh) . "<br>\n"; 
echo "Charge for kwh over 475:    \$  ". sprintf("%.02f", $res_overkwh) . "<br>\n";
echo "Customer Charge:    \$  ". sprintf("%.02f", $res_customercharge) . "<br>\n";
echo "<u>WCEC / kwh:    \n\$  ". sprintf("%.03f", $res_wceckwh) . "<br></u>\n";
echo "Total WCEC Charge:    <b>\n\$  ". sprintf("%.02f", $res_totalwcec) . "<br><br></b>\n";
echo "Security Light:    \$  ". sprintf("%.02f", $sl) . "<br><br>\n";
echo "Your Final Bill Estimate:   <b><u>\n  \$  ". sprintf("%.02f", $res_total) . "<br><br></u></b>\n";
echo "Total cost / kwh: <b>\n  \$  ". sprintf("%.03f", $res_kwhcost) . "<br><br></b>\n";
}
?>
<__script__ language='javascript'>	function SwitchMember(myObj){		if (myObj.checked){			document.getElementById('billingblock').style.display="none";
		
		}else{			
			document.getElementById('billingblockmember').style.display="none";
		}	}</__script>

<?   
if (isset($_POST['submit']))    { 
echo "<br><br><input type=checkbox name=member  style=\"position:relative; left:2px; top:4px\" onClick='SwitchMember(this)';> Clear Output "; 
} ?>
</div>
  


<div id=billingblockmember style="display:">

</td></tr>
</table><br><br>

Any ideas or help would be greatly appreciated to help get us ported over to CMSMS.
Last edited by Keithb on Thu Aug 12, 2010 1:11 am, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: PHP Script within CMS Made Simple?

Post by Nullig »

Put the script in  UDT.

You can read about UDTs here:

http://wiki.cmsmadesimple.org/index.php ... fined_Tags

Nullig
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Re: PHP Script within CMS Made Simple?

Post by Keithb »

Thanks for the reply.  I'm having problems removing all of the <PHP and getting errors.

# Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\Program Files\VertrigoServ\www\cms\admin\adduserplugin.php(100) : eval()'d code on line 15

I'm not a PHP expert but dabble in it but has been years since doing so.  I'm weeding through it.
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Re: PHP Script within CMS Made Simple?

Post by Keithb »

I believe I found the culprit on most of the errors.  It was the quotes.  I changed to single quotes and all but one line works:

Code: Select all

echo "<form action=" echo $_SERVER['../PHP_SELF'] " method="POST" class="style2">";
I'm unsure how to change that code where it won't give an error.
Last edited by Keithb on Wed Aug 04, 2010 1:54 pm, edited 1 time in total.
User avatar
Nullig
Power Poster
Power Poster
Posts: 2380
Joined: Fri Feb 02, 2007 4:31 pm

Re: PHP Script within CMS Made Simple?

Post by Nullig »

Try

echo "";

Nullig
hlf

Re: PHP Script within CMS Made Simple?

Post by hlf »

$_SERVER is an array ,the call  of $_SERVER['../PHP_SELF'] results in this Notice: Undefined index: ../PHP_SELF.

if you need .. you must write

echo "";
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Re: PHP Script within CMS Made Simple?

Post by Keithb »

hlf wrote: $_SERVER is an array ,the call  of $_SERVER['../PHP_SELF'] results in this Notice: Undefined index: ../PHP_SELF.

if you need .. you must write

echo "";
This appears to just take me to my homepage after clicking Submit.
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Re: PHP Script within CMS Made Simple?

Post by Keithb »

Nullig wrote: Try

echo "";

Nullig
This appears to take me to a 404 page:

http://localhost:8081/cms/method=%27POS ... mit=submit

Not Found

The requested URL /cms/method='POST' was not found on this server.

Not sure what I'm doing wrong.  This is frustrating already.
Keithb
Forum Members
Forum Members
Posts: 15
Joined: Mon Aug 02, 2010 7:27 pm

Re: PHP Script within CMS Made Simple?

Post by Keithb »

I believe I figured it out.  I used:

Code: Select all

echo "<form action='$PHP_SELF' method='POST'>";
And the script worked as intended.  Thank you both for your assistance.
Post Reply

Return to “The Lounge”