Esempio n. 1
0
 public function testRestore()
 {
     $keyGet = 'context_test_restore_1';
     $keyPost = 'context_test_restore_2';
     $_GET[$keyGet] = 'foo';
     $_POST[$keyPost] = 'bar';
     $context = rex_context::restore();
     $this->assertEquals($_GET[$keyGet], $context->getParam($keyGet));
     $this->assertEquals($_POST[$keyPost], $context->getParam($keyPost));
 }
Esempio n. 2
0
 public static function formatLi(rex_structure_element $OOobject, $current_category_id, rex_context $context, $liAttr = '', $linkAttr = '')
 {
     $linkAttr .= ' class="' . ($OOobject->isOnline() ? 'rex-online' : 'rex-offline') . '"';
     if (strpos($linkAttr, ' href=') === false) {
         $linkAttr .= ' href="' . $context->getUrl(['category_id' => $OOobject->getId()]) . '"';
     }
     $label = self::formatLabel($OOobject);
     $icon = '<i class="rex-icon rex-icon-' . ($OOobject->isStartArticle() ? 'startarticle' : 'article') . '"></i>';
     return '<li' . $liAttr . '><a' . $linkAttr . '>' . $icon . ' ' . htmlspecialchars($label) . '</a>';
 }
Esempio n. 3
0
 public function execute()
 {
     // check if a new category was folded
     $category_id = rex_request('toggle_category_id', 'int', -1);
     $category_id = rex_category::get($category_id) ? $category_id : -1;
     /**
      * @var rex_user
      */
     $user = rex::getUser();
     if (!$user->getComplexPerm('structure')->hasCategoryPerm($category_id)) {
         throw new rex_api_exception('user has no permission for this category!');
     }
     $context = rex_context::fromGet();
     $categoryTree = new rex_sitemap_category_tree($context);
     $tree = $categoryTree->getTree($category_id);
     $result = new rex_api_result(true);
     return $result;
 }
