function manageOutput($soap_params, &$output, &$fd) { $output = false; if ($soap_params['output']) { $output = $soap_params['output']; } elseif ($soap_params['remote_name']) { $fileInfo = $GLOBALS['soap']->call('getFileInfo', $soap_params); $output = basename($fileInfo->file_name); } if ($output !== false) { while (!($fd = @fopen($output, "wb"))) { echo "Couldn't open file " . $output . " for writing.\n"; $output = ""; while (!$output) { $output = get_user_input("Please specify a new file name: "); } } } }
function soapResult($params, $soap_result, $fieldnames = array(), $loaded_params = array()) { $file = $soap_result->bin_data; if ($loaded_params['others']['output']) { $output = $loaded_params['others']['output']; while (!($fh = @fopen($output, "wb"))) { echo "Couldn't open file " . $output . " for writing.\n"; $output = ""; while (!$output) { $output = get_user_input("Please specify a new file name: "); } } fwrite($fh, $file, strlen($file)); fclose($fh); if (!$loaded_params['others']['quiet']) { echo "File retrieved successfully.\n"; } } else { if (!$loaded_params['others']['quiet']) { echo $file; } // if not saving to a file, output to screen } }
#photoset_doc = zooomr.photosets.create("Photoset title", # "description", # first_photo_id, # rule_set, # $PHOTOSFROM_EVERYONE, # $SORTEDBY_AWESOMENESS, # token) $photoset_id = $photoset_doc->photoset->id; $zooomr->photosets->getInfo(array('photoset_id' => $photoset_id)); $zooomr->photosets->getInfo(array('photoset_id' => "30060")); $zooomr->photosets->getList(array('user_id' => "bluemonki")); $zooomr->photosets->edit(array('photoset_id' => $photoset_id, 'title' => "New title", 'primary_photo_id' => $first_photo_id, 'auth_token' => $token)); get_user_input("Check that a photoset has been edited"); $zooomr->photosets->getPhotos(array('photoset_id' => $photoset_id)); $zooomr->photosets->delete(array('photoset_id' => $photoset_id, 'auth_token' => $token)); get_user_input("Check that a photoset has been deleted"); # tags $photo_tags = $zooomr->tags->getListPhoto(array('photo_id' => $first_photo_id)); $user_tags = $zooomr->tags->getListUser(array('user_id' => "bluemonki")); # test $params = array('param_name' => "param_value"); $zooomr->test->echo_call($params); $zooomr->test->login(array('auth_token' => $token)); # delete the photo $zooomr->photos->delete(array('photo_id' => $first_photo_id, 'auth_token' => $token)); get_user_input("Check that the first photo has been deleted"); # test zipline $zooomr->zipline->postLine(array('status' => "Final testing of the PHP Zooomr API", 'auth_token' => $token)); $zooomr->zipline->getLine(array('auth_token' => $token)); get_user_input("Check that a zipline post has been created");
/** * Get the variables for a task from the command line. This function is used when * adding/updating a task * * @param bool Specify that we're getting the variables for adding a task and not updating * @return array */ function get_task_params($adding = false) { global $PARAMS, $SOAP, $LOG; $group_id = get_working_group($PARAMS); $ret = array(); $ret["data"] = array(); $ret["desc"] = array(); $updating = !$adding; // we're updating if and only if we're not adding $group_project_id = get_parameter($PARAMS, "group", true); if (!$group_project_id || !is_numeric($group_project_id)) { exit_error("You must specify the group ID as a valid number"); } // Force the input of the task ID only if we're updating if ($updating) { if (!($project_task_id = get_parameter($PARAMS, "id", true))) { $project_task_id = get_user_input("ID of the task to modify: "); } if (!$project_task_id || !is_numeric($project_task_id)) { exit_error("You must specify the task ID as a valid number"); } // check the task ID is valid $tasks = $SOAP->call("getProjectTasks", array("group_id" => $group_id, "group_project_id" => $group_project_id, "assigned_to" => "", "status" => "", "category" => "", "group" => "")); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } $original_data = array(); foreach ($tasks as $task) { if ($task["project_task_id"] == $project_task_id) { $original_data = $task; $original_summary = $task["summary"]; break; } } // The task wasn't found if (count($original_data) == 0) { exit_error("The task #" . $project_task_id . " doesn't exist"); } } // Check the summary if (!($summary = get_parameter($PARAMS, "summary")) && $adding) { $summary = get_user_input("Summary for this task: "); } $summary = trim($summary); if ($adding && !$summary) { // Summary is required only if adding an artifact exit_error("You must specify a summary for this item"); } // Check the details if (!($details = get_parameter($PARAMS, "details")) && $adding) { $details = get_user_input("Details for this task: "); } $details = trim($details); if ($adding && !$details) { exit_error("You must specify a detail for this item"); } // Check the priority if (!($priority = get_parameter($PARAMS, "priority", true)) && $adding) { // set a default value (only if adding) $priority = 3; } if (!is_null($priority) && (!is_numeric($priority) || $priority < 1 || $priority > 5)) { exit_error("The priority must be a number between 1 and 5"); } // Check the estimated hours if (!($hours = get_parameter($PARAMS, "hours", true)) && $adding) { // set a default value (only if adding) exit_error("You must define the estimated hours with the --hours parameter"); } if (!is_null($hours) && !is_numeric($hours)) { exit_error("The estimated hours must be a valid number"); } // Check the start date $start_date = get_parameter($PARAMS, "start_date", true); if ($start_date) { if ($date_error = check_date($start_date)) { exit_error("The starting date is invalid: " . $date_error); } else { $start_date = convert_date($start_date); } } else { if ($adding) { // set a default value (only if adding) $start_date = time(); } } $start_date_desc = strftime("%Y-%m-%d", $start_date); // Check the end date $end_date = get_parameter($PARAMS, "end_date", true); if ($end_date) { if ($date_error = check_date($end_date)) { exit_error("The ending date is invalid: " . $date_error); } else { $end_date = convert_date($end_date); } } else { if ($adding) { // set a default value (only if adding): one week after the starting date $end_date = $start_date + 60 * 60 * 24 * 7; } } $end_date_desc = strftime("%Y-%m-%d", $end_date); // Check the category if (!($category_id = get_parameter($PARAMS, "category", true)) && $adding) { $category_id = 100; // "none" } if ($category_id && !is_numeric($category_id)) { exit_error("The category ID must be a valid number"); } // Check the percent if (!($percent_complete = get_parameter($PARAMS, "percent", true)) && $adding) { // default value if adding $percent_complete = 0; } if (!is_null($percent_complete) && (!is_numeric($percent_complete) || $percent_complete < 0 || $percent_complete > 100 || $percent_complete % 5 != 0)) { exit_error("The percent must be a number divisible by 5 between 0 and 100"); } // Check the status (only if updating) $status_desc = ""; if ($updating) { if ($status_id = get_parameter($PARAMS, "status", true)) { if (strtolower($status_id) == "open" || strtolower($status_id) == "o" || $status_id == STATUS_OPEN) { $status_id = STATUS_OPEN; $status_desc = "Open"; } elseif (strtolower($status_id) == "closed" || strtolower($status_id) == "c" || $status_id == STATUS_CLOSED) { $status_id = STATUS_CLOSED; $status_desc = "Closed"; } else { exit_error("Status must be either " . STATUS_OPEN . " (open) or " . STATUS_CLOSED . " (closed)"); } } } // assigned_to is a list of comma-separated user IDs $assigned_to = get_parameter($PARAMS, "assigned_to", true); if ($assigned_to) { // special value if (strtolower($assigned_to) == "nobody") { $assigned_to = array(100); } else { $assigned_to = split(",", $assigned_to); //check they're all valid ints for ($i = 0; $i < count($assigned_to); $i++) { if (!is_numeric($assigned_to[$i])) { exit_error("The list of users must be a comma-separated list of valid users IDs"); } else { $assigned_to[$i] = intval($assigned_to[$i]); } } } } elseif ($adding) { $assigned_to = array(); } // dependent_on is a list of comma-separated task IDs $dependent_on = get_parameter($PARAMS, "dependent_on", true); if ($dependent_on) { // special value if (strtolower($dependent_on) == "none") { $dependent_on = array(); } else { $dependent_on = split(",", $dependent_on); //check they're all valid ints for ($i = 0; $i < count($dependent_on); $i++) { if (!is_numeric($dependent_on[$i])) { exit_error("The list of dependent tasks must be a comma-separated list of valid task IDs"); } else { $dependent_on[$i] = intval($dependent_on[$i]); } } } } elseif ($adding) { $dependent_on = array(); } else { // if updating, set to null to indicate we don't want any changes $dependent_on = null; } $group_id = get_working_group($PARAMS); // Check for invalid IDs $group_res = $SOAP->call("getGroups", array("group_ids" => array($group_id))); if (count($group_res) == 0) { // Group doesn't exist exit_error("Group " . $group_id . " doesn't exist"); } $group_name = $group_res[0]["group_name"]; $project_group_res = $SOAP->call("getProjectGroups", array("group_id" => $group_id)); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } $found = false; foreach ($project_group_res as $project_group) { if ($project_group["group_project_id"] == $group_project_id) { $found = true; $group_project_name = $project_group["name"]; break; } } if (!$found) { exit_error("Group #" . $group_project_id . " doesn't exist"); } // check the category_id exists $category_name = ""; if ($category_id && $category_id != 100) { $categories_res = $SOAP->call("getProjectTaskCategories", array("group_id" => $group_id, "group_project_id" => $group_project_id)); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } $found = false; foreach ($categories_res as $category) { if ($category["category_id"] == $category_id) { $found = true; $category_name = $category["category_name"]; break; } } if (!$found) { exit_error("Category #" . $category_id . " doesn't exist"); } } elseif ($adding) { $category_name = "(none)"; } // check the users IDs $assigned_to_names = ""; if (count($assigned_to) > 0) { $users_res = $SOAP->call("getUsers", array("user_ids" => $assigned_to)); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } // check all IDs are valid foreach ($assigned_to as $user_id) { $found = false; foreach ($users_res as $user) { if ($user["user_id"] == $user_id) { $found = true; $assigned_to_names .= $user["firstname"] . " " . $user["lastname"] . " (" . $user["user_name"] . "), "; break; } } if (!$found) { exit_error("Invalid user ID: " . $user_id); } } // Remove trailing , $assigned_to_names = preg_replace("/, \$/", "", $assigned_to_names); } elseif ($adding) { $assigned_to_names = "(nobody)"; } // check the dependent tasks $dependent_on_names = ""; if (count($dependent_on) > 0) { $tasks_res = $SOAP->call("getProjectTasks", array("group_id" => $group_id, "group_project_id" => $group_project_id, "assigned_to" => "", "status" => "", "category" => "", "group" => "")); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } foreach ($dependent_on as $dependent_on_id) { $found = false; foreach ($tasks_res as $task) { if ($task["project_task_id"] == $dependent_on_id) { $found = true; $dependent_on_names .= $task["summary"] . ", "; break; } } if (!$found) { exit_error("Invalid task ID: " . $dependent_on_id); } } // Remove trailing , $dependent_on_names = preg_replace("/, \$/", "", $dependent_on_names); } elseif ($adding || $updating && !is_null($dependent_on)) { $dependent_on_names = "(none)"; } $ret["data"]["group_id"] = $group_id; $ret["data"]["group_project_id"] = $group_project_id; if ($updating) { $ret["data"]["project_task_id"] = $project_task_id; $ret["data"]["original_data"] = $original_data; if ($summary) { $ret["data"]["summary"] = $summary; } if ($details) { $ret["data"]["details"] = $details; } if (!is_null($priority)) { $ret["data"]["priority"] = $priority; } if (!is_null($hours)) { $ret["data"]["hours"] = $hours; } if ($start_date) { $ret["data"]["start_date"] = $start_date; } if ($end_date) { $ret["data"]["end_date"] = $end_date; } if ($category_id) { $ret["data"]["category_id"] = $category_id; } if (!is_null($percent_complete)) { $ret["data"]["percent_complete"] = $percent_complete; } if (count($assigned_to) > 0) { $ret["data"]["assigned_to"] = $assigned_to; } if (!is_null($dependent_on)) { $ret["data"]["dependent_on"] = $dependent_on; } if (!is_null($status_id)) { $ret["data"]["status_id"] = $status_id; } $ret["desc"]["group_name"] = $group_name; $ret["desc"]["group_project_name"] = $group_project_name; $ret["desc"]["original_summary"] = $original_summary; if ($summary) { $ret["desc"]["summary"] = $summary; } if ($priority) { $ret["desc"]["priority"] = $priority; } if (!is_null($hours)) { $ret["desc"]["hours"] = $hours; } if ($start_date) { $ret["desc"]["start_date"] = $start_date_desc; } if ($end_date) { $ret["desc"]["end_date"] = $end_date_desc; } if ($category_name) { $ret["desc"]["category_name"] = $category_name; } if (!is_null($percent_complete)) { $ret["desc"]["percent_complete"] = $percent_complete . "%"; } if ($assigned_to_names) { $ret["desc"]["assigned_to"] = $assigned_to_names; } if ($dependent_on_names) { $ret["desc"]["dependent_on"] = $dependent_on_names; } if ($details) { $ret["desc"]["details"] = $details; } if ($status_desc) { $ret["desc"]["status"] = $status_desc; } } else { $ret["data"]["summary"] = $summary; $ret["data"]["details"] = $details; $ret["data"]["priority"] = $priority; $ret["data"]["hours"] = $hours; $ret["data"]["start_date"] = $start_date; $ret["data"]["end_date"] = $end_date; $ret["data"]["category_id"] = $category_id; $ret["data"]["percent_complete"] = $percent_complete; $ret["data"]["assigned_to"] = $assigned_to; $ret["data"]["dependent_on"] = $dependent_on; $ret["desc"]["group_name"] = $group_name; $ret["desc"]["group_project_name"] = $group_project_name; $ret["desc"]["summary"] = $summary; $ret["desc"]["priority"] = $priority; $ret["desc"]["hours"] = $hours; $ret["desc"]["start_date"] = $start_date_desc; $ret["desc"]["end_date"] = $end_date_desc; $ret["desc"]["category_name"] = $category_name; $ret["desc"]["percent_complete"] = $percent_complete . "%"; $ret["desc"]["assigned_to"] = $assigned_to_names; $ret["desc"]["dependent_on"] = $dependent_on_names; $ret["desc"]["details"] = $details; } return $ret; }
/** * Get the variables for an artifact from the command line. This function is used when * adding/updating an artifact * * @param bool Specify that we're getting the variables for adding an artifact and not updating * @return array */ function get_artifact_params($adding = false) { global $PARAMS, $SOAP, $LOG, $extra_fields; $group_id = get_working_group($PARAMS); $ret = array(); $updating = !$adding; // we're updating if and only if we're not adding // Check the type ID if (!($group_artifact_id = get_parameter($PARAMS, "type", true))) { $group_artifact_id = get_user_input("Type ID of the artifact: "); } if (!$group_artifact_id || !is_numeric($group_artifact_id)) { exit_error("You must specify the type ID of the artifact as a valid number"); } // Force the input of the artifact ID only if we're updating if ($updating) { if (!($artifact_id = get_parameter($PARAMS, "id", true))) { $artifact_id = get_user_input("ID of the artifact to modify: "); } if (!$artifact_id || !is_numeric($artifact_id)) { exit_error("You must specify the artifact ID as a valid number"); } // check the artifact ID is valid $artifacts = $SOAP->call("getArtifacts", array("group_id" => $group_id, "group_artifact_id" => $group_artifact_id, "assigned_to" => "", "status" => "")); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } $original_data = array(); foreach ($artifacts as $artifact) { if ($artifact["artifact_id"] == $artifact_id) { $original_data = $artifact; $artifact_summary = $artifact["summary"]; } } // The artifact wasn't found if (count($original_data) == 0) { exit_error("The artifact #" . $artifact_id . " doesn't belong to tracker #" . $group_artifact_id); } } // Check the priority if (!($priority = get_parameter($PARAMS, "priority", true)) && $adding) { // set a default value (only if adding) $priority = 3; } if ($priority && (!is_numeric($priority) || $priority < 1 || $priority > 5)) { exit_error("The priority must be a number between 1 and 5"); } // ID of the user the artifact is assigned to if (!($assigned_to = get_parameter($PARAMS, "assigned_to", true)) && $adding) { $assigned_to = 100; // 100 = nobody } // Status ID (only for updating) if ($updating) { $status_id = get_parameter($PARAMS, "status", true); } // Check the summary if (!($summary = get_parameter($PARAMS, "summary")) && $adding) { $summary = get_user_input("Summary for this item: "); } $summary = trim($summary); if ($adding && !$summary) { // Summary is required only if adding an artifact exit_error("You must specify a summary for this item"); } // Check the details if (!($details = get_parameter($PARAMS, "details")) && $adding) { $details = get_user_input("Details for this item: "); } $details = trim($details); if ($adding && !$details) { exit_error("You must specify a detail for this item"); } // Check for invalid IDs // Get the group $group_res = $SOAP->call("getGroups", array("group_ids" => array($group_id))); if (count($group_res) == 0) { // Group doesn't exist exit_error("Group " . $group_id . " doesn't exist"); } $group_name = $group_res[0]["group_name"]; // Get the artifact type $artifact_type_res = $SOAP->call("getArtifactTypes", array("group_id" => $group_id)); if (is_array($artifact_type_res) && count($artifact_type_res) > 0) { $found = false; // Search the name of the selected artifact type in the array of artifact types for the project for ($i = 0; $i < count($artifact_type_res); $i++) { if ($artifact_type_res[$i]["group_artifact_id"] == $group_artifact_id) { $found = true; $artifact_type_name = $artifact_type_res[$i]["name"]; $artifact_index = $i; break; } } if (!$found) { exit_error("Type number " . $group_artifact_id . " doesn't belong to project " . $group_name); } } else { exit_error("Type number " . $group_artifact_id . " doesn't belong to project " . $group_name); } // Get the extra fields for this artifact and validate the input $extra_fields_tmp = $artifact_type_res[$artifact_index]["extra_fields"]; $extra_fields = array(); $extra_fields_data = array(); $efd_index = 0; // rebuild the array in a more convenient way foreach ($extra_fields_tmp as $extra_field) { $alias = $extra_field["alias"]; if (strlen($alias) == 0) { continue; } $extra_fields[$alias] = $extra_field; // Get the value specified for this extra field (if any) $value = get_parameter($PARAMS, $alias, true); // the extra field wasn't specified but it is required... if ($adding && strlen($value) == 0 && $extra_field["is_required"]) { exit_error("You must specify the parameter '" . $alias . "'"); } if (strlen($value) > 0) { $value_ok = false; switch ($extra_field["field_type"]) { case ARTIFACT_EXTRAFIELDTYPE_TEXT: case ARTIFACT_EXTRAFIELDTYPE_TEXTAREA: // this doesn't need validation $value_ok = true; break; case ARTIFACT_EXTRAFIELDTYPE_CHECKBOX: case ARTIFACT_EXTRAFIELDTYPE_MULTISELECT: if (strtolower($value) == "none") { $value = "100"; $value_ok = true; break; } // in this case, $value is a list of comma-separated ids $available_values_str = ""; // first get the list of the available values foreach ($extra_field["available_values"] as $available_value) { $available_values_str .= $available_value["element_id"] . " (" . $available_value["element_name"] . "), "; } // remove trailing , $available_values_str = preg_replace("/, \$/", "", $available_values_str); $value_ok = true; $values = split(",", $value); $invalid_values = array(); // list of invalid values entered by the user foreach ($values as $id) { $found = false; foreach ($extra_field["available_values"] as $available_value) { // note we are comparing strings if ("{$id}" == "" . $available_value["element_id"]) { $found = true; break; } } if (!$found) { $value_ok = false; $invalid_values[] = $id; } } if (!$value_ok) { if (count($invalid_values) == 1) { $error = "Value " . $invalid_values[0] . " is invalid for the field '" . $extra_field["field_name"] . "'. Available values are: " . $available_values_str; } else { $error = "Values " . implode(",", $invalid_values) . " are invalid for the field '" . $extra_field["field_name"] . "'. Available values are: " . $available_values_str; } } break; case ARTIFACT_EXTRAFIELDTYPE_STATUS: case ARTIFACT_EXTRAFIELDTYPE_RADIO: case ARTIFACT_EXTRAFIELDTYPE_SELECT: // Map the value entered by the user to an existing element_id $available_values_str = ""; foreach ($extra_field["available_values"] as $available_value) { $available_values_str .= $available_value["element_id"] . " (" . $available_value["element_name"] . "), "; // note we are comparing strings if ("" . $available_value["element_id"] == "{$value}") { $value_ok = true; } } // remove trailing , $available_values_str = preg_replace("/, \$/", "", $available_values_str); if (!$value_ok) { $error = "Value '{$value}' is invalid for the field '" . $extra_field["field_name"] . "'. Available values are: " . $available_values_str; } break; } if (!$value_ok) { exit_error($error); } else { $extra_fields_data[$efd_index] = array(); $extra_fields_data[$efd_index]["extra_field_id"] = $extra_field["extra_field_id"]; $extra_fields_data[$efd_index]["field_data"] = $value; $efd_index++; } } } // Get the user if ($assigned_to) { $users_res = $SOAP->call("getUsers", array("user_ids" => array($assigned_to))); if (!$SOAP->getError() && is_array($users_res) && count($users_res) > 0) { $assigned_to_name = $users_res[0]["firstname"] . " " . $users_res[0]["lastname"] . " (" . $users_res[0]["user_name"] . ")"; } else { exit_error("Invalid user ID: " . $assigned_to); } } else { $assigned_to_name = "(nobody)"; } // return the data to insert $ret["data"]["group_id"] = $group_id; $ret["data"]["group_artifact_id"] = $group_artifact_id; if ($updating) { $ret["data"]["artifact_id"] = $artifact_id; $ret["data"]["original_data"] = $original_data; if ($status_id) { $ret["data"]["status_id"] = $status_id; } if ($priority) { $ret["data"]["priority"] = $priority; } if ($assigned_to) { $ret["data"]["assigned_to"] = $assigned_to; } if ($summary) { $ret["data"]["summary"] = $summary; } if ($details) { $ret["data"]["details"] = $details; } } else { $ret["data"]["priority"] = $priority; $ret["data"]["assigned_to"] = $assigned_to; $ret["data"]["summary"] = $summary; $ret["data"]["details"] = $details; } $ret["data"]["extra_fields_data"] = $extra_fields_data; // also return the textual description of the data $ret["desc"]["group_name"] = $group_name; $ret["desc"]["artifact_type_name"] = $artifact_type_name; if ($updating) { $ret["desc"]["original_summary"] = $artifact_summary; } if ($priority) { $ret["desc"]["priority"] = $priority; } if ($summary) { $ret["desc"]["summary"] = $summary; } if ($details) { $ret["desc"]["details"] = $details; } if ($assigned_to) { $ret["desc"]["assigned_to_name"] = $assigned_to_name; } return $ret; }
/** * default_do_login - Login in the system */ function default_do_login() { global $PARAMS, $SOAP, $LOG; if (get_parameter($PARAMS, "help")) { echo <<<EOF login - Log into GForge server Available parameters: --username=<username> or -U <username> Specify the user name --password=<password> or -p <password> Specify the password. If none is entered, it will be asked (note that this is the UNIX name of the project) --project=<projectname> (Optional) Select a project to work on --help Show this screen Example: gforge login -U john -p doe --project=myproject EOF; return; } $username = get_parameter($PARAMS, array("username", "U"), true); $password = get_parameter($PARAMS, array("password", "p"), true); $host = get_parameter($PARAMS, "host", true); $secure = get_parameter($PARAMS, array("secure", "s")); $projectname = get_parameter($PARAMS, "project", true); // If no username is specified, use the system user name if (strlen($username) == 0) { if (array_key_exists("USER", $_ENV)) { $username = $_ENV["USER"]; } else { exit_error("You must specify the user name with the --username parameter"); } } // If no password is specified, ask for it if (strlen($password) == 0) { $password = get_user_input("Password: "******"https"; } else { $protocol = "http"; } $SOAP->setWSDL($protocol . "://" . $host . "/soap/?wsdl"); } // Terminate an existing session (if any) $SOAP->endSession(); // try to login in the server $session_string = $SOAP->call("login", array("userid" => $username, "passwd" => $password), false); // there was an error if ($err = $SOAP->getError()) { exit_error($err, $SOAP->faultcode); } // Login is OK, $result containts the session hash string $LOG->add("Logged in as user " . $username . ", using session string " . $session_string); echo "Logged in.\n"; $SOAP->setSessionString($session_string); $SOAP->setSessionUser($username); // If project was specified, get project information and store for future use if (strlen($projectname) > 0) { $group_id = get_group_id($projectname); if (!$group_id) { exit_error("Project \"" . $projectname . "\" doesn't exist"); } $SOAP->setSessionGroupID($group_id); $LOG->add("Using group #" . $group_id); } $SOAP->saveSession(); }
function docman_do_getfile() { global $PARAMS, $SOAP, $LOG; $group_id = get_working_group($PARAMS); if (!($doc_group = get_parameter($PARAMS, "doc_group"))) { exit_error("You must specify a document group id: (e.g.) --doc_group=3"); } if (!($doc_id = get_parameter($PARAMS, "doc_id"))) { exit_error("You must specify a document id: (e.g.) --doc_id=10"); } $params = array("group_id" => $group_id, "doc_group" => $doc_group, "doc_id" => $doc_id); $res = $SOAP->call("getDocumentFiles", $params); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } if (!is_array($res) || count($res) == 0) { die("No files were found for this document."); } $filename = $res[0]['filename']; if (strcmp($res[0]['filetype'], "URL") == 0) { die("This document can be found in the following URL: " . $filename . "\n"); } // Should we save the contents to a file? $output = get_parameter($PARAMS, "output", true); if ($output) { if (file_exists($filename)) { $sure = get_user_input("File {$filename} already exists. Do you want to overwrite it? (y/n): "); if (strtolower($sure) != "y" && strtolower($sure) != "yes") { exit_error("Retrieval of file aborted"); } } } $file = base64_decode($res[0]['data']); if ($output) { while (!($fh = @fopen($filename, "wb"))) { echo "Couldn't open file {$filename} for writing.\n"; $filename = ""; while (!$filename) { $filename = get_user_input("Please specify a new file name: "); } } fwrite($fh, $file, strlen($file)); fclose($fh); echo "File: {$filename} retrieved successfully.\n"; } else { echo $file; // if not saving to a file, output to screen } }
function frs_do_getfile() { global $PARAMS, $SOAP, $LOG; if (!($package_id = get_parameter($PARAMS, "package", true))) { exit_error("You must define a package with the --package parameter"); } if (!($release_id = get_parameter($PARAMS, "release", true))) { exit_error("You must define a release with the --release parameter"); } if (!($file_id = get_parameter($PARAMS, "id", true))) { exit_error("You must define a file with the --id parameter"); } // Should we save the contents to a file? $output = get_parameter($PARAMS, "output", true); if ($output) { if (file_exists($output)) { $sure = get_user_input("File {$output} already exists. Do you want to overwrite it? (y/n): "); if (strtolower($sure) != "y" && strtolower($sure) != "yes") { exit_error("Retrieval of file aborted"); } } } $group_id = get_working_group($PARAMS); $cmd_params = array("group_id" => $group_id, "package_id" => $package_id, "release_id" => $release_id, "file_id" => $file_id); $res = $SOAP->call("getFile", $cmd_params); if ($error = $SOAP->getError()) { $LOG->add($SOAP->responseData); exit_error($error, $SOAP->faultcode); } $file = base64_decode($res); if ($output) { while (!($fh = @fopen($output, "wb"))) { echo "Couldn't open file " . $output . " for writing.\n"; $output = ""; while (!$output) { $output = get_user_input("Please specify a new file name: "); } } fwrite($fh, $file, strlen($file)); fclose($fh); echo "File retrieved successfully.\n"; } else { echo $file; // if not saving to a file, output to screen } }