Example #1
0
 public function addBoardFormSucceded(Form $form, $values)
 {
     $user = UserService::loadFromSession($form->getPresenter()->getUser());
     if ($values->boardId == 0) {
         $newBoard = BoardService::create($values, $user);
     } else {
         $newBoard = BoardService::loadForUpdate($values->boardId, $values->content);
     }
     $this->boardFacade->save($newBoard);
     if ($form->getPresenter()->isAjax()) {
         if ($values->boardId == 0) {
             $form->setValues([], TRUE);
             $form->getPresenter()->redrawControl("addBoard");
         } else {
             $form->setValues(array("content" => $newBoard->content));
             $form->getPresenter()->getTemplate()->edit = true;
             $form->getPresenter()->redrawControl("editBoard");
         }
         $form->getPresenter()->setupPaginator();
         $form->getPresenter()->getTemplate()->boards = $this->boardFacade->findAll($form->getPresenter()->getLimit());
         $form->getPresenter()->redrawControl("boards");
         $form->getPresenter()->redrawControl("paginator");
     } else {
         $form->getPresenter()->redirect("this");
     }
 }
Example #2
0
 public function addCommentFormSucceded(Form $form)
 {
     $values = (object) $form->getHttpData();
     if (isset($values->antispam) && $values->antispam != $values->firstAddend + $values->secondAddend) {
         $form->getPresenter()->getTemplate()->wrongAntispam = true;
         $form->getPresenter()->getTemplate()->needsAntispam = true;
         $form->getPresenter()->redrawControl("wrongAntispam");
     } else {
         $articleId = $form->getPresenter()->getParameter("id");
         $user = UserService::loadFromSession($form->getPresenter()->getUser());
         $newComment = CommentService::create($values->content, $user);
         $this->commentFacade->save($newComment, $articleId);
         if ($this->commentFacade->needsAntispam($user)) {
             $form->getPresenter()->getTemplate()->needsAntispam = true;
             $form->getPresenter()->getTemplate()->firstAddend = Antispam::generate();
             $form->getPresenter()->getTemplate()->secondAddend = Antispam::generate();
         }
         if (!$form->getPresenter()->isAjax()) {
             $form->getPresenter()->redirect("this");
         } else {
             $form->getPresenter()->redrawControl("addCommentForm");
             $form->getPresenter()->redrawControl("comments");
             $form->getPresenter()->redrawControl("metainfoArea");
             $form->getPresenter()->redrawControl("metainfo");
             $form->setValues([], TRUE);
         }
     }
 }
Example #3
0
 /**
  * @return Nette\Application\UI\Form
  */
 protected function createComponentServerProps()
 {
     $form = new Form();
     $form->addTextArea('props', '', 70, 36);
     $form->addSubmit('submit', 'Nastavit')->setAttribute('class', 'ajax');
     try {
         $value = $this->fileModel->open($this->filePath, FALSE);
         $form->setValues(array('props' => implode('', $value)));
     } catch (\Nette\FileNotFoundException $e) {
         $form->setValues(array('props' => 'Soubor ještě nebyl vytvořen!'));
         $form['submit']->setDisabled();
     }
     if (!$this->allowedToEdit) {
         $form['submit']->setDisabled();
     }
     $form->onSuccess[] = $this->serverPropsFormSubmitted;
     return $form;
 }
Example #4
0
 /**
  * @param  Nette\Application\UI\Form $form
  */
 public function taskFormSubmitted(Form $form)
 {
     $this->taskRepository->createTask($this->list->id, $form->values->text, $form->values->userId);
     $this->flashMessage('Úkol přidán.', 'success');
     if (!$this->isAjax()) {
         $this->redirect('this');
     }
     $form->setValues(array('userId' => $form->values->userId), TRUE);
     $this->invalidateControl('form');
     $this['taskList']->invalidateControl();
 }
