insert_data($tbname, $_POST); $cdb = new control_db(); $sql = "select id from newsOutside where contentTypeID='$_POST[contentTypeID]' and createDate='$dt'"; $query = $cdb->conn->prepare($sql); $query->execute(); $data = $query->fetch(PDO::FETCH_ASSOC); /*switch ($_POST['contentTypeID']) { case '1': $fd = 'article'; break; case '2': $fd = 'event'; break; case '3': $fd = 'trainningcourse'; break; case '4': $fd = 'salaryguide'; break; }*/ $fd = 'NewsOutside'; uploadFiles('file_jpg', $fd, $data['id']); break; //แก้ไขข้อมูล case '2': $id = $_POST['id']; unset($_POST['form_action'], $_POST['id']); //$_POST['update_at'] = $dt; if ($_FILES['file_jpg']['error'] == 0) { $sql = "select coverImg from newsOutside where id='$id'"; $query->$cdb->conn->prepare($sql); $query->execute(); $data = $query->fetch(PDO::FETCH_ASSOC); /*switch ($_POST['contentTypeID']) { case '1': $fd = 'article'; break; case '2': $fd = 'event'; break; case '3': $fd = 'trainningcourse'; break; case '4': $fd = 'salaryguide'; break; }*/ $fd = 'NewsOutside'; $fds = "../../uploads/" . $fd . "/" . $id . "." . $data['coverImg']; unset($fds); uploadFiles('file_jpg', $fd, $id); } echo $cdb->update_data($tbname, $_POST, "id='$id'"); break; // ลบข้อมูล case '3': echo $cdb->delete_data($tbname, "id='$_POST[id]'"); break; // เช็ค url ซ้ำ case '4': /* unset($_POST['form_action'],$_POST['stamp'],$_POST['username']); $sql="select menu_url from menu where menu_url=:menu_url"; $query=$cdb->conn->prepare($sql); try{ $query->execute($_POST); $count = $query->rowCount(); echo $count; }catch(PDOException $er){ echo 'Error :'.$er->getMessage(); } */ break; //ดึงข้อมูลเพื่อแก้ไขข้อมูล case '5': $sql = "select * "; $sql .= " from $tbname "; $sql .= " where id=:id "; unset($_POST['form_action'], $_POST['createDate'], $_POST['createBy']); //print_r($_POST); $query = $cdb->conn->prepare($sql); try { $query->execute($_POST); $data = $query->fetch(PDO::FETCH_ASSOC); foreach ($data as $key => $value) { if ($value == '') { $value = ' '; } $json_data[$key] = $value; } $json = json_encode($json_data); echo $json; } catch (PDOException $er) { echo 'Error :' . $er->getMessage(); } break; //ดึงข้อมูลเพื่อแสดง case '6': //ดึงข้อมูลหมวดหมู่ $sql = "select id, title from contentType"; $query = $cdb->conn->prepare($sql); try { $query->execute(); $count = $query->rowCount(); $i = 1; while ($data = $query->fetch(PDO::FETCH_ASSOC)) { $sjt[$data['id']] = $data['title']; } } catch (PDOException $er) { echo 'Error :' . $er->getMessage(); } //จบข้อมูลหมวดหมู่ $userName = $_SESSION['login_workGroup']; $no_field = array('page', 'qpage', 'form_action'); $sql = "select * "; $sql .= " from $tbname where 1=1 and $tbname.contentTypeID LIKE '$userName' "; foreach ($_POST as $key => $value) { if (!in_array($key, $no_field)) { if ($value <> '') { $field = str_replace('s_', '', $key); if (strpos($key, 'title') <> '') { $param[$field] = "%$value%"; $sql .= " and $field like :$field "; } else { $param[$field] = $value; $sql .= " and $field=:$field "; } } } } $sql .= " order by id DESC "; //echo $sql; // คำนวณจำนวนหน้า $query = $cdb->conn->prepare($sql); $query->execute($param); $count = $query->rowCount(); $json_data['pagination']['max_data'] = $count; //คำนวณ record เริ่มต้น if ($_POST['page'] == 1) { $json_data['pagination']['state'] = 'แสดง 1 - ' . $_POST['qpage'] . ' จาก ' . number_format($count) . ' รายการ'; $start = 0; } else { $start = ($_POST['page'] - 1) * $_POST['qpage']; $json_data['pagination']['state'] = 'แสดง ' . ($start + 1) . ' - ' . ($start + $_POST['qpage']) . ' จาก ' . number_format($count) . ' รายการ'; } $json_data['pagination']['max_loop'] = ceil(($count / $_POST['qpage'])); // $sql .= " limit $start,$_POST[qpage] "; //echo $sql; $query = $cdb->conn->prepare($sql); try { $query->execute($param); $count = $query->rowCount(); $i = 1; while ($data = $query->fetch(PDO::FETCH_ASSOC)) { foreach ($data as $key => $value) { //ดึงข้อหมวดหมู่ if ($key == 'contentTypeID') { $json_data[$i]['name_type'] = $sjt[$value]; } //จบข้อมูลหมวดหมู่ $json_data[$i][$key] = $value; } ++$i; } } catch (PDOException $er) { echo 'Error :' . $er->getMessage(); } $json = json_encode($json_data); echo $json; break; case '7': $sql = "select * from $tbname order by rec_order"; $query = $cdb->conn->prepare($sql); //print_r($_POST); try { $query->execute(); $count = $query->rowCount(); $i = 1; while ($data = $query->fetch(PDO::FETCH_ASSOC)) { foreach ($data as $key => $value) { $json_data[$i][$key] = $value; } if ($data['id'] == $_POST['id']) { $x = $i; } unset($json_data[$x]); ++$i; } $json = json_encode($json_data); echo $json; } catch (PDOException $er) { echo 'Error :' . $er->getMessage(); } break; //สลับตำแหน่งข้อมูล function sort case 'getArticle': $sql = "select id,title from articleType order by id "; $query = $cdb->conn->prepare($sql); $query->execute($param); while ($data = $query->fetch(PDO::FETCH_ASSOC)) { $json_data[$data['id']] = $data['title']; } echo json_encode($json_data); break; }