$resourceSrvc = $siteConn->CreateService(MgServiceType::ResourceService); $webLayoutName = "Session:" . $adminSession . "//" . "Map" . rand() . "." . MgResourceType::WebLayout; $webLayOutId = new MgResourceIdentifier($webLayoutName); // get contents of a file into a string try { //under Liunx, we should use '/' instead of '\\' $filename = "profilingmapxml/MapViewerTemplate.xml"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); } catch (Exception $e) { echo $e->getMessage(); } $contents = str_replace("{0}", $mapDefiniton, $contents); $content_byteSource = new MgByteSource($contents, strlen($contents)); $content_byteSource->setMimeType("text/xml"); $content_byteReader = $content_byteSource->GetReader(); $resourceSrvc->SetResource($webLayOutId, $content_byteReader, null); //pass the seesion ID with the url, so when the map viewer is opened, there is no need to re-enter the password $ajaxViewerFolder = "mapviewerajax/?"; //when user installed the ajax java viewer, the apache will add a redict //from mapviewerajax to mapviewerjava, and change the relative path to absolute path //which casues the cross-domain problem //now we check if we install the ajax java, then use the "mapviewerjava/ajaxviewer.jsp?" directly to avoid this problem $os = DIRECTORY_SEPARATOR == '\\' ? "winNT" : "linux"; //under the linux system, the mapviewerjava is always installed, so if someone is running apache + java on linux, //the admin should manually change the line 51 as: //if(file_exists("../mapviewerjava/ajaxviewer.jsp")) if ("winNT" == $os && file_exists("../mapviewerjava/ajaxviewer.jsp")) { $ajaxViewerFolder = "mapviewerjava/ajaxviewer.jsp?"; }
function AddUser($username, $password, $email) { try { $user = new MgUserInformation(MG_ADMIN_USER, MG_ADMIN_PASSWD); $siteConnection = new MgSiteConnection(); $siteConnection->Open($user); $site = $siteConnection->GetSite(); $username = trim($username); $fullname = $username; $site->AddUser($username, $username, $password, $fullname); //set author role $usersToGrant = new MgStringCollection(); $roleToUpdate = new MgStringCollection(); $roleToUpdate->Add(MgRole::Author); $usersToGrant->Add($username); $site->GrantRoleMembershipsToUsers($roleToUpdate, $usersToGrant); // Create user directory in repository: // Create Header $headerContent = $this->GetUserFolderHeader($username); $header_byteSource = new MgByteSource($headerContent, strlen($headerContent)); $header_byteSource->setMimeType("text/xml"); $header_byteReader = $header_byteSource->GetReader(); $resourceService = $siteConnection->CreateService(MgServiceType::ResourceService); // Create Folder $id = new MgResourceIdentifier(MG_USER_DIRECTORY_ROOT . $username . '/'); $resourceService->SetResource($id, NULL, $header_byteReader); $encryptedPassword = crypt($password, SALT); $success = $this->db->queryExec('INSERT INTO users (username, password, disabled, email) VALUES ("' . $username . '", "' . $encryptedPassword . '", 0, "' . $email . '" );'); if ($success) { $userId = $this->db->lastInsertRowid(); //setup default prefs foreach ($this->aszInitialPrefs as $key => $value) { $result = $this->db->SingleQuery('SELECT prefid FROM prefs WHERE name="' . $key . '";'); if ($result) { $prefid = $result; } //TODO: improve efficiency by combining queries $this->AddUserPref($userId, $prefid, $value); } return $this->GetUser($userId); } else { echo "<Error>Failed to insert user</Error>"; return FALSE; } } catch (MgDuplicateUserException $du_e) { echo '<Error>Duplicate user!</Error>'; return FALSE; } catch (MgException $e) { echo "<Error>" . $e->GetMessage() . "\n"; echo $e->GetDetails() . "\n"; echo $e->GetStackTrace() . "</Error>\n"; return FALSE; } }