Ejemplo n.º 1
0
 /**
  * Build for for editing component parameters.
  * The form creation is based on XML widget's data received per POST request.
  *
  * @throws SystemException 'ERR_INSUFFICIENT_DATA'
  * @throws SystemException 'ERR_BAD_XML_DESCR'
  */
 protected function buildParamsForm()
 {
     if (!isset($_POST['modalBoxData'])) {
         throw new SystemException('ERR_INSUFFICIENT_DATA');
     }
     if (!($widgetXML = simplexml_load_string($_POST['modalBoxData']))) {
         throw new SystemException('ERR_BAD_XML_DESCR');
     }
     list($componentName) = $this->getStateParams();
     $component = ComponentManager::findBlockByName($widgetXML, $componentName);
     $dd = new DataDescription();
     $d = new Data();
     $this->setType(self::COMPONENT_TYPE_FORM_ALTER);
     $this->setDataDescription($dd);
     $this->setData($d);
     $this->setBuilder(new Builder());
     $this->js = $this->buildJS();
     foreach ($component->params->children() as $param) {
         $paramName = (string) $param['name'];
         $paramType = isset($param['type']) ? (string) $param['type'] : FieldDescription::FIELD_TYPE_STRING;
         $fd = new FieldDescription($paramName);
         if (isset($param['nullable'])) {
             $fd->setProperty('nullable', true);
         }
         $fd->setType($paramType)->setProperty('tabName', E()->Utils->translate('TAB_PARAMS'));
         if ($paramType == FieldDescription::FIELD_TYPE_SELECT && isset($param['values'])) {
             $availableValues = array();
             foreach (explode('|', (string) $param['values']) as $value) {
                 array_push($availableValues, array('key' => $value, 'value' => $value));
             }
             $fd->loadAvailableValues($availableValues, 'key', 'value');
         }
         $dd->addFieldDescription($fd);
         $f = new Field($paramName);
         $f->setRowData(0, $param);
         $d->addField($f);
     }
     $this->addToolbar($this->loadToolbar());
 }
Ejemplo n.º 2
0
 /**
  * Build tab with division rights.
  *
  * @return DOMNode
  */
 private function buildDivRightsData()
 {
     $builder = new TreeBuilder();
     $builder->setTree(TreeConverter::convert($this->dbh->select('share_sitemap', ['smap_id', 'smap_pid'], null, ['smap_order_num' => QAL::ASC]), 'smap_id', 'smap_pid'));
     $id = $this->getFilter();
     $id = !empty($id) ? current($id) : '';
     $data = convertDBResult($this->dbh->select('select s.smap_id as Id, smap_pid as Pid, site_id as Site, smap_name as Name ' . 'from share_sitemap s ' . 'left join share_sitemap_translation st on st.smap_id = s.smap_id ' . 'where lang_id=%s', E()->getLanguage()->getCurrent()), 'Id');
     foreach ($data as $smapID => $smapInfo) {
         $data[$smapID]['RightsId'] = E()->getMap($smapInfo['Site'])->getDocumentRights($smapID, $id);
         $data[$smapID]['Site'] = E()->getSiteManager()->getSiteByID($smapInfo['Site'])->name;
     }
     $dataObject = new Data();
     $dataObject->load($data);
     $builder->setData($dataObject);
     $dataDescriptionObject = new DataDescription();
     $f = new FieldDescription('Id');
     $f->setType(FieldDescription::FIELD_TYPE_INT);
     $f->setProperty('key', true);
     $dataDescriptionObject->addFieldDescription($f);
     $f = new FieldDescription('Pid');
     $f->setType(FieldDescription::FIELD_TYPE_INT);
     $dataDescriptionObject->addFieldDescription($f);
     $f = new FieldDescription('Name');
     $f->setType(FieldDescription::FIELD_TYPE_STRING);
     $dataDescriptionObject->addFieldDescription($f);
     $f = new FieldDescription('Site');
     $f->setType(FieldDescription::FIELD_TYPE_STRING);
     $dataDescriptionObject->addFieldDescription($f);
     $f = new FieldDescription('RightsId');
     $f->setType(FieldDescription::FIELD_TYPE_SELECT);
     if ($this->getState() == 'view') {
         $f->setMode(FieldDescription::FIELD_MODE_READ);
     }
     $rights = $this->dbh->select('user_group_rights', ['right_id', 'right_const']);
     $rights = array_merge([['right_id' => 0, 'right_const' => 'NO_RIGHTS']], $rights);
     foreach ($rights as $key => $value) {
         $rights[$key]['right_const'] = $this->translate('TXT_' . $value['right_const']);
     }
     $f->loadAvailableValues($rights, 'right_id', 'right_const');
     $dataDescriptionObject->addFieldDescription($f);
     $builder->setData($dataObject);
     $builder->setDataDescription($dataDescriptionObject);
     $builder->build();
     return $builder->getResult();
 }
