<?php
//2009-01-05 UWAGA NWOSZA WERSJA NA SOWA - tam edytowac nastepna wersje!!!!! bindera

//echo "DUPA";
//2008-08-12 sqix update chmod
//2008-09-16 sqix update KORESP, and web links
//2008-11-27 Bindera (sqix) added Relations to KORESPONDENCJA
//2009-11-29 Bindera added KORESP search for ID of files
//2011-05-20 Bindera - added config parser for examples::
//2012-04-20 Bindera - modified if in line 514 if(strlen($VARNAME_EVAL)>1) for Indexname better in IN7_MK_BAZA_DYSTRYBUCJI table
//$FOLDERS[KSIEG_DOKUMENTY_COLUMN_LOOKAT][FOLDER][1][LOOK_REGEX]='/FAKTURY\/.$/';
//$FOLDERS[KSIEG_DOKUMENTY_COLUMN_LOOKAT][FOLDER][1][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]';
//$FOLDERS[KSIEG_DOKUMENTY_COLUMN_LOOKAT][FOLDER][2][LOOK_REGEX]='/.<VARNAME>./';
//$FOLDERS[KSIEG_DOKUMENTY_COLUMN_LOOKAT][FOLDER][2][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][DATA_DOK]';
//$FOLDERS[KSIEG_DOKUMENTY_COLUMN_LOOKAT][NEGFILE][LOOK_REGEX]='.<VARNAME>.';
//$FOLDERS[KSIEG_DOKUMENTY_COLUMN_LOOKAT][NEGFILE][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]';



error_reporting(E_ALL);

if(!function_exists('IN7_BPCOPY')) include("superedit-IN7_BPCOPY.php");
if(!function_exists('array_isearch')) include("superedit-array_isearch.php");
if(!function_exists('IN7_FILERENAME')) include("superedit-IN7_FILERENAME.php");
if(!function_exists('IN7_POST_HISTORY')) include("superedit-IN7_POST_HISTORY.php");
if(!function_exists('M_DIST_FILES_RELATIONS')) include("superedit-M_DIST_FILES_RELATIONS.php");

//		$BAD_FILE_SIGNS=array('.',' ',',','/','A');
//		$OK_FILE_SIGNS=array("-",'_','--','---','a');



//echo "dupa";
//added line 179 080222
//print_r($_SESSION[TRG_FILE]);

function M_DIST_FILES($COMMAND,$M_DIST_FILES,$HIDE) {
global $BAD_FILE_SIGNS,$OK_FILE_SIGNS,$FOLDERS,$TRG_FILE,$SSL_IFACE,$PHP_SELF,$thiss,$ARG1,$ARG1_VAL,$result,$MENU_INIT;

//		$BAD_FILE_SIGNS=array('.',' ',',','/');
//		$OK_FILE_SIGNS=array("-",'_','--','---');


//	$M_DIST_FILES_PROJECT_FOLDER="/home/www/biall.com.pl/MARKETING_SMB/BAZA_REKLAM_2008";

  if($ARG1_VAL=='DRUKUJ_ZLECENIE') {
   echo "PRINT";

   $MENU_INIT="DOL";
  } else if($ARG1_VAL=="DRUKUJ_obr_dbf_dokument") {
    include("superedit-M_DIST_FILES-DRUKUJ_obr_dbf_dokument.php"); 
  } else if($ARG1_VAL=="DRUKUJ_ETYKETE") {
   echo "<html><body>";
   echo "<table><tr><td></td></tr></table>";
	

   DOL();
   $MENU_INIT="DOL";

  } else if($ARG1_VAL=='DODAJ_PLIK') {

if(!$HIDE)	echo "<html><body>";


 SEF("M_DIST_FILES_RELATIONS");
		  if(!$HIDE)          echo "<br> Szukam powiazanej korespondencji (po datach tymczasowo):";
          M_DIST_FILES_RELATIONS('IN7_MK_BAZA_DYSTRYBUCJI_COLUMN',$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID],'IN7_DZIENNIK_KORESP');

 if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]) {
      
		     $FOLDERS_LOOK=array($FOLDERS[$thiss->DETECT_TABLE_COLUMN]);
					 if(!$HIDE)     echo "<br>Szukam plikow (do projektow 1 ) w katalogu odpowiednim. | ";
				     foreach($FOLDERS_LOOK as $FOLDER_I=>$FOLDER) {
						if(!$HIDE)     echo "\n otwieram dir $FOLDER [ $FOLDER_I ]  ";
				  	    if ($handle = opendir($FOLDER)) {
			     		   	  while (false !== ($file = readdir($handle))) {
            						 if(is_dir($FOLDER."/".$file)) { 
 	     								 $files['LISTA0'][]=$FOLDER."/".$file;
									 }
							  }
 						 }
  					  }
		//} else echo "<br><font color=red>ERROR in CONFIG - \$FOLDERS[".$thiss->DETECT_TABLE_COLUMN."_LOOKAT\"]['DIR'] could be = \"FILES or = \"DIRECTORY\"  </font>";


   if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['FOLDER'][1]['LOOK_REGEX']) {
            $iFLR=1;
        	foreach ($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['FOLDER'] as $FFLR ) {
             	 //echo "<br>Odpalam nowy konfig majster L94:  "; 
             	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][LOOK_REGEX]='$1.';		     	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]';		     	 //$FOUND_FILES["TEN_PRODUKT"]=array_isearch($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".",$files[LISTA0]);       
		     	 eval("\$VARNAME_EVAL=\$FOLDERS[\$thiss->DETECT_TABLE_COLUMN.\"_LOOKAT\"][FOLDER][\$iFLR][VARNAME];");eval("\$VARNAME_EVAL=$VARNAME_EVAL;");
		     	 $LOOK_REGEX=str_replace('<VARNAME>',$VARNAME_EVAL,$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['FOLDER'][$iFLR]['LOOK_REGEX']);
		     	 
		     	 echo " VARNAME_EVAL=".$VARNAME_EVAL." , LOOK_REGEX = ".$LOOK_REGEX."";
		     	 $FOUND_FILES["TEN_PRODUKT"]=array_isearch_file($LOOK_REGEX,$files['LISTA0']);
		     	 //echo "<br> found files: <br>"; print_r($FOUND_FILES["TEN_PRODUKT"]);     
		     	 if($FOUND_FILES["TEN_PRODUKT"]) break;
		     	 $iFLR++; 
         	}
         	
         	
   }
   
   
 
     //Teraz wchodzimy do katalogow i listujemy co w nich  mamy , pierwszy zaznaczamy inaczej niz inny, pokazujemy jaki to katalog


     if(count($FOUND_FILES["TEN_PRODUKT"])>1) {

			$iFLR=1;
        	foreach ($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['FOLDER'] as $FFLR ) {
             	 echo " CASE2 - test nieprawidlowosci - L 118:  "; 
             	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][LOOK_REGEX]='$1.';		     	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]';		     	 //$FOUND_FILES["TEN_PRODUKT"]=array_isearch($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".",$files[LISTA0]);       
		     	 eval("\$VARNAME_EVAL=\$FOLDERS[\$thiss->DETECT_TABLE_COLUMN.\"_LOOKAT\"][FOLDER][\$iFLR][VARNAME];");eval("\$VARNAME_EVAL=$VARNAME_EVAL;");
		     	 $LOOK_REGEX=str_replace('<VARNAME>',$VARNAME_EVAL,$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['FOLDER'][$iFLR]['LOOK_REGEX']);
		     	 
		     	 echo " | VARNAME_EVAL=".$VARNAME_EVAL." , LOOK_REGEX = ".$LOOK_REGEX."";
		     	 $FOUND_FILES["TEN_PRODUKT"]=array_isearch_file($LOOK_REGEX,$files['LISTA0']);
		     	 //echo "<br> found files: <br>"; print_r($FOUND_FILES["TEN_PRODUKT"]);     
		     	 if($FOUND_FILES["TEN_PRODUKT"]) break;
		     	 $iFLR++; 
         	}
