get('stiri', null, $cols); $ret = array_map(function($item) { return array( 'id' => $item['ID'], 'title' => $item['Titlu'], "image" => $item['Imagine'], "date" => $item['Datas'], "publish" => $item['Activs'], "isSticky" => $item['Stickys'] ); }, $ret); return json_encode($ret); } public function getNews($id) { $db = \MysqliDb::getInstance(); $cols = Array ("ID", "Titlu", "Continut", "Content_Short", "Imagine", "Datas", "Activs", "Stickys"); $db->where ('ID', $id); $ret = $db->get('stiri', null, $cols); if(count($ret) === 0) { header("Status: 404 Not Found"); return ""; } $item = array( 'id' => $ret[0]['ID'], 'title' => $ret[0]['Titlu'], 'content' => $ret[0]['Continut'], 'content_short' => $ret[0]['Content_Short'], "image" => $ret[0]['Imagine'], "fileName" => null, "date" => $ret[0]['Datas'], "publish" => $ret[0]['Activs'], "isSticky" => $ret[0]['Stickys'] ); return json_encode($item); } public function updateNews() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $data = Array ( 'Titlu' => $requstOb['title'], "Continut" => $requstOb['content'], "Content_Short" => $requstOb['content_short'], "Datas" => $requstOb['date'], "Activs" => $requstOb['publish'], "Stickys" => $requstOb['isSticky'] ); if(!empty($requstOb['fileName'])) { // copy file from temp $srcPath = $GLOBALS['paths']['images_temp'] . $requstOb['fileName']; $destPath = $GLOBALS['paths']['news_images'] . $requstOb['fileName']; if(!rename($srcPath, $destPath)) { return json_encode(array('status'=> 0, 'message'=>'Unable to move uploaded file.', 'item'=>null)); } $data["Imagine"] = $requstOb['fileName']; } $db->where ('id', $requstOb['id']); $db->update ('stiri', $data); $item = array( 'id' => $requstOb['id'], 'title' => $requstOb['title'], "date" => $requstOb['date'], "publish" => $requstOb['publish'], "isSticky" => $requstOb['isSticky']); if(isset($data['Imagine'])) { $item["image"] = $requstOb['fileName']; } return json_encode(array('status'=>1, 'message'=>'News updated.', 'item'=>$item)); } public function addNews() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $data = Array ( 'Titlu' => $requstOb['title'], "Continut" => $requstOb['content'], "Content_Short" => $requstOb['content_short'], "Datas" => $requstOb['date'], "Activs" => $requstOb['publish'], "Stickys" => $requstOb['isSticky'] ); if(!empty($requstOb['fileName'])) { // copy file from temp $srcPath = $GLOBALS['paths']['images_temp'] . $requstOb['fileName']; $destPath = $GLOBALS['paths']['news_images'] . $requstOb['fileName']; if(!rename($srcPath, $destPath)) { return json_encode(array('status'=> 0, 'message'=>'Unable to move uploaded file.', 'item'=>null)); } $data["Imagine"] = $requstOb['fileName']; } $id = $db->insert ('stiri', $data); $item = array( 'id' => $id, 'title' => $requstOb['title'], "date" => $requstOb['date'], "publish" => $requstOb['publish'], "isSticky" => $requstOb['isSticky']); if(isset($data['Imagine'])) { $item["image"] = $requstOb['fileName']; } return json_encode(array('status'=>1, 'message'=>'News added.', 'item'=>$item)); } public function deleteNews() { $body = file_get_contents('php://input'); $requstOb = json_decode($body,true); $db = \MysqliDb::getInstance(); $db->where('ID', $requstOb['id']); $id = $db->delete ('stiri'); // TODO: delete image $item = array('id' => $requstOb['id']); return json_encode(array('status'=> 1, 'message'=>'News deleted.', 'item'=> $item)); } } ?>x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586