public function updateAction()
 {
     $request = $this->getRequest();
     $data = $request->getPost();
     $db = $this->getTable('category');
     if ($data['actiontype'] == 'delete') {
         $db->delete(array('id' => $data['id']));
     } elseif ($data['actiontype'] == 'update') {
         $postdata = array();
         foreach ($data as $key => $value) {
             if ($key == 'actiontype') {
                 continue;
             }
             $postdata[$key] = $value;
         }
         $db->update($postdata, array('id' => $data['id']));
     } elseif ($data['actiontype'] == 'addsub') {
         $user = new User($this->getServiceLocator());
         $adminloginuser = new Container('adminloginuser');
         $menus = $user->getUserMenu($adminloginuser->userid);
         $view = new ViewModel(array('userdetail' => $adminloginuser->userdetail, 'menus' => $menus, 'controller' => 'Category', 'categorytree' => $this->getAllCategory(), 'parentcategoryid' => $data['id'], 'parentcategoryname' => $data['name']));
         return $view->setTemplate('/category/category/index.phtml');
     }
     return $this->redirect()->toRoute('category/default', array('controller' => 'category', 'action' => 'index'));
 }
 public function addAction()
 {
     $container = new Container('adminloginuser');
     if ($container->userid == '') {
         // this section is not working. Need some more work here
         return $this->redirect()->toRoute('admin/default', array('controller' => 'index', 'action' => 'login'));
     }
     $user = new User($this->getServiceLocator());
     //        $adminloginuser = new Container('adminloginuser');
     $menus = $user->getUserMenu($container->userid);
     return new ViewModel(array('userdetail' => $container->userdetail, 'islink' => true, 'menus' => $menus, 'controller' => 'Customer'));
 }
 public function indexAction()
 {
     $checklogin = new IndexController();
     return $checklogin->checkLogin('Products', $this->getServiceLocator());
     $checklogin = new IndexController();
     $obj = $checklogin->checkLogin($this->getServiceLocator());
     if (is_object($obj)) {
         return $obj;
     } else {
         $user = new User($this->getServiceLocator());
         $adminloginuser = new Container('adminloginuser');
         $menus = $user->getUserMenu($adminloginuser->userid);
         return new ViewModel(array('userdetail' => $adminloginuser->userdetail, 'menus' => $menus, 'controller' => 'User'));
     }
 }
 public function updateAction()
 {
     $request = $this->getRequest();
     $data = $request->getPost();
     $categoryid = '';
     $default_image = '';
     $db = $this->getTable('product');
     if ($data['actiontype'] == 'delete') {
         $db->delete(array('id' => $data['id']));
     } elseif ($data['actiontype'] == 'save' || $data['actiontype'] == 'save_continue') {
         $postdata = array();
         foreach ($data as $key => $value) {
             if ($key == 'name' || $key == 'description' || $key == 'short_description' || $key == 'status' || $key == 'price' || $key == 'imagepath' || $key == 'inventory' || $key == 'customer_id' || $key == 'approved') {
                 $postdata[$key] = $value;
             } else {
                 if ($key == 'category') {
                     $categoryid = $value;
                     continue;
                 } else {
                     if ($key == 'default_image') {
                         $default_image = $value;
                         continue;
                     }
                 }
             }
         }
         $db->update($postdata, array('id' => $data['id']));
         $this->setProductCategory($data['id'], $categoryid);
         // image part
         if ($_FILES['photo']['name']) {
             //if no errors...
             if (!$_FILES['photo']['error']) {
                 $valid_file = true;
                 //now is the time to modify the future file name and validate the file
                 $new_file_name = strtolower($_FILES['photo']['tmp_name']);
                 //rename file
                 if ($_FILES['photo']['size'] > 1024000) {
                     //can't be larger than 1 MB
                     $valid_file = false;
                     $message = 'Oops!  Your file\'s size is to large.';
                 }
                 if ($valid_file) {
                     $imgname = '/' . $data['id'] . '_' . $_FILES['photo']['name'];
                     move_uploaded_file($_FILES['photo']['tmp_name'], realpath(dirname(__FILE__) . '/../../../../../public/images/products/') . $imgname);
                     $db = $this->getTable('product_image');
                     $postdata = array();
                     $postdata['product_id'] = $data['id'];
                     $postdata['imagepath'] = 'images/products' . $imgname;
                     $db->delete(array('product_id' => $data['id'], 'imagepath' => 'images/products' . $imgname));
                     $db->insert($postdata);
                 }
             } else {
                 //set that to be the returned message
                 $message = 'Ooops!  Your upload triggered the following error:  ' . $_FILES['photo']['error'];
             }
         }
         // image part
         // default image if found update
         if ($default_image) {
             $image_db = $this->getTable('product_image');
             $image_db->update(array('is_default' => 0), array('is_default' => 1, 'product_id' => $data['id']));
             $image_db->update(array('is_default' => 1), array('id' => $default_image));
         }
         // default image if found update
         // check for attribute
         foreach ($data as $key => $value) {
             $subatt = explode('||', $key);
             if ($subatt[0] == 'attribute') {
                 // get table name from id
                 $tablename = $subatt[2];
                 // delete old value for $data['id'] in that table
                 $attTable = $this->getTable($tablename);
                 $attTable->delete(array('product_id' => $data['id'], 'attributetype_id' => $subatt[1]));
                 // insert new $value in that table
                 $newdata = array();
                 $newdata['product_id'] = $data['id'];
                 $newdata['attributetype_id'] = $subatt[1];
                 if ($tablename == 'attribute_date') {
                     $newdata['value'] = strtotime($value);
                 } else {
                     $newdata['value'] = $value;
                 }
                 $attTable->insert($newdata);
             }
         }
         // check for attribute
     } elseif ($data['actiontype'] == 'remove_image' || $data['remove_image_id'] != '') {
         // remove file $data['remove_image_path']
         unlink(realpath(dirname(__FILE__)) . '/../../../../../public/' . $data['remove_image_path']);
         $db = $this->getTable('product_image');
         $db->delete(array('id' => $data['remove_image_id']));
     }
     if ($data['actiontype'] == 'save_continue' || $data['actiontype'] == 'remove_image') {
         $user = new User($this->getServiceLocator());
         $adminloginuser = new Container('adminloginuser');
         $menus = $user->getUserMenu($adminloginuser->userid);
         $productdetail = $this->getProductCollection(0, 1, '', $data['id']);
         $view = new ViewModel(array('userdetail' => $adminloginuser->userdetail, 'menus' => $menus, 'customername' => $this->getCustomerName($productdetail['customer_id']), 'controller' => 'Products', 'islink' => true, 'productdetail' => $productdetail, 'categorytree' => $this->getAllCategory(), 'categoryid' => $this->getProductCategoryId($data['id']), 'activeattributes' => $this->getActiveAttributes($data['id'])));
         return $view->setTemplate('/product/product/edit.phtml');
     }
     return $this->redirect()->toRoute('product/default', array('controller' => 'product', 'action' => 'index'));
 }
 public function logindetail($serviceLocator)
 {
     $user = new User($serviceLocator);
     $adminloginuser = new Container('adminloginuser');
     return $user->getUserMenu($adminloginuser->userid);
 }