Hi I've already installed the CometChat, but I'm facing the following error:
Call to undefined function mcrypt_decrypt() in /home/vagrant/changeglobe/public/cometchat/integration.php on line 89
I'm using Homestead with Nginx for Laravel. I have read at many places that I need to enable mycrypt, but did not found any correct. Please let me know about this issue if you know. Thank you.
Try replacing the getUserID() function in /cometchat/integration.php file with the code below:
function getUserID() {
$userid = 0;
if (!empty($_SESSION['basedata']) && $_SESSION['basedata'] != 'null') {
$_REQUEST['basedata'] = $_SESSION['basedata'];
}
if (!empty($_REQUEST['basedata'])) {
if (function_exists('mcrypt_encrypt') && defined('ENCRYPT_USERID') && ENCRYPT_USERID == '1') {
$key = "";
if( defined('KEY_A') && defined('KEY_B') && defined('KEY_C') ){
$key = KEY_A.KEY_B.KEY_C;
}
$uid = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode(rawurldecode($_REQUEST['basedata'])), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
if (intval($uid) > 0) {
$userid = $uid;
}
} else {
$userid = $_REQUEST['basedata'];
}
}
if (!empty($_COOKIE['laravel_session'])) {
$session= cookie_decrypt($_COOKIE['laravel_session']);
$data = file_get_contents(dirname(dirname(dirname(__FILE__))).'/storage/framework/sessions/'.$session);
if (!empty($data)) {
$k = explode(';i:',$data);
$m = explode(';s:',$k[1]);
$userid = $m[0];
}
}
$userid = intval($userid);
return $userid;
}
If you are still facing issues please create a support ticket https://my.cometchat.com/tickets and our team will assist you.
Related
Hi, I have problem with routes, it's always return "Missing Required Parameters".Please see my code below. Thank you! I think my route is wrong, what should I do?
//Controller Code
public function index($id = 0,$dateStart = null, $dateEnd = null)
{
//$current_date = date('Y-m-d');
// $attendances= Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')-
>where('Date','=',$current_date)->get();
// return view('attendance.index',compact('attendances'))
if($id == 0 && $dateStart == null && $dateEnd == null)
{
$current_date = date('Y-m-d');
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')-
>where('Date','=',$current_date)->get();
return view('manage.index',compact('attendances'));
}
elseif ($id != 0)
{
$sUser = User::select('name')->where('id','=',$id)->get();
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')->where('user_id','=',$id)-
>get();
return view('manage.index',compact('attendances','sUser'));
}
elseif($dateStart != null && $dateEnd == null)
{
$attendances =
Attendance::select('Name','CheckIn','CheckOut','Note','Date','TotalHours')
>whereBetween('Date',$dateStart,$dateEnd)->get();
return view('manage.index',compact('attendances'));
}
// return view('manage.index');
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
}
And here is my route.
Route::get('manageattendance/{id}/{dateStart}/{dateEnd}',
[App\Http\Controllers\ManageAttendanceController::class, 'index'])->name('manageattendance');
if you set the parameters in function must say for route these parameters are not required are optionally add ? after each parameter
Route::get('manageattendance/{id?}/{dateStart?}/{dateEnd?}',
The orignial code was like this , I want to get landline_no value also in getRecords, How to do that
public function checklead() {
$lead = $_POST['number'];
$check = $this->common_model->getRecords('leads',array("phone_no"=>$lead));
if(count($check) > 0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead));
if($lead->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';}
What I have achieved so far,but not getting array values from getRecords
$lead = $_POST['number'];
$check = $this->common_model->getRecords('leads',array("phone_no"=>$lead),array("landline_no"=>$lead));
//echo "<pre>";
//print_r($check);
//echo $check[0]['landline_no'];exit;
if(count($check) > 0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$lead,"landline_no"=>$check[0]['landline_no']));
Code for getRecords:
function getRecords($table,$db = array(),$select = "*",$ordercol = '',$group = '',$start='',$limit=''){
$this->db->select($select);
if(!empty($ordercol)){
$this->db->order_by($ordercol);
}
if($limit != '' && $start !=''){
$this->db->limit($limit,$start);
}
if($group != ''){
$this->db->group_by($group);
}
$q=$this->db->get_where($table, $db);
return $q->result_array();
}
// Get Recored row
public function getRecored_row($table,$where)
{
$q = $this->db->where($where)
->select('*')
->get($table);
return $q->row();
}
Check my answer: This code also working well, i have written, but i am not sure , this logic is correct or not kindly check this one.
public function checklead() {
$lead = $_POST['number'];
if($this->common_model->getRecords('leads',array("phone_no"=>$lead)))
{
$check=$this->common_model->getRecords('leads',array("phone_no"=>$lead));
}
else
{
$check=$this->common_model->getRecords('leads',array("landline_no"=>$lead));
}
echo "<pre>";
//echo $check;
//print_r($check); exit;
$p= $check[0]['phone_no'];
$l= $check[0]['landline_no'];
// exit;
if(count($p) > 0 || count($l)>0) {
$lead = $this->common_model->getRecored_row('leads',array("phone_no"=>$p));
$lead1 = $this->common_model->getRecored_row('leads',array("landline_no"=>$l));
if($lead->assignto_self != 0 || $lead1->assignto_self != 0) {
$assignto = $lead->assignto_self;
$key = 'Self Assign';
} else if($lead->assignto_se != 0 || $lead1->assignto_se != 0) {
$assignto = $lead->assignto_se;
$key = '';
}else if($lead->assignto_tl != 0 || $lead1->assignto_tl != 0) {
$assignto = $lead->assignto_tl;
$key = '';
} else if($lead->uploaded_by != 0 || $lead1->uploaded_by != 0) {
$assignto = $lead->uploaded_by;
$key = 'Uploaded by';
}
$user = $this->common_model->getRecored_row('admin',array("id"=>$assignto));
$role = $this->common_model->getRecored_row('role',array("id"=>$user->role));
$this->session->set_flashdata('message', array('message' => 'This Lead Already exist with '.$user->name.' ('.$role->role.') '.' ','class' => 'danger'));
redirect(base_url().'leads');
} else {
redirect(base_url().'leads/add_newlead/'.$lead);
}
}
There does not seem to be any reason to use getRecords(). The $check value has no useful purpose and creating it is a waste of resources.
We don't need $check because getRecord_row() will return the "lead" if found so the only check needed is to see if getRecord_row() returns anything. getRecord_row() uses the database function row() which returns only one row or null if no rows are found. Read about row() here.
If what you want is to find the "lead" that has either a "phone_no" or a "landline_no" equal to $_POST['number'] then you need to use a custom string for the where clause. (See #4 at on this documentation page.) You need a custom string because getRecord_row() does not allow any other way to ask for rows where a='foo' OR b='foo'. Here is what I think you are looking for.
public function checklead()
{
// use input->post() it is the safe way to get data from $_POST
$phone = $this->input->post('number');
// $phone could be null if $_POST['number'] is not set
if($phone)
{
$lead = $this->common_model->getRecored_row('leads', "phone_no = $phone OR landline_no = $phone");
// $lead could be null if nothing matches where condition
if($lead)
{
if($lead->assignto_self != 0)
{
$assignto = $lead->assignto_self;
$key = 'Self Assign';
}
else if($lead->assignto_se != 0)
{
$assignto = $lead->assignto_se;
$key = '';
}
}
}
}
The main difference between getRecords() and getRecord_row() is the number of records (rows of data) to return. getRecord_row() will return a maximum of one record while getRecords() might return many records.
getRecords() accepts arguments that allow control of what data is selected ($db, $select), how it is arranged ($ordercol, $group), and the number of rows to retrieve ($limit) starting at row number x ($start) .
Controller:
$next_id = $this->o->next_id();
$data['next_id']=$next_id;
Model:
public function next_id(){
$this->db->select_max('p_ori_id');
$max = $this->db->get('orientation_master');
if($max==0){
$next_id = 1;
}else{
$next_id = 1+$max;
}
return $next_id;
}
Return Error:
Object of class CI_DB_mysqli_result could not be converted to int
Please solve problem..
No offense to #pradeep but you may have some unexpected results if you don't have any rows. I suggest:
public function next_id()
{
$this->db->select_max('p_ori_id', 'max');
$query = $this->db->get('orientation_master');
if ($query->num_rows() == 0) {
return 1;
}
$max = $query->row()->max;
return $max == 0 ? 1 : $max + 1;
}
Hope this will help you:
public function next_id()
{
$this->db->select_max('p_ori_id', 'max');
$query = $this->db->get('orientation_master');
// Produces: SELECT MAX(p_ori_id) as max FROM orientation_master
$max = $query->row()->max;
if($max == 0){
$next_id = 1;
}else{
$next_id = $max+1;
}
return $next_id;
}
For more : https://www.codeigniter.com/user_guide/database/query_builder.html
You are getting that error becuase $max is a result set object and not an integer record value like you're trying to use it.
You can try this function to get the next id.
Modified function:
public function next_id(){
$this->db->select_max('p_ori_id', 'max');
$result = $this->db->get('orientation_master');
$row = $result->row_array();
$next_id = isset($row['max']) ? ($row['max']+1) : 1;
return $next_id;
}
If the column is auto increment, you can use the below code instead.
Alternative:
public function next_id() {
$sql_string = "SELECT `auto_increment` FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '".$this->db->dbprefix."orientation_master'";
$query = $this->db->query($sql_string);
$row = $query->row_array();
return $row['auto_increment'];
}
I am trying to unlink files that were created the day before
I have a custom application > core > MY_Log.php file and it creates a log for each error level. For easier reading.
logs > DEBUG-04-08-2016.php
logs > ERROR-04-08-2016.php
logs > INFO-04-08-2016.php
logs > DEBUG-03-08-2016.php
logs > ERROR-03-08-2016.php
logs > INFO-03-08-2016.php
Question how am I able to modify the write_log so could delete / unlink files that were created the day before?
<?php
class MY_Log extends CI_Log {
public function write_log($level, $msg)
{
if ($this->_enabled === FALSE)
{
return FALSE;
}
$level = strtoupper($level);
if (( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
&& ! isset($this->_threshold_array[$this->_levels[$level]]))
{
return FALSE;
}
$filepath = $this->_log_path . $level .'-'. date('d-m-Y').'.'.$this->_file_ext;
$message = '';
if ( ! file_exists($filepath))
{
$newfile = TRUE;
// Only add protection to php files
if ($this->_file_ext === 'php')
{
$message .= "";
}
}
if ( ! $fp = #fopen($filepath, 'ab'))
{
return FALSE;
}
flock($fp, LOCK_EX);
// Instantiating DateTime with microseconds appended to initial date is needed for proper support of this format
if (strpos($this->_date_fmt, 'u') !== FALSE)
{
$microtime_full = microtime(TRUE);
$microtime_short = sprintf("%06d", ($microtime_full - floor($microtime_full)) * 1000000);
$date = new DateTime(date('d-m-Y H:i:s.'.$microtime_short, $microtime_full));
$date = $date->format($this->_date_fmt);
}
else
{
$date = date($this->_date_fmt);
}
$message .= $this->_format_line($level, $date, $msg);
for ($written = 0, $length = strlen($message); $written < $length; $written += $result)
{
if (($result = fwrite($fp, substr($message, $written))) === FALSE)
{
break;
}
}
flock($fp, LOCK_UN);
fclose($fp);
if (isset($newfile) && $newfile === TRUE)
{
chmod($filepath, $this->_file_permissions);
}
return is_int($result);
}
}
First of use
$config['log_threshold'] = 1;
For only error message, so there will be less number of files
Add below code just before $filepath; to delete previous date logs
$unlink_date = date('Y-m-d',strtotime("-1 days"));
$filepath_unlink = $this->_log_path . $level .'-'. $unlink_date.'.'.$this->_file_ext;
if ( file_exists($filepath_unlink))
{
unlink($filepath_unlink);
}
I hope someone can help guide me in the right direction. I am new to Laravel and far from the best php coder. I am trying to build dynamic nested where/orWhere clauses and I am stuck, and by stuck I mean I can't figure it out. The code I have so far is:
public static function runNested($rId, $current_id) {
$insidestuff = DB::table('tableName')
->select('all fields necessary')
...
->get();
$count=1;
foreach ($insidestuff as $inside)
{
$var1 = $inside->var1;
$var2 = $inside->var2;
$var3 = $inside->var3;
$var4 = $inside->var4;
if ($count == 1)
{
$outsideMet = $outsideMet->where(function($query) use ($var1, $var2, $var3, $var4, $id)
{
$query->where($var1, $var2, $var3);
$outsideMet = myClass::runNested($var4, $id);
});
} else {
$outsideMet = $outsideMet->orWhere(function($query) use ($var1, $var2, $var3, $var4, $id)
{
$query->where($var1, $var2, $var3);
$outsideMet = myClass::runNested($var4, $id);
});
}
$count++;
}
}
public static function runOutside($rId) {
$outsideQuery = DB::table('tableName')
->select('all necessary fields')
->get();
$outsideMet = dbTable::select('*');
$outsideMet = $outsideMet->leftJoin('necessary fields');
$outsideCount=1;
foreach ($oursideQuery as $oQuery)
{
$oVar1 = $oQuery->oVar1;
$oVar2 = $oQuery->oVar2;
$oVar3 = $oQuery->oVar3;
$oVar4 = $oVar4;
$oVar5 = $oQuery->oVar5;
if ($outsideCount == 1)
{
$outsideMet = $outsideMet->where(function($query) use ($oVar1, $oVar2, $oVar3, $oVar4, $oVar5)
{
$query->where($oVar1, $oVar2, $oVar3);
$outsideMet = myClass::runNested($oVar4, $oVar5);
});
} else {
$outsideMet = $outsideMet->orWhere(function($query) use ($oVar1, $oVar2, $oVar3, $oVar4, $oVar5)
{
$query->where($oVar1, $oVar2, $oVar3);
$outsideMet = myClass::runNested($oVar4, $oVar5);
});
}
$outsideCount++;
}
$outsideMet = $outsideMet->count();
I hope someone can tell me how to do this properly, and if the above code is even close, what I am doing wrong. Thank you in advance for the help and guidance.