public function editClassified($data)
 {
     $error = false;
     $response = array();
     $result = array();
     if (trim($data['category']) == "") {
         $error = true;
     }
     if (trim($data['title']) == "") {
         $error = true;
     }
     if (trim($data['price']) == "") {
         $error = true;
     }
     if ($error != true) {
         ## check for blocked word
         $blockedWordArr = getBlockedWords();
         //pr($blockedWordArr,8);
         $searchTitleArr = explode(' ', trim($data['title']));
         $searchDescArr = explode(' ', trim($data['description']));
         foreach ($blockedWordArr as $token) {
             if (trim($token) != '') {
                 //if (stristr($cladtitle, $token) !== FALSE) {
                 if (in_array($token, $searchTitleArr)) {
                     $result['status'] = "205";
                     $result['message'] = "Your Ad Title contains some bad words which is not accepted in our system.";
                     $result['data'] = array("error" => "Your Ad Title contains some bad words which is not accepted in our system.");
                     return $result;
                 }
                 //if (stristr($claddesc, $token) !== FALSE) {
                 if (in_array($token, $searchDescArr)) {
                     $result['status'] = "205";
                     $result['message'] = "Your Ad Description contains some bad words which is not accepted in our system.";
                     $result['data'] = array("error" => "Your Ad Description contains some bad words which is not accepted in our system.");
                     return $result;
                 }
             }
         }
         $curDate = date('Y-m-d H:i:s');
         $ads = $data['adid'];
         $where = 'clad_id = ' . $ads;
         $ret = $this->common_model->selectData(CLASSIFIEDAD, '*', array('clad_id' => $ads));
         $files = processAdImages($_FILES);
         $param = array('clad_title' => $data['title'], 'clad_price' => $data['price'], 'clad_category' => trim($data['category']), 'clad_description' => $data['description'], 'clad_modified_date' => $curDate, 'clad_city' => $data['city']);
         #$filelist = implode(',', array_filter($files['images']['name']));
         $filelist = trim($data['images']);
         $filelist = explode(",", $filelist);
         $filelist1 = array_filter(explode(",", $ret[0]->clad_image));
         $param['clad_image'] = implode(',', array_merge($filelist, $filelist1));
         if (isset($data['defaultImageKey']) && $data['defaultImageKey'] != '') {
             $items = array_filter(explode(',', $param['clad_image']));
             if (($key = array_search($data['defaultImageKey'], $items)) !== false) {
                 unset($items[$key]);
             }
             $temp = implode(',', $items);
             if ($temp != '') {
                 $param['clad_image'] = $data['defaultImageKey'] . "," . $temp;
             } else {
                 $param['clad_image'] = $data['defaultImageKey'];
             }
         }
         if (isset($data['locality']) && $data['locality'] != '') {
             $param['clad_locality'] = trim($data['locality']);
         }
         foreach ($this->otherFields as $key => $value) {
             if (isset($data[$key])) {
                 $param[$key] = $data[$key];
             }
         }
         //$param['clad_active'] = 1;
         //$param['clad_expiry_date'] = date("Y-m-d H:i:s", strtotime(" +50 day"));
         $update = $this->common_model->updateData(CLASSIFIEDAD, $param, $where);
         if ($update) {
             ## Upload images
             /*$config['upload_path'] = DOC_ROOT_CLASSIFIED_AD;
             				$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
             				$this->load->library('upload', $config);
             				$fileParam = array('name', 'type', 'tmp_name', 'error', 'size');
             				for ($i = 0; $i < count($files['images']['name']); $i++) {
             					$imgName = $files['images']['name'][$i];
             					foreach ($fileParam as $j)
             						$_FILES['images'][$j] = $files['images'][$j][$i];
             
             					$_FILES['images']['name'] = $imgName;
             
             					if (!$this->upload->do_upload('images')) {
             						$error = $this->upload->display_errors();
             					}
             
             					/* Watermark */
             /*$this->load->library('image_lib');
             					$config['source_image'] = $config['upload_path'].$imgName;
             					$config['wm_text']  = WATERMARK;
             					$config['wm_type'] = 'text';
             					$config['wm_font_size'] = '80';
             					$config['wm_opacity']       = 50;
             					$config['wm_vrt_alignment'] = 'bottom';
             					$config['wm_hor_alignment'] = 'right';
             					
             					$this->image_lib->initialize($config);
             					
             					if (!$this->image_lib->watermark()) {
             						$e_flag = 1;
             						$error = $this->image_lib->display_errors();
             					}
             
             					dowatermark($config['upload_path'].$imgName);
             					if ($error != "")
             					{
             						echo "Error:" . $error;
             						die;
             					}
             				}*/
             $result['status'] = "200";
             $result['message'] = "Request successfuly completed";
             $data["clad_image"] = $param['clad_image'];
             $result['data'] = array("adid" => $data);
         } else {
             $result['status'] = "200";
             $result['message'] = "Request successfuly completed";
             $data["clad_image"] = $param['clad_image'];
             $result['data'] = array("adid" => $data);
         }
     } else {
         $result['status'] = "204";
         $result['message'] = "There is problem with data passing";
         $result['data'] = array();
     }
     return $result;
 }
 public function userAdEdit($id)
 {
     //echo $id;die;
     $session = $this->session->userdata('user_session');
     #pr($session,1);
     if (!isset($session['uid'])) {
         redirect(base_url());
     }
     $uid = $this->user_session['uid'];
     $post = $this->input->post();
     $adArr = $this->common_model->selectData(CLASSIFIEDAD, '*', array("clad_id" => $id), 'clad_modified_date', 'desc');
     $data['resArr'] = $prevImgArr = (array) $adArr[0];
     if ($post) {
         //pr($post,8);
         $this->load->library('form_validation');
         $this->form_validation->set_rules('category', 'Category', 'trim|required');
         $this->form_validation->set_rules('heading', 'Heading', 'trim|required');
         $this->form_validation->set_rules('price', 'Price', 'trim|required');
         $this->form_validation->set_rules('textcomment', 'Comment', 'trim|required');
         if ($this->form_validation->run() !== false) {
             $curDate = date('Y-m-d H:i:s');
             $where = 'clad_id = ' . $id;
             //pr($post,8);
             ## check for blocked word
             $cladtitle = trim($post['heading']);
             $claddesc = trim($post['textcomment']);
             $this->load->library('user_agent');
             $blockedWordArr = getBlockedWords();
             $searchTitleArr = explode(' ', $cladtitle);
             $searchDescArr = explode(' ', $claddesc);
             //pr($blockedWordArr,8);
             foreach ($blockedWordArr as $token) {
                 //if (strpos($cladtitle, $token) !== FALSE) {
                 if (in_array($token, $searchTitleArr)) {
                     $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'Your Ad Title contains some bad words which is not accepted in our system.');
                     $this->session->set_flashdata($flash_arr);
                     redirect($this->agent->referrer());
                 }
                 //if (strpos($claddesc, $token) !== FALSE) {
                 if (in_array($token, $searchDescArr)) {
                     $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'Your Ad Description contains some bad words which is not accepted in our system.');
                     $this->session->set_flashdata($flash_arr);
                     redirect($this->agent->referrer());
                 }
             }
             //echo $previmgstr = $prevImgArr['clad_image'];
             //$files = processAdImages($_FILES);
             //$previmgstr = $prevImgArr['clad_image'];
             $newimagesArr = array();
             /**  Old popup based image upload code :Mitesh
             				$newimages = array_filter(explode(",",$post['newimages']));
             				foreach ($newimages as $img)
             					$imgArray[]=str_replace("tmp/","",$img);
             				$newimagesArr = implode(",",$imgArray);*/
             $resimg = array();
             $prevImgArr['clad_image'] = trim($prevImgArr['clad_image'], ',');
             $prevImgArr = explode(',', $prevImgArr['clad_image']);
             //$newimages = array_filter(explode(",",$post['newimagesid']));
             $newimagesArr = $post['newimagesid'];
             $unlinkimgarr = array();
             $ij = 1;
             //$curoldimg = explode('||',$post['newimagesid']);
             //$curoldimg = explode(',',$curoldimg[1]);
             $newimagesArr = trim($newimagesArr, ',');
             $curoldimg = explode(',', $newimagesArr);
             foreach ($prevImgArr as $k => $v) {
                 if (!in_array($v, $curoldimg)) {
                     $unlinkimgarr[] = $v;
                     unset($prevImgArr[$k]);
                 }
             }
             //pr($unlinkimgarr,9);
             ##get first image to set mainimage
             /*if(isset($post['firstimage']) && $post['firstimage']!='')
             		{
             			$xArr = explode("||",$post['firstimage']);
             			$firstimage = '';
             			if($xArr[1] != "")
             				$firstimage = $xArr[1];
             		}*/
             /*foreach($newimages as $img)
             				{
             					$imgdata = $post[$img];
             					if($imgdata!='')
             					{
             						$resimg[] = $retval = base64_to_jpeg($imgdata,$ij);
             						//if($firstimage == '' && $xArr[0]==$img)
             						//	$firstimage = $retval;
             
             						//if(isset($prevImgArr[$ij-1]) && $prevImgArr[$ij-1] != '')
             							//$unlinkimgarr[] = $prevImgArr[$ij-1];
             					}
             					else
             					{
             						if(isset($prevImgArr[$ij-1]) && $prevImgArr[$ij-1] != '')
             							$resimg[] = $prevImgArr[$ij-1];
             					}
             					$ij++;
             				}
             				
             				
             				$imgArray=array();
             				foreach ($resimg as $img)
             					$imgArray[]=str_replace("uploads/ad/tmp/","",$img);
             				$firstimage = str_replace("uploads/ad/tmp/","",$firstimage);
             				$imgArray = array_diff($imgArray, array($firstimage));
             				array_unshift($imgArray,$firstimage);
             				$newimagesArr = implode(",",$imgArray);*/
             //pr($unlinkimgarr);
             //pr($newimagesArr);
             //pr($resimg,9);
             $param = array('clad_title' => $post['heading'], 'clad_price' => $post['price'], 'clad_category' => trim($post['clad_category']), 'clad_description' => $post['textcomment'], 'clad_city' => trim($post['city']), 'clad_image' => $newimagesArr, 'clad_modified_date' => $curDate);
             if (isset($post['locality']) && $post['locality'] != '') {
                 $param['clad_locality'] = trim($post['locality']);
             }
             /*if(!empty($files['images']['name']))
             		{
             			$param['clad_image']=implode(',', array_filter($files['images']['name']));
             			if(isset($_POST['images']) && !empty($_POST['images']))
             			{
             				foreach($_POST['images'] as $k=>$v)
             				{
             					if(isset($_FILES['images']['name'][$k]) && $_FILES['images']['name'][$k] != '')
             					{
             						if(file_exists(DOC_ROOT_CLASSIFIED_AD.$v))
             							unlink(DOC_ROOT_CLASSIFIED_AD.$v);
             						unset($_POST['images'][$k]);
             					}
             				}
             				$param['clad_image'] = $param['clad_image'].','.implode(',',$_POST['images']);
             			}
             		}*/
             //pr($param,9);
             foreach ($this->otherFields as $key => $value) {
                 if (isset($post[$key])) {
                     $param[$key] = $post[$key];
                 }
             }
             $update = $this->common_model->updateData(CLASSIFIEDAD, $param, $where);
             if ($update) {
                 ## Upload images
                 /*$config['upload_path'] = DOC_ROOT_CLASSIFIED_AD;
                 					$config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
                 					$this->load->library('upload', $config);
                 					$fileParam = array('name', 'type', 'tmp_name', 'error', 'size');
                 					for ($i = 0; $i < count($files['images']['name']); $i++) {
                 						$imgName = $files['images']['name'][$i];
                 						foreach ($fileParam as $j)
                 							$_FILES['images'][$j] = $files['images'][$j][$i];
                 
                 						$_FILES['images']['name'] = $imgName;
                 						//echo $imgName;die;
                 						if (!$this->upload->do_upload('images')) {
                 							$error = $this->upload->display_errors();
                 						}
                 
                 						if ($error != "")
                 							echo "Error:" . $error;
                 					}*/
                 // Old popup based image upload code :Mitesh
                 /*$newimages = array_filter(explode(",",$post['newimages']));
                 		foreach ($newimages as $img)
                 		{
                 			if(strpos($img,"tmp")!==false)
                 			{
                 				$from = './uploads/ad/'.$img;
                 				$to = './uploads/ad/'.str_replace("tmp/","",$img);
                 				rename($from, $to);
                 			}
                 		}*/
                 //move files from tmp to upload folder
                 foreach ($curoldimg as $img) {
                     $from = './uploads/ad/tmp/' . $img;
                     $to = './uploads/ad/' . $img;
                     rename($from, $to);
                 }
                 // unlink old file
                 if (!empty($unlinkimgarr)) {
                     foreach ($unlinkimgarr as $v) {
                         if (file_exists(DOC_ROOT_CLASSIFIED_AD . $v)) {
                             unlink(DOC_ROOT_CLASSIFIED_AD . $v);
                         }
                     }
                 }
                 $flash_arr = array('flash_type' => 'success', 'flash_msg' => 'Your Ad has been updated successfully');
                 $this->session->set_flashdata($flash_arr);
                 redirect("myaccount/my-ad-list");
             } else {
                 $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'Error Occured during processing..Please try again later.');
             }
         }
         $this->session->set_flashdata($flash_arr);
         $data['error_msg'] = validation_errors();
         //$error;
     }
     $data['otherFields'] = $this->otherFields;
     $data['cityArr'] = getCities();
     $data['view'] = 'myAdEdit';
     $data['categories'] = $this->common_model->getCategoryOrderedArray();
     $this->load->view('content', $data);
 }
 public function submitad()
 {
     $post = $this->input->post();
     //pr($_FILES);
     //pr($post,9);
     if ($post) {
         $this->load->library('form_validation');
         /* $this->form_validation->set_rules('email', 'Email address', 'trim|valid_email', array(
            "required" => "Please enter %s.",
            "valid_email" => "Please enter valid %s.",
            )
            ); */
         $this->form_validation->set_rules('category', 'Category', 'trim|required');
         $this->form_validation->set_rules('heading', 'Heading', 'trim|required');
         $this->form_validation->set_rules('price', 'Price', 'trim|required');
         if (isset($this->user_session['uid']) && $this->user_session['uid'] != '') {
             ##
         } else {
             $this->form_validation->set_rules('fname', 'Name', 'trim|required');
             $this->form_validation->set_rules('mobile', 'Phone no.', 'trim|required');
         }
         if ($this->form_validation->run() !== false) {
             $curDate = date('Y-m-d H:i:s');
             $verify = true;
             $user_verified = '';
             //$adActiveStatus =0;
             $cladtitle = trim($post['heading']);
             $claddesc = trim($post['textcomment']);
             $this->load->library('user_agent');
             ## check for duplicate Ad
             $checkary = array('clad_title' => trim($post['heading']), 'clad_category' => trim($post['clad_category']), 'clad_description' => trim($post['textcomment']));
             $adArr = $this->common_model->selectData(CLASSIFIEDAD, 'clad_id', $checkary);
             ## check for blocked word
             $blockedWordArr = getBlockedWords();
             //pr($blockedWordArr,8);
             $searchTitleArr = explode(' ', $cladtitle);
             $searchDescArr = explode(' ', $claddesc);
             foreach ($blockedWordArr as $token) {
                 //if (stristr($cladtitle, $token) !== FALSE) {
                 if (in_array($token, $searchTitleArr)) {
                     $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'Your Ad Title contains bad word <b>"' . $token . '"</b> which is not accepted in our system.');
                     $this->session->set_flashdata($flash_arr);
                     redirect($this->agent->referrer());
                 }
                 //if (stristr($claddesc, $token) !== FALSE) {
                 if (in_array($token, $searchDescArr)) {
                     $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'Your Ad Description contains some bad words <b>"' . $token . '"</b> which is not accepted in our system.');
                     $this->session->set_flashdata($flash_arr);
                     redirect($this->agent->referrer());
                 }
             }
             //pr($_POST,8);
             if (isset($this->user_session['uid']) && $this->user_session['uid'] != '') {
                 //if(isset($this->user_session['u_canpost']) && $this->user_session['u_canpost']==1)
                 //	$adActiveStatus=1;
                 ##check for duplicate add
                 //$this->checkDuplicateAd($post);
                 $uid = $this->user_session['uid'];
                 $user_verified = $this->user_session['user_verified'];
                 $uArr = $this->common_model->selectData(USER, '*', array("u_id" => $uid));
                 if (!empty($uArr)) {
                     if ($uArr[0]->u_mobile != '') {
                         $verify = false;
                         $this->session->set_userdata('user_mobile', $uArr[0]->u_mobile);
                     } else {
                         ## v hvn't user's mobile no so getting again from user and check it and send pwd on it and update in db
                         if (trim($post['mobile']) != '') {
                             $uArr = $this->common_model->selectData(USER, '*', array("u_mobile" => $post['mobile']));
                             if (!empty($uArr)) {
                                 $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'This Mobile Number is already registered with us.');
                                 $this->session->set_flashdata($flash_arr);
                                 redirect($this->agent->referrer());
                             }
                             $password = sendSMS($post['mobile']);
                             $wheread = 'u_id = ' . $uid;
                             $updateRecord = array('u_mobile' => $post['mobile'], 'u_password' => md5($password['password']));
                             $updateads = $this->common_model->updateData(USER, $updateRecord, $wheread);
                             $this->session->set_userdata('user_mobile', trim($post['mobile']));
                         }
                     }
                     if ($uArr[0]->u_email == '' && $post['email'] != '') {
                         $wheread = 'u_id = ' . $uid;
                         $updateRecord = array('u_email' => $post['email']);
                         $updateads = $this->common_model->updateData(USER, $updateRecord, $wheread);
                         $this->session->set_userdata('email', trim($post['email']));
                     }
                 }
                 $uidVal = $uid;
             } else {
                 ## check for duplicate Ad
                 $this->checkDuplicateAd($post);
                 ## check first if user exist
                 $uArr = $this->common_model->selectData(USER, 'u_id', array("u_mobile" => $post['mobile']));
                 if (!empty($uArr)) {
                     $uidVal = $uArr[0]->u_id;
                 } else {
                     $data = array('u_fname' => trim($post['fname']), 'u_mobile' => trim($post['mobile']), 'u_city' => trim($post['city']), 'u_created_date' => $curDate, 'u_modified_date' => $curDate, 'u_active' => 1, 'u_is_verified' => 0);
                     if (isset($post['email']) && $post['email'] != '') {
                         $data['u_email'] = trim($post['email']);
                     }
                     $uidVal = $this->common_model->insertData(USER, $data);
                     ## send welcome mail to user who post ad first time
                     if (isset($post['email']) && $post['email'] != '') {
                         $Arr = array();
                         $Arr['name'] = $post['fname'] . ' ' . $post['lname'];
                         $Arr['username'] = trim($post['mobile']);
                         $emailTpl = $this->load->view('email_templates/signup', $Arr, true);
                         $ret = sendEmail($post['email'], SUBJECT_WELCOME_USER_NOTIFICATION, $emailTpl, FROM_EMAIL, FROM_NAME);
                     }
                 }
                 $this->session->set_userdata('user_mobile', trim($post['mobile']));
                 $this->session->set_userdata('email', trim($post['email']));
             }
             if ($uidVal > 0) {
                 ## Process images for name
                 //$data = $_FILES;
                 //$files = processAdImages($data);
                 $newimagesArr = '';
                 /**  Old popup based image upload code :Mitesh
                       $newimages = array_filter(explode(",",$post['newimages']));
                       foreach ($newimages as $img)
                       $imgArray[]=str_replace("tmp/","",$img);
                       $newimagesArr = implode(",",$imgArray);
                      */
                 ##get first image to set mainimage
                 /* if(isset($post['firstimage']) && $post['firstimage']!='')
                                       {
                                       $xArr = explode("||",$post['firstimage']);
                                       $firstimage = '';
                                       if($xArr[1] != "")
                                       $firstimage = $xArr[1];
                                       }
                 
                                       $resimg =array();
                                       $newimages = array_filter(explode(",",$post['newimagesid']));
                                       $ij=1;
                                       foreach ($newimages as $img)
                                       {
                                       $imgdata = $post[$img];
                                       if($imgdata!='')
                                       $resimg[] = $retval = base64_to_jpeg($imgdata,$ij);
                                       if($firstimage == '' && $xArr[0]==$img)
                                       $firstimage = $retval;
                                       $ij++;
                                       }
                 
                                       $imgArray = array();
                                       foreach ($resimg as $img)
                                       $imgArray[]=str_replace("uploads/ad/tmp/","",$img);
                                       $firstimage = str_replace("uploads/ad/tmp/","",$firstimage);
                                       $imgArray = array_diff($imgArray, array($firstimage));
                                       array_unshift($imgArray,$firstimage);
                 
                                       $newimagesArr = implode(",",$imgArray); */
                 if ($post['newimagesid'] != '') {
                     $ts = array();
                     $newimagesArr1 = explode(',', $post['newimagesid']);
                     foreach ($newimagesArr1 as $v) {
                         if ($v != '') {
                             $ts[] = $v;
                         }
                     }
                     $newimagesArr = implode(',', $ts);
                 }
                 //pr($newimagesArr);die;
                 $data = array('clad_uid' => $uidVal, 'clad_title' => $cladtitle, 'clad_category' => trim($post['clad_category']), 'clad_description' => $claddesc, 'clad_price' => trim($post['price']), 'clad_city' => trim($post['city']), 'clad_created_date' => $curDate, 'clad_modified_date' => $curDate, 'clad_expiry_date' => adExpiryDate($post['clad_condition']), 'clad_active' => 2, 'is_deleted' => 0, 'clad_total_views' => 0, 'clad_image' => $newimagesArr);
                 if (isset($post['locality']) && $post['locality'] != '') {
                     $data['clad_locality'] = trim($post['locality']);
                 }
                 foreach ($this->otherFields as $key => $value) {
                     if (isset($post[$key])) {
                         $data[$key] = $post[$key];
                     }
                 }
                 $ads = $this->common_model->insertData(CLASSIFIEDAD, $data);
                 if ($ads > 0) {
                     ## Upload images
                     /*
                                               $config['upload_path'] = DOC_ROOT_CLASSIFIED_AD;
                                               $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
                                               $this->load->library('upload', $config);
                                               $fileParam = array('name', 'type', 'tmp_name', 'error', 'size');
                                               for ($i = 0; $i < count($files['images']['name']); $i++) {
                                               $imgName = $files['images']['name'][$i];
                                               foreach ($fileParam as $j)
                                               $_FILES['images'][$j] = $files['images'][$j][$i];
                     
                                               $_FILES['images']['name'] = $imgName;
                     
                                               if (!$this->upload->do_upload('images')) {
                                               $error = $this->upload->display_errors();
                                               }
                     
                                               if ($error != "")
                                               {
                                               echo "Error:" . $error;
                                               die;
                                               }
                                               } */
                     // Old popup based image upload code :Mitesh
                     /* $newimages = array_filter(explode(",",$post['newimages']));
                        foreach ($newimages as $img)
                        {
                        if(strpos($img,"tmp")!==false)
                        {
                        $from = './uploads/ad/'.$img;
                        $to = './uploads/ad/'.str_replace("tmp/","",$img);
                        rename($from, $to);
                        }
                        } */
                     /* foreach ($resimg as $img)
                        {
                        if(strpos($img,"tmp")!==false)
                        {
                        $from = './'.$img;
                        $to = './'.str_replace("tmp/","",$img);
                        rename($from, $to);
                        }
                        } */
                     $newimagesArr = array_filter(explode(',', $post['newimagesid']));
                     foreach ($newimagesArr as $img) {
                         $from = './uploads/ad/tmp/' . $img;
                         $to = './uploads/ad/' . $img;
                         rename($from, $to);
                     }
                 }
                 ## send mail to admin regarding new Ad.
                 if (isset($post['fname']) && $post['fname'] != '') {
                     $custName = $post['fname'];
                 } else {
                     $custName = $this->user_session['firstname'];
                 }
                 $Arr = array();
                 $Arr['name'] = FROM_NAME;
                 $Arr['customer_name'] = trim($custName);
                 $Arr['siteurl'] = "http://" . $_SERVER['HTTP_HOST'];
                 $Arr['adUrl'] = createUrl("detail", array($ads, $data['clad_title']));
                 $Arr['clad_id'] = $ads;
                 $frmEmail = FROM_EMAIL;
                 $Arr['baseurl'] = base_url();
                 if (isset($post['email']) && $post['email'] != '') {
                     $frmEmail = $post['email'];
                 }
                 $Arr['frmEmail'] = $frmEmail;
                 $emailTpl = $this->load->view('email_templates/adPostedSuccessfully', $Arr, true);
                 $ret = sendEmail(FROM_EMAIL, SUBJECT_NEWAD_ADMIN_NOTIFICATION, $emailTpl, $frmEmail, $Arr['name']);
                 ## send mail to user who post ad
                 //if (isset($post['email']) && $post['email'] != '') {
                 if (isset($post['email']) && $post['email'] != '') {
                     $custEmail = $post['email'];
                 } else {
                     $custEmail = $this->user_session['email'];
                 }
                 if ($custEmail != '') {
                     $Arr = array();
                     $Arr['name'] = $custName;
                     $Arr['siteurl'] = "http://" . $_SERVER['HTTP_HOST'];
                     $Arr['adUrl'] = createUrl("detail", array($ads, $data['clad_title']));
                     $Arr['clad_id'] = $ads;
                     $Arr['frmEmail'] = FROM_EMAIL;
                     $Arr['ad_title'] = $post['heading'];
                     $emailTpl = $this->load->view('email_templates/adPostNotificationUser', $Arr, true);
                     $ret = sendEmail($this->user_session['email'], SUBJECT_NEWAD_USER_NOTIFICATION, $emailTpl, FROM_EMAIL, FROM_NAME);
                 }
                 if ($user_verified != '1') {
                     if ($verify) {
                         $password = sendSMS($post['mobile']);
                         $where = 'u_id = ' . $uidVal;
                         $update = $this->common_model->updateData(USER, array('u_password' => md5($password['password'])), $where);
                         $flash_arr = array('flash_type' => 'success', 'flash_msg' => 'Check password in your mobile number which we have set with this ad');
                         $this->session->set_userdata('user_verification', true);
                         $this->session->userdata('user_from', 'createad');
                         $this->session->set_userdata('user_ads', $ads);
                         $this->session->set_userdata('user_id', $uidVal);
                         $this->session->set_flashdata($flash_arr);
                         redirect("classified/verification");
                     } else {
                         $wheread = 'clad_id = ' . $ads;
                         $updateRecord = array('clad_active' => 2, "is_deleted" => 0);
                         $updateads = $this->common_model->updateData(CLASSIFIEDAD, $updateRecord, $wheread);
                         $this->session->set_userdata('user_ads', $ads);
                         $this->session->set_userdata('user_id', $this->user_session['uid']);
                         $flash_arr = array('flash_type' => 'success', 'flash_msg' => 'Your ad submitted successfully and available on our site after reviewed by company.');
                         $this->session->set_flashdata($flash_arr);
                         ## Send sms to customer who post ad
                         $phonemsg = AD_ADD_NOTIFICATION;
                         ## take msg content from constant
                         $phonemsg = str_replace('{clad_id}', "#" . $ads, $phonemsg);
                         $response = connectMobile($phonemsg, $this->user_session['mobile']);
                         $res = json_decode($response->raw_body, true);
                         redirect("/classified/search");
                     }
                 } else {
                     $wheread = 'clad_id = ' . $ads;
                     $updateRecord = array('clad_active' => 2, "is_deleted" => 0);
                     $updateads = $this->common_model->updateData(CLASSIFIEDAD, $updateRecord, $wheread);
                     $flash_arr = array('flash_type' => 'success', 'flash_msg' => 'Your ad submitted successfully and available on our site after reviewed by company.');
                     $this->session->set_flashdata($flash_arr);
                     ## Send sms to customer who post ad
                     $phonemsg = AD_ADD_NOTIFICATION;
                     ## take msg content from constant
                     $phonemsg = str_replace('{clad_id}', "#" . $ads, $phonemsg);
                     $response = connectMobile($phonemsg, $this->user_session['mobile']);
                     $res = json_decode($response->raw_body, true);
                     redirect("/classified/search");
                 }
             } else {
                 $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'An error occurred while processing.');
                 redirect("/classified/add/");
             }
             $this->session->set_flashdata($flash_arr);
             redirect("classified/search");
         } else {
             //pr(validation_errors(),8);
             $data['error_msg'] = validation_errors();
             //$error;
             $data['view'] = "add";
             $this->load->view('content', $data);
         }
     }
 }