File: /home/barbeatleanalyti/public_html/m.beatleanalytics.com/application/models/New_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 getAllCity()
{
$this->load->database();
$query = $this->db->get('cities');
$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 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 checkAjaxloginUserName($username)
{
$this->load->database();
$query = $this->db->get_where("beatle_userlogin", array("db_userLoginName"=>$username));
$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" , 'left');
$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 admin_userlogin($username,$password)
{
$pass = md5($password);
$this->load->database();
$this->db->where("db_username",$username);
$this->db->or_where("db_email",$username);
$this->db->or_where("db_phone",$username);
$this->db->where("db_password",$pass);
$query = $this->db->get('beatle_userlogin');
//$query = $this->db->get_where('beatle_userlogin' , array('db_username'=>$username , 'db_password'=>$pass));
$data = $query->result();
return $data;
}
public function getuserdata($ida)
{
$this->load->database();
$query = $this->db->get_where('beatle_userlogin',array('userId'=>$ida));
$data = $query->result();
return $data;
}
public function getAllUser()
{
$this->load->database();
$query = $this->db->get('beatle_userlogin');
$data = $query->result();
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();
$query = $this->db->delete('beatle_userlogin' , array('userId'=>$UID));
//$data = $query->result();
echo '1';
}
public function deleteBranchById($UID)
{
$this->load->database();
$query = $this->db->delete('beatle_branch' , array('branchId'=>$UID));
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();
$query = $this->db->delete('beatle_organization' , array('OrgId'=>$UID));
if ($query)
{
$query1 = $this->db->delete('beatle_branch' , array('db_branchOrg'=>$UID));
}
echo '1';
}
public function InsertUser($insertedData,$email,$addOrgname,$addIndname,$addBranchname,$loginId,$lastOrgId,$mainBraId,$usergroup)
{//echo $addOrgname.' ' .$addBranchname.' '.$lastOrgId;die;
//print_r($insertedData);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('beatle_userlogin',$insertedData);
$lastUserId = $this->db->insert_id();
if ($Insertquery)
{
if (!empty($addOrgname))
{
if ($usergroup == 'owner')
{
$lastinsertId = $lastUserId;
}
else if ($usergroup == 'manager')
{
$lastinsertIdMa = $lastUserId;
}
else if ($usergroup == 'line_manager')
{
$lastinsertIdBr = $lastUserId;
}
else
{
$lastinsertIdBr = '';
$lastinsertIdMa = '';
$lastinsertId = '';
}
$selectOrg = $this->db->get_where('beatle_organization', array('db_Orgname'=>$addOrgname));
$result = $selectOrg->result();
if (empty($result))
{
$date = date ('Y-m-d H:i:s');
$status = '1';
$insertOrgData = array
(
'db_Orgname' => $addOrgname,
'db_userById' => $loginId,
'db_ownerId' => $lastinsertId,
'created_date' => $date,
'status' => $status
);
$insertOrg = $this->db->insert("beatle_organization" , $insertOrgData);
$lastorg = $this->db->insert_id();
}
else
{
$lastorg = $lastOrgId;
}
if (!empty($addOrgname) && !empty($addBranchname) )
{
$selectOrg = $this->db->get_where('beatle_branch', array('db_branchName'=>$addBranchname));
$result = $selectOrg->result();
if (empty($result))
{
$date = date ('Y-m-d H:i:s');
$status = '1';
$insertBraData = array
(
'db_branchName' => $addBranchname,
'db_branchAddedBy' => $loginId,
'db_branchManager' => $lastinsertIdMa,
'db_branchOrg' => $lastorg,
'Branchcreated_date' => $date,
'status' => $status
);
$insertBranch = $this->db->insert("beatle_branch" , $insertBraData);
$lastinsertIdBr = $this->db->insert_id() ;
}
}
if (!empty($addOrgname) && !empty($addBranchname) && !empty($addIndname))
{
$selectOrg = $this->db->get_where('beatle_industry', array('db_industry'=>$addBranchname));
$result = $selectOrg->result();
if (empty($result))
{
$date = date ('Y-m-d H:i:s');
$status = '1';
$insertBraData = array
(
'db_industry' => $addIndname,
'db_bracnchid' => $mainBraId,
'db_userid' => $lastinsertIdBr,
'db_addedBy' => $loginId,
'created_date' => $date,
'status' => $status
);
$insertOrg = $this->db->insert("beatle_industry" , $insertBraData);
}
}
}
//return 'yes';
}
else
{
return 'no';
}
}
else
{
return 'already';
}
}
public function editUserById($insertData,$editId)
{
$this->load->database();
$query = $this->db->where('userId',$editId)->update('beatle_userlogin',$insertData);
if ($query)
{
return 'updated';
}
}
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)
{
echo 'yes';
}
else{echo 'no';}
}
else
{
echo 'already';
}
}
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 UpdateOrganizationById($insertdata,$Orid)
{
$query = $this->db->where('OrgId',$Orid)->update('beatle_organization',$insertdata);
if ($query)
{
return 'updated';
}
}
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);
if ($query)
{
echo 'yes';
}
else
{
echo 'No';
}
}
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 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);
if ($query)
{
echo 'yes';
}
else{ echo 'no';}
}
public function updateIndustry($insertdata,$InId)
{
$query = $this->db->where('IndId',$InId)->update('beatle_industry' , $insertdata);
if ($query)
{
echo 'yes';
}
else{ echo 'no';}
}
public function getIndustryById($InId)
{
$query = $this->db->get_where('beatle_industry',array('IndId'=>$InId));
$result = $query->result();
return $result;
}
public function getAllIndustry()
{
$query = $this->db->get('beatle_industry');
$result = $query->result();
return $result;
}
public function getAllIndustryForGraph()
{
$this->db->select("created_date, COUNT(*) as Cdate");
$this->db->from("beatle_industry");
$this->db->group_by('created_date');
$query = $this->db->get();
//$query = $this->db->get('beatle_industry');
$result = $query->result();
return $result;
}
public function insertPage($inserdata)
{
$query = $this->db->insert('beatle_page' , $inserdata);
if ($query)
{
echo 'yes';
}
else
{
echo 'No';
}
}
public function UpdatePageById($inserdata,$pageid)
{
$query = $this->db->where('pageId',$pageid)->update('beatle_page' ,$inserdata);
if ($query)
{
echo 'yes';
}
else
{
echo 'No';
}
}
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));
}
echo '1';
}
public function insertPageContent($inserdata)
{
$query = $this->db->insert('beatle_pageContent' , $inserdata);
if ($query)
{
echo 'yes';
}
else
{
echo 'No';
}
}
public function getallPageContent()
{
$query = $this->db->get('beatle_pageContent');
$result = $query->result();
return $result;
}
public function getPageConByPageId($pageId)
{
$query = $this->db->get_where('beatle_pageContent' , array('db_pageid'=>$pageId));
$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 updatePageContent($inserdata,$pageid)
{
$query = $this->db->where('db_pageid',$pageid)->update('beatle_pageContent',$inserdata);
//echo $this->db->last_query();die;
if($query)
{
echo 'yes';
}else {echo 'no';}
}
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);
if ($query)
{
echo '1';
}
}
// ======================= 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");
$this->db->where("beatle_organization.OrgId",$orgId);
$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($bracId)
{
$query = $this->db->get_where("beatle_industry", array("db_bracnchid"=>$bracId));
$result = $query->result();
return $result;
}
public function getAllOrgByIndustryId($indId)
{
$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 getAllUserByIndustryId($indId)
{
$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_userlogin" , "beatle_userlogin.userId = beatle_branch.db_branchManager");
$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 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;
}
*/
}
?>