|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 * Copyright (C) 2005 Alfresco, Inc. 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 00019 * As a special exception to the terms and conditions of version 2.0 of 00020 * the GPL, you may redistribute this Program in connection with Free/Libre 00021 * and Open Source Software ("FLOSS") applications as described in Alfresco's 00022 * FLOSS exception. You should have recieved a copy of the text describing 00023 * the FLOSS exception, and it is also available here: 00024 * http://www.alfresco.com/legal/licensing" 00025 */ 00026 00027 // change by moodle 00028 require_once $CFG->libdir.'/alfresco/Service/WebService/WebServiceFactory.php'; 00029 require_once $CFG->libdir.'/alfresco/Service/BaseObject.php'; 00030 00031 if (isset($_SESSION) == false) 00032 { 00033 // Start the session 00034 session_start(); 00035 } 00036 00037 // change by moodle 00038 class Alfresco_Repository extends BaseObject 00039 { 00040 private $_connectionUrl; 00041 private $_host; 00042 private $_port; 00043 00044 public function __construct($connectionUrl="http://localhost:8080/alfresco/api") 00045 { 00046 $this->_connectionUrl = $connectionUrl; 00047 $parts = parse_url($connectionUrl); 00048 $this->_host = $parts["host"]; 00049 if (empty($parts["port"])) { 00050 $this->_port = 80; 00051 } else { 00052 $this->_port = $parts["port"]; 00053 } 00054 } 00055 00056 public function getConnectionUrl() 00057 { 00058 return $this->_connectionUrl; 00059 } 00060 00061 public function getHost() 00062 { 00063 return $this->_host; 00064 } 00065 00066 public function getPort() 00067 { 00068 return $this->_port; 00069 } 00070 00071 public function authenticate($userName, $password) 00072 { 00073 // TODO need to handle exceptions! 00074 00075 $authenticationService = WebServiceFactory::getAuthenticationService($this->_connectionUrl); 00076 $result = $authenticationService->startSession(array ( 00077 "username" => $userName, 00078 "password" => $password 00079 )); 00080 00081 // Get the ticket and sessionId 00082 $ticket = $result->startSessionReturn->ticket; 00083 $sessionId = $result->startSessionReturn->sessionid; 00084 00085 // Store the session id for later use 00086 if ($sessionId != null) 00087 { 00088 $sessionIds = null; 00089 if (isset($_SESSION["sessionIds"]) == false) 00090 { 00091 $sessionIds = array(); 00092 } 00093 else 00094 { 00095 $sessionIds = $_SESSION["sessionIds"]; 00096 } 00097 $sessionIds[$ticket] = $sessionId; 00098 $_SESSION["sessionIds"] = $sessionIds; 00099 } 00100 00101 return $ticket; 00102 } 00103 00104 public function createSession($ticket=null) 00105 { 00106 $session = null; 00107 00108 if ($ticket == null) 00109 { 00110 // TODO get ticket from some well known location ie: the $_SESSION 00111 } 00112 else 00113 { 00114 // TODO would be nice to be able to check that the ticket is still valid! 00115 00116 // Create new session 00117 $session = new Session($this, $ticket); 00118 } 00119 00120 return $session; 00121 } 00122 00126 public static function getSessionId($ticket) 00127 { 00128 $result = null; 00129 if (isset($_SESSION["sessionIds"]) == true) 00130 { 00131 $result = $_SESSION["sessionIds"][$ticket]; 00132 } 00133 return $result; 00134 00135 } 00136 00137 } 00138 00139 ?>