/** * [retainDataSave description] * @return [type] [description] */ public function retainDataSave() { $data = Input::all(); $startretaindate = $data['retainDate']; $data_id = $data['report_data_type']; $period = $data['retain_period']; list($year, $month, $day) = explode("-", $startretaindate); list($num, $type) = explode(":", $period); if ($num != '') { if ($type == 'day') { $time = date("Y-m-d H:i:s", mktime(0, 0, 0, $month, $day + $num, $year)); $rt = new RetainData(); $count = $rt->checkRetain($data_id); if ($count > 0) { $rt_id = $rt->getRetainIdByDataId($data_id); $rt_edit = RetainData::find($rt_id[0]['id']); $rt_edit->data_id = $data_id; $rt_edit->period = $time; $rt_edit->retain_text = $period; $rt_edit->start_retain_date = $startretaindate; $rt_edit->save(); } else { $rt->data_id = $data_id; $rt->period = $time; $rt->retain_text = $period; $rt->start_retain_date = $startretaindate; $rt->save(); } } else { if ($type == 'month') { $time = date("Y-m-d H:i:s", mktime(0, 0, 0, $month + $num, $day, $year)); $rt = new RetainData(); $count = $rt->checkRetain($data_id); if ($count > 0) { $rt_id = $rt->getRetainIdByDataId($data_id); $rt_edit = RetainData::find($rt_id[0]['id']); $rt_edit->data_id = $data_id; $rt_edit->period = $time; $rt_edit->retain_text = $period; $rt_edit->start_retain_date = $startretaindate; $rt_edit->save(); } else { $rt->data_id = $data_id; $rt->period = $time; $rt->retain_text = $period; $rt->start_retain_date = $startretaindate; $rt->save(); } } else { $time = date("Y-m-d H:i:s", mktime(0, 0, 0, $month, $day, $year + $num)); $rt = new RetainData(); $count = $rt->checkRetain($data_id); if ($count > 0) { $rt_id = $rt->getRetainIdByDataId($data_id); $rt_edit = RetainData::find($rt_id[0]['id']); $rt_edit->data_id = $data_id; $rt_edit->period = $time; $rt_edit->retain_text = $period; $rt_edit->start_retain_date = $startretaindate; $rt_edit->save(); } else { $rt->data_id = $data_id; $rt->period = $time; $rt->retain_text = $period; $rt->start_retain_date = $startretaindate; $rt->save(); } } } } // return Redirect::to('/privacy/' . Auth::User()->id)->with('success', 'บันทึกสำเร็จ'); }