form ul.inline { margin-left:0; padding:0; }
form ul.inline li { float:left; padding-right:7px; }
+.checkgroup_master li {list-style: none outside none}
+.checkgroup_master li label {width:auto;float:none}
+
/* ALIGNED FIELDSETS */
.aligned label { display:block; padding:0 1em 3px 0; float:left; width:8em; }
.aligned label.inline { display:inline; float:none; }
<div id="footer"></div>
</div>
{block commonjs}
- {if isset($form) && method_exists($form, 'render_commonjs')}
- {$form.render_commonjs()|safe}
- {else}
- <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.js"></script>
- <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery-ui.custom.js"></script>
- <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/admin.js"></script>
- {/if}
+ <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery.js"></script>
+ <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/jquery-ui.custom.js"></script>
+ <script type="text/javascript" src="{$ADMIN_MEDIA_URL}js/admin.js"></script>
{/block}
{block scripts}{/block}
</body>
+++ /dev/null
-<?php
-
-class IPF_Auth_Forms_Widget_Permissions extends IPF_Form_Extra_Widget_CheckboxGroupInput
-{
- public function __construct($attrs=array())
- {
- if (isset($attrs['choices']))
- ksort($attrs['choices']);
-
- parent::__construct($attrs);
- }
-}
-
type: INNODB
collate: utf8_unicode_ci
charset: utf8
+---
Role:
tableName: auth_role
columns:
type: INNODB
collate: utf8_unicode_ci
charset: utf8
-
-
+---
Permission:
tableName: auth_permission
columns:
type: INNODB
collate: utf8_unicode_ci
charset: utf8
-
+---
RolePermission:
tableName: auth_role_permission
columns:
type: INNODB
collate: utf8_unicode_ci
charset: utf8
-
+---
UserRole:
tableName: auth_user_role
columns:
type: INNODB
collate: utf8_unicode_ci
charset: utf8
-
+---
UserPermission:
tableName: auth_user_permission
columns:
type: INNODB
collate: utf8_unicode_ci
charset: utf8
+---
+
return IPF_Auth_App::GetHumanNameOfPermission($this->name);
}
}
+
}
}
+class IPFAdminRoleForm extends IPF_Form_Model
+{
+ public function add__Permissions__field()
+ {
+ if (!IPF_Auth_App::ArePermissionsEnabled())
+ return;
+
+ $choices = array();
+ foreach (IPF_ORM::getTable('Permission')->findAll() as $o)
+ $choices[$o->__toString()] = $o->id;
+ ksort($choices);
+
+ $field = new IPF_Form_Field_ModelMultipleChoice(array(
+ 'required' => false,
+ 'label' => 'Permissions',
+ 'help_text' => '',
+ 'type' => 'manytomany',
+ 'editable' => true,
+ 'model' => 'Permission',
+ 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+ 'choices' => $choices,
+ 'widget_attrs' => array('class' => 'checkgroup'),
+ ));
+
+ $this->fields['Permissions'] = $field;
+ }
+
+ public function extra_js()
+ {
+ $extra_js = parent::extra_js();
+ if (IPF_Auth_App::ArePermissionsEnabled())
+ $extra_js[] = '<script type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/checkall.js"></script>';
+ return array_unique($extra_js);
+ }
+}
+
class AdminRole extends IPF_Admin_Model
{
public function list_display()
protected function _getForm($model_obj, $data, $extra)
{
$extra['model'] = $model_obj;
- $extra['checkgroup_fields'] = array(
- 'Permissions' => array('widget'=>'IPF_Auth_Forms_Widget_Permissions'),
- );
- return new IPF_Form_Extra_CheckGroup($data, $extra);
- }
-
- protected function _setupForm($form)
- {
- IPF_Form_Extra_CheckGroup::SetupForm($form);
+ return new IPFAdminRoleForm($data, $extra);
}
public function page_title() { return 'Group'; }
public function verbose_name() { return 'Group'; }
}
-IPF_Admin_Model::register('Role','AdminRole');
+IPF_Admin_Model::register('Role', 'AdminRole');
+
<?php
-/**
- * This class has been auto-generated by the IPF ORM Framework
- */
class RolePermission extends BaseRolePermission
{
+}
-}
\ No newline at end of file
<?php
-class IPFAuthAdminUserForm extends IPF_Form_Extra_CheckGroup
+class IPFAuthAdminUserForm extends IPF_Form_Model
{
function initFields($extra=array())
{
parent::initFields($extra);
-
+
$this->fields['email']->label = 'E-mail';
-
+
$this->fields['is_active']->label = 'Active';
$this->fields['is_staff']->label = 'Staff status';
$this->fields['is_superuser']->label = 'Superuser status';
$this->fields['is_active']->help_text = 'Designates whether this user should be treated as active. Unselect this instead of deleting accounts.';
$this->fields['is_staff']->help_text = 'Designates whether the user can log into this admin site.';
$this->fields['is_superuser']->help_text = 'Designates that this user has all permissions without explicitly assigning them.';
-
+
$this->fields['username']->help_text = 'Required. 32 characters or less. Alphanumeric characters only (letters, digits and underscores).';
-
- if (!$this->model->id)
- {
+
+ if (!$this->model->id) {
unset($this->fields['password']);
-
+
$this->fields['password1'] = new IPF_Form_Field_Varchar(array(
'label' => 'Password',
'required' => true,
'max_length' => 32,
'widget' => 'IPF_Form_Widget_PasswordInput'
));
-
+
$this->fields['password2'] = new IPF_Form_Field_Varchar(array(
'label' => 'Password (again)',
'required' => true,
'widget' => 'IPF_Form_Widget_PasswordInput',
'help_text' => 'Enter the same password as above, for verification.'
));
-
+
$account = array('username', 'password1', 'password2');
- }
- else
- {
+ } else {
$this->fields['password']->help_text = "Use '[algo]$[salt]$[hexdigest]' or use the <a href=\"password/\">change password form</a>.";
-
+
$account = array('username', 'password');
}
if (IPF_Auth_App::ArePermissionsEnabled()) {
$permissions[] = 'Permissions';
$permissions[] = 'Roles';
-
- $this->fields['Roles']->label = 'Groups';
- $this->fields['Roles']->help_text = 'In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.';
-
- parent::SetupForm($this);
- } else {
- unset($this->fields['Permissions']);
- unset($this->fields['Roles']);
}
$this->field_groups = array(
array('fields' => $permissions, 'label' => 'Permissions'),
);
}
-
+
+ public function add__Permissions__field()
+ {
+ if (!IPF_Auth_App::ArePermissionsEnabled())
+ return;
+
+ $choices = array();
+ foreach (IPF_ORM::getTable('Permission')->findAll() as $o)
+ $choices[$o->__toString()] = $o->id;
+ ksort($choices);
+
+ $field = new IPF_Form_Field_ModelMultipleChoice(array(
+ 'required' => false,
+ 'label' => 'Permissions',
+ 'help_text' => '',
+ 'type' => 'manytomany',
+ 'editable' => true,
+ 'model' => 'Permission',
+ 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+ 'choices' => $choices,
+ 'widget_attrs' => array('class' => 'checkgroup'),
+ ));
+
+ $this->fields['Permissions'] = $field;
+ }
+
+ public function add__Roles__field()
+ {
+ if (!IPF_Auth_App::ArePermissionsEnabled())
+ return;
+
+ $choices = array();
+ foreach (IPF_ORM::getTable('Role')->findAll() as $o)
+ $choices[$o->__toString()] = $o->id;
+
+ $field = new IPF_Form_Field_ModelMultipleChoice(array(
+ 'required' => false,
+ 'label' => 'Groups',
+ 'help_text' => 'In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in.',
+ 'type' => 'manytomany',
+ 'editable' => true,
+ 'model' => 'Role',
+ 'widget' => 'IPF_Form_Widget_SelectMultipleInputCheckbox',
+ 'choices' => $choices,
+ 'widget_attrs' => array('class' => 'checkgroup'),
+ ));
+
+ $this->fields['Roles'] = $field;
+ }
+
+ public function extra_js()
+ {
+ $extra_js = parent::extra_js();
+ if (IPF_Auth_App::ArePermissionsEnabled())
+ $extra_js[] = '<script type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/checkall.js"></script>';
+ return array_unique($extra_js);
+ }
+
function isValid()
{
$ok = parent::isValid();
- if ($ok===true && !$this->model->id)
- {
- if ($this->cleaned_data['password1'] != $this->cleaned_data['password2'])
- {
+ if ($ok===true && !$this->model->id) {
+ if ($this->cleaned_data['password1'] != $this->cleaned_data['password2']) {
$this->is_valid = false;
$this->errors['password2'][] = "The two password fields didn't match.";
-
+
return false;
}
-
+
$this->cleaned_data['password'] = User::SetPassword2($this->cleaned_data['password1']);
}
-
+
return $ok;
}
}
public function fields()
{
- return array(
+ $fields = array(
'username',
'password',
'email',
'is_active',
'is_staff',
'is_superuser',
- 'Permissions',
- 'Roles',
);
+ if (IPF_Auth_App::ArePermissionsEnabled()) {
+ $fields[] = 'Permissions';
+ $fields[] = 'Roles';
+ }
+ return $fields;
}
function _searchFields()
protected function _getForm($model_obj, $data, $extra)
{
$extra['model'] = $model_obj;
- $extra['checkgroup_fields'] = array(
- 'Permissions' => array('widget'=>'IPF_Auth_Forms_Widget_Permissions'),
- 'Roles' => array(),
- );
return new IPFAuthAdminUserForm($data, $extra);
}
}
const UNUSABLE_PASSWORD = '!';
public $session_key = 'IPF_User_auth';
- public function __toString() {
+ public function __toString()
+ {
$s = $this->username;
if ($s===null)
return 'Anonymous';
return $s;
}
- public function smartName() {
+ public function smartName()
+ {
$username = $this->username;
if ($username===null)
return __('Anonymous');
return $user;
}
- function setUnusablePassword(){
+ function setUnusablePassword()
+ {
$this->password = UNUSABLE_PASSWORD;
}
- static function SetPassword2($raw_password){
+ static function SetPassword2($raw_password)
+ {
$salt = IPF_Utils::randomString(5);
return 'sha1:'.$salt.':'.sha1($salt.$raw_password);
}
- function setPassword($raw_password){
+ function setPassword($raw_password)
+ {
$this->password = self::SetPassword2($raw_password);
}
- function checkPassword($password){
+ function checkPassword($password)
+ {
if ( ($this->password=='') || ($this->password==User::UNUSABLE_PASSWORD) )
return false;
list($algo, $salt, $hash) = explode(':', $this->password);
function isAnonymous()
{
- if (0===(int)$this->id)
- return true;
- return false;
+ return 0 === (int)$this->id;
}
function checkCreditentials($username, $password)
}
}
-IPF_Admin_Model::register('User','AdminUser');
+IPF_Admin_Model::register('User', 'AdminUser');
+
<?php
-/**
- * This class has been auto-generated by the IPF ORM Framework
- */
class UserPermission extends BaseUserPermission
{
+}
-}
\ No newline at end of file
<?php
-/**
- * This class has been auto-generated by the IPF ORM Framework
- */
class UserRole extends BaseUserRole
{
+}
-}
\ No newline at end of file
<?php
-class IPF_Form_DB_Boolean extends IPF_Form_DB{
+class IPF_Form_DB_Boolean extends IPF_Form_DB
+{
public $type = 'boolean';
- function formField($def, $form_field='IPF_Form_Field_Boolean'){
+
+ function formField($def, $form_field='IPF_Form_Field_Boolean')
+ {
return parent::formField($def, $form_field);
}
}
+
return parent::formField($def, $form_field);
}
}
+
+++ /dev/null
-<?php
-
-class IPF_Form_Extra_AddJs extends IPF_Form_Model
-{
- protected $add_js = array();
-
- function initFields($extra=array())
- {
- parent::initFields($extra);
-
- $this->add_js[] = '<script language="javascript" type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/jquery.js"></script>';
-
- if (array_key_exists('add_js', $extra) && is_array($extra['add_js']))
- $this->add_js = array_merge($this->add_js, $extra['add_js']);
- }
-
- public function render_commonjs()
- {
- return implode('', $this->add_js);
- }
-}
\ No newline at end of file
+++ /dev/null
-<?php
-
-class IPF_Form_Extra_Checkgroup extends IPF_Form_Extra_AddJs
-{
- public $checkgroup_fields = array();
-
- function initFields($extra=array())
- {
- parent::initFields($extra);
-
- if (array_key_exists('checkgroup_fields', $extra) && is_array($extra['checkgroup_fields']))
- $this->checkgroup_fields = $extra['checkgroup_fields'];
- }
-
- static function SetupForm($form, $checkgroup_fields=null)
- {
- if (!$checkgroup_fields)
- $checkgroup_fields = &$form->checkgroup_fields;
-
- foreach ($checkgroup_fields as $fieldName=>&$params)
- {
- $field = $form->fields[$fieldName];
-
- if (array_key_exists('label', $params))
- $field->label = $params['label'];
-
- $widget = null;
- if (array_key_exists('widget', $params))
- $widget = $params['widget'];
- if (!$widget)
- $widget = 'IPF_Form_Extra_Widget_CheckboxGroupInput';
-
- $field->widget = new $widget(array(
- 'choices' => $field->widget->choices,
- ));
-
- if (array_key_exists('class', $field->widget->attrs) && $field->widget->attrs['class'])
- $field->widget->attrs['class'] .= ' checkgroup';
- else $field->widget->attrs['class'] = 'checkgroup';
- }
- }
-
- public function render_commonjs()
- {
- if (count($this->checkgroup_fields))
- $result = '<script language="javascript" type="text/javascript" src="'.IPF::get('admin_media_url').'js/extra/checkall.js"></script>';
- else $result = '';
-
- return implode('', $this->add_js).$result;
- }
-}
+++ /dev/null
-<?php
-
-class IPF_Form_Extra_Widget_CheckboxGroupInput extends IPF_Form_Widget_SelectMultipleInputCheckbox
-{
- public function render($name, $value, $extra_attrs=array(), $choices=array())
- {
- $output = array();
- if ($value === null || $value == '')
- $value = array();
- $final_attrs = $this->buildAttrs($extra_attrs);
- $output[] = '<div><ul style="float:left;">';
- $choices = array_merge($this->choices, $choices);
- $i=0;
- $base_id = $final_attrs['id'];
- foreach ($choices as $option_label=>$option_value)
- {
- $final_attrs['id'] = $base_id.'_'.$i;
- $final_attrs['value'] = htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8');
- $field = new IPF_Form_Extra_Widget_CheckboxInput($final_attrs);
- $rendered = $field->render($name.'[]', in_array($option_value, $value), array('value'=>$option_value));
- $output[] = sprintf(
- '<li style="list-style-type:none;"><label style="width:600px;">%s %s</label></li><br/>',
- $rendered, htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8')
- );
- $i++;
- }
- $output[] = '</ul><div style="clear:both; height:0px;"></div></div>';
- return new IPF_Template_SafeString(implode("\n", $output), true);
- }
-}
+++ /dev/null
-<?php
-
-class IPF_Form_Extra_Widget_CheckboxInput extends IPF_Form_Widget_Input
-{
- public $input_type = 'checkbox';
-
- public function render($name, $checked, $extra_attrs=array())
- {
- if ($checked)
- $extra_attrs['checked'] = 'checked';
- return parent::render($name, '', $extra_attrs);
- }
-
- public function valueFromFormData($name, &$data)
- {
- return (!isset($data[$name]) || false === $data[$name] || (string)$data[$name] === '0' || (string)$data[$name] === 'off') ? false : true;
- }
-}
<?php
-class IPF_Form_Field_ModelMultipleChoice extends IPF_Form_Field_MultipleChoice{
+class IPF_Form_Field_ModelMultipleChoice extends IPF_Form_Field_MultipleChoice
+{
public $widget = 'IPF_Form_Widget_SelectMultipleInput';
+
protected $_model;
- function __construct($params=array()){
+ function __construct($params=array())
+ {
parent::__construct($params);
$this->_model = $params['model'];
}
else
$exclude = array();
- foreach($db_columns as $name=>$col) {
- if (array_search($name,$exclude)!==false)
+ foreach ($db_columns as $name => $col) {
+ if (array_search($name, $exclude) !== false)
continue;
- $this->addDBField($name,$col);
+ $this->addDBField($name, $col);
}
- foreach($db_relations as $name => $relation) {
- if (array_search($name,$exclude)!==false)
+ foreach ($db_relations as $name => $relation) {
+ if (array_search($name, $exclude) !== false)
continue;
- $this->addDBRelation($name,$relation,$col);
+ $this->addDBRelation($name, $relation, $col);
}
} else {
- foreach($user_fields as $uname) {
+ foreach ($user_fields as $uname) {
$add_method = 'add__'.$uname.'__field';
- if (method_exists($this,$add_method)) {
+ if (method_exists($this, $add_method)) {
$this->$add_method();
continue;
}
public function render($name, $value, $extra_attrs=array())
{
- if ((bool)$value) {
+ if ($value)
$extra_attrs['checked'] = 'checked';
- }
- $extra_attrs['value'] = '1';
+ if (!array_key_exists('value', $extra_attrs))
+ $extra_attrs['value'] = '1';
return parent::render($name, '', $extra_attrs);
}
public function valueFromFormData($name, &$data)
{
- if (!isset($data[$name]) or false === $data[$name] or (string)$data[$name] === '0' or (string)$data[$name] === 'off') {
- return false;
- }
- return true;
+ return isset($data[$name]) && false !== $data[$name] && (string)$data[$name] !== '0' && (string)$data[$name] !== 'off';
}
}
+
public function __construct($attrs=array())
{
- if (isset($attrs['choices'])){
- $this->choices = $attrs['choices'];
- unset($attrs['choices']);
- }
+ if (isset($attrs['choices'])) {
+ $this->choices = $attrs['choices'];
+ unset($attrs['choices']);
+ }
parent::__construct($attrs);
}
}
return null;
}
-
}
+
class IPF_Form_Widget_SelectMultipleInputCheckbox extends IPF_Form_Widget_SelectMultipleInput
{
- public function render($name, $value, $extra_attrs=array(),
- $choices=array())
+ public function render($name, $value, $extra_attrs=array(), $choices=array())
{
$output = array();
- if ($value === null or $value == '') {
+ if ($value === null || $value == '')
$value = array();
- }
$final_attrs = $this->buildAttrs($extra_attrs);
$output[] = '<ul>';
$choices = array_merge($this->choices, $choices);
$i=0;
$base_id = $final_attrs['id'];
foreach ($choices as $option_label=>$option_value) {
-
$final_attrs['id'] = $base_id.'_'.$i;
$final_attrs['value'] = htmlspecialchars($option_value, ENT_COMPAT, 'UTF-8');
$checkbox = new IPF_Form_Widget_CheckboxInput($final_attrs);
- $rendered = $checkbox->render($name.'[]', in_array($option_value, $value));
-
- $output[] = sprintf('<li><label>%s %s</label></li>', $rendered,
+ $rendered = $checkbox->render($name.'[]', in_array($option_value, $value), array('value'=>$option_value));
+ $output[] = sprintf('<li><label>%s %s</label></li>',
+ $rendered,
htmlspecialchars($option_label, ENT_COMPAT, 'UTF-8'));
$i++;
}
}
return $id;
}
+}
-
-}
\ No newline at end of file