| 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
 | <?phpsession_start();
 
 require_once(__DIR__ . '/../checkuser.php');
 //-----------------------------------------------------------------------------
 // Check permission
 //-----------------------------------------------------------------------------
 //if (!Util::isAdmin()) {
 //    redirectAndExit('index.php?message=No permission!');
 //}
 
 //-----------------------------------------------------------------------------
 // Save if POST method
 //-----------------------------------------------------------------------------
 if (isPost()) {
 
 //check the type of contract, no need to do with type 2 (package)
 
 $now = date("Y-m-d H:i:s");
 $remarks           = $_POST["task_remarks"];
 $titles            = $_POST["task_title"];
 $task_category_ids = $_POST["task_category_id"];
 
 
 $arraynum = $_POST["arraynum"];
 
 foreach ($arraynum as $key2 => $rownum) {
 $start_date_task = $_POST["start_date_" . $rownum];
 $end_date_task   = $_POST["end_date_" . $rownum];
 
 foreach ($titles as $key => $title) { //each task add the start date and end date
 
 $_remarks          = $remarks[$key];
 $_task_category_id = $task_category_ids[$key];
 
 $sql = "insert into sup_period_task (contract_id, customer_id, task_title, task_remarks,task_category_id, createdate, createby, lastupdate, lastupby, start_date, end_date) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
 
 //echo $sql;
 $parameters = array($_POST['contract_id'], $_POST["customer_id"], $title, $_remarks, $_task_category_id, $now, $_SESSION['webadmin']['id'], $now, $_SESSION['webadmin']['id'], $start_date_task, $end_date_task);
 
 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"] = $_POST['contract_id'];
 if(!empty($arraynum)){
 
 redirectAndExit("index.php?message=New Contract Task Created.");
 }else{
 redirectAndExit("index.php?message=No Action.");
 }
 
 
 }
 
 |