function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $loggedUser = AuthService::getLoggedUser();
     if (ENABLE_USERS && !$loggedUser->isAdmin()) {
         return;
     }
     if ($action == "edit") {
         if (isset($httpVars["sub_action"])) {
             $action = $httpVars["sub_action"];
         }
     }
     switch ($action) {
         //------------------------------------
         //	BASIC LISTING
         //------------------------------------
         case "ls":
             $rootNodes = array("users" => array("LABEL" => "Users", "ICON" => "yast_kuser.png"), "repositories" => array("LABEL" => "Repositories", "ICON" => "folder_red.png"), "logs" => array("LABEL" => "Logs", "ICON" => "toggle_log.png"), "diagnostic" => array("LABEL" => "Diagnostic", "ICON" => "susehelpcenter.png"));
             $dir = isset($httpVars["dir"]) ? $httpVars["dir"] : "";
             $splits = explode("/", $dir);
             if (count($splits)) {
                 if ($splits[0] == "") {
                     array_shift($splits);
                 }
                 if (count($splits)) {
                     $strippedDir = strtolower(urldecode($splits[0]));
                 } else {
                     $strippedDir = "";
                 }
             }
             if (array_key_exists($strippedDir, $rootNodes)) {
                 AJXP_XMLWriter::header();
                 if ($strippedDir == "users") {
                     $this->listUsers();
                 } else {
                     if ($strippedDir == "repositories") {
                         $this->listRepositories();
                     } else {
                         if ($strippedDir == "logs") {
                             $this->listLogFiles($dir);
                         } else {
                             if ($strippedDir == "diagnostic") {
                                 $this->printDiagnostic();
                             }
                         }
                     }
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             } else {
                 AJXP_XMLWriter::header();
                 print '<columns switchGridMode="filelist"><column messageString="Configuration Data" attributeName="ajxp_label" sortType="String"/></columns>';
                 foreach ($rootNodes as $key => $data) {
                     $src = '';
                     if ($key == "logs") {
                         $src = 'src="content.php?dir=' . $key . '"';
                     }
                     print '<tree text="' . $data["LABEL"] . '" icon="' . $data["ICON"] . '" filename="/' . $key . '" parentname="/" ' . $src . ' />';
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             break;
         case "edit_user":
             $confStorage = ConfService::getConfStorageImpl();
             $userId = $httpVars["user_id"];
             $userObject = $confStorage->createUserObject($userId);
             //print_r($userObject);
             AJXP_XMLWriter::header("admin_data");
             AJXP_XMLWriter::sendUserData($userObject, true);
             // Add WALLET DATA : DEFINITIONS AND VALUES
             print "<drivers>";
             print ConfService::availableDriversToXML("user_param");
             print "</drivers>";
             $wallet = $userObject->getPref("AJXP_WALLET");
             if (is_array($wallet) && count($wallet) > 0) {
                 print "<user_wallet>";
                 foreach ($wallet as $repoId => $options) {
                     foreach ($options as $optName => $optValue) {
                         print "<wallet_data repo_id=\"{$repoId}\" option_name=\"{$optName}\" option_value=\"{$optValue}\"/>";
                     }
                 }
                 print "</user_wallet>";
             }
             $editPass = $userId != "guest" ? "1" : "0";
             $authDriver = ConfService::getAuthDriverImpl();
             if (!$authDriver->passwordsEditable()) {
                 $editPass = "******";
             }
             print "<edit_options edit_pass=\"" . $editPass . "\" edit_admin_right=\"" . ($userId != "guest" && $userId != $loggedUser->getId() ? "1" : "0") . "\" edit_delete=\"" . ($userId != "guest" && $userId != $loggedUser->getId() && $authDriver->usersEditable() ? "1" : "0") . "\"/>";
             AJXP_XMLWriter::close("admin_data");
             exit(1);
             break;
         case "create_user":
             if (!isset($_GET["new_user_login"]) || $_GET["new_user_login"] == "" || !isset($_GET["new_user_pwd"]) || $_GET["new_user_pwd"] == "") {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, "Wrong Arguments!");
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $forbidden = array("guest", "share");
             if (AuthService::userExists($_GET["new_user_login"]) || in_array($_GET["new_user_login"], $forbidden)) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, "User already exists, please choose another login!");
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             if (get_magic_quotes_gpc()) {
                 $_GET["new_user_login"] = stripslashes($_GET["new_user_login"]);
             }
             $_GET["new_user_login"] = str_replace("'", "", $_GET["new_user_login"]);
             $confStorage = ConfService::getConfStorageImpl();
             $newUser = $confStorage->createUserObject($_GET["new_user_login"]);
             $newUser->save();
             AuthService::createUser($_GET["new_user_login"], $_GET["new_user_pwd"]);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("User created successfully", null);
             AJXP_XMLWriter::reloadFileList($_GET["new_user_login"]);
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "change_admin_right":
             $userId = $_GET["user_id"];
             $confStorage = ConfService::getConfStorageImpl();
             $user = $confStorage->createUserObject($userId);
             $user->setAdmin($_GET["right_value"] == "1" ? true : false);
             $user->save();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Changed admin right for user " . $_GET["user_id"], null);
             AJXP_XMLWriter::reloadFileList(false);
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "update_user_right":
             if (!isset($_GET["user_id"]) || !isset($_GET["repository_id"]) || !isset($_GET["right"]) || !AuthService::userExists($_GET["user_id"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, "Wrong arguments");
                 print "<update_checkboxes user_id=\"" . $_GET["user_id"] . "\" repository_id=\"" . $_GET["repository_id"] . "\" read=\"old\" write=\"old\"/>";
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $confStorage = ConfService::getConfStorageImpl();
             $user = $confStorage->createUserObject($_GET["user_id"]);
             $user->setRight($_GET["repository_id"], $_GET["right"]);
             $user->save();
             $loggedUser = AuthService::getLoggedUser();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Changed right for user " . $_GET["user_id"], null);
             print "<update_checkboxes user_id=\"" . $_GET["user_id"] . "\" repository_id=\"" . $_GET["repository_id"] . "\" read=\"" . $user->canRead($_GET["repository_id"]) . "\" write=\"" . $user->canWrite($_GET["repository_id"]) . "\"/>";
             AJXP_XMLWriter::reloadRepositoryList();
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "save_repository_user_params":
             $userId = $_GET["user_id"];
             if ($userId == $loggedUser->getId()) {
                 $user = $loggedUser;
             } else {
                 $confStorage = ConfService::getConfStorageImpl();
                 $user = $confStorage->createUserObject($userId);
             }
             $wallet = $user->getPref("AJXP_WALLET");
             if (!is_array($wallet)) {
                 $wallet = array();
             }
             $repoID = $_GET["repository_id"];
             if (!array_key_exists($repoID, $wallet)) {
                 $wallet[$repoID] = array();
             }
             $options = $wallet[$repoID];
             $this->parseParameters($_GET, $options, $userId);
             $wallet[$repoID] = $options;
             $user->setPref("AJXP_WALLET", $wallet);
             $user->save();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Saved data for user " . $_GET["user_id"], null);
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "update_user_pwd":
             if (!isset($_GET["user_id"]) || !isset($_GET["user_pwd"]) || !AuthService::userExists($_GET["user_id"]) || trim($_GET["user_pwd"]) == "") {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, "Wrong Arguments!");
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $res = AuthService::updatePassword($_GET["user_id"], $_GET["user_pwd"]);
             AJXP_XMLWriter::header();
             if ($res === true) {
                 AJXP_XMLWriter::sendMessage("Password changed successfully for user " . $_GET["user_id"], null);
             } else {
                 AJXP_XMLWriter::sendMessage(null, "Cannot update password : {$res}");
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "get_drivers_definition":
             AJXP_XMLWriter::header("drivers");
             print ConfService::availableDriversToXML("param");
             AJXP_XMLWriter::close("drivers");
             exit(1);
             break;
         case "create_repository":
             $options = array();
             $repDef = $_GET;
             unset($repDef["get_action"]);
             $this->parseParameters($repDef, $options);
             if (count($options)) {
                 $repDef["DRIVER_OPTIONS"] = $options;
             }
             // NOW SAVE THIS REPOSITORY!
             $newRep = ConfService::createRepositoryFromArray(0, $repDef);
             if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php")) {
                 chdir(INSTALL_PATH . "/server/tests/plugins");
                 include INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php";
                 $className = "ajxp_" . $newRep->getAccessType();
                 $class = new $className();
                 $result = $class->doRepositoryTest($newRep);
                 if (!$result) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage(null, $class->failedInfo);
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
             }
             $res = ConfService::addRepository($newRep);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, "The conf directory is not writeable");
             } else {
                 AJXP_XMLWriter::sendMessage("Successfully created repository", null);
                 AJXP_XMLWriter::reloadFileList($newRep->getDisplay());
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "edit_repository":
             $repId = $httpVars["repository_id"];
             $repList = ConfService::getRootDirsList();
             //print_r($repList);
             AJXP_XMLWriter::header("admin_data");
             if (!isset($repList[$repId])) {
                 AJXP_XMLWriter::close("admin_data");
                 exit(1);
             }
             $repository = $repList[$repId];
             $nested = array();
             print "<repository index=\"{$repId}\"";
             foreach ($repository as $name => $option) {
                 if (!is_array($option)) {
                     if (is_bool($option)) {
                         $option = $option ? "true" : "false";
                     }
                     print " {$name}=\"" . SystemTextEncoding::toUTF8(Utils::xmlEntities($option)) . "\" ";
                 } else {
                     if (is_array($option)) {
                         $nested[] = $option;
                     }
                 }
             }
             if (count($nested)) {
                 print ">";
                 foreach ($nested as $option) {
                     foreach ($option as $key => $optValue) {
                         if (is_bool($optValue)) {
                             $optValue = $optValue ? "true" : "false";
                         }
                         print "<param name=\"{$key}\" value=\"{$optValue}\"/>";
                     }
                 }
                 print "</repository>";
             } else {
                 print "/>";
             }
             print ConfService::availableDriversToXML("param", $repository->accessType);
             AJXP_XMLWriter::close("admin_data");
             exit(1);
             break;
         case "edit_repository_label":
         case "edit_repository_data":
             $repId = $_GET["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             $res = 0;
             if (isset($_GET["newLabel"])) {
                 $repo->setDisplay(SystemTextEncoding::fromPostedFileName($_GET["newLabel"]));
                 $res = ConfService::replaceRepository($repId, $repo);
             } else {
                 $options = array();
                 $this->parseParameters($_GET, $options);
                 if (count($options)) {
                     foreach ($options as $key => $value) {
                         $repo->addOption($key, $value);
                     }
                 }
                 if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) {
                     chdir(INSTALL_PATH . "/server/tests/plugins");
                     include INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $repo->getAccessType() . ".php";
                     $className = "ajxp_" . $repo->getAccessType();
                     $class = new $className();
                     $result = $class->doRepositoryTest($repo);
                     if (!$result) {
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage(null, $class->failedInfo);
                         AJXP_XMLWriter::close();
                         exit(1);
                     }
                 }
                 ConfService::replaceRepository($repId, $repo);
             }
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, "Error while trying to edit repository");
             } else {
                 AJXP_XMLWriter::sendMessage("Successfully edited repository", null);
                 AJXP_XMLWriter::reloadFileList(isset($_GET["newLabel"]) ? SystemTextEncoding::fromPostedFileName($_GET["newLabel"]) : false);
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             exit(1);
         case "delete":
             if (isset($httpVars["repository_id"])) {
                 $repId = $httpVars["repository_id"];
                 //if(get_magic_quotes_gpc()) $repLabel = stripslashes($repLabel);
                 $res = ConfService::deleteRepository($repId);
                 AJXP_XMLWriter::header();
                 if ($res == -1) {
                     AJXP_XMLWriter::sendMessage(null, "The conf directory is not writeable");
                 } else {
                     AJXP_XMLWriter::sendMessage("Successfully deleted repository", null);
                     AJXP_XMLWriter::reloadFileList(false);
                     AJXP_XMLWriter::reloadRepositoryList();
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             } else {
                 $forbidden = array("guest", "share");
                 if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || in_array($_GET["user_id"], $forbidden) || $loggedUser->getId() == $httpVars["user_id"]) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage(null, "Wrong Arguments!");
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
                 $res = AuthService::deleteUser($httpVars["user_id"]);
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage("User successfully erased", null);
                 AJXP_XMLWriter::reloadFileList($httpVars["user_id"]);
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             break;
         default:
             break;
     }
     return;
 }
 /**
  * Update a user with admin rights and return it
  * @param AJXP_User $adminUser
  * @return AJXP_User
  */
 static function updateAdminRights($adminUser)
 {
     foreach (array_keys(ConfService::getRootDirsList()) as $rootDirIndex) {
         $adminUser->setRight($rootDirIndex, "rw");
     }
     $adminUser->save();
     return $adminUser;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	SWITCH THE ROOT REPOSITORY
         //------------------------------------
         case "switch_root_dir":
             if (!isset($root_dir_index)) {
                 break;
             }
             $dirList = ConfService::getRootDirsList();
             if (!isset($dirList[$root_dir_index])) {
                 $errorMessage = "Trying to switch to an unkown folder!";
                 break;
             }
             ConfService::switchRootDir($root_dir_index);
             $logMessage = "Successfully Switched!";
             AJXP_Logger::logAction("Switch Repository", array("rep. id" => $root_dir_index));
             break;
             //------------------------------------
             //	GET AN HTML TEMPLATE
             //------------------------------------
         //------------------------------------
         //	GET AN HTML TEMPLATE
         //------------------------------------
         case "get_template":
             header("Content-type:text/html; charset:UTF-8");
             if (isset($template_name) && is_file(CLIENT_RESOURCES_FOLDER . "/html/" . $template_name)) {
                 if ($template_name == "gui_tpl.html") {
                     include CLIENT_RESOURCES_FOLDER . "/html/usertemplate_top.html";
                 }
                 include CLIENT_RESOURCES_FOLDER . "/html/" . $template_name;
                 if ($template_name == "gui_tpl.html") {
                     include CLIENT_RESOURCES_FOLDER . "/html/usertemplate_bottom.html";
                 }
             }
             exit(0);
             break;
             //------------------------------------
             //	GET I18N MESSAGES
             //------------------------------------
         //------------------------------------
         //	GET I18N MESSAGES
         //------------------------------------
         case "get_i18n_messages":
             header("Content-type:text/javascript");
             HTMLWriter::writeI18nMessagesClass(ConfService::getMessages());
             exit(0);
             break;
             //------------------------------------
             //	BOOKMARK BAR
             //------------------------------------
         //------------------------------------
         //	BOOKMARK BAR
         //------------------------------------
         case "get_bookmarks":
             $bmUser = null;
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser = AuthService::getLoggedUser();
             } else {
                 if (!AuthService::usersEnabled()) {
                     $confStorage = ConfService::getConfStorageImpl();
                     $bmUser = $confStorage->createUserObject("shared");
                 }
             }
             if ($bmUser == null) {
                 exit(1);
             }
             if (isset($_GET["bm_action"]) && isset($_GET["bm_path"])) {
                 if ($_GET["bm_action"] == "add_bookmark") {
                     $title = "";
                     if (isset($_GET["title"])) {
                         $title = $_GET["title"];
                     }
                     if ($title == "" && $_GET["bm_path"] == "/") {
                         $title = ConfService::getCurrentRootDirDisplay();
                     }
                     $bmUser->addBookMark($_GET["bm_path"], $title);
                 } else {
                     if ($_GET["bm_action"] == "delete_bookmark") {
                         $bmUser->removeBookmark($_GET["bm_path"]);
                     } else {
                         if ($_GET["bm_action"] == "rename_bookmark" && isset($_GET["bm_title"])) {
                             $bmUser->renameBookmark($_GET["bm_path"], $_GET["bm_title"]);
                         }
                     }
                 }
             }
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser->save();
                 AuthService::updateUser($bmUser);
             } else {
                 if (!AuthService::usersEnabled()) {
                     $bmUser->save();
                 }
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks());
             AJXP_XMLWriter::close();
             exit(1);
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "save_user_pref":
             $userObject = AuthService::getLoggedUser();
             if ($userObject == null) {
                 exit(1);
             }
             $i = 0;
             while (isset($_GET["pref_name_" . $i]) && isset($_GET["pref_value_" . $i])) {
                 $prefName = $_GET["pref_name_" . $i];
                 $prefValue = $_GET["pref_value_" . $i];
                 if ($prefName != "password") {
                     $userObject->setPref($prefName, $prefValue);
                     $userObject->save();
                     AuthService::updateUser($userObject);
                     setcookie("AJXP_{$prefName}", $prefValue);
                 } else {
                     if (isset($_GET["crt"]) && AuthService::checkPassword($userObject->getId(), $_GET["crt"], false, $_GET["pass_seed"])) {
                         AuthService::updatePassword($userObject->getId(), $prefValue);
                     } else {
                         //$errorMessage = "Wrong password!";
                         header("Content-Type:text/plain");
                         print "PASS_ERROR";
                         exit(1);
                     }
                 }
                 $i++;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             exit(1);
             break;
             //------------------------------------
             //	DISPLAY DOC
             //------------------------------------
         //------------------------------------
         //	DISPLAY DOC
         //------------------------------------
         case "display_doc":
             header("Content-type:text/html; charset:UTF-8");
             echo HTMLWriter::getDocFile(htmlentities($_GET["doc_file"]));
             exit(1);
             break;
         default:
             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)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     $loggedUser = AuthService::getLoggedUser();
     if (AuthService::usersEnabled() && !$loggedUser->isAdmin()) {
         return;
     }
     if ($action == "edit") {
         if (isset($httpVars["sub_action"])) {
             $action = $httpVars["sub_action"];
         }
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	BASIC LISTING
         //------------------------------------
         case "ls":
             $rootNodes = array("data" => array("LABEL" => $mess["ajxp_conf.110"], "ICON" => "user.png", "CHILDREN" => array("repositories" => array("LABEL" => $mess["ajxp_conf.3"], "ICON" => "hdd_external_unmount.png", "LIST" => "listRepositories"), "users" => array("LABEL" => $mess["ajxp_conf.2"], "ICON" => "user.png", "LIST" => "listUsers"), "roles" => array("LABEL" => $mess["ajxp_conf.69"], "ICON" => "yast_kuser.png", "LIST" => "listRoles"))), "config" => array("LABEL" => $mess["ajxp_conf.109"], "ICON" => "preferences_desktop.png", "CHILDREN" => array("core" => array("LABEL" => $mess["ajxp_conf.98"], "ICON" => "preferences_desktop.png", "LIST" => "listPlugins"), "plugins" => array("LABEL" => $mess["ajxp_conf.99"], "ICON" => "folder_development.png", "LIST" => "listPlugins"))), "admin" => array("LABEL" => $mess["ajxp_conf.111"], "ICON" => "toggle_log.png", "CHILDREN" => array("logs" => array("LABEL" => $mess["ajxp_conf.4"], "ICON" => "toggle_log.png", "LIST" => "listLogFiles"), "files" => array("LABEL" => $mess["ajxp_shared.3"], "ICON" => "html.png", "LIST" => "listSharedFiles"), "diagnostic" => array("LABEL" => $mess["ajxp_conf.5"], "ICON" => "susehelpcenter.png", "LIST" => "printDiagnostic"))));
             AJXP_Controller::applyHook("ajxp_conf.list_config_nodes", array(&$rootNodes));
             $dir = trim(AJXP_Utils::decodeSecureMagic(isset($httpVars["dir"]) ? $httpVars["dir"] : ""), " /");
             if ($dir != "") {
                 $splits = explode("/", $dir);
                 $root = array_shift($splits);
                 if (count($splits)) {
                     $child = $splits[0];
                     if (strstr(urldecode($child), "#") !== false) {
                         list($child, $hash) = explode("#", urldecode($child));
                     }
                     if (isset($rootNodes[$root]["CHILDREN"][$child])) {
                         $callback = $rootNodes[$root]["CHILDREN"][$child]["LIST"];
                         if (is_string($callback) && method_exists($this, $callback)) {
                             AJXP_XMLWriter::header();
                             call_user_func(array($this, $callback), implode("/", $splits), $root, $hash);
                             AJXP_XMLWriter::close();
                         } else {
                             if (is_array($callback)) {
                                 call_user_func($callback, implode("/", $splits), $root, $hash);
                             }
                         }
                         return;
                     }
                 } else {
                     $parentName = "/" . $root . "/";
                     $nodes = $rootNodes[$root]["CHILDREN"];
                 }
             } else {
                 $parentName = "/";
                 $nodes = $rootNodes;
             }
             if (isset($nodes)) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_conf.1" attributeName="ajxp_label" sortType="String"/></columns>');
                 foreach ($nodes as $key => $data) {
                     print '<tree text="' . AJXP_Utils::xmlEntities($data["LABEL"]) . '" icon="' . $data["ICON"] . '" filename="' . $parentName . $key . '"/>';
                 }
                 AJXP_XMLWriter::close();
             }
             break;
         case "stat":
             header("Content-type:application/json");
             print '{"mode":true}';
             return;
             break;
         case "create_role":
             $roleId = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["role_id"]), AJXP_SANITIZE_HTML_STRICT);
             if (!strlen($roleId)) {
                 throw new Exception($mess[349]);
             }
             if (AuthService::getRole($roleId) !== false) {
                 throw new Exception($mess["ajxp_conf.65"]);
             }
             AuthService::updateRole(new AjxpRole($roleId));
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null);
             AJXP_XMLWriter::reloadDataNode("", $httpVars["role_id"]);
             AJXP_XMLWriter::close();
             break;
         case "edit_role":
             $roleId = SystemTextEncoding::magicDequote($httpVars["role_id"]);
             $role = AuthService::getRole($roleId);
             if ($role === false) {
                 throw new Exception("Cant find role! ");
             }
             AJXP_XMLWriter::header("admin_data");
             print AJXP_XMLWriter::writeRoleRepositoriesData($role);
             AJXP_XMLWriter::close("admin_data");
             break;
         case "update_role_right":
             if (!isset($httpVars["role_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 print "<update_checkboxes user_id=\"" . $httpVars["role_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>";
                 AJXP_XMLWriter::close();
                 return;
             }
             $role = AuthService::getRole($httpVars["role_id"]);
             if ($role === false) {
                 throw new Exception("Cant find role!");
             }
             $role->setRight($httpVars["repository_id"], $httpVars["right"]);
             AuthService::updateRole($role);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.64"] . $httpVars["role_id"], null);
             print "<update_checkboxes user_id=\"" . $httpVars["role_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $role->canRead($httpVars["repository_id"]) . "\" write=\"" . $role->canWrite($httpVars["repository_id"]) . "\"/>";
             //AJXP_XMLWriter::reloadRepositoryList();
             AJXP_XMLWriter::close();
             break;
         case "update_role_actions":
             if (!isset($httpVars["role_id"]) || !isset($httpVars["disabled_actions"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             $role = AuthService::getRole($httpVars["role_id"]);
             if ($role === false) {
                 throw new Exception("Cant find role!");
             }
             $actions = explode(",", $httpVars["disabled_actions"]);
             // Clear and reload actions
             foreach ($role->getSpecificActionsRights("ajxp.all") as $actName => $actValue) {
                 $role->setSpecificActionRight("ajxp.all", $actName, true);
             }
             foreach ($actions as $action) {
                 if (($action = AJXP_Utils::sanitize($action, AJXP_SANITIZE_ALPHANUM)) == "") {
                     continue;
                 }
                 $role->setSpecificActionRight("ajxp.all", $action, false);
             }
             AuthService::updateRole($role);
             AJXP_XMLWriter::header("admin_data");
             print AJXP_XMLWriter::writeRoleRepositoriesData($role);
             AJXP_XMLWriter::close("admin_data");
             break;
         case "update_role_default":
             if (!isset($httpVars["role_id"]) || !isset($httpVars["default_value"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             $role = AuthService::getRole($httpVars["role_id"]);
             if ($role === false) {
                 throw new Exception("Cannot find role!");
             }
             $role->setDefault($httpVars["default_value"] == "true");
             AuthService::updateRole($role);
             AJXP_XMLWriter::header("admin_data");
             print AJXP_XMLWriter::writeRoleRepositoriesData($role);
             AJXP_XMLWriter::close("admin_data");
             break;
         case "get_custom_params":
             $confStorage = ConfService::getConfStorageImpl();
             AJXP_XMLWriter::header("admin_data");
             $confDriver = ConfService::getConfStorageImpl();
             $customData = $confDriver->options['CUSTOM_DATA'];
             if (is_array($customData) && count($customData) > 0) {
                 print "<custom_data>";
                 foreach ($customData as $custName => $custValue) {
                     print "<param name=\"{$custName}\" type=\"string\" label=\"{$custValue}\" description=\"\" value=\"\"/>";
                 }
                 print "</custom_data>";
             }
             AJXP_XMLWriter::close("admin_data");
             break;
         case "edit_user":
             $confStorage = ConfService::getConfStorageImpl();
             $userId = $httpVars["user_id"];
             if (!AuthService::userExists($userId)) {
                 throw new Exception("Invalid user id!");
             }
             $userObject = $confStorage->createUserObject($userId);
             //print_r($userObject);
             AJXP_XMLWriter::header("admin_data");
             AJXP_XMLWriter::sendUserData($userObject, true);
             // Add CUSTOM USER DATA
             $confDriver = ConfService::getConfStorageImpl();
             $customData = $confDriver->options['CUSTOM_DATA'];
             if (is_array($customData) && count($customData) > 0) {
                 $userCustom = $userObject->getPref("CUSTOM_PARAMS");
                 print "<custom_data>";
                 foreach ($customData as $custName => $custValue) {
                     $value = isset($userCustom[$custName]) ? $userCustom[$custName] : '';
                     print "<param name=\"{$custName}\" type=\"string\" label=\"{$custValue}\" description=\"\" value=\"{$value}\"/>";
                 }
                 print "</custom_data>";
             }
             // Add WALLET DATA : DEFINITIONS AND VALUES
             print "<drivers>";
             print AJXP_XMLWriter::replaceAjxpXmlKeywords(ConfService::availableDriversToXML("user_param"));
             print "</drivers>";
             $wallet = $userObject->getPref("AJXP_WALLET");
             if (is_array($wallet) && count($wallet) > 0) {
                 print "<user_wallet>";
                 foreach ($wallet as $repoId => $options) {
                     foreach ($options as $optName => $optValue) {
                         print "<wallet_data repo_id=\"{$repoId}\" option_name=\"{$optName}\" option_value=\"{$optValue}\"/>";
                     }
                 }
                 print "</user_wallet>";
             }
             $editPass = $userId != "guest" ? "1" : "0";
             $authDriver = ConfService::getAuthDriverImpl();
             if (!$authDriver->passwordsEditable()) {
                 $editPass = "******";
             }
             print "<edit_options edit_pass=\"" . $editPass . "\" edit_admin_right=\"" . ($userId != "guest" && $userId != $loggedUser->getId() ? "1" : "0") . "\" edit_delete=\"" . ($userId != "guest" && $userId != $loggedUser->getId() && $authDriver->usersEditable() ? "1" : "0") . "\"/>";
             print "<ajxp_roles>";
             foreach (AuthService::getRolesList() as $roleId => $roleObject) {
                 print "<role id=\"" . AJXP_Utils::xmlEntities($roleId) . "\"/>";
             }
             print "</ajxp_roles>";
             AJXP_XMLWriter::close("admin_data");
             break;
         case "create_user":
             if (!isset($httpVars["new_user_login"]) || $httpVars["new_user_login"] == "" || !isset($httpVars["new_user_pwd"]) || $httpVars["new_user_pwd"] == "") {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             $new_user_login = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["new_user_login"]), AJXP_SANITIZE_EMAILCHARS);
             if (AuthService::userExists($new_user_login) || AuthService::isReservedUserId($new_user_login)) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.43"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             $confStorage = ConfService::getConfStorageImpl();
             $newUser = $confStorage->createUserObject($new_user_login);
             $customData = array();
             $this->parseParameters($httpVars, $customData);
             if (is_array($customData) && count($customData) > 0) {
                 $newUser->setPref("CUSTOM_PARAMS", $customData);
             }
             $newUser->save("superuser");
             AuthService::createUser($new_user_login, $httpVars["new_user_pwd"]);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.44"], null);
             AJXP_XMLWriter::reloadDataNode("", $new_user_login);
             AJXP_XMLWriter::close();
             break;
         case "change_admin_right":
             $userId = $httpVars["user_id"];
             if (!AuthService::userExists($userId)) {
                 throw new Exception("Invalid user id!");
             }
             $confStorage = ConfService::getConfStorageImpl();
             $user = $confStorage->createUserObject($userId);
             $user->setAdmin($httpVars["right_value"] == "1" ? true : false);
             $user->save("superuser");
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.45"] . $httpVars["user_id"], null);
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         case "update_user_right":
             if (!isset($httpVars["user_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"]) || !AuthService::userExists($httpVars["user_id"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>";
                 AJXP_XMLWriter::close();
                 return;
             }
             $confStorage = ConfService::getConfStorageImpl();
             $user = $confStorage->createUserObject($httpVars["user_id"]);
             $user->setRight(AJXP_Utils::sanitize($httpVars["repository_id"], AJXP_SANITIZE_ALPHANUM), AJXP_Utils::sanitize($httpVars["right"], AJXP_SANITIZE_ALPHANUM));
             $user->save();
             $loggedUser = AuthService::getLoggedUser();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.46"] . $httpVars["user_id"], null);
             print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $user->canRead($httpVars["repository_id"]) . "\" write=\"" . $user->canWrite($httpVars["repository_id"]) . "\"/>";
             AJXP_XMLWriter::reloadRepositoryList();
             AJXP_XMLWriter::close();
             return;
             break;
         case "user_add_role":
         case "user_delete_role":
             if (!isset($httpVars["user_id"]) || !isset($httpVars["role_id"]) || !AuthService::userExists($httpVars["user_id"]) || !AuthService::getRole($httpVars["role_id"])) {
                 throw new Exception($mess["ajxp_conf.61"]);
             }
             if ($action == "user_add_role") {
                 $act = "add";
                 $messId = "73";
             } else {
                 $act = "remove";
                 $messId = "74";
             }
             $this->updateUserRole($httpVars["user_id"], $httpVars["role_id"], $act);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf." . $messId] . $httpVars["user_id"], null);
             AJXP_XMLWriter::close();
             return;
             break;
         case "batch_users_roles":
             $confStorage = ConfService::getConfStorageImpl();
             $selection = new UserSelection();
             $selection->initFromHttpVars($httpVars);
             $files = $selection->getFiles();
             $detectedRoles = array();
             if (isset($httpVars["role_id"]) && isset($httpVars["update_role_action"])) {
                 $update = $httpVars["update_role_action"];
                 $roleId = $httpVars["role_id"];
                 if (AuthService::getRole($roleId) === false) {
                     throw new Exception("Invalid role id");
                 }
             }
             foreach ($files as $index => $file) {
                 $userId = basename($file);
                 if (isset($update)) {
                     $userObject = $this->updateUserRole($userId, $roleId, $update);
                 } else {
                     $userObject = $confStorage->createUserObject($userId);
                 }
                 if ($userObject->hasParent()) {
                     unset($files[$index]);
                     continue;
                 }
                 $userRoles = $userObject->getRoles();
                 foreach ($userRoles as $roleIndex => $bool) {
                     if (!isset($detectedRoles[$roleIndex])) {
                         $detectedRoles[$roleIndex] = 0;
                     }
                     if ($bool === true) {
                         $detectedRoles[$roleIndex]++;
                     }
                 }
             }
             $count = count($files);
             AJXP_XMLWriter::header("admin_data");
             print "<user><ajxp_roles>";
             foreach ($detectedRoles as $roleId => $roleCount) {
                 if ($roleCount < $count) {
                     continue;
                 }
                 print "<role id=\"{$roleId}\"/>";
             }
             print "</ajxp_roles></user>";
             print "<ajxp_roles>";
             foreach (AuthService::getRolesList() as $roleId => $roleObject) {
                 print "<role id=\"{$roleId}\"/>";
             }
             print "</ajxp_roles>";
             AJXP_XMLWriter::close("admin_data");
             break;
         case "save_custom_user_params":
             $userId = $httpVars["user_id"];
             if ($userId == $loggedUser->getId()) {
                 $user = $loggedUser;
             } else {
                 $confStorage = ConfService::getConfStorageImpl();
                 $user = $confStorage->createUserObject($userId);
             }
             $custom = $user->getPref("CUSTOM_PARAMS");
             if (!is_array($custom)) {
                 $custom = array();
             }
             $options = $custom;
             $this->parseParameters($httpVars, $options, $userId);
             $custom = $options;
             $user->setPref("CUSTOM_PARAMS", $custom);
             $user->save();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null);
             AJXP_XMLWriter::close();
             break;
         case "save_repository_user_params":
             $userId = $httpVars["user_id"];
             if ($userId == $loggedUser->getId()) {
                 $user = $loggedUser;
             } else {
                 $confStorage = ConfService::getConfStorageImpl();
                 $user = $confStorage->createUserObject($userId);
             }
             $wallet = $user->getPref("AJXP_WALLET");
             if (!is_array($wallet)) {
                 $wallet = array();
             }
             $repoID = $httpVars["repository_id"];
             if (!array_key_exists($repoID, $wallet)) {
                 $wallet[$repoID] = array();
             }
             $options = $wallet[$repoID];
             $this->parseParameters($httpVars, $options, $userId);
             $wallet[$repoID] = $options;
             $user->setPref("AJXP_WALLET", $wallet);
             $user->save();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null);
             AJXP_XMLWriter::close();
             break;
         case "update_user_pwd":
             if (!isset($httpVars["user_id"]) || !isset($httpVars["user_pwd"]) || !AuthService::userExists($httpVars["user_id"]) || trim($httpVars["user_pwd"]) == "") {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             $res = AuthService::updatePassword($httpVars["user_id"], $httpVars["user_pwd"]);
             AJXP_XMLWriter::header();
             if ($res === true) {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.48"] . $httpVars["user_id"], null);
             } else {
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.49"] . " : {$res}");
             }
             AJXP_XMLWriter::close();
             break;
         case "save_user_preference":
             if (!isset($httpVars["user_id"]) || !AuthService::userExists($httpVars["user_id"])) {
                 throw new Exception($mess["ajxp_conf.61"]);
             }
             $userId = $httpVars["user_id"];
             if ($userId == $loggedUser->getId()) {
                 $userObject = $loggedUser;
             } else {
                 $confStorage = ConfService::getConfStorageImpl();
                 $userObject = $confStorage->createUserObject($userId);
             }
             $i = 0;
             while (isset($httpVars["pref_name_" . $i]) && isset($httpVars["pref_value_" . $i])) {
                 $prefName = AJXP_Utils::sanitize($httpVars["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM);
                 $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($httpVars["pref_value_" . $i]));
                 if ($prefName == "password") {
                     continue;
                 }
                 if ($prefName != "pending_folder" && $userObject == null) {
                     $i++;
                     continue;
                 }
                 $userObject->setPref($prefName, $prefValue);
                 $userObject->save("user");
                 $i++;
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage("Succesfully saved user preference", null);
             AJXP_XMLWriter::close();
             break;
         case "get_drivers_definition":
             AJXP_XMLWriter::header("drivers");
             print AJXP_XMLWriter::replaceAjxpXmlKeywords(ConfService::availableDriversToXML("param", "", true));
             AJXP_XMLWriter::close("drivers");
             break;
         case "get_templates_definition":
             AJXP_XMLWriter::header("repository_templates");
             $repositories = ConfService::getRepositoriesList();
             foreach ($repositories as $repo) {
                 if (!$repo->isTemplate) {
                     continue;
                 }
                 $repoId = $repo->getUniqueId();
                 $repoLabel = $repo->getDisplay();
                 $repoType = $repo->getAccessType();
                 print "<template repository_id=\"{$repoId}\" repository_label=\"{$repoLabel}\" repository_type=\"{$repoType}\">";
                 foreach ($repo->getOptionsDefined() as $optionName) {
                     print "<option name=\"{$optionName}\"/>";
                 }
                 print "</template>";
             }
             AJXP_XMLWriter::close("repository_templates");
             break;
         case "create_repository":
             $options = array();
             $repDef = $httpVars;
             $isTemplate = isset($httpVars["sf_checkboxes_active"]);
             unset($repDef["get_action"]);
             unset($repDef["sf_checkboxes_active"]);
             $this->parseParameters($repDef, $options);
             if (count($options)) {
                 $repDef["DRIVER_OPTIONS"] = $options;
             }
             if (strstr($repDef["DRIVER"], "ajxp_template_") !== false) {
                 $templateId = substr($repDef["DRIVER"], 14);
                 $templateRepo = ConfService::getRepositoryById($templateId);
                 $newRep = $templateRepo->createTemplateChild($repDef["DISPLAY"], $repDef["DRIVER_OPTIONS"]);
             } else {
                 $pServ = AJXP_PluginsService::getInstance();
                 $driver = $pServ->getPluginByTypeName("access", $repDef["DRIVER"]);
                 $newRep = ConfService::createRepositoryFromArray(0, $repDef);
                 $testFile = $driver->getBaseDir() . "/test." . $newRep->getAccessType() . "Access.php";
                 if (!$isTemplate && is_file($testFile)) {
                     //chdir(AJXP_TESTS_FOLDER."/plugins");
                     include $testFile;
                     $className = $newRep->getAccessType() . "AccessTest";
                     $class = new $className();
                     $result = $class->doRepositoryTest($newRep);
                     if (!$result) {
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage(null, $class->failedInfo);
                         AJXP_XMLWriter::close();
                         return;
                     }
                 }
                 // Apply default metasource if any
                 if ($driver != null && $driver->getConfigs() != null) {
                     $confs = $driver->getConfigs();
                     if (!empty($confs["DEFAULT_METASOURCES"])) {
                         $metaIds = AJXP_Utils::parseCSL($confs["DEFAULT_METASOURCES"]);
                         $metaSourceOptions = array();
                         foreach ($metaIds as $metaID) {
                             $metaPlug = $pServ->getPluginById($metaID);
                             if ($metaPlug == null) {
                                 continue;
                             }
                             $pNodes = $metaPlug->getManifestRawContent("//param[@default]", "nodes");
                             $defaultParams = array();
                             foreach ($pNodes as $domNode) {
                                 $defaultParams[$domNode->getAttribute("name")] = $domNode->getAttribute("default");
                             }
                             $metaSourceOptions[$metaID] = $defaultParams;
                         }
                         $newRep->addOption("META_SOURCES", $metaSourceOptions);
                     }
                 }
             }
             if ($this->repositoryExists($newRep->getDisplay())) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             if ($isTemplate) {
                 $newRep->isTemplate = true;
             }
             $res = ConfService::addRepository($newRep);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]);
             } else {
                 $loggedUser = AuthService::getLoggedUser();
                 $loggedUser->setRight($newRep->getUniqueId(), "rw");
                 $loggedUser->save("superuser");
                 AuthService::updateUser($loggedUser);
                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.52"], null);
                 AJXP_XMLWriter::reloadDataNode("", $newRep->getUniqueId());
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             break;
         case "edit_repository":
             $repId = $httpVars["repository_id"];
             $repList = ConfService::getRootDirsList();
             //print_r($repList);
             if (!isset($repList[$repId])) {
                 throw new Exception("Cannot find repository with id {$repId}");
             }
             $repository = $repList[$repId];
             $pServ = AJXP_PluginsService::getInstance();
             $plug = $pServ->getPluginById("access." . $repository->accessType);
             if ($plug == null) {
                 throw new Exception("Cannot find access driver (" . $repository->accessType . ") for repository!");
             }
             AJXP_XMLWriter::header("admin_data");
             $slug = $repository->getSlug();
             if ($slug == "" && $repository->isWriteable()) {
                 $repository->setSlug();
                 ConfService::replaceRepository($repId, $repository);
             }
             $nested = array();
             print "<repository index=\"{$repId}\"";
             foreach ($repository as $name => $option) {
                 if (strstr($name, " ") > -1) {
                     continue;
                 }
                 if (!is_array($option)) {
                     if (is_bool($option)) {
                         $option = $option ? "true" : "false";
                     }
                     print " {$name}=\"" . SystemTextEncoding::toUTF8(AJXP_Utils::xmlEntities($option)) . "\" ";
                 } else {
                     if (is_array($option)) {
                         $nested[] = $option;
                     }
                 }
             }
             if (count($nested)) {
                 print ">";
                 foreach ($nested as $option) {
                     foreach ($option as $key => $optValue) {
                         if (is_array($optValue) && count($optValue)) {
                             print "<param name=\"{$key}\"><![CDATA[" . json_encode($optValue) . "]]></param>";
                         } else {
                             if (is_bool($optValue)) {
                                 $optValue = $optValue ? "true" : "false";
                             }
                             print "<param name=\"{$key}\" value=\"{$optValue}\"/>";
                         }
                     }
                 }
                 // Add SLUG
                 if (!$repository->isTemplate) {
                     print "<param name=\"AJXP_SLUG\" value=\"" . $repository->getSlug() . "\"/>";
                 }
                 print "</repository>";
             } else {
                 print "/>";
             }
             if ($repository->hasParent()) {
                 $parent = ConfService::getRepositoryById($repository->getParentId());
                 if (isset($parent) && $parent->isTemplate) {
                     $parentLabel = $parent->getDisplay();
                     $parentType = $parent->getAccessType();
                     print "<template repository_id=\"" . $repository->getParentId() . "\" repository_label=\"{$parentLabel}\" repository_type=\"{$parentType}\">";
                     foreach ($parent->getOptionsDefined() as $parentOptionName) {
                         print "<option name=\"{$parentOptionName}\"/>";
                     }
                     print "</template>";
                 }
             }
             $manifest = $plug->getManifestRawContent("server_settings/param");
             $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest);
             print "<ajxpdriver name=\"" . $repository->accessType . "\">{$manifest}</ajxpdriver>";
             print "<metasources>";
             $metas = $pServ->getPluginsByType("metastore");
             $metas = array_merge($metas, $pServ->getPluginsByType("meta"));
             $metas = array_merge($metas, $pServ->getPluginsByType("index"));
             foreach ($metas as $metaPlug) {
                 print "<meta id=\"" . $metaPlug->getId() . "\" label=\"" . AJXP_Utils::xmlEntities($metaPlug->getManifestLabel()) . "\">";
                 $manifest = $metaPlug->getManifestRawContent("server_settings/param");
                 $manifest = AJXP_XMLWriter::replaceAjxpXmlKeywords($manifest);
                 print $manifest;
                 print "</meta>";
             }
             print "</metasources>";
             AJXP_XMLWriter::close("admin_data");
             return;
             break;
         case "edit_repository_label":
         case "edit_repository_data":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             $res = 0;
             if (isset($httpVars["newLabel"])) {
                 $newLabel = AJXP_Utils::decodeSecureMagic($httpVars["newLabel"]);
                 if ($this->repositoryExists($newLabel)) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]);
                     AJXP_XMLWriter::close();
                     return;
                 }
                 $repo->setDisplay($newLabel);
                 $res = ConfService::replaceRepository($repId, $repo);
             } else {
                 $options = array();
                 $this->parseParameters($httpVars, $options);
                 if (count($options)) {
                     foreach ($options as $key => $value) {
                         if ($key == "AJXP_SLUG") {
                             $repo->setSlug($value);
                             continue;
                         }
                         $repo->addOption($key, $value);
                     }
                 }
                 if (is_file(AJXP_TESTS_FOLDER . "/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) {
                     chdir(AJXP_TESTS_FOLDER . "/plugins");
                     include AJXP_TESTS_FOLDER . "/plugins/test.ajxp_" . $repo->getAccessType() . ".php";
                     $className = "ajxp_" . $repo->getAccessType();
                     $class = new $className();
                     $result = $class->doRepositoryTest($repo);
                     if (!$result) {
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage(null, $class->failedInfo);
                         AJXP_XMLWriter::close();
                         return;
                     }
                 }
                 ConfService::replaceRepository($repId, $repo);
             }
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.53"]);
             } else {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.54"], null);
                 AJXP_XMLWriter::reloadDataNode("", isset($httpVars["newLabel"]) ? $repId : false);
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             break;
         case "add_meta_source":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             if (!is_object($repo)) {
                 throw new Exception("Invalid repository id! {$repId}");
             }
             $metaSourceType = AJXP_Utils::sanitize($httpVars["new_meta_source"], AJXP_SANITIZE_ALPHANUM);
             $options = array();
             $this->parseParameters($httpVars, $options);
             $repoOptions = $repo->getOption("META_SOURCES");
             if (is_array($repoOptions) && isset($repoOptions[$metaSourceType])) {
                 throw new Exception($mess["ajxp_conf.55"]);
             }
             if (!is_array($repoOptions)) {
                 $repoOptions = array();
             }
             $repoOptions[$metaSourceType] = $options;
             uksort($repoOptions, array($this, "metaSourceOrderingFunction"));
             $repo->addOption("META_SOURCES", $repoOptions);
             ConfService::replaceRepository($repId, $repo);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.56"], null);
             AJXP_XMLWriter::close();
             break;
         case "delete_meta_source":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             if (!is_object($repo)) {
                 throw new Exception("Invalid repository id! {$repId}");
             }
             $metaSourceId = $httpVars["plugId"];
             $repoOptions = $repo->getOption("META_SOURCES");
             if (is_array($repoOptions) && array_key_exists($metaSourceId, $repoOptions)) {
                 unset($repoOptions[$metaSourceId]);
                 uksort($repoOptions, array($this, "metaSourceOrderingFunction"));
                 $repo->addOption("META_SOURCES", $repoOptions);
                 ConfService::replaceRepository($repId, $repo);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.57"], null);
             AJXP_XMLWriter::close();
             break;
         case "edit_meta_source":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             if (!is_object($repo)) {
                 throw new Exception("Invalid repository id! {$repId}");
             }
             $metaSourceId = $httpVars["plugId"];
             $options = array();
             $this->parseParameters($httpVars, $options);
             $repoOptions = $repo->getOption("META_SOURCES");
             if (!is_array($repoOptions)) {
                 $repoOptions = array();
             }
             $repoOptions[$metaSourceId] = $options;
             uksort($repoOptions, array($this, "metaSourceOrderingFunction"));
             $repo->addOption("META_SOURCES", $repoOptions);
             ConfService::replaceRepository($repId, $repo);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.58"], null);
             AJXP_XMLWriter::close();
             break;
         case "delete":
             if (isset($httpVars["repository_id"])) {
                 $repId = $httpVars["repository_id"];
                 $res = ConfService::deleteRepository($repId);
                 AJXP_XMLWriter::header();
                 if ($res == -1) {
                     AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]);
                 } else {
                     AJXP_XMLWriter::sendMessage($mess["ajxp_conf.59"], null);
                     AJXP_XMLWriter::reloadDataNode();
                     AJXP_XMLWriter::reloadRepositoryList();
                 }
                 AJXP_XMLWriter::close();
                 return;
             } else {
                 if (isset($httpVars["shared_file"])) {
                     AJXP_XMLWriter::header();
                     $element = basename($httpVars["shared_file"]);
                     $dlFolder = ConfService::getCoreConf("PUBLIC_DOWNLOAD_FOLDER");
                     $publicletData = $this->loadPublicletData($dlFolder . "/" . $element . ".php");
                     unlink($dlFolder . "/" . $element . ".php");
                     AJXP_XMLWriter::sendMessage($mess["ajxp_shared.13"], null);
                     AJXP_XMLWriter::reloadDataNode();
                     AJXP_XMLWriter::close();
                 } else {
                     if (isset($httpVars["role_id"])) {
                         $roleId = $httpVars["role_id"];
                         if (AuthService::getRole($roleId) === false) {
                             throw new Exception($mess["ajxp_conf.67"]);
                         }
                         AuthService::deleteRole($roleId);
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null);
                         AJXP_XMLWriter::reloadDataNode();
                         AJXP_XMLWriter::close();
                     } else {
                         if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || AuthService::isReservedUserId($httpVars["user_id"]) || $loggedUser->getId() == $httpVars["user_id"]) {
                             AJXP_XMLWriter::header();
                             AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                             AJXP_XMLWriter::close();
                         }
                         $res = AuthService::deleteUser($httpVars["user_id"]);
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage($mess["ajxp_conf.60"], null);
                         AJXP_XMLWriter::reloadDataNode();
                         AJXP_XMLWriter::close();
                     }
                 }
             }
             break;
         case "clear_expired":
             $deleted = $this->clearExpiredFiles();
             AJXP_XMLWriter::header();
             if (count($deleted)) {
                 AJXP_XMLWriter::sendMessage(sprintf($mess["ajxp_shared.23"], count($deleted) . ""), null);
                 AJXP_XMLWriter::reloadDataNode();
             } else {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_shared.24"], null);
             }
             AJXP_XMLWriter::close();
             break;
         case "get_plugin_manifest":
             $ajxpPlugin = AJXP_PluginsService::getInstance()->getPluginById($httpVars["plugin_id"]);
             AJXP_XMLWriter::header("admin_data");
             echo AJXP_XMLWriter::replaceAjxpXmlKeywords($ajxpPlugin->getManifestRawContent());
             $definitions = $ajxpPlugin->getConfigsDefinitions();
             $values = $ajxpPlugin->getConfigs();
             if (!is_array($values)) {
                 $values = array();
             }
             echo "<plugin_settings_values>";
             foreach ($values as $key => $value) {
                 if ($definitions[$key]["type"] == "array" && is_array($value)) {
                     $value = implode(",", $value);
                 } else {
                     if ($definitions[$key]["type"] == "boolean") {
                         $value = $value === true || $value === "true" || $value == 1 ? "true" : "false";
                     } else {
                         if ($definitions[$key]["type"] == "textarea") {
                             //$value = str_replace("\\n", "\n", $value);
                         }
                     }
                 }
                 echo "<param name=\"{$key}\" value=\"" . AJXP_Utils::xmlEntities($value) . "\"/>";
             }
             if ($ajxpPlugin->getType() != "core") {
                 echo "<param name=\"AJXP_PLUGIN_ENABLED\" value=\"" . ($ajxpPlugin->isEnabled() ? "true" : "false") . "\"/>";
             }
             echo "</plugin_settings_values>";
             echo "<plugin_doc><![CDATA[<p>" . $ajxpPlugin->getPluginInformationHTML("Charles du Jeu", "http://ajaxplorer.info/plugins/") . "</p>";
             if (file_exists($ajxpPlugin->getBaseDir() . "/plugin_doc.html")) {
                 echo file_get_contents($ajxpPlugin->getBaseDir() . "/plugin_doc.html");
             }
             echo "]]></plugin_doc>";
             AJXP_XMLWriter::close("admin_data");
             break;
         case "edit_plugin_options":
             $options = array();
             $this->parseParameters($httpVars, $options);
             $confStorage = ConfService::getConfStorageImpl();
             $confStorage->savePluginConfig($httpVars["plugin_id"], $options);
             @unlink(AJXP_PLUGINS_CACHE_FILE);
             @unlink(AJXP_PLUGINS_REQUIRES_FILE);
             @unlink(AJXP_PLUGINS_MESSAGES_FILE);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.97"], null);
             AJXP_XMLWriter::reloadDataNode();
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     return;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     $xmlBuffer = "";
     foreach ($httpVars as $getName => $getValue) {
         ${$getName} = AJXP_Utils::securePath($getValue);
     }
     if (isset($dir) && $action != "upload") {
         $dir = SystemTextEncoding::fromUTF8($dir);
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	SWITCH THE ROOT REPOSITORY
         //------------------------------------
         case "switch_repository":
             if (!isset($repository_id)) {
                 break;
             }
             $dirList = ConfService::getRootDirsList();
             if (!isset($dirList[$repository_id])) {
                 $errorMessage = "Trying to switch to an unkown repository!";
                 break;
             }
             ConfService::switchRootDir($repository_id);
             // Load try to init the driver now, to trigger an exception
             // if it's not loading right.
             ConfService::loadRepositoryDriver();
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $user = AuthService::getLoggedUser();
                 $activeRepId = ConfService::getCurrentRootDirIndex();
                 $user->setArrayPref("history", "last_repository", $activeRepId);
                 $user->save();
             }
             //$logMessage = "Successfully Switched!";
             AJXP_Logger::logAction("Switch Repository", array("rep. id" => $repository_id));
             break;
             //------------------------------------
             //	BOOKMARK BAR
             //------------------------------------
         //------------------------------------
         //	BOOKMARK BAR
         //------------------------------------
         case "get_bookmarks":
             $bmUser = null;
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser = AuthService::getLoggedUser();
             } else {
                 if (!AuthService::usersEnabled()) {
                     $confStorage = ConfService::getConfStorageImpl();
                     $bmUser = $confStorage->createUserObject("shared");
                 }
             }
             if ($bmUser == null) {
                 exit(1);
             }
             if (isset($_GET["bm_action"]) && isset($_GET["bm_path"])) {
                 if ($_GET["bm_action"] == "add_bookmark") {
                     $title = "";
                     if (isset($_GET["bm_title"])) {
                         $title = $_GET["bm_title"];
                     }
                     if ($title == "" && $_GET["bm_path"] == "/") {
                         $title = ConfService::getCurrentRootDirDisplay();
                     }
                     $bmUser->addBookMark(SystemTextEncoding::magicDequote($_GET["bm_path"]), SystemTextEncoding::magicDequote($title));
                 } else {
                     if ($_GET["bm_action"] == "delete_bookmark") {
                         $bmUser->removeBookmark($_GET["bm_path"]);
                     } else {
                         if ($_GET["bm_action"] == "rename_bookmark" && isset($_GET["bm_title"])) {
                             $bmUser->renameBookmark($_GET["bm_path"], $_GET["bm_title"]);
                         }
                     }
                 }
             }
             if (AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
                 $bmUser->save();
                 AuthService::updateUser($bmUser);
             } else {
                 if (!AuthService::usersEnabled()) {
                     $bmUser->save();
                 }
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::writeBookmarks($bmUser->getBookmarks());
             AJXP_XMLWriter::close();
             exit(1);
             break;
             //------------------------------------
             //	SAVE USER PREFERENCE
             //------------------------------------
         //------------------------------------
         //	SAVE USER PREFERENCE
         //------------------------------------
         case "save_user_pref":
             $userObject = AuthService::getLoggedUser();
             $i = 0;
             while (isset($_GET["pref_name_" . $i]) && isset($_GET["pref_value_" . $i])) {
                 $prefName = AJXP_Utils::sanitize($_GET["pref_name_" . $i], AJXP_SANITIZE_ALPHANUM);
                 $prefValue = AJXP_Utils::sanitize(SystemTextEncoding::magicDequote($_GET["pref_value_" . $i]));
                 if ($prefName == "password") {
                     continue;
                 }
                 if ($prefName != "pending_folder" && ($userObject == null || $userObject->getId() == "guest")) {
                     $i++;
                     continue;
                 }
                 $userObject->setPref($prefName, $prefValue);
                 $userObject->save();
                 AuthService::updateUser($userObject);
                 //setcookie("AJXP_$prefName", $prefValue);
                 $i++;
             }
             header("Content-Type:text/plain");
             print "SUCCESS";
             exit(1);
             break;
         default:
             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);
     }
     return $xmlBuffer;
 }
 function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     $loggedUser = AuthService::getLoggedUser();
     if (ENABLE_USERS && !$loggedUser->isAdmin()) {
         return;
     }
     if ($action == "edit") {
         if (isset($httpVars["sub_action"])) {
             $action = $httpVars["sub_action"];
         }
     }
     $mess = ConfService::getMessages();
     switch ($action) {
         //------------------------------------
         //	BASIC LISTING
         //------------------------------------
         case "ls":
             $rootNodes = array("repositories" => array("LABEL" => $mess["ajxp_conf.3"], "ICON" => "folder_red.png"), "users" => array("LABEL" => $mess["ajxp_conf.2"], "ICON" => "yast_kuser.png"), "roles" => array("LABEL" => $mess["ajxp_conf.69"], "ICON" => "user_group_new.png"), "files" => array("LABEL" => $mess["ajxp_shared.3"], "ICON" => "html.png"), "logs" => array("LABEL" => $mess["ajxp_conf.4"], "ICON" => "toggle_log.png"), "diagnostic" => array("LABEL" => $mess["ajxp_conf.5"], "ICON" => "susehelpcenter.png"));
             $dir = isset($httpVars["dir"]) ? $httpVars["dir"] : "";
             $splits = explode("/", $dir);
             if (count($splits)) {
                 if ($splits[0] == "") {
                     array_shift($splits);
                 }
                 if (count($splits)) {
                     $strippedDir = strtolower(urldecode($splits[0]));
                 } else {
                     $strippedDir = "";
                 }
             }
             if (array_key_exists($strippedDir, $rootNodes)) {
                 AJXP_XMLWriter::header();
                 if ($strippedDir == "users") {
                     $this->listUsers();
                 } else {
                     if ($strippedDir == "roles") {
                         $this->listRoles();
                     } else {
                         if ($strippedDir == "repositories") {
                             $this->listRepositories();
                         } else {
                             if ($strippedDir == "logs") {
                                 $this->listLogFiles($dir);
                             } else {
                                 if ($strippedDir == "diagnostic") {
                                     $this->printDiagnostic();
                                 } else {
                                     if ($strippedDir == "files") {
                                         $this->listSharedFiles();
                                     }
                                 }
                             }
                         }
                     }
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             } else {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendFilesListComponentConfig('<columns switchGridMode="filelist"><column messageId="ajxp_conf.1" attributeName="ajxp_label" sortType="String"/></columns>');
                 foreach ($rootNodes as $key => $data) {
                     $src = '';
                     if ($key == "logs") {
                         $src = 'src="content.php?get_action=ls&amp;dir=' . $key . '"';
                     }
                     print '<tree text="' . $data["LABEL"] . '" icon="' . $data["ICON"] . '" filename="/' . $key . '" parentname="/" ' . $src . ' />';
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             break;
         case "stat":
             header("Content-type:application/json");
             print '{"mode":true}';
             exit(1);
             break;
         case "create_role":
             $roleId = $httpVars["role_id"];
             if (AuthService::getRole($roleId) !== false) {
                 throw new Exception($mess["ajxp_conf.65"]);
             }
             AuthService::updateRole(new AjxpRole($roleId));
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null);
             AJXP_XMLWriter::reloadDataNode("", $httpVars["role_id"]);
             AJXP_XMLWriter::close();
             break;
         case "edit_role":
             $roleId = $httpVars["role_id"];
             $role = AuthService::getRole($roleId);
             AJXP_XMLWriter::header("admin_data");
             print AJXP_XMLWriter::writeRoleRepositoriesData($role);
             AJXP_XMLWriter::close("admin_data");
             break;
         case "update_role_right":
             if (!isset($httpVars["role_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 print "<update_checkboxes user_id=\"" . $httpVars["role_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>";
                 AJXP_XMLWriter::close();
                 return;
                 //exit(1);
             }
             $role = AuthService::getRole($httpVars["role_id"]);
             $role->setRight($httpVars["repository_id"], $httpVars["right"]);
             AuthService::updateRole($role);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.64"] . $httpVars["role_id"], null);
             print "<update_checkboxes user_id=\"" . $httpVars["role_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $role->canRead($httpVars["repository_id"]) . "\" write=\"" . $role->canWrite($httpVars["repository_id"]) . "\"/>";
             //AJXP_XMLWriter::reloadRepositoryList();
             AJXP_XMLWriter::close();
             //exit(1);
             break;
         case "update_role_actions":
             if (!isset($httpVars["role_id"]) || !isset($httpVars["disabled_actions"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 return;
             }
             $role = AuthService::getRole($httpVars["role_id"]);
             $actions = array_map("trim", explode(",", $httpVars["disabled_actions"]));
             // Clear and reload actions
             foreach ($role->getSpecificActionsRights("ajxp.all") as $actName => $actValue) {
                 $role->setSpecificActionRight("ajxp.all", $actName, true);
             }
             foreach ($actions as $action) {
                 if ($action == "") {
                     continue;
                 }
                 $role->setSpecificActionRight("ajxp.all", $action, false);
             }
             AuthService::updateRole($role);
             AJXP_XMLWriter::header("admin_data");
             print AJXP_XMLWriter::writeRoleRepositoriesData($role);
             AJXP_XMLWriter::close("admin_data");
             break;
         case "edit_user":
             $confStorage = ConfService::getConfStorageImpl();
             $userId = $httpVars["user_id"];
             $userObject = $confStorage->createUserObject($userId);
             //print_r($userObject);
             AJXP_XMLWriter::header("admin_data");
             AJXP_XMLWriter::sendUserData($userObject, true);
             // Add WALLET DATA : DEFINITIONS AND VALUES
             print "<drivers>";
             print ConfService::availableDriversToXML("user_param");
             print "</drivers>";
             $wallet = $userObject->getPref("AJXP_WALLET");
             if (is_array($wallet) && count($wallet) > 0) {
                 print "<user_wallet>";
                 foreach ($wallet as $repoId => $options) {
                     foreach ($options as $optName => $optValue) {
                         print "<wallet_data repo_id=\"{$repoId}\" option_name=\"{$optName}\" option_value=\"{$optValue}\"/>";
                     }
                 }
                 print "</user_wallet>";
             }
             $editPass = $userId != "guest" ? "1" : "0";
             $authDriver = ConfService::getAuthDriverImpl();
             if (!$authDriver->passwordsEditable()) {
                 $editPass = "******";
             }
             print "<edit_options edit_pass=\"" . $editPass . "\" edit_admin_right=\"" . ($userId != "guest" && $userId != $loggedUser->getId() ? "1" : "0") . "\" edit_delete=\"" . ($userId != "guest" && $userId != $loggedUser->getId() && $authDriver->usersEditable() ? "1" : "0") . "\"/>";
             print "<ajxp_roles>";
             foreach (AuthService::getRolesList() as $roleId => $roleObject) {
                 print "<role id=\"{$roleId}\"/>";
             }
             print "</ajxp_roles>";
             AJXP_XMLWriter::close("admin_data");
             exit(1);
             break;
         case "create_user":
             if (!isset($httpVars["new_user_login"]) || $httpVars["new_user_login"] == "" || !isset($httpVars["new_user_pwd"]) || $httpVars["new_user_pwd"] == "") {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $forbidden = array("guest", "share");
             if (AuthService::userExists($httpVars["new_user_login"]) || in_array($httpVars["new_user_login"], $forbidden)) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.43"]);
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             if (get_magic_quotes_gpc()) {
                 $httpVars["new_user_login"] = stripslashes($httpVars["new_user_login"]);
             }
             $httpVars["new_user_login"] = str_replace("'", "", $httpVars["new_user_login"]);
             $confStorage = ConfService::getConfStorageImpl();
             $newUser = $confStorage->createUserObject($httpVars["new_user_login"]);
             $newUser->save();
             AuthService::createUser($httpVars["new_user_login"], $httpVars["new_user_pwd"]);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.44"], null);
             AJXP_XMLWriter::reloadFileList($httpVars["new_user_login"]);
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "change_admin_right":
             $userId = $httpVars["user_id"];
             $confStorage = ConfService::getConfStorageImpl();
             $user = $confStorage->createUserObject($userId);
             $user->setAdmin($httpVars["right_value"] == "1" ? true : false);
             $user->save();
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.45"] . $httpVars["user_id"], null);
             AJXP_XMLWriter::reloadFileList(false);
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "update_user_right":
             if (!isset($httpVars["user_id"]) || !isset($httpVars["repository_id"]) || !isset($httpVars["right"]) || !AuthService::userExists($httpVars["user_id"])) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"old\" write=\"old\"/>";
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $confStorage = ConfService::getConfStorageImpl();
             $user = $confStorage->createUserObject($httpVars["user_id"]);
             $user->setRight($httpVars["repository_id"], $httpVars["right"]);
             $user->save();
             $loggedUser = AuthService::getLoggedUser();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.46"] . $httpVars["user_id"], null);
             print "<update_checkboxes user_id=\"" . $httpVars["user_id"] . "\" repository_id=\"" . $httpVars["repository_id"] . "\" read=\"" . $user->canRead($httpVars["repository_id"]) . "\" write=\"" . $user->canWrite($httpVars["repository_id"]) . "\"/>";
             AJXP_XMLWriter::reloadRepositoryList();
             AJXP_XMLWriter::close();
             return;
             break;
         case "user_add_role":
         case "user_delete_role":
             if (!isset($httpVars["user_id"]) || !isset($httpVars["role_id"]) || !AuthService::userExists($httpVars["user_id"])) {
                 throw new Exception($mess["ajxp_conf.61"]);
             }
             if ($action == "user_add_role") {
                 $act = "add";
                 $messId = "73";
             } else {
                 $act = "remove";
                 $messId = "74";
             }
             $this->updateUserRole($httpVars["user_id"], $httpVars["role_id"], $act);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf." . $messId] . $httpVars["user_id"], null);
             AJXP_XMLWriter::close();
             return;
             break;
         case "batch_users_roles":
             $confStorage = ConfService::getConfStorageImpl();
             $selection = new UserSelection();
             $selection->initFromHttpVars($httpVars);
             $files = $selection->getFiles();
             $detectedRoles = array();
             if (isset($httpVars["role_id"]) && isset($httpVars["update_role_action"])) {
                 $update = $httpVars["update_role_action"];
                 $roleId = $httpVars["role_id"];
             }
             foreach ($files as $index => $file) {
                 $userId = basename($file);
                 if (isset($update)) {
                     $userObject = $this->updateUserRole($userId, $roleId, $update);
                 } else {
                     $userObject = $confStorage->createUserObject($userId);
                 }
                 if ($userObject->hasParent()) {
                     unset($files[$index]);
                     continue;
                 }
                 $userRoles = $userObject->getRoles();
                 foreach ($userRoles as $roleIndex => $bool) {
                     if (!isset($detectedRoles[$roleIndex])) {
                         $detectedRoles[$roleIndex] = 0;
                     }
                     if ($bool === true) {
                         $detectedRoles[$roleIndex]++;
                     }
                 }
             }
             $count = count($files);
             AJXP_XMLWriter::header("admin_data");
             print "<user><ajxp_roles>";
             foreach ($detectedRoles as $roleId => $roleCount) {
                 if ($roleCount < $count) {
                     continue;
                 }
                 print "<role id=\"{$roleId}\"/>";
             }
             print "</ajxp_roles></user>";
             print "<ajxp_roles>";
             foreach (AuthService::getRolesList() as $roleId => $roleObject) {
                 print "<role id=\"{$roleId}\"/>";
             }
             print "</ajxp_roles>";
             AJXP_XMLWriter::close("admin_data");
             break;
         case "save_repository_user_params":
             $userId = $httpVars["user_id"];
             if ($userId == $loggedUser->getId()) {
                 $user = $loggedUser;
             } else {
                 $confStorage = ConfService::getConfStorageImpl();
                 $user = $confStorage->createUserObject($userId);
             }
             $wallet = $user->getPref("AJXP_WALLET");
             if (!is_array($wallet)) {
                 $wallet = array();
             }
             $repoID = $httpVars["repository_id"];
             if (!array_key_exists($repoID, $wallet)) {
                 $wallet[$repoID] = array();
             }
             $options = $wallet[$repoID];
             $this->parseParameters($httpVars, $options, $userId);
             $wallet[$repoID] = $options;
             $user->setPref("AJXP_WALLET", $wallet);
             $user->save();
             if ($loggedUser->getId() == $user->getId()) {
                 AuthService::updateUser($user);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.47"] . $httpVars["user_id"], null);
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "update_user_pwd":
             if (!isset($httpVars["user_id"]) || !isset($httpVars["user_pwd"]) || !AuthService::userExists($httpVars["user_id"]) || trim($httpVars["user_pwd"]) == "") {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $res = AuthService::updatePassword($httpVars["user_id"], $httpVars["user_pwd"]);
             AJXP_XMLWriter::header();
             if ($res === true) {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.48"] . $httpVars["user_id"], null);
             } else {
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.49"] . " : {$res}");
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "get_drivers_definition":
             AJXP_XMLWriter::header("drivers");
             print ConfService::availableDriversToXML("param");
             AJXP_XMLWriter::close("drivers");
             exit(1);
             break;
         case "create_repository":
             $options = array();
             $repDef = $httpVars;
             unset($repDef["get_action"]);
             $this->parseParameters($repDef, $options);
             if (count($options)) {
                 $repDef["DRIVER_OPTIONS"] = $options;
             }
             // NOW SAVE THIS REPOSITORY!
             $newRep = ConfService::createRepositoryFromArray(0, $repDef);
             if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php")) {
                 chdir(INSTALL_PATH . "/server/tests/plugins");
                 include INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $newRep->getAccessType() . ".php";
                 $className = "ajxp_" . $newRep->getAccessType();
                 $class = new $className();
                 $result = $class->doRepositoryTest($newRep);
                 if (!$result) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage(null, $class->failedInfo);
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
             }
             if ($this->repositoryExists($newRep->getDisplay())) {
                 AJXP_XMLWriter::header();
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]);
                 AJXP_XMLWriter::close();
                 exit(1);
             }
             $res = ConfService::addRepository($newRep);
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]);
             } else {
                 $confStorage = ConfService::getConfStorageImpl();
                 $loggedUser = AuthService::getLoggedUser();
                 $loggedUser->setRight($newRep->getUniqueId(), "rw");
                 $loggedUser->save();
                 AuthService::updateUser($loggedUser);
                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.52"], null);
                 AJXP_XMLWriter::reloadFileList($newRep->getDisplay());
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             exit(1);
             break;
         case "edit_repository":
             $repId = $httpVars["repository_id"];
             $repList = ConfService::getRootDirsList();
             //print_r($repList);
             AJXP_XMLWriter::header("admin_data");
             if (!isset($repList[$repId])) {
                 AJXP_XMLWriter::close("admin_data");
                 exit(1);
             }
             $repository = $repList[$repId];
             $nested = array();
             print "<repository index=\"{$repId}\"";
             foreach ($repository as $name => $option) {
                 if (!is_array($option)) {
                     if (is_bool($option)) {
                         $option = $option ? "true" : "false";
                     }
                     print " {$name}=\"" . SystemTextEncoding::toUTF8(AJXP_Utils::xmlEntities($option)) . "\" ";
                 } else {
                     if (is_array($option)) {
                         $nested[] = $option;
                     }
                 }
             }
             if (count($nested)) {
                 print ">";
                 foreach ($nested as $option) {
                     foreach ($option as $key => $optValue) {
                         if (is_array($optValue) && count($optValue)) {
                             print "<param name=\"{$key}\"><![CDATA[" . json_encode($optValue) . "]]></param>";
                         } else {
                             if (is_bool($optValue)) {
                                 $optValue = $optValue ? "true" : "false";
                             }
                             print "<param name=\"{$key}\" value=\"{$optValue}\"/>";
                         }
                     }
                 }
                 print "</repository>";
             } else {
                 print "/>";
             }
             $pServ = AJXP_PluginsService::getInstance();
             $plug = $pServ->getPluginById("access." . $repository->accessType);
             $manifest = $plug->getManifestRawContent("server_settings/param");
             print "<ajxpdriver name=\"" . $repository->accessType . "\">{$manifest}</ajxpdriver>";
             print "<metasources>";
             $metas = $pServ->getPluginsByType("meta");
             foreach ($metas as $metaPlug) {
                 print "<meta id=\"" . $metaPlug->getId() . "\">";
                 $manifest = $metaPlug->getManifestRawContent("server_settings/param");
                 print $manifest;
                 print "</meta>";
             }
             print "</metasources>";
             AJXP_XMLWriter::close("admin_data");
             exit(1);
             break;
         case "edit_repository_label":
         case "edit_repository_data":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             $res = 0;
             if (isset($httpVars["newLabel"])) {
                 $newLabel = SystemTextEncoding::fromPostedFileName($httpVars["newLabel"]);
                 if ($this->repositoryExists($newLabel)) {
                     AJXP_XMLWriter::header();
                     AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.50"]);
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
                 $repo->setDisplay($newLabel);
                 $res = ConfService::replaceRepository($repId, $repo);
             } else {
                 $options = array();
                 $this->parseParameters($httpVars, $options);
                 if (count($options)) {
                     foreach ($options as $key => $value) {
                         $repo->addOption($key, $value);
                     }
                 }
                 if (is_file(INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $repo->getAccessType() . ".php")) {
                     chdir(INSTALL_PATH . "/server/tests/plugins");
                     include INSTALL_PATH . "/server/tests/plugins/test.ajxp_" . $repo->getAccessType() . ".php";
                     $className = "ajxp_" . $repo->getAccessType();
                     $class = new $className();
                     $result = $class->doRepositoryTest($repo);
                     if (!$result) {
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage(null, $class->failedInfo);
                         AJXP_XMLWriter::close();
                         exit(1);
                     }
                 }
                 ConfService::replaceRepository($repId, $repo);
             }
             AJXP_XMLWriter::header();
             if ($res == -1) {
                 AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.53"]);
             } else {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_conf.54"], null);
                 AJXP_XMLWriter::reloadDataNode("", isset($httpVars["newLabel"]) ? SystemTextEncoding::fromPostedFileName($httpVars["newLabel"]) : false);
                 AJXP_XMLWriter::reloadRepositoryList();
             }
             AJXP_XMLWriter::close();
             exit(1);
         case "add_meta_source":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             $metaSourceType = $httpVars["new_meta_source"];
             $options = array();
             $this->parseParameters($httpVars, $options);
             $repoOptions = $repo->getOption("META_SOURCES");
             if (is_array($repoOptions) && isset($repoOptions[$metaSourceType])) {
                 throw new Exception($mess["ajxp_conf.55"]);
             }
             if (!is_array($repoOptions)) {
                 $repoOptions = array();
             }
             $repoOptions[$metaSourceType] = $options;
             $repo->addOption("META_SOURCES", $repoOptions);
             ConfService::replaceRepository($repId, $repo);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.56"], null);
             AJXP_XMLWriter::close();
             break;
         case "delete_meta_source":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             $metaSourceId = $httpVars["plugId"];
             $repoOptions = $repo->getOption("META_SOURCES");
             if (is_array($repoOptions) && array_key_exists($metaSourceId, $repoOptions)) {
                 unset($repoOptions[$metaSourceId]);
                 $repo->addOption("META_SOURCES", $repoOptions);
                 ConfService::replaceRepository($repId, $repo);
             }
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.57"], null);
             AJXP_XMLWriter::close();
             break;
         case "edit_meta_source":
             $repId = $httpVars["repository_id"];
             $repo = ConfService::getRepositoryById($repId);
             $metaSourceId = $httpVars["plugId"];
             $options = array();
             $this->parseParameters($httpVars, $options);
             $repoOptions = $repo->getOption("META_SOURCES");
             if (!is_array($repoOptions)) {
                 $repoOptions = array();
             }
             $repoOptions[$metaSourceId] = $options;
             $repo->addOption("META_SOURCES", $repoOptions);
             ConfService::replaceRepository($repId, $repo);
             AJXP_XMLWriter::header();
             AJXP_XMLWriter::sendMessage($mess["ajxp_conf.58"], null);
             AJXP_XMLWriter::close();
             break;
         case "delete":
             if (isset($httpVars["repository_id"])) {
                 $repId = $httpVars["repository_id"];
                 //if(get_magic_quotes_gpc()) $repLabel = stripslashes($repLabel);
                 $res = ConfService::deleteRepository($repId);
                 AJXP_XMLWriter::header();
                 if ($res == -1) {
                     AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.51"]);
                 } else {
                     AJXP_XMLWriter::sendMessage($mess["ajxp_conf.59"], null);
                     AJXP_XMLWriter::reloadDataNode();
                     AJXP_XMLWriter::reloadRepositoryList();
                 }
                 AJXP_XMLWriter::close();
                 exit(1);
             } else {
                 if (isset($httpVars["shared_file"])) {
                     AJXP_XMLWriter::header();
                     $element = basename($httpVars["shared_file"]);
                     $publicletData = $this->loadPublicletData(PUBLIC_DOWNLOAD_FOLDER . "/" . $element . ".php");
                     unlink(PUBLIC_DOWNLOAD_FOLDER . "/" . $element . ".php");
                     AJXP_XMLWriter::sendMessage($mess["ajxp_shared.13"], null);
                     AJXP_XMLWriter::reloadDataNode();
                     AJXP_XMLWriter::close();
                 } else {
                     if (isset($httpVars["role_id"])) {
                         $roleId = $httpVars["role_id"];
                         if (AuthService::getRole($roleId) === false) {
                             throw new Exception($mess["ajxp_conf.67"]);
                         }
                         AuthService::deleteRole($roleId);
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage($mess["ajxp_conf.66"], null);
                         AJXP_XMLWriter::reloadDataNode();
                         AJXP_XMLWriter::close();
                     } else {
                         $forbidden = array("guest", "share");
                         if (!isset($httpVars["user_id"]) || $httpVars["user_id"] == "" || in_array($httpVars["user_id"], $forbidden) || $loggedUser->getId() == $httpVars["user_id"]) {
                             AJXP_XMLWriter::header();
                             AJXP_XMLWriter::sendMessage(null, $mess["ajxp_conf.61"]);
                             AJXP_XMLWriter::close();
                             exit(1);
                         }
                         $res = AuthService::deleteUser($httpVars["user_id"]);
                         AJXP_XMLWriter::header();
                         AJXP_XMLWriter::sendMessage($mess["ajxp_conf.60"], null);
                         AJXP_XMLWriter::reloadDataNode();
                         AJXP_XMLWriter::close();
                         exit(1);
                     }
                 }
             }
             break;
         case "clear_expired":
             $deleted = $this->clearExpiredFiles();
             AJXP_XMLWriter::header();
             if (count($deleted)) {
                 AJXP_XMLWriter::sendMessage(sprintf($mess["ajxp_shared.23"], count($deleted) . ""), null);
                 AJXP_XMLWriter::reloadDataNode();
             } else {
                 AJXP_XMLWriter::sendMessage($mess["ajxp_shared.24"], null);
             }
             AJXP_XMLWriter::close();
             break;
         default:
             break;
     }
     return;
 }