/var/www/hkosl.com/ifapc/html_20210817/IFAPC2021/application/views/main/application_file_form.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php include_once('templates/top.php'); ?>
<style>
    input[type=checkbox] {
        transform: scale(1.5);
    }

    .upload_form_btn {
        border-radius: 2px;
        padding: 6px 10px;
        margin-bottom: 15px;
        font-size: 16px;
        -webkit-transition: all .2s ease-in-out;
        -o-transition: all .2s ease-in-out;
        transition: all .2s ease-in-out;
    }

    .upload_btn {
        background-color: #6CB359;
        color: #fff;
        border: 1px solid #6CB359;
    }

    .delete_btn {
        background-color: #D46A6A;
        color: #fff;
        border: 1px solid #D46A6A;
    }

    .download_btn {
        background-color: #496B8A;
        color: #fff;
        border: 1px solid #496B8A;
    }
</style>
<section id="page-title" style="background-image: url('<?= assets_url('main/img/lady_gold_2018.jpg'); ?>');" class="background-title">
    <div class="container clearfix">
        <h1><?= __('Application Fom'); ?></h1>
        <ol class="breadcrumb">
            <li><a href="#"><?= __('Home'); ?></a></li>
            <li><a href="#"><?= __('Application'); ?></a></li>
            <li class="active"><?= __('Form'); ?></li>
        </ol>
    </div>
</section>

<!-- Content
        ============================================= -->
