/var/www/onesupportsys.onesolution.hk/contract/modify.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
<?php

    $nowdate 
date("Y-m-d H:i:s");

    
//for delete the task, using ajax
    
if(!empty($_POST["delete_task_id"])){

        require (
'../inc/configure.php');
        
//only can de
        
$sql      "UPDATE sup_period_task set deleted=?, lastupdate=?, lastupby=? where ptask_id=? ";

        
$parameters = array("1"$nowdate$_SESSION['webadmin']['id'], (int)$_POST["delete_task_id"], );
        if (!(
$sth $dbh->prepare($sql))) {
            throw new 
Exception("sql prepare statement failure: $sql");
        }
        
$sth->setFetchMode(PDO::FETCH_ASSOC);
        if (!
$sth->execute($parameters)) {
            throw new 
Exception("sql execute statement failure: $sql");
        }

        
$_contract_id $_POST["contract_id"];
        exit;
    }

    
//checking here
    
$schedulecall 0;
    if (!empty(
$_POST["schedule_call_3hrs"])) {
        
$schedulecall++;
    }
    if (!empty(
$_POST["schedule_call_half_day"])) {
        
$schedulecall++;
    }
    if (!empty(
$_POST["schedule_call_full_day"])) {
        
$schedulecall++;
    }

    if (
$schedulecall 1) { //only one type of schedule call is allowed
        
echo "<script>alert('Only one option is allowed in Schedule Call!');history.back();</script>";
        exit;
    }

    
//if(strtotime($_POST["contract_from"]) > strtotime($_POST["contract_to"])){
    
if(strtotime($_POST["date_from"]) > strtotime($_POST["date_to"])){
        echo 
"<script>alert('Contract From Date should before the Contract To Date!');history.back();</script>";
        exit;
    }

    require_once(
__DIR__ '/../checkuser.php');
//-----------------------------------------------------------------------------
// Save if POST method
//-----------------------------------------------------------------------------
    
if (isPost()) {
        if (!
$dbh->beginTransaction()) {
            throw new 
Exception('mysql begin transaction failure.');
        }
        try {

            
$post $_POST;

            
$sql        "SELECT column_name FROM information_schema.columns WHERE table_schema = (SELECT DATABASE()) AND table_name = ?";
            
$parameters = array('sup_contract');
            if (!(
$sth $dbh->prepare($sql))) {
                throw new 
Exception("sql prepare statement failure: $sql");
            }
            
$sth->setFetchMode(PDO::FETCH_ASSOC);
            if (!
$sth->execute($parameters)) {
                throw new 
Exception("sql execute statement failure: $sql");
            }
            
$columns $sth->fetchAll();

            foreach (
$columns as $column) {
                
$column $column['column_name'];
                if (isset(
$post[$column])) {
                    
$contract[$column] = $post[$column];
                }
            }

            
// Append record time
            
$now      date("Y-m-d H:i:s");
            
$contract array_merge($contract, array(
                
'lastupdate' => $now,
                
'lastupby'   => $_SESSION['webadmin']['id'],
            ));

            
// Update contract
            
$values     = array();
            
$parameters = array();
            foreach (
$contract as $column => $value) {
                if (
$column != 'contract_id') {
                    
$parameters[] = !strlen($value) ? null $value;
                    
$values[]     = "`$column` = ?";
                }
            }
            
$sql          "UPDATE sup_contract SET " implode(', '$values) . " WHERE contract_id = ?";
            
$parameters[] = $contract['contract_id'];
            if (!(
$sth $dbh->prepare($sql))) {
                throw new 
Exception("sql prepare statement failure: $sql");
            }
            
$sth->setFetchMode(PDO::FETCH_ASSOC);
            if (!
$sth->execute($parameters)) {
                throw new 
Exception("sql execute statement failure: $sql");
            }

            
$_SESSION["remark_contract_id"] = $contract['contract_id'];


            
//update the previous record with correct time

            
$sql "UPDATE sup_contract SET `contract_from` = ?, `contract_to` = ? WHERE contract_id = ?";

            if (!(
$sth $dbh->prepare($sql))) {
                throw new 
Exception("sql prepare statement failure: $sql");
            }
            
$sth->setFetchMode(PDO::FETCH_ASSOC);
            if (!
$sth->execute(array($_POST["date_from"], $_POST["date_to"], $contract['contract_id']))) {
                throw new 
Exception("sql execute statement failure: $sql");
            }


            if(
$contract["contract_type"] == 1){
                
//for update the current task use
                
$task_category_id $_POST["task_category_id"];
                
$remarks $_POST["task_remarks"];
                
$titles $_POST["task_title"];
                
$task_ids $_POST["task_id"];
                
$status $_POST["task_status"];
                
$completed_date $_POST["task_completed_date"];
                
$task_start_date $_POST["task_start_date"];
                
$task_end_date $_POST["task_end_date"];

                foreach (
$task_ids as $key => $task_id) {
                    
$_task_category_id $task_category_id[$task_id];
                    
$_title   $titles[$task_id];
                    
$_remarks =$remarks[$task_id];
                    
$_status $status[$task_id];
                    
$_completed_date $completed_date[$task_id];
                    
$_start_date $task_start_date[$task_id];
                    
$_end_date $task_end_date[$task_id];

                    if(
$_status == 2){
                        
$_completed_date date("Y-m-d");
                    }else{
                        
$_completed_date $completed_date[$task_id];
                    }

                    
$sql      "UPDATE sup_period_task set task_category_id=?, task_title=?, task_remarks=?, status=?, completed_date=?,start_date=?, end_date=?, lastupdate=?, lastupby=? where ptask_id=? ";

                    
$parameters = array($_task_category_id$_title$_remarks$_status$_completed_date,$_start_date$_end_date$nowdate$_SESSION['webadmin']['id'], $task_id);

                    if (!(
$sth $dbh->prepare($sql))) {
                        throw new 
Exception("sql prepare statement failure: $sql");
                    }
                    
$sth->setFetchMode(PDO::FETCH_ASSOC);
                    if (!
$sth->execute($parameters)) {
                        throw new 
Exception("sql execute statement failure: $sql");
                    }

                }


            }



            if (!
$dbh->commit()) {
                throw new 
Exception('mysql commit transaction failure.');
            }
        } catch (
Exception $exception) {
            if (!
$dbh->rollBack()) {
                throw new 
Exception('mysql roll back transaction failure.');
            }
            throw 
$exception;
        }

        
redirectAndExit('index.php?message=Contract Saved.');
    }