Esempio n. 4
0
 function getFieldPage()
 {
     // ********************************************* FIELD ADD/EDIT/LIST
     $func = rex_request('func', 'string', 'list');
     $type_id = rex_request('type_id', 'string');
     $type_name = rex_request('type_name', 'string');
     $field_id = rex_request('field_id', 'int');
     $link_vars = '';
     foreach ($this->getLinkVars() as $k => $v) {
         $link_vars .= '&' . urlencode($k) . '=' . urlencode($v);
     }
     $TYPE = array('value' => rex_i18n::msg('yform_values'), 'validate' => rex_i18n::msg('yform_validates'), 'action' => rex_i18n::msg('yform_action'));
     // ********************************** TABELLE HOLEN
     $table = $this->table;
     $table_info = '<b>' . rex_i18n::translate($table->getName()) . ' [' . $table->getTableName() . ']</b> ';
     echo rex_view::info($table_info);
     // ********************************************* Missing Fields
     $mfields = $table->getMissingFields();
     // ksort($mfields);
     $type_real_field = rex_request('type_real_field', 'string');
     if ($type_real_field != '' && !array_key_exists($type_real_field, $mfields)) {
         $type_real_field = '';
     }
     if ($type_real_field != '') {
         $panel = '';
         $panel .= '<dl class="dl-horizontal text-left">';
         $rfields = $this->table->getColumns();
         foreach ($rfields[$type_real_field] as $k => $v) {
             $panel .= '<dt>' . ucfirst($k) . ':</dt><dd>' . $v . '</dd>';
         }
         $panel .= '</dl>';
         $fragment = new rex_fragment();
         $fragment->setVar('class', 'info');
         $fragment->setVar('title', 'Folgendes Feld wird verwendet: ' . $type_real_field);
         $fragment->setVar('body', $panel, false);
         echo $fragment->parse('core/page/section.php');
     }
     // ********************************************* CHOOSE FIELD
     $types = rex_yform::getTypeArray();
     if ($func == 'choosenadd') {
         $link = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=add&';
         $content = [];
         $panels = [];
         if (!$table->hasId()) {
             $content[] = rex_i18n::msg('yform_id_is_missing') . '' . rex_i18n::msg('yform_id_missing_info');
         } else {
             if ($type_real_field == '' && count($mfields) > 0) {
                 $tmp = '';
                 $d = 0;
                 foreach ($mfields as $k => $v) {
                     $d++;
                     $l = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=choosenadd&type_real_field=' . $k . '&type_layout=t';
                     $tmp .= '<a class="btn btn-default" href="' . $l . '">' . $k . '</a> ';
                 }
                 $fragment = new rex_fragment();
                 $fragment->setVar('class', 'info');
                 $fragment->setVar('title', 'Es gibt noch Felder in der Tabelle welche nicht zugewiesen sind.');
                 $fragment->setVar('body', $tmp, false);
                 echo $fragment->parse('core/page/section.php');
             }
             $tmp = '';
             if (isset($types['value'])) {
                 ksort($types['value']);
                 $tmp .= '<table class="table table-hover">';
                 foreach ($types['value'] as $k => $v) {
                     $tmp .= '<tr><th><a class="btn btn-default btn-block" href="' . $link . 'type_id=value&type_name=' . $k . '&type_real_field=' . $type_real_field . '"><code>' . $k . '</code></a></th><td class="vertical-middle">' . $v['description'] . '</td></tr>';
                 }
                 $tmp .= '</table>';
             }
             $fragment = new rex_fragment();
             $fragment->setVar('title', $TYPE['value']);
             $fragment->setVar('content', $tmp, false);
             $panels[] = $fragment->parse('core/page/section.php');
             $tmp = '';
             if (isset($types['validate'])) {
                 ksort($types['validate']);
                 $tmp .= '<table class="table table-hover">';
                 foreach ($types['validate'] as $k => $v) {
                     $tmp .= '<tr><th><a class="btn btn-default btn-block" href="' . $link . 'type_id=validate&type_name=' . $k . '"><code>' . $k . '</code></a></th><td class="vertical-middle">' . $v['description'] . '</td></tr>';
                 }
                 $tmp .= '</table>';
             }
             $fragment = new rex_fragment();
             $fragment->setVar('title', $TYPE['validate']);
             $fragment->setVar('content', $tmp, false);
             $panels[] = $fragment->parse('core/page/section.php');
         }
         $fragment = new rex_fragment();
         $fragment->setVar('title', rex_i18n::msg('yform_choosenadd'));
         $fragment->setVar('body', rex_i18n::msg('yform_choosenadd_description'), false);
         echo $fragment->parse('core/page/section.php');
         $fragment = new rex_fragment();
         $fragment->setVar('content', $panels, false);
         echo $fragment->parse('core/page/grid.php');
         $table_echo = '<a class="btn btn-default" href="index.php?' . $link_vars . '&amp;table_name=' . $table->getTableName() . '">' . rex_i18n::msg('yform_back_to_overview') . '</a>';
         $fragment = new rex_fragment();
         $fragment->setVar('footer', $table_echo, false);
         echo $fragment->parse('core/page/section.php');
     }
     // ********************************************* FORMULAR
     if (($func == 'add' || $func == 'edit') && isset($types[$type_id][$type_name])) {
         $yform = new rex_yform();
         $yform->setDebug(false);
         foreach ($this->getLinkVars() as $k => $v) {
             $yform->setHiddenField($k, $v);
         }
         $yform->setHiddenField('func', $func);
         $yform->setHiddenField('table_name', $table->getTableName());
         $yform->setHiddenField('type_real_field', $type_real_field);
         $yform->setHiddenField('list', rex_request('list', 'string'));
         $yform->setHiddenField('sort', rex_request('sort', 'string'));
         $yform->setHiddenField('sorttype', rex_request('sorttype', 'string'));
         $yform->setHiddenField('start', rex_request('start', 'string'));
         $yform->setValueField('hidden', array('table_name', $table->getTableName()));
         $yform->setValueField('hidden', array('type_name', $type_name, 'REQUEST'));
         $yform->setValueField('hidden', array('type_id', $type_id, 'REQUEST'));
         $yform->setValueField('prio', array('prio', 'Prioritaet', array('name', 'type_id', 'type_name'), array('table_name')));
         $selectFields = array();
         $i = 1;
         foreach ($types[$type_id][$type_name]['values'] as $k => $v) {
             $field = $this->getFieldName($k, $type_id);
             $selectFields['f' . $i] = $field;
             $i++;
             switch ($v['type']) {
                 case 'name':
                     if ($func == 'edit') {
                         $yform->setValueField('showvalue', array($field, 'Name'));
                     } else {
                         if (!isset($v['value']) && $type_real_field != '') {
                             $v['value'] = $type_real_field;
                         } elseif (!isset($v['value'])) {
                             $v['value'] = '';
                         }
                         $yform->setValueField('text', array($field, 'Name', $v['value']));
                         $yform->setValidateField('empty', array($field, rex_i18n::msg('yform_validatenamenotempty')));
                         $yform->setValidateField('preg_match', array($field, "/(([a-zA-Z])+([a-zA-Z0-9\\_])*)/", rex_i18n::msg('yform_validatenamepregmatch')));
                         $yform->setValidateField('customfunction', array($field, 'rex_yform_manager_checkField', array('table_name' => $table->getTableName()), rex_i18n::msg('yform_validatenamecheck')));
                     }
                     break;
                 case 'no_db':
                     if (!isset($v['default']) || $v['default'] != 1) {
                         $v['default'] = 0;
                     }
                     $yform->setValueField('checkbox', array($field, rex_i18n::msg('yform_donotsaveindb'), 'no_db', $v['default']));
                     break;
                 case 'boolean':
                     // checkbox|check_design|Bezeichnung|Value|1/0|[no_db]
                     if (!isset($v['default'])) {
                         $v['default'] = '';
                     }
                     $yform->setValueField('checkbox', array($field, $v['label'], '', $v['default']));
                     break;
                 case 'select':
                     // select|gender|Geschlecht *|Frau=w;Herr=m|[no_db]|defaultwert|multiple=1
                     $yform->setValueField('select', array($field, $v['label'], $v['options'], '', $v['default'], 0));
                     break;
                 case 'table':
                     // ist fest eingetragen, damit keine Dinge durcheinandergehen
                     if ($func == 'edit') {
                         $yform->setValueField('showvalue', array($field, $v['label']));
                     } else {
                         $_tables = rex_yform_manager_table::getAll();
                         $_options = array();
                         if (isset($v['empty_option']) && $v['empty_option']) {
                             $_options[0] = '–=';
                         }
                         foreach ($_tables as $_table) {
                             $_options[$_table['table_name']] = str_replace('=', '-', rex_i18n::translate($_table['name']) . ' [' . $_table['table_name'] . ']') . '=' . $_table['table_name'];
                             $_options[$_table['table_name']] = str_replace(',', '.', $_options[$_table['table_name']]);
                         }
                         if (!isset($v['default'])) {
                             $v['default'] = '';
                         }
                         $yform->setValueField('select', array($field, $v['label'], implode(',', $_options), '', $v['default'], 0));
                     }
                     break;
                 case 'textarea':
                     $yform->setValueField('textarea', array($field, $v['label']));
                     break;
                 case 'table.field':
                     // Todo:
                 // Todo:
                 case 'select_name':
                     $_fields = array();
                     foreach ($table->getValueFields() as $_k => $_v) {
                         $_fields[] = $_k;
                     }
                     $yform->setValueField('select', array($field, $v['label'], implode(',', $_fields), '', '', 0));
                     break;
                 case 'select_names':
                     $_fields = array();
                     foreach ($table->getValueFields() as $_k => $_v) {
                         $_fields[] = $_k;
                     }
                     $yform->setValueField('select', array($field, $v['label'], implode(',', $_fields), '', '', 1, 5));
                     break;
                 default:
                     // nur beim "Bezeichnungsfeld"
                     if ($field == 'label' && $type_real_field != '' && !isset($v['value'])) {
                         $v['value'] = $type_real_field;
                     } elseif (!isset($v['value'])) {
                         $v['value'] = '';
                     }
                     $yform->setValueField('text', array($field, $v['label'], $v['value']));
             }
         }
         $yform->setActionField('showtext', array('', '<p>' . rex_i18n::msg('yform_thankyouforentry') . '</p>'));
         $yform->setObjectparams('main_table', rex_yform_manager_field::table());
         if ($func == 'edit') {
             $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_save'));
             $yform->setHiddenField('field_id', $field_id);
             $yform->setActionField('manage_db', array(rex_yform_manager_field::table(), "id={$field_id}"));
             $yform->setObjectparams('main_id', $field_id);
             $yform->setObjectparams('main_where', "id={$field_id}");
             $sql = rex_sql::factory();
             $sql->setQuery('SELECT * FROM ' . rex_yform_manager_field::table() . " WHERE id={$field_id}");
             foreach ($selectFields as $alias => $field) {
                 if ($alias != $field) {
                     if ((!$sql->hasValue($field) || null === $sql->getValue($field) || '' === $sql->getValue($field)) && $sql->hasValue($alias)) {
                         $sql->setValue($field, $sql->getValue($alias));
                     }
                     $yform->setValueField('hidden', array($alias, ''));
                 }
             }
             $yform->setObjectparams('sql_object', $sql);
             $yform->setObjectparams('getdata', true);
         } elseif ($func == 'add') {
             $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_add'));
             $yform->setActionField('manage_db', array(rex_yform_manager_field::table()));
         }
         if ($type_id == 'value') {
             $yform->setValueField('checkbox', array('list_hidden', rex_i18n::msg('yform_hideinlist'), 1, '1'));
             $yform->setValueField('checkbox', array('search', rex_i18n::msg('yform_useassearchfieldalidatenamenotempty'), 1, '1'));
         } elseif ($type_id == 'validate') {
             $yform->setValueField('hidden', array('list_hidden', 1));
         }
         $form = $yform->getForm();
         if ($yform->objparams['form_show']) {
             if ($func == 'add') {
                 $title = rex_i18n::msg('yform_addfield') . ' "' . $type_name . '"';
             } else {
                 $title = rex_i18n::msg('yform_editfield') . ' "' . $type_name . '"';
             }
             $fragment = new rex_fragment();
             $fragment->setVar('class', 'edit', false);
             $fragment->setVar('title', $title);
             $fragment->setVar('body', $form, false);
             // $fragment->setVar('buttons', $buttons, false);
             $form = $fragment->parse('core/page/section.php');
             echo $form;
             $table_echo = '<a class="btn btn-default" href="index.php?' . $link_vars . '&amp;table_name=' . $table->getTableName() . '">' . rex_i18n::msg('yform_back_to_overview') . '</a>';
             $fragment = new rex_fragment();
             $fragment->setVar('footer', $table_echo, false);
             echo $fragment->parse('core/page/section.php');
             $func = '';
         } else {
             if ($func == 'edit') {
                 $this->generateAll();
                 echo rex_view::success(rex_i18n::msg('yform_thankyouforupdate'));
             } elseif ($func == 'add') {
                 $this->generateAll();
                 echo rex_view::success(rex_i18n::msg('yform_thankyouforentry'));
             }
             $func = 'list';
         }
     }
     // ********************************************* LOESCHEN
     if ($func == 'delete') {
         $sf = rex_sql::factory();
         $sf->debugsql = self::$debug;
         $sf->setQuery('select * from ' . rex_yform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id);
         $sfa = $sf->getArray();
         if (count($sfa) == 1) {
             $query = 'delete from ' . rex_yform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id;
             $delsql = rex_sql::factory();
             $delsql->debugsql = self::$debug;
             $delsql->setQuery($query);
             echo rex_view::success(rex_i18n::msg('yform_tablefielddeleted'));
             $this->generateAll();
         } else {
             echo rex_view::warning(rex_i18n::msg('yform_tablefieldnotfound'));
         }
         $func = 'list';
     }
     // ********************************************* CREATE/UPDATE FIELDS
     if ($func == 'updatetable') {
         $this->generateAll();
         echo rex_view::info(rex_i18n::msg('yform_tablesupdated'));
         $func = 'list';
     }
     if ($func == 'updatetablewithdelete') {
         $this->generateAll(array('delete_fields' => true));
         echo rex_view::info(rex_i18n::msg('yform_tablesupdated'));
         $func = 'list';
     }
     if ($func == 'show_form_notation') {
         $formbuilder_fields = $table->getFields();
         $notation_php = '';
         $notation_pipe = '';
         $notation_email = '';
         $notation_php_pre = array('$yform = new rex_yform();', '$yform->setObjectparams(\'form_skin\', \'default\');', '$yform->setObjectparams(\'form_showformafterupdate\', 0);', '$yform->setObjectparams(\'real_field_names\', true);');
         $notation_php .= implode("\n", $notation_php_pre) . "\n";
         $notation_pipe_pre = array('objparams|form_skin|bootstrap', 'objparams|form_showformafterupdate|0', 'objparams|real_field_names|true');
         $notation_pipe .= implode("\n", $notation_pipe_pre) . "\n";
         foreach ($formbuilder_fields as $field) {
             $class = 'rex_yform_' . $field->getType() . '_' . $field->getTypeName();
             $cl = new $class();
             $definitions = $cl->getDefinitions();
             $values = array();
             $i = 1;
             foreach ($definitions['values'] as $key => $_) {
                 $key = $this->getFieldName($key, $field['type_id']);
                 if (isset($field[$key])) {
                     $values[] = $field[$key];
                 } elseif (isset($field['f' . $i])) {
                     $values[] = $field['f' . $i];
                 } else {
                     $values[] = '';
                 }
                 $i++;
             }
             if ($field['type_id'] == 'value') {
                 $notation_php .= "\n" . '$yform->setValueField(\'' . $field['type_name'] . '\', array("' . rtrim(implode('","', $values), '","') . '"));';
                 $notation_pipe .= "\n" . $field['type_name'] . '|' . rtrim(implode('|', $values), '|') . '|';
                 $notation_email .= "\n" . $field['label'] . ': ###' . $field['name'] . '###';
             } elseif ($field['type_id'] == 'validate') {
                 $notation_php .= "\n" . '$yform->setValidateField(\'' . $field['type_name'] . '\', array("' . rtrim(implode('","', $values), '","') . '"));';
                 $notation_pipe .= "\n" . $field['type_id'] . '|' . $field['type_name'] . '|' . rtrim(implode('|', $values), '|') . '|';
             } elseif ($field['type_id'] == 'action') {
                 $notation_php .= "\n" . '$yform->setActionField(\'' . $field['type_name'] . '\', array("' . rtrim(implode('","', $values), '","') . '"));';
                 $notation_pipe .= "\n" . $field['type_id'] . '|' . $field['type_name'] . '|' . rtrim(implode('|', $values), '|') . '|';
             }
         }
         $notation_php .= "\n\n" . '$yform->setActionField(\'email\', array(\'emailtemplate\', \'emaillabel\', \'email@domain.de\'));';
         $notation_php .= "\n" . 'echo $yform->getForm();';
         $notation_pipe .= "\n\n" . 'action|email|emailtemplate|emaillabel|email@domain.de';
         $fragment = new rex_fragment();
         $fragment->setVar('title', 'PHP');
         $fragment->setVar('body', '<pre class="pre-scrollable">' . $notation_php . '</pre>', false);
         $content = $fragment->parse('core/page/section.php');
         echo $content;
         $fragment = new rex_fragment();
         $fragment->setVar('title', 'Pipe');
         $fragment->setVar('body', '<pre class="pre-scrollable">' . $notation_pipe . '</pre>', false);
         $content = $fragment->parse('core/page/section.php');
         echo $content;
         $fragment = new rex_fragment();
         $fragment->setVar('title', 'E-Mail');
         $fragment->setVar('body', '<pre class="pre-scrollable">' . $notation_email . '</pre>', false);
         $content = $fragment->parse('core/page/section.php');
         echo $content;
         $func = 'list';
     }
     // ********************************************* LIST
     if ($func == 'list') {
         $show_list = true;
         $show_list = rex_extension::registerPoint(new rex_extension_point('YFORM_MANAGER_TABLE_FIELD_FUNC', $show_list, ['table' => $table, 'link_vars' => $this->getLinkVars()]));
         if ($show_list) {
             function rex_yform_list_format($p, $value = '')
             {
                 if ($value != '') {
                     $p['value'] = $value;
                 }
                 switch ($p['list']->getValue('type_id')) {
                     case 'validate':
                         $style = 'color:#aaa;';
                         // background-color:#cfd9d9;
                         break;
                     case 'action':
                         $style = 'background-color:#cfd9d9;';
                         break;
                     default:
                         $style = 'background-color:#eff9f9;';
                         break;
                 }
                 return '<td style="' . $style . '">' . $p['value'] . '</td>';
             }
             function rex_yform_list_edit_format($p)
             {
                 return rex_yform_list_format($p, $p['list']->getColumnLink(rex_i18n::msg('yform_function'), '<i class="rex-icon rex-icon-edit"></i> ' . rex_i18n::msg('yform_edit')));
             }
             function rex_yform_list_delete_format($p)
             {
                 return rex_yform_list_format($p, $p['list']->getColumnLink(rex_i18n::msg('yform_delete'), '<i class="rex-icon rex-icon-delete"></i> ' . rex_i18n::msg('yform_delete')));
             }
             $context = new rex_context($this->getLinkVars());
             $items = [];
             $item = [];
             $item['label'] = rex_i18n::msg('yform_manager_show_form_notation');
             $item['url'] = $context->getUrl(['table_name' => $table->getTableName(), 'func' => 'show_form_notation']);
             $item['attributes']['class'][] = 'btn-default';
             if (rex_request('func', 'string') == 'show_form_notation') {
                 $item['attributes']['class'][] = 'active';
             }
             $items[] = $item;
             $item = [];
             $item['label'] = rex_i18n::msg('yform_updatetable');
             $item['url'] = $context->getUrl(['table_name' => $table->getTableName(), 'func' => 'updatetable']);
             $item['attributes']['class'][] = 'btn-default';
             if (rex_request('func', 'string') == 'updatetable') {
                 $item['attributes']['class'][] = 'active';
             }
             $items[] = $item;
             $item = [];
             $item['label'] = rex_i18n::msg('yform_updatetable_with_delete');
             $item['url'] = $context->getUrl(['table_name' => $table->getTableName(), 'func' => 'updatetablewithdelete']);
             $item['attributes']['class'][] = 'btn-default';
             if (rex_request('func', 'string') == 'updatetablewithdelete') {
                 $item['attributes']['class'][] = 'active';
             }
             $item['attributes']['onclick'][] = 'return confirm(\'' . rex_i18n::msg('yform_updatetable_with_delete_confirm') . '\')';
             $items[] = $item;
             $fragment = new rex_fragment();
             $fragment->setVar('buttons', $items, false);
             $fragment->setVar('size', 'xs', false);
             $panel_options = $fragment->parse('core/buttons/button_group.php');
             $sql = 'select id, prio, type_id, type_name, name from ' . rex_yform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" order by prio';
             $list = rex_list::factory($sql, 30);
             // $list->debug = 1;
             // $list->setColumnFormat('id', 'Id');
             $tdIcon = '<i class="rex-icon rex-icon-table"></i>';
             $thIcon = '<a href="' . $list->getUrl(['table_name' => $table->getTableName(), 'func' => 'choosenadd']) . '"' . rex::getAccesskey(rex_i18n::msg('add'), 'add') . '><i class="rex-icon rex-icon-add"></i></a>';
             $list->addColumn($thIcon, $tdIcon, 0, ['<th class="rex-table-icon">###VALUE###</th>', '<td class="rex-table-icon">###VALUE###</td>']);
             $list->setColumnParams($thIcon, ['field_id' => '###id###', 'func' => 'edit', 'type_name' => '###type_name###', 'type_id' => '###type_id###']);
             foreach ($this->getLinkVars() as $k => $v) {
                 $list->addParam($k, $v);
             }
             $list->addParam('start', rex_request('start', 'int'));
             $list->addParam('table_name', $table->getTableName());
             $list->removeColumn('id');
             $list->setColumnLabel('prio', rex_i18n::msg('yform_manager_table_prio_short'));
             //$list->setColumnLayout('prio', ['<th class="rex-table-priority">###VALUE###</th>', '<td class="rex-table-priority" data-title="' . rex_i18n::msg('yform_manager_table_prio_short') . '">###VALUE###</td>']);
             $list->setColumnLayout('prio', array('<th>###VALUE###</th>', '###VALUE###'));
             $list->setColumnFormat('prio', 'custom', 'rex_yform_list_format');
             $list->setColumnLabel('type_id', rex_i18n::msg('yform_manager_type_id'));
             $list->setColumnLayout('type_id', array('<th>###VALUE###</th>', '###VALUE###'));
             $list->setColumnFormat('type_id', 'custom', 'rex_yform_list_format');
             $list->setColumnLabel('type_name', rex_i18n::msg('yform_manager_type_name'));
             $list->setColumnLayout('type_name', array('<th>###VALUE###</th>', '###VALUE###'));
             $list->setColumnFormat('type_name', 'custom', 'rex_yform_list_format');
             $list->setColumnLabel('name', rex_i18n::msg('yform_manager_name'));
             $list->setColumnLayout('name', array('<th>###VALUE###</th>', '###VALUE###'));
             // ###VALUE###
             $list->setColumnFormat('name', 'custom', 'rex_yform_list_format');
             $list->addColumn(rex_i18n::msg('yform_function'), '<i class="rex-icon rex-icon-edit"></i> ' . rex_i18n::msg('yform_edit'));
             $list->setColumnParams(rex_i18n::msg('yform_function'), array('field_id' => '###id###', 'func' => 'edit', 'type_name' => '###type_name###', 'type_id' => '###type_id###'));
             $list->setColumnLayout(rex_i18n::msg('yform_function'), array('<th class="rex-table-action" colspan="2">###VALUE###</th>', '###VALUE###'));
             $list->setColumnFormat(rex_i18n::msg('yform_function'), 'custom', 'rex_yform_list_edit_format');
             $list->addColumn(rex_i18n::msg('yform_delete'), '<i class="rex-icon rex-icon-delete"></i> ' . rex_i18n::msg('yform_delete'));
             $list->setColumnParams(rex_i18n::msg('yform_delete'), array('field_id' => '###id###', 'func' => 'delete'));
             $list->setColumnLayout(rex_i18n::msg('yform_delete'), array('', '###VALUE###'));
             $list->setColumnFormat(rex_i18n::msg('yform_delete'), 'custom', 'rex_yform_list_delete_format');
             $list->addLinkAttribute(rex_i18n::msg('yform_delete'), 'onclick', 'return confirm(\' [###type_id###, ###type_name###, ###name###] ' . rex_i18n::msg('yform_delete') . ' ?\')');
             $content = $list->get();
             $fragment = new rex_fragment();
             $fragment->setVar('title', rex_i18n::msg('yform_manager_tablefield_overview'));
             $fragment->setVar('options', $panel_options, false);
             $fragment->setVar('content', $content, false);
             $content = $fragment->parse('core/page/section.php');
             echo $content;
         }
     }
 }
