public function edit_post()
 {
     if ($this->request->is('post')) {
         // get uuid
         $guid = String::uuid();
         // get todays datetime in seconds
         $time_in_seconds = CakeTime::convert(time(), new DateTimeZone('Asia/Calcutta'));
         // set final id for array
         $id = "ad_" . $time_in_seconds . '_' . $guid;
         $final_aray['timestamp']['created'] = $time_in_seconds;
         $final_aray['timestamp']['modified'] = $time_in_seconds;
         $item_data = $this->data;
         // pr($item_data);
         // final Array for cloudant
         $final_aray = array();
         $final_aray['id'] = $id;
         $final_aray['doc_type'] = 'ad';
         $final_aray['i_want_to'] = $item_data['i_want_to'];
         $final_aray['job_type'] = $item_data['job_type'];
         $final_aray['condition'] = $item_data['condition'];
         $final_aray['you_are/i_am'] = $item_data['youare'];
         $final_aray['item_type']['id'] = $item_data['ItemType']['id'];
         $final_aray['item_type']['name'] = $item_data['ItemType']['name'];
         // for resume
         if (!$item_data['ItemType']['resume_file']['size'] <= 0) {
             $filename = array();
             $filename['resume_file']['name'] = $item_data['ItemType']['resume_file']['name'];
             $filename['resume_file']['type'] = $item_data['ItemType']['resume_file']['type'];
             $filename['resume_file']['tmp_name'] = $item_data['ItemType']['resume_file']['tmp_name'];
             $filename['resume_file']['size'] = $item_data['ItemType']['resume_file']['size'];
             $filename['resume_file']['error'] = $item_data['ItemType']['resume_file']['error'];
             $filename['guid'] = $id;
             if (!$this->ItemPhoto->save($filename)) {
                 $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
                 $this->redirect(array('controller' => 'ad_posts', 'action' => 'index'));
             } else {
                 $last_uploaded_resume = $this->ItemPhoto->findByGuid($id);
                 $final_aray['resume'] = $last_uploaded_resume['ItemPhoto']['id'] . "/" . $last_uploaded_resume['ItemPhoto']['resume_file'];
             }
         }
         // end of resume
         // check photo uploaded or not
         if (!$item_data['ItemType']['image_files'][0]['size'] <= 0) {
             // save images in sql database
             $item_photo_details = array();
             // loop each uploaded images
             foreach ($item_data['ItemType']['image_files'] as $key => $value) {
                 $filename = array();
                 $filename['image_file']['name'] = $value['name'];
                 $filename['image_file']['type'] = $value['type'];
                 $filename['image_file']['tmp_name'] = $value['tmp_name'];
                 $filename['image_file']['size'] = $value['size'];
                 $filename['image_file']['error'] = $value['error'];
                 $filename['guid'] = $id;
                 array_push($item_photo_details, $filename);
             }
             if ($this->ItemPhoto->saveMany($item_photo_details)) {
                 // get current uploaded photos
                 $last_uploaded_images = $this->ItemPhoto->find('all', array('conditions' => array('guid' => $id), 'order' => 'created'));
                 $count = 0;
                 //pr(json_encode($last_uploaded_images));die();
                 $primary_photo = array();
                 // for save primary photo
                 $photos = array();
                 // for save other photos
                 $tmp_photo = array();
                 foreach ($last_uploaded_images as $value) {
                     // for photos
                     if ($count == 0) {
                         $primary_photo['filename'] = $value['ItemPhoto']['image_file'];
                         $primary_photo['dir'] = $value['ItemPhoto']['id'];
                         // add photos array into final_aray
                         $final_aray['primary_photo'] = $primary_photo;
                         //array_push($final_aray, $primary_photo);
                     } else {
                         $tmp_photo['filename'] = $value['ItemPhoto']['image_file'];
                         $tmp_photo['dir'] = $value['ItemPhoto']['id'];
                         array_push($photos, $tmp_photo);
                     }
                     $count++;
                 }
                 $final_aray['photo'] = $photos;
             } else {
                 $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
                 $this->redirect(array('controller' => 'ad_posts', 'action' => 'index'));
             }
         }
         // end of photo
         //pr($final_aray);
         $final_aray['item_category']['id'] = $item_data['ItemCategory']['id'];
         $final_aray['item_category']['name'] = $item_data['ItemCategory']['name'];
         $final_aray['brand']['id'] = $item_data['brand']['id'];
         $final_aray['brand']['name'] = $item_data['brand']['name'];
         // find included item name
         if (isset($item_data['included'])) {
             $included = 0;
             $item = "";
             foreach ($item_data['included'] as $key => $value) {
                 if ($key === 'charger') {
                     $item = 'Charger';
                 } else {
                     if ($key === 'data_cabel') {
                         $item = 'Data Cabel';
                     } else {
                         if ($key === 'ear_phone') {
                             $item = 'Ear Phone/Head Phone';
                         } else {
                             if ($key === 'memory_card') {
                                 $item = 'Memory Card';
                             } else {
                                 if ($key === 'others') {
                                     $item = 'Other';
                                 }
                             }
                         }
                     }
                 }
                 $final_aray['included'][$included] = $item;
                 $included++;
             }
             // end of included
         }
         $final_aray['jobs']['Role']['id'] = $item_data['Role']['id'];
         $final_aray['jobs']['Role']['name'] = $item_data['Role']['name'];
         $final_aray['jobs']['company_name'] = $item_data['company_name'];
         $final_aray['jobs']['designation'] = $item_data['designation'];
         $final_aray['jobs']['education'] = $item_data['education'];
         $final_aray['jobs']['experience'] = $item_data['experience'];
         $final_aray['jobs']['key_skills'] = $item_data['key_skills'];
         $final_aray['AutoModel']['id'] = $item_data['AutoModel']['id'];
         $final_aray['AutoModel']['name'] = $item_data['AutoModel']['name'];
         $final_aray['year'] = $item_data['year'];
         $final_aray['kms_driven'] = $item_data['kms_driven'];
         $final_aray['fuel_type'] = $item_data['fuel_type'];
         $final_aray['valid_till'] = $item_data['valid_till'];
         $final_aray['vehicle_type'] = $item_data['vehicle_type'];
         $final_aray['event_date'] = $item_data['event_date'];
         $final_aray['venue'] = $item_data['venue'];
         $final_aray['real_estate']['area'] = $item_data['area'];
         $final_aray['real_estate']['city'] = $item_data['city'];
         $final_aray['real_estate']['locality'] = $item_data['locality'];
         $final_aray['title'] = $item_data['title'];
         $final_aray['description'] = $item_data['desc'];
         $final_aray['price'] = $item_data['price'];
         $final_aray['negotiable'] = $item_data['negotiable'];
         $final_aray['usage'] = $item_data['usage'];
         $final_aray['is_deleted'] = 0;
         $final_aray['is_completed'] = 0;
         $final_aray['status'] = 'active';
         $final_aray['personal_info']['name'] = $item_data['name'];
         $final_aray['personal_info']['mobile'] = $item_data['mobile'];
         $final_aray['personal_info']['email'] = $item_data['email'];
         $final_aray['personal_info']['area'] = $item_data['personal_area'];
         $final_aray['personal_info']['city'] = $item_data['personal_city'];
         // Set created and modified timestamp
         date_default_timezone_set('Asia/Calcutta');
         $todays = new DateTime();
         $final_date = str_replace('-', '', $todays->format('Y-m-d'));
         $final_aray['created'] = $todays->format('Y-m-d');
         $final_aray['modified'] = $todays->format('Y-m-d');
         $ad_post = json_encode($final_aray);
         // pr($final_aray);
         // pr($ad_post);die();
         // Save JSON
         if ($this->AdPost->save($final_aray)) {
             $this->Session->setFlash('Post added successfully.', 'default', array('class' => 'alert alert-success'), 'success');
             $this->redirect(array('controller' => 'ad_posts', 'action' => 'index'));
         } else {
             $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
             $this->redirect(array('controller' => 'ad_posts', 'action' => 'index'));
         }
     }
     // get item types
     $item_types = $this->ItemType->find('list', array('order' => array('sort_order')));
     $this->set('item_types', $item_types);
     // get Role list
     $roles = $this->Role->find('list', array('order' => array('Role.name')));
     $this->set('roles', $roles);
     $user_data = $this->activeUser;
     $this->set('user_data', $user_data);
 }
