mirror of
https://github.com/e107inc/e107.git
synced 2025-03-14 01:19:44 +01:00
Improve Form handler - work in progress
This commit is contained in:
parent
016a4b9e4e
commit
cac0e1cf12
@ -9,8 +9,8 @@
|
||||
* Cache Administration Area
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_admin/cache.php,v $
|
||||
* $Revision: 1.5 $
|
||||
* $Date: 2008-12-11 18:13:10 $
|
||||
* $Revision: 1.6 $
|
||||
* $Date: 2008-12-12 16:36:45 $
|
||||
* $Author: secretr $
|
||||
*
|
||||
*/
|
||||
@ -25,8 +25,9 @@ $e_sub_cat = 'cache';
|
||||
|
||||
require_once("auth.php");
|
||||
require_once(e_HANDLER."cache_handler.php");
|
||||
require_once(e_HANDLER."message_handler.php");
|
||||
$ec = new ecache;
|
||||
$message = array();
|
||||
$emessage = &eMessage::getInstance();
|
||||
|
||||
if ($pref['cachestatus'] == '2')
|
||||
{
|
||||
@ -58,9 +59,11 @@ if (isset($_POST['submit_cache']))
|
||||
$ec->clear();
|
||||
$ec->clear_sys();
|
||||
|
||||
//FIXME - admin_update - return formatted message instead tablerender & output, new message handler
|
||||
//admin_update(true, 'update', CACLAN_4);
|
||||
$message = array(LAN_UPDATE, CACLAN_4);
|
||||
$emessage->add(CACLAN_4, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
$emessage->add(LAN_NO_CHANGE, E_MESSAGE_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,18 +71,14 @@ if (isset($_POST['empty_syscache']))
|
||||
{
|
||||
$ec->clear_sys();
|
||||
$admin_log->log_event('CACHE_02', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, '');
|
||||
|
||||
//$ns->tablerender(LAN_UPDATE, "<div style='text-align:center'><b>".CACLAN_15."</b></div>");
|
||||
$message = array(LAN_UPDATE, CACLAN_15);
|
||||
$emessage->add(CACLAN_15, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
|
||||
if (isset($_POST['empty_cache']))
|
||||
{
|
||||
$ec->clear();
|
||||
$admin_log->log_event('CACHE_03', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, '');
|
||||
|
||||
//$ns->tablerender(LAN_UPDATE, "<div style='text-align:center'><b>".CACLAN_6."</b></div>");
|
||||
$message = array(LAN_UPDATE, CACLAN_6);
|
||||
$emessage->add(CACLAN_6, E_MESSAGE_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
@ -93,43 +92,55 @@ $cache_files_num = count($cache_files);
|
||||
$sys_count = CACLAN_17." ".$syscache_files_num." ".($syscache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||
$nonsys_count = CACLAN_17." ".$cache_files_num." ".($cache_files_num != 1 ? CACLAN_19 : CACLAN_18);
|
||||
|
||||
$text = "<div style='text-align:center'>
|
||||
$text = "
|
||||
<form method='post' action='".e_SELF."'>
|
||||
<table style='".ADMIN_WIDTH."' class='fborder'>
|
||||
<tr>
|
||||
<td colspan='3' class='fcaption'>".CACLAN_1."</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='forumheader3' style='width:60%;'>".CACLAN_11.": <div class='smalltext'>".CACLAN_13."</div><br />{$nonsys_count}</td>
|
||||
<td class='forumheader3' style='width:20%'>
|
||||
<input type='radio' name='cachestatus' value='1'".($pref['cachestatus'] ? " checked='checked'" : "")." /> ".LAN_ENABLED."
|
||||
<input type='radio' name='cachestatus' value='0'".(!$pref['cachestatus'] ? " checked='checked'" : "")." /> ".LAN_DISABLED."
|
||||
</td>
|
||||
<td class='forumheader3' style='width:20%'> <input class='button' type='submit' name='empty_cache' value=\"".CACLAN_5."\" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td class='forumheader3' style='width:60%;'>".CACLAN_12.": <div class='smalltext'>".CACLAN_14."</div><br />{$sys_count}</td>
|
||||
<td class='forumheader3' style='width:20%'>
|
||||
<input type='radio' name='syscachestatus' value='1'".($pref['syscachestatus'] ? " checked='checked'" : "")." /> ".LAN_ENABLED."
|
||||
<input type='radio' name='syscachestatus' value='0'".(!$pref['syscachestatus'] ? " checked='checked'" : "")." /> ".LAN_DISABLED."
|
||||
</td>
|
||||
<td class='forumheader3' style='width:20%'>
|
||||
<input class='button' type='submit' name='empty_syscache' value=\"".CACLAN_16."\" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
<tr style='vertical-align:top'>
|
||||
<td colspan='3' style='text-align:center' class='forumheader'>
|
||||
<input class='button' type='submit' name='submit_cache' value=\"".CACLAN_2."\" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
</div>";
|
||||
<fieldset id='core-cache-settings'>
|
||||
<legend class='e-hideme'>".CACLAN_3."</legend>
|
||||
<table cellpadding='0' cellspacing='0' class='adminlist'>
|
||||
<colgroup span='2'>
|
||||
<col style='width:80%' />
|
||||
<col style='width:20%' />
|
||||
</colgroup>
|
||||
<thead>
|
||||
<tr>
|
||||
<th><!-- --></th>
|
||||
<th class='center last'>".CACLAN_1."</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>".CACLAN_11."</strong>: {$nonsys_count}
|
||||
<div class='smalltext'>".CACLAN_13."</div>
|
||||
</td>
|
||||
<td class='center middle'>
|
||||
<input type='radio' id='cachestatus-1a' name='cachestatus' value='1'".($pref['cachestatus'] ? " checked='checked'" : "")." />
|
||||
<label for='cachestatus-1a'>".LAN_ENABLED."</label>
|
||||
<input type='radio' id='cachestatus-1b' name='cachestatus' value='0'".(!$pref['cachestatus'] ? " checked='checked'" : "")." />
|
||||
<label for='cachestatus-1b'>".LAN_DISABLED."</label>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<strong>".CACLAN_12."</strong>: {$sys_count}
|
||||
<div class='smalltext'>".CACLAN_14."</div>
|
||||
</td>
|
||||
<td class='center middle'>
|
||||
<input type='radio' name='syscachestatus' id='syscachestatus-1a' value='1'".($pref['syscachestatus'] ? " checked='checked'" : "")." />
|
||||
<label for='syscachestatus-1a'>".LAN_ENABLED."</label>
|
||||
<input type='radio' name='syscachestatus' id='syscachestatus-1b' value='0'".(!$pref['syscachestatus'] ? " checked='checked'" : "")." />
|
||||
<label for='syscachestatus-1b'>".LAN_DISABLED."</label>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div class='buttons-bar left'>
|
||||
<button class='submit f-right' type='submit' name='submit_cache'><span>".CACLAN_2."</span></button>
|
||||
<button class='delete' type='submit' name='empty_cache'><span>".CACLAN_5."</span></button>
|
||||
<button class='delete' type='submit' name='empty_syscache'><span>".CACLAN_16."</span></button>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>";
|
||||
|
||||
$ns->tablerender(CACLAN_3, $text);
|
||||
|
||||
|
@ -1,33 +1,238 @@
|
||||
<?php
|
||||
/*
|
||||
+ ----------------------------------------------------------------------------+
|
||||
| e107 website system
|
||||
|
|
||||
| ©Steve Dunstan 2001-2002
|
||||
| http://e107.org
|
||||
| jalist@e107.org
|
||||
|
|
||||
| Released under the terms and conditions of the
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
|
||||
| $Revision: 1.3 $
|
||||
| $Date: 2008-04-04 21:40:38 $
|
||||
| $Author: e107steved $
|
||||
+----------------------------------------------------------------------------+
|
||||
* e107 website system
|
||||
*
|
||||
* Copyright (C) 2001-2008 e107 Inc (e107.org)
|
||||
* Released under the terms and conditions of the
|
||||
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
|
||||
*
|
||||
* Form Handler
|
||||
*
|
||||
* $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $
|
||||
* $Revision: 1.4 $
|
||||
* $Date: 2008-12-12 16:36:45 $
|
||||
* $Author: secretr $
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
if (!defined('e107_INIT')) { exit; }
|
||||
|
||||
/**
|
||||
* Automate Form fields creation. Produced markup is following e107 CSS/XHTML standards
|
||||
* If options argument is omitted, default values will be used (which OK most of the time)
|
||||
* Options are intended to handle some very special cases.
|
||||
*
|
||||
* Overall field options format (array or GET string like this one: var1=val1&var2=val2...):
|
||||
*
|
||||
* - id => (mixed) custom id attribute value
|
||||
* if numeric value is passed it'll be just appended to the name e.g. {filed-name}-{value}
|
||||
* if false is passed id will be not created
|
||||
* if empty string is passed (or no 'id' option is found)
|
||||
* in all other cases the value will be used as field id
|
||||
* default: empty string
|
||||
*
|
||||
* - class => (string) field class(es)
|
||||
* Example: 'tbox select class1 class2 class3'
|
||||
* NOTE: this will override core classes, so you have to explicit include them!
|
||||
* default: empty string
|
||||
*
|
||||
* - size => (int) size attribute value (used when needed)
|
||||
* default: 40
|
||||
*
|
||||
* - readonly => (bool) readonly attribute
|
||||
* default: false
|
||||
*
|
||||
* - disabled => (bool) disabled attribute
|
||||
* default: false
|
||||
*
|
||||
* - tabindex => (int) tabindex attribute value
|
||||
* default: inner tabindex counter
|
||||
*
|
||||
* - other => (string) additional data
|
||||
* Example: 'attribute1="value1" attribute2="value2"'
|
||||
* default: empty string
|
||||
*/
|
||||
class e_form
|
||||
{
|
||||
var $_tabindex_counter = 0;
|
||||
var $_tabindex_enabled = true;
|
||||
var $_cached_attributes = array();
|
||||
|
||||
function e_form($enable_tabindex = true)
|
||||
{
|
||||
$this->_tabindex_enabled = $enable_tabindex;
|
||||
}
|
||||
|
||||
function text($name, $value, $maxlength = 200, $options = array())
|
||||
{
|
||||
$options = $this->format_options('text', $name, $options);
|
||||
return "<input type='text' name='{$name}' value='{$value}' maxlength={$maxlength}".$this->get_attributes($options)." />";
|
||||
}
|
||||
|
||||
function password($name, $maxlength = 50, $options = array())
|
||||
{
|
||||
$options = $this->format_options('text', $name, $options);
|
||||
return "<input type='password' name='{$name}' value='' maxlength={$maxlength}".$this->get_attributes($options)." />";
|
||||
}
|
||||
|
||||
//------------------ Work in progress START --------------------------->
|
||||
function textarea($name, $value, $rows, $cols, $options = array())
|
||||
{
|
||||
//TODO - Add title to option array
|
||||
}
|
||||
|
||||
|
||||
//------------------ Work in progress END --------------------------->
|
||||
|
||||
function get_attributes($options)
|
||||
{
|
||||
$ret = '';
|
||||
//
|
||||
foreach ($options as $option => $optval)
|
||||
{
|
||||
switch ($option) {
|
||||
|
||||
case 'id':
|
||||
$ret .= $this->_format_id($optval, varset($options['name']));
|
||||
break;
|
||||
|
||||
case 'class':
|
||||
if(!empty($optval)) $ret .= " class='{$optval}'";
|
||||
break;
|
||||
|
||||
case 'size':
|
||||
if($optval) $ret .= " size='{$optval}'";
|
||||
break;
|
||||
|
||||
case 'tabindex':
|
||||
if($optval === false || !$this->_tabindex_enabled) break;
|
||||
$ret .= " tabindex='".($optval ? $optval : $this->_tabindex_counter++)."'";
|
||||
break;
|
||||
|
||||
case 'readonly':
|
||||
if($optval) $ret .= " readonly='readonly'";
|
||||
break;
|
||||
|
||||
case 'disabled':
|
||||
if($optval) $ret .= " disabled='disabled'";
|
||||
break;
|
||||
|
||||
case 'other':
|
||||
if($optval) $ret .= " $optval";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function _format_id($value, $name)
|
||||
{
|
||||
if($value === false) return '';
|
||||
|
||||
//format the name first
|
||||
$name = str_replace(array('[]', '[', ']', '_'), array('', '-', '', '-'), $name);
|
||||
|
||||
if(is_numeric($value) && $name) return " id='{$name}-{$value}'";// also useful when name is e.g. name='my_name[]'
|
||||
elseif(empty($value)) return " id='{$name}'";// also useful when name is e.g. name='my_name[some_id]'
|
||||
else return " id='{$value}'";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format options based on the field type,
|
||||
* merge with default
|
||||
*
|
||||
* @param string $type
|
||||
* @param string $name form name attribute value
|
||||
* @param array|string $user_options
|
||||
* @return array merged options
|
||||
*/
|
||||
function format_options($type, $name, $user_options)
|
||||
{
|
||||
if(is_string($user_options)) parse_str($user_options, $user_options);
|
||||
|
||||
$def_options = $this->_default_options($type);
|
||||
|
||||
foreach (array_keys($user_options) as $key)
|
||||
{
|
||||
if(!isset($def_options[$key])) unset($user_options[$key]);
|
||||
}
|
||||
|
||||
$user_options['name'] = $name; //required for some of the automated tasks
|
||||
return array_merge($def_options, $user_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default options array based on the filed type
|
||||
*
|
||||
* @param string $type
|
||||
* @return array default options
|
||||
*/
|
||||
function _default_options($type)
|
||||
{
|
||||
if(isset($this->_cached_attributes[$type])) return $this->_cached_attributes[$type];
|
||||
|
||||
$def_options = array(
|
||||
'class' => '',
|
||||
'size' => '',
|
||||
'readonly' => false,
|
||||
'disabled' => false,
|
||||
'tabindex' => $this->_tab_counter,
|
||||
'other' => ''
|
||||
);
|
||||
|
||||
switch ($type) {
|
||||
case 'hidden':
|
||||
$def_options = array('disabled' => false, 'other' => '');
|
||||
break;
|
||||
|
||||
case 'text':
|
||||
$def_options['class'] = 'tbox input-text';
|
||||
break;
|
||||
|
||||
case 'textarea':
|
||||
$def_options['class'] = 'tbox textarea';
|
||||
break;
|
||||
|
||||
case 'select':
|
||||
$def_options['class'] = 'tbox select';
|
||||
break;
|
||||
|
||||
case 'radio':
|
||||
$def_options['class'] = 'radio';
|
||||
break;
|
||||
|
||||
case 'checkbox':
|
||||
$def_options['class'] = 'checkbox';
|
||||
break;
|
||||
|
||||
case 'submit':
|
||||
$def_options['class'] = 'button';
|
||||
break;
|
||||
|
||||
case 'admin_button':
|
||||
break;
|
||||
|
||||
case 'option':
|
||||
$def_options = array('class' => '', 'other' => '');
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_cached_attributes[$type] = $def_options;
|
||||
return $def_options;
|
||||
}
|
||||
}
|
||||
|
||||
class form {
|
||||
|
||||
|
||||
function form_open($form_method, $form_action, $form_name = "", $form_target = "", $form_enctype = "", $form_js = "") {
|
||||
$method = ($form_method ? "method='".$form_method."'" : "");
|
||||
$target = ($form_target ? " target='".$form_target."'" : "");
|
||||
$name = ($form_name ? " id='".$form_name."' " : " id='myform'");
|
||||
return "\n<form action='".$form_action."' ".$method.$target.$name.$form_enctype.$form_js.">";
|
||||
}
|
||||
|
||||
|
||||
function form_text($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox", $form_readonly = "", $form_tooltip = "", $form_js = "") {
|
||||
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
||||
$value = (isset($form_value) ? " value='".$form_value."'" : "");
|
||||
@ -37,7 +242,7 @@ class form {
|
||||
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
||||
return "\n<input class='".$form_class."' type='text' ".$name.$value.$size.$maxlength.$readonly.$tooltip.$form_js." />";
|
||||
}
|
||||
|
||||
|
||||
function form_password($form_name, $form_size, $form_value, $form_maxlength = FALSE, $form_class = "tbox", $form_readonly = "", $form_tooltip = "", $form_js = "") {
|
||||
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
||||
$value = (isset($form_value) ? " value='".$form_value."'" : "");
|
||||
@ -47,14 +252,14 @@ class form {
|
||||
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
||||
return "\n<input class='".$form_class."' type='password' ".$name.$value.$size.$maxlength.$readonly.$tooltip.$form_js." />";
|
||||
}
|
||||
|
||||
|
||||
function form_button($form_type, $form_name, $form_value, $form_js = "", $form_image = "", $form_tooltip = "") {
|
||||
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
||||
$image = ($form_image ? " src='".$form_image."' " : "");
|
||||
$tooltip = ($form_tooltip ? " title='".$form_tooltip."' " : "");
|
||||
return "\n<input class='button' type='".$form_type."' ".$form_js." value='".$form_value."'".$name.$image.$tooltip." />";
|
||||
}
|
||||
|
||||
|
||||
function form_textarea($form_name, $form_columns, $form_rows, $form_value, $form_js = "", $form_style = "", $form_wrap = "", $form_readonly = "", $form_tooltip = "") {
|
||||
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
||||
$readonly = ($form_readonly ? " readonly='readonly'" : "");
|
||||
@ -63,52 +268,52 @@ class form {
|
||||
$style = ($form_style ? " style='".$form_style."'" : "");
|
||||
return "\n<textarea class='tbox' cols='".$form_columns."' rows='".$form_rows."' ".$name.$form_js.$style.$wrap.$readonly.$tooltip.">".$form_value."</textarea>";
|
||||
}
|
||||
|
||||
|
||||
function form_checkbox($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
|
||||
$name = ($form_name ? " id='".$form_name.$form_value."' name='".$form_name."'" : "");
|
||||
$checked = ($form_checked ? " checked='checked'" : "");
|
||||
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
||||
return "\n<input type='checkbox' value='".$form_value."'".$name.$checked.$tooltip.$form_js." />";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function form_radio($form_name, $form_value, $form_checked = 0, $form_tooltip = "", $form_js = "") {
|
||||
$name = ($form_name ? " id='".$form_name.$form_value."' name='".$form_name."'" : "");
|
||||
$checked = ($form_checked ? " checked='checked'" : "");
|
||||
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
||||
return "\n<input type='radio' value='".$form_value."'".$name.$checked.$tooltip.$form_js." />";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function form_file($form_name, $form_size, $form_tooltip = "", $form_js = "") {
|
||||
$name = ($form_name ? " id='".$form_name."' name='".$form_name."'" : "");
|
||||
$tooltip = ($form_tooltip ? " title='".$form_tooltip."'" : "");
|
||||
return "<input type='file' class='tbox' size='".$form_size."'".$name.$tooltip.$form_js." />";
|
||||
}
|
||||
|
||||
|
||||
function form_select_open($form_name, $form_js = "") {
|
||||
return "\n<select id='".$form_name."' name='".$form_name."' class='tbox' ".$form_js." >";
|
||||
}
|
||||
|
||||
|
||||
function form_select_close() {
|
||||
return "\n</select>";
|
||||
}
|
||||
|
||||
|
||||
function form_option($form_option, $form_selected = "", $form_value = "", $form_js = "") {
|
||||
$value = ($form_value !== FALSE ? " value='".$form_value."'" : "");
|
||||
$selected = ($form_selected ? " selected='selected'" : "");
|
||||
return "\n<option".$value.$selected." ".$form_js.">".$form_option."</option>";
|
||||
}
|
||||
|
||||
|
||||
function form_hidden($form_name, $form_value) {
|
||||
return "\n<input type='hidden' id='".$form_name."' name='".$form_name."' value='".$form_value."' />";
|
||||
}
|
||||
|
||||
|
||||
function form_close() {
|
||||
return "\n</form>";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Usage
|
||||
echo $rs->form_open("post", e_SELF, "_blank");
|
||||
@ -130,6 +335,6 @@ echo $rs->form_option("Option 4");
|
||||
echo $rs->form_select_close();
|
||||
echo $rs->form_close();
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user