Some ideas for file uploads

Discuss MySQL Ajax Table Editor Paid Version

Re: Some ideas for file uploads

Postby pq_rar » Fri Feb 18, 2011 7:07 pm

this is how I have this done:
in uploadtodir.php
Code: Select all
   function UploadToDir()
   {
      session_start();
      ob_start();
      $this->mysqlConnect();
      $this->initiateEditor();
      if(isset($_POST['json']))
      {
         if(ini_get('magic_quotes_gpc'))
         {
            $_POST['json'] = stripslashes($_POST['json']);
         }
         $this->Editor->data = $this->Editor->jsonDecode($_POST['json']);
         $this->Editor->setDefaults();
         $this->Editor->main();
             if($this->Editor->data->action == 'edit_row')
             {
            foreach($this->Editor->tableColumns as $colName => $info)
            {
                if(isset($info['file_upload']))
               {
                 $this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'addDeleteIcon("'.$colName.'");');
                }
             }             
          }
             echo $this->Editor->jsonEncode($this->Editor->retArr);
          }
      else if(isset($_GET['export']))
........................................

then I use it as:
Code: Select all
      $tableColumns['invoice'] = array('display_text' => 'Invoice', 'perms' => 'EVTAXQSFHO',
         'file_upload' => array('upload_fun' => array(&$this,'handleUpload')),
         'table_fun' => array(&$this,'formatImage'), 'view_fun' => array(&$this,'formatImage'));   

let me know if it works...
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby ericimprint » Fri Feb 18, 2011 7:39 pm

Thanks pq_rar. Can you share your final function deleteFile($info)?
ericimprint
 
Posts: 24
Joined: Wed Feb 02, 2011 1:05 am

Re: Some ideas for file uploads

Postby pq_rar » Fri Feb 18, 2011 8:33 pm

Code: Select all
            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);
                }
            }
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby ericimprint » Fri Feb 18, 2011 8:42 pm

pq_rar wrote:
Code: Select all
            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);
                }
            }

I meant the php function that actually does the deleting.
ericimprint
 
Posts: 24
Joined: Wed Feb 02, 2011 1:05 am

Re: Some ideas for file uploads

Postby pq_rar » Fri Feb 18, 2011 9:46 pm

Code: Select all
    function deleteFile($info)
    {
      $query0 = "select ".$info->col." from report where idreport = '".$info->id."'";
      $result0 = mysql_query($query0);
      $row = mysql_fetch_assoc($result0);
      $query1 = "update report set ".$info->col." = '' where idreport = '".$info->id."'";
      $result1 = mysql_query($query1);
      if($result1)
      {
         unlink("uploads/".$row[$info->col]);
         $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("'.$info->col.'_file_name_table").remove();');
      }
    }
pq_rar
 
Posts: 89
Joined: Thu May 27, 2010 4:44 am

Re: Some ideas for file uploads

Postby ericimprint » Fri Feb 18, 2011 9:53 pm

Awesome. Thanks.

Here is the final code for the next person:

Code: Select all
              echo $javascript;
           
           //Add Delete Functions
           ?>
                <script type="text/javascript">
                function addDeleteIcon(col)
                      {
                      var id = $('UniqueId').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;
                      }
                      }

                function deleteFile(id,col)
                  {
                      var info = {id: id, col: col};
                      if(confirm('Are you sure you would like to delete the image from '+info['col']+' for UniqueId '+id+' ?'))
                      {
                          toAjaxTableEditor('delete_file',info);
                      }
                  }
                    </script>
                  <?
               }
            function deleteFile($info)
                {
                 $query1 = "select $info->col from asi_product_overrides where UniqueId = '$info->id'";
                 $result1 = $this->Editor->doQuery($query1);
                $query = "update asi_product_overrides set $info->col = '' where UniqueId = '$info->id'";
                $result = mysql_query($query);
                if($result)
                   {
                  unlink($this->dataDir.$row[$info->col]);
                   $this->Editor->retArr[] = array('where' => 'javascript', 'value' => '$("'.$info->col.'_file_name_table").remove();');
                   }
                }
         //End Add delete
           
           function formatFileSize($col,$size,$row)


Code: Select all
$this->Editor->setConfig('defaultJsCalFormat','%B %d, %Y');
              $this->Editor->setConfig('paginationLinks',true);
              $userActions = array('delete_file' => array(&$this,'deleteFile'));
              $this->Editor->setConfig('userActions',$userActions);


Code: Select all
$this->Editor->main();
                 //Add Delete Button
                 if($this->Editor->data->action == 'edit_row')
                 {
                    foreach($this->Editor->tableColumns as $colName => $info)
                    {
                       if(isset($info['file_upload']))
                       {
                          $this->Editor->retArr[] = array('where' => 'javascript', 'value' => 'addDeleteIcon("'.$colName.'");');
                       }
                    }
                 }
                 //End Add Delete                 
                 echo $this->Editor->jsonEncode($this->Editor->retArr);
ericimprint
 
Posts: 24
Joined: Wed Feb 02, 2011 1:05 am

Re: Some ideas for file uploads

Postby frank » Thu Apr 07, 2011 12:49 pm

Hi, (appologies for cross-post)

I'm having a hair pulling time trying to fix a problem viewing the delete Icons on IE. I have this:
Code: Select all
         <script type="text/javascript">
         function addDeleteIcon(col)
         {
            var id = $('id').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;
            }
         }

         function deleteFile(id,col)
         {
            var info = {id: id, col: col};
               if(confirm('Are you sure you would like to delete the image file?'))
            {
               toAjaxTableEditor('delete_file',info);
            }
         }
           
         </script>


I have tried many variations and still, the icon will only show on Chrome and Firefox. Can any one help?

Regards
frank
 
Posts: 17
Joined: Wed Mar 02, 2011 10:53 am

Re: Some ideas for file uploads

Postby admin » Thu Apr 07, 2011 2:02 pm

Does the javascript get executed in ie? Throw some alerts in there and see if it gets executed. Maybe replace the inserted html with a simple string and see if it shows up.
admin
Site Admin
 
Posts: 1502
Joined: Fri Jul 11, 2008 1:34 am

Re: Some ideas for file uploads

Postby frank » Thu Apr 07, 2011 4:08 pm

Yip, the javascript does not get executed in IE, yet its enabled in addins and security settings?

I inserted var newHtml = 'Hello There'; and this shows up in Firefox but not IE.

Any consequent search for what the problem may be results in a dead end?
frank
 
Posts: 17
Joined: Wed Mar 02, 2011 10:53 am

Re: Some ideas for file uploads

Postby admin » Thu Apr 07, 2011 4:28 pm

Did you put any alerts in the function? I would put an alert in the very top of the addDeleteIcon function just to make sure it is not getting executed in ie.

Also in the ajax_table_editor.js file in the displayInfo function there are a few lines of code you can un-comment for debugging. You can un-comment these lines and see if ie is executing the javascript before the table is there or choking on a previous line of javascript and then stops executing.
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 4 guests

cron