//        $FOUND_FILES["TEN_PRODUKT"]=array_isearch(".".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".",$files[LISTA0]);       


        foreach( $FOUND_FILES["TEN_PRODUKT"] as $FFOLDER) {
         echo "<br><font color=\"red\">ERROR Folder <b> ".$files['LISTA0'][$FFOLDER]."</b> jest nieprawdidlowo nazwany - POPRAW  TO NIEZWLOCZNIE</font>";
       }
     } else if(count($FOUND_FILES["TEN_PRODUKT"])==0) {
     //Nic nie znaleziono
         echo "<br><font color=\"red\">WARNING Nie znaleziono odpowiedniego folderu w ".$FOLDERS[$thiss->DETECT_TABLE_COLUMN]." dla projektu <b>".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID']."</b> Nalezy niezwlocznie go utworzyc!";
     } 
     //Dodatkowy error jak wiecej projektow spelnia zalozenia
      if(count($FOUND_FILES["TEN_PRODUKT"])>1) {
        echo "<br><font color=\"red\">ERROR jest az <b>".count($FOUND_FILES["TEN_PRODUKT"])."</b> folderow dla numer ID ".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'].". POPRAW TO NIEZWLOCZNIE</font>";
     } // EOF case      if(count($FOUND_FILES["TEN_PRODUKT"])>1) {

      



if(!$HIDE)     echo "<br> Znalazlem : ".count($FOUND_FILES["TEN_PRODUKT"])." katalogow<br>";  


   
   

 }  //eof  if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]) {



/* else  {



//print_r($FOLDERS);
//echo "<br>$thiss->DETECT_TABLE_COLUMN<br>";
     $FOLDERS_LOOK=array($FOLDERS[$thiss->DETECT_TABLE_COLUMN]);

//   if($thiss->DETECT_TABLE_COLUMN=="IN7_DZIENNIK_KORESP_COLUMN") $FOLDERS_LOOK=array($FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][K_TYP_KORESP]);
//      $FOLDERS_LOOK=array($FOLDERS[MARKETING_PROJEKTY]);

	echo "<h1>asdf91</h1>";


if(!$HIDE)     echo "<br>Szukam plikow (do projektow 1 ) w katalogu odpowiednim <br>";
     foreach($FOLDERS_LOOK as $FOLDER_I=>$FOLDER) {
if(!$HIDE)     echo "\n otwieram dir $FOLDER [ $FOLDER_I ]  ";

     if ($handle = opendir($FOLDER)) {
//     if ($handle = opendir('/home/samba/PROJEKTY')) {
//               echo "Directory handle: $handle\n";
//                            echo "Files: from $FOLDER\n";
 

             //
          while (false !== ($file = readdir($handle))) {
             
             if(is_dir($FOLDER."/".$file)) { 
             	 //die($FOLDER);

//                            echo "$FOLDER  , $FOLDER_I ,  $file\n";

			

         	   if($thiss->DETECT_TABLE_COLUMN=="KSIEG_DOKUMENTY_COLUMN"){
	     	 $files[LISTA0][]=$FOLDER."/".$file;
            }else if($thiss->DETECT_TABLE_COLUMN=="IN7_PRODUKTY_STATUS_COLUMN"){
//             echo "IN7_PRODUKTY_STATUS_COLUMN $FOLDER ";
            
             if(is_dir($FOLDER."/".$file)) $files[LISTA0][]=$FOLDER."/".$file;
            
          	  } else if($thiss->DETECT_TABLE_COLUMN=="IN7_DZIENNIK_KORESP_COLUMN"){
	      $files[LISTA0][]=$FOLDER."/".$file;
//if(!$HIDE)                            echo "$FOLDER  , $FOLDER_I ,  $file\n";
                            //		echo "KSIEG...";
//            print_r($files[LISTA0]);
	    } else if(is_dir($FOLDER."/".$file)) $files[LISTA0][]=$FOLDER."/".$file;


//               print_r($file);
		    }
        }
      }
    }
	  

     //Pierwsza proba ID+Data


     if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"][FOLDER][1][LOOK_REGEX]) {
         	echo "<br>Odpalam nowy konfig majster 110526:  "; 
     }      
        
//     print_r($FOUND_FILES);   

//echo $files[LISTA0][$FOUND_DIR];

//print_r($files[LISTA0][48]);
//echo "$FOUND_FILES";


} //EOF  l17 if($thiss->DETECT_TABLE_COLUMN=="KSIEG_DOKUMENTY_COLUMN"){

*/


