Page MenuHomeGRNET

hc_no_oc.php
No OneTemporary

File Metadata

Created
Sat, Mar 21, 3:36 AM

hc_no_oc.php

<?php
include_once("global_const.php");
include_once('utility.php');
include_once('db.php');
include_once("borrowing.php");
include_once("biblio.php");
include_once("message.php");
include_once("mail.php");
session_start();
$_SESSION['db'] = new DB();
$_SESSION['lang'] = "gr";
include_once("../contents/lang/gr/const.php");
function update_nilde_dd($ddid, $stato_hc) {
$borrow = new Borrowing($ddid);
if ($borrow->dd_id > 0) {
$bibforni = new Biblio($borrow->bi_idforni);
switch ($stato_hc) {
case (int) 0:
$borrow->dd_stato_ddill = 0;
$borrow->dd_stato_file = getConstVar("DD_STATO_FILE_DOWNLOAD_READY");
break;
case -1:
case -2:
$borrow->dd_stato_ddill = 0;
$borrow->dd_stato_file = getConstVar("DD_STATO_FILE_NO_DOWNLOAD");
break;
case 1:
$borrow->dd_stato_ddill = 0;
$borrow->dd_stato_file = getConstVar("DD_STATO_FILE_DOWNLOAD_HC");
break;
case 2:
$borrow->dd_stato_ddill = 0;
$borrow->dd_stato_file = getConstVar("DD_STATO_FILE_DOWNLOAD_WM");
break;
}
$borrow->dd_stato_borr = getConstVar("BORR_CONS_DIRETTA");
$borrow->dd_file = $ddid . ".pdf";
$ok = $borrow->aggiornaDB();
} else {
sendAjaxXML(501, getConstVar("ERR_LASTMODIFY_MSG"), null, null);
exit();
}
}
$msg = null;
$er = false;
if (isset($_GET["recover"]) && $_GET["recover"] == 1 && isset($_GET["ddid"]) && isset($_GET["statofile"])) {
update_nilde_dd($_GET["ddid"], $_GET["statofile"]);
echo "Recovery of ID: " . $_GET["ddid"] . " successfully performed. New State: " . $_GET["statofile"];
} else
if (isset($_POST["ddid"]) && isset($_POST["statofile"])) {
$borrow = new Borrowing($_POST["ddid"]);
}
if ($_POST["statofile"] == 1 || $_POST["statofile"] == 2) {
$upload_folder = getConstVar("HC_UPLOAD_DIR");
} else if ($_POST["statofile"] == 0 || $_POST["statofile"] == -2 || $_POST["statofile"] == -1) {
$upload_folder = getConstVar("UPLOAD_DIR");
}
if ($_POST["statofile"] == 1 || $_POST["statofile"] == 2 || $_POST["statofile"] == 0 || $_POST["statofile"] == -2 || $_POST["statofile"] == -1) {
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
$aaa = move_uploaded_file($_FILES['userfile'] ['tmp_name'], $upload_folder . $_POST["ddid"] . ".pdf");
if ($aaa) {
$msg = $_POST["ddid"] . " moved to " . $upload_folder . "-> OK | ";
$filename = $upload_folder . $_POST["ddid"] . ".pdf";
$credentials = array(
'{username}',
'{password}'
);
$header[] = "Content-Type: application/pdf";
$post_fields = array('file' => '@' . $filename);
$APP = "{URL}" . $_POST["ddid"] . ".pdf";
$ch = curl_init();
$filesize = filesize($filename);
$fp = fopen($filename, 'r');
$options = array(
CURLOPT_URL => $APP,
CURLOPT_HTTPHEADER => $header,
CURLOPT_PUT => true,
CURLOPT_POSTFIELDS => $post_fields,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_UPLOAD => true,
CURLOPT_INFILE => $fp,
CURLOPT_INFILESIZE => $filesize,
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_USERPWD => implode(':', $credentials),
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CAINFO => "/nilde_files/HaricaHeallinkCAR1.pem",
CURLOPT_CERTINFO => TRUE
);
curl_setopt_array($ch, $options);
$postResult = curl_exec($ch);
$info = curl_getinfo($ch);
$error_no = curl_errno($ch);
fclose($fp);
curl_close($ch);
if ($error_no == 0) {
$msg .= "uploaded to owncloud -> OK | ";
$url = "{URL}";
$ch2 = curl_init();
$post_fields_share = array(
'path' => 'Documents/' . $_POST["ddid"] . ".pdf",
'shareType' => '3',
'permissions' => '1',
);
$options = array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $post_fields_share,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_USERPWD => implode(':', $credentials),
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_CAINFO => "{path to CA}",
CURLOPT_CERTINFO => TRUE
);
curl_setopt_array($ch2, $options);
$postResult2 = curl_exec($ch2);
$result = simplexml_load_string($postResult2);
$info2 = curl_getinfo($ch2);
$error_no2 = curl_errno($ch2);
curl_close($ch2);
if ($error_no2 == 0 && $result->meta->status == 'ok' && $result->meta->statuscode == 100) {
$msg .= "owncloud share has been created successfully -> OK | ";
$ut = $_SESSION['db']->execute("SELECT ut_id FROM docdel WHERE dd_id=" . $borrow->dd_id);
if ($ut && $_SESSION['db']->numrows($ut) == 1) {
$utente = $_SESSION['db']->fetch($ut);
$resrichie = $_SESSION['db']->execute("SELECT ut_nome,ut_cognome,ut_email FROM utente WHERE ut_id=" . $utente["ut_id"]);
if ($resrichie && $_SESSION['db']->numrows($resrichie) == 1) {
$dati_utente = $_SESSION['db']->fetch($resrichie);
$ut_email = $dati_utente['ut_email'];
}
$GET_VARS = "token=" . $result->data->token . "&id=" . $result->data->id . "&fn=" . $_POST["ddid"] . ".pdf";
$download_url = "<a href=\"https://diadosis.grnet.gr/modules/hc_download_file.php?" . $GET_VARS . "\">https://diadosis.grnet.gr/modules/hc_download_file.php?" . $GET_VARS . "</a>";
$testmsg = getConstVar("download_article_1") . $download_url . getConstVar("download_article_2");
$testMail = new Mail($ut_email, "test@mail.gr", getConstVar("SUBJECTLN_DOWNLOAD") . $borrow->dd_id, $testmsg);
$testMail->send();
$msg .= 'Selecting user from DB and send email -> OK';
} else {
$msg .= 'Problem in selecting user from DB. Email is not sent';
$er = true;
update_nilde_dd(0, -1);
}
} else {
$msg .= 'File uploaded to owncloud but Share NOT Created. Error number: ' . $error_no2;
$er = true;
update_nilde_dd(0, -1);
}
} else {
$msg .= $_POST["ddid"] . " ERROR - Can't upload file to owncloud. Error number: " . $error_no;
$er = true;
update_nilde_dd(0, -1);
}
} else {
$er = true;
$msg = $_POST["ddid"] . " ERROR - Error in uploading/moving file to " . $upload_folder . $_POST["ddid"] . ".pdf";
update_nilde_dd(0, -1);
}
}
if (!$er)
update_nilde_dd($_POST["ddid"], $_POST["statofile"]);
else {
$file_orig = $upload_folder . $_POST["ddid"] . ".pdf";
$ut = $_SESSION['db']->execute("SELECT ut_id FROM docdel WHERE dd_id=" . $borrow->dd_id);
if ($ut && $_SESSION['db']->numrows($ut) == 1) {
$utente = $_SESSION['db']->fetch($ut);
$resrichie = $_SESSION['db']->execute("SELECT ut_nome,ut_cognome,ut_email FROM utente WHERE ut_id=" . $utente["ut_id"]);
if ($resrichie && $_SESSION['db']->numrows($resrichie) == 1) {
$dati_utente = $_SESSION['db']->fetch($resrichie);
$ut_email = $dati_utente['ut_email'];
}
$GET_VARS = "f=".$file_orig . "&fn=" . $_POST["ddid"] . ".pdf";;
$download_url = "<a href=\"https://diadosis.grnet.gr/modules/hc_download_file.php?" . $GET_VARS . "\">https://diadosis.grnet.gr/modules/hc_download_file.php?" . $GET_VARS . "</a>";
$testmsg = getConstVar("download_article_1") . $download_url . getConstVar("download_article_2");
$testMail = new Mail($ut_email, "nilde@heal-link.gr", getConstVar("SUBJECTLN_DOWNLOAD") . $borrow->dd_id, $testmsg);
$testMail->send();
$msg .= 'Selecting user from DB and send email with original file -> OK';
}
}
echo $msg;
} else
echo $_POST["statofile"] . " " . $_POST["ddid"] . " - ERROR - Wrong Parameters or POST error. Probably original file sent. Check owncloud first.";
?>

Event Timeline