Example #5
0
 /**
  * @return Form
  */
 public function createComponentForm()
 {
     $form = new Form();
     $form->addText(CF::NAME, 'Name:')->setRequired('Please enter your name.');
     $form->addText(CF::E_MAIL, 'Email:')->setRequired('Please enter your email.')->addRule(Form::EMAIL, 'Please enter valid email address.');
     $form->addText(CF::PHONE_NO, 'Phone no.:')->setRequired('Please enter your phone number.');
     $form->addText(CF::ADDRESS, 'Street:')->setRequired('Please enter your street.');
     $form->addText(CF::CITY, 'Ciy:')->setRequired('Please enter your city.');
     $form->addText(CF::POST_CODE, 'Postal code:')->setRequired('Please enter your postal code.');
     $form->addSelect(CF::COUNTRY_REGION_CODE, 'Country:', $this->cs->getPairs())->setRequired('Please select your country.')->setValue('FI');
     $form->addSubmit('send', 'Save');
     $form->setValues((array) $this->cus->Read($this->user->id));
     $form->onSuccess[] = array($this, 'formSucceeded');
     return $form;
 }
 public function messageFormSucceeded(Form $form, $values)
 {
     if (trim($values->message) === '') {
         return;
     }
     $message = new Message();
     $message->text = $values->message;
     $message->course = $this->presenter->courseRegistry->course;
     $message->unit = $this->presenter->courseRegistry->unit;
     $message->user = $this->presenter->userInfo;
     $message->submitted_at = new DateTime();
     $this->messageRepository->persist($message);
     $this->generatedFilesStorage->remove($this->presenter->courseRegistry->course->id, 'html', '/chat/');
     $form->setValues(array(), TRUE);
     $this->redrawControl('chatForm');
 }
 /**
  * @return Nette\Application\UI\Form
  */
 protected function createComponentServerParams()
 {
     $form = new Form();
     $form->addGroup('runtime');
     $form->addText('name', 'Jméno: ', 30, 20)->addRule(Form::FILLED, 'server musí mít jméno');
     $form->addText('path', 'Cesta: ', 30)->addRule(Form::FILLED, 'je nutné specifikovat cestu')->addRule(Form::PATTERN, "Toto není platná cesta ke složce, ty začínají a končí lomítkem.", "^/[^/].*/\$");
     $form->addText('executable', 'jméno .jar: ', 30)->addRule(Form::FILLED, 'je nutno specifikovat jméno .jar souboru');
     $form->addSubmit('update', 'Upravit')->setAttribute('class', 'ajax');
     if ($this->commonStorage) {
         $form['path']->setDisabled();
         $form['executable']->setDisabled();
     }
     if (!$this->user->isAllowed('server-settings', 'edit')) {
         $form['update']->setDisabled();
     }
     //defaults
     $values = $this->serverRepo->findById($this->selectedServerId)->fetch();
     $form->setValues($values);
     $form->onSuccess[] = $this->serverParamsFormSubmitted;
     return $form;
 }
Example #8
0
 public function addCategoryFormSucceeded(Form $form, $values)
 {
     if ($values->categoryId == 0) {
         $values->rank = $this->categoryFacade->findMaxRank() + 1;
         $category = CategoryService::create($values);
     } else {
         $category = CategoryService::loadForUpdate($values);
     }
     $this->categoryFacade->save($category);
     if ($form->getPresenter()->isAjax()) {
         if ($values->categoryId == 0) {
             $form->setValues([], true);
             $form->getPresenter()->redrawControl("addCategoryForm");
         } else {
             $form->getPresenter()->getTemplate()->edit = true;
             $form->getPresenter()->redrawControl("editCategoryForm");
         }
         $form->getPresenter()->redrawControl("categories");
     } else {
         $form->getPresenter()->flashMessage("Nová kategorie byla úspěšně vytvořena.", "alert-success");
         $form->getPresenter()->redirect("this");
     }
 }
 /**
  * @param UI\Form $form
  */
 public function changePasswordFormSucceeded(UI\Form $form)
 {
     try {
         $values = $form->getValues();
         $this->userManager->changeUserPassword($values->old_password, $values->new_password, $this->user->identity->id);
         $form->setValues(array(), TRUE);
         $this->flashMessage('Your password change was successful.');
     } catch (\Aprila\InvalidArgumentException $e) {
         $this->flashMessage('Fill your current password correctly.', 'error');
     }
 }
 /**
  * Pre-processing HTML obtained from CKEditor
  *
  * @param Form $form
  */
 public function save(Form $form)
 {
     $values = $form->getValues();
     $html = new Html();
     $html->setHtml($values['editor']);
     foreach ($html->getImages() as $image) {
         list($width, $height) = $image->getDimensionsFromStyle();
         $newFilename = substr($image->getSrc()->getFilename(), 0, strrpos($image->getSrc()->getFilename(), '.')) . "[{$width}x{$height}]" . substr($image->getSrc()->getFilename(), strrpos($image->getSrc()->getFilename(), '.'));
         $newSrc = $image->getSrc()->getPathinfo()->getPath() . '/' . self::TEMP_DIR_NAME . '/' . $newFilename;
         $imFile = realpath($this->publicDir . DIRECTORY_SEPARATOR . $image->getSrc()->getFilename());
         if ($imFile !== FALSE) {
             $im = Image::fromFile($imFile);
             // TODO: resize only if image is larger than real dimensions
             $im->resize($width, $height);
             if ($im->save($this->tempDir . DIRECTORY_SEPARATOR . $newFilename)) {
                 $image->setSrc($newSrc);
             }
         }
     }
     $values['editor'] = $html->getHtml();
     $form->setValues($values, TRUE);
     $this->onSuccess($form);
 }
