/** * addPackage - add a package in the file release manager of the project $group_id with given values * * @param string $sessionKey the session hash associated with the session opened by the person who calls the service * @param int $group_id the ID of the group we want to add the package * @param string $package_name the name of the package * @param int $status_id the ID of the status of the package * @param int $rank the rank of the package in the package list page (optionnal, by default set to 0) * @param int $approve_license true if we need to approve the license before downloading every file in this package, false otherwise. * @return int the ID of the new created package, * or a soap fault if : * - group_id does not match with a valid project, * - the user does not have the permissions to create a package * - the package creation failed. */ function addPackage($sessionKey, $group_id, $package_name, $status_id, $rank = 0, $approve_license = true) { if (session_continue($sessionKey)) { try { $pm = ProjectManager::instance(); $group = $pm->getGroupByIdForSoap($group_id, 'addPackage'); } catch (SoapFault $e) { return $e; } $pkg_fact = new FRSPackageFactory(); if ($pkg_fact->userCanCreate($group_id)) { // we check that the package name don't already exist if ($pkg_fact->isPackageNameExist($package_name, $group_id)) { return new SoapFault(invalid_package_fault, 'Package name already exists in this project', 'addPackage'); } else { $pkg_array = array('group_id' => $group->getID(), 'name' => $package_name, 'status_id' => $status_id, 'rank' => $rank, 'approve_license' => $approve_license); $dar = $pkg_fact->create($pkg_array); if (!$dar) { return new SoapFault(invalid_package_fault, $dar->isError(), 'addPackage'); } else { // if there is no error, $dar contains the package_id return $dar; } } } else { return new SoapFault(invalid_package_fault, 'User is not allowed to create a package', 'addPackage'); } } else { return new SoapFault(invalid_session_fault, 'Invalid Session', 'addPackage'); } }
$GLOBALS['Response']->redirect('/file/?group_id=' . $group_id); break; case 'add': $package = new FRSPackage(array('group_id' => $group_id)); frs_display_package_form($package, $GLOBALS['Language']->getText('file_admin_editpackages', 'create_new_p'), '?group_id=' . $group_id . '&func=create', $existing_packages); break; case 'create': if (!$request->exist('submit')) { $GLOBALS['Response']->addFeedback('info', $Language->getText('file_admin_editpackages', 'create_canceled')); $GLOBALS['Response']->redirect('/file/?group_id=' . $group_id); } else { $package_data = $request->get('package'); $package_data['group_id'] = $group_id; if (isset($package_data['name']) && isset($package_data['rank']) && isset($package_data['status_id'])) { $package_data['name'] = htmlspecialchars($package_data['name']); if ($frspf->isPackageNameExist($package_data['name'], $group_id)) { $GLOBALS['Response']->addFeedback('error', $Language->getText('file_admin_editpackages', 'p_name_exists')); $package = new FRSPackage($package_data); frs_display_package_form($package, $GLOBALS['Language']->getText('file_admin_editpackages', 'create_new_p'), '?func=create&group_id=' . $group_id, $existing_packages); } else { //create a new package $res_id = $frspf->create($package_data); $GLOBALS['Response']->addFeedback('info', $Language->getText('file_admin_editpackages', 'p_added')); $GLOBALS['Response']->redirect('/file/?group_id=' . $group_id); } } else { $GLOBALS['Response']->addFeedback('error', $GLOBALS['Language']->getText('global', 'missing_parameters')); frs_display_package_form($package, $GLOBALS['Language']->getText('file_admin_editpackages', 'create_new_p'), '?func=create&group_id=' . $group_id, $existing_packages); } } break;