めまぴークライアントのデモ11のソース

めまぴークライアントのデモ11の記事はこちらです。

■Application.cfm

<cfsetting enableCFoutputOnly="yes">

<cfapplication name="#hash( getCurrentTemplatePath() )#"
    clientmanagement="Yes"
    sessionmanagement="yes"
    loginStorage="session"
    sessiontimeout=#CreateTimeSpan(1, 0, 0, 0)# >

<!---===================================
設定
====================================--->
<cfparam name="cookie.user_id"  default="">
<cfparam name="cookie.key"      default="">
<cfparam name="session.word"    default="">
<cfparam name="session.chk"     default="">
<cfset request.user_id          = cookie.user_id>
<cfset request.key              = cookie.key>
<cfset request.word             = session.word>
<cfset request.chk              = session.chk>
<cfset request.cat_id           = 14>

<!--- 通常
<cfset request.proxyServer      = "">
<cfset request.proxyPort        = "80">
--->
<!--- 会社
<cfset request.proxyServer      = "xx.xx.xx.xx">
<cfset request.proxyPort        = "xx">
--->
<cfset request.proxyServer      = "">
<cfset request.proxyPort        = "80">
<cfset request.url              = "http://memapi.utalab.com/index.cfm?go=">

■index.cfm

<cfprocessingdirective pageEncoding = "UTF-8">
<!---/////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////--->
<cfparam name="url.p"       default="">
<cfparam name="url.page"    default="1">

<cfparam name="form.id"         default="">
<cfparam name="form.c1"         default="">
<cfparam name="form.c2"         default="">
<cfparam name="form.c2_yyyy"    default="">
<cfparam name="form.c2_mm"      default="">
<cfparam name="form.c2_dd"      default="">
<cfparam name="form.c3"         default="">
<cfparam name="form.c4"         default="">
<cfparam name="form.c4_yyyy"    default="">
<cfparam name="form.c4_mm"      default="">
<cfparam name="form.c4_dd"      default="">
<cfparam name="form.chk"        default="">

<cfswitch expression = "#url.p#">
    <!--- srch --->
    <cfcase value="srch">
        <cfset session.word = form.word>
        <cfset session.chk  = form.chk>
    </cfcase>
    <!--- addEnd --->
    <cfcase value="addEnd">
        <cfhttp url="#request.url#dataAddEx"
            proxyServer = "#request.proxyServer#"
            proxyPort   = "#request.proxyPort#"
            method="post">

            <cfhttpparam type="formField" name="user_id"    value="#request.user_id#">
            <cfhttpparam type="formField" name="key"        value="#request.key#">
            <cfhttpparam type="formField" name="cat_id"     value="#request.cat_id#">
            <cfhttpparam type="formField" name="c1"         value="#form.c1#">
            <cfhttpparam type="formField" name="c2"         value="#form.c2_yyyy#/#form.c2_mm#/#form.c2_dd#">
            <cfhttpparam type="formField" name="c3"         value="#form.c3#">
            <cfhttpparam type="formField" name="c4"         value="NO">
        </cfhttp>
    </cfcase>
    <!--- updEnd --->
    <cfcase value="updEnd">
        <cfhttp url="#request.url#dataUpdEx"
            proxyServer = "#request.proxyServer#"
            proxyPort   = "#request.proxyPort#"
            method="post">

            <cfhttpparam type="formField" name="user_id"    value="#request.user_id#">
            <cfhttpparam type="formField" name="key"        value="#request.key#">
            <cfhttpparam type="formField" name="cat_id"     value="#request.cat_id#">
            <cfhttpparam type="formField" name="id"         value="#form.id#">
            <cfhttpparam type="formField" name="c1"         value="#form.c1#">
            <cfhttpparam type="formField" name="c2"         value="#form.c2_yyyy#/#form.c2_mm#/#form.c2_dd#">
            <cfhttpparam type="formField" name="c3"         value="#form.c3#">
            <cfset tmp = form.c4_yyyy & form.c4_mm & form.c4_dd>
            <cfif tmp eq "">
                <cfhttpparam type="formField" name="c4"         value="NO">
            <cfelse>
                <cfhttpparam type="formField" name="c4"         value="#form.c4_yyyy#/#form.c4_mm#/#form.c4_dd#">
            </cfif>
        </cfhttp>
    </cfcase>
    <!--- delEnd --->
    <cfcase value="delEnd">
        <cfhttp url="#request.url#dataDelEx"
            proxyServer = "#request.proxyServer#"
            proxyPort   = "#request.proxyPort#"
            method="post">

            <cfhttpparam type="formField" name="user_id"    value="#request.user_id#">
            <cfhttpparam type="formField" name="key"        value="#request.key#">
            <cfhttpparam type="formField" name="cat_id"     value="#request.cat_id#">
            <cfhttpparam type="formField" name="id"         value="#form.id#">
        </cfhttp>
    </cfcase>
