Ejemplo n.º 1
0
 public function fileUploadSuccess(AppForm $form)
 {
     try {
         foreach ($form->values->image as $image) {
             $file = new \File();
             $d = $image->getImageSize();
             if ($d[0] < 300 && $d[1] < 300) {
                 throw new InvalidArgumentException('Obrázek je příliš malý. Musí mít minimálně jeden rozměr vyšší než 300px. Nahrajte prosím větší obrázek.');
             }
             if ($d[0] > 3000 || $d[1] > 3000) {
                 throw new InvalidArgumentException('Obrázek je až zbytečně veliký. Žádný rozměr by neměl být vyšší než 3000px. Nahrajte prosím menší obrázek.');
             }
             $file->file_prefix = "";
             $file->file_sufix = "_u" . $this->context->user->id . "_" . substr(sha1(time()), 0, 4);
             $file->user_id = $this->context->user->id;
             $file->insertUploaded($image, FILESTORAGE_DIR);
             $file->visible = 1;
             // automaticka publikace
             $file->save();
             if ($form->values->type == "event") {
                 dibi::query('INSERT INTO event_x_file', array('event_id' => $form->values->id, 'file_id' => $file->id));
                 $res = dibi::select('*')->from('event_x_file')->where('first', '=', 1)->where('event_id', '=', $form->values->id);
                 if (count($res) == 0) {
                     $res = dibi::select('*')->from('event_x_file')->where('event_id', '=', $form->values->id)->fetch();
                     dibi::query('UPDATE event_x_file SET ', array('first' => 1), 'WHERE event_id = ', $res->event_id, 'AND file_id =', $res->file_id);
                 }
             } elseif ($form->values->type == "place") {
                 dibi::query('INSERT INTO subject_x_file', array('subject_id' => $form->values->id, 'file_id' => $file->id));
                 $res = dibi::select('*')->from('subject_x_file')->where('first', '=', 1)->where('subject_id', '=', $form->values->id);
                 if (count($res) == 0) {
                     $res = dibi::select('*')->from('subject_x_file')->where('subject_id', '=', $form->values->id)->fetch();
                     dibi::query('UPDATE subject_x_file SET ', array('first' => 1), 'WHERE subject_id = ', $res->subject_id, 'AND file_id =', $res->file_id);
                 }
             }
         }
     } catch (Exception $e) {
         $form->addError($e->getMessage());
     }
     if ($form->isSuccess()) {
         $cache = new \Nette\Caching\Cache($this->context->cacheStorage);
         $cache->clean(array('files', 'images', 'file', 'image', $form->values->type, $form->values->type . 's'));
         $this->presenter->flashMessage('Dobrá zpráva, fotografie se podařilo vložit!', 'success');
         $this->redirect('this');
     }
 }
Ejemplo n.º 2
0
 public function saveEmail(Form $form)
 {
     $values = $form->getValues();
     try {
         $this->context->createService('newsletters')->insert($values);
     } catch (\Exception $e) {
         if ($e->getCode() == 23000) {
             $form->addError('E-mailová adresa "' . $values->email . '" je již v databázi uložena');
         }
     }
     if ($form->isSuccess()) {
         $this->flashMessage('E-mailová adresa byla úspěšně přidána do databáze.', 'success');
         if (!$this->presenter->isAjax()) {
             $this->presenter->redirect('this');
         }
     }
     if ($this->presenter->isAjax()) {
         $this->redrawControl('subscribeForm');
     }
 }
Ejemplo n.º 3
0
 public function fileUploadSuccess(AppForm $form)
 {
     try {
         foreach ($form->values->image as $key => $image) {
             $file = new \File();
             $file->file_prefix = "user" . $this->user->id . "_";
             $file->insertUploaded($image, FILESTORAGE_DIR);
             $file->user_id = $this->user->id;
             $file->save();
         }
     } catch (Exception $e) {
         $form->addError($e->getMessage());
     } catch (DibiException $e) {
         $form->addError($e->getMessage());
     }
     if ($form->isSuccess()) {
         $this->cleanCache('subjects', 'subject', 'files', 'images', 'file', 'image');
         $this->flashMessage('Successfully saved.', 'ok');
         $this->redirect('default');
     }
 }
