Radicore Forum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » RADICORE development » Transaction Patterns » PopUp and add1 - key fields
PopUp and add1 - key fields [message #5189] Thu, 10 December 2015 05:20 Go to next message
htManager is currently offline  htManager
Messages: 316
Registered: May 2014
Senior Member
I have a virtual private database with a shared table 'orga_kontakte' and a table 'orga_kontakte_adresse' with contacts of the logged-in account.

Key fields in both tables are user_id, user_seq_no and rdcaccount_id.

If I add a record in 'orga_kontakte_adresse' I have the possibility to choose from the shared table 'orga_kontakte' with a popup form. If I choose from the shared table I want to keep the values for user_id and user_seq_no and only want to change the value for rdcaccount_id. This is done in function _cm_post_popupReturn() in orga_kontakte_adresse.class.inc and I can see the right key values.

My problem is now that if I press the submit button the values are changed because of the following code:

function _cm_getInitialData ($fieldarray)
// Perform custom processing for the getInitialData method.
// $fieldarray contains data from the initial $where clause.
{
{
// get next available number for user_seq_no
$where = "user_id='{$_SESSION['logon_user_id']}'";
$query = "SELECT max(user_seq_no) FROM $this->tablename WHERE $where";
$count = $this->getCount($query);
$fieldarray['user_id'] = $_SESSION['logon_user_id'];
$fieldarray['user_seq_no'] = $count + 1;
} // if

// set these fields to 'noedit' (read only)
$this->fieldspec['user_id']['noedit'] = 'y';
$this->fieldspec['user_seq_no']['noedit'] = 'y';

return $fieldarray;

} // _cm_getInitialData

This code is correct if the popup form is not used and the new contact is only for this account.

Can I insert a condition clause after $count = $this->getCount($query); to decide if the popup was called or not? And if yes with which function/variable can I do this?

The purpose of this is to keep trace of the contacts in the shared table.
Re: PopUp and add1 - key fields [message #5190 is a reply to message #5189] Thu, 10 December 2015 05:48 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2244
Registered: April 2006
Location: Surrey, UK
Senior Member
After returning from another form you can use the following code to determine the pattern_id of that form:
if (!empty($GLOBALS['return_from'])) {
    $prev_pattern_id = getPatternId($GLOBALS['return_from']);
}

$GLOBALS['return_from'] will contain the task_id of the form from which you have just returned, and with the above code you can identify its pattern.


Re: PopUp and add1 - key fields [message #5191 is a reply to message #5190] Thu, 10 December 2015 08:51 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 316
Registered: May 2014
Senior Member
Thank you. It works just the way I want.
Re: PopUp and add1 - key fields [message #5194 is a reply to message #5191] Fri, 11 December 2015 06:21 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 316
Registered: May 2014
Senior Member
Sorry, I was too fast. When I press the submit button the _cm_getInitialData function is called again and the $prev_pattern_id is 'ADD1'. Thus the key fields are changed once more with the other, original values. How can I prevent this?
Re: PopUp and add1 - key fields [message #5195 is a reply to message #5194] Fri, 11 December 2015 11:11 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2244
Registered: April 2006
Location: Surrey, UK
Senior Member
If the code inside the _cm_getInitialData() method is dependent on what is returned from a popup, the only way to deal with this is to set a class variable in the _cm_popupReturn() method which you can examine in the _cm_getInitialData() method.

Re: PopUp and add1 - key fields [message #5221 is a reply to message #5195] Fri, 18 December 2015 11:08 Go to previous messageGo to next message
htManager is currently offline  htManager
Messages: 316
Registered: May 2014
Senior Member
I do know and understand what you mean but I can't get the code right. I worked through two more php tutorials but I don't succeed. Here is my code, can you take a look at it?

Why can't I change the status of $popupaufruf_status? Is it because of the visibility of the variable? Thank you very much in advance.

<?php
require_once 'std.table.class.inc';
class orga_kontakte_adresse extends Default_Table
{
public $popupaufruf_status = False;

// ************************************************************ ****************
function orga_kontakte_adresse ()
{
// save directory name of current script
$this->dirname = dirname(__file__);

$this->dbms_engine = ''; // to be supplied by getFieldSpec_original()
$this->dbprefix = ''; // to be supplied by getFieldSpec_original()
$this->dbname = 'htm';
$this->tablename = 'orga_kontakte_adresse';

// call this method to get original field specifications
// (note that they may be modified at runtime)
$this->fieldspec = $this->getFieldSpec_original();

} // kontakte

function _cm_getInitialData ($fieldarray)
// Perform custom processing for the getInitialData method.
// $fieldarray contains data from the initial $where clause.
{
{
if ($popupaufruf_status == True) {
echo 'Wahre Welt';
}
elseif ($popupaufruf_status == False) {
echo 'Falsche Welt';

// get next available number for user_seq_no
$where = "user_id='{$_SESSION['logon_user_id']}'";
$query = "SELECT max(user_seq_no) FROM $this->tablename WHERE $where";
$count = $this->getCount($query);
$fieldarray['user_id'] = $_SESSION['logon_user_id'];
$fieldarray['user_seq_no'] = $count + 1;
}
}

// set these fields to 'noedit' (read only)
$this->fieldspec['user_id']['noedit'] = 'y';
$this->fieldspec['user_seq_no']['noedit'] = 'y';

return $fieldarray;

} // _cm_getInitialData

function _cm_popupCall ($popupname, $where, $fieldarray, &$settings)
// if a popup button has been pressed the contents of $where may need to
// be altered before the popup screen is called.
// NOTE: $settings is passed BY REFERENCE as it may be altered.
{
// allow only one entry to be selected (the default)
$settings['select_one'] = FALSE;

return $where;

} // _cm_popupCall

// ************************************************************ ****************
function _cm_popupReturn ($fieldarray, $return_from, &$select_array, $return_files)
// process a selection returned from a popup screen.
// $fieldarray contains the record data when the popup button was pressed.
// $return_from identifies which popup screen was called.
// $select_array contains an array of item(s) selected in that popup screen.
// $return_files contains a list of all files loaded via a fileupload task.
// NOTE: $select_array is passed BY REFERENCE so that it can be modified.
{
//if ($return_from == '???(popup)') {
// // change field name from 'foo_id' to 'bar_id'
// $select_array['bar_id'] = $select_array['foo_id'];
// unset($select_array['foo_id']);
//} // if

// Variable für _cm_GetInitialData, dass Daten aus Kontakt-Pool übernommen werden
$this->popupaufruf_status(True);

return $fieldarray;

} // _cm_popupReturn


// ************************************************************ ****************
function _cm_post_popupReturn ($fieldarray, $return_from, $select_array)
{

// liest Daten in Abhängigkeit des aufrufenden Formulars ein
if ($return_from == 'htm_orga_kontakte(popup1)'){

// get contents of foreign table KONTAKTE
$dbobject =& RDCsingleton::getInstance('orga_kontakte'); // Instanz für Lookup-Tabelle
$where = "user_id='{$select_array['user_id']}'
AND user_seq_no='{$select_array['user_seq_no']}'
AND rdcaccount_id='{$select_array['rdcaccount_id']}'";
$data = $dbobject->getData ($where);

if (!empty($data)){
$data = $data[0];
$fieldarray['user_id'] = $data['user_id'];
$fieldarray['user_seq_no'] = $data['user_seq_no'];
$fieldarray['rdcaccount_id'] = $_SESSION['rdcaccount_id'];
$fieldarray['kontakt_name'] = $data['kontakt_name'];
$fieldarray['kontakt_vorname'] = $data['kontakt_vorname'];
$fieldarray['kontakt_middlename'] = $data['kontakt_middlename'];
$fieldarray['kontakt_geburtstag'] = $data['kontakt_geburtstag'];
} // if
}

return $fieldarray;

}

// ************************************************************ ****************
function popupaufruf_status($neuer_status) {
// ändert die Eigenschaft von $popupaufruf
$this->popupaufruf_status = $neuer_status;
}

// function __construct($neuer_status){
// $this->popupaufruf_status = $neuer_status;
// }

// ************************************************************ ****************
} // end class
// ************************************************************ ****************

// Variable für _cm_GetInitialData, dass Daten aus Kontakt-Pool übernommen werden
$popupobject = new orga_kontakte_adresse();

?>
Re: PopUp and add1 - key fields [message #5230 is a reply to message #5221] Sat, 19 December 2015 03:40 Go to previous message
AJM is currently offline  AJM
Messages: 2244
Registered: April 2006
Location: Surrey, UK
Senior Member
You say that the code in _cm_getInitialData() is overwriting the value for seq_no after returning from a popup when it should not. What you want is a piece of code whiuc says the equivalent of "If I have just returned from a popup then do not execute this code". This means that in _cm_popupReturn() you need to set a class variable and in _cm_getInitialData() you need to test this variable.

Previous Topic: Different Categories
Next Topic: Del1 - no table name in query
Goto Forum:
  


Current Time: Wed May 12 17:05:38 EDT 2021

Total time taken to generate the page: 0.01652 seconds