/**
  * Processing of Upload Photos Form
  *
  * @Privilege('generate')
  *
  * @param Form $form
  */
 public function uploadPhotosFormSucceded(Form $form)
 {
     $values = $form->getValues();
     $event = $this->loadItem($values['id']);
     $calendar = $event->ref('calendar');
     $year = $calendar->yearpart === 'podzim' ? $calendar->year : $calendar->year - 1;
     $date = substr($event->datestart, 0, 4) . substr($event->datestart, 5, 2) . substr($event->datestart, 8, 2);
     // check if the year dir exist. if not, create one
     $params = $this->context->parameters;
     $dirYear = $params['wwwDir'] . $params['chroniclePhotosStorage'] . '/' . $year . ($year + 1) . '/';
     // check if the event dir exists. if not, create one
     $dir = $dirYear . $date . '/';
     if (!file_exists($dir)) {
         mkdir($dir, 0777, TRUE);
     }
     \Tracy\Debugger::barDump($dir);
     // start uploading files
     $counter = 0;
     foreach ($values['upload'] as $file) {
         if ($file->isOK()) {
             if ($file->isImage()) {
                 do {
                     $counter += 1;
                     //increment counter until you hit empty space for file
                     $filePath = $dir . \Nette\Utils\Strings::padLeft($counter, 4, '0') . '.jpg';
                 } while (file_exists($filePath));
                 $image = $file->toImage();
                 $image->save($filePath, 85, \Nette\Image::JPEG);
                 $this->database->table('chronicle_photos')->insert(['event_id' => $values['id'], 'order' => $counter]);
                 $this->flashMessage("Soubor " . $file->getName() . " byl úspěšně nahrán!");
             } else {
                 $form->addError('Soubor' . $file->getName() . ' nebyl rozpoznán jako fotka.');
             }
         } else {
             $form->addError('Nepodařilo se nahrát soubor:' . $file->getName());
         }
     }
     //change event visibility
     if (!array_key_exists('showchronicle', $values)) {
         //user did not have the sufficient permission
         $showchronicle = FALSE;
     } else {
         $showchronicle = $values['showchronicle'] ? TRUE : FALSE;
     }
     $this->events->showChronicle($values['id'], $showchronicle);
     if (!$form->hasErrors()) {
         $this->redirect('default');
     }
 }
Exemplo n.º 2
0
 protected function drawGroups(OutputInterface $output, Group $group)
 {
     $output->writeln(Nette\Utils\Strings::padLeft('', $group->getDepth(), ' ') . '\\_ ' . $group->getName() . ":" . $group->getType());
     foreach ($group->getChild() as $v) {
         $this->drawGroups($output, $v);
     }
 }
Exemplo n.º 3
0
 /**
  * @param double|double[] $price
  * @param null|string     $units
  * @param int             $decimalLength
  *
  * @return string|string[]
  */
 public static function priceCreate($price, $units = NULL, $decimalLength = 2)
 {
     if (is_array($price)) {
         $out = [];
         foreach ($price as $v) {
             $out[] = static::priceCreate($v, $units, $decimalLength);
         }
         return $out;
     } else {
         $workPrice = floor(abs($price * pow(10, $decimalLength)));
         $workDecimalPrice = floor(abs($price * pow(10, $decimalLength + 1)));
         $integerPrice = floor($workPrice / pow(10, $decimalLength));
         $integerLength = strlen($integerPrice);
         $decimalPrice = Nette\Utils\Strings::padLeft(round(static::numberAt($workDecimalPrice, 0, $decimalLength + 1) / 10), $decimalLength, '0');
         $integerTernary = ceil($integerLength / 3);
         $outPrice = '';
         for ($i = $integerTernary - 1; $i >= 0; $i--) {
             if ($outPrice != "") {
                 $outPrice .= '.';
             }
             $outPrice .= Nette\Utils\Strings::padLeft(static::numberAt($integerPrice, $i * 3, 3), 3, '0');
         }
         $outPrice = Nette\Utils\Strings::replace($outPrice, ['~^[0]*~' => '']);
         return ($price < 0 ? '-' : '') . $outPrice . ',' . (in_array($decimalPrice, ['', '0']) ? '-' : $decimalPrice) . (is_null($units) ? '' : ' ' . $units);
     }
 }