Exemple #2
0
 /**
  * Converts given time (in server's time zone) to user's local time, given his/her timezone.
  *
  * @param string              $serverTime UNIX timestamp
  * @param string|DateTimeZone $timezone   User's timezone string or DateTimeZone object
  *
  * @return int UNIX timestamp
  * @see  CakeTime::convert()
  * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting
  */
 public function convert($serverTime, $timezone)
 {
     return $this->_engine->convert($serverTime, $timezone);
 }
Exemple #3
0
 /**
  * Upload your file
  *
  * @param  array $file file detail
  * @param  string $path upload path
  * @param  string $name file name when update file
  * @param  boolean $edit check edit upload mode
  * @return array
  * @author Chaiwut <*****@*****.**>
  * @since 12 July 2015
  */
 public function uploadImage($file = null, $path = null, $name = null, $edit = false)
 {
     //status to return, 0 mean `false`.
     $status = array('status' => 0, 'message' => __('ข้อมูลไม่ถูกต้อง'));
     //Check user data.
     if ($file == null || $path == null) {
         return $status;
     }
     //Alowed only `jpg`, `jpeg` and `png` only
     //to avoid large file.
     if (!in_array($file['type'], Configure::read('typeImg'))) {
         $status['message'] = __('ไม่อนุญาตให้ไฟล์ไฟล์นี้');
         return $status;
     }
     //Set file extendtion.
     $fileExtention = '';
     switch ($file['type']) {
         case 'image/png':
             $fileExtention = '.png';
             break;
         case 'image/jpeg':
             $fileExtention = '.jpg';
             break;
     }
     $fileName = CakeTime::convert(time(), new DateTimeZone('Asia/Bangkok')) . $fileExtention;
     //Set file name
     //I use timestamp for file name.
     //If user send the name to us use thier name
     if ($name != null && !$edit) {
         $fileName = $name . $fileExtention;
     } else {
         if ($name != null && $edit) {
             $fileName = $name;
         }
     }
     //Upload file
     if (is_uploaded_file($file['tmp_name'])) {
         move_uploaded_file($file['tmp_name'], $path . $fileName);
         $status['status'] = 1;
         $status['message'] = __('เพิ่มข้อมูลสำเร็จ');
         $status['file_name'] = $fileName;
         return $status;
     }
     $status['message'] = __('เพิ่มข้อมูลไม่สำเร็จ');
     return $status;
 }
