Some ideas for file uploads

Discuss MySQL Ajax Table Editor Paid Version

Re: Some ideas for file uploads

Postby pq_rar » Tue Jul 20, 2010 8:50 pm

that worked perfect in UploadToDb.php

Unfortunately I am using UploadToDir.php and I changed the code appropriately but I cannot make it working.
This is what I've added:
Code: Select all
...................
         echo $javascript;
         
          ?>
             <script type="text/javascript">
                function addDeleteIcon()
                {
                   var id = $('id').value;
                   var html = $('file_data_input_cell').innerHTML;
                   var htmlParts = html.split(/<br>/);
                   if(htmlParts.length == 2)
                   {
                      var newHtml = '<table id="file_name_table"><tr><td style="border: none;">'+htmlParts[0]+'</td><td style="border: none;"><ul class="actions"><li class="delete"><a href="javascript: void(0);" onclick="deleteFile(\''+id+'\');" title="Delete '+htmlParts[0]+'"></a></li></ul></td></tr></table>';
                      newHtml += htmlParts[1];
                      $('file_data_input_cell').innerHTML = newHtml;
                   }
                }
               
                function deleteFile(id)
                {
                   if(confirm('Are you sure you would like to delete this file?'))
                   {
                      toAjaxTableEditor('delete_file',id);
                   }
                }
               
             </script>
          <?php
         
       }
       
       function deleteFile($id)
       {
          $query = "update emp_upload_db set file_data = '', file_name = '', file_type = '' where id = '$id'";
          $result = mysql_query($query);
          if($result)
          {
             $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("file_name_table").remove();');
          }
       }
       
function formatFileSize($col,$size,$row)
{    .........................

then
Code: Select all
$userActions = array('delete_file' => array(&$this,'deleteFile'));
$this->Editor->setConfig('userActions',$userActions);

and finally
Code: Select all
.........................
$this->Editor->main();
if($this->Editor->data->action == 'edit_row')
{
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'addDeleteIcon();');
}
echo $this->Editor->jsonEncode($this->Editor->retArr);
........................

but I cannot get the delete icon at all...
Am I missing something?
THANKS a LOT for your hard work.
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby admin » Tue Jul 20, 2010 9:08 pm

In the addDeleteIcon javascript function change "file_data_input_cell" to "file_name_input_cell" or if your upload column it named something other than file_name then change it to "upload_column_name_input_cell".
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Some ideas for file uploads

Postby pq_rar » Tue Jul 20, 2010 9:33 pm

this is what I am using for upload:
Code: Select all
$tableColumns['dynamicrep'] = array('display_text' => 'Report Dynamic', 'perms' => 'EVTAXQSFHO',
'file_upload' => array('upload_fun' => array(&$this,'handleUpload')),
'table_fun' => array(&$this,'formatImage'), 'view_fun' => array(&$this,'formatImage')
);   
      
$tableColumns['3dvideo'] = array('display_text' => '3D Video', 'perms' => 'EVTAXQSFHO',
'file_upload' => array('upload_fun' => array(&$this,'handleUpload')),
'table_fun' => array(&$this,'formatImage'), 'view_fun' => array(&$this,'formatImage')
);

not
Code: Select all
$tableColumns['file_data'] = array('display_text' => 'Image', 'perms' => 'EVCAXTQSFHO',
'file_upload' => array('type' => 'file_type', 'name' => 'file_name'),
'display_mask' => 'file_name', 'table_fun' => array(&$this,'formatImage'), 'view_fun' => array(&$this,'formatImage')
          );

I did "file_data_input_cell" to "file_name_input_cell", "upload_column_name_input_cell", "upload_3dvideo_input_cell"....none are working
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby admin » Tue Jul 20, 2010 9:44 pm

I guess I wasn't clear in my explanation. It should be "3dvideo_input_cell". Note that you'll have to change it in a couple of places and if your primary column is not named "id" you will have to change that also. For example change
Code: Select all
var id = $('id').value;

to
Code: Select all
var id = $('primary_column').value;
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Some ideas for file uploads

Postby pq_rar » Wed Jul 21, 2010 2:49 pm

nice, works good for one column. But what if I have 5 columns for upload? How I can make the difference in calling the addDeleteIcon() function? I should add an argument as addDeleteIcon(column_name)?
Thanks
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby admin » Wed Jul 21, 2010 3:19 pm

Yes that sounds like it would work and then you'd want to pass more information to the delete file function so you know which file to delete. For example the file name, column name and id. And then to pass the information back to the server you need to load it up into an object or an array for example
Code: Select all
function deleteFile(id,fileName,columnName)
{
    var info = {id: id, fileName: fileName, columnName: columnName};
    if(confirm('Are you sure you would like to delete this file?'))
    {
        toAjaxTableEditor('delete_file',info);
    }
}
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Some ideas for file uploads