//Druga proba Samo ID
//print_r($FOUND_FILES);
//print_r($files[LISTA0]);
//echo "HERE";
//print_r($FOUND_FILES["TEN_PRODUKT"]);
//echo "afrer here";


  	if(!$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['NEGFILE']['LOOK_REGEX']) echo "<br><font color=\"red\"> CONFIG dosn't have setting for \$FOLDERS[".$thiss->DETECT_TABLE_COLUMN."_LOOKAT][NEGFILE][LOOK_REGEX]= </font>";

	 foreach($FOUND_FILES["TEN_PRODUKT"] as $FOUND_DIR) {
//	   echo "<br>Wchodze do :  $FOUND_DIR  ".$files[LISTA0][$FOUND_DIR];


    if ($handle2 = opendir($files['LISTA0'][$FOUND_DIR])) {
//	    if ($handle2 = opendir('/var/www/forumkike/SE/PROJEKTY/2008-09-20.229.Projekt_Tanie_Lacze_id_229/')) {
//	    	    if ($handle2 = opendir('/var/www/forumkike/SE/PROJEKTY')) {
//	   	  if ($handle2 = opendir("/var/www/forumkike/SE/PROJEKTY/229/")) {
	   echo "<br>Wchodze do :  $FOUND_DIR  ".$files['LISTA0'][$FOUND_DIR];


$PATH_SAMBA=$files['LISTA0'][$FOUND_DIR];
$PATH_WWW=$files['LISTA0'][$FOUND_DIR];
settype($PATH_SAMBA, "string");  

$PATH_SAMBA=ereg_replace($FOLDERS[$thiss->DETECT_TABLE_COLUMN],$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_PATH"],$PATH_SAMBA);
$PATH_WWW=ereg_replace($FOLDERS[$thiss->DETECT_TABLE_COLUMN],$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_WWW"],$PATH_WWW);

//echo "<hr>Zawartosc katalogu: ". $files[LISTA0][$FOUND_DIR] ."<br>::: PATH_SAMBA:: $PATH_SAMBA  replace ".$FOLDERS[MARKETING_PROJEKTY_PATH]." , ".$files[LISTA0][$FOUND_DIR]."".$thiss->DETECT_TABLE_COLUMN;
echo "<table border=1 bordercolor=\"#777777\" cellspacing=0 cellpadding=0 RULES=COLS ><tr><td colspan=3 bgcolor=\"#ccccff\"><img src=\"icon/ms_directory.gif\" border=\"0\"><font face=arial size=\"-1\">Adres:<a href=\"file://$PATH_SAMBA\">$PATH_SAMBA</font> </a> <a href=\"$PATH_WWW\">(Web)</font></a> </td></tr>";
echo "<tr><td><font face=arial size=\"-1\">Nazwa</td><td><font face=arial size=\"-1\">Rozmiar</td><td><font face=arial size=\"-1\">Typ</td></tr>";

						 	if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['NEGFILE']['LOOK_REGEX']) {
        			     	 echo "<br>NEGFILE#L269"; 
        			     	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][LOOK_REGEX]='$1.';		     	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]';		     	 //$FOUND_FILES["TEN_PRODUKT"]=array_isearch($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".",$files[LISTA0]);       
					     	 eval("\$VARNAME_EVAL=\$FOLDERS[\$thiss->DETECT_TABLE_COLUMN.\"_LOOKAT\"][NEGFILE][VARNAME];");eval("\$VARNAME_EVAL=$VARNAME_EVAL;");
					     	 $LOOK_REGEX=str_replace('<VARNAME>',$VARNAME_EVAL,$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['NEGFILE']['LOOK_REGEX']);
					     	 
					     	 echo "<br>VARNAME_EVAL=".$VARNAME_EVAL." , LOOK_REGEX = ".$LOOK_REGEX."";
					     	 //$FOUND_FILES["TEN_PRODUKT"]=array_isearch_file($LOOK_REGEX,$files[LISTA0]);
							 } 
							$CUR_DIR_2=$files['LISTA0'][$FOUND_DIR];
							
                     while (false !== ($file = readdir($handle2))) {

	   	  	   
	   	  	   				   	  	   
	   	  	    if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['NEGFILE']['LOOK_REGEX'])if((!preg_match($LOOK_REGEX,$file))) continue;
			
//	                     echo  "$CUR_DIR_2 / $file\n";
                              if(is_dir($CUR_DIR_2."/".$file)) 
                                 echo "<tr><td border=1><font face=arial size=\"-1\"><img src=\"icon/ms_directory.gif\" border=\"0\"><a href=\"file://$PATH_SAMBA/$file\"> $file</a></td><td>-</td><td>Folder plikow <a href=\"$PATH_WWW/$file\">(Web)</font></a></td></tr></a>";  
                                 else { 
                                   echo "<tr><td><font face=arial size=\"-1\"><a href=\"file://$PATH_SAMBA/$file\"><img src=\"icon/new.gif\" border=\"0\"> $file</a></td><td><font face=arial size=\"-1\">".round(filesize($CUR_DIR_2."/".$file)/1000000,2)." Mb</td><td>";
                                    if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_WWW"]) echo "<a href=\"$PATH_WWW/$file\" target=\"_blank\"> W </a>";
                                                                   
                                   echo "Plik</a></td></tr></a>";
                                    //TODO wersja http zapodawanie plikow
                                  //echo "<a href=\"$PATH_WWW/$file\" target=\"_blank\"> W </a>";
                                 }
//	                     echo  "<font face=arial size=-1> $file </font>\n<br>";
//	                     echo "3. szukamy spelniajacych kryterii zalozen $TRG_FILE\n";
	                    }
	              }      else echo " Nie wszedlem do katalogu";
	 } 

