Author |
|
phil13 Groupie
Joined: December 19 2004 Location: France
Online Status: Offline Posts: 60
|
Posted: December 29 2004 at 04:59 | IP Logged
|
|
|
Dave,
i've made a psp page to manage my units (i've copied somes pieces of code from the forum).
To make it, i've reproduice 10 times the following code :
<tr>
<td width="4%" align="center">
</td>
<td width="13%" align="center">
<p align="left">Garden light </td>
<td width="4%" align="center"><% case(ph_getx10stat("A",12) when 0 then "?" when 1 then "off" when 2 then "ON") %> </td>
<td width="11%">
<input type="button" value="on" onclick="x10on('A',12)" style="color: #008000" name="a1on"> <input type="button" value="off" onclick="x10off('A',12)" style="color: #800000" name="a1off"></td>
<td width="65%"> </td>
</tr>
with these 2 fonctions in the html header :
function x10on(house,unit)
{
document.execsendkeys.sendkeys.value = "ph_rtne( ph_x10(1,'" + house + "'," + unit + " , 0) + ph_x10( 1,'" + house + "', 102, 0))";
document.execsendkeys.submit(); }
function x10off(house,unit)
{
document.execsendkeys.sendkeys.value = "ph_rtne( ph_x10(1,'" + house + "'," + unit + " , 0) + ph_x10( 1,'" + house + "', 103, 0))";
document.execsendkeys.submit(); }
All works but it is not easy to modify and dmaintain the code.
It is possible to combine javascript and psp to generate these 10 blocs in a one command (based for example with an array) ?
thanks
Philippe
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 29 2004 at 12:01 | IP Logged
|
|
|
My temporary work-around was to put the repeating code section into an external file, load LOCAL variables with the house and unit codes, then, load the external file, like an include, into my main PSP page with ph_readfile(). I can't find it now, but, there is another post covering this.
|
Back to Top |
|
|
phil13 Groupie
Joined: December 19 2004 Location: France
Online Status: Offline Posts: 60
|
Posted: December 29 2004 at 12:55 | IP Logged
|
|
|
Thanks Tony.
i'm going to try to use ph_readfile but in fact i wanted to use PSP like PHP :
<?
$i=0;
while ($i<$num)
{
$nom = mysql_result($resultat,$i,"nom");
$duree = mysql_result($resultat,$i,"duree");
$categorie = mysql_result($resultat,$i,"categorie");
echo "<table>
<tr>
<td>
<br>
<font color=\"#006633\"><b>".$nom."</b>
<br><br>
<font color=\"#990066\"><b>".$duree."</b>
<br><br>
<font color=\"#990066\"><b>".$categorie."</b>
<br>
<br>
</td>
</tr>
</table>";
$i++;
}
?>
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 29 2004 at 19:00 | IP Logged
|
|
|
You went over my head with that one. I was suggesting to use the ph_readfile() instead of having repeating blocks of code that you would need to cut and paste, then, change the values in. My solution was only to cover myself until I could get some tips from Dave on how to do it more intelligently (maybe SQL like his macro loading example).
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 30 2004 at 23:43 | IP Logged
|
|
|
Philippe,
I suppose it could be done. Javascript and PSP can be combined just fine. However, PSP runs on the PowerHome server with the result being passed back to the browser and javascript runs within the client after the page has been returned from the server. I am not a javascript expert by any means, so I don't know how you would do it in javascript (or if you even could since it runs in the browser).
I would think that you would concentrate on doing it using PSP. You would not be able to use an array however since PowerHome does not really have arrays (you could simulate them a couple of different ways perhaps). What could be done however, would be to write the bulk of the processing in vbscript (which has arrays) with the script saving the output to a TEMP variable then call the script from within PSP and then display the results of the TEMP variable within the HTML.
However, I think what you're trying to do is make smaller, more manageable X-10 control pages so I'll provide the sample below:
****************************************
<html>
<head><title>PowerHome</title></head>
<body>
<table cellspacing=1 cellpadding=1>
<tr bgcolor="#a6caf0">
<font color="#000000"><td align=left valign=center><b>Status</b></td>
<td align=left valign=center><b>Level</b></td>
<td align=left valign=center><b>Device Name</b></td>
<td align=left valign=center><b>ID</b></td>
<td align=left valign=center><b>Location</b></td>
<td align=left valign=center><b>Last Change</b></td>
<td align=left valign=center><b>Control</b></td>
</font>
</tr>
<%
ph_rtne(
ph_sqlselect(1,"select id,code,key_desc,location,if standard_dim = '1' and status = 2 then round(level,0) else null endif,
(case status when 0 then 'Unknown' when 1 then off_message else on_message end),dateformat(lastchange,'Mmm dd, yyyy
hh:mm:ss'),standard_dim,status_only,
(case status when 0 then unk_textcolor when 1 then off_textcolor else if level < 100 then dim_textcolor else on_textcolor endif end),
(case status when 0 then unk_backcolor when 1 then off_backcolor else if level < 100 then dim_backcolor else on_backcolor endif end)
from x10unitcode,x10types where x10unitcode.typeid = x10types.typeid order by 4,1,2"
) +
ph_setvar_a(1,1,1) +
ph_setvar_s(1,2,"") +
ph_forloop(
"ph_concatvar(1,2,
'<tr>~r~n<td align=left valign=center bgcolor=~~"' + ph_htmlcolor(long(ph_getdata(1,ph_getvar_n(1,1),11))) + '~~" nowrap><font color=~~"' +
ph_htmlcolor(long(ph_getdata(1,ph_getvar_n(1,1),10))) + '~~">' + ph_getdata(1,ph_getvar_n(1,1),6) + '</font></td>~r~n' +
'<td align=center valign=center bgcolor=~~"#c0c0c0~~" nowrap>' + ph_getdata(1,ph_getvar_n(1,1),5) + '</td>~r~n' +
'<td align=left valign=center bgcolor=~~"#fffbf0~~" nowrap>' + ph_getdata(1,ph_getvar_n(1,1),3) + '</td>~r~n' +
'<td align=center valign=center bgcolor=~~"#c0c0c0~~" nowrap>' + ph_getdata(1,ph_getvar_n(1,1),1) + ph_getdata(1,ph_getvar_n(1,1),2) +
'</td>~r~n' +
'<td align=left valign=center bgcolor=~~"#fffbf0~~" nowrap>' + ph_getdata(1,ph_getvar_n(1,1),4) + '</td>~r~n' +
'<td align=left valign=center bgcolor=~~"#c0c0c0~~" nowrap>' + left(ph_getdata(1,ph_getvar_n(1,1),7),12) + '     ' +
mid(ph_getdata(1,ph_getvar_n(1,1),7),14) + '</td>~r~n' +
'<form method=~~"get~~" action=~~"x10button.psp~~"><td align=left valign=center bgcolor=~~"#c0c0c0~~" nowrap>' +
if(ph_getdata(1,ph_getvar_n(1,1),9) = '0','<input type=~~"hidden~~" name=~~"hc~~" value=~~"' + ph_getdata(1,ph_getvar_n(1,1),1) + '~~">' +
'<input type=~~"hidden~~" name=~~"uc~~" value=~~"' + ph_getdata(1,ph_getvar_n(1,1),2) + '~~"> <input type=~~"submit~~" name=~~"cmd~~"
value=~~"ON~~" ' +
'style=~~"font-family:arial; font-size:8pt~~"> <input type=~~"submit~~" name=~~"cmd~~" value=~~"OFF~~" style=~~"font-family:arial;
font-size:8pt~~">' +
if(ph_getdata(1,ph_getvar_n(1,1),8) = '1','  <input type=~~"text~~" name=~~"dim~~" size=~~"2~~" style=~~"font-family:arial;
font-size:8pt~~">' +
' <input type=~~"submit~~" name=~~"cmd~~" value=~~"ADIM~~" style=~~"font-family:arial; font-size:8pt~~">',''),'') +
'</td></form>~r~n</tr>~r~n'
) +
ph_rtne(ph_addtovar(1,1,1))",
1,
ph_getsqlrows(1),
1
)
) +
ph_getvar_s(1,2) +
ph_rtne(ph_sqldestroy(1))
%>
</table>
</center>
</body>
</html>
**************************************************
The PSP code above will bring up an X-10 status screen with control for all X-10 devices. By modifying the SQL statements WHERE clause, you could limit the devices returned to ones you were interested in. For example, to limit the X-10 devices to just the "A" housecode, modify the WHERE clause to:
where x10unitcode.typeid = x10types.typeid and x10unitcode.id = 'A'
If you were instead interested in a particular location, modify the WHERE clause like so:
where x10unitcode.typeid = x10types.typeid and x10unitcode.location = 'LIVING ROOM'
Using this code, cut and paste, and some careful SQL modification should help you get to where you would like.
HTH,
Dave.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 31 2004 at 00:19 | IP Logged
|
|
|
Wow. Thanks, Dave! This and you other post should help greatly, especially the part where you reminded us about the table info in the docs , and how to snoop around in the database with reports!
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 31 2004 at 00:42 | IP Logged
|
|
|
|
Back to Top |
|
|
phil13 Groupie
Joined: December 19 2004 Location: France
Online Status: Offline Posts: 60
|
Posted: December 31 2004 at 06:36 | IP Logged
|
|
|
Wow and thanks too ...
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 10 2005 at 03:40 | IP Logged
|
|
|
I have tried your code.... Nothing is shown on the screen and a lot of garbage is seen. As of the PHP-code is not recoqnised...... The 2 blue areas are shown but on top of that the PHP-code can be read ....
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 10 2005 at 07:18 | IP Logged
|
|
|
I just copied the code above and dropped it into my PH/web folder... Works fine.
Maybe you saved it as .HTML instead of .PSP?
Tony
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 11 2005 at 05:03 | IP Logged
|
|
|
eehm, what can I say:
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 11 2005 at 07:54 | IP Logged
|
|
|
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 16 2005 at 08:15 | IP Logged
|
|
|
Hey tonyno, i've been trying to get something out of the code you've written but my knowlegde of the language is not sufficient. I've wwritten a little page like this:
<html>
<head>
<title>X-10 Control Panel</title>
</script>
</head>
<body bgcolor=whitesmoke text=black link=blue vlink=blue alink=blue>
<center>
<table border=4 cellpadding=1 cellspacing=2>
<tr bgcolor=navy><td nowrap>
<table border=0 width="100%"cellpadding=0 cellspacing=0><tr>
<td nowrap><img src= "imgicon.gif">
<td nowrap><font face="MS Sans Serif" color=white size=2><b>X-10 Control Panel</b></td>
<td nowrap align=right><img src= "imgx.gif">
</tr></table>
</td></tr>
<tr bgcolor=silver><td>
</td></tr>
</table>
</center>
<p>
<center>
Rolluik voordeur:
<form method="get" action="/ph-cgi/x10">
<input type="hidden" name="hc" value="K">
<input type="hidden" name="uc" value="4">
<input type="submit" name="cmd" value="ON">
<input type="submit" name="cmd" value="OFF">
</form>
<font color="#000000"><td align=Center><b><%[X10STATK4]%></b></td>
</center>
<center>
Telefoonlamp:
<form method="get" action="/ph-cgi/x10">
<input type="hidden" name="hc" value="K">
<input type="hidden" name="uc" value="1">
<input type="submit" name="cmd" value="ON">
<input type="submit" name="cmd" value="OFF">
</form>
<font color="#000000"><td align=Center><b><%[X10STATK1]%></b></td>
</center>
<center>
Vuurtorenlamp:
<form method="get" action="/ph-cgi/x10">
<input type="hidden" name="hc" value="K">
<input type="hidden" name="uc" value="3">
<input type="submit" name="cmd" value="ON">
<input type="submit" name="cmd" value="OFF">
</form>
<font color="#000000"><td align=Center><b><%[X10STATK3]%></b></td>
</center>
<center>
Eetkamerlamp:
<form method="get" action="/ph-cgi/x10">
<input type="hidden" name="hc" value="K">
<input type="hidden" name="uc" value="2">
<input type="submit" name="cmd" value="ON">
<input type="submit" name="cmd" value="OFF">
</form>
<font color="#000000"><td align=Center><b><%[X10STATK2]%></b></td>
</center>
<center>
Rolluik Achterdeur:
<form method="get" action="/ph-cgi/x10">
<input type="hidden" name="hc" value="K">
<input type="hidden" name="uc" value="5">
<input type="submit" name="cmd" value="ON">
<input type="submit" name="cmd" value="OFF">
</form>
<font color="#000000"><td align=Center><b><%[X10STATK5]%></b></td>
</center>
At itself a winning code for me because I was able to get the status of the different switches and shutters on the screen, but now I want to convert the numeric values of [X10statk1] to a word. With my limited knowledge I tried to get it like this
if ([X10STATK1]=1): '<center><b>Status: On</b></center>' but this evaluates to a (damn) !
Also I've tried it with the - when - statement but like I said, my knowledge is very limited. Can I work with the [x10stat##] in a psp-file? When I try to get the Status with ph_getx10status, always this (F******) ! seens to be looking around the corner and blows my idea to kngdom come.... sad isn't it!
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 16 2005 at 09:06 | IP Logged
|
|
|
Heh! Almost got it. What you want for the if() is...
<% if( [X10STATK1] = 1, '<center><b>Status: On</b></center>', '<center><b>Status: Off</b></center>') %>
More efficiently, you would do this...
<center><b>Status: <% if( [X10STATK1] = 1, 'On', 'Off') %></b></center>
Keep an eye on the PH Function help file; it has lots of good info.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 17 2005 at 03:52 | IP Logged
|
|
|
Quote: Originally posted by TonyNo on January 16 2005
Heh! Almost got it. What you want for the if() is...
<% if( [X10STATK1] = 1, '<center><b>Status: On</b></center>', '<center><b>Status: Off</b></center>') %>
More efficiently, you would do this...
<center><b>Status: <% if( [X10STATK1] = 1, 'On', 'Off') %></b></center>
Keep an eye on the PH Function help file; it has lots of good info.
Shouldn't it be the other way around? 1 equals off isn't it? So the best thing in a psp-file is to declare the htm-code first and then psp-code? BTW: The help file says a lot I agree but it is not sufficient enough to learn the language....IMHO
Shouldn't it be like this? <% if( [X10STATK1] = 1, 'Off', 'On') %></b></center>
So the If statement always has 2 declarations with it....? If the [x10stat] equals 1 the value is Off, any other value equals on? is that the proper way to interpret it?
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 17 2005 at 07:36 | IP Logged
|
|
|
Whoops! You're right. I just copied your line without looking at that part.
Note that there are three possible states: 0 = unknown, 1 = off, and 2 = on, so, you should use a case()...
<% case( [X10STATK1] when 0 then "Unk" when 1 then "Off" when 2 then "On") %>
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: January 17 2005 at 09:25 | IP Logged
|
|
|
Quote: Originally posted by TonyNo on January 17 2005
Whoops! You're right. I just copied your line without looking at that part.
Note that there are three possible states: 0 = unknown, 1 = off, and 2 = on, so, you should use a case()...
<% case( [X10STATK1] when 0 then "Unk" when 1 then "Off" when 2 then "On") %>
I am actually starting to get this code into my head.... Do the exprssions that have to be put on the screen between " " ? Does omitting these "" result to this (d***) - ! - again?
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: January 17 2005 at 10:01 | IP Logged
|
|
|
In the CASE statement above, the double quotes are required. You can also use single quotes if you wish. Single and double quotes can both delimit string data. You just have to match an opening single quote with a closing single quote and the same for double quotes.
The way the PSP works is that everything within the <% and %> tags will be evaluated as a formula. The result of that formula (string, numeric, datetime, etc) will be converted to a string and then inserted in place of the PSP tags.
HTH,
Dave.
|
Back to Top |
|
|
|
|