/** * View for <param type="private" class="cbpaidParamsExt" method="datalist">... * * @param string $value Stored Data of Model Value associated with the element * @param ParamsInterface $pluginParams Main settigns parameters of the plugin * @param string $name Name attribute * @param CBSimpleXMLElement $param This XML node * @param string $control_name Name of the control * @param string $control_name_name css id-encode of the names of the controls surrounding this node * @param boolean $view TRUE: view, FALSE: edit * @param cbpaidTable $modelOfData Data of the Model corresponding to this View * @param cbpaidTable[] $modelOfDataRows Displayed Rows if it is a table * @param int $modelOfDataRowsNumber Total Number of rows * @return null|string */ public function datalist($value, &$pluginParams, $name, &$param, $control_name, $control_name_name, $view, &$modelOfData, &$modelOfDataRows, &$modelOfDataRowsNumber) { global $_CB_database; //TBD $multi = ( $param->attributes( 'multiple' ) == 'true' ); $data = $param->getElementByPath('data'); if ($data) { $dataTable = $data->attributes('table'); if (!$dataTable) { if (isset($this->table)) { $dataTable = $this->table; } elseif (is_object($modelOfData) && $modelOfData instanceof TableInterface) { $dataTable = $modelOfData->getTableName(); } elseif (is_object($modelOfData) && isset($modelOfData->_tbl)) { $dataTable = $modelOfData->_tbl; } else { $dataTable = null; } } $xmlsql = new XmlQuery($_CB_database, $dataTable, $pluginParams); $xmlsql->setExternalDataTypeValues('modelofdata', $modelOfData); $xmlsql->process_orderby($data->getElementByPath('orderby')); // <data><orderby><field> fields $xmlsql->process_fields($data->getElementByPath('rows')); // <data><rows><field> fields $xmlsql->process_where($data->getElementByPath('where')); // <data><where><column> fields $groupby = $data->getElementByPath('groupby'); if (!$groupby) { $groupby = 'value'; } if ($data->attributes('dogroupby') != 'false') { $xmlsql->process_groupby($groupby); } $fieldValuesInDb = $xmlsql->queryLoadObjectsList($data); // get the records if ($view) { if (is_array($fieldValuesInDb)) { foreach ($fieldValuesInDb as $v) { if ($v->value == $value) { $value = $v->text; break; } } } return htmlspecialchars($value); } else { // check if value is in possible values: if ($value != $param->attributes('default') && is_array($fieldValuesInDb)) { $setToDefault = true; foreach ($fieldValuesInDb as $v) { if ($v->value == $value) { $setToDefault = false; break; } } if ($setToDefault) { $value = $param->attributes('default'); } } if ($param->attributes('blanktext') && ($param->attributes('hideblanktext') != 'true' || $value == $param->attributes('default'))) { $default = (string) $param->attributes('default'); array_unshift($fieldValuesInDb, moscomprofilerHTML::makeOption($default, CBPTXT::T($param->attributes('blanktext')))); } //TBD $selected = explode( '|*|', $value ); $classes = 'class="' . RegistryEditView::buildClasses($param, array('form-control')) . '"'; return moscomprofilerHTML::selectList($fieldValuesInDb, $control_name_name, $classes . $this->_title($param), 'value', 'text', $value, 2); // return $this->selectList( $fieldValuesInDb, $param, $control_name, $name, $selected, $multi ); } } return null; }
/** * Writes the edit form for new and existing module * * A new record is defined when <var>$row</var> is passed with the <var>id</var> * property set to 0. * * @param array $options * @param array $actionPath * @param SimpleXMLElement $viewModel * @param TableInterface|\stdClass $data * @param RegistryEditController $params * @param PluginTable $pluginRow * @param string $viewType ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) * @param string $cbprevstate * @param boolean $htmlOutput True to output headers for CSS and Javascript */ public static function editPluginView($options, $actionPath, $viewModel, $data, $params, $pluginRow, $viewType, $cbprevstate, $htmlOutput) { global $_CB_framework, $_CB_Backend_Title, $_PLUGINS, $ueConfig; $name = $viewModel->attributes('name'); $label = $viewModel->attributes('label'); $iconPair = explode(':', $viewModel->attributes('icon')); if (count($iconPair) > 1) { $iconset = isset($iconPair[0]) ? $iconPair[0] : null; $icon = isset($iconPair[1]) ? $iconPair[1] : null; } else { $iconset = 'fa'; $icon = isset($iconPair[0]) ? $iconPair[0] : null; } if ($icon) { if ($iconset == 'fa') { $icon = 'fa fa-' . $icon; } elseif ($iconset) { $icon = $iconset . $icon; } } $id = null; if (is_object($data)) { $dataArray = get_object_vars($data); if (in_array('id', $dataArray)) { // General object $id = (int) $data->id; } elseif (in_array('tabid', $dataArray)) { // Field object $id = (int) $data->tabid; } elseif (in_array('fieldid', $dataArray)) { // Tab object $id = (int) $data->fieldid; } } if ($id !== null) { if (isset($data->title)) { $item = $data->title; } elseif (isset($data->name)) { $item = $data->name; } else { $item = $id; } $title = ($id ? CBTxt::T('Edit') : CBTxt::T('New')) . ($label ? ' ' . htmlspecialchars(CBTxt::T($label)) . ' ' : null) . ($item ? ' [' . htmlspecialchars(CBTxt::T($item)) . ']' : null); } else { $title = $label ? htmlspecialchars(CBTxt::T($label)) : null; } if ($viewModel->attributes('label')) { $showDisclaimer = true; if ($pluginRow) { if (!$icon) { $icon = 'cb-' . str_replace('.', '_', $pluginRow->element) . '-' . $name; } $_CB_Backend_Title = array(0 => array($icon, htmlspecialchars(CBTxt::T($pluginRow->name)) . ($title ? ': ' . $title : null))); } else { if (!$icon) { $icon = 'cb-' . $name; } $_CB_Backend_Title = array(0 => array($icon, htmlspecialchars(CBTxt::T('Community Builder')) . ($title ? ': ' . $title : null))); } // Null the label so the view form doesn't output it as we already did as page title: $viewModel->addAttribute('label', null); } else { $showDisclaimer = false; } $htmlFormatting = $viewModel->attributes('viewformatting'); if (!$htmlFormatting) { if ($_CB_framework->getUi() == 1 && (isset($ueConfig['use_divs']) && $ueConfig['use_divs'] == 1)) { $htmlFormatting = 'div'; } else { $htmlFormatting = 'table'; } } new cbTabs(true, 2); $settingsHtml = $params->draw(null, null, null, null, null, null, false, $viewType, $htmlFormatting); if ($htmlOutput) { outputCbTemplate(); outputCbJs(); self::outputAdminJs(); initToolTip(); self::outputRegTemplate(); } $return = null; if ($pluginRow && $pluginRow->id) { if (!$pluginRow->published) { $return .= '<div class="alert alert-danger">' . CBTxt::T('PLUGIN_NAME_IS_NOT_PUBLISHED', '[plugin_name] is not published.', array('[plugin_name]' => htmlspecialchars(CBTxt::T($pluginRow->name)))) . '</div>'; } if (!$_PLUGINS->checkPluginCompatibility($pluginRow)) { $return .= '<div class="alert alert-danger">' . CBTxt::T('PLUGIN_NAME_IS_NOT_COMPATIBLE_WITH_YOUR_CURRENT_CB_VERSION', '[plugin_name] is not compatible with your current CB version.', array('[plugin_name]' => htmlspecialchars(CBTxt::T($pluginRow->name)))) . '</div>'; } } if (is_object($data) && isset($data->id) && $data->id) { if (isset($data->published) && !$data->published) { $return .= '<div class="alert alert-danger">' . CBTxt::T('NAME_IS_NOT_PUBLISHED', '[name] is not published.', array('[name]' => htmlspecialchars(CBTxt::T($label)))) . '</div>'; } if (isset($data->enabled) && !$data->enabled) { $return .= '<div class="alert alert-danger">' . CBTxt::T('NAME_IS_NOT_ENABLED', '[name] is not enabled.', array('[name]' => htmlspecialchars(CBTxt::T($label)))) . '</div>'; } } if ($viewModel->attributes('formformatting') == 'none') { $return .= $settingsHtml ? $settingsHtml : null; } else { cbValidator::loadValidation(); $cssClass = RegistryEditView::buildClasses($viewModel); if (!$cssClass) { $cssClass = 'cb_form form-auto'; } $return .= '<form enctype="multipart/form-data" action="' . $_CB_framework->backendUrl('index.php') . '" method="post" name="adminForm" class="cbValidation ' . htmlspecialchars($cssClass) . '" id="cbAdminFormForm">' . ($settingsHtml ? $settingsHtml : null) . '<input type="hidden" name="option" value="' . htmlspecialchars($options['option']) . '" />' . ($pluginRow ? '<input type="hidden" name="cid" value="' . (int) $pluginRow->id . '" />' : null) . ($cbprevstate ? '<input type="hidden" name="cbprevstate" value="' . htmlspecialchars($cbprevstate) . '" />' : null); if ($actionPath) { foreach ($actionPath as $k => $v) { $return .= '<input type="hidden" name="' . htmlspecialchars($k) . '" value="' . htmlspecialchars($v) . '" />'; } } $return .= cbGetSpoofInputTag('plugin') . '</form>'; } if ($showDisclaimer) { $disclaimerTitle = 'Disclaimer'; $disclaimerText = 'This software comes "as is" with no guarantee for accuracy, function or fitness for any purpose.'; $disclaimerTitleTr = CBTxt::Th('Disclaimer'); $disclaimerTextTr = CBTxt::Th('This software comes "as is" with no guarantee for accuracy, function or fitness for any purpose.'); $return .= '<div class="cbregCopyrightfooter content-spacer" style="font-size:11px; color:black; display:block;">' . CBTxt::Th('CB_FOOTNOTE_OPEN_SOURCE_WITH_PLUGINS', 'Community Builder for Joomla, an open-source social framework by <a href="http://www.joomlapolis.com/?pk_campaign=in-cb&pk_kwd=footer" target="_blank">Joomlapolis.com</a>, easy to extend with <a href="http://www.joomlapolis.com/cb-solutions?pk_campaign=in-cb&pk_kwd=footer" target="_blank">CB plugins</a>. Professional <a href="http://www.joomlapolis.com/support?pk_campaign=in-cb&pk_kwd=footer" target="_blank">Support</a> is available with a <a href="http://www.joomlapolis.com/memberships?pk_campaign=in-cb&pk_kwd=footer" target="_blank">Membership</a>.') . '<br /><strong>' . $disclaimerTitle . ':</strong> ' . $disclaimerText . ($disclaimerText != $disclaimerTextTr ? '<br /><strong>' . $disclaimerTitleTr . ':</strong> ' . $disclaimerTextTr : null) . '<br />' . CBTxt::Th('CB_FOOTNOTE_REVIEW_AND_RATE_AT_JED', 'If you use Community Builder, please post a rating and a review on the <a href="[JEDURL]" target="_blank">Joomla! Extensions Directory</a>.', array('[JEDURL]' => htmlspecialchars('http://extensions.joomla.org/extensions/clients-a-communities/communities/210 '))) . '</div>'; } echo $return; }
/** * @param SimpleXMLElement[] $xmlToolbarMenuArray * @return void */ static function _PLUGIN_MENU($xmlToolbarMenuArray) { if ($xmlToolbarMenuArray && count($xmlToolbarMenuArray) > 0) { $started = false; foreach ($xmlToolbarMenuArray as $xmlTBmenu) { if ($xmlTBmenu && count($xmlTBmenu->children()) > 0) { foreach ($xmlTBmenu->children() as $menu) { /** @var SimpleXMLElement $menu */ if ($menu->getName() == 'menu') { // $name = $menu->attributes( 'name' ); $action = $menu->attributes('action'); $task = $menu->attributes('task'); $label = $menu->attributes('label'); $class = RegistryEditView::buildClasses($menu); $description = $menu->attributes('description'); if (in_array($action, get_class_methods('CBtoolmenuBar')) || in_array(strtolower($action), get_class_methods('CBtoolmenuBar'))) { // PHP 5 || PHP 4 if (!$started) { CBtoolmenuBar::startTable(); $started = true; } switch ($action) { case 'custom': case 'customX': $icon = $menu->attributes('icon'); $iconOver = $menu->attributes('iconover'); CBtoolmenuBar::$action($task, $icon, $iconOver, $label, false, null, $class); break; case 'editList': CBtoolmenuBar::editListNoSelect($task, $label); break; case 'deleteList': case 'deleteListX': $message = $menu->attributes('message'); CBtoolmenuBar::$action($message, $task, $label); break; case 'trash': CBtoolmenuBar::$action($task, $label, false); break; case 'preview': $popup = $menu->attributes('popup'); CBtoolmenuBar::$action($popup, true); break; case 'help': $ref = $menu->attributes('href'); if (!$ref) { // Backwards compatibility to CB 1.x: $ref = $menu->attributes('ref'); } CBtoolmenuBar::$action($ref, true); break; case 'divider': case 'spacer': CBtoolmenuBar::$action(); break; case 'back': $href = $menu->attributes('href'); CBtoolmenuBar::$action($label, $href); break; case 'media_manager': $directory = $menu->attributes('directory'); CBtoolmenuBar::$action($directory, $label); break; case 'linkAction': $urllink = $menu->attributes('urllink'); if ($menu->attributes('task') == 'new') { CBtoolmenuBar::$action($task, $urllink, $label, $class ? $class : (checkJversion('j3.0+') ? 'btn-success' : null)); } else { CBtoolmenuBar::$action($task, $urllink, $label, $class); } break; default: CBtoolmenuBar::$action($task, $label); break; } } elseif ($action == 'permissions') { if ($description) { $headerHtml = '<div class="cbbejeoptionsintro cbbejeoptionsintro' . htmlspecialchars($task) . '">' . $description . '</div>'; } else { $headerHtml = null; } self::_PERMISSIONS($task, $headerHtml); if ($label) { self::_TRANSLATECONFIGTITLE($task, $label); } } // if ( in_array( $action, array( 'customX', 'addNew', 'addNewX', 'publish', 'publishList', 'makeDefault', 'assign', 'unpublish', 'unpublishList', // 'archiveList', 'unarchiveList', ) ) ) { // nothing // } } } } } if ($started) { CBtoolmenuBar::endTable(); } } }
/** * Implements a form password field * * @param string $name The name of the form element * @param string $value The value of the element * @param SimpleXMLElement $node The xml element for the parameter * @param string $control_name The control name * @return string The html for the element */ function _form_password( $name, $value, &$node, $control_name ) { if ( $this->_view ) { $sprintf = $node->attributes( 'sprintf' ); if ( $sprintf ) { return htmlspecialchars( sprintf( $sprintf, $value ) ); } else { return "********"; // htmlspecialchars($value); } } else { $size = $node->attributes( 'size' ); $siz = ( $size ? ' size="' . (int) $size . '"' : null ); $classes = ' class="' . htmlspecialchars( RegistryEditView::buildClasses( $node, array( 'form-control' ) ) ) . '"'; return '<input type="password" autocomplete="off" name="'. $this->control_name( $control_name, $name ) . '" id="'. $this->control_id( $control_name, $name ) . '" value="'. htmlspecialchars($value) .'"' . $siz . $classes . ' />'; } }
/** * Renders as ECHO HTML code of a table * * @param SimpleXMLElement $modelView * @param array $modelRows * @param DrawController $controllerView * @param array $options * @param string $viewType ( 'view', 'param', 'depends': means: <param> tag => param, <field> tag => view ) */ protected function renderList(&$modelView, &$modelRows, &$controllerView, &$options, $viewType = 'view') { global $_CB_framework; static $JS_loaded = 0; $pluginParams = $this->_pluginParams; $renderer = new RegistryEditView($this->input, $this->_db, $pluginParams, $this->_types, $this->_actions, $this->_views, $this->_pluginObject, $this->_tabid); $renderer->setParentView($modelView); $renderer->setModelOfDataRows($modelRows); $name = $modelView->attributes('name'); $listFieldsRows = $modelView->getElementByPath('listfields/rows'); $listFieldsPager = $modelView->getElementByPath('listfields/paging'); $filtersArray = $controllerView->filters($renderer, 'table'); $batchArray = $controllerView->batchprocess($renderer, 'table'); outputCbJs(); $tableLabel = trim(CBTxt::Th($modelView->attributes('label'))); $tableMenu = $modelView->getElementByPath('tablemenu'); if (!$JS_loaded++) { if ($controllerView->pageNav !== null) { $searchButtonJs = $controllerView->pageNav->limitstartJs(0); } else { $searchButtonJs = 'cbParentForm( this ).submit();'; } $js = "\$( '.cbTableHeader' ).on( 'click', '.cbTableHeaderExpand', function() {" . "\$( this ).removeClass( 'btn-default cbTableHeaderExpand' ).addClass( 'btn-primary cbTableHeaderCollapse' );" . "\$( this ).find( '.fa' ).removeClass( 'fa-caret-down' ).addClass( 'fa-caret-up' );" . "\$( '.' + \$( this ).data( 'toggle' ) ).slideDown();" . "});" . "\$( '.cbTableHeader' ).on( 'click', '.cbTableHeaderCollapse', function() {" . "var toggle = \$( this ).data( 'toggle' );" . "\$( this ).removeClass( 'btn-primary cbTableHeaderCollapse' ).addClass( 'btn-default cbTableHeaderExpand' );" . "\$( this ).find( '.fa' ).removeClass( 'fa-caret-up' ).addClass( 'fa-caret-down' );" . "\$( '.' + toggle ).slideUp();" . "if ( toggle == 'cbBatchTools' ) {" . "\$( '.' + toggle ).find( 'input,textarea,select' ).val( '' );" . "if ( \$.fn.cbselect ) {" . "\$( '.' + toggle ).find( 'select.cbSelect2' ).each( function() {" . "\$( this ).cbselect( 'set', '' );" . "});" . "}" . "} else {" . "\$( '.' + toggle ).find( 'input,textarea,select' ).each( function() {" . "var value = null;" . "if ( \$( this ).hasClass( 'cbSelect2' ) ) {" . "if ( \$.fn.cbselect ) {" . "value = \$( this ).cbselect( 'get' );" . "} else {" . "value = \$( this ).val();" . "}" . "} else {" . "value = \$( this ).val();" . "}" . "if ( ( value != null ) && ( value != '' ) ) {" . "\$( '.cbTableHeaderClear' ).click(); return;" . "}" . "});" . "}" . "});" . "\$( '.cbTableHeader' ).on( 'click', '.cbTableHeaderClear', function() {" . "\$( '.cbTableHeader' ).find( 'input,textarea,select' ).val( '' );" . "if ( \$.fn.cbselect ) {" . "\$( '.cbTableHeader' ).find( 'select.cbSelect2' ).each( function() {" . "\$( this ).cbselect( 'set', '' );" . "});" . "}" . $searchButtonJs . "});" . "\$( '.cbTableBrowserRowsHeader' ).on( 'click', '.cbTableBrowserSort', function() {" . "\$( '.cbTableHeader' ).find( '.cbTableBrowserSorting > select' ).val( \$( this ).data( 'table-sort' ) ).change();" . "});" . ($this->_filtered ? "\$( '.cbSearchToolsToggle' ).click();" : null); $_CB_framework->outputCbJQuery($js); } $return = '<div class="table-responsive cbTableBrowserDiv' . ($name ? ' cbDIV' . htmlspecialchars($name) : null) . '">'; if ($tableLabel || $tableMenu || $controllerView->hasSearchFields() || $controllerView->hasOrderbyFields() || count($filtersArray) > 0 || count($batchArray) > 0) { $return .= '<table class="table table-noborder cbTableBrowserHeader' . ($name ? ' cbTA' . htmlspecialchars($name) : null) . '">' . '<thead>' . '<tr class="cbTableHeader">'; if ($tableLabel || $tableMenu) { $return .= '<th style="width: 10%;" class="text-left cbTableBrowserLabel' . ($name ? ' cbTH' . htmlspecialchars($name) : null) . '">' . ($tableLabel ? $tableLabel : null); if ($tableMenu) { $menuIndex = 1; $return .= $tableLabel ? '<div><small>[ ' : null; foreach ($tableMenu->children() as $menu) { /** @var SimpleXMLElement $menu */ $menuAction = $menu->attributes('action'); $menuLabelHtml = trim(CBTxt::Th(htmlspecialchars($menu->attributes('label')))); $menuDesc = $menu->attributes('description'); if ($menuDesc) { $menuDesc = ' title="' . trim(htmlspecialchars(CBTxt::T($menuDesc))) . '"'; } $return .= $menuIndex > 1 ? ' - ' : null; if ($menuAction) { $data = null; $link = $controllerView->drawUrl($menuAction, $menu, $data, 0, true); if ($link) { $return .= '<a href="' . $link . '"' . $menuDesc . '>' . $menuLabelHtml . '</a>'; } } elseif ($menuDesc) { $return .= '<span' . $menuDesc . '>' . $menuLabelHtml . '</span>'; } else { $return .= $menuLabelHtml; } $menuIndex++; } $return .= $tableLabel ? ' ]</small></div>' : null; } $return .= '</th>'; } if ($controllerView->hasSearchFields() || $controllerView->hasOrderbyFields() || count($filtersArray) > 0 || count($batchArray) > 0) { $return .= '<th class="cbTableHeaderTools">' . '<div class="text-left clearfix cbTableBrowserTools">'; if ($controllerView->hasSearchFields()) { $return .= $controllerView->quicksearchfields(); } if (count($filtersArray) > 0) { if ($controllerView->hasSearchFields()) { $return .= ' '; } $return .= '<button type="button" class="btn btn-default cbSearchToolsToggle cbTableHeaderExpand" data-toggle="cbSearchTools">' . CBTxt::Th('Search Tools') . ' <span class="fa fa-caret-down"></span></button>'; } if (count($batchArray) > 0) { if (count($filtersArray) > 0 || $controllerView->hasSearchFields()) { $return .= ' '; } $return .= '<button type="button" class="btn btn-default cbBatchToolsToggle cbTableHeaderExpand" data-toggle="cbBatchTools">' . CBTxt::Th('Batch Tools') . ' <span class="fa fa-caret-down"></span></button>'; } $return .= ' <button type="button" class="btn btn-default cbTableHeaderClear">' . CBTxt::Th('Clear') . '</button>'; if ($controllerView->hasOrderbyFields()) { if (count($filtersArray) > 0 || count($batchArray) > 0 || $controllerView->hasSearchFields()) { $return .= ' '; } $return .= '<span class="text-right pull-right cbTableBrowserSorting">' . $controllerView->orderbyfields() . '</span>'; } $return .= '</div>'; if (count($filtersArray) > 0) { $return .= '<fieldset class="cbFilters cbSearchTools cbFieldset">' . '<legend>' . CBTxt::Th('Search Tools') . '</legend>' . implode(' ', $filtersArray) . '</fieldset>'; } if (count($batchArray) > 0) { $return .= '<fieldset class="cbBatchProcess cbBatchTools cbFieldset">' . '<legend>' . CBTxt::Th('Batch Tools') . '</legend>' . implode(' ', $batchArray) . '</fieldset>'; } $return .= '</th>'; } $return .= '</tr>' . '</thead>' . '</table>'; } if ($listFieldsRows) { $columnCount = 0; $return .= '<table class="table table-hover cbTableBrowserRows' . ($name ? ' cbTL' . htmlspecialchars($name) : null) . '">' . '<thead>' . '<tr class="cbTableBrowserRowsHeader">'; foreach ($listFieldsRows->children() as $field) { /** @var SimpleXMLElement $field */ if ($field->attributes('type') != 'hidden' && Access::authorised($field)) { $classes = RegistryEditView::buildClasses($field); $attributes = ($classes ? ' class="' . htmlspecialchars($classes) . '"' : null) . ($field->attributes('width') || $field->attributes('align') ? ' style="' . ($field->attributes('width') ? 'width: ' . htmlspecialchars($field->attributes('width')) . ';' : null) . ($field->attributes('align') ? 'text-align: ' . htmlspecialchars($field->attributes('align')) . ';' : null) . '"' : null) . ($field->attributes('nowrap') ? ' nowrap="nowrap"' : null); $fieldName = $field->attributes('name'); $fieldOrdering = $field->attributes('allowordering'); $return .= '<th' . $attributes . '>'; if ($field->attributes('type') == 'primarycheckbox') { $jsToggleAll = "cbToggleAll( this, " . count($modelRows) . ", '" . $controllerView->fieldId('id') . "' );"; $return .= '<input type="checkbox" id="' . $controllerView->fieldId('toggle') . '" name="' . $controllerView->fieldName('toggle') . '" value="" onclick="' . $jsToggleAll . '" />'; } else { $fieldIcon = null; if ($fieldOrdering) { $fieldSort = explode(',', $fieldOrdering); $fieldAsc = in_array('ascending', $fieldSort); $fieldDesc = in_array('descending', $fieldSort); if ($fieldAsc && $this->orderby == $fieldName . '_asc') { // If ascending is allowed and is already active then set click to descending if descending is allowed: if ($fieldDesc) { $return .= '<a href="javascript: void(0);" class="text-nowrap cbTableBrowserSort cbTableBrowserSortDesc" data-table-sort="' . htmlspecialchars($fieldName . '_desc') . '">'; } else { $return .= '<a href="javascript: void(0);">'; } $fieldIcon = ' <span class="fa fa-sort-alpha-asc text-default"></span>'; } elseif ($fieldDesc && $this->orderby == $fieldName . '_desc') { // If descending is allowed and is already active then set click to ascending if ascending is allowed: if ($fieldAsc) { $return .= '<a href="javascript: void(0);" class="text-nowrap cbTableBrowserSort cbTableBrowserSortAsc" data-table-sort="' . htmlspecialchars($fieldName . '_asc') . '">'; } else { $return .= '<a href="javascript: void(0);">'; } $fieldIcon = ' <span class="fa fa-sort-alpha-desc text-default"></span>'; } elseif ($fieldSort[0] == 'ascending') { // Default to ascending if this field allows it: $return .= '<a href="javascript: void(0);" class="cbTableBrowserSort cbTableBrowserSortAsc" data-table-sort="' . htmlspecialchars($fieldName . '_asc') . '">'; } elseif ($fieldSort[0] == 'descending') { // Default to descending if this field allows it: $return .= '<a href="javascript: void(0);" class="cbTableBrowserSort cbTableBrowserSortDesc" data-table-sort="' . htmlspecialchars($fieldName . '_desc') . '">'; } else { $return .= '<a href="javascript: void(0);">'; } } $return .= $field->attributes('description') ? cbTooltip(2, CBTxt::Th($field->attributes('description')), null, null, null, CBTxt::Th($field->attributes('label')), null, 'data-hascbtooltip="true"') : CBTxt::Th($field->attributes('label')); if ($fieldOrdering) { $return .= $fieldIcon . '</a>'; } } if ($field->attributes('type') == 'ordering') { if (!$fieldOrdering || in_array($this->orderby, array($fieldName . '_asc', $fieldName . '_desc', $fieldName))) { if ($fieldOrdering) { $field->addAttribute('noordering', 'false'); } if (strpos($field->attributes('onclick'), 'number') !== false) { $jsOrderSave = "cbsaveorder( this, " . count($modelRows) . ", '" . $controllerView->fieldId('id', null, false) . "', '" . $controllerView->taskName(false) . "', '" . $controllerView->subtaskName(false) . "', '" . $controllerView->subtaskValue('saveorder/' . $field->attributes('name'), false) . "' );"; $return .= ' <a href="javascript: void(0);" onclick="' . $jsOrderSave . '">' . '<span class="fa fa-save fa-lg text-default" title="' . htmlspecialchars(CBTxt::T('Save Order')) . '"></span>' . '</a>'; } } else { if ($fieldOrdering) { $field->addAttribute('noordering', 'true'); } } } $return .= '</th>'; $columnCount++; } } $return .= '</tr>' . '</thead>' . '</tbody>'; $total = count($modelRows); $controllerView->pageNav->setRowsNumber($total); if ($total) { for ($i = 0; $i < $total; $i++) { $controllerView->pageNav->setRowIndex($i); $renderer->setModelOfDataRowsNumber($i); $row = $modelRows[$i]; $rowlink = $listFieldsRows->attributes('link'); if ($rowlink) { $hrefRowEdit = $controllerView->drawUrl($rowlink, $listFieldsRows, $row, $row->id, false); if ($hrefRowEdit) { if ($listFieldsRows->attributes('target') == '_blank') { $onclickJS = 'window.open(\'' . htmlspecialchars(cbUnHtmlspecialchars($hrefRowEdit)) . '\', \'cbinvoice\', \'status=no,toolbar=no,scrollbars=yes,titlebar=no,menubar=no,resizable=yes,width=640,height=480,directories=no,location=no\'); return false;'; } else { $onclickJS = "window.location='" . htmlspecialchars(cbUnHtmlspecialchars($hrefRowEdit)) . "'"; } $rowOnclickHtml = ' onclick="' . $onclickJS . '"'; } else { $rowOnclickHtml = null; } } else { $rowOnclickHtml = null; } $controllerView->setControl_name($this->name . '[rows][' . $i . ']'); $return .= '<tr class="cbTableBrowserRow"' . $rowOnclickHtml . '>' . $renderer->renderEditRowView($listFieldsRows, $row, $controllerView, $options, $viewType, 'td') . '</tr>'; } } $controllerView->setControl_name($this->name); $return .= '</tbody>'; if ($total && (!$listFieldsPager || $listFieldsPager && $listFieldsPager->attributes('type') != 'none')) { if ($listFieldsPager) { $showPageLinks = strpos($listFieldsPager->attributes('type'), 'nopagelinks') === false; $showLimitBox = strpos($listFieldsPager->attributes('type'), 'nolimitbox') === false; $showPagesCount = strpos($listFieldsPager->attributes('type'), 'nopagescount') === false; } else { $showPageLinks = true; $showLimitBox = true; $showPagesCount = true; } if ($controllerView->pageNav->total <= $controllerView->pageNav->limit) { $showPageLinks = false; } $return .= '<tfoot>' . '<tr class="cbTableBrowserRowsPaging">' . '<th colspan="' . (int) $columnCount . '" class="text-center">' . $controllerView->pageNav->getListFooter($showPageLinks, $showLimitBox, $showPagesCount) . '</th>' . '</tr>' . '</tfoot>' . '</table>'; } elseif ($controllerView->pageNav !== null) { $return .= '</table>' . $controllerView->pageNav->getLimitBox(false); } else { $return .= '</table>'; } } elseif ($controllerView->pageNav !== null) { $return .= $controllerView->pageNav->getLimitBox(false); } $return .= '<input type="hidden" name="' . $controllerView->fieldName('subtask') . '" value="" />'; $statistics = $controllerView->getStatistics(); if ($statistics) { foreach ($statistics as $stat) { $return .= $renderer->renderEditRowView($stat['view'], $stat['values'], $controllerView, $options, 'view', 'table'); } } $return .= '</div>'; echo $return; }
/** * Handles the backend plugin edition * * @param string $option * @param string $action * @param SimpleXMLElement $element * @param string $mode * @return string HTML * * @throws \LogicException */ public function drawView($option, $action, $element, $mode) { global $_CB_Backend_Menu; $ui = $this->clientId == 1 ? 2 : 1; $context = new Context(); $pluginParams = $context->getParams(); $interfaceUi = $ui == 2 ? 'admin' : 'frontend'; $adminActionsModel = $element->getChildByNameAttr('actions', 'ui', $interfaceUi); if (!$adminActionsModel) { $adminActionsModel = $element->getChildByNameAttr('actions', 'ui', 'all'); } if (!$adminActionsModel) { throw new \LogicException('No ' . $interfaceUi . ' actions defined in XML'); } // Check permission if specified: if (!Access::authorised($adminActionsModel)) { return CBTxt::T("Access to these actions is not authorized by the permissions of your user groups."); } // General-purpose extenders: $extenders = $adminActionsModel->xpath('extend'); /** @var SimpleXMLElement[] $extenders */ foreach ($extenders as $k => $extends) { $error = RegistryEditView::extendXMLnode($extenders[$k], $element, null, $context->getPluginObject()); if ($error) { echo $error; } } $found = false; $actionPath = array(); if ($action) { $actionsModel = $adminActionsModel->getChildByNameAttr('action', 'name', $action); $found = $actionsModel != null; if ($found) { $requests = explode(' ', $actionsModel->attributes('request')); $values = explode(' ', $actionsModel->attributes('action')); $actionPath = array(); for ($i = 0, $n = count($requests); $i < $n; $i++) { $actionPath[$requests[$i]] = $values[$i]; } } } if (!$found) { // EVENT: select the event from URL and compute the selected $actionPath $found = false; $actionsModel = null; foreach ($adminActionsModel->children() as $actionsModel) { /** @var SimpleXMLElement $actionsModel */ $request = $actionsModel->attributes('request'); if ($request) { $requests = explode(' ', $request); $values = explode(' ', $actionsModel->attributes('action')); $actionPath = array(); for ($i = 0, $n = count($requests); $i < $n; $i++) { $actionPath[$requests[$i]] = $this->input->get($requests[$i], null, GetterInterface::STRING); // Temporary fix for older versions of CBSubs before CBSubs 4.0.0 stable to avoid warnings on ajax version checks: if ($requests[$i] === 'view' && $actionPath['view'] === null) { $actionPath['view'] = $this->input->get('task', null, GetterInterface::STRING); } if ($actionPath[$requests[$i]] != $values[$i]) { break; } } if ($i == $n) { $found = true; break; } } } } if (!$found) { $actionPath = array(); // try finding first default one: if ($ui == 2) { $actionsModel = $adminActionsModel->getChildByNameAttr('action', 'request', ''); } if (!isset($actionsModel)) { return CBTxt::T('AHAWOW_REQUESTED_ACTION_NOT_DEFINED_IN_XML', "Requested action '[ACTION]' not defined in XML.", array('[ACTION]' => htmlspecialchars($action))); } } // Check permission if specified: if (!isset($actionsModel) || !Access::authorised($actionsModel)) { return CBTxt::T("This action is not authorized by the permissions of your user groups."); } if (!isset($actionPath['view'])) { $actionPath['view'] = $ui == 2 ? 'editPlugin' : ''; //TODO: 2nd should come from target routing } elseif ($actionPath['view'] != 'editPlugin') { $actionPath['act'] = ''; } // EVENT: fetch the input parameters from URL: $parametersNames = explode(' ', $actionsModel->attributes('requestparameters')); $parametersValues = array(); foreach ($parametersNames as $paraNam) { $parametersValues[$paraNam] = null; if (strpos($paraNam, '[') === false) { if (trim($paraNam)) { $parametersValues[$paraNam] = $this->input->get($paraNam, '', GetterInterface::STRING); } } else { $matches = null; preg_match_all('/(.*)(?:\\[(.*)\\])+/', $paraNam, $matches); if (is_array($matches) && count($matches) >= 3 && count($matches[2]) >= 1) { $parametersValues[$paraNam] = $this->input->get($matches[1][0] . '.' . $matches[2][0], null, GetterInterface::STRING); } } } $keyValues = array(); // Action-specific general extenders: $extenders = $adminActionsModel->xpath('actionspecific/extend'); /** @var SimpleXMLElement[] $extenders */ foreach ($extenders as $k => $extends) { $error = RegistryEditView::extendXMLnode($extenders[$k], $element, $actionsModel, $context->getPluginObject()); if ($error) { echo $error; } } // First extend what can be extended so the showview's below have a complete XML tree: /** @var $actionItem SimpleXMLElement */ foreach ($actionsModel->xpath('extend') as $actionItem) { $error = RegistryEditView::extendXMLnode($actionItem, $element, $actionsModel, $context->getPluginObject()); if ($error) { echo $error; } } /** @var $actionItem SimpleXMLElement */ foreach ($actionsModel->children() as $actionItem) { // CONTROLLER: select the controller: switch ($actionItem->getName()) { case 'extend': // Treated just above. break; case 'showview': $viewName = $actionItem->attributes('view'); $showviewType = $actionItem->attributes('type'); $viewMode = $actionItem->attributes('mode'); // MODEL: load data to view: $dataModel = $actionItem->getElementByPath('data'); if ($dataModel) { $dataModelType = $dataModel->attributes('type'); $cbDatabase = $this->db; if (in_array($dataModelType, array('sql:row', 'sql:multiplerows', 'sql:field', 'parameters'))) { $xmlsql = new XmlQuery($cbDatabase, null, $pluginParams); $data = $xmlsql->loadObjectFromData($dataModel); if ($data === null) { return 'showview::sql:row: load failed: ' . $cbDatabase->getErrorMsg(); } $dataModelValueName = $dataModel->attributes('value'); $dataModelValueType = $dataModel->attributes('valuetype'); // if the value of key is a parameter name, replace it with the corresponding parameter: $dataModelValueTypeArray = explode(':', $dataModelValueType); if ($dataModelValueTypeArray[0] == 'request') { if (isset($parametersValues[$dataModelValueName])) { $dataModelValue = $parametersValues[$dataModelValueName]; // database escaping to int is done at request time $keyValues[$dataModelValueName] = $dataModelValue; unset($parametersValues[$dataModelValueName]); } else { echo sprintf('showview::sql::row %s: request %s not in parameters of action.', $dataModel->attributes('name'), $dataModelValueName); } } if ($dataModelType == 'sql:field') { $data = new Registry($data); } } elseif ($dataModelType == 'class') { $dataModelClass = $dataModel->attributes('class'); $dataModelValue = $dataModel->attributes('value'); $dataModelValueName = $dataModelValue; $dataModelValueType = $dataModel->attributes('valuetype'); $dataModelValueTypeArray = explode(':', $dataModelValueType); if ($dataModelValueTypeArray[0] == 'request') { if (isset($parametersValues[$dataModelValueName])) { $dataModelValue = $parametersValues[$dataModelValueName]; $keyValues[$dataModelValueName] = $dataModelValue; unset($parametersValues[$dataModelValueName]); } else { echo sprintf('showview::sql::row %s: request %s not in parameters of action.', $dataModel->attributes('name'), $dataModelValue); } } if (strpos($dataModelClass, '::') === false) { $data = new $dataModelClass($cbDatabase); // normal clas="className" /** @var $data TableInterface */ $data->load($dataModelValue); } else { $dataModelSingleton = explode('::', $dataModelClass); // class object loader from singleton: class="loaderClass::loadStaticMethor" with 1 parameter, the key value. if (is_callable($dataModelSingleton)) { if (is_callable(array($dataModelSingleton[0], 'getInstance'))) { $instance = call_user_func_array(array($dataModelSingleton[0], 'getInstance'), array(&$cbDatabase)); $rows = call_user_func_array(array($instance, $dataModelSingleton[1]), array($dataModelValue)); } else { $rows = call_user_func_array($dataModelSingleton, array($dataModelValue)); } } else { echo sprintf('showview::class %s: missing singleton class creator %s.', $dataModel->attributes('name'), $dataModelClass); $std = new \stdClass(); $rows = array($std); } $data = $rows[0]; } } else { $data = null; echo 'showview: Data model type ' . $dataModelType . ' is not implemented !'; } } else { if ($this->_data instanceof TableInterface || $this->_data instanceof \comprofilerDBTable) { $data = $this->_data; $dataModelType = 'sql:row'; } elseif ($this->_data instanceof ParamsInterface) { $data = $this->_data; $dataModelType = 'sql:row'; } else { $data = null; $dataModelType = null; } } // VIEW: select view: $allViewsModels = $element->getElementByPath('views'); if ($viewName && (!$showviewType || $showviewType == 'view')) { ////// $viewModel = $allViewsModels->getChildByNameAttributes( 'view', array( 'name' => $viewName ) ); $xpathUi = '/*/views/view[@ui="' . $interfaceUi . '" and @name="' . $viewName . '"]'; $xpathAll = '/*/views/view[@ui="all" and @name="' . $viewName . '"]'; $viewModel = $element->xpath($xpathUi); if (!$viewModel) { $viewModel = $element->xpath($xpathAll); } if (!$viewModel) { $viewModel = RegistryEditView::xpathWithAutoLoad($element, $xpathUi); } if (!$viewModel) { $viewModel = RegistryEditView::xpathWithAutoLoad($element, $xpathAll); } /* if ( ! $viewModel ) { $viewModel = RegistryEditView::xpathWithAutoLoad( $element, '/ * / views/view[not(@ui) and @name="' . $viewName . '"]' ); } */ if ($viewModel) { $viewModel = $viewModel[0]; } else { return 'XML:showview: View ' . $viewName . ' not defined in ui ' . $interfaceUi . ' in XML'; } } elseif ($showviewType == 'xml') { // e.g.: <showview name="gateway_paymentstatus_information" mode="view" type="xml" file="processors/{payment_method}/edit.gateway" path="/*/views/view[@name="paymentstatusinformation"]" mandatory="false" /> $fromNode = $actionItem->attributes('path'); $fromFile = $actionItem->attributes('file'); if ($fromNode && $fromFile !== null) { // $this->substituteName( $fromFile, true ); // $this->substituteName( $fromNode, false ); $fromFile = $context->getPluginPath() . '/' . $fromFile . '.xml'; if ($fromFile === '' || is_readable($fromFile)) { if ($fromFile === '') { $fromRoot = $element; } else { $fromRoot = new SimpleXMLElement($fromFile, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0), true); } $viewModel = $fromRoot->xpath($fromNode); if (!$viewModel) { trigger_error('Admin:showview: View ' . $viewName . ': file ' . $fromFile . ', path: ' . $fromNode . ' does not exist or is empty.', E_USER_NOTICE); } $viewModel = $viewModel[0]; } else { throw new \LogicException('Admin:showview: View ' . $viewName . ': file ' . $fromFile . ' does not exist or is not readable.'); } } else { throw new \LogicException('Admin:showview: View ' . $viewName . ' file or path not defined..', E_USER_NOTICE); } } else { throw new \LogicException('Admin:showview: View ' . $viewName . ' not of supported type.', E_USER_NOTICE); } $viewUi = $viewModel->attributes('ui'); if ($viewUi & $viewUi != 'all' && $viewUi != $interfaceUi) { throw new \LogicException('showview: View ' . $viewName . ' not allowed for ' . $interfaceUi); } $extendedParser = $allViewsModels->getElementByPath('extendxmlparser'); $actionPath = array_merge($actionPath, $keyValues); $options = array_merge($this->getBaseOptions(), $actionPath, $parametersValues); if ($ui == 2) { $options = array_merge($options, $actionPath, $parametersValues); } $cbprevstate = $this->input->get('cbprevstate', null, GetterInterface::STRING); $params = new RegistryEditController($this->input, $this->db, new Registry(), $viewModel, $element, $context->getPluginObject()); $displayData = $this->bindInput($viewMode, $data); // Set the parameters with the $displayData : $registry = new Registry(); $registry->load($displayData); $registry->setStorage($displayData); $params->setRegistry($registry); $params->setPluginParams($pluginParams); $params->setOptions($options); if ($extendedParser) { $params->setExtendedViewParser($extendedParser); } $extenders = $allViewsModels->xpath('extend'); foreach ($extenders as $extends) { RegistryEditView::extendXMLnode($extends, $element, $actionsModel, $context->getPluginObject()); } $viewType = $viewModel->attributes('type'); switch ($viewType) { case 'params': if ($mode == 'edit') { if ($viewMode == 'edit' || $viewMode == 'show') { $viewTypeMode = $viewMode == 'edit' ? 'param' : 'view'; if ($ui == 2) { $htmlOutput = $this->input->get('no_html', 0, GetterInterface::COMMAND) != 1 && $this->input->get('format', null, GetterInterface::COMMAND) != 'raw'; ActionViewAdmin::editPluginView($options, $actionPath, $viewModel, $displayData, $params, $context->getPluginObject(), $viewTypeMode, $cbprevstate, $htmlOutput); $settings = null; $html = null; } else { /** @global \stdClass $_CB_Backend_Menu : 'show' : only displays close button, 'edit' : special close button */ global $_CB_Backend_Menu; $_CB_Backend_Menu = new \stdClass(); $html = ''; outputCbTemplate(); outputCbJs(); // $_CB_framework->outputCbJQuery( '' ); initToolTip(); $htmlFormatting = $viewModel->attributes('viewformatting'); if (!$htmlFormatting) { global $ueConfig; if (isset($ueConfig['use_divs']) && $ueConfig['use_divs'] == 1) { $htmlFormatting = 'div'; } else { $htmlFormatting = 'table'; } } $settings = $params->draw(null, null, null, null, null, null, false, $viewTypeMode, $htmlFormatting); } if ($ui == 2) { $_CB_Backend_Menu->mode = $viewMode; // Implemented in lower level in RegistryEditView: $toolbarMenu = $viewModel->getElementByPath( 'toolbarmenu' ); } if ($ui != 2) { $actionView = new ActionView(); $buttonSaveText = $actionsModel->attributes('label'); if (!$buttonSaveText) { $buttonSaveText = 'Save'; } $buttonSaveText = CBTxt::Th($buttonSaveText); // CBTxt::Th("Save"); For translation strings extraction $warning = null; if ($viewTypeMode == 'param') { $settings .= '<div class="cbControlButtonsLine">' . "\n\t" . '<span class="cb_button_wrapper">' . '<button type="submit" name="actbutton" value="' . 'save' . $action . '" class="button cbregButton cbregSaveButton">' . $buttonSaveText . '</button>' . '</span>' . "\n\t" . '</div>' . "\n"; $postedActionPath = $actionPath; unset($postedActionPath['view']); $formHiddens = array_merge($this->getBaseOptions(), array('act' => 'save' . $action), $postedActionPath); } else { $formHiddens = null; } $html .= $actionView->drawForm($settings, $warning, $formHiddens, array_merge($this->_getParams, array('act' => $action)), RegistryEditView::buildClasses($viewModel)); return $html; } } else { echo 'showview::params: mode is ' . $mode . ' but view mode is ' . $viewMode . ' instead of edit.'; } } elseif (in_array($mode, array('apply', 'save', 'savenew', 'savecopy'))) { $this->savePluginView($options, $actionPath, $keyValues, $parametersValues, $viewModel, $data, $params, $mode, $dataModelType, $context->getPluginObject(), $dataModel, $pluginParams, $cbprevstate, $ui); if ($ui == 2 && $mode == 'apply') { // We arrive here only in case of saving error, as redirect (performed in savePluginView) would loose the inputs: return $this->drawView($option, $action, $element, 'edit'); } } else { echo 'showview::params: view type params mode ' . $mode . ' is not implemented !'; } break; default: echo 'showview::not-params: type of view ' . $viewType . ' is not implemented !'; break; } break; default: echo 'action::not-showview: child xml element "' . $actionItem->getName() . '" of action is not implemented !'; break; } } return null; }
/** * Renders the header of the menu group * * @param SimpleXMLElement $param * @param string $htmlFormatting * @return string */ protected function renderMenuGroupHeader(&$param, $htmlFormatting) { $html = array(); $legend = $param->attributes('label'); $description = $param->attributes('description'); $cssclass = RegistryEditView::buildClasses($param); if ($htmlFormatting == 'table') { $html[] = '<tr><td colspan="3" style="width: 100%;"' . ($cssclass ? ' class="' . htmlspecialchars($cssclass) . '"' : '') . '>'; } elseif ($htmlFormatting == 'td') { $html[] = '<td' . ($cssclass ? ' class="' . htmlspecialchars($cssclass) . '"' : '') . '>'; } if ($legend) { $html[] = '<h2>' . CBTxt::Th($legend) . '</h2>'; } if ($htmlFormatting == 'table') { $html[] = '<table class="table table-noborder">'; if ($description) { $html[] = '<tr><td colspan="3" style="width: 100%;"><strong>' . CBTxt::Th($description) . '</strong></td></tr>'; } } elseif ($htmlFormatting == 'td') { if ($description) { $html[] = '<td colspan="3" style="width: 100%;"><strong>' . CBTxt::Th($description) . '</strong></td>'; } } else { if ($description) { $html[] = '<strong>' . CBTxt::Th($description) . '</strong>'; } } if (!in_array($htmlFormatting, array('table', 'td'))) { $html[] = '<div class="cbButtonMenu' . ($cssclass ? ' ' . htmlspecialchars($cssclass) : '') . '">'; } return implode('', $html); }