Esempio n. 5
0
 /**
  * checks whether an api function is bound to the current requests. If so, so the api function will be executed.
  */
 public static function handleCall()
 {
     if (static::hasFactoryClass()) {
         return static::callFactoryClass(__FUNCTION__, func_get_args());
     }
     $apiFunc = self::factory();
     if ($apiFunc != null) {
         if ($apiFunc->published !== true) {
             if (rex::isBackend() !== true) {
                 throw new rex_http_exception(new rex_api_exception('the api function ' . get_class($apiFunc) . ' is not published, therefore can only be called from the backend!'), rex_response::HTTP_FORBIDDEN);
             }
             if (!rex::getUser()) {
                 throw new rex_http_exception(new rex_api_exception('missing backend session to call api function ' . get_class($apiFunc) . '!'), rex_response::HTTP_UNAUTHORIZED);
             }
         }
         $urlResult = rex_get(self::REQ_RESULT_PARAM, 'string');
         if ($urlResult) {
             // take over result from url and do not execute the apiFunc
             $result = rex_api_result::fromJSON($urlResult);
             $apiFunc->result = $result;
         } else {
             try {
                 $result = $apiFunc->execute();
                 if (!$result instanceof rex_api_result) {
                     throw new rex_exception('Illegal result returned from api-function ' . rex_get(self::REQ_CALL_PARAM) . '. Expected a instance of rex_api_result but got "' . (is_object($result) ? get_class($result) : gettype($result)) . '".');
                 }
                 $apiFunc->result = $result;
                 if ($result->requiresReboot()) {
                     $context = rex_context::fromGet();
                     // add api call result to url
                     $context->setParam(self::REQ_RESULT_PARAM, $result->toJSON());
                     // and redirect to SELF for reboot
                     rex_response::sendRedirect($context->getUrl([], false));
                 }
             } catch (rex_api_exception $e) {
                 $message = $e->getMessage();
                 $result = new rex_api_result(false, $message);
                 $apiFunc->result = $result;
             }
         }
     }
 }
