File size: 9,584 Bytes
971eb1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<?php
/* 

 * Author		= Dian Hermanto

 * Create Date	= 10 Agustus 2017

 * File Name	= C_task_request

 * Function		= -

*/

class C_task_request extends CI_Controller

{
 	function index()

	{
		$sqlApp 		= "SELECT * FROM tappname";
		$resultaApp = $this->db->query($sqlApp)->result();
		foreach($resultaApp as $therow) :
			$appName = $therow->app_name;		
		endforeach;
		
		$url			= site_url('c_help/c_task_request/task_request_idx/?id='.$this->url_encryption_helper->encode_url($appName));
		redirect($url);
	}
	
	function task_request_idx()

	{
		$this->load->model('m_help/m_task_request', '', TRUE);
		
		$DefEmp_ID 		= $this->session->userdata['Emp_ID'];
		if ($this->session->userdata('login') == TRUE)
		{
			$idAppName	= $_GET['id'];
			$appName	= $this->url_encryption_helper->decode_url($idAppName);
			
			$data['title'] 		= $appName;
			$data['h1_title']	= 'task';
			$data['h2_title']	= 'task request';
			$data['h3_title']	= 'Database';
			$data['secAddURL'] 	= site_url('c_help/c_task_request/add/?id='.$this->url_encryption_helper->encode_url($appName));
			
			$data["countTask"] 	= $this->m_task_request->count_all_task($DefEmp_ID);	 
			$data['vwTask'] 	= $this->m_task_request->view_all_task($DefEmp_ID)->result();
			
			$this->load->view('v_help/v_task_request/v_task_request', $data);
		}
		else
		{
			redirect('Auth');
		}
	}
	
	function add() // OK

	{	
		$this->load->model('m_help/m_task_request', '', TRUE);
		
		if ($this->session->userdata('login') == TRUE)
		{
			$idAppName	= $_GET['id'];
			$appName	= $this->url_encryption_helper->decode_url($idAppName);
					
			$docPatternPosition 		= 'Especially';	
			$data['title'] 				= $appName;
			$data['task'] 				= 'add';
			$data['h2_title']			= 'Add Task';
			$data['h3_title']			= 'help';
			$data['form_action']		= site_url('c_help/c_task_request/add_process');
			$data['link'] 				= array('link_back' => anchor('c_help/c_task_request/','<input type="button" class="btn btn-danger" id="btnCancel" class="button_css" value="Cancel" />', array('style' => 'text-decoration: none;')));
			$data['backURL'] 	= site_url('c_help/c_task_request/');
			
			$MenuCode 					= 'MN208';
			$data['viewDocPattern'] 	= $this->m_task_request->getDataDocPat($MenuCode)->result();
			
			$this->load->view('v_help/v_task_request/v_task_request_form', $data);
		}
		else
		{
			redirect('Auth');
		}
	}
	
	function add_process() // OK

