예제 #1
0
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     switch ($action) {
         case "ls":
             $doc = DOMDocument::load($this->repository->getOption("HOST") . "?request=GetCapabilities");
             $xPath = new DOMXPath($doc);
             $dir = $httpVars["dir"];
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="wms.1" attributeName="ajxp_label" sortType="String"/><column messageId="wms.6" attributeName="srs" sortType="String"/><column messageId="wms.4" attributeName="style" sortType="String"/><column messageId="wms.5" attributeName="keywords" sortType="String"/></columns>');
             $layers = $xPath->query("Capability/Layer/Layer");
             // Detect "levels"
             $levels = array();
             $leafs = array();
             $styleLevels = $prefixLevels = false;
             foreach ($layers as $layer) {
                 $name = $xPath->evaluate("Name", $layer)->item(0)->nodeValue;
                 $stylesList = $xPath->query("Style/Name", $layer);
                 if (strstr($name, ":") !== false) {
                     $exp = explode(":", $name);
                     if (!isset($levels[$exp[0]])) {
                         $levels[$exp[0]] = array();
                     }
                     $levels[$exp[0]][] = $layer;
                     $prefixLevels = true;
                 } else {
                     if ($stylesList->length > 1) {
                         if (!isset($levels[$name])) {
                             $levels[$name] = array();
                         }
                         foreach ($stylesList as $style) {
                             $levels[$name][$style->nodeValue] = $layer;
                         }
                         $styleLevels = true;
                     } else {
                         $leafs[] = $layer;
                     }
                 }
             }
             if ($dir == "/" || $dir == "") {
                 $this->listLevels($levels);
                 $this->listLayers($leafs, $xPath);
             } else {
                 if (isset($levels[basename($dir)])) {
                     $this->listLayers($levels[basename($dir)], $xPath, $styleLevels ? array($this, "replaceStyle") : null);
                 }
             }
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
 }
 function listRepositories()
 {
     $repos = ConfService::getRepositoriesList();
     AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/><column messageId="ajxp_conf.9" attributeName="accessType" sortType="String"/><column messageId="ajxp_shared.9" attributeName="repo_accesses" sortType="String"/></columns>');
     $repoArray = array();
     $childRepos = array();
     $loggedUser = AuthService::getLoggedUser();
     $users = AuthService::listUsers();
     foreach ($repos as $repoIndex => $repoObject) {
         if ($repoObject->getAccessType() == "ajxp_conf") {
             continue;
         }
         if (!$repoObject->hasOwner() || $repoObject->getOwner() != $loggedUser->getId()) {
             continue;
         }
         if (is_numeric($repoIndex)) {
             $repoIndex = "" . $repoIndex;
         }
         $name = AJXP_Utils::xmlEntities(SystemTextEncoding::toUTF8($repoObject->getDisplay()));
         $repoArray[$name] = $repoIndex;
     }
     // Sort the list now by name
     ksort($repoArray);
     // Append child repositories
     $sortedArray = array();
     foreach ($repoArray as $name => $repoIndex) {
         $sortedArray[$name] = $repoIndex;
         if (isset($childRepos[$repoIndex]) && is_array($childRepos[$repoIndex])) {
             foreach ($childRepos[$repoIndex] as $childData) {
                 $sortedArray[$childData["name"]] = $childData["index"];
             }
         }
     }
     foreach ($sortedArray as $name => $repoIndex) {
         $repoObject =& $repos[$repoIndex];
         $repoAccesses = array();
         foreach ($users as $userId => $userObject) {
             if (!$userObject->hasParent()) {
                 continue;
             }
             if ($userObject->canWrite($repoIndex)) {
                 $repoAccesses[] = $userId . " (rw)";
             } else {
                 if ($userObject->canRead($repoIndex)) {
                     $repoAccesses[] = $userId . " (r)";
                 }
             }
         }
         $metaData = array("repository_id" => $repoIndex, "accessType" => $repoObject->getAccessType(), "icon" => "document_open_remote.png", "openicon" => "document_open_remote.png", "parentname" => "/repositories", "repo_accesses" => implode(", ", $repoAccesses), "ajxp_mime" => "shared_repository");
         AJXP_XMLWriter::renderNode("/repositories/{$repoIndex}", $name, true, $metaData);
     }
 }
예제 #3
0
 public function listTasks($nodeName, $baseDir)
 {
     $mess = ConfService::getMessages();
     AJXP_XMLWriter::renderHeaderNode("/{$baseDir}/{$nodeName}", "Scheduler", false, array("icon" => "scheduler/ICON_SIZE/player_time.png"));
     AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist" switchDisplayMode="list"  template_name="action.scheduler_list">
              <column messageId="action.scheduler.12" attributeName="ajxp_label" sortType="String"/>
              <column messageId="action.scheduler.2" attributeName="schedule" sortType="String"/>
              <column messageId="action.scheduler.1" attributeName="action_name" sortType="String"/>
              <column messageId="action.scheduler.4s" attributeName="repository_id" sortType="String"/>
              <column messageId="action.scheduler.17" attributeName="user_id" sortType="String"/>
              <column messageId="action.scheduler.3" attributeName="NEXT_EXECUTION" sortType="String"/>
              <column messageId="action.scheduler.14" attributeName="LAST_EXECUTION" sortType="String"/>
              <column messageId="action.scheduler.13" attributeName="STATUS" sortType="String"/>
     </columns>');
     $tasks = AJXP_Utils::loadSerialFile($this->getDbFile(), false, "json");
     foreach ($tasks as $task) {
         $timeArray = $this->getTimeArray($task["schedule"]);
         $res = $this->getNextExecutionTimeForScript(time(), $timeArray);
         $task["NEXT_EXECUTION"] = date($mess["date_format"], $res);
         $task["PARAMS"] = implode(", ", $task["PARAMS"]);
         $task["icon"] = "scheduler/ICON_SIZE/task.png";
         $task["ajxp_mime"] = "scheduler_task";
         $sFile = AJXP_CACHE_DIR . "/cmd_outputs/task_" . $task["task_id"] . ".status";
         if (is_file($sFile)) {
             $s = $this->getTaskStatus($task["task_id"]);
             $task["STATUS"] = implode(":", $s);
             $task["LAST_EXECUTION"] = date($mess["date_format"], filemtime($sFile));
         } else {
             $task["STATUS"] = "n/a";
             $task["LAST_EXECUTION"] = "n/a";
         }
         AJXP_XMLWriter::renderNode("/admin/scheduler/" . $task["task_id"], isset($task["label"]) ? $task["label"] : "Action " . $task["action_name"], true, $task);
     }
     AJXP_XMLWriter::close();
 }