Esempio n. 6
0
 /**
  * Returns a clang switch.
  *
  * @param rex_context $context
  *
  * @return string
  */
 public static function clangSwitchAsDropdown(rex_context $context)
 {
     if (rex_clang::count() == 1) {
         return '';
     }
     $button_label = '';
     $items = [];
     foreach (rex_clang::getAll() as $id => $clang) {
         if (rex::getUser()->getComplexPerm('clang')->hasPerm($id)) {
             $item = [];
             $item['title'] = rex_i18n::translate($clang->getName());
             $item['href'] = $context->getUrl(['clang' => $id]);
             if ($id == $context->getParam('clang')) {
                 $item['active'] = true;
                 $button_label = rex_i18n::translate($clang->getName());
             }
             $items[] = $item;
         }
     }
     $fragment = new rex_fragment();
     $fragment->setVar('class', 'rex-language');
     $fragment->setVar('button_prefix', rex_i18n::msg('language'));
     $fragment->setVar('button_label', $button_label);
     $fragment->setVar('header', rex_i18n::msg('clang_select'));
     $fragment->setVar('items', $items, false);
     if (rex::getUser()->isAdmin()) {
         $fragment->setVar('footer', '<a href="' . rex_url::backendPage('system/lang') . '"><i class="fa fa-flag"></i> ' . rex_i18n::msg('languages_edit') . '</a>', false);
     }
     return $fragment->parse('core/dropdowns/dropdown.php');
 }
