Пример #1
0
 /**
  * Display some RSS options, and a list of the current feeds
  *
  * @return string
  */
 public function indexSection()
 {
     if (!$this->_acl->check('rss_edit')) {
         throw new Module_NoPermission();
     }
     $this->setTitle(t('RSS configuration'));
     $this->setOutputType(self::_OT_CONFIG);
     /**
      * Prepare form validation
      */
     $form = new View_Form('config/main.html', 'rss');
     $form->addElement('rss/global', (bool) $this->_config->get('rss/global_agg_enable'), t('Global aggregation'), new Validator_Bool());
     $form->addElement('rss/default', $this->_config->get('rss/default_feed'), t('Default feed'), new Validator_Alphanumeric('_-'));
     $form->addElement('rss/items', $this->_config->get('rss/items_per_feed'), t('Number of items'), new Validator_Numeric());
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('rss');
         // Check default feed given is valid
         if ($fd['default'] != 0 && !in_array($fd['default'], array_keys($this->feeds))) {
             $this->_event->error(t('Please select a valid default RSS feed.'));
         } else {
             $this->_config_sql->update(array('rss/global_agg_enable', 'rss/items_per_feed', 'rss/default_feed'), array($fd['global'], $fd['items'], $fd['default']));
             $this->_event->success(t('Updated RSS configuration'));
             return zula_redirect($this->_router->makeUrl('rss', 'config'));
         }
     }
     // Add additional data
     $form->assign(array('RSS_FEEDS' => $this->feeds));
     return $form->getOutput();
 }
Пример #2
0
 /**
  * Add the first user which will be created in the special
  * 'root' group.
  *
  * @return bool|string
  */
 public function indexSection()
 {
     $this->setTitle(t('First user'));
     if ($this->_zula->getMode() != 'cli' && (!isset($_SESSION['installStage']) || $_SESSION['installStage'] !== 3)) {
         return zula_redirect($this->_router->makeUrl('install', 'checks'));
     }
     // Get data from either a form or CLI arguments
     if ($this->_zula->getMode() == 'cli') {
         $data = array('username' => $this->_input->cli('u'), 'password' => $this->_input->cli('p'), 'email' => $this->_input->cli('e'));
     } else {
         $form = new View_Form('user.html', 'install');
         $form->addElement('username', null, t('Username'), array(new Validator_Alphanumeric('_-'), new Validator_Length(2, 32)));
         $form->addElement('password', null, t('Password'), array(new Validator_Length(4, 32), new Validator_Confirm('password2', Validator_Confirm::_POST)));
         $form->addElement('email', null, t('Email'), array(new Validator_Email(), new Validator_Confirm('email2', Validator_Confirm::_POST)));
         if ($form->hasInput() && $form->isValid()) {
             $data = $form->getValues();
         } else {
             return $form->getOutput();
         }
     }
     if (strcasecmp($data['username'], 'guest') === 0) {
         $this->_event->error(t('Username of "guest" is invalid'));
         if (isset($form)) {
             return $form->getOutput();
         } else {
             $this->_zula->setExitCode(3);
             return false;
         }
     }
     $this->_ugmanager->editUser(2, $data);
     if (isset($_SESSION['installStage'])) {
         ++$_SESSION['installStage'];
     }
     $this->_event->success(t('First user has been created'));
     return zula_redirect($this->_router->makeUrl('install', 'modules'));
 }
Пример #3
0
 /**
  * Change settings regarding themeing and style
  *
  * @return string
  */
 public function settingsSection()
 {
     $this->setTitle(t('Theme settings'));
     $this->setOutputType(self::_OT_CONFIG);
     // Prepare form validation
     $form = new View_Form('settings.html', 'theme');
     $form->addElement('theme/allow_user_override', $this->_config->get('theme/allow_user_override'), t('Allow user override'), new Validator_Bool());
     if ($form->hasInput() && $form->isValid()) {
         $allowOverride = $form->getValues('theme/allow_user_override');
         try {
             $this->_config_sql->update('theme/allow_user_override', $allowOverride);
         } catch (Config_KeyNoExist $e) {
             $this->_config_sql->add('theme/allow_user_override', $allowOverride);
         }
         $this->_event->success(t('Updated theme settings'));
         return zula_redirect($this->_router->makeUrl('theme', 'index', 'settings'));
     }
     return $form->getOutput();
 }
