1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-06 06:38:00 +02:00

Improve Form handler - work in progress

This commit is contained in:
secretr
2008-12-12 16:36:45 +00:00
parent 016a4b9e4e
commit cac0e1cf12
2 changed files with 298 additions and 82 deletions

View File

@@ -9,8 +9,8 @@
* Cache Administration Area * Cache Administration Area
* *
* $Source: /cvs_backup/e107_0.8/e107_admin/cache.php,v $ * $Source: /cvs_backup/e107_0.8/e107_admin/cache.php,v $
* $Revision: 1.5 $ * $Revision: 1.6 $
* $Date: 2008-12-11 18:13:10 $ * $Date: 2008-12-12 16:36:45 $
* $Author: secretr $ * $Author: secretr $
* *
*/ */
@@ -25,8 +25,9 @@ $e_sub_cat = 'cache';
require_once("auth.php"); require_once("auth.php");
require_once(e_HANDLER."cache_handler.php"); require_once(e_HANDLER."cache_handler.php");
require_once(e_HANDLER."message_handler.php");
$ec = new ecache; $ec = new ecache;
$message = array(); $emessage = &eMessage::getInstance();
if ($pref['cachestatus'] == '2') if ($pref['cachestatus'] == '2')
{ {
@@ -58,9 +59,11 @@ if (isset($_POST['submit_cache']))
$ec->clear(); $ec->clear();
$ec->clear_sys(); $ec->clear_sys();
//FIXME - admin_update - return formatted message instead tablerender & output, new message handler $emessage->add(CACLAN_4, E_MESSAGE_SUCCESS);
//admin_update(true, 'update', CACLAN_4); }
$message = array(LAN_UPDATE, CACLAN_4); else
{
$emessage->add(LAN_NO_CHANGE, E_MESSAGE_INFO);
} }
} }
@@ -68,18 +71,14 @@ if (isset($_POST['empty_syscache']))
{ {
$ec->clear_sys(); $ec->clear_sys();
$admin_log->log_event('CACHE_02', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, ''); $admin_log->log_event('CACHE_02', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, '');
$emessage->add(CACLAN_15, E_MESSAGE_SUCCESS);
//$ns->tablerender(LAN_UPDATE, "<div style='text-align:center'><b>".CACLAN_15."</b></div>");
$message = array(LAN_UPDATE, CACLAN_15);
} }
if (isset($_POST['empty_cache'])) if (isset($_POST['empty_cache']))
{ {
$ec->clear(); $ec->clear();
$admin_log->log_event('CACHE_03', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, ''); $admin_log->log_event('CACHE_03', $pref['syscachestatus'].', '.$pref['cachestatus'], E_LOG_INFORMATIVE, '');
$emessage->add(CACLAN_6, E_MESSAGE_SUCCESS);
//$ns->tablerender(LAN_UPDATE, "<div style='text-align:center'><b>".CACLAN_6."</b></div>");
$message = array(LAN_UPDATE, CACLAN_6);
} }
@@ -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); $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); $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."'> <form method='post' action='".e_SELF."'>
<table style='".ADMIN_WIDTH."' class='fborder'> <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> <tr>
<td colspan='3' class='fcaption'>".CACLAN_1."</td> <th><!-- --></th>
<th class='center last'>".CACLAN_1."</th>
</tr> </tr>
</thead>
<tbody>
<tr> <tr>
<td class='forumheader3' style='width:60%;'>".CACLAN_11.": <div class='smalltext'>".CACLAN_13."</div><br />{$nonsys_count}</td> <td>
<td class='forumheader3' style='width:20%'> <strong>".CACLAN_11."</strong>: {$nonsys_count}
<input type='radio' name='cachestatus' value='1'".($pref['cachestatus'] ? " checked='checked'" : "")." /> ".LAN_ENABLED."&nbsp;&nbsp; <div class='smalltext'>".CACLAN_13."</div>
<input type='radio' name='cachestatus' value='0'".(!$pref['cachestatus'] ? " checked='checked'" : "")." /> ".LAN_DISABLED."&nbsp;&nbsp;
</td> </td>
<td class='forumheader3' style='width:20%'> <input class='button' type='submit' name='empty_cache' value=\"".CACLAN_5."\" /> <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>&nbsp;&nbsp;
<input type='radio' id='cachestatus-1b' name='cachestatus' value='0'".(!$pref['cachestatus'] ? " checked='checked'" : "")." />
<label for='cachestatus-1b'>".LAN_DISABLED."</label>
</td> </td>
</tr> </tr>
<tr> <tr>
<td class='forumheader3' style='width:60%;'>".CACLAN_12.": <div class='smalltext'>".CACLAN_14."</div><br />{$sys_count}</td> <td>
<td class='forumheader3' style='width:20%'> <strong>".CACLAN_12."</strong>: {$sys_count}
<input type='radio' name='syscachestatus' value='1'".($pref['syscachestatus'] ? " checked='checked'" : "")." /> ".LAN_ENABLED."&nbsp;&nbsp; <div class='smalltext'>".CACLAN_14."</div>
<input type='radio' name='syscachestatus' value='0'".(!$pref['syscachestatus'] ? " checked='checked'" : "")." /> ".LAN_DISABLED."&nbsp;&nbsp;
</td> </td>
<td class='forumheader3' style='width:20%'> <td class='center middle'>
<input class='button' type='submit' name='empty_syscache' value=\"".CACLAN_16."\" /> <input type='radio' name='syscachestatus' id='syscachestatus-1a' value='1'".($pref['syscachestatus'] ? " checked='checked'" : "")." />
</td> <label for='syscachestatus-1a'>".LAN_ENABLED."</label>&nbsp;&nbsp;
</tr> <input type='radio' name='syscachestatus' id='syscachestatus-1b' value='0'".(!$pref['syscachestatus'] ? " checked='checked'" : "")." />
<label for='syscachestatus-1b'>".LAN_DISABLED."</label>
<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> </td>
</tr> </tr>
</tbody>
</table> </table>
</form> <div class='buttons-bar left'>
</div>"; <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); $ns->tablerender(CACLAN_3, $text);

View File

@@ -1,24 +1,229 @@
<?php <?php
/* /*
+ ----------------------------------------------------------------------------+ * e107 website system
| e107 website system *
| * Copyright (C) 2001-2008 e107 Inc (e107.org)
| <20>Steve Dunstan 2001-2002 * Released under the terms and conditions of the
| http://e107.org * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
| jalist@e107.org *
| * Form Handler
| 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.4 $
| $Source: /cvs_backup/e107_0.8/e107_handlers/form_handler.php,v $ * $Date: 2008-12-12 16:36:45 $
| $Revision: 1.3 $ * $Author: secretr $
| $Date: 2008-04-04 21:40:38 $ *
| $Author: e107steved $
+----------------------------------------------------------------------------+
*/ */
if (!defined('e107_INIT')) { exit; } 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 { class form {
function form_open($form_method, $form_action, $form_name = "", $form_target = "", $form_enctype = "", $form_js = "") { function form_open($form_method, $form_action, $form_name = "", $form_target = "", $form_enctype = "", $form_js = "") {