Exemple #4
0
 /**
  * Added new Blog Content
  *
  * @return void
  * @author Alongkot <*****@*****.**>
  * @since 21 June 2015
  */
 public function admin_add($preview = NULL)
 {
     $this->layout = 'dashboard';
     $this->set('bloggroups', $this->Blog->Bloggroup->find('list'));
     if ($this->request->is('post')) {
         // User
         if ($preview == "preview") {
             // preview Blog
             $this->set('data', $this->request->data);
             $this->render('admin_preview');
         } else {
             // Insert to Blog Table
             $this->request->data['Blog']['user_id'] = AuthComponent::user('id');
             $this->request->data['Blog']['image_dir'] = CakeTime::convert(time(), new DateTimeZone('Asia/Bangkok'));
             // change path temp -> foder
             $temp_folder = AuthComponent::user('username') . '_temp';
             $this->request->data['Blog']['detail_th'] = str_replace($temp_folder, $this->request->data['Blog']['image_dir'], $this->request->data['Blog']['detail_th']);
             $this->request->data['Blog']['detail_en'] = str_replace($temp_folder, $this->request->data['Blog']['image_dir'], $this->request->data['Blog']['detail_en']);
             // Upload Blog Photo
             $this->Blog->create();
             $photo = $this->request->data['Blog']['photo'];
             $this->request->data['Blog']['photo'] = '';
             if (!$this->Blog->save($this->request->data)) {
                 $this->Session->setFlash(__('ไม่สามารถเพิ่มข้อมูลได้'), 'flash-fail');
                 return $this->redirect(array('action' => 'index', 'admin' => true));
             }
             // Check Temp folder and Copy file to image folder
             $this->is_copyTempFolder(AuthComponent::user('username'), $this->request->data['Blog']['image_dir']);
             // Upload Photo Cover In This Foler Blog
             if (!empty($photo['name'])) {
                 $lastId = $this->Blog->getLastInsertId();
                 $path = WWW_ROOT . 'uploads/blog/' . $this->request->data['Blog']['image_dir'] . '/';
                 $folder = new Folder($path);
                 // Check Folder path If Not to Create
                 if (is_null($folder->path)) {
                     //$folder->delete();
                     $folder->create(WWW_ROOT . DS . 'uploads' . DS . 'blog' . DS . $this->request->data['Blog']['image_dir']);
                 }
                 $status = $this->uploadImage($photo, $path, $lastId);
                 if (!$status['status']) {
                     $this->Session->setFlash($status['message'], 'flash-fail');
                     return;
                 }
                 $this->Blog->id = $lastId;
                 $this->Blog->saveField('photo', $status['file_name']);
             }
             $this->Session->setFlash(__('เพิ่มข้อมูลสำเร็จ'), 'flash-success');
             return $this->redirect(array('action' => 'index', 'admin' => true));
         }
     }
     // Open New Page
     if ($preview == NULL) {
         // Check Temp folder for delete first
         $this->is_deleteTempFolder(AuthComponent::user('username') . '_temp');
     }
     $this->set('title_for_layout', __('เขียนโพสใหม่'));
 }
 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";
         }
     }
 }
 public function edit_post($id = null)
 {
     $files_aaray = array();
     // get item types
     $item_types = $this->ItemType->find('list', array('order' => array('sort_order')));
     $this->set('item_types', $item_types);
     // get Role list
     $roles = $this->AdPost->curlGet('axi_fxchng/role_2d7e8411c977679a8dade0f7c4b967c5');
     $this->set('roles', $roles['role']);
     $user_data = $this->activeUser;
     $this->set('user_data', $user_data);
     // get last inserted ad_id of current user
     $ad_details = $this->AdPost->curlGet('axi_fxchng/' . $id);
     $this->set('ad_details', $ad_details);
     // 	// pr($ad_details);
     // // check resume
     // if (isset($ad_details['resume'])) {
     // 	if($ad_details['resume'] != null) {
     // 		$files_aaray['resume'] = $ad_details['resume'];
     // 	}
     // }
     // // check photos
     // if(isset($ad_details['primary_photo'])) {
     // 	if($ad_details['primary_photo']['filename'] != null) {
     // 		$files_aaray['primary_photo']['filename'] = $ad_details['primary_photo']['filename'];
     // 		$files_aaray['primary_photo']['dir'] = $ad_details['primary_photo']['dir'];
     // 	}
     // 	if(sizeof($ad_details['photo']) > 0) {
     // 		$outer_temp = array();
     // 		foreach ($ad_details['photo'] as $avail_photo) {
     // 			$tmp_photo = array();
     // 			$tmp_photo['filename'] = $avail_photo['filename'];
     // 			$tmp_photo['dir'] = $avail_photo['dir'];
     // 			array_push($outer_temp, $tmp_photo);
     // 		}
     // 		$files_aaray['photo'] = $outer_temp;
     // 	}
     // }
     // $this->set('saved_paths', $files_aaray);
     if ($this->request->is('post')) {
         // get uuid
         $guid = String::uuid();
         // get todays datetime in seconds
         $time_in_seconds = CakeTime::convert(time(), new DateTimeZone('Asia/Calcutta'));
         // set final id for array
         $id = "ad_1435730552_55938278-9a78-4086-ba8d-378e52d40771";
         $item_data = $this->data;
         // final Array for cloudant
         $final_aray = array();
         $final_aray['id'] = $id;
         // $final_aray['doc_type'] = 'ad';
         $final_aray['fb_id'] = $this->activeUser['User']['fb_id'];
         // $final_aray['created_timestamp'] = $time_in_seconds*1000;
         $final_aray['i_want_to'] = $item_data['i_want_to'];
         $final_aray['job_type'] = $item_data['job_type'];
         $final_aray['condition'] = $item_data['condition'];
         // $final_aray['item_type']['id'] = $item_data['ItemType']['id'];
         $final_aray['item_type']['name'] = $item_data['ItemType']['name'];
         // for resume
         // if (!$item_data['ItemType']['resume_file']['size'] <= 0) {
         // 	$filename = array();
         //              $filename['resume_file']['name'] = $item_data['ItemType']['resume_file']['name'];
         //              $filename['resume_file']['type'] = $item_data['ItemType']['resume_file']['type'];
         //              $filename['resume_file']['tmp_name'] = $item_data['ItemType']['resume_file']['tmp_name'];
         //              $filename['resume_file']['size'] = $item_data['ItemType']['resume_file']['size'];
         //              $filename['resume_file']['error'] = $item_data['ItemType']['resume_file']['error'];
         //              $filename['guid'] = $id;
         //              if(!$this->ItemPhoto->save($filename)) {
         //              	$this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger') , 'error');
         //              	$this -> redirect(array('controller' => 'ad_posts', 'action' => 'index'));
         //              }
         //              else {
         //              	$last_uploaded_resume = $this->ItemPhoto->findByGuid($id);
         //              	$final_aray['resume'] = $last_uploaded_resume['ItemPhoto']['id']."/".$last_uploaded_resume['ItemPhoto']['resume_file'];
         //              }
         // } // end of resume
         // check photo uploaded or not
         // if (!$item_data['ItemType']['image_files'][0]['size'] <= 0) {
         // 	// save images in sql database
         // 	$item_photo_details = array();
         // 	// loop each uploaded images
         //           foreach($item_data['ItemType']['image_files'] as $value) {
         //       	 	$filename = array();
         //               $filename['image_file']['name'] = $value['name'];
         //               $filename['image_file']['type'] = $value['type'];
         //               $filename['image_file']['tmp_name'] = $value['tmp_name'];
         //               $filename['image_file']['size'] = $value['size'];
         //               $filename['image_file']['error'] = $value['error'];
         //               $filename['guid'] = $id;
         //               array_push($item_photo_details, $filename);
         //           }
         //           	if($this->ItemPhoto->saveMany($item_photo_details)) {
         //           		// get current uploaded photos
         //              	$last_uploaded_images = $this->ItemPhoto->find('all',array('conditions'=>array('guid' => $id), 'order'=>'created'));
         //              	$count = 0;
         //              	$primary_photo = array(); // for save primary photo
         //             		$photos = array(); // for save other photos
         //             		$tmp_photo = array();
         //              	foreach ($last_uploaded_images as $value) {
         //              		// for photos
         //              		if($count == 0) {
         //              			$primary_photo['filename'] = $value['ItemPhoto']['image_file'];
         //              			$primary_photo['dir'] = $value['ItemPhoto']['id'];
         //              			// add photos array into final_aray
         //              			$final_aray['primary_photo'] = $primary_photo;
         //              			//array_push($final_aray, $primary_photo);
         //              		}
         //              		else {
         //              			$tmp_photo['filename'] = $value['ItemPhoto']['image_file'];
         //              			$tmp_photo['dir'] = $value['ItemPhoto']['id'];
         //              			array_push($photos, $tmp_photo);
         //              		}
         //              		$count++;
         //              	}
         //              	$final_aray['photo'] = $photos;
         //           }
         //           else {
         //               $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger') , 'error');
         //              	$this -> redirect(array('controller' => 'ad_posts', 'action' => 'index'));
         //           }
         // } // end of photo
         //pr($final_aray);
         // $final_aray['item_category']['id'] = $item_data['ItemCategory']['id'];
         $final_aray['item_category']['name'] = $item_data['ItemCategory']['name'];
         $final_aray['brand']['id'] = $item_data['brand']['id'];
         $final_aray['brand']['name'] = $item_data['brand']['name'];
         // find included item name
         if (isset($item_data['included'])) {
             $included = 0;
             $item = "";
             foreach ($item_data['included'] as $key => $value) {
                 if ($key === 'charger') {
                     $item = 'Charger';
                 } else {
                     if ($key === 'data_cabel') {
                         $item = 'Data Cabel';
                     } else {
                         if ($key === 'ear_phone') {
                             $item = 'Ear Phone/Head Phone';
                         } else {
                             if ($key === 'memory_card') {
                                 $item = 'Memory Card';
                             } else {
                                 if ($key === 'others') {
                                     $item = 'Other';
                                 }
                             }
                         }
                     }
                 }
                 $final_aray['included'][$included] = $item;
                 $included++;
             }
             // end of included
         }
         $final_aray['jobs']['Role']['id'] = $item_data['Role']['id'];
         $final_aray['jobs']['Role']['name'] = $item_data['Role']['name'];
         $final_aray['jobs']['company_name'] = $item_data['company_name'];
         $final_aray['jobs']['designation'] = $item_data['designation'];
         $final_aray['jobs']['education'] = $item_data['education'];
         $final_aray['jobs']['experience'] = $item_data['experience'];
         $final_aray['jobs']['key_skills'] = $item_data['key_skills'];
         // $final_aray['auto_model']['id'] = $item_data['AutoModel']['id'];
         // $final_aray['auto_model']['name'] = $item_data['AutoModel']['name'];
         // $final_aray['year'] = $item_data['year'];
         // $final_aray['kms_driven'] = $item_data['kms_driven'];
         // $final_aray['fuel_type'] = $item_data['fuel_type'];
         // $final_aray['valid_till'] = $item_data['valid_till'];
         // $final_aray['vehicle_type'] = $item_data['vehicle_type'];
         $final_aray['event_date'] = $item_data['event_date'];
         $final_aray['venue'] = $item_data['venue'];
         $final_aray['real_estate']['area'] = $item_data['area'];
         $final_aray['real_estate']['city'] = $item_data['city'];
         $final_aray['real_estate']['locality'] = $item_data['locality'];
         $final_aray['title'] = $item_data['title'];
         $final_aray['description'] = $item_data['desc'];
         $final_aray['price'] = (int) $item_data['price'];
         $final_aray['negotiable'] = $item_data['negotiable'];
         // $final_aray['usage'] = $item_data['how_old'];
         $final_aray['is_deleted'] = 0;
         $final_aray['is_completed'] = 0;
         $final_aray['status'] = 'active';
         $final_aray['personal_info']['you_are/i_am'] = $item_data['youare'];
         $final_aray['personal_info']['name'] = $item_data['name'];
         $final_aray['personal_info']['mobile'] = $item_data['mobile'];
         $final_aray['personal_info']['email'] = $item_data['email'];
         $final_aray['personal_info']['area'] = $item_data['personal_area'];
         $final_aray['personal_info']['city'] = $item_data['personal_city'];
         $final_aray['personal_info']['fb_id'] = $this->activeUser['User']['fb_id'];
         $final_aray['personal_info']['fb_pic'] = $this->activeUser['User']['fb_profilepic'];
         $final_aray['personal_info']['fb_link'] = $this->activeUser['User']['fb_link'];
         // Set created and modified timestamp
         date_default_timezone_set('Asia/Calcutta');
         $todays = new DateTime();
         $final_aray['created'] = $todays->format('Y-m-d H:i:s');
         $final_aray['modified'] = $todays->format('Y-m-d H:i:s');
         // $this->Post->id = 'ad_1435730552_55938278-9a78-4086-ba8d-378e52d40771';
         if ($this->AdPost->save($final_aray)) {
             // send thank you message to current user
             $Email = new CakeEmail('default');
             // set variable values
             $Email->viewVars(array('name' => $this->activeUser['User']['fb_name'], 'title' => $final_aray['title']));
             // set format html/text or both
             $Email->emailFormat('html');
             $Email->subject('Fxchng support');
             $Email->template('thank_you', 'fxchng');
             // welcome template and fxchng layout
             $Email->to($this->activeUser['User']['username']);
             $Email->send();
             // redirect to thank you page
             return $this->redirect(array('controller' => 'ad_posts', 'action' => 'posted', 'ad_1435730552_55938278-9a78-4086-ba8d-378e52d40771'));
         } else {
             $this->Session->setFlash('Sorry, an error occurred.', 'default', array('class' => 'alert alert-danger'), 'error');
             $this->redirect($this->referer());
         }
     }
 }