public function askAction() { $form = Model_Static_Loader::loadForm('forum'); $forumModel = new Model_DbTable_Forum(); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { $question = $forumModel->createRow($form->getValues()); if (preg_match('/^\\w+[\\w-\\.]*\\@\\w+((-\\w+)|(\\w*))\\.[a-z]{2,3}$/', $question->email) && ($question->category == 'Вопросы и запросы' || $question->category == 'Отзывы и предложения' || $question->category == 'Книга жалоб')) { $question->content = str_replace("\n", "<br/>\n", $question->content); $question->save(); $users = new Zend_Config_Xml(APPLICATION_PATH . "/config/admins.xml"); $users = $users->toArray(); $mailer = new Zend_Mail("UTF-8"); $mailer->setFrom($question->email, $question->author); $mailer->setSubject("форум"); // wdaemon 2013-02-08 $mailer->setBodyHtml ( "Новый вопрос: " . $question->content, "utf8", "UTF-8"); $mailer->setBodyHtml("Новый вопрос: " . $question->content); $mailer->addTo("*****@*****.**", "ALPHA-HYDRO info"); $mailer->addBcc("*****@*****.**", "Fedonov Roman A."); $mailer->addBcc("*****@*****.**", "Быков Дмитрий Владимирович"); foreach ($users as $user) { if ($user["role"] == "administrator") { $mailer->addTo($user['email'], $user['name']); } } $mailer->send(); $this->view->error = 0; } else { $this->view->error = 1; } } else { $this->_redirect($this->view->url(array("action" => "index"))); return; } }
public function editCatalogAction() { $catalogForm = Model_Static_Loader::loadForm("catalog"); $catalogForm->preview->setDestination(APPLICATION_ROOT . "/public/files/catalogs"); $catalogForm->file->setDestination(APPLICATION_ROOT . "/public/files/catalogs"); $catalogs = new Zend_Config_Xml(APPLICATION_PATH . "/config/catalogs.xml"); $id = $this->getRequest()->getParam('guid'); if ($id && !isset($catalogs->{$id})) { throw new Zend_Exception("Not found", 404); } elseif ($id) { $catalogForm->setDefaults($catalogs->{$id}->toArray()); } if ($this->getRequest()->isPost() && $catalogForm->isValid($_POST)) { $data = $catalogForm->getValues(); $data["preview"] = "/files/catalogs/" . $data["preview"]; $data["file"] = "/files/catalogs/" . $data["file"]; $catalogs = $catalogs->toArray(); if ($id) { $catalogs[$id] = $data; } else { $catalogs['cat' . date("ymdhis")] = $data; } $xml = new Zend_Config_Writer_Xml(); $xml->setConfig(new Zend_Config($catalogs)); $xml->setFilename(APPLICATION_PATH . "/config/catalogs.xml"); $xml->write(); } $this->view->form = $catalogForm; }
/** * Edit selected category * * @var int $pcategory Selected category */ public function editAction() { if (!Zend_Auth::getInstance()->hasIdentity()) { throw new Zend_Exception("Page not found", 404); } $id = $this->getRequest()->getParam("id"); $categoriesModel = new Model_DbTable_Categories(); $category = $categoriesModel->find($id)->current(); if (!$category && $id) { throw new Zend_Exception("Selected category not found", 404); } elseif (!$id) { $category = $categoriesModel->createRow(); } $form = Model_Static_Loader::loadForm("category"); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { $file = $form->image->getFileInfo(); $ext = pathinfo($file['image']['name'], PATHINFO_EXTENSION); $name = pathinfo($file['image']['name'], PATHINFO_FILENAME); $newName = time() . '_' . $name . '.' . $ext; $form->image->addFilter('Rename', APPLICATION_ROOT . "/public/files/images/category/" . $newName); $form->image->receive(); $data = $form->getValues(); $category->parent_id = $data["parent_id"] ? $data["parent_id"] : NULL; $category->image = $data["image"] ? $data["image"] : $category->image; unset($data['image']); unset($data['parent_id']); foreach ($data as $key => $val) { $category->{$key} = $val; } $category->save(); } $form->setDefaults($category->toArray()); $this->view->form = $form; $this->view->row = $category; }
/** * Login action */ public function loginAction() { $zend_auth = Zend_Auth::getInstance(); $form = Model_Static_Loader::loadForm("login"); if ($this->getRequest()->isPost() && $form->isValid($_POST) && !$zend_auth->hasIdentity()) { $adapter = new Model_Static_Auth($form->getValue("username"), $form->getValue("password")); $result = $zend_auth->authenticate($adapter); if ($result->isValid()) { $zend_auth->getStorage()->write($result->getIdentity()); $this->_forward("index"); } } elseif ($zend_auth->hasIdentity()) { $this->_forward("index"); } $this->view->form = $form; }
/** * Admin action. * Create or edit selected subproduct * * @var int $id Product */ public function subeditAction() { if (!Zend_Auth::getInstance()->hasIdentity()) { throw new Zend_Exception("Access Forbidden", 403); } $parent_id = $this->getRequest()->getParam("parent_id"); $subid = $this->getRequest()->getParam("subid"); $productsModel = new Model_DbTable_Products(); $subproductsModel = new Model_DbTable_Subproducts(); // признаки вида операции $newRecord = $subid == null; $this->view->newRecord = $newRecord; if ($subid) { $product = $subproductsModel->find($subid)->current(); } else { $product = $subproductsModel->createRow(); $product->parent_id = $parent_id; } $editForm = Model_Static_Loader::loadForm("subproduct"); if ($this->getRequest()->isPost()) { // отправка формы if ($editForm->isValid($_POST)) { // product first $values = $editForm->getValues(); foreach ($values as $name => $value) { if (isset($product->{$name})) { $product->{$name} = $value; } } $product->mod_date = date("Y-m-d H:i:s"); if (!$product->add_date) { $product->add_date = $product->mod_date; } $product->save(); } // save productParams $newParams = $this->getRequest()->getParam("productparams"); if ($newParams) { $newParams = array_values($newParams); } else { $newParams = array(); } $product->saveNewParams($newParams); $this->redirect("/catalog/products/edit/category/" . $this->getRequest()->getParam("category") . "/id/" . $parent_id); return; } $editForm->setDefaults($product->toArray()); $this->view->newproduct = $editForm; if (!$newRecord) { // редактируем подпродукт $this->view->row = $product; $this->view->productParams = $product->getParamsValues(); } else { // новый подпродукт $this->view->row = $subproductsModel->createRow(); $this->view->row->parent_id = $parent_id; $parentProduct = $productsModel->find($parent_id)->current(); if ($parentProduct) { $this->view->productParams = $parentProduct->getSubParams(); } else { $this->view->productParams = array(); } } }
public function editAction() { if (!Zend_Auth::getInstance()->hasIdentity()) { throw new Zend_Exception("You cant edit this item"); } $id = $this->getRequest()->getParam("id"); $type = $this->getRequest()->getParam("type"); $from = $this->getRequest()->getParam("from"); $this->view->type = $type; $this->view->from = $from; $categoriesModel = new Model_DbTable_PagesCategories(); $categories = $categoriesModel->getMedia(); $pagesModel = new Model_DbTable_Pages(); if ($id) { $page = $pagesModel->find($id)->current(); } elseif ($this->getRequest()->isPost() && isset($categories[$type]) || !$this->getRequest()->isPost()) { $page = $pagesModel->createRow(); $page->category_id = $categories[$type]->id; } elseif ($this->getRequest()->getParam("parent_id")) { $page = $pagesModel->createRow(); $page->category_id = $this->getRequest()->getParam("parent_id"); } else { throw new Zend_Exception("Selected type not available"); } if (!$page) { throw new Zend_Exception("Page isn't found"); } $form = Model_Static_Loader::loadForm("page"); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { $values = $form->getValues(); unset($values["thumb"]); foreach ($values as $key => $val) { $page->{$key} = $val; } if ($type != "posts") { // upload files if (isset($_FILES["thumb"]) && $_FILES["thumb"]["size"]) { $filename = date("Ymd_His") . $_FILES["thumb"]["name"]; if (!$type) { $type = "common"; } move_uploaded_file($_FILES['thumb']['tmp_name'], $_SERVER["DOCUMENT_ROOT"] . "/files/" . $type . "/" . $filename); $page->thumb = "/files/" . $type . "/" . $filename; } } $page->save(); switch ($page->category_id) { case 4: $url = "/sections/post?id={$page->id}"; break; case 3: case 2: $url = "/sections/news?id={$page->id}"; break; case 7: $url = "/sections/pipeline/"; break; } $this->_redirect($url); exit; } $this->view->page = $page; }
/** * The default action - show the home page */ public function indexAction() { $form = Model_Static_Loader::loadForm("basket"); $session = new Zend_Session_Namespace("basket"); $model = new Model_DbTable_Products(); $items = array(); foreach ($session->items as $item_id => $count) { $items[$item_id] = (object) array("item" => $model->find($item_id)->current(), "count" => $count); } if ($this->getRequest()->isPost() && $form->isValid($_POST) && $items) { $data = $form->getValues(); $orderItems = $this->getRequest()->getParam("items"); /* ****************************************** * EMAIL MESSAGE * ******************************************/ ob_start(); ?> Новый заказ на сайте альфа гидро: <ul><?php foreach ($orderItems as $item => $count) { $item = $items[$item]->item; ?> <li><?php echo $item->sku; ?> , кол-во: <?php echo $count; ?> шт.</li> <?php } ?> </ul> Имя: <?php echo $data['name']; ?> <br/> Email: <?php echo $data['email']; ?> <br/> Телефон: <?php echo $data['phone']; ?> <br/> Примечание:<br/><pre><?php echo strip_tags($data['content']); ?> </pre><br/> <?php $messageHtml = ob_get_clean(); /* ************************************************ * MESSAGE END * ************************************************/ $message = new Zend_Mail("UTF-8"); $message->setFrom("*****@*****.**", "Альфа-Гидро"); $message->setSubject("Новый заказ на сайта Альфа-Гидро"); $message->setBodyHtml($messageHtml, "utf8", "UTF-8"); $users = new Zend_Config_Xml(APPLICATION_PATH . "/config/admins.xml"); $users = $users->toArray(); $message->addTo("*****@*****.**", "Альфа-Гидро"); $message->addTo("*****@*****.**", "Быков Дмитрий Владимирович"); foreach ($users as $user) { if ($user["role"] == "administrator") { $message->addTo($user['email'], $user['name']); } } $message->send(); $session->items = array(); $this->_helper->viewRenderer("index-success"); } $this->view->items = $items; $this->_helper->layout()->setLayout("basket"); }