public function save($params, $payment_id = 0) { $returnArray = array(); // Adjust the params for the further DB usage. foreach ($params as $key => $value) { $params[$key] = $this->db->res($value); } util_UtilFunctions::p($params); $validationArray = $this->validate($params); if (empty($validationArray) === FALSE) { $returnArray['result'] = FALSE; $returnArray['error'] = implode(' ', $validationArray); } else { // Check if we are adding a new Payment or updating an old one. if ((int) $payment_id > 0) { $query = ' UPDATE payment SET date = ' . $this->db->quote(util_UtilFunctions::dateFormat($params['date'], 'sql')) . ', paid_amount = ' . (double) $params['paid_amount'] . ', bank_name = ' . $this->db->quote($params['bank_name']) . ', extras = ' . $this->db->quote($params['extras']) . ' WHERE id = ' . (int) $payment_id . ' '; } else { $query = ' INSERT INTO payment (id, date, paid_amount, bank_name, extras) VALUES ( DEFAULT, ' . $this->db->quote(util_UtilFunctions::dateFormat($params['date'], 'sql')) . ', ' . (double) $params['paid_amount'] . ', ' . $this->db->quote($params['bank_name']) . ', ' . $this->db->quote($params['extras']) . ' )'; } $result = $this->db->query($query); $returnArray = array(); $returnArray['result'] = $result; $returnArray['error'] = $this->db->error(); } return $returnArray; }
/** * @return string */ public function generateHTML($options = array()) { $string = '<select id=\'' . $this->id . '\' name=\'' . $this->name . '\' class=\'' . $this->css_class . '\'>'; if (empty($options) === FALSE) { foreach ($options as $index => $row) { if ((int) $this->selected_id === (int) $row['id']) { $string .= '<option selected=\'selected\' value=\'' . $row['id'] . '\'>' . $row['sf_option'] . '</option>'; } else { $string .= '<option value=\'' . $row['id'] . '\'>' . $row['sf_option'] . '</option>'; } } } $string .= '</select>'; $script = '$(function() { $(\'#' . $this->id . '\').select2({ placeholder: \'' . $this->placeHolder . '\' }); });'; $string .= '<script>' . $script . '</script>'; util_UtilFunctions::p($string); return $string; }
public function save($params, $deal_id = 0) { $returnArray = array(); // Adjust the params for the further DB usage. foreach ($params as $key => $value) { $params[$key] = $this->db->res($value); } util_UtilFunctions::p($params); $validationArray = $this->validate($params); if (empty($validationArray) === FALSE) { $returnArray['result'] = FALSE; $returnArray['error'] = implode(' ', $validationArray); } else { // Check if we are adding a new Customer or updating an old one. if ((int) $deal_id > 0) { $query = ' UPDATE deal SET customer_id = ' . (int) $params['customer_id'] . ', article_id = ' . (int) $params['article_id'] . ', amount = ' . (int) $params['amount'] . ', total_price = ' . (double) $params['total_price'] . ', platform_name = ' . $this->db->quote($params['platform_name']) . ', commented = ' . (int) $params['commented'] . ', status = ' . (int) $params['status'] . ', extras = ' . $this->db->quote($params['extras']) . ' WHERE id = ' . (int) $deal_id . ' '; } else { // Save deal with shipment and payment. $query = ' INSERT INTO shipment (id, number, date, transport_charge, extras) VALUES ( DEFAULT, 0, \'0000-00-00\', 0, \'\' )'; $result = $this->db->query($query); if ($result === FALSE) { $returnArray = array(); $returnArray['result'] = $result; $returnArray['error'] = $this->db->error(); return $returnArray; } $last_shipment_id = $this->db->getLastId(); $query = ' INSERT INTO payment (id, date, paid_amount, bank_name, extras) VALUES ( DEFAULT, \'0000-00-00\', 0, \'\', \'\' )'; $result = $this->db->query($query); if ($result === FALSE) { $returnArray = array(); $returnArray['result'] = $result; $returnArray['error'] = $this->db->error(); return $returnArray; } $last_payment_id = $this->db->getLastId(); $query = ' INSERT INTO deal (id, customer_id, article_id, payment_id, shipment_id, amount, total_price, platform_name, commented, status, extras) VALUES ( DEFAULT, ' . (int) $params['customer_id'] . ', ' . (int) $params['article_id'] . ', ' . (int) $last_payment_id . ', ' . (int) $last_shipment_id . ', ' . (int) $params['amount'] . ', ' . (double) $params['total_price'] . ', ' . $this->db->quote($params['platform_name']) . ', ' . (int) $params['commented'] . ', ' . (int) $params['status'] . ', ' . $this->db->quote($params['extras']) . ' )'; } $result = $this->db->query($query); $returnArray = array(); $returnArray['result'] = $result; $returnArray['error'] = $this->db->error(); } return $returnArray; }
public function getResult() { $return = array('messages' => array('info' => '', 'success' => '', 'danger' => '')); $target_dir = "images/article/"; $image_name = strtolower(basename($this->params["input_image"]["name"])); util_UtilFunctions::p($image_name); $image_name = strtolower(end(explode('/', $this->params["input_image"]["name"]))); util_UtilFunctions::p($image_name); $target_file = $target_dir . $image_name; $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if (isset($_POST["submit"])) { $check = getimagesize($this->params["input_image"]["tmp_name"]); if ($check !== false) { $return['messages']['info'] = "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { $return['messages']['danger'] = "File is not an image. "; $uploadOk = 0; } } // Check if file already exists if (file_exists($target_file)) { $return['messages']['danger'] .= "Sorry, file already exists. "; $uploadOk = 0; } // Check file size if ($this->params["input_image"]["size"] > 5000000) { $return['messages']['danger'] .= "Sorry, your file is too large. "; $uploadOk = 0; } // Allow certain file formats if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") { $return['messages']['danger'] .= "Sorry, only JPG, JPEG, PNG & GIF files are allowed. "; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { $return['messages']['danger'] .= "Sorry, your file was not uploaded. "; // if everything is ok, try to upload file } else { if (move_uploaded_file($this->params["input_image"]["tmp_name"], $target_file)) { $return['messages']['success'] = "The file " . basename($this->params["input_image"]["name"]) . " has been uploaded. "; $uploadOk = 1; } else { $return['messages']['danger'] .= "Sorry, there was an error uploading your file."; } } // Add a reference to the DB. $query = 'UPDATE article SET image_path = \'article/' . $image_name . '\' WHERE id = ' . $this->params['article_id'] . ' '; $result = $this->db->query($query); if ($result === TRUE) { $return['messages']['success'] .= "The reference was successfully added to the article."; } else { $return['messages']['danger'] .= "Couldn't assign a reference to the image in the DB."; } return json_encode($return); }