Some code examples of Douglas Knudsen.

materialisticrampantInternet and Web Development

Nov 10, 2013 (3 years and 11 months ago)

119 views

Some code examples of Douglas Knudsen.



This is an example of a webservice written as a façade. The CFC
called another CFC that does all the labour.



<!
-----------------------------------------------------------------------
>

<!
---


This file is the pro
perty of Alltel

Original Author: Douglas Knudsen

Project Name:

Purpose:

Called by:

Parameters: url.action




Returns:




Changes/whom:

this is a facade CFC for com.alltel.trend.trend.trend.cfc located in custom tags



---
>

<!
-----------------------------
------------------------------------------
>


<cfcomponent displayname="TrendIT Data!" output="no">


<cffunction name="getData"


access="remote" returntype="data" hint="" output="no">


<cfargument name="posnbr" required="true" type="string" />


<cfargumen
t name="period" required="true" type="string" />


<cfargument name="elementid" required="true" type="numeric" />


<cfargument name="segment" type="string" required="yes" />


<cfset var tmp ='' />


<cfif NOT ListFind('YTD,MTD,QTD,PD',arguments.period)>


<cfthrow message="Incorrect argument in com.alltel.trendit.custserv.getData"
type="application" detail="Period requires YTD,MTD,QTD, or PD" errorcode="999">


</cfif>


<cfif NOT ListFind('FS,SALES,CS',arguments.segment)>


<cfthrow message="Incorrect
argument in com.alltel.trendit.trend.getData"
type="application" detail="Segment requires FS,CS, or SALES" errorcode="999">


</cfif>


<cfinvoke



component="com.alltel.trendit.trend"



method="getData"



returnvariable="f
oo"



posnbr="#arguments.posnbr#"



period="#arguments.period#"



elementid="#arguments.elementid#"



segment="#arguments.segment#" />


<cfset tmp =
CreateObject("component","data").init(foo.displayname,foo.category,foo.amount) />


<cfreturn tm
p />


</cffunction>




<cffunction name="getAllElementsForUser"


access="remote" returntype="query"
hint="return a q of all dps available for a posnbr" output="no">


<cfargument name="posnbr" required="true" type="string" />


<cfargument name="segment" t
ype="string" required="no" default="" />




<cfinvoke



component="com.alltel.trendit.trend"



method="getAllElementsForUser"



returnvariable="goo"



posnbr="#arguments.posnbr#"



segment="#arguments.segment#"



orderby="c.category"/>


<cfreturn goo />


</cffunction>





</cfcomponent>



An example of PL/SQL. This stored procedure was scheduled to
execute every night and updated data for contests for the ACE
application, a sales contest application.



CREATE OR

REPLACE PACKAGE BODY acepkg AS


TYPE numericArray is VARRAY(20) OF NUMBER;


FUNCTION getFormula(v_contestID NUMBER) RETURN VARCHAR2


IS


v_formula VARCHAR2(500);


i pls_integer;


CURSOR c_myform IS


SELECT a.id, a.elementid, a.attainmentid, a.attainmentva
lue, a.weight,


t1.displayname,


nvl2(a.attainmentid, t2.displayname, to_char(a.attainmentvalue)) as attain


FROM contest_formula a, elements t1, elements t2


WHERE a.elementid = t1.FIELD_ID


AND a.attainmentid = t2.FIELD_ID(+)


AND a.id = v_contestID


or
der by a.myorder;


BEGIN


i := 0;


FOR cr_myform IN c_myform LOOP


if (i>0) then


v_formula := v_formula || ' +<br>';


end if;


v_formula:= v_formula || cr_myform.weight || ' * ' || cr_myform.displayname || ' / ' ||
cr_myform.attain;


i:=i+1;


END LOOP;


R
ETURN v_formula;


END;


PROCEDURE runAce


AS


CURSOR c_contests IS


SELECT *


FROM contest


WHERE sysdate BETWEEN fromdate AND todate


AND isactive = '1'


AND (SELECT COUNT(*) FROM contest_formula WHERE id = contest.id) > 0;


BEGIN


FOR cr_contest IN c_co
ntests LOOP


computeScores(cr_contest.id);


END LOOP;


END;


PROCEDURE computeScores(v_contestID NUMBER)


AS


v_posnbrlevel VARCHAR2(15);


v_elementNum NUMBER;


v_rankNum NUMBER;


v_startdate DATE;


v_enddate DATE;


v_numofelems NUMBER;


v_isBalanced NUMBE
R;


v_score NUMBER;


v_temp NUMBER;


v_tempMoney NUMBER;


TYPE numericArray is VARRAY(5) OF NUMBER;


v_numArray numericArray := numericArray(NULL,NULL,NULL,NULL,NULL);


v_denArray numericArray := numericArray(NULL,NULL,NULL,NULL,NULL);


v_weightArray numer
icArray := numericArray(NULL,NULL,NULL,NULL,NULL);


--
cursor of employees in the contest with the dates in the position on the last day of the contest.
We use these dates for computing scores


CURSOR c_empls IS


select emplid, posnbr, jobcode


from employe
es


where v_enddate between effdate and endeffdate


AND isactive = '1'


AND emplid != ' '


