Problem with php code in php-plugin on form when use "copy"+"clone"

Hi,

I try copy 1 record from list1 to multiple new records.
Use "copy" button from form1 and form-plugin-clone.

When i go from list1 with "edit"-option to displaying choosen record and i use "copy"-button i get this amount of new record that i have written in field: {ccjom_cc_kk_karta_rejestr___zamow_quantity_pos_ordered}.
lets assume that this amount is: "6".

I need for all new records get unique serial_number stored in field:
{ccjom_cc_kk_karta_rejestr___product_serial_num2}
i write on form "first-serial-number2" - for example --- number: "26"

i need get for
first new record --- ___product_serial_num2 = 26
second new record --- ___product_serial_num2 =28
third (3) new record --- ___product_serial_num2 =30
(4) new record --- ___product_serial_num2 =32
(5) new record --- ___product_serial_num2 =34
(6) new record --- ___product_serial_num2 =36

on first record field --- ___product_serial_num2 = 26 should be not changed
all next records --- ___product_serial_num2 = should be earlier + 2

on my screen shot i created 6 records with id: 31 - 36
record 31 --- should be = 26
record 32 --- should be = 28
record 33 --- should be = 30
record 34 --- should be = 32
record 35 --- should be = 34
record 36 --- should be = 36

my code for php-plugin on form is:
PHP:
$db =& JFactory::getDBO();
$quantity2 = '{ccjom_cc_kk_karta_rejestr___zamow_quantity_pos_ordered_raw}';
$currentserial2 = '{ccjom_cc_kk_karta_rejestr___product_serial_num2_raw}';
$idclone2 = '{ccjom_cc_kk_karta_rejestr___id_raw}';
 
for ($i = 2; $i <= $quantity2; $i++) {
    $idclone2 = '{ccjom_cc_kk_karta_rejestr___id_raw}' + 1;
    $currentserial2 = '{ccjom_cc_kk_karta_rejestr___product_serial_num2_raw}' + 2;
 
$query = "UPDATE `ccjom_cc_kk_karta_rejestr` SET `product_serial_num2`= $currentserial2
WHERE `id` = " . $db->Quote($idclone2);
 
$db->setQuery($query);
$db->query();
}

this code seems nothing to do.
What is wrong?
 

Attachments

  • Zaznaczenie_024.png
    Zaznaczenie_024.png
    108.3 KB · Views: 374
  • Zaznaczenie_025.png
    Zaznaczenie_025.png
    39.5 KB · Views: 368
  • Zaznaczenie_026.png
    Zaznaczenie_026.png
    15 KB · Views: 359
  • Zaznaczenie_027.png
    Zaznaczenie_027.png
    54.6 KB · Views: 351
  • Zaznaczenie_028.png
    Zaznaczenie_028.png
    56.1 KB · Views: 376
I try also this code, but also doesn't work:

PHP:
$db =& JFactory::getDBO();
$quantity2 = '{ccjom_cc_kk_karta_rejestr___zamow_quantity_pos_ordered_raw}';
$currentserial2 = '{ccjom_cc_kk_karta_rejestr___product_serial_num2_raw}';
$idclone2 = '{ccjom_cc_kk_karta_rejestr___id_raw}';
 
for ($i = 2; $i <= $quantity2; $i++) {
    $idclone3 = $idclone2 + 1;
    $currentserial3 = $currentserial2 + 2;
 
$query = "UPDATE `ccjom_cc_kk_karta_rejestr` SET `product_serial_num2`= ". $currentserial3
WHERE `id` = .$idclone3 ";
 
$db->setQuery($query);
$db->query();
}


I try also something more simple, this also doesn' t work:
PHP:
$db =& JFactory::getDBO();
$quantity2 = (int) '{ccjom_cc_kk_karta_rejestr___zamow_quantity_pos_ordered}';
$currentserial2 = (int) '{ccjom_cc_kk_karta_rejestr___product_serial_num2}';
$idclone2 = (int) '{ccjom_cc_kk_karta_rejestr___id}';
 
    $idclone3 = $idclone2 + 1;
    $currentserial3 = $currentserial2 + 2;
 
$query = "UPDATE `ccjom_cc_kk_karta_rejestr` SET `product_serial_num2`='222', `ip_nr_seryjny`='numer_t1'
WHERE `id` = " .$idclone3 ;
 
$db->setQuery($query);
$db->query();
 
Something simple without this: " for ($i = 2; $i <= $quantity2; $i++).... "
actually works:
PHP:
$db =& JFactory::getDBO();
$quantity2 = (int) '{ccjom_cc_kk_karta_rejestr___zamow_quantity_pos_ordered}';
$currentserial2 = (int) '{ccjom_cc_kk_karta_rejestr___product_serial_num2}';
$idclone2 = (int) '{ccjom_cc_kk_karta_rejestr___id}';
 
    $idclone3 = $idclone2 - 1;
    $currentserial3 = $currentserial2 + ($quantity2 - 2)*2;
 
    $idclone4 = $idclone2;
    $currentserial4 = $currentserial2 + ($quantity2 - 1)*2;
 
 
$query1 = "UPDATE `ccjom_cc_kk_karta_rejestr` SET `product_serial_num2`= " .$currentserial3. " WHERE `id` = " .$idclone3. " " ;
 
$db->setQuery($query1);
$db->query();
 
$query2 = "UPDATE `ccjom_cc_kk_karta_rejestr` SET `product_serial_num2`= " .$currentserial4. " WHERE `id` = " .$idclone4. " " ;
 
$db->setQuery($query2);
$db->query();

this set serial number in "last-1"-record and in "last"-record.
 
In your loops, you are always setting $idclone3 to the same thing, it never gets incremented, which I presume is what you need to do.

But really, this is custom code which is beyond the scope of standard support.

-- hugh
 
OK, i coded this at friday afternoon. It works.

All what is wrong that is: option "copy" + "clone" ( even without any php-plugin with my code) doesn't work when i have on my form field---databasejoin-render_as_multiselect_dropdown :-(. I ,temporary , unpublished this field from my form and then all nicely works.
That is no problem with this field databasejoin-render_as_multiselect_dropdown when i use only "copy" --- when use to copy edited record to --1 new copied record-- (plugin "clone" is unpublished then)

When i want "copy" multiple new records using this ""copy" + "clone"" than i get "error message" and this not works.

I will try to test this problem else.
 
We are in need of some funding.
More details.

Thank you.

Staff online

Members online

Back
Top