public function creatworksheet() { global $session; if (!empty($_POST["prod_id"]) && !empty($_POST["w_date"])) { if ($session->empright == "Customer Support Engineer") { $newWorkSheet = Worksheet::find_by_formid($_POST['wsid']); } elseif ($session->empright == "Customer Service Services") { $newWorkSheet = new Worksheet(); } else { return 5; exit; } if (isset($_FILES['fupload']) && $_FILES['fupload']['error'] == 0) { //if file upload is set move_uploaded_file($_FILES['fupload']['tmp_name'], "public/uploads/" . basename($_FILES['fupload']['name'])); $image = new Imageresize(); // an instance of image resize object $image->load("public/uploads/" . basename($_FILES['fupload']['name'])); //$image->image =; $image->resize(400, 400); $image->save("public/uploads/" . basename($_FILES['fupload']['name'])); //this section is needed to get the extension for image type in renaming the image if ($_FILES['fupload']['type'] == "image/gif") { $ext = ".gif"; } if ($_FILES['fupload']['type'] == "image/png") { $ext = ".png"; } if ($_FILES['fupload']['type'] == "image/jpeg") { $ext = ".jpeg"; } if ($_FILES['fupload']['type'] == "image/pjpeg") { $ext = ".jpeg"; } if ($_FILES['fupload']['type'] == "image/gif") { $ext = ".gif"; } if ($_FILES['fupload']['type'] == "image/jpg") { $ext = ".jpg"; } $new_name = uniqid() . "_" . time() . $ext; //new name for the image rename("public/uploads/" . basename($_FILES['fupload']['name']), "public/uploads/" . $new_name); $photo = $new_name; $newWorkSheet->scan_url = $photo; } else { //$applicant->img_url = $_POST['imgvalue']; } $mySchedule = Schedule::find_by_id($_POST['wsid']); $newWorkSheet->prod_id = $_POST["prod_id"]; $newWorkSheet->formid = $_POST['wsid']; $newWorkSheet->prod_name = ""; $newWorkSheet->sheet_date = $_POST["w_date"]; $newWorkSheet->time_in = $_POST["time_in"]; $newWorkSheet->time_out = $_POST["time_out"]; $newWorkSheet->contact_person = $_POST["contact_person"]; $newWorkSheet->cse_emp_id = $_POST["emp_id"]; $newWorkSheet->problem = $_POST["problem"]; $newWorkSheet->cause = $_POST["cause"]; $newWorkSheet->corrective_action = $_POST["corrective_action"]; $newWorkSheet->part_changed = $_POST["part_changed"]; $newWorkSheet->cse_remark = $_POST["cse_remark"]; $newWorkSheet->client_remark = $_POST["client_remark"]; $newWorkSheet->datecreated = date("Y-m-d H:i:s"); global $session; if ($session->empright == "Customer Support Services") { if ($newWorkSheet->create()) { $schedulee = Schedule::find_by_id($_POST["wsid"]); $schedulee->status = "Closed"; $schedulee->update(); $_SESSION["message"] = "<div data-alert class='alert-box success'>Record Saved <a href='#' class='close'>×</a></div>"; return 1; //returns 1 on success } else { $_SESSION["message"] = "<div data-alert class='alert-box alert'>Unexpected Error! Record not Saved <a href='#' class='close'>×</a></div>"; return 2; // returns 2 on insert error } } elseif ($session->empright == "Customer Support Engineer") { if ($newWorkSheet->Update()) { $schedulee = Schedule::find_by_id($_POST["wsid"]); $schedulee->status = "Closed"; $schedulee->update(); $_SESSION["message"] = "<div data-alert class='alert-box success'>Record Saved <a href='#' class='close'>×</a></div>"; return 1; //returns 1 on success } else { $_SESSION["message"] = "<div data-alert class='alert-box alert'>Unexpected Error! Record not Saved <a href='#' class='close'>×</a></div>"; return 2; // returns 2 on insert error } } } else { $_SESSION["message"] = "<div data-alert class='alert-box alert'>Unexpected Error! Record not Saved <a href='#' class='close'>×</a></div>"; return 3; //returns 3 if requiered input field is not supplied } }