Example #11
0
 public function addSerialSucceeded(Form $form, $values)
 {
     $values->byUser = $this->user->id;
     $this->articleManager->addSerial($values);
     $this->flashMessage('Přidáno');
     $form->setValues([], true);
     $form->setValues(['underSection' => $values->underSection, 'underSubSection' => $values->underSubSection]);
     $this->redrawAjax('section');
 }
Example #12
0
 public function setValues($values, $erase = FALSE)
 {
     $values = Helpers::contractArray($values, $this->delimiter, TRUE);
     return parent::setValues($values, $erase);
 }
Example #13
0
 /** Catch submitted newItem
  * 
  * @param \Nette\Application\UI\Form $form
  * @throws InvalidStateException
  * @throws Exception
  */
 public function newItemFormSubmitted(Form $form)
 {
     /** test for permissions, if user can add new item */
     $permissions = $this->getUser()->isLoggedIn() ? $this->getUser()->getIdentity()->getRoles() : NULL;
     if (isset($permissions[$this->pageUrl]) && $this->pageConfig['settings']['lvlForAdding'] <= $permissions[$this->pageUrl] || $permissions['admin'] || $this->pageConfig['settings']['lvlForAdding'] == 0) {
         try {
             /** validate date inputs */
             $values = $form->getValues();
             unset($values['kontrolni']);
             // remove antispam
             unset($values['form_created']);
             // remove antispam
             foreach ($values as $key => &$value) {
                 // Because email is added to all forms and not in config,
                 //  it could cause error.
                 if ($key == 'email') {
                     continue;
                 }
                 $confItem = $this->pageConfig['form'][$key];
                 // if date is empty and this item is not mandatory
                 // also skip
                 if ($value == "" && (!isset($confItem['mandatory']) || !$confItem['mandatory'])) {
                     continue;
                 }
                 if ($confItem['type'] == 'calendar') {
                     // check for another conditions
                     if (!empty($this->pageConfig["form"][$key]["greaterEqualThen"])) {
                         $cond = $this->pageConfig["form"][$key]["greaterEqualThen"];
                         if (strtotime($values[$cond]) > strtotime($value)) {
                             $tmp = $value;
                             $value = $values[$cond];
                             $values[$cond] = $tmp;
                             $this->flashMessage('Akce nemůže skončit dříve než začne! Opravte prosím data.', 'error');
                             throw new Exception('badDateFormat');
                             // dump("gg");
                         }
                     }
                     $value = preg_replace('/\\s\\s+/', '', $value);
                     if ($this->itemRepository->isValidDate($value)) {
                         //$value = date('d.m.Y',$date)
                     } else {
                         $this->flashMessage('Zadali jste neplatné datum pro položku ' . $confItem['text'] . '!', 'error');
                         throw new Exception('badDateFormat');
                     }
                 }
             }
             unset($value);
             // get email and save it also to session
             if (isset($values->email)) {
                 $session = $this->getSession('agility');
                 $session->email = $values->email;
                 $email = $values->email;
             } else {
                 $email = '';
             }
             /** create hash for editing link */
             $hash = sha1(microtime() . $email);
             /** add new item to DB */
             $this->itemRepository->add($this->pageUrl, $hash, $this->pageConfig, $this->getHttpRequest(), $values);
             // also dont forget for calendar
             if (isset($this->pageConfig['settings']['calendar'])) {
                 // get from date
                 $dateFrom = date('Y-m-d', strtotime($values[$this->pageConfig['settings']['calendar']['from']]));
                 // get to date
                 if (isset($this->pageConfig['settings']['calendar']['to'])) {
                     // if TO is set
                     $dateTo = date('Y-m-d', strtotime($values[$this->pageConfig['settings']['calendar']['to']]));
                 } else {
                     if (isset($this->pageConfig['settings']['calendar']['duration'])) {
                         // if only duration is known
                         $dateTo = date('Y-m-d', strtotime($values[$this->pageConfig['settings']['calendar']['from']] . ' + ' . $values[$this->pageConfig['settings']['calendar']['duration']] . ' days'));
                     } else {
                         // if TO date is not set
                         $dateTo = NULL;
                     }
                 }
                 $this->calendarRepository->add($this->itemRepository->lastInsertId(), $dateFrom, $dateTo, $this->pageUrl);
             }
             /** auto delete items if wanted */
             if (isset($this->pageConfig['settings']['delete'])) {
                 $this->deleteOld();
             }
             /** sent email if it is enabled */
             if (!empty($this->pageConfig["settings"]["sendEmail"]) && $this->context->parameters['email']['send']) {
                 try {
                     $this->sendMail($this->context->parameters['email']['from'], $email, "Potvrzení nového záznamu", 'newItem', array('title' => $values->title, 'values' => $values, 'hash' => $hash));
                     $this->flashMessage($this->pageConfig["texts"]["successAdd"], 'success');
                 } catch (Exception $e) {
                     $this->flashMessage("Záznam byl uložen, ale došlo k chybě při odesílání emailu - pokud budete potřebovat upravit záznamy, kontaktujte nás na agility.tulak.me.", 'error');
                     \Nette\Diagnostics\Debugger::log('Email cannot be sent! ' . $e->getMessage());
                 }
             } else {
                 $this->flashMessage($this->pageConfig["texts"]["successAdd"], 'success');
             }
             // invalidate cache
             $cache = \Nette\Environment::getCache('Nette.Templating.Cache');
             $cache->clean(array(\Nette\Caching\Cache::TAGS => array('items/' . $this->pageUrl)));
             if (!$this->isAjax()) {
                 // $this->redirect('this');
             } else {
                 $this->invalidateControl('list');
                 $this->invalidateControl('form');
                 $form->setValues(array(), TRUE);
             }
             $this->redirect('Item:default', array('item' => $this->pageUrl));
         } catch (InvalidStateException $e) {
             $this->flashMessage($this->pageConfig["texts"]["failAdd"], 'error');
             throw $e;
         } catch (Exception $e) {
             if ($e->getMessage() != 'badDateFormat') {
                 throw $e;
             }
         }
     }
 }
