function admin_edit_product($id = null) { if (!$id && empty($this->data)) { $this->Session->setFlash('Invalid product'); $this->redirect(array('action' => 'admin_show_all_products', 'admin' => true)); } if (!empty($this->data)) { //pogledamo ce je file upload prazen if ($this->data['Product']['file']['error'] == 4) { //ce je file prazen in je forma submitala polje 'image', to pomeni da je produkt ze vseboval sliko if (!empty($this->data['Product']['image'])) { //ker produkt vsebuje sliko, ime slike v bazi shranimo nazaj v $this->data tako da se ob ponovnem shranjevanju produkta ta ne prepise s praznim poljem $this->data['Product']['pd_image'] = $this->data['Product']['image']; } else { $this->data['Product']['pd_image'] = null; } //ce fajl submit ni prazen, pomeni da moremo sliko na novo shraniti oziroma prepisati } else { $this->data['Product']['pd_image'] = $this->Product->admin_upload_photo($this->data); } if (empty($this->data)) { //$this->Product->invalidate('file','isUploaded'); $this->Session->setFlash('You must upload a product image'); //$this->render(); } else { //$this->data['Product']['pd_last_update'] = date('Y-m-d H:i:s', time()); if ($this->Product->save($this->data)) { $this->Session->setFlash('Product has been edited successfully'); $this->redirect(array('action' => 'admin_show_all_products', 'admin' => true)); } else { $this->Session->setFlash('Product could not be edited!'); } } } if (empty($this->data)) { $this->Product->recursive = 1; $this->data = $this->Product->read(null, $id); } $categories = $this->Product->Category->find('list', array('fields' => array('Category.id', 'Category.cat_name'))); $this->set(compact('categories')); }
<?php !defined('IN_PTF') && exit('ILLEGAL EXECUTION'); /** * @file index * @author ryan <*****@*****.**> * @created Jun 27, 2012 6:24:01 PM */ if ($user_type === 'Admin') { redirect('order/all'); } if ($user_type === 'SuperAdmin') { redirect('admin'); } list($name, $no, $stone_size, $type) = _get('name', 'no', 'stone_size', 'type'); $mode = _get('mode') ?: 'list'; $cur_page = _get('p') ?: 1; $page_num_map = array('list' => 10, 'image' => 24); $per_page = $page_num_map[$mode]; $conds = compact('name', 'no', 'stone_size', 'type'); $total = Product::count($conds); $paging = new Paginate($per_page, $total); $paging->setCurPage($cur_page); $products = Product::read(array_merge($conds, array('limit' => $per_page, 'offset' => $paging->offset()))); $chosen_map = SesState::chosenProducts(); $types = Product::types(); $view .= '?master'; $page['scripts'][] = 'widget';