Exemplo n.º 1
0
 public function getListData()
 {
     $rep = $this->getResponse('json', true);
     try {
         $form = jForms::get($this->param('__form'), $this->param('__formid'));
         if (!$form) {
             throw new Exception('dummy');
         }
     } catch (Exception $e) {
         throw new Exception('invalid form selector');
     }
     if ($form->securityLevel == jFormsBase::SECURITY_CSRF) {
         if ($form->getContainer()->token !== $this->param('__JFORMS_TOKEN__')) {
             throw new jException("jelix~formserr.invalid.token");
         }
     }
     $control = $form->getControl($this->param('__ref'));
     if (!$control || !$control instanceof jFormsControlDatasource) {
         throw new Exception('bad control');
     }
     if (!$control->datasource instanceof jFormsDaoDatasource) {
         throw new Exception('not supported datasource type');
     }
     $dependentControls = $control->datasource->getDependentControls();
     if (!$dependentControls) {
         throw new Exception('no dependent controls');
     }
     foreach ($dependentControls as $ctname) {
         $form->setData($ctname, $this->param($ctname));
     }
     $rep->data = array('data' => $control->datasource->getData($form));
     return $rep;
 }
Exemplo n.º 2
0
 protected function _prepareTpl()
 {
     $config = new \Jelix\JCommunity\Config();
     $this->_tpl->assign('canRegister', $config->isRegistrationEnabled());
     $this->_tpl->assign('canResetPassword', $config->isResetPasswordEnabled());
     if (jAuth::isConnected()) {
         $this->_tpl->assign('login', jAuth::getUserSession()->login);
     } else {
         $conf = jAuth::loadConfig();
         $this->_tpl->assign('persistance_ok', jAuth::isPersistant());
         $form = jForms::get("jcommunity~login");
         if (!$form) {
             $form = jForms::create("jcommunity~login");
         }
         $this->_tpl->assign('form', $form);
         $this->_tpl->assign('url_return', '');
         if ($conf['enable_after_login_override']) {
             $req = jApp::coord()->request;
             if ($req->getParam('auth_url_return')) {
                 $this->_tpl->assign('url_return', $req->getParam('auth_url_return'));
             } else {
                 if ($this->param('as_main_content')) {
                     if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] && $_SERVER['HTTP_REFERER'] != jUrl::getCurrentUrl(false, true)) {
                         $this->_tpl->assign('url_return', $_SERVER['HTTP_REFERER']);
                     }
                 } else {
                     if ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') {
                         $this->_tpl->assign('url_return', jUrl::getCurrentUrl(false, true));
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 protected function _prepareTpl()
 {
     $form = jForms::get('password');
     if ($form == null) {
         $form = jForms::create('password');
     }
     $this->_tpl->assign('form', $form);
 }
Exemplo n.º 4
0
 protected function _prepareTpl()
 {
     $form = jForms::get('registration');
     if ($form == null) {
         $form = jForms::create('registration');
     }
     jForms::destroy('confirmation');
     jEvent::notify('jcommunity_registration_init_form', array('form' => $form, 'tpl' => $this->_tpl));
     $this->_tpl->assign('form', $form);
 }
Exemplo n.º 5
0
 /**
  *
  */
 function index()
 {
     $rep = $this->getResponse('html');
     $form = jForms::get('config');
     if (!$form) {
         $form = jForms::create('config');
         $activeusers = jClasses::create('activeusers~connectedusers');
         $form->setData('timeout_visit', $activeusers->getVisitTimeout());
     }
     $tpl = new jTpl();
     $tpl->assign('form', $form);
     $rep->body->assign('MAIN', $tpl->fetch('config'));
     return $rep;
 }
Exemplo n.º 6
0
 /**
  * form to enter the confirmation key
  * to activate the new password
  */
 function confirmform()
 {
     if (jAuth::isConnected()) {
         return $this->noaccess();
     }
     $rep = $this->getResponse('html');
     $form = jForms::get('confirmation');
     if ($form == null) {
         $form = jForms::create('confirmation');
     }
     $tpl = new jTpl();
     $tpl->assign('form', $form);
     $rep->body->assign('MAIN', $tpl->fetch('password_confirmation'));
     return $rep;
 }
Exemplo n.º 7
0
 function savecreate()
 {
     $form = jForms::get('files');
     $form->initFromRequest();
     $rep = $this->getResponse('redirect');
     $form->saveAllFiles("files/");
     $dao = jDao::get('files');
     $record = jDao::createRecord('files');
     $record->name = $form->getData('name');
     $record->url = "http://www.helenekling.com/" . $this->testDir . $this->uploadsDirectory . "/" . $form->getData('file');
     $dao->insert($record);
     $rep->action = 'files:index';
     jForms::destroy($this->form);
     return $rep;
 }
Exemplo n.º 8
0
 function ok()
 {
     $form = jForms::get('sample');
     $rep = $this->getResponse('html');
     $rep->title = 'Form editing';
     if ($form) {
         $tpl = new jTpl();
         $tpl->assign('form', $form);
         $rep->body->assign('MAIN', $tpl->fetch('sampleformresult'));
     } else {
         $rep->body->assign('MAIN', '<p>The form doesn\'t exist.</p>');
     }
     $rep->body->assign('page_title', 'formulaires');
     return $rep;
 }
Exemplo n.º 9
0
 /**
  * web service for XHR request when a control should be filled with a list
  * of values, depending of the value of an other control.
  */
 public function getListData()
 {
     $rep = $this->getResponse('json', true);
     try {
         $form = jForms::get($this->param('__form'), $this->param('__formid'));
         if (!$form) {
             throw new Exception('dummy');
         }
     } catch (Exception $e) {
         throw new Exception('invalid form selector');
     }
     // check CSRF
     if ($form->securityLevel == jFormsBase::SECURITY_CSRF) {
         if ($form->getContainer()->token !== $this->param('__JFORMS_TOKEN__')) {
             throw new jException("jelix~formserr.invalid.token");
         }
     }
     // retrieve the control to fill
     $control = $form->getControl($this->param('__ref'));
     if (!$control || !$control instanceof jFormsControlDatasource) {
         throw new Exception('bad control');
     }
     if (!$control->datasource instanceof jIFormsDynamicDatasource) {
         throw new Exception('not supported datasource type');
     }
     $dependentControls = $control->datasource->getCriteriaControls();
     if (!$dependentControls) {
         throw new Exception('no dependent controls');
     }
     foreach ($dependentControls as $ctname) {
         $form->setData($ctname, $this->param($ctname));
     }
     $rep->data = array();
     if ($control->datasource->hasGroupedData()) {
         foreach ($control->datasource->getData($form) as $k => $items) {
             $data = array();
             foreach ($items as $k2 => $v) {
                 $data[] = array('value' => $k2, 'label' => $v);
             }
             $rep->data[] = array('items' => $data, 'label' => $k);
         }
     } else {
         foreach ($control->datasource->getData($form) as $k => $v) {
             $rep->data[] = array('value' => $k, 'label' => $v);
         }
     }
     return $rep;
 }
Exemplo n.º 10
0
 function config()
 {
     $resp = $this->getResponse('html');
     $form = jForms::get('hfnuadmin~config');
     if (!$form) {
         $form = jForms::create('hfnuadmin~config');
         $this->initform($form);
     }
     $tpl = new jTpl();
     $tpl->assign('form', $form);
     $forumUrl = '<a href="' . jUrl::get('hfnuadmin~forum:index') . '" >' . jLocale::get('config.anonymous_post_authorized.rights.management.by.forum') . '</a>';
     $tpl->assign('forumUrl', $forumUrl);
     $resp->body->assign('MAIN', $tpl->fetch('config'));
     $resp->body->assign('selectedMenuItem', 'config');
     return $resp;
 }
Exemplo n.º 11
0
 function answer()
 {
     $resp = $this->precreate();
     $this->_markAsRead();
     if ($id = $this->param("id")) {
         // verify i'm the dest of the message i will answer
         $mail = jDao::get($this->dao)->get($id);
         if ($mail->id_for != jAuth::getUserSession()->id) {
             return $resp;
         }
         $form = jForms::get($this->form);
         if ($form == null) {
             $form = jForms::create($this->form);
         }
         $form->deactivate("id_for", true);
         $form->setData("answer_to", $mail->id_from);
         $resp->params['id'] = $id;
         $form->setData("title", "Re : " . jDao::get($this->dao)->get($id)->title);
     }
     return $resp;
 }
Exemplo n.º 12
0
 protected function _prepareTpl()
 {
     if (jAuth::isConnected()) {
         $this->_tpl->assign('login', jAuth::getUserSession()->login);
     } else {
         $conf = jApp::coord()->getPlugin('auth')->config;
         $this->_tpl->assign('persistance_ok', $conf['persistant_enable']);
         $form = jForms::get("jcommunity~login");
         if (!$form) {
             $form = jForms::create("jcommunity~login");
         }
         $this->_tpl->assign('form', $form);
         if ($conf['enable_after_login_override']) {
             $req = jApp::coord()->request;
             if ($req->getParam('auth_url_return')) {
                 $this->_tpl->assign('url_return', $req->getParam('auth_url_return'));
             } else {
                 if ($this->param('as_main_content')) {
                     if ($_SERVER['HTTP_REFERER']) {
                         $this->_tpl->assign('url_return', $_SERVER['HTTP_REFERER']);
                     } else {
                         $this->_tpl->assign('url_return', '');
                     }
                 } else {
                     //(empty($_SERVER['HTTPS'])?'http':'https').'://'.$_SERVER["HTTP_HOST"].
                     $url = $req->urlScript . $req->urlPathInfo;
                     if (!empty($_SERVER['QUERY_STRING'])) {
                         $url .= '?' . $_SERVER['QUERY_STRING'];
                     }
                     $this->_tpl->assign('url_return', $url);
                 }
             }
         } else {
             $this->_tpl->assign('url_return', '');
         }
     }
 }
Exemplo n.º 13
0
 /**
  * form to enter the confirmation key
  * to activate the account
  */
 function confirmform()
 {
     if (jAuth::isConnected()) {
         return $this->noaccess();
     }
     $rep = $this->getResponse('html');
     $form = jForms::get('confirmation');
     if ($form == null) {
         $form = jForms::create('confirmation');
         $login = $this->param('login');
         if ($login) {
             $form->setData('conf_login', $login);
         }
     }
     $tpl = new jTpl();
     $tpl->assign('form', $form);
     $rep->body->assign('MAIN', $tpl->fetch('registration_confirmation'));
     return $rep;
 }
 /**
  * Form validation : destroy it and display a message
  *
  * @param string $repository Lizmap Repository
  * @param string $project Name of the project
  * @param string $layerId Qgis id of the layer
  * @param integer $featureId Id of the feature.
  * @return Confirmation message that the form has been saved.
  */
 public function validateFeature()
 {
     // Get repository, project data and do some right checking
     if (!$this->getEditionParameters()) {
         return $this->serviceAnswer();
     }
     // Destroy the form
     if ($form = jForms::get('view~edition', $this->featureId)) {
         jForms::destroy('view~edition', $this->featureId);
     } else {
         // undefined form : redirect to error
         jMessage::add('An error has been raised when getting the form', 'error');
         return $this->serviceAnswer();
     }
     // Return html fragment response
     jMessage::add(jLocale::get('view~edition.form.data.saved'), 'success');
     return $this->serviceAnswer();
 }
Exemplo n.º 15
0
    function testFill()
    {
        global $gJCoord;
        $savedParams = $gJCoord->request->params;
        $form = jForms::fill('product');
        $this->assertComplexIdenticalStr($form, $this->form1Descriptor);
        $gJCoord->request->params['name'] = 'phone';
        $gJCoord->request->params['price'] = '45';
        $form = jForms::fill('product');
        $verif = '
<object class="cForm_jelix_tests_Jx_product">
    <object method="getContainer()" class="jFormsDataContainer">
        <integer property="formId" value="' . jForms::DEFAULT_ID . '" />
        <string property="formSelector" value="jelix_tests~product" />
        <array property="data">
            <string key="name" value="phone" />
            <string key="price" value="45" />
        </array>
        <array property="errors">array()</array>
    </object>
    <array method="getAllData()">
        <string key="name" value="phone" />
        <string key="price" value="45" />
    </array>
    <integer method="id()" value="' . jForms::DEFAULT_ID . '" />
    <array method="getControls()">
        <object key="name" class="jFormsControlInput">
            <string property="ref" value="name"/>
            <boolean property="required" value="true"/>
            <boolean method="isReadOnly()" value="false"/>
            <string property="label" value="product name"/>
            <string property="defaultValue" value=""/>
        </object>
        <object key="price" class="jFormsControlInput">
            <string property="ref" value="price"/>
            <boolean property="required" value="false"/>
            <boolean method="isReadOnly()" value="false"/>
            <string property="label" value="The price"/>
            <string property="defaultValue" value=""/>
        </object>
    </array>
</object>';
        $this->assertComplexIdenticalStr($form, $verif);
        // verify that the other form hasn't changed
        $form = jForms::get('product', 'akey');
        $this->assertComplexIdenticalStr($form, $this->form2Descriptor);
        $form = jForms::fill('product', 'akey');
        $verif = '
<object class="cForm_jelix_tests_Jx_product">
    <object method="getContainer()" class="jFormsDataContainer">
        <integer property="formId" value="akey" />
        <string property="formSelector" value="jelix_tests~product" />
        <array property="data">
            <string key="name" value="phone" />
            <string key="price" value="45" />
        </array>
        <array property="errors">array()</array>
    </object>
    <array method="getAllData()">
        <string key="name" value="phone" />
        <string key="price" value="45" />
    </array>
    <integer method="id()" value="akey" />
    <array method="getControls()">
        <object key="name" class="jFormsControlInput">
            <string property="ref" value="name"/>
            <boolean property="required" value="true"/>
            <boolean method="isReadOnly()" value="false"/>
            <string property="label" value="product name"/>
            <string property="defaultValue" value=""/>
        </object>
        <object key="price" class="jFormsControlInput">
            <string property="ref" value="price"/>
            <boolean property="required" value="false"/>
            <boolean method="isReadOnly()" value="false"/>
            <string property="label" value="The price"/>
            <string property="defaultValue" value=""/>
        </object>
    </array>
</object>';
        $gJCoord->request->params = $savedParams;
    }
Exemplo n.º 16
0
 function testValueNotPkMultiKeyTable()
 {
     $form = jForms::get('product');
     // ---- retrieve data with a value which is not part of the key
     // should not work
     //$ds = new jFormsDaoDatasource('jelix_tests~labels' , "findByAlias" , 'label', 'keyalias', '');
     //$ds->labelMethod = 'getByAlias';
     //$data = $ds->getData($form);
     //$this->assertError();
     // ---- retrieve data with a value which is not part of the key, + a criteria
     $ds = new jFormsDaoDatasource('jelix_tests~labels', "findByLang", 'label', 'keyalias', '', 'fr');
     $ds->labelMethod = 'getByAliasLang';
     $data = $ds->getData($form);
     $this->assertEqual($data, array('aa' => 'aa-fr', 'bb' => 'bb-fr', 'cc' => 'cc-fr'));
     $this->assertEqual($ds->getLabel2('aa', $form), 'aa-fr');
     $this->assertEqual($ds->getLabel2('dd', $form), null);
 }
Exemplo n.º 17
0
 /**
  * get an existing form. You can redefine this method to modify dynamically the form
  * Typically, you call jForms::get and then you can call addControl or whatever.
  * Don't do a jForms::create or jForms::fill in this method !
  * called in methods: create, savecreate, editupdate, saveupdate
  * @return jFormsBase the form
  * @since 1.1
  */
 protected function _getForm($formId = null)
 {
     return jForms::get($this->form, $formId);
 }
Exemplo n.º 18
0
 /**
  * save data of a form in a new record
  */
 function saveupdate()
 {
     $rep = $this->getResponse('redirect');
     $id = $this->param('id');
     $form = jForms::get($this->form, $id);
     $form->initFromRequest();
     if ($form === null || $id === null) {
         $rep->action = 'master_admin~default:index';
         return $rep;
     }
     $evresp = array();
     if ($form->check() && !jEvent::notify('jauthdbAdminCheckUpdateForm', array('form' => $form))->inResponse('check', false, $evresp)) {
         extract($form->prepareDaoFromControls($this->dao, $id, $this->dbProfile), EXTR_PREFIX_ALL, "form");
         // we call jAuth instead of using jDao, to allow jAuth to do
         // all process, events...
         jAuth::updateUser($form_daorec);
         $form->saveAllFiles($this->uploadsDirectory);
         $rep->action = 'user:index';
         jMessage::add(jLocale::get('crud.message.update.ok', $id), 'notice');
         jForms::destroy($this->form, $id);
     } else {
         $rep->action = 'user:editupdate';
     }
     $rep->params['id'] = $id;
     return $rep;
 }
Exemplo n.º 19
0
 function save()
 {
     $user = $this->param('user');
     $rep = $this->getResponse('redirect');
     $rep->action = 'jcommunity~account:show';
     $rep->params = array('user' => $user);
     if ($user == '' || !jAuth::isConnected() || jAuth::getUserSession()->login != $user) {
         return $rep;
     }
     $form = jForms::get('account', $user);
     if (!$form) {
         return $rep;
     }
     jEvent::notify('jcommunity_init_edit_form_account', array('login' => $user, 'form' => $form));
     $form->initFromRequest();
     $form->check();
     $accountFact = jDao::get($this->getDaoName());
     if ($accountFact->verifyNickname($user, $form->getData('nickname'))) {
         $form->setErrorOn('nickname', jLocale::get('account.error.dup.nickname'));
     }
     jEvent::notify('jcommunity_check_before_save_account', array('login' => $user, 'form' => $form));
     if (count($form->getErrors())) {
         $rep->action = 'jcommunity~account:edit';
     } else {
         extract($form->prepareDaoFromControls($this->getDaoName()), EXTR_PREFIX_ALL, "form");
         jEvent::notify('jcommunity_save_account', array('login' => $user, 'form' => $form, 'factory' => $form_dao, 'record' => $form_daorec, 'to_insert' => $form_toInsert));
         if ($form_toInsert) {
             $form_dao->insert($form_daorec);
         } else {
             $form_dao->update($form_daorec);
         }
         jForms::destroy('account', $user);
     }
     return $rep;
 }
Exemplo n.º 20
0
 /**
  * form to enter the confirmation key
  * to activate the new password
  */
 function confirmform()
 {
     $repError = $this->_check();
     if ($repError) {
         return $repError;
     }
     $rep = $this->_getjCommunityResponse();
     $form = jForms::get('confirmation');
     if ($form == null) {
         $form = jForms::create('confirmation');
     }
     $tpl = new jTpl();
     $tpl->assign('form', $form);
     $rep->body->assign('MAIN', $tpl->fetch('password_confirmation'));
     return $rep;
 }
Exemplo n.º 21
0
 function view()
 {
     $form = jForms::get('sample2', $this->param('id'));
     $rep = $this->getResponse('html');
     $rep->title = 'Content of a form';
     $rep->body->assign('page_title', 'forms');
     if ($form) {
         $tpl = new jTpl();
         $tpl->assign('nom', $form->getData('nom'));
         $tpl->assign('prenom', $form->getData('prenom'));
         $tpl->assign('id', $this->param('id'));
         $rep->body->assign('MAIN', $tpl->fetch('forms_view'));
     } else {
         $rep->body->assign('MAIN', '<p>The form doesn\'t exist.</p>');
     }
     return $rep;
 }
Exemplo n.º 22
0
 /**
  * Save the data for one section.
  * @return Redirect to the index.
  */
 function validateSection()
 {
     $repository = $this->param('repository');
     $new = $this->intParam('new');
     // Destroy the form
     if ($form = jForms::get('admin~config_section')) {
         jForms::destroy('admin~config_section');
     } else {
         // undefined form : redirect
         $rep = $this->getResponse("redirect");
         $rep->action = "admin~config:index";
         return $rep;
     }
     // Redirect to the index
     $rep = $this->getResponse("redirect");
     if ($new) {
         jMessage::add(jLocale::get("admin~admin.form.admin_section.message.configure.rights"));
         $rep->action = "admin~config:modifySection";
         $rep->params['repository'] = $repository;
     } else {
         $rep->action = "admin~config:index";
     }
     return $rep;
 }
Exemplo n.º 23
0
 /**
  * Confirm form submission and destroy form.
  * @return Redirect to the index.
  */
 function validateAccount()
 {
     // Destroy the form
     if ($form = jForms::get('view~lizmap_user')) {
         jForms::destroy('view~lizmap_user');
     }
     // Redirect to the index
     $rep = $this->getResponse("redirect");
     $rep->action = "view~default:index";
     return $rep;
 }
Exemplo n.º 24
0
 /**
  * displays a forms to edit an existing record. The form should be
  * prepared with the preupdate before, so a refresh of the page
  * won't cause a reset of the form
  */
 function editupdate()
 {
     $spk = $this->param($this->spkName);
     $dpk = $this->param($this->dpkName);
     $page = $this->param($this->offsetParameterName);
     $id = $this->_getPk($spk, $dpk);
     $form = jForms::get($this->form, $id);
     if ($form === null || $dpk === null) {
         $rep = $this->getResponse('redirect');
         $rep->params[$this->spkName] = $spk;
         $rep->action = $this->_getAction('index');
         return $rep;
     }
     $rep = $this->_getResponse();
     $tpl = new jTpl();
     $tpl->assign('dpk', $dpk);
     $tpl->assign('dpkName', $this->dpkName);
     $tpl->assign('spkName', $this->spkName);
     $tpl->assign('spk', $spk);
     $tpl->assign('form', $form);
     $tpl->assign('page', $page);
     $tpl->assign('offsetParameterName', $this->offsetParameterName);
     $tpl->assign('submitAction', $this->_getAction('saveupdate'));
     $tpl->assign('listAction', $this->_getAction('index'));
     $tpl->assign('viewAction', $this->_getAction('view'));
     $this->_editUpdate($form, $rep, $tpl);
     $rep->body->assign($this->templateAssign, $tpl->fetch($this->editTemplate));
     return $rep;
 }
 /**
  * form to enter the confirmation key
  * to activate the account
  */
 function confirmform()
 {
     $repError = $this->_check();
     if ($repError) {
         return $repError;
     }
     $rep = $this->_getjCommunityResponse();
     $form = jForms::get('confirmation');
     if ($form == null) {
         $form = jForms::create('confirmation');
         $login = $this->param('login');
         if ($login) {
             $form->setData('conf_login', $login);
         }
     }
     $tpl = new jTpl();
     $tpl->assign('form', $form);
     $rep->body->assign('MAIN', $tpl->fetch('registration_confirmation'));
     return $rep;
 }