Order/Form: documents can be uploaded even if order is closed already
This commit is contained in:
@@ -1041,7 +1041,7 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-2 col-form-label" for="note">Datei auswählen</label>
|
||||
<div class="col-lg-10">
|
||||
<input type="file" name="OrderFileUpload" class="form-control" />
|
||||
<input type="file" name="OrderFileUpload" id="OrderFileUpload" class="form-control" />
|
||||
<small>Erlaubte Dateiendungen: <?=MFUPLOAD_ALLOWED_EXTENSIONS_STR?></small>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1823,9 +1823,47 @@
|
||||
|
||||
//$("#orderForm").detach();
|
||||
|
||||
/*$("#upload-button").click(() => {
|
||||
$("#orderForm").wrap('<form method="post" enctype="formdata/');
|
||||
});*/
|
||||
$("#upload-button").click(async () => {
|
||||
// ajax upload
|
||||
|
||||
const selectedFile = document.getElementById("OrderFileUpload").files[0];
|
||||
console.log(selectedFile);
|
||||
const reader = new FileReader();
|
||||
reader.onload = async () => {
|
||||
const fileContent = reader.result;
|
||||
//console.log(fileContent);
|
||||
|
||||
formdata = new FormData();
|
||||
formdata.append("id", <?=$order->id?>);
|
||||
formdata.append("file_name", $("#order-files select").val());
|
||||
//formdata.append("orig_filename", selectedFile.name);
|
||||
formdata.append("file_description", $("#order-files textarea[name='file_description']").val());
|
||||
formdata.append("file_contents", new Blob([fileContent]), selectedFile.name);
|
||||
|
||||
await fetch("<?=self::getUrl("Order", "api", ["do" => "uploadDocument"])?>", {
|
||||
body: formdata,
|
||||
method: "POST",
|
||||
}).then(resp => {
|
||||
if (resp.ok) {
|
||||
return resp.json();
|
||||
}
|
||||
}).then(data => {
|
||||
if(data.status == "OK") {
|
||||
window.location.replace(window.location.href);
|
||||
} else {
|
||||
window.notify("error", "Fehler beim Dateiupload!");
|
||||
}
|
||||
}).catch(err => {
|
||||
window.notify("error", "Fehler beim Dateiupload!");
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
reader.readAsText(selectedFile);
|
||||
|
||||
|
||||
});
|
||||
$("#upload-button").show();
|
||||
|
||||
|
||||
|
||||
@@ -42,20 +42,12 @@ class File extends mfBaseModel {
|
||||
if($this->id) {
|
||||
$id = $this->id;
|
||||
|
||||
// delete file in store
|
||||
if($this->subfolder) {
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->subfolder."/".$this->store_filename;
|
||||
} else {
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->store_filename;
|
||||
}
|
||||
if(!unlink($path)) {
|
||||
$this->log->warn(__CLASS__."::delete(): Error unlinking file ($path)");
|
||||
// delete physical file
|
||||
if(!unlink($this->getFullPath())) {
|
||||
$this->log->warn(__CLASS__."::delete(): Error unlinking file ({$this->getFullPath()})");
|
||||
}
|
||||
|
||||
$where = "id=$id";
|
||||
if($this->fieldprefix && !strstr($field,"_")) {
|
||||
$where = $this->fieldprefix."_id=$id";
|
||||
}
|
||||
if($this->db->delete($this->table,$where)) {
|
||||
if(method_exists($this, "afterDelete")) {
|
||||
$this->afterDelete();
|
||||
|
||||
@@ -239,7 +239,7 @@ class OrderController extends mfBaseController {
|
||||
&& $lop->product->attributes['termination_required']
|
||||
&& $lop->termination_id
|
||||
) {
|
||||
$has_term = true;
|
||||
$has_term = true; // is already in orders with terminations
|
||||
}
|
||||
}
|
||||
if(!$has_bras && !$has_voice && !$has_term) {
|
||||
@@ -1479,4 +1479,75 @@ class OrderController extends mfBaseController {
|
||||
$this->redirect("Order");
|
||||
}
|
||||
|
||||
protected function apiAction() {
|
||||
$do = $this->request->do;
|
||||
$data = [];
|
||||
|
||||
switch($do) {
|
||||
case "uploadDocument":
|
||||
$return = $this->uploadDocumentApi();
|
||||
break;
|
||||
default:
|
||||
$return = false;
|
||||
}
|
||||
|
||||
if(!is_array($return) || !count($return)) {
|
||||
$data = ["status" => "error"];
|
||||
$this->returnJson($data);
|
||||
}
|
||||
|
||||
if(mfResponse::isResponse($return)) {
|
||||
$this->returnJson($return);
|
||||
} else {
|
||||
$data['status'] = "OK";
|
||||
$data['result'] = $return;
|
||||
$this->returnJson($data);
|
||||
}
|
||||
}
|
||||
|
||||
private function uploadDocumentApi() {
|
||||
$order_id = $this->request->id;
|
||||
$filename = $this->request->file_name;
|
||||
$orig_filename = $this->request->orig_filename;
|
||||
$description = $this->request->file_description;
|
||||
|
||||
if(!$order_id || !is_numeric($order_id) || $order_id < 1) {
|
||||
return false;
|
||||
}
|
||||
$order = new Order($order_id);
|
||||
if(!$order->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!$filename) {
|
||||
$this->log->error(__METHOD__.": No filename");
|
||||
return false;
|
||||
}
|
||||
|
||||
$file = mfUpload::handleFormUpload("file_contents");
|
||||
|
||||
if(!$file) {
|
||||
$this->log->error(__METHOD__.": Error uploading file");
|
||||
return false;
|
||||
} else {
|
||||
$of = [];
|
||||
$of['order_id'] = $order_id;
|
||||
$of['file_id'] = $file->id;
|
||||
$of['name'] = $filename;
|
||||
$of['description'] = $description;
|
||||
|
||||
$orderfile = OrderFileModel::create($of);
|
||||
if(!$orderfile->save()) {
|
||||
$file->delete();
|
||||
$this->log->error(__METHOD__.": Error saving OrderFile object: ".print_r($orderfile, true));
|
||||
} else {
|
||||
// send email based on file type
|
||||
$order->sendFileuploadEmail($orderfile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ["status" => "OK", "message" => "File uploaded successfully"];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class mfUpload {
|
||||
}
|
||||
|
||||
if($randomFileName) {
|
||||
$this->filename = $this->getRandomFilename().'-'.$this->filename;
|
||||
$this->filename = self::getRandomFilename().'-'.$this->filename;
|
||||
}
|
||||
|
||||
$this->size = $this->upload->getFileSize();
|
||||
@@ -184,7 +184,7 @@ class mfUpload {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getRandomFilename() {
|
||||
public static function getRandomFilename() {
|
||||
$length = 20;
|
||||
$characters = '0123456789abcdef';
|
||||
$string = '';
|
||||
|
||||
Reference in New Issue
Block a user