</cfswitch>
<cfif findnocase("end", url.p)>
    <cflocation url="index.cfm" addtoken="no">
</cfif>

<cfparam name="form.flg"    default="add">
<cfif url.p eq "upd">
    <cfset st = cst_getData(url.id, url.page)>
    <cfset form.id      = st.data.id>
    <cfset form.c1      = st.data.c1>
    <cfset form.c2_yyyy = ListGetAt(st.data.c2, 1, "/")>
    <cfset form.c2_mm   = ListGetAt(st.data.c2, 2, "/")>
    <cfset form.c2_dd   = ListGetAt(st.data.c2, 3, "/")>
    <cfset form.c3      = st.data.c3>
    <cfset form.c4_yyyy = "">
    <cfset form.c4_mm   = "">
    <cfset form.c4_dd   = "">
    <cfif st.data.c4 neq "NO">
        <cfset form.c4_yyyy = ListGetAt(st.data.c4, 1, "/")>
        <cfset form.c4_mm   = ListGetAt(st.data.c4, 2, "/")>
        <cfset form.c4_dd   = ListGetAt(st.data.c4, 3, "/")>
    </cfif>
    <cfset form.flg     = "upd">
</cfif>
<cfset fm = cst_fm()>
<cfset st = cst_getData("", url.page)>
<cfset cst_layout(st,fm)>
<!---=================================================================
cst_getData
==================================================================--->
<cffunction name="cst_getData" access="public" returnType="struct" output="no">
    <cfargument name="id" type="string" required="yes">
    <cfargument name="page" type="string" default="1">

    <cfhttp url         = "#request.url#dataGetEx"
            proxyServer = "#request.proxyServer#"
            proxyPort   = "#request.proxyPort#"
            method="post">
        <cfhttpparam type="formField" name="user_id"    value="#request.user_id#">
        <cfhttpparam type="formField" name="key"        value="#request.key#">
        <cfhttpparam type="formField" name="id"         value="#arguments.id#">
        <cfhttpparam type="formField" name="cat_id"     value="#request.cat_id#">
        <cfhttpparam type="formField" name="fil_id"     value="c2">
        <cfhttpparam type="formField" name="fld_list"   value="id,cat_id,c1,c2,c3,c4">
        <cfhttpparam type="formField" name="srch_fld"   value="c1">
        <cfhttpparam type="formField" name="word"       value="#session.word#">
        <cfif form.chk neq "">
            <cfhttpparam type="formField" name="fromto_fld" value="c4">
            <!--- 未使用 --->
            <cfif form.chk eq "1">
                <cfhttpparam type="formField" name="from"       value="NO">
                <cfhttpparam type="formField" name="to"         value="NO">
            </cfif>
            <!--- 使用済 --->
            <cfif form.chk eq "2">
                <cfhttpparam type="formField" name="from"       value="1999/01/01">
                <cfhttpparam type="formField" name="to"         value="2999/01/01">
            </cfif>
        </cfif>
        <cfhttpparam type="formField" name="row"        value="10">
        <cfhttpparam type="formField" name="page"       value="#arguments.page#">
        <cfhttpparam type="formField" name="type"       value="wddx">
        <cfhttpparam type="formField" name="debug"      value="">
    </cfhttp>

    <cfwddx action="wddx2cfml" input="#cfhttp.filecontent#" output="outData">

    <cfreturn outdata>
