/**
* upload()
*
* Processes uploaded backup file.
*
* @return array True on upload success; false otherwise.
*/
function upload()
{
if (isset($_POST['upload']) && $_POST['upload'] == 'local') {
if (pb_backupbuddy::$options['password'] != '#PASSWORD#') {
$path_parts = pathinfo($_FILES['file']['name']);
if (strtolower(substr($_FILES['file']['name'], 0, 6)) == 'backup' && strtolower($path_parts['extension']) == 'zip') {
if (move_uploaded_file($_FILES['file']['tmp_name'], basename($_FILES['file']['name']))) {
pb_backupbuddy::alert('File Uploaded. Your backup was successfully uploaded.');
return true;
} else {
pb_backupbuddy::alert('Sorry, there was a problem uploading your file.', true);
return false;
}
} else {
pb_backupbuddy::alert('Only properly named BackupBuddy zip archives with a zip extension may be uploaded.', true);
return false;
}
} else {
pb_backupbuddy::alert('Upload Access Denied. To prevent unauthorized file uploads an importbuddy password must be configured and properly entered to use this feature.');
return false;
}
}
// DOWNLOAD FILE FROM STASH TO LOCAL.
if (pb_backupbuddy::_POST('upload') == 'stash') {
pb_backupbuddy::set_greedy_script_limits(true);
/*
echo '<pre>';
print_r( $_POST );
echo '</pre>';
*/
$requestcore_file = dirname(dirname(dirname(__FILE__))) . '/lib/requestcore/requestcore.class.php';
require_once $requestcore_file;
$link = pb_backupbuddy::_POST('link');
$destination_file = dirname(dirname(dirname(dirname(__FILE__)))) . '/' . basename(pb_backupbuddy::_POST('link'));
$destination_file = substr($destination_file, 0, stripos($destination_file, '.zip') + 4);
$_GET['file'] = basename($destination_file);
$request = new RequestCore($link);
$request->set_write_file($destination_file);
echo '<div id="pb_importbuddy_working" style="padding: 20px;">Downloading backup from Stash to `' . $destination_file . '`...<br><br><img src="' . pb_backupbuddy::plugin_url() . '/images/loading_large.gif" title="Working... Please wait as this may take a moment..."><br><br></div>';
flush();
$response = $request->send_request(false);
if ($response !== true) {
pb_backupbuddy::alert('Error #8548459598. Unable to download file from Stash. You may manually download it and upload to the server via FTP.');
} else {
// No error.
if (!file_exists($destination_file)) {
pb_backupbuddy::alert('Error #34845745878. Stash returned a success but the backup file was not found locally. Check this server\'s directory write permissions. You may manually download it and upload to the server via FTP.');
}
}
echo '<script type="text/javascript">jQuery("#pb_importbuddy_working").hide();</script>';
}
}
开发者ID:brettex,项目名称:pspark,代码行数:59,代码来源:1.php
示例2: closeRequestAdditionalActions
function closeRequestAdditionalActions($requestId)
{
$messageArray = array("message_value" => "Solicitud cerrada con éxito!", "message_type" => "success");
$handlerRequestCore = new RequestCore();
$requestData = $handlerRequestCore->getRequestData($requestId);
// Poner aquí los ID de flujo para customización
switch ($requestData["request_flow"]) {
// Proceso de reclamos
case '1':
$messageArray = reclamoFinalizado($requestId);
break;
// Proceso de adquisiciones
// Proceso de adquisiciones
case '2':
$messageArray = requisicionFinalizada($requestId);
break;
}
return $messageArray;
}
/**
* Consolida las requisiciones correspondientes y mueve las solicitudes en EF
* @return Array
*/
public function consolidarRequisiciones()
{
$returnArray = array('status' => true, 'message' => '');
$input = Request::createFromGlobals();
$requestCore = new \RequestCore();
$flow = $_SESSION['user_flow'];
$step = FlowSettings::get($_SESSION['user_flow'], 'ADQ_STEP_CONSOLIDATION');
$requisiciones = Requisicion::getRequisicionesParaConsolidar();
$ordenescompra = OrdenCompra::getOrdenesCompraParaConsolidar();
// Tomar la tarea actual, si no está completada salir
foreach ($requisiciones as $requisicion) {
if ($requisicion->asignada_totalmente == 0) {
$returnArray['status'] = false;
$returnArray['message'] = 'La requisición ' . $requisicion->id . ' no se encuentra asignada por completo. No se puede continuar';
return $returnArray;
}
}
// Cambiar estado de las ordenes de compra cuyas requisiciones estén totalmente asignadas
foreach ($ordenescompra as $ordencompra) {
$ordencompra->estado = 'C';
$ordencompra->save();
}
foreach ($requisiciones as $requisicion) {
// Solo completar tareas de requisiciones asignadas totalmente
if ($requisicion->asignada_totalmente == 1) {
// Cambiar estado a 'C' (Consolidada)
$requisicion->estado = 'C';
$requisicion->save();
$task = $requisicion->ef_request->open_tasks[0];
// Completar tareas diferentes a la actual
// (No se completa la actual porque EF lo hace por default)
if ($task->task_id != $input->task_id) {
$requestCore->completeTask($task->task_request, $task->task_id, $input->flow_id, $input->step_id, $input->user_id, 'Requisición consolidada por el usuario ' . $_SESSION['user_id'], 'next');
}
}
}
return $returnArray;
}
/**
* Fetches and caches EC2 instance profile credentials. This is meant to be used by the constructor, and is not to
* be manually invoked.
*
* @param CacheCore $cache (Required) The a reference to the cache object that is being used to handle the caching.
* @param array $options (Required) The options that were passed into the constructor.
* @return mixed The data to be cached, or NULL.
*/
public function cache_instance_profile_credentials($cache, $options)
{
$instance_profile_url = 'http://169.254.169.254/latest/meta-data/iam/security-credentials/';
$connect_timeout = isset($options['instance_profile_timeout']) ? $options['instance_profile_timeout'] : 2;
try {
// Make a call to the EC2 Metadata Service to find the available instance profile
$request = new RequestCore($instance_profile_url);
$request->set_curlopts(array(CURLOPT_CONNECTTIMEOUT => $connect_timeout));
$response = $request->send_request(true);
if ($response->isOK()) {
// Get the instance profile name
$profile = (string) $response->body;
// Make a call to the EC2 Metadata Service to get the instance profile credentials
$request = new RequestCore($instance_profile_url . $profile);
$request->set_curlopts(array(CURLOPT_CONNECTTIMEOUT => $connect_timeout));
$response = $request->send_request(true);
if ($response->isOK()) {
// Get the credentials
$credentials = json_decode($response->body, true);
if ($credentials['Code'] === 'Success') {
// Determine the expiration time
$expiration_time = strtotime((string) $credentials['Expiration']);
$expiration_duration = round(($expiration_time - time()) * 0.85);
$cache->expire_in($expiration_duration);
// Return the credential information
return array('key' => $credentials['AccessKeyId'], 'secret' => $credentials['SecretAccessKey'], 'token' => $credentials['Token'], 'expires' => $credentials['Expiration']);
}
}
}
} catch (cURL_Exception $e) {
// The EC2 Metadata Service does not exist or had timed out.
// An exception will be thrown on the next line.
}
// @codeCoverageIgnoreStart
throw new CFCredentials_Exception('No credentials were provided. The SDK attempted to retrieve Instance ' . 'Profile credentials from the EC2 Instance Metadata Service, but failed to do so. Instance profile ' . 'credentials are only accessible on EC2 instances configured with a specific IAM role.');
// @codeCoverageIgnoreEnd
}
/**
* Fetches the activation code for a gateway using its public URL.
*
* @param string $gateway_url (Required) The public URL to a gateway.
* @return string|boolean The activation key for the gateway, or false if it could not be determined.
*/
public function acquire_activation_code($gateway_url)
{
// Send a request to the gateway's URL
$request = new RequestCore($gateway_url);
$request->ssl_verification = false;
$request->set_curlopts(array(CURLOPT_FOLLOWLOCATION => false));
$response = $request->send_request(true);
// Parse the query string from the URL in the location header to get the activation key
if (isset($response->header['location'])) {
$url = $response->header['location'];
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $params);
if (isset($params['activationKey'])) {
return $params['activationKey'];
}
}
return false;
}
public function procesarOrdenesCompra()
{
$input = Request::createFromGlobals();
$returnArray = array('status' => true, 'message' => '');
$requestCore = new \RequestCore();
$arrayRequisiciones = [];
// Traer ordenes de compra
$ordenes_compra = $this->getOrdenesCompra($input->request_id);
// Iterar las ordenes de compra
foreach ($ordenes_compra as $orden_compra) {
// Verificar solo las que tengan cotización seleccionada
$seleccionada = false;
$cotizaciones = $orden_compra->cotizaciones;
foreach ($cotizaciones as $cotizacion) {
if ($cotizacion->estado == 'S') {
$seleccionada = true;
break;
}
}
if ($seleccionada) {
// Actualizar cabecera de OC
$orden_compra->update(['estado' => 'S']);
// Llenar arreglo con número de requisiciones correspondientes
foreach ($orden_compra->lineas as $linea) {
$arrayRequisiciones[] = $linea->linea_requisicion->requisicion->id;
}
}
}
// Mover ef_requests correspondientes
$arrayRequisiciones = array_unique($arrayRequisiciones);
foreach ($arrayRequisiciones as $id_requisicion) {
$requisicion = Requisicion::find($id_requisicion);
$task = $requisicion->ef_request->open_tasks[0];
// Completar tareas diferentes a la actual
// (No se completa la actual porque EF lo hace por default)
if ($task->task_id != $input->task_id) {
$requestCore->completeTask($task->task_request, $task->task_id, $input->flow_id, $input->step_id, $input->user_id, 'Proveedor seleccionado por el usuario ' . $_SESSION['user_id'], 'next');
}
}
return $returnArray;
}
请发表评论