Merge remote-tracking branch 'svnexport/master'
commit
c3c12de58e
@ -0,0 +1,137 @@
|
|||||||
|
<?php /**
|
||||||
|
* Postfix Admin
|
||||||
|
*
|
||||||
|
* LICENSE
|
||||||
|
* This source file is subject to the GPL license that is bundled with
|
||||||
|
* this package in the file LICENSE.TXT.
|
||||||
|
*
|
||||||
|
* Further details on the project are available at http://postfixadmin.sf.net
|
||||||
|
*
|
||||||
|
* @version $Id$
|
||||||
|
* @license GNU GPL v2 or later.
|
||||||
|
*
|
||||||
|
* File: list.php
|
||||||
|
* List all items as a quick overview.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once('common.php');
|
||||||
|
|
||||||
|
# if (safeget('token') != $_SESSION['PFA_token']) die('Invalid token!');
|
||||||
|
|
||||||
|
$username = authentication_get_username(); # enforce login
|
||||||
|
|
||||||
|
$table = safeget('table');
|
||||||
|
|
||||||
|
$handlerclass = ucfirst($table) . 'Handler';
|
||||||
|
|
||||||
|
if ( !preg_match('/^[a-z]+$/', $table) || !file_exists("model/$handlerclass.php")) { # validate $table
|
||||||
|
die ("Invalid table name given!");
|
||||||
|
}
|
||||||
|
|
||||||
|
# default: domain admin restrictions
|
||||||
|
$list_admins = array($username);
|
||||||
|
$is_superadmin = 0;
|
||||||
|
|
||||||
|
if (authentication_has_role('global-admin')) { # more permissions? Fine!
|
||||||
|
$list_admins = array_keys(list_admins());
|
||||||
|
$is_superadmin = 1;
|
||||||
|
$username = safepost('username', safeget('username', $username)); # prefer POST over GET variable
|
||||||
|
}
|
||||||
|
|
||||||
|
$is_admin = authentication_has_role('admin');
|
||||||
|
|
||||||
|
$handler = new $handlerclass(0, $username, $is_admin);
|
||||||
|
|
||||||
|
$formconf = $handler->webformConfig();
|
||||||
|
|
||||||
|
if ($is_admin) {
|
||||||
|
authentication_require_role($formconf['required_role']);
|
||||||
|
} else {
|
||||||
|
if (empty($formconf['user_hardcoded_field'])) {
|
||||||
|
die($handlerclass . ' is not available for users');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$search = safeget('search', safesession("search_$table", array()));
|
||||||
|
$searchmode = safeget('searchmode', safesession("searchmode_$table", array()));
|
||||||
|
|
||||||
|
if (!is_array($search) || !is_array($searchmode)) {
|
||||||
|
# avoid injection of raw SQL if $search is a string instead of an array
|
||||||
|
die("Invalid parameter");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (safeget('reset_search', 0)) {
|
||||||
|
$search = array();
|
||||||
|
$searchmode = array();
|
||||||
|
}
|
||||||
|
$_SESSION["search_$table"] = $search;
|
||||||
|
$_SESSION["searchmode_$table"] = $searchmode;
|
||||||
|
|
||||||
|
if (count($search)) {
|
||||||
|
$handler->getList($search, $searchmode);
|
||||||
|
} else {
|
||||||
|
$handler->getList('');
|
||||||
|
}
|
||||||
|
$items = $handler->result();
|
||||||
|
|
||||||
|
if (count($handler->errormsg)) flash_error($handler->errormsg);
|
||||||
|
if (count($handler->infomsg)) flash_error($handler->infomsg);
|
||||||
|
|
||||||
|
|
||||||
|
if (safeget('output') == 'csv') {
|
||||||
|
|
||||||
|
$out = fopen('php://output', 'w');
|
||||||
|
header( 'Content-Type: text/csv; charset=utf-8' );
|
||||||
|
header( 'Content-Disposition: attachment;filename='.$table.'.csv');
|
||||||
|
|
||||||
|
print "\xEF\xBB\xBF"; # utf8 byte-order to indicate the file is utf8 encoded
|
||||||
|
# print "sep=;"; # hint that ; is used as seperator - breaks the utf8 flag in excel import!
|
||||||
|
print "\n";
|
||||||
|
|
||||||
|
if (!defined('ENT_HTML401')) { # for compability for PHP < 5.4.0
|
||||||
|
define('ENT_HTML401', 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
# print column headers as csv
|
||||||
|
$header = array();
|
||||||
|
$columns = array();
|
||||||
|
foreach ($handler->getStruct() as $key => $field) {
|
||||||
|
if ($field['display_in_list'] && $field['label'] != '') { # don't show fields without a label
|
||||||
|
$header[] = html_entity_decode ( $field['label'], ENT_COMPAT | ENT_HTML401, 'UTF-8' );
|
||||||
|
$columns[] = $key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fputcsv($out, $header, ';');
|
||||||
|
|
||||||
|
# print items as csv
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$fields = array();
|
||||||
|
foreach ($columns as $column) {
|
||||||
|
$fields[] = $item[$column];
|
||||||
|
}
|
||||||
|
fputcsv($out, $fields, ';');
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($out);
|
||||||
|
|
||||||
|
} else { # HTML output
|
||||||
|
|
||||||
|
$smarty->assign('admin_list', $list_admins);
|
||||||
|
$smarty->assign('admin_selected', $username);
|
||||||
|
$smarty->assign('smarty_template', 'list');
|
||||||
|
$smarty->assign('struct', $handler->getStruct());
|
||||||
|
$smarty->assign('msg', $handler->getMsg());
|
||||||
|
$smarty->assign('table', $table);
|
||||||
|
$smarty->assign('items', $items);
|
||||||
|
$smarty->assign('id_field', $handler->getId_field());
|
||||||
|
$smarty->assign('formconf', $formconf);
|
||||||
|
$smarty->assign('search', $search);
|
||||||
|
$smarty->assign('searchmode', $searchmode);
|
||||||
|
|
||||||
|
$smarty->display ('index.tpl');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|
||||||
|
?>
|
@ -0,0 +1,104 @@
|
|||||||
|
<?php
|
||||||
|
# $Id$
|
||||||
|
/**
|
||||||
|
* class to display the database scheme (for usage in upgrade.php) in Cli
|
||||||
|
*
|
||||||
|
* extends the "Shell" class
|
||||||
|
*/
|
||||||
|
|
||||||
|
class CliScheme extends Shell {
|
||||||
|
|
||||||
|
public $handler_to_use = "";
|
||||||
|
public $new = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execution method always used for tasks
|
||||||
|
*/
|
||||||
|
public function execute() {
|
||||||
|
|
||||||
|
$module = preg_replace('/Handler$/', '', $this->handler_to_use);
|
||||||
|
$module = strtolower($module);
|
||||||
|
|
||||||
|
$handler = new $this->handler_to_use($this->new);
|
||||||
|
$struct = $handler->getStruct();
|
||||||
|
|
||||||
|
foreach (array_keys($struct) as $field) {
|
||||||
|
if ($field == 'created') {
|
||||||
|
$struct[$field]['db_code'] = '{DATE}';
|
||||||
|
} elseif ($field == 'modified') {
|
||||||
|
$struct[$field]['db_code'] = '{DATECURRENT}';
|
||||||
|
} else {
|
||||||
|
switch ($struct[$field]['type']) {
|
||||||
|
case 'int':
|
||||||
|
$struct[$field]['db_code'] = '{BIGINT}';
|
||||||
|
break;
|
||||||
|
case 'bool':
|
||||||
|
$struct[$field]['db_code'] = '{BOOLEAN}';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$struct[$field]['db_code'] = 'VARCHAR(255) {LATIN1} NOT NULL';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out("For creating a new table with upgrade.php:");
|
||||||
|
$this->out("");
|
||||||
|
|
||||||
|
$this->out('db_query_parsed("');
|
||||||
|
$this->out(' CREATE TABLE {IF_NOT_EXISTS} " . table_by_key("' . $module . '") . " (');
|
||||||
|
# TODO: $module is not really correct - $handler->db_table would be
|
||||||
|
|
||||||
|
foreach (array_keys($struct) as $field) {
|
||||||
|
if ($struct[$field]['not_in_db'] == 0 && $struct[$field]['dont_write_to_db'] == 0) {
|
||||||
|
$this->out(" $field " . $struct[$field]['db_code'] . ",");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out(" INDEX domain(domain,username), // <--- change as needed");
|
||||||
|
$this->out(" PRIMARY KEY (" . $handler->getId_field() . ")");
|
||||||
|
$this->out(' ) {MYISAM} ');
|
||||||
|
$this->out('");');
|
||||||
|
|
||||||
|
$this->out('');
|
||||||
|
$this->hr();
|
||||||
|
$this->out('For adding fields with upgrade.php:');
|
||||||
|
$this->out('');
|
||||||
|
|
||||||
|
$prev_field = '';
|
||||||
|
foreach (array_keys($struct) as $field) {
|
||||||
|
if ($struct[$field]['not_in_db'] == 0 && $struct[$field]['dont_write_to_db'] == 0) {
|
||||||
|
$this->out(" _db_add_field('$module', '$field',\t'" . $struct[$field]['db_code'] . "',\t'$prev_field');");
|
||||||
|
$prev_field = $field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->out('');
|
||||||
|
$this->hr();
|
||||||
|
$this->out('Note that the above is only a template.');
|
||||||
|
$this->out('You might need to adjust some parts.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays help contents
|
||||||
|
*/
|
||||||
|
public function help() {
|
||||||
|
$module = preg_replace('/Handler$/', '', $this->handler_to_use);
|
||||||
|
$module = strtolower($module);
|
||||||
|
|
||||||
|
$this->out(
|
||||||
|
"Usage:
|
||||||
|
|
||||||
|
postfixadmin-cli $module scheme
|
||||||
|
|
||||||
|
Print the $module database scheme in a way that can be
|
||||||
|
pasted into upgrade.php.
|
||||||
|
|
||||||
|
");
|
||||||
|
|
||||||
|
$this->_stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
|
@ -0,0 +1,108 @@
|
|||||||
|
<div id="overview">
|
||||||
|
<form name="frmOverview" method="post" action="">
|
||||||
|
{if ($admin_list|count > 1)}
|
||||||
|
{html_options name='username' output=$admin_list values=$admin_list selected=$admin_selected onchange="this.form.submit();"}
|
||||||
|
<input class="button" type="submit" name="go" value="{$PALANG.go}" />
|
||||||
|
{/if}
|
||||||
|
</form>
|
||||||
|
{#form_search#}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{if ($search|count > 0)}
|
||||||
|
<div class='searchparams'>
|
||||||
|
<p>{$PALANG.searchparams}
|
||||||
|
{foreach key=key item=field from=$search}
|
||||||
|
<span>{if $struct.$key.label}{$struct.$key.label}{else}{$key}{/if}
|
||||||
|
{if isset($searchmode.$key)}{$searchmode.$key}{else}={/if} {$field}
|
||||||
|
</span>
|
||||||
|
{/foreach}
|
||||||
|
<span><a href="list.php?table={$table}&reset_search=1">[x]</a></span>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div id="list">
|
||||||
|
<table border=0 id='admin_table'><!-- TODO: 'admin_table' needed because of CSS for table header -->
|
||||||
|
|
||||||
|
<tr class="header">
|
||||||
|
{foreach key=key item=field from=$struct}
|
||||||
|
{if $field.display_in_list == 1 && $field.label}{* don't show fields without a label *}
|
||||||
|
<td>{$field.label}</td>
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
<td> </td>
|
||||||
|
<td> </td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
{foreach from=$items item=item}
|
||||||
|
{#tr_hilightoff#}
|
||||||
|
|
||||||
|
{foreach key=key item=field from=$struct}
|
||||||
|
{if $field.display_in_list == 1 && $field.label}
|
||||||
|
|
||||||
|
{if $field.linkto != '' && ($item.$id_field != '' || $item.$id_field > 0) }
|
||||||
|
{assign "linkto" "{$field.linkto|replace:'%s':{$item.$id_field|escape:url}}"} {* TODO: use label field instead *}
|
||||||
|
{assign "linktext" "<a href='{$linkto}'>{$item.{$key}}</a>"}
|
||||||
|
{else}
|
||||||
|
{assign "linktext" $item.$key}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{if $table == 'foo' && $key == 'bar'}
|
||||||
|
<td>Special handling (complete table row) for {$table} / {$key}</td></tr>
|
||||||
|
{else}
|
||||||
|
<td>
|
||||||
|
{if $table == 'foo' && $key == 'bar'}
|
||||||
|
Special handling (td content) for {$table} / {$key}
|
||||||
|
{* {elseif $table == 'domain' && $key == 'domain'}
|
||||||
|
<a href="list.php?table=domain&domain={$item.domain|escape:"url"}">{$item.domain}</a>
|
||||||
|
*}
|
||||||
|
{elseif $key == 'active'}
|
||||||
|
<a href="{#url_editactive#}{$table}&id={$item.$id_field|escape:"url"}&active={if ($item.active==0)}1{else}0{/if}&token={$smarty.session.PFA_token|escape:"url"}">{$item._active}</a>
|
||||||
|
{elseif $field.type == 'bool'}
|
||||||
|
{assign "tmpkey" "_{$key}"}{$item.{$tmpkey}}
|
||||||
|
{elseif $field.type == 'list'}
|
||||||
|
{foreach key=key2 item=field2 from=$value_{$key}}<p>{$field2} {/foreach}
|
||||||
|
{elseif $field.type == 'pass'}
|
||||||
|
(hidden)
|
||||||
|
{elseif $field.type == 'quot'}
|
||||||
|
{assign "tmpkey" "_{$key}_percent"}
|
||||||
|
|
||||||
|
{if $item[$tmpkey]>90}
|
||||||
|
{assign var="quota_level" value="high"}
|
||||||
|
{elseif $item[$tmpkey]>55}
|
||||||
|
{assign var="quota_level" value="mid"}
|
||||||
|
{else}
|
||||||
|
{assign var="quota_level" value="low"}
|
||||||
|
{/if}
|
||||||
|
{if $item[$tmpkey] > -1}
|
||||||
|
<div class="quota quota_{$quota_level}" style="width:{$item[$tmpkey] *1.2}px;"></div>
|
||||||
|
<div class="quota_bg"></div></div>
|
||||||
|
<div class="quota_text quota_text_{$quota_level}">{$linktext}</div>
|
||||||
|
{else}
|
||||||
|
{$item[$key]}
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{elseif $field.type == 'txtl'}
|
||||||
|
{foreach key=key2 item=field2 from=$value_{$key}}<p>{$field2} {/foreach}
|
||||||
|
{else}
|
||||||
|
{$linktext}
|
||||||
|
{/if}
|
||||||
|
</td>
|
||||||
|
{/if}
|
||||||
|
{/if}
|
||||||
|
{/foreach}
|
||||||
|
|
||||||
|
<td>{if $item._can_edit}<a href="edit.php?table={$table|escape:"url"}&edit={$item.$id_field|escape:"url"}">{$PALANG.edit}</a>{else} {/if}</td>
|
||||||
|
<td>{if $item._can_delete}<a href="{#url_delete#}?table={$table}&delete={$item.$id_field|escape:"url"}&token={$smarty.session.PFA_token|escape:"url"}"
|
||||||
|
onclick="return confirm ('{$PALANG.{$msg.confirm_delete}|replace:'%s':$item.$id_field}')">{$PALANG.del}</a>{else} {/if}</td>
|
||||||
|
</tr>
|
||||||
|
{/foreach}
|
||||||
|
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<br /><a href="edit.php?table={$table|escape:"url"}" class="button">{$PALANG.{$formconf.create_button}}</a><br />
|
||||||
|
<br />
|
||||||
|
<br /><a href="list.php?table={$table|escape:"url"}&output=csv">{$PALANG.download_csv}</a>
|
||||||
|
|
||||||
|
</div>
|
Loading…
Reference in New Issue