</cffunction>
<!---=================================================================
cst_fm
==================================================================--->
<cffunction name="cst_fm" access="public" returnType="string" output="no">

    <cfset var local = structNew()>

    <cfsavecontent variable = "local.tmp">
    <cfoutput>
    <form name="frm_in" action="index.cfm?p=addEnd" method="post">
        <input type="hidden" name="page"    value="1">
        <input type="hidden" name="id"      value="#form.id#">

        <table>
            <tr>
                <th>名称</th>
                <td>
                    <input type="text" name="c1" size="70" maxlength="255" value="#form.c1#">
                </td>
            </tr>
            <tr>
                <th>賞味期限</th>
                <td>
                    <select name="c2_yyyy">
                    <cfset local.from   = dateformat(DateAdd("yyyy", -1, now()), "yyyy")>
                    <cfset local.to     = local.from + 10>
                    <cfloop index="local.idx" from="#local.from#" to="#local.to#">
                        <option value="#local.idx#" <cfif form.c2_yyyy eq local.idx>selected</cfif>>#local.idx#</option>
                    </cfloop>
                    </select><select name="c2_mm">
                    <cfloop index="local.idx" from="1" to="12">
                        <cfset local.tmp = right("0" & local.idx, 2)>
                        <option value="#local.tmp#" <cfif form.c2_mm eq local.tmp>selected</cfif>>#local.tmp#</option>
                    </cfloop>
                    </select><select name="c2_dd">
                    <cfloop index="local.idx" from="1" to="31">
                        <cfset local.tmp = right("0" & local.idx, 2)>
                        <option value="#local.tmp#" <cfif form.c2_dd eq local.tmp>selected</cfif>>#local.tmp#</option>
                    </cfloop>
                    </select></td>
            </tr>
            <tr>
                <th>保管場所</th>
                <td>
                    <input type="text" name="c3" size="70" maxlength="255" value="#form.c3#">
                </td>
            </tr>
            <cfif form.flg neq "add">
                <tr>
                    <th>使用日</th>
                    <td>
                        <select name="c4_yyyy">
                        <option value=""></option>
                        <cfset local.from   = dateformat(DateAdd("yyyy", -1, now()), "yyyy")>
                        <cfset local.to     = local.from + 2>
                        <cfloop index="local.idx" from="#local.from#" to="#local.to#">
                            <option value="#local.idx#" <cfif form.c4_yyyy eq local.idx>selected</cfif>>#local.idx#</option>
                        </cfloop>
                        </select><select name="c4_mm">
                        <option value=""></option>
                        <cfloop index="local.idx" from="1" to="12">
                            <cfset local.tmp = right("0" & local.idx, 2)>
                            <option value="#local.tmp#" <cfif form.c4_mm eq local.tmp>selected</cfif>>#local.tmp#</option>
                        </cfloop>
                        </select><select name="c4_dd">
                        <option value=""></option>
                        <cfloop index="local.idx" from="1" to="31">
                            <cfset local.tmp = right("0" & local.idx, 2)>
                            <option value="#local.tmp#" <cfif form.c4_dd eq local.tmp>selected</cfif>>#local.tmp#</option>
                        </cfloop>
                        </select></td>
                </tr>
            </cfif>
        </table>
        <cfif form.flg eq "add">
            <input type="button" value="登録" onClick="js_add()">
        <cfelse>
            <input type="button" value="更新" onClick="js_upd()">
            <input type="button" value="削除" onClick="js_del()">
        </cfif>
        <br>
        <br>
    </form>
    </cfoutput>
    </cfsavecontent>

    <cfreturn local.tmp>
