Пример #1
0
 public function addAction()
 {
     $form = new ProductForm();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $product = new Product();
         $form->setInputFilter($product->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $product->exchangeArray($form->getData());
             //$this->getProductTable()->saveProduct($product);
             $adapter = new \Zend\File\Transfer\Adapter\Http();
             $dir = getcwd() . '/public/img/';
             $data = $form->getData();
             $filename = $data['image'];
             $fileTlsName = $dir . $filename;
             // pashet
             //$adapter->addValidator('Extension', false, 'jpg,png,gif');
             var_dump($adapter);
             die;
             //var_dump($fileTlsName);die;
             //$adapter->addFilter('Rename', $fileTlsName);// rename file
             if ($adapter->receive($filename)) {
                 // upload file
                 return $this->redirect()->toRoute('product');
             }
         }
     }
     return array('form' => $form);
 }
Пример #2
0
 public function addAction()
 {
     if ($this->zfcUserAuthentication()->hasIdentity() && $this->zfcUserAuthentication()->getIdentity()->getRole() == "admin") {
         $form = new ProductForm();
         $request = $this->getRequest();
         if ($request->isPost()) {
             $product = new Product();
             $form->setInputFilter($product->getInputFilter());
             $form->setData(array_merge($request->getPost()->toArray(), $request->getFiles()->toArray()));
             if ($form->isValid()) {
                 $fileName = $form->getData()['image']['name'];
                 if (move_uploaded_file($form->getData()['image']['tmp_name'], getcwd() . '/public/img/' . $fileName)) {
                     echo "Файл корректен и был успешно загружен.\n";
                 } else {
                     echo "Возможная атака с помощью файловой загрузки!\n";
                 }
                 $product->exchangeArray($form->getData());
                 $this->getProductTable()->saveProduct($product);
                 // Redirect to list of products
                 return $this->redirect()->toRoute('product');
             }
         }
         return array('form' => $form);
     } else {
         $view = new ViewModel(array('message' => 'GET OUT OF HERE!'));
         $view->setTemplate('product/error/access');
         return $view;
     }
 }
Пример #3
0
 public function addAction()
 {
     $form = new ProductForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $product = new Product();
         $form->setInputFilter($product->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $product->exchangeArray($form->getData());
             $this->getProductTable()->saveProduct($product);
             return $this->redirect()->toRoute('product');
         }
     }
     return array('form' => $form);
 }
Пример #4
0
 public function addAction()
 {
     $form = new ProductForm();
     $form->get('submit')->setValue('Add');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $product = new Product();
         $form->setInputFilter($product->getInputFilter());
         $form->setData($request->getPost());
         var_dump($request->getPost());
         if ($form->isValid()) {
             $product->exchangeArray($form->getData());
             $this->getProductTable()->saveProduct($product);
             // Redirect to list of products
             return $this->redirect()->toRoute('product');
         } else {
             echo 'NOPE';
         }
     }
     return array('form' => $form, 'shops' => $this->getShopTable()->fetchAll($this->getServiceLocator()->get('AuthService')->getStorage()->read()->id), 'product_categories' => $this->getProductCategoryTable()->fetchAll($this->getServiceLocator()->get('AuthService')->getStorage()->read()->id));
 }