Пример #4
0
 /**
  * Builds the correct view form for either adding or editing
  * a menu item, can also add in default values.
  *
  * @param int $cid
  * @param string $name
  * @param string $parentHeading
  * @param string $url
  * @param string $attrTitle
  * @param string $itemId
  * @return object
  */
 protected function buildItemForm($cid, $name = null, $parentHeading = 0, $url = null, $attrTitle = null, $itemId = null)
 {
     if (is_null($itemId)) {
         $op = 'add';
         $aclResource = 'menu-item';
     } else {
         $op = 'edit';
         $aclResource = 'menu-item-' . $itemId;
     }
     // Build form and validation
     $form = new View_Form('config/form_item.html', 'menu', is_null($itemId));
     $form->addElement('menu/id', $itemId, 'ID', new Validator_Int(), $op == 'edit');
     $form->addElement('menu/cat_id', $cid, 'Cat ID', new Validator_Int(), $op == 'add');
     $form->addElement('menu/name', $name, t('Name'), new Validator_Length(1, 64));
     $form->addElement('menu/parent', $parentHeading, t('Parent'), new Validator_Numeric());
     $form->addElement('menu/url', $url, 'URL', new Validator_Length(0, 255));
     $form->addElement('menu/attr_title', $attrTitle, t('Attribute Text'), new Validator_Length(0, 255));
     // Add additional vars
     $form->assign(array('OP' => $op, 'HEADINGS' => zula_array_flatten($this->_model()->getAllItems($cid), 'children')));
     $form->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View menu item') => $aclResource))));
     return $form;
 }
Пример #5
0
 /**
  * Builds the view form to add/edit a user
  *
  * @param array $details
  * @return object
  */
 protected function buildUserForm(array $details = array())
 {
     $op = empty($details['id']) ? 'add' : 'edit';
     $details = zula_merge_recursive(array('id' => null, 'username' => null, 'status' => 'active', 'group' => null, 'first_name' => null, 'last_name' => null, 'email' => null, 'hide_email' => true), $details);
     // Build form and validation
     $form = new View_Form('config/user_form.html', 'users', empty($details['id']));
     $form->addElement('users/username', $details['username'], t('Username'), array(new Validator_Alphanumeric('_()!:@.^-'), new Validator_Length(2, 32), array($this, 'validateUsername')));
     $form->addElement('users/status', $details['status'], t('Status'), new Validator_InArray(array('active', 'locked')));
     $form->addElement('users/group', $details['group'], t('Group'), new Validator_Int(), false);
     $form->addElement('users/first_name', $details['first_name'], t('First name'), new Validator_Length(0, 255));
     $form->addElement('users/last_name', $details['last_name'], t('Last name'), new Validator_Length(0, 255));
     $form->addElement('users/password', null, t('Password'), array(new Validator_Length(4, 32), new Validator_Confirm('users_password_confirm', Validator_Confirm::_POST)), empty($details['id']));
     $form->addElement('users/hide_email', $details['hide_email'], t('Hide email'), new Validator_Bool());
     // Email validation, we still want to display email when editing remember
     $emailValidation = array(new Validator_Email());
     if ($op == 'add' || $this->_input->has('post', 'users_email_confirm') && $this->_input->post('users_email_confirm')) {
         $emailValidation[] = new Validator_Confirm('users_email_confirm', Validator_Confirm::_POST);
     }
     $form->addElement('users/email', $details['email'], t('Email'), $emailValidation);
     $form->assign(array('OP' => $op, 'ID' => $details['id']));
     return $form;
 }
