/var/www/hkosl.com/ifapc/html_20210817/IFAPC2021/application/controllers/Score.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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
<?php
ob_start
();
var_dump($object);
$getOb ob_get_clean();
$fileName APPPATH 'tmp' DIRECTORY_SEPARATOR 'phpdebug.php';
file_put_contents($fileNamedate('H:i:s') . ' ' __FILE__ ' -s- ' "\r\n" $getOb "\r\n"FILE_APPEND);
require_once 
APPPATH 'core/MY_Controller_2.php';
use 
Illuminate\Database\Capsule\Manager as DB;

class 
Score extends MY_Controller_2
{
    public function 
__construct()
    {
        
// set $this->table and $this->model
        
parent::__construct(__CLASS__);

        if (!(
$this->judge check_judge_login())) {
            
redirect(front_url('judge'));
        }

        
$this->updated_single_language_fields = array(

        );
        
$tmp = array(
            
'category_id' => __('Category'),
            
'nominee_title' => __('Title'),
            
'nominee_birth_date' => __('Date of Birth'),
            
'nominee_birth_place' => __('Place of Birth'),
            
'nominee_tel' => __('Contact Tel./ Moile No.'),
            
'nominee_wechat' => __('Wechat Account'),
            
'nominee_assistant_title' => __('Assistant&#39;s Title'),
            
'nominee_assistant_email' => __('Assistant&#39;s Email'),
            
'nominee_assistant_tel' => __('Assistant&#39;s Contact No.'),

            
'company_name' => __('Name of Present Company Name'),
            
'company_address' => __('Address of Present Company Name'),
            
'company_position' => __('Present Position'),
            
'company_position_years' => __('Number of years in present position'),
            
'company_is_founder' => __('Is the nominee a founder of current company?'),
            
'company_is_family_business' => __('Is it a family business?'),
            
'company_founded_year' => __('What year was the company established?'),
            
'company_industry' => __('Industry'),
            
'company_website' => __('Company website'),
            
'company_is_listed' => __('Is the company publicly listed?'),
            
'company_stock_code' => __('Stock code'),

            
'narrative_enterprise' => __('Enterprise Management and Development') . ' (' __('by bullet points') . ')',
            
'narrative_industry' => __('Industry Influence and Achievement') . ' (' __('by bullet points') . ')',
            
'narrative_contribution' => __('Contribution for the Greater Bay Area Development') . ' (' __('by bullet points') . ')',
            
'narrative_corporate' => __('Corporate and Social Responsibility') . ' (' __('by bullet points') . ')',
            
'narrative_personal' => __('Personal Reputation and Recognition') . ' (' __('provide supporting information') . ')',

            
'terms_is_declaration' => __('Declaration'),
            
'terms_is_not_attend' => __('Not Attend'),

            
'nominator_title' => __('Title'),
            
'nominator_job_title' => __('Present Position'),
            
'nominator_company' => __('Name of Present Company'),
            
'nominator_tel' => __('Office Tel./ Mobile No.'),
            
'nominator_address' => __('Correspondence Address'),
            
'nominator_reason' => __('Reason for nomination'),

            
'nominee_email' => __('Email'),
            
'nominator_email' => __('Email'),

            
'organization_name' => __('Name of Organization'),
            
'service_position' => __('Position Held'),
            
'participation_year' => __('Participation Year'),
            
'involvement' => __('Community Service Involvement'),
            
'achievement' => __('Achievement and Contributions'),
            
'judge_remark' => __('Remark'),
        );
        
$this->single_language_fields array_merge($this->updated_single_language_fields$tmp);

        
$this->updated_multiple_language_fields = array(

        );
        
$tmp = array(
            
'nominee_name_' => __('Name'),
            
'nominee_assistant_name_' => __('Assistant&#39;s Name'),

            
'nominator_name_' => __('Name'),
        );
        
$this->multiple_language_fields array_merge($this->updated_multiple_language_fields$tmp);

        
$this->single_language_validate_fields = array(
        );
        
$this->multiple_language_validate_fields = array(
        );


        
$this->single_language_encpytion_fields = array(
            
'nominee_birth_place''nominee_tel''nominee_wechat''nominee_assistant_tel''company_name''company_address''company_position''company_industry''company_website''narrative_enterprise''narrative_industry''narrative_contribution''narrative_corporate''narrative_personal''nominator_job_title''nominator_company''nominator_tel''nominator_address''nominator_reason',
        );
        
$this->multiple_language_encpytion_fields = array(
            
'nominee_name_''nominee_assistant_name_''company_position_years''nominator_name_',
        );
        
// $this->fields_permission[$field][0]: nomminee, $this->fields_permission[$field][1]: nommintor
        // 1: view
        // premission = view | update
        
$this->fields_permission = array(
            
'category_id' => '1',
            
'nominee_title' => '1',
            
'nominee_name_' => '1',
            
'nominee_birth_date' => '1',
            
'nominee_birth_place' => '1',
            
'nominee_email' => '1',
            
'nominee_tel' => '1',
            
'nominee_wechat' => '1',
            
'nominee_assistant_title' => '1',
            
'nominee_assistant_name_' => '1',
            
'nominee_assistant_email' => '1',
            
'nominee_assistant_tel' => '1',
            
'company_name' => '1',
            
'company_address' => '1',
            
'company_position' => '1',
            
'company_position_years' => '1',
            
'company_is_founder' => '1',
            
'company_is_family_business' => '1',
            
'company_founded_year' => '1',
            
'company_industry' => '1',
            
'company_website' => '1',
            
'company_is_listed' => '1',
            
'company_stock_code' => '1',
            
'organization_name' => '1',
            
'service_position' => '1',
            
'participation_year' => '1',
            
'involvement' => '1',
            
'achievement' => '1',
            
'narrative_enterprise' => '1',
            
'narrative_industry' => '1',
            
'narrative_contribution' => '1',
            
'narrative_corporate' => '1',
            
'narrative_personal' => '1',
            
'terms_is_declaration' => '1',
            
'terms_is_not_attend' => '1',
            
'nominator_title' => '1',
            
'nominator_name_' => '1',
            
'nominator_job_title' => '1',
            
'nominator_company' => '1',
            
'nominator_email' => '1',
            
'nominator_tel' => '1',
            
'nominator_address' => '1',
            
'nominator_reason' => '1',
        );
    }

    public function 
save_form($id)
    {
        
$this->run_validation false;
        
$this->submit_form($id);
    }

    public function 
submit_form($id null)
    {
        
$this->allow_methods = array('submit_form');

        
$groups_judges Group_judge_model::get_data_by_field_with_value(['judge_id' => $_SESSION['judge_id']]);
        
$groups_id = array();
        foreach (
$groups_judges as $row) {
            
$groups_id[] = $row['group_id'];
        }

        if (
count($application Application_model::get_certain($id)) == || !in_array($application['group_id'], $groups_id)) {
            
$_SESSION['msg_type'] = 'error';
            
$_SESSION['error_msg'] = __('The application is not available.');
            
$_SESSION['msg_back_url'] = front_url('score');
            
redirect(front_url('message'));
        }

        
$this->single_language_fields = array();
        
$this->single_language_validate_fields = array();
        
$scoring_items Scoring_item_model::get_data_by_application_id($id);
        foreach (
$scoring_items as $row) {
            
$this->single_language_fields[$row['code']] = $row['name_' get_lang()];
            
$this->single_language_validate_fields[$row['code']] = 'required|is_natural|greater_than_equal_to[0]|less_than_equal_to[20]';
        }

        
parent::submit_form($id);
    }

    protected function 
update_other_tables($id$current_update_data$action)
    {
        
$application $this->model->get_certain($id);

        if (
count(Score_status_model::get_data_by_field_with_value(['application_id' => $id'judge_id' => $_SESSION['judge_id'], 'judge_submitted' => 1]))) {
            
$_SESSION['msg_type'] = 'error';
            
$_SESSION['error_msg'] = __('The application have been scored.');
            
$_SESSION['msg_back_url'] = front_url('score');
            
redirect(front_url('message'));
        }

        
$delete_data = array(
            
"deleted" => 1,
            
"deleted_by" => $_SESSION['sys_user_id'],
            
"deleted_at" => date('Y-m-d H:i:s'),
        );
        
Score_model::where('application_id'$id)->where('judge_id'$_SESSION['judge_id'])->update($delete_data);

        
$scoring_items Scoring_item_model::get_data_by_application_id($id);
        
$have_score_status false;
        foreach(
$scoring_items as $row) {
            
$point $_POST[$row['code']];
            if (!empty(
$point) || $point === '0') {
                
$data = array(
                    
'application_id' => $id,
                    
'judge_id' => $_SESSION['judge_id'],
                    
'scoring_item_id' => $row['id'],
                    
'point' => $point
                
);
                
Score_model::create()->update($data);
                if (
$this->run_validation && !$have_score_status) {
                    
$have_score_status true;
                    
$data = array(
                        
'application_id' => $id,
                        
'judge_id' => $_SESSION['judge_id'],
                        
'judge_submitted' => 1,
                    );
                    
Score_status_model::create()->update($data);
                }
            };
        }

        
Score_remark_model::where('application_id'$id)->where('judge_id'$_SESSION['judge_id'])->update($delete_data);
        if (!empty(
$_POST['judge_remark'])){
            
$data = array(
                
'application_id' => $id,
                
'judge_id' => $_SESSION['judge_id'],
                
'remark' => $_POST['judge_remark'],
            );
            
Score_remark_model::create()->update($data);
        }

        
redirect(front_url('score'));
    }

    public function 
index()
    {
        
$where = empty($_GET['category']) ? "" "AND `category_id` = '" $_GET['category'] . "'";
        
$condition_master_id Master_type_code_model::get_data_by_field_with_value(['type_code' => 'APPLICATION CONDITION''code' => 'approve'])[0]['id'];

        
$sql "SELECT *
                FROM application AS a
                INNER JOIN
                    (SELECT group_id FROM group_judge WHERE `deleted` = 0 AND `status` = 1 AND judge_id = '
{$_SESSION['judge_id']}') AS gj
                ON a.`group_id` = gj.`group_id`
                LEFT JOIN
                    (SELECT SUM(`point`) AS total_point, `application_id` FROM score WHERE `deleted` = 0 AND `status` = 1 AND `judge_id` = '
{$_SESSION['judge_id']}' GROUP BY `application_id`) AS s
                ON a.`id` = s.`application_id`
                WHERE
                    `deleted` = 0 AND
                    `status` = 1 AND
                    `nominee_submitted` = 1 AND
                    `nominator_submitted` = 1 AND
                    `condition_master_id` = '
{$condition_master_id}'
                    
{$where}
        "
;
        
$applications json_decode(json_encode(DB::select($sql)), true);

        
$this->load->vars('model'$applications);
        
$this->load->vars('categoies'Category_model::get_data());
        
$this->allow_methods = array('index');
        
parent::index();
    }

    public function 
list_all()
    {
        
$where = empty($_GET['category']) ? "" "AND `category_id` = '" $_GET['category'] . "'";
        
$condition_master_id Master_type_code_model::get_data_by_field_with_value(['type_code' => 'APPLICATION CONDITION''code' => 'approve'])[0]['id'];

        
$sql "SELECT *
                FROM application AS a
                INNER JOIN
                    (SELECT group_id FROM group_judge WHERE `deleted` = 0 AND `status` = 1 AND judge_id = '
{$_SESSION['judge_id']}') AS gj
                ON a.`group_id` = gj.`group_id`
                LEFT JOIN
                    (SELECT
                        application_id,
                        MAX(CASE
                            WHEN scoring_item_id = 1
                                THEN point
                        END) AS item_1,
                        MAX(CASE
                            WHEN scoring_item_id = 2
                                THEN point
                        END) AS item_2,
                        MAX(CASE
                            WHEN scoring_item_id = 3
                                THEN point
                        END) AS item_3,
                        MAX(CASE
                            WHEN scoring_item_id = 4
                                THEN point
                        END) AS item_4,
                        MAX(CASE
                            WHEN scoring_item_id = 5
                                THEN point
                        END) AS item_5
                    FROM score
                    WHERE `deleted` = 0 AND `status` = 1 AND `judge_id` = '13'
                    GROUP BY `application_id`
                    ) AS s
                ON a.`id` = s.`application_id`
                WHERE
                    `deleted` = 0 AND
                    `status` = 1 AND
                    `nominee_submitted` = 1 AND
                    `nominator_submitted` = 1 AND
                    `condition_master_id` = '
{$condition_master_id}'
                    
{$where}
        "
;

        
$applications json_decode(json_encode(DB::select($sql)), true);

        
$this->load->vars('model'$applications);
        
$this->load->vars('scoring_items'Scoring_item_model::where('deleted'0)->where('status'1)->get());
        
$this->load->vars('categoies'Category_model::get_data());
        
$this->allow_methods = array('index');

        
$data["name_fields"] = $this->get_concat_single_and_multiple_language_fields('name');
        
$data["encrypt_fields"] = $this->get_concat_single_and_multiple_language_fields('encrypt');

        
$this->load->view('main/' $this->table '_list'$data);
    }

    public function 
modify($id)
    {
        
$this->allow_methods = array('modify');

        
$groups_judges Group_judge_model::get_data_by_field_with_value(['judge_id' => $_SESSION['judge_id']]);
        
$groups_id = array();
        foreach (
$groups_judges as $row) {
            
$groups_id[] = $row['group_id'];
        }

        if (
count($application Application_model::get_certain($id)) == || !in_array($application['group_id'], $groups_id)) {
            
$_SESSION['msg_type'] = 'error';
            
$_SESSION['error_msg'] = __('The application is not available.');
            
$_SESSION['msg_back_url'] = front_url('score');
            
redirect(front_url('message'));
        }

        
$scoring_items Scoring_item_model::get_data_by_application_id($id);

        
$this->tmp_data['model'] = $application;

        
$this->load->vars('scoring_items'$scoring_items);
        
$this->load->vars('categories'Category_model::get_data());
        
$this->load->vars('fields_permission'$this->fields_permission);
        
$this->load->vars('services'Application_service_model::get_data_by_field_with_value(['application_id' => $id]));

        if (
$count_application_file count($application_file Application_file_model::whereDeleted(0)->where('application_id'$id)->get())) {
            
$this->load->vars('count_application_file'$count_application_file);
            
$this->load->vars('base64_path''assets/files/application/');
            
$this->load->vars('application_file'$application_file);
        }

        
$data['name_fields'] = $this->get_concat_single_and_multiple_language_fields('name');

        
parent::modify($id);
    }

    public function 
list_submit() {
        
$scores json_decode($_POST['scores']);

        
$groups_judges Group_judge_model::get_data_by_field_with_value(['judge_id' => $_SESSION['judge_id']]);
        
$groups_id = array();
        foreach (
$groups_judges as $row) {
            
$groups_id[] = $row['group_id'];
        }

        foreach (
$scores as $id => $row) {
            if (
count($application Application_model::get_certain($id)) == || !in_array($application['group_id'], $groups_id)) {
                
$_SESSION['msg_type'] = 'error';
                
$_SESSION['error_msg'] = __('The application is not available.');
                
$_SESSION['msg_back_url'] = front_url('score');
                
redirect(front_url('message'));
            }
        }

        if (
$_POST['type'] == 'submit') {
            foreach (
$scores as $id => $row) {
                foreach (
$row as $item=> $value) {
                    if (!
is_numeric($value) || $value || $value 20) {
                        
$_SESSION['msg_type'] = 'error';
                        
$_SESSION['error_msg'] = __('Please enter validate score');
                        
$_SESSION['msg_back_url'] = front_url('score');
                        
redirect(front_url('message'));
                    }
                }
            }
        }

        foreach (
$scores as $id => $row) {
            if (
count(Score_status_model::get_data_by_field_with_value(['application_id' => $id'judge_id' => $_SESSION['judge_id'], 'judge_submitted' => 1]))) {
                
$_SESSION['msg_type'] = 'error';
                
$_SESSION['error_msg'] = __('The application have been scored.');
                
$_SESSION['msg_back_url'] = front_url('score');
                
redirect(front_url('message'));
            }
        }

        foreach (
$scores as $id => $row) {
            
$delete_data = array(
                
"deleted" => 1,
                
"deleted_by" => $_SESSION['sys_user_id'],
                
"deleted_at" => date('Y-m-d H:i:s'),
            );
            
Score_model::where('application_id'$id)->where('judge_id'$_SESSION['judge_id'])->update($delete_data);

            
$scoring_items Scoring_item_model::get_data_by_application_id($id);
            
$have_score_status false;

            foreach(
$scoring_items as $items) {
                
$point $row->{$items['code']};
                if (!empty(
$point) || $point === '0') {
                    
$data = array(
                        
'application_id' => $id,
                        
'judge_id' => $_SESSION['judge_id'],
                        
'scoring_item_id' => $items['id'],
                        
'point' => $point
                    
);
                    
Score_model::create()->update($data);
                    if (
$_POST['type'] == 'submit' && !$have_score_status) {
                        
$have_score_status true;
                        
$data = array(
                            
'application_id' => $id,
                            
'judge_id' => $_SESSION['judge_id'],
                            
'judge_submitted' => 1,
                        );
                        
Score_status_model::create()->update($data);
                    }
                };
            }
        }
        
redirect(front_url('score/list_all'));
    }
}