tomolimo / processmaker

GLPI plugin that provides an interface with ProcessMaker (http://www.processmaker.com/)
30 stars 11 forks source link

file upload web control #78

Closed tomolimo closed 5 years ago

tomolimo commented 6 years ago

From @rohit-ambre-uno on August 7, 2018 14:35

Dear @tomolimo , file upload web control is not available in processmaker-server which is very important for my use case. In processmaker 3.0 i have to use file web control for which i have to create input document which only allows me to upload only one document. if I set step as input document in designer it is not attaching documents in GLPI.

I want have multiple file upload in dynaform and which can be seen in further tasks of process.

Copied from original issue: tomolimo/processmaker-server#11

tomolimo commented 6 years ago

Hello @rohit-ambre-uno Three questions/remarks:

  1. What is the "file upload web control"?
  2. please read this about input/output of documents: https://github.com/tomolimo/processmaker/wiki/Restrictions-of-use
  3. Do you run your process in Central or in Self-service interface?

What yo have to understand is that PM server is managing documents on its own, and of course not attaching uploaded document into GLPI.

We may imagine an enhancement to permit this, but as a workaround you may manage that asking your people to attach document into the Tickets (or Changes, or Problems).

Thank you Regards, Tomolimo

tomolimo commented 6 years ago

From @rohit-ambre-uno on August 7, 2018 17:4

To answer your questions

  1. processmaker introduced file upload web control in dynaform in PM 3.1 which enables to attach files in forms but as you are using processmaker 3.0 it does not have that plugin so by using 'file' web control available in PM3.0, i have to create input document. I followed documentation to use file web control and input document I am not able to use just input document as step in processmaker(it shows input document page in GLPI but it does not accepts file) and if i use file web control in dynaform then i can only upload single file(or else i have to use file web control multiple times in form)
  2. I understand this
  3. i ran my process in standard interface in GLPI

Yes, we can attach documents in GLPI but that's inconvenient for user

It would be much easier if PM server is upgraded to newer version

tomolimo commented 6 years ago

If you use the self-service interface then end-users can add documents to the ticket at the same time they are doing the first task of the chosen process.

Currently the input of document is not supported by the plug-in, even if the pm server is upgraded to latest version, I'm not sure that it will change something for the plug-in.

tomolimo commented 6 years ago

Hello @rohit-ambre-uno

I made a modification of the function that sends Dynaform data to PM server, so that the input document will be saved into the PM server. You may test it by adding the following code:

     // check if any files are in the $_FILES global array
      // and add them to the curl POST 
      if (isset($_FILES['form']['name'])) {
         foreach ($_FILES['form']['name'] as $key => $file) {
            $cfile = new CURLFile($_FILES['form']['tmp_name'][$key], $_FILES['form']['type'][$key],$_FILES['form']['name'][$key]);
            $data["form[$key]"] = $cfile;
         }
      }

This should be added into the function saveForm(...) in the processmaker.class.php source file, just before the line $ch = curl_init();

As example, here is the complete php file (beware that this file is for version 3.3.2) processmaker.class.php.zip

Could you do some tests, and give me feedback about these?

Thank you Regards, Tomolimo

rohit-ambre-uno commented 6 years ago

I installed new processmaker and processmaker-server and also copied your code to the given location but still it is not uploading documents to processmaker-server via GLPI but it is uploading from processmaker alone

Kindly suggest

tomolimo commented 6 years ago

Hello @rohit-ambre-uno

I made a test on my machine and it was uploading document into PM server: here is the project I used to test: File-Doc-input-1.zip

Could you post PM server PHP log files? Could you post GLPI version? Could you post PM plugin configuration? Could you post you PM project? Could you post screenshots of the test you made?

Thank you

rohit-ambre-uno commented 6 years ago

Yeah, your process does upload file to the server

nothing got logged in php log file but following got logged in GLPI php-error.log *** PHP Warning(2): CURLFile::__construct() expects parameter 1 to be a valid path, array given Backtrace : : ...ns/processmaker/inc/processmaker.class.php:2339 CURLFile->__construct() ...ns/processmaker/inc/processmaker.class.php:2614 PluginProcessmakerProcessmaker->saveForm() plugins/processmaker/front/case.form.php:26 PluginProcessmakerProcessmaker->derivateCase()

GLPI versiom : 9.2.4 processmaker_conf

my process flow : input_document.zip

tomolimo commented 6 years ago

Hello @rohit-ambre-uno

You may do some tests with the following modification of the code part I gave you (https://github.com/tomolimo/processmaker/issues/78#issuecomment-412071813):

// check if any files are in the $_FILES global array
      // and add them to the curl POST
      if (isset($_FILES['form']['name'])) {
         foreach ($_FILES['form']['name'] as $key => $file) {
            if (is_array($file)) {
               // it's a grid which contains documents
               foreach ($file as $row => $col) {
                  foreach($col as $control => $filename) {
                     $cfile = new CURLFile($_FILES['form']['tmp_name'][$key][$row][$control], $_FILES['form']['type'][$key][$row][$control],$_FILES['form']['name'][$key][$row][$control]);
                     $data["form[$key][$row][$control]"] = $cfile;
                  }
               }
            } else {
               $cfile = new CURLFile($_FILES['form']['tmp_name'][$key], $_FILES['form']['type'][$key],$_FILES['form']['name'][$key]);
               $data["form[$key]"] = $cfile;
            }
         }
      }

This will upload the documents in the grid.

Regards, Tomolimo

rohit-ambre-uno commented 6 years ago

Yeah, I will test it and let you know. Not only grid, documents from file control also did not get uploaded in my process. Did you tried my process and found whats wrong in it?

Thank you

tomolimo commented 6 years ago

Your process seems okay, I tested the upload of the documents in grid with it.

rohit-ambre-uno commented 6 years ago

I created new process with just file upload web control and it did upload a file onto server then i made new modifications in code given by you and added grid in dynaform, it threw an error on browser

screenshot from 2018-08-16 19-01-30

I tried several times then it was working fine, I suppose it was due to cache. But i noticed that file from file web control and files from grid are getting uploaded together but if i just attach files in grid then that files did not get upload

rohit-ambre-uno commented 6 years ago

are files getting uploaded only through grid on your side? are you facing this problem?

rohit-ambre-uno commented 6 years ago

Hello, The code snippet you gave to upload files from processmaker plugin to processmaer-server which was compatible for processmaker 3.3.2 and PM-server RE-1.9. I tried that same snippet in processmaker 3.2.8 and Pm-server RE-1.8 and it worked perfectly fine without any changes till yesterday when I found that it fails when you have file upload and Exclusive gate after the task. Till yesterday I did not test my processes with upload and exclusive gate.

In this case, if you don't upload anything in file upload or grid with file upload and select a Boolean value for exclusive gate then process does not move to next step and shows same dynaform after refreshing in processmaker 3.2.8 and in processmaker 3.3.2, task tab disappears from left panel and shows task assigned to same user but form do not get display. But if you upload attachments and select any boolean value then task moves forward to next task according to exclusive gate properties.

I also tested this scenarios with file upload process you gave in above comments in processmaker 3.3.2 and PM-server 1.9.

Please test above scenario of upload with exclusive gate

tomolimo commented 6 years ago

Hello @rohit-ambre-uno Could post your process? Thank you regards, Tomolimo

rohit-ambre-uno commented 6 years ago

Yeah sure. this is the same process you sent me File-Doc-with-Gate.zip

this is the process to display uploaded docs in next grid having same problem input-document-grid.zip

It is kind of important feature which was stuck from long time but I pushed it ahead last week as it was uploading docs from processmaker 3.2.8 but yesterday i came across this issue and it is kind of a road block for us now.

tomolimo commented 6 years ago

Ok, Thank you, but I may not have time before end of September to look at them... sorry for that, as I'm working on some top-priority topics and I'll have some holidays too :smiley: Tomolimo

rohit-ambre-uno commented 6 years ago

Ohk, It also do not bring values from previously filled dynaforms having same variables. Keep me posted about this issue, as it is kind of important and Enjoy your holidays

rohit-ambre-uno commented 5 years ago

I hope u had fun holidays. Did you get time to look at this issue? I tried making process in different ways to avoid this issue but I couldn't find a way. Please take a look at it and let me know.

rohit-ambre-uno commented 5 years ago

Hi @tomolimo, I have made the following minor changes in your code of file attachment and it now works for the time being.

if (isset($_FILES['form']['name'])) {

I have made the following changes and this works, you can verify if it works for you.

$fileForm = $_FILES['form']['name']; if( !empty($fileForm[array_keys($fileForm)[0]][1][array_keys($fileForm[array_keys($fileForm)[0]][1])[0]]) ){

in this comment

rohit-ambre-uno commented 5 years ago

Hi, I checked the same feature in new release i.e. processmaker-3.4.5 but it is not going to next task unless you upload a file when there is exclusive gate after the task. So I changed the code to one I sent in this issue above in comments and it is working fine now.

tomolimo commented 5 years ago

Sorry for that regression, but you should provide a pull request instead of putting source code in the issues. It will be better for me to trace the modifications. Thank you Regards, Tomolimo