Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Sobota, 28. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Problem with: Trigger update before

phpMyEdit Configuration     Problem with: Trigger update before
Odoslať novú tému   Odpovedať na tému    
 
Malino     Založený: 23.02.2010   Príspevky: 7  
Príspevok Zaslal: 2010-03-08 00:22
Návrat hore  Odpovedať s citátom     

Hi Community,
i have a additional virtual field:
Kód:
$opts['fdd']['hf_confirmpwd'] = array(
  'name'     => 'Passwort wiederholen',
  'select'   => 'T',
  'input'    => 'W',
  'maxlen'   => 20,
  'sort'     => true,
  'options'  => 'ACPVD',
  'sql'      => 'CONCAT("")',
);

and try to compare it's content in my trigger:
Kód:
$opts['triggers']['insert']['before'] = 'ghsv_hundefuehrer.inc';
$opts['triggers']['update']['before'] = 'ghsv_hundefuehrer.inc';

It works fine :)

But after that i must unset the variable, because i have no database field with this name:
Kód:
unset($newvals['hf_confirmpwd']);


I get the following error messages:
Citácia:
MySQL error 1054
Unknown column 'hf_confirmpwd' in 'field list'
---
Test-Code from my Trigger: "hello trigger"

MySQL error 1054
Unknown column 'hf_confirmpwd' in 'field list'
---
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\...\phpMyEdit.class.php on line 2749


In insert mode it works fine :)
In update mode the variables $oldvals and $changed are empty.

greets Malino

My settings:
Windows XP Vers.2002 SP3
Mozilla Firefox 3.5.8
XAMPP with PHP 5.2.8
phpMyEdit.class.php,v 1.212 2008-11-11 04:46:36 nepto
phpMyEdit-mce-cal.class.php,v 1.10 2008-05-21 17:28:17 ajh

 
doug     Založený: 10.02.2003   Príspevky: 1013   Bydlisko: Denver, Colorado (USA)
Príspevok Zaslal: 2010-03-09 23:51
Návrat hore  Odpovedať s citátom     

I think the virtual fields only work in VLF modes and for visual purposes display only. Thus you can't use it with insert or update.

Kód:
$opts['fdd']['hf_confirmpwd'] = array(
  'name'     => 'Passwort wiederholen',
  'select'   => 'T',
  'input'    => 'W',
  'maxlen'   => 20,
  'sort'     => true,
  'options'  => 'VLF',
  'sql'      => 'CONCAT("")',
);


 
Malino     Založený: 23.02.2010   Príspevky: 7  
Príspevok Zaslal: 2010-03-10 23:33
Návrat hore  Odpovedať s citátom     

What a pity! I'll do it by myself...

First step: i need the identifier for my virtual field:
Kód:
$opts[fdd][my_virtual_field][input] = 'V';
$opts[fdd][my_virtual_field][sql] = 'CONCAT("")'; // sql is required


Changes in phpMyEdit.class.php
2. step: virtual fields are readonly
Kód:
function readonly($k) { return stristr($this->fdd[$k]['input'],'R') || $this->virtual($k); }

Delete the second condition, the field is editable.
Kód:
function readonly($k) { return stristr($this->fdd[$k]['input'],'R'); }

3. step: SQL-Querys fail, because my virtual field doesn't exist.
3.1. change sql insert statement: (add + line to your code)
Kód:
function do_add_record() {
...
    // Real query (no additional query in this method)
    foreach ($newvals as $fd => $val) {
        if ($fd == '') continue;
+   if ($this->virtual($fd)) continue; /* NEW! don't insert virtual fields */
   if ($this->col_has_sqlw($this->fdn[$fd])) {
...
}

3.2. change sql update statement
Kód:
function do_change_record () {
...
    foreach ($newvals as $fd => $val) {
        if ($fd == '') continue;
+   if ($this->virtual($fd)) continue;   /* NEW! */
   if ($this->col_has_sqlw($this->fdn[$fd])) {
...
}

4. insert my_virtual_field in $newvals and $oldvals
4.1. don't check virtual in processed
Kód:

function processed($k)
{
/*  if($this->virtual($k)) {
        return false;
    }*/
    $options = @$this->fdd[$k]['options'];
...

4.2 insert the sql as value in $oldvalue
Kód:

function do_change_record() {
...
    // Prepare query to retrieve oldvals
    for ($k = 0; $k < $this->num_fds; $k++) {
        if ($this->processed($k) && !$this->readonly($k)) {
       $fd = $this->fds[$k];
       $fn = $this->get_data_cgi_var($fd);
       $newvals[$this->fds[$k]] = is_array($fn) ? join(',',$fn) : $fn;
//OLD
/*          if ($query_oldrec == '') {
            $query_oldrec = 'SELECT '.$this->sd.$fd.$this->ed;
            } else {
            $query_oldrec .= ','.$this->sd.$fd.$this->ed;
       }*/
//NEW: for virtual fields get the fdd sql as value
            $query_oldrec == '' ? $query_oldrec = 'SELECT ' : $query_oldrec .= ',';
       if(!$this->virtual($k)) {
            $query_oldrec .= $this->sd.$fd.$this->ed;
       } else {
            $query_oldrec .= $this->fdd[$k][sql].' as '.$this->sd.$fd.$this->ed;
       }
   }
    }
...



i have realised a "confirm password" with this hack.

greets Malino

 
sagiben     Založený: 27.01.2009   Príspevky: 15  
Príspevok Zaslal: 2010-10-06 13:39
Návrat hore  Odpovedať s citátom     

Hi Malino,

I applied your change to my copy of phpMyEdit class and it works just great.

Can you please publish the code of your trigger, i.e. ghsv_hundefuehrer.inc ?

I want to use it for the same reason, i.e. confirm password.

Thank you,
Sagi.

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov