/var/www/hkosl.com/sinomax/survey/webadmin/survey_form_modifyform.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php
    
require_once('check_login.php');

    
$campaign_id = (int)$_GET["campaign_id"];

    
$row get_campaign($campaign_id);

    
$sql99        "SELECT * FROM sys_cms_login WHERE cmsloginid=?";
    
$parameters99 = array((int)$row{'lastupby'});
    
$row99        bind_pdo($sql99$parameters99"selectone");
?>
<!DOCTYPE html>
<html>
<head>
    <?php require_once('html_head.php'); ?>
    <link rel="stylesheet" type="text/css" media="screen" href="../js/form_builder/assets/css/form-builder.min.css">
    <script src="../js/form_builder/assets/js/form-builder.min.js"></script>
    <script src="../js/form_builder/assets/js/form-render.min.js"></script>
    <script>
        jQuery(document).ready(function ($) {
            var fbTemplate = document.getElementById('fb-template'),
                formContainer = document.getElementById('rendered-form'),
                $fBInstance = $(document.getElementById('edit-form')),
                formRenderOpts = {
                    container: $('form', formContainer)
                };


            var options = {
                controlOrder: [
                    'header',
                    'text',
                    'checkbox-group',
                    'radio-group',
                    'date',
                ]
            };

            $(fbTemplate).formBuilder(options);

            $('.form-builder-save').click(function () {

                /*var edit_html = $("#edit-form").html();
                 $("#edit-form").html(edit_html.replace(/<br>/g, "||"));*/

                $fBInstance.toggle();
                $(formContainer).toggle();
                $(fbTemplate).formRender(formRenderOpts);
                //rendered-form

                var form_html = $("#rendered-form form").html();
                form_html = form_html.replace(/\|\|/g, "<br>");
                $("#rendered-form form").html(form_html.replace(/\|\|/g, "<br>"));
                $("#rendered-form form").html(form_html.replace(/checked/g, ""));


                /*$("#rendered-form form label").each(function () {
                 var label_space = $(this).html();
                 label_space = label_space.replace(/ /g, "&nbsp;");
                 $(this).html(label_space);
                 });*/
            });

            /*var edit_html = $("#edit-form").html();
             $("#edit-form").html(edit_html.replace(/\|\|/g, "<br>"));*/

            $('#save_form').click(function () {
                var form_html = $("#rendered-form form").html();
                var form_xml = $("#form-xml pre .xml").text();

                //ajax data
                var xmlhttp;

                if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                    xmlhttp = new XMLHttpRequest();
                }
                else {// code for IE6, IE5
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
                xmlhttp.onreadystatechange = function () {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        //document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
                        //console.log(xmlhttp.responseText);
                        var result = $.trim(xmlhttp.responseText);
                        console.log(result);
                        if (result != "SUCCESS") {
                            //alert(result);
                        } else {
                            location.href = "campaign_index.php";
                        }
                    }
                }
                xmlhttp.open("POST", "survey_form_modify.php", true);
                xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                xmlhttp.send("form_html=" + form_html + "&form_xml=" + form_xml + "&campaign_id=<?=$campaign_id?>");
            });

            $('.edit-form', formContainer).click(function () {
                $fBInstance.toggle();
                $(formContainer).toggle();
            });
        });
    </script>

    <?php
        
if (date("Y-m-d H:i:s") >= $row["start_date"]) {
            
//echo "<script type='text/javascript'>alert('This campaign has stated. You do not allow to update the survey form.'); /*history.back();*/ </script>";
            //exit;
        
}
    
?>
    <style>
        #rendered-form {
            clear: both;
            display: none;

        button {
            float: right;
        }

        }

        .view-data {
            display: none;
        }

        /* hide field option */
        #edit-form .description-wrap, #edit-form .access-wrap, #edit-form .className-wrap, #edit-form .name-wrap, #edit-form .maxlength-wrap, #edit-form .subtype-wrap{
            display: none;
        }

        .header-field .form-elements .label-wrap, .header-field .form-elements .subtype-wrap {
            display: block !important;
        }

        .radio-group label, .checkbox-group label {
            display: inline-table;
        }

        /* valid form type */
        .frmb-control li {
            display: none;
        }

        .icon-checkbox-group, .icon-radio-group, .icon-text-input, .icon-header, .icon-calendar{
            display: block !important;
        }

    </style>
</head>
<body>

<table width="1200" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td height="70" align="right" valign="middle" class="icontxt">
            <table border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td width="50" align="center" style="font-size: 12px;">
                    </td>
                    <td width="50" align="center">
                        <a href="campaign_index.php?msg=4"><img src="images/iconCancel.png" alt="Cancel" width="32" height="32" border="0"><br>
                            &nbsp;Cancel&nbsp;&nbsp;</a></td>
                    <td>&nbsp;</td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td>
            <span style="float:left;" class="pagetitletxt">
                &nbsp;&nbsp;<b><img src="images/iconList.jpg" width="48" height="48" align="absmiddle"/> Modify Survey
                    Form </b></span><span style="float:right;" class="msg">Last
                Update: <?= $row99{'cmsusername'} . '&nbsp;&nbsp;&nbsp;' $row{'lastupdate'}; ?></span>
        </td>
    </tr>
    <tr>
        <td align="left" valign="middle" style="padding-left: 10px;"><!-- Content -->
            <span class="msg">Add "||" (not L) in "Label" can separate question into 2 rows. This is for multiple
                language survey.<br> For question type with "Options", please set the "Value" same as"Label". "Options"
                cannot duplicate with others.</span>
            <hr style="margin-bottom: 20px;">
            <div id="edit-form"><textarea id="fb-template"><?= html_entity_decode($row["form_xml"]) ?></textarea>
            </div>
            <div id="rendered-form">
                <form action="#"></form>

                <hr style="margin-bottom: 20px;">
                <button class="btn btn-default edit-form">Edit</button>

                <?php
                    
//if (date("Y-m-d H:i:s") < $row["start_date"]) {
                    
echo '<button class="btn btn-primary" id="save_form">Save</button>';
                    
//}
                
?>

            </div>

            <div id="form-xml" style="display: none;"></div>

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

</body>
</html>