public function make_an_offer() { if ($this->request->is('post')) { $this->layout = "ajax_layout"; $sms_data = $this->request->data; $ad_title = $sms_data['ad_title']; $offer_rs = $sms_data['offer_rs']; $receiver_mobile = $sms_data['receiver_mobile']; $sender_mobile = $sms_data['sender_mobile']; $sender_name = $this->activeUser['User']['fb_name']; $sender_email = $this->activeUser['User']['username']; // save on cloudant // get uuid $guid = String::uuid(); // get todays datetime in seconds $time_in_seconds = CakeTime::convert(time(), new DateTimeZone('Asia/Calcutta')); // set array for cloudant DB $msg_array['id'] = "msg_" . $time_in_seconds . '_' . $guid; $msg_array['created_timestamp'] = $time_in_seconds; $msg_array['doc_type'] = 'sms'; $msg_array['ad_id'] = $sms_data['ad_id']; $msg_array['ad_fb_id'] = $sms_data['ad_fb_id']; $msg_array['sender_fb_id'] = $this->activeUser['User']['fb_id']; $msg_array['name'] = $sender_name; $msg_array['mobile'] = $sender_mobile; $msg_array['email'] = $sender_email; // Set created timestamp date_default_timezone_set('Asia/Calcutta'); $todays = new DateTime(); $msg_array['created'] = $todays->format('Y-m-d H:i:s'); // pr($msg_array);die(); $this->SetAdReply->setDataSource('cloudant_db'); if (!$this->SetAdReply->save($msg_array)) { echo 0; } //send sms if ($receiver_mobile != null) { $sms = new Sms(); $sms->sendMakeAnOffer($ad_title, $sender_name, $sender_mobile, $sender_email, $offer_rs, $receiver_mobile); //$msg_array['message'] = $sender_data['senderMsg']; echo "1"; } else { echo "0"; } } }