public function delete()
 {
     $post = $this->input->post();
     if ($post) {
         $ids = array_filter(explode(",", $post['id']));
         foreach ($ids as $id) {
             $cladArr = $imgArr = $this->common_model->selectData(CLASSIFIEDAD, '*', array("clad_id" => $id));
             //pr($imgArr,9);
             if (!empty($imgArr)) {
                 $imglist = $imgArr[0]->clad_image;
                 if ($imglist != '') {
                     $imgArr = array_filter(explode(',', $imglist));
                     foreach ($imgArr as $k => $v) {
                         removeAdImgs($v);
                         /*if(file_exists(DOC_ROOT_CLASSIFIED_AD.$v))
                         		unlink(DOC_ROOT_CLASSIFIED_AD.$v);*/
                     }
                 }
             }
             $uData = $this->common_model->selectData(USER, '*', array("u_id" => $cladArr[0]->clad_uid));
             //pr($uData,9);
             //$ret = $this->common_model->deleteData(CLASSIFIEDAD, array('clad_id' => $id ));
             $curDate = date('Y-m-d H:i:s');
             $where = 'clad_id = ' . $id;
             $param = array('clad_active' => 0, 'is_deleted' => 1, 'clad_image' => '', 'clad_modified_date' => $curDate);
             $ret = $this->common_model->updateData(CLASSIFIEDAD, $param, $where);
             if ($ret > 0) {
                 ## send mail n sms to owner
                 $uName = $uData[0]->u_fname ? $uData[0]->u_fname : '';
                 $uEmail = $uData[0]->u_email ? $uData[0]->u_email : '';
                 if ($uEmail != '') {
                     $emailTpl = $this->load->view('email_templates/addeletenotification', array('name' => $uName, 'adtitle' => $cladArr[0]->clad_title, 'adid' => $post['id']), true);
                     $retemail = sendEmail($uEmail, SUBJECT_ADDELETE_INFO, $emailTpl, FROM_EMAIL, FROM_NAME);
                 }
                 ## Send sms to seller
                 $phonemsg = AD_DELETE_NOTIFICATION;
                 ## take msg content from constant
                 $phonemsg = str_replace('{name}', $cnt, $phonemsg);
                 $phonemsg = str_replace('{clad_id}', "#" . $post['id'], $phonemsg);
                 $phonemsg = str_replace('{clad_title}', $cladArr[0]->clad_title, $phonemsg);
                 $response = connectMobile($phonemsg, $uData[0]->u_mobile);
                 $res = json_decode($response->raw_body, true);
             }
         }
         if ($ret > 0) {
             echo "success";
         } else {
             echo "error";
         }
     }
 }
 public function deleteAd($clad_id)
 {
     //$ret = $this->common_model->deleteData(CLASSIFIEDAD, array('clad_id' => $clad_id ));
     $curDate = date('Y-m-d H:i:s');
     $where = 'clad_id = ' . $clad_id;
     $param = array('clad_active' => 0, 'is_deleted' => 1, 'clad_image' => '', 'clad_modified_date' => $curDate);
     $update = $this->common_model->updateData(CLASSIFIEDAD, $param, $where);
     $flsmsg = 'Your Ad has been removed successfuly';
     if ($update) {
         $cladArr = $imgArr = $this->common_model->selectData(CLASSIFIEDAD, '*', array("clad_id" => $clad_id));
         //pr($imgArr,9);
         if (!empty($imgArr)) {
             $imglist = $imgArr[0]->clad_image;
             if ($imglist != '') {
                 $imgArr = explode(',', $imglist);
                 foreach ($imgArr as $k => $v) {
                     if (file_exists(DOC_ROOT_CLASSIFIED_AD . $v)) {
                         unlink(DOC_ROOT_CLASSIFIED_AD . $v);
                     }
                 }
             }
         }
         ## Send sms to customer of ad
         $phonemsg = AD_DELETE_NOTIFICATION;
         ## take msg content from constant
         $phonemsg = str_replace('{clad_id}', "#" . $clad_id, $phonemsg);
         $response = connectMobile($phonemsg, $this->user_session['mobile']);
         $res = json_decode($response->raw_body, true);
         $flash_arr = array('flash_type' => 'success', 'flash_msg' => $flsmsg);
     } else {
         $flash_arr = array('flash_type' => 'error', 'flash_msg' => 'Error Occured during processing..Please try again later.');
     }
     $this->session->set_flashdata($flash_arr);
     redirect("myaccount/my-ad-list");
 }
 public function deletead($data)
 {
     if (isset($data['user']) && isset($data['adid'])) {
         if ($data['user'] != '' && $data['adid'] != '') {
             $ret = $this->common_model->selectData(CLASSIFIEDAD, '*', array('clad_uid' => $data['user'], 'clad_id' => $data['adid']));
             if (count($ret) == 0) {
                 $result['status'] = "204";
                 $result['message'] = "User is not permitted to delete this ad";
                 $result['data'] = $result;
             } else {
                 $curDate = date('Y-m-d H:i:s');
                 $where = "clad_id =" . $data['adid'];
                 #$update = $this->common_model->deleteData(CLASSIFIEDAD, $where);
                 $update = $this->common_model->updateData(CLASSIFIEDAD, array('is_deleted' => '1', 'clad_active' => '0', 'clad_image' => '', 'clad_modified_date' => $curDate), $where);
                 ## remove all image of ad
                 if (!empty($ret)) {
                     $imglist = $ret[0]->clad_image;
                     if ($imglist != '') {
                         $imgArr = explode(',', $imglist);
                         foreach ($imgArr as $k => $v) {
                             if (file_exists(DOC_ROOT_CLASSIFIED_AD . $v)) {
                                 unlink(DOC_ROOT_CLASSIFIED_AD . $v);
                             }
                         }
                     }
                 }
                 ## Send sms to customer of ad
                 $res = $this->common_model->selectData(USER, '*', array('u_id' => $ret[0]->clad_uid));
                 $phonemsg = AD_DELETE_NOTIFICATION;
                 ## take msg content from constant
                 $phonemsg = str_replace('{clad_id}', "#" . $data['adid'], $phonemsg);
                 $response = connectMobile($phonemsg, $res[0]->u_mobile);
                 $res = json_decode($response->raw_body, true);
                 $result['status'] = "200";
                 $result['message'] = "Request successfuly completed";
                 $result['data'] = $result;
             }
         } else {
             $result['status'] = "204";
             $result['message'] = "Please enter valid data";
             $result['data'] = $result;
         }
     } else {
         $result['status'] = "204";
         $result['message'] = "Please enter valid data";
         $result['data'] = $result;
     }
     return $result;
 }