echo "</table>";
//	 print_r($CUR_DIR_2);




     if(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['PERMEDIT']['M_DIST_FILES'],"W")) {   
	//TODO security improvments!	
	
	//Okreslenie docelowego katalogu
	if($CUR_DIR_2) $DEST_FOLDER=$CUR_DIR_2;
	else {

         if($thiss->DETECT_TABLE_COLUMN=="IN7_PRODUKTY_STATUS_COLUMN") {
               echo "<br> CUR DIR PRODUKTY";
  	       $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['PRODUKT_ID']."_".str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['M_DIST_TYPE']) ;
//		$DEST_FOLDER=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$DEST_FOLDER);

            } else if($thiss->DETECT_TABLE_COLUMN=="IN7_DZIENNIK_KORESP_COLUMN") {
               echo "<br> CUR DIR PRODUKTY";
  	       $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['K_TYP_KORESP']  ;
//  	       $DEST_FOLDER=$FOLDERS[IN7_DZIENNIK_KORESP_COLUMN]  ;
//			echo $DEST_FOLDER;
		
//		$DEST_FOLDER=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$DEST_FOLDER);

            } else if($thiss->DETECT_TABLE_COLUMN=="odb_dbf_COLUMN") {
               echo "<br> CUR DIR PRODUKTY";
  	       //$DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][PRODUKT_ID]."_".str_replace(' ','_',$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_TYPE]) ;
  	       $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['symbol'] ;

            } else if($thiss->DETECT_TABLE_COLUMN=="zam_dbf_COLUMN") {
               echo "<br> CUR DIR PRODUKTY";
  	       //$DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][PRODUKT_ID]."_".str_replace(' ','_',$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_TYPE]) ;
  	       $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['nrdok']."-".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['mag']."-".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['dok'].".ZAMOWIENIE.Oper_".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['operator']."_Do_".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['dokad'].".".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['data_op'].".".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] ;

            }  else if($thiss->DETECT_TABLE_COLUMN=="USERS_COLUMN") {
  	       $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_NAME']).".".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'].".".str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ADDRESS_POST_CODE'].$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_ADDRESS_CITY']) ;
            } else { 
				
				
				//DEST_FOLDER_BEGIN_11
				//echo "xxx";
				if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_DEST_FOLDER"]['FOLDER'][1]['LOOK_REGEX']) {
        			     	 echo "<br>_DEST_FOLDER Odpalam nowy konfig majster L335"; 
							foreach ($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_DEST_FOLDER"]['FOLDER'] as $A1=>$V1) {
								//echo "<br>A1:".$A1." xxx ".$V1 ;
									$LOOK_REGEX=$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_DEST_FOLDER"]['FOLDER'][$A1]['LOOK_REGEX'];
										foreach ($V1['VARNAME'] as $A2=>$V2) {
											//echo "<br> --- A:(".$A2.") V:".$V2;
											 eval("\$VARNAME_EVAL=\$V2;");eval("\$VARNAME_EVAL=$VARNAME_EVAL;");
											 $VARNAME_EVAL=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$VARNAME_EVAL);
					     					 $LOOK_REGEX=str_replace("<VARNAME".$A2.">",$VARNAME_EVAL,$LOOK_REGEX);
					     					// echo "<br>VARNAME_EVAL=".$VARNAME_EVAL." , LOOK_REGEX = ".$LOOK_REGEX."";
					     					 //$FOUND_FILES["TEN_PRODUKT"]=array_isearch_file($LOOK_REGEX,$files[LISTA0]);

										}


        			     		 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][LOOK_REGEX]='$1.';		     	 //$FOLDERS[IN7_MK_BAZA_DYSTRYBUCJI_COLUMN_LOOKAT][FOLDER][1][VARNAME]='$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID]';		     	 //$FOUND_FILES["TEN_PRODUKT"]=array_isearch($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".",$files[LISTA0]);       
					     							     		 
								$DEST_FOLDER.="/".$LOOK_REGEX;
					     		 //echo "<br>DEST_FOLDER:".$DEST_FOLDER;


							}
					  $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN].$DEST_FOLDER ;
   	 				// echo "<br>FINAL_DEST_FOLDER:".$DEST_FOLDER;
					  //$DEST_FOLDER=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$DEST_FOLDER);
					
				} 
				
				
				//DEST_FOLDER_END_11
				
				
				
               $M_DISTRIBUTOR=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,substr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['M_DIST_DESC'],0,15)."_".substr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['M_DISTRIBUTOR'],0,15));
//	 	$DEST_FOLDER=$FOLDERS[MARKETING_PROJEKTY]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_DATE].".".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".".str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_TYPE]).".".$M_DISTRIBUTOR ;
  	     //  $DEST_FOLDER=$FOLDERS[$thiss->DETECT_TABLE_COLUMN]."/".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_DATE].".".str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_TYPE]).".".str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$M_DISTRIBUTOR) ;
  	        //$PATH_SAMBA=ereg_replace($FOLDERS[MARKETING_PROJEKTY],$FOLDERS[MARKETING_PROJEKTY_PATH],$DEST_FOLDER);

