/**
  * Display the form to create/modify a Section.
  * @param string $repository (optional) Name of the repository.
  * @return Display the form.
  */
 public function editSection()
 {
     $rep = $this->getResponse('html');
     $repository = $this->param('repository');
     $new = (bool) $this->param('new');
     // Get repository data
     $lrep = lizmap::getRepository($repository);
     // what to do if it's a new one!
     // Get the form
     $form = jForms::get('admin~config_section');
     if ($form) {
         // reconstruct form fields based on repositoryPropertyList
         $propertiesOptions = lizmap::getRepositoryPropertiesOptions();
         foreach (lizmap::getRepositoryProperties() as $k) {
             if ($propertiesOptions[$k]['fieldType'] == 'checkbox') {
                 $ctrl = new jFormsControlCheckbox($k);
             } else {
                 $ctrl = new jFormsControlInput($k);
             }
             $ctrl->required = $propertiesOptions[$k]['required'];
             $ctrl->label = jLocale::get("admin~admin.form.admin_section.repository." . $k . ".label");
             $ctrl->size = 100;
             $datatype = new jDatatypeString();
             $ctrl->datatype = $datatype;
             $form->addControl($ctrl);
             // if edition, set the form data with the data taken from the ini file
             if ($repository and $new) {
                 $form->setData($k, $lrep->getData($k));
             }
         }
         // Create and fill the form control relative to rights for each group for this repository
         if ($this->intParam('errors') && $lrep) {
             $form = $this->populateRepositoryRightsFormControl($form, $lrep->getKey(), 'request');
         } else {
             if ($lrep) {
                 $form = $this->populateRepositoryRightsFormControl($form, $lrep->getKey(), false);
             }
         }
         // Display form
         $tpl = new jTpl();
         $tpl->assign('form', $form);
         $rep->body->assign('MAIN', $tpl->fetch('config_section'));
         $rep->body->assign('selectedMenuItem', 'lizmap_configuration');
         return $rep;
     } else {
         // Redirect to default page
         jMessage::add('error in editSection');
         $rep = $this->getResponse('redirect');
         $rep->action = 'admin~config:index';
         return $rep;
     }
 }
Пример #2
0
 /**
  * Get the jForm for a repository.
  *
  */
 public static function constructRepositoryForm($rep, $form)
 {
     $services = lizmap::getServices();
     $rootRepositories = $services->getRootRepositories();
     $repositories = array();
     foreach (lizmap::getRepositoryList() as $repo) {
         if ($rep && $rep->getKey() == $repo) {
             continue;
         }
         $repositories[] = lizmap::getRepository($repo);
     }
     // reconstruct form fields based on repositoryPropertyList
     $propertiesOptions = lizmap::getRepositoryPropertiesOptions();
     foreach (lizmap::getRepositoryProperties() as $k) {
         $ctrl = null;
         if ($propertiesOptions[$k]['fieldType'] == 'checkbox') {
             $ctrl = new jFormsControlCheckbox($k);
         } else {
             if ($k == 'path' && $rootRepositories != '') {
                 if ($rep == null || substr($rep->getPath(), 0, strlen($rootRepositories)) === $rootRepositories) {
                     $ctrl = new jFormsControlMenulist($k);
                     $dataSource = new jFormsStaticDatasource();
                     $data = array();
                     $data[''] = '';
                     if ($dh = opendir($rootRepositories)) {
                         while (($file = readdir($dh)) !== false) {
                             if ($file == '.' || $file == '..') {
                                 continue;
                             }
                             $filePath = $rootRepositories . $file . '/';
                             if (is_dir($filePath)) {
                                 $allreadyUsed = False;
                                 foreach ($repositories as $repo) {
                                     if ($repo->getPath() == $filePath) {
                                         $allreadyUsed = True;
                                         break;
                                     }
                                 }
                                 if (!$allreadyUsed) {
                                     $data[$filePath] = $file;
                                 }
                             }
                         }
                     }
                     $dataSource->data = $data;
                     $ctrl->datasource = $dataSource;
                 } else {
                     $ctrl = new jFormsControlHidden($k);
                 }
             } else {
                 $ctrl = new jFormsControlInput($k);
                 $ctrl->datatype = new jDatatypeString();
             }
         }
         $ctrl->required = $propertiesOptions[$k]['required'];
         $ctrl->label = jLocale::get("admin~admin.form.admin_section.repository." . $k . ".label");
         $ctrl->size = 100;
         $form->addControl($ctrl);
     }
     if ($rep) {
         foreach ($rep->getProperties() as $k) {
             $v = $rep->getData($k);
             if ($k == 'path' && $rootRepositories != '' && substr($rep->getPath(), 0, strlen($rootRepositories)) === $rootRepositories) {
                 $v = $rep->getPath();
             }
             $form->setData($k, $v);
         }
     }
     return $form;
 }