public function postGetLetterTemplate($id) { $row = Templates::find($id); $data = unserialize($row->array); echo json_encode($data); }
public function postGetPeTemplates($group, $id, $default) { if ($default == 'y' && $id == '0') { $gender = Session::get('gender'); if ($gender == 'male') { $sex = 'm'; } elseif ($gender == 'female') { $sex = 'f'; } else { $sex = 'u'; } $row = DB::table('templates')->where('user_id', '=', '0')->where('sex', '=', $sex)->where('category', '=', 'pe')->where('group', '=', $group)->where('default', '=', "default")->first(); $data = unserialize($row->array); $data1 = json_encode($data); } else { $row = Templates::find($id); $data = unserialize($row->array); $data1 = json_encode($data); $data1 = str_replace('pe_form_buttonset', 'pe_buttonset', $data1); $data1 = str_replace('pe_form', $group, $data1); } echo $data1; }
public function postSaveReferralForm($type) { if ($type == 'user') { $user_id = Session::get('user_id'); } else { $user_id = "0"; } $group = str_replace(" ", "_", strtolower(Input::get('template_name'))); $array = serialize(Input::get('array')); if (Input::get('sex') == 'b') { $template_data1 = array('user_id' => $user_id, 'default' => 'default', 'template_name' => Input::get('template_name'), 'age' => Input::get('age'), 'category' => 'referral', 'sex' => 'm', 'group' => $group, 'array' => $array, 'practice_id' => Session::get('practice_id')); $template_data2 = array('user_id' => $user_id, 'default' => 'default', 'template_name' => Input::get('template_name'), 'age' => Input::get('age'), 'category' => 'referral', 'sex' => 'f', 'group' => $group, 'array' => $array, 'practice_id' => Session::get('practice_id')); $template_data3 = array('user_id' => $user_id, 'default' => 'default', 'template_name' => Input::get('template_name'), 'age' => Input::get('age'), 'category' => 'referral', 'sex' => 'u', 'group' => $group, 'array' => $array, 'practice_id' => Session::get('practice_id')); if (Input::get('template_id') == '') { DB::table('templates')->insert($template_data1); $this->audit('Add'); DB::table('templates')->insert($template_data2); $this->audit('Add'); DB::table('templates')->insert($template_data3); $this->audit('Add'); $message = "Form added as a template!"; } else { $template_row = Templates::find(Input::get('template_id')); if ($template_row->sex == 'm') { $template_id1 = Input::get('template_id'); } elseif ($template_row->sex == 'f') { $template_id2 = Input::get('template_id'); } else { $template_id3 = Input::get('template_id'); } $template_row1 = Templates::where('group', '=', $template_row->group)->where('template_id', '!=', Input::get('template_id'))->get(); if ($template_row1) { foreach ($template_row1 as $template_row1_row) { if ($template_row1->sex == 'm') { $template_id1 = $template_row1->template_id; } elseif ($template_row1->sex == 'f') { $template_id2 = $template_row1->template_id; } else { $template_id3 = $template_row1->template_id; } } DB::table('templates')->where('template_id', '=', $template_id1)->update($template_data1); $this->audit('Update'); DB::table('templates')->where('template_id', '=', $template_id2)->update($template_data2); $this->audit('Update'); DB::table('templates')->where('template_id', '=', $template_id3)->update($template_data3); $this->audit('Update'); } else { if ($template_row->sex == 'm') { DB::table('templates')->insert($template_data2); $this->audit('Add'); DB::table('templates')->insert($template_data3); $this->audit('Add'); } elseif ($template_row->sex == 'f') { DB::table('templates')->insert($template_data1); $this->audit('Add'); DB::table('templates')->insert($template_data3); $this->audit('Add'); } else { DB::table('templates')->insert($template_data1); $this->audit('Add'); DB::table('templates')->insert($template_data2); $this->audit('Add'); } } $message = "Form updated as a template!"; } } else { $template_data4 = array('user_id' => $user_id, 'default' => 'default', 'template_name' => Input::get('template_name'), 'age' => Input::get('age'), 'category' => 'referral', 'sex' => Input::get('sex'), 'group' => $group, 'array' => $array, 'practice_id' => Session::get('practice_id')); if (Input::get('template_id') == '') { DB::table('templates')->insert($template_data4); $this->audit('Add'); $message = "Form added as a template!"; } else { DB::table('templates')->where('template_id', '=', Input::get('template_id'))->update($template_data4); $this->audit('Update'); $message = "Form updated as a template!"; } } echo $message; }