File: /home/barbeatleanalyti/public_html/mbaris.beatleanalytics.com/application/models/Admin_model.php
<?php
class Admin_model extends CI_Model
{
public function getAllCountry()
{
$this->load->database();
$query = $this->db->get('countries');
$result = $query->result();
return $result;
}
public function getAllState()
{
$this->load->database();
$query = $this->db->get_where('states' , array('country_id'=>'101'));
$result = $query->result();
return $result;
}
public function getAllStateName($sid)
{
$this->load->database();
$query = $this->db->get_where('states' , array('country_id'=>'101','id'=>$sid));
$result = $query->result();
return $result;
}
public function getAllCity()
{
$this->load->database();
$query = $this->db->get('cities');
$result = $query->result();
return $result;
}
public function getAllCityName($cid)
{
$this->load->database();
$query = $this->db->get_where('cities' , array('id'=>$cid));
$result = $query->result();
return $result;
}
public function getAllUser($type)
{
$this->load->database();
$this->db->where("db_usertype",$type);
$query = $this->db->get('baris_userlogin');
$result = $query->result();
return $result;
}
public function getDataById($tablename,$field,$id)
{
$this->load->database();
$query = $this->db->get_where($tablename, array($field=>$id));
$result = $query->result();
return $result;
}
public function getAllOrganizationByUserId($usertype,$userid)
{
$this->load->database();
if ($usertype == 'owner')
{
$query = $this->db->get_where("beatle_organization" , array("db_ownerId"=>$userid));
$result = $query->result();
return $result;
}
else if ($usertype == 'manager')
{
$this->db->select("*");
$this->db->from("beatle_branch");
$this->db->join("beatle_organization","beatle_organization.OrgId = beatle_branch.db_branchOrg");
$this->db->where("beatle_branch.db_branchManager" , $userid);
$query = $this->db->get();
$result = $query->result();
return $result;
}
else if ($usertype == 'line_manager')
{
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch","beatle_industry.db_bracnchid = beatle_branch.branchId" , 'left');
$this->db->join("beatle_organization","beatle_branch.db_branchOrg = beatle_organization.OrgId", 'left');
$this->db->where("beatle_industry.db_userid" , $userid);
$query = $this->db->get();
$result = $query->result();
return $result;
}
}
public function getAjaxOrgByName($Orgname)
{
$this->load->database();
$query = $this->db->select("*")->from("beatle_organization")->like("db_Orgname",$Orgname,'both')->get();
$result = $query->result();
return $result;
}
public function getIndByUserid($Uid)
{
$this->load->database();
$data = $this->db->get_where("beatle_industry" , array("db_userid"=>$Uid));
$result = $data->result();
return $result;
}
public function getAjaxBranchByName($Orgname)
{
$this->load->database();
$query = $this->db->select("*")->from("beatle_branch")->like("db_branchName",$Orgname,'both')->get();
$result = $query->result();
return $result;
}
public function getAjaxBranchByType($Orgname)
{
$this->load->database();
$query = $this->db->distinct("db_branch_type")->select("db_branch_type")->from("beatle_branch")->like("db_branch_type",$Orgname,'both')->get();
$result = $query->result();
return $result;
}
public function checkAjaxloginUserName($username,$uid)
{
$this->load->database();
$query = $this->db->get_where("beatle_userlogin", array("db_userLoginName"=>$username,"userId != " => $uid));
//$query = $this->db->where("beatle_userlogin", array("userId != ".$uid));
$result = $query->result();
return $result;
}
public function getAjaxIndByName($Orgname)
{
$this->load->database();
$query = $this->db->select("*")->from("beatle_industry")->like("db_industry",$Orgname,'both')->get();
$result = $query->result();
return $result;
}
public function getAllUsersMangerByOrgId($orgId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_branch");
$this->db->join("beatle_userlogin","beatle_branch.db_branchManager = beatle_userlogin.userId");
$this->db->where("beatle_branch.db_branchOrg",$orgId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllUsersLimeByOrgId($orgId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch","beatle_industry.db_bracnchid = beatle_branch.branchId" , 'left');
$this->db->join("beatle_userlogin","beatle_industry.db_userid = beatle_userlogin.userId" , 'left');
$this->db->where("beatle_branch.db_branchOrg",$orgId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllUsersownerByOrgId($orgId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_organization");
$this->db->join("beatle_userlogin","beatle_organization.db_ownerId = beatle_userlogin.userId" , 'left');
$this->db->where("beatle_organization.OrgId",$orgId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function fetch_all_ind_type_data($typeid = 0){
$this->load->database();
if(empty($typeid) || $typeid == 0)
$query = $this->db->get('beatle_industry_type');
else
$query = $this->db->get_where('beatle_industry_type',array('indtypeid'=>$typeid));
$data = $query->result();
return $data;
}
public function admin_userlogin($username,$password)
{
$pass = md5($password);
$this->load->database();
$this->db->where("db_userLoginName",$username);
//$this->db->or_where("db_email",$username);
//$this->db->or_where("db_phone",$username);
$this->db->where("db_password",$pass);
$this->db->where("db_usertype","SU_admin");
$query = $this->db->get('baris_userlogin');
//$query = $this->db->get_where('beatle_userlogin' , array('db_username'=>$username , 'db_password'=>$pass));
$data = $query->result();
return $data;
}
public function fetchAllSurveyData($dataArr){
$this->load->database();
$SQL = "SELECT
beatle_survey.surveyId,
beatle_survey.db_surveyBranchid,
beatle_survey.db_surveyUserid,
beatle_survey.db_surveyIndId,
beatle_survey.db_surveyPageid,
beatle_survey.db_surveyContentId,
beatle_survey.db_surveyValue,
beatle_survey.created_date,
beatle_survey.updated_date,
beatle_survey.tokenid,
beatle_survey.orgid,
beatle_survey.is_submit,
beatle_userlogin.db_phone,
beatle_userlogin.db_userLoginName,
beatle_userlogin.db_username,
beatle_userlogin.userId,
beatle_branch.db_branchName,
beatle_industry.db_industry,
beatle_organization.db_Orgname
FROM
beatle_survey
INNER JOIN beatle_userlogin ON beatle_survey.db_surveyUserid = beatle_userlogin.userId
INNER JOIN beatle_branch ON beatle_survey.db_surveyBranchid = beatle_branch.branchId
INNER JOIN beatle_industry ON beatle_survey.db_surveyIndId = beatle_industry.IndId
INNER JOIN beatle_organization ON beatle_survey.orgid = beatle_organization.OrgId
WHERE beatle_survey.is_submit = 'Y' ";
/*if(!empty($this->FromDate) && !empty($this->ToDate)){
$SQL .= " AND beatle_survey.created_date BETWEEN '".date("Y-m-d",strtotime($this->FromDate))." 00:00:00' AND '".date("Y-m-d",strtotime($this->ToDate))." 23:59:59' ";
}
*/
if(isset($dataArr['orgid']) && !empty($dataArr['orgid']) && $dataArr['orgid'] != 0)
$SQL .= " AND beatle_survey.orgid = ".$dataArr['orgid']." " ;
if(isset($dataArr['branchid']) && !empty($dataArr['branchid']) && $dataArr['branchid'] != 0)
$SQL .= " AND beatle_survey.db_surveyBranchid = ".$dataArr['branchid']." " ;
if(isset($dataArr['indid']) && !empty($dataArr['indid']) && $dataArr['indid'] != 0)
$SQL .= " AND beatle_survey.db_surveyIndId = ".$dataArr['indid']." " ;
if(isset($dataArr['tokenid']) && !empty($dataArr['tokenid']) && $dataArr['tokenid'] != 0)
$SQL .= " AND beatle_survey.tokenid = '".$dataArr['tokenid']."' " ;
$SQL .= " GROUP BY beatle_survey.tokenid ORDER BY beatle_survey.created_date DESC";
//echo $SQL;
$query = $this->db->query($SQL);
return $result = $query->result();
}
public function getuserdata($ida)
{
$this->load->database();
//echo $ida;
//echo "<br />";
$query = $this->db->get_where('baris_userlogin',array('userId'=>$ida));
$data = $query->result();
return $data;
}
public function getreporttypedata($id="")
{
$this->load->database();
if(!empty($id))
$this->db->where("id",$id);
$query = $this->db->get('baris_report_type');
$data = $query->result();
return $data;
}
public function getshiftdata($ida)
{
$this->load->database();
$query = $this->db->get_where('beatle_shift',array('userId'=>$ida));
$data = $query->result();
return $data;
}
public function fetchCustomerAppMenu(){
$menu_cnt = 0;
?>
<!--<div class="manu-icon"> -->
<ul id="1">
<li <?php if(CA_HOME_MENU != 'checked') { echo 'style="display:none;"'; $menu_cnt++; } ?> class="active"><a href="<?php echo base_url();?>index.php/customer/search_home"><img src="<?php echo base_url();?>assets/customer/img/home.png"><P>Home</P></a></li>
<li <?php if(CA_PRODUCT_MENU != 'checked') { echo 'style="display:none;"'; $menu_cnt++; }?>><a href="<?php echo base_url();?>index.php/customer/product_list"><img src="<?php echo base_url();?>assets/customer/img/product.png"><P>Product</P></a></li>
<li <?php if(CA_OFFERS_MENU != 'checked') { echo 'style="display:none;"'; $menu_cnt++; }?>><a href="<?php echo base_url();?>index.php/customer/offers"><img src="<?php echo base_url();?>assets/customer/img/offer.png"><P>Offers</P></a></li>
<li <?php if(CA_POINT_MENU != 'checked') { echo 'style="display:none;"'; $menu_cnt++; } ?>><a href="<?php echo base_url();?>index.php/customer/bonus_point"><img src="<?php echo base_url();?>assets/customer/img/my-bonuss-point.png"><P>Point</P></a></li>
<li <?php if(CA_ORDER_MENU != 'checked') { echo 'style="display:none;"'; $menu_cnt++; }?>><a href="<?php echo base_url();?>index.php/customer/order"><img src="<?php echo base_url();?>assets/customer/img/order.png"><P>Order</P></a></li>
<li <?php if($menu_cnt == 0 || CA_PROFILE_MENU != 'checked') { echo 'style="display:none;"';}?>><a href="<?php echo base_url();?>index.php/customer/profile"><img src="<?php echo base_url();?>assets/customer/img/profile.png"><P>Profile</P></a></li>
<li <?php if($menu_cnt == 1 || $menu_cnt == 0 || CA_CHANGE_PASS_MENU != 'checked') { echo 'style="display:none;"';}?>><a href="<?php echo base_url();?>index.php/customer/change_password"><img src="<?php echo base_url();?>assets/customer/img/change-password.png"><P>C. Pass</P></a></li>
<li <?php if($menu_cnt == 1 || $menu_cnt == 0 || $menu_cnt == 2) { echo 'style="display:none;"';}?>><a href="<?php echo base_url();?>index.php/customer/logout"><img src="<?php echo base_url();?>assets/customer/img/Logout.png"><P> Logout </P></a></li>
<?php
if($menu_cnt == 0 || $menu_cnt == 1 || $menu_cnt == 2) {
?>
<li class="other"style="cursor:pointer; <?php ?>" onclick="javascript: return openNav()">
<a onclick="javascript: return openNav()" href="#"> <img src="<?php echo base_url();?>assets/customer/img/more.png">
<P>Other</P> </a> </li>
<?php } ?>
<?php
//echo $menu_cnt;
?>
<div id="mySidenav" class="sidenav" style="display:none;">
<a href="#" class="closebtn" onclick="javascript: closeNav()">×</a>
<ul class="right-slider-manu">
<li <?php if(CA_HOME_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/search_home"><img src="<?php echo base_url();?>assets/customer/img/home.png"><P>Home</P></a></li>
<li <?php if(CA_PRODUCT_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/product_list"><img src="<?php echo base_url();?>assets/customer/img/product.png"><P>Product</P></a></li>
<li <?php if(CA_OFFERS_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/offers"><img src="<?php echo base_url();?>assets/customer/img/offer.png"><P>Offers</P></a></li>
<li <?php if(CA_POINT_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/bonus_point"><img src="<?php echo base_url();?>assets/customer/img/my-bonuss-point.png"><P>My Bonus Point</P></a></li>
<li <?php if(CA_PROFILE_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/profile"><img src="<?php echo base_url();?>assets/customer/img/profile.png"><P>My Profile</P></a></li>
<li <?php if(CA_ORDER_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/order"><img src="<?php echo base_url();?>assets/customer/img/order.png"><P>My Order</P></a></li>
<li <?php if(CA_CHANGE_PASS_MENU != 'checked') { echo 'style="display:none;"'; } ?>><a href="<?php echo base_url();?>index.php/customer/change_password"><img src="<?php echo base_url();?>assets/customer/img/change-password.png"><P> Change Password </P></a></li>
<li><a href="<?php echo base_url();?>index.php/customer/logout"><img src="<?php echo base_url();?>assets/customer/img/Logout.png"><P> Logout </P></a></li>
</ul>
</div>
</ul>
<!--</div> -->
<?php
}
public function getAllProductsData($prodid)
{
$this->load->database();
if(empty($prodid))
$query = $this->db->get('beatle_products');
else {
$this->db->select("*");
$this->db->from("beatle_products");
$this->db->where("productid",$prodid);
$query = $this->db->get();
}
$data = $query->result();
return $data;
}
public function getAllOffersData($prodid)
{
$this->load->database();
if(empty($prodid))
{
$this->db->select("*");
$this->db->from("beatle_offers");
$this->db->order_by("offeruid","DESC");
$query = $this->db->get();
}
else {
$this->db->select("*");
$this->db->from("beatle_offers");
$this->db->where("offerid",$prodid);
$query = $this->db->get();
}
$data = $query->result();
return $data;
}
public function getAllRequestData($prodid)
{
$this->load->database();
if(empty($prodid))
$query = $this->db->get('beatle_offers_temp');
else if ($prodid == 'new'){
$this->db->select("*");
$this->db->from("beatle_offers_temp");
$this->db->where("accept",'new');
$query = $this->db->get();
}
else {
$this->db->select("*");
$this->db->from("beatle_offers_temp");
$this->db->where("offertempid",$prodid);
$query = $this->db->get();
}
$data = $query->result();
return $data;
}
public function getNewEmailPurchaseRequestByAdmin(){
$this->db->select("*");
$this->db->from("beatle_purchase");
$this->db->where("type",'email');
$this->db->where("status",'new');
$query = $this->db->get();
$data = $query->result();
return $data;
}
public function getAllNewsData($newsid)
{
$this->load->database();
if(empty($newsid))
$query = $this->db->get('beatle_news');
else {
$this->db->select("*");
$this->db->from("beatle_news");
$this->db->where("newsid",$newsid);
$query = $this->db->get();
}
$data = $query->result();
return $data;
}
public function getAllPurchaseData($purchaseid,$type,$status)
{
$this->load->database();
$this->db->select("*");
$this->db->from('beatle_purchase');
if(empty($purchaseid)) {
if(!empty($type))
$this->db->where("type",$type);
}
else {
$this->db->where("purchaseid",$purchaseid);
if(!empty($type))
$this->db->where("type",$type);
}
if(!empty($status) && $status == 'new')
$this->db->where("status",'new');
$this->db->order_by('purchaseid','asc');
$query = $this->db->get();
$data = $query->result();
return $data;
}
public function getAllOrdersData($orderid)
{
$this->load->database();
if(empty($orderid)) {
$this->db->select("*");
$this->db->from("beatle_order");
$this->db->order_by('created_date','desc');
$query = $this->db->get();
}
else {
$this->db->select("*");
$this->db->from("beatle_order");
$this->db->where("orderid",$orderid);
$query = $this->db->get();
}
$data = $query->result();
//echo "<pre>";
//print_r($data);
//echo "</pre>";
return $data;
}
public function getAllUserOwner()
{
$this->load->database();
$query = $this->db->get_where('beatle_userlogin',array("db_usertype"=>'owner'));
$data = $query->result();
return $data;
}
public function getAllUserManager()
{
$this->load->database();
$query = $this->db->get_where('beatle_userlogin',array("db_usertype"=>'manager'));
$data = $query->result();
return $data;
}
public function getAllUserLinemanage()
{
$this->load->database();
$query = $this->db->get_where('beatle_userlogin',array("db_usertype"=>'line_manager'));
$data = $query->result();
return $data;
}
public function deleteUserById($UID)
{
$this->load->database();
$selectUser = $this->db->get_where("baris_userlogin" ,array('userId'=>$UID));
$result = $selectUser->result();
$query = $this->db->delete('baris_userlogin' , array('userId'=>$UID));
$usertype = $result[0]->db_usertype;
if ($query)
{
if ($usertype == 'owner')
{
$selectorg = $this->db->get_where('baris_organization' , array('db_ownerId'=>$UID));
$res = $selectorg->result();
$orgid = $res[0]->OrgID;
$selectBranch = $this->db->get_where('baris_division' , array('OrgID'=>$orgid));
$res1 = $selectBranch->result();
$braId = $res1[0]->DivisionId;
$queryOrg = $this->db->delete('baris_organization' , array('db_ownerId'=>$UID));
$queryOrg = $this->db->delete('baris_division' , array('OrgID'=>$orgid));
$queryOrg = $this->db->delete('baris_station' , array('DivisionId'=>$braId));
}
// if ($usertype == 'manager')
// {
// $selectorg = $this->db->get_where('beatle_branch' , array('db_branchManager'=>$UID));
// $res = $selectorg->result();
// $orgid = $res[0]->OrgId;
// $queryOrg = $this->db->delete('beatle_branch' , array('db_branchManager'=>$UID));
// $queryOrg = $this->db->delete('beatle_industry' , array('db_bracnchid'=>$orgid));
// }
// if ($usertype == 'line_manager')
// {
// $queryOrg = $this->db->delete('beatle_industry' , array('db_userid'=>$UID));
// }
}
}
public function deleteReportTypeById($id)
{
$this->load->database();
$query = $this->db->delete('baris_report_type' , array('id'=>$id));
}
public function deleteNewsById($UID)
{
$this->load->database();
$queryNews = $this->db->delete('beatle_news' , array('newsid'=>$UID));
}
public function deletePurchaseById($UID)
{
$this->load->database();
$queryPurchase = $this->db->delete('beatle_purchase' , array('purchaseid'=>$UID));
}
public function deleteBranchById($UID)
{
$selectbranch = $this->db->get_where("beatle_branch" ,array('branchId'=>$UID));
$result = $selectbranch->result();
$braid = $result[0]->branchId;
$this->load->database();
$query = $this->db->delete('beatle_branch' , array('branchId'=>$UID));
if ($query)
{
$queryOrg = $this->db->delete('beatle_industry' , array('db_bracnchid'=>$braid));
}
//echo '1';
}
public function deleteIndById($UID)
{
$this->load->database();
$query = $this->db->delete('beatle_industry' , array('IndId'=>$UID));
echo '1';
}
public function deleteOrgById($UID)
{
$this->load->database();
$selectorg = $this->db->get_where('beatle_organization' , array('OrgId'=>$UID));
$res = $selectorg->result();
$orgid = $res[0]->OrgId;
$query = $this->db->delete('beatle_organization' , array('OrgId'=>$UID));
if ($query)
{
$selectBranch = $this->db->get_where('beatle_branch' , array('db_branchOrg'=>$orgid));
$res1 = $selectBranch->result();
$braId = $res1[0]->branchId;
$queryOrg = $this->db->delete('beatle_branch' , array('db_branchOrg'=>$orgid));
if ($queryOrg)
{
$queryOrg = $this->db->delete('beatle_industry' , array('db_bracnchid'=>$braId));
}
}
}
public function editReportTypeById($id,$type){
$this->load->database();
return $query = $this->db->where('id',$id)->update('baris_report_type',array("type"=>$type));
}
public function addProductData($insertProduct){
$this->load->database();
$products = $this->db->get_where('beatle_products' , array('name'=>$insertProduct['name']));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return '0';
exit;
}
if(!empty($_FILES['productImage']['name'])){
$imgExt = pathinfo($_FILES['productImage']['name'],PATHINFO_EXTENSION);
$extArr = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','gif');
if(!in_array($imgExt,$extArr)){
// Please select proper image format for product image
return 1;
exit;
}
$imageName = date('YmdHis').'_'.rand(999999999,100000000).'.'.$imgExt;
$dirfile = "assets/products/".$imageName;
if(move_uploaded_file($_FILES['productImage']['tmp_name'],$dirfile)){
$insertProduct['prod_image'] = $imageName;
}
}
$Insertquery = $this->db->insert('beatle_products',$insertProduct);
return 1;
exit;
}
public function addOfferData($insertProduct,$bannerlink = ""){
$this->load->database();
$products = $this->db->get_where('beatle_offers' , array('title'=>$insertProduct['title']));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return 'title_taken';
exit;
}
if(!empty($_FILES['productImage']['name'])){
$imgExt = pathinfo($_FILES['productImage']['name'],PATHINFO_EXTENSION);
$extArr = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','gif');
$sizeArr = getimagesize($_FILES['productImage']['tmp_name']);
//print_r($sizeArr);
$width_tmp = $sizeArr[0];
$height_tmp = $sizeArr[1];
if(!in_array($imgExt,$extArr)){
// Please select proper image format for product image
///echo 'img_ext_error';
return 'img_ext_error';
exit;
}
if($width_tmp < 1000 || $width_tmp > 1200){
//echo 'img_size_error';
return 'img_size_error';
exit;
}
if($height_tmp < 400 || $height_tmp > 500){
//echo 'img_size_error';
return 'img_size_error';
exit;
}
$imageName = date('YmdHis').'_'.rand(999999999,100000000).'.'.$imgExt;
$dirfile = "assets/offers/".$imageName;
if(move_uploaded_file($_FILES['productImage']['tmp_name'],$dirfile)){
$insertProduct['offer_image'] = $imageName;
}
}else if($bannerlink != ""){
$imgArr = array();
$imgArr = explode("/",$bannerlink);
$imageName = $imgArr[count($imgArr)-1];
$dirfile = "assets/offers/".$imageName;
if(copy($bannerlink,$dirfile)){
$insertProduct['offer_image'] = $imageName;
}else{
return 'img_not_copied';
exit;
}
}
$this->db->insert('beatle_offers',$insertProduct);
$id = $this->db->insert_id();
$uid = str_pad($id, 5, "0", STR_PAD_LEFT); //00002
$this->db->where('offerid',$id)->update('beatle_offers',array('offeruid'=>$uid));
return 'success';
exit;
}
public function changeStatusOfferTemprData($status,$tempofferid){
$this->load->database();
return $query = $this->db->where('offertempid',$tempofferid)->update('beatle_offers_temp',array("accept"=>$status));
}
public function addIndTypeData($insertArr){
$this->load->database();
$products = $this->db->get_where('beatle_industry_type' , array('name'=>$insertArr['name']));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return 'title_taken';
exit;
}
$this->db->insert('beatle_industry_type',$insertArr);
return 'success';
exit;
}
public function editIndTypeData($insertArr,$typeid){
$this->load->database();
$products = $this->db->get_where('beatle_industry_type' , array('name'=>$insertArr['name'],'indtypeid != '=>$typeid));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return '0';
exit;
}
$query = $this->db->where('indtypeid',$typeid)->update('beatle_industry_type',$insertArr);
}
public function addNewsData($insertProduct){
$this->load->database();
$products = $this->db->get_where('beatle_news' , array('title'=>$insertProduct['title']));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return 'title_taken';
exit;
}
$this->db->insert('beatle_news',$insertProduct);
return 'success';
exit;
}
public function editProductData($insertProduct,$prodID){
$this->load->database();
$products = $this->db->get_where('beatle_products' , array('name'=>$insertProduct['name'],'productid != '=>$prodID));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return '0';
exit;
}
if(!empty($_FILES['productImage']['name'])){
$imgExt = pathinfo($_FILES['productImage']['name'],PATHINFO_EXTENSION);
$extArr = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','gif');
if(!in_array($imgExt,$extArr)){
// Please select proper image format for product image
return 1;
exit;
}
$imageName = date('YmdHis').'_'.rand(999999999,100000000).'.'.$imgExt;
$dirfile = "assets/products/".$imageName;
if(move_uploaded_file($_FILES['productImage']['tmp_name'],$dirfile)){
$insertProduct['prod_image'] = $imageName;
$products = $this->db->get_where('beatle_products' , array('productid'=>$prodID));
$productCount = $products->result();
if(!empty($productCount[0]->prod_image)){
$dirfile = base_url()."assets/products/".$productCount[0]->prod_image;
@chmod($dirfile, 0644);
@unlink($dirfile);
}
}
}
//$Insertquery = $this->db->insert('beatle_products',$insertProduct);
$query = $this->db->where('productid',$prodID)->update('beatle_products',$insertProduct);
}
public function editStatusOfferData($insertProduct,$prodID){
$this->load->database();
return $query = $this->db->where('offerid',$prodID)->update('beatle_offers',$insertProduct);
}
public function editStatusNewsData($statusArr,$newsid){
$this->load->database();
return $query = $this->db->where('newsid',$newsid)->update('beatle_news',$statusArr);
}
public function editStatusOnholdData($insertProduct,$prodID){
$this->load->database();
return $query = $this->db->where('offerid',$prodID)->update('beatle_offers',$insertProduct);
}
public function editOfferData($insertProduct,$prodID){
$this->load->database();
$products = $this->db->get_where('beatle_offers' , array('title'=>$insertProduct['title'],'offerid != '=>$prodID));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return '0';
exit;
}
/*
if(!empty($_FILES['productImage']['name'])){
$imgExt = pathinfo($_FILES['productImage']['name'],PATHINFO_EXTENSION);
$extArr = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','gif');
if(!in_array($imgExt,$extArr)){
// Please select proper image format for product image
return 1;
exit;
}
$imageName = date('YmdHis').'_'.rand(999999999,100000000).'.'.$imgExt;
$dirfile = "assets/offers/".$imageName;
if(move_uploaded_file($_FILES['productImage']['tmp_name'],$dirfile)){
$insertProduct['offer_image'] = $imageName;
$products = $this->db->get_where('beatle_offers' , array('offerid'=>$prodID));
$productCount = $products->result();
if(!empty($productCount[0]->offer_image)){
$dirfile = base_url()."assets/offers/".$productCount[0]->offer_image;
@chmod($dirfile, 0644);
@unlink($dirfile);
}
}
} */
if(!empty($_FILES['productImage']['name'])){
$imgExt = pathinfo($_FILES['productImage']['name'],PATHINFO_EXTENSION);
$extArr = array('jpg','JPG','jpeg','JPEG','png','PNG','gif','GIF','gif');
$sizeArr = getimagesize($_FILES['productImage']['tmp_name']);
//print_r($sizeArr);
$width_tmp = $sizeArr[0];
$height_tmp = $sizeArr[1];
if(!in_array($imgExt,$extArr)){
// Please select proper image format for product image
///echo 'img_ext_error';
return 'img_ext_error';
exit;
}
if($width_tmp < 1000 || $width_tmp > 1200){
//echo 'img_size_error';
return 'img_size_error';
exit;
}
if($height_tmp < 400 || $height_tmp > 500){
//echo 'img_size_error';
return 'img_size_error';
exit;
}
$imageName = date('YmdHis').'_'.rand(999999999,100000000).'.'.$imgExt;
$dirfile = "assets/offers/".$imageName;
if(move_uploaded_file($_FILES['productImage']['tmp_name'],$dirfile)){
$insertProduct['offer_image'] = $imageName;
$products = $this->db->get_where('beatle_offers' , array('offerid'=>$prodID));
$productCount = $products->result();
if(!empty($productCount[0]->offer_image)){
$dirfile = base_url()."assets/offers/".$productCount[0]->offer_image;
@chmod($dirfile, 0644);
@unlink($dirfile);
}
}
}
//$Insertquery = $this->db->insert('beatle_products',$insertProduct);
$query = $this->db->where('offerid',$prodID)->update('beatle_offers',$insertProduct);
}
public function editNewsData($insertProduct,$newsid){
$this->load->database();
$products = $this->db->get_where('beatle_news' , array('title'=>$insertProduct['title'],'newsid != '=>$newsid));
$productCount = $products->result();
if(count($productCount) > 0){
// Product allready taken, please try again with different name!
return '0';
exit;
}
$query = $this->db->where('newsid',$newsid)->update('beatle_news',$insertProduct);
}
public function editPurchaseData($insertProduct,$purid){
$this->load->database();
$this->db->where('purchaseid',$purid)->update('beatle_purchase',$insertProduct);
return 'success';
}
public function newInsertPurchaseData($insertPurchase){
$this->load->database();
$this->db->insert('beatle_manage_points',$insertPurchase);
}
public function fetchPurchaseDataOrgWise($orgid){
$this->load->database();
$this->db->select('*');
$this->db->from("beatle_manage_points");
$this->db->where("orgid",$orgid);
$this->db->order_by("id","desc");
$this->db->limit(1);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function editOrderData($insertProduct,$prodID){
$this->load->database();
$query = $this->db->where('orderid',$prodID)->update('beatle_order',$insertProduct);
}
public function InsertUser($insertedData,$email,$addOrgname,$addDivisionname,$addStationname,$addZonename,$loginId,$usergroup)
{//echo $addOrgname.' ' .$addBranchname.' '.$lastOrgId;die;
//print_r($insertedData);die;
//echo $insertedData['db_username'];die();
$this->load->database();
$checkEmail = $this->db->get_where('beatle_userlogin',array('db_email'=>$email));
$checkEmailData = $checkEmail->result();
// if (empty($checkEmailData))
// {
$Insertquery = $this->db->insert('baris_userlogin',$insertedData);
$lastUserId = $this->db->insert_id();
if ($Insertquery)
{
if (!empty($addOrgname))
{
if ($usergroup == 'owner')
{
$lastinsertId = $lastUserId;
}
else
{
$lastinsertId = '';
}
$selectOrg = $this->db->get_where('baris_organization', array('db_Orgname'=>$addOrgname));
$result = $selectOrg->result();
//if (empty($result))
//{
$date = date ('Y-m-d H:i:s');
$insertOrgData = array
(
'db_Orgname' => $addOrgname,
'db_userById' => $loginId,
'db_ownerId' => $lastinsertId,
'created_date' => $date
);
$insertOrg = $this->db->insert("baris_organization" , $insertOrgData);
$lastorg = $this->db->insert_id();
$editArr = array("OrgID"=>$lastorg);
$query = $this->db->where('userId',$lastUserId)->update('baris_userlogin',$editArr);
//return '1';
//}
// else
// {
// // $lastorg = $lastOrgId;
// $lastorg = $result[0]->OrgID;
// $editArr = array("OrgID"=>$lastorg);
// $query = $this->db->where('userId',$lastUserId)->update('baris_userlogin',$editArr);
// }
if (!empty($addOrgname) && !empty($addDivisionname) )
{
$selectOrg = $this->db->get_where('baris_division', array('DivisionName'=>$addDivisionname));
$result = $selectOrg->result();
// if (empty($result))
// {
$date = date ('Y-m-d H:i:s');
$insertBraData = array
(
'DivisionName' => $addDivisionname,
'userById' => $loginId,
'OrgID' => $lastorg,
'created_date' => $date
);
$insertBranch = $this->db->insert("baris_division" , $insertBraData);
$lastinsertIdBr = $this->db->insert_id() ;
// $editArr = array("OrgID"=>$lastorg,"BranchID"=>$lastinsertIdBr,"IndustryID"=>$IndustryID);
$editArr = array("DivisionId"=>$lastinsertIdBr);
$query = $this->db->where('userId',$lastUserId)->update('baris_userlogin',$editArr);
//return '1';
// }else{
// // $editArr = array("OrgID"=>$lastorg,"BranchID"=>$lastinsertIdBr,"IndustryID"=>$IndustryID);
// $editArr = array("DivisionId"=>$result[0]->DivisionId);
// $query = $this->db->where('userId',$lastUserId)->update('baris_userlogin',$editArr);
// }
}
if (!empty($addOrgname) && !empty($addDivisionname) && !empty($addStationname))
{
$selectOrg = $this->db->get_where('baris_station', array('stationName'=>$addStationname));
$result = $selectOrg->result();
// if (!empty($result))
// {
// $IndunqId = $result[0]->stationId;
// }
// else
// {
$Induniq = rand(1,1000);
$IndunqId = 'STA_'.$lastinsertIdBr.'_'.$Induniq;
// }
$Induniqlogin = rand(1,1000);
$IndunqIdlogin = 'STA_'.$lastinsertIdBr.'_'.$Induniqlogin;
$date = date ('Y-m-d H:i:s');
$status = '1';
$insertBraData = array
(
'stationName' => $addStationname,
'zoneName' => $addZonename,
'db_stLoginId' => $IndunqIdlogin,
'db_questionsId' => '11,12,13,14',
'OrgID' => $lastorg,
'DivisionId' => $lastinsertIdBr,
'created_date' => $date
);
$insertOrg = $this->db->insert("baris_station" , $insertBraData);
$IndustryID = $this->db->insert_id() ;
// $editArr = array("OrgID"=>$lastorg,"BranchID"=>$lastinsertIdBr,"IndustryID"=>$IndustryID);
$editArr = array("StationId"=>$IndustryID);
$query = $this->db->where('userId',$lastUserId)->update('baris_userlogin',$editArr);
//return '1';
//}
}
}
/*$SQL = "UPDATE beatle_userlogin SET
OrgID = ".$lastorg.",
BranchID = ".$lastinsertIdBr.",
IndustryID = ".$IndustryID." WHERE userId = ".$lastUserId;
$this->db->query($SQL);
*/
//return '1';
}
else
{
return '3';
}
// }
// else
// {
// return '4';
// }
}
public function editUserById($insertData,$editId)
{
$this->load->database();
$query = $this->db->where('userId',$editId)->update('baris_userlogin',$insertData);
// if(!empty($keywords))
// $query1 = $this->db->where('db_userid',$editId)->update('beatle_industry',$keywords);
if ($query)
{
// usres data updated successfully.
return 5;
}
}
public function editOrgById($insertData,$editId)
{
$this->load->database();
$query = $this->db->where('OrgID',$editId)->update('baris_organization',$insertData);
}
public function editDivisionById($insertData,$editId)
{
$this->load->database();
$query = $this->db->where('DivisionId',$editId)->update('baris_division',$insertData);
}
public function editStationById($insertData,$editId)
{
$this->load->database();
$query = $this->db->where('stationId',$editId)->update('baris_station',$insertData);
}
public function insertReportType($type)
{
$this->load->database();
$data['type'] = $type;
$data['created'] = date("Y-m-d H:i:s");
$query = $this->db->insert('baris_report_type',$data);
if ($query) return '1'; else return '2';
}
public function SearchUserByType($usertype)
{
$this->load->database();
if ($usertype == 'All')
{
$query = $this->db->get('beatle_userlogin');
}
else
{
$query = $this->db->get_where('beatle_userlogin',array('db_usertype'=>$usertype));
}
$data = $query->result();
return $data;
}
public function addOrganization($insertdata,$Orgname)
{
$this->load->database();
$selectQuery = $this->db->get_where('beatle_organization', array('db_Orgname'=>$Orgname));
$result = $selectQuery->result();
if (empty($result))
{
$query = $this->db->insert('beatle_organization',$insertdata);
if ($query)
{
return '1';
}
else{return '2';}
}
else
{
return '3';
}
}
public function getAllOrganization()
{
$this->load->database();
$this->db->select("*");
$this->db->from('beatle_organization');
$this->db->join('beatle_userlogin' , 'beatle_organization.db_ownerId = beatle_userlogin.userId','left');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllOrganizationtype()
{
$this->load->database();
$query = $this->db->get("beatle_organization");
$result = $query->result();
return $result;
}
public function getOrgByType($serachType)
{
$this->load->database();
$query = $this->db->get_where("beatle_organization",array ("db_orgtype"=>$serachType));
$result = $query->result();
return $result;
}
public function getBranchInfoById($id)
{
$this->db->select("*");
$this->db->from('beatle_branch');
$this->db->join('beatle_organization' , 'beatle_organization.OrgId = beatle_branch.db_branchOrg');
$this->db->where('beatle_branch.branchId',$id);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getOrganizationById($Orgid)
{
$this->load->database();
$query = $this->db->get_where('beatle_organization' , array('OrgId'=>$Orgid));
$result = $query->result();
return $result;
}
public function getBranchName($brnchID){
$this->load->database();
$query = $this->db->get_where('beatle_branch' , array('branchId'=>$brnchID));
$result = $query->result();
return $result;
}
public function getIndustryName($indid){
$this->load->database();
$query = $this->db->get_where('beatle_industry' , array('IndId'=>$indid));
$result = $query->result();
return $result;
}
public function UpdateOrganizationById($insertdata,$Orid)
{
$query = $this->db->where('OrgId',$Orid)->update('beatle_organization',$insertdata);
if ($query)
{
return 'updated';
}
}
public function UpdateReviewPageById($insertdata,$Orgid)
{
$query = $this->db->where(array("orgId"=>$Orgid,"type"=>'org'))->update('beatle_review',$insertdata);
}
public function addBranch($insertdata)
{
$query = $this->db->insert('beatle_branch',$insertdata);
if ($query)
{
echo 'yes';
}
else
{
echo 'No';
}
}
public function editBranch($insertdata,$bracId)
{
$query = $this->db->where('branchId',$bracId)->update('beatle_branch',$insertdata);
return '1';
}
public function getAllBranchByOrg($Orgid)
{
$this->db->select("*");
$this->db->from('beatle_branch');
$this->db->join('beatle_organization' , 'beatle_organization.OrgId = beatle_branch.db_branchOrg','left');
$this->db->join('beatle_userlogin' , 'beatle_userlogin.userId = beatle_branch.db_branchManager' , 'left');
$this->db->join('states' , 'states.id = beatle_branch.db_branchLocation' , 'left');
$this->db->where('beatle_branch.db_branchOrg',$Orgid);
$query = $this->db->get();
//echo $this->db->last_query();die;
//$query = $this->db->get_where('beatle_branch' , array('db_branchOrg'=>$Orgid));
$result = $query->result();
return $result;
}
public function getAllBranchByOrgnization()
{
$this->db->select("*");
$this->db->from('beatle_branch');
$this->db->join('beatle_organization' , 'beatle_organization.OrgId = beatle_branch.db_branchOrg','left');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getBranchByIndId($Orgid)
{
$this->db->select("*");
$this->db->from('beatle_industry');
$this->db->join('beatle_branch' , 'beatle_branch.branchId = beatle_industry.db_bracnchid','left');
$this->db->join('beatle_organization' , 'beatle_organization.OrgId = beatle_branch.db_branchOrg','right');
$this->db->join('beatle_userlogin' , 'beatle_userlogin.userId = beatle_branch.db_branchManager' , 'left');
$this->db->join('states' , 'states.id = beatle_branch.db_branchLocation' , 'left');
$this->db->where('beatle_industry.IndId', $Orgid);
$query = $this->db->get();
//$query = $this->db->get_where('beatle_branch' , array('db_branchOrg'=>$Orgid));
$result = $query->result();
return $result;
}
public function getBranchById($bracId)
{
$this->db->select("*");
$this->db->from("beatle_branch");
$this->db->join("beatle_userlogin" , 'beatle_userlogin.userId = beatle_branch.db_branchManager' , 'left');
$query = $this->db->where('beatle_branch.branchId',$bracId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllBranch()
{
$this->db->select("*");
$this->db->from('beatle_branch');
$this->db->join('beatle_organization' , 'beatle_organization.OrgId = beatle_branch.db_branchOrg','left');
$this->db->join('beatle_userlogin' , 'beatle_userlogin.userId = beatle_branch.db_branchManager' , 'left');
$this->db->join('states' , 'states.id = beatle_branch.db_branchLocation' , 'left');
$query = $this->db->get();
//echo $this->db->last_query();die;
//$query = $this->db->get('beatle_branch');
$result = $query->result();
return $result;
}
public function insertIndustry($insertdata)
{
$query = $this->db->insert('beatle_industry' , $insertdata);
return '1';
}
public function updateIndustry($insertdata,$InId)
{
$this->load->database();
$update = $this->db->where("IndId",$InId)->update('beatle_industry',$insertdata);
return '1';
}
public function updateReviewPageIndustry($insertdata,$InId)
{
$this->load->database();
$update = $this->db->where(array("indId"=>$InId,"type"=>'ind'))->update('beatle_review',$insertdata);
return '1';
}
public function getIndustryById($InId)
{
$query = $this->db->get_where('beatle_industry',array('IndId'=>$InId));
$result = $query->result();
return $result;
}
public function getUserPhoneNo($loginID,$tokenID)
{
$query = $this->db->get_where('beatle_userlogin',array("userId"=>$loginID));
$result = $query->result();
return $result;
}
public function setBonusPoints($loginID,$tokenID,$indId,$Orgid,$BranchID,$uType)
{
$this->load->database();
$objPointAmount = $this->db->get_where("appconfig" , array("ConfigName"=>"DEFAULT_BONUS_POINT_AMOUNT"));
$rsPoints = $objPointAmount->result();
$bonusPoint = $rsPoints[0]->ConfigValue;
$select = $this->db->get_where("beatle_points",array("tokenid"=>$tokenID,"UserID"=>$loginID,"UserID"=>$loginID));
$result = $select->result();
$inserdata = array();
$inserdata['UserID'] = $loginID;
$inserdata['OrgID'] = $Orgid;
$inserdata['BranchID'] = $BranchID;
$inserdata['IndustryID'] = $indId;
$inserdata['tokenid'] = $tokenID;
$inserdata['UserType'] = $uType;
$inserdata['Amount'] = $bonusPoint;
$inserdata['AddedDate'] = date("Y-m-d H:i:s");
$inserdata['IsRedeem'] = 'N';
if (empty($result))
{
$query = $this->db->insert('beatle_points' , $inserdata);
return '1';
}
else
{
return '2';
}
}
public function getAllIndustry()
{
$query = $this->db->get('beatle_industry');
$result = $query->result();
return $result;
}
public function getIndUsedTabsByUserid($Uid)
{
$this->load->database();
$this->db->select("db_numberTabs, COUNT(*) as tabscount");
$this->db->from("beatle_industry");
$this->db->group_by('db_numberTabs');
$this->db->where(array("db_userid"=>$Uid));
$query = $this->db->get();
$this->db->last_query();
$result = $query->result();
return $result;
}
public function getAllIndustryForGraph()
{
$this->load->database();
$this->db->select("created_date, COUNT(*) as Cdate");
$this->db->from("beatle_industry");
$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllIndustryForGraphByDate($date)
{
$this->load->database();
$this->db->select("COUNT(*) as Cdate");
$this->db->from("beatle_industry");
$this->db->where('created_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ');
//$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllOrganizationForGraph()
{
$this->load->database();
$this->db->select("created_date, COUNT(*) as Cdate");
$this->db->from("beatle_organization");
$this->db->where('created_date BETWEEN "'. date('Y-m-01'). '" and "'. date('Y-m-d').'"');
$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllOrganizationByDateWise($date)
{
$this->load->database();
$this->db->select("COUNT(*) as Cdate");
$this->db->from("beatle_organization");
$this->db->where('created_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ');
//$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllBranchForGraphByDateWise($date)
{
$this->load->database();
$this->db->select("COUNT(*) as Cdate");
$this->db->from("beatle_branch");
$this->db->where('Branchcreated_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ');
//$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllBranchForGraph()
{
$this->load->database();
$this->db->select("Branchcreated_date, COUNT(*) as Cdate");
$this->db->from("beatle_branch");
$this->db->group_by('Branchcreated_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllenduserForGraph()
{
$this->load->database();
$this->db->select("created_date, COUNT(*) as Cdate");
$this->db->from("beatle_userlogin");
$this->db->where(array("db_usertype"=>'End_user'));
$this->db->where(array("db_phone != "=>'Guest'));
$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllenduserForGraphByDateWise($date)
{
$this->load->database();
$this->db->select("COUNT(*) as Cdate");
$this->db->from("beatle_userlogin");
$this->db->where('created_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ');
$this->db->where(array("db_usertype"=>'End_user'));
$this->db->where(array("db_phone != "=>'Guest'));
//$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllTabForGraph()
{
$this->load->database();
$this->db->select("created_date, COUNT(*) as Cdate");
$this->db->from("beatle_industry");
$this->db->group_by('created_date');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllTabForGraphByDateWise($date)
{
$this->load->database();
$this->db->select("COUNT(*) as Cdate, SUM(db_numberTabs) AS totalTabs");
$this->db->from("beatle_industry");
$this->db->where('created_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ');
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAlltabs()
{
$this->load->database();
$query = $this->db->get("beatle_industry");
$result = $query->result();
return $result;
}
public function insertPage($inserdata,$page)
{
$this->load->database();
$select = $this->db->get_where("beatle_page" , array("db_pagename"=>$page));
$result = $select->result();
if (empty($result))
{
$query = $this->db->insert('beatle_page' , $inserdata);
return '1';
}
else
{
return '2';
}
}
public function UpdatePageById($inserdata,$pageid,$page)
{
$this->load->database();
$select = $this->db->get_where("beatle_page" , array("db_pagename"=>$page));
$result = $select->result();
if (empty($result))
{
$query = $this->db->where('pageId',$pageid)->update('beatle_page' ,$inserdata);
return '3';
}
else
{
return '2';
}
}
public function getallpage()
{
$query = $this->db->get('beatle_page');
$result = $query->result();
return $result;
}
public function getallpageByIndId($indId)
{
$query = $this->db->get_where('beatle_industry', array('IndId'=>$indId));
$result = $query->result();
$pagesCount = explode(',',$result[0]->db_pagesId);
if ($pagesCount[0] == '')
{
echo '0';
}
else
{
foreach ($pagesCount as $k=>$v)
{
$query = $this->db->get_where('beatle_page', array('pageId'=>$v));
$result1[] = $query->result();
} return $result1;
}
}
public function getPageById($pageid)
{
$query = $this->db->get_where('beatle_page', array('pageId'=>$pageid));
$result = $query->result();
return $result;
}
public function deletePageById($UID)
{
$this->load->database();
$query = $this->db->delete('beatle_page' , array('pageId'=>$UID));
if ($query)
{
$query = $this->db->delete('beatle_pagecontent',array('db_pageid'=>$UID));
}
$query = $this->db->select("*")->from("beatle_industry")->like("db_pagesId",$UID,'both')->get();
$result = $query->result();
return $result;
//echo '1';
}
public function deletePageContentById($UID){
$this->load->database();
$query = $this->db->delete('beatle_pagecontent',array('pageConId'=>$UID));
echo '1';
}
public function insertPageContent($inserdata,$page)
{
$this->load->database();
$select = $this->db->get_where("beatle_pagecontent" , array("db_pageConTitle" => $page));
$result = $select->result();
if (empty($result))
{
$query = $this->db->insert('beatle_pagecontent' , $inserdata);
if ($query)
{
return '1';
}
}
else
{
return '2';
}
}
public function getallPageContent()
{
$query = $this->db->get('beatle_pagecontent');
$result = $query->result();
return $result;
}
public function getPageConByPageId($pageId)
{
$this->load->database();
$query = $this->db->get_where('beatle_pagecontent' , array('db_pageid'=>$pageId));
$result = $query->result();
return $result;
}
public function getPageConByPageContentId($pagecId)
{
$this->load->database();
$query = $this->db->get_where('beatle_pagecontent' , array('pageConId'=>$pagecId));
$result = $query->result();
return $result;
}
public function pagesContentListById($conid)
{
$this->db->select("*");
$this->db->from("beatle_pagecontent");
$this->db->join("beatle_page" , "beatle_pagecontent.db_pageid = beatle_page.pageId");
$this->db->where('beatle_pagecontent.pageConId',$conid);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function pagesContentList($pageid)
{
$this->db->select("*");
$this->db->from("beatle_pagecontent");
$this->db->join("beatle_page" , "beatle_pagecontent.db_pageid = beatle_page.pageId");
$this->db->where('beatle_pagecontent.db_pageid',$pageid);
$query = $this->db->get();
$result = $query->result();
return $result;
}
//
public function getSavedResult($UserID,$pageID,$pageConId,$tokenID)
{
/*$this->db->select("*");
$rsArr = array("db_surveyUserid"=>$UserID,"db_surveyPageid"=>$pageID,"db_surveyContentId"=>$pageConId);
$query->db->get_where("beatle_survey",$rsArr);
$result = $query->result();
*/
$SQL = "SELECT db_surveyValue FROM beatle_survey WHERE db_surveyUserid = ".$UserID." AND db_surveyPageid = ".$pageID." AND db_surveyContentId = ".$pageConId." AND tokenid = '".$tokenID."' ";
//echo "<br />";
$query = $this->db->query($SQL);
return $result = $query->result();
}
//
public function getSavedResultOthers($UserID,$pageID,$pageConId,$tokenID)
{
$SQL = "SELECT db_surveyValue FROM beatle_survey WHERE db_surveyUserid = ".$UserID." AND db_surveyPageid = ".$pageID." AND db_surveyContentId = ".$pageConId." AND tokenid = '".$tokenID."' ";
$query = $this->db->query($SQL);
return $query->result();
}
public function fetchCountPages($str)
{
$SQL = "SELECT count(pageId) as totalContentPages FROM `beatle_page` WHERE beatle_page.pageId IN ".$str." ";
$query = $this->db->query($SQL);
$result = $query->result();
return $result;
}
public function fetchPageData($str)
{
$SQL = "SELECT * FROM beatle_page WHERE db_pagetype = 'Content' AND pageId IN (".$str.")";
$query = $this->db->query($SQL);
$result = $query->result();
return $result;
}
public function updatePageContent($inserdata,$pageid)
{
$query = $this->db->where('pageConId',$pageid)->update('beatle_pagecontent',$inserdata);
return '1';
}
public function insertsurvey($inserdata)
{
$query = $this->db->insert('beatle_survey',$inserdata);
if ($query)
{
echo 'yes';
}
else{ echo 'no';}
}
public function getallsurvey()
{
$query = $this->db->get('beatle_survey');
$result = $query->result();
return $result;
}
public function getSurveyById($sId)
{
$query = $this->db->get_where('beatle_survey', array('surveyId'=>$sId));
$result = $query->result();
return $result;
}
public function updatesurvey($inserdata,$sId)
{
$query = $this->db->where('surveyId',$sId)->update('beatle_survey',$inserdata);
if ($query)
{
echo 'yes';
}
}
public function deleteSurveyById($sId)
{
$this->load->database();
$query = $this->db->delete('beatle_survey' , array('surveyId'=>$UID));
if ($query)
{
echo '1';
}
}
public function addpagesToIndustry($mainIndId,$insertdata)
{
$this->load->database();
$query = $this->db->where('IndId',$mainIndId)->update('beatle_industry',$insertdata);
return $query;
}
// ======================= Organization Related Data ============================
public function getAllManagerByOrg($orgId)
{
$query = $this->db->get_where('beatle_branch' , array ("db_branchOrg"=>$orgId));
$result = $query->result();
return $result;
}
public function getAllUsersownerByBranchId($orgId)
{
$this->db->select("*");
$this->db->from("beatle_branch");
$this->db->join("beatle_industry" , "beatle_branch.branchId = beatle_industry.db_bracnchid",'left');
$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_industry.db_userid");
$this->db->where("beatle_branch.branchId",$orgId);
$query = $this->db->get();
//echo $this->db->last_query();die;
$result = $query->result();
return $result;
}
public function getBranchByInd($InId)
{
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch" , "beatle_branch.branchId = beatle_industry.db_bracnchid");
$this->db->where("beatle_industry.IndId" , $InId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllLineManByOrg($orgId)
{
$this->db->select("*");
$this->db->from("beatle_organization");
$this->db->join("beatle_branch","beatle_organization.OrgId = beatle_branch.db_branchOrg" , 'left');
$this->db->join("beatle_industry","beatle_branch.branchId = beatle_industry.db_bracnchid",'left');
$this->db->join("beatle_userlogin","beatle_industry.db_userid = beatle_userlogin.userId",'left');
$this->db->where("beatle_organization.OrgId",$orgId);
$query = $this->db->get();
//echo $this->db->last_query();die;
$result = $query->result();
return $result;
}
public function getAllLineManByOrganization()
{
$this->db->select("*");
$this->db->from("beatle_organization");
$this->db->join("beatle_branch","beatle_organization.OrgId = beatle_branch.db_branchOrg" , 'left');
$this->db->join("beatle_industry","beatle_branch.branchId = beatle_industry.db_bracnchid",'left');
$this->db->join("beatle_userlogin","beatle_industry.db_userid = beatle_userlogin.userId",'left');
$query = $this->db->get();
//echo $this->db->last_query();die;
$result = $query->result();
return $result;
}
public function getAllOwnerByOrgId($branchId)
{
/*$this->db->select("*");
$this->db->from("beatle_branch");
$this->db->join("beatle_organization" , 'beatle_organization.OrgId = beatle_branch.db_branchOrg' , 'left');
$this->db->join("beatle_userlogin" , 'beatle_userlogin.userId = beatle_organization.db_ownerId' , 'left');
$query = $this->db->where('beatle_branch.branchId',$branchname);
$query = $this->db->get();
$result = $query->result();
return $result; */
$this->db->select("*");
$this->db->from("beatle_branch");
$this->db->join("beatle_organization" , "beatle_organization.OrgId = beatle_branch.db_branchOrg",'left');
$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_organization.db_ownerId" , 'right');
$query = $this->db->where('beatle_branch.branchId',$branchId);
echo $this->db->last_query();die;
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getIndustryByBranchId($orgid)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch" , "beatle_branch.branchId = beatle_industry.db_bracnchid" , 'left');
$this->db->join("beatle_organization" , "beatle_organization.OrgId = beatle_branch.db_branchOrg");
$this->db->where("beatle_branch.db_branchOrg" , $orgid);
$query = $this->db->get();
$result = $query->result();
/* $query = $this->db->get_where("beatle_industry", array("db_bracnchid"=>$bracId));
$result = $query->result();
*/
return $result;
}
public function getAllOrgByIndustryId($indId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch" , "beatle_branch.branchId = beatle_industry.db_bracnchid" , 'left');
$this->db->join("beatle_organization" , "beatle_organization.OrgId = beatle_branch.db_branchOrg");
$this->db->where("beatle_industry.IndId" , $indId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllWholeIndIDS($indId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_industry.db_userid");
$this->db->where("beatle_industry.IndId" , $indId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function fetchPageIDDetails($PageID)
{
$SQL = "SELECT beatle_page.pageId AS PageID, beatle_page.db_pagename FROM beatle_page WHERE pageId IN (".$PageID.") AND LOWER(db_pagetype) = 'content'";
$query = $this->db->query($SQL);
return $rsSurveyData = $query->result();
}
public function fetchRatingCustomer($tokenid,$pageID){
$SQL = "SELECT ROUND(AVG(db_surveyValue),2) AS AvgValue FROM beatle_survey WHERE db_surveyPageid = ".$pageID." AND is_submit = 'Y'
AND created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59' AND tokenid = '".$tokenid."' ";
//echo $SQL;
//echo "<br />";
$query = $this->db->query($SQL);
$rsSurveyData = $query->result();
return $rsSurveyData[0]->AvgValue;
}
public function fetchLoginDataFrom($indId,$OrgID,$BranchID,$PageID)
{
$SQL = "SELECT GROUP_CONCAT(pageId) AS PageID FROM beatle_page WHERE pageId IN (".$PageID.") AND LOWER(db_pagetype) = 'content'";
$query = $this->db->query($SQL);
$rsPageData = $query->result();
$SQL = "SELECT beatle_survey.*,beatle_userlogin.userId,beatle_userlogin.db_phone FROM beatle_survey INNER JOIN beatle_userlogin ON
beatle_survey.db_surveyUserid = beatle_userlogin.userId
WHERE
beatle_survey.db_surveyIndId = ".$indId." AND
beatle_survey.orgid = ".$OrgID." AND
beatle_survey.db_surveyPageid IN (".$rsPageData[0]->PageID.") AND
beatle_survey.db_surveyBranchid = ".$BranchID." AND
beatle_survey.created_date BETWEEN '".date("Y-m-d")." 00:00:00' AND '".date("Y-m-d")." 23:59:59'
GROUP BY beatle_survey.tokenid ORDER BY beatle_survey.created_date ASC";
$query = $this->db->query($SQL);
return $rsSurveyData = $query->result();
}
public function getLinemanagerByIndustryId($indId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch" , "beatle_branch.branchId = beatle_industry.db_bracnchid" , 'left');
// OLD CODE IF ANY PROBLAME OCCURE THEN REMOVE COMMENT FROM BELOW
//$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_branch.db_branchManager");
$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_industry.db_userid");
$this->db->where("beatle_industry.IndId" , $indId);
$this->db->where("beatle_userlogin.db_usertype" , "line_manager");
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllUserByIndustryId($indId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_branch" , "beatle_branch.branchId = beatle_industry.db_bracnchid" , 'left');
// OLD CODE IF ANY PROBLAME OCCURE THEN REMOVE COMMENT FROM BELOW
$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_branch.db_branchManager");
//$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_industry.db_userid");
$this->db->where("beatle_industry.IndId" , $indId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getLineManagerByIndstry($indId)
{
$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_userlogin" , "beatle_userlogin.userId = beatle_industry.db_userid");
$this->db->where("beatle_industry.IndId" , $indId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getAllFeedback()
{
$this->load->database();
/*$this->db->select("*");
$this->db->from("beatle_industry");
$this->db->join("beatle_survey", "beatle_survey.db_surveyIndId=beatle_industry.IndId","left");
$query = $this->db->get();
*/
$SQL = "SELECT beatle_industry.IndId, beatle_industry.db_industry FROM beatle_survey INNER JOIN beatle_industry ON beatle_industry.IndId = beatle_survey.db_surveyIndId WHERE beatle_survey.is_submit = 'Y' GROUP BY beatle_survey.tokenid";
$query = $this->db->query($SQL);
//return array();
return $query->result();
}
public function getAllLowRating()
{
$this->load->database();
$SQLPAGE = "SELECT GROUP_CONCAT(pageId) AS PageID FROM beatle_page WHERE LOWER(db_pagetype) = 'content'";
//$SQL = "SELECT beatle_industry.IndId, beatle_industry.db_industry FROM beatle_survey INNER JOIN beatle_industry ON beatle_industry.IndId = beatle_survey.db_surveyIndId WHERE beatle_survey.is_submit = 'Y' GROUP BY beatle_survey.tokenid";
//$SQL_ = "SELECT AVG(db_surveyValue) AS AvgValue from beatle_survey WHERE db_surveyPageid IN (".$rsIndustry[$indst]['db_pagesId'].") AND db_surveyValue IN (1,2) AND is_submit = 'Y' ";
$SQL = "SELECT AVG(db_surveyValue) AS AvgValue from beatle_survey WHERE db_surveyPageid IN (".$SQLPAGE.") AND db_surveyValue IN (1,2) AND is_submit = 'Y' GROUP BY tokenid ";
$query = $this->db->query($SQL);
//return array();
return $query->result();
}
public function getAllTicket()
{
$this->load->database();
$SQL = "SELECT * from beatle_ticket where id != '0'";
$query = $this->db->query($SQL);
//return array();
return $query->result();
}
public function getAllFeedbackByDateWise($date="",$orgid = "",$branchid = "",$indid = "")
{
/*$this->load->database();
$this->db->select("COUNT(*) as Cdate");
$this->db->from("beatle_survey");
$this->db->where('created_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ');
*/
$SQL = 'SELECT COUNT(*) as Cdate FROM beatle_survey WHERE is_submit = "Y" '; //GROUP BY tokenid
if(!empty($date)){
$SQL .= ' AND created_date BETWEEN "'. date($date).' 00:00:00" AND "'. date($date). ' 23:59:59" ' ;
}
if(!empty($orgid) && $orgid != 0){
$SQL .= ' AND orgid = '.$orgid ;
}
if(!empty($branchid) && $branchid != 0){
$SQL .= ' AND db_surveyBranchid = '.$branchid ;
}
if(!empty($indid) && $indid != 0){
$SQL .= ' AND db_surveyIndId = '.$indid ;
}
$SQL .= ' GROUP BY tokenid';
$query = $this->db->query($SQL);
$rsdata = $query->result();
if(count($rsdata) > 0){
return count($rsdata);
}else{
return 0;
}
}
public function getLastTicketid(){
$this->load->database();
$this->db->select("id");
$this->db->from("beatle_ticket");
$this->db->where("parentid",0);
$this->db->order_by("ticketid","desc");
$this->db->limit(1);
$query = $this->db->get();
$result = $query->result();
return $result[0]->id + 1;
}
public function insertTicketData($insertTicketData){
$this->load->database();
$this->db->insert('beatle_ticket',$insertTicketData);
$id = $this->db->insert_id();
$uid = str_pad($insertTicketData['id'], 5, "0", STR_PAD_LEFT); //00002
$this->db->where('ticketid',$id)->update('beatle_ticket',array('ticketuid'=>$uid));
return array("1",$uid);
}
public function getAllDataForSurveyByUserId($loginuserId)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_userlogin");
$this->db->join("beatle_organization","beatle_userlogin.userId = beatle_organization.db_ownerId" , "left");
$this->db->join("beatle_branch","beatle_organization.OrgId = beatle_branch.db_branchOrg" , "right");
$this->db->where("beatle_userlogin.userId",$loginuserId);
$query = $this->db->get();
$result = $query->result();
return $result;
}
public function getSurveyByPageIndIdBranchId($checkIndId,$page,$branchid)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_survey");
$this->db->where(array("db_surveyIndId"=>$checkIndId));
$this->db->where(array("db_surveyPageid"=>$page));
$this->db->where(array("db_surveyBranchid"=>$branchid));
$query = $this->db->get();
//echo $this->db->last_query();
$result = $query->result();
return $result;
}
public function getSurveyByIndId($checkIndId,$branchid)
{
$this->load->database();
$this->db->select("*");
$this->db->from("beatle_survey");
$this->db->where("db_surveyIndId",$checkIndId);
$this->db->where_not_in("db_surveyBranchid",$branchid);
$query = $this->db->get();
//echo $this->db->last_query();
$result = $query->result();
return $result;
}
public function fetchOwnersImage($img,$height = "",$width = "",$imgStyle = ""){
if(@fopen(base_url().'/assets/OrganizationPics/'.$img,'r') && !empty($img)) { ?>
<img style=" <?php echo $imgStyle;?>" height="<?php echo $height;?>" width="<?php echo $width;?>" alt="<?php echo $img; ?>" src="<?php echo base_url();?>/assets/OrganizationPics/<?php echo $img; ?>" class="headerImg">
<?php }else{ ?>
<img style=" <?php echo $imgStyle;?>" height="<?php echo $height;?>" width="<?php echo $width;?>" alt="No image found" src="<?php echo base_url();?>/assets/OrganizationPics/no-image-found.png" class="headerImg">
<?php }
}
public function fetchProductsImage($img,$height = "",$width = "",$imgStyle = ""){
if(@fopen(base_url().'/assets/products/'.$img,'r') && !empty($img)) { ?>
<img style=" <?php echo $imgStyle;?>" height="<?php echo $height;?>" width="<?php echo $width;?>" alt="<?php echo $img; ?>" src="<?php echo base_url();?>/assets/products/<?php echo $img; ?>" class="headerImg">
<?php }else{ ?>
<img style=" <?php echo $imgStyle;?>" height="<?php echo $height;?>" width="<?php echo $width;?>" alt="No image found" src="<?php echo base_url();?>/assets/OrganizationPics/no-image-found.png" class="headerImg">
<?php }
}
public function fetchOfferImage($img,$height = "",$width = "",$imgStyle = ""){
if(@fopen(base_url().'/assets/offers/'.$img,'r') && !empty($img)) { ?>
<img style=" <?php echo $imgStyle;?>" height="<?php echo $height;?>" width="<?php echo $width;?>" alt="<?php echo $img; ?>" src="<?php echo base_url();?>/assets/offers/<?php echo $img; ?>" class="headerImg">
<?php }else{ ?>
<img style=" <?php echo $imgStyle;?>" height="<?php echo $height;?>" width="<?php echo $width;?>" alt="No image found" src="<?php echo base_url();?>/assets/OrganizationPics/no-image-found.png" class="headerImg">
<?php }
}
public function updateSetAsView(){
$this->load->database();
$query = $this->db->where('viewbyadmin','N')->update('beatle_order',array("viewbyadmin"=>'Y'));
}
public function getUnviewedOrderByAdmin()
{
$this->load->database();
$query = $this->db->get_where('beatle_order' , array('viewbyadmin'=>'N'));
$result = $query->result();
return $result;
}
public function getUnviewedOfferByAdmin()
{
$this->load->database();
$query = $this->db->get_where('beatle_offers_temp' , array('accept'=>'new'));
$result = $query->result();
return $result;
}
/*
public function AllCountry()
{
$this->load->database();
$query = $this->db->get('countries');
$data = $query->result();
return $data;
}
public function getStateAccCountry($counId)
{
$this->load->database();
$query = $this->db->get_where('states',array('country_id'=>$counId));
$data = $query->result();
if (!empty($data))
{
if (!empty($data))
{
foreach ($data as $keusta=>$valsta)
{
echo '<option value='.$valsta->id.'>'.$valsta->name.'</option>';
}
}
}
}
public function getCityAccState($stateId)
{
$this->load->database();
$query = $this->db->get_where('cities',array('state_id'=>$stateId));
$data = $query->result();
if (!empty($data))
{
if (!empty($data))
{
foreach ($data as $keusta=>$valsta)
{
echo '<option value='.$valsta->id.'>'.$valsta->name.'</option>';
}
}
}
}
public function deletePatientById($deleteId)
{
$this->load->database();
$this->db->where('patient_id',$deleteId);
$data = $this->db->delete('clinic_patient');
if ($data)
{
echo '1';
}
}
public function getUserById($editId)
{
$this->load->database();
$query = $this->db->get_where('clinic_patient',array('patient_id'=>$editId));
$data = $query->result();
return $data;
}
*/
}
?>