Esempio n. 1
0
 /**
  * Delete page
  * @param \Difra\Param\AnyInt $id
  * @param \Difra\Param\AjaxCheckbox $confirm
  */
 public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null)
 {
     if ($confirm and $confirm->val()) {
         \Difra\Plugins\CMS\Page::get($id->val())->delete();
         Ajaxer::close();
         Ajaxer::redirect('/adm/content/pages');
         return;
     }
     $page = \Difra\Plugins\CMS\Page::get($id->val());
     Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/delete-page-confirm-1') . $page->getTitle() . \Difra\Locales::get('cms/adm/delete-page-confirm-2') . '</span>' . '<form action="/adm/content/pages/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>');
 }
Esempio n. 2
0
 /**
  * @backupGlobals enabled
  */
 public function test_actions()
 {
     \Difra\Debugger::disable();
     \Difra\Ajaxer::clean();
     $actions = [];
     \Difra\Ajaxer::notify('notification message');
     $actions[] = ['action' => 'notify', 'message' => 'notification message', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]];
     \Difra\Ajaxer::display('<span>test</span>');
     $actions[] = ['action' => 'display', 'html' => '<span>test</span>'];
     \Difra\Ajaxer::error('error message <span>test</span>');
     $actions[] = ['action' => 'error', 'message' => 'error message &lt;span&gt;test&lt;/span&gt;', 'lang' => ['close' => \Difra\Locales::get('notifications/close')]];
     \Difra\Ajaxer::required('element');
     $actions[] = ['action' => 'require', 'name' => 'element'];
     \Difra\Ajaxer::invalid('inv1');
     $actions[] = ['action' => 'invalid', 'name' => 'inv1'];
     \Difra\Ajaxer::invalid('inv2');
     $actions[] = ['action' => 'invalid', 'name' => 'inv2'];
     \Difra\Ajaxer::status('field1', 'bad value', 'problem');
     $actions[] = ['action' => 'status', 'name' => 'field1', 'message' => 'bad value', 'classname' => 'problem'];
     \Difra\Ajaxer::redirect('/some/page');
     $actions[] = ['action' => 'redirect', 'url' => '/some/page'];
     $_SERVER['HTTP_REFERER'] = '/current/page';
     \Difra\Ajaxer::refresh();
     $actions[] = ['action' => 'redirect', 'url' => '/current/page'];
     \Difra\Ajaxer::reload();
     $actions[] = ['action' => 'reload'];
     \Difra\Ajaxer::load('someid', 'some <b>content</b>');
     $actions[] = ['action' => 'load', 'target' => 'someid', 'html' => 'some <b>content</b>'];
     \Difra\Ajaxer::close();
     $actions[] = ['action' => 'close'];
     \Difra\Ajaxer::reset();
     $actions[] = ['action' => 'reset'];
     \Difra\Envi::setUri('/current/page');
     \Difra\Ajaxer::confirm('Are you sure?');
     $actions[] = ['action' => 'display', 'html' => '<form action="/current/page" class="ajaxer"><input type="hidden" name="confirm" value="1"/>' . '<div>Are you sure?</div>' . '<input type="submit" value="' . \Difra\Locales::get('ajaxer/confirm-yes') . '"/>' . '<input type="button" value="' . \Difra\Locales::get('ajaxer/confirm-no') . '" onclick="ajaxer.close(this)"/>' . '</form>'];
     $this->assertEquals(\Difra\Ajaxer::getResponse(), json_encode(['actions' => $actions], \Difra\Ajaxer::getJsonFlags()));
     \Difra\Ajaxer::clean();
     $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]');
     $this->assertFalse(\Difra\Ajaxer::hasProblem());
     \Difra\Ajaxer::reload();
     \Difra\Ajaxer::clean(true);
     $this->assertEquals(\Difra\Ajaxer::getResponse(), '[]');
     $this->assertTrue(\Difra\Ajaxer::hasProblem());
 }
Esempio n. 3
0
 /**
  * Registration form submit (registration page version)
  * @param AjaxCheckbox $accept
  * @param AjaxCheckbox $redirect
  * @param AjaxString|null $email
  * @param AjaxString|null $password1
  * @param AjaxString|null $password2
  * @param AjaxString|null $login
  * @param AjaxString|null $capcha
  * @throws Exception
  */
 public function submitAjaxAction(AjaxCheckbox $accept, AjaxCheckbox $redirect, AjaxString $email = null, AjaxString $password1 = null, AjaxString $password2 = null, AjaxString $login = null, AjaxString $capcha = null)
 {
     $register = new Users\Register();
     $register->setEmail($email);
     $register->setLogin($login);
     $register->setPassword1($password1);
     $register->setPassword2($password2);
     $register->setCaptcha($capcha);
     if (!$register->validate()) {
         $register->callAjaxerEvents();
         return;
     }
     // EULA
     if (!$accept->val() and \Difra\Config::getInstance()->getValue('auth', 'eula')) {
         $this->root->appendChild($this->xml->createElement('eula'));
         Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
         return;
     }
     $register->register();
     $this->afterSuccess();
 }
Esempio n. 4
0
 /**
  * Recover password (ajax)
  * @param AjaxString $login Login or e-mail
  * @param AjaxString $captcha
  * @throws Exception
  */
 public function indexAjaxAction(AjaxString $login, AjaxString $captcha)
 {
     // show recover form
     if (is_null($login)) {
         $this->root->appendChild($this->xml->createElement('recover'));
         Ajaxer::display(View::render($this->xml, 'auth-ajax', true));
         return;
     }
     $error = false;
     // login's empty
     if ($login->val() === '') {
         Ajaxer::required('login');
         $error = true;
     }
     if (!$captcha or $captcha->val() == '') {
         Ajaxer::required('captcha');
         $error = true;
     }
     /** @var \Difra\Plugins\Capcha $captchaClass */
     $captchaClass = \Difra\Plugger::getClass('captcha');
     if (!$captchaClass::getInstance()->verifyKey($captcha->val())) {
         Ajaxer::invalid('captcha');
         $error = true;
     }
     if ($error) {
         return;
     }
     // recover
     try {
         Recover::send($login->val());
         Ajaxer::close();
         Ajaxer::notify(Locales::get('auth/login/recovered'));
     } catch (Exception $ex) {
         Ajaxer::status('email', Locales::get('auth/login/' . $ex->getMessage()), 'problem');
     }
 }
Esempio n. 5
0
 /**
  * Delete menu element
  * @param Difra\Param\AnyInt $id
  * @param Difra\Param\AjaxCheckbox $confirm
  */
 public function deleteAjaxAction(\Difra\Param\AnyInt $id, \Difra\Param\AjaxCheckbox $confirm = null)
 {
     if (!$confirm or !$confirm->val()) {
         \Difra\Ajaxer::display('<span>' . \Difra\Locales::get('cms/adm/menuitem/delete-item-confirm') . '</span>' . '<form action="/adm/content/menu/delete/' . $id . '" method="post" class="ajaxer">' . '<input type="hidden" name="confirm" value="1"/>' . '<input type="submit" value="Да"/>' . '<a href="#" onclick="ajaxer.close(this)" class="button">Нет</a>' . '</form>');
     } else {
         \Difra\Plugins\CMS\MenuItem::get($id->val())->delete();
         \Difra\Ajaxer::refresh();
         \Difra\Ajaxer::close();
     }
 }