Exemplo n.º 1
0
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue));
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     $newArgs = RecycleBinManager::filterActions($action, $selection, $dir);
     foreach ($newArgs as $argName => $argValue) {
         ${$argName} = $argValue;
     }
     // FILTER DIR PAGINATION ANCHOR
     if (isset($dir) && strstr($dir, "#") !== false) {
         $parts = explode("#", $dir);
         $dir = $parts[0];
         $page = $parts[1];
     }
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD, IMAGE & MP3 PROXYS
         //------------------------------------
         case "download":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             set_error_handler(array("HTMLWriter", "javascriptErrorHandler"), E_ALL & ~E_NOTICE);
             register_shutdown_function("restore_error_handler");
             if ($selection->inZip) {
                 $tmpDir = dirname($selection->getZipPath()) . "/.tmpExtractDownload";
                 $delDir = $this->getPath() . "/" . $tmpDir;
                 @mkdir($delDir);
                 register_shutdown_function(array($this, "deldir"), $delDir);
                 $this->convertSelectionToTmpFiles($tmpDir, $selection);
             }
             $zip = false;
             if ($selection->isUnique()) {
                 if (is_dir($this->getPath() . "/" . $selection->getUniqueFile())) {
                     $zip = true;
                     $dir .= "/" . basename($selection->getUniqueFile());
                 }
             } else {
                 $zip = true;
             }
             if ($zip) {
                 // Make a temp zip and send it as download
                 $loggedUser = AuthService::getLoggedUser();
                 $file = USERS_DIR . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "/" . time() . "tmpDownload.zip";
                 $zipFile = $this->makeZip($selection->getFiles(), $file, $dir);
                 if (!$zipFile) {
                     AJXP_Exception::errorToXml("Error while compressing");
                 }
                 register_shutdown_function("unlink", $file);
                 $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip";
                 $this->readFile($file, "force-download", $localName, false, false);
             } else {
                 $this->readFile($this->getPath() . "/" . $selection->getUniqueFile(), "force-download");
             }
             exit(0);
             break;
         case "compress":
             // Make a temp zip and send it as download
             if (isset($archive_name)) {
                 $localName = SystemTextEncoding::fromUTF8($archive_name);
             } else {
                 $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip";
             }
             $file = $this->getPath() . "/" . $dir . "/" . $localName;
             $zipFile = $this->makeZip($selection->getFiles(), $file, $dir);
             if (!$zipFile) {
                 AJXP_Exception::errorToXml("Error while compressing file {$localName}");
             }
             $reload_current_node = true;
             $reload_file_list = $localName;
             break;
         case "image_proxy":
             if ($split = UserSelection::detectZip(SystemTextEncoding::fromUTF8($file))) {
                 require_once "server/classes/pclzip.lib.php";
                 $zip = new PclZip($this->getPath() . $split[0]);
                 $data = $zip->extract(PCLZIP_OPT_BY_NAME, substr($split[1], 1), PCLZIP_OPT_EXTRACT_AS_STRING);
                 header("Content-Type: " . Utils::getImageMimeType(basename($split[1])) . "; name=\"" . basename($split[1]) . "\"");
                 header("Content-Length: " . strlen($data[0]["content"]));
                 header('Cache-Control: public');
                 print $data[0]["content"];
             } else {
                 if (isset($get_thumb) && $get_thumb == "true" && $this->driverConf["GENERATE_THUMBNAIL"]) {
                     require_once "server/classes/PThumb.lib.php";
                     $pThumb = new PThumb($this->driverConf["THUMBNAIL_QUALITY"]);
                     if (!$pThumb->isError()) {
                         $pThumb->use_cache = $this->driverConf["USE_THUMBNAIL_CACHE"];
                         $pThumb->cache_dir = $this->driverConf["THUMBNAIL_CACHE_DIR"];
                         $pThumb->fit_thumbnail($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), 200);
                         if ($pThumb->isError()) {
                             print_r($pThumb->error_array);
                         }
                         exit(0);
                     }
                 }
                 $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), "image");
             }
             exit(0);
             break;
         case "mp3_proxy":
             if ($split = UserSelection::detectZip(SystemTextEncoding::fromUTF8($file))) {
                 require_once "server/classes/pclzip.lib.php";
                 $zip = new PclZip($this->getPath() . $split[0]);
                 $data = $zip->extract(PCLZIP_OPT_BY_NAME, substr($split[1], 1), PCLZIP_OPT_EXTRACT_AS_STRING);
                 header("Content-Type: audio/mp3; name=\"" . basename($split[1]) . "\"");
                 header("Content-Length: " . strlen($data[0]["content"]));
                 print $data[0]["content"];
             } else {
                 $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), "mp3");
             }
             exit(0);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit":
             if (isset($save) && $save == 1 && isset($code)) {
                 // Reload "code" variable directly from POST array, do not "securePath"...
                 $code = $_POST["code"];
                 AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file)));
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
                 $fileName = $this->getPath() . SystemTextEncoding::fromUTF8("/{$file}");
                 if (!is_file($fileName) || !is_writable($fileName)) {
                     header("Content-Type:text/plain");
                     print !is_writable($fileName) ? "1001" : "1002";
                     exit(1);
                 }
                 $fp = fopen($fileName, "w");
                 fputs($fp, $code);
                 fclose($fp);
                 header("Content-Type:text/plain");
                 print $mess[115];
             } else {
                 $this->readFile($this->getPath() . "/" . SystemTextEncoding::fromUTF8($file), "plain");
             }
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             if ($selection->inZip()) {
                 $tmpDir = dirname($selection->getZipPath()) . "/.tmpExtractDownload";
                 @mkdir($this->getPath() . "/" . $tmpDir);
                 $this->convertSelectionToTmpFiles($tmpDir, $selection);
                 if (is_dir($tmpDir)) {
                     $this->deldir($this->getPath() . "/" . $tmpDir);
                 }
             }
             $success = $error = array();
             $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $action == "move" ? true : false);
             if (count($error)) {
                 $errorMessage = join("\n", $error);
             } else {
                 $logMessage = join("\n", $success);
                 AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest));
             }
             $reload_current_node = true;
             if (isset($dest_node)) {
                 $reload_dest_node = $dest_node;
             }
             $reload_file_list = true;
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $logMessages = array();
             $errorMessage = $this->delete($selection->getFiles(), $logMessages);
             if (count($logMessages)) {
                 $logMessage = join("\n", $logMessages);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reload_current_node = true;
             $reload_file_list = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $file = SystemTextEncoding::fromUTF8($file);
             $filename_new = SystemTextEncoding::fromUTF8($filename_new);
             $error = $this->rename($file, $filename_new);
             if ($error != null) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reload_current_node = true;
             $reload_file_list = basename($filename_new);
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = Utils::processFileName(SystemTextEncoding::fromUTF8($dirname));
             $error = $this->mkDir($dir, $dirname);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $reload_file_list = $dirname;
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_current_node = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = Utils::processFileName(SystemTextEncoding::fromUTF8($filename));
             $error = $this->createEmptyFile($dir, $filename);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_file_list = $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //	CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $messtmp = "";
             $files = $selection->getFiles();
             $changedFiles = array();
             foreach ($files as $fileName) {
                 $error = $this->chmod($this->getPath() . $fileName, $chmod_value, $recursive == "on", $recursive == "on" ? $recur_apply_to : "both", $changedFiles);
             }
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             //$messtmp.="$mess[34] ".SystemTextEncoding::toUTF8($filename)." $mess[39] ";
             $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($changedFiles) . " files or folders";
             $reload_file_list = $dir;
             AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($changedFiles)));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             $fancyLoader = false;
             if (isset($fileVars["Filedata"])) {
                 $fancyLoader = true;
                 if ($dir != "") {
                     $dir = "/" . base64_decode($dir);
                 }
             }
             if ($dir != "") {
                 $rep_source = "/{$dir}";
             } else {
                 $rep_source = "";
             }
             $destination = SystemTextEncoding::fromUTF8($this->getPath() . $rep_source);
             if (!$this->isWriteable($destination)) {
                 global $_GET;
                 $errorMessage = "{$mess['38']} " . SystemTextEncoding::toUTF8($dir) . " {$mess['99']}.";
                 if ($fancyLoader || isset($_GET["ajxp_sessid"])) {
                     header('HTTP/1.0 412 ' . $errorMessage);
                     die('Error 412 ' . $errorMessage);
                 } else {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');";
                     break;
                 }
             }
             $logMessage = "";
             foreach ($fileVars as $boxName => $boxData) {
                 if ($boxName != "Filedata" && substr($boxName, 0, 9) != "userfile_") {
                     continue;
                 }
                 if ($boxName == "Filedata") {
                     $fancyLoader = true;
                 }
                 $err = Utils::parseFileDataErrors($boxData, $fancyLoader);
                 if ($err != null) {
                     $errorMessage = $err;
                     break;
                 }
                 $userfile_name = $boxData["name"];
                 if ($fancyLoader) {
                     $userfile_name = SystemTextEncoding::fromUTF8($userfile_name);
                 }
                 $userfile_name = Utils::processFileName($userfile_name);
                 if (isset($auto_rename)) {
                     $userfile_name = fsDriver::autoRenameForDest($destination, $userfile_name);
                 }
                 if (!move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name)) {
                     $errorMessage = ($fancyLoader ? "411 " : "") . "{$mess['33']} " . $userfile_name;
                     break;
                 }
                 $this->changeMode($destination . "/" . $userfile_name);
                 $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
                 AJXP_Logger::logAction("Upload File", array("file" => SystemTextEncoding::fromUTF8($dir) . "/" . $userfile_name));
             }
             if ($fancyLoader) {
                 if (isset($errorMessage)) {
                     header('HTTP/1.0 ' . $errorMessage);
                     die('Error ' . $errorMessage);
                 } else {
                     header('HTTP/1.0 200 OK');
                     die("200 OK");
                 }
             } else {
                 print "<html><script language=\"javascript\">\n";
                 if (isset($errorMessage)) {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');";
                 } else {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext();";
                 }
                 print "</script></html>";
             }
             exit;
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = SystemTextEncoding::fromUTF8($file);
             $url = $this->makePubliclet($file, $password, $expiration);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             if (isset($skipZip) && $skipZip == "true") {
                 $skipZip = true;
             } else {
                 $skipZip = false;
             }
             if ($test = UserSelection::detectZip($dir)) {
                 $liste = array();
                 $zip = $this->zipListing($test[0], $test[1], $liste);
                 AJXP_XMLWriter::header();
                 $tmpDir = $this->getPath() . dirname($test[0]) . ".tmpZipExtract";
                 foreach ($liste as $zipEntry) {
                     $atts = array();
                     if (!$fileListMode && !$zipEntry["folder"]) {
                         continue;
                     }
                     $atts[] = "is_file=\"" . ($zipEntry["folder"] ? "false" : "true") . "\"";
                     $atts[] = "text=\"" . Utils::xmlEntities(basename(SystemTextEncoding::toUTF8($zipEntry["stored_filename"]))) . "\"";
                     $atts[] = "filename=\"" . Utils::xmlEntities(SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     if ($fileListMode) {
                         $atts[] = "filesize=\"" . Utils::roundSize($zipEntry["size"]) . "\"";
                         $atts[] = "bytesize=\"" . $zipEntry["size"] . "\"";
                         $atts[] = "ajxp_modiftime=\"" . $zipEntry["mtime"] . "\"";
                         $atts[] = "mimestring=\"" . Utils::mimetype($zipEntry["stored_filename"], "mime", $zipEntry["folder"]) . "\"";
                         $atts[] = "icon=\"" . Utils::mimetype($zipEntry["stored_filename"], "image", $zipEntry["folder"]) . "\"";
                         $is_image = Utils::is_image(basename($zipEntry["stored_filename"]));
                         $atts[] = "is_image=\"" . $is_image . "\"";
                         if ($is_image) {
                             if (!is_dir($tmpDir)) {
                                 mkdir($tmpDir);
                             }
                             $currentFile = $tmpDir . "/" . basename($zipEntry["stored_filename"]);
                             $data = $zip->extract(PCLZIP_OPT_BY_NAME, $zipEntry["stored_filename"], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $tmpDir);
                             list($width, $height, $type, $attr) = @getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                             unlink($currentFile);
                         }
                     } else {
                         $atts[] = "icon=\"client/images/foldericon.png\"";
                         $atts[] = "openicon=\"client/images/foldericon.png\"";
                         $atts[] = "src=\"content.php?dir=" . urlencode(SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     }
                     print "<tree " . join(" ", $atts) . "/>";
                 }
                 if (is_dir($tmpDir)) {
                     rmdir($tmpDir);
                 }
                 AJXP_XMLWriter::close();
                 exit(0);
             }
             $nom_rep = $this->initName($dir);
             AJXP_Exception::errorToXml($nom_rep);
             $threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
             if (!isset($threshold) || intval($threshold) == 0) {
                 $threshold = 500;
             }
             $limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
             if (!isset($limitPerPage) || intval($limitPerPage) == 0) {
                 $limitPerPage = 200;
             }
             if ($fileListMode) {
                 $countFiles = $this->countFiles($nom_rep);
                 if ($countFiles > $threshold) {
                     $offset = 0;
                     $crtPage = 1;
                     if (isset($page)) {
                         $offset = (intval($page) - 1) * $limitPerPage;
                         $crtPage = $page;
                     }
                     $totalPages = floor($countFiles / $limitPerPage) + 1;
                     $reps = $this->listing($nom_rep, false, $offset, $limitPerPage);
                 } else {
                     $reps = $this->listing($nom_rep, $searchMode);
                 }
             } else {
                 $countFolders = $this->countFiles($nom_rep, true);
                 if ($countFolders > $threshold) {
                     AJXP_XMLWriter::header();
                     $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                     $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                     $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\"";
                     print "<tree text=\"{$mess['306']} ({$countFolders})...\" {$attributes}></tree>";
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
                 $reps = $this->listing($nom_rep, !$searchMode);
             }
             //$reps = $result[0];
             AJXP_XMLWriter::header();
             if (isset($totalPages) && isset($crtPage)) {
                 //print '<columns switchDisplayMode="list" switchGridMode="filelist"/>';
                 print '<pagination count="' . $countFiles . '" total="' . $totalPages . '" current="' . $crtPage . '"/>';
             }
             foreach ($reps as $repIndex => $repName) {
                 if (preg_match("/\\.zip\$/", $repName) && $skipZip) {
                     continue;
                 }
                 $attributes = "";
                 if ($searchMode) {
                     if (is_file($nom_rep . "/" . $repIndex)) {
                         $attributes = "is_file=\"true\" icon=\"{$repName}\"";
                         $repName = $repIndex;
                     }
                 } else {
                     if ($fileListMode) {
                         $currentFile = $nom_rep . "/" . $repIndex;
                         $atts = array();
                         $atts[] = "is_file=\"" . (is_file($currentFile) ? "1" : "0") . "\"";
                         $atts[] = "is_image=\"" . Utils::is_image($currentFile) . "\"";
                         $fGroup = @filegroup($currentFile) || "unknown";
                         $atts[] = "file_group=\"" . $fGroup . "\"";
                         $fOwner = @fileowner($currentFile) || "unknown";
                         $atts[] = "file_owner=\"" . $fOwner . "\"";
                         $fPerms = @fileperms($currentFile);
                         if ($fPerms !== false) {
                             $fPerms = substr(decoct($fPerms), is_file($currentFile) ? 2 : 1);
                         } else {
                             $fPerms = '0000';
                         }
                         $atts[] = "file_perms=\"" . $fPerms . "\"";
                         if (Utils::is_image($currentFile)) {
                             list($width, $height, $type, $attr) = @getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                         }
                         $atts[] = "mimestring=\"" . Utils::mimetype($currentFile, "type", is_dir($currentFile)) . "\"";
                         $datemodif = $this->date_modif($currentFile);
                         $atts[] = "ajxp_modiftime=\"" . ($datemodif ? $datemodif : "0") . "\"";
                         $bytesize = @filesize($currentFile) or 0;
                         if ($bytesize < 0) {
                             $bytesize = sprintf("%u", $bytesize);
                         }
                         $atts[] = "filesize=\"" . Utils::roundSize($bytesize) . "\"";
                         $atts[] = "bytesize=\"" . $bytesize . "\"";
                         $atts[] = "filename=\"" . Utils::xmlEntities(SystemTextEncoding::toUTF8($dir . "/" . $repIndex)) . "\"";
                         $atts[] = "icon=\"" . (is_file($currentFile) ? SystemTextEncoding::toUTF8($repName) : (is_dir($currentFile) ? "folder.png" : "mime-empty.png")) . "\"";
                         $attributes = join(" ", $atts);
                         $repName = $repIndex;
                     } else {
                         $folderBaseName = Utils::xmlEntities($repName);
                         $link = SystemTextEncoding::toUTF8(SERVER_ACCESS . "?dir=" . $dir . "/" . $folderBaseName);
                         $link = urlencode($link);
                         $folderFullName = Utils::xmlEntities($dir) . "/" . $folderBaseName;
                         $parentFolderName = $dir;
                         if (!$completeMode) {
                             $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                             $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                             if (preg_match("/\\.zip\$/", $repName)) {
                                 $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png";
                             }
                             $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\" filename=\"" . SystemTextEncoding::toUTF8($folderFullName) . "\" src=\"{$link}\"";
                         }
                     }
                 }
                 print "<tree text=\"" . Utils::xmlEntities(SystemTextEncoding::toUTF8($repName)) . "\" {$attributes}>";
                 print "</tree>";
             }
             // ADD RECYCLE BIN TO THE LIST
             if ($nom_rep == $this->repository->getOption("PATH") && RecycleBinManager::recycleEnabled() && !$completeMode && !$skipZip) {
                 $recycleBinOption = $this->repository->getOption("RECYCLE_BIN");
                 if (is_dir($this->repository->getOption("PATH") . "/" . $recycleBinOption)) {
                     $recycleIcon = $this->countFiles($this->repository->getOption("PATH") . "/" . $recycleBinOption, false, true) > 0 ? "trashcan_full.png" : "trashcan.png";
                     if ($fileListMode) {
                         print "<tree text=\"" . Utils::xmlEntities($mess[122]) . "\" filesize=\"-\" is_file=\"0\" is_recycle=\"1\" mimestring=\"Trashcan\" ajxp_modiftime=\"" . $this->date_modif($this->repository->getOption("PATH") . "/" . $recycleBinOption) . "\" filename=\"/" . $recycleBinOption . "\" icon=\"{$recycleIcon}\"></tree>";
                     } else {
                         print "<tree text=\"{$mess['122']}\" is_recycle=\"true\" icon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/{$recycleIcon}\"  openIcon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/{$recycleIcon}\" filename=\"/" . $recycleBinOption . "\"/>";
                     }
                 }
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
Exemplo n.º 2
0
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue));
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     $recycleBinOption = $this->repository->getOption("RECYCLE_BIN");
     // FILTER ACTION FOR DELETE
     if ($recycleBinOption != "" && $action == "delete" && $dir != "/" . $recycleBinOption) {
         $action = "move";
         $dest = "/" . $recycleBinOption;
         $dest_node = "AJAXPLORER_RECYCLE_NODE";
     }
     // FILTER ACTION FOR RESTORE
     if ($recycleBinOption != "" && $action == "restore" && $dir == "/" . $recycleBinOption) {
         $originalRep = RecycleBinManager::getFileOrigin($selection->getUniqueFile());
         if ($originalRep != "") {
             $action = "move";
             $dest = $originalRep;
         }
     }
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD, IMAGE & MP3 PROXYS
         //------------------------------------
         case "download":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             $zip = false;
             if ($selection->isUnique()) {
                 if (is_dir($this->getPath() . "/" . $selection->getUniqueFile())) {
                     $zip = true;
                     $dir .= "/" . basename($selection->getUniqueFile());
                 }
             } else {
                 $zip = true;
             }
             if ($zip) {
                 // Make a temp zip and send it as download
                 $this->downFile($this->makeName($selection->getFiles()), "force-download", "archive.zip");
             } else {
                 $this->downFile($this->makeName($selection->getUniqueFile()), "force-download", $selection->getUniqueFile());
             }
             exit(0);
             break;
         case "image_proxy":
             $this->downFile($this->makeName($file), "image", $file);
             exit(0);
             break;
         case "mp3_proxy":
             $this->downFile($this->makeName($file), "mp3", $file);
             exit(0);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit":
             if (isset($save) && $save == 1) {
                 AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file)));
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
                 $this->SSHOperation->setRemoteContent($this->makeName($file), $code);
                 echo $mess[115];
             } else {
                 $this->sendFile($this->SSHOperation->getRemoteContent($this->makeName($file)), "plain", $file);
             }
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $result = "";
             if ($action == "move") {
                 $result = $this->SSHOperation->moveFile($this->makeName($selection->getFiles()), $this->makeName($dest));
             } else {
                 $result = $this->SSHOperation->copyFile($this->makeName($selection->getFiles()), $this->makeName($dest));
             }
             $mess = ConfService::getMessages();
             if (strlen($result)) {
                 $errorMessage = $mess[114];
             } else {
                 foreach ($selection->getFiles() as $files) {
                     $logMessage .= $mess[34] . " " . SystemTextEncoding::toUTF8(basename($file)) . " " . $mess[$action == "move" ? 74 : 73] . " " . SystemTextEncoding::toUTF8($dest) . "\n";
                 }
                 AJXP_Logger::logAction($action == "move" ? "Move" : "Copy", array("files" => $selection, "destination" => $dest));
             }
             $reload_current_node = true;
             if (isset($dest_node)) {
                 $reload_dest_node = $dest_node;
             }
             $reload_file_list = true;
             break;
             //------------------------------------
             //  CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //  CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $messtmp = "";
             $changedFiles = array();
             $value = "0" . decoct(octdec(ltrim($chmod_value, "0")));
             // On error, the command will fail
             $result = $this->SSHOperation->chmodFile($this->makeName($selection->getFiles()), $chmod_value);
             $mess = ConfService::getMessages();
             if (strlen($result)) {
                 $errorMessage = $mess[114];
             } else {
                 $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($selection->getFiles()) . " files or folders";
                 AJXP_Logger::logAction("Chmod", array("dir" => $dir, "filesCount" => count($selection->getFiles())));
                 $reload_file_list = $dir;
             }
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $logMessages = array();
             $result = $this->SSHOperation->deleteFile($this->makeName($selection->getFiles()));
             if (strlen($result)) {
                 $mess = ConfService::getMessages();
                 $errorMessage = $mess[120];
             } else {
                 $mess = ConfService::getMessages();
                 foreach ($selection->getFiles() as $file) {
                     $logMessages[] = "{$mess['34']} " . SystemTextEncoding::toUTF8($file) . " {$mess['44']}.";
                 }
                 $logMessage = join("\n", $logMessages);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reload_current_node = true;
             $reload_file_list = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $filename_new = $dir . "/" . $filename_new;
             $error = $this->SSHOperation->moveFile($this->makeName($file), $this->makeName($filename_new));
             if ($error != null) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reload_current_node = true;
             $reload_file_list = basename($filename_new);
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = Utils::processFileName($dirname);
             $error = $this->SSHOperation->createRemoteDirectory($this->makeName($dir . "/" . $dirname));
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $reload_file_list = $dirname;
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_current_node = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = Utils::processFileName($filename);
             $error = $this->SSHOperation->setRemoteContent($this->makeName($dir . "/" . $filename), "");
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_file_list = $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             $fancyLoader = false;
             if (isset($fileVars["Filedata"])) {
                 $fancyLoader = true;
                 if ($dir != "") {
                     $dir = "/" . base64_decode($dir);
                 }
             }
             if ($dir != "") {
                 $rep_source = "/{$dir}";
             } else {
                 $rep_source = "";
             }
             $destination = $rep_source;
             $logMessage = "";
             //$fancyLoader = false;
             foreach ($fileVars as $boxName => $boxData) {
                 if ($boxName != "Filedata" && substr($boxName, 0, 9) != "userfile_") {
                     continue;
                 }
                 if ($boxName == "Filedata") {
                     $fancyLoader = true;
                 }
                 $err = Utils::parseFileDataErrors($boxData, $fancyLoader);
                 if ($err != null) {
                     $errorMessage = $err;
                     break;
                 }
                 $userfile_name = $boxData["name"];
                 $userfile_name = Utils::processFileName($userfile_name);
                 if (!$this->SSHOperation->uploadFile($boxData["tmp_name"], $this->makeName($destination . "/" . $userfile_name))) {
                     $errorMessage = ($fancyLoader ? "411 " : "") . "{$mess['33']} " . $userfile_name;
                     break;
                 }
                 $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
                 AJXP_Logger::logAction("Upload File", array("file" => $dir . "/" . $userfile_name));
             }
             if ($fancyLoader) {
                 if (isset($errorMessage)) {
                     header('HTTP/1.0 ' . $errorMessage);
                     die('Error ' . $errorMessage);
                 } else {
                     header('HTTP/1.0 200 OK');
                     die("200 OK");
                 }
             } else {
                 print "<html><script language=\"javascript\">\n";
                 if (isset($errorMessage)) {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext('" . str_replace("'", "\\'", $errorMessage) . "');";
                 } else {
                     print "\n if(parent.ajaxplorer.actionBar.multi_selector)parent.ajaxplorer.actionBar.multi_selector.submitNext();";
                 }
                 print "</script></html>";
             }
             exit;
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = SystemTextEncoding::fromUTF8($file);
             $url = $this->makePubliclet($file, $password, $expiration);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             $nom_rep = $dir;
             AJXP_Exception::errorToXml($nom_rep);
             $result = $this->SSHOperation->listFilesIn($nom_rep);
             AJXP_XMLWriter::header();
             foreach ($result as $file) {
                 $attributes = "";
                 $fileName = SystemTextEncoding::toUTF8($file["name"]);
                 $icon = Utils::mimetype($fileName, "image", $file["isDir"] == 1);
                 if ($searchMode) {
                     if ($file["isDir"] == 0) {
                         $attributes = "is_file=\"true\" icon=\"" . SystemTextEncoding::toUTF8($icon) . "\"";
                     }
                 } else {
                     if ($fileListMode) {
                         $atts = array();
                         $atts[] = "is_file=\"" . (1 - $file["isDir"]) . "\"";
                         $atts[] = "is_image=\"" . Utils::is_image($fileName) . "\"";
                         $atts[] = "mimestring=\"" . Utils::mimetype($fileName, "type", $file["isDir"] == 1) . "\"";
                         $atts[] = "ajxp_modiftime=\"" . $this->dateModif($file["time"]) . "\"";
                         $atts[] = "filesize=\"" . Utils::roundSize($file["size"]) . "\"";
                         $atts[] = "bytesize=\"" . $file["size"] . "\"";
                         $atts[] = "filename=\"" . str_replace("&", "&amp;", $dir . "/" . $fileName) . "\"";
                         $atts[] = "icon=\"" . ($file["isDir"] == 1 ? "folder.png" : SystemTextEncoding::toUTF8($icon)) . "\"";
                         $attributes = join(" ", $atts);
                     } else {
                         if ($file["isDir"] == 1) {
                             $link = SERVER_ACCESS . "?dir=" . $dir . "/" . $fileName;
                             $link = urlencode($link);
                             $folderBaseName = str_replace("&", "&amp;", $fileName);
                             $folderFullName = "{$dir}/" . $folderBaseName;
                             $parentFolderName = $dir;
                             if (!$completeMode) {
                                 $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                                 $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                                 if (preg_match("/\\.zip\$/", $file["name"])) {
                                     $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png";
                                 }
                                 $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\" filename=\"" . $folderFullName . "\" src=\"{$link}\"";
                             }
                         }
                     }
                 }
                 if (strlen($attributes) > 0) {
                     print "<tree text=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($this->SSHOperation->unescapeFileName($file["name"]))) . "\" {$attributes}>";
                     print "</tree>";
                 }
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
Exemplo n.º 3
0
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath(SystemTextEncoding::magicDequote($getValue));
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     if (class_exists("RecycleBinManager")) {
         $newArgs = RecycleBinManager::filterActions($action, $selection, $dir);
         foreach ($newArgs as $argName => $argValue) {
             ${$argName} = $argValue;
         }
     }
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD, IMAGE & MP3 PROXYS
         //------------------------------------
         case "download":
         case "image_proxy":
         case "mp3_proxy":
             AJXP_Logger::logAction("Download", array("files" => $selection));
             $this->sendRemoteFile($selection->files[0], $action == "download");
             exit(0);
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit":
             $file_name = basename($file);
             $this->ftp_get_contents($file);
             if (isset($save) && $save == 1 && isset($code)) {
                 // Reload "code" variable directly from POST array, do not "securePath"...
                 $code = $_POST["code"];
                 AJXP_Logger::logAction("Online Edition", array("file" => SystemTextEncoding::fromUTF8($file_name)));
                 $code = stripslashes($code);
                 $code = str_replace("&lt;", "<", $code);
                 $fp = fopen("files/" . SystemTextEncoding::fromUTF8("{$file_name}"), "w");
                 fputs($fp, $code);
                 fclose($fp);
                 echo $mess[115];
                 ftp_put($this->connect, $this->secureFtpPath($this->getPath() . $file), "files/" . SystemTextEncoding::fromUTF8($file_name), FTP_BINARY);
                 $this->ftpRemoveFileTmp("files/" . SystemTextEncoding::fromUTF8("{$file_name}"));
                 $reload_current_node = true;
             } else {
                 $this->readFile("files/" . SystemTextEncoding::fromUTF8($file_name), "plain");
             }
             exit(0);
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $action == "move" ? true : false);
             if (count($error)) {
                 $errorMessage = join("\n", $error);
             } else {
                 $logMessage = join("\n", $success);
             }
             $reload_current_node = true;
             if (isset($dest_node)) {
                 $reload_dest_node = $dest_node;
             }
             $reload_file_list = true;
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 $errorMessage = $mess[113];
                 break;
             }
             $logMessages = array();
             $errorMessage = $this->delete($selection->getFiles(), $logMessages, $dir);
             if (count($logMessages)) {
                 $logMessage = join("\n", $logMessages);
             }
             AJXP_Logger::logAction("Delete", array("files" => $selection));
             $reload_current_node = true;
             $reload_file_list = true;
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "rename":
             $file = SystemTextEncoding::fromUTF8($file);
             $filename_new = SystemTextEncoding::fromUTF8($filename_new);
             $error = $this->rename($file, $filename_new);
             if ($error != null) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             $reload_current_node = true;
             $reload_file_list = basename($filename_new);
             AJXP_Logger::logAction("Rename", array("original" => $file, "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             $dirname = Utils::processFileName(SystemTextEncoding::fromUTF8($dirname));
             $error = $this->mkDir($dir, $dirname);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $reload_file_list = $dirname;
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_current_node = true;
             AJXP_Logger::logAction("Create Dir", array("dir" => $dir . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             $filename = Utils::processFileName(SystemTextEncoding::fromUTF8($filename));
             $error = $this->createEmptyFile($dir, $filename);
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             $reload_file_list = $filename;
             AJXP_Logger::logAction("Create File", array("file" => $dir . "/" . $filename));
             break;
             //------------------------------------
             //	CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //	CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $files = $selection->getFiles();
             if (@ftp_chmod($this->connect, $chmod_value, $this->getPath() . $files[0]) === false) {
                 $error = "Error chmod";
             }
             if (isset($error)) {
                 $errorMessage = $error;
                 break;
             }
             $logMessage = "Successfully changed permission to " . $chmod_value . " for " . $files[0];
             $reload_file_list = $dir;
             AJXP_Logger::logAction("Chmod", array("dir" => $dir, "file" => $files[0]));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             break;
             //------------------------------------
             // Public URL
             //------------------------------------
         //------------------------------------
         // Public URL
         //------------------------------------
         case "public_url":
             $file = SystemTextEncoding::fromUTF8($file);
             $url = $this->makePubliclet($file, $password, $expiration);
             header("Content-type:text/plain");
             echo $url;
             exit(1);
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             if (isset($skipZip) && $skipZip == "true") {
                 $skipZip = true;
             } else {
                 $skipZip = false;
             }
             if ($test = UserSelection::detectZip($dir)) {
                 $liste = array();
                 $zip = $this->zipListing($test[0], $test[1], $liste);
                 AJXP_XMLWriter::header();
                 $tmpDir = $this->getPath() . dirname($test[0]) . ".tmpZipExtract";
                 foreach ($liste as $zipEntry) {
                     $atts = array();
                     if (!$fileListMode && !$zipEntry["folder"]) {
                         continue;
                     }
                     $atts[] = "is_file=\"" . ($zipEntry["folder"] ? "false" : "true") . "\"";
                     $atts[] = "text=\"" . str_replace("&", "&amp;", basename(SystemTextEncoding::toUTF8($zipEntry["stored_filename"]))) . "\"";
                     $atts[] = "filename=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     if ($fileListMode) {
                         $atts[] = "filesize=\"" . Utils::roundSize($zipEntry["size"]) . "\"";
                         $atts[] = "bytesize=\"" . $zipEntry["size"] . "\"";
                         $atts[] = "ajxp_modiftime=\"" . $zipEntry["mtime"] . "\"";
                         $atts[] = "mimestring=\"" . Utils::mimetype($zipEntry["stored_filename"], "mime", $zipEntry["folder"]) . "\"";
                         $atts[] = "icon=\"" . Utils::mimetype($zipEntry["stored_filename"], "image", $zipEntry["folder"]) . "\"";
                         $is_image = Utils::is_image(basename($zipEntry["stored_filename"]));
                         $atts[] = "is_image=\"" . $is_image . "\"";
                         if ($is_image) {
                             if (!is_dir($tmpDir)) {
                                 mkdir($tmpDir);
                             }
                             $currentFile = $tmpDir . "/" . basename($zipEntry["stored_filename"]);
                             $data = $zip->extract(PCLZIP_OPT_BY_NAME, $zipEntry["stored_filename"], PCLZIP_OPT_REMOVE_ALL_PATH, PCLZIP_OPT_PATH, $tmpDir);
                             list($width, $height, $type, $attr) = @getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                             unlink($currentFile);
                         }
                     } else {
                         $atts[] = "icon=\"client/images/foldericon.png\"";
                         $atts[] = "openicon=\"client/images/foldericon.png\"";
                         $atts[] = "src=\"content.php?dir=" . urlencode(SystemTextEncoding::toUTF8($zipEntry["filename"])) . "\"";
                     }
                     print "<tree " . join(" ", $atts) . "/>";
                     if (is_dir($tmpDir)) {
                         rmdir($tmpDir);
                     }
                 }
                 AJXP_XMLWriter::close();
                 exit(0);
             }
             $nom_rep = $this->initName($dir);
             AJXP_Exception::errorToXml($nom_rep);
             $result = $this->listing($nom_rep, !($searchMode || $fileListMode));
             $this->fileListData = $result[0];
             $reps = $result[0];
             AJXP_XMLWriter::header();
             if (!is_array($reps)) {
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             foreach ($reps as $repIndex => $repName) {
                 if (is_string($repName) && (preg_match("/\\.zip\$/", $repName) && $skipZip)) {
                     continue;
                 }
                 $attributes = "";
                 if ($searchMode) {
                     if (is_file($nom_rep . "/" . $repIndex)) {
                         $attributes = "is_file=\"true\" icon=\"{$repName}\"";
                         $repName = $repIndex;
                     }
                 } else {
                     if ($fileListMode) {
                         $currentFile = $nom_rep . "/" . $repName['name'];
                         $atts = array();
                         $atts[] = "is_file=\"" . ($repName['isDir'] ? "0" : "1") . "\"";
                         $atts[] = "is_image=\"" . Utils::is_image($currentFile) . "\"";
                         $atts[] = "file_group=\"" . $repName['group'] . "\"";
                         $atts[] = "file_owner=\"" . $repName['owner'] . "\"";
                         $atts[] = "file_perms=\"" . $repName['chmod1'] . "\"";
                         if (Utils::is_image($currentFile)) {
                             list($width, $height, $type, $attr) = $this->getimagesize($currentFile);
                             $atts[] = "image_type=\"" . image_type_to_mime_type($type) . "\"";
                             $atts[] = "image_width=\"{$width}\"";
                             $atts[] = "image_height=\"{$height}\"";
                         }
                         $atts[] = "mimestring=\"" . $repName['type'] . "\"";
                         $datemodif = $repName['modifTime'];
                         $atts[] = "ajxp_modiftime=\"" . ($datemodif ? $datemodif : "0") . "\"";
                         $bytesize = $repName['size'] or 0;
                         if ($bytesize < 0) {
                             $bytesize = sprintf("%u", $bytesize);
                         }
                         $atts[] = "filesize=\"" . Utils::roundSize($bytesize) . "\"";
                         $atts[] = "bytesize=\"" . $bytesize . "\"";
                         $atts[] = "filename=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($dir . "/" . $repIndex)) . "\"";
                         $atts[] = "icon=\"" . $repName['icon'] . "\"";
                         $attributes = join(" ", $atts);
                         $repName = $repIndex;
                     } else {
                         //Menu treeview repertoire
                         $folderBaseName = str_replace("&", "&amp;", $repName['name']);
                         $link = SystemTextEncoding::toUTF8(SERVER_ACCESS . "?dir=" . $dir . "/" . $folderBaseName);
                         $link = urlencode($link);
                         $folderFullName = str_replace("&", "&amp;", $dir) . "/" . $folderBaseName;
                         $parentFolderName = $dir;
                         $repName = $repIndex;
                         if (!$completeMode) {
                             $icon = CLIENT_RESOURCES_FOLDER . "/images/foldericon.png";
                             $openicon = CLIENT_RESOURCES_FOLDER . "/images/openfoldericon.png";
                             if (preg_match("/\\.zip\$/", $repName)) {
                                 $icon = $openicon = CLIENT_RESOURCES_FOLDER . "/images/crystal/actions/16/accessories-archiver.png";
                             }
                             $attributes = "icon=\"{$icon}\"  openicon=\"{$openicon}\" filename=\"" . SystemTextEncoding::toUTF8($folderFullName) . "\" src=\"{$link}\"";
                         }
                     }
                 }
                 print "<tree text=\"" . str_replace("&", "&amp;", SystemTextEncoding::toUTF8($repName)) . "\" {$attributes}>";
                 print "</tree>";
             }
             // ADD RECYCLE BIN TO THE LIST
             if ($nom_rep == $this->repository->getOption("PATH") && RecycleBinManager::recycleEnabled() && !$completeMode && !$skipZip) {
                 $recycleBinOption = $this->repository->getOption("RECYCLE_BIN");
                 if ($fileListMode) {
                     print "<tree text=\"" . Utils::xmlEntities($mess[122]) . "\" filesize=\"-\" is_file=\"0\" is_recycle=\"1\" mimestring=\"Trashcan\" ajxp_modiftime=\"\" filename=\"/" . $recycleBinOption . "\" icon=\"trashcan.png\"></tree>";
                 } else {
                     print "<tree text=\"{$mess['122']}\" is_recycle=\"true\" icon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/trashcan.png\"  openIcon=\"" . CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/trashcan.png\" filename=\"/" . $recycleBinOption . "\"/>";
                 }
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     $repo = ConfService::getRepository();
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath($getValue);
     }
     $selection = new UserSelection();
     $selection->initFromHttpVars($httpVars);
     if (isset($dir) && $action != "upload") {
         $safeDir = $dir;
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     // FILTER DIR PAGINATION ANCHOR
     if (isset($dir) && strstr($dir, "#") !== false) {
         $parts = split("#", $dir);
         $dir = $parts[0];
         $page = $parts[1];
     }
     if (isset($dest)) {
         $dest = SystemTextEncoding::fromUTF8($dest);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "edit_record":
             $isNew = false;
             if (isset($record_is_new) && $record_is_new == "true") {
                 $isNew = true;
             }
             $tableName = $_POST["table_name"];
             $pkName = $_POST["pk_name"];
             $query = "";
             $arrValues = array();
             foreach ($_POST as $key => $value) {
                 if (substr($key, 0, strlen("ajxp_mysql_")) == "ajxp_mysql_") {
                     $newKey = substr($key, strlen("ajxp_mysql_"));
                     $arrValues[$newKey] = $value;
                 }
             }
             if ($isNew) {
                 $string = "";
                 $index = 0;
                 foreach ($arrValues as $k => $v) {
                     // CHECK IF AUTO KEY!!!
                     $string .= "'" . addslashes(SystemTextEncoding::fromUTF8($v)) . "'";
                     if ($index < count($arrValues) - 1) {
                         $string .= ",";
                     }
                     $index++;
                 }
                 $query = "INSERT INTO {$tableName} VALUES ({$string})";
             } else {
                 $string = "";
                 $index = 0;
                 foreach ($arrValues as $k => $v) {
                     if ($k == $pkName) {
                         $pkValue = $v;
                     } else {
                         $string .= $k . "='" . addslashes(SystemTextEncoding::fromUTF8($v)) . "'";
                         if ($index < count($arrValues) - 1) {
                             $string .= ",";
                         }
                     }
                     $index++;
                 }
                 $query = "UPDATE {$tableName} SET {$string} WHERE {$pkName}='{$pkValue}'";
             }
             $link = $this->createDbLink();
             $res = $this->execQuery($query);
             $this->closeDbLink($link);
             if (is_a($res, "AJXP_Exception")) {
                 $errorMessage = $res->messageId;
             } else {
                 $logMessage = $query;
                 $reload_file_list = true;
             }
             break;
             //------------------------------------
             //	CHANGE COLUMNS OR CREATE TABLE
             //------------------------------------
         //------------------------------------
         //	CHANGE COLUMNS OR CREATE TABLE
         //------------------------------------
         case "edit_table":
             $link = $this->createDbLink();
             if (isset($httpVars["current_table"])) {
                 if (isset($httpVars["delete_column"])) {
                     $query = "ALTER TABLE " . $httpVars["current_table"] . " DROP COLUMN " . $httpVars["delete_column"];
                     $res = $this->execQuery($query);
                     if (is_a($res, "AJXP_Exception")) {
                         $errorMessage = $res->messageId;
                     } else {
                         $logMessage = $query;
                         $reload_file_list = true;
                     }
                     $this->closeDbLink($link);
                     break;
                 }
                 if (isset($httpVars["add_column"])) {
                     $defString = $this->makeColumnDef($httpVars, "add_field_");
                     $query = "ALTER TABLE " . $httpVars["current_table"] . " ADD COLUMN ({$defString})";
                     if (isset($httpVars["add_field_pk"]) && $httpVars["add_field_pk"] == "1") {
                         $query .= ", ADD PRIMARY KEY (" . $httpVars["add_field_name"] . ")";
                     }
                     if (isset($httpVars["add_field_index"]) && $httpVars["add_field_index"] == "1") {
                         $query .= ", ADD INDEX (" . $httpVars["add_field_name"] . ")";
                     }
                     if (isset($httpVars["add_field_uniq"]) && $httpVars["add_field_uniq"] == "1") {
                         $query .= ", ADD UNIQUE (" . $httpVars["add_field_name"] . ")";
                     }
                     $res = $this->execQuery($query);
                     if (is_a($res, "AJXP_Exception")) {
                         $errorMessage = $res->messageId;
                     } else {
                         $logMessage = $query;
                         $reload_file_list = true;
                     }
                     $this->closeDbLink($link);
                     break;
                 }
             }
             $fields = array("origname", "name", "default", "null", "size", "type", "flags", "pk", "index", "uniq");
             $rows = array();
             foreach ($httpVars as $k => $val) {
                 $split = split("_", $k);
                 if (count($split) == 3 && $split[0] == "field" && is_numeric($split[2]) && in_array($split[1], $fields)) {
                     if (!isset($rows[intval($split[2])])) {
                         $rows[intval($split[2])] = array();
                     }
                     $rows[intval($split[2])][$split[1]] = $val;
                 }
             }
             if (isset($current_table)) {
                 $qMessage = '';
                 foreach ($rows as $row) {
                     $sizeString = $row["size"] != "" ? "(" . $row["size"] . ")" : "";
                     $defString = $row["default"] != "" ? " DEFAULT " . $row["default"] . "" : "";
                     $query = "ALTER TABLE {$current_table} CHANGE " . $row["origname"] . " " . $row["name"] . " " . $row["type"] . $sizeString . $defString . " " . $row["null"];
                     $res = $this->execQuery(trim($query));
                     if (is_a($res, "AJXP_Exception")) {
                         $errorMessage = $res->messageId;
                         $this->closeDbLink($link);
                         break;
                     } else {
                         $qMessage .= $query;
                         $reload_file_list = true;
                     }
                 }
                 $logMessage = $qMessage;
             } else {
                 if (isset($new_table)) {
                     $fieldsDef = "";
                     $pks = array();
                     $indexes = array();
                     $uniqs = array();
                     foreach ($rows as $index => $row) {
                         $fieldsDef .= $this->makeColumnDef($row);
                         // Analyse keys
                         if ($row["pk"] == "1") {
                             $pks[] = $row["name"];
                         }
                         if ($row["index"] == "1") {
                             $indexes[] = $row["name"];
                         }
                         if ($row["uniq"] == "1") {
                             $uniqs[] = $row["name"];
                         }
                         if ($index < count($rows) - 1) {
                             $fieldsDef .= ",";
                         }
                     }
                     if (count($pks)) {
                         $fieldsDef .= ",PRIMARY KEY (" . join(",", $pks) . ")";
                     }
                     if (count($indexes)) {
                         $fieldsDef .= ",INDEX (" . join(",", $indexes) . ")";
                     }
                     if (count($uniqs)) {
                         $fieldsDef .= ",UNIQUE (" . join(",", $uniqs) . ")";
                     }
                     $query = "CREATE TABLE {$new_table} ({$fieldsDef})";
                     $res = $this->execQuery(trim($query));
                     if (is_a($res, "AJXP_Exception")) {
                         $errorMessage = $res->messageId;
                     } else {
                         $logMessage = $query;
                         $reload_file_list = true;
                         $reload_current_node = true;
                     }
                 }
             }
             $this->closeDbLink($link);
             break;
             //------------------------------------
             //	SUPPRIMER / DELETE
             //------------------------------------
         //------------------------------------
         //	SUPPRIMER / DELETE
         //------------------------------------
         case "delete_table":
         case "delete_record":
             $dir = basename($dir);
             $link = $this->createDbLink();
             if (trim($dir) == "") {
                 // ROOT NODE => DROP TABLES
                 $tables = $selection->getFiles();
                 $query = "DROP TABLE";
                 foreach ($tables as $index => $tableName) {
                     $tables[$index] = basename($tableName);
                 }
                 $query .= " " . join(",", $tables);
                 $res = $this->execQuery($query);
                 $reload_current_node = true;
             } else {
                 // TABLE NODE => DELETE RECORDS
                 $tableName = $dir;
                 $pks = $selection->getFiles();
                 foreach ($pks as $key => $pkString) {
                     $parts = split("\\.", $pkString);
                     array_pop($parts);
                     // remove .pk extension
                     array_shift($parts);
                     // remove record prefix
                     foreach ($parts as $index => $pkPart) {
                         $parts[$index] = str_replace("__", "='", $pkPart) . "'";
                     }
                     $pks[$key] = "(" . implode(" AND ", $parts) . ")";
                 }
                 $query = "DELETE FROM {$tableName} WHERE " . implode(" OR ", $pks);
                 $res = $this->execQuery($query);
             }
             AJXP_Exception::errorToXml($res);
             if (is_a($res, "AJXP_Exception")) {
                 $errorMessage = $res->messageId;
             } else {
                 $logMessage = $query;
                 $reload_file_list = true;
             }
             $this->closeDbLink($link);
             break;
             //------------------------------------
             //	RENOMMER / RENAME
             //------------------------------------
         //------------------------------------
         //	RENOMMER / RENAME
         //------------------------------------
         case "set_query":
             $query = $httpVars["query"];
             $_SESSION["LAST_SQL_QUERY"] = $query;
             print "<tree store=\"true\"></tree>";
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $searchMode = $fileListMode = $completeMode = false;
             if (isset($mode)) {
                 if ($mode == "search") {
                     $searchMode = true;
                 } else {
                     if ($mode == "file_list") {
                         $fileListMode = true;
                     } else {
                         if ($mode == "complete") {
                             $completeMode = true;
                         }
                     }
                 }
             }
             $link = $this->createDbLink();
             AJXP_Exception::errorToXml($link);
             if ($dir == "") {
                 AJXP_XMLWriter::header();
                 $tables = $this->listTables();
                 print '<columns switchDisplayMode="list" switchGridMode="filelist"><column messageString="Table Name" attributeName="ajxp_label" sortType="String"/><column messageString="Byte Size" attributeName="bytesize" sortType="NumberKo"/><column messageString="Count" attributeName="count" sortType="Number"/></columns>';
                 $icon = $mode == "file_list" ? "sql_images/mimes/ICON_SIZE/table_empty.png" : "sql_images/mimes/ICON_SIZE/table_empty_tree.png";
                 foreach ($tables as $tableName) {
                     $size = $this->getSize($tableName);
                     $count = $this->getCount($tableName);
                     print "<tree is_file=\"0\" text=\"{$tableName}\" filename=\"/{$tableName}\" bytesize=\"{$size}\" count=\"{$count}\" icon=\"{$icon}\" ajxp_mime=\"table\" />";
                 }
                 print "<tree is_file=\"0\" text=\"Search Results\" ajxp_node=\"true\" filename=\"/ajxpmysqldriver_searchresults\" bytesize=\"-\" count=\"-\" icon=\"" . ($mode == "file_list" ? "search.png" : CLIENT_RESOURCES_FOLDER . "/images/crystal/mimes/16/search.png") . "\"/>";
                 AJXP_XMLWriter::close();
             } else {
                 $tableName = basename($dir);
                 if (isset($page)) {
                     $currentPage = $page;
                 } else {
                     $currentPage = 1;
                 }
                 $query = "SELECT * FROM {$tableName}";
                 $searchQuery = false;
                 if ($tableName == "ajxpmysqldriver_searchresults") {
                     if (isset($_SESSION["LAST_SQL_QUERY"])) {
                         $query = $_SESSION["LAST_SQL_QUERY"];
                         $matches = array();
                         if (preg_match("/SELECT [\\S, ]* FROM (\\S*).*/i", $query, $matches) !== false) {
                             $tableName = $matches[1];
                             $searchQuery = true;
                         } else {
                             break;
                         }
                     } else {
                         break;
                     }
                 }
                 if (isset($order_column)) {
                     $query .= " ORDER BY {$order_column} " . strtoupper($order_direction);
                     if (!isset($_SESSION["AJXP_ORDER_DATA"])) {
                         $_SESSION["AJXP_ORDER_DATA"] = array();
                     }
                     $_SESSION["AJXP_ORDER_DATA"][$this->repository->getUniqueId() . "_" . $tableName] = array("column" => $order_column, "dir" => $order_direction);
                 } else {
                     if (isset($_SESSION["AJXP_ORDER_DATA"])) {
                         if (isset($_SESSION["AJXP_ORDER_DATA"][$this->repository->getUniqueId() . "_" . $tableName])) {
                             $order_column = $_SESSION["AJXP_ORDER_DATA"][$this->repository->getUniqueId() . "_" . $tableName]["column"];
                             $order_direction = $_SESSION["AJXP_ORDER_DATA"][$this->repository->getUniqueId() . "_" . $tableName]["dir"];
                             $query .= " ORDER BY {$order_column} " . strtoupper($order_direction);
                         }
                     }
                 }
                 $result = $this->showRecords($query, $tableName, $currentPage);
                 if ($searchQuery && is_a($result, "AJXP_Exception")) {
                     unset($_SESSION["LAST_SQL_QUERY"]);
                     // Do not store wrong query!
                 }
                 AJXP_Exception::errorToXml($result);
                 AJXP_XMLWriter::header();
                 $blobCols = array();
                 print '<columns switchDisplayMode="list" switchGridMode="grid">';
                 foreach ($result["COLUMNS"] as $col) {
                     print "<column messageString=\"" . $col["NAME"] . "\" attributeName=\"" . $col["NAME"] . "\" field_name=\"" . $col["NAME"] . "\" field_type=\"" . $col["TYPE"] . "\" field_size=\"" . $col["LENGTH"] . "\" field_flags=\"" . $this->cleanFlagString($col["FLAGS"]) . "\" field_pk=\"" . (preg_match("/primary/", $col["FLAGS"]) ? "1" : "0") . "\" field_null=\"" . (preg_match("/not_null/", $col["FLAGS"]) ? "NOT_NULL" : "NULL") . "\" sortType=\"" . $this->sqlTypeToSortType($col["TYPE"]) . "\" field_default=\"" . $col["DEFAULT"] . "\"/>";
                     if (stristr($col["TYPE"], "blob") !== false && ($col["FLAGS"] != "" && stristr($col["FLAGS"], "binary"))) {
                         $blobCols[] = $col["NAME"];
                     }
                 }
                 print '</columns>';
                 print '<pagination total="' . $result["TOTAL_PAGES"] . '" current="' . $currentPage . '" remote_order="true" currentOrderCol="' . $order_column . '" currentOrderDir="' . $order_direction . '"/>';
                 foreach ($result["ROWS"] as $row) {
                     print '<tree ';
                     $pkString = "";
                     foreach ($row as $key => $value) {
                         if (in_array($key, $blobCols)) {
                             $sizeStr = "-NULL";
                             if (strlen($value)) {
                                 $sizeStr = "-" . Utils::roundSize(strlen($sizeStr));
                             }
                             print "{$key}=\"BLOB{$sizeStr}\" ";
                         } else {
                             $value = str_replace("\"", "", $value);
                             $value = Utils::xmlEntities($value);
                             print $key . '="' . SystemTextEncoding::toUTF8($value) . '" ';
                             if ($result["HAS_PK"] > 0) {
                                 if (in_array($key, $result["PK_FIELDS"])) {
                                     $pkString .= $key . "__" . $value . ".";
                                 }
                             }
                         }
                     }
                     if ($result["HAS_PK"] > 0) {
                         print 'filename="record.' . $pkString . 'pk" ';
                         print 'is_file="1" ajxp_mime="pk"/>';
                     } else {
                         print 'filename="record.no_pk" ';
                         print 'is_file="1" ajxp_mime="row"/>';
                     }
                 }
                 AJXP_XMLWriter::close();
             }
             $this->closeDbLink($link);
             exit(1);
             break;
     }
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if (isset($requireAuth)) {
         $xmlBuffer .= AJXP_XMLWriter::requireAuth(false);
     }
     if (isset($reload_current_node) && $reload_current_node == "true") {
         $xmlBuffer .= AJXP_XMLWriter::reloadCurrentNode(false);
     }
     if (isset($reload_dest_node) && $reload_dest_node != "") {
         $xmlBuffer .= AJXP_XMLWriter::reloadNode($reload_dest_node, false);
     }
     if (isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadFileList($reload_file_list, false);
     }
     return $xmlBuffer;
 }
 /**
  * @param $promptType
  * @param array $data
  * @param String $messageString
  * @param string|bool $messageId
  */
 public function __construct($promptType, $data, $messageString, $messageId = false)
 {
     $this->promptType = $promptType;
     $this->promptData = $data;
     parent::__construct($messageString, $messageId);
 }