public function postAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         $product = new Product();
         $product->name = $request->getPost('name');
         $product->price = $request->getPost('price');
         $product->manufacture = $request->getPost('manufacture');
         $product->inventory_number = $request->getPost('inventory_number');
         $product->date = $request->getPost('date');
         $product->show = $request->getPost('show');
         // Get images
         $temp = array();
         $imgTotal = intval($request->getPost('imgTotal'));
         $httpadapter = new Http();
         $httpadapter->addValidator('Size', true, array('min' => 1000));
         $httpadapter->addValidator('Extension', true, array('png', 'jpg', 'jpeg'));
         for ($i = 0; $i < $imgTotal; $i++) {
             $fileName = 'image_' . $i;
             $image = $request->getFiles($fileName);
             $httpadapter->addFilter('Rename', array('target' => __UPLOAD__ . '/products/' . $product->name . '-' . $image['name'], 'randomize' => true));
             if ($httpadapter->isValid()) {
                 if ($httpadapter->receive($image['name'])) {
                     $temp[] = $httpadapter->getFileInfo()[$fileName]['name'];
                 }
             }
         }
         $product->images = implode(';', $temp);
         $product->display = $request->getPost('display');
         $product->os = $request->getPost('os');
         $product->cpu = $request->getPost('cpu');
         $product->camera = $request->getPost('camera');
         $product->internal_memory = $request->getPost('internal_memory');
         $product->ram = $request->getPost('ram');
         $product->battery = $request->getPost('battery');
         $product->more = $request->getPost('more');
         // Insert product
         if ($this->getProductTable()->insertProduct($product)) {
             echo json_encode('successful');
         } else {
             echo json_encode('Insert error');
         }
         exit;
     }
 }
 public function updateAction()
 {
     $id = $this->params()->fromRoute('id');
     $request = $this->getRequest();
     $message = null;
     if ($request->isPost()) {
         // Get file upload
         $files = $request->getFiles()->toArray();
         $filePostName = 'image';
         $file = $files[$filePostName];
         // Check validate
         $httpadapter = new Http();
         $httpadapter->addValidator('Size', true, array('min' => 1000), $filePostName);
         $httpadapter->addValidator('Extension', true, array('png', 'jpg', 'jpeg'), $filePostName);
         // Rename file upload
         $httpadapter->addFilter('Rename', array('target' => __UPLOAD__ . '/ads/' . $file['name'], 'randomize' => true), $filePostName);
         // Save file upload
         $newFileName = null;
         if ($httpadapter->isValid()) {
             if ($httpadapter->receive($file['name'])) {
                 $fileInfo = $httpadapter->getFileInfo();
                 $newFileName = $fileInfo[$filePostName]['name'];
             }
         }
         $adsPost = new Advertise();
         $adsPost->id = $id;
         $adsPost->image = $newFileName;
         $adsPost->link = $request->getPost('link');
         $adsPost->date_start = $request->getPost('date_start');
         $adsPost->date_end = $request->getPost('date_end');
         $adsPost->location = $request->getPost('location');
         $adsPost->show = $request->getPost('show');
         $adsPost->view_count = $request->getPost('view_count');
         $adsPost->click_count = $request->getPost('click_count');
         $result = $this->getAdvertiseTable()->updateAdvertise($adsPost);
         if ($result) {
             $message = 'Successful!';
         } else {
             $message = 'Error!! Please try again.';
         }
     }
     $ads = $this->getAdvertiseTable()->getAdvertiseById($id);
     return new ViewModel(array('ads' => $ads, 'message' => $message));
 }
 public function updateAction()
 {
     $request = $this->getRequest();
     if ($request->isPost()) {
         // Get file upload
         $files = $request->getFiles()->toArray();
         $logo = $files['logo'];
         // Check validate
         $httpadapter = new Http();
         $httpadapter->addValidator('Size', true, array('min' => 1000));
         $httpadapter->addValidator('Extension', true, array('png', 'jpg', 'jpeg'));
         // Rename file upload
         $httpadapter->addFilter('Rename', array('target' => __UPLOAD__ . '/page/' . $logo['name'], 'randomize' => true));
         // Save file upload
         $newFileName = null;
         if ($httpadapter->isValid()) {
             if ($httpadapter->receive($logo['name'])) {
                 $fileInfo = $httpadapter->getFileInfo();
                 $newFileName = $fileInfo['logo']['name'];
             }
         }
         $data = new Info();
         $data->name = $request->getPost('name');
         if (isset($newFileName)) {
             $data->logo = '/upload/page/' . $newFileName;
         } else {
             $data->logo = null;
         }
         $data->address = $request->getPost('address');
         $data->tel = $request->getPost('tel');
         $data->introduce = $request->getPost('introduce');
         $data->image = $request->getPost('image');
         $this->getInfoTable()->updateInfo($data);
     }
     $this->redirect()->toRoute('shopinfo');
 }