/** * update only one field * */ public function update_field() { //init controller data $this->extensions->hk_InitData($this, __FUNCTION__); if (!$this->user->canModify('listing_grid/download')) { $error = new AError(''); return $error->toJSONResponse('NO_PERMISSIONS_402', array('error_text' => sprintf($this->language->get('error_permission_modify'), 'listing_grid/download'), 'reset_value' => true)); } $this->loadLanguage('catalog/download'); $this->loadModel('catalog/download'); $allowedFields = array('name', 'filename', 'mask', 'max_downloads', 'shared', 'expire_days', 'sort_order', 'activate_order_status_id', 'status', 'attributes'); if (isset($this->request->get['id'])) { $download_id = (int) $this->request->get['id']; //request sent from edit form. ID in url foreach ($this->request->post as $key => $value) { if (!in_array($key, $allowedFields)) { continue; } // check first if ($key == 'name' && (mb_strlen($value) < 2 || mb_strlen($value) > 64)) { $error = $this->language->get('error_download_name'); } elseif ($key == 'activate' && !in_array($data['activate'], array('before_order', 'immediately', 'order_status', 'manually'))) { $error = $this->language->get('error_activate'); } elseif ($key == 'attributes') { $attr_mngr = new AAttribute_Manager('download_attribute'); $attr_errors = $attr_mngr->validateAttributeData($value[$download_id]); if ($attr_errors) { $error = $this->language->get('error_download_attributes') . '<br> ' . implode('<br> ', $attr_errors); } } if (!$error) { $data = array($key => $value); $this->model_catalog_download->editDownload($download_id, $data); } else { $e = new AError(''); return $e->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $error)); } } return null; } else { //request sent from jGrid. ID is key of array foreach ($this->request->post as $field => $value) { foreach ($value as $k => $v) { if ($field == 'name') { if (mb_strlen($v) < 2 || mb_strlen($v) > 64) { $err = $this->language->get('error_name'); $error = new AError(''); return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => $err)); } } $this->model_catalog_download->editDownload($k, array($field => $v)); } } } //update controller data $this->extensions->hk_UpdateData($this, __FUNCTION__); return null; }
/** * @param array $data * @return bool */ private function _validateDownloadForm($data = array()) { if (!$this->user->canModify('catalog/product_files')) { $this->error['warning'] = $this->language->get('error_permission'); } $this->error = array(); $this->loadLanguage('catalog/files'); $this->loadModel('catalog/download'); if (!empty($data['download_id']) && !$this->model_catalog_download->getDownload($data['download_id'])) { $this->error['download_id'] = $this->language->get('error_download_exists'); } if (mb_strlen($data['name']) < 2 || mb_strlen($data['name']) > 64) { $this->error['name'] = $this->language->get('error_download_name'); } if (!in_array($data['activate'], array('before_order', 'immediately', 'order_status', 'manually'))) { $this->error['activate'] = $this->language->get('error_activate'); } else { if ($data['activate'] == 'order_status' && !(int) $data['activate_order_status_id']) { $this->error['order_status'] = $this->language->get('error_order_status'); } } $attr_mngr = new AAttribute_Manager('download_attribute'); $attr_errors = $attr_mngr->validateAttributeData($data['attributes'][$data['download_id']]); if ($attr_errors) { $this->error['attributes'] = $attr_errors; } $this->extensions->hk_ValidateData($this); return $this->error ? false : true; }
/** * @param array $data * @return bool */ private function _validateDownloadForm($data = array()) { $this->error = array(); $this->load->language('catalog/files'); if (!empty($data['download_id']) && !$this->model_catalog_download->getDownload($data['download_id'])) { $this->error['download_id'] = $this->language->get('error_download_exists'); } if (mb_strlen($data['name']) < 2 || mb_strlen($data['name']) > 64) { $this->error['name'] = $this->language->get('error_download_name'); } if (!in_array($data['activate'], array('before_order', 'immediately', 'order_status', 'manually'))) { $this->error['activate'] = $this->language->get('error_activate'); } else { if ($data['activate'] == 'order_status' && !(int) $data['activate_order_status_id']) { $this->error['order_status'] = $this->language->get('error_order_status'); } } $attr_mngr = new AAttribute_Manager('download_attribute'); $attr_errors = $attr_mngr->validateAttributeData($data['attributes'][$data['download_id']]); if ($attr_errors) { $this->error['atributes'] = $this->language->get('error_download_attributes') . '<br> ' . implode('<br> ', $attr_errors); } return $this->error ? false : true; }