/** * Gets instance of cbUsersList for $listId * * @since 1.8 * * @param int $listId List id * @return ListTable */ public static function getInstance($listId) { global $_CB_framework; static $lists = array(); $listId = (int) $listId; if (!isset($lists[$listId])) { $row = new ListTable(); if (!$row->load($listId) || $_CB_framework->getUi() != 2 && $row->published != 1) { return null; } $lists[$listId] = $row; } return $lists[$listId]; }
/** * Commented CBT calls for language parser pickup: Moved to cb.core.php so they get picked-up in front-end language file and not in backend one. */ function loadSampleData() { global $_CB_Backend_Title; @set_time_limit(240); $_CB_Backend_Title = array(0 => array('fa fa-wrench', CBTxt::T('TOOLS_SAMPLE_DATA_TITLE', 'CB Tools: Sample Data: Results'))); $return = null; $affected = false; $tab = new TabTable(); $tab->load(array('title' => '_UE_ADDITIONAL_INFO_HEADER')); if (!$tab->tabid) { $affected = true; $tab->set('title', '_UE_ADDITIONAL_INFO_HEADER'); $tab->set('displaytype', 'menunested'); $tab->set('position', 'canvas_main_middle'); $tab->set('viewaccesslevel', 1); $tab->set('enabled', 1); $tab->set('ordering', 1); if ($tab->getError() || !$tab->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_TAB_NOT_OK', 'Tab [title] failed to add. Error: [error]', array('[title]' => $tab->get('title'), '[error]' => $tab->getError())) . '</div>'; } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_TAB_OK', 'Tab Added Successfully!') . '</div>'; } $affected = false; $fields = array('cb_website' => array('title' => '_UE_Website', 'type' => 'webaddress', 'registration' => 0, 'ordering' => 1), 'cb_location' => array('title' => '_UE_Location', 'type' => 'text', 'maxlength' => 50, 'size' => 25, 'registration' => 0, 'ordering' => 2), 'cb_occupation' => array('title' => '_UE_Occupation', 'type' => 'text', 'registration' => 0, 'ordering' => 3), 'cb_interests' => array('title' => '_UE_Interests', 'type' => 'text', 'registration' => 0, 'ordering' => 4), 'cb_company' => array('title' => '_UE_Company', 'type' => 'text', 'ordering' => 5), 'cb_city' => array('title' => '_UE_City', 'type' => 'text', 'ordering' => 6), 'cb_state' => array('title' => '_UE_State', 'type' => 'text', 'maxlength' => 10, 'size' => 4, 'ordering' => 7), 'cb_zipcode' => array('title' => '_UE_ZipCode', 'type' => 'text', 'ordering' => 8), 'cb_country' => array('title' => '_UE_Country', 'type' => 'text', 'ordering' => 9), 'cb_address' => array('title' => '_UE_Address', 'type' => 'text', 'ordering' => 10), 'cb_phone' => array('title' => '_UE_PHONE', 'type' => 'text', 'ordering' => 11), 'cb_fax' => array('title' => '_UE_FAX', 'type' => 'text', 'ordering' => 12)); foreach ($fields as $fieldName => $fieldSettings) { $field = new FieldTable(); $field->load(array('name' => $fieldName)); if (!$field->fieldid) { $affected = true; $field->set('name', $fieldName); $field->set('registration', 1); $field->set('profile', 1); $field->set('edit', 1); $field->set('published', 1); foreach ($fieldSettings as $column => $value) { $field->set($column, $value); } $field->set('tabid', $tab->tabid); $field->set('pluginid', 1); if ($field->getError() || !$field->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_FIELD_NOT_OK', 'Field [name] failed to add. Error: [error]', array('[name]' => $field->get('name'), '[error]' => $field->getError())) . '</div>'; } } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_FIELD_OK', 'Fields Added Successfully!') . '</div>'; } $affected = false; $list = new ListTable(); $list->load(array('title' => 'Members List')); if (!$list->listid) { $affected = true; $list->set('title', 'Members List'); $list->set('viewaccesslevel', 1); $list->set('usergroupids', '1|*|6|*|7|*|2|*|3|*|4|*|5|*|8'); $list->set('default', 1); $list->set('published', 1); $list->set('ordering', 1); $listParams = new Registry(); $listParams->set('sort_mode', '0'); $listParams->set('basic_sort', array(array('column' => 'username', 'direction' => 'ASC'))); $listParams->set('columns', array(array('title' => 'User', 'size' => '3', 'fields' => array(array('field' => '17', 'display' => '4'), array('field' => '29', 'display' => '4'), array('field' => '42', 'display' => '4'), array('field' => '26', 'display' => '4'))), array('title' => 'Info', 'size' => '9', 'fields' => array(array('field' => '27', 'display' => '1'), array('field' => '49', 'display' => '1'), array('field' => '28', 'display' => '1'))))); $listParams->set('list_grid_layout', '1'); $list->set('params', $listParams->asJson()); if ($list->getError() || !$list->store()) { $return .= '<div class="form-group cb_form_line clearfix text-danger">' . CBTxt::T('TOOLS_SAMPLE_DATA_LIST_NOT_OK', 'List [title] failed to add. Error: [error]', array('[title]' => $list->get('title'), '[error]' => $tab->getError())) . '</div>'; } } if ($affected) { $return .= '<div class="form-group cb_form_line clearfix text-success">' . CBTxt::T('TOOLS_SAMPLE_DATA_LIST_OK', 'List Added Successfully!') . '</div>'; } if (!$return) { $return .= '<div class="form-group cb_form_line clearfix">' . CBTxt::T('TOOLS_SAMPLE_DATA_ALREADY_CONFIGURED', 'Sample Data is already loaded!') . '</div>'; } echo $return; }
/** * Fix old 1.x usergroups-based permissions to 2.x access-levels in lists and in tabs * * @param \CB\Database\Table\TabTable|\CB\Database\Table\ListTable $loaderTabOrList * @param string $titleIfCreate Title for newly created access levels if needed (e.g. 'CB Tab access') * @return void * * @throws \RuntimeException */ private function convertUserGroupsToViewAccessLevels($loaderTabOrList, $titleIfCreate) { $loaderTabOrList->getDbo()->setQuery('SELECT * FROM ' . $loaderTabOrList->getDbo()->NameQuote($loaderTabOrList->getTableName())); $allTabsOrLists = $loaderTabOrList->loadTrueObjects(); foreach ($allTabsOrLists as $tabOrList) { if (isset($tabOrList->useraccessgroupid)) { if ((int) $tabOrList->useraccessgroupid == 0) { // Already converted or new in 2.x+: continue; } $alreadyConvertedButNotZeroed = (int) $tabOrList->useraccessgroupid == -2 && $tabOrList->viewaccesslevel; if ((int) $tabOrList->viewaccesslevel <= 1 && !$alreadyConvertedButNotZeroed) { // Still database default: Convert: $tabOrList->viewaccesslevel = Application::CmsPermissions()->convertOldGroupToViewAccessLevel($tabOrList->useraccessgroupid, $titleIfCreate); } // Always set to 0 after conversion: $tabOrList->useraccessgroupid = 0; $tabOrList->store(); } } }