	{	
		$this->load->model('m_help/m_task_request', '', TRUE);
		
		$sqlApp 		= "SELECT * FROM tappname";
		$resultaApp = $this->db->query($sqlApp)->result();
		foreach($resultaApp as $therow) :
			$appName = $therow->app_name;		
		endforeach;	
		
		date_default_timezone_set("Asia/Jakarta");
		
		$DefEmp_ID 	= $this->session->userdata['Emp_ID'];
		$TASK_DATE	= date('Y-m-d',strtotime($this->input->post('TASK_DATE')));
		$Patt_Year	= date('Y',strtotime($this->input->post('TASK_DATE')));
		$Patt_Month	= date('m',strtotime($this->input->post('TASK_DATE')));
		$Patt_Date	= date('d',strtotime($this->input->post('TASK_DATE')));
		
		$TASK_CODE		= $this->input->post('TASK_CODE');
		$TASK_TYPE		= $this->input->post('TASK_TYPE');
		if($TASK_TYPE == '')
			$TASK_TYPE = 0;
		$TASK_AUTHOR	= $this->input->post('TASK_AUTHOR');
		$TASK_REQUESTER	= $this->input->post('TASK_REQUESTER');
		$TASK_FOR		= $this->input->post('TASK_FOR');
		echo "TASK_TYPE = $TASK_TYPE<br>";
		return false;
		if($TASK_TYPE > 0) // this is concultant information for users
		{
			$TASK_AUTHOR	= $DefEmp_ID;
		}
		
		if ($this->session->userdata('login') == TRUE)
		{		
			$this->db->trans_begin();
			
			// CREATE HEADER
			$InsTR 		= array('TASK_CODE' 	=> $this->input->post('TASK_CODE'),
								'TASK_DATE'		=> $TASK_DATE,
								'TASK_TITLE'	=> $this->input->post('TASK_TITLE'),
								'TASK_TYPE'		=> $this->input->post('TASK_TYPE'),
								'TASK_AUTHOR'	=> $TASK_AUTHOR,
								'TASK_REQUESTER'=> $this->input->post('TASK_REQUESTER'),
								'TASK_STAT'		=> $this->input->post('TASK_STAT'),
								'TASK_CREATED'	=> date('Y-m-d H:i:s'),
								'Patt_Year'		=> $Patt_Year,
								'Patt_Month'	=> $Patt_Month,
								'Patt_Date'		=> $Patt_Date,
								'Patt_Number'	=> $this->input->post('Patt_Number'));
												
			$this->m_task_request->add($InsTR);
			
			if($TASK_TYPE == 0)	// From user to author
			{
				// CREATE DETAIL
				// Karena $TASK_AUTHOR = "All", maka cari salah  satu author dari detail
				$getC1	= "tbl_task_request_detail WHERE TASKD_PARENT = '$TASK_CODE' AND TASKD_EMPID != '$TASK_REQUESTER'";
				$resC1	= $this->db->count_all($getC1);
				if($resC1 > 0)
				{
					$getID1		= "SELECT TASKD_EMPID

									FROM tbl_task_request_detail WHERE TASKD_PARENT = '$TASK_CODE' AND TASKD_EMPID != '$TASK_REQUESTER' LIMIT 1";
					$resID1		= $this->db->query($getID1)->result();
					foreach($resID1 as $rowID1) :
						$TASKD_EMPID2 	= $rowID1->TASKD_EMPID;
					endforeach;
				}
				else
				{
					$myrow		= 0;
					$getAuthID	= "SELECT Emp_ID FROM tbl_employee WHERE isHelper = 1";
					$resAuthID	= $this->db->query($getAuthID)->result();
					foreach($resAuthID as $rowAuthID) :
						$myrow	= $myrow + 1;
						$Emp_ID 	= $rowAuthID->Emp_ID;
						if($myrow == 1)
						{
							$TASKD_EMPID2	= "$Emp_ID";
						}
						if($myrow > 1)
						{
							$TASKD_EMPID2	= "$TASKD_EMPID2;$Emp_ID";
						}
					endforeach;
				}
				$InsTRD		= array('TASKD_PARENT' 		=> $this->input->post('TASK_CODE'),
									'TASKD_TITLE'		=> $this->input->post('TASK_TITLE'),
									'TASKD_CONTENT'		=> $this->input->post('TASK_CONTENT'),
									'TASKD_DATE'		=> date('Y-m-d'),
									'TASKD_CREATED'		=> date('Y-m-d H:i:s'),
									'TASKD_EMPID'		=> $DefEmp_ID,
									'TASKD_EMPID2'		=> $TASKD_EMPID2,
									'TASKD_EMPID'		=> $DefEmp_ID);
													
				$this->m_task_request->addDet($InsTRD);
			}
			else // this is concultant information for users
			{
				if($TASK_TYPE == 1)
				{
					$TASKD_EMPID2	= "All";
				}
				elseif($TASK_TYPE == 2)
				{
					// FOR GROUPING RECEIVING BY PERSONAL
					$selStep	= 0;
					foreach ($TASK_FOR as $sel_users)
					{
						$selStep	= $selStep + 1;
						if($selStep == 1)
						{
							$user_to		= explode ("|",$sel_users);
							$user_ID		= $user_to[0];
							$user_ADD		= $user_to[1];
							$TASKD_EMPID2	= $user_ID;
							//$coll_MADD	= $user_ADD;
						}
						else
						{					
							$user_to		= explode ("|",$sel_users);
							$user_ID		= $user_to[0];
							$user_ADD		= $user_to[1];
							
							$TASKD_EMPID2	= "$TASKD_EMPID2;$user_ID";
							//$coll_MADD	= "$coll_MADD;$user_ADD";
						}
					}
				}
				
				$InsTRD		= array('TASKD_PARENT' 		=> $this->input->post('TASK_CODE'),
									'TASKD_TITLE'		=> $this->input->post('TASK_TITLE'),
									'TASKD_CONTENT'		=> $this->input->post('TASK_CONTENT'),
									'TASKD_DATE'		=> date('Y-m-d'),
									'TASKD_CREATED'		=> date('Y-m-d H:i:s'),
									'TASKD_EMPID'		=> $DefEmp_ID,
									'TASKD_EMPID2'		=> $TASKD_EMPID2,
									'TASKD_EMPID'		=> $DefEmp_ID);
													
				$this->m_task_request->addDet($InsTRD);
			}
			
			// UPDATE NEW
			$UPD_HD_A	= "UPDATE tbl_task_request SET TASK_TO = '$TASKD_EMPID2' WHERE TASK_CODE = '$TASK_CODE'";
			$this->db->query($UPD_HD_A);
			
			if ($this->db->trans_status() === FALSE)
			{
				$this->db->trans_rollback();
			}
			else
			{
				$this->db->trans_commit();
			}
			
			$url			= site_url('c_help/c_task_request/index/?id='.$this->url_encryption_helper->encode_url($appName));
			redirect($url);
		}
		else
		{
			redirect('Auth');
		}
	}
	
