[PHPVortex-Commit] phpvortex SEC_Edit.class.php,NONE,1.1 SEC_Form.class.php,1.1,1.2 SEC_List.class.p
Brought to you by:
nop144666
From: Thiago R. <nop...@us...> - 2004-10-08 17:14:59
|
Update of /cvsroot/phpvortex/phpvortex In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20310 Modified Files: SEC_Form.class.php SEC_List.class.php SEC_ListNavigator.class.php TB_Base.class.php Added Files: SEC_Edit.class.php Log Message: Added SEC_Edit, and made several changes and improvements around to better suit it Index: SEC_List.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/SEC_List.class.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SEC_List.class.php 7 Oct 2004 18:34:44 -0000 1.2 --- SEC_List.class.php 8 Oct 2004 17:14:47 -0000 1.3 *************** *** 66,70 **** * Constructor: Load all parameters into member variables. * - * @param TB_Base $table Table to show the list from. * @param array $opts Parameters for the object, as 'var' => 'value'. */ --- 66,69 ---- *************** *** 84,88 **** { echo "<div class='div_list_full'>\n"; ! $page = (isset($_REQUEST["page_{$this->table->name}"])?$_REQUEST["page_{$this->table->name}"]:(($this->recspage>0)?0:-1)); if ($this->recspage > 0) $this->table->list_recspage = $this->recspage; $this->table->ShowList($this->url, $page, $this->data); --- 83,87 ---- { echo "<div class='div_list_full'>\n"; ! $page = (isset($_REQUEST["page_{$this->table->name}"])?$_REQUEST["page_{$this->table->name}"]:0); if ($this->recspage > 0) $this->table->list_recspage = $this->recspage; $this->table->ShowList($this->url, $page, $this->data); *************** *** 92,96 **** } parent::Show(); ! echo "</div>"; } } --- 91,95 ---- } parent::Show(); ! echo "</div>\n"; } } --- NEW FILE: SEC_Edit.class.php --- <?php /** * File for class SEC_Edit. * * @package Vortex * @subpackage Page * @author Thiago Ramon Gonçalves Montoya * @copyright Copyright 2004, Thiago Ramon Gonçalves Montoya * @license http://opensource.org/licenses/lgpl-license.php GNU Lesser General Public License */ /** Require the base class */ require_once('SEC_Base.class.php'); /** Require the URL utility class */ require_once('URL.class.php'); /** * Class for full Table editing, with forms and lists. * * @package Vortex * @subpackage Page */ class SEC_Edit extends SEC_Base { /** * Table to edit. * * @var TB_Base */ var $table = NULL; /** * Form class to use. * * @var string */ var $form = 'SEC_Form'; /** * List class to use. * * @var string */ var $list = 'SEC_List'; /** * Navigator class to use. Empty to use no navigator. * * @var string */ var $navi = 'SEC_ListNavigator'; /** * Number of records per page to display in the list. * * @var int */ var $recspage = -1; /** * Buttons to use, and order. * * The buttons are:<ul> * <li /> 'S' = Submit * <li /> 'R' = Reset * <li /> 'N' = New * <li /> 'D' = Delete * </ul> * * @var string */ var $buttons = 'SRND'; /** * Text for the submit button. * * @var string */ var $txt_submit = ''; /** * Image for the submit button. * * @var string */ var $img_submit = ''; /** * Text for the reset button. * * @var string */ var $txt_reset = ''; /** * Image for the reset button. * * @var string */ var $img_reset = ''; /** * Text for the new button. * * @var string */ var $txt_new = ''; /** * Image for the new button. * * @var string */ var $img_new = ''; /** * Text for the delete button. * * @var string */ var $txt_delete = ''; /** * Image for the delete button. * * @var string */ var $img_delete = ''; /** * Constructor: Process form data and prepare the section to display. * * @param array $opts Parameters for the object, as 'var' => 'value'. */ function SEC_Edit($opts = array()) { // Load all parameters into member variables. parent::SEC_Base($opts); // See what to do and perform the action if (!empty($_REQUEST["{$this->table->name}_action"])) { $this->Perform($_REQUEST["{$this->table->name}_action"]); } $submit = $this->BuildButtons(); $url =& new URL(); $url->parameters["{$this->table->name}_action"] = 'E'; $opts = array( 'table' => &$this->table, 'url' => $url, 'recspage' => $this->recspage ); if (!empty($this->navi)) $opts['navigator'] = array( 'class' => $this->navi, 'opts' => array( 'url' => $url ) ); $this->AddSection("{$this->table->name}_list", $this->list, $opts); $url->parameters["{$this->table->name}_action"] = 'S'; $this->AddSection("{$this->table->name}_form", $this->form, array( 'table' => &$this->table, 'url' => $url, 'submit' => $submit )); } /** * Perform a action. * * @param string $action Action to perform ('S' for INSERT/UPDATE, 'E' for edit, 'N' for new, 'D' for DELETE). */ function Perform($action) { global $vortex_errors; if (!strcmp($action, 'S')) { if ($this->table->Save($_REQUEST)) { $this->table->Seek(); } else { switch ($this->table->Error()) { case TB_ERR_INCONSIST: $this->AddSection("{$this->table->name}_error", 'SEC_Static', array( 'code' => "<div class='div_error'>{$vortex_errors[TB_ERR_INCONSIST]}</div>" )); $this->table->LoadForm($_REQUEST); break; default: trigger_error($vortex_errors[$this->table->Error()]); break; } } } elseif (!strcmp($action, 'E')) { $this->table->Seek($_REQUEST); } elseif (!strcmp($action, 'N')) { $this->table->Seek(); } elseif (!strcmp($action, 'D')) { if ($this->table->Delete($_REQUEST)) { $this->table->Seek(); } else { switch ($this->table->Error()) { case TB_ERR_EMPTY: $this->AddSection("{$this->table->name}_error", 'SEC_Static', array( 'code' => "<div class='div_error'>{$vortex_errors[TB_ERR_EMPTY]}</div>" )); break; default: trigger_error($vortex_errors[$this->table->Error()]); break; } } } } /** * Build the buttons and return them. * * @return string Returns the HTML code for the form's buttons. */ function BuildButtons() { global $vortex_msgs; $code = ''; $buttons = preg_split('//', $this->buttons, -1, PREG_SPLIT_NO_EMPTY); foreach ($buttons as $button) { if (!strcmp($button, 'S')) { if (empty($this->img_submit)) { $code .= "<input type='submit' value='".(empty($this->txt_submit)?$vortex_msgs['form_submit']:$this->txt_submit)."' />\n"; } else { $code .= "<input type='image' src='{$this->img_submit}' alt='".(empty($this->txt_submit)?$vortex_msgs['form_submit']:$this->txt_submit)."' />\n"; } } elseif (!strcmp($button, 'R')) { if (empty($this->img_reset)) { $code .= "<input type='reset' value='".(empty($this->txt_reset)?$vortex_msgs['form_reset']:$this->txt_reset)."' />\n"; } else { $code .= "<input type='image' src='{$this->img_reset}' alt='".(empty($this->txt_reset)?$vortex_msgs['form_reset']:$this->txt_reset)."' onclick='document.form_{$this->table->name}.reset();return false;' />\n"; } } elseif (!strcmp($button, 'N')) { $url =& new URL(); $url->parameters["{$this->table->name}_action"] = 'N'; $code .= "<script language='JavaScript'>\n\tfunction {$this->table->name}_New() {\n\t\tdocument.form_{$this->table->name}.action = '".$url->Get()."';\n\t\tdocument.form_{$this->table->name}.submit();\n\t}\n</script>\n"; if (empty($this->img_new)) { $code .= "<input type='button' value='".(empty($this->txt_new)?$vortex_msgs['form_new']:$this->txt_new)."' onclick='{$this->table->name}_New();' />\n"; } else { $code .= "<input type='image' src='{$this->img_new}' alt='".(empty($this->txt_new)?$vortex_msgs['form_new']:$this->txt_new)."' onclick='{$this->table->name}_New();' />\n"; } } elseif (!strcmp($button, 'D')) { $url =& new URL(); $url->parameters["{$this->table->name}_action"] = 'D'; $code .= "<script language='JavaScript'>\n\tfunction {$this->table->name}_Delete() {\n\t\tdocument.form_{$this->table->name}.action = '".$url->Get()."';\n\t\tdocument.form_{$this->table->name}.submit();\n\t}\n</script>\n"; if (empty($this->img_delete)) { $code .= "<input type='button' value='".(empty($this->txt_delete)?$vortex_msgs['form_delete']:$this->txt_delete)."' onclick='{$this->table->name}_Delete();' />\n"; } else { $code .= "<input type='image' src='{$this->img_delete}' alt='".(empty($this->txt_delete)?$vortex_msgs['form_delete']:$this->txt_delete)."' onclick='{$this->table->name}_Delete();' />\n"; } } } return $code; } /** * Outputs the section to the client. */ function Show() { echo "<div class='div_edit'>\n"; parent::Show(); echo "</div>\n"; } } ?> Index: SEC_Form.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/SEC_Form.class.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SEC_Form.class.php 7 Oct 2004 21:20:03 -0000 1.1 --- SEC_Form.class.php 8 Oct 2004 17:14:47 -0000 1.2 *************** *** 12,15 **** --- 12,17 ---- /** Require the base class */ require_once('SEC_Base.class.php'); + /** Require the URL utility class */ + require_once('URL.class.php'); /** Index: SEC_ListNavigator.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/SEC_ListNavigator.class.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SEC_ListNavigator.class.php 7 Oct 2004 18:35:23 -0000 1.2 --- SEC_ListNavigator.class.php 8 Oct 2004 17:14:47 -0000 1.3 *************** *** 132,136 **** } parent::Show(); ! echo "</div>"; } } --- 132,136 ---- } parent::Show(); ! echo "</div>\n"; } } Index: TB_Base.class.php =================================================================== RCS file: /cvsroot/phpvortex/phpvortex/TB_Base.class.php,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** TB_Base.class.php 7 Oct 2004 21:22:08 -0000 1.13 --- TB_Base.class.php 8 Oct 2004 17:14:47 -0000 1.14 *************** *** 14,48 **** /** - * No Error - * - * Error codes for TB_* - */ - define('TB_ERR_OK', 0); - /** - * Inconsistency detected in a field. - * - * Error codes for TB_* - */ - define('TB_ERR_INCONSIST', 1); - /** - * No Primary Key found. - * - * Error codes for TB_* - */ - define('TB_ERR_NOPKEY', 2); - /** - * Empty parameter or RecordSet. - * - * Error codes for TB_* - */ - define('TB_ERR_EMPTY', 3); - /** - * Database error (use {@link DB_Base::Error()} to discover which error). - * - * Error codes for TB_* - */ - define('TB_ERR_DB', 4); - - /** * Base class for tables in databases. * --- 14,17 ---- *************** *** 108,112 **** * @var int */ ! var $list_recspage = 25; /** --- 77,81 ---- * @var int */ ! var $list_recspage = 15; /** *************** *** 184,187 **** --- 153,169 ---- /** + * Set the internal buffer to the data coming from a form. + * + * @param array $data Array containing the data to load as 'field' => 'value'. + */ + function LoadForm($data) + { + $this->data = array(); + foreach ($this->fields as $field) { + if (isset($data[$field->name_form])) $this->data[$field->name_db] = $data[$field->name_form]; + } + } + + /** * INSERT or UPDATE the data to the database. * *************** *** 257,261 **** { if (!empty($data)) if (!$this->Seek($data)) return FALSE; ! if (empty($this->data)) return FALSE; $where = ''; foreach ($this->fields as $field) if ($field->pkey) { --- 239,246 ---- { if (!empty($data)) if (!$this->Seek($data)) return FALSE; ! if (empty($this->data)) { ! $this->error = TB_ERR_EMPTY; ! return FALSE; ! } $where = ''; foreach ($this->fields as $field) if ($field->pkey) { |