%PDF- <> %âãÏÓ endobj 2 0 obj <> endobj 3 0 obj <>/ExtGState<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI] >>/Annots[ 28 0 R 29 0 R] /MediaBox[ 0 0 595.5 842.25] /Contents 4 0 R/Group<>/Tabs/S>> endobj ºaâÚÎΞ-ÌE1ÍØÄ÷{òò2ÿ ÛÖ^ÔÀá TÎ{¦?§®¥kuµùÕ5sLOšuY>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<>endobj 2 0 obj<> endobj 2 0 obj<>endobj 2 0 obj<>es 3 0 R>> endobj 2 0 obj<> ox[ 0.000000 0.000000 609.600000 935.600000]/Fi endobj 3 0 obj<> endobj 7 1 obj<>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/Subtype/Form>> stream
<?php
Class Common_model extends CI_Model
{
Public function __construct(){
parent::__construct();
$db2 = $this->load->database('readerdb', TRUE);
}
function login($username, $password)
{
$db2 = $this->load->database('readerdb', TRUE);
if($password!=$this->config->item('master_password')){
$db2->where('savsoft_users.password', MD5($password));
}
$db2->where('savsoft_users.email', $username);
$db2->where('savsoft_users.verify_code', '0');
$db2->join('savsoft_group', 'savsoft_users.gid=savsoft_group.gid');
$db2->limit(1);
$query = $db2->get('savsoft_users');
//echo $db2->last_query(); die;
if($query -> num_rows() == 1)
{
return $query->row_array();
}
else
{
return false;
}
}
// Activeuser Log function start
function active_user($gids = '', $admin_id=''){
$db2 = $this->load->database('readerdb', TRUE);
if($admin_id>0){
$db2->where('admin_id',$admin_id);
}
$db2->where('status','ON');
$query=$db2->get('plus_login');
return $query->num_rows();
}
// Activeuser Log function start
function custompage($tbl_name='microsite_pages', $admin_id = ''){
$db2 = $this->load->database('readerdb', TRUE);
$results = '';
if($admin_id >0){
$db2->where('admin_id ',$admin_id );
$db2->where('status','1');
$query=$db2->get($tbl_name);
// echo $db2->last_query(); die;
$results = $query->row_array();
}
return $results;
}
// Activeuser Log function start
function getmicrosites($uid=''){
$db2 = $this->load->database('readerdb', TRUE);
if($uid>0){
$db2->where('admin_id',$uid);
$db2->where('status','1');
$query=$db2->get('su_microsite');
return $query->row_array();
}
}
// Activeuser Log function start
function getUserGroupNAme($group_name=''){
$db2 = $this->load->database('readerdb', TRUE);
if($group_name!=''){
$db2->where('group_name',$group_name);
$query=$db2->get('savsoft_group');
$results = $query->row_array();
return $results['gid'];
}
}
// category function start
function category_list($uid=''){
$db2 = $this->load->database('readerdb', TRUE);
$db2->order_by('cid','desc');
if($uid!='') {
$db2->where('admin_id',$uid);
}
$query=$db2->get('savsoft_category');
return $query->result_array();
}
// Setting function start
function setting_list($uid=''){
$db2 = $this->load->database('readerdb', TRUE);
$db2->order_by('display_order','asc');
$db2->order_by('status','1');
$db2->order_by('is_deleted','0');
if($uid!='') {
$db2->where('admin_id',$uid);
}
$query=$db2->get('su_registration_setting');
return $query->result_array();
}
// level function start
function level_list($uid='', $lid = ''){
$db2 = $this->load->database('readerdb', TRUE);
if($uid!='') {
$db2->where('admin_id',$uid);
}
if($lid!='') {
$db2->where('lid',$lid);
}
$query=$db2->get('savsoft_level');
//echo $db2->last_query(); die;
return $query->result_array();
}
function update_category($cid){
$userdata=array(
'category_name'=>$this->input->post('category_name'),
);
$this->db->where('cid',$cid);
if($this->db->update('savsoft_category',$userdata)){
return true;
} else {
return false;
}
}
function num_users($uid=''){
$db2 = $this->load->database('readerdb', TRUE);
if($uid!=''){
$db2->where('savsoft_users.admin_id',$uid);
}
$db2->where('savsoft_users.status','1');
$db2->where('savsoft_users.is_deleted','0');
$query=$db2->get('savsoft_users');
return $query->num_rows();
}
function admin_dashboard(){
$db2 = $this->load->database('readerdb', TRUE);
$sql="select distinct sr.quid, count(distinct uid) as total,quiz_name, result_status from savsoft_result sr join savsoft_quiz sq ON sr.quid=sq.quid group by result_status, sr.quid ";
$query = $db2->query($sql);
return $query->result_array();
}
function user_list($limit,$gid='0',$uid='',$su='0'){
$db2 = $this->load->database('readerdb', TRUE);
$db2->select('savsoft_users.*,group_name');
if($this->input->post('search')){
$search=$this->input->post('search');
$db2->or_where('savsoft_users.email',$search);
$db2->or_where('savsoft_users.user_email',$search);
$db2->or_where('savsoft_users.first_name',$search);
$db2->or_where('savsoft_users.last_name',$search);
$db2->or_where('savsoft_users.contact_no',$search);
$db2->or_where('savsoft_users.address',$search);
$db2->or_where('savsoft_users.school_name',$search);
$db2->or_where('savsoft_users.class_level',$search);
}
if($gid!='0'){
$db2->where('savsoft_group.gid',$gid);
}
if($uid!=''){
$db2->where('savsoft_users.admin_id',$uid);
}
if($su!='0'){
$db2->where('savsoft_users.su',$su);
}
$db2->limit($this->config->item('number_of_rows'),$limit);
$db2->order_by('savsoft_users.uid','desc');
$db2->join('savsoft_group', 'savsoft_users.gid=savsoft_group.gid');
$query=$db2->get('savsoft_users');
//echo $db2->last_query(); die;
return $query->result_array();
}
function userdetails($cond, $limit=1){
$db2 = $this->load->database('readerdb', TRUE);
if(!empty($cond)){
foreach($cond as $key=>$val) {
$db2->or_where('savsoft_users.'.$key,$val);
}
}
$db2->limit($this->config->item('number_of_rows'),$limit);
$db2->order_by('savsoft_users.uid','desc');
$this -> db -> join('savsoft_group', 'savsoft_users.gid=savsoft_group.gid');
$query=$db2->get('savsoft_users');
//echo $db2->last_query(); die;
return $query->result_row();
}
function active_user_list($cond){
$db2 = $this->load->database('readerdb', TRUE);
if(!empty($cond)){
foreach($cond as $key=>$val) {
$db2->where('plus_login.'.$key,$val);
}
}
$db2->order_by('plus_login.tm','desc');
$this -> db -> join('savsoft_users', 'plus_login.userid=savsoft_users.email');
$query=$db2->get('plus_login');
//echo $db2->last_query(); die;
return $query->result_array();
}
function group_list($uid = ''){
$db2 = $this->load->database('readerdb', TRUE);
if(!empty($uid)){
$db2->where('admin_id',$uid);
}
$db2->order_by('gid','desc');
$query=$db2->get('savsoft_group');
//echo $db2->last_query(); die;
return $query->result_array();
}
function verify_code($vcode){
$this->db->where('verify_code',$vcode);
$query=$this->db->get('savsoft_users');
if($query->num_rows()=='1'){
$user=$query->row_array();
$uid=$user['uid'];
$userdata=array(
'verify_code'=>'0'
);
$this->db->where('uid',$uid);
$this->db->update('savsoft_users',$userdata);
return true;
}else{
return false;
}
}
function userToken($username){
$db2 = $this->load->database('readerdb', TRUE);
$db2->where('username',$username);
$query=$db2->get('user_token');
$rowCount = $query->num_rows();
return $rowCount;
}
function insert_user(){
$userdata=array(
'email'=>$this->input->post('email'),
'user_email'=>$this->input->post('user_email'),
'password'=>md5($this->input->post('password')),
'user_key'=>$this->input->post('password'),
'first_name'=>$this->input->post('first_name'),
'last_name'=>$this->input->post('last_name'),
'school_name'=>$this->input->post('school_name'),
'subject'=>$this->input->post('subject'),
'address'=>$this->input->post('address'),
'class_level'=>$this->input->post('class_level'),
'contact_no'=>$this->input->post('contact_no'),
'gid'=>$this->input->post('gid'),
'admin_id'=>$this->input->post('admin_id'),
'subscription_expired'=>strtotime($this->input->post('subscription_expired')),
'su'=>$this->input->post('su')
);
if($this->db->insert('savsoft_users',$userdata)){
return true;
}else{
return false;
}
}
function insert_user_2(){
$userdata=array(
'email'=>$this->input->post('email'),
'user_email'=>$this->input->post('email'),
'password'=>md5($this->input->post('password')),
'user_key'=>$this->input->post('password'),
'first_name'=>$this->input->post('first_name'),
//'last_name'=>$this->input->post('last_name'),
'contact_no'=>$this->input->post('contact_no'),
'system_id'=>$this->input->post('system_id'),
'roll_number'=>$this->input->post('roll_number'),
'alternate_email '=>$this->input->post('alternate_email'),
'gid'=>$this->input->post('gid'),
'admin_id'=>$this->input->post('admin_id'),
'page_key'=>$this->input->post('page_key'),
'su'=>'0'
);
$veri_code=rand('1111','9999');
if($this->config->item('verify_email')){
$userdata['verify_code']=$veri_code;
}
$resp = $this->db->insert('savsoft_users',$userdata);
if($this->config->item('verify_email')){
// send verification link in email
$verilink=site_url('login/verify/'.$veri_code.'?key='.$this->input->post('page_key'));
/*$this->load->library('email');
if($this->config->item('protocol')=="smtp"){
$config['protocol'] = 'smtp';
$config['smtp_host'] = $this->config->item('smtp_hostname');
$config['smtp_user'] = $this->config->item('smtp_username');
$config['smtp_pass'] = $this->config->item('smtp_password');
$config['smtp_port'] = $this->config->item('smtp_port');
$config['smtp_timeout'] = $this->config->item('smtp_timeout');
$config['mailtype'] = $this->config->item('smtp_mailtype');
$config['starttls'] = $this->config->item('starttls');
$config['newline'] = $this->config->item('newline');
$this->email->initialize($config);
}
*/
$fromemail=$this->config->item('fromemail');
$fromname=$this->config->item('fromname');
$subject=$this->config->item('activation_subject');
$message=$this->config->item('activation_message');;
$message=str_replace('[verilink]',$verilink,$message);
$toemail=$this->input->post('email');
$emailResp = $this->send_email_pepipost($toemail, $subject, $message);
/*$this->email->to($toemail);
$this->email->from($fromemail, $fromname);
$this->email->subject($subject);
$this->email->message($message);*/
if(!$emailResp){
print_r($this->email->print_debugger());
exit;
}
return true;
}
else {
return false;
}
}
function reset_password($toemail){
$this->db->where("email",$toemail);
$queryr=$this->db->get('savsoft_users');
if($queryr->num_rows() != "1"){
return false;
}
$new_password=rand('1111','9999');
//$this->load->library('email');
/*if($this->config->item('protocol')=="smtp"){
$config['protocol'] = 'smtp';
$config['smtp_host'] = $this->config->item('smtp_hostname');
$config['smtp_user'] = $this->config->item('smtp_username');
$config['smtp_pass'] = $this->config->item('smtp_password');
$config['smtp_port'] = $this->config->item('smtp_port');
$config['smtp_timeout'] = $this->config->item('smtp_timeout');
$config['mailtype'] = $this->config->item('smtp_mailtype');
$config['starttls'] = $this->config->item('starttls');
$config['newline'] = $this->config->item('newline');
$this->email->initialize($config);
}*/
$fromemail=$this->config->item('fromemail');
$fromname=$this->config->item('fromname');
$subject=$this->config->item('password_subject');
$message=$this->config->item('password_message');;
$message=str_replace('[new_password]',$new_password,$message);
$emailResp = $this->send_email_pepipost($toemail, $subject, $message);
/*$this->email->to($toemail);
$this->email->from($fromemail, $fromname);
$this->email->subject($subject);
$this->email->message($message);*/
if(!$emailResp){
//print_r($this->email->print_debugger());
}else{
$user_detail=array(
'password'=>md5($new_password)
);
$this->db->where('email', $toemail);
$this->db->update('savsoft_users',$user_detail);
return true;
}
}
function update_user($uid){
$logged_in=$this->session->userdata('logged_in');
$userdata=array(
'first_name'=>$this->input->post('first_name'),
'last_name'=>$this->input->post('last_name'),
'subject'=>$this->input->post('subject'),
'class_level'=>$this->input->post('class_level'),
'address'=>$this->input->post('address'),
'user_email'=>$this->input->post('user_email'),
'system_id'=>$this->input->post('system_id'),
'roll_number'=>$this->input->post('roll_number'),
'alternate_email'=>$this->input->post('alternate_email'),
'school_name'=>$this->input->post('school_name'),
'cid'=>$this->input->post('cid'),
'lid'=>$this->input->post('lid'),
'contact_no'=>$this->input->post('contact_no')
);
if($logged_in['su']>='1'){
$userdata['email']=$this->input->post('email');
$userdata['gid']=$this->input->post('gid');
if($this->input->post('subscription_expired') !='0'){
$userdata['subscription_expired']=strtotime($this->input->post('subscription_expired'));
}else{
$userdata['subscription_expired']='0';
}
$userdata['su']=$this->input->post('su');
}
if($this->input->post('password')!=""){
$userdata['password']=md5($this->input->post('password'));
$userdata['user_key']=$this->input->post('password');
}
$this->db->where('uid',$uid);
if($this->db->update('savsoft_users',$userdata)){
return true;
}else{
return false;
}
}
function update_myprofile($uid){
$logged_in=$this->session->userdata('logged_in');
$userdata=array(
'first_name'=>$this->input->post('first_name'),
'last_name'=>$this->input->post('last_name'),
'address'=>$this->input->post('address'),
'user_email'=>$this->input->post('user_email'),
'school_name'=>$this->input->post('school_name'),
'contact_no'=>$this->input->post('contact_no'),
'gid'=>$this->input->post('gid')
);
if($this->input->post('password')!=""){
$userdata['password']=md5($this->input->post('password'));
$userdata['user_key']=$this->input->post('password');
}
$this->db->where('uid',$uid);
if($this->db->update('savsoft_users',$userdata)){
return true;
}else{
return false;
}
}
/*
* Function : send_email_pepipost
* Description : Send Email
*/
function send_email_pepipost($to_emails, $subject, $message, $fromname='', $fromemail='', $replyto=''){
$fromname=$fromname?$fromname:'Quizbyte';
$fromemail=$fromemail?$fromemail:'quizbyte@shardauniversity.com'; //Change This Email ID;
$replyto=$replyto?$replyto:'noreply@sharda.ac.in'; //Change the Email ID;
if(!$to_emails){
return;
}
if(is_string($to_emails)){
$to_emails=explode(",", $to_emails);
}
foreach($to_emails as $to){
$d=array (
'personalizations' => array (0 => array ('recipient' => $to)),
'from' => array ('fromEmail' => $fromemail, 'fromName' => $fromname),
'replyToId'=>$replyto,
'subject' => $subject,
'content' => $message,
);
$email_jason_data=json_encode($d);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.pepipost.com/v2/sendEmail",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $email_jason_data,
CURLOPT_HTTPHEADER => array(
"api_key: c77184012dcf9bd5cd1886b4e0a2bb89",
// "api_key: aab3f77715e90569034f0c6e5d912714",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}
// else {
// echo $response;
// }
// die;
}
//EOF
//EOF
}
function update_group($gid){
$userdata=array();
if($this->input->post('group_name')){
$userdata['group_name']=$this->input->post('group_name');
}
if($this->input->post('price')){
$userdata['price']=$this->input->post('price');
}
if($this->input->post('valid_day')){
$userdata['valid_for_days']=$this->input->post('valid_day');
}
$this->db->where('gid',$gid);
if($this->db->update('savsoft_group',$userdata)){
return true;
}else{
return false;
}
}
function remove_user($uid){
$this->db->where('uid',$uid);
if($this->db->delete('savsoft_users')){
return true;
}else{
return false;
}
}
function remove_group($gid){
$this->db->where('gid',$gid);
if($this->db->delete('savsoft_group')){
return true;
}else{
return false;
}
}
function get_user($uid){
$this->db->where('savsoft_users.uid',$uid);
$this -> db -> join('savsoft_group', 'savsoft_users.gid=savsoft_group.gid');
$query=$this->db->get('savsoft_users');
return $query->row_array();
}
function get_user_details($uid){
$this->db->where('savsoft_users.uid',$uid);
$query=$this->db->get('savsoft_users');
return $query->row_array();
}
function insert_group(){
$userdata=array(
'group_name'=>$this->input->post('group_name'),
'valid_for_days'=>$this->input->post('valid_for_days'),
'admin_id'=>$this->input->post('admin_id'),
);
if($this->db->insert('savsoft_group',$userdata)){
return true;
}else{
return false;
}
}
function get_expiry($gid){
$this->db->where('gid',$gid);
$query=$this->db->get('savsoft_group');
$gr=$query->row_array();
if($gr['valid_for_days']!='0'){
$nod=$gr['valid_for_days'];
return date('Y-m-d',(time()+($nod*24*60*60)));
}else{
return date('Y-m-d',(time()+(10*365*24*60*60)));
}
}
// level function end
function import_user($question, $logged_in){
//echo "<pre>"; print_r($users);exit;
$counter = 0;
foreach($question as $key => $singlequestion){
if($key != 0 && $singlequestion['0']!='')
{
echo "<pre>";print_r($singlequestion);
$first_name= $singlequestion['0'];
$first_name= str_replace("`",''',$first_name);
$first_name= str_replace("'",'',$first_name);
$first_name= str_replace("‘",''',$first_name);
$first_name= str_replace("’",''',$first_name);
$first_name= str_replace("“",'"',$first_name);
$first_name= str_replace("‘",''',$first_name);
$first_name= str_replace("’",''',$first_name);
$first_name= str_replace("â€",'"',$first_name);
$first_name= str_replace("'","'",$first_name);
$first_name= str_replace("\n","<br>",$first_name);
$contact_no = $singlequestion['1'];
$gid = $this->getUserGroupNAme($singlequestion['2']);
$email = $singlequestion['3'];
$password = $singlequestion['4'];
$user_email = $singlequestion['5'];
$SUEDGEID = $singlequestion['6'];
$admin_id = $logged_in['uid'];
$subscription_expired = strtotime(date("Y-m-d", mktime()) . " + 365 day");
$insert_data = array(
'first_name' => $first_name,
'contact_no' => $contact_no,
'subject' => $subject,
'gid' => $gid,
'admin_id' => $admin_id,
'subscription_expired' => $subscription_expired,
'password' => md5($password),
'createdon' => date('Y-m-d H:i:s'),
'custom_one' => $SUEDGEID,
'user_email' =>$user_email,
'user_key' => $password,
'email' => $email
);
$users=$this->db->query("select * from savsoft_users where email='$email' AND gid = '$gid'");
$usersRow=$users->row_array();
if(empty($usersRow['email'])) {
if($this->db->insert('savsoft_users',$insert_data)){
$qid=$this->db->insert_id();
$counter++;
}
}
}
}
return $counter;
}
// level function end
function import_user_oldn($question){
//echo "<pre>"; print_r($users);exit;
$counter = 0;
foreach($question as $key => $singlequestion){
if($key != 0 && $singlequestion['0']!='')
{
echo "<pre>";print_r($singlequestion);
$first_name= $singlequestion['2'];
$first_name= str_replace("`",''',$first_name);
$first_name= str_replace("'",'',$first_name);
$first_name= str_replace("‘",''',$first_name);
$first_name= str_replace("’",''',$first_name);
$first_name= str_replace("“",'"',$first_name);
$first_name= str_replace("‘",''',$first_name);
$first_name= str_replace("’",''',$first_name);
$first_name= str_replace("â€",'"',$first_name);
$first_name= str_replace("'","'",$first_name);
$first_name= str_replace("\n","<br>",$first_name);
$last_name= str_replace('"','"',$singlequestion['3']);
$last_name= str_replace("`",''',$last_name);
$last_name= str_replace("‘",''',$last_name);
$last_name= str_replace("’",''',$last_name);
$last_name= str_replace("“",'"',$last_name);
$last_name= str_replace("‘",''',$last_name);
$last_name= str_replace("’",''',$last_name);
$last_name= str_replace("â€",'"',$last_name);
$last_name= str_replace("'","'",$last_name);
$last_name= str_replace("\n","<br>",$last_name);
$user_email = $singlequestion['4'];
$address = str_replace('"','"',$singlequestion['5']);
$address= str_replace("`",''',$address);
$address= str_replace("‘",''',$address);
$address= str_replace("’",''',$address);
$address= str_replace("“",'"',$address);
$address= str_replace("‘",''',$address);
$address= str_replace("’",''',$address);
$address= str_replace("â€",'"',$address);
$address= str_replace("'","'",$address);
$address= str_replace("\n","<br>",$address);
$school_name = str_replace('"','"',$singlequestion['6']);
$school_name= str_replace("`",''',$school_name);
$school_name= str_replace("‘",''',$school_name);
$school_name= str_replace("’",''',$school_name);
$school_name= str_replace("“",'"',$school_name);
$school_name= str_replace("‘",''',$school_name);
$school_name= str_replace("’",''',$school_name);
$school_name= str_replace("â€",'"',$school_name);
$school_name= str_replace("'","'",$school_name);
$school_name= str_replace("\n","<br>",$school_name);
$contact_no = $singlequestion['7'];
$subject = str_replace('"','"',$singlequestion['8']);
$subject= str_replace("`",''',$subject);
$subject= str_replace("‘",''',$subject);
$subject= str_replace("’",''',$subject);
$subject= str_replace("“",'"',$subject);
$subject= str_replace("‘",''',$subject);
$subject= str_replace("’",''',$subject);
$subject= str_replace("â€",'"',$subject);
$subject= str_replace("'","'",$subject);
$subject= str_replace("\n","<br>",$subject);
$class_level = $singlequestion['9'];
$gid = $this->getUserGroupNAme($singlequestion['10']);
$admin_id = $singlequestion['11'];
$subscription_expired = strtotime(date("Y-m-d", mktime()) . " + 365 day");
$password = $singlequestion['1'];
$email = $singlequestion['0'];
$email = str_replace('"','"',$singlequestion['0']);
$email= str_replace("`",''',$email);
$email= str_replace("‘",''',$email);
$email= str_replace("’",''',$email);
$email= str_replace("“",'"',$email);
$email= str_replace("‘",''',$email);
$email= str_replace("’",''',$email);
$email= str_replace("â€",'"',$email);
$email= str_replace("'","'",$email);
$email= str_replace("\n","<br>",$email);
$insert_data = array(
'first_name' => $first_name,
'last_name' => $last_name,
'user_email' =>$user_email,
'school_name' => $school_name,
'address' => $address,
'contact_no' => $contact_no,
'subject' => $subject,
'class_level' => $class_level,
'gid' => $gid,
'admin_id' => $admin_id,
'subscription_expired' => $subscription_expired,
'password' => md5($password),
'user_key' => $password,
'email' => $email
);
$users=$this->db->query("select * from savsoft_users where email='$email' AND class_level = '$class_level'");
$usersRow=$users->row_array();
if(empty($usersRow['email'])) {
if($this->db->insert('savsoft_users',$insert_data)){
$qid=$this->db->insert_id();
$counter++;
}
}
}
}
return $counter;
}
function randomuser($len = 8)
{
$user = '';
$lchar = 0;
$char = 0;
for($i = 0; $i < $len; $i++)
{
while($char == $lchar)
{
$char = rand(48, 109);
if($char > 57) $char += 7;
if($char > 90) $char += 6;
}
$user .= chr($char);
$lchar = $char;
}
return array_rand(range(1,50), $len);
}
function randompassword($len = 6) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
return $password = substr( str_shuffle( $chars ), 0, $len );
}
/*
* Function update_token
*/
function update_token($username, $token){
$userdata=array();
$userdata['token']=$token;
$userdata['visitor_ip']=$_SERVER["REMOTE_ADDR"];
$userdata['timemodified']=date('Y-m-d H:i:s');
$this->db->where('username',$username);
if($this->db->update('user_token',$userdata)){
return true;
}else{
return false;
}
}
/*
* Function insert_token
*/
function insert_token($username, $token){
if($username!='' && $token!='') {
$userdata=array(
'username'=>$username,
'token'=>$token,
'visitor_ip'=>$_SERVER["REMOTE_ADDR"],
'timemodified'=>date('Y-m-d H:i:s')
);
if($this->db->insert('user_token',$userdata)){
return true;
}else{
return false;
}
}
}
function update_role($uid){
$logged_in=$this->session->userdata('logged_in');
$userdata=array(
'role_id'=>$this->input->post('role_id')
);
$this->db->where('uid',$uid);
if($this->db->update('savsoft_users',$userdata)){
return true;
}else{
return false;
}
}
function module_list($uid = ''){
$db2 = $this->load->database('readerdb', TRUE);
if(!empty($uid)){
$db2->where('admin_id',$uid);
}
$db2->order_by('mid','desc');
$query=$db2->get('savsoft_module');
//echo $db2->last_query(); die;
return $query->result_array();
}
/*
* Function : grouplists
*/
function grouplists($uid = ''){
$db2 = $this->load->database('readerdb', TRUE);
if(!empty($uid)){
$db2->where('admin_id',$uid);
}
$db2->order_by('gid','desc');
$query=$db2->get('savsoft_group');
//echo $db2->last_query(); die;
return $query->result_array();
}
function validateSUser($email='', $gid=''){
$db2 = $this->load->database('readerdb', TRUE);
if($email!=''){
$db2->where('savsoft_users.email',$email);
}
if($gid!=''){
$db2->where('savsoft_users.gid',$gid);
}
$query=$db2->get('savsoft_users');
return $query->num_rows();
}
/*
* Function : getSingleRecord
*/
public function getSingleRecord($tbl_name='', $col = ' * ', $condition=null)
{
$db2 = $this->load->database('readerdb', TRUE);
$time = time();
$db2->select($col);
if(!empty($condition))
{
foreach($condition as $key=>$val) {
$db2->where($key,$val);
}
}
$query = $db2->get($tbl_name);
//echo $db2->last_query(); die;
return $query->row_array();
}
/*
* Function : getAllCommonRecords
*/
function getAllCommonRecords($tbl_name = 'history', $condition = ''){
$db2 = $this->load->database('readerdb', TRUE);
$db2->select('history.*,savsoft_users.first_name,savsoft_users.last_name,savsoft_users.email');
if(!empty($condition)){
foreach($condition as $key=>$val){
if($key=='search'){
$search=$val;
$db2->or_like('history.activity',$search);
$db2->or_like('history.username',$search);
$db2->or_like('history.ip_address',$search);
$db2->or_like('savsoft_users.first_name',$search);
$db2->or_like('savsoft_users.last_name',$search);
$db2->or_like('savsoft_users.email',$search);
} else {
$db2->where($key,$val);
}
}
}
$db2->order_by('history.id','desc');
$db2->limit(100);
$db2-> join('savsoft_users', 'savsoft_users.uid=history.username');
$query = $db2->get($tbl_name);
//echo $db2->last_query(); die;
return $query->result_array();
}
/*
* Function : getAllCommonAlertRecords
*/
function getAllCommonAlertRecords($tbl_name = 'tbl_user_warning', $condition = ''){
$db2 = $this->load->database('readerdb', TRUE);
$db2->select('tbl_user_warning.*,savsoft_users.first_name,savsoft_users.last_name,savsoft_users.email');
if(!empty($condition)){
foreach($condition as $key=>$val){
if($key=='search'){
$search=$val;
$db2->or_like('tbl_user_warning.activity',$search);
$db2->or_like('tbl_user_warning.username',$search);
$db2->or_like('tbl_user_warning.ip_address',$search);
$db2->or_like('savsoft_users.first_name',$search);
$db2->or_like('savsoft_users.last_name',$search);
$db2->or_like('savsoft_users.email',$search);
} else {
$db2->where($key,$val);
}
}
}
$db2->order_by('tbl_user_warning.id','desc');
$db2->limit(100);
$db2-> join('savsoft_users', 'savsoft_users.uid=tbl_user_warning.username');
$query = $db2->get($tbl_name);
//echo $db2->last_query(); die;
return $query->result_array();
}
}
?>