Ejemplo n.º 3
0
 protected function prepare()
 {
     parent::prepare();
     if (in_array($this->getState(), array('add', 'edit'))) {
         $fd = new FieldDescription('domains');
         $fd->setType(FieldDescription::FIELD_TYPE_TAB);
         $fd->setProperty('title', $this->translate('TAB_DOMAINS'));
         $this->getDataDescription()->addFieldDescription($fd);
         $field = new Field('domains');
         $state = $this->getState();
         $tab_url = ($state != 'add' ? $this->getData()->getFieldByName($this->getPK())->getRowData(0) : '') . '/domains/';
         $field->setData($tab_url, true);
         $this->getData()->addField($field);
         $fd = $this->getDataDescription()->getFieldDescriptionByName('site_folder');
         $fd->setType(FieldDescription::FIELD_TYPE_SELECT);
         $fd->loadAvailableValues($this->loadFoldersData(), 'key', 'value');
         if ($this->getData()->getFieldByName('site_is_default')->getRowData(0) == 1) {
             $this->getDataDescription()->getFieldDescriptionByName('site_is_default')->setMode(FieldDescription::FIELD_MODE_READ);
         }
         $tagField = new FieldDescription('tags');
         $tagField->setType(FieldDescription::FIELD_TYPE_STRING);
         $tagField->removeProperty('pattern');
         $this->getDataDescription()->addFieldDescription($tagField);
         if ($this->getState() == 'add') {
             //Добавляем селект позволяющий скопировать структуру одного из существующих сайтов в новый
             $fd = new FieldDescription('copy_site_structure');
             $fd->setType(FieldDescription::FIELD_TYPE_SELECT);
             $fd->loadAvailableValues($this->dbh->select('SELECT ss.site_id, site_name FROM share_sites ss LEFT JOIN share_sites_translation sst ON ss.site_id = sst.site_id WHERE lang_id =%s ', $this->document->getLang()), 'site_id', 'site_name');
             $this->getDataDescription()->addFieldDescription($fd);
         } else {
             $this->getDataDescription()->getFieldDescriptionByName($this->getPK())->setType(FieldDescription::FIELD_TYPE_INT)->setMode(FieldDescription::FIELD_MODE_READ);
             $tm = new TagManager($this->getDataDescription(), $this->getData(), $this->getTableName());
             $tm->createFieldDescription();
             $tm->createField();
         }
     }
 }
