<modification>
       <id>Multiupload files with filemanager</id>
       <version>1.0.0</version>
       <vqmver>1.2.0</vqmver>
       <author>ASK BARAKA CAUSE YOUR CODE IS NOT LEET</author>
       <file name="/admin/controller/common/filemanager.php">
           <operation error="skip">
               <search position="replace" offset="71"><![CDATA[
	            // Not needed cause this DOES NOT REPLACE ANYTHING
               ]]></search>
               <add trim="false"><![CDATA[
     // Not needed cause this DOES NOT REPLACE ANYTHING
               ]]></add>
           </operation>
       </file>
	   
       <file name="/admin/view/template/catalog/product_form.tpl">
           <operation error="skip">
               <search position="replace"><![CDATA[
                width: 700,
               ]]></search>
               <add trim="false"><![CDATA[
                width: 710,
               ]]></add>
           </operation>

           <operation error="skip">
               <search position="replace"><![CDATA[
                <a onclick="addImage();" class="button">
               ]]></search>
               <add trim="false"><![CDATA[
                <a onclick="image_upload();" class="button">
               ]]></add>
           </operation>   

           <operation error="skip">
               <search position="replace"><![CDATA[
                function image_upload(field, preview) {
               ]]></search>
               <add trim="false"><![CDATA[
                /* BARAKA MOD */

    function activeNow() {
        var selected = new Array();
        parent.$('#images tbody tr td.left input').each(function(number) {
            selected.push($(this).val());
            //console.log(selected[number]);
            $("iframe").contents().find("div#column_right div a[file='"+selected[number]+"']").remove();
        });
        if($("iframe").contents().find("#column_right div a").length == null || $("iframe").contents().find("#column_right div a").length == ''){
            $("iframe").contents().find("#column_right").html("<div style='background: #FFF;'>All images here are already added to the form</div>");
        }
    }

    function image_upload(field, preview) {
   // setInterval(activeNow, 1000);

               ]]></add>
           </operation>      
       </file>

       <file name="/admin/view/template/module/gallery/form.tpl">
           <operation error="skip">
               <search position="replace"><![CDATA[
                width: 700,
               ]]></search>
               <add trim="false"><![CDATA[
                width: 710,
               ]]></add>
           </operation>

           <operation error="skip">
               <search position="replace"><![CDATA[
                <a onclick="addImage();" class="button">
               ]]></search>
               <add trim="false"><![CDATA[
                <a onclick="image_upload();" class="button">
               ]]></add>
           </operation>   

           <operation error="skip">
               <search position="replace"><![CDATA[
                function image_upload(field, preview) {
               ]]></search>
               <add trim="false"><![CDATA[
                /* BARAKA MOD */

    function activeNow() {
        var selected = new Array();
        parent.$('#images tbody tr td.left input').each(function(number) {
            selected.push($(this).val());
            //console.log(selected[number]);
            $("iframe").contents().find("div#column_right div a[file='"+selected[number]+"']").remove();
        });
        if($("iframe").contents().find("#column_right div a").length == null || $("iframe").contents().find("#column_right div a").length == ''){
            $("iframe").contents().find("#column_right").html("<div style='background: #FFF;'>All images here are already added to the form</div>");
        }
    }

    function image_upload(field, preview) {
   // setInterval(activeNow, 1000);

               ]]></add>
           </operation>      
       </file>


       <file name="/admin/view/template/common/filemanager.tpl">
           <operation error="error">
               <search position="replace" ><![CDATA[
               <script type="text/javascript" src="view/javascript/jquery/ajaxupload.js"></script>
               ]]>
               </search>
               <add trim="false"><![CDATA[
                <script type="text/javascript" src="view/javascript/jquery/mf_ajaxupload.js"></script>
               ]]>
               </add>
           </operation>
           <operation error="skip">
               <search position="replace"><![CDATA[
                name: 'image',
               ]]></search>
               <add trim="false"><![CDATA[
                name: 'image[]',
               ]]></add>
           </operation>
           <operation error="skip">
               <search position="after" offset="42"><![CDATA[
				$('#create').bind('click', function () {
               ]]></search>
               <add trim="false"><![CDATA[
    $('#addimage').bind('click', function() {
         if ($('#column-right a.selected').length > 0) {
            $('#column-right a.selected').each( function() { 
                     var derectory  = 'data/';
                     var path = derectory + $(this).find('input[name=\'image\']').attr('value');
                     $.ajax({
                        url: 'index.php?route=common/filemanager/image_ext&token=<?php echo $token;?>&image=' + encodeURIComponent( path),
                        dataType: 'text',
                        success: function(response_json) {
                            if ( response_json ) {
                                response_json = eval("(" + response_json + ")");
                                var image_id = parent.addImage();
                                parent.$('#image' + image_id ).attr('value', response_json.image );
                                parent.$('#thumb' + image_id ).replaceWith('<img src="' + response_json.text + '" alt="" id="thumb' + image_id +'" />');
                                alert(response_json.success);
                            }
                        }
                    });
            });
         } else {
            $('#column-right a').each( function() { 
                     var derectory  = 'data/';
                     var path = derectory + $(this).find('input[name=\'image\']').attr('value');
                     $.ajax({
                        url: 'index.php?route=common/filemanager/image_ext&token=<?php echo $token;?>&image=' + encodeURIComponent( $($.tree.focused().selected).attr('directory') + path),
                        dataType: 'text',
                        success: function(response_json) {
                            if ( response_json ) {
                                response_json = eval("(" + response_json + ")");
                                var image_id = parent.addImage();
                                parent.$('#image' + image_id ).attr('value', response_json.image );
                                parent.$('#thumb' + image_id ).replaceWith('<img src="' + response_json.text + '" alt="" id="thumb' + image_id +'" />');
                                alert(response_json.success);
                            }
                        }
                    });

            });
         }
    });
               ]]></add>
           </operation>
           <operation error="skip">
               <search position="replace" offset="74"><![CDATA[
	$('#delete').bind('click', function () {
		path = $('#column_right a.selected').attr('file');
							 
		if (path) {
			$.ajax({
				url: 'index.php?route=common/filemanager/delete&token=<?php echo $token; ?>',
				type: 'POST',
				data: 'path=' + path,
				dataType: 'json',
				success: function(json) {
					if (json.success) {
						var tree = $.tree.focused();
					
						tree.select_branch(tree.selected);
						
						alert(json.success);
					}
					
					if (json.error) {
						alert(json.error);
					}
				}
			});				
		} else {
			var tree = $.tree.focused();
			
			if (tree.selected) {
				$.ajax({
					url: 'index.php?route=common/filemanager/delete&token=<?php echo $token; ?>',
					type: 'POST',
					data: 'path=' + encodeURIComponent($(tree.selected).attr('directory')),
					dataType: 'json',
					success: function(json) {
						if (json.success) {
							tree.select_branch(tree.parent(tree.selected));
							
							tree.refresh(tree.selected);
							
							alert(json.success);
						} 
						
						if (json.error) {
							alert(json.error);
						}
					}
				});			
			} else {
				alert('<?php echo $error_select; ?>');
			}			
		}
	});
               ]]></search>
               <add trim="false"><![CDATA[
	$('#delete').bind('click', function () {
		path = $('#column_right a.selected').attr('file');
		
		if(path==undefined){
         $('#dialog').remove();
		
		html  = '<div id="dialog">';
		html += '<p><strong  style="color: red;">WARNING:</strong> You are trying to delete a folder.<br />';
		html += 'All files and folder under it will be deleted. <strong  style="color: red;">Confirm?</strong></p>';
		html += '</div>';

		$('#column_right').prepend(html);
		
		$( "#dialog" ).dialog({
			resizable: false,
			height:165,
			width: 380,
			modal: true,
			title: 'Folder deletion',
			buttons: {
				"Delete folder": function() {
					var tree = $.tree.focused();
			
			if (tree.selected) {
				$.ajax({
					url: 'index.php?route=common/filemanager/delete&token=<?php echo $token; ?>',
					type: 'POST',
					data: 'path=' + encodeURIComponent($(tree.selected).attr('directory')),
					dataType: 'json',
					success: function(json) {
						if (json.success) {
							tree.select_branch(tree.parent(tree.selected));
							
							tree.refresh(tree.selected);
							
							alert(json.success);
						} 
						
						if (json.error) {
							alert(json.error);
						}
					}
				});			
			} else {
				alert('<?php echo $error_select; ?>');
			}	
			$( this ).dialog( "close" );
				},
				Cancel: function() {
					$( this ).dialog( "close" );
				}
			}
			});
		} else if (path) {
		
			$.ajax({
				url: 'index.php?route=common/filemanager/delete&token=<?php echo $token; ?>',
				type: 'POST',
				data: 'path=' + path,
				dataType: 'json',
				success: function(json) {
					if (json.success) {
						var tree = $.tree.focused();
					
						tree.select_branch(tree.selected);
						
						alert(json.success);
					}
					
					if (json.error) {
						alert(json.error);
					}
				}
			});				
		} 
	});           
            ]]></add>
           </operation>
       </file>
</modification>