AND jobcode IN (SELECT contest_jobcode.jobcode FROM contest_jobcode WHERE
contest_jobcode.id = v_contestID)


AND emplid IN (SELECT emplsunderposnbr.subemplid FROM em
plsunderposnbr WHERE
emplsunderposnbr.mgrposnbr = v_posnbrlevel AND emplsunderposnbr.subemplid != ' ')


AND emplid IN (SELECT pspath.emplid FROM pspath WHERE pspath.compplan IN (SELECT
contest_compplan.compplan FROM contest_compplan WHERE contest_compplan.
id =
v_contestID) )


--
and emplid = '0099460'


ORDER BY emplid;


/* SELECT emplid, posnbr,


Greatest(effdate,v_startdate) as startdate,


Least(endeffdate,v_enddate) as enddate


FROM employees


WHERE endeffdate = to_date('01/01/9999','mm/dd/yyyy')


AND jo
bcode IN (SELECT contest_jobcode.jobcode FROM contest_jobcode WHERE
contest_jobcode.id = v_contestID)


AND emplid IN (SELECT emplsunderposnbr.subemplid FROM emplsunderposnbr WHERE
emplsunderposnbr.mgrposnbr = v_posnbrlevel AND emplsunderposnbr.subemplid !=

' ')


AND emplid IN (SELECT pspath.emplid FROM pspath WHERE pspath.compplan IN (SELECT
contest_compplan.compplan FROM contest_compplan WHERE contest_compplan.id =
v_contestID) )


AND isactive = '1'


AND emplid != ' '


ORDER BY emplid;*/


v_balancedRequire
d number;


--
cursor for ranking of scores


CURSOR c_rank IS


SELECT score, rank() OVER (partition by id order by score desc) as rank


FROM contest_data


WHERE (balanced = 1 OR v_balancedRequired = 0)


AND id = v_contestID


ORDER BY rank ASC


for update;


-
-

cursor holding the elements of the formula


CURSOR c_elements IS


SELECT a.weight, t1.formula as e_num, nvl2(a.attainmentid, t2.formula, a.attainmentvalue) as
e_den


FROM contest_formula a, elements t1, elements t2


WHERE a.elementid = t1.FIELD_ID


AND a
.attainmentid = t2.FIELD_ID(+)


AND a.id = v_contestID


ORDER BY myorder;


v_emplstartdate date;


v_nummonths number := 0;


v_isMonthly number := 0;


i number;


v_thismonthstart date;


v_thismonthend date;


v_tmpVal number;


v_tmpTotal number;


BEGIN


--
ge
t the contest dates


SELECT fromdate, todate, balanced


INTO v_startdate, v_enddate, v_balancedRequired


FROM contest


WHERE id = v_contestid;


if (v_startdate = trunc(v_startdate,'MONTH') and v_enddate = last_day(v_enddate)) then


v_isMonthly := 1;


v_num
months := round((v_enddate
-
v_startdate)/30);
--

if contest is over 3 years long, this won't
work :)


end if;


--
get the posnbr of the contest level...makes the query above run faster actually...odd


SELECT posnbr


INTO v_posnbrlevel


FROM contest_level


WHERE id = v_contestID;


--
get the number of elements


SELECT count(*)


INTO v_numofelems


FROM contest_formula


WHERE id = v_contestID;


--

remove all old scores first


DELETE FROM contest_data WHERE id = v_contestid;


--
now loop over the employees in

contest entering data on each iter


--
note the AND ROWNUM < 2 in the two queries...if the num or denom is a literal, we need to pull
back only one row.


v_tempMoney := 0;


FOR cr_empl IN c_empls LOOP


v_score := 0;


v_elementNum := 1;


--

get the start d
ate for this empl in the current contiguous job code


select greatest(min(effdate),v_startdate)


into v_emplstartdate


from


(


select emplid, effdate, endeffdate, jobcode,


lead(effdate,1) over (order by effdate) as nextdate


from employees


where emplid
= cr_empl.emplid


and jobcode IN (SELECT contest_jobcode.jobcode FROM contest_jobcode WHERE
contest_jobcode.id = v_contestID)


and isactive = 1


)


where (nextdate = endeffdate+1 or nextdate is null);


FOR cr_elements IN c_elements LOOP


--

get the numerat
or


BEGIN


EXECUTE IMMEDIATE 'SELECT NVL(' || cr_elements.e_num || ',0) FROM data_empl_sales
WHERE emplid = :1 AND tran_date BETWEEN :2 AND :3 '


INTO v_numArray(v_elementNum)


USING cr_empl.emplid,v_emplstartdate,v_enddate;


EXCEPTION


WHEN No_data_foun
d THEN


v_numArray(v_elementNum) := 0;


when others then


declare


errmsg varchar2(256) := sqlerrm;


begin


