public function toggleStatus() { $post = $this->input->post(); $curDate = date('Y-m-d H:i:s'); if ($post) { switch ($post['status']) { case '1': $act = 0; break; case '2': $act = 1; break; case '0': $act = 1; break; } $data = array('clad_active' => $act); if ($act == 1) { $data['clad_modified_date'] = "'" . $curDate . "'"; } if (isset($post['status']) && $post['status'] == 0) { $data1 = array('clad_expiry_date' => ' CASE WHEN clad_expiry_date <= DATE(CURDATE()) THEN "' . adExpiryDate() . '" ELSE clad_expiry_date END'); $data = array_merge($data, $data1); } $where = array("clad_id" => $post['id']); $ret_deal = $this->common_model->updateData(CLASSIFIEDAD, $data, $where, false); if ($ret_deal > 0) { echo "success"; } else { echo "error"; } } }
public function changestatus($data) { $adid = $data['adid']; $status = $data['status']; $curDate = date('Y-m-d H:i:s'); if (isset($adid) && isset($status)) { if ($adid != '' && $status != '') { if (strtolower($status) == 'active') { $status = 1; $expDate = adExpiryDate(); } else { if (strtolower($status) == 'inactive') { $status = 0; $expDate = $curDate; } } ## save into db $param = array('clad_active' => $status, 'clad_modified_date' => $curDate); $param['clad_expiry_date'] = $expDate; $where = array("clad_id" => $adid); $update = $this->common_model->updateData(CLASSIFIEDAD, $param, $where); $messages['adid'] = $adid; $messages['status'] = $status; $result['status'] = "200"; $result['message'] = "Request successfuly completed"; $result['data'] = $messages; } else { $result['status'] = "204"; $result['message'] = "Please enter valid data"; $result['data'] = array(); } } else { $result['status'] = "204"; $result['message'] = "Please enter valid data"; $result['data'] = array(); } return $result; }
public function makeAdActive($clad_id, $flg) { //echo $id;die; //echo $clad_id;echo $flg;die; $session = $this->session->userdata('user_session'); #pr($session,1); if (!isset($session['uid'])) { redirect(base_url()); } $uid = $this->user_session['uid']; $curDate = date('Y-m-d H:i:s'); $where = 'clad_id = ' . $clad_id; $expDate = adExpiryDate(); if ($flg == 0) { $expDate = $curDate; } $param = array('clad_active' => $flg, 'clad_expiry_date' => $expDate); if ($flg == 1) { $param['clad_modified_date'] = $curDate; } $update = $this->common_model->updateData(CLASSIFIEDAD, $param, $where); $flsmsg = 'Your Ad has been active successfuly'; if ($flg == 0) { $flsmsg = 'Your Ad has been In-active successfuly'; } if ($update) { $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 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); } } }