Пример #6
0
 /**
  * Builds the form view that will allow users to add or edit a page.
  *
  * @param int $parent
  * @param int $id
  * @param string $title
  * @param string $body
  * @param bool $isQuickEdit
  * @return object
  */
 protected function buildForm($parent = null, $id = null, $title = null, $body = null, $isQuickEdit = false)
 {
     $parent = abs($parent);
     $validParents = array(0, $parent);
     if ($id === null) {
         $op = 'add';
     } else {
         $op = 'edit';
         /**
          * Gather all children and find out all possible parents that this page
          * can be part of, not including sub-children of its self.
          */
         $children = $this->_model()->getChildren($id);
         if ($parent) {
             $treePath = $this->_model()->findPath($id);
             $possibleParents = $this->_model()->getChildren($treePath[0]['id'], true, array($id));
             array_unshift($possibleParents, $treePath[0]);
         } else {
             $possibleParents = $this->_model()->getAllPages(0, 0, $parent);
         }
         foreach ($possibleParents as $key => $tmpParent) {
             if ($this->_acl->check('page-manage_' . $tmpParent['id']) && $tmpParent['id'] != $id) {
                 if (!isset($tmpParent['depth'])) {
                     $possibleParents[$key]['depth'] = 0;
                 }
                 $validParents[] = $tmpParent['id'];
             } else {
                 unset($possibleParents[$key]);
             }
         }
     }
     // Setup the correct ACL resources
     if ($id === null || $this->_acl->check('page-manage_' . $id)) {
         $aclForm = $this->_acl->buildForm(array(t('View page') => 'page-view_' . $id, t('Edit page') => array('page-edit_' . $id, 'group_admin'), t('Delete, edit, add subpages & manage permissions') => array('page-manage_' . $id, 'group_admin')));
     } else {
         $aclForm = null;
     }
     // Build up the form
     $form = new View_Form('config/form_page.html', 'page', $op == 'add');
     $form->addElement('page/id', $id, 'ID', new Validator_Int(), $op == 'edit');
     $form->addElement('page/title', $title, t('Title'), new Validator_Length(2, 255));
     $form->addElement('page/parent', $parent, t('Parent'), new Validator_InArray($validParents), !empty($parent));
     $form->addElement('page/body', $body, t('Body'), new Validator_Length(1, 50000));
     $form->assign(array('OP' => $op, 'PARENTS' => isset($possibleParents) ? $possibleParents : null, 'QUICK_EDIT' => $isQuickEdit));
     $form->assignHtml(array('ACL_FORM' => $aclForm, 'CHILDREN' => empty($children) ? null : $this->createChildRows($children)));
     return $form;
 }
Пример #7
0
 /**
  * Builds a form that allows users to add or edit a category
  * and can fill the values with default values
  *
  * @param string $title
  * @param string $desc
  * @param int $id
  * @return string
  */
 protected function buildCategoryForm($title = null, $desc = null, $id = null)
 {
     $op = is_null($id) ? 'add' : 'edit';
     $form = new View_Form('config/form_category.html', 'article', is_null($id));
     $form->action($this->_router->makeUrl('article', 'config', $op . 'cat', null, array('id' => $id)));
     $form->addElement('article/title', $title, t('Title'), new Validator_Length(1, 255));
     $form->addElement('article/description', $desc, t('Description'), new Validator_Length(0, 255));
     // Set op and other tags
     $form->assign(array('OP' => $op, 'ID' => $id));
     $resource = $op == 'edit' ? 'article-cat-' . $id : 'article-cat';
     $form->assignHtml(array('ACL_FORM' => $this->_acl->buildForm(array(t('View category') => $resource))));
     return $form;
 }