Esempio n. 7
0
 private function getModuleSelect($sliceId)
 {
     // ----- BLOCKAUSWAHL - SELECT
     $context = new rex_context(['page' => rex_be_controller::getCurrentPage(), 'article_id' => $this->article_id, 'clang' => $this->clang, 'ctype' => $this->ctype, 'slice_id' => $sliceId, 'function' => 'add']);
     $items = [];
     if (isset($this->MODULESELECT[$this->ctype])) {
         foreach ($this->MODULESELECT[$this->ctype] as $module) {
             $item = [];
             $item['title'] = $module['name'];
             $item['href'] = $context->getUrl(['module_id' => $module['id']]) . '#slice' . $sliceId;
             $items[] = $item;
         }
     }
     $fragment = new rex_fragment();
     $fragment->setVar('block', true);
     $fragment->setVar('button_label', rex_i18n::msg('add_block'));
     $fragment->setVar('items', $items, false);
     return '<li class="rex-slice rex-slice-select">' . $fragment->parse('core/dropdowns/dropdown.php') . '</li>';
 }
Esempio n. 8
0
 public static function checkPage(rex_user $user)
 {
     $page = self::getCurrentPageObject();
     // --- page pruefen und benoetigte rechte checken
     if (!$page || !$page->checkPermission($user)) {
         // --- fallback zur user startpage -> rechte checken
         $page = self::getPageObject($user->getStartPage());
         if (!$page || !$page->checkPermission($user)) {
             // --- fallback zur system startpage -> rechte checken
             $page = self::getPageObject(rex::getProperty('start_page'));
             if (!$page || !$page->checkPermission($user)) {
                 // --- fallback zur profile page
                 $page = self::getPageObject('profile');
             }
         }
         rex_response::setStatus(rex_response::HTTP_FORBIDDEN);
         rex_response::sendRedirect($page->getHref());
     }
     if ($page !== ($leaf = $page->getFirstSubpagesLeaf())) {
         rex_response::setStatus(rex_response::HTTP_MOVED_PERMANENTLY);
         $url = $leaf->hasHref() ? $leaf->getHref() : rex_context::restore()->getUrl(['page' => $leaf->getFullKey()], false);
         rex_response::sendRedirect($url);
     }
 }
