Fix AJAX message sending
This commit is contained in:
@@ -370,106 +370,115 @@ class Proj extends Users_Controller {
|
||||
}
|
||||
|
||||
public function thisjob() {
|
||||
|
||||
$data = $this->getSessionArray();
|
||||
$data['redirect_to'] = '/proj/active/';
|
||||
$uploaded = false;
|
||||
|
||||
if (!isset($_SESSION['username']) or $_SESSION['username'] == '') {
|
||||
redirect(home);
|
||||
return;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
$message = "";
|
||||
$res = -1;
|
||||
// echo rand(100,9999). " ameye 1";
|
||||
|
||||
if ($_POST) {
|
||||
$ajax = $this->input->post('ajax');
|
||||
$jobID = $this->input->post('jobID');
|
||||
} else {
|
||||
$message = "";
|
||||
// echo rand(100,9999). " ameye 1";
|
||||
$ajax = $this->input->get('ajax');
|
||||
$jobID = $this->input->get('jobID');
|
||||
$message = $this->input->get('message');
|
||||
}
|
||||
$data['jobID'] = $jobID;
|
||||
|
||||
if ($_POST) {
|
||||
$ajax = $this->input->post('ajax');
|
||||
$jobID = $this->input->post('jobID');
|
||||
} else {
|
||||
$ajax = $this->input->get('ajax');
|
||||
$jobID = $this->input->get('jobID');
|
||||
$message = $this->input->get('message');
|
||||
}
|
||||
$data['jobID'] = $jobID;
|
||||
//$mybalance = 10666;
|
||||
//$data['mybalance'] = $mybalance;
|
||||
|
||||
//$mybalance = 10666;
|
||||
//$data['mybalance'] = $mybalance;
|
||||
$this->load->model('backend_model');
|
||||
// echo rand(100,9999). " ameye 2";
|
||||
if ($_POST && !isset($_POST['uploadForm'])) {
|
||||
// echo rand(100,9999). " ameye 2222-2222";
|
||||
// exit;
|
||||
$msgArray = array();
|
||||
$msgArray['message'] = trim($this->input->post('jobmessage'));
|
||||
$msgArray['contract'] = $this->input->post('contractId');
|
||||
$msgArray['msg_type'] = 'TEXT';
|
||||
$msgArray['member_id'] = $_SESSION['member_id']; // = $ret->email;
|
||||
|
||||
$this->load->model('backend_model');
|
||||
// echo rand(100,9999). " ameye 2";
|
||||
if ($_POST && !isset($_POST['uploadForm'])) {
|
||||
// echo rand(100,9999). " ameye 2222-2222";
|
||||
// exit;
|
||||
$msgArray = array();
|
||||
$msgArray['message'] = trim($this->input->post('jobmessage'));
|
||||
$msgArray['contract'] = $this->input->post('contractId');
|
||||
if (trim($msgArray['message']) != '') { // NOTE THAT IT msg_type is IMPORTTANT
|
||||
$msgArray['msg_type'] = 'TEXT';
|
||||
$msgArray['member_id'] = $_SESSION['member_id']; // = $ret->email;
|
||||
$msgArray['action'] = WRENCHBOARD_CONTRACT_MESSAGE;
|
||||
|
||||
if ($msgArray['message'] != '') { // NOTE THAT IT msg_type is IMPORTTANT
|
||||
$msgArray['msg_type'] = 'TEXT';
|
||||
$msgArray['action'] = WRENCHBOARD_CONTRACT_MESSAGE;
|
||||
|
||||
$out = array();
|
||||
$res = $this->backend_model->wrenchboard_api($msgArray, $out);
|
||||
}
|
||||
} else if ($_POST && isset($_POST['uploadForm']) && isset($_FILES["fileToUpload"])) {
|
||||
list ($message, $uploaded) = $this->process_files($_FILES["fileToUpload"]);
|
||||
$out = array();
|
||||
$res = $this->backend_model->wrenchboard_api($msgArray, $out);
|
||||
} else {
|
||||
$res = "Message is empty!";
|
||||
}
|
||||
} else if ($_POST && isset($_POST['uploadForm']) && isset($_FILES["fileToUpload"])) {
|
||||
list ($message, $uploaded) = $this->process_files($_FILES["fileToUpload"]);
|
||||
}
|
||||
|
||||
$data = $this->load_files($data, $jobID);
|
||||
//$this->load_files($data, $jobID);
|
||||
$data = $this->load_files($data, $jobID);
|
||||
//$this->load_files($data, $jobID);
|
||||
|
||||
$data["sizeLimit"] = $this->backend_model->cfgReadChar("system.upload_size_limit");
|
||||
$data["sizeLimit"] = $this->backend_model->cfgReadChar("system.upload_size_limit");
|
||||
|
||||
$this->load->model('dash_model');
|
||||
$out = $this->dash_model->getDashData($data);
|
||||
$data['active_task'] = $out['active_task'];
|
||||
$data['active_pass_due'] = $out['active_pass_due'];
|
||||
$data['current_balance'] = $out['current_balance'];
|
||||
$data['new_message'] = $out['new_message'];
|
||||
$data['message'] = $message;
|
||||
$this->load->model('dash_model');
|
||||
$out = $this->dash_model->getDashData($data);
|
||||
$data['active_task'] = $out['active_task'];
|
||||
$data['active_pass_due'] = $out['active_pass_due'];
|
||||
$data['current_balance'] = $out['current_balance'];
|
||||
$data['new_message'] = $out['new_message'];
|
||||
$data['message'] = $message;
|
||||
|
||||
$data['this_is_client'] = false;
|
||||
$data['this_is_project_owner'] = false;
|
||||
|
||||
$data['disabled1'] = 'disabled';
|
||||
$data['disabled2'] = 'disabled';
|
||||
|
||||
$data['disabled11'] = 'disabled';
|
||||
$data['disabled22'] = 'disabled';
|
||||
/*
|
||||
$data['job_status'] = $jbD1->status;
|
||||
$data['job_member_id'] = $jbD1->member_id;
|
||||
$data['job_client_id'] = $jbD1->client_id;
|
||||
*/
|
||||
if ($data['job_member_id'] == $_SESSION['member_id']) {
|
||||
$data['this_is_client'] = false;
|
||||
$data['this_is_project_owner'] = false;
|
||||
|
||||
$data['disabled1'] = 'disabled';
|
||||
$data['disabled2'] = 'disabled';
|
||||
|
||||
$data['disabled11'] = 'disabled';
|
||||
$data['disabled22'] = 'disabled';
|
||||
/*
|
||||
$data['job_status'] = $jbD1->status;
|
||||
$data['job_member_id'] = $jbD1->member_id;
|
||||
$data['job_client_id'] = $jbD1->client_id;
|
||||
*/
|
||||
if ($data['job_member_id'] == $_SESSION['member_id']) {
|
||||
$data['this_is_client'] = false;
|
||||
$data['this_is_project_owner'] = true;
|
||||
if ($data["job_status"] == CONTRACT_NOTIFY_COMPLETE) {
|
||||
$data['disabled11'] = '';
|
||||
$data['disabled22'] = '';
|
||||
}
|
||||
} else {
|
||||
$data['this_is_client'] = true;
|
||||
$data['this_is_project_owner'] = false;
|
||||
if ($data["job_status"] == 1 and $data['force_wait'] == false) {
|
||||
|
||||
$data['disabled1'] = '';
|
||||
$data['disabled2'] = '';
|
||||
}
|
||||
$data['this_is_project_owner'] = true;
|
||||
if ($data["job_status"] == CONTRACT_NOTIFY_COMPLETE) {
|
||||
$data['disabled11'] = '';
|
||||
$data['disabled22'] = '';
|
||||
}
|
||||
} else {
|
||||
$data['this_is_client'] = true;
|
||||
$data['this_is_project_owner'] = false;
|
||||
if ($data["job_status"] == 1 and $data['force_wait'] == false) {
|
||||
|
||||
if ($ajax == 1) {
|
||||
echo isset($res)? $res:'';
|
||||
$this->RenderUserPage('jobs/view_thisjob', $data);
|
||||
$data['disabled1'] = '';
|
||||
$data['disabled2'] = '';
|
||||
}
|
||||
}
|
||||
|
||||
if ($ajax == 1) {
|
||||
ob_end_clean();
|
||||
echo isset($res)? $res:'';
|
||||
// $this->RenderUserPage('jobs/view_thisjob', $data);
|
||||
} else {
|
||||
/* $this->load->view('users/view_header_user', $data);
|
||||
$this->load->view('jobs/view_thisjob', $data);
|
||||
$this->load->view('users/view_footer_user', $data); */
|
||||
ob_end_flush();
|
||||
if ($uploaded) {
|
||||
redirect('/proj/thisjob?jobID='.$jobID.'&message='.$message);
|
||||
} else {
|
||||
/* $this->load->view('users/view_header_user', $data);
|
||||
$this->load->view('jobs/view_thisjob', $data);
|
||||
$this->load->view('users/view_footer_user', $data); */
|
||||
if ($uploaded) {
|
||||
redirect('/proj/thisjob?jobID='.$jobID.'&message='.$message);
|
||||
} else {
|
||||
$this->RenderUserPage('jobs/view_thisjob', $data);
|
||||
}
|
||||
$this->RenderUserPage('jobs/view_thisjob', $data);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -656,12 +665,8 @@ class Proj extends Users_Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private function load_files($data, $jobID) {
|
||||
|
||||
$data['username'] = $_SESSION['username']; // = $this->input->post('username');
|
||||
$data['name'] = $_SESSION['name']; // = $this->input->post('username');
|
||||
$data['firstname'] = $_SESSION['firstname']; // = $ret->firstname;
|
||||
@@ -683,9 +688,13 @@ class Proj extends Users_Controller {
|
||||
$mysql = "SELECT '<b>Project ID :</b>'||mc.contract||' - <b>Name: </b><a href=\"#\" onclick=\"showModal('||m.id||');\" >'||m.firstname||'</a><br><b>Title:</b>'||mc.title||'<br>'||'<b>Description: </b>'||mc.description||'<br><b>Timeline: </b> '||mc.timeline_days||' day(s) <b>Price: </b>'||mc.price*0.01||'Naira'||' <b>Expected Delivery: </b>'||mc.delivery_date||' '||$detail_button AS this_job,"
|
||||
. " mc.contract AS contract_id, mc.job_detail AS job_detail "
|
||||
. "FROM members_jobs_contract mc LEFT JOIN members m ON m.id=mc.client_id "
|
||||
. " WHERE (mc.member_id = " . $_SESSION['member_id'] . " OR mc.client_id=" . $_SESSION['member_id'] . ") AND mc.id=" . $jobID;
|
||||
. " WHERE (mc.member_id = '" . $_SESSION['member_id'] . "' OR mc.client_id='" . $_SESSION['member_id'] . "') AND mc.id=" . ((int)$jobID);
|
||||
$query = $this->db->query($mysql);
|
||||
$jbD = $query->row();
|
||||
$result = $query->result_array();
|
||||
$jbD = array("this_job" => "", "contract_id" => "", "job_detail" => "");
|
||||
if (is_array($result) && count($result)>0) {
|
||||
$jbD = $result[0];
|
||||
}
|
||||
|
||||
//----------------------
|
||||
$mysql = "SELECT m.id,mc.contract, m.firstname,mc.title,mc.description,
|
||||
@@ -694,16 +703,20 @@ class Proj extends Users_Controller {
|
||||
$detail_button As delivery_details
|
||||
FROM members_jobs_contract mc
|
||||
LEFT JOIN members m ON m.id=mc.client_id
|
||||
WHERE (mc.member_id = " . $_SESSION['member_id'] . " OR mc.client_id=" . $_SESSION['member_id'] . ")
|
||||
AND mc.id=" . $jobID;
|
||||
WHERE (mc.member_id = '" . $_SESSION['member_id'] . "' OR mc.client_id='" . $_SESSION['member_id'] . "')
|
||||
AND mc.id=" . ((int)$jobID);
|
||||
$query = $this->db->query($mysql);
|
||||
$data["this_job_result"] = $query->result()[0];
|
||||
$result = $query->result();
|
||||
$r = new stdClass();
|
||||
$r->id = ""; $r->contract = ""; $r->firstname = ""; $r->title = ""; $r->description = ""; $r->timeline_days = "";
|
||||
$r->price = ""; $r->delivery_date = ""; $r->contract_id = ""; $r->job_detail = ""; $r->delivery_details = "";
|
||||
$data["this_job_result"] = is_array($result) ? $result[0] : $r;
|
||||
//----------------------
|
||||
// $this->table->set_heading('Job', 'Client', 'Terms', 'Price', 'Manage', 'Status');
|
||||
$data['job_table'] = $this->table->generate($query);
|
||||
$data['this_job'] = $jbD->this_job;
|
||||
$data['contract_id'] = $jbD->contract_id;
|
||||
$data['job_detail'] = $jbD->job_detail;
|
||||
$data['this_job'] = $jbD["this_job"];
|
||||
$data['contract_id'] = $jbD["contract_id"];
|
||||
$data['job_detail'] = $jbD["job_detail"];
|
||||
/*
|
||||
$sqlMsg = "SELECT (CASE WHEN jc.msg_type='FILE' THEN '<a target=\"_blank\" href=\"/smedia/" . ($is_live ? "LIVE" : "TEST") . "/contract/" . $data['contract_id'] . "/'||jc.message||'\">'||jc.message||'</a>' ELSE '<b>['||m.firstname||']->'||jc.created||'</b><br>'||jc.message END) AS msg "
|
||||
. "FROM jobs_contract_message jc "
|
||||
@@ -751,15 +764,19 @@ class Proj extends Users_Controller {
|
||||
// $data['message_result_show'] = $this->messageAccordion($data['message_result']);
|
||||
|
||||
|
||||
$mysql3 = "SELECT *,(delivery_date::date- now()::date)::int AS remaining_days FROM members_jobs_contract WHERE id= " . $jobID;
|
||||
$mysql3 = "SELECT *,(delivery_date::date- now()::date)::int AS remaining_days FROM members_jobs_contract WHERE id= " . ((int)$jobID);
|
||||
$query3 = $this->db->query($mysql3);
|
||||
$jbD1 = $query3->row();
|
||||
$data['job_status'] = $jbD1->status;
|
||||
$data['job_member_id'] = $jbD1->member_id;
|
||||
$data['job_client_id'] = $jbD1->client_id;
|
||||
$data['job_contract'] = $jbD1->contract;
|
||||
$data['timeline_days'] = $jbD1->timeline_days;
|
||||
$data['remaining_days'] = $jbD1->remaining_days;
|
||||
$result3 = $query3->result_array();
|
||||
$jbD1 = array("status"=>"","member_id"=>"","client_id"=>"","contract"=>"","timeline_days"=>"","remaining_days"=>"");
|
||||
if (is_array($result3) && count($result3)) {
|
||||
$jbD1 = $result3[0];
|
||||
}
|
||||
$data['job_status'] = $jbD1["status"];
|
||||
$data['job_member_id'] = $jbD1["member_id"];
|
||||
$data['job_client_id'] = $jbD1["client_id"];
|
||||
$data['job_contract'] = $jbD1["contract"];
|
||||
$data['timeline_days'] = $jbD1["timeline_days"];
|
||||
$data['remaining_days'] = $jbD1["remaining_days"];
|
||||
$data['force_wait'] = false;
|
||||
if ($data['remaining_days'] > 0) {
|
||||
if ($data['timeline_days'] / 2 < $data['remaining_days']) {
|
||||
|
||||
@@ -322,6 +322,7 @@
|
||||
$('#jobmessage').data("wysihtml5").editor.clear();
|
||||
$('#sendmessagenote').html('<div class=\"text-left\"><div class=\"alert alert-info no-border\">Message was sent!</div></div>');
|
||||
} else {
|
||||
alert(data);
|
||||
alert('<div class=\"text-left\"><div class=\"alert alert-danger no-border\">Failed to send message</div></div>');
|
||||
}
|
||||
document.message.btn_cancel.disabled = false;
|
||||
|
||||
Reference in New Issue
Block a user