Пример #8
0
 /**
  * Displays and handles the form for new users to register an account
  *
  * @return string
  */
 public function indexSection()
 {
     $this->setTitle(t('Register an account'));
     // Check that registrations are actually available
     if ($this->_config->get('session/allow_register') == false) {
         throw new Module_ControllerNoExist();
     } else {
         if ($this->_config->get('session/force_https')) {
             $formUrl = $this->_router->makeUrl('session', 'register')->makeFull('&', null, true);
             if ($this->_router->getScheme() != 'https') {
                 return zula_redirect($formUrl);
             }
         } else {
             $formUrl = $this->_router->makeUrl('session', 'register');
         }
     }
     // Build the form and prepare validation
     $form = new View_Form('register/form.html', 'session');
     $form->action($formUrl)->antispam(true);
     $form->addElement('session/username', null, t('Username'), array(new Validator_Alphanumeric('_()!:@.^-'), new Validator_Length(2, 32), array($this, 'validateUsername')));
     $form->addElement('session/password', null, t('Password'), array(new Validator_Length(4, 64), new Validator_Confirm('session/password_confirm', Validator_Confirm::_POST)));
     $form->addElement('session/email', null, t('Email'), array(new Validator_Email(), new Validator_Confirm('session/email_confirm', Validator_Confirm::_POST), array($this, 'validateEmail')));
     $form->addElement('session/terms_agree', null, t('Terms'), new Validator_Bool(), false);
     if ($form->hasInput()) {
         if ($this->_config->get('session/register_terms') && !$this->_input->has('post', 'session/terms')) {
             $this->_event->error(t('Please agree to the terms and conditions'));
             $hasTerms = false;
         } else {
             $hasTerms = true;
         }
         if ($form->isValid() && $hasTerms) {
             /**
              * Attempt to add the new user and send correct email
              */
             $fd = $form->getValues('session');
             $userDetails = array('status' => 'locked', 'username' => $fd['username'], 'password' => $fd['password'], 'email' => $fd['email'], 'group' => $this->_config->get('session/register_group'), 'activate_code' => zula_create_key());
             $validationMethod = $this->_config->get('session/validation_method');
             switch ($validationMethod) {
                 case 'none':
                     $userDetails['status'] = 'active';
                     $userDetails['activate_code'] = '';
                     $eventMsg = t('Successfully registered, you may now login.');
                     break;
                 case 'admin':
                     $eventMsg = t('Successfully registered, an admin will review your registration shortly.');
                     break;
                 case 'user':
                 default:
                     $validationMethod = 'user';
                     # Ensure a known validation method.
                     $eventMsg = t('Successfully registered, an email has been sent to confirm your registration.');
             }
             // Add the new user and attempt to send the email.
             $uid = $this->_ugmanager->addUser($userDetails);
             try {
                 $msgView = $this->loadView('register/validation_' . $validationMethod . '.txt');
                 $msgView->assign($userDetails);
                 $message = new Email_Message(t('Account Details'), $msgView->getOutput());
                 $message->addTo($userDetails['email']);
                 $email = new Email();
                 $email->send($message);
                 // All done, redirect user
                 $this->_event->success($eventMsg);
                 return zula_redirect($this->_router->makeUrl('session'));
             } catch (Email_Exception $e) {
                 $this->_ugmanager->deleteUser($uid);
                 $this->_event->error(t('An error occurred while sending the email. Please try again later'));
                 $this->_log->message('Unable to send registration email: ' . $e->getMessage(), Log::L_WARNING);
             }
         }
     }
     // Add T&Cs then output the form
     $form->assign(array('TERMS' => $this->_config->get('session/register_terms')));
     return $form->getOutput();
 }