예제 #4
0
 /**
  * Main callback for all share- actions.
  * @param string $action
  * @param array $httpVars
  * @param array $fileVars
  * @return null
  * @throws Exception
  */
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (strpos($action, "sharelist") === false && !isset($this->accessDriver)) {
         throw new Exception("Cannot find access driver!");
     }
     if (strpos($action, "sharelist") === false && $this->accessDriver->getId() == "access.demo") {
         $errorMessage = "This is a demo, all 'write' actions are disabled!";
         if ($httpVars["sub_action"] == "delegate_repo") {
             return AJXP_XMLWriter::sendMessage(null, $errorMessage, false);
         } else {
             print $errorMessage;
         }
         return null;
     }
     switch ($action) {
         //------------------------------------
         // SHARING FILE OR FOLDER
         //------------------------------------
         case "share":
             $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : "";
             // REST API COMPATIBILITY
             if (empty($subAction) && isset($httpVars["simple_share_type"])) {
                 $subAction = "create_minisite";
                 if (!isset($httpVars["simple_right_read"]) && !isset($httpVars["simple_right_download"])) {
                     $httpVars["simple_right_read"] = $httpVars["simple_right_download"] = "true";
                 }
                 $httpVars["create_guest_user"] = "******";
                 if ($httpVars["simple_share_type"] == "private" && !isset($httpVars["guest_user_pass"])) {
                     throw new Exception("Please provide a guest_user_pass for private link");
                 }
             }
             $userSelection = new UserSelection(ConfService::getRepository(), $httpVars);
             $ajxpNode = $userSelection->getUniqueNode();
             if (!file_exists($ajxpNode->getUrl())) {
                 throw new Exception("Cannot share a non-existing file: " . $ajxpNode->getUrl());
             }
             $this->updateToMaxAllowedValue($httpVars, "downloadlimit", "FILE_MAX_DOWNLOAD");
             $this->updateToMaxAllowedValue($httpVars, "expiration", "FILE_MAX_EXPIRATION");
             $httpHash = null;
             $originalHash = null;
             if (!isset($httpVars["share_scope"]) || !in_array($httpVars["share_scope"], array("public", "private"))) {
                 $httpVars["share_scope"] = "private";
             }
             $shareScope = $httpVars["share_scope"];
             $plainResult = 'unknown sub_action';
             if ($subAction == "delegate_repo") {
                 $auth = $this->getAuthorization("folder", "workspace");
                 if (!$auth) {
                     $mess = ConfService::getMessages();
                     throw new Exception($mess["351"]);
                 }
                 $users = array();
                 $groups = array();
                 $this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups);
                 $result = $this->createSharedRepository($httpVars, $isUpdate, $users, $groups);
                 if (is_a($result, "Repository")) {
                     if (!$isUpdate) {
                         $this->getShareStore()->storeShare($this->repository->getId(), array("REPOSITORY" => $result->getUniqueId(), "OWNER_ID" => AuthService::getLoggedUser()->getId()), "repository");
                     }
                     AJXP_Controller::applyHook($isUpdate ? "node.share.update" : "node.share.create", array('type' => 'repository', 'repository' => &$this->repository, 'accessDriver' => &$this->accessDriver, 'new_repository' => &$result));
                     if ($ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) {
                         $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "repository", $result->getUniqueId(), $shareScope == "public", $originalHash);
                     }
                     $plainResult = 200;
                 } else {
                     $plainResult = $result;
                 }
             } else {
                 if ($subAction == "create_minisite") {
                     if (isset($httpVars["hash"]) && !empty($httpVars["hash"])) {
                         $httpHash = $httpVars["hash"];
                     }
                     $result = $this->createSharedMinisite($httpVars, $isUpdate);
                     if (!is_array($result)) {
                         $url = $result;
                     } else {
                         list($hash, $url) = $result;
                         if ($ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) {
                             $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "minisite", $hash, $shareScope == "public", $httpHash != null && $hash != $httpHash ? $httpHash : null);
                         }
                     }
                     $plainResult = $url;
                 } else {
                     if ($subAction == "share_node") {
                         $httpVars["return_json"] = true;
                         if (isset($httpVars["hash"]) && !empty($httpVars["hash"])) {
                             $httpHash = $httpVars["hash"];
                         }
                         $ajxpNode->loadNodeInfo();
                         $results = $this->shareNode($ajxpNode, $httpVars, $isUpdate);
                         if (is_array($results) && $ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) {
                             foreach ($results as $shareObject) {
                                 if ($shareObject instanceof \Pydio\OCS\Model\TargettedLink) {
                                     $hash = $shareObject->getHash();
                                     $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "ocs_remote", $hash, $shareScope == "public", $hash);
                                 } else {
                                     if (is_a($shareObject, "ShareLink")) {
                                         $hash = $shareObject->getHash();
                                         $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "minisite", $hash, $shareScope == "public", $httpHash != null && $hash != $httpHash ? $httpHash : null);
                                     } else {
                                         if (is_a($shareObject, "Repository")) {
                                             $this->getShareStore()->getMetaManager()->addShareInMeta($ajxpNode, "repository", $shareObject->getUniqueId(), $shareScope == "public", null);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
             /*
              * Send IM to inform that node has been shared or unshared.
              * Should be done only if share scope is public.
              */
             if ($shareScope == "public") {
                 $ajxpNode->loadNodeInfo();
                 $content = AJXP_XMLWriter::writeNodesDiff(["UPDATE" => array($ajxpNode->getPath() => $ajxpNode)]);
                 AJXP_Controller::applyHook("msg.instant", array($content, $ajxpNode->getRepositoryId(), null, null, [$ajxpNode->getPath()]));
             }
             if (!isset($httpVars["return_json"])) {
                 header("Content-Type: text/plain");
                 print $plainResult;
             } else {
                 $compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($ajxpNode);
                 header("Content-type:application/json");
                 if (!empty($compositeShare)) {
                     echo json_encode($this->compositeShareToJson($compositeShare));
                 } else {
                     echo json_encode(array());
                 }
             }
             // as the result can be quite small (e.g error code), make sure it's output in case of OB active.
             flush();
             break;
         case "toggle_link_watch":
             $userSelection = new UserSelection($this->repository, $httpVars);
             $shareNode = $selectedNode = $userSelection->getUniqueNode();
             $watchValue = $httpVars["set_watch"] == "true" ? true : false;
             $folder = false;
             if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "folder") {
                 $folder = true;
                 $selectedNode = new AJXP_Node("pydio://" . AJXP_Utils::sanitize($httpVars["repository_id"], AJXP_SANITIZE_ALPHANUM) . "/");
             }
             $shares = array();
             $this->getShareStore()->getMetaManager()->getSharesFromMeta($shareNode, $shares, false);
             if (!count($shares)) {
                 break;
             }
             if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) {
                 $elementId = $httpVars["element_id"];
             } else {
                 $sKeys = array_keys($shares);
                 $elementId = $sKeys[0];
             }
             if ($this->watcher !== false) {
                 if (!$folder) {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($selectedNode, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_READ, array($elementId));
                     } else {
                         $this->watcher->removeWatchFromFolder($selectedNode, AuthService::getLoggedUser()->getId(), true, $elementId);
                     }
                 } else {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($selectedNode, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH);
                     } else {
                         $this->watcher->removeWatchFromFolder($selectedNode, AuthService::getLoggedUser()->getId());
                     }
                 }
             }
             $mess = ConfService::getMessages();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["share_center.47"], null);
             AJXP_XMLWriter::close();
             break;
         case "load_shared_element_data":
             $node = null;
             if (isset($httpVars["hash"]) && $httpVars["element_type"] == "file") {
                 // LEGACY LINKS
                 $parsedMeta = array($httpVars["hash"] => array("type" => "file"));
                 $jsonData = array();
                 foreach ($parsedMeta as $shareId => $shareMeta) {
                     $jsonData[] = $this->shareToJson($shareId, $shareMeta, $node);
                 }
                 header("Content-type:application/json");
                 echo json_encode($jsonData);
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $node = new AJXP_Node($this->urlBase . $file);
                 $loggedUser = AuthService::getLoggedUser();
                 if (isset($httpVars["owner"]) && $loggedUser->isAdmin() && $loggedUser->getGroupPath() == "/" && $loggedUser->getId() != AJXP_Utils::sanitize($httpVars["owner"], AJXP_SANITIZE_EMAILCHARS)) {
                     // Impersonate the current user
                     $node->setUser(AJXP_Utils::sanitize($httpVars["owner"], AJXP_SANITIZE_EMAILCHARS));
                 }
                 if (!file_exists($node->getUrl())) {
                     $mess = ConfService::getMessages();
                     throw new Exception(str_replace('%s', "Cannot find file " . $file, $mess["share_center.219"]));
                 }
                 if (isset($httpVars["tmp_repository_id"]) && AuthService::getLoggedUser()->isAdmin()) {
                     $compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($node, true);
                 } else {
                     $compositeShare = $this->getShareStore()->getMetaManager()->getCompositeShareForNode($node);
                 }
                 if (empty($compositeShare)) {
                     $mess = ConfService::getMessages();
                     throw new Exception(str_replace('%s', "Cannot find share for node " . $file, $mess["share_center.219"]));
                 }
                 header("Content-type:application/json");
                 $json = $this->compositeShareToJson($compositeShare);
                 echo json_encode($json);
             }
             break;
         case "unshare":
             $mess = ConfService::getMessages();
             $userSelection = new UserSelection($this->repository, $httpVars);
             if (isset($httpVars["hash"])) {
                 $sanitizedHash = AJXP_Utils::sanitize($httpVars["hash"], AJXP_SANITIZE_ALPHANUM);
                 $ajxpNode = $userSelection->isEmpty() ? null : $userSelection->getUniqueNode();
                 $result = $this->getShareStore()->deleteShare($httpVars["element_type"], $sanitizedHash, false, false, $ajxpNode);
                 if ($result !== false) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage($mess["share_center.216"], null);
                     AJXP_XMLWriter::close();
                 }
             } else {
                 $userSelection = new UserSelection($this->repository, $httpVars);
                 $ajxpNode = $userSelection->getUniqueNode();
                 $shares = array();
                 $this->getShareStore()->getMetaManager()->getSharesFromMeta($ajxpNode, $shares, false);
                 if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) {
                     $elementId = $httpVars["element_id"];
                     if (isset($shares[$elementId])) {
                         $shares = array($elementId => $shares[$elementId]);
                     }
                 }
                 if (count($shares)) {
                     $res = true;
                     foreach ($shares as $shareId => $share) {
                         $t = isset($share["type"]) ? $share["type"] : "file";
                         try {
                             $result = $this->getShareStore()->deleteShare($t, $shareId, false, true);
                         } catch (Exception $e) {
                             if ($e->getMessage() == "repo-not-found") {
                                 $result = true;
                             } else {
                                 throw $e;
                             }
                         }
                         $this->getShareStore()->getMetaManager()->removeShareFromMeta($ajxpNode, $shareId);
                         $res = $result && $res;
                     }
                     if ($res !== false) {
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage($mess["share_center.216"], null);
                         AJXP_XMLWriter::close();
                         AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
                         if (isset($httpVars["share_scope"]) && $httpVars["share_scope"] == "public") {
                             $ajxpNode->loadNodeInfo();
                             $content = AJXP_XMLWriter::writeNodesDiff(["UPDATE" => [$ajxpNode->getPath() => $ajxpNode]]);
                             AJXP_Controller::applyHook("msg.instant", array($content, $ajxpNode->getRepositoryId(), null, null, [$ajxpNode->getPath()]));
                         }
                     }
                 }
             }
             break;
         case "reset_counter":
             if (isset($httpVars["hash"])) {
                 $userId = AuthService::getLoggedUser()->getId();
                 if (isset($httpVars["owner_id"]) && $httpVars["owner_id"] != $userId) {
                     if (!AuthService::getLoggedUser()->isAdmin()) {
                         throw new Exception("You are not allowed to access this resource");
                     }
                     $userId = $httpVars["owner_id"];
                 }
                 $this->getShareStore()->resetDownloadCounter($httpVars["hash"], $userId);
             } else {
                 $userSelection = new UserSelection($this->repository, $httpVars);
                 $ajxpNode = $userSelection->getUniqueNode();
                 $metadata = $this->getShareStore()->getMetaManager()->getNodeMeta($ajxpNode);
                 if (!isset($metadata["shares"]) || !is_array($metadata["shares"])) {
                     return null;
                 }
                 if (isset($httpVars["element_id"]) && isset($metadata["shares"][$httpVars["element_id"]])) {
                     $this->getShareStore()->resetDownloadCounter($httpVars["element_id"], $httpVars["owner_id"]);
                 } else {
                     $keys = array_keys($metadata["shares"]);
                     foreach ($keys as $key) {
                         $this->getShareStore()->resetDownloadCounter($key, null);
                     }
                 }
             }
             break;
         case "update_shared_element_data":
             if (!in_array($httpVars["p_name"], array("counter", "tags"))) {
                 return null;
             }
             $hash = AJXP_Utils::decodeSecureMagic($httpVars["element_id"]);
             $userSelection = new UserSelection($this->repository, $httpVars);
             $ajxpNode = $userSelection->getUniqueNode();
             if ($this->getShareStore()->shareIsLegacy($hash)) {
                 // Store in metadata
                 $metadata = $this->getShareStore()->getMetaManager()->getNodeMeta($ajxpNode);
                 if (isset($metadata["shares"][$httpVars["element_id"]])) {
                     if (!is_array($metadata["shares"][$httpVars["element_id"]])) {
                         $metadata["shares"][$httpVars["element_id"]] = array();
                     }
                     $metadata["shares"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"];
                     // Set Private=true by default.
                     $this->getShareStore()->getMetaManager()->setNodeMeta($ajxpNode, $metadata, true);
                 }
             } else {
                 // TODO: testUserCanEditShare ?
                 $this->getShareStore()->updateShareProperty($hash, $httpVars["p_name"], $httpVars["p_value"]);
             }
             break;
         case "sharelist-load":
             $parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : "";
             $userContext = $httpVars["user_context"];
             $currentUser = true;
             if ($userContext == "global" && AuthService::getLoggedUser()->isAdmin()) {
                 $currentUser = false;
             } else {
                 if ($userContext == "user" && AuthService::getLoggedUser()->isAdmin() && !empty($httpVars["user_id"])) {
                     $currentUser = AJXP_Utils::sanitize($httpVars["user_id"], AJXP_SANITIZE_EMAILCHARS);
                 }
             }
             $nodes = $this->listSharesAsNodes("/data/repositories/{$parentRepoId}/shares", $currentUser, $parentRepoId);
             AJXP_XMLWriter::header();
             if ($userContext == "current") {
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns template_name="ajxp_user.shares">
                 <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
                 <column messageId="share_center.132" attributeName="shared_element_parent_repository_label" sortType="String"/>
                 <column messageId="3" attributeName="share_type_readable" sortType="String"/>
                 </columns>');
             } else {
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="filelist" template_name="ajxp_conf.repositories">
                 <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
                 <column messageId="share_center.159" attributeName="owner" sortType="String"/>
                 <column messageId="3" attributeName="share_type_readable" sortType="String"/>
                 <column messageId="share_center.52" attributeName="share_data" sortType="String"/>
                 </columns>');
             }
             foreach ($nodes as $node) {
                 AJXP_XMLWriter::renderAjxpNode($node);
             }
             AJXP_XMLWriter::close();
             break;
         case "sharelist-clearExpired":
             $accessType = ConfService::getRepository()->getAccessType();
             $currentUser = $accessType != "ajxp_conf" && $accessType != "ajxp_admin";
             $count = $this->getShareStore()->clearExpiredFiles($currentUser);
             AJXP_XMLWriter::header();
             if ($count) {
                 AJXP_XMLWriter::sendMessage("Removed " . count($count) . " expired links", null);
             } else {
                 AJXP_XMLWriter::sendMessage("Nothing to do", null);
             }
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     return null;
 }
 public function printDiagnostic($dir, $root = NULL, $hash = null, $returnNodes = false)
 {
     $outputArray = array();
     $testedParams = array();
     $allNodes = array();
     AJXP_Utils::runTests($outputArray, $testedParams);
     AJXP_Utils::testResultsToFile($outputArray, $testedParams);
     if (!$returnNodes) {
         AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="fileList" template_name="ajxp_conf.diagnostic" defaultWidth="20%"><column messageId="ajxp_conf.23" attributeName="ajxp_label" sortType="String"/><column messageId="ajxp_conf.24" attributeName="data" sortType="String"/></columns>');
     }
     if (is_file(TESTS_RESULT_FILE)) {
         include_once TESTS_RESULT_FILE;
         if (isset($diagResults)) {
             foreach ($diagResults as $id => $value) {
                 $value = AJXP_Utils::xmlEntities($value);
                 $xml = "<tree icon=\"susehelpcenter.png\" is_file=\"1\" filename=\"/{$dir}/{$id}\" text=\"{$id}\" data=\"{$value}\" ajxp_mime=\"testResult\"/>";
                 if (!$returnNodes) {
                     print $xml;
                 } else {
                     $allNodes["/{$dir}/{$id}"] = $xml;
                 }
             }
         }
     }
     return $allNodes;
 }
    function listSharedFiles()
    {
        AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist" template_name="ajxp_conf.shared">
				<column messageId="ajxp_shared.4" attributeName="ajxp_label" sortType="String" defaultWidth="30%"/>
				<column messageId="ajxp_shared.27" attributeName="owner" sortType="String" defaultWidth="10%"/>
				<column messageId="ajxp_shared.17" attributeName="download_url" sortType="String" defaultWidth="40%"/>
				<column messageId="ajxp_shared.6" attributeName="password" sortType="String" defaultWidth="4%"/>
				<column messageId="ajxp_shared.7" attributeName="expiration" sortType="String" defaultWidth="4%"/>
				<column messageId="ajxp_shared.20" attributeName="expired" sortType="String" defaultWidth="4%"/>
				<column messageId="ajxp_shared.14" attributeName="integrity" sortType="String" defaultWidth="4%" hidden="true"/>
			</columns>');
        $dlFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER");
        if (!is_dir($dlFolder)) {
            return;
        }
        $files = glob($dlFolder . "/*.php");
        if ($files === false) {
            return;
        }
        $mess = ConfService::getMessages();
        $loggedUser = AuthService::getLoggedUser();
        $userId = $loggedUser->getId();
        $dlURL = ConfService::getCoreConf("PUBLIC_DOWNLOAD_URL");
        if ($dlURL != "") {
            $downloadBase = rtrim($dlURL, "/");
        } else {
            $fullUrl = AJXP_Utils::detectServerURL() . dirname($_SERVER['REQUEST_URI']);
            $downloadBase = str_replace("\\", "/", $fullUrl . rtrim(str_replace(AJXP_INSTALL_PATH, "", $dlFolder), "/"));
        }
        foreach ($files as $file) {
            $publicletData = $this->loadPublicletData($file);
            AJXP_XMLWriter::renderNode(str_replace(".php", "", basename($file)), "" . SystemTextEncoding::toUTF8($publicletData["REPOSITORY"]->getDisplay()) . ":/" . SystemTextEncoding::toUTF8($publicletData["FILE_PATH"]), true, array("icon" => "html.png", "password" => $publicletData["PASSWORD"] != "" ? $publicletData["PASSWORD"] : "******", "expiration" => $publicletData["EXPIRE_TIME"] != 0 ? date($mess["date_format"], $publicletData["EXPIRE_TIME"]) : "-", "expired" => $publicletData["EXPIRE_TIME"] != 0 ? $publicletData["EXPIRE_TIME"] < time() ? $mess["ajxp_shared.21"] : $mess["ajxp_shared.22"] : "-", "integrity" => !$publicletData["SECURITY_MODIFIED"] ? $mess["ajxp_shared.15"] : $mess["ajxp_shared.16"], "download_url" => $downloadBase . "/" . basename($file), "owner" => isset($publicletData["OWNER_ID"]) ? $publicletData["OWNER_ID"] : "-", "ajxp_mime" => "shared_file"));
        }
    }