Example #14
0
 public function formCommentSucceeded(Form $form, $values)
 {
     $sub = $form->getHttpData();
     $under = isset($sub['subcomment']) && $sub['subcomment'] > 0 && $sub['subcomment'] !== '0' ? $sub['subcomment'] : false;
     if (!$this->user->isLoggedIn()) {
         try {
             $this->captchaManager->checkCaptcha($values->captcha);
             $this->captchaManager->setNewQuestion();
         } catch (\Exception $e) {
             if ($under !== false) {
                 $this->template->currentSubComment = $under;
             }
             $this->template->badAnswer = true;
             $this->flashMessage($e->getMessage() . ' Klikněte na: nová otázka');
             $this->redrawAjax(['captchaContainer', 'captchaStatic', 'flashMessageComment']);
             return;
         }
     }
     $this->commentsManager->addComment($values, $under);
     if ($under === false) {
         $this->setPage(1, true);
         $this->flashMessage('Přidán komentář');
         $this->redrawAjax('commentContainerAll');
     } else {
         $this->template->currentSubComment = $under;
         $this->flashMessage('Přidán podkomentář');
         $this->redrawAjax('commentContainerAll');
     }
     $this->redrawAjax(['captchaContainer', 'captchaStatic', 'flashMessageComment']);
     $form->setValues([], true);
 }