Пример #9
0
 /**
  * Provides ability to add a new content layout. The user will
  * be redirect to the page, as if they had gone 'Edit' on the
  * layout once it has been created.
  *
  * @return string
  */
 public function addSection()
 {
     $this->setTitle(t('Add new layout'));
     $this->setOutputType(self::_OT_CONFIG);
     try {
         $cloner = $this->_router->getArgument('clone');
         $cloner = new Layout($cloner);
         if ($cloner->exists()) {
             $cloneName = $cloner->getName();
             $cloneRegex = $cloner->getRegex();
             $this->setTitle(sprintf(t('Clone layout "%1$s"'), $cloneName));
         } else {
             throw new Exception();
         }
     } catch (Exception $e) {
         $cloneName = null;
         $cloneRegex = null;
     }
     // Build and check form
     $form = new View_Form('index/form_layout.html', 'content_layout');
     $form->action($this->_router->makeUrl('content_layout', 'index', 'add'));
     $form->addElement('content_layout/name', null, t('Name'), array(new Validator_Alphanumeric('-'), new Validator_Length(2, 225)));
     $form->addElement('content_layout/regex', $cloneRegex, t('URL/Regex'), new Validator_Length(2, 255));
     $form->addElement('content_layout/site_type', $this->_router->getDefaultSiteType(), t('Site type'), new Validator_InArray($this->_router->getSiteTypes()));
     $form->addElement('content_layout/clone', $cloneName, t('Clone'), array(new Validator_Alphanumeric('-'), new Validator_Length(0, 225)));
     if ($form->hasInput() && $form->isValid()) {
         $fd = $form->getValues('content_layout');
         // Check if we are cloning a layout
         if ($fd['clone']) {
             $layout = new Layout($fd['clone']);
             $layout->setName($fd['site_type'] . '-' . $fd['name']);
         } else {
             $layout = new Layout($fd['site_type'] . '-' . $fd['name']);
         }
         $layout->setRegex($fd['regex']);
         $path = $this->_zula->getDir('config') . '/layouts/' . $layout->getName() . '.xml';
         if ($layout->save($path)) {
             $this->_event->success(t('Added new content layout'));
             return zula_redirect($this->_router->makeUrl('content_layout', 'manage', $layout->getName()));
         }
         $this->_event->error(t('Unable to save content layout'));
     }
     return $form->getOutput();
 }
Пример #10
0
 /**
  * Builds the view for adding/editing a field
  *
  * @param int $fid
  * @param string $name
  * @param bool $required
  * @param string $type
  * @param string $options
  * @param int $id
  * @return string
  */
 protected function buildFieldForm($fid = null, $name = null, $required = false, $type = null, $options = null, $id = null)
 {
     if ($id === null) {
         $op = 'add';
         $args = array('id' => $fid);
     } else {
         $op = 'edit';
         $args = array('id' => $id);
     }
     $form = new View_Form('config/field_form.html', 'contact', is_null($id));
     $form->action($this->_router->makeUrl('contact', 'config', $op . 'field', null, $args));
     $form->addElement('contact/name', $name, t('Name'), new Validator_Length(1, 255));
     $form->addElement('contact/required', $required, t('Required'), new Validator_Bool());
     $form->addElement('contact/type', $type, t('Type'), new Validator_Alphanumeric());
     $form->addElement('contact/options', $options, t('Options'), new Validator_Length(0, 255));
     // Assign some additional tags
     $form->assign(array('OP' => $op, 'FORM_ID' => $fid, 'ID' => $id, 'TYPES' => array('textbox' => t('Textbox'), 'textarea' => t('Textarea'), 'radio' => t('Radio options'), 'checkbox' => t('Checkbox'), 'select' => t('Drop down Menu'), 'password' => t('Password textbox'))));
     return $form;
 }