Ejemplo n.º 4
0
 public function regeneratePassword(UI\Form $form)
 {
     $values = $form->getValues();
     $user = $this->context->createServiceUsers()->where('hash', $values->hash)->fetch();
     if ($user) {
         try {
             $unhash_password = $values->password;
             $values->password = $this->users->calculateHash($values->password);
             $values->hash = sha1($values->username . $values->password);
             $user->update(array('password' => $values->password));
         } catch (Exception $e) {
             $this->flashMessage('Neco se nezdarilo. Zkuste to prosim za chvili znovu', 'error');
         }
     } else {
         $form->addError('Neexistuje žádný uživatel s touto e-maiovou adresou. Zkuste to znovu.', 'error');
     }
     if ($form->isSuccess()) {
         $this->cleanCache('users', 'user');
         $this->flashMessage('Vaše nové heslo bylo uloženo a přihlášení proběhlo úspěšně. Vítejte!', 'success');
         $this->logUser($values->username, $unhash_password);
     }
 }
Ejemplo n.º 5
0
 public function fileUploadSuccess(AppForm $form)
 {
     try {
         foreach ($form->values->image as $key => $image) {
             $file = new \File();
             $d = $image->getImageSize();
             if ($d[0] < 300 && $d[1] < 300) {
                 throw new Exception('Obrázek je příliš malý. Musí mít minimálně jeden rozměr vyšší než 300px. Nahrajte prosím větší obrázek.');
             }
             if ($d[0] > 3000 || $d[1] > 3000) {
                 throw new Exception('Obrázek je až zbytečně veliký. Žádný rozměr by neměl být vyšší než 3000px. Nahrajte prosím menší obrázek.');
             }
             $file->file_prefix = "";
             $file->file_sufix = "_u" . $this->user->id . "_" . substr(sha1(time()), 0, 4);
             $file->user_id = $this->user->id;
             $file->insertUploaded($image, FILESTORAGE_DIR);
             $file->save();
             dibi::query('INSERT INTO event_x_file', array('event_id' => $form->values->event_id, 'file_id' => $file->id));
         }
     } catch (Exception $e) {
         $form->addError($e->getMessage());
     } catch (DibiException $e) {
         $form->addError($e->getMessage());
     }
     if ($form->isSuccess()) {
         $this->cleanCache('subjects', 'subject', 'files', 'images', 'file', 'image');
         $this->flashMessage('Successfully saved.', 'ok');
         $this->redirect('thx', array('event_id' => $form->values->event_id));
     }
 }
Ejemplo n.º 6
0
 /**
  * Create edge between two nodes.
  * @param string $name
  * @return Form
  */
 public function createComponentCreateEdgeForm($name)
 {
     $form = new Form($this, $name);
     $form->addText('source');
     $form->addText('label');
     $form->addText('target');
     $form->addSubmit('create');
     if ($form->isSuccess()) {
         $this->graph->createEdge($form['source']->isFilled() ? $form['source']->value : $this->node->getLabel(), $form['target']->isFilled() ? $form['target']->value : $this->node->getLabel(), $form['label']->value);
         $this->redirect('this');
     }
     return $form;
 }
Ejemplo n.º 7
0
 public function fileUploadSuccess(AppForm $form)
 {
     try {
         foreach ($form->values->image as $key => $image) {
             $file = new \File();
             $file->file_prefix = "user" . $this->user->id . "_";
             $file->insertUploaded($image, FILESTORAGE_DIR);
             //$file->simulation = true;
             $file->visible = 1;
             $file->user_id = $this->user->id;
             $file->save();
             switch ($this->getParameter('module')) {
                 case "subject":
                     \dibi::query('INSERT INTO subject_x_file', array('subject_id' => $this->getParameter('item_id'), 'file_id' => $file->id));
                     break;
                 case "event":
                     \dibi::query('INSERT INTO event_x_file', array('event_id' => $this->getParameter('item_id'), 'file_id' => $file->id));
                     break;
             }
         }
     } catch (Exception $e) {
         $form->addError($e->getMessage());
     } catch (DibiException $e) {
         $form->addError($e->getMessage());
     }
     if ($form->isSuccess()) {
         $this->cleanCache('subjects', 'subject', 'files', 'images', 'file', 'image');
         $this->flashMessage('Successfully saved.', 'ok');
         $this->redirect('default', array('item_id' => $form->values->item_id, 'module' => $form->values->module));
     }
 }