/var/www/onesupportdemo.onesolution.hk/task/add.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
<?php
require_once(__DIR__ '/../checkuser.php');
//-----------------------------------------------------------------------------
// Save if POST method
//-----------------------------------------------------------------------------
if (isPost()) {


        
$keyValues $_POST['job_detail'];
        
/*foreach ($keyValues as $id => $attributes) {
            //$keyValues[$id]['job_id'] = $_POST['job_id'];
        }*/

        
if (!$dbh->beginTransaction()) {
            throw new 
Exception('mysql begin transaction failure.');
        }
        try {
            
$activate_pending_task = array();
            
//for pending task
            
if(!empty($_POST["pending_task"])){
                
//$pending_tasks = $_POST["pending_task"];

                //var_dump($_POST["pending_task"]);

                
foreach($_POST["pending_task"] as $key => $task){
                    
//var_dump($task);
                    
if(isset($task["add_to_job"]) && $task["add_to_job"] == ){
                        
//add follow up task to new job

                        
$activate_pending_task[] = $task;
                        
//set old task status to 4 as cancel
                        /*$sql = "update sup_job_detail set status = ? where id = ? and status = ?";
                        $parameters = array(4, $task["job_detail_id"], 3);

                        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");
                        }*/

                        //keep status as follow up and update follow up flag
                        
$sql "update sup_job_detail set follow_up_flag = ? where id = ? and follow_up_flag = ?";
                        
$parameters = array(1$task["job_detail_id"], 0);

                        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");
                        }

                        
//set sup_job_pending to delete
                        
$sql "update sup_job_pending set actived = ? where job_detail_id = ?";
                        
$parameters = array(0$task["job_detail_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");
                        }

                        
//insert new task to that job
                        /*$sql = "insert into sup_job_detail set createby=?, createdate=?, lastupdate=?, lastupby=?, actived=?, deleted=?, job_id=?, title=?, remarks=?, status=?, task_category_id=?, from_job_pending_id=?";
                        $parameters = array($_SESSION['webadmin']['id'], date("Y-m-d H:i:s"), $_SESSION['webadmin']['id'], date("Y-m-d H:i:s"), 1, 0, $task["job_detail_id"], $task["title"], $task["remarks"], 1, $task["task_category_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");
                        }*/
                    
}

                }

                
//var_dump($activate_pending_task);
                
Job::createDetails($activate_pending_task);
            }

            
Job::createDetails($keyValues);

            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;
        }

        unset(
$_SESSION["all_job_ids"]);

        if (
Util::isAdmin()) {
            
//redirectAndExit(Util::link(__DIR__ . '/../job/index.php') . '?message=Saved.');
            //redirectAndExit(Util::link(__DIR__ . '/../job/modifyform.php') . '?id='.$_POST['job_id'].'&message=Job Created.');
            //redirectAndExit(Util::link(__DIR__ . '/../job/index.php') . '?message=Job Created.');
            
$startdate date("Y-m-d");
            
$enddate Date('Y-m-d'strtotime($startdate ."+1 month"));
            
redirectAndExit(Util::link(__DIR__ '/../job/index.php') . '?start_date='.$startdate.'&end_date='.$enddate.'&message=Job Created.');

        } else if(
$_SESSION['webadmin']['role'] == 2){
            
redirectAndExit(Util::link(__DIR__ '/../job/index.php') . '?today=1&message=Job Created.');
        } else if(
$_SESSION['webadmin']['role'] == 3){
            
redirectAndExit(Util::link(__DIR__ '/../job/index.php') . '?today=1&message=Job Created.');}
        else{
            
$data = array(
                
'id' => $_POST['job_id'],
                
'message' => 'Job Saved',
            );
            
//redirectAndExit(Util::link(__DIR__ . '/../job/modifyform.php') . '?' . http_build_query($data));
            
redirectAndExit(Util::link(__DIR__ '/../job/modifyform.php') . '?' http_build_query($data));
        }


}