예제 #7
0
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (strpos($action, "sharelist") === false && !isset($this->accessDriver)) {
         throw new Exception("Cannot find access driver!");
     }
     if (strpos($action, "sharelist") === false && $this->accessDriver->getId() == "access.demo") {
         $errorMessage = "This is a demo, all 'write' actions are disabled!";
         if ($httpVars["sub_action"] == "delegate_repo") {
             return AJXP_XMLWriter::sendMessage(null, $errorMessage, false);
         } else {
             print $errorMessage;
         }
         return null;
     }
     switch ($action) {
         //------------------------------------
         // SHARING FILE OR FOLDER
         //------------------------------------
         case "share":
             $subAction = isset($httpVars["sub_action"]) ? $httpVars["sub_action"] : "";
             if (empty($subAction) && isset($httpVars["simple_share_type"])) {
                 $subAction = "create_minisite";
                 if (!isset($httpVars["simple_right_read"]) && !isset($httpVars["simple_right_download"])) {
                     $httpVars["simple_right_read"] = $httpVars["simple_right_download"] = "true";
                 }
             }
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $ajxpNode = new AJXP_Node($this->urlBase . $file);
             if (!file_exists($ajxpNode->getUrl())) {
                 throw new Exception("Cannot share a non-existing file: " . $ajxpNode->getUrl());
             }
             //$metadata = null;
             $newMeta = null;
             $maxdownload = abs(intval($this->getFilteredOption("FILE_MAX_DOWNLOAD", $this->repository->getId())));
             $download = isset($httpVars["downloadlimit"]) ? abs(intval($httpVars["downloadlimit"])) : 0;
             if ($maxdownload == 0) {
                 $httpVars["downloadlimit"] = $download;
             } elseif ($maxdownload > 0 && $download == 0) {
                 $httpVars["downloadlimit"] = $maxdownload;
             } else {
                 $httpVars["downloadlimit"] = min($download, $maxdownload);
             }
             $maxexpiration = abs(intval($this->getFilteredOption("FILE_MAX_EXPIRATION", $this->repository->getId())));
             $expiration = isset($httpVars["expiration"]) ? abs(intval($httpVars["expiration"])) : 0;
             if ($maxexpiration == 0) {
                 $httpVars["expiration"] = $expiration;
             } elseif ($maxexpiration > 0 && $expiration == 0) {
                 $httpVars["expiration"] = $maxexpiration;
             } else {
                 $httpVars["expiration"] = min($expiration, $maxexpiration);
             }
             $forcePassword = $this->getFilteredOption("SHARE_FORCE_PASSWORD", $this->repository->getId());
             $httpHash = null;
             $originalHash = null;
             if ($subAction == "delegate_repo") {
                 header("Content-type:text/plain");
                 $auth = $this->getAuthorization("folder", "workspace");
                 if (!$auth) {
                     print 103;
                     break;
                 }
                 $result = $this->createSharedRepository($httpVars, $this->repository, $this->accessDriver);
                 if (is_a($result, "Repository")) {
                     $newMeta = array("id" => $result->getUniqueId(), "type" => "repository");
                     $numResult = 200;
                 } else {
                     $numResult = $result;
                 }
                 print $numResult;
             } else {
                 if ($subAction == "create_minisite") {
                     header("Content-type:text/plain");
                     if (isset($httpVars["hash"]) && !empty($httpVars["hash"])) {
                         $httpHash = $httpVars["hash"];
                     }
                     if (isset($httpVars["simple_share_type"])) {
                         $httpVars["create_guest_user"] = "******";
                         if ($httpVars["simple_share_type"] == "private" && !isset($httpVars["guest_user_pass"])) {
                             throw new Exception("Please provide a guest_user_pass for private link");
                         }
                     }
                     if ($forcePassword && (isset($httpVars["create_guest_user"]) && $httpVars["create_guest_user"] == "true" && empty($httpVars["guest_user_pass"]) || isset($httpVars["guest_user_id"]) && isset($httpVars["guest_user_pass"]) && $httpVars["guest_user_pass"] == "")) {
                         $mess = ConfService::getMessages();
                         throw new Exception($mess["share_center.175"]);
                     }
                     $res = $this->createSharedMinisite($httpVars, $this->repository, $this->accessDriver);
                     if (!is_array($res)) {
                         $url = $res;
                     } else {
                         list($hash, $url) = $res;
                         $newMeta = array("id" => $hash, "type" => "minisite");
                         if ($httpHash != null && $hash != $httpHash) {
                             $originalHash = $httpHash;
                         }
                     }
                     print $url;
                 } else {
                     $data = $this->accessDriver->makePublicletOptions($file, $httpVars["password"], $httpVars["expiration"], $httpVars["downloadlimit"], $this->repository);
                     $customData = array();
                     foreach ($httpVars as $key => $value) {
                         if (substr($key, 0, strlen("PLUGINS_DATA_")) == "PLUGINS_DATA_") {
                             $customData[substr($key, strlen("PLUGINS_DATA_"))] = $value;
                         }
                     }
                     if (count($customData)) {
                         $data["PLUGINS_DATA"] = $customData;
                     }
                     list($hash, $url) = $this->writePubliclet($data, $this->accessDriver, $this->repository);
                     $newMeta = array("id" => $hash, "type" => "file");
                     if (isset($httpVars["format"]) && $httpVars["format"] == "json") {
                         header("Content-type:application/json");
                         echo json_encode(array("element_id" => $hash, "publiclet_link" => $url));
                     } else {
                         header("Content-type:text/plain");
                         echo $url;
                     }
                     flush();
                 }
             }
             if ($newMeta != null && $ajxpNode->hasMetaStore() && !$ajxpNode->isRoot()) {
                 $this->addShareInMeta($ajxpNode, $newMeta["type"], $newMeta["id"], $originalHash);
             }
             AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
             // as the result can be quite small (e.g error code), make sure it's output in case of OB active.
             flush();
             break;
         case "toggle_link_watch":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $watchValue = $httpVars["set_watch"] == "true" ? true : false;
             $folder = false;
             $shNode = new AJXP_Node($this->urlBase . $file);
             if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "folder") {
                 $folder = true;
                 $node = new AJXP_Node($this->baseProtocol . "://" . $httpVars["repository_id"] . "/");
             } else {
                 $node = new AJXP_Node($this->urlBase . $file);
             }
             $this->getSharesFromMeta($shNode, $shares, false);
             if (!count($shares)) {
                 break;
             }
             if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) {
                 $elementId = $httpVars["element_id"];
             } else {
                 $sKeys = array_keys($shares);
                 $elementId = $sKeys[0];
             }
             if ($this->watcher !== false) {
                 if (!$folder) {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_USERS_READ, array($elementId));
                     } else {
                         $this->watcher->removeWatchFromFolder($node, AuthService::getLoggedUser()->getId(), true, $elementId);
                     }
                 } else {
                     if ($watchValue) {
                         $this->watcher->setWatchOnFolder($node, AuthService::getLoggedUser()->getId(), MetaWatchRegister::$META_WATCH_BOTH);
                     } else {
                         $this->watcher->removeWatchFromFolder($node, AuthService::getLoggedUser()->getId());
                     }
                 }
             }
             $mess = ConfService::getMessages();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["share_center.47"], null);
             AJXP_XMLWriter::close();
             break;
         case "load_shared_element_data":
             $node = null;
             if (isset($httpVars["hash"])) {
                 $t = "minisite";
                 if (isset($httpVars["element_type"]) && $httpVars["element_type"] == "file") {
                     $t = "file";
                 }
                 $parsedMeta = array($httpVars["hash"] => array("type" => $t));
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $node = new AJXP_Node($this->urlBase . $file);
                 $this->getSharesFromMeta($node, $parsedMeta, true);
             }
             $flattenJson = false;
             $jsonData = array();
             foreach ($parsedMeta as $shareId => $shareMeta) {
                 $jsonData[] = $this->shareToJson($shareId, $shareMeta, $node);
                 if ($shareMeta["type"] != "file") {
                     $flattenJson = true;
                 }
             }
             header("Content-type:application/json");
             if ($flattenJson && count($jsonData)) {
                 $jsonData = $jsonData[0];
             }
             echo json_encode($jsonData);
             break;
         case "unshare":
             if (isset($httpVars["hash"])) {
                 $res = $this->getShareStore()->deleteShare($httpVars["element_type"], $httpVars["hash"]);
                 if ($res !== false) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage("Successfully unshared element", null);
                     AJXP_XMLWriter::close();
                 }
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $ajxpNode = new AJXP_Node($this->urlBase . $file);
                 $this->getSharesFromMeta($ajxpNode, $shares, false);
                 if (count($shares)) {
                     if (isset($httpVars["element_id"]) && isset($shares[$httpVars["element_id"]])) {
                         $elementId = $httpVars["element_id"];
                     } else {
                         $sKeys = array_keys($shares);
                         $elementId = $sKeys[0];
                     }
                     if (isset($shares[$elementId]) && isset($shares[$elementId]["type"])) {
                         $t = $shares[$elementId]["type"];
                     } else {
                         $t = "file";
                     }
                     $this->getShareStore()->deleteShare($t, $elementId);
                     $this->removeShareFromMeta($ajxpNode, $elementId);
                     AJXP_Controller::applyHook("msg.instant", array("<reload_shared_elements/>", ConfService::getRepository()->getId()));
                 }
             }
             break;
         case "reset_counter":
             if (isset($httpVars["hash"])) {
                 $userId = AuthService::getLoggedUser()->getId();
                 if (isset($httpVars["owner_id"]) && $httpVars["owner_id"] != $userId) {
                     if (!AuthService::getLoggedUser()->isAdmin()) {
                         throw new Exception("You are not allowed to access this resource");
                     }
                     $userId = $httpVars["owner_id"];
                 }
                 $this->getShareStore()->resetDownloadCounter($httpVars["hash"], $userId);
             } else {
                 $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
                 $ajxpNode = new AJXP_Node($this->urlBase . $file);
                 $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
                 if (!isset($metadata["shares"]) || !is_array($metadata["shares"])) {
                     return null;
                 }
                 if (isset($httpVars["element_id"]) && isset($metadata["shares"][$httpVars["element_id"]])) {
                     $this->getShareStore()->resetDownloadCounter($httpVars["element_id"], $httpVars["owner_id"]);
                 } else {
                     $keys = array_keys($metadata["shares"]);
                     foreach ($keys as $key) {
                         $this->getShareStore()->resetDownloadCounter($key, null);
                     }
                 }
             }
             break;
         case "update_shared_element_data":
             if (!in_array($httpVars["p_name"], array("counter", "tags"))) {
                 return null;
             }
             $hash = AJXP_Utils::decodeSecureMagic($httpVars["element_id"]);
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if ($this->getShareStore()->shareIsLegacy($hash)) {
                 // Store in metadata
                 $ajxpNode = new AJXP_Node($this->urlBase . $file);
                 $metadata = $ajxpNode->retrieveMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY);
                 if (isset($metadata["shares"][$httpVars["element_id"]])) {
                     if (!is_array($metadata["shares"][$httpVars["element_id"]])) {
                         $metadata["shares"][$httpVars["element_id"]] = array();
                     }
                     $metadata["shares"][$httpVars["element_id"]][$httpVars["p_name"]] = $httpVars["p_value"];
                     $ajxpNode->setMetadata("ajxp_shared", $metadata, true, AJXP_METADATA_SCOPE_REPOSITORY);
                 }
             } else {
                 $this->getShareStore()->updateShareProperty($hash, $httpVars["p_name"], $httpVars["p_value"]);
             }
             break;
         case "sharelist-load":
             $parentRepoId = isset($httpVars["parent_repository_id"]) ? $httpVars["parent_repository_id"] : "";
             $userContext = $httpVars["user_context"];
             $currentUser = true;
             if ($userContext == "global" && AuthService::getLoggedUser()->isAdmin()) {
                 $currentUser = false;
             }
             $nodes = $this->listSharesAsNodes("/data/repositories/{$parentRepoId}/shares", $currentUser, $parentRepoId);
             AJXP_XMLWriter::header();
             if ($userContext == "current") {
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns template_name="ajxp_user.shares">
                 <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
                 <column messageId="share_center.132" attributeName="shared_element_parent_repository_label" sortType="String"/>
                 <column messageId="3" attributeName="share_type_readable" sortType="String"/>
                 </columns>');
             } else {
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="filelist" template_name="ajxp_conf.repositories">
                 <column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/>
                 <column messageId="share_center.159" attributeName="owner" sortType="String"/>
                 <column messageId="3" attributeName="share_type_readable" sortType="String"/>
                 <column messageId="share_center.52" attributeName="share_data" sortType="String"/>
                 </columns>');
             }
             foreach ($nodes as $node) {
                 AJXP_XMLWriter::renderAjxpNode($node);
             }
             AJXP_XMLWriter::close();
             break;
         case "sharelist-clearExpired":
             $currentUser = ConfService::getRepository()->getAccessType() != "ajxp_conf";
             $count = $this->clearExpiredFiles($currentUser);
             AJXP_XMLWriter::header();
             if ($count) {
                 AJXP_XMLWriter::sendMessage("Removed " . count($count) . " expired links", null);
             } else {
                 AJXP_XMLWriter::sendMessage("Nothing to do", null);
             }
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     return null;
 }
 public function listRepositories()
 {
     AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_conf.8" attributeName="ajxp_label" sortType="String"/><column messageId="user_dash.9" attributeName="parent_label" sortType="String"/><column messageId="user_dash.9" attributeName="repo_accesses" sortType="String"/></columns>');
     $repoArray = array();
     $loggedUser = AuthService::getLoggedUser();
     $count = 0;
     $repos = ConfService::listRepositoriesWithCriteria(array("owner_user_id" => $loggedUser->getId()), $count);
     $searchAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS", "conf");
     $displayAll = ConfService::getCoreConf("CROSSUSERS_ALLGROUPS_DISPLAY", "conf");
     if ($searchAll || $displayAll) {
         $baseGroup = "/";
     } else {
         $baseGroup = AuthService::filterBaseGroup("/");
     }
     AuthService::setGroupFiltering(false);
     $users = AuthService::listUsers($baseGroup);
     $minisites = $this->listSharedFiles("minisites");
     foreach ($repos as $repoIndex => $repoObject) {
         if ($repoObject->getAccessType() == "ajxp_conf") {
             continue;
         }
         if (!$repoObject->hasOwner() || $repoObject->getOwner() != $loggedUser->getId()) {
             continue;
         }
         if (is_numeric($repoIndex)) {
             $repoIndex = "" . $repoIndex;
         }
         $name = (isset($minisites[$repoIndex]) ? "[Minisite] " : "") . AJXP_Utils::xmlEntities(SystemTextEncoding::toUTF8($repoObject->getDisplay()));
         $repoArray[$name] = $repoIndex;
     }
     // Sort the list now by name
     ksort($repoArray);
     foreach ($repoArray as $name => $repoIndex) {
         $repoObject =& $repos[$repoIndex];
         $repoAccesses = array();
         foreach ($users as $userId => $userObject) {
             if ($userObject->getId() == $loggedUser->getId()) {
                 continue;
             }
             $label = $userObject->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, $userId);
             if (empty($label)) {
                 $label = $userId;
             }
             $acl = $userObject->mergedRole->getAcl($repoObject->getId());
             if (!empty($acl)) {
                 $repoAccesses[] = $label . " (" . $acl . ")";
             }
         }
         $parent = $repoObject->getParentId();
         $parentRepo =& $repos[$parent];
         $parentLabel = $this->metaIcon("folder-open") . $parentRepo->getDisplay();
         $repoPath = $repoObject->getOption("PATH");
         $parentPath = $parentRepo->getOption("PATH");
         $parentLabel .= " (" . str_replace($parentPath, "", $repoPath) . ")";
         $metaData = array("repository_id" => $repoIndex, "icon" => "document_open_remote.png", "openicon" => "document_open_remote.png", "parentname" => "/repositories", "parent_label" => $parentLabel, "repo_accesses" => count($repoAccesses) ? $this->metaIcon("share-sign") . implode(", ", $repoAccesses) : "", "ajxp_mime" => "shared_repository");
         AJXP_XMLWriter::renderNode("/repositories/{$repoIndex}", $name, true, $metaData);
     }
 }
