public function indexAction($maker_id = null, $product_id = null) { if ($this->request->isPost()) { $redirect = "revaluation/index"; $input_maker = $this->request->getPost('maker_id'); if (!empty($input_maker)) { if (preg_match('/^\\d+$/', $input_maker)) { $maker_id = $input_maker; } else { $maker_id = PMaker::findFirst("name='{$input_maker}'")->id; } // $maker_id = $this->request->getPost('maker_id', 'int'); $redirect = "revaluation/index/{$maker_id}"; // return $this->response->redirect("revaluation/index/$maker_id"); } if (!empty($this->request->getPost('product_id', 'int'))) { $product_id = $this->request->getPost('product_id', 'int'); if ($find_product = PProductMain::findFirst($product_id)) { $maker_id = $find_product->maker_id; $redirect = "revaluation/index/{$maker_id}/{$product_id}"; } else { $redirect = "revaluation/index"; } // return $this->response->redirect("revaluation/index/$maker_id/$product_id"); } return $this->response->redirect($redirect); } if ($maker_id != null) { // Find maker $and_prod_id = $product_id != null ? " AND id={$product_id}" : null; $maker = PMaker::findFirst($maker_id); if (!$maker) { $this->flash->error("Мастер с id {$maker_id} не найден!"); return $this->response->redirect("revaluation/index"); } $maker_products = PProductMain::find("parent=0 AND maker_id={$maker_id}" . $and_prod_id); $maker_count = PProductMain::count("parent=0 AND maker_id={$maker_id}" . $and_prod_id); $this->view->maker = $maker->name; $this->view->maker_count = $maker_count; $this->view->maker_curr = $maker->currencystr; // Currency rate // $this->view->crosscurr = PCrosscurrency::findFirst("title='{$maker->currencystr}'")->currencyrate; // Paginator $perpage = $this->request->getQuery('perpage', 'int') ? $this->request->getQuery('perpage', 'int') : 50; $page = $this->request->getQuery('page', 'int') ? $this->request->getQuery('page', 'int') : 1; $paginator = new Paginator(["data" => $maker_products, "limit" => $perpage, "page" => $page]); $this->view->page = $paginator->getPaginate(); } // All makers // $this->view->makers_list = array_column(PMaker::find(["name IS NOT NULL AND isseller=1 AND approved=1 AND (banned=0 OR banned IS NULL)", 'order' => 'name ASC'])->toArray(), 'name', 'id'); $this->view->maker_id = $maker_id; $this->view->requests = PRevaluation::find(['active=1', 'order' => 'created DESC']); }
public function index2Action($maker_id = null) { if ($maker_id != null) { $maker_id = $this->filter->sanitize($maker_id, 'int'); if ($maker = PMaker::findFirst($maker_id)) { $this->view->products = $products = PProductMain::find("maker_id={$maker_id}"); $this->view->maker = $maker; $this->view->count = PProductMain::count("maker_id={$maker_id}"); if ($this->request->isPost()) { $args = ['main_comment' => ['filter' => FILTER_SANITIZE_STRING], 'title' => ['filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY], 'oldprice' => ['filter' => FILTER_SANITIZE_NUMBER_FLOAT, 'flags' => FILTER_REQUIRE_ARRAY], 'comment' => ['filter' => FILTER_SANITIZE_STRING, 'flags' => FILTER_REQUIRE_ARRAY]]; $inpData = filter_input_array(INPUT_POST, $args); $main_comment = $inpData['main_comment']; $title = $inpData['title']; $oldprice = $inpData['oldprice']; $comment = $inpData['comment']; $body = ""; if (!empty($main_comment)) { $body = "Комментарий: {$main_comment}<br><br>"; } $body .= "<table width='100%' border='1' cellpadding='2' cellspacing='1'>"; $body .= "<tr><td>ID</td><td>Название</td><td>Старая цена</td><td>Комментарий</td></tr>"; foreach ($comment as $product_id => $value) { if (!$value) { continue; } $body .= "<tr>\n <td>{$product_id}</td>\n <td>{$title[$product_id]}</td>\n <td>{$oldprice[$product_id]} {$maker->currencystr}</td>\n <td>{$value}</td>\n </tr>"; } $body .= "</table>"; // Compose a message $msg = ['To' => $this->config->emails->usercab2, 'From' => $this->config->POSTMARK->POSTMARK_FROM, 'Subject' => "Комментарии от мастера - {$maker->name}", 'HtmlBody' => "<html><body>{$body}</body></html>"]; try { $client = new PostmarkClient($this->config->POSTMARK->POSTMARK_API); $send = $client->sendEmailBatch([$msg]); $this->flash->success('Сохранено!'); } catch (PostmarkException $ex) { if ($ex) { $this->flash->error('Произошла ошибка!'); } } } } else { $this->flash->error('Мастер с таким ID не найден!'); $this->response->redirect('usercab/index2'); } } }
/** * Delete a maker * @param null $maker_id * @return \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface */ public function deleteMakerAction($maker_id = null) { if ($maker_id != null) { $maker = PMaker::findFirst($maker_id); if (!$maker->delete()) { $this->flash->error("Произошла ошибка при удалении мастера!"); return $this->response->redirect($_SERVER['HTTP_REFERER']); } else { $this->flash->success("Мастер был удален!"); return $this->response->redirect($_SERVER['HTTP_REFERER']); } } }