public function create() { //if( !empty($_POST["issue"]) ){ $newticket = new Ticket(); $error = array(); if (isset($_POST["cname"])) { if ($_POST['cname'] != "") { $newticket->contact_name = $_POST['cname']; } else { array_push($error, "Name"); } } else { array_push($error, "Name"); } if (isset($_POST["terminal_id"])) { if ($_POST['terminal_id'] != "") { $newticket->terminal_id = $_POST['terminal_id']; } else { array_push($error, "Terminal ID"); } } else { array_push($error, "Terminal ID"); } if (isset($_POST["atm_type"])) { if ($_POST['atm_type'] != "") { $newticket->atm_type = $_POST['atm_type']; } else { array_push($error, "ATM TYPE"); } } else { array_push($error, "ATM TYPE"); } if (isset($_POST["branch"])) { if ($_POST['branch'] != "") { $newticket->branch = $_POST['branch']; } else { array_push($error, "Branch"); } } else { array_push($error, "Branch"); } if (isset($_POST["email"])) { if ($_POST['email'] != "" && preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})\$/i", $_POST["email"])) { $newticket->contact_email = $_POST['email']; } else { array_push($error, "Email"); } } else { array_push($error, "Email"); } if (isset($_POST["phone"])) { if ($_POST['phone'] != "" && ctype_digit($_POST['phone'])) { $newticket->contact_phone = $_POST['phone']; } else { array_push($error, "Phone Number"); } } else { array_push($error, "Phone Number"); } if (isset($_POST["location"])) { $newticket->location = $_POST["location"]; } else { array_push($error, "Location"); } if (isset($_POST["plevel"])) { $newticket->priority = $_POST["plevel"]; } else { array_push($error, "Priority"); } if (isset($_POST["issue"])) { $newticket->issue = htmlspecialchars($_POST['issue']); } else { array_push($error, "Issue"); } if (isset($_POST["subject"])) { $newticket->subject = htmlspecialchars($_POST['subject']); } else { $newticket->subject = htmlspecialchars($_POST['issue']); } $newticket->department = $_POST["dept"]; $newticket->datecreated = $newticket->datemodified = date("Y-m-d H:i:s"); $newticket->status = "Open"; $newticket->client_id = $_SESSION["client_ident"]; if (!empty($_FILES['fupload']['name']) && $_FILES['fupload']['error'] == 0) { //if file upload is set move_uploaded_file($_FILES['fupload']['tmp_name'], "public/uploads/" . basename($_FILES['fupload']['name'])); $ext = pathinfo($_FILES['fupload']['name'], PATHINFO_EXTENSION); $new_name = uniqid() . "_" . time() . $ext; //new name for the image rename("public/uploads/" . basename($_FILES['fupload']['name']), "public/uploads/" . $new_name); $photo = $new_name; $newticket->file = $photo; } if (empty($error)) { if (Cproduct::find_by_terminal($_POST['terminal_id'])) { $cproduct = Cproduct::find_by_terminal($_POST['terminal_id']); $cproduct->client_id = $_SESSION["client_ident"]; //$cproduct->client_name = $_POST["clientname"]; $cproduct->prod_id = $_POST['terminal_id']; $cproduct->terminal_id = $_POST['terminal_id']; $cproduct->prod_name = $_POST['product_name']; $cproduct->branch = $_POST['branch']; $cproduct->atm_type = $_POST['atm_type']; $cproduct->install_status = 1; $cproduct->status = 1; $cproduct->client_id = $_SESSION['client_ident']; $cproduct->install_city = $_POST['city']; $cproduct->install_address = $_POST['location']; $cproduct->install_state = $_POST['state']; $cproduct->update(); $newticket->prod_id = $cproduct->id; } else { $cproduct = new Cproduct(); $cproduct->client_id = $_SESSION["client_ident"]; //$cproduct->client_name = $_POST["clientname"]; $cproduct->prod_id = $_POST['terminal_id']; $cproduct->terminal_id = $_POST['terminal_id']; $cproduct->prod_name = $_POST['product_name']; $cproduct->branch = $_POST['branch']; $cproduct->atm_type = $_POST['atm_type']; $cproduct->install_status = 1; $cproduct->status = 1; $cproduct->datecreated = date("Y-m-d H:i:s"); $cproduct->install_city = $_POST['city']; $cproduct->install_address = $_POST['location']; $cproduct->install_state = $_POST['state']; $cproduct->create(); $newticket->prod_id = $cproduct->id; $newticket->prod_id = $cproduct->id; } // } $newticket->terminal_id = $cproduct->terminal_id; if ($newticket->create()) { $ddticket = Ticket::find_by_id($newticket->id); $issue = array(); $objIssue = Issue::find_all(); $ddticket->subject = ""; foreach ($objIssue as $objI) { if (isset($_POST[$objI->issue_accronym])) { $issueLog = new Issuelog(); $issueLog->ticket_id = $newticket->id; $issueLog->issue_id = $objI->id; $issueLog->issue_accronym = $objI->issue_accronym; $issueLog->issue_name = $objI->issue_name; $issueLog->prod_id = $newticket->prod_id; $issueLog->datecreated = date("Y-m-d H:i:s"); $ddticket->subject .= $_POST[$objI->issue_accronym] . ", "; $issueLog->create(); } } $ddticket->issue = $ddticket->subject . "\r\n" . $_POST['issue']; $ddticket->update(); // = Ticket::find_by_id($newticket->id); $newReply = new Ticketreply(); $newReply->sender_id = $newticket->client_id; $newReply->ticket_id = $newticket->id; $theCustomer = Client::find_by_id($_SESSION["client_ident"]); $newReply->sender_name = $theCustomer->name; $newReply->sender_type = "Client"; $newReply->message = $ddticket->issue; $newReply->datecreated = date("Y-m-d H:i:s"); $newReply->create(); if (!empty($_POST['ccemail'])) { $emails = explode(",", $_POST['ccemail']); $emaillenght = count($emails); for ($j = 0; $j < $emaillenght; $j++) { if (preg_match("/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})\$/i", trim($emails[$j]))) { $ccemail = new Ccemail(); $ccemail->email = trim($emails[$j]); $ccemail->ticket_id = $newticket->id; $ccemail->create(); } } } $this->sendMail($newReply->id); return 1; //returns 1 on success } else { return 2; // returns 2 on insert error } } else { $message = "Please check the following errors: "; $lenght = count($error); for ($i = 0; $i < $lenght; $i++) { $message = $message . $error[$i] . ", "; } echo "<div data-alert class='alert-box error'><a href='#' class='close'>×</a>{$message}</div>"; } }
public function create() { if (!empty($_POST['clientid']) && !empty($_POST['prodname']) && !empty($_POST['serial']) && !empty($_POST["address"])) { /*if(Client::find_by_id($_POST['clientid'])){ return 4; //Ensures that user creates the clients before proceeding exit; } if(Client::find_by_id($_POST['prodid'])){ return 5; //Cannot enter ensures that users enter an existing product in the category exit; }*/ $newProduct = new Cproduct(); 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; $newProduct->img_url = $photo; } else { //$applicant->img_url = $_POST['imgvalue']; } $cid = explode(",", $_POST["country"]); $newProduct->client_id = $_POST["clientid"]; $newProduct->client_name = $_POST["clientname"]; $newProduct->prod_id = $_POST["prodid"]; $newProduct->prod_name = $_POST["prodname"]; $newProduct->prod_serial = $_POST["serial"]; $newProduct->install_address = $_POST["address"]; $newProduct->install_country = $cid[1]; $newProduct->install_state = $_POST["state"]; $newProduct->install_city = $_POST["city"]; $newProduct->install_status = 0; $newProduct->status = 0; $newProduct->branch = $_POST['site']; $newProduct->atm_type = $_POST["mmode"]; $newProduct->os = $_POST["os"]; $newProduct->selling_price = $_POST["amount"]; $newProduct->datecreated = date("Y-m-d H:i:s"); global $session; if ($newProduct->create()) { $_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 } }
public function activate() { global $database; $error = array(); $activate = new Activation(); $input = $_REQUEST; if (isset($_POST["contact_name"])) { if ($_POST['contact_name'] != "") { $activate->contact_name = $_POST['contact_name']; } else { array_push($error, "Contact Name"); } } else { array_push($error, "Contact Name"); } if (isset($_POST["terminal_id"])) { if ($_POST['terminal_id'] != "") { $activate->contact_name = $_POST['terminal_id']; } else { array_push($error, "Terminal ID"); } } else { array_push($error, "Terminal ID"); } if (empty($error)) { $cproduct = Cproduct::find_by_terminal($_POST['terminal_id']); if ($cproduct) { $cproduct->client_id = $_SESSION["client_ident"]; //$cproduct->client_name = $_POST["clientname"]; $cproduct->terminal_id = $_POST['terminal_id']; $cproduct->prod_name = $_POST['product_name']; $cproduct->branch = $_POST['branch']; $cproduct->atm_type = $_POST['atm_type']; $cproduct->install_status = 1; $cproduct->status = 1; $cproduct->client_id = $_SESSION['client_ident']; $cproduct->install_city = $_POST['city']; $cproduct->install_address = $_POST['location']; $cproduct->install_state = $_POST['state']; $cproduct->update(); } else { $cproduct = new Cproduct(); $cproduct->client_id = $_SESSION["client_ident"]; //$cproduct->client_name = $_POST["clientname"]; $cproduct->terminal_id = $_POST['terminal_id']; $cproduct->prod_name = $_POST['product_name']; $cproduct->branch = $_POST['branch']; $cproduct->atm_type = $_POST['atm_type']; $cproduct->install_status = 1; $cproduct->status = 1; $cproduct->datecreated = date("Y-m-d H:i:s"); $cproduct->install_city = $_POST['city']; $cproduct->install_address = $_POST['location']; $cproduct->install_state = $_POST['state']; $cproduct->create(); } if (!empty($input)) { foreach ($input as $key => $value) { $activate->{$key} = $value; } $activate->client_id = $_SESSION['client_ident']; $activate->prod_id = $cproduct->id; $activate->created_at = date("Y-m-d H:i:s"); $activate->updated_at = date("Y-m-d H:i:s"); } if ($activate->create()) { return 1; //returns 1 on success } else { return 2; //unexpected Error } } else { /* $message = "Please check the following errors: "; $lenght = count($error); for($i = 0; $i < $lenght; $i++){ $message = $message.$error[$i].", "; } echo "<div data-alert class='alert-box error'><a href='#' class='close'>×</a>$message</div>";*/ return 3; } }