mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 02:44:53 +00:00
API code style tidy
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<?php
|
||||
define('number_regex', '/[^0-9]/');
|
||||
|
||||
$name = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_name'])));
|
||||
$title = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_title'])));
|
||||
$department = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_department'])));
|
||||
$name = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['contact_name'])));
|
||||
$title = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['contact_title'])));
|
||||
$department = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['contact_department'])));
|
||||
$phone = preg_replace(number_regex, '', $_POST['contact_phone']);
|
||||
$extension = preg_replace(number_regex, '', $_POST['contact_extension']);
|
||||
$mobile = preg_replace(number_regex, '', $_POST['contact_mobile']);
|
||||
$email = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_email'])));
|
||||
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_notes'])));
|
||||
$auth_method = trim(strip_tags(mysqli_real_escape_string($mysqli,$_POST['contact_auth_method'])));
|
||||
$email = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['contact_email'])));
|
||||
$notes = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['contact_notes'])));
|
||||
$auth_method = trim(strip_tags(mysqli_real_escape_string($mysqli, $_POST['contact_auth_method'])));
|
||||
$location_id = intval($_POST['contact_location_id']);
|
||||
@@ -1,34 +1,34 @@
|
||||
<?php
|
||||
require('../validate_api_key.php');
|
||||
|
||||
require('../require_post_method.php');
|
||||
require_once('../validate_api_key.php');
|
||||
require_once('../require_post_method.php');
|
||||
|
||||
// Parse Info
|
||||
include('contact_model.php');
|
||||
require_once('contact_model.php');
|
||||
|
||||
// Default
|
||||
$insert_id = FALSE;
|
||||
|
||||
if(!empty($name) && !empty($email) && !empty($client_id)){
|
||||
if (!empty($name) && !empty($email) && !empty($client_id)) {
|
||||
|
||||
// Check contact with $email doesn't already exist
|
||||
$email_duplication_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_email = '$email' AND contact_client_id = '$client_id'");
|
||||
// Check contact with $email doesn't already exist
|
||||
$email_duplication_sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_email = '$email' AND contact_client_id = '$client_id'");
|
||||
|
||||
if(mysqli_num_rows($email_duplication_sql) == 0){
|
||||
if (mysqli_num_rows($email_duplication_sql) == 0) {
|
||||
|
||||
// Insert contact
|
||||
$insert_sql = mysqli_query($mysqli,"INSERT INTO contacts SET contact_name = '$name', contact_title = '$title', contact_phone = '$phone', contact_extension = '$extension', contact_mobile = '$mobile', contact_email = '$email', contact_notes = '$notes', contact_auth_method = '$auth_method', contact_created_at = NOW(), contact_department = '$department', contact_location_id = $location_id, contact_client_id = $client_id, company_id = $company_id");
|
||||
// Insert contact
|
||||
$insert_sql = mysqli_query($mysqli, "INSERT INTO contacts SET contact_name = '$name', contact_title = '$title', contact_phone = '$phone', contact_extension = '$extension', contact_mobile = '$mobile', contact_email = '$email', contact_notes = '$notes', contact_auth_method = '$auth_method', contact_created_at = NOW(), contact_department = '$department', contact_location_id = $location_id, contact_client_id = $client_id, company_id = $company_id");
|
||||
|
||||
// Check insert & get insert ID
|
||||
if ($insert_sql) {
|
||||
$insert_id = mysqli_insert_id($mysqli);
|
||||
//Logging
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Created contact $name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
}
|
||||
|
||||
// Check insert & get insert ID
|
||||
if($insert_sql){
|
||||
$insert_id = mysqli_insert_id($mysqli);
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Created', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Created contact $name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
include('../create_output.php');
|
||||
require_once('../create_output.php');
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
require('../validate_api_key.php');
|
||||
|
||||
require('../require_post_method.php');
|
||||
require_once('../validate_api_key.php');
|
||||
require_once('../require_post_method.php');
|
||||
|
||||
// Parse ID
|
||||
$contact_id = intval($_POST['contact_id']);
|
||||
@@ -9,20 +9,20 @@ $contact_id = intval($_POST['contact_id']);
|
||||
// Default
|
||||
$delete_count = FALSE;
|
||||
|
||||
if(!empty($contact_id)){
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_id = $contact_id AND contact_client_id = $client_id AND company_id = '$company_id' LIMIT 1"));
|
||||
$contact_name = $row['contact_name'];
|
||||
if (!empty($contact_id)) {
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_id = $contact_id AND contact_client_id = $client_id AND company_id = '$company_id' LIMIT 1"));
|
||||
$contact_name = $row['contact_name'];
|
||||
|
||||
$delete_sql = mysqli_query($mysqli, "DELETE FROM contacts WHERE contact_id = $contact_id AND contact_client_id = $client_id AND company_id = '$company_id' LIMIT 1");
|
||||
$delete_sql = mysqli_query($mysqli, "DELETE FROM contacts WHERE contact_id = $contact_id AND contact_client_id = $client_id AND company_id = '$company_id' LIMIT 1");
|
||||
|
||||
// Check delete & get affected rows
|
||||
if($delete_sql && !empty($contact_name)){
|
||||
$delete_count = mysqli_affected_rows($mysqli);
|
||||
// Check delete & get affected rows
|
||||
if ($delete_sql && !empty($contact_name)) {
|
||||
$delete_count = mysqli_affected_rows($mysqli);
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Deleted', log_description = '$contact_name via API ($api_key_name)', log_ip = '$ip', log_client_id = $client_id, company_id = $company_id");
|
||||
}
|
||||
//Logging
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Deleted', log_description = '$contact_name via API ($api_key_name)', log_ip = '$ip', log_client_id = $client_id, company_id = $company_id");
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
include('../delete_output.php');
|
||||
require_once('../delete_output.php');
|
||||
@@ -1,24 +1,24 @@
|
||||
<?php
|
||||
require('../validate_api_key.php');
|
||||
|
||||
require('../require_get_method.php');
|
||||
require_once('../validate_api_key.php');
|
||||
require_once('../require_get_method.php');
|
||||
|
||||
// Specific contact via ID (single)
|
||||
if(isset($_GET['contact_id'])){
|
||||
if (isset($_GET['contact_id'])) {
|
||||
$id = intval($_GET['contact_id']);
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_id = '$id' AND contact_client_id LIKE '$client_id' AND company_id = '$company_id'");
|
||||
}
|
||||
|
||||
// Specific contact via email (single)
|
||||
elseif(isset($_GET['contact_email'])){
|
||||
$email = trim(strip_tags(mysqli_real_escape_string($mysqli,$_GET['contact_email'])));
|
||||
elseif (isset($_GET['contact_email'])) {
|
||||
$email = trim(strip_tags(mysqli_real_escape_string($mysqli, $_GET['contact_email'])));
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_email = '$email' AND contact_client_id LIKE '$client_id' AND company_id = '$company_id'");
|
||||
}
|
||||
|
||||
// All contacts
|
||||
else{
|
||||
else {
|
||||
$sql = mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_client_id LIKE '$client_id' AND company_id = '$company_id' ORDER BY contact_id LIMIT $limit OFFSET $offset");
|
||||
}
|
||||
|
||||
// Output
|
||||
include("../read_output.php");
|
||||
require_once("../read_output.php");
|
||||
@@ -1,28 +1,28 @@
|
||||
<?php
|
||||
require('../validate_api_key.php');
|
||||
|
||||
require('../require_post_method.php');
|
||||
require_once('../validate_api_key.php');
|
||||
require_once('../require_post_method.php');
|
||||
|
||||
// Parse Info
|
||||
$contact_id = intval($_POST['contact_id']);
|
||||
include('contact_model.php');
|
||||
require_once('contact_model.php');
|
||||
|
||||
// Default
|
||||
$update_count = FALSE;
|
||||
|
||||
if(!empty($name) && !empty($email)){
|
||||
if (!empty($name) && !empty($email)) {
|
||||
|
||||
$update_sql = mysqli_query($mysqli,"UPDATE contacts SET contact_name = '$name', contact_title = '$title', contact_phone = '$phone', contact_extension = '$extension', contact_mobile = '$mobile', contact_email = '$email', contact_notes = '$notes', contact_auth_method = '$auth_method', contact_updated_at = NOW(), contact_department_id = $department, contact_location_id = $location_id, contact_client_id = $client_id, company_id = $company_id WHERE contact_id = $contact_id LIMIT 1");
|
||||
$update_sql = mysqli_query($mysqli, "UPDATE contacts SET contact_name = '$name', contact_title = '$title', contact_phone = '$phone', contact_extension = '$extension', contact_mobile = '$mobile', contact_email = '$email', contact_notes = '$notes', contact_auth_method = '$auth_method', contact_updated_at = NOW(), contact_department_id = $department, contact_location_id = $location_id, contact_client_id = $client_id, company_id = $company_id WHERE contact_id = $contact_id LIMIT 1");
|
||||
|
||||
// Check insert & get insert ID
|
||||
if($update_sql){
|
||||
$update_count = mysqli_affected_rows($mysqli);
|
||||
// Check insert & get insert ID
|
||||
if ($update_sql) {
|
||||
$update_count = mysqli_affected_rows($mysqli);
|
||||
|
||||
//Logging
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Contact', log_action = 'Updated', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Updated contact $name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
}
|
||||
//Logging
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Contact', log_action = 'Updated', log_description = '$name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'API', log_action = 'Success', log_description = 'Updated contact $name via API ($api_key_name)', log_ip = '$ip', log_created_at = NOW(), log_client_id = $client_id, company_id = $company_id");
|
||||
}
|
||||
}
|
||||
|
||||
// Output
|
||||
include('../update_output.php');
|
||||
require_once('../update_output.php');
|
||||
Reference in New Issue
Block a user