Postby pq_rar » Wed Jul 21, 2010 4:49 pm

I am getting an error:
Image
This is the code for JAVASCRIPT:
Code: Select all
function addDeleteIcon()
{
var id = $('idreport').value;
var column = '3dvideo';
var html = $('3dvideo_input_cell').innerHTML;
var htmlParts = html.split(/<br>/);
if(htmlParts.length == 2)
{
var newHtml = '<table id="file_name_table"><tr><td style="border: none;">'+htmlParts[0]+'</td><td style="border: none;"><ul class="actions"><li class="delete"><a href="javascript: void(0);" onclick="deleteFile(\''+id+'\',\''+column+'\');" title="Delete '+htmlParts[0]+'"></a></li></ul></td></tr></table>';
newHtml += htmlParts[1];
$('3dvideo_input_cell').innerHTML = newHtml;
}
}
               
function deleteFile(id,col)
{
var info = {id: id, col: col};
if(confirm('Are you sure you would like to delete this file?'))
{
toAjaxTableEditor('delete_file',info);
}
}

and this is the code for PHP:
Code: Select all
function deleteFile($id,$col)
{
$query = "update report set '$col' = '' where idreport = '$id'";
$result = mysql_query($query);
if($result)
{
$this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("file_name_table").remove();');
}
}

error lines are for PHP code.
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby admin » Wed Jul 21, 2010 5:22 pm

Change
Code: Select all
    function deleteFile($id,$col)
    {
    $query = "update report set '$col' = '' where idreport = '$id'";
    $result = mysql_query($query);
    if($result)
    {
    $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("file_name_table").remove();');
    }
    }

to
Code: Select all
    function deleteFile($info)
    {
    $query = "update report set '$info->col' = '' where idreport = '$info->id'";
    $result = mysql_query($query);
    if($result)
    {
    $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("file_name_table").remove();');
    }
    }
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Some ideas for file uploads

Postby pq_rar » Wed Jul 21, 2010 7:42 pm

this is getting very close
the last function that I think needs to be changed(generalizing from one column to more than one) is:
Code: Select all
function addDeleteIcon()
{
var id = $('idreport').value;
var html = $('3dvideo_input_cell').innerHTML;
var htmlParts = html.split(/<br>/);
if(htmlParts.length == 2)
{
var newHtml = '<table id="file_name_table"><tr><td style="border: none;">'+htmlParts[0]+'</td><td style="border: none;"><ul class="actions"><li class="delete"><a href="javascript: void(0);" onclick="deleteFile(\''+id+'\');" title="Delete '+htmlParts[0]+'"></a></li></ul></td></tr></table>';
newHtml += htmlParts[1];
$('3dvideo_input_cell').innerHTML = newHtml;
}
}

thanks again for your fast replay.
error is
Code: Select all
There was a problem with the response text
<b>Notice</b>:  Undefined property: stdClass::$col in <b>C:\wamp\www\msmanager\UploadToDir.php</b> on line <b>196</b>
[{"where":"javascript","value":"storeSessionData('eyJvcmRlckJ5Q29sdW1uIjoicGF0aWRpbnQiLCJhc2NPckRlc2MiOiJhc2MiLCJmaWx0ZXJTZWFyY2hlcyI6eyJwZmlyc3QiOiJqaWxsIn0sInN0YXJ0IjowfQ==');"}]
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby admin » Thu Jul 22, 2010 2:35 pm

Yes you will need to change it to something like
Code: Select all
    function addDeleteIcon(col)
    {
    var id = $('idreport').value;
    var html = $(col+'_input_cell').innerHTML;
    var htmlParts = html.split(/<br>/);
    if(htmlParts.length == 2)
    {
    var newHtml = '<table id="'+col+'_file_name_table"><tr><td style="border: none;">'+htmlParts[0]+'</td><td style="border: none;"><ul class="actions"><li class="delete"><a href="javascript: void(0);" onclick="deleteFile(\''+id+'\',\''+col+'\');" title="Delete '+htmlParts[0]+'"></a></li></ul></td></tr></table>';
    newHtml += htmlParts[1];
    $(col+'_input_cell').innerHTML = newHtml;
    }
    }

And then call this function once for each column.

And then in the php deleteFile function you'll have to change the way it removes the garbage can icon.
Code: Select all
    function deleteFile($info)
    {
    $query = "update report set '$info->col' = '' where idreport = '$info->id'";
    $result = mysql_query($query);
    if($result)
    {
    $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("'.$info->col.'_file_name_table").remove();');
    }
    }
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

PreviousNext

Return to Paid Version

Who is online

Users browsing this forum: No registered users and 3 guests

cron