Ejemplo n.º 4
0
 protected function createDataDescription()
 {
     $result = parent::createDataDescription();
     if (in_array($this->getState(), array('add', 'edit'))) {
         foreach ($result as $fieldDescription) {
             $fieldDescription->setProperty('tabName', E()->Utils->translate('TXT_USER_EDITOR'));
         }
         $result->getFieldDescriptionByName('u_name')->setType(FieldDescription::FIELD_TYPE_EMAIL);
         if ($fd = $result->getFieldDescriptionByName('u_is_active')) {
             $result->removeFieldDescription($fd);
         }
         $fd = new FieldDescription('group_id');
         $fd->setSystemType(FieldDescription::FIELD_TYPE_INT);
         $fd->setType(FieldDescription::FIELD_TYPE_MULTI);
         $fd->setProperty('tabName', E()->Utils->translate('TXT_USER_GROUPS'));
         $fd->setProperty('customField', true);
         $data = $this->dbh->select('user_groups', array('group_id', 'group_name'), 'group_id IN(select group_id from user_groups where group_default=0)');
         $fd->loadAvailableValues($data, 'group_id', 'group_name');
         $result->addFieldDescription($fd);
     }
     if ($this->getType() == self::COMPONENT_TYPE_FORM_ALTER && ($f = $result->getFieldDescriptionByName('u_password'))) {
         $f->removeProperty('pattern');
         $f->removeProperty('message');
         $f->setProperty('nullable', true);
     }
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * Build tab of rights.
  *
  * @param int $id Division ID.
  *
  * @note By creation of new division use parent ID.
  */
 private function buildRightsTab($id)
 {
     $builder = new Builder($this->getTitle());
     //получаем информацию о всех группах имеющихся в системе
     $groups = $this->dbh->select('user_groups', ['group_id', 'group_name']);
     $groups = convertDBResult($groups, 'group_id');
     //создаем матриц
     //название группы/перечень прав
     foreach (array_keys($groups) as $groupID) {
         $res[] = ['right_id' => 0, 'group_id' => $groupID];
     }
     $resultData = new Data();
     $resultData->load($res);
     $builder->setData($resultData);
     $rightsField = $resultData->getFieldByName('right_id');
     $groupsField = $resultData->getFieldByName('group_id');
     //создаем переменную содержащую идентификторы групп в которые входит пользователь
     $data = $this->dbh->select('share_access_level', ['group_id', 'right_id'], ['smap_id' => $id]);
     if ($data) {
         $data = convertDBResult($data, 'group_id', true);
         for ($i = 0; $i < $resultData->getRowCount(); $i++) {
             //если установлены права для группы  - изменяем в объекте данных
             if (isset($data[$groupsField->getRowData($i)])) {
                 $rightsField->setRowData($i, $data[$groupsField->getRowData($i)]['right_id']);
             }
             $groupsField->setRowProperty($i, 'group_id', $groupsField->getRowData($i));
         }
     }
     for ($i = 0; $i < $resultData->getRowCount(); $i++) {
         $groupsField->setRowProperty($i, 'group_id', $groupsField->getRowData($i));
         $groupsField->setRowData($i, $groups[$groupsField->getRowData($i)]['group_name']);
     }
     $resultDD = new DataDescription();
     $fd = new FieldDescription('group_id');
     $fd->setSystemType(FieldDescription::FIELD_TYPE_STRING);
     $fd->setMode(FieldDescription::FIELD_MODE_READ);
     $fd->setLength(30);
     $resultDD->addFieldDescription($fd);
     $fd = new FieldDescription('right_id');
     $fd->setSystemType(FieldDescription::FIELD_TYPE_SELECT);
     $data = $this->dbh->select('user_group_rights', ['right_id', 'right_const as right_name']);
     $data = array_map(function ($a) {
         $a["right_name"] = translate("TXT_" . $a["right_name"]);
         return $a;
     }, $data);
     $data[] = ['right_id' => 0, 'right_name' => $this->translate('TXT_NO_RIGHTS')];
     $fd->loadAvailableValues($data, 'right_id', 'right_name');
     $resultDD->addFieldDescription($fd);
     $builder->setDataDescription($resultDD);
     $builder->build();
     $field = new Field('page_rights');
     for ($i = 0; $i < count(E()->getLanguage()->getLanguages()); $i++) {
         $field->addRowData($builder->getResult());
     }
     $this->getData()->addField($field);
 }