[ 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 ('ModuleInstall/PackageManager/PackageManagerDisplay.php'); 34 require_once ('ModuleInstall/PackageManager/PackageManager.php'); 35 class PackageController{ 36 var $_pm; 37 38 /** 39 * Constructor: this class is called from the the ajax call and handles invoking the correct 40 * functionality on the server. 41 */ 42 function PackageController(){ 43 $this->_pm = new PackageManager(); 44 } 45 46 function performBasicSearch(){ 47 require_once ('include/json_config.php'); 48 $json_config = new json_config(); 49 $json = getJSONobj(); 50 $search_term = ''; 51 $node_id = ''; 52 if(isset($_REQUEST['search_term'])) { 53 $search_term = nl2br($_REQUEST['search_term']); 54 } 55 if(isset($_REQUEST['node_id'])) { 56 $node_id = nl2br($_REQUEST['node_id']); 57 } 58 $xml = PackageManager::getPackages($node_id); 59 echo 'result = ' . $json->encode(array('packages' => $xml)); 60 } 61 62 /** 63 * Retrieve a list of packages which belong to the corresponding category 64 * 65 * @param category_id this is passed via POST and is the category id of packages 66 * we wish to retrieve 67 * @return packages xml string consisting of the packages and releases which belong to 68 * the category 69 */ 70 function getPackages(){ 71 require_once ('include/json_config.php'); 72 $json_config = new json_config(); 73 $json = getJSONobj(); 74 $category_id = ''; 75 76 if(isset($_REQUEST['category_id'])) { 77 $category_id = nl2br($_REQUEST['category_id']); 78 } 79 $xml = PackageManager::getPackages($category_id); 80 echo 'result = ' . $json->encode(array('package_output' => $xml)); 81 } 82 83 /** 84 * Obtain a list of releases from the server. This function is currently used for generating the patches/langpacks for upgrade wizard 85 * as well as during installation 86 */ 87 function getReleases(){ 88 require_once ('include/json_config.php'); 89 $json_config = new json_config(); 90 $json = getJSONobj(); 91 $category_id = ''; 92 $package_id = ''; 93 $types = ''; 94 if(isset($_REQUEST['category_id'])) { 95 $category_id = nl2br($_REQUEST['category_id']); 96 } 97 if(isset($_REQUEST['package_id'])) { 98 $package_id = nl2br($_REQUEST['package_id']); 99 } 100 if(isset($_REQUEST['types'])) { 101 $types = nl2br($_REQUEST['types']); 102 } 103 $types = explode(',', $types); 104 105 $filter = array(); 106 $count = count($types); 107 $index = 1; 108 $type_str = ''; 109 foreach($types as $type){ 110 $type_str .= "'".$type."'"; 111 if($index < $count) 112 $type_str .= ","; 113 $index++; 114 } 115 116 $filter = array('type' => $type_str); 117 $filter = PackageManager::toNameValueList($filter); 118 $releases = PackageManager::getReleases($category_id, $package_id, $filter); 119 $nodes = array(); 120 $release_map = array(); 121 foreach($releases['packages'] as $release){ 122 $release = PackageManager::fromNameValueList($release); 123 $nodes[] = array('description' => $release['description'], 'version' => $release['version'], 'build_number' => $release['build_number'], 'id' => $release['id']); 124 $release_map[$release['id']] = array('package_id' => $release['package_id'], 'category_id' => $release['category_id']); 125 } 126 $_SESSION['ML_PATCHES'] = $release_map; 127 echo 'result = ' . $json->encode(array('releases' => $nodes)); 128 } 129 130 /** 131 * Obtain a promotion from the depot 132 */ 133 function getPromotion(){ 134 require_once ('include/json_config.php'); 135 $json_config = new json_config(); 136 $json = getJSONobj(); 137 138 $header = PackageManager::getPromotion(); 139 140 echo 'result = ' . $json->encode(array('promotion' => $header)); 141 } 142 143 /** 144 * Download the given release 145 * 146 * @param category_id this is passed via POST and is the category id of the release we wish to download 147 * @param package_id this is passed via POST and is the package id of the release we wish to download 148 * @param release_id this is passed via POST and is the release id of the release we wish to download 149 * @return bool true is successful in downloading, false otherwise 150 */ 151 function download(){ 152 global $sugar_config; 153 require_once ('include/json_config.php'); 154 $json_config = new json_config(); 155 $json = getJSONobj(); 156 $package_id = ''; 157 $category_id = ''; 158 $release_id = ''; 159 if(isset($_REQUEST['package_id'])) { 160 $package_id = nl2br($_REQUEST['package_id']); 161 } 162 if(isset($_REQUEST['category_id'])) { 163 $category_id = nl2br($_REQUEST['category_id']); 164 } 165 if(isset($_REQUEST['release_id'])) { 166 $release_id = nl2br($_REQUEST['release_id']); 167 } 168 $GLOBALS['log']->debug("PACKAGE ID: ".$package_id); 169 $GLOBALS['log']->debug("CATEGORY ID: ".$category_id); 170 $GLOBALS['log']->debug("RELEASE ID: ".$release_id); 171 $result = $this->_pm->download($category_id, $package_id, $release_id, getcwd().'/'.$sugar_config['upload_dir']); 172 $GLOBALS['log']->debug("RESULT: ".print_r($result,true)); 173 $success = 'false'; 174 if($result != null){ 175 $GLOBALS['log']->debug("Performing Setup"); 176 $this->_pm->performSetup($result, 'module', false); 177 $GLOBALS['log']->debug("Complete Setup"); 178 $success = 'true'; 179 } 180 echo 'result = ' . $json->encode(array('success' => $success)); 181 } 182 183 /** 184 * Retrieve a list of categories that are subcategories to the selected category 185 * 186 * @param id - the id of the parent_category, -1 if this is the root 187 * @return array - a list of categories/nodes which are underneath this node 188 */ 189 function getCategories(){ 190 require_once ('include/json_config.php'); 191 $json_config = new json_config(); 192 $json = getJSONobj(); 193 $node_id = ''; 194 if(isset($_REQUEST['category_id'])) { 195 $node_id = nl2br($_REQUEST['category_id']); 196 } 197 $GLOBALS['log']->debug("NODE ID: ".$node_id); 198 $nodes = PackageManager::getCategories($node_id); 199 echo 'result = ' . $json->encode(array('nodes' => $nodes)); 200 } 201 202 function getNodes(){ 203 require_once ('include/json_config.php'); 204 $json_config = new json_config(); 205 $json = getJSONobj(); 206 $category_id = ''; 207 if(isset($_REQUEST['category_id'])) { 208 $category_id = nl2br($_REQUEST['category_id']); 209 } 210 $GLOBALS['log']->debug("CATEGORY ID: ".$category_id); 211 $nodes = PackageManager::getModuleLoaderCategoryPackages($category_id); 212 $GLOBALS['log']->debug(var_export($nodes, true)); 213 echo 'result = ' . $json->encode(array('nodes' => $nodes)); 214 } 215 216 /** 217 * Check the SugarDepot for updates for the given type as passed in via POST 218 * @param type the type to check for 219 * @return array return an array of releases for each given installed object if an update is found 220 */ 221 function checkForUpdates(){ 222 require_once ('include/json_config.php'); 223 $json_config = new json_config(); 224 $json = getJSONobj(); 225 $type = ''; 226 if(isset($_REQUEST['type'])) { 227 $type = nl2br($_REQUEST['type']); 228 } 229 $pm = new PackageManager(); 230 $updates = $pm->checkForUpdates(); 231 $nodes = array(); 232 $release_map = array(); 233 if(!empty($updates)){ 234 foreach($updates as $update){ 235 $update = PackageManager::fromNameValueList($update); 236 $nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']); 237 $release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']); 238 } 239 } 240 //patches 241 $filter = array(array('name' => 'type', 'value' => "'patch'")); 242 $releases = $pm->getReleases('', '', $filter); 243 if(!empty($releases['packages'])){ 244 foreach($releases['packages'] as $update){ 245 $update = PackageManager::fromNameValueList($update); 246 $nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']); 247 $release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']); 248 } 249 } 250 $_SESSION['ML_PATCHES'] = $release_map; 251 echo 'result = ' . $json->encode(array('updates' => $nodes)); 252 } 253 254 function getLicenseText(){ 255 require_once ('include/json_config.php'); 256 $json_config = new json_config(); 257 $json = getJSONobj(); 258 $file = ''; 259 if(isset($_REQUEST['file'])) { 260 $file = nl2br($_REQUEST['file']); 261 } 262 $GLOBALS['log']->debug("FILE : ".$file); 263 echo 'result = ' . $json->encode(array('license_display' => PackageManagerDisplay::buildLicenseOutput($file))); 264 } 265 266 /** 267 * build the list of modules that are currently in the staging area waiting to be installed 268 */ 269 function getPackagesInStaging(){ 270 $packages = $this->_pm->getPackagesInStaging('module'); 271 require_once ('include/json_config.php'); 272 $json_config = new json_config(); 273 $json = getJSONobj(); 274 275 echo 'result = ' . $json->encode(array('packages' => $packages)); 276 } 277 278 /** 279 * build the list of modules that are currently in the staging area waiting to be installed 280 */ 281 function performInstall(){ 282 $file = ''; 283 if(isset($_REQUEST['file'])) { 284 $file = nl2br($_REQUEST['file']); 285 } 286 $file = urldecode($file); 287 $this->_pm->performInstall($file); 288 require_once ('include/json_config.php'); 289 $json_config = new json_config(); 290 $json = getJSONobj(); 291 292 echo 'result = ' . $json->encode(array('result' => 'success')); 293 } 294 295 function authenticate(){ 296 require_once ('include/json_config.php'); 297 $json_config = new json_config(); 298 $json = getJSONobj(); 299 $username = ''; 300 $password = ''; 301 $servername = ''; 302 $terms_checked = ''; 303 if(isset($_REQUEST['username'])) { 304 $username = nl2br($_REQUEST['username']); 305 } 306 if(isset($_REQUEST['password'])) { 307 $password = nl2br($_REQUEST['password']); 308 } 309 if(isset($_REQUEST['servername'])) { 310 $servername = $_REQUEST['servername']; 311 } 312 if(isset($_REQUEST['terms_checked'])) { 313 $terms_checked = $_REQUEST['terms_checked']; 314 if($terms_checked == 'on') 315 $terms_checked = true; 316 } 317 318 if(!empty($username) && !empty($password)){ 319 $password = md5($password); 320 $result = PackageManager::authenticate($username, $password, $servername, $terms_checked); 321 if(!is_array($result) && $result == true) 322 $status = 'success'; 323 else 324 $status = $result['faultstring']; 325 }else{ 326 $status = 'failed'; 327 } 328 329 echo 'result = ' . $json->encode(array('status' => $status)); 330 } 331 332 function getDocumentation(){ 333 require_once ('include/json_config.php'); 334 $json_config = new json_config(); 335 $json = getJSONobj(); 336 $package_id = ''; 337 $release_id = ''; 338 339 if(isset($_REQUEST['package_id'])) { 340 $package_id = nl2br($_REQUEST['package_id']); 341 } 342 if(isset($_REQUEST['release_id'])) { 343 $release_id = nl2br($_REQUEST['release_id']); 344 } 345 346 $documents = PackageManager::getDocumentation($package_id, $release_id); 347 $GLOBALS['log']->debug("DOCUMENTS: ".var_export($documents, true)); 348 echo 'result = ' . $json->encode(array('documents' => $documents)); 349 } 350 351 function downloadedDocumentation(){ 352 require_once ('include/json_config.php'); 353 $json_config = new json_config(); 354 $json = getJSONobj(); 355 $document_id = ''; 356 357 if(isset($_REQUEST['document_id'])) { 358 $document_id = nl2br($_REQUEST['document_id']); 359 } 360 $GLOBALS['log']->debug("Downloading Document: ".$document_id); 361 PackageManagerComm::downloadedDocumentation($document_id); 362 echo 'result = ' . $json->encode(array('result' => 'true')); 363 } 364 365 function remove(){ 366 require_once ('include/json_config.php'); 367 $json_config = new json_config(); 368 $json = getJSONobj(); 369 $file = ''; 370 371 if(isset($_REQUEST['file'])) { 372 $file = urldecode(nl2br($_REQUEST['file'])); 373 } 374 $GLOBALS['log']->debug("FILE TO REMOVE: ".$file); 375 if(!empty($file)){ 376 unlink($file); 377 } 378 echo 'result = ' . $json->encode(array('result' => 'true')); 379 } 380 } 381 ?>
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 |