Esempio n. 9
0
File: boot.php Progetto: eaCe/redaxo
         } elseif (rex::getUser()->hasPerm('version[live_version]')) {
             rex_article_revision::copyContent($params['article_id'], $params['clang'], rex_article_revision::WORK, rex_article_revision::LIVE);
             $return .= rex_view::success(rex_i18n::msg('version_info_working_version_to_live'));
         }
         break;
     case 'copy_live_to_work':
         rex_article_revision::copyContent($params['article_id'], $params['clang'], rex_article_revision::LIVE, rex_article_revision::WORK);
         $return .= rex_view::success(rex_i18n::msg('version_info_live_version_to_working'));
         break;
 }
 if (!rex::getUser()->hasPerm('version[live_version]')) {
     $rex_version_article[$params['article_id']] = 1;
     unset($revisions[0]);
 }
 rex::getProperty('login')->setSessionVar('rex_version_article', $rex_version_article);
 $context = new rex_context(['page' => $params['page'], 'article_id' => $params['article_id'], 'clang' => $params['clang'], 'ctype' => $params['ctype']]);
 $items = [];
 $brand = '';
 foreach ($revisions as $version => $revision) {
     $item = [];
     $item['title'] = $revision;
     $item['href'] = $context->getUrl(['rex_set_version' => $version]);
     if ($rex_version_article[$params['article_id']] == $version) {
         $item['active'] = true;
         $brand = $revision;
     }
     $items[] = $item;
 }
 $toolbar = '';
 $fragment = new rex_fragment();
 $fragment->setVar('button_prefix', rex_i18n::msg('version'));
Esempio n. 10
0
<?php

