{$action}(); else die(json_encode(['errors' => $this->module->l('Access denied!', 'upload')])); } } static $avatar_field = 'avatar'; public function ajaxProcessUploadProfileImage() { $pcCustomer = new EtsRVProductCommentCustomer($this->context->customer->id); $files = EtsRVTools::getInstance()->processUploadImage(self::$avatar_field, 'a', $this->errors, false, null, 150, 150); if (!$this->errors) { list($image, $file_dest, $file_name) = $files; $oldImage = $pcCustomer->id && $pcCustomer->avatar ? $file_dest . $pcCustomer->avatar : ''; if (trim($image) !== '') $pcCustomer->avatar = $image; if (!$pcCustomer->save()) { if (trim($image) !== '' && !@file_exists($file_name)) @unlink($file_name); $this->errors[] = sprintf($this->module->l('An error occurred while adding this image: %s', 'upload'), Tools::stripslashes($image)); } elseif (trim($image) !== '' && @file_exists($oldImage)) { @unlink($oldImage); } $this->module->clearCache('footer.tpl', $this->module->getCacheId('footer')); } $hasError = count($this->errors) ? 1 : 0; $this->module->ajaxRender(json_encode([ 'errors' => $hasError ? implode(Tools::nl2br(PHP_EOL), $this->errors) : false, 'msg' => !$hasError ? $this->module->l('Upload image successfully', 'upload') : '', ])); } public function viewAccess() { if (!isset($this->context->customer->id) || !$this->context->customer->id) { $this->module->ajaxRender([ 'errors' => true, 'msg' => $this->module->l('Customer does not exist.', 'upload'), ]); } } public function ajaxProcessDeleteProfileImage() { $pcCustomer = new EtsRVProductCommentCustomer($this->context->customer->id); $dest = _PS_IMG_DIR_ . $this->module->name . '/a/' . $pcCustomer->avatar; $pcCustomer->avatar = ''; if ($pcCustomer->update()) { if (@file_exists($dest)) @unlink($dest); $this->module->clearCache('footer.tpl', $this->module->getCacheId('footer')); } else $this->errors[] = $this->module->l('Cannot delete avatar.', 'upload'); $hasError = count($this->errors) ? 1 : 0; $this->module->ajaxRender(json_encode([ 'errors' => $hasError ? implode('
', $this->errors) : false, 'msg' => !$hasError ? $this->module->l('Image deleted', 'upload') : '', ])); } }