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

Home » RADICORE » How To » pickup subdir from table and put into upload_subdir
pickup subdir from table and put into upload_subdir [message #1363] Fri, 06 June 2008 03:58 Go to next message
Jovan is currently offline  Jovan
Messages: 24
Registered: February 2008
Location: Serbia
Junior Member

Hi Tony,

I have in my user table column upload_path, and I have a problem to read this in _cm_initialiseFileUpload function, and put in $this->upload_subdir field.

This is the sequence:

1. LIST1 of my custom table
2. Than select first row, and press read button
3. After that I press Upload button inside Read option

My demand is to pickup value of selected column upload_path and put in $this->upload_subdir inside _cm_initialiseFileUpload function.

I sow that Upload don't work with select option, but how to simulate it ?

Everything is o.k. when I put string in $this->upload_subdir.

I tried, and could not find solution.


Jovan
Re: pickup subdir from table and put into upload_subdir [message #1364 is a reply to message #1363] Fri, 06 June 2008 04:19 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
This should not be a problem. Simply modify your _cm_initialiseFileUpload() method to read the record which contains the subdir and load this value into $this->upload_subdir.

Re: pickup subdir from table and put into upload_subdir [message #1365 is a reply to message #1364] Fri, 06 June 2008 05:52 Go to previous messageGo to next message
Jovan is currently offline  Jovan
Messages: 24
Registered: February 2008
Location: Serbia
Junior Member

I use _cm_pre_get_data function and pick up subdir value but it perform AFTER _cm_initialiseFileUpload. Tell me How to activate reading record inside _cm_initialiseFileUpload function ? I tried but I have no results.

Jovan
Re: pickup subdir from table and put into upload_subdir [message #1366 is a reply to message #1365] Fri, 06 June 2008 06:11 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
If you have modified _cm_pre_get_data() to obtain the value for subdir then why is that value not available in the $fieldarray which is passed to _cm_initialiseFileUpload()?

If you need to obtain data which is not available in $fieldarray the take a look at the sample which is documented in http://www.tonymarston.net/php-mysql/functions-and-variables .html#notes._cm_getforeigndata.


Re: pickup subdir from table and put into upload_subdir [message #1371 is a reply to message #1363] Wed, 11 June 2008 20:03 Go to previous messageGo to next message
Jovan is currently offline  Jovan
Messages: 24
Registered: February 2008
Location: Serbia
Junior Member

Hi Tony,

I tried with code which you suggest me, but I could not pick up data from table.
This is code which I implement:

function _cm_initialiseFileUpload ($where, $fieldarray)
// perform any initialisation before displaying the File Upload screen.
{
// ******* new code
$fieldarray = $this->_cm_getForeignData($fieldarray);
// ******
$this->upload_subdir = $fieldarray['path']; // **** new
$this->upload_filetypes = 'text/plain';

$this->upload_maxfilesize = 1000000;
return $fieldarray;

This part of code :

$fieldarray = $this->_cm_getForeignData($fieldarray);

works when I put in other _cm ... functions. Also I tried with global variable and found very interesting thing that data from global variable is not possible transfer from _cm .. function, to _cm functions, but when I put global variable in first function (function table_name()) I could read content of global variable inside _cm_initialiseFileUpload function.










Jovan
Re: pickup subdir from table and put into upload_subdir [message #1372 is a reply to message #1363] Wed, 11 June 2008 20:08 Go to previous messageGo to next message
Jovan is currently offline  Jovan
Messages: 24
Registered: February 2008
Location: Serbia
Junior Member

Hi Tony,

I forgot something, I am testing this application in Radicore 1.35.

Thanks in advance


Jovan
Re: pickup subdir from table and put into upload_subdir [message #1373 is a reply to message #1372] Thu, 12 June 2008 04:56 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
When I pointed you to that link I did not mean that you had to call the _cm_getForeigndata() method, I meant that you could use that code sample within your _cm_initialiseFileUpload() method.

You can access any other table from anywhere in your code with the following:
$dbobject =& singleton::getInstance('other_table');
$dbobject->sql_select = 'other_field';
$other_data = $dbobject->getData("other_id='whatever'");

What you do with the contents of $other_data is up to you.


Re: pickup subdir from table and put into upload_subdir [message #1559 is a reply to message #1363] Thu, 21 August 2008 17:18 Go to previous messageGo to next message
ikatz is currently offline  ikatz
Messages: 40
Registered: December 2007
Location: Durham, NH
Member
I came across this thread from a Google search. I think I am working on something along the same lines, so here is my solution for whoever comes next.

I was setting up a file upload directory that would hold a large number of files: several per database record, and many records. In order to make the directory more manageable, I set up a subdirectory for each record (based on primary key) and accessed the file upload screen from a list1 transaction.

You have to put the file upload task as a navigation button in your list1 transaction, and mark it as "preselect" (I didn't try enq1). Then when you select an item from your list1 and click "File Upload", you will get your primary key as an element of the fieldarray argument to _cm_initialiseFileUpload. Then you can use it to set $this->upload_subdir.

The only downside to this is that there seems to be no way to browse the directory from Radicore. The most apt transaction would be a filepicker, because it will show you the contents of a directory ... but the problem is that there is no way (that I can see) to get the primary key of the record you are looking at from _cm_initialiseFilePicker() -- it takes no arguments.

So you have to do it the "hack" way:
    function _cm_initialiseFilePicker ()
    // perform any initialisation before displaying the File Picker screen.
    {

        $sv = $GLOBALS['HTTP_SESSION_VARS'];
        $svp = $sv['pages'];
        $keys = array_keys($svp);
        //get previous page in stack ... you may need to adjust the 2
        $page = $keys[count($keys) - 2];
        $task = $svp[$page]['task_id'];
        $where = $svp[$page][$task]['where'];

        //the field we want
        $field = 'your_table_pkey_id';

        //Tony's sample code (more or less)
        $dbobject =& singleton::getInstance('your_table');
        $dbobject->sql_select = $field;
        $data = $dbobject->getData($where);

        $primary_key = $data[0][$field];

        // now do something with the primary key
        //.....
Re: pickup subdir from table and put into upload_subdir [message #1560 is a reply to message #1559] Thu, 21 August 2008 18:28 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
If your problem is that _cm_initialiseFilePicker() does not take any arguments then I can change it in the next release to accept a $fieldarray argument. This will be the $where string converted into an associative array. You can then use the contents of this array to modify $this->picker_subdir.

Re: pickup subdir from table and put into upload_subdir [message #1561 is a reply to message #1560] Thu, 21 August 2008 19:57 Go to previous messageGo to next message
ikatz is currently offline  ikatz
Messages: 40
Registered: December 2007
Location: Durham, NH
Member
Actually -- and this is slightly embarassing -- at the time that I wrote the last post, I had only verified that the fieldarray would contain the primary key that I needed (to set the upload directory), and I had not attempted to upload the file into that directory.

As it turns out, when you submit an uploaded file, _cm_initialiseFileUpload() will be called a second time -- and the fieldarray will be empty. I ended up having to do the above hack for both the upload and picker transactions in order to make them work as I intended.

So, to answer your question, I definitely would feel more comfortable if this data was provided directly (vs my workaround), but it would be your call on how best to do it. Having an argument called "fieldarray" might be misleading, as it would need to access the fieldarray from the previous transaction. I'm not sure what the implications are here, but it almost seems like there could be separate functions that get called, one initialization for entering the file upload and one for leaving it with the submitted file.

[Updated on: Thu, 21 August 2008 20:05]

Report message to a moderator

Re: pickup subdir from table and put into upload_subdir [message #1562 is a reply to message #1561] Fri, 22 August 2008 04:57 Go to previous messageGo to next message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
You are incorrect when you say that _cm_initialiseFileUpload() will be called a second time when you submit an uploaded file. It is only called when the component is first activated. When you submit a file name it is the _cm_fileUpload() method which is called.

Calling the argument "$fieldarray" should not be misleading as that is the generic name that is used for an associative array. If you automatically assume that this is the contents of $fieldarray in the calling task then your assumption is incorrect - it is only the $where string which is passed from the parent to the child task, and this string is then converted into an associative array.

Although by default the $where string which is extracted from a parent object and passed to a child object is the primary key of the parent object, it is possible to modify it at the point of extraction. For example, if the filepicker is activated from a POPUP button then $where can be set to whatever you like in the _cm_popupCall() method.

I have changed std.filepicker1.inc so that it is passed the $where string from the parent task, and this string is therefore available to be passed from the filepicker to the fileupload task. This will then be available in both the _cm_initialiseFileUpload() and _cm_fileUpload() methods.


Re: pickup subdir from table and put into upload_subdir [message #1564 is a reply to message #1562] Fri, 22 August 2008 10:14 Go to previous messageGo to next message
ikatz is currently offline  ikatz
Messages: 40
Registered: December 2007
Location: Durham, NH
Member
Hmm... I can't seem to reproduce the behavior today, and it looks like I was indeed mistaken about the initialize function being called twice. I will chalk that up to some simple mistake on my part unless/until I run across this issue again.

Having the $where string in both of those functions would be perfect for my needs.
Re: pickup subdir from table and put into upload_subdir [message #1566 is a reply to message #1564] Fri, 22 August 2008 15:42 Go to previous messageGo to next message
ikatz is currently offline  ikatz
Messages: 40
Registered: December 2007
Location: Durham, NH
Member
I found my simple mistake. Even though I had marked the file upload button as "preselect" in the menu system, uploading doesn't require a selected record. So in my list1 transaction, I hit the upload button with nothing selected and it didn't complain -- it just proceeded with an empty fieldarray. I should have expected that.

I moved the button into an list2, and it seems to be working fine (as well as eliminating the confusion over the preselect option). I'd imagine that it would also work in an enq1 situation.
Re: pickup subdir from table and put into upload_subdir [message #1567 is a reply to message #1566] Fri, 22 August 2008 15:53 Go to previous message
AJM is currently offline  AJM
Messages: 2371
Registered: April 2006
Location: Surrey, UK
Senior Member
It will work with an ENQ1 because an ENQ1 can only be activated with something in $where, whereas a LIST1 usually has nothing in $where.

Previous Topic: Filter values of fields depending on other fields
Next Topic: Use the ADD5 template
Goto Forum:
  


Current Time: Sun Dec 22 01:31:41 EST 2024

Total time taken to generate the page: 0.01487 seconds