// ------- Default Values
$HTMLArea = rex_request('HTMLArea', 'string');
$opener_input_field = rex_request('opener_input_field', 'string');
$opener_input_field_name = rex_request('opener_input_field_name', 'string');
$category_id = rex_request('category_id', 'int');
$category_id = rex_category::get($category_id) ? $category_id : 0;
$clang = rex_request('clang', 'int');
$clang = rex_clang::exists($clang) ? $clang : rex_clang::getStartId();
$context = new rex_context(['page' => rex_be_controller::getCurrentPage(), 'HTMLArea' => $HTMLArea, 'opener_input_field' => $opener_input_field, 'opener_input_field_name' => $opener_input_field_name, 'category_id' => $category_id, 'clang' => $clang]);
// ------- Build JS Functions
$func_body = '';
if ($HTMLArea != '') {
    if ($HTMLArea == 'TINY') {
        $func_body = 'window.opener.tinyMCE.insertLink(link);';
    } else {
        $func_body = 'window.opener.' . $HTMLArea . '.surroundHTML("<a href="+link+">","</a>");';
    }
}
if ($opener_input_field != '' && $opener_input_field_name == '') {
    $opener_input_field_name = $opener_input_field . '_NAME';
}
if ($opener_input_field == 'TINY') {
    $func_body .= 'window.opener.insertLink(link,name);
                                 self.close();';
} elseif (substr($opener_input_field, 0, 13) == 'REX_LINKLIST_') {
    $id = substr($opener_input_field, 13, strlen($opener_input_field));
    $func_body .= 'var linklist = "REX_LINKLIST_SELECT_' . $id . '";
                             var linkid = link.replace("redaxo://","");
                 var source = opener.document.getElementById(linklist);
Esempio n. 11
0
/**
 * @param rex_context $context
 *
 * @return string
 *
 * @package redaxo\structure
 */
function rex_structure_searchbar(rex_context $context)
{
    $message = '';
    $search_result = '';
    // ------------ Parameter
    $clang = $context->getParam('clang', 1);
    $category_id = $context->getParam('category_id', 0);
    $article_id = $context->getParam('article_id', 0);
    $search_article_name = rex_request('search_article_name', 'string');
    // ------------ Suche via ArtikelId
    if (preg_match('/^[0-9]+$/', $search_article_name, $matches)) {
        if ($OOArt = rex_article::get($matches[0], $clang)) {
            rex_response::sendRedirect($context->getUrl(['page' => 'content/edit', 'article_id' => $OOArt->getId()], false));
        }
    }
    // Auswahl eines normalen Artikels => category holen
    if ($article_id != 0) {
        $OOArt = rex_article::get($article_id, $clang);
        // Falls Artikel gerade geloescht wird, gibts keinen rex_article
        if ($OOArt) {
            $category_id = $OOArt->getCategoryId();
        }
    }
    // ------------ Suche via ArtikelName
    if (rex_request('search_start', 'bool')) {
        // replace LIKE wildcards
        $search_article_name_like = str_replace(['_', '%'], ['\\_', '\\%'], $search_article_name);
        $qry = '
        SELECT id
        FROM ' . rex::getTablePrefix() . 'article
        WHERE
            clang_id = ' . $clang . ' AND
            (
                name LIKE "%' . $search_article_name_like . '%" OR
                catname LIKE "%' . $search_article_name_like . '%"
            )';
        if (rex_addon::get('structure')->getConfig('searchmode', 'local') != 'global') {
            // Suche auf aktuellen Kontext eingrenzen
            if ($category_id != 0) {
                $qry .= ' AND path LIKE "%|' . $category_id . '|%"';
            }
        }
        $search = rex_sql::factory();
        //    $search->setDebug();
        $search->setQuery($qry);
        $foundRows = $search->getRows();
        // Suche ergab nur einen Treffer => Direkt auf den Treffer weiterleiten
        if ($foundRows == 1) {
            $OOArt = rex_article::get($search->getValue('id'), $clang);
            if (rex::getUser()->getComplexPerm('structure')->hasCategoryPerm($OOArt->getCategoryId())) {
                rex_response::sendRedirect($context->getUrl(['page' => 'content/edit', 'article_id' => $search->getValue('id')], false));
            }
        } elseif ($foundRows > 0) {
            $needle = htmlspecialchars($search_article_name);
            $search_result .= '<div class="list-group">';
            for ($i = 0; $i < $foundRows; ++$i) {
                $breadcrumb = [];
                $OOArt = rex_article::get($search->getValue('id'), $clang);
                $label = $OOArt->getName();
                if (rex::getUser()->getComplexPerm('structure')->hasCategoryPerm($OOArt->getCategoryId())) {
                    $label .= ' [' . $search->getValue('id') . ']';
                    $highlightHit = function ($string, $needle) {
                        return preg_replace('/(.*)(' . preg_quote($needle, '/') . ')(.*)/i', '\\1<mark>\\2</mark>\\3', $string);
                    };
                    foreach ($OOArt->getParentTree() as $treeItem) {
                        $treeLabel = $treeItem->getName();
                        if (rex::getUser()->hasPerm('advancedMode[]')) {
                            $treeLabel .= ' [' . $treeItem->getId() . ']';
                        }
                        $treeLabel = htmlspecialchars($treeLabel);
                        $treeLabel = $highlightHit($treeLabel, $needle);
                        $e = [];
                        $e['title'] = $treeLabel;
                        $e['href'] = $context->getUrl(['page' => 'structure', 'category_id' => $treeItem->getId()]);
                        $breadcrumb[] = $e;
                    }
                    $label = htmlspecialchars($label);
                    $label = $highlightHit($label, $needle);
                    $e = [];
                    $e['title'] = $label;
                    $e['href'] = $context->getUrl(['page' => 'content/edit', 'article_id' => $treeItem->getId()]);
                    $breadcrumb[] = $e;
                    $fragment = new rex_fragment();
                    $fragment->setVar('items', $breadcrumb, false);
                    $search_result .= '<div class="list-group-item">' . $fragment->parse('core/navigations/breadcrumb.php') . '</div>';
                }
                $search->next();
            }
            $search_result .= '</div>';
            $fragment = new rex_fragment();
            $fragment->setVar('title', rex_i18n::msg('be_search_result'), false);
            $fragment->setVar('content', $search_result, false);
            $search_result = $fragment->parse('core/page/section.php');
        } else {
            $message = rex_view::info(rex_i18n::msg('be_search_no_results'));
        }
    }
    $select_name = 'category_id';
    $add_homepage = true;
    if (rex_be_controller::getCurrentPagePart(1) == 'content') {
        $select_name = 'article_id';
        $add_homepage = false;
    }
    $category_select = new rex_category_select(false, false, true, $add_homepage);
    $category_select->setName($select_name);
    $category_select->setSize('1');
    $category_select->setAttribute('onchange', 'this.form.submit();');
    $category_select->setSelected($category_id);
    $select = $category_select->get();
    $doc = new DOMDocument();
    $doc->loadHTML('<?xml encoding="UTF-8">' . $select);
    $options = $doc->getElementsByTagName('option');
    $droplistContext = new rex_context(['page' => 'structure', 'category_id' => 0]);
    $button_label = '';
    $items = [];
    foreach ($options as $option) {
        $value = '';
        $item = [];
        if ($option->hasAttributes()) {
            foreach ($option->attributes as $attribute) {
                if ($attribute->name == 'value') {
                    $value = $attribute->value;
                    $droplistContext->setParam('category_id', $value);
                    if ($attribute->value == $category_id) {
                        $button_label = str_replace(" ", '', $option->nodeValue);
                        $item['active'] = true;
                    }
                }
            }
        }
        $item['title'] = preg_replace('/\\[([0-9]+)\\]$/', '<small class="rex-primary-id">$1</small>', $option->nodeValue);
        $item['href'] = $droplistContext->getUrl();
        $items[] = $item;
    }
    $fragment = new rex_fragment();
    $fragment->setVar('button_prefix', rex_i18n::msg('be_search_quick_navi'));
    $fragment->setVar('button_label', $button_label);
    $fragment->setVar('items', $items, false);
    $droplist = '<div class="navbar-btn navbar-right">' . $fragment->parse('core/dropdowns/dropdown.php');
    $formElements = [];
    $n = [];
    $n['field'] = '<input class="form-control" type="text" name="search_article_name" value="' . htmlspecialchars($search_article_name) . '" placeholder="' . htmlspecialchars(rex_i18n::msg('be_search_article_name') . '/' . rex_i18n::msg('be_search_article_id')) . '" />';
    $n['right'] = '<button class="btn btn-search" type="submit" name="search_start" value="1">' . rex_i18n::msg('be_search_start') . '</button>';
    $formElements[] = $n;
    $fragment = new rex_fragment();
    $fragment->setVar('elements', $formElements, false);
    $toolbar = $fragment->parse('core/form/input_group.php');
    $toolbar = '
    <form action="' . rex_url::currentBackendPage() . '" method="post">
    ' . $context->getHiddenInputFields() . '
    <div class="navbar-form navbar-left">
        <div class="form-group">
            ' . $toolbar . '
        </div>
    </div>
    </form>';
    $toolbar = rex_view::toolbar($toolbar . $droplist, rex_i18n::msg('be_search_search'));
    return $toolbar . $search_result;
}
Esempio n. 12
0
 public static function formatLi(rex_structure_element $OOobject, $current_category_id, rex_context $context, $liAttr = '', $linkAttr = '')
 {
     $liAttr .= $OOobject->getId() == $current_category_id ? ' id="rex-linkmap-active"' : '';
     $linkAttr .= ' class="' . ($OOobject->isOnline() ? 'rex-online' : 'rex-offline') . '"';
     if (strpos($linkAttr, ' href=') === false) {
         $linkAttr .= ' href="' . $context->getUrl(['category_id' => $OOobject->getId()]) . '"';
     }
     $label = self::formatLabel($OOobject);
     return '<li' . $liAttr . '><a' . $linkAttr . '>' . htmlspecialchars($label) . '</a>';
 }
Esempio n. 13
0
 public static function checkPagePermissions(rex_user $user)
 {
     $check = function (rex_be_page $page) use(&$check, $user) {
         if (!$page->checkPermission($user)) {
             return false;
         }
         $subpages = $page->getSubpages();
         foreach ($subpages as $key => $subpage) {
             if (!$check($subpage)) {
                 unset($subpages[$key]);
             }
         }
         $page->setSubpages($subpages);
         return true;
     };
     foreach (self::$pages as $key => $page) {
         if (!$check($page)) {
             unset(self::$pages[$key]);
         }
     }
     self::$pageObject = null;
     $page = self::getCurrentPageObject();
     // --- page pruefen und benoetigte rechte checken
     if (!$page) {
         // --- fallback zur user startpage -> rechte checken
         $page = self::getPageObject($user->getStartPage());
         if (!$page) {
             // --- fallback zur system startpage -> rechte checken
             $page = self::getPageObject(rex::getProperty('start_page'));
             if (!$page) {
                 // --- fallback zur profile page
                 $page = self::getPageObject('profile');
             }
         }
         rex_response::setStatus(rex_response::HTTP_NOT_FOUND);
         rex_response::sendRedirect($page->getHref());
     }
     if ($page !== ($leaf = $page->getFirstSubpagesLeaf())) {
         rex_response::setStatus(rex_response::HTTP_MOVED_PERMANENTLY);
         $url = $leaf->hasHref() ? $leaf->getHref() : rex_context::restore()->getUrl(['page' => $leaf->getFullKey()], false);
         rex_response::sendRedirect($url);
     }
 }
Esempio n. 14
0
 private function getModuleSelect($sliceId)
 {
     // ----- BLOCKAUSWAHL - SELECT
     $context = new rex_context(['page' => rex_be_controller::getCurrentPage(), 'article_id' => $this->article_id, 'clang' => $this->clang, 'ctype' => $this->ctype, 'slice_id' => $sliceId, 'function' => 'add']);
     $position = ++$this->sliceAddPosition;
     $items = [];
     if (isset($this->MODULESELECT[$this->ctype])) {
         foreach ($this->MODULESELECT[$this->ctype] as $module) {
             $item = [];
             $item['title'] = $module['name'];
             $item['href'] = $context->getUrl(['module_id' => $module['id']]) . '#slice-add-pos-' . $position;
             $items[] = $item;
         }
     }
     $fragment = new rex_fragment();
     $fragment->setVar('block', true);
     $fragment->setVar('button_label', rex_i18n::msg('add_block'));
     $fragment->setVar('items', $items, false);
     $select = $fragment->parse('core/dropdowns/dropdown.php');
     $select = rex_extension::registerPoint(new rex_extension_point('STRUCTURE_CONTENT_MODULE_SELECT', $select, ['page' => rex_be_controller::getCurrentPage(), 'article_id' => $this->article_id, 'clang' => $this->clang, 'ctype' => $this->ctype, 'slice_id' => $sliceId]));
     return '<li class="rex-slice rex-slice-select" id="slice-add-pos-' . $position . '">' . $select . '</li>';
 }