Пример #11
0
 /**
  * Gathers all details needed to connect to the database
  * and create the initial tables to populate.
  *
  * The config.ini.php file also gets updated with the SQL
  * details and others such as hashing salt and router type.
  *
  * @return bool|string
  */
 public function indexSection()
 {
     $this->setTitle(t('SQL details'));
     if ($this->_zula->getMode() != 'cli' && (!isset($_SESSION['installStage']) || $_SESSION['installStage'] !== 2)) {
         return zula_redirect($this->_router->makeUrl('install', 'checks'));
     }
     // Get data from either a form or CLI arguments
     if ($this->_zula->getMode() == 'cli') {
         $dsn = parse_url($this->_input->cli('dsn'));
         if (isset($dsn['scheme'], $dsn['host'], $dsn['user'], $dsn['path'])) {
             $data = array('type' => $dsn['scheme'], 'user' => $dsn['user'], 'pass' => isset($dsn['pass']) ? $dsn['pass'] : '', 'host' => $dsn['host'], 'port' => isset($dsn['port']) ? $dsn['port'] : 3306, 'dbname' => ltrim($dsn['path'], '/'), 'prefix' => $this->_input->cli('dbPrefix'));
         } else {
             $this->_event->error(t('Invalid DSN string'));
             $this->_zula->setExitCode(3);
             return false;
         }
     } else {
         $form = new View_Form('sql.html', 'install');
         $form->addElement('user', null, t('Username'), new Validator_Length(1, 16));
         $form->addElement('pass', null, t('Password'), array(new Validator_Length(0, 64), new Validator_Regex('#^[^"]*$#')));
         $form->addElement('host', 'localhost', t('SQL host'), new Validator_Length(1, 80));
         $form->addElement('port', 3306, t('SQL Port'), new Validator_Int());
         $form->addElement('dbname', null, t('SQL Database'), new Validator_Length(1, 64));
         $form->addElement('prefix', 'tcm_', t('Table prefix'), array(new Validator_Length(0, 12), new Validator_Alphanumeric('_-')));
         if ($form->hasInput() && $form->isValid()) {
             $data = $form->getValues();
             $data['type'] = 'mysql';
         } else {
             return $form->getOutput();
         }
     }
     try {
         $sql = new SQL($data['type'], $data['dbname'], $data['host'], $data['user'], $data['pass'], $data['port']);
         $sql->setPrefix($data['prefix']);
         $sql->query("SET NAMES 'utf8'");
         # Use UTF-8 character set for the connection
         $sql->loadSqlFile($this->getPath() . '/schema.sql');
         /**
          * Update config.ini.php file with the new values
          */
         $confKeys = array('sql/enable' => true, 'sql/host' => $data['host'], 'sql/user' => $data['user'], 'sql/pass' => $data['pass'], 'sql/database' => $data['dbname'], 'sql/type' => $data['type'], 'sql/prefix' => $data['prefix'], 'sql/port' => $data['port'], 'hashing/salt' => zula_make_salt(), 'acl/enable' => true);
         if ($this->_input->has('get', 'ns')) {
             $confKeys['url_router/type'] = 'standard';
         }
         $this->_config_ini->update(array_keys($confKeys), array_values($confKeys));
         try {
             $this->_config_ini->writeIni();
             if (isset($_SESSION['installStage'])) {
                 ++$_SESSION['installStage'];
             }
             $this->_event->success(t('Initial database tables have been created'));
             return zula_redirect($this->_router->makeUrl('install', 'user'));
         } catch (Config_ini_FileNotWriteable $e) {
             $this->_event->error($e->getMessage());
         }
     } catch (SQL_UnableToConnect $e) {
         $this->_event->error(t('Unable to connect to, or select SQL database'));
     }
     if (isset($form)) {
         return $form->getOutput();
     } else {
         $this->_zula->setExitCode(3);
         return false;
     }
 }
