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">
|
<div class="form-group row">
|
||||||
<label class="col-lg-2 col-form-label" for="note">Datei auswählen</label>
|
<label class="col-lg-2 col-form-label" for="note">Datei auswählen</label>
|
||||||
<div class="col-lg-10">
|
<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>
|
<small>Erlaubte Dateiendungen: <?=MFUPLOAD_ALLOWED_EXTENSIONS_STR?></small>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -1823,9 +1823,47 @@
|
|||||||
|
|
||||||
//$("#orderForm").detach();
|
//$("#orderForm").detach();
|
||||||
|
|
||||||
/*$("#upload-button").click(() => {
|
$("#upload-button").click(async () => {
|
||||||
$("#orderForm").wrap('<form method="post" enctype="formdata/');
|
// 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();
|
$("#upload-button").show();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+10
-18
@@ -40,26 +40,18 @@ class File extends mfBaseModel {
|
|||||||
|
|
||||||
public function delete() {
|
public function delete() {
|
||||||
if($this->id) {
|
if($this->id) {
|
||||||
$id = $this->id;
|
$id = $this->id;
|
||||||
|
|
||||||
// delete file in store
|
// delete physical file
|
||||||
if($this->subfolder) {
|
if(!unlink($this->getFullPath())) {
|
||||||
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->subfolder."/".$this->store_filename;
|
$this->log->warn(__CLASS__."::delete(): Error unlinking file ({$this->getFullPath()})");
|
||||||
} else {
|
}
|
||||||
$path = MFUPLOAD_FILE_SAVE_PATH."/".$this->store_filename;
|
|
||||||
}
|
|
||||||
if(!unlink($path)) {
|
|
||||||
$this->log->warn(__CLASS__."::delete(): Error unlinking file ($path)");
|
|
||||||
}
|
|
||||||
|
|
||||||
$where = "id=$id";
|
$where = "id=$id";
|
||||||
if($this->fieldprefix && !strstr($field,"_")) {
|
if($this->db->delete($this->table,$where)) {
|
||||||
$where = $this->fieldprefix."_id=$id";
|
if(method_exists($this, "afterDelete")) {
|
||||||
}
|
$this->afterDelete();
|
||||||
if($this->db->delete($this->table,$where)) {
|
}
|
||||||
if(method_exists($this, "afterDelete")) {
|
|
||||||
$this->afterDelete();
|
|
||||||
}
|
|
||||||
$this->data = new stdClass();
|
$this->data = new stdClass();
|
||||||
$this->id = "";
|
$this->id = "";
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ class OrderController extends mfBaseController {
|
|||||||
&& $lop->product->attributes['termination_required']
|
&& $lop->product->attributes['termination_required']
|
||||||
&& $lop->termination_id
|
&& $lop->termination_id
|
||||||
) {
|
) {
|
||||||
$has_term = true;
|
$has_term = true; // is already in orders with terminations
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!$has_bras && !$has_voice && !$has_term) {
|
if(!$has_bras && !$has_voice && !$has_term) {
|
||||||
@@ -1286,7 +1286,7 @@ class OrderController extends mfBaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function saveVorortterminAction() {
|
protected function saveVorortterminAction() {
|
||||||
if(!$this->me->is(["Admin","salespartner"])) {
|
if(!$this->me->is(["Admin","salespartner"])) {
|
||||||
$this->layout()->setFlash("Keine Berechtigung", "error");
|
$this->layout()->setFlash("Keine Berechtigung", "error");
|
||||||
@@ -1478,5 +1478,76 @@ class OrderController extends mfBaseController {
|
|||||||
|
|
||||||
$this->redirect("Order");
|
$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) {
|
if($randomFileName) {
|
||||||
$this->filename = $this->getRandomFilename().'-'.$this->filename;
|
$this->filename = self::getRandomFilename().'-'.$this->filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->size = $this->upload->getFileSize();
|
$this->size = $this->upload->getFileSize();
|
||||||
@@ -184,7 +184,7 @@ class mfUpload {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRandomFilename() {
|
public static function getRandomFilename() {
|
||||||
$length = 20;
|
$length = 20;
|
||||||
$characters = '0123456789abcdef';
|
$characters = '0123456789abcdef';
|
||||||
$string = '';
|
$string = '';
|
||||||
|
|||||||
Reference in New Issue
Block a user