ProcessTblMember.proc.class.php 3.63 KB
Newer Older
Deni Andreyan Feneza's avatar
Deni Andreyan Feneza committed
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
<?php
/**
 * @author Prima Noor
 */
 
class ProcessTblMember
{
    var $Obj;
    var $user;
    var $cssDone = 'notebox-done';
    var $cssFail = 'notebox-warning';
    var $cssAlert = 'notebox-alert';

    function __construct()
    {
        $this->ObjTblMember = GtfwDispt()->load->business('TblMember');
        $this->user = Security::Authentication()->GetCurrentUser()->GetUserId();
    }

    function input()
    {
        $post = $_POST->AsArray();
        $Val = GtfwDispt()->load->library('Validation');
        
        
        $Val->set_rules('name', GtfwLangText('name'), 'required');
        $Val->set_rules('birthdate', GtfwLangText('birthdate'), 'required');
        $Val->set_rules('gender', GtfwLangText('gender'), 'required');
        
        $result = $Val->run();
        if ($result) {
            if (!$post['id']) {
                $this->ObjTblMember->StartTrans();
                $params = array(
                    $post['name'],
                    $post['birthdate'],
                    $post['province_id'],
                    $post['gender'],
                    $post['latitude'],
                    $post['longitude'],
                    $this->user
                );
                $result = $result && $this->ObjTblMember->insertTblMember($params);
                $this->ObjTblMember->EndTrans($result);
                if ($result) {
                    $msg = GtfwLangText('msg_add_success');
                    $css = $this->cssDone;
                } else {
                    $msg = GtfwLangText('msg_add_fail');
                    $css = $this->cssFail;
                }
            } else {
                $this->ObjTblMember->StartTrans();
                $params = array(
                    $post['name'],
                    $post['birthdate'],
                    $post['province_id'],
                    $post['gender'],
                    $post['latitude'],
                    $post['longitude'],
                    $this->user,
                    $post['id']
                );
                $result = $result && $this->ObjTblMember->updateTblMember($params);
                $this->ObjTblMember->EndTrans($result);   
                if ($result) {
                    $msg = GtfwLangText('msg_update_success');
                    $css = $this->cssDone;
                } else {
                    $msg = GtfwLangText('msg_update_fail');
                    $css = $this->cssFail;
                }             
            }
        } else {
            $msg = $Val->error_string('', '<br />');
            $css = $this->cssFail;
        }     
        if ($result) {
            Messenger::Instance()->Send('tbl.member', 'TblMember', 'view', 'html', array(NULL, $msg, $css), Messenger::NextRequest);
            //return Dispatcher::Instance()->GetUrl('tbl.member', 'tblmember', 'view', 'html');
        } else {
            Messenger::Instance()->Send('tbl.member', 'inputTblMember', 'view', 'html', array($post, $msg, $css), Messenger::NextRequest);
            //return Dispatcher::Instance()->GetUrl('tbl.member', (empty($post['id'])?'add':'update').'TblMember', 'view', 'html');
        }
        return $result;     
    }
    
    function delete($id)
    {
        $result = $this->ObjTblMember->deleteTblMember($id);
        if ($result) {
            $msg = GtfwLangText('msg_delete_success');
            $css = $this->cssDone;
        } else {
            $msg = GtfwLangText('msg_delete_fail');
            $css = $this->cssFail;            
        }
        Messenger::Instance()->Send('tbl.member', 'TblMember', 'view', 'html', array(NULL, $msg, $css), Messenger::NextRequest);
        
        return $result;
    }
}

?>