Пример #5
0
 public function addAction()
 {
     $utility = new Utility();
     $product = new Product();
     $view = new ViewModel();
     $this->layout('layout/bags');
     $getuser = $this->forward()->dispatch('Admin\\Controller\\Index', array('action' => 'getuser'));
     $this->layout()->getuser = $getuser;
     // notlogin
     if (!$getuser) {
         $this->redirect()->toUrl(WEBPATH);
     }
     $this->layout()->getuser = $getuser;
     $dataPayout = $this->getServiceLocator()->get('PayoutypeTable')->gettype();
     $img = null;
     $img1 = null;
     $img2 = null;
     $img3 = null;
     $img4 = null;
     $img5 = null;
     $img6 = null;
     $img7 = null;
     $img8 = null;
     $img9 = null;
     $img0 = null;
     $dbAdapter = $this->getServiceLocator()->get('Zend\\Db\\Adapter\\Adapter');
     if ($getuser && ($getuser->group == 'admin' || $getuser->group == 'supperadmin')) {
         $form = new Productform($dbAdapter);
         $form->setInputFilter(new ProductFilter());
         $catalogarr = $this->getdataAction();
         $form->setId($catalogarr);
         $tags = $this->getTagsAction();
         $form->settagsId($tags);
         // 			$manufacturer = array ();
         // 			$form->setmanufacturerId ( $manufacturer );
         $request = $this->getRequest();
         if ($request->isPost()) {
             $form->setInputFilter($product->getInputFilter());
             // check validate
             $data = array_merge_recursive($request->getPost()->toArray(), $request->getFiles()->toArray());
             $form->setData($data);
             //
             if ($form->isValid()) {
                 if ($data['img']['name'] != '') {
                     $id = $data['id'];
                     $getcata = $this->getServiceLocator()->get('ProductTable')->get($id);
                     if ($data['img']['name'] != '') {
                         // edit anh
                         $_array_img = $data['img'];
                         // Recyle Bin img older
                         if ($getcata) {
                             //img
                             $get_img_older = $getcata->img;
                             $_dir = UPLOAD_PATH_IMG;
                             if ($get_img_older) {
                                 $utility->deleteImage($get_img_older, $_dir);
                             }
                         }
                         // upload and rename
                         $renname_file_img = $utility->uploadImageAlatca($_array_img);
                         if (!$renname_file_img) {
                             $view->check = 0;
                             return $view;
                         }
                     }
                     //img
                     $img = $renname_file_img;
                     if ($data['img1']['name'] != '') {
                         //not  edit anh
                         $_array_img = $data['img1'];
                         // Recyle Bin img older
                         if ($getcata) {
                             //img
                             $get_img_older = $getcata->img1;
                             $_dir = UPLOAD_PATH_IMG;
                             if ($get_img_older) {
                                 $utility->deleteImage($get_img_older, $_dir);
                             }
                         }
                         // upload and rename
                         $renname_file_img = $utility->uploadImageAlatca($_array_img);
                         if (!$renname_file_img) {
                             $view->check = 0;
                             return $view;
                         }
                     }
                     //img1
                     $img1 = $renname_file_img;
                     $product = new Product();
                     $product->dataArraySwap($data, $img, $img1, $img2, $img3, $img4, $img5, $img6, $img7, $img8, $img9, $img0);
                     $check = $this->getServiceLocator()->get('ProductTable')->save($product);
                     if ($check != 0) {
                         $_url = WEBPATH . '/product/index/index';
                         $this->redirect()->toUrl($_url);
                     } else {
                         $view->check = 0;
                         return $view;
                     }
                 } else {
                     $id = $data['id'];
                     $getcata = $this->getServiceLocator()->get('ProductTable')->get($id);
                     if ($getcata) {
                         $get_img_older = $getcata->img;
                         $get_img_older1 = $getcata->img1;
                         $get_img_older2 = $getcata->img2;
                         $get_img_older3 = $getcata->img3;
                         $get_img_older4 = $getcata->img4;
                         $get_img_older5 = $getcata->img5;
                         $get_img_older6 = $getcata->img6;
                         $get_img_older7 = $getcata->img7;
                         $get_img_older8 = $getcata->img8;
                         $get_img_older9 = $getcata->img9;
                         $get_img_older10 = $getcata->img0;
                     }
                     $product = new Product();
                     $product->dataArraySwap($form->getData(), $get_img_older, $get_img_older1, $get_img_older2, $get_img_older3, $get_img_older4, $get_img_older5, $get_img_older6, $get_img_older7, $get_img_older8, $get_img_older9, $get_img_older10);
                     $check = $this->getServiceLocator()->get('ProductTable')->save($product);
                     $_url = WEBPATH . '/product/index/add/' . $id;
                     if ($check == 0) {
                         // notupdate
                         $_url = WEBPATH . '/product/index/index';
                         $this->redirect()->toUrl($_url);
                     }
                     if ($check != 0) {
                         $_url = WEBPATH . '/product/index/index';
                         $this->redirect()->toRoute('Product', array('controller' => 'index', 'action' => 'add', 'id' => $check));
                     }
                 }
             }
         }
         // end post
         $product_id = (int) $this->params()->fromRoute('id', 0);
         $catalog_cr = $this->getServiceLocator()->get('ProductTable')->get($product_id);
         if ($product_id == 0) {
             $form->get('submit')->setAttribute('value', 'Add Product');
         } else {
             $form->get('submit')->setAttribute('value', 'Edit Product');
         }
         $_img_thumb = null;
         $_img_thumb1 = null;
         $_img_thumb2 = null;
         $_img_thumb3 = null;
         $_img_thumb4 = null;
         $_img_thumb5 = null;
         $_img_thumb6 = null;
         $_img_thumb7 = null;
         $_img_thumb8;
         $_img_thumb9 = null;
         if (!empty($catalog_cr) and $product_id != 0) {
             $view->setVariable('Error', 1);
             $form->bind($catalog_cr);
             $_img_thumb = $catalog_cr->img;
             //$_img_thumb1 = $catalog_cr->img1;
             // 				$_img_thumb2 = $catalog_cr->img2;
             // 				$_img_thumb3 = $catalog_cr->img3;
             // 				$_img_thumb4 = $catalog_cr->img4;
             // 				$_img_thumb5 = $catalog_cr->img5;
             // 				$_img_thumb6 = $catalog_cr->img6;
             // 				$_img_thumb7 = $catalog_cr->img7;
             // 				$_img_thumb8 = $catalog_cr->img8;
             // 				$_img_thumb9 = $catalog_cr->img9;
             // 				$_img_thumb0 = $catalog_cr->img0;
             // 				$view->setVariable ( 'img_thumb1', $_img_thumb1 );
             // 				$view->setVariable ( 'img_thumb2', $_img_thumb2 );
             // 				$view->setVariable ( 'img_thumb3', $_img_thumb3 );
             // 				$view->setVariable ( 'img_thumb4', $_img_thumb4 );
             // 				$view->setVariable ( 'img_thumb5', $_img_thumb5 );
             // 				$view->setVariable ( 'img_thumb6', $_img_thumb6 );
             // 				$view->setVariable ( 'img_thumb7', $_img_thumb7 );
             // 				$view->setVariable ( 'img_thumb8', $_img_thumb8 );
             // 				$view->setVariable ( 'img_thumb9', $_img_thumb9 );
             // 				$view->setVariable ( 'img_thumb0', $_img_thumb0 );
         }
         $view->setVariable('Productform', $form);
         $view->setVariable('id_product', $product_id);
         $view->setVariable('img_thumb', $_img_thumb);
         return $view;
     } else {
         $view->check = 2;
         $this->layout('error/admin');
         return $view;
     }
 }