//	 	$PATH_SAMBA=ereg_replace('\\','/',$PATH_SAMBA);
             }
  	        $PATH_SAMBA=ereg_replace($FOLDERS[$thiss->DETECT_TABLE_COLUMN],$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_PATH"],$DEST_FOLDER);         

	}

  if(!$HIDE) { //BEGIN NOT FORM ADD FILE L272
	 echo "<form enctype=\"multipart/form-data\" method=\"POST\" action=\"$PHP_SELF?FUNCTION_INIT=$_GET[FUNCTION_INIT]&ARG1_VAL=DODAJ_PLIK_ADD&HEADER_NOT_INIT=YES\"> \n";
	 echo "<input type=hidden name='FUNCTION_INIT' value='M_DIST_FILES'>";
	 echo "<input type=hidden name='ARG1_VAL' value='DODAJ_PLIK_ADD'>";
	 echo "<input type=hidden name='HEADER_NOT_INIT' value='YES'>";
	 echo "<input type=hidden name='M_DIST_FILES_DEST_FOLDER' value='$DEST_FOLDER'>";

	echo "<table border=1 RULES=COLS bgcolor=\"#ffcccc\"><tr><td colspan=5>DODAWANIE PLIKU DO PROJEKTU w/w <input  name=\"M_DIST_FILES_NAME\" type=\"file\" size=30><font size=\"-1\"> (Wskaz Plik na dysku Twojego Komputera lub Serwera Plikow)</td></tr>";

	  if ($handle3 = opendir($FOLDERS['SCANS_COLUMN'])) {  //IF line 196
	        echo "<tr  bgcolor=\"#FFCCFF\"  ><td colspan=\"6\" bgcolor=\"#FFCCCC\">";
		echo "<table bgcolor=\"#FFEEEE\" border=1 RULES=COLS  ><tr><td colspan=4>";
		echo "...wzglednie dodaj plik ze skrzynki SKANOW <a href=\"file:".$FOLDERS['SCANS_COLUMN_PATH']."\">".$FOLDERS['SCANS_COLUMN_PATH']."</a> (staraj sie nie uzywac polskich liter i spacji, to unikniesz problemow)</td></tr><tr><td>";
					$II_SCAN=0;
		 			unset($_SESSION['SCANS_COLUMN']['ADD_FILE']);
		 			
		 			
		 	/*		
		 			 // BEGING 2011-12	
								while($file = readdir($handle3)) {
								        if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_LOOKAT"]['NEGFILE']['LOOK_REGEX'])if((!preg_match($LOOK_REGEX,$file))) continue;


								        if(is_dir($file))        {
								                continue;
								        }

								        else if($file != '.' && $file != '..')        {
								                //echo "<a href='$path/$file'>$file</a><br/>";
								                $narray[$iii]=$file;
								                //$datearray[$iii]=$file;
								                $filectime[$iii]=filectime($FOLDERS[SCANS_COLUMN]."/".$file);
								                $iii++;
								        }
								}
								sort($filectime);

								echo "<pre>";
								print_r($filectime);
								echo "</pre>";	

								foreach ($filectime as $ctime_index=>$ctime_ctime) {
						//       echo "<a href=".chr(34).$path."\"".$narray[$ctime_index].chr(34).">".$narray[$ctime_index]."</a><br/>";
						      	$file=$narray[$ctime_index];
								}
//							print_r($narray);



							 // BEGING END 2011-12

*/
		 			
		                     while (false !== ($file = readdir($handle3))) {

//					echo "<a href=\"file:".$FOLDERS[SCANS_COLUMN_PATH]."/".$file."\">".$file."</a><br> \n ";
				                              if(is_dir($FOLDERS[SCANS_COLUMN]."/".$file)) {}
                                				 //echo "<tr><td border=1><td></td><font face=arial size=\"-1\"><img src=\"icon/ms_directory.gif\" border=\"0\"><a href=\"file://$PATH_SAMBA/$file\"> $file</a></td><td>-</td><td></td><td>Folder plikow</td></tr></a>";  
				                                 else { 
                                				   echo "<tr><td>";
								   $_SESSION['SCANS_COLUMN']['ADD_FILE'][$II_SCAN]['FOLDER']=$FOLDERS['SCANS_COLUMN'] ;
								   $_SESSION['SCANS_COLUMN'][ADD_FILE][$II_SCAN]['FILE']=$file ;
								   echo "<input type='checkbox' name='SCANS_COLUMN_ADD__".$II_SCAN."'></input> ";
									echo "</td><td>";
									if($FOLDERS['SCANS_COLUMN_WWW'])$SCANDIR_HREF="".$FOLDERS['SCANS_COLUMN_WWW'] ;
						                              else $SCANDIR_HREF="file://".$FOLDERS['SCANS_COLUMN_PATH'] ;
						                              echo "<font face=arial size=\"-1\"><a href=\"$SCANDIR_HREF/$file\"><img src=\"icon/new.gif\" border=\"0\"> $file</a></td>
									<td><font face=arial size=\"-1\">".round(filesize($FOLDERS['SCANS_COLUMN']."/".$file)/1000000,2)." Mb</td>
									<td><font face=arial size=\"-1\">".date("Y-m-d H:i:s.", filectime($FOLDERS['SCANS_COLUMN']."/".$file))."</td><td>Plik</td></tr></a>";
				                                    //TODO wersja http zapodawanie plikow
                                				  //echo "<a href=\"$PATH_WWW/$file\" target=\"_blank\"> W </a>";
				                                 }
					$II_SCAN++;
				      }

		echo "</td></tr></table>";
		  echo "</td></tr>";
          } //EOF L196
	  echo "<tr><td> YYYY-MM-DD . </td><td>TYP</td><td>Opis</td><td>Data Wersji</td><td>Numer Wersji</td><td>Rozszerzenie</td></tr>";
	  echo "<tr><td>Indeks pliku/Data Wersji / Numer Indeksu / Inny wskazik( XXXXX.Typ.Opis.Data.Wersja.Roz) </td><td>TYP</td><td>Opis pliku (kogo dotyczy/czego/sprawa/nazwa_firmy itp)( Indeks.Typ.XXXXXX.Data.Wersja.Roz)</td><td>Data Wersji</td><td>Numer Wersji</td><td>Rozszerzenie</td></tr>";

	  //1 linia
	  echo "<tr><td><input type='checkbox' name='M_DIST_FILES_INDEXNAME_AUTO'>Wykrycie automatyczne indeksu z wysylanego pliku </input>
	  <br><input type='checkbox' name='M_DIST_FILES_FOLDER_CREATE_AUTO' checked>Zalozenie katalogu/folderu (jak nie ma) </input></td>
	  <td><input type='checkbox' name='M_DIST_FILES_TYPE_AUTO'>Wykrycie automatyczne TYPU z wysylanego pliku </input>";




	  //2 linia
	  $M_DIST_FILES_DESCRIPTION_AUTO="checked";
	  $M_DIST_FILES_DATE_TODAY="checked";
	  $M_DIST_FILES_VERSION_AUTO="checked";
	  if($thiss->DETECT_TABLE_COLUMN=="IN7_PRODUKTY_STATUS_COLUMN")  $M_DIST_FILES_INDEXNAME=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['PRODUKT_ID'] ;
	  else	  if($thiss->DETECT_TABLE_COLUMN=="IN7_DZIENNIK_KORESP_COLUMN") {
	     $M_DIST_FILES_INDEXNAME=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['K_DATA_OTRZYMANEJ_KORESP'] ;
	     $M_DIST_FILES_DESCRIPTION=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['K_ZAWARTOS']) ;
	     $M_DIST_FILES_DESCRIPTION_AUTO="" ;
	     $M_DIST_FILES_VERSION_AUTO="";
	     
	     $M_DIST_FILES_VERSION=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'];
	  } else if($thiss->DETECT_TABLE_COLUMN=="KSIEG_DOKUMENTY_COLUMN") {
	  $M_DIST_FILES_INDEXNAME=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['DATA_DOK'] ;
//		$BAD_FILE_SIGNS=array('.',' ',',','/');
//		$OK_FILE_SIGNS=array("-",'_','--','---');



	  $M_DIST_FILES_DESCRIPTION=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['SPRZEDAWCA']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SPRZEDAWCA']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SPRZEDAWCA']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['NUMER_DOK']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_KONTO_KSIEG']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['NR_POZ_OPIS']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['CZY_URZADZENIE']) ;
	  $M_DIST_FILES_DATE=substr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_RECORD_CREATE_DATE'],0,10) ;
	  $M_DIST_FILES_VERSION=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] ;
	  } else if($thiss->DETECT_TABLE_COLUMN=="IN7_MK_BAZA_DYSTRYBUCJI_COLUMN") {
	  
	  $M_DIST_FILES_INDEXNAME=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] ;