</cffunction>
<!---=================================================================
cst_layout
==================================================================--->
<cffunction name="cst_layout" access="public" returnType="void" output="yes">
    <cfargument name="stru" type="struct" required="yes">
    <cfargument name="fm"   type="string" required="yes">

    <cfset var st       = arguments.stru>
    <cfset var local    = structNew()>

    <cfoutput>
    <!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" lang="ja" xml:lang="ja">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="content-style-type" content="text/css; charset=utf-8" />
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <title>めまぴークライアントのデモ(保存食管理)</title>
        <meta name="keywords" content="めまぴー,memapi" />
        <meta name="description" content="めまぴークライアントのデモ(保存食管理)です。" />
        <link href="common.css" rel="stylesheet" type="text/css" media="all" />
        <script type="text/javascript" src="common.js"></script>
        <script type="text/javascript" src="index.js"></script>
    </head>
    <body>
    <!-- container -->
    <div id="container">

        <!-- header -->
        <div id="header">
            <!-- left -->
            <div class="left">
                <h1><a href="index.cfm" accesskey="1">めまぴークライアントのデモ(保存食管理)</a></h1>
                <h2>by <a href="http://memapi.utalab.com/" target="_blank">めまぴー</a></h2>
            <!-- /.left --></div>

            <!-- right -->
            <div class="right">
            <!-- /.right --></div>

        <!-- /##header --></div>

        <div class="clearblock"/>

        <!-- left -->
        <div id="left">
            <!-- menu -->
            <div class="menu">
                <p class="title">STATUS</p>

                <table>
                    <tr>
                        <th>ret</th>
                        <td align="right" id="ret">#st.ret#</td>
                    </tr>
                    <tr>
                        <th>pageCount</th>
                        <td align="right" id="pageCount">#st.pageCount#</td>
                    </tr>
                    <tr>
                        <th>recCount</th>
                        <td align="right" id="recCount">#st.recCount#</td>
                    </tr>
                </table>

            <!-- /.menu --></div>

            <!-- menu -->
            <div class="menu">
                <p class="title">検索</p>

                <form name="frm_srch" action="index.cfm?p=srch" method="post">
                <table>
                    <tr>
                        <td>
                            <input type="text" name="word" id="word" value="#session.word#"><br>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <select name="chk" id="chk">
                            <option value=""></option>
                            <option value="1"   <cfif session.chk eq 1>selected</cfif>  >未使用</option>
                            <option value="2"   <cfif session.chk eq 2>selected</cfif>  >使用済</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <input type="submit" value="検索">
                        </td>
                    </tr>
                </table>
                </form>
            <!-- /.menu --></div>
        <!-- /##left --></div>

        <!-- center -->
        <div id="center">
            <!-- content -->
            <div id="content">
                <h3>保存食管理</h3>

                #arguments.fm#

                <cfif st.recCount neq 0>
                    <table border="1">

                        <tr>
                            <th>名称</th>
                            <th>賞味期限</th>
                            <th>保管場所</th>
                            <th>使用日</th>
                        </tr>
                        <cfloop query="st.data">
                            <tr>
                                <td><a href="index.cfm?p=upd&id=#st.data.id#">#st.data.c1#</a></td>
                                <td>#st.data.c2#</td>
                                <td>#st.data.c3#</td>
                                <td>#st.data.c4#</td>
                            </tr>
                        </cfloop>
                    </table>
                    page:
                    <cfloop index="local.idx" from="1" to="#st.pageCount#">
                        <cfif local.idx eq url.page>
                            <strong>#local.idx#</strong>
                        <cfelse>
                            <a href="index.cfm?page=#local.idx#">#local.idx#</a>
                        </cfif>
                    </cfloop>
                </cfif>

            <!-- /##content --></div>
        <!-- /##center --></div>

        <div class="clearblock"/>

        <!-- footer -->
        <div id="footer">
            <form name="frm_cookie">
                <table border="0" width="100%">
                    <tr>
                        <td>user_id:<input type="text" name="user_id" id="user_id" value="#request.user_id#"></td>
                        <td>key:<input type="text" name="key" id="key" value="#request.key#"></td>
                        <td>
                            <input type="button" value="cookie change" onClick="js_cookie('index.cfm')">
                            <input type="button" value="cookie delete" onClick="js_cookie_del('index.cfm')">
                        </td>
                    </tr>
                </table>
            </form>
        <!-- /##footer --></div>
    <!-- /##container --></div>
    </body>
    </html>
    </cfoutput>
</cffunction>