	function task_read() // OK

	{
		if ($this->session->userdata('login') == TRUE)
		{
			$this->load->model('m_help/m_task_request', '', TRUE);
			
			$sqlApp 		= "SELECT * FROM tappname";
			$resultaApp = $this->db->query($sqlApp)->result();
			foreach($resultaApp as $therow) :
				$appName 	= $therow->app_name;		
			endforeach;
			
			$TASK_CODE		= $_GET['id'];
			$TASK_CODE		= $this->url_encryption_helper->decode_url($TASK_CODE);
			
			$data['title'] 		= $appName;
			$data['h2_title']	= 'Task View';
			$data['h3_title']	= 'help';
			$data['TASK_CODE'] 	= $TASK_CODE;
			$data['link'] 		= array('link_back' => anchor('c_help/c_task_request/','<input type="button" class="btn btn-danger" id="btnCancel" class="button_css" value="Cancel" />', array('style' => 'text-decoration: none;')));
					
			$this->load->view('v_help/v_task_request/v_task_request_read', $data);
		}
		else
		{
			redirect('Auth');
		}
	}
	
	function downloadFile()

	{
		$FileUpName	= $_GET['id'];
		$FileUpName	= $this->url_encryption_helper->decode_url($FileUpName);
		
        header("Content-Type: text/plain; charset=utf-8");
		header("Content-Type: application/force-download");
		header("Content-Disposition: attachment; filename=".$FileUpName);
	}
	
	function upd_readstat() // OK

	{		
		$this->load->model('m_help/m_task_request', '', TRUE);
		
		$sqlApp 		= "SELECT * FROM tappname";
		$resultaApp = $this->db->query($sqlApp)->result();
		foreach($resultaApp as $therow) :
			$appName = $therow->app_name;		
		endforeach;	
		
		$TASKD_ID	= $_GET['id'];
		$DefEmp_ID 	= $this->session->userdata['Emp_ID'];
		
		if ($this->session->userdata('login') == TRUE)
		{			
			$this->m_task_request->UpdateOriginal($TASKD_ID);
		}
		else
		{
			redirect('Auth');
		}
	}
}
?>