//		$BAD_FILE_SIGNS=array('.',' ',',','/');
//		$OK_FILE_SIGNS=array("-",'_','--','---');



	  $M_DIST_FILES_DESCRIPTION=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['SPRZEDAWCA']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SPRZEDAWCA']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_SPRZEDAWCA']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['NUMER_DOK']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID_KONTO_KSIEG']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['NR_POZ_OPIS']."__".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['CZY_URZADZENIE']) ;
	  $M_DIST_FILES_DATE=substr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['A_RECORD_CREATE_DATE'],0,10) ;
	  $M_DIST_FILES_VERSION=$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['ID'] ;
	  } 
	  
		  	if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_DEST_FOLDER"]['M_DIST_FILES_INDEXNAME']) {
		  		    	 eval("\$VARNAME_EVAL=\$FOLDERS[\$thiss->DETECT_TABLE_COLUMN.\"_DEST_FOLDER\"][M_DIST_FILES_INDEXNAME];");eval("\$VARNAME_EVAL=$VARNAME_EVAL;");
						if(strlen($VARNAME_EVAL)>1)
						 $M_DIST_FILES_INDEXNAME=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$VARNAME_EVAL);
		  	}
		  	if($FOLDERS[$thiss->DETECT_TABLE_COLUMN."_DEST_FOLDER"]['M_DIST_FILES_DESCRIPTION']) {
		  		    	 eval("\$VARNAME_EVAL=\$FOLDERS[\$thiss->DETECT_TABLE_COLUMN.\"_DEST_FOLDER\"][M_DIST_FILES_DESCRIPTION];");eval("\$VARNAME_EVAL=$VARNAME_EVAL;");
						if(strlen($VARNAME_EVAL)>1)
						 $M_DIST_FILES_DESCRIPTION=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$VARNAME_EVAL);
		  	}
	  
	  


	if(strlen($M_DIST_FILES_DESCRIPTION)>25) $M_DIST_FILES_DESCRIPTION=substr($M_DIST_FILES_DESCRIPTION,0,25);

	  echo "<br><input type='checkbox' name='M_DIST_FILES_TEMP'>Plik tymczasowy/roboczy/nieoficjalny (_TEMP)</input>
        
          <br><input type='checkbox' name='M_DIST_FILES_PROJECT_TYPE' checked>Czy plik dotyczy jakiegos projektu (_P) </input></td>
          <td><input type='checkbox' name='M_DIST_FILES_DESCRIPTION_AUTO' ".$M_DIST_FILES_DESCRIPTION_AUTO."> (automatyczny opis z nazwy pliku wysylanego)</input>
          <td><input type='checkbox' name='M_DIST_FILES_DATE_TODAY' ".$M_DIST_FILES_DATE_TODAY.">Data wersji = DZISIAJ (lub wpisz ja recznie) </input></td>
          <td><input type='checkbox' name='M_DIST_FILES_VERSION_AUTO' ".$M_DIST_FILES_VERSION_AUTO.">Automatycznie dodaj wersje (TODO) </input>
          <br><input type='checkbox' name='M_DIST_FILES_VERSION_OVERWRITE'>Nadpisz istniejaca wersje/plik (OVERWRITE) </input>
             </td>
          <td><input type='checkbox' name='M_DIST_FILES_EXTENSION_AUTO' checked>Automatyczne Rozszerzenie na podstawie wysylanego pliku </input></td>

          </tr>";
	  echo "<tr>";
	  echo "<td><input type='text' name='M_DIST_FILES_INDEXNAME' value='".$M_DIST_FILES_INDEXNAME."'></input></td>";

  	  echo "<td><select name='M_DIST_FILES_TYPE'>";
	    //TODO select different types from PROCESY3.php
  
	    foreach($TRG_FILE as $M_DIST_FILES_TYPE_TYPES_INDEX=>$M_DIST_FILES_TYPE_TYPES_VALUE){
	    echo "<option value='$M_DIST_FILES_TYPE_TYPES_INDEX' ";
			   if($M_DIST_FILES_TYPE_TYPES_INDEX==$FOLDERS[$thiss->DETECT_TABLE_COLUMN."_DEST_FOLDER"]['M_DIST_FILES_TYPE_TYPES_VALUE']) echo "selected=\"true\" ";
			  echo ">".$M_DIST_FILES_TYPE_TYPES_INDEX."</OPTION>\n";
	    //            echo "<br> \n $M_DIST_FILES_TYPE_TYPES_INDEX ";
            }
           echo "</select></td> ";      
	  echo "<td><input type='text' name='M_DIST_FILES_DESCRIPTION' value='".$M_DIST_FILES_DESCRIPTION."' size=50> </input></td>";
	  echo "<td><input type='text' name='M_DIST_FILES_DATE' value='".$M_DIST_FILES_DATE."' SIZE=\"10\"> </input></td>";        
	  echo "<td><input type='text' name='M_DIST_FILES_VERSION' value='".$M_DIST_FILES_VERSION."'>  </input></td>";
	  echo "<td><input type='text' name='M_DIST_FILES_EXTENSION' size=5> </input></td>";
	  echo "</tr>";
	  
	  //3 linia


	  echo "<tr><td colspan=6>";
	 echo "  <br>aby go wgrac do <br>$PATH_SAMBA<br>";
	 echo "<br><input type=\"submit\" value=\"Jak klikniesz tu to wgrasz zalaczony plik do folderu , zgodnie z zaznaczonymi wyzej parametrami  \"> ";
	  echo "</td></tr>";


	  echo "<br><br>";



	
	 echo "</form><font color=\"#cccccc\">config in superedit-M_DIST_FILES.func </font>";
        } //   EOF if(!$HIDE) { //BEGIN NOT FORM ADD FILE L272

     }




   $MENU_INIT="DOL";

  } else if($ARG1_VAL=='DODAJ_PLIK_ADD') { 

         if(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['PERMEDIT']['M_DIST_FILES'],"W")) {

	    echo "Jade if($COMMAND==DODAJ_PLIK_ADD)";

	if (is_uploaded_file($_FILES['M_DIST_FILES_NAME']['tmp_name'])) {
	
	    if($_POST['M_DIST_FILES_DEST_FOLDER']) echo "jest $_POST[M_DIST_FILES_DEST_FOLDER]";
	    

	    $IN7_FILERENAME=IN7_FILERENAME($_POST,$_FILES['M_DIST_FILES_NAME']['name'],$_POST['M_DIST_FILES_DEST_FOLDER']);

//            print_r($IN7_FILERENAME);	    

               if(($IN7_FILERENAME['DST_FILE_NAME'])&&($IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER'])&&(!$IN7_FILERENAME['ERROR'])) {
//poprawa nazwy zlej
//		$IN7_FILERENAME[DST_FILE_NAME]=str_replace($BAD_FILE_SIGNS,$OK_FILE_SIGNS,$IN7_FILERENAME[DST_FILE_NAME]);
                   move_uploaded_file($_FILES['M_DIST_FILES_NAME']['tmp_name'],$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME']);
                   echo "<br>wykonalem funkcje move dla parametrow ".$_FILES['M_DIST_FILES_NAME']['tmp_name']." oraz ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME'] ." <br>
                   Informacje dodatkowe :".$IN7_FILERENAME['INFO']." <br> EOL <br> ";
	  	if($IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME']) {
			 echo "<hr><h1><FONT COLOR=GREEN>OK PRAWDOPODOBNIE WGRALES PLIK</FONT>, <a href=\"JavaScript:window.close()\">zamknij to okno i wroc do wczesniejszego</a></h1>";
			IN7_POST_HISTORY($TABLE,array('M_DIST_FILES'),array(" Wgrano plik z przegladarki WWW ".$_SERVER['REMOTE_ADDR']." ".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER']."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FILE']." do ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME']." "),$thiss,$SESSION);
			$WYLADOWANO_PLIK='TAK';
		} else echo "<hr><h1><FONT COLOR=RED>PLIK NIE ZOSTAL WGRANY BLAD/ERROR</FONT>, <a href=\"JavaScript:window.close()\">zamknij to okno i wroc do wczesniejszego</a></h1>";
		
               } else if($IN7_FILERENAME['ERROR']) echo "<br> <font color=red> Wystapil error (".$IN7_FILERENAME['ERROR'].")<br>EOL.";
        }//         if (is_uploaded_file($_FILES['M_DIST_FILES_NAME']['tmp_name'])) {

  //  }
 	 }

	//TODO MAKE SECURITY IMPROVEMENTS $IN7_FILERENAME[M_DIST_FILES_DEST_FOLDER] - I $_POST[DEST_FOLDER] IS NOT SECURE IT SHOUDL BE PASSED VIA SESSION

if(!$WYLADOWANO_PLIK)	echo "<br> Nie ma uploaded file ale idzie funkcja alternatywna ";
//	print_r($_POST);
	foreach($_POST as $POST_I=>$POST_V) {
	  	if(strstr($POST_I,'SCANS_COLUMN_ADD__')) {
			echo "<br> Proba przeniesienia pliku ze SCANS_COLUMN \n";
		        list(,$SCAN_PLIK)=explode('__',$POST_I);
			echo "DLa ID $SCAN_PLIK";
			echo $_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER'] ;
//			print_r($_SESSION[SCANS_COLUMN][ADD_FILE]);
			$IN7_FILERENAME=IN7_FILERENAME($_POST,$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FILE'],$_POST['M_DIST_FILES_DEST_FOLDER']);
			               if(($IN7_FILERENAME['DST_FILE_NAME'])&&($IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER'])&&(!$IN7_FILERENAME['ERROR'])) {
					if(file_exists($_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER']."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FILE'])) {
                   			 if(copy($_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER']."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK][FILE],$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME'])) {
						chmod("$IN7_FILERENAME[M_DIST_FILES_DEST_FOLDER]."/".$IN7_FILERENAME[DST_FILE_NAME]", 0777);
					 unlink($_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER']."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FILE']);
					 } else $IN7_FILERENAME['ERROR'].="COPY_ERROR Problem z kopiowaniem pliku w docelowe miejsce , ";
					} else $IN7_FILERENAME['ERROR'].="COPY_ERROR Problem z kopiowaniem brak pliku zrodlowego , ";
                   		echo "<br>wykonalem funkcje move dla parametrow ".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER']."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FILE']." oraz ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME'] ." <br>
                   		Informacje dodatkowe :".$IN7_FILERENAME['INFO']." <br> EOL <br> <hr><h1>PRAWDOPODOBNIE WGRALES PLIK, zamknij to okno i wroc do wczesniejszego</h1>";
               } else if($IN7_FILERENAME['ERROR']) echo "<br> <font color=red> Wystapil error (".$IN7_FILERENAME['ERROR'].")<br>EOL.";
		if($IN7_FILERENAME['ERROR']) echo "<br> <font color=red> Wystapil error (".$IN7_FILERENAME['ERROR'].")<br>EOL."; 
		else IN7_POST_HISTORY($TABLE,array('M_DIST_FILES'),array("Przeniesiono plik z folderu ".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FOLDER']."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK]['FILE']." do ".$IN7_FILERENAME['M_DIST_FILES_DEST_FOLDER']."/".$IN7_FILERENAME['DST_FILE_NAME']." "),$thiss,$SESSION);
//IN7_POST_HISTORY($TABLE,array('M_DIST_FILES'),array("Przeniesiono plik z folderu ".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK][FOLDER]."/".$_SESSION["SCANS_COLUMN"]["ADD_FILE"][$SCAN_PLIK][FILE]." do ".$IN7_FILERENAME[M_DIST_FILES_DEST_FOLDER]."/".$IN7_FILERENAME[DST_FILE_NAME]." "),$thiss,$SESSION);
		}
	}	

	    $MENU_INIT="DOL";  

  } else if($COMMAND=='POST_VERIFY') { 
//    echo "POST VERIFY dla<pre>";
 //   echo "GET:"; print_r($_GET);
 //   echo "POST:"; print_r($_POST);
    echo "Zamknij okno, plik zostal prawdopodobnie dograny, mozesz tez cofnac okno skrotem alt+lewa_strzalka</pre>";

   

  } else {
  if($_SESSION['CURRENT_MENU']==$thiss->DETECT_EDIT_FUNCTION) {

   if(strstr($_SESSION[$thiss->DETECT_TABLE_COLUMN]['PERMEDIT']['M_DIST_FILES'],"W")) {
//        GETFORMITEM($_SESSION[$thiss->DETECT_TABLE_COLUMN][EDIT_TEMPLATE]['M_DIST_FILES'],$_SESSION[$thiss->DETECT_TABLE_COLUMN]['TYPE']['M_DIST_FILES'],'M_DIST_FILES');
//         echo " ( $thiss->DETECT_TABLE_COLUMN )" . $_SESSION[$thiss->DETECT_TABLE_COLUMN]['DESC']['M_DIST_FILES'] ;
//	echo "<input type=file name='M_DIST_FILES'> ";

echo "	<a target=blank href=$PHP_SELF?FUNCTION_INIT=M_DIST_FILES&ARG1_VAL=DODAJ_PLIK&HEADER_NOT_INIT=YES>DODAJ_PLIK</a><br>";
	//DRUKUJ_ETYKETE Drukowanie etykiet adresowych - 2009-01-28 by SQIX
     if(($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['OD_KOGO_ADRES'])||($_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['P_NAME'])) echo "  <a target=blank href=$PHP_SELF?FUNCTION_INIT=M_DIST_FILES&ARG1_VAL=DRUKUJ_ETYKETE&HEADER_NOT_INIT=YES>DRUKUJ_ETYKETE</a><br>";

	echo $_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['M_DIST_FILES'];
	 include("superedit-M_DIST_FILES-BIALL.php");
	 if($thiss->DETECT_TABLE_COLUMN=="IN7_PRODUKTY_STATUS_COLUMN")  {
     	    echo "    <a target=blank href=procesy-produkty-v1.php?LISTA_CECH_PRODUKTOW=1&EDIT=1&ADD_PROCES_ID=".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['PRODUKT_ID'].">DODAJ_CECHY</a><br>";
     	   echo "    <a target=blank href=http://forum.kike.pl/ses/params/show_parameters.php?INDEKS=".$_SESSION[$thiss->DETECT_TABLE_COLUMN]['EDITRECORD']['PRODUKT_ID'].">PODGLAD_WWW</a><br>";
         }
       }

//   echo $M_DIST_FILES." (drukuj) ";
//    echo "&nbsp;<a target=blank href=$PHP_SELF?FUNCTION_INIT=M_DIST_FILES&ARG1_VAL=DRUKUJ_ZLECENIE&HEADER_NOT_INIT=YES>
//    <img src=icon/print.gif border=0 alt=DRUKUJ_ZLECENIE_DO_OPRACOWANIA_GRAFICZNEGO></a><br>";
//    echo "&nbsp;<a target=blank href=$PHP_SELF?FUNCTION_INIT=M_DIST_FILES&ARG1_VAL=DRUKUJ_WEW_FORMULARZ&HEADER_NOT_INIT=YES>FORMULARZ-WEW</a><br>";
//echo "&nbsp;<a target=blank href=\"file:\\\\zbyszek/MARKETING/BAZA_REKLAM_2008/".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_DATE].".".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][ID].".".$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DIST_TYPE].".".str_replace(" ","_",$_SESSION[$thiss->DETECT_TABLE_COLUMN][EDITRECORD][M_DISTRIBUTOR])."/\">LINK w BAZIE REKLAM.</a><br>";

  } else {
    echo "<br> ELSE1 ";
  }
 }

//echo "MDF.";

}

