| [ Index ] |
|
Code source de SugarCRM 5.0.0beta1 |
1 <?php 2 /********************************************************************************* 3 * SugarCRM is a customer relationship management program developed by 4 * SugarCRM, Inc. Copyright (C) 2004 - 2007 SugarCRM Inc. 5 * 6 * This program is free software; you can redistribute it and/or modify it under 7 * the terms of the GNU General Public License version 3 as published by the 8 * Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 13 * details. 14 * 15 * You should have received a copy of the GNU General Public License along with 16 * this program; if not, see http://www.gnu.org/licenses or write to the Free 17 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18 * 02110-1301 USA. 19 * 20 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, 21 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. 22 * 23 * The interactive user interfaces in modified source and object code versions 24 * of this program must display Appropriate Legal Notices, as required under 25 * Section 5 of the GNU General Public License version 3. 26 * 27 * In accordance with Section 7(b) of the GNU General Public License version 3, 28 * these Appropriate Legal Notices must retain the display of the "Powered by 29 * SugarCRM" logo. If the display of the logo is not reasonably feasible for 30 * technical reasons, the Appropriate Legal Notices must display the words 31 * "Powered by SugarCRM". 32 ********************************************************************************/ 33 require_once ('include/nusoap/nusoap.php'); 34 require_once ('ModuleInstall/PackageManager/PackageManagerDownloader.php'); 35 36 define("HTTPS_URL", "https://depot.sugarcrm.com/depot/SugarDepotSoap.php"); 37 38 39 40 define("ACTIVE_STATUS", "ACTIVE"); 41 42 class PackageManagerComm{ 43 /** 44 * Initialize the soap client and store in the $GLOBALS object for use 45 * 46 * @param login designates whether we want to try to login after we initialize or not 47 */ 48 function initialize($login = true){ 49 if(empty($GLOBALS['SugarDepot'])){ 50 $GLOBALS['log']->debug('USING HTTPS TO CONNECT TO HEARTBEAT'); 51 $soap_client = new nusoapclient(HTTPS_URL, false); 52 $ping = $soap_client->call('sugarPing', array()); 53 54 55 56 57 58 59 60 61 62 63 64 $GLOBALS['SugarDepot'] = $soap_client; 65 } 66 //if we do not have a session, then try to login 67 if($login && empty($_SESSION['SugarDepotSessionID'])){ 68 PackageManagerComm::login(); 69 } 70 } 71 72 /** 73 * Check for errors in the response or error_str 74 */ 75 function errorCheck(){ 76 if(!empty($GLOBALS['SugarDepot']->error_str)){ 77 $GLOBALS['log']->fatal($GLOBALS['SugarDepot']->error_str); 78 $GLOBALS['log']->fatal($GLOBALS['SugarDepot']->response); 79 } 80 } 81 82 /** 83 * Set the credentials for use during login 84 * 85 * @param username Mambo username 86 * @param password Mambo password 87 * @param download_key User's download key 88 */ 89 function setCredentials($username, $password, $download_key){ 90 $_SESSION['SugarDepotUsername'] = $username; 91 $_SESSION['SugarDepotPassword'] = $password; 92 $_SESSION['SugarDepotDownloadKey'] = $download_key; 93 } 94 95 /** 96 * Clears out the session so we can reauthenticate. 97 */ 98 function clearSession(){ 99 $_SESSION['SugarDepotSessionID'] = null; 100 unset($_SESSION['SugarDepotSessionID']); 101 } 102 ///////////////////////////////////////////////////////// 103 ////////// BEGIN: Base Functions for Communicating with the depot 104 /** 105 * Login to the depot 106 * 107 * @return true if successful, false otherwise 108 */ 109 function login($terms_checked = true){ 110 if(empty($_SESSION['SugarDepotSessionID'])){ 111 global $license; 112 $GLOBALS['log']->debug("Begin SugarDepot Login"); 113 PackageManagerComm::initialize(false); 114 require ('sugar_version.php'); 115 require ('config.php'); 116 $credentials = PackageManager::getCredentials(); 117 if(empty($license))loadLicense(); 118 $info = sugarEncode('2813', serialize(getSystemInfo(true))); 119 $pm = new PackageManager(); 120 $installed = $pm->buildInstalledReleases(); 121 $installed = base64_encode(serialize($installed)); 122 $params = array('installed_modules' => $installed, 'terms_checked' => $terms_checked, 'system_name' => $credentials['system_name']); 123 $terms_version = (!empty($_SESSION['SugarDepot_TermsVersion']) ? $_SESSION['SugarDepot_TermsVersion'] : ''); 124 if(!empty($terms_version)) 125 $params['terms_version'] = $terms_version; 126 127 $result = $GLOBALS['SugarDepot']->call('depotLogin', array(array('user_name' => $credentials['username'], 'password' => $credentials['password']),'info'=>$info, 'params' => $params)); 128 PackageManagerComm::errorCheck(); 129 if(!is_array($result)) 130 $_SESSION['SugarDepotSessionID'] = $result; 131 $GLOBALS['log']->debug("End SugarDepot Login"); 132 return $result; 133 } 134 else 135 return $_SESSION['SugarDepotSessionID']; 136 } 137 138 /** 139 * Logout from the depot 140 */ 141 function logout(){ 142 PackageManagerComm::initialize(); 143 $result = $GLOBALS['SugarDepot']->call('depotLogout', array('session_id' => $_SESSION['SugarDepotSessionID'])); 144 } 145 146 /** 147 * Get all promotions from the depot 148 */ 149 function getPromotion(){ 150 PackageManagerComm::initialize(); 151 //check for fault first and then return 152 $name_value_list = $GLOBALS['SugarDepot']->call('depotGetPromotion', array('session_id' => $_SESSION['SugarDepotSessionID'])); 153 return $name_value_list; 154 } 155 156 /** 157 * A generic function which given a category_id some filter will 158 * return an object which contains categories and packages 159 * 160 * @param category_id the category_id to fetch 161 * @param filter a filter which will limit theh number of results returned 162 * @return categories_and_packages 163 * @see categories_and_packages 164 */ 165 function getCategoryPackages($category_id, $filter = array()){ 166 PackageManagerComm::initialize(); 167 //check for fault 168 return $GLOBALS['SugarDepot']->call('depotGetCategoriesPackages', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'filter' => $filter)); 169 } 170 171 /** 172 * Return a list of child categories to the parent specified in category_id 173 * 174 * @param category_id the parent category_id 175 * @param filter a filter which will limit theh number of results returned 176 * @return categories_and_packages 177 * @see categories_and_packages 178 */ 179 function getCategories($category_id, $filter = array()){ 180 PackageManagerComm::initialize(); 181 //check for fault 182 return $GLOBALS['SugarDepot']->call('depotGetCategories', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'filter' => $filter)); 183 } 184 185 /** 186 * Return a list of packages which belong to the parent category_id 187 * 188 * @param category_id the category_id to fetch 189 * @param filter a filter which will limit theh number of results returned 190 * @return packages 191 * @see packages 192 */ 193 function getPackages($category_id, $filter = array()){ 194 PackageManagerComm::initialize(); 195 //check for fault 196 return $GLOBALS['SugarDepot']->call('depotGetPackages', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'filter' => $filter)); 197 } 198 199 /** 200 * Return a list of releases belong to a package 201 * 202 * @param category_id the category_id to fetch 203 * @param package_id the package id which the release belongs to 204 * @return packages 205 * @see packages 206 */ 207 function getReleases($category_id, $package_id, $filter = array()){ 208 PackageManagerComm::initialize(); 209 //check for fault 210 return $GLOBALS['SugarDepot']->call('depotGetReleases', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'package_id' => $package_id, 'filter' => $filter)); 211 } 212 213 /** 214 * Download a given release 215 * 216 * @param category_id the category_id to fetch 217 * @param package_id the package id which the release belongs to 218 * @param release_id the release we want to download 219 * @return download 220 * @see download 221 */ 222 function download($category_id, $package_id, $release_id){ 223 PackageManagerComm::initialize(); 224 //check for fault 225 return $GLOBALS['SugarDepot']->call('depotDownloadRelease', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'package_id' => $package_id, 'release_id' => $release_id)); 226 } 227 228 /** 229 * Add a requested download to the queue 230 * 231 * @param category_id the category_id to fetch 232 * @param package_id the package id which the release belongs to 233 * @param release_id the release we want to download 234 * @return the filename to download 235 */ 236 function addDownload($category_id, $package_id, $release_id){ 237 PackageManagerComm::initialize(); 238 //check for fault 239 return $GLOBALS['SugarDepot']->call('depotAddDownload', array('session_id' => $_SESSION['SugarDepotSessionID'], 'category_id' => $category_id, 'package_id' => $package_id, 'release_id' => $release_id, 'download_key' => '123')); 240 } 241 242 /** 243 * Call the PackageManagerDownloader function which uses curl in order to download the specified file 244 * 245 * @param filename the file to download 246 * @return path to downloaded file 247 */ 248 function performDownload($filename, $save_dir){ 249 PackageManagerComm::initialize(); 250 //check for fault 251 $GLOBALS['log']->debug("Performing download from depot: Session ID: ".$_SESSION['SugarDepotSessionID']." Filename: ".$filename); 252 return PackageManagerDownloader::download($_SESSION['SugarDepotSessionID'], $filename, $save_dir); 253 } 254 255 /** 256 * Retrieve documentation for the given release or package 257 * 258 * @param package_id the specified package to retrieve documentation 259 * @param release_id the specified release to retrieve documentation 260 * 261 * @return documents 262 */ 263 function getDocumentation($package_id, $release_id){ 264 PackageManagerComm::initialize(); 265 //check for fault 266 return $GLOBALS['SugarDepot']->call('depotGetDocumentation', array('session_id' => $_SESSION['SugarDepotSessionID'], 'package_id' => $package_id, 'release_id' => $release_id)); 267 } 268 269 function getTermsAndConditions(){ 270 PackageManagerComm::initialize(false); 271 return $GLOBALS['SugarDepot']->call('depotTermsAndConditions',array()); 272 } 273 274 /** 275 * Log that the user has clicked on a document 276 * 277 * @param document_id the document the user has clicked on 278 */ 279 function downloadedDocumentation($document_id){ 280 PackageManagerComm::initialize(); 281 //check for fault 282 $GLOBALS['log']->debug("Logging Document: ".$document_id); 283 $GLOBALS['SugarDepot']->call('depotDownloadedDocumentation', array('session_id' => $_SESSION['SugarDepotSessionID'], 'document_id' => $document_id)); 284 } 285 286 /** 287 * Send the list of installed objects, could be patches, or modules, .. to the depot and allow the depot to send back 288 * a list of corresponding updates 289 * 290 * @param objects_to_check an array of name_value_lists which contain the appropriate values 291 * which will allow the depot to check for updates 292 * 293 * @return array of name_value_lists of corresponding updates 294 */ 295 function checkForUpdates($objects_to_check){ 296 PackageManagerComm::initialize(); 297 //check for fault 298 return $GLOBALS['SugarDepot']->call('depotCheckForUpdates', array('session_id' => $_SESSION['SugarDepotSessionID'], 'objects' => $objects_to_check)); 299 } 300 /** 301 * Ping the server to determine if we have established proper communication 302 * 303 * @return true if we can communicate with the server and false otherwise 304 */ 305 function isAlive(){ 306 PackageManagerComm::initialize(false); 307 308 $status = $GLOBALS['SugarDepot']->call('sugarPing', array()); 309 if(empty($status) || $GLOBALS['SugarDepot']->getError() || $status != ACTIVE_STATUS){ 310 return false; 311 }else{ 312 return true; 313 } 314 } 315 ////////// END: Base Functions for Communicating with the depot 316 //////////////////////////////////////////////////////// 317 } 318 319 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Tue Sep 11 10:48:47 2007 | par Balluche grâce à PHPXref 0.7 |