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']); } } }
public function productsAction() { $request = $this->request; $persistent = $this->persistent; // Reset $reset = $this->request->getQuery('reset', 'int'); if (isset($reset)) { $persistent->productsParams = null; } // Persistent parameters if (!is_array($persistent->productsParams)) { $persistent->productsParams = ['qry' => ['conditions' => "id IS NOT NULL", 'order' => 'id ASC'], 'sort' => ['page' => 1, 'perpage' => 50]]; } $parameters = $persistent->productsParams; $parameters['sort']['perpage'] = 50; $parameters['sort']['page'] = 1; if ($request->getQuery('page', 'int')) { $parameters['sort']['page'] = $request->getQuery('page', 'int'); } if ($request->getQuery('perpage', 'int')) { $parameters['sort']['perpage'] = $request->getQuery('perpage', 'int'); } // ---------------------------------------- // Search if ($request->isPost()) { $parameters['search_cat'] = null; $parameters['search_virtcat'] = null; $parameters['search_maker'] = null; $parameters['search_material'] = null; $parameters['search_hold'] = null; $parameters['search_id'] = null; // Category if (!empty($_POST['search_cat'])) { $search_cat_get = $request->getPost('search_cat', 'int'); $parameters['search_cat'] = $search_cat_get; $search_cats = PCategory::getCatTree($search_cat_get); $search_cat = " AND category_id IN ({$search_cats})"; } else { $search_cat = null; } // Virtual category if (!empty($_POST['search_virtcat'])) { $search_virtcat_get = $request->getPost('search_virtcat', 'int'); $parameters['search_virtcat'] = $search_virtcat_get; $search_virtcat = " AND tmaterial_id = {$search_virtcat_get}"; } else { $search_virtcat = null; } // Maker if (!empty($_POST['search_maker'])) { $search_maker_get = $request->getPost('search_maker', 'int'); $parameters['search_maker'] = $search_maker_get; $search_maker = " AND maker_id = {$search_maker_get}"; } else { $search_maker = null; } // Material if (!empty($_POST['search_material'])) { $search_material_get = $request->getPost('search_material', 'int'); $parameters['search_material'] = $search_material_get; $search_material = " AND cmaterial_id = {$search_material_get}"; } else { $search_material = null; } // Hold if (!empty($_POST['search_hold'])) { $search_hold_get = $request->getPost('search_hold', 'int'); $parameters['search_hold'] = $search_hold_get; $search_hold = $search_hold_get == 1 ? " AND hold = 1" : " AND hold = 0"; } else { $search_hold = null; } // ID if (!empty($_POST['search_id'])) { $parameters['search_id'] = $request->getPost('search_id', 'string'); $search_id_get = preg_split('/[,\\s]/', $request->getPost('search_id', 'string'), null, PREG_SPLIT_NO_EMPTY); $search_id = join(', ', $search_id_get); $search_id = " AND id IN ({$search_id})"; } else { $search_id = null; } // Search parameters $parameters['qry'] = ['conditions' => "id IS NOT NULL\n {$search_cat}\n {$search_virtcat}\n {$search_maker}\n {$search_material}\n {$search_hold}\n {$search_id}"]; } // Other parameters $parameters['query_count'] = PProductMain::count($parameters['qry']); $parameters['qry']['order'] = "id ASC"; $parameters['qry']['limit'] = 10000; $persistent->productsParams = $parameters; // var_dump($parameters); // Find all placements that correspond to set parameters $products = PProductMain::find($parameters['qry']); // Paginator $paginator = new Paginator(["data" => $products, "limit" => $parameters['sort']['perpage'], "page" => $parameters['sort']['page']]); $this->view->page = $paginator->getPaginate(); // Set selected search values $this->view->selected_cat = isset($parameters['search_cat']) && !empty($parameters['search_cat']) ? $parameters['search_cat'] : null; $this->view->selected_virtcat = isset($parameters['search_virtcat']) && !empty($parameters['search_virtcat']) ? $parameters['search_virtcat'] : null; $this->view->selected_maker = isset($parameters['search_maker']) && !empty($parameters['search_maker']) ? $parameters['search_maker'] : null; $this->view->selected_material = isset($parameters['search_material']) && !empty($parameters['search_material']) ? $parameters['search_material'] : null; $this->view->selected_hold = isset($parameters['search_hold']) && !empty($parameters['search_hold']) ? $parameters['search_hold'] : null; $this->view->selected_id = isset($parameters['search_id']) && !empty($parameters['search_id']) ? $parameters['search_id'] : null; // Products count (overall or filtered) $this->view->products_count = $parameters['query_count']; // All categories $this->view->cats_list = PCategory::getCatList(); // All virtual categories $virtcats = PCategoryGroup::find(['order' => 'title ASC']); foreach ($virtcats as $virtcat) { $virtcats_array[$virtcat->id] = $virtcat->title; } $this->view->virtcats_list = $virtcats_array; // All makers // $makers = PMaker::find(["name IS NOT NULL AND isseller=1 AND approved=1 AND banned=0", 'order' => 'name ASC']); $makers = PMaker::find(["name IS NOT NULL AND isseller=1", 'order' => 'name ASC']); foreach ($makers as $maker) { $makers_array[$maker->id] = $maker->name; } $this->view->makers_list = $makers_array; // All materials $materials = PProdMaterial::find(['order' => 'title ASC']); foreach ($materials as $material) { $materials_array[$material->id] = $material->title; } $this->view->materials_list = $materials_array; // Langs stat $langs = PProdInfo::count(["coder_status = 5", 'group' => 'lang', 'order' => 'id']); foreach ($langs as $lang) { $langs_stat[$lang->lang] = $lang->rowcount; } $this->view->langs_stat = $langs_stat; // Check if user can put products on hold $this->view->can_hold = AccRoles::findFirst("user_id={$this->auth->id} AND (role_id=5 OR role_id=1000)"); }