public function __viewIndex() { $this->setTitle(__('%1$s – %2$s', array(__('Symphony'), __('Sections')))); $this->appendSubheading(__('Sections'), Widget::Anchor(__('Create New'), Administration::instance()->getCurrentPageURL() . '/new/', array('title' => __('Create a new section'), 'class' => 'create button'))); $sections = new SectionIterator(); $aTableHead = array(array(__('Name'), 'col'), array(__('Entries'), 'col'), array(__('Navigation Group'), 'col'), array(__('Sync Status'), 'col')); $aTableBody = array(); $colspan = count($aTableHead); if ($sections->length() <= 0) { $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None found.'), array('class' => 'inactive', 'colspan' => $colspan))), array('class' => 'odd'))); } else { foreach ($sections as $s) { $entry_count = 0; $result = Symphony::Database()->query("\n\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\tcount(*) AS `count`\n\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t`tbl_entries` AS e\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\te.section = '%s'\n\t\t\t\t\t\t", array($s->handle)); if ($result->valid()) { $entry_count = (int) $result->current()->count; } // Setup each cell $td1 = Widget::TableData(Widget::Anchor($s->name, Administration::instance()->getCurrentPageURL() . "/edit/{$s->handle}/", array('class' => 'content'))); $td2 = Widget::TableData(Widget::Anchor((string) $entry_count, ADMIN_URL . "/publish/{$s->handle}/")); $td3 = Widget::TableData($s->{'navigation-group'}); $td3->appendChild(Widget::Input("items[{$s->handle}]", 'on', 'checkbox')); if (Section::syncroniseStatistics($s)->synced) { $td4 = Widget::TableData(__('Synced'), array('class' => 'content inactive')); } else { $td4 = Widget::TableData(__('Not synced'), array('class' => 'content')); } // Add a row to the body array, assigning each cell to the row $aTableBody[] = Widget::TableRow(array($td1, $td2, $td3, $td4)); } } $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody)); $table->setAttribute('id', 'sections-list'); $this->Form->appendChild($table); $tableActions = $this->createElement('div'); $tableActions->setAttribute('class', 'actions'); $options = array(array(NULL, false, __('With Selected...')), array('delete', false, __('Delete'), 'confirm'), array('delete-entries', false, __('Delete Entries'), 'confirm')); $tableActions->appendChild(Widget::Select('with-selected', $options)); $tableActions->appendChild(Widget::Input('action[apply]', __('Apply'), 'submit')); $this->Form->appendChild($tableActions); }
public static function clearCachedFiles() { self::$sections = array(); }
private function __form() { $this->insertNodeIntoHead($this->createStylesheetElement(URL . '/extensions/aac/assets/roles.css')); $this->insertNodeIntoHead($this->createScriptElement(URL . '/extensions/aac/assets/roles.js')); // The "symphony.selectable.js" messes up the checkboxes, so remove it foreach ($this->xpath("//head/script[contains(@src, 'symphony/assets/js/symphony.selectable.js')]") as $element) { $element->parentNode->removeChild($element); } if (!in_array($this->_context[0], array('new', 'edit'))) { throw new AdministrationPageNotFoundException(); } $callback = Administration::instance()->getPageCallback(); if (isset($callback['flag'])) { switch ($callback['flag']) { case 'saved': $this->alerts()->append(__('Role updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/extension/aac/roles/new/', ADMIN_URL . '/extension/aac/roles/')), AlertStack::SUCCESS); break; case 'created': $this->alerts()->append(__('Role created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Roles</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), ADMIN_URL . '/extension/aac/roles/new/', ADMIN_URL . '/extension/aac/roles/')), AlertStack::SUCCESS); break; } } /********** INSERT logic for determining the current role and whether the user has permission to edit it **********/ $this->setTitle(__($this->_context[0] == 'new' ? '%1$s – %2$s – Untitled' : '%1$s – %2$s – %3$s', array(__('Symphony'), __('Roles'), $this->role->name))); $this->appendSubheading($this->_context[0] == 'new' ? __('Untitled') : $this->role->name); // SETUP PAGE $layout = new Layout(); $left = $layout->createColumn(Layout::SMALL); $middle = $layout->createColumn(Layout::LARGE); $right = $layout->createColumn(Layout::LARGE); /** ESSENTIALS **/ $fieldset = Widget::Fieldset(__('Essentials')); $label = Widget::Label(__('Name')); $label->appendChild(Widget::Input('fields[name]', $this->role->name)); $fieldset->appendChild(isset($this->errors->name) ? Widget::wrapFormElementWithError($label, $this->errors->name) : $label); $label = Widget::Label(__('Description')); $label->appendChild(Widget::Textarea('fields[description]', $this->role->description, array('rows' => 7, 'cols' => 50))); $fieldset->appendChild(isset($this->errors->description) ? Widget::wrapFormElementWithError($label, $this->errors->description) : $label); $left->appendChild($fieldset); /// PUBLISHING PERMISSIONS $fieldset = Widget::Fieldset(__('Publishing Permissions')); $sections = new SectionIterator(); if ($sections->length() <= 0) { $p = $this->createElement('p', 'No sections exist. '); $p->appendChild(Widget::Anchor(__('Create one'), ADMIN_URL . '/sections/new/')); $fieldset->appendChild($p); } else { $thead = array(array(__('Section'), 'col'), array(__('Create'), 'col', array('class' => 'checkbox')), array(__('Edit'), 'col', array('class' => 'checkbox'))); $tbody = array(); /* // TODO: Global permissions set all permissions $td1 = Widget::TableData(__('Global Permissions')); $td2 = Widget::TableData( Widget::Input('global-add', '1', 'checkbox'), array('class' => 'checkbox') ); $td3 = Widget::TableData(NULL, array('class' => 'edit')); $td3->appendChild($this->createElement('p', NULL, array('class' => 'global-slider'))); $td3->appendChild($this->createElement('span', 'n/a')); $tbody[] = Widget::TableRow(array($td1, $td2, $td3), array('class' => 'global')); */ foreach ($sections as $section) { $td1 = Widget::TableData($section->name); // TODO: Remove this and implement sliders $td2 = Widget::TableData(); $td2->appendChild(Widget::Input("fields[permissions][publish::{$section->handle}][create]", '0', 'checkbox', array('checked' => 'checked', 'style' => 'display: none;'))); $td2->appendChild(Widget::Input("fields[permissions][publish::{$section->handle}][create]", '1', 'checkbox', (int) $this->role->permissions()->{"publish::{$section->handle}.create"} > 0 ? array('checked' => 'checked') : NULL)); $edit_level = (int) $this->role->permissions()->{"publish::{$section->handle}.edit"}; $td3 = Widget::TableData(Widget::Select("fields[permissions][publish::{$section->handle}][edit]", array(array('0', false, 'None'), array(1, $edit_level == 1, 'Own'), array(2, $edit_level == 2, 'All')))); /* $td2 = Widget::TableData( Widget::Input( "fields[permissions][{$section->handle}][create]", '1', 'checkbox', ($permissions['create'] == 1 ? array('checked' => 'checked') : array()) ), array('class' => 'checkbox') ); $td3 = Widget::TableData(NULL, array('class' => 'edit')); $td3->appendChild($this->createElement('p', NULL, array('class' => 'slider'))); $td3->appendChild( $this->createElement('span', '') ); $td3->appendChild( Widget::Input('fields[permissions][' . $section->handle .'][edit]', (isset($permissions['edit']) ? $permissions['edit'] : '0'), 'hidden' ) ); */ $tbody[] = Widget::TableRow(array($td1, $td2, $td3)); } $table = Widget::Table(Widget::TableHead($thead), NULL, Widget::TableBody($tbody), array('id' => 'role-permissions')); $fieldset->appendChild($table); $right->appendChild($fieldset); } /// BLUEPRINTS PERMISSIONS $fieldset = Widget::Fieldset(__('Blueprints Permissions')); $thead = array(array(__('Area'), 'col'), array(__('Create'), 'col', array('class' => 'checkbox')), array(__('Edit'), 'col', array('class' => 'checkbox'))); $tbody = array(); $areas = array('sections' => 'Sections', 'datasources' => 'Data Sources', 'events' => 'Events', 'views' => 'Views', 'utilities' => 'Utilities'); foreach ($areas as $key => $name) { $td1 = Widget::TableData($name); $td2 = Widget::TableData(Widget::Input("fields[permissions][blueprints::{$key}][create]", '1', 'checkbox', (int) $this->role->permissions()->{"blueprints::{$key}.create"} > 0 ? array('checked' => 'checked') : NULL)); $td3 = Widget::TableData(Widget::Input("fields[permissions][blueprints::{$key}][edit]", '1', 'checkbox', (int) $this->role->permissions()->{"blueprints::{$key}.edit"} > 0 ? array('checked' => 'checked') : NULL)); $tbody[] = Widget::TableRow(array($td1, $td2, $td3)); } $table = Widget::Table(Widget::TableHead($thead), NULL, Widget::TableBody($tbody), array('id' => 'role-permissions')); $fieldset->appendChild($table); $middle->appendChild($fieldset); /// SYSTEM PERMISSIONS $fieldset = Widget::Fieldset(__('System Permissions')); $tbody = array(); $items = array('Access Settings' => array('settings', 'access', 1), 'Access Extensions' => array('extensions', 'access', 1), 'Create New Users' => array('users', 'create', 1)); foreach ($items as $name => $item) { list($key, $type, $level) = $item; $td1 = Widget::TableData($name); $td2 = Widget::TableData(Widget::Input("fields[permissions][system::{$key}][{$type}]", (string) $level, 'checkbox', (int) $this->role->permissions()->{"system::{$key}.{$type}"} > 0 ? array('checked' => 'checked') : NULL)); $tbody[] = Widget::TableRow(array($td1, $td2)); } $user_edit_level = (int) $this->role->permissions()->{"system::users.edit"}; $td1 = Widget::TableData('Edit User Profiles'); $td2 = Widget::TableData(Widget::Select("fields[permissions][system::users][edit]", array(array('0', false, 'None'), array(1, $user_edit_level == 1, 'Own'), array(2, $user_edit_level == 2, 'All')))); $tbody[] = Widget::TableRow(array($td1, $td2)); $td1 = Widget::TableData('Change Users Role'); $td2 = Widget::TableData(Widget::Input("fields[permissions][system::users][change-role]", (string) $level, 'checkbox', (int) $this->role->permissions()->{"system::users.change-role"} > 0 ? array('checked' => 'checked') : NULL)); $tbody[] = Widget::TableRow(array($td1, $td2)); $table = Widget::Table(NULL, NULL, Widget::TableBody($tbody), array('id' => 'role-permissions')); $fieldset->appendChild($table); $middle->appendChild($fieldset); /********** BUILD view list and set up permissions interface **********/ $layout->appendTo($this->Form); /** FORM ACTIONS **/ $div = $this->createElement('div'); $div->setAttribute('class', 'actions'); $div->appendChild(Widget::Submit('action[save]', $this->_context[0] == 'edit' ? __('Save Changes') : __('Create Role'), array('accesskey' => 's'))); if ($this->_context[0] == 'edit' && !$isOwner) { $div->appendChild(Widget::Submit('action[delete]', __('Delete'), array('class' => 'confirm delete', 'title' => __('Delete this role')))); } $this->Form->appendChild($div); }