raise_application_error(
-
20001,errmsg || ': rownum='||v_elementNum||',
emplid='||cr_empl.emplid||', ' ||cr_elements.e_num);


end;


END;


--

get the

denomenator


BEGIN


if (v_isMonthly = 1) then


v_tmpTotal := 0;


v_tmpVal := 0;


for i in reverse 0..v_nummonths
-
1 loop


v_thismonthstart := add_months(v_startdate,i);


v_thismonthend := last_day(add_months(v_startdate,i));


if (v_emplstartdate <= v_this
monthend) then


EXECUTE IMMEDIATE 'SELECT NVL(' || cr_elements.e_den || ',0) FROM data_empl_sales
WHERE emplid = :1 AND tran_date BETWEEN :2 AND :3 '


INTO v_tmpVal


USING cr_empl.emplid,v_thismonthstart,v_thismonthend;


--

else just use previous value


en
d if;


v_tmpTotal := v_tmpTotal + v_tmpVal;


end loop;


v_denArray(v_elementNum) := v_tmpTotal;


else


EXECUTE IMMEDIATE 'SELECT NVL(' || cr_elements.e_den || ',0) FROM data_empl_sales
WHERE emplid = :1 AND tran_date BETWEEN :2 AND :3 '


INTO v_denArray(v_
elementNum)


USING cr_empl.emplid,v_startdate,v_enddate;


end if;


EXCEPTION


WHEN No_data_found THEN


v_denArray(v_elementNum) := cr_elements.e_den;


when others then


declare


errmsg varchar2(256) := sqlerrm;


begin


raise_application_error(
-
20002,err
msg || ': rownum='||v_elementNum||',
emplid='||cr_empl.emplid);


end;


END;


--

get the weight


v_weightArray(v_elementNum) := cr_elements.weight;


v_elementNum := v_elementNum + 1;


END LOOP;


--
compute is balanced


v_isBalanced := 1;


FOR i IN 1..v_numof
elems LOOP


IF (v_denArray(i) = 0) THEN


v_isBalanced :=0;


exit;


ELSIF (v_numArray(i)/v_denArray(i) < 1) THEN


v_isBalanced :=0;


exit;


END IF;


END LOOP;


--
compute score


FOR i IN 1..v_numofelems LOOP


IF( v_denArray(i) = 0) THEN


v_score := NVL(v_sco
re,0);


ELSE


v_score := v_score + v_weightArray(i)*v_numArray(i)/v_denArray(i);


END IF;


END LOOP;


--

now insert the value into the table


INSERT INTO contest_data


(id, emplid, posnbr, score, balanced,


e1_num, e1_den,


e2_num, e2_den,


e3_num, e3_den
,


e4_num, e4_den,


e5_num, e5_den )


VALUES


(v_contestID, cr_empl.emplid, cr_empl.posnbr, Trunc(v_score, 4), v_isBalanced,


v_numArray(1), v_denArray(1),


v_numArray(2), v_denArray(2),


v_numArray(3), v_denArray(3),


v_numArray(4), v_denArray(4),


v_numA
rray(5), v_denArray(5)


);


END LOOP;


--
loop to insert ranks and tally points


v_rankNum := 1;


FOR cr_rank IN c_rank LOOP


--
compute money award if any


BEGIN


SELECT money_VALUE


INTO v_tempMoney


FROM contest_money


WHERE id = v_contestid


AND cr_rank
.rank BETWEEN rangefrom AND rangeto;


EXCEPTION


WHEN No_data_found THEN


v_tempMoney := NULL;


WHEN too_many_rows THEN


v_tempMoney := NULL;


END;


UPDATE contest_data


SET rank = cr_rank.rank,


tallypoint = (SELECT value FROM contest_tallypoint WHERE i
d = v_contestid AND rank =
v_rankNum ),


money = v_tempMoney


WHERE current of c_rank;


v_rankNum := v_rankNum + 1;


END LOOP;


UPDATE contest


SET lastrun = sysdate


WHERE id = v_contestid;


COMMIT;


END computeScores;


END;


/


Some CFML, this is a page

from the current project that displays
some related select controls. An example of mixing JavaScript with
CFML. Also shows use of a custom tag library via CFIMPORT


<!
-----------------------------------------------------------------------
>

<!
---


This f
ile is the property of Alltel

Original Author: Douglas Knudsen


Project Name:


Purpose:


Called by:



Parameters:





Returns:





Changes/whom:


---
>

<!
-----------------------------------------------------------------------
>

<!
---

begin non display

layer
---
>

<cfsilent>


<!
---

import taglib
---
>


<cfimport taglib="/customtags/display/" prefix="dsp" />




<!
---

page vars SET THESE FOR YOUR PAGE if needed
---
>


<!
---

end page vars
---
>


<!
---

local code for your page
---
>


<cfquery name="rate
s" datasource="#application.portal.getDSN()#">


SELECT rp.*, p.rateplan, b.billsystem


FROM rateplan rp, c_rateplan p, c_billsystem b


WHERE rp.c_rateplanid = p.c_rateplanid


AND rp.c_billsystemid = b.c_billsystemid


ORDER BY b.billsystem, p.rat
eplan, rp.descr, rp.url </cfquery>




<cfquery name="comp" datasource="#application.portal.getDSN()#">


SELECT rp.*, p.rateplan


FROM rateplancompete rp, c_rateplan p


WHERE rp.c_rateplanid = p.c_rateplanid


ORDER BY rp.type, p.rateplan, rp.price, rp
.url


</cfquery>


<!
---

end local code
---
>

</cfsilent>

<!
---

end non display layer
---
>

<!
---

begin display layer
---
>

<!DOCTYPE html PUBLIC "
-
//W3C//DTD XHTML 1.0 Transitional//EN"
"
http://www.w3.org/TR/xhtml1/DTD/xhtml1
-
transitional.dtd
">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>


<meta http
-
equiv="Content
-
Type" content="text/html; charset=iso
-
8859
-
1" />
<title><cfoutput>#application.portal.getAppTitle()#</cfoutput></t
itle>


<link href="/assets/styles/global.css" rel="stylesheet" type="text/css" /> <script
language="JavaScript" type="text/JavaScript" src="/assets/scripts/global.js"></script>




<script language="javascript">


//build arrays


var sys_plan = new Array;


var plan_code = new Array;


var code_url = new Array;


<cfoutput query="rates" group="billsystem">


sys_plan['#rates.billsystem#'] = new Array;


<cfset count = 0 />


<cfoutput group="rateplan">


sys_plan['#rates.billsystem#'][#count#] = '#rat
es.rateplan#';


<cfset count = count + 1 />




<cfset count2 = 0 />


plan_code['#rates.rateplan#'] = new Array;


<cfoutput group="descr">


plan_code['#rates.rateplan#'][#count2#] = '#rates.descr#';


<cfset count2 = count2 + 1 />





<cfset count3 = 0 />


code_url['#rates.descr#'] = new Array;


<cfoutput>


code_url['#rates.descr#'][#count3#] = '#rates.url#';


<cfset count3 = count3 + 1 />


</cfoutput>


</cfoutput>


</cfoutput>


</cfoutput>




var t
ype_plan = new Array;


var plan_price = new Array;


var price_url = new Array;


<cfoutput query="comp" group="type">


type_plan['#comp.type#'] = new Array;


<cfset count = 0 />


<cfoutput group="rateplan">


type_plan['#comp.type#'][#count#] = '
#comp.rateplan#';


<cfset count = count + 1 />


<cfset count2 = 0 />


plan_price['#comp.rateplan#'] = new Array;


<cfoutput group="price">


plan_price['#comp.rateplan#'][#count2#] = '#comp.price#';


<cfset count2 = count2 + 1 />


<
cfset count3 = 0 />


price_url['#comp.price#'] = new Array;


<cfoutput>


price_url['#comp.price#'][#count3#] = '#comp.url#';


<cfset count3 = count3 + 1 />


</cfoutput>


</cfoutput>


</cfoutput>


</cfoutput>










function

setPlans(system)


{


var tmp = sys_plan[system];


var ptr = document.plan.rateplan;


ptr.options.length = 1;


for(var i=0; i<tmp.length; i++)


{


var o = document.createElement('OPTION');


o.value = tmp[i];


o.innerHTML = tmp[i];


ptr.appendC
hild(o);


}


document.plan.code.options.length = 1;


document.plan.code.selectedIndex = 0;


}




function setCodes(plan)


{


var tmp = plan_code[plan];


var ptr = document.plan.code;


ptr.options.length = 1;


for(var i=0; i<tmp.length; i++)


{


v
ar o = document.createElement('OPTION');


o.value = tmp[i];


o.innerHTML = tmp[i];


ptr.appendChild(o);


}


}




function getIt()


{


var tmp = document.plan.code.value;


if(tmp)


{


url = code_url[tmp];


pop = window.open(url,'pop','');


}


}






function setPlansB(type)


{


var tmp = type_plan[type];


var ptr = document.comp.rateplan;


ptr.options.length = 1;


for(var i=0; i<tmp.length; i++)


{


var o = document.createElement('OPTION');


o.value = tmp[i];


o.innerHTML = tmp[i];


ptr.appendChild(o);


}


document.comp.price.options.length = 1;


document.comp.price.selectedIndex = 0;


}




function setPrices(plan)


{


var tmp = plan_price[plan];


var ptr = document.comp.price;


ptr.options.length = 1;


for(var i=0; i<tmp.le
ngth; i++)


{


var o = document.createElement('OPTION');


o.value = tmp[i];


o.innerHTML = tmp[i];


ptr.appendChild(o);


}


}




function getItB()


{


var tmp = document.comp.price.value;


if(tmp)


{


url = price_url[tmp];


pop = window.op
en(url,'pop','');


}


}


</script>

</head>

<body>

<!
---

get header
---
>

<dsp:navheader ratespromos='true' username="#session.user.name#"
level="#session.user.level#" role="#session.user.role#" />

<!
---

end header call
---
>

<!
---

BREADCRUMBS have been

removed...not in requirements...maybe for phase 2 DK
---
>

<!
---

breadcrumb
---
>

<!
---

<dsp:breadcrumb />
---
>

<!
---

end call
---
>



<!
---

Begin Left Column
---
>

<dsp:leftcolumn />

<!
---

End Left Column
---
>

<!
---

Begin Right Column
---
>

<dsp:right
column />

<!
---

End Right Column
---
>

<!
---

Begin Middle Column
---
>

<div id="middlecolumn">


<!
---

news
---
>


<!
---

section is rates & promos news so sectiond = 6
---
> <dsp:news title="Rates & Promos
News" newssectionid="6" roleid="#session.user.rol
eid#" levelid="#session.user.levelid#" />


<!
---

end call
---
>


<br />


<h1>Pricing Grids </h1>




<h3>Current ALLTEL Pricing</h3>


<p>Select the criteria below to view the latest pricing grid.</p>




<p>


<form name="plan">


<strong>Select System:</stro
ng>


<cfoutput query="rates" group="billsystem">


<input name="billsystem" type="radio" value="#rates.billsystem#" onclick="setPlans(this.value);"
/> #rates.billsystem# </cfoutput> <br /> <select name="rateplan"
onChange="setCodes(this.value);">


<opt
ion valu="">
--

Select Plan
--
</option>


</select>


<select name="code">


<option selected="selected">
--

Select Code
--
</option>


</select>


<a href="javascript:;"><input type="button" value="View" class="formbutton" onclick="getIt();"
/>
</a> </form> </p>




<div class="litegraybox" style="clear:both; ">


<!
---

Begin Color Box Top : DO NOT put any spaces in DIV "colorboxtop" or the design will
break.
---
>


<div class="colorboxtop"><img src="/assets/images/global/corner_tr.gif" width="4
" height="4"
border="0" style="float:right;" /><img src="/assets/images/global/corner_tl.gif" width="4"
height="4" border="0" /></div>


<!
---

End Color Box Top
---
>


<!
---

Begin Color Box Content
---
>


<span style="float:right;"><a href="javascript:;">
View Latest
Newsletter</a></span><h3>Competitive Information</h3>


<p>Select the criteria below to view a comparison grid of ALLTEL plans with our
competitors.</p>


<form name="comp">


<strong>Select Competitor Type:</strong>


<cfoutput query="comp
" group="type">


<input name="type" type="radio" value="#comp.type#" onclick="setPlansB(this.value);" />
#comp.type# </cfoutput> <br />


<select name="rateplan" onChange="setPrices(this.value);">


<option selected="selected">
--

Select Plan
--
</option
>


</select>




<select name="price">


<option selected="selected">
--

Select Price Range
--
</option>


</select>


<a href="javascript:;"><input type="submit" value="View" class="formbutton" onclick="getItB();"
/></a>


</form>


<!
---

Begin Color B
ox Bottom : DO NOT put any spaces in DIV "colorboxbottom" or the design
will break.
---
>


</span>


<div class="colorboxbottom"><img src="/assets/images/global/corner_br.gif" width="4"
height="4" border="0" style="float:right;" /><img src="/assets/images/
global/corner_bl.gif"
width="4" height="4" border="0" /></div>


<!
---

End Color Box Bottom
---
>


</div>


<!
---

End Lite Gray Box
---
>




<!
---

get footer
---
>


<dsp:footer />


<!
---

end footer call
---
>

</div>

<!
---

End Middle Column
---
>

</body>

</h
tml>

<!
---

end display layer
---
>



My “wow, that’s impressive JavaScript” example. This code was
written about 2.5 years ago now. It allowed the user to build a logic
statement out of some variables. Such as

If(a) Then (b) else (c)


<!
-------------
----------------------------------------------------------
>

<!
---


This file is the property of Alltel

Original Author: Douglas Knudsen

Project Name:

Purpose:



Called by:






Parameters:






Returns:






Changes/whom:


---
>

<!
-------------------
----------------------------------------------------
>




<!
---

web page starts here
---
>

<!DOCTYPE HTML PUBLIC "
-
//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head>
<title>Untitled</title>




<script language="JavaScript">




a_state = new Array();


a_
state[0] = 'ST_START';


a_state[1] = 'ST_OPEN_IF';


a_state[2] = 'ST_IF_OPER';


a_state[3] = 'ST_OPEN_THEN';


a_state[4] = 'ST_THEN_OPER';


a_state[5] = 'ST_LAST';




LC_IF = "If ("


LC_OPENPAREN = " ("


LC_AND = " AND "


LC_OR = " OR
"


LC_CLOSEPAREN = ") "


LC_THEN = ") Then ("


LC_ELSE = ") Else ("


LC_ELSEIF = ") Else If ("


LC_END = ") End If"



a_qual = new Array();


<cfloop index="i" from="1" to="#quals.recordcount#">


a_qual[<cfoutput>#val(i
-
1)#</cfoutput>] = '<cfoutput
>#quals.descr[i]#</cfoutput>';


</cfloop>






a_pay = new Array();


<cfloop index="i" from="1" to="#pays.recordcount#">


a_pay[<cfoutput>#val(i
-
1)#</cfoutput>] = '<cfoutput>#pays.descr[i]#</cfoutput>';


</cfloop>




var statenum = 0;


var a_stat
e = new Array();


var a_logic = new Array();


var clickcnt = 0;


a_state[0] = 0;


a_logic[0] = '';


parencnt = 1;


elsecnt = 0;




function changeState(direction)


{


state_ptr = document.daForm.state;


disp_ptr = document.daForm.disp;







if(direction == 'forw')


{


tmp = check_parens(a_state[clickcnt], state_ptr.value);


if(tmp)


{


clickcnt = clickcnt + 1;


a_state[clickcnt] = next_state(a_state[clickcnt
-

1], state_ptr.value);


a_logic[clickcnt] = state_ptr.va
lue;


}


else


{


return false;


}


}


else if(direction == 'back')


{


if(clickcnt == 0)


return false;


if(a_logic[clickcnt] == LC_OPENPAREN)


parencnt = parencnt
-

1;


if(a_logic[clickcnt] == LC_CLOSEPAREN)


pa
rencnt = parencnt + 1;


clickcnt = clickcnt
-

1;


a_state.length = a_state.length
-

1;


a_logic.length = a_logic.length
-

1;


}




// alert(a_logic[clickcnt]);




// alert(statenum);


fill_select(choices_load(a_state[clickcnt]));




//alert(a_logic[clickcnt]);


add2disp(a_logic);






}




function next_state(state, lc_choice)


{


switch(state)


{


case 0:


return 1;


break;


case 1:


if(lc_choice == LC_OPENPAREN)


return 1;


else


ret
urn 2;


break;


case 2:


if(lc_choice == LC_THEN)


return 3;


else if(lc_choice == LC_CLOSEPAREN)


return 2;


else


return 1;


break;


case 3:


return 4;


break;


case 4:



if( lc_choice == LC_AND)


return 3;


else if(lc_choice == LC_ELSE)


return 3;


else if(lc_choice == LC_ELSEIF)


return 1;


else if(lc_choice == LC_END)


return

0;


break;


}


}


function check_parens(state, lc_choice)


{


// checking paren count


if(lc_choice == LC_OPENPAREN)


parencnt = parencnt + 1;


else if(lc_choice == LC_CLOSEPAREN)


parencnt = parencnt
-

1;


else if((lc_choice == LC
_THEN) || (lc_choice == LC_ELSE) || (lc_choice == LC_ELSEIF))


{


if(parencnt > 1)


{


alert('Syntax Error: Unmatched left parentheses. Use back button and correct.');


return false;


}


else if(parencnt < 1)


{


alert('Syntax

Error: Unmatched right parentheses. Use back button and correct.');


return false;


}


}




//checking else count


if((state == 4) && (elsecnt == 1))


{


if(lc_choice == LC_ELSE)


{


alert("Syntax Error: Only one 'Else' is allow
ed per 'If'.");


return false;


}


else if(lc_choice == LC_ELSEIF)


{


alert("Syntax Error: An 'Else If' may not follow an 'Else'.");


return false;


}


}


else if(lc_choice == LC_ELSE)


elsecnt = 1;


else if(lc_choice == L
C_IF)


elsecnt = 0;


return true;




}




function choices_load(state)


{


var a_tmp = new Array();




switch(state)


{


case 0:


a_tmp[0] = LC_IF;


break;


case 1:


a_tmp[0] = LC_OPENPAREN;


for(i=0; i < a_qual
.length; i++)


{


a_tmp[i + 1] = a_qual[i];


}


break;


case 2:


a_tmp[0] = LC_AND;


a_tmp[1] = LC_OR;


a_tmp[2] = LC_CLOSEPAREN;


a_tmp[3] = LC_THEN;


break;


case 3:


for(i=0; i < a_pay.length; i++)


{



a_tmp[i] = a_pay[i];


}


break;


case 4:


a_tmp[0] = LC_AND;


a_tmp[1] = LC_ELSE;


a_tmp[2] = LC_ELSEIF;


a_tmp[3] = LC_END;


break;


default:


break;




}


return a_tmp;


}




function fill_select(in_ar
ray)


{


state_ptr = document.daForm.state;


state_ptr.options.length = 0;




for(i=0; i < in_array.length; i++)


{


op = document.createElement("OPTION");


op.value = in_array[i];


txt = document.createTextNode(in_array[i]);


op.app
endChild(txt);


state_ptr.appendChild(op);


}


}




function add2disp(a_in)


{


var disp_ptr = document.daForm.disp;


disp_ptr.value = '';




for(i=0; i < a_in.length; i=i+1)


{


disp_ptr.value = disp_ptr.value + a_in[i];


}


}





function savelogic()


{


document.daForm.statelist.value = a_state.toString();


document.daForm.logiclist.value = a_logic.toString();


document.daForm.submit();


}




</script>



</head>

<body>


<form
action="index.cfm?action=add&compplan=<cfou
tput>#url.compplan#</cfoutput>&cmptnbr=<cfout
put>#url.cmptnbr#</cfoutput>&rulenbr=<cfoutput>#url.rulenbr#</cfoutput>" name="daForm"
method="post"> <table align="center">


<tr>


<td>


<input class="butt" type="button" value="Go Back" onClick="change
State('back');"
onmouseover="this.style.background='#00ccff';"
onmouseout="this.style.background='#4B97E4';">


</td>


<td>


<select name="state" size="10" onClick="changeState('forw');" style="cursor:
Hand;width:300px;">


<option value="If (">If

(</option>


</select>


</td>


<td>


<textarea name="disp" cols="40" rows="10" onClick="this.blur();"
onFocus="this.blur();"></textarea>


</td>


<td>


<input class="butt" type="button" value="Save Changes" onClick="savelogic();"
onmouseov
er="this.style.background='#00ccff';"
onmouseout="this.style.background='#4B97E4';">


</td>


</tr>




</table>

<input type="Hidden" name="statelist" value="">

<input type="Hidden" name="logiclist" value="">

</form>


</body>

</html>




Some WAP code.
This is part of a wireless portal I am working on.


<cfsilent>


<cfset ws =
CreateObject("webservice","http://rapiddev.alltel.com/webservices/com/alltel/trendit/trend.cfc?wsd
l") /> <cfinvoke component="#application.tools#"


method="getTrendITWML" return
variable="userRpts"


emplid="#session.user.emplid#"


type="WML" />


<cfquery name="daRpts" dbtype="query">


SELECT * FROM userRpts WHERE segment = 'SALES'


</cfquery>


<cfset posnbrTop = application.tools.getPosnbrTop(session.user.emplid) />

<cf
invoke component="com.alltel.employee" method="getEmployeeByPosnbr"
posnbr="#posnbrTop#" returnvariable="who" /> </cfsilent> <cfheader NAME="Expires"
VALUE="Mon, 26 Jul 1997 05:00:00 GMT"> <cfheader NAME="Pragma" VALUE="no
-
cache">
<cfheader NAME="cache
-
con
trol" VALUE="no
-
cache, no
-
store, must
-
revalidate"> <cfcontent
type="text/vnd.wap.wml"><?xml version="1.0"?> <!DOCTYPE wml PUBLIC "
-
//PHONE.COM//DTD WML 1.1//EN" "
http://www.phone.com/dtd/wml11.dtd
">

<wml>


<card id="home" title="TRENDIT">


<p>Data for <cfoutput>#who.name#</cfoutput><br />


SEGMENT: SALES <br /><br />


<cfoutput query="daRpts">


<cfset tmp = ws.getData(posnbrTop,daRpts.period,daRpts.elementid, 'SALES') />


#tmp.displayname#<br />


#d
aRpts.period#<br />


#tmp.amount#<br /><br />


</cfoutput>


</p>


<do type="gome" label="BACK">


<prev />


</do>


</card>

</wml>




Some Java, a DO for a small project I did that involved a form and
code to turn the data into XML and pass it to an

external app via an
HTTP POST.


package com.alltel.alltelagents.csform;



/**


* @version 1.0


*

@author Douglas Knudse


* Date: 01/18/2004


*


* Description: This class is the Data Object for the Customer Service Data.


*


* Change History


*


* 01
/18/2004
-

Initial creation


*


*/



public class CustSvcData

{


//Agent Information


private String m_strCompanyNm = "";


private String m_strAgentPhoneNo = "";


private String m_strAgentNm = "";


private String m_strSalesID = "";


private String m_strEm
ail = "";




//Customer Information


private String m_strBillSysInd = "";


private String m_strCustFirstNm = "";


private String m_strCustLastNm = "";


private String m_strCustPhoneNo = "";


private String m_strCustMobileNo = "";


private String m_strCustA
cctNo = "";


private String m_strCustEmail = "";




//Other


private String m_strAcctPassword = "";


private String m_strSSN = "";


private String m_strBillingAddress = "";


private String m_strBillingCity = "";


private String m_strBillingState = "";


pri
vate String m_strBillingZip = "";


private String m_strDOB = "";


private String m_strAdjustmentAmount = "";




//Customer Service Options


//Change of Address


private String m_strChangeOfAddress = "";


private String m_strNewAddress = "";


private String

m_strNewCity = "";


private String m_strNewState = "";


private String m_strNewZip = "";


private String m_strNewHomePhone = "";




//Rate Plan Change


private String m_strRatePlanChange = "";


private String m_strCurrentPlanName = "";


private String m_s
trCurrentPlanCode = "";


private String m_strCurrentMonthlyAccess = "";


private String m_strNewPlanName = "";


private String m_strNewPlanCode = "";


private String m_strNewMonthlyAccess = "";




//Promotion Discrepancy


private String m_strPromotionDiscr
epancy = "";


private String m_strPromoDiscrepancyDesc = "";




//Billing Inquiries and Adjustments


private String m_strBillingAdjustment = "";


private String m_strBillingAdjDesc = "";



//Generic Comments


private String m_strGenericComments = "";




pu
blic CustSvcData()


{


}




public String getCompanyNm()


{



return this.m_strCompanyNm;


}




public void setCompanyNm(String val)


{



this.m_strCompanyNm = val;


}




public String getAgentPhoneNo()


{



return this.m_strAgentPhoneNo;


}




public void

setAgentPhoneNo(String val)


{



this.m_strAgentPhoneNo = val;


}




public String getAgentNm()


{



return this.m_strAgentNm;


}




public void setAgentNm(String val)


{



this.m_strAgentNm = val;


}




public String getSalesID()


{



return this.m_strSa
lesID;


}




public void setSalesID(String val)


{



this.m_strSalesID = val;


}



public String getEmail()


{



return this.m_strEmail;


}




public void setEmail(String val)


{



this.m_strEmail = val;


}




public String getCustFirstNm()


{



return thi
s.m_strCustFirstNm;


}




public String getCustLastNm()


{



return this.m_strCustLastNm;


}




public void setCustFirstNm(String val)


{



this.m_strCustFirstNm = val;


}




public void setCustLastNm(String val)


{



this.m_strCustLastNm = val;


}




publ
ic String getCustPhoneNo()


{



return this.m_strCustPhoneNo;


}




public void setCustPhoneNo(String val)


{



this.m_strCustPhoneNo = val;


}




public String getBillSysInd()


{



return this.m_strBillSysInd;


}




public void setBillSysInd(String val)


{



this.m_strBillSysInd = val;


}




public String getCustMobileNo()


{



return this.m_strCustMobileNo;


}




public void setCustMobileNo(String val)


{



this.m_strCustMobileNo = val;


}




public String getCustAcctNo()


{



return this.m_strCustAcctNo;


}




public void setCustAcctNo(String val)


{



this.m_strCustAcctNo = val;


}




public String getCustEmail()


{



return this.m_strCustEmail;


}




public void setCustEmail(String val)


{



this.m_strCustEmail = val;


}




public String getAcctPassword
()


{



return this.m_strAcctPassword;


}




public void setAcctPassword(String val)


{



this.m_strAcctPassword = val;


}




public String getSSN()


{



return this.m_strSSN;


}




public void setSSN(String val)


{



this.m_strSSN = val;


}




public Stri
ng getBillingAddress()


{



return this.m_strBillingAddress;


}




public void setBillingAddress(String val)


{



this.m_strBillingAddress = val;


}




public String getBillingCity()


{



return this.m_strBillingCity;


}




public void setBillingCity(Strin
g val)


{



this.m_strBillingCity = val;


}




public String getBillingState()


{



return this.m_strBillingState;


}




public void setBillingState(String val)


{



this.m_strBillingState = val;


}






public String getBillingZip()


{



return this.m_str
BillingZip;


}




public void setBillingZip(String val)


{



this.m_strBillingZip = val;


}











public String getDOB()


{



return this.m_strDOB;


}




public void setDOB(String val)


{



this.m_strDOB = val;


}













public String getAdjustmen
tAmount()


{



return this.m_strAdjustmentAmount;


}




public void setAdjustmentAmount(String val)


{



this.m_strAdjustmentAmount = val;


}




//Change of Address


public String getChangeOfAddress()


{



return this.m_strChangeOfAddress;


}




public voi
d setChangeOfAddress(String val)


{



this.m_strChangeOfAddress = val;


}




public String getNewAddress()


{



return this.m_strNewAddress;


}




public void setNewAddress(String val)


{



this.m_strNewAddress = val;


}




public String getNewCity()


{



return this.m_strNewCity;


}




public void setNewCity(String val)


{



this.m_strNewCity = val;


}





public String getNewState()


{



return this.m_strNewState;


}




public void setNewState(String val)


{



this.m_strNewState = val;


}





public Strin
g getNewZip()


{



return this.m_strNewZip;


}




public void setNewZip(String val)


{



this.m_strNewZip = val;


}






public String getNewHomePhone()


{



return this.m_strNewHomePhone;


}




public void setNewHomePhone(String val)


{



this.m_strNewHom
ePhone = val;


}







//Rate Plan Change


public String getRatePlanChange()


{



return this.m_strRatePlanChange;


}




public void setRatePlanChange(String val)


{



this.m_strRatePlanChange = val;


}




public String getCurrentPlanName()


{



return thi
s.m_strCurrentPlanName;


}




public void setCurrentPlanName(String val)


{



this.m_strCurrentPlanName = val;


}




public String getCurrentPlanCode()


{



return this.m_strCurrentPlanCode;


}




public void setCurrentPlanCode(String val)


{



this.m_strC
urrentPlanCode = val;


}




public String getCurrentMonthlyAccess()


{



return this.m_strCurrentMonthlyAccess;


}




public void setCurrentMonthlyAccess(String val)


{



this.m_strCurrentMonthlyAccess = val;


}




public String getNewPlanName()


{



retur
n this.m_strNewPlanName;


}




public void setNewPlanName(String val)


{



this.m_strNewPlanName = val;


}




public String getNewPlanCode()


{



return this.m_strNewPlanCode;


}




public void setNewPlanCode(String val)


{



this.m_strNewPlanCode = val;


}




public String getNewMonthlyAccess()


{



return this.m_strNewMonthlyAccess;


}




public void setNewMonthlyAccess(String val)


{



this.m_strNewMonthlyAccess = val;


}





//Promotion Discrepancy



public String getPromotionDiscrepancy()


{



return t
his.m_strPromotionDiscrepancy;


}




public void setPromotionDiscrepancy(String val)


{



this.m_strPromotionDiscrepancy = val;


}




public String getPromoDiscrepancyDesc()


{



return this.m_strPromoDiscrepancyDesc;


}




public void setPromoDiscrepancyD
esc(String val)


{



this.m_strPromoDiscrepancyDesc = val;


}





//Billing Issue/Adjustment


public String getBillingAdjustment()


{



return this.m_strBillingAdjustment;


}




public void setBillingAdjustment(String val)


{



this.m_strBillingAdjustment
= val;


}




public String getBillingAdjDesc()


{



return this.m_strBillingAdjDesc;


}




public void setBillingAdjDesc(String val)


{



this.m_strBillingAdjDesc = val;


}




//Generic Comments


public String getGenericComments()


{



return this.m_strGen
ericComments;


}




public void setGenericComments(String val)


{



this.m_strGenericComments = val;


}


}