663 lines
23 KiB
PHP
663 lines
23 KiB
PHP
<?php
|
|
class Ticketing_v3 extends MY_Controller
|
|
{
|
|
var $db;
|
|
var $load;
|
|
function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->load->helper(array('form', 'url'));
|
|
}
|
|
|
|
function submit_ticket()
|
|
{
|
|
|
|
$prm = $this->sys_input;
|
|
|
|
|
|
if (trim($prm['title']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Title is required'));
|
|
exit;
|
|
}
|
|
|
|
if (trim($prm['sender']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Sender is required'));
|
|
exit;
|
|
}
|
|
|
|
if (trim($prm['branch_code']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Branch code is required'));
|
|
exit;
|
|
}
|
|
|
|
if (!isset($prm['is_direct'])) {
|
|
$prm['is_direct'] = "N";
|
|
} else {
|
|
$prm['is_direct'] = $prm['is_direct'] == 'False' ? "N" : "Y";
|
|
}
|
|
|
|
if (trim($prm['description']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Description is required'));
|
|
exit;
|
|
}
|
|
|
|
if (trim($prm['client_id']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Client ID is required'));
|
|
exit;
|
|
}
|
|
|
|
$ticket_number = $this->generate_string();
|
|
|
|
$sql = "INSERT INTO ticketing (
|
|
TicketTitle,
|
|
TicketingNumber,
|
|
TicketingSender,
|
|
TicketingM_BranchCode,
|
|
TicketingIsDirect,
|
|
TicketingDescription,
|
|
TicketingCreated,
|
|
TicketingCreatedUserID,
|
|
TicketingClientID
|
|
)VALUES(
|
|
'{$prm['title']}',
|
|
'{$ticket_number}',
|
|
'{$prm['sender']}',
|
|
'{$prm['branch_code']}',
|
|
'{$prm['is_direct']}',
|
|
'{$prm['description']}',
|
|
NOW(),
|
|
1,
|
|
'{$prm['client_id']}',
|
|
)";
|
|
|
|
$query = $this->db->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert new ticket", $this->db);
|
|
exit;
|
|
}
|
|
$xlast_id = $this->db->insert_id();
|
|
|
|
$path = '/home/one/project/one/one-media/one-support/';
|
|
$config['upload_path'] = $path;
|
|
$config['allowed_types'] = 'jpg|jpeg|png|gif';
|
|
$config['max_size'] = '10000';
|
|
$count = count($_FILES['files']['name']);
|
|
$this->load->library('upload', $config);
|
|
$images_odoo = [];
|
|
$images_odoo_url = [];
|
|
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
if (!empty($_FILES['files']['name'][$i])) {
|
|
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
|
|
|
|
$_FILES['file']['type'] = 'image/jpeg';
|
|
|
|
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
|
|
|
|
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
|
|
|
|
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
|
|
|
$namex = $_FILES['files']['name'][$i];
|
|
|
|
$config['file_name'] = $namex;
|
|
$this->upload->initialize($config);
|
|
|
|
|
|
if ($this->upload->do_upload('file')) {
|
|
$uploadData = $this->upload->data();
|
|
$filename = $uploadData['file_name'];
|
|
$sql = "INSERT INTO ticketing_images(
|
|
TicketingImagesTicketingID,
|
|
TicketingImagesName,
|
|
TicketingImagesCreated,
|
|
TicketingImagesCreatedUserID
|
|
) VALUES(
|
|
{$xlast_id},
|
|
'{$filename}',
|
|
NOW(),
|
|
1
|
|
)";
|
|
|
|
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
|
|
$img_attach_url = "https://devone.aplikasi.web.id/one-media/one-support/" . urlencode($filename);
|
|
array_push($images_odoo_url, $img_attach_url);
|
|
} else {
|
|
$error = array('error' => $this->upload->display_errors());
|
|
echo json_encode(array("error" => $error));
|
|
exit();
|
|
}
|
|
}
|
|
}
|
|
|
|
$insert_odoo = $this->create_task_odoo($prm['title'], $prm['sender'], $ticket_number, $prm['description'], $prm['is_direct'], $prm['branch_code'], $images_odoo_url, $prm['client_id']);
|
|
if ($insert_odoo) {
|
|
//echo json_encode(array('status' => 'OK', 'msg' => 'Success', 'data' => array("id" => $xlast_id, 'number' => $ticket_number)));
|
|
echo json_encode(array("status" => "success", "ticket_number" => $ticket_number, "count" => $count));
|
|
$this->wa_to_sasone($prm['title'], $prm['description'], $ticket_number, $insert_odoo, $prm['client_id']);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
function get_branchs()
|
|
{
|
|
$sql = "select M_BranchID, M_BranchCode, M_BranchName
|
|
from m_branch
|
|
WHERE
|
|
M_BranchIsActive = 'Y'";
|
|
$query = $this->db->query($sql);
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
echo json_encode($rows);
|
|
} else {
|
|
$this->sys_error_db("m_company rows", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
|
|
public function search_branch()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
$max_rst = 12;
|
|
$tot_count = 0;
|
|
|
|
$q = [
|
|
'search' => '%'
|
|
];
|
|
|
|
if ($prm['search'] != '') {
|
|
$q['search'] = "%{$prm['search']}%";
|
|
}
|
|
|
|
// Tambahkan parameter id ke dalam array $q
|
|
if (isset($prm['client_id']) && $prm['client_id'] != '') {
|
|
$q['client_id'] = $prm['client_id'];
|
|
} else {
|
|
// Berikan nilai default atau keluarkan error jika 'id' tidak ada
|
|
$this->sys_error("Parameter 'client_id' tidak ditemukan");
|
|
exit;
|
|
}
|
|
|
|
// QUERY TOTAL
|
|
$sql = "SELECT COUNT(*) total
|
|
FROM m_branch
|
|
WHERE M_BranchName LIKE ?
|
|
AND M_BranchClientID = ?";
|
|
$query = $this->db->query($sql, array($q['search'], $q['client_id']));
|
|
|
|
if ($query) {
|
|
$tot_count = $query->result_array()[0]["total"];
|
|
} else {
|
|
$this->sys_error_db("m_branch count", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$sql = "SELECT M_BranchID, M_BranchCode, M_BranchName
|
|
FROM m_branch
|
|
WHERE M_BranchName LIKE ?
|
|
AND M_BranchClientID = ?
|
|
LIMIT ?";
|
|
$query = $this->db->query($sql, array($q['search'], $q['client_id'], $max_rst));
|
|
|
|
if ($query) {
|
|
$rows = $query->result_array();
|
|
|
|
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
|
|
$this->sys_ok($result);
|
|
} else {
|
|
$this->sys_error_db("m_branch rows", $this->db);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
function search_client()
|
|
{
|
|
|
|
try {
|
|
$prm = $this->sys_input;
|
|
|
|
$qry = "%" . $prm["search"] . '%';
|
|
|
|
$sql = "SELECT clientId,clientName
|
|
FROM client
|
|
WHERE clientName LIKE ?
|
|
AND clientIsActive = 'Y'
|
|
ORDER BY clientId DESC";
|
|
$query = $this->db->query($sql, array($qry));
|
|
if (!$query) {
|
|
$this->sys_error_db("select client error", $this->db);
|
|
exit;
|
|
} else {
|
|
$rows = $query->result_array();
|
|
$rows[] = array("clientID" => 0, "clientName" => "Semua");
|
|
}
|
|
|
|
$result = array(
|
|
"data" => $rows
|
|
);
|
|
$this->sys_ok($result);
|
|
} catch (Exception $exc) {
|
|
$message = $exc->getMessage();
|
|
$this->sys_error($message);
|
|
}
|
|
}
|
|
|
|
function generate_string()
|
|
{
|
|
$strength = 6;
|
|
$input = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$input_length = strlen($input);
|
|
$random_string = '';
|
|
for ($i = 0; $i < $strength; $i++) {
|
|
$random_character = $input[mt_rand(0, $input_length - 1)];
|
|
$random_string .= $random_character;
|
|
}
|
|
|
|
$sql = "SELECT COUNT(*) as xcount FROM ticketing WHERE TicketingNumber = '{$random_string}'";
|
|
$query = $this->db->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("error select patient", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$exist_number = $query->row()->xcount;
|
|
if ($exist_number > 0) {
|
|
return $this->generate_string();
|
|
} else {
|
|
return strtoupper($random_string);
|
|
}
|
|
}
|
|
|
|
function new_ticket()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
if (trim($prm['title']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Title is required'));
|
|
exit;
|
|
}
|
|
|
|
if (trim($prm['sender']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Sender is required'));
|
|
exit;
|
|
}
|
|
|
|
if (trim($prm['branch_code']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Branch code is required'));
|
|
exit;
|
|
}
|
|
|
|
if (!isset($prm['is_direct'])) {
|
|
$prm['is_direct'] = "N";
|
|
}
|
|
|
|
if (trim($prm['description']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Description is required'));
|
|
exit;
|
|
}
|
|
|
|
if (trim($prm['client_id']) == "") {
|
|
echo json_encode(array('status' => false, 'msg' => 'Client ID is required'));
|
|
exit;
|
|
}
|
|
|
|
$ticket_number = $this->generate_string();
|
|
|
|
$sql = "INSERT INTO ticketing (
|
|
TicketTitle,
|
|
TicketingNumber,
|
|
TicketingSender,
|
|
TicketingM_BranchCode,
|
|
TicketingIsDirect,
|
|
TicketingDescription,
|
|
TicketingCreated,
|
|
TicketingCreatedUserID,
|
|
TicketingClientID
|
|
)VALUES(
|
|
'{$prm['title']}',
|
|
'{$ticket_number}',
|
|
'{$prm['sender']}',
|
|
'{$prm['branch_code']}',
|
|
'{$prm['is_direct']}',
|
|
'{$prm['description']}',
|
|
NOW(),
|
|
1,
|
|
'{$prm['client_id']}'
|
|
)";
|
|
|
|
$query = $this->db->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("error insert new ticket", $this->db);
|
|
exit;
|
|
}
|
|
$xlast_id = $this->db->insert_id();
|
|
$path = '/home/one/project/one/one-media/one-support/';
|
|
$config['upload_path'] = $path;
|
|
$config['allowed_types'] = 'jpg|jpeg|png|gif';
|
|
$config['max_size'] = '10000';
|
|
$count = count($_FILES['files']['name']);
|
|
$this->load->library('upload', $config);
|
|
$images_odoo = [];
|
|
$images_odoo_url = [];
|
|
|
|
$error = [];
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
if (!empty($_FILES['files']['name'][$i])) {
|
|
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
|
|
|
|
$_FILES['file']['type'] = $_FILES['files']['type'][$i];
|
|
|
|
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
|
|
|
|
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
|
|
|
|
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
|
|
|
$namex = $_FILES['files']['name'][$i];
|
|
|
|
$config['file_name'] = $namex;
|
|
$this->upload->initialize($config);
|
|
|
|
|
|
if ($this->upload->do_upload('file')) {
|
|
$uploadData = $this->upload->data();
|
|
|
|
$filename = $uploadData['file_name'];
|
|
$target_path = $path . $filename;
|
|
$type = pathinfo($target_path, PATHINFO_EXTENSION);
|
|
$data = file_get_contents($target_path);
|
|
$base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
|
|
array_push($images_odoo, $base64);
|
|
$sql = "INSERT INTO ticketing_images(
|
|
TicketingImagesTicketingID,
|
|
TicketingImagesName,
|
|
TicketingImagesCreated,
|
|
TicketingImagesCreatedUserID
|
|
) VALUES(
|
|
{$xlast_id},
|
|
'{$filename}',
|
|
NOW(),
|
|
1
|
|
)";
|
|
$img_attach_url = "https://devone.aplikasi.web.id/one-media/one-support/" . urlencode($filename);
|
|
array_push($images_odoo_url, $img_attach_url);
|
|
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
// $xlast_id = $this->db->insert_id();
|
|
//$data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-support/' . $filename);
|
|
} else {
|
|
$error = array('error' => $this->upload->display_errors());
|
|
}
|
|
}
|
|
}
|
|
|
|
$sender_name = "Pengirim : {$prm['sender']} \n";
|
|
$xticket_number = "No. Tiket : {$ticket_number}\n";
|
|
$branch = "Cabang : " . $prm['branch_code'] . " - " . $prm['branch_name'] . "\n";
|
|
|
|
$is_direct = $prm['is_direct'] == "Y" ? "Direct Message : Ya\n" : "Direct Message : Tidak\n";
|
|
$x_description = $sender_name . " " . $xticket_number . " " . $branch . " " . $is_direct . " {$prm['description']}";
|
|
|
|
$insert_odoo = $this->create_task_odoo($prm['title'], $prm['sender'], $ticket_number, $prm['description'], $prm['is_direct'], $prm['branch_code'], $images_odoo_url, $prm['client_id']);
|
|
if ($insert_odoo) {
|
|
echo json_encode(array('status' => 'OK', 'msg' => 'Success', 'data' => array("id" => $xlast_id, 'number' => $ticket_number)));
|
|
$this->wa_to_sasone(
|
|
$prm['title'],
|
|
$x_description,
|
|
$ticket_number,
|
|
$insert_odoo,
|
|
$prm['client_id']
|
|
);
|
|
exit;
|
|
} else {
|
|
echo json_encode(array('status' => 'ERR', 'msg' => 'odoo down', 'data' => array("id" => $xlast_id, 'number' => $ticket_number)));
|
|
$this->wa_to_sasone(
|
|
$prm['title'],
|
|
$x_description,
|
|
$ticket_number,
|
|
$insert_odoo,
|
|
$prm['client_id']
|
|
);
|
|
exit;
|
|
}
|
|
/*if ($xlast_id == 0) {
|
|
$this->sys_error("Failed to insert new ticket, insert_id 0");
|
|
exit;
|
|
} else {
|
|
|
|
$this->create_task_odoo($prm['title'], $prm['sender'], $ticket_number, $prm['description'], $prm['is_direct'], $prm['branch_code']);
|
|
|
|
echo json_encode(array('status' => 'OK', 'msg' => 'Success', 'data' => array("id" => $xlast_id, 'number' => $ticket_number)));
|
|
exit;
|
|
}*/
|
|
}
|
|
function wa_to_sasone($title, $description, $tiket_number, $insert_odoo, $client_id)
|
|
{
|
|
$url_odoo = "http://odoo.sismedika.com/web#id=$insert_odoo&menu_id=225&action=342&active_id=70&model=project.task&view_type=form";
|
|
$msg = "Halo! Kami telah menerima permintaan Anda dan telah membuat tiket nomor $tiket_number. Tim kami akan segera meninjau dan memberikan tanggapan sesegera mungkin";
|
|
$msg .= "\nOdoo Task $title [# $tiket_number]\n```\n $description \n```\n";
|
|
//$hp="6281328282909-1583223560@g.us";
|
|
$hp = "6281328282909-1583223560@g.us";
|
|
if ($client_id != 1) {
|
|
$hp = "6282113702602-1584412485@g.us";
|
|
}
|
|
$this->load->library("Wa_sas");
|
|
$resp = $this->wa_sas->send_message($hp, $msg, true);
|
|
// $resp = $this->wa_sas->send_message($hp, $msg, false);
|
|
}
|
|
|
|
|
|
function base64_to_jpeg($base64_string, $output_file)
|
|
{
|
|
// open the output file for writing
|
|
$ifp = fopen($output_file, 'wb');
|
|
|
|
// split the string on commas
|
|
// $data[ 0 ] == "data:image/png;base64"
|
|
// $data[ 1 ] == <actual base64 string>
|
|
$data = explode(',', $base64_string);
|
|
|
|
// we could add validation here with ensuring count( $data ) > 1
|
|
fwrite($ifp, base64_decode($data[1]));
|
|
|
|
// clean up the file resource
|
|
fclose($ifp);
|
|
|
|
return $output_file;
|
|
}
|
|
|
|
function create_task_odoo($title, $sender, $number, $description, $is_direct, $branch_code, $images_odoo, $client_id)
|
|
{
|
|
//print_r($images_odoo);
|
|
$sql = "SELECT * FROM m_branch WHERE M_BranchCode = '{$branch_code}'";
|
|
$query = $this->db->query($sql);
|
|
if (!$query) {
|
|
$this->sys_error_db("error select branch", $this->db);
|
|
exit;
|
|
}
|
|
|
|
$data_branch = $query->row_array();
|
|
|
|
$sender_name = "Pengirim : <b>{$sender}</b><br/>";
|
|
$ticket_number = "No. Tiket : <b>{$number}</b><br/>";
|
|
$branch = "Cabang : <b>{$data_branch['M_BranchName']}</b><br/>";
|
|
$is_direct = $is_direct == "Y" ? "Direct Message : Ya<br/>" : "Direct Message : Tidak<br/>";
|
|
$x_description = $sender_name . " " . $ticket_number . " " . $branch . " " . $is_direct . " <p>{$description}</p>";
|
|
|
|
$project_id = 70;
|
|
if ($client_id == 2) {
|
|
$project_id = 123;
|
|
}
|
|
if ($client_id == 4 || $client_id == 5 || $client_id == 6) {
|
|
$project_id = 30;
|
|
}
|
|
|
|
|
|
|
|
$json_data = array(
|
|
'title' => $title, 'description' => $x_description,
|
|
'images' => $images_odoo, 'client_id' => $client_id, 'project_id' => $project_id
|
|
);
|
|
$json_payload = json_encode($json_data);
|
|
|
|
// Insert ke tabel tmp_odoo
|
|
$insert_sql = "INSERT INTO tmp_odoo (TmpOdooDate, TmpOdooJsonPayload, TmpOdooTaskUrl, TmpOdooIsSent) VALUES (NOW(), ?, ?, 'N')";
|
|
$this->db->query($insert_sql, array($json_payload, 'devone.aplikasi.web.id/one-api/odoo/create_task'));
|
|
|
|
// Mengambil ID dari row yang baru saja diinsert
|
|
$tmp_odoo_id = $this->db->insert_id();
|
|
|
|
$curl = curl_init();
|
|
curl_setopt_array($curl, array(
|
|
CURLOPT_URL => 'devone.aplikasi.web.id/one-api/odoo/create_task',
|
|
CURLOPT_RETURNTRANSFER => true,
|
|
CURLOPT_ENCODING => '',
|
|
CURLOPT_MAXREDIRS => 10,
|
|
CURLOPT_TIMEOUT => 0,
|
|
CURLOPT_FOLLOWLOCATION => true,
|
|
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
|
|
CURLOPT_CUSTOMREQUEST => 'POST',
|
|
CURLOPT_POSTFIELDS => $json_payload,
|
|
CURLOPT_HTTPHEADER => array(
|
|
'Content-Type: application/json'
|
|
),
|
|
));
|
|
|
|
$response = curl_exec($curl);
|
|
|
|
// Decode JSON response
|
|
$response_data = json_decode($response, true);
|
|
|
|
// kalau statu OK update Y kalau tidak E
|
|
if (isset($response_data['status']) && $response_data['status'] === 'OK') {
|
|
$update_sql = "UPDATE tmp_odoo SET TmpOdooIsSent = 'Y' WHERE TmpOdooID = ?";
|
|
} else {
|
|
$update_sql = "UPDATE tmp_odoo SET TmpOdooIsSent = 'E' WHERE TmpOdooID = ?";
|
|
}
|
|
$this->db->query($update_sql, array($tmp_odoo_id));
|
|
|
|
curl_close($curl);
|
|
|
|
return $response;
|
|
}
|
|
|
|
|
|
|
|
function uploadimage()
|
|
{
|
|
$prm = $this->sys_input;
|
|
|
|
// print_r($_SERVER);
|
|
|
|
$data = [];
|
|
$ticketid = $this->input->post('ticketid');
|
|
|
|
$path = '/home/one/project/one/one-media/one-support/';
|
|
$config['upload_path'] = $path;
|
|
$config['allowed_types'] = 'jpg|jpeg|png|gif';
|
|
$config['max_size'] = '10000';
|
|
$count = count($_FILES['files']['name']);
|
|
$this->load->library('upload', $config);
|
|
|
|
$error = [];
|
|
for ($i = 0; $i < $count; $i++) {
|
|
|
|
if (!empty($_FILES['files']['name'][$i])) {
|
|
$_FILES['file']['name'] = $_FILES['files']['name'][$i];
|
|
|
|
$_FILES['file']['type'] = $_FILES['files']['type'][$i];
|
|
|
|
$_FILES['file']['tmp_name'] = $_FILES['files']['tmp_name'][$i];
|
|
|
|
$_FILES['file']['error'] = $_FILES['files']['error'][$i];
|
|
|
|
$_FILES['file']['size'] = $_FILES['files']['size'][$i];
|
|
|
|
$namex = $_FILES['files']['name'][$i];
|
|
|
|
$config['file_name'] = $namex;
|
|
$this->upload->initialize($config);
|
|
|
|
|
|
if ($this->upload->do_upload('file')) {
|
|
$uploadData = $this->upload->data();
|
|
|
|
$filename = $uploadData['file_name'];
|
|
|
|
$sql = "INSERT INTO ticketing_images(
|
|
TicketingImagesTicketingID,
|
|
TicketingImagesName,
|
|
TicketingImagesCreated,
|
|
TicketingImagesCreatedUserID
|
|
) VALUES(
|
|
{$ticketid},
|
|
'{$filename}',
|
|
NOW(),
|
|
1
|
|
)";
|
|
$qry = $this->db->query($sql);
|
|
$last_qry = $this->db->last_query();
|
|
if (!$qry) {
|
|
$this->db->trans_rollback();
|
|
$error = array(
|
|
"message" => $this->db->error()["message"],
|
|
"sql" => $last_qry
|
|
);
|
|
$this->sys_error_db($error, $this->db);
|
|
exit;
|
|
}
|
|
$xlast_id = $this->db->insert_id();
|
|
$data['totalFiles'][] = array('xid' => $xlast_id, 'image_url' => '/one-media/one-support/' . $filename);
|
|
} else {
|
|
$error = array('error' => $this->upload->display_errors());
|
|
}
|
|
}
|
|
}
|
|
|
|
$result = array("total" => count($data['totalFiles']), "records" => $data['totalFiles'], 'errors' => $error);
|
|
$this->sys_ok($result);
|
|
}
|
|
|
|
function generateRandomString($length = 10)
|
|
{
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
}
|
|
}
|