Пример #12
0
 /**
  * Allows the current user to edit account details, such as password and email.
  *
  * @return string
  */
 public function settingsSection()
 {
     if (!$this->_session->isLoggedIn()) {
         throw new Module_NoPermission();
     }
     $this->setTitle(t('Edit account settings'));
     // Gather user details
     $this->displayPageLinks();
     $user = $this->_session->getUser();
     if (!isset($user['theme'])) {
         $user['theme'] = null;
     }
     /**
      * Prepare form validation
      */
     $form = new View_Form('profile/settings.html', 'users');
     $form->addElement('users/passwd/current', null, t('Current password'), array(array($this, 'validatePassword')));
     $form->addElement('users/passwd/new', null, t('Password'), array(new Validator_Length(4, 32), new Validator_Confirm('users/passwd/conf', Validator_Confirm::_POST)), false);
     $form->addElement('users/hide_email', $user['hide_email'], t('Hide email'), new Validator_Bool());
     $form->addElement('users/theme', $user['theme'], t('Theme name'), new Validator_InArray(Theme::getAll()), false);
     try {
         // Add Email validation if needed
         $emailConf = $this->_input->post('users/email_confirm');
         if ($emailConf) {
             $form->addElement('users/email', $user['email'], t('Email'), array(new Validator_Email(), new Validator_Confirm($emailConf)));
         } else {
             throw new Exception();
         }
     } catch (Exception $e) {
         $form->assign(array('USERS' => array('EMAIL' => $user['email'])));
     }
     if ($form->hasInput() && $form->isValid()) {
         try {
             $fd = $form->getValues('users');
             if (empty($fd['theme'])) {
                 $fd['theme'] = null;
             }
             $fd['password'] = $fd['passwd']['new'];
             unset($fd['passwd']);
             $this->_ugmanager->editUser($this->_session->getUserId(), $fd);
             $this->_event->success(t('Updated Profile'));
             return zula_redirect($this->_router->makeUrl('users', 'profile', 'settings'));
         } catch (Exception $e) {
             $this->_event->error($e->getMessage());
         }
     }
     return $form->getOutput();
 }
Пример #13
0
 /**
  * Builds the form for adding or editing a group
  *
  * @param int $id
  * @param string $name
  * @param int $inherits
  * @param int $roleId
  * @param string $status
  * @return object
  */
 protected function buildForm($id = null, $name = null, $inherits = null, $roleId = null, $status = 'active')
 {
     if (is_null($id)) {
         $op = 'add';
         $inherits = Ugmanager::_GUEST_GID;
         $groups = $this->_ugmanager->getAllGroups();
     } else {
         $op = 'edit';
         // Grab all groups that are not a child of the current one
         $invalidGid = array();
         foreach ($this->_acl->getRoleTree($roleId, true) as $child) {
             $invalidGid[] = $child['id'];
         }
         $groups = array();
         foreach ($this->_ugmanager->getAllGroups() as $group) {
             if (!in_array($group['role_id'], $invalidGid)) {
                 $groups[] = $group;
             }
         }
     }
     $form = new View_Form('form.html', 'groups', is_null($id));
     $form->addElement('group/name', $name, t('Group name'), array(new Validator_Alphanumeric(), new Validator_Length(1, 32)));
     $form->addElement('group/inherits', $inherits, t('Inheritance group'), new Validator_Numeric());
     $form->addElement('group/status', $status, t('Status'), new Validator_InArray(array('active', 'locked')));
     // Additional config data
     $form->assign(array('OP' => $op, 'ID' => $id, 'GROUPS' => $groups));
     return $form;
 }
Пример #14
0
 /**
  * Builds form for adding or editing a media category
  *
  * @param int $cid
  * @param string $name
  * @param string $desc
  * @return object
  */
 protected function buildCatForm($cid = null, $name = null, $desc = null)
 {
     $form = new View_Form('config/form_cat.html', 'media', is_null($cid));
     $form->addElement('media/name', $name, t('Name'), new Validator_Length(1, 255));
     $form->addElement('media/desc', $desc, t('Description'), new Validator_Length(0, 255));
     // Add additional data on
     $form->assign(array('OP' => is_null($cid) ? 'add' : 'edit'));
     $aclForm = $this->_acl->buildForm(array(t('View Media Category') => 'media-cat_view_' . $cid, t('Upload media items') => array('media-cat_upload_' . $cid, 'group_admin'), t('Edit/Delete media items') => array('media-cat_moderate_' . $cid, 'group_admin')));
     $form->assignHtml(array('ACL_FORM' => $aclForm));
     return $form;
 }