예제 #9
0
 public function switchAction($action, $httpVars, $fileVars)
 {
     $repo = ConfService::getRepository();
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = AJXP_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, "%23") !== false) {
         $parts = explode("%23", $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 = explode("_", $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;
                 } else {
                     if (count($split) == 2 && $split[0] == "field" && in_array($split[1], $fields)) {
                         if (!isset($rows[0])) {
                             $rows[0] = array();
                         }
                         $rows[0][$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 = array();
                     $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"];
                         }
                     }
                     $fieldsDef = implode(",", $fieldsDef);
                     if (count($pks)) {
                         $fieldsDef .= ",PRIMARY KEY (" . implode(",", $pks) . ")";
                     }
                     if (count($indexes)) {
                         $fieldsDef .= ",INDEX (" . implode(",", $indexes) . ")";
                     }
                     if (count($uniqs)) {
                         $fieldsDef .= ",UNIQUE (" . implode(",", $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 .= " " . implode(",", $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 = explode(".", $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();
                 AJXP_XMLWriter::sendFilesListComponentConfig('<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=\"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);
                         }
                     }
                 }
                 try {
                     $result = $this->showRecords($query, $tableName, $currentPage);
                 } catch (AJXP_Exception $ex) {
                     unset($_SESSION["LAST_SQL_QUERY"]);
                     throw $ex;
                 }
                 AJXP_XMLWriter::header();
                 $blobCols = array();
                 $columnsString = '<columns switchDisplayMode="list" switchGridMode="grid">';
                 foreach ($result["COLUMNS"] as $col) {
                     $columnsString .= "<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"];
                     }
                 }
                 $columnsString .= '</columns>';
                 AJXP_XMLWriter::sendFilesListComponentConfig($columnsString);
                 //print '<pagination total="'.$result["TOTAL_PAGES"].'" current="'.$currentPage.'" remote_order="true" currentOrderCol="'.$order_column.'" currentOrderDir="'.$order_direction.'"/>';
                 if ($result["TOTAL_PAGES"] > 1) {
                     AJXP_XMLWriter::renderPaginationData($count, $currentPage, $result["TOTAL_PAGES"]);
                 }
                 foreach ($result["ROWS"] as $arbitIndex => $row) {
                     print '<tree ';
                     $pkString = "";
                     foreach ($row as $key => $value) {
                         if (in_array($key, $blobCols)) {
                             $sizeStr = " - NULL";
                             if (strlen($value)) {
                                 $sizeStr = " - " . AJXP_Utils::roundSize(strlen($value));
                             }
                             print "{$key}=\"BLOB{$sizeStr}\" ";
                         } else {
                             $value = str_replace("\"", "", $value);
                             $value = AJXP_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_' . $arbitIndex . '.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" || isset($reload_file_list)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadDataNode("", "", false);
     }
     return $xmlBuffer;
 }
 function printDiagnostic()
 {
     $outputArray = array();
     $testedParams = array();
     $passed = AJXP_Utils::runTests($outputArray, $testedParams);
     AJXP_Utils::testResultsToFile($outputArray, $testedParams);
     AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchDisplayMode="list" switchGridMode="fileList"><column messageId="ajxp_conf.23" attributeName="ajxp_label" sortType="String"/><column messageId="ajxp_conf.24" attributeName="data" sortType="String"/></columns>');
     if (is_file(TESTS_RESULT_FILE)) {
         include_once TESTS_RESULT_FILE;
         foreach ($diagResults as $id => $value) {
             print "<tree icon=\"susehelpcenter.png\" is_file=\"1\" filename=\"{$id}\" text=\"{$id}\" data=\"{$value}\" ajxp_mime=\"testResult\"/>";
         }
     }
 }