[SPIP] +installation version 3.0.10
[lhc/web/www.git] / www / plugins-dist / svp / inc / pcltar.php
diff --git a/www/plugins-dist/svp/inc/pcltar.php b/www/plugins-dist/svp/inc/pcltar.php
new file mode 100644 (file)
index 0000000..f010d22
--- /dev/null
@@ -0,0 +1,3557 @@
+<?php\r
+// --------------------------------------------------------------------------------\r
+// PhpConcept Library - Tar Module 1.3.1\r
+// --------------------------------------------------------------------------------\r
+// License GNU/GPL - Vincent Blavet - January 2003\r
+// http://www.phpconcept.net\r
+// --------------------------------------------------------------------------------\r
+//\r
+// Presentation :\r
+//   PclTar is a library that allow you to create a GNU TAR + GNU ZIP archive,\r
+//   to add files or directories, to extract all the archive or a part of it.\r
+//   So far tests show that the files generated by PclTar are readable by\r
+//   gzip tools and WinZip application.\r
+//\r
+// Description :\r
+//   See readme.txt (English & Fran�ais) and http://www.phpconcept.net\r
+//\r
+// Warning :\r
+//   This library and the associated files are non commercial, non professional\r
+//   work.\r
+//   It should not have unexpected results. However if any damage is caused by\r
+//   this software the author can not be responsible.\r
+//   The use of this software is at the risk of the user.\r
+//\r
+// --------------------------------------------------------------------------------\r
+\r
+// ----- Look for double include\r
+if (!defined("PCL_TAR"))\r
+{\r
+  define( "PCL_TAR", 1 );\r
+\r
+  // ----- Configuration variable\r
+  // Theses values may be changed by the user of PclTar library\r
+  if (!isset($g_pcltar_lib_dir))\r
+    $g_pcltar_lib_dir = find_in_path("lib/pcltar");\r
+\r
+  // ----- Error codes\r
+  //   -1 : Unable to open file in binary write mode\r
+  //   -2 : Unable to open file in binary read mode\r
+  //   -3 : Invalid parameters\r
+  //   -4 : File does not exist\r
+  //   -5 : Filename is too long (max. 99)\r
+  //   -6 : Not a valid tar file\r
+  //   -7 : Invalid extracted file size\r
+  //   -8 : Unable to create directory\r
+  //   -9 : Invalid archive extension\r
+  //  -10 : Invalid archive format\r
+  //  -11 : Unable to delete file (unlink)\r
+  //  -12 : Unable to rename file (rename)\r
+  //  -13 : Invalid header checksum\r
+\r
+\r
+// --------------------------------------------------------------------------------\r
+// ***** UNDER THIS LINE NOTHING NEEDS TO BE MODIFIED *****\r
+// --------------------------------------------------------------------------------\r
+\r
+  // ----- Global variables\r
+  $g_pcltar_version = "1.3.1";\r
+\r
+  // ----- Extract extension type (.php3/.php/...)\r
+  $g_pcltar_extension = "php";\r
+\r
+  // ----- Include other libraries\r
+  // This library should be called by each script before the include of PhpZip\r
+  // Library in order to limit the potential 'lib' directory path problem.\r
+  if (!defined("PCLERROR_LIB"))\r
+  {\r
+    include($g_pcltar_lib_dir."/pclerror.lib.".$g_pcltar_extension);\r
+  }\r
+  if (!defined("PCLTRACE_LIB"))\r
+  {\r
+    include($g_pcltar_lib_dir."/pcltrace.lib.".$g_pcltar_extension);\r
+  }\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarCreate()\r
+  // Description :\r
+  //   Creates a new archive with name $p_tarname containing the files and/or\r
+  //   directories indicated in $p_list. If the tar filename extension is\r
+  //   ".tar", the file will not be compressed. If it is ".tar.gz" or ".tgz"\r
+  //   it will be a gzip compressed tar archive.\r
+  //   If you want to use an other extension, you must indicate the mode in\r
+  //   $p_mode ("tar" or "tgz").\r
+  //   $p_add_dir and $p_remove_dir give you the ability to store a path\r
+  //   which is not the real path of the files.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_filelist : An array containing file or directory names, or\r
+  //                 a string containing one filename or directory name, or\r
+  //                 a string containing a list of filenames and/or directory\r
+  //                 names separated by spaces.\r
+  //   $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive,\r
+  //             if $p_mode is not specified, it will be determined by the extension.\r
+  //   $p_add_dir : Path to add in the filename path archived\r
+  //   $p_remove_dir : Path to remove in the filename path archived\r
+  // Return Values :\r
+  //   1 on success, or an error code (see table at the beginning).\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarCreate($p_tarname, $p_filelist="", $p_mode="", $p_add_dir="", $p_remove_dir="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarCreate", "tar=$p_tarname, file='$p_filelist', mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+    $v_result=1;\r
+\r
+    // ----- Look for default mode\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      // ----- Extract the tar format from the extension\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Trace\r
+      TrFctMessage(__FILE__, __LINE__, 1, "Auto mode selected : found $p_mode");\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist))\r
+    {\r
+      // ----- Call the create fct\r
+      $v_result = PclTarHandleCreate($p_tarname, $p_filelist, $p_mode, $p_add_dir, $p_remove_dir);\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist))\r
+    {\r
+      // ----- Create a list with the elements from the string\r
+      $v_list = explode(" ", $p_filelist);\r
+\r
+      // ----- Call the create fct\r
+      $v_result = PclTarHandleCreate($p_tarname, $v_list, $p_mode, $p_add_dir, $p_remove_dir);\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type p_filelist");\r
+      $v_result = -3;\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarAdd()\r
+  // Description :\r
+  //   PLEASE DO NOT USE ANY MORE THIS FUNCTION. Use PclTarAddList().\r
+  //\r
+  //   This function is maintained only for compatibility reason\r
+  //\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_filelist : An array containing file or directory names, or\r
+  //                 a string containing one filename or directory name, or\r
+  //                 a string containing a list of filenames and/or directory\r
+  //                 names separated by spaces.\r
+  // Return Values :\r
+  //   1 on success,\r
+  //   Or an error code (see list on top).\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarAdd($p_tarname, $p_filelist)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarAdd", "tar=$p_tarname, file=$p_filelist");\r
+    $v_result=1;\r
+    $v_list_detail = array();\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+    {\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist))\r
+    {\r
+      // ----- Call the add fct\r
+      $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $v_list_detail, "", "");\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist))\r
+    {\r
+      // ----- Create a list with the elements from the string\r
+      $v_list = explode(" ", $p_filelist);\r
+\r
+      // ----- Call the add fct\r
+      $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $v_list_detail, "", "");\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type p_filelist");\r
+      $v_result = -3;\r
+    }\r
+\r
+    // ----- Cleaning\r
+    unset($v_list_detail);\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarAddList()\r
+  // Description :\r
+  //   Add a list of files or directories ($p_filelist) in the tar archive $p_tarname.\r
+  //   The list can be an array of file/directory names or a string with names\r
+  //   separated by one space.\r
+  //   $p_add_dir and $p_remove_dir will give the ability to memorize a path which is\r
+  //   different from the real path of the file. This is usefull if you want to have PclTar\r
+  //   running in any directory, and memorize relative path from an other directory.\r
+  //   If $p_mode is not set it will be automatically computed from the $p_tarname\r
+  //   extension (.tar, .tar.gz or .tgz).\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_filelist : An array containing file or directory names, or\r
+  //                 a string containing one filename or directory name, or\r
+  //                 a string containing a list of filenames and/or directory\r
+  //                 names separated by spaces.\r
+  //   $p_add_dir : Path to add in the filename path archived\r
+  //   $p_remove_dir : Path to remove in the filename path archived\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //   1 on success,\r
+  //   Or an error code (see list on top).\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarAddList($p_tarname, $p_filelist, $p_add_dir="", $p_remove_dir="", $p_mode="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarAddList", "tar=$p_tarname, file=$p_filelist, p_add_dir='$p_add_dir', p_remove_dir='$p_remove_dir', mode=$p_mode");\r
+    $v_result=1;\r
+    $p_list_detail = array();\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist))\r
+    {\r
+      // ----- Call the add fct\r
+      $v_result = PclTarHandleAppend($p_tarname, $p_filelist, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist))\r
+    {\r
+      // ----- Create a list with the elements from the string\r
+      $v_list = explode(" ", $p_filelist);\r
+\r
+      // ----- Call the add fct\r
+      $v_result = PclTarHandleAppend($p_tarname, $v_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type p_filelist");\r
+      $v_result = -3;\r
+    }\r
+\r
+    // ----- Return\r
+    if ($v_result != 1)\r
+    {\r
+      TrFctEnd(__FILE__, __LINE__, 0);\r
+      return 0;\r
+    }\r
+    TrFctEnd(__FILE__, __LINE__, $p_list_detail);\r
+    return $p_list_detail;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarList()\r
+  // Description :\r
+  //   Gives the list of all the files present in the tar archive $p_tarname.\r
+  //   The list is the function result, it will be 0 on error.\r
+  //   Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the\r
+  //   function will determine the type of the archive.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //  0 on error (Use PclErrorCode() and PclErrorString() for more info)\r
+  //  or\r
+  //  An array containing file properties. Each file properties is an array of\r
+  //  properties.\r
+  //  The properties (array field names) are :\r
+  //    filename, size, mode, uid, gid, mtime, typeflag, status\r
+  //  Exemple : $v_list = PclTarList("my.tar");\r
+  //            for ($i=0; $i<sizeof($v_list); $i++)\r
+  //              echo "Filename :'".$v_list[$i][filename]."'<br>";\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarList($p_tarname, $p_mode="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarList", "tar=$p_tarname, mode='$p_mode'");\r
+    $v_result=1;\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Call the extracting fct\r
+    $p_list = array();\r
+    if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "list", "", $p_mode, "")) != 1)\r
+    {\r
+      unset($p_list);\r
+      TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+      return(0);\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarExtract()\r
+  // Description :\r
+  //   Extract all the files present in the archive $p_tarname, in the directory\r
+  //   $p_path. The relative path of the archived files are keep and become\r
+  //   relative to $p_path.\r
+  //   If a file with the same name already exists it will be replaced.\r
+  //   If the path to the file does not exist, it will be created.\r
+  //   Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the\r
+  //   function will determine the type of the archive.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file.\r
+  //   $p_path : Path where the files will be extracted. The files will use\r
+  //             their memorized path from $p_path.\r
+  //             If $p_path is "", files will be extracted in "./".\r
+  //   $p_remove_path : Path to remove (from the file memorized path) while writing the\r
+  //                    extracted files. If the path does not match the file path,\r
+  //                    the file is extracted with its memorized path.\r
+  //                    $p_path and $p_remove_path are commulative.\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //   Same as PclTarList()\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarExtract($p_tarname, $p_path="./", $p_remove_path="", $p_mode="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarExtract", "tar='$p_tarname', path='$p_path', remove_path='$p_remove_path', mode='$p_mode'");\r
+    $v_result=1;\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Call the extracting fct\r
+    if (($v_result = PclTarHandleExtract($p_tarname, 0, $p_list, "complete", $p_path, $v_tar_mode, $p_remove_path)) != 1)\r
+    {\r
+      TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+      return(0);\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarExtractList()\r
+  // Description :\r
+  //   Extract the files present in the archive $p_tarname and specified in\r
+  //   $p_filelist, in the directory\r
+  //   $p_path. The relative path of the archived files are keep and become\r
+  //   relative to $p_path.\r
+  //   If a directory is sp�cified in the list, all the files from this directory\r
+  //   will be extracted.\r
+  //   If a file with the same name already exists it will be replaced.\r
+  //   If the path to the file does not exist, it will be created.\r
+  //   Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the\r
+  //   function will determine the type of the archive.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_filelist : An array containing file or directory names, or\r
+  //                 a string containing one filename or directory name, or\r
+  //                 a string containing a list of filenames and/or directory\r
+  //                 names separated by spaces.\r
+  //   $p_path : Path where the files will be extracted. The files will use\r
+  //             their memorized path from $p_path.\r
+  //             If $p_path is "", files will be extracted in "./".\r
+  //   $p_remove_path : Path to remove (from the file memorized path) while writing the\r
+  //                    extracted files. If the path does not match the file path,\r
+  //                    the file is extracted with its memorized path.\r
+  //                    $p_path and $p_remove_path are commulative.\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //   Same as PclTarList()\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarExtractList($p_tarname, $p_filelist, $p_path="./", $p_remove_path="", $p_mode="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarExtractList", "tar=$p_tarname, list, path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");\r
+    $v_result=1;\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist))\r
+    {\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleExtract($p_tarname, $p_filelist, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist))\r
+    {\r
+      // ----- Create a list with the elements from the string\r
+      $v_list = explode(" ", $p_filelist);\r
+\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleExtract($p_tarname, $v_list, $p_list, "partial", $p_path, $v_tar_mode, $p_remove_path)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type p_filelist");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return 0;\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarExtractIndex()\r
+  // Description :\r
+  //   Extract the files present in the archive $p_tarname and specified at\r
+  //   the indexes in $p_index, in the directory\r
+  //   $p_path. The relative path of the archived files are keep and become\r
+  //   relative to $p_path.\r
+  //   If a directory is specified in the list, the directory only is created. All\r
+  //   the file stored in this archive for this directory\r
+  //   are not extracted.\r
+  //   If a file with the same name already exists it will be replaced.\r
+  //   If the path to the file does not exist, it will be created.\r
+  //   Depending on the $p_tarname extension (.tar, .tar.gz or .tgz) the\r
+  //   function will determine the type of the archive.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_index : A single index (integer) or a string of indexes of files to\r
+  //              extract. The form of the string is "0,4-6,8-12" with only numbers\r
+  //              and '-' for range or ',' to separate ranges. No spaces or ';'\r
+  //              are allowed.\r
+  //   $p_path : Path where the files will be extracted. The files will use\r
+  //             their memorized path from $p_path.\r
+  //             If $p_path is "", files will be extracted in "./".\r
+  //   $p_remove_path : Path to remove (from the file memorized path) while writing the\r
+  //                    extracted files. If the path does not match the file path,\r
+  //                    the file is extracted with its memorized path.\r
+  //                    $p_path and $p_remove_path are commulative.\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //   Same as PclTarList()\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarExtractIndex($p_tarname, $p_index, $p_path="./", $p_remove_path="", $p_mode="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarExtractIndex", "tar=$p_tarname, index='$p_index', path=$p_path, remove_path='$p_remove_path', mode='$p_mode'");\r
+    $v_result=1;\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_index is really an integer\r
+    if (is_integer($p_index))\r
+    {\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleExtractByIndexList($p_tarname, "$p_index", $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_index))\r
+    {\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleExtractByIndexList($p_tarname, $p_index, $p_list, $p_path, $p_remove_path, $v_tar_mode)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type $p_index");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return 0;\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarDelete()\r
+  // Description :\r
+  //   This function deletes from the archive $p_tarname the files which are listed\r
+  //   in $p_filelist. $p_filelist can be a string with file names separated by\r
+  //   spaces, or an array containing the file names.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_filelist : An array or a string containing file names to remove from the\r
+  //                 archive.\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //   List of the files which are kept in the archive (same format as PclTarList())\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarDelete($p_tarname, $p_filelist, $p_mode="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarDelete", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");\r
+    $v_result=1;\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist))\r
+    {\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleDelete($p_tarname, $p_filelist, $p_list, $p_mode)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist))\r
+    {\r
+      // ----- Create a list with the elements from the string\r
+      $v_list = explode(" ", $p_filelist);\r
+\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleDelete($p_tarname, $v_list, $p_list, $p_mode)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type p_filelist");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return 0;\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarUpdate()\r
+  // Description :\r
+  //   This function updates the files in $p_filelist which are already in the\r
+  //   $p_tarname archive with an older last modified date. If the file does not\r
+  //   exist, it is added at the end of the archive.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_filelist : An array or a string containing file names to update from the\r
+  //                 archive.\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  // Return Values :\r
+  //   List of the files contained in the archive. The field status contains\r
+  //   "updated", "not_updated", "added" or "ok" for the files not concerned.\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarUpdate($p_tarname, $p_filelist, $p_mode="", $p_add_dir="", $p_remove_dir="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarUpdate", "tar='$p_tarname', list='$p_filelist', mode='$p_mode'");\r
+    $v_result=1;\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is really an array\r
+    if (is_array($p_filelist))\r
+    {\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleUpdate($p_tarname, $p_filelist, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Look if the $p_filelist is a string\r
+    else if (is_string($p_filelist))\r
+    {\r
+      // ----- Create a list with the elements from the string\r
+      $v_list = explode(" ", $p_filelist);\r
+\r
+      // ----- Call the extracting fct\r
+      if (($v_result = PclTarHandleUpdate($p_tarname, $v_list, $p_list, $p_mode, $p_add_dir, $p_remove_dir)) != 1)\r
+      {\r
+        TrFctEnd(__FILE__, __LINE__, 0, PclErrorString());\r
+        return(0);\r
+      }\r
+    }\r
+\r
+    // ----- Invalid variable\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid variable type p_filelist");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return 0;\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $p_list);\r
+    return $p_list;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarMerge()\r
+  // Description :\r
+  //   This function add the content of $p_tarname_add at the end of $p_tarname.\r
+  // Parameters :\r
+  //   $p_tarname : Name of an existing tar file\r
+  //   $p_tarname_add : Name of an existing tar file taht will be added at the end\r
+  //                    of $p_tarname.\r
+  //   $p_mode : 'tar' or 'tgz', if not set, will be determined by $p_tarname extension\r
+  //   $p_mode_add : 'tar' or 'tgz', if not set, will be determined by $p_tarname_add\r
+  //                 extension\r
+  // Return Values :\r
+  //   List of the files contained in the archive. The field status contains\r
+  //   "updated", "not_updated", "added" or "ok" for the files not concerned.\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarMerge($p_tarname, $p_tarname_add, $p_mode="", $p_mode_add="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarMerge", "tar='$p_tarname', tar_add='$p_tarname_add', mode='$p_mode', mode_add='$p_mode_add'");\r
+    $v_result=1;\r
+\r
+    // ----- Check the parameters\r
+    if (($p_tarname == "") || ($p_tarname_add == ""))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid empty archive name");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Extract the tar format from the extension\r
+    if (($p_mode == "") || (($p_mode!="tar") && ($p_mode!="tgz")))\r
+    {\r
+      if (($p_mode = PclTarHandleExtension($p_tarname)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+    if (($p_mode_add == "") || (($p_mode_add!="tar") && ($p_mode_add!="tgz")))\r
+    {\r
+      if (($p_mode_add = PclTarHandleExtension($p_tarname_add)) == "")\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return 0;\r
+      }\r
+    }\r
+\r
+    // ----- Clear filecache\r
+    clearstatcache();\r
+\r
+    // ----- Check the file size\r
+    if ((!is_file($p_tarname)) ||\r
+        (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))\r
+    {\r
+      // ----- Error log\r
+      if (!is_file($p_tarname))\r
+        PclErrorLog(-4, "Archive '$p_tarname' does not exist");\r
+      else\r
+        PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+    if ((!is_file($p_tarname_add)) ||\r
+        (((($v_size_add = filesize($p_tarname_add)) % 512) != 0) && ($p_mode_add=="tar")))\r
+    {\r
+      // ----- Error log\r
+      if (!is_file($p_tarname_add))\r
+        PclErrorLog(-4, "Archive '$p_tarname_add' does not exist");\r
+      else\r
+        PclErrorLog(-6, "Archive '$p_tarname_add' has invalid size ".filesize($p_tarname_add)."(not a 512 block multiple)");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Look for compressed archive\r
+    if ($p_mode == "tgz")\r
+    {\r
+      // ----- Open the file in read mode\r
+      if (($p_tar = @gzopen($p_tarname, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Open a temporary file in write mode\r
+      $v_temp_tarname = uniqid("pcltar-").".tmp";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");\r
+      if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Close tar file\r
+        gzclose($p_tar);\r
+\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Read the first 512 bytes block\r
+      $v_buffer = gzread($p_tar, 512);\r
+\r
+      // ----- Read the following blocks but not the last one\r
+      if (!gzeof($p_tar))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");\r
+        $i=1;\r
+\r
+        // ----- Read new 512 block and write the already read\r
+        do{\r
+          // ----- Write the already read block\r
+          $v_binary_data = pack("a512", "$v_buffer");\r
+          gzputs($v_temp_tar, $v_binary_data);\r
+\r
+          $i++;\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");\r
+\r
+          // ----- Read next block\r
+          $v_buffer = gzread($p_tar, 512);\r
+\r
+        } while (!gzeof($p_tar));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");\r
+      }\r
+    }\r
+\r
+    // ----- Look for uncompressed tar file\r
+    else if ($p_mode=="tar")\r
+    {\r
+      // ----- Open the tar file\r
+      if (($p_tar = fopen($p_tarname, "r+b")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Go to the beginning of last block\r
+      TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+      fseek($p_tar, $v_size-512);\r
+      TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+    }\r
+\r
+    // ----- Look for unknown type\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid tar mode $p_mode");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Look for type of archive to add\r
+    if ($p_mode_add == "tgz")\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 4, "Opening file $p_tarname_add");\r
+\r
+      // ----- Open the file in read mode\r
+      if (($p_tar_add = @gzopen($p_tarname_add, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Read the first 512 bytes block\r
+      $v_buffer = gzread($p_tar_add, 512);\r
+\r
+      // ----- Read the following blocks but not the last one\r
+      if (!gzeof($p_tar_add))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");\r
+        $i=1;\r
+\r
+        // ----- Read new 512 block and write the already read\r
+        do{\r
+          // ----- Write the already read block\r
+          $v_binary_data = pack("a512", "$v_buffer");\r
+          if ($p_mode=="tar")\r
+            fputs($p_tar, $v_binary_data);\r
+          else\r
+            gzputs($v_temp_tar, $v_binary_data);\r
+\r
+          $i++;\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");\r
+\r
+          // ----- Read next block\r
+          $v_buffer = gzread($p_tar_add, 512);\r
+\r
+        } while (!gzeof($p_tar_add));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");\r
+      }\r
+\r
+      // ----- Close the files\r
+      gzclose($p_tar_add);\r
+    }\r
+\r
+    // ----- Look for uncompressed tar file\r
+    else if ($p_mode=="tar")\r
+    {\r
+      // ----- Open the file in read mode\r
+      if (($p_tar_add = @fopen($p_tarname_add, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname_add' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Read the first 512 bytes block\r
+      $v_buffer = fread($p_tar_add, 512);\r
+\r
+      // ----- Read the following blocks but not the last one\r
+      if (!feof($p_tar_add))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");\r
+        $i=1;\r
+\r
+        // ----- Read new 512 block and write the already read\r
+        do{\r
+          // ----- Write the already read block\r
+          $v_binary_data = pack("a512", "$v_buffer");\r
+          if ($p_mode=="tar")\r
+            fputs($p_tar, $v_binary_data);\r
+          else\r
+            gzputs($v_temp_tar, $v_binary_data);\r
+\r
+          $i++;\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");\r
+\r
+          // ----- Read next block\r
+          $v_buffer = fread($p_tar_add, 512);\r
+\r
+        } while (!feof($p_tar_add));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");\r
+      }\r
+\r
+      // ----- Close the files\r
+      fclose($p_tar_add);\r
+    }\r
+\r
+    // ----- Call the footer of the tar archive\r
+    $v_result = PclTarHandleFooter($p_tar, $p_mode);\r
+\r
+    // ----- Look for closing compressed archive\r
+    if ($p_mode == "tgz")\r
+    {\r
+      // ----- Close the files\r
+      gzclose($p_tar);\r
+      gzclose($v_temp_tar);\r
+\r
+      // ----- Unlink tar file\r
+      if (!@unlink($p_tarname))\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-11, "Error while deleting archive name $p_tarname");\r
+      }\r
+\r
+      // ----- Rename tar file\r
+      if (!@rename($v_temp_tarname, $p_tarname))\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Look for closing uncompressed tar file\r
+    else if ($p_mode=="tar")\r
+    {\r
+      // ----- Close the tarfile\r
+      fclose($p_tar);\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+// --------------------------------------------------------------------------------\r
+// ***** UNDER THIS LINE ARE DEFINED PRIVATE INTERNAL FUNCTIONS *****\r
+// *****                                                        *****\r
+// *****       THESES FUNCTIONS MUST NOT BE USED DIRECTLY       *****\r
+// --------------------------------------------------------------------------------\r
+\r
+\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleCreate()\r
+  // Description :\r
+  // Parameters :\r
+  //   $p_tarname : Name of the tar file\r
+  //   $p_list : An array containing the file or directory names to add in the tar\r
+  //   $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleCreate($p_tarname, $p_list, $p_mode, $p_add_dir="", $p_remove_dir="")\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleCreate", "tar=$p_tarname, list, mode=$p_mode, add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+    $v_result=1;\r
+    $v_list_detail = array();\r
+\r
+    // ----- Check the parameters\r
+    if (($p_tarname == "") || (($p_mode != "tar") && ($p_mode != "tgz")))\r
+    {\r
+      // ----- Error log\r
+      if ($p_tarname == "")\r
+        PclErrorLog(-3, "Invalid empty archive name");\r
+      else\r
+        PclErrorLog(-3, "Unknown mode '$p_mode'");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Look for tar file\r
+    if ($p_mode == "tar")\r
+    {\r
+      // ----- Open the tar file\r
+      if (($p_tar = fopen($p_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Call the adding fct inside the tar\r
+      if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)\r
+      {\r
+        // ----- Call the footer of the tar archive\r
+        $v_result = PclTarHandleFooter($p_tar, $p_mode);\r
+      }\r
+\r
+      // ----- Close the tarfile\r
+      fclose($p_tar);\r
+    }\r
+    // ----- Look for tgz file\r
+    else\r
+    {\r
+      // ----- Open the tar file\r
+      if (($p_tar = @gzopen($p_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file [$p_tarname] in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Call the adding fct inside the tar\r
+      if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $v_list_detail, $p_add_dir, $p_remove_dir)) == 1)\r
+      {\r
+        // ----- Call the footer of the tar archive\r
+        $v_result = PclTarHandleFooter($p_tar, $p_mode);\r
+      }\r
+\r
+      // ----- Close the tarfile\r
+      gzclose($p_tar);\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleAppend()\r
+  // Description :\r
+  // Parameters :\r
+  //   $p_tarname : Name of the tar file\r
+  //   $p_list : An array containing the file or directory names to add in the tar\r
+  //   $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleAppend($p_tarname, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleAppend", "tar=$p_tarname, list, mode=$p_mode");\r
+    $v_result=1;\r
+\r
+    // ----- Check the parameters\r
+    if ($p_tarname == "")\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid empty archive name");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    clearstatcache();\r
+\r
+    // ----- Check the file size\r
+    if ((!is_file($p_tarname)) ||\r
+        (((($v_size = filesize($p_tarname)) % 512) != 0) && ($p_mode=="tar")))\r
+    {\r
+      // ----- Error log\r
+      if (!is_file($p_tarname))\r
+        PclErrorLog(-4, "Archive '$p_tarname' does not exist");\r
+      else\r
+        PclErrorLog(-6, "Archive '$p_tarname' has invalid size ".filesize($p_tarname)."(not a 512 block multiple)");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Look for compressed archive\r
+    if ($p_mode == "tgz")\r
+    {\r
+      // ----- Open the file in read mode\r
+      if (($p_tar = @gzopen($p_tarname, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Open a temporary file in write mode\r
+      $v_temp_tarname = uniqid("pcltar-").".tmp";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");\r
+      if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Close tar file\r
+        gzclose($p_tar);\r
+\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Read the first 512 bytes block\r
+      $v_buffer = gzread($p_tar, 512);\r
+\r
+      // ----- Read the following blocks but not the last one\r
+      if (!gzeof($p_tar))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "More than one 512 block file");\r
+        $i=1;\r
+\r
+        // ----- Read new 512 block and write the already read\r
+        do{\r
+          // ----- Write the already read block\r
+          $v_binary_data = pack("a512", "$v_buffer");\r
+          gzputs($v_temp_tar, $v_binary_data);\r
+\r
+          $i++;\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Reading block $i");\r
+\r
+          // ----- Read next block\r
+          $v_buffer = gzread($p_tar, 512);\r
+\r
+        } while (!gzeof($p_tar));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 3, "$i 512 bytes blocks");\r
+      }\r
+\r
+      // ----- Call the adding fct inside the tar\r
+      if (($v_result = PclTarHandleAddList($v_temp_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)\r
+      {\r
+        // ----- Call the footer of the tar archive\r
+        $v_result = PclTarHandleFooter($v_temp_tar, $p_mode);\r
+      }\r
+\r
+      // ----- Close the files\r
+      gzclose($p_tar);\r
+      gzclose($v_temp_tar);\r
+\r
+      // ----- Unlink tar file\r
+      if (!@unlink($p_tarname))\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-11, "Error while deleting archive name $p_tarname");\r
+      }\r
+\r
+      // ----- Rename tar file\r
+      if (!@rename($v_temp_tarname, $p_tarname))\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, $v_result);\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Look for uncompressed tar file\r
+    else if ($p_mode=="tar")\r
+    {\r
+      // ----- Open the tar file\r
+      if (($p_tar = fopen($p_tarname, "r+b")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$p_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Go to the beginning of last block\r
+      TrFctMessage(__FILE__, __LINE__, 4, "Position before :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+      fseek($p_tar, $v_size-512);\r
+      TrFctMessage(__FILE__, __LINE__, 4, "Position after :".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+\r
+      // ----- Call the adding fct inside the tar\r
+      if (($v_result = PclTarHandleAddList($p_tar, $p_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir)) == 1)\r
+      {\r
+        // ----- Call the footer of the tar archive\r
+        $v_result = PclTarHandleFooter($p_tar, $p_mode);\r
+      }\r
+\r
+      // ----- Close the tarfile\r
+      fclose($p_tar);\r
+    }\r
+\r
+    // ----- Look for unknown type\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid tar mode $p_mode");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleAddList()\r
+  // Description :\r
+  //   $p_add_dir and $p_remove_dir will give the ability to memorize a path which is\r
+  //   different from the real path of the file. This is usefull if you want to have PclTar\r
+  //   running in any directory, and memorize relative path from an other directory.\r
+  // Parameters :\r
+  //   $p_tar : File descriptor of the tar archive\r
+  //   $p_list : An array containing the file or directory names to add in the tar\r
+  //   $p_mode : "tar" for normal tar archive, "tgz" for gzipped tar archive\r
+  //   $p_list_detail : list of added files with their properties (specially the status field)\r
+  //   $p_add_dir : Path to add in the filename path archived\r
+  //   $p_remove_dir : Path to remove in the filename path archived\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleAddList($p_tar, $p_list, $p_mode, &$p_list_detail, $p_add_dir, $p_remove_dir)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleAddList", "tar='$p_tar', list, mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+    $v_result=1;\r
+    $v_header = array();\r
+\r
+    // ----- Recuperate the current number of elt in list\r
+    $v_nb = sizeof($p_list_detail);\r
+\r
+    // ----- Check the parameters\r
+    if ($p_tar == 0)\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Check the arguments\r
+    if (sizeof($p_list) == 0)\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Loop on the files\r
+    for ($j=0; ($j<count($p_list)) && ($v_result==1); $j++)\r
+    {\r
+      // ----- Recuperate the filename\r
+      $p_filename = $p_list[$j];\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Looking for file [$p_filename]");\r
+\r
+      // ----- Skip empty file names\r
+      if ($p_filename == "")\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Skip empty filename");\r
+        continue;\r
+      }\r
+\r
+      // ----- Check the filename\r
+      if (!file_exists($p_filename))\r
+      {\r
+        // ----- Error log\r
+        TrFctMessage(__FILE__, __LINE__, 2, "File '$p_filename' does not exists");\r
+        PclErrorLog(-4, "File '$p_filename' does not exists");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Check the path length\r
+      if (strlen($p_filename) > 99)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-5, "File name is too long (max. 99) : '$p_filename'");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 4, "File position before header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+\r
+      // ----- Add the file\r
+      if (($v_result = PclTarHandleAddFile($p_tar, $p_filename, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)\r
+      {\r
+        // ----- Return status\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Store the file infos\r
+      $p_list_detail[$v_nb++] = $v_header;\r
+\r
+      // ----- Look for directory\r
+      if (is_dir($p_filename))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "$p_filename is a directory");\r
+\r
+        // ----- Look for path\r
+        if ($p_filename != ".")\r
+          $v_path = $p_filename."/";\r
+        else\r
+          $v_path = "";\r
+\r
+        // ----- Read the directory for files and sub-directories\r
+        $p_hdir = opendir($p_filename);\r
+        $p_hitem = readdir($p_hdir); // '.' directory\r
+        $p_hitem = readdir($p_hdir); // '..' directory\r
+        while ($p_hitem = readdir($p_hdir))\r
+        {\r
+          // ----- Look for a file\r
+          if (is_file($v_path.$p_hitem))\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 4, "Add the file '".$v_path.$p_hitem."'");\r
+\r
+            // ----- Add the file\r
+            if (($v_result = PclTarHandleAddFile($p_tar, $v_path.$p_hitem, $p_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)\r
+            {\r
+              // ----- Return status\r
+              TrFctEnd(__FILE__, __LINE__, $v_result);\r
+              return $v_result;\r
+            }\r
+\r
+            // ----- Store the file infos\r
+            $p_list_detail[$v_nb++] = $v_header;\r
+          }\r
+\r
+          // ----- Recursive call to PclTarHandleAddFile()\r
+          else\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 4, "'".$v_path.$p_hitem."' is a directory");\r
+\r
+            // ----- Need an array as parameter\r
+            $p_temp_list[0] = $v_path.$p_hitem;\r
+            $v_result = PclTarHandleAddList($p_tar, $p_temp_list, $p_mode, $p_list_detail, $p_add_dir, $p_remove_dir);\r
+          }\r
+        }\r
+\r
+        // ----- Free memory for the recursive loop\r
+        unset($p_temp_list);\r
+        unset($p_hdir);\r
+        unset($p_hitem);\r
+      }\r
+      else\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleAddFile()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleAddFile($p_tar, $p_filename, $p_mode, &$p_header, $p_add_dir, $p_remove_dir)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleAddFile", "tar='$p_tar', filename='$p_filename', p_mode='$p_mode', add_dir='$p_add_dir', remove_dir='$p_remove_dir'");\r
+    $v_result=1;\r
+\r
+    // ----- Check the parameters\r
+    if ($p_tar == 0)\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Skip empty file names\r
+    if ($p_filename == "")\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid file list parameter (invalid or empty list)");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Calculate the stored filename\r
+    $v_stored_filename = $p_filename;\r
+    if ($p_remove_dir != "")\r
+    {\r
+      if (substr($p_remove_dir, -1) != '/')\r
+        $p_remove_dir .= "/";\r
+\r
+      if ((substr($p_filename, 0, 2) == "./") || (substr($p_remove_dir, 0, 2) == "./"))\r
+      {\r
+        if ((substr($p_filename, 0, 2) == "./") && (substr($p_remove_dir, 0, 2) != "./"))\r
+          $p_remove_dir = "./".$p_remove_dir;\r
+        if ((substr($p_filename, 0, 2) != "./") && (substr($p_remove_dir, 0, 2) == "./"))\r
+          $p_remove_dir = substr($p_remove_dir, 2);\r
+      }\r
+\r
+      if (substr($p_filename, 0, strlen($p_remove_dir)) == $p_remove_dir)\r
+      {\r
+        $v_stored_filename = substr($p_filename, strlen($p_remove_dir));\r
+        TrFctMessage(__FILE__, __LINE__, 3, "Remove path '$p_remove_dir' in file '$p_filename' = '$v_stored_filename'");\r
+      }\r
+    }\r
+    if ($p_add_dir != "")\r
+    {\r
+      if (substr($p_add_dir, -1) == "/")\r
+        $v_stored_filename = $p_add_dir.$v_stored_filename;\r
+      else\r
+        $v_stored_filename = $p_add_dir."/".$v_stored_filename;\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_filename' = '$v_stored_filename'");\r
+    }\r
+\r
+    // ----- Check the path length\r
+    if (strlen($v_stored_filename) > 99)\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-5, "Stored file name is too long (max. 99) : '$v_stored_filename'");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Look for a file\r
+    if (is_file($p_filename))\r
+    {\r
+      // ----- Open the source file\r
+      if (($v_file = fopen($p_filename, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_filename' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Call the header generation\r
+      if (($v_result = PclTarHandleHeader($p_tar, $p_filename, $p_mode, $p_header, $v_stored_filename)) != 1)\r
+      {\r
+        // ----- Return status\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 4, "File position after header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+\r
+      // ----- Read the file by 512 octets blocks\r
+      $i=0;\r
+      while (($v_buffer = fread($v_file, 512)) != "")\r
+      {\r
+        $v_binary_data = pack("a512", "$v_buffer");\r
+        if ($p_mode == "tar")\r
+          fputs($p_tar, $v_binary_data);\r
+        else\r
+          gzputs($p_tar, $v_binary_data);\r
+        $i++;\r
+      }\r
+      TrFctMessage(__FILE__, __LINE__, 2, "$i 512 bytes blocks");\r
+\r
+      // ----- Close the file\r
+      fclose($v_file);\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 4, "File position after blocks =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+    }\r
+\r
+    // ----- Look for a directory\r
+    else\r
+    {\r
+      // ----- Call the header generation\r
+      if (($v_result = PclTarHandleHeader($p_tar, $p_filename, $p_mode, $p_header, $v_stored_filename)) != 1)\r
+      {\r
+        // ----- Return status\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 4, "File position after header =".($p_mode=="tar"?ftell($p_tar):gztell($p_tar)));\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleHeader()\r
+  // Description :\r
+  //   This function creates in the TAR $p_tar, the TAR header for the file\r
+  //   $p_filename.\r
+  //\r
+  //   1. The informations needed to compose the header are recuperated and formatted\r
+  //   2. Two binary strings are composed for the first part of the header, before\r
+  //      and after checksum field.\r
+  //   3. The checksum is calculated from the two binary strings\r
+  //   4. The header is write in the tar file (first binary string, binary string\r
+  //      for checksum and last binary string).\r
+  // Parameters :\r
+  //   $p_tar : a valid file descriptor, opened in write mode,\r
+  //   $p_filename : The name of the file the header is for,\r
+  //   $p_mode : The mode of the archive ("tar" or "tgz").\r
+  //   $p_header : A pointer to a array where will be set the file properties\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleHeader($p_tar, $p_filename, $p_mode, &$p_header, $p_stored_filename)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleHeader", "tar=$p_tar, file='$p_filename', mode='$p_mode', stored_filename='$p_stored_filename'");\r
+    $v_result=1;\r
+\r
+    // ----- Check the parameters\r
+    if (($p_tar == 0) || ($p_filename == ""))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-3, "Invalid file descriptor in file ".__FILE__.", line ".__LINE__);\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Filename (reduce the path of stored name)\r
+    if ($p_stored_filename == "")\r
+      $p_stored_filename = $p_filename;\r
+    $v_reduce_filename = PclTarHandlePathReduction($p_stored_filename);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Filename (reduced) '$v_reduce_filename', strlen ".strlen($v_reduce_filename));\r
+\r
+    // ----- Get file info\r
+    $v_info = stat($p_filename);\r
+    $v_uid = sprintf("%6s ", DecOct($v_info[4]));\r
+    $v_gid = sprintf("%6s ", DecOct($v_info[5]));\r
+    TrFctMessage(__FILE__, __LINE__, 3, "uid=$v_uid, gid=$v_gid");\r
+    $v_perms = sprintf("%6s ", DecOct(fileperms($p_filename)));\r
+    TrFctMessage(__FILE__, __LINE__, 3, "file permissions $v_perms");\r
+\r
+    // ----- File mtime\r
+    $v_mtime_data = filemtime($p_filename);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "File mtime : $v_mtime_data");\r
+    $v_mtime = sprintf("%11s", DecOct($v_mtime_data));\r
+\r
+    // ----- File typeflag\r
+    // '0' or '\0' is the code for regular file\r
+    // '5' is directory\r
+    if (is_dir($p_filename))\r
+    {\r
+      $v_typeflag = "5";\r
+      $v_size = 0;\r
+    }\r
+    else\r
+    {\r
+      $v_typeflag = "";\r
+\r
+      // ----- Get the file size\r
+      clearstatcache();\r
+      $v_size = filesize($p_filename);\r
+    }\r
+\r
+    TrFctMessage(__FILE__, __LINE__, 2, "File size : $v_size");\r
+    $v_size = sprintf("%11s ", DecOct($v_size));\r
+\r
+    TrFctMessage(__FILE__, __LINE__, 2, "File typeflag : $v_typeflag");\r
+\r
+    // ----- Linkname\r
+    $v_linkname = "";\r
+\r
+    // ----- Magic\r
+    $v_magic = "";\r
+\r
+    // ----- Version\r
+    $v_version = "";\r
+\r
+    // ----- uname\r
+    $v_uname = "";\r
+\r
+    // ----- gname\r
+    $v_gname = "";\r
+\r
+    // ----- devmajor\r
+    $v_devmajor = "";\r
+\r
+    // ----- devminor\r
+    $v_devminor = "";\r
+\r
+    // ----- prefix\r
+    $v_prefix = "";\r
+\r
+    // ----- Compose the binary string of the header in two parts arround the checksum position\r
+    $v_binary_data_first = pack("a100a8a8a8a12A12", $v_reduce_filename, $v_perms, $v_uid, $v_gid, $v_size, $v_mtime);\r
+    $v_binary_data_last = pack("a1a100a6a2a32a32a8a8a155a12", $v_typeflag, $v_linkname, $v_magic, $v_version, $v_uname, $v_gname, $v_devmajor, $v_devminor, $v_prefix, "");\r
+\r
+    // ----- Calculate the checksum\r
+    $v_checksum = 0;\r
+    // ..... First part of the header\r
+    for ($i=0; $i<148; $i++)\r
+    {\r
+      $v_checksum += ord(substr($v_binary_data_first,$i,1));\r
+    }\r
+    // ..... Ignore the checksum value and replace it by ' ' (space)\r
+    for ($i=148; $i<156; $i++)\r
+    {\r
+      $v_checksum += ord(' ');\r
+    }\r
+    // ..... Last part of the header\r
+    for ($i=156, $j=0; $i<512; $i++, $j++)\r
+    {\r
+      $v_checksum += ord(substr($v_binary_data_last,$j,1));\r
+    }\r
+    TrFctMessage(__FILE__, __LINE__, 3, "Calculated checksum : $v_checksum");\r
+\r
+    // ----- Write the first 148 bytes of the header in the archive\r
+    if ($p_mode == "tar")\r
+      fputs($p_tar, $v_binary_data_first, 148);\r
+    else\r
+      gzputs($p_tar, $v_binary_data_first, 148);\r
+\r
+    // ----- Write the calculated checksum\r
+    $v_checksum = sprintf("%6s ", DecOct($v_checksum));\r
+    $v_binary_data = pack("a8", $v_checksum);\r
+    if ($p_mode == "tar")\r
+      fputs($p_tar, $v_binary_data, 8);\r
+    else\r
+      gzputs($p_tar, $v_binary_data, 8);\r
+\r
+    // ----- Write the last 356 bytes of the header in the archive\r
+    if ($p_mode == "tar")\r
+      fputs($p_tar, $v_binary_data_last, 356);\r
+    else\r
+      gzputs($p_tar, $v_binary_data_last, 356);\r
+\r
+    // ----- Set the properties in the header "structure"\r
+    $p_header[filename] = $v_reduce_filename;\r
+    $p_header[mode] = $v_perms;\r
+    $p_header[uid] = $v_uid;\r
+    $p_header[gid] = $v_gid;\r
+    $p_header[size] = $v_size;\r
+    $p_header[mtime] = $v_mtime;\r
+    $p_header[typeflag] = $v_typeflag;\r
+    $p_header[status] = "added";\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleFooter()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleFooter($p_tar, $p_mode)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleFooter", "tar='$p_tar', p_mode=$p_mode");\r
+    $v_result=1;\r
+\r
+    // ----- Write the last 0 filled block for end of archive\r
+    $v_binary_data = pack("a512", "");\r
+    if ($p_mode == "tar")\r
+      fputs($p_tar, $v_binary_data);\r
+    else\r
+      gzputs($p_tar, $v_binary_data);\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleExtract()\r
+  // Description :\r
+  // Parameters :\r
+  //   $p_tarname : Filename of the tar (or tgz) archive\r
+  //   $p_file_list : An array which contains the list of files to extract, this\r
+  //                  array may be empty when $p_mode is 'complete'\r
+  //   $p_list_detail : An array where will be placed the properties of  each extracted/listed file\r
+  //   $p_mode : 'complete' will extract all files from the archive,\r
+  //             'partial' will look for files in $p_file_list\r
+  //             'list' will only list the files from the archive without any extract\r
+  //   $p_path : Path to add while writing the extracted files\r
+  //   $p_tar_mode : 'tar' for GNU TAR archive, 'tgz' for compressed archive\r
+  //   $p_remove_path : Path to remove (from the file memorized path) while writing the\r
+  //                    extracted files. If the path does not match the file path,\r
+  //                    the file is extracted with its memorized path.\r
+  //                    $p_remove_path does not apply to 'list' mode.\r
+  //                    $p_path and $p_remove_path are commulative.\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleExtract($p_tarname, $p_file_list, &$p_list_detail, $p_mode, $p_path, $p_tar_mode, $p_remove_path)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleExtract", "archive='$p_tarname', list, mode=$p_mode, path=$p_path, tar_mode=$p_tar_mode, remove_path='$p_remove_path'");\r
+    $v_result=1;\r
+    $v_nb = 0;\r
+    $v_extract_all = TRUE;\r
+    $v_listing = FALSE;\r
+\r
+    // ----- Check the path\r
+    if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../")))\r
+      $p_path = "./".$p_path;\r
+\r
+    // ----- Look for path to remove format (should end by /)\r
+    if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))\r
+    {\r
+      $p_remove_path .= '/';\r
+    }\r
+    $p_remove_path_size = strlen($p_remove_path);\r
+\r
+    // ----- Study the mode\r
+    switch ($p_mode) {\r
+      case "complete" :\r
+        // ----- Flag extract of all files\r
+        $v_extract_all = TRUE;\r
+        $v_listing = FALSE;\r
+      break;\r
+      case "partial" :\r
+          // ----- Flag extract of specific files\r
+          $v_extract_all = FALSE;\r
+          $v_listing = FALSE;\r
+      break;\r
+      case "list" :\r
+          // ----- Flag list of all files\r
+          $v_extract_all = FALSE;\r
+          $v_listing = TRUE;\r
+      break;\r
+      default :\r
+        // ----- Error log\r
+        PclErrorLog(-3, "Invalid extract mode ($p_mode)");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+    }\r
+\r
+    // ----- Open the tar file\r
+    if ($p_tar_mode == "tar")\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+      $v_tar = fopen($p_tarname, "rb");\r
+    }\r
+    else\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");\r
+      $v_tar = @gzopen($p_tarname, "rb");\r
+    }\r
+\r
+    // ----- Check that the archive is open\r
+    if ($v_tar == 0)\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-2, "Unable to open archive '$p_tarname' in binary read mode");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Read the blocks\r
+    While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");\r
+\r
+      // ----- Clear cache of file infos\r
+      clearstatcache();\r
+\r
+      // ----- Reset extract tag\r
+      $v_extract_file = FALSE;\r
+      $v_extraction_stopped = 0;\r
+\r
+      // ----- Read the 512 bytes header\r
+      if ($p_tar_mode == "tar")\r
+        $v_binary_data = fread($v_tar, 512);\r
+      else\r
+        $v_binary_data = gzread($v_tar, 512);\r
+\r
+      // ----- Read the header properties\r
+      if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)\r
+      {\r
+        // ----- Close the archive file\r
+        if ($p_tar_mode == "tar")\r
+          fclose($v_tar);\r
+        else\r
+          gzclose($v_tar);\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Look for empty blocks to skip\r
+      if ($v_header[filename] == "")\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");\r
+        continue;\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");\r
+\r
+      // ----- Look for partial extract\r
+      if ((!$v_extract_all) && (is_array($p_file_list)))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Look if the file '$v_header[filename]' need to be extracted");\r
+\r
+        // ----- By default no unzip if the file is not found\r
+        $v_extract_file = FALSE;\r
+\r
+        // ----- Look into the file list\r
+        for ($i=0; $i<sizeof($p_file_list); $i++)\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Compare archived file '$v_header[filename]' from asked list file '".$p_file_list[$i]."'");\r
+\r
+          // ----- Look if it is a directory\r
+          if (substr($p_file_list[$i], -1) == "/")\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Compare file '$v_header[filename]' with directory '$p_file_list[$i]'");\r
+\r
+            // ----- Look if the directory is in the filename path\r
+            if ((strlen($v_header[filename]) > strlen($p_file_list[$i])) && (substr($v_header[filename], 0, strlen($p_file_list[$i])) == $p_file_list[$i]))\r
+            {\r
+              // ----- The file is in the directory, so extract it\r
+              TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in directory '$p_file_list[$i]' : extract it");\r
+              $v_extract_file = TRUE;\r
+\r
+              // ----- End of loop\r
+              break;\r
+            }\r
+          }\r
+\r
+          // ----- It is a file, so compare the file names\r
+          else if ($p_file_list[$i] == $v_header[filename])\r
+          {\r
+            // ----- File found\r
+            TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should be extracted");\r
+            $v_extract_file = TRUE;\r
+\r
+            // ----- End of loop\r
+            break;\r
+          }\r
+        }\r
+\r
+        // ----- Trace\r
+        if (!$v_extract_file)\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' should not be extracted");\r
+        }\r
+      }\r
+      else\r
+      {\r
+        // ----- All files need to be extracted\r
+        $v_extract_file = TRUE;\r
+      }\r
+\r
+      // ----- Look if this file need to be extracted\r
+      if (($v_extract_file) && (!$v_listing))\r
+      {\r
+        // ----- Look for path to remove\r
+        if (($p_remove_path != "")\r
+            && (substr($v_header[filename], 0, $p_remove_path_size) == $p_remove_path))\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '$v_header[filename]'");\r
+          // ----- Remove the path\r
+          $v_header[filename] = substr($v_header[filename], $p_remove_path_size);\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Reslting file is '$v_header[filename]'");\r
+        }\r
+\r
+        // ----- Add the path to the file\r
+        if (($p_path != "./") && ($p_path != "/"))\r
+        {\r
+          // ----- Look for the path end '/'\r
+          while (substr($p_path, -1) == "/")\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");\r
+            $p_path = substr($p_path, 0, strlen($p_path)-1);\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");\r
+          }\r
+\r
+          // ----- Add the path\r
+          if (substr($v_header[filename], 0, 1) == "/")\r
+              $v_header[filename] = $p_path.$v_header[filename];\r
+          else\r
+            $v_header[filename] = $p_path."/".$v_header[filename];\r
+        }\r
+\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '$v_header[filename]', size '$v_header[size]'");\r
+\r
+        // ----- Check that the file does not exists\r
+        if (file_exists($v_header[filename]))\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' already exists");\r
+\r
+          // ----- Look if file is a directory\r
+          if (is_dir($v_header[filename]))\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is a directory");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "already_a_directory";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+          // ----- Look if file is write protected\r
+          else if (!is_writeable($v_header[filename]))\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is write protected");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "write_protected";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+          // ----- Look if the extracted file is older\r
+          else if (filemtime($v_header[filename]) > $v_header[mtime])\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is newer (".date("l dS of F Y h:i:s A", filemtime($v_header[filename])).") than the extracted file (".date("l dS of F Y h:i:s A", $v_header[mtime]).")");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "newer_exist";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+        }\r
+\r
+        // ----- Check the directory availability and create it if necessary\r
+        else\r
+        {\r
+          if ($v_header[typeflag]=="5")\r
+            $v_dir_to_check = $v_header[filename];\r
+          else if (!strstr($v_header[filename], "/"))\r
+            $v_dir_to_check = "";\r
+          else\r
+            $v_dir_to_check = dirname($v_header[filename]);\r
+\r
+          if (($v_result = PclTarHandlerDirCheck($v_dir_to_check)) != 1)\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '$v_header[filename]'");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "path_creation_fail";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+        }\r
+\r
+        // ----- Do the extraction\r
+        if (($v_extract_file) && ($v_header[typeflag]!="5"))\r
+        {\r
+          // ----- Open the destination file in write mode\r
+          if (($v_dest_file = @fopen($v_header[filename], "wb")) == 0)\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Error while opening '$v_header[filename]' in write binary mode");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "write_error";\r
+\r
+            // ----- Jump to next file\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");\r
+            if ($p_tar_mode == "tar")\r
+              fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+            else\r
+              gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+          }\r
+          else\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Start extraction of '$v_header[filename]'");\r
+\r
+            // ----- Read data\r
+            $n = floor($v_header[size]/512);\r
+            for ($i=0; $i<$n; $i++)\r
+            {\r
+              TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));\r
+              if ($p_tar_mode == "tar")\r
+                $v_content = fread($v_tar, 512);\r
+              else\r
+                $v_content = gzread($v_tar, 512);\r
+              fwrite($v_dest_file, $v_content, 512);\r
+            }\r
+            if (($v_header[size] % 512) != 0)\r
+            {\r
+              TrFctMessage(__FILE__, __LINE__, 3, "Read last ".($v_header[size] % 512)." bytes in a 512 block");\r
+              if ($p_tar_mode == "tar")\r
+                $v_content = fread($v_tar, 512);\r
+              else\r
+                $v_content = gzread($v_tar, 512);\r
+              fwrite($v_dest_file, $v_content, ($v_header[size] % 512));\r
+            }\r
+\r
+            // ----- Close the destination file\r
+            fclose($v_dest_file);\r
+\r
+            // ----- Change the file mode, mtime\r
+            touch($v_header[filename], $v_header[mtime]);\r
+            //chmod($v_header[filename], DecOct($v_header[mode]));\r
+          }\r
+\r
+          // ----- Check the file size\r
+          clearstatcache();\r
+          if (filesize($v_header[filename]) != $v_header[size])\r
+          {\r
+            // ----- Close the archive file\r
+            if ($p_tar_mode == "tar")\r
+              fclose($v_tar);\r
+            else\r
+              gzclose($v_tar);\r
+\r
+            // ----- Error log\r
+            PclErrorLog(-7, "Extracted file '$v_header[filename]' does not have the correct file size '".filesize($v_filename)."' ('$v_header[size]' expected). Archive may be corrupted.");\r
+\r
+            // ----- Return\r
+            TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+            return PclErrorCode();\r
+          }\r
+\r
+          // ----- Trace\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Extraction done");\r
+        }\r
+\r
+        else\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Extraction of file '$v_header[filename]' skipped.");\r
+\r
+          // ----- Jump to next file\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");\r
+          if ($p_tar_mode == "tar")\r
+            fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+          else\r
+            gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+        }\r
+      }\r
+\r
+      // ----- Look for file that is not to be unzipped\r
+      else\r
+      {\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Jump file '$v_header[filename]'");\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");\r
+\r
+        // ----- Jump to next file\r
+        if ($p_tar_mode == "tar")\r
+          fseek($v_tar, ($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))+(ceil(($v_header[size]/512))*512));\r
+        else\r
+          gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Position apr�s jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");\r
+      }\r
+\r
+      if ($p_tar_mode == "tar")\r
+        $v_end_of_file = feof($v_tar);\r
+      else\r
+        $v_end_of_file = gzeof($v_tar);\r
+\r
+      // ----- File name and properties are logged if listing mode or file is extracted\r
+      if ($v_listing || $v_extract_file || $v_extraction_stopped)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");\r
+\r
+        // ----- Log extracted files\r
+        if (($v_file_dir = dirname($v_header[filename])) == $v_header[filename])\r
+          $v_file_dir = "";\r
+        if ((substr($v_header[filename], 0, 1) == "/") && ($v_file_dir == ""))\r
+          $v_file_dir = "/";\r
+\r
+        // ----- Add the array describing the file into the list\r
+        $p_list_detail[$v_nb] = $v_header;\r
+\r
+        // ----- Increment\r
+        $v_nb++;\r
+      }\r
+    }\r
+\r
+    // ----- Close the tarfile\r
+    if ($p_tar_mode == "tar")\r
+      fclose($v_tar);\r
+    else\r
+      gzclose($v_tar);\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleExtractByIndexList()\r
+  // Description :\r
+  //   Extract the files which are at the indexes specified. If the 'file' at the\r
+  //   index is a directory, the directory only is created, not all the files stored\r
+  //   for that directory.\r
+  // Parameters :\r
+  //   $p_index_string : String of indexes of files to extract. The form of the\r
+  //                     string is "0,4-6,8-12" with only numbers and '-' for\r
+  //                     for range, and ',' to separate ranges. No spaces or ';'\r
+  //                     are allowed.\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleExtractByIndexList($p_tarname, $p_index_string, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndexList", "archive='$p_tarname', index_string='$p_index_string', list, path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");\r
+    $v_result=1;\r
+    $v_nb = 0;\r
+\r
+    // ----- TBC : I should check the string by a regexp\r
+\r
+    // ----- Check the path\r
+    if (($p_path == "") || ((substr($p_path, 0, 1) != "/") && (substr($p_path, 0, 3) != "../") && (substr($p_path, 0, 2) != "./")))\r
+      $p_path = "./".$p_path;\r
+\r
+    // ----- Look for path to remove format (should end by /)\r
+    if (($p_remove_path != "") && (substr($p_remove_path, -1) != '/'))\r
+    {\r
+      $p_remove_path .= '/';\r
+    }\r
+    $p_remove_path_size = strlen($p_remove_path);\r
+\r
+    // ----- Open the tar file\r
+    if ($p_tar_mode == "tar")\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+      $v_tar = @fopen($p_tarname, "rb");\r
+    }\r
+    else\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");\r
+      $v_tar = @gzopen($p_tarname, "rb");\r
+    }\r
+\r
+    // ----- Check that the archive is open\r
+    if ($v_tar == 0)\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-2, "Unable to open archive '$p_tarname' in binary read mode");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Manipulate the index list\r
+    $v_list = explode(",", $p_index_string);\r
+    sort($v_list);\r
+\r
+    // ----- Loop on the index list\r
+    $v_index=0;\r
+    for ($i=0; ($i<sizeof($v_list)) && ($v_result); $i++)\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Looking for index part '$v_list[$i]'");\r
+\r
+      // ----- Extract range\r
+      $v_index_list = explode("-", $v_list[$i]);\r
+      $v_size_index_list = sizeof($v_index_list);\r
+      if ($v_size_index_list == 1)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "Only one index '$v_index_list[0]'");\r
+\r
+        // ----- Do the extraction\r
+        $v_result = PclTarHandleExtractByIndex($v_tar, $v_index, $v_index_list[0], $v_index_list[0], $p_list_detail, $p_path, $p_remove_path, $p_tar_mode);\r
+      }\r
+      else if ($v_size_index_list == 2)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "Two indexes '$v_index_list[0]' and '$v_index_list[1]'");\r
+\r
+        // ----- Do the extraction\r
+        $v_result = PclTarHandleExtractByIndex($v_tar, $v_index, $v_index_list[0], $v_index_list[1], $p_list_detail, $p_path, $p_remove_path, $p_tar_mode);\r
+      }\r
+    }\r
+\r
+    // ----- Close the tarfile\r
+    if ($p_tar_mode == "tar")\r
+      fclose($v_tar);\r
+    else\r
+      gzclose($v_tar);\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleExtractByIndex()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleExtractByIndex($p_tar, &$p_index_current, $p_index_start, $p_index_stop, &$p_list_detail, $p_path, $p_remove_path, $p_tar_mode)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractByIndex", "archive_descr='$p_tar', index_current=$p_index_current, index_start='$p_index_start', index_stop='$p_index_stop', list, path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");\r
+    $v_result=1;\r
+    $v_nb = 0;\r
+\r
+    // TBC : I should replace all $v_tar by $p_tar in this function ....\r
+    $v_tar = $p_tar;\r
+\r
+    // ----- Look the number of elements already in $p_list_detail\r
+    $v_nb = sizeof($p_list_detail);\r
+\r
+    // ----- Read the blocks\r
+    While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Looking for next file ...");\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Index current=$p_index_current, range=[$p_index_start, $p_index_stop])");\r
+\r
+      if ($p_index_current > $p_index_stop)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Stop extraction, past stop index");\r
+        break;\r
+      }\r
+\r
+      // ----- Clear cache of file infos\r
+      clearstatcache();\r
+\r
+      // ----- Reset extract tag\r
+      $v_extract_file = FALSE;\r
+      $v_extraction_stopped = 0;\r
+\r
+      // ----- Read the 512 bytes header\r
+      if ($p_tar_mode == "tar")\r
+        $v_binary_data = fread($v_tar, 512);\r
+      else\r
+        $v_binary_data = gzread($v_tar, 512);\r
+\r
+      // ----- Read the header properties\r
+      if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)\r
+      {\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Look for empty blocks to skip\r
+      if ($v_header[filename] == "")\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");\r
+        continue;\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");\r
+\r
+      // ----- Look if file is in the range to be extracted\r
+      if (($p_index_current >= $p_index_start) && ($p_index_current <= $p_index_stop))\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is in the range to be extracted");\r
+        $v_extract_file = TRUE;\r
+      }\r
+      else\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' is out of the range");\r
+        $v_extract_file = FALSE;\r
+      }\r
+\r
+      // ----- Look if this file need to be extracted\r
+      if ($v_extract_file)\r
+      {\r
+        if (($v_result = PclTarHandleExtractFile($v_tar, $v_header, $p_path, $p_remove_path, $p_tar_mode)) != 1)\r
+        {\r
+          // ----- Return\r
+          TrFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+      }\r
+\r
+      // ----- Look for file that is not to be extracted\r
+      else\r
+      {\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Jump file '$v_header[filename]'");\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");\r
+\r
+        // ----- Jump to next file\r
+        if ($p_tar_mode == "tar")\r
+          fseek($v_tar, ($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))+(ceil(($v_header[size]/512))*512));\r
+        else\r
+          gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Position apr�s jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");\r
+      }\r
+\r
+      if ($p_tar_mode == "tar")\r
+        $v_end_of_file = feof($v_tar);\r
+      else\r
+        $v_end_of_file = gzeof($v_tar);\r
+\r
+      // ----- File name and properties are logged if listing mode or file is extracted\r
+      if ($v_extract_file)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");\r
+\r
+        // ----- Log extracted files\r
+        if (($v_file_dir = dirname($v_header[filename])) == $v_header[filename])\r
+          $v_file_dir = "";\r
+        if ((substr($v_header[filename], 0, 1) == "/") && ($v_file_dir == ""))\r
+          $v_file_dir = "/";\r
+\r
+        // ----- Add the array describing the file into the list\r
+        $p_list_detail[$v_nb] = $v_header;\r
+\r
+        // ----- Increment\r
+        $v_nb++;\r
+      }\r
+\r
+      // ----- Increment the current file index\r
+      $p_index_current++;\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleExtractFile()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleExtractFile($p_tar, &$v_header, $p_path, $p_remove_path, $p_tar_mode)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleExtractFile", "archive_descr='$p_tar', path=$p_path, remove_path='$p_remove_path', tar_mode=$p_tar_mode");\r
+    $v_result=1;\r
+\r
+    // TBC : I should replace all $v_tar by $p_tar in this function ....\r
+    $v_tar = $p_tar;\r
+    $v_extract_file = 1;\r
+\r
+    $p_remove_path_size = strlen($p_remove_path);\r
+\r
+        // ----- Look for path to remove\r
+        if (($p_remove_path != "")\r
+            && (substr($v_header[filename], 0, $p_remove_path_size) == $p_remove_path))\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Found path '$p_remove_path' to remove in file '$v_header[filename]'");\r
+          // ----- Remove the path\r
+          $v_header[filename] = substr($v_header[filename], $p_remove_path_size);\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Resulting file is '$v_header[filename]'");\r
+        }\r
+\r
+        // ----- Add the path to the file\r
+        if (($p_path != "./") && ($p_path != "/"))\r
+        {\r
+          // ----- Look for the path end '/'\r
+          while (substr($p_path, -1) == "/")\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Destination path [$p_path] ends by '/'");\r
+            $p_path = substr($p_path, 0, strlen($p_path)-1);\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Modified to [$p_path]");\r
+          }\r
+\r
+          // ----- Add the path\r
+          if (substr($v_header[filename], 0, 1) == "/")\r
+              $v_header[filename] = $p_path.$v_header[filename];\r
+          else\r
+            $v_header[filename] = $p_path."/".$v_header[filename];\r
+        }\r
+\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Extracting file (with path) '$v_header[filename]', size '$v_header[size]'");\r
+\r
+        // ----- Check that the file does not exists\r
+        if (file_exists($v_header[filename]))\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 2, "File '$v_header[filename]' already exists");\r
+\r
+          // ----- Look if file is a directory\r
+          if (is_dir($v_header[filename]))\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is a directory");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "already_a_directory";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+          // ----- Look if file is write protected\r
+          else if (!is_writeable($v_header[filename]))\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is write protected");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "write_protected";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+          // ----- Look if the extracted file is older\r
+          else if (filemtime($v_header[filename]) > $v_header[mtime])\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Existing file '$v_header[filename]' is newer (".date("l dS of F Y h:i:s A", filemtime($v_header[filename])).") than the extracted file (".date("l dS of F Y h:i:s A", $v_header[mtime]).")");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "newer_exist";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+        }\r
+\r
+        // ----- Check the directory availability and create it if necessary\r
+        else\r
+        {\r
+          if ($v_header[typeflag]=="5")\r
+            $v_dir_to_check = $v_header[filename];\r
+          else if (!strstr($v_header[filename], "/"))\r
+            $v_dir_to_check = "";\r
+          else\r
+            $v_dir_to_check = dirname($v_header[filename]);\r
+\r
+          if (($v_result = PclTarHandlerDirCheck($v_dir_to_check)) != 1)\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Unable to create path for '$v_header[filename]'");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "path_creation_fail";\r
+\r
+            // ----- Skip the extract\r
+            $v_extraction_stopped = 1;\r
+            $v_extract_file = 0;\r
+          }\r
+        }\r
+\r
+        // ----- Do the real bytes extraction (if not a directory)\r
+        if (($v_extract_file) && ($v_header[typeflag]!="5"))\r
+        {\r
+          // ----- Open the destination file in write mode\r
+          if (($v_dest_file = @fopen($v_header[filename], "wb")) == 0)\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Error while opening '$v_header[filename]' in write binary mode");\r
+\r
+            // ----- Change the file status\r
+            $v_header[status] = "write_error";\r
+\r
+            // ----- Jump to next file\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");\r
+            if ($p_tar_mode == "tar")\r
+              fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+            else\r
+              gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+          }\r
+          else\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 2, "Start extraction of '$v_header[filename]'");\r
+\r
+            // ----- Read data\r
+            $n = floor($v_header[size]/512);\r
+            for ($i=0; $i<$n; $i++)\r
+            {\r
+              TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));\r
+              if ($p_tar_mode == "tar")\r
+                $v_content = fread($v_tar, 512);\r
+              else\r
+                $v_content = gzread($v_tar, 512);\r
+              fwrite($v_dest_file, $v_content, 512);\r
+            }\r
+            if (($v_header[size] % 512) != 0)\r
+            {\r
+              TrFctMessage(__FILE__, __LINE__, 3, "Read last ".($v_header[size] % 512)." bytes in a 512 block");\r
+              if ($p_tar_mode == "tar")\r
+                $v_content = fread($v_tar, 512);\r
+              else\r
+                $v_content = gzread($v_tar, 512);\r
+              fwrite($v_dest_file, $v_content, ($v_header[size] % 512));\r
+            }\r
+\r
+            // ----- Close the destination file\r
+            fclose($v_dest_file);\r
+\r
+            // ----- Change the file mode, mtime\r
+            touch($v_header[filename], $v_header[mtime]);\r
+            //chmod($v_header[filename], DecOct($v_header[mode]));\r
+          }\r
+\r
+          // ----- Check the file size\r
+          clearstatcache();\r
+          if (filesize($v_header[filename]) != $v_header[size])\r
+          {\r
+            // ----- Error log\r
+            PclErrorLog(-7, "Extracted file '$v_header[filename]' does not have the correct file size '".filesize($v_filename)."' ('$v_header[size]' expected). Archive may be corrupted.");\r
+\r
+            // ----- Return\r
+            TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+            return PclErrorCode();\r
+          }\r
+\r
+          // ----- Trace\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Extraction done");\r
+        }\r
+        else\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Extraction of file '$v_header[filename]' skipped.");\r
+\r
+          // ----- Jump to next file\r
+          TrFctMessage(__FILE__, __LINE__, 2, "Jump to next file");\r
+          if ($p_tar_mode == "tar")\r
+            fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+          else\r
+            gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+        }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleDelete()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleDelete($p_tarname, $p_file_list, &$p_list_detail, $p_tar_mode)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleDelete", "archive='$p_tarname', list, tar_mode=$p_tar_mode");\r
+    $v_result=1;\r
+    $v_nb=0;\r
+\r
+    // ----- Look for regular tar file\r
+    if ($p_tar_mode == "tar")\r
+    {\r
+      // ----- Open file\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+      if (($v_tar = @fopen($p_tarname, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Open a temporary file in write mode\r
+      $v_temp_tarname = uniqid("pcltar-").".tmp";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");\r
+      if (($v_temp_tar = @fopen($v_temp_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Close tar file\r
+        fclose($v_tar);\r
+\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Look for compressed tar file\r
+    else\r
+    {\r
+      // ----- Open the file in read mode\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");\r
+      if (($v_tar = @gzopen($p_tarname, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Open a temporary file in write mode\r
+      $v_temp_tarname = uniqid("pcltar-").".tmp";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");\r
+      if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Close tar file\r
+        gzclose($v_tar);\r
+\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Read the blocks\r
+    While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");\r
+\r
+      // ----- Clear cache of file infos\r
+      clearstatcache();\r
+\r
+      // ----- Reset delete tag\r
+      $v_delete_file = FALSE;\r
+\r
+      // ----- Read the first 512 block header\r
+      if ($p_tar_mode == "tar")\r
+        $v_binary_data = fread($v_tar, 512);\r
+      else\r
+        $v_binary_data = gzread($v_tar, 512);\r
+\r
+      // ----- Read the header properties\r
+      if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)\r
+      {\r
+        // ----- Close the archive file\r
+        if ($p_tar_mode == "tar")\r
+        {\r
+          fclose($v_tar);\r
+          fclose($v_temp_tar);\r
+        }\r
+        else\r
+        {\r
+          gzclose($v_tar);\r
+          gzclose($v_temp_tar);\r
+        }\r
+        @unlink($v_temp_tarname);\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Look for empty blocks to skip\r
+      if ($v_header[filename] == "")\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");\r
+        continue;\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");\r
+\r
+      // ----- Look for filenames to delete\r
+      for ($i=0, $v_delete_file=FALSE; ($i<sizeof($p_file_list)) && (!$v_delete_file); $i++)\r
+      {\r
+        // ----- Compare the file names\r
+//        if ($p_file_list[$i] == $v_header[filename])\r
+        if (($v_len = strcmp($p_file_list[$i], $v_header[filename])) <= 0)\r
+        {\r
+          if ($v_len==0)\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Found that '$v_header[filename]' need to be deleted");\r
+            $v_delete_file = TRUE;\r
+          }\r
+          else\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "Look if '$v_header[filename]' is a file in $p_file_list[$i]");\r
+            if (substr($v_header[filename], strlen($p_file_list[$i]), 1) == "/")\r
+            {\r
+              TrFctMessage(__FILE__, __LINE__, 3, "'$v_header[filename]' is a file in $p_file_list[$i]");\r
+              $v_delete_file = TRUE;\r
+            }\r
+          }\r
+        }\r
+      }\r
+\r
+      // ----- Copy files that do not need to be deleted\r
+      if (!$v_delete_file)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Keep file '$v_header[filename]'");\r
+\r
+        // ----- Write the file header\r
+        if ($p_tar_mode == "tar")\r
+        {\r
+          fputs($v_temp_tar, $v_binary_data, 512);\r
+        }\r
+        else\r
+        {\r
+          gzputs($v_temp_tar, $v_binary_data, 512);\r
+        }\r
+\r
+        // ----- Write the file data\r
+        $n = ceil($v_header[size]/512);\r
+        for ($i=0; $i<$n; $i++)\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($i+1));\r
+          if ($p_tar_mode == "tar")\r
+          {\r
+            $v_content = fread($v_tar, 512);\r
+            fwrite($v_temp_tar, $v_content, 512);\r
+          }\r
+          else\r
+          {\r
+            $v_content = gzread($v_tar, 512);\r
+            gzwrite($v_temp_tar, $v_content, 512);\r
+          }\r
+        }\r
+\r
+        // ----- File name and properties are logged if listing mode or file is extracted\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");\r
+\r
+        // ----- Add the array describing the file into the list\r
+        $p_list_detail[$v_nb] = $v_header;\r
+        $p_list_detail[$v_nb][status] = "ok";\r
+\r
+        // ----- Increment\r
+        $v_nb++;\r
+      }\r
+\r
+      // ----- Look for file that is to be deleted\r
+      else\r
+      {\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Start deletion of '$v_header[filename]'");\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Position avant jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");\r
+\r
+        // ----- Jump to next file\r
+        if ($p_tar_mode == "tar")\r
+          fseek($v_tar, ftell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+        else\r
+          gzseek($v_tar, gztell($v_tar)+(ceil(($v_header[size]/512))*512));\r
+\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Position apr�s jump [".($p_tar_mode=="tar"?ftell($v_tar):gztell($v_tar))."]");\r
+      }\r
+\r
+      // ----- Look for end of file\r
+      if ($p_tar_mode == "tar")\r
+        $v_end_of_file = feof($v_tar);\r
+      else\r
+        $v_end_of_file = gzeof($v_tar);\r
+    }\r
+\r
+    // ----- Write the last empty buffer\r
+    PclTarHandleFooter($v_temp_tar, $p_tar_mode);\r
+\r
+    // ----- Close the tarfile\r
+    if ($p_tar_mode == "tar")\r
+    {\r
+      fclose($v_tar);\r
+      fclose($v_temp_tar);\r
+    }\r
+    else\r
+    {\r
+      gzclose($v_tar);\r
+      gzclose($v_temp_tar);\r
+    }\r
+\r
+    // ----- Unlink tar file\r
+    if (!@unlink($p_tarname))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-11, "Error while deleting archive name $p_tarname");\r
+    }\r
+\r
+\r
+    // ----- Rename tar file\r
+    if (!@rename($v_temp_tarname, $p_tarname))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleUpdate()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleUpdate($p_tarname, $p_file_list, &$p_list_detail, $p_tar_mode, $p_add_dir, $p_remove_dir)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleUpdate", "archive='$p_tarname', list, tar_mode=$p_tar_mode");\r
+    $v_result=1;\r
+    $v_nb=0;\r
+    $v_found_list = array();\r
+\r
+    // ----- Look for regular tar file\r
+    if ($p_tar_mode == "tar")\r
+    {\r
+      // ----- Open file\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in binary read mode");\r
+      if (($v_tar = @fopen($p_tarname, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Open a temporary file in write mode\r
+      $v_temp_tarname = uniqid("pcltar-").".tmp";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");\r
+      if (($v_temp_tar = @fopen($v_temp_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Close tar file\r
+        fclose($v_tar);\r
+\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Look for compressed tar file\r
+    else\r
+    {\r
+      // ----- Open the file in read mode\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Open file in gzip binary read mode");\r
+      if (($v_tar = @gzopen($p_tarname, "rb")) == 0)\r
+      {\r
+        // ----- Error log\r
+        PclErrorLog(-2, "Unable to open file '$p_tarname' in binary read mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+\r
+      // ----- Open a temporary file in write mode\r
+      $v_temp_tarname = uniqid("pcltar-").".tmp";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Creating temporary archive file $v_temp_tarname");\r
+      if (($v_temp_tar = @gzopen($v_temp_tarname, "wb")) == 0)\r
+      {\r
+        // ----- Close tar file\r
+        gzclose($v_tar);\r
+\r
+        // ----- Error log\r
+        PclErrorLog(-1, "Unable to open file '$v_temp_tarname' in binary write mode");\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+        return PclErrorCode();\r
+      }\r
+    }\r
+\r
+    // ----- Prepare the list of files\r
+    for ($i=0; $i<sizeof($p_file_list); $i++)\r
+    {\r
+      // ----- Reset the found list\r
+      $v_found_list[$i] = 0;\r
+\r
+    // ----- Calculate the stored filename\r
+    $v_stored_list[$i] = $p_file_list[$i];\r
+    if ($p_remove_dir != "")\r
+    {\r
+      if (substr($p_file_list[$i], -1) != '/')\r
+        $p_remove_dir .= "/";\r
+\r
+      if (substr($p_file_list[$i], 0, strlen($p_remove_dir)) == $p_remove_dir)\r
+      {\r
+        $v_stored_list[$i] = substr($p_file_list[$i], strlen($p_remove_dir));\r
+        TrFctMessage(__FILE__, __LINE__, 3, "Remove path '$p_remove_dir' in file '$p_file_list[$i]' = '$v_stored_list[$i]'");\r
+      }\r
+    }\r
+    if ($p_add_dir != "")\r
+    {\r
+      if (substr($p_add_dir, -1) == "/")\r
+        $v_stored_list[$i] = $p_add_dir.$v_stored_list[$i];\r
+      else\r
+        $v_stored_list[$i] = $p_add_dir."/".$v_stored_list[$i];\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Add path '$p_add_dir' in file '$p_file_list[$i]' = '$v_stored_list[$i]'");\r
+    }\r
+    $v_stored_list[$i] = PclTarHandlePathReduction($v_stored_list[$i]);\r
+      TrFctMessage(__FILE__, __LINE__, 3, "After reduction '$v_stored_list[$i]'");\r
+    }\r
+\r
+\r
+    // ----- Update file cache\r
+    clearstatcache();\r
+\r
+    // ----- Read the blocks\r
+    While (!($v_end_of_file = ($p_tar_mode == "tar"?feof($v_tar):gzeof($v_tar))))\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 3, "Looking for next header ...");\r
+\r
+      // ----- Clear cache of file infos\r
+      clearstatcache();\r
+\r
+      // ----- Reset current found filename\r
+      $v_current_filename = "";\r
+\r
+      // ----- Reset delete tag\r
+      $v_delete_file = FALSE;\r
+\r
+      // ----- Read the first 512 block header\r
+      if ($p_tar_mode == "tar")\r
+        $v_binary_data = fread($v_tar, 512);\r
+      else\r
+        $v_binary_data = gzread($v_tar, 512);\r
+\r
+      // ----- Read the header properties\r
+      if (($v_result = PclTarHandleReadHeader($v_binary_data, $v_header)) != 1)\r
+      {\r
+        // ----- Close the archive file\r
+        if ($p_tar_mode == "tar")\r
+        {\r
+          fclose($v_tar);\r
+          fclose($v_temp_tar);\r
+        }\r
+        else\r
+        {\r
+          gzclose($v_tar);\r
+          gzclose($v_temp_tar);\r
+        }\r
+        @unlink($v_temp_tarname);\r
+\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, $v_result);\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Look for empty blocks to skip\r
+      if ($v_header[filename] == "")\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Empty block found. End of archive ?");\r
+        continue;\r
+      }\r
+\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Found file '$v_header[filename]', size '$v_header[size]'");\r
+\r
+      // ----- Look for filenames to update\r
+      for ($i=0, $v_update_file=FALSE, $v_found_file=FALSE; ($i<sizeof($v_stored_list)) && (!$v_update_file); $i++)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 4, "Compare with file '$v_stored_list[$i]'");\r
+\r
+        // ----- Compare the file names\r
+        if ($v_stored_list[$i] == $v_header[filename])\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 3, "File '$v_stored_list[$i]' is present in archive");\r
+          TrFctMessage(__FILE__, __LINE__, 3, "File '$v_stored_list[$i]' mtime=".filemtime($p_file_list[$i])." ".date("l dS of F Y h:i:s A", filemtime($p_file_list[$i])));\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Archived mtime=".$v_header[mtime]." ".date("l dS of F Y h:i:s A", $v_header[mtime]));\r
+\r
+          // ----- Store found informations\r
+          $v_found_file = TRUE;\r
+          $v_current_filename = $p_file_list[$i];\r
+\r
+          // ----- Look if the file need to be updated\r
+          if (filemtime($p_file_list[$i]) > $v_header[mtime])\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' need to be updated");\r
+            $v_update_file = TRUE;\r
+          }\r
+          else\r
+          {\r
+            TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' does not need to be updated");\r
+            $v_update_file = FALSE;\r
+          }\r
+\r
+          // ----- Flag the name in order not to add the file at the end\r
+          $v_found_list[$i] = 1;\r
+        }\r
+        else\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 4, "File '$p_file_list[$i]' is not '$v_header[filename]'");\r
+        }\r
+      }\r
+\r
+      // ----- Copy files that do not need to be updated\r
+      if (!$v_update_file)\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Keep file '$v_header[filename]'");\r
+\r
+        // ----- Write the file header\r
+        if ($p_tar_mode == "tar")\r
+        {\r
+          fputs($v_temp_tar, $v_binary_data, 512);\r
+        }\r
+        else\r
+        {\r
+          gzputs($v_temp_tar, $v_binary_data, 512);\r
+        }\r
+\r
+        // ----- Write the file data\r
+        $n = ceil($v_header[size]/512);\r
+        for ($j=0; $j<$n; $j++)\r
+        {\r
+          TrFctMessage(__FILE__, __LINE__, 3, "Read complete 512 bytes block number ".($j+1));\r
+          if ($p_tar_mode == "tar")\r
+          {\r
+            $v_content = fread($v_tar, 512);\r
+            fwrite($v_temp_tar, $v_content, 512);\r
+          }\r
+          else\r
+          {\r
+            $v_content = gzread($v_tar, 512);\r
+            gzwrite($v_temp_tar, $v_content, 512);\r
+          }\r
+        }\r
+\r
+        // ----- File name and properties are logged if listing mode or file is extracted\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Memorize info about file '$v_header[filename]'");\r
+\r
+        // ----- Add the array describing the file into the list\r
+        $p_list_detail[$v_nb] = $v_header;\r
+        $p_list_detail[$v_nb][status] = ($v_found_file?"not_updated":"ok");\r
+\r
+        // ----- Increment\r
+        $v_nb++;\r
+      }\r
+\r
+      // ----- Look for file that need to be updated\r
+      else\r
+      {\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Start update of file '$v_current_filename'");\r
+\r
+        // ----- Store the old file size\r
+        $v_old_size = $v_header[size];\r
+\r
+        // ----- Add the file\r
+        if (($v_result = PclTarHandleAddFile($v_temp_tar, $v_current_filename, $p_tar_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)\r
+        {\r
+          // ----- Close the tarfile\r
+          if ($p_tar_mode == "tar")\r
+          {\r
+            fclose($v_tar);\r
+            fclose($v_temp_tar);\r
+          }\r
+          else\r
+          {\r
+            gzclose($v_tar);\r
+            gzclose($v_temp_tar);\r
+          }\r
+          @unlink($p_temp_tarname);\r
+\r
+          // ----- Return status\r
+          TrFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+\r
+        // ----- Trace\r
+        TrFctMessage(__FILE__, __LINE__, 2, "Skip old file '$v_header[filename]'");\r
+\r
+        // ----- Jump to next file\r
+        if ($p_tar_mode == "tar")\r
+          fseek($v_tar, ftell($v_tar)+(ceil(($v_old_size/512))*512));\r
+        else\r
+          gzseek($v_tar, gztell($v_tar)+(ceil(($v_old_size/512))*512));\r
+\r
+        // ----- Add the array describing the file into the list\r
+        $p_list_detail[$v_nb] = $v_header;\r
+        $p_list_detail[$v_nb][status] = "updated";\r
+\r
+        // ----- Increment\r
+        $v_nb++;\r
+      }\r
+\r
+      // ----- Look for end of file\r
+      if ($p_tar_mode == "tar")\r
+        $v_end_of_file = feof($v_tar);\r
+      else\r
+        $v_end_of_file = gzeof($v_tar);\r
+    }\r
+\r
+    // ----- Look for files that does not exists in the archive and need to be added\r
+    for ($i=0; $i<sizeof($p_file_list); $i++)\r
+    {\r
+      // ----- Look if file not found in the archive\r
+      if (!$v_found_list[$i])\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' need to be added");\r
+\r
+        // ----- Add the file\r
+        if (($v_result = PclTarHandleAddFile($v_temp_tar, $p_file_list[$i], $p_tar_mode, $v_header, $p_add_dir, $p_remove_dir)) != 1)\r
+        {\r
+          // ----- Close the tarfile\r
+          if ($p_tar_mode == "tar")\r
+          {\r
+            fclose($v_tar);\r
+            fclose($v_temp_tar);\r
+          }\r
+          else\r
+          {\r
+            gzclose($v_tar);\r
+            gzclose($v_temp_tar);\r
+          }\r
+          @unlink($p_temp_tarname);\r
+\r
+          // ----- Return status\r
+          TrFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+\r
+        // ----- Add the array describing the file into the list\r
+        $p_list_detail[$v_nb] = $v_header;\r
+        $p_list_detail[$v_nb][status] = "added";\r
+\r
+        // ----- Increment\r
+        $v_nb++;\r
+      }\r
+      else\r
+      {\r
+        TrFctMessage(__FILE__, __LINE__, 3, "File '$p_file_list[$i]' was already updated if needed");\r
+      }\r
+    }\r
+\r
+    // ----- Write the last empty buffer\r
+    PclTarHandleFooter($v_temp_tar, $p_tar_mode);\r
+\r
+    // ----- Close the tarfile\r
+    if ($p_tar_mode == "tar")\r
+    {\r
+      fclose($v_tar);\r
+      fclose($v_temp_tar);\r
+    }\r
+    else\r
+    {\r
+      gzclose($v_tar);\r
+      gzclose($v_temp_tar);\r
+    }\r
+\r
+    // ----- Unlink tar file\r
+    if (!@unlink($p_tarname))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-11, "Error while deleting archive name $p_tarname");\r
+    }\r
+\r
+\r
+    // ----- Rename tar file\r
+    if (!@rename($v_temp_tarname, $p_tarname))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-12, "Error while renaming temporary file $v_temp_tarname to archive name $p_tarname");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleReadHeader()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleReadHeader($v_binary_data, &$v_header)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleReadHeader", "");\r
+    $v_result=1;\r
+\r
+    // ----- Read the 512 bytes header\r
+    /*\r
+    if ($p_tar_mode == "tar")\r
+      $v_binary_data = fread($p_tar, 512);\r
+    else\r
+      $v_binary_data = gzread($p_tar, 512);\r
+    */\r
+\r
+    // ----- Look for no more block\r
+    if (strlen($v_binary_data)==0)\r
+    {\r
+      $v_header[filename] = "";\r
+      $v_header[status] = "empty";\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, $v_result, "End of archive found");\r
+      return $v_result;\r
+    }\r
+\r
+    // ----- Look for invalid block size\r
+    if (strlen($v_binary_data) != 512)\r
+    {\r
+      $v_header[filename] = "";\r
+      $v_header[status] = "invalid_header";\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Invalid block size : ".strlen($v_binary_data));\r
+\r
+      // ----- Error log\r
+      PclErrorLog(-10, "Invalid block size : ".strlen($v_binary_data));\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Calculate the checksum\r
+    $v_checksum = 0;\r
+    // ..... First part of the header\r
+    for ($i=0; $i<148; $i++)\r
+    {\r
+      $v_checksum+=ord(substr($v_binary_data,$i,1));\r
+    }\r
+    // ..... Ignore the checksum value and replace it by ' ' (space)\r
+    for ($i=148; $i<156; $i++)\r
+    {\r
+      $v_checksum += ord(' ');\r
+    }\r
+    // ..... Last part of the header\r
+    for ($i=156; $i<512; $i++)\r
+    {\r
+      $v_checksum+=ord(substr($v_binary_data,$i,1));\r
+    }\r
+    TrFctMessage(__FILE__, __LINE__, 3, "Calculated checksum : $v_checksum");\r
+\r
+    // ----- Extract the values\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Header : '$v_binary_data'");\r
+    $v_data = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $v_binary_data);\r
+\r
+    // ----- Extract the checksum for check\r
+    $v_header[checksum] = OctDec(trim($v_data[checksum]));\r
+    TrFctMessage(__FILE__, __LINE__, 3, "File checksum : $v_header[checksum]");\r
+    if ($v_header[checksum] != $v_checksum)\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 2, "File checksum is invalid : $v_checksum calculated, $v_header[checksum] expected");\r
+\r
+      $v_header[filename] = "";\r
+      $v_header[status] = "invalid_header";\r
+\r
+      // ----- Look for last block (empty block)\r
+      if (($v_checksum == 256) && ($v_header[checksum] == 0))\r
+      {\r
+        $v_header[status] = "empty";\r
+        // ----- Return\r
+        TrFctEnd(__FILE__, __LINE__, $v_result, "End of archive found");\r
+        return $v_result;\r
+      }\r
+\r
+      // ----- Error log\r
+      PclErrorLog(-13, "Invalid checksum : $v_checksum calculated, $v_header[checksum] expected");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+    TrFctMessage(__FILE__, __LINE__, 2, "File checksum is valid ($v_checksum)");\r
+\r
+    // ----- Extract the properties\r
+    $v_header[filename] = trim($v_data[filename]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Name : '$v_header[filename]'");\r
+    $v_header[mode] = OctDec(trim($v_data[mode]));\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Mode : '".DecOct($v_header[mode])."'");\r
+    $v_header[uid] = OctDec(trim($v_data[uid]));\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Uid : '$v_header[uid]'");\r
+    $v_header[gid] = OctDec(trim($v_data[gid]));\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Gid : '$v_header[gid]'");\r
+    $v_header[size] = OctDec(trim($v_data[size]));\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Size : '$v_header[size]'");\r
+    $v_header[mtime] = OctDec(trim($v_data[mtime]));\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Date : ".date("l dS of F Y h:i:s A", $v_header[mtime]));\r
+    if (($v_header[typeflag] = $v_data[typeflag]) == "5")\r
+    {\r
+      $v_header[size] = 0;\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Size (folder) : '$v_header[size]'");\r
+    }\r
+    TrFctMessage(__FILE__, __LINE__, 2, "File typeflag : $v_header[typeflag]");\r
+    /* ----- All these fields are removed form the header because they do not carry interesting info\r
+    $v_header[link] = trim($v_data[link]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Linkname : $v_header[linkname]");\r
+    $v_header[magic] = trim($v_data[magic]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Magic : $v_header[magic]");\r
+    $v_header[version] = trim($v_data[version]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Version : $v_header[version]");\r
+    $v_header[uname] = trim($v_data[uname]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Uname : $v_header[uname]");\r
+    $v_header[gname] = trim($v_data[gname]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Gname : $v_header[gname]");\r
+    $v_header[devmajor] = trim($v_data[devmajor]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Devmajor : $v_header[devmajor]");\r
+    $v_header[devminor] = trim($v_data[devminor]);\r
+    TrFctMessage(__FILE__, __LINE__, 2, "Devminor : $v_header[devminor]");\r
+    */\r
+\r
+    // ----- Set the status field\r
+    $v_header[status] = "ok";\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandlerDirCheck()\r
+  // Description :\r
+  //   Check if a directory exists, if not it creates it and all the parents directory\r
+  //   which may be useful.\r
+  // Parameters :\r
+  //   $p_dir : Directory path to check (without / at the end).\r
+  // Return Values :\r
+  //    1 : OK\r
+  //   -1 : Unable to create directory\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandlerDirCheck($p_dir)\r
+  {\r
+    $v_result = 1;\r
+\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandlerDirCheck", "$p_dir");\r
+\r
+    // ----- Check the directory availability\r
+    if ((is_dir($p_dir)) || ($p_dir == ""))\r
+    {\r
+      TrFctEnd(__FILE__, __LINE__, "'$p_dir' is a directory");\r
+      return 1;\r
+    }\r
+\r
+    // ----- Look for file alone\r
+    /*\r
+    if (!strstr("$p_dir", "/"))\r
+    {\r
+      TrFctEnd(__FILE__, __LINE__,  "'$p_dir' is a file with no directory");\r
+      return 1;\r
+    }\r
+    */\r
+\r
+    // ----- Extract parent directory\r
+    $p_parent_dir = dirname($p_dir);\r
+    TrFctMessage(__FILE__, __LINE__, 3, "Parent directory is '$p_parent_dir'");\r
+\r
+    // ----- Just a check\r
+    if ($p_parent_dir != $p_dir)\r
+    {\r
+      // ----- Look for parent directory\r
+      if ($p_parent_dir != "")\r
+      {\r
+        if (($v_result = PclTarHandlerDirCheck($p_parent_dir)) != 1)\r
+        {\r
+          TrFctEnd(__FILE__, __LINE__, $v_result);\r
+          return $v_result;\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Create the directory\r
+    TrFctMessage(__FILE__, __LINE__, 3, "Create directory '$p_dir'");\r
+    if (!@mkdir($p_dir, 0777))\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-8, "Unable to create directory '$p_dir'");\r
+\r
+      // ----- Return\r
+      TrFctEnd(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+      return PclErrorCode();\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result, "Directory '$p_dir' created");\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandleExtension()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandleExtension($p_tarname)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandleExtension", "tar=$p_tarname");\r
+\r
+    // ----- Look for file extension\r
+    if ((substr($p_tarname, -7) == ".tar.gz") || (substr($p_tarname, -4) == ".tgz"))\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Archive is a gzip tar");\r
+      $v_tar_mode = "tgz";\r
+    }\r
+    else if (substr($p_tarname, -4) == ".tar")\r
+    {\r
+      TrFctMessage(__FILE__, __LINE__, 2, "Archive is a tar");\r
+      $v_tar_mode = "tar";\r
+    }\r
+    else\r
+    {\r
+      // ----- Error log\r
+      PclErrorLog(-9, "Invalid archive extension");\r
+\r
+      TrFctMessage(__FILE__, __LINE__, PclErrorCode(), PclErrorString());\r
+\r
+      $v_tar_mode = "";\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_tar_mode);\r
+    return $v_tar_mode;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+  // --------------------------------------------------------------------------------\r
+  // Function : PclTarHandlePathReduction()\r
+  // Description :\r
+  // Parameters :\r
+  // Return Values :\r
+  // --------------------------------------------------------------------------------\r
+  function PclTarHandlePathReduction($p_dir)\r
+  {\r
+    TrFctStart(__FILE__, __LINE__, "PclTarHandlePathReduction", "dir='$p_dir'");\r
+    $v_result = "";\r
+\r
+    // ----- Look for not empty path\r
+    if ($p_dir != "")\r
+    {\r
+      // ----- Explode path by directory names\r
+      $v_list = explode("/", $p_dir);\r
+\r
+      // ----- Study directories from last to first\r
+      for ($i=sizeof($v_list)-1; $i>=0; $i--)\r
+      {\r
+        // ----- Look for current path\r
+        if ($v_list[$i] == ".")\r
+        {\r
+          // ----- Ignore this directory\r
+          // Should be the first $i=0, but no check is done\r
+        }\r
+        else if ($v_list[$i] == "..")\r
+        {\r
+          // ----- Ignore it and ignore the $i-1\r
+          $i--;\r
+        }\r
+        else if (($v_list[$i] == "") && ($i!=(sizeof($v_list)-1)) && ($i!=0))\r
+        {\r
+          // ----- Ignore only the double '//' in path,\r
+          // but not the first and last '/'\r
+        }\r
+        else\r
+        {\r
+          $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");\r
+        }\r
+      }\r
+    }\r
+\r
+    // ----- Return\r
+    TrFctEnd(__FILE__, __LINE__, $v_result);\r
+    return $v_result;\r
+  }\r
+  // --------------------------------------------------------------------------------\r
+\r
+\r
+// ----- End of double include look\r
+}\r
+?>
\ No newline at end of file