<section id="content">
    <div class="content-wrap">
        <div class="container clearfix">
            <div class="form-controls">
                <div class="fl">
                    <a href="<?= front_url('application'); ?>""><i class="icon-angle-left"></i> <?= __('Back'); ?></a>
                </div>
                <div class="pull-right">
                    <?= __('Ref no.: ') . $reference_no?>
                </div>
                <div class="clear"></div>
            </div>

            <div class="tabpanel panel-form-01 active">
                <div class="nomination-form" id="upload_form">
                    <div class="heading"><?= __('Upload File'); ?></div>
                    <?php if (!empty($count_application_file)) {
                        foreach (
$application_file as $row) {
                            if (
$row['deleted'] == 1) {
                                continue;
                            }
                            
?>
                            <div class="row formrow">
                                <?= form_open_multipart(front_url(current_controller() . '/add/' $id), 'class="upload_file_form" '); ?>
                                <div class="col-md-6">
                                    <input type="text" class="sm-form-control file_title" name="title" placeholder="<?= __('Title'?>" value="<?= $row['title'?>">
                                </div>

                                <div class="col-md-3 display_file"><?php
                                    
if (!empty($row['file_name'])) {
                                        if (
preg_match("/jpg|jpeg|png|gif/i"$row["extension"])) {
                                            
base64_upload_decode($base64_path $row['file_name'], $row['extension'], $row['ori_file_name'], '') . '<br>' $row['ori_file_name'];
                                        } else {
                                            
base64_upload_decode($base64_path $row['file_name'], $row['extension'], $row['ori_file_name'], '');
                                        }
                                    }
                                    
?></div>

                                <div class="col-md-3" style="text-align: right;">
                                    <button type="button" class="upload_form_btn download_btn"
                                            onclick="dowload_upload_file(<?= $row['id'?>, this);"><?= __('Download'?></button>
                                    <button type="button" class="upload_form_btn delete_btn"
                                            onclick="delete_upload_file(<?= $row['id'?>, this);"><?= __('Delete'?></button>
                                </div>
                                <?= form_close(); ?>
                            </div>
                        <?php }
                    } 
?>


                    <div class="action-control">
                        <span class="button button-dark button-rounded" style="margin-left: 0;" onclick="add_upload_file();"><i class="icon-plus"></i></span>
                    </div>
                </div>

                <div id="clone_container" style="display: none;">
                    <div class="row formrow">
                        <?= form_open_multipart(front_url(current_controller() . '/upload_file/' $id), 'class="upload_file_form" '); ?>
                        <div class="col-md-4">
                            <input type="text" class="sm-form-control file_title" name="title" placeholder="<?= __('Title'?>">
                        </div>

                        <div class="col-md-2">
                            <input type="file" name="upload_file" class="file_content">
                            <span style="font-size: 12px;"><?= __('Format: jpg, png, gif, tif, doc, docx, ppt, pptx, pdf | Size: 20MB'?></span>
                        </div>

                        <div class="col-md-3 display_file"></div>

                        <div class="col-md-3" style="text-align: right;">
                            <span class="loading" style="display: none;"><?= __('Loading...'?> </span>
                            <button type="button" class="upload_form_btn upload_btn" onclick="ajax_upload_file(this);"><?= __('Upload'?></button>

                        </div>
                        <?= form_close(); ?>
                    </div>
                </div>

                <?php include_once('templates/bottom.php'); ?>

                <script>
                    $(function () {
                        <?php if(empty($count_application_file)){ ?>
                        add_upload_file();
                        <?php ?>
                    });

                    function add_upload_file() {
                        var clone = $('#clone_container').html();

                        if($('#upload_form .row').length == 0){
                            $('#upload_form .heading').after(clone);
                        }else{
                            $('#upload_form .row').last().after(clone);
                        }
                    }

                    function ajax_upload_file(_this) {
                        //console.log('ajax_upload_file');
                        //e.preventDefault();

                        var upload_file_form_selector = $(_this).closest('.upload_file_form');

                        var title = upload_file_form_selector.find('.file_title').val();
                        var file = upload_file_form_selector.find('.file_content').prop('files')[0];

                        var form_data = new FormData($(_this).closest('.upload_file_form')[0]);

                        //console.log(Array.from(form_data));

                        if (!file) {
                            alert('<?=__('Please upload file.')?>');
                        } else {
                            if (!title) {
                                alert('<?=__('Please enter title.')?>');
                            } else {
                                if (file.size > (1024 * 1024 * 20)) {
                                    upload_file_form_selector.find('.file_content').val("");
                                    alert('<?=__('File size should lower than 20 MB.')?>');
                                } else {
                                    $.ajax({
                                        url: '<?=front_url(current_controller() . '/add/' $id)?>',
                                        data: form_data,
                                        //data: new FormData(this),
                                        cache: false,
                                        processData: false,
                                        contentType: false,
                                        type: "POST",
                                        method: "POST",
                                        dataType: 'json',
                                        success: function (result) {
                                            //alert(msg);
                                            //console.log(result);
                                            if (result.response == 1) {
                                                upload_file_form_selector.find('.display_file').html(result.data.file_content);
                                                $(_this).parent().append('<button type="button" class="upload_form_btn delete_btn" onclick="delete_upload_file(' + result.data.id + ', this);"><?= __('Delete'?></button>');
                                            } else {
                                                alert(result.msg);
                                            }
                                        },
                                        beforeSend: function () {
                                            upload_file_form_selector.find('.loading').show();
                                        },
                                        complete: function () {
                                            upload_file_form_selector.find('.loading').hide();
                                        },
                                        error: function (xhr, ajaxOptions, thrownError) {
                                            //$('#loading').hide();
                                            alert(String(xhr.status));
                                            alert(String(thrownError));
                                        }
                                    });
                                }
                            }
                        }
                    }

                    function delete_upload_file(id, _this) {
                        alertify.set({
                            labels: {
                                ok: "<?=__('Delete')?>",
                                cancel: "<?=__('Cancel')?>"
                            }
                        });

                        alertify.confirm("<?=__('Confirm to delete?')?>", function (e) {
                            if (e) {
                                $.ajax({
                                    url: '<?=front_url(current_controller() . '/delete/')?>' + id,
                                    data: {},
                                    cache: false,
                                    processData: false,
                                    contentType: false,
                                    type: "GET",
                                    method: "GET",
                                    dataType: 'json',
                                    success: function (result) {
                                        //alert(msg);
                                        //console.log(result);
                                        if (result.response == 1) {
                                            $(_this).closest('.row').remove();
                                        } else {
                                            alert(result.msg);
                                        }
                                    },
                                    error: function (xhr, ajaxOptions, thrownError) {
                                        alert(String(xhr.status));
                                        alert(String(thrownError));
                                    }
                                });
                            } else {
                                // user clicked "cancel"
                            }
                        });
                    }

                    function dowload_upload_file(id, _this) {
                        window.open('<?=front_url(current_controller() . '/download/')?>' + id);
                    }

                </script>