function sendSMS($phoneNumber)
{
    $password = mt_rand(10000, 99999);
    #$password="******";
    $message = "Thanks to use Gujjubazar.Your Mobile No:{$phoneNumber}. Your Password : {$password} Use this number as your password in login.";
    $response = connectMobile($message, $phoneNumber);
    $res = json_decode($response->raw_body, true);
    if ($res['response']['status'] == 'success') {
        return array('status' => 'success', 'password' => $password);
    } else {
        return array('status' => 'error', 'password' => $password);
    }
}
 public function autoActiveAd()
 {
     $curDate = date('Y-m-d H:i:s');
     $this->db->select('ad.*,u.*');
     $this->db->from(CLASSIFIEDAD_AD);
     $this->db->join(USER_U, "ad.clad_uid = u.u_id");
     $where = 'ad.clad_created_date < "' . date('Y-m-d H:i:s', strtotime('-30 minutes')) . '" AND ad.clad_active=2 AND u.u_active = 1 AND u.u_canpost=1 AND u.u_is_verified=1 AND ad.is_deleted=0';
     $this->db->where($where);
     $query = $this->db->get();
     $result = $query->result();
     //echo "<pre>"; print_r($this->db->queries);pr($result,9);exit;
     if (!empty($result)) {
         foreach ($result as $k => $v) {
             $where = 'clad_id = ' . $v->clad_id;
             $ret = $this->common_model->updateData(CLASSIFIEDAD, array('clad_active' => 1, 'clad_modified_date' => $curDate), $where);
             if ($ret) {
                 if ($v->u_email != '') {
                     $Arr = array();
                     $Arr['name'] = $v->u_fname;
                     $Arr['ad_title'] = $v->clad_title;
                     $Arr['siteurl'] = "http://" . $_SERVER['HTTP_HOST'];
                     $Arr['adUrl'] = createUrl("detail", array($v->clad_id, $v->clad_title));
                     $Arr['clad_id'] = $v->clad_id;
                     $Arr['baseurl'] = base_url();
                     $emailTpl = $this->load->view('email_templates/adLiveSuccessfully', $Arr, true);
                     //pr($emailTpl,8);
                     $ret = sendEmail($v->u_email, SUBJECT_NEWADLIVE_USER_NOTIFICATION, $emailTpl, FROM_EMAIL, FROM_NAME);
                 }
                 ## Send sms to customer who post ad
                 $phonemsg = AD_APPROVAL_NOTIFICATION;
                 ## take msg content from constant
                 $phonemsg = str_replace('{clad_id}', "#" . $v->clad_id, $phonemsg);
                 $response = connectMobile($phonemsg, $v->u_mobile);
                 $res = json_decode($response->raw_body, true);
             }
         }
     }
 }
 public function messageToSeller()
 {
     //pr($_POST);die;
     if (isset($_POST['message']) && $_POST['message'] != '') {
         //$cnt = urldecode($_POST['contact']);
         $message = urldecode($_POST['message']);
         $dataArr = array();
         $dataArr['message'] = $message;
         //$dataArr['buyer_contact'] = $cnt;
         $this->load->helper('email');
         ## send mail / msg to seller regarding msg notification on his/her Ad
         $res = $this->common_model->selectData(USER, 'u_fname,u_lname,u_email,u_mobile', array("u_id" => $_POST['clad_uid']));
         $sellerEmail = @$res[0]->u_email;
         $cnt = $phoneNumber = @$res[0]->u_mobile;
         $dataArr['name'] = $res[0]->u_fname . ' ' . $res[0]->u_lname;
         //$dataArr['siteurl'] = "http://" . $_SERVER['HTTP_HOST'];
         /*             * * User notification ** */
         $macids = array();
         $macid = $this->common_model->getMacids(trim($_POST['clad_uid']));
         foreach ($macid as $val) {
             $macids[] = $val->macid;
         }
         ## get ad title
         $adDetail = $this->common_model->selectData(CLASSIFIEDAD, '*', array("clad_id" => $_POST['clad_id']));
         $pushMsg = "You have new message on Ad " . $adDetail[0]->clad_title . " - " . trim($message);
         $msg = array('message' => $pushMsg, 'title' => 'Gujjubazar', 'subtitle' => 'No. 1 Classified site', 'type' => 'message', 'msgcnt' => 3, 'vibrate' => 1, 'sound' => 1);
         if (count($macids) != 0) {
             sendNotification($macids, $msg);
         }
         if ($sellerEmail != '') {
             ## send mail to seller if seller's mail id available
             // $adDetail = $this->common_model->selectData(CLASSIFIEDAD, '*', array('clad_id' => $_POST['clad_id']));
             $dataArr['adtitle'] = $adDetail[0]->clad_title;
             $dataArr['adid'] = $_POST['clad_id'];
             $emailTpl = $this->load->view('email_templates/sellerContactMail', $dataArr, true);
             $ret = sendEmail($sellerEmail, SUBJECT_SELLER_NOTIFICATION, $emailTpl, FROM_EMAIL, FROM_NAME);
             if (!$ret) {
                 $sendM = "Error occured during contacting seller.Please try after sometime";
             } else {
                 $sendM = "Your Message has been send to seller.";
             }
         }
         ## Send sms to seller
         $phonemsg = SELLER_MSG_NOTIFICATION;
         ## take msg content from constant
         $phonemsg = str_replace('{name}', $cnt, $phonemsg);
         $phonemsg = str_replace('{clad_id}', "#" . $_POST['clad_id'], $phonemsg);
         $response = connectMobile($phonemsg, $phoneNumber);
         $res = json_decode($response->raw_body, true);
         ## save into db
         $uid = $this->user_session['uid'];
         if (isset($uid) && $uid != '') {
             $data = array('clad_id' => trim($_POST['clad_id']), 'ad_msg_from' => $uid, 'ad_msg_to' => trim($_POST['clad_uid']), 'ad_message' => trim($message), 'ad_msg_read_flag' => 0);
             $insVal = $this->common_model->insertData(MESSAGE, $data);
         } else {
             $data = array('ad_reply_user_contact' => trim($cnt), 'ad_reply_user_message' => trim($message), 'clad_id' => trim($_POST['clad_id']), 'ad_reply_created_date' => date('Y-m-d H:i:s'), 'ad_reply_modified_date' => date('Y-m-d H:i:s'), 'ad_reply_status' => 0);
             $insVal = $this->common_model->insertData(ADREPLY, $data);
         }
         ## process to update cache json for this new msg by read cache .. process index .. and write cache
         if ($insVal) {
             $sendM = "Your Message has been send to seller.";
         } else {
             $sendM = "Error occured during contacting seller.Please try after sometime";
         }
         $this->manageCache($_POST['clad_id']);
         echo $sendM;
         return;
     } else {
         echo 'Error occured during processing..Please try again.';
         return;
     }
 }