Exemplo n.º 4
0
 protected function drawRole(OutputInterface $output, Trejjam\Authorization\Acl\Role $role, $depth = 0)
 {
     $output->writeln(Nette\Utils\Strings::padLeft('', $depth, ' ') . '\\_ ' . $role->getName());
     $resource = [];
     /** @var Trejjam\Authorization\Acl\Resource $v */
     foreach ($role->getResource() as $v) {
         $resource[] = $v->getNameRaw() . ":" . $v->getActionRaw();
     }
     if (count($resource) > 0) {
         $output->writeln(Nette\Utils\Strings::padLeft('', $depth + 2, ' ') . "-" . implode(", ", $resource));
     }
     /** @var Trejjam\Authorization\Acl\Role $v */
     foreach ($role->getChild() as $v) {
         $this->drawRole($output, $v, $depth + 1);
     }
 }
Exemplo n.º 5
0
 function signUpFormSucceeded(\Nette\Forms\BootstrapUIForm $form)
 {
     $activationCode = \Nette\Utils\Random::generate(12, "987654321zyxwvutsrqponmlkjihgfedcba");
     $password = \Nette\Security\Passwords::hash($form->values->pwd);
     $arr = array("email" => $form->values->email, "username" => $form->values->username, "password" => $password, "activation" => $activationCode, "newsletter" => (bool) $form->values->newsletter, "state" => 0, "users_roles_id" => 4, "date_created" => date("Y-m-d H:i:s"));
     if ($this->presenter->template->settings['members:groups:enabled']) {
         $arr["categories_id"] = $form->values->group;
     }
     $userId = $this->database->table("users")->insert($arr);
     $this->database->table("users")->where(array("id" => $userId->id))->update(array("uid" => \Nette\Utils\Strings::padLeft($userId->id, 6, '0')));
     if ($this->template->settings['members:signup:contactEnabled']) {
         $arrContacts = array("categories_id" => 44, "users_id" => $userId, "name" => $form->values->name, "street" => $form->values->street, "city" => $form->values->city, "zip" => $form->values->zip, "countries_id" => 1);
         if ($this->presenter->template->settings['members:signup:companyEnabled']) {
             $arrContacts["company"] = $form->values->company;
             $arrContacts["vatin"] = $form->values->vatin;
             $arrContacts["vatid"] = $form->values->vatid;
         }
         $contactId = $this->database->table("contacts")->insert($arrContacts);
         $this->database->table("contacts")->get($contactId)->update(array("order" => $contactId));
     }
     if ($form->values->vatin) {
         $ares = new \h4kuna\Ares\Ares();
         $aresArr = $ares->loadData('')->toArray();
     }
     $latte = new \Latte\Engine();
     $latte->setLoader(new \Latte\Loaders\StringLoader());
     $params = array('username' => $form->values->username, 'activationCode' => $activationCode, 'settings' => $this->presenter->template->settings, 'form' => $form, 'aresArr' => $aresArr);
     $helpdesk = $this->database->table("helpdesk")->get(3);
     $helpdesk_signup_member = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(5);
     $helpdesk_signup_confirmbyadmin = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(6);
     $helpdesk_signup_adminconfirm = $helpdesk->related("helpdesk_emails", "helpdesk_id")->get(7);
     try {
         if ($this->presenter->template->settings['members:signup:confirmByAdmin']) {
             $email_signup_confirmbyamin = $latte->renderToString($helpdesk_signup_confirmbyadmin->body, $params);
             $email_signup_adminconfirm = $latte->renderToString($helpdesk_signup_adminconfirm->body, $params);
             $mail = new \Nette\Mail\Message();
             $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($form->values->email)->setHTMLBody($email_signup_confirmbyamin);
             $this->presenter->mailer->send($mail);
             $mailA = new \Nette\Mail\Message();
             $mailA->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($this->presenter->template->settings['contacts:email:hq'])->setHTMLBody($email_signup_adminconfirm);
             $this->presenter->mailer->send($mailA);
             $this->flashMessage('Registrace byla dokončena. Po ověření Vám bude zaslán e-mail, po kterém se můžete přihlásit', 'note');
         } else {
             $email_signup_member = $latte->renderToString($helpdesk_signup_member->body, $params);
             $mail = new \Nette\Mail\Message();
             $mail->setFrom($this->presenter->template->settings['contacts:email:hq'])->addTo($form->values->email)->setHTMLBody($email_signup_member);
             $this->presenter->mailer->send($mail);
             $this->presenter->flashMessage('Vaše registrace proběhla úspěšně. Po ověření se můžete přihlásit.', 'note');
         }
         $this->presenter->redirect(":Front:Sign:ed");
     } catch (\Nette\Mail\SmtpException $e) {
         $this->presenter->flashMessage('E-mail nebyl odeslán' . $e->getMessage(), 'error');
         $this->presenter->redirect(":Front:Sign:up");
     }
 }