function postSavesql(Request $request, $id) { $select = $request->input('sql_select'); $where = $request->input('sql_where'); $group = $request->input('sql_group'); /*try { \DB::select( $select .' '.$where.' '.$group ); }catch(Exception $e){ // Do something when query fails. $error ='Error : '.$select .' '.$where.' '.$group ; return Redirect::to('sximo/module/sql/'.$request->input('module_name')) ->with('messagetext', $error)->with('msgstatus','error'); }*/ $row = \DB::table('tb_module')->where('module_name', $id)->get(); if (count($row) <= 0) { return Redirect::to($this->module)->with('messagetext', 'Can not find module')->with('msgstatus', 'error'); } $row = $row[0]; $config = \SiteHelpers::CF_decode_json($row->module_config); $this->data['row'] = $row; $pdo = \DB::getPdo(); $columns = Module::getColoumnInfo($select . ' ' . $where . ' ' . $group); $i = 0; $form = array(); $grid = array(); foreach ($columns as $field) { $name = $field['name']; $alias = $field['table']; $grids = self::configGrid($name, $alias, '', $i); foreach ($config['grid'] as $g) { if (!isset($g['type'])) { $g['type'] = 'text'; } if ($g['field'] == $name && $g['alias'] == $alias) { $grids = $g; } } $grid[] = $grids; if ($row->module_db == $alias) { $forms = self::configForm($name, $alias, 'text', $i); foreach ($config['forms'] as $f) { if ($f['field'] == $name && $f['alias'] == $alias) { $forms = $f; } } $form[] = $forms; } $i++; } //echo '<pre>';print_r($grid); echo '</pre>'; exit; // Remove Old Grid unset($config["forms"]); // Remove Old Form unset($config["grid"]); // Remove Old Query unset($config["sql_group"]); unset($config["sql_select"]); unset($config["sql_where"]); // Inject New Grid $new_config = array("sql_select" => $select, "sql_where" => $where, "sql_group" => $group, "grid" => $grid, "forms" => $form); $config = array_merge($config, $new_config); \DB::table('tb_module')->where('module_id', '=', $row->module_id)->update(array('module_config' => \SiteHelpers::CF_encode_json($config))); return Redirect::to('sximo/module/sql/' . $row->module_name)->with('messagetext', 'SQL Has Changed Successful.')->with('msgstatus', 'success'); }