<?php
-class IPF_Admin_App extends IPF_Application{
- public function __construct(){
+class IPF_Admin_App extends IPF_Application
+{
+ public function __construct()
+ {
parent::__construct(array(
'models'=>array('AdminLog')
));
}
- public static function urls(){
+
+ public static function urls()
+ {
return array(
array('regex'=>'fb_rename/$#', 'func'=>'IPF_Admin_Views_FileBrowserRename'),
- array('regex'=>'filebrowser(.+)#', 'func'=>'IPF_Admin_Views_FileBrowser'),
- array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'),
+ array('regex'=>'filebrowser(.+)#', 'func'=>'IPF_Admin_Views_FileBrowser'),
+ array('regex'=>'$#', 'func'=>'IPF_Admin_Views_Index'),
array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/$#i', 'func'=>'IPF_Admin_Views_ListItems'),
array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/reorder/$#i', 'func'=>'IPF_Admin_Views_Reorder'),
array('regex'=>'([\w\_\-]+)/([\w\_\-]+)/add/$#i', 'func'=>'IPF_Admin_Views_AddItem'),
);
}
- static function checkAdminAuth($request){
- $ok = true;
- if ($request->user->isAnonymous())
- $ok = false;
- elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
- $ok = false;
+ static function checkAdminAuth($request)
+ {
+ $ok = true;
+ if ($request->user->isAnonymous())
+ $ok = false;
+ elseif ( (!$request->user->is_staff) && (!$request->user->is_superuser) )
+ $ok = false;
- if ($ok)
- return true;
- else
- return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
- }
+ if ($ok)
+ return true;
+ else
+ return new IPF_HTTP_Response_Redirect(IPF_HTTP_URL_urlForView('IPF_Admin_Views_Login'));
+ }
static function GetAppModelFromSlugs($lapp, $lmodel)
{
- foreach (IPF_Project::getInstance()->appList() as $app)
- {
- if ($app->getSlug() == $lapp)
- {
- foreach($app->modelList() as $m)
- {
+ foreach (IPF_Project::getInstance()->appList() as $app) {
+ if ($app->getSlug() == $lapp) {
+ foreach($app->modelList() as $m) {
if (strtolower($m) == $lmodel)
return array('app' => $app, 'modelname' => $m);
}
}
}
-
return null;
}
$perms = array();
- foreach (IPF_Auth_App::checkPermissions($request, $app, $m, $adminPerms) as $permName=>$permValue)
- {
+ foreach (IPF_Auth_App::checkPermissions($request, $app, $m, $adminPerms) as $permName=>$permValue) {
if ($permValue)
$perms[] = $permName;
}
return $perms;
}
+
+ public static function renderForm($form)
+ {
+ return $form->htmlOutput(
+ '<div class="form-row"><div>%2$s %1$s%3$s%4$s</div></div>',
+ '<div>%s</div>',
+ '</div>',
+ '<p class="help">%s</p>',
+ true,
+ '<div class="form-group-title">%s</div>',
+ false);
+ }
}
+
'mode'=>'add',
'page_title'=>$this->titleAdd(),
'classname'=>$this->verbose_name(),
- 'form'=>$form,
+ 'form' => $form,
+ 'form_html' => IPF_Admin_App::renderForm($form),
+ 'extra_js' => $form->extra_js(),
'inlineInstances'=>$this->inlineInstances,
'lapp'=>$lapp,
'perms'=>$perms,
'page_title'=>$this->titleEdit(),
'classname'=>$this->verbose_name(),
'object'=>$o,
- 'form'=>$form,
+ 'form' => $form,
+ 'form_html' => IPF_Admin_App::renderForm($form),
+ 'extra_js' => $form->extra_js(),
'inlineInstances'=>$this->inlineInstances,
'lapp'=>$lapp,
'perms'=>$perms,
{/if}
<fieldset class="module aligned">
{block form}
- {$form.render_admin()}
+ {$form_html}
{/block}
</fieldset>
{if $inlineInstances}
});
{/literal}
</script>
+{foreach $extra_js as $js}
+{$js|safe}
+{/foreach}
{/block}
{block breadcrumbs}<div class="breadcrumbs"><a href="{url 'IPF_Admin_Views_Index'}">Home</a> » <a href="{url 'IPF_Admin_Views_ListItems', array($lapp, $lmodel)}">{$classname}</a> » <a href="{url 'IPF_Admin_Views_EditItem', array($lapp, $lmodel, $object.id)}">{$object}</a> » Change Password</div>{/block}
{block content}
-
<div id="content" class="colM">
- <h1>{$page_title}</h1>
- <div id="content-main">
- <form method="post" action="">
- <div>
- {if $form.errors}
- <p class="errornote">Please correct the error below.</p>
- {/if}
- <fieldset class="module aligned">
- {$form.render_admin()}
- </fieldset>
- <div class="submit-row">
- <input type="submit" value="Change password" class="default" />
- <input type="button" value="Cancel" onclick="javascript:history.back();" />
- </div>
- </div>
- </form>
- </div>
+ <h1>{$page_title}</h1>
+ <div id="content-main">
+ <form method="post" action="">
+ <div>
+ {if $form.errors}
+ <p class="errornote">Please correct the error below.</p>
+ {/if}
+ <fieldset class="module aligned">
+ {$form_html}
+ </fieldset>
+ <div class="submit-row">
+ <input type="submit" value="Change password" class="default" />
+ <input type="button" value="Cancel" onclick="javascript:history.back();" />
+ </div>
+ </div>
+ </form>
+ </div>
</div>
+{/block}
+{block scripts}
+{foreach $extra_js as $js}
+{$js|safe}
+{/foreach}
{/block}
{block usertools}{/block}
{block content}
- <div id="content" class="colM">
- <div id="content-main">
- <form method="post">
- {if $form.message}<ul class="errorlist"><li>{$form.message}</li></ul>{/if}
- {$form.render_admin()}
- <div class="submit-row">
- <input type="submit" value="Sign In" class="default" />
- </div>
- </form>
- </div>
- </div>
- <script type="text/javascript">
- document.getElementById('id_username').focus();
- </script>
+<div id="content" class="colM">
+ <div id="content-main">
+ <form method="post">
+ {if $form.message}<ul class="errorlist"><li>{$form.message}</li></ul>{/if}
+ {$form_html}
+ <div class="submit-row">
+ <input type="submit" value="Sign In" class="default" />
+ </div>
+ </form>
+ </div>
+</div>
{/block}
+
+{block scripts}
+{foreach $extra_js as $js}
+{$js|safe}
+{/foreach}
+<script type="text/javascript">
+ document.getElementById('id_username').focus();
+</script>
+{/block}
+
'page_title'=>'Change Password: '.$user->username,
'classname'=>'User',
'object'=>$user,
- 'form'=>$form,
+ 'form' => $form,
+ 'form_html' => IPF_Admin_App::renderForm($form),
'lapp'=>$lapp,
'lmodel'=>$lmodel,
'admin_title' => IPF::get('admin_title'),
return new IPF_HTTP_Response_NotFound();
}
-function IPF_Admin_Views_Login($request, $match){
+function IPF_Admin_Views_Login($request, $match)
+{
$success_url = '';
if (!empty($request->REQUEST['next']))
$success_url = $request->REQUEST['next'];
if ($request->method == 'POST') {
$form = new IPF_Auth_Forms_Login($request->POST);
- if ($form->isValid()){
+ if ($form->isValid()) {
$users = new User();
if (false === ($user = $users->checkCreditentials($form->cleaned_data['username'], $form->cleaned_data['password']))) {
$form->message = __('The login or the password is not valid. The login and the password are case sensitive.');
return new IPF_HTTP_Response_Redirect($success_url);
}
}
- }
- else
+ } else {
$form = new IPF_Auth_Forms_Login(array('next'=>$success_url));
+ }
$context = array(
- 'page_title' => IPF::get('admin_title'),
- 'form' => $form,
- 'admin_title' => IPF::get('admin_title'),
- 'indexpage_url'=>IPF::get('indexpage_url','/'),
+ 'page_title' => IPF::get('admin_title'),
+ 'form' => $form,
+ 'form_html' => IPF_Admin_App::renderForm($form),
+ 'admin_title' => IPF::get('admin_title'),
+ 'indexpage_url'=>IPF::get('indexpage_url','/'),
);
return IPF_Shortcuts::RenderToResponse('admin/login.html', $context, $request);
}
-function IPF_Admin_Views_Logout($request, $match){
+function IPF_Admin_Views_Logout($request, $match)
+{
IPF_Auth_App::logout($request);
$context = array(
'page_title' => IPF::get('admin_title'),
return IPF_Shortcuts::RenderToResponse('admin/logout.html', $context, $request);
}
-function cmp($a, $b){
- if ($a['name'] == $b['name']) {
+function cmp($a, $b)
+{
+ if ($a['name'] == $b['name'])
return 0;
- }
return ($a['name'] < $b['name']) ? -1 : 1;
}
-function dir_recursive($dir, $path=DIRECTORY_SEPARATOR, $level=''){
+function dir_recursive($dir, $path=DIRECTORY_SEPARATOR, $level='')
+{
$dirtree = array();
if ($level=='')
$dirtree[] = array('path'=>'', 'name'=>'Root Folder');
$account = array('username', 'password');
}
-
- if (IPF_Auth_App::ArePermissionsEnabled())
- {
+
+ $permissions = array('is_active', 'is_staff', 'is_superuser');
+ 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
- {
+ } else {
unset($this->fields['Permissions']);
unset($this->fields['Roles']);
}
-
+
$this->field_groups = array(
array('fields' => $account),
array('fields' => array('email', 'first_name', 'last_name'), 'label' => 'Personal info'),
- array('fields' => array('is_active', 'is_staff', 'is_superuser','Permissions','Roles'), 'label' => 'Permissions'),
+ array('fields' => $permissions, 'label' => 'Permissions'),
);
}
return (isset($this->errors['__all__'])) ? $this->errors['__all__'] : array();
}
- protected function htmlOutput($normal_row, $error_row, $row_ender,
- $help_text_html, $errors_on_separate_row, $group_title=null)
+ public function htmlOutput($normal_row, $error_row, $row_ender,
+ $help_text_html, $errors_on_separate_row, $group_title=null,
+ $extra_js=true)
{
$top_errors = (isset($this->errors['__all__'])) ? $this->errors['__all__'] : array();
array_walk($top_errors, 'IPF_Form_htmlspecialcharsArray');
$output = array();
$hidden_fields = array();
-
- $groups = array();
-
- if (count($this->field_groups))
- {
- foreach ($this->field_groups as $field_group)
- {
- if (array_key_exists('fields', $field_group) && is_array($field_group['fields']))
- {
- $_fields = array();
-
- foreach ($field_group['fields'] as $field_name)
- {
- if (array_key_exists($field_name, $this->fields))
- $_fields[$field_name] = $this->fields[$field_name];
- }
-
- if (count($_fields))
- {
- $_group = array('fields'=>$_fields);
-
- if (array_key_exists('label', $field_group))
- $_group['label'] = $field_group['label'];
-
- $groups[] = $_group;
- }
- }
- }
+
+ foreach ($this->field_groups as $field_group) {
+ if (!$field_group['fields'])
+ throw new IPF_Exception('Empty field group.');
+ foreach ($field_group['fields'] as $field_name)
+ if (!array_key_exists($field_name, $this->fields))
+ throw new IPF_Exception('Unknown field "' . $field_name . '".');
+ }
+
+ $groups = array();
+ foreach ($this->field_groups as $field_group) {
+ $_fields = array();
+ foreach ($field_group['fields'] as $field_name)
+ $_fields[$field_name] = $this->fields[$field_name];
+ $groups[] = array(
+ 'fields' => $_fields,
+ 'label' => @$field_group['label'],
+ );
}
if (count($groups)) {
}
foreach ($groups as $group) {
- if ($render_group_title && array_key_exists('label', $group))
+ if ($render_group_title && isset($group['label']))
$output[] = sprintf($group_title, $group['label']);
foreach ($group['fields'] as $name=>$field) {
}
}
- $extra_js = array();
- foreach ($groups as $group)
- foreach ($group['fields'] as $name => $field)
- $extra_js = array_merge($extra_js, $field->widget->extra_js());
- $output[] = implode("\n", array_unique($extra_js));
+ if ($extra_js)
+ $output = array_merge($output, $this->extra_js());
return new IPF_Template_SafeString($this->before_render . implode("\n", $output) . $this->after_render, true);
}
+ public function extra_js()
+ {
+ $extra_js = array();
+ foreach ($this->fields as $name => $field)
+ $extra_js = array_merge($extra_js, $field->widget->extra_js());
+ return array_unique($extra_js);
+ }
+
public function render_p()
{
return $this->htmlOutput('<p>%1$s%2$s %3$s%4$s</p>', '%s', '</p>', ' %s', true);