I need to return all the InstallmentDates along with the return data, the issue here is I have same OrderInstallmentDetailsId for multiple InstallmentDates.
$select = $this->select()
->setIntegrityCheck(false)
->from(array('j' => DB_TABLE_PREFIX . 'finance_journal'), array(
'*',
'JournalCreatedDate' => 'CreatedDate'
))
->join(array('jr' => DB_TABLE_PREFIX . 'finance_journal_reference'), 'j.JournalId = jr.JournalId', array(
'totalDebitAmount' => 'SUM(DebitAmount)',
'totalCreditAmount' => 'SUM(CreditAmount)',
'debitBalanceAmount' => 'SUM(DebitAmount) - SUM(CreditAmount)',
))
->join(array('a' => DB_TABLE_PREFIX . 'finance_account'), 'jr.AccountId = a.AccountId', array(
'AccountId',
'AccountGroupId',
'AccountCode',
'AccountPath',
'AccountName'
))
->join(array('ja' => DB_TABLE_PREFIX . 'finance_journal_approved_user'), 'j.JournalId = ja.JournalId', array())
->join(array('c' => DB_TABLE_PREFIX . 'customer'), 'a.AccountId = c.AccountId', array(
'CustomerId',
'CustomerAccountId' => 'AccountId'
))
->join(array('O' => DB_TABLE_PREFIX . 'order'), 'O.UserId = c .CustomerId', array(
'OrderId'
,'OrderInstallmentId'))
->join(array('oi' => DB_TABLE_PREFIX . 'order_installment'), 'oi.OrderInstallmentId = O.OrderInstallmentId', array(
'OrderInstallmentId',
'InstallmentId',
'NumberOfInstallments'
))
->join(array('oid' => DB_TABLE_PREFIX . 'order_installment_details'), 'oid.OrderInstallmentId = oi.OrderInstallmentId', array(
'OrderInstallmentDetailsId',
'InstallmentDate'
))
->join(array('f' => DB_TABLE_PREFIX . 'firm'), 'f.FirmId = c.FirmId', array('FirmName'))
->join(array('u' => DB_TABLE_PREFIX . 'user'), 'u.UserId = c.CustomerId', array('FirstName', 'LastName'))
->group('a.AccountId')
->order('j.CreatedDate ASC');
//->order('oid.OrderInstallmentDetailsId DESC');
if ($this->_authUser->sessionBranch() > 0) {
$select->where('j.BranchId = ?', $this->_authUser->sessionBranch());
}
if ($firmId > 0) {
$select->where('f.FirmId = ?', $firmId);
}
if (empty($fromDate)) {
$fromDate = strtotime('-30 days');
} else {
$select->where('j.JournalDate >= ?', Utils_Converter::mysqlDate($fromDate));
}
if (!empty($toDate)) {
$select->where('j.JournalDate <= ?', Utils_Converter::mysqlDate($toDate));
}
if ($minimumDebitBalance == 0) {
$select->having('debitBalanceAmount > ?', $minimumDebitBalance);
} else {
$select->having('debitBalanceAmount >= ?', $minimumDebitBalance);
}
if ($maximumDebitBalance == 0) {
} else {
$select->having('debitBalanceAmount < ?', $maximumDebitBalance);
}
//echo $select;exit;
$returnData = array();
foreach ($this->fetchAll($select) as $row) {
//if($row['debitBalanceAmount'] >= $minimumDebitBalance){
$returnData[$row['AccountId']] = $row->toArray();
//}
}
return $returnData;
}
My main aim is to get the maximum date from the array of dates.
->join(array('oid' => DB_TABLE_PREFIX . 'order_installment_details'), 'oid.OrderInstallmentId = oi.OrderInstallmentId', array(
'OrderInstallmentDetailsId',
'lastInstallmentDate' => new Zend_Db_Expr('MAX(InstallmentDate)')
))
->join(array('f' => DB_TABLE_PREFIX . 'firm'), 'f.FirmId = c.FirmId', array('FirmName'))
->join(array('u' => DB_TABLE_PREFIX . 'user'), 'u.UserId = c.CustomerId', array('FirstName', 'LastName'))
->group('a.AccountId')
->order('j.CreatedDate ASC');
Related
When adding scores for students, I would like those with a total score of 0 not to be inserted into the database at all.
Controller:
public function entrymarks()
{
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('exam_group_class_batch_exam_subject_id', 'Subject', 'required|trim|xss_clean');
if ($this->form_validation->run() == false) {
$data = array(
'exam_group_class_batch_exam_subject_id' => form_error('exam_group_class_batch_exam_subject_id'),
);
$array = array('status' => 0, 'error' => $data);
echo json_encode($array);
} else {
$exam_group_student_id = $this->input->post('exam_group_student_id');
$insert_array = array();
$update_array = array();
if (!empty($exam_group_student_id)) {
foreach ($exam_group_student_id as $exam_group_student_key => $exam_group_student_value) {
$attendance_post = $this->input->post('exam_group_student_attendance_' . $exam_group_student_value);
if (isset($attendance_post)) {
$attendance = $this->input->post('exam_group_student_attendance_' . $exam_group_student_value);
} else {
$attendance = "present";
}
$array = array(
'exam_group_class_batch_exam_subject_id' => $this->input->post('exam_group_class_batch_exam_subject_id'),
'exam_group_class_batch_exam_student_id' => $exam_group_student_value,
'attendence' => $attendance,
'get_ca1' => $this->input->post('exam_group_student_ca1_' . $exam_group_student_value),
'get_ca2' => $this->input->post('exam_group_student_ca2_' . $exam_group_student_value),
'get_ca3' => $this->input->post('exam_group_student_ca3_' . $exam_group_student_value),
'get_ca4' => $this->input->post('exam_group_student_ca4_' . $exam_group_student_value),
'get_exam' => $this->input->post('exam_group_student_exam_' . $exam_group_student_value),
'note' => $this->input->post('exam_group_student_note_' . $exam_group_student_value),
);
$insert_array[] = $array;
}
}
if ( intval($array['get_ca1'] +$array['get_ca2']+$array['get_ca3']+$array['get_ca4']+$array['get_exam'] ) > 0 ) {
$this->examgroupstudent_model->add_result($insert_array);
}
}
$array = array('status' => '1', 'error' => '', 'message' => $this->lang->line('success_message'));
echo json_encode($array);
}
}
I will like to first get the sum total of get_ca1+get_ca2+get_ca3+get_ca4+get_exam then if it is 0, don't insert.
Please how do I do this?
I don't think you can access the array value on the fly without any workaround, and you've placed the insert outside the foreach.
It would be best if you spent more time on these.
Code Indexing
Use proper IDE. Not like notepad.
Debug all and every line for errors.
Do like this.
Since you're not using batch insert, you can do it one by one.
$cal1 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$cal2 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$cal3 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$cal4 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$exam = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$total = $cal1 + $cal2 + $cal3 + $cal4 + $exam;
$array = array(
'exam_group_class_batch_exam_subject_id' => $this->input->post('exam_group_class_batch_exam_subject_id'),
'exam_group_class_batch_exam_student_id' => $exam_group_student_value,
'attendence' => $attendance,
'get_ca1' => $cal1,
'get_ca2' => $cal2,
'get_ca3' => $cal3,
'get_ca4' => $cal4,
'get_exam' => $exam,
'note' => $this->input->post('exam_group_student_note_' . $exam_group_student_value)
);
if ($total > 0) {
$this->examgroupstudent_model->add_result($array);
}
So final code will be
public function entrymarks()
{
$this->form_validation->set_error_delimiters('', '');
$this->form_validation->set_rules('exam_group_class_batch_exam_subject_id', 'Subject', 'required|trim|xss_clean');
if ($this->form_validation->run() == false) {
$data = array(
'exam_group_class_batch_exam_subject_id' => form_error('exam_group_class_batch_exam_subject_id'),
);
$array = array('status' => 0, 'error' => $data);
echo json_encode($array);
} else {
$exam_group_student_id = $this->input->post('exam_group_student_id');
$insert_array = array();
$update_array = array();
if (!empty($exam_group_student_id)) {
foreach ($exam_group_student_id as $exam_group_student_key => $exam_group_student_value) {
$attendance_post = $this->input->post('exam_group_student_attendance_' . $exam_group_student_value);
if (isset($attendance_post)) {
$attendance = $this->input->post('exam_group_student_attendance_' . $exam_group_student_value);
} else {
$attendance = "present";
}
$cal1 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$cal2 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$cal3 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$cal4 = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$exam = $this->input->post('exam_group_student_ca1_' . $exam_group_student_value);
$total = $cal1 + $cal2 + $cal3 + $cal4 + $exam;
$array = array(
'exam_group_class_batch_exam_subject_id' => $this->input->post('exam_group_class_batch_exam_subject_id'),
'exam_group_class_batch_exam_student_id' => $exam_group_student_value,
'attendence' => $attendance,
'get_ca1' => $cal1,
'get_ca2' => $cal2,
'get_ca3' => $cal3,
'get_ca4' => $cal4,
'get_exam' => $exam,
'note' => $this->input->post('exam_group_student_note_' . $exam_group_student_value)
);
if ($total > 0) {
$this->examgroupstudent_model->add_result($array);
}
}
}
}
$array = array('status' => '1', 'error' => '', 'message' => $this->lang->line('success_message'));
echo json_encode($array);
}
It turns out that students can actually start an exam even when the exam date is still to the future.
Normally, when a student clicks on the 'start exam' button when it's not time, there is usually a warning message but for some reason, it doesn't work again.
Students should be restricted from being able to start an exam when the date of the exam has not been reached
View
<button type="button" class="btn btn-info questions" data-recordid="<?php echo $exam->id; ?>" data-loading-text="<i class='fa fa-spinner fa-spin'></i> Please wait..."><i class="fa fa-bullhorn"></i> <?php echo $this->lang->line('start') . " " . $this->lang->line('exam') ?></button>
Teacher Controller
public function add() {
$this->form_validation->set_rules('exam', $this->lang->line('exam'), 'trim|required|xss_clean');
$this->form_validation->set_rules('attempt', $this->lang->line('attempt'), 'trim|required|xss_clean');
$this->form_validation->set_rules('exam_from', $this->lang->line('exam') . " " . $this->lang->line('from'), 'trim|required|xss_clean');
$this->form_validation->set_rules('exam_to', $this->lang->line('exam') . " " . $this->lang->line('to'), 'trim|required|xss_clean');
$this->form_validation->set_rules('duration', $this->lang->line('duration'), 'trim|required|xss_clean');
$this->form_validation->set_rules('description', $this->lang->line('description'), 'trim|required|xss_clean');
$this->form_validation->set_rules('passing_percentage', $this->lang->line('percentage'), 'trim|required|xss_clean');
if ($this->form_validation->run() == false) {
$msg = array(
'exam' => form_error('exam'),
'attempt' => form_error('attempt'),
'exam_from' => form_error('exam_from'),
'duration' => form_error('duration'),
'exam_to' => form_error('exam_to'),
'description' => form_error('description'),
'passing_percentage' => form_error('passing_percentage'),
);
$array = array('status' => 0, 'error' => $msg, 'message' => '');
} else {
$is_active = 0;
$publish_result = 0;
if (isset($_POST['is_active'])) {
$is_active = 1;
}
if (isset($_POST['publish_result'])) {
$publish_result = 1;
}
$idd = $this->session->userdata('admin');
$insert_data = array(
'exam' => $this->input->post('exam'),
'attempt' => $this->input->post('attempt'),
'exam_from' => date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('exam_from'))),
'exam_to' => date('Y-m-d', $this->customlib->datetostrtotime($this->input->post('exam_to'))),
'duration' => $this->input->post('duration'),
'description' => $this->input->post('description'),
'session_id' => $this->setting_model->getCurrentSession(),
'is_active' => $is_active,
'publish_result' => $publish_result,
'passing_percentage' => $this->input->post('passing_percentage'),
'teacher_id' => $idd['id'],
);
$id = $this->input->post('recordid');
if ($id != 0) {
$insert_data['id'] = $id;
}
$this->onlineexam_model->add($insert_data);
$array = array('status' => 1, 'error' => '', 'message' => $this->lang->line('success_message'));
}
echo json_encode($array);
}
user controller
public function startexam____($id) {
$data = array();
$this->session->set_userdata('top_menu', 'Hostel');
$this->session->set_userdata('sub_menu', 'hostel/index');
$questionOpt = $this->customlib->getQuesOption();
$data['questionOpt'] = $questionOpt;
$onlineexam_question = $this->onlineexam_model->getExamQuestions($id);
$data['examquestion'] = $onlineexam_question;
$this->load->view('layout/student/header');
$this->load->view('user/onlineexam/startexam', $data);
$this->load->view('layout/student/footer');
}
public function getExamForm() {
$data = array();
$question_status = 0;
$recordid = $this->input->post('recordid');
$exam = $this->onlineexam_model->get($recordid);
$data['questions'] = $this->onlineexam_model->getExamQuestions($recordid);
$student_current_class = $this->customlib->getStudentCurrentClsSection();
$student_session_id = $student_current_class->student_session_id;
$onlineexam_student = $this->onlineexam_model->examstudentsID($student_session_id, $exam->id);
$data['onlineexam_student_id'] = $onlineexam_student;
$getStudentAttemts = $this->onlineexam_model->getStudentAttemts($onlineexam_student->id);
$data['question_status'] = 0;
if (strtotime(date('Y-m-d H:i:s')) >= strtotime(date($exam->exam_to . ' 23:59:59'))) {
$question_status = 1;
$data['question_status'] = 1;
} else if ($exam->attempt > $getStudentAttemts) {
$this->onlineexam_model->addStudentAttemts(array('onlineexam_student_id' => $onlineexam_student->id));
} else {
$question_status = 1;
$data['question_status'] = 1;
}
$questionOpt = $this->customlib->getQuesOption();
$data['questionOpt'] = $questionOpt;
$pag_content = $this->load->view('user/onlineexam/_searchQuestionByExamID', $data, true);
echo json_encode(array('status' => 0, 'exam' => $exam, 'page' => $pag_content, 'question_status' => $question_status));
}
Really need your support on this one.
This works on intranet not until we decided to upload it on public.
Im using Codeigniter + SQL Server + Apache
This how it should work:
upload the excel file, read the content, save to database and send an email & sms.
But:
Everytime I upload the excel file after 3 Mins it stops and got this error written on Developer Opt->Network Tab:
"Network Error (tcp_error)
A communication error occurred: ""
The Web Server may be down, too busy, or experiencing other problems preventing it from responding to requests. You may wish to try again at a later time."
Here's my code:
public function do_upload()
{
set_time_limit(0);
ignore_user_abort(1);
$accID = $this->input->get('acc');
$rmi = $this->input->get('rmi');
$spInst = $this->input->get('spInst');
$dateReq = '';
$dateReqq = $this->input->get('dateReq');
if($dateReqq==null or $dateReqq==''){
$dateReq = date('Y-m-d');
}else{
$dateReq = $this->input->get('dateReq');
}
$dateNow = date("F_d_Y__h_i_s__A");
$status = "";
$msg = "";
$file_element_name = 'file';
$file_name = '';
if ($status != "error")
{
$config['upload_path'] = 'c:/xampp/htdocs/eDR/assets/uploads/';
$config['allowed_types'] = 'xlsx';
$config['max_size'] = 60000;
$config['overwrite'] = TRUE;
$config['remove_spaces'] = TRUE;
$config['file_name'] = uniqid('file')."_". $dateNow;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name))
{
$status = FALSE;
$msg = $this->upload->display_errors('', '');
}
else
{
$data = $this->upload->data();
//$file_id = $this->files_model->insert_file($data['file_name'], $_POST['title']);
//if($file_id)
//{
$file_name = $data['file_name'];
$file = "c:/xampp/htdocs/eDR/assets/uploads/" . $file_name;
$this->do_read($file,$accID,$rmi,$spInst,$dateReq);
$status = TRUE;
$msg = "File successfully uploaded";
//}
//else
// {
// unlink($data['full_path']);
// $status = "error";
// $msg = "Something went wrong when saving the file, please try again.";
// }
}
#unlink($_FILES[$file_element_name]);
}
echo json_encode(array('status' => $status, 'msg' => $msg, 'name' => $file_name));
}
public function do_read($file,$accID,$rmi,$spInst,$dateReq){
//load the excel library
$this->load->library('excel');
//read file from path
$objPHPExcel = PHPExcel_IOFactory::load($file);
//get only the Cell Collection
$cell_collection = $objPHPExcel->getActiveSheet()->getCellCollection();
//extract to a PHP readable array format
foreach ($cell_collection as $cell) {
$column = $objPHPExcel->getActiveSheet()->getCell($cell)->getColumn();
$row = $objPHPExcel->getActiveSheet()->getCell($cell)->getRow();
$data_value = $objPHPExcel->getActiveSheet()->getCell($cell)->getValue();
//header will/should be in row 1 only. of course this can be modified to suit your need.
//if ($row == 1) {
// $header[$row][$column] = $data_value;
//} else {
$arr_data[$row][$column] = $data_value;
//}
}
//send the data in an array format
//$data['header'] = $header;
$drCount = ($this->up->get_DRcount($accID));
$date = date("F d, Y h:i: s A");
$data['values'] = $arr_data;
$last = count($arr_data) - 1;
$totalQty = 0;
$abbr = $this->up->get_Abbr($accID);
$TATnAGING = '';
$dAdd ='';
$posReq='';
$reqD;
foreach ($arr_data as $i => $row)
{
if( empty($row['B']) or
empty($row['C']) or
empty($row['D']) or
empty($row['E']) or
empty($row['F']) or
empty($row['G']) or
empty($row['H']) or
empty($row['I']) or
empty($row['J']) or
empty($row['K'])
){
$msg = 'B = ' . $row['B'] . ' C = ' . $row['C'] . ' D = ' . $row['D'] . ' E = ' . $row['E'] . ' F = ' . $row['F'] . ' G = ' . $row['G'] . ' H = ' . $row['H'] . ' I = ' . $row['I']
. ' J = ' . $row['J'] . ' K = ' . $row['K'] ;
$status = FALSE;
echo json_encode(array('status' => $status, 'msg'=>$msg));
exit();
}
}
foreach ($arr_data as $i => $row)
{
try {
$reqDatee = date('F d, Y', strtotime($dateReq));
$start = new DateTime( $reqDatee );
$end = new DateTime(date("F d, Y"));
$oneday = new DateInterval("P1D");
$days = array();
$data1 = "7.5";
foreach(new DatePeriod($start, $oneday, $end->add($oneday)) as $day) {
$day_num = $day->format("N"); /* 'N' number days 1 (mon) to 7 (sun) */
if($day_num < 6) { /* weekday */
$days[$day->format("Y-m-d")] = $data1;
}
}
$TATnAGING = count($days). ' day/s';
$dAdd = trim(strtoupper($row['D']));
$posReq = trim(strtoupper($row['B']));
$reqD = $dateReq;
$isFirst = ($i == 0);
$isLast = ($i == $last);
$id = $this->session->userdata('username');
$totalQty += $row['G'];
} catch (Exception $e) {
$msg = 'Caught exception: '. $e->getMessage(). "\n";
$status = FALSE;
echo json_encode(array('status' => $status, 'error'=>$msg));
exit();
}
if($i>1){
$data1 = array();
try {
if(trim(strtoupper($row['B']))=='YES' or trim(strtoupper($row['B']))=='Y'){
$data1 = array(
"drRef" => $abbr . '2017' . sprintf("%07d", ($drCount + 1)),
"postReq" => trim(strtoupper($row['B'])),
"reqDate" => $dateReq,
"reqBy" => trim(strtoupper($row['C'])),
"deliveryAcc" => trim(strtoupper($row['D'])),
"matCode" => trim(strtoupper($row['E'])),
"matDescription" => trim(strtoupper($row['F'])),
"qty" => $row['G'],
"UOM" => trim(strtoupper($row['H'])),
"location" => trim(strtoupper($row['I'])),
"postRef" => '',
// "postDate" => date("F d, Y h:i:s A"),
// "postBy" => $this->session->userdata['name'],
"status" => 'PENDING FOR POSTING',
// "TAT" => trim(strtoupper($row['O'])),
// "AGING" => trim(strtoupper($row['P'])),
"userID" => $id,
'addedBy' => $this->session->userdata('name'),
'addedUsing' => gethostbyaddr($_SERVER['REMOTE_ADDR']),
'dateAdded' => $date,
'seqNo' => uniqid(),
'accID' => $accID,
'fromIMEI' => trim(strtoupper($row['J'])),
'toIMEI' => trim(strtoupper($row['K'])),
);
}else{
$data1 = array(
"drRef" => $abbr .'2017' . sprintf("%07d", ($drCount + 1)),
"postReq" => trim(strtoupper($row['B'])),
"reqDate" => $dateReq,
"reqBy" => trim(strtoupper($row['C'])),
"deliveryAcc" => trim(strtoupper($row['D'])),
"matCode" => trim(strtoupper($row['E'])),
"matDescription" => trim(strtoupper($row['F'])),
"qty" => $row['G'],
"UOM" => trim(strtoupper($row['H'])),
"location" => trim(strtoupper($row['I'])),
"postRef" => '',
"postDate" => date("F d, Y h:i:s A"),
"postBy" => $this->session->userdata['name'],
"status" => 'POSTED',
"TAT" => $TATnAGING,
"userID" => $id,
'addedBy' => $this->session->userdata('name'),
'addedUsing' => gethostbyaddr($_SERVER['REMOTE_ADDR']),
'dateAdded' => $date,
'seqNo' => uniqid(),
'accID' => $accID,
'fromIMEI' => trim(strtoupper($row['J'])),
'toIMEI' => trim(strtoupper($row['K'])),
);
}
} catch (Exception $e) {
$msg = 'Caught exception: '. $e->getMessage(). "\n";
$status = FALSE;
echo json_encode(array('status' => $status, 'error'=>$msg));
exit;
}
$insert = $this->up->save($data1);
$data1 = array();
}
}
if($posReq=='YES' or $posReq=='Y'){
$data1 = array(
'drRef' => $abbr . '2017' . sprintf("%07d", ($drCount + 1)),
'accID' => $accID,
'userID' => $this->session->userdata['id'],
// 'postRef' => trim(strtoupper($row['K'])),
// 'postBy' => $this->session->userdata['name'],
// 'postDate' => $date,
'totQty' => $totalQty,
'status' => 'PENDING FOR POSTING',
'isPosted' => 'No',
'isApproved' => 'Pending',
'approverID' => $this->session->userdata('head'),
'postReq' => $posReq,
'reqDate' => $reqD,
'deliveryAdd' => $dAdd,
'reason' => urldecode($rmi),
'spInst' => urldecode($spInst),
);
}else{
$data1 = array(
'drRef' => $abbr . '2017' . sprintf("%07d", ($drCount + 1)),
'accID' => $accID,
'userID' => $this->session->userdata['id'],
//'postRef' => $this->session->userdata('username'),
'postBy' => $this->session->userdata['name'],
'postDate' => $date,
'totQty' => $totalQty,
'status' => 'POSTED',
'isPosted' => 'Yes',
'isApproved' => 'Pending',
'approverID' => $this->session->userdata('head'),
'postReq' => $posReq,
'tat' => $TATnAGING ,
'reqDate' => $reqD,
'deliveryAdd' => $dAdd,
'reason' => urldecode($rmi),
'spInst' => urldecode($spInst),
);
}
$insert = $this->up->saveOrder($data1);
$drRef = $abbr . '2017' . sprintf("%07d", ($drCount + 1));
$id = $this->up->get_Data('head','tblUser','userID',$this->session->userdata('id'));
$recepient = $this->up->get_Data('email','tblUser','userID',$id);
$name = $this->up->get_Data('name','tblUser','userID',$id);
$config = Array(
'protocol' => 'smtp',
'smtp_host' => '182.50.151.61',
'smtp_port' => 587,
'smtp_user' => 'user',
'smtp_pass' => 'pass',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$this->email->from('eDR#domain.com', 'e - Delivery Receipt');
$this->email->to($recepient);
//$this->email->subject('eDR Notifications');
$this->email->subject('eDR Notification < DR Request >');
$message = 'Message';
$this->email->message($message);
$result = $this->email->send();
// if (!$result) {
// $this->email->print_debugger();
// }
$receiver = $this->up->get_Data('phoneNum','tblUser','userID',$this->session->userdata('head'));
$sms = array(
'receiver' => $receiver,
'msg' => 'message',
'status' => 'Send',
);
$this->up->sendSMS($sms);
}
Thanks.
I solved this problem via CRON job or calling cmd command on my PHP script so that it will execute the query on server itself really fast. :)
I'm only using a small part of this function actually but I wanted to post it all to provide the big picture. There is a part of the query in this function that finds recent attachments a user has posted to the forums. The block is on the user profile. IT works but the problem is ... it's VERY slow!! Core attachments locks up for 30+ seconds and makes my site unusable.
Any one who could help it would be much appreciated.
private function getAttImages($limit, $forumIds = 0, $fidsReverse = false, $topicIds = 0, $membersIds = 0, $order = 'attach_date', $sort = 'desc', $group = null)
{
$fids = '';
if ($forumIds)
{
$r = '';
if ($fidsReverse)
{
$r = ' NOT ';
}
if (is_array($forumIds))
{
$forumIds = implode(',', $forumIds);
}
$fids = ' AND forums_topics.forum_id ' . $r . ' IN (' . $forumIds . ')';
}
$tids = '';
if ($topicIds)
{
$tids = ' AND forums_topics.tid IN (' . $topicIds . ')';
}
$mids = '';
if ($membersIds)
{
$mids = ' AND core_attachments.attach_member_id IN (' . $membersIds . ')';
}
$whereT = array();
$joinsT = array();
$findInPosts = ' AND ' . \IPS\Db::i()->findInSet('queued', array('0'));
$joinsT[] = array(
'select' => 'forums_posts.*',
'from' => 'forums_posts',
'where' => array("forums_posts.pid=core_attachments_map.id2" . $findInPosts),
);
$findInTopics = ' AND ' . \IPS\Db::i()->findInSet('approved', array('1'));
$joinsT[] = array(
'select' => 'forums_topics.*',
'from' => 'forums_topics',
'where' => array("forums_topics.tid=forums_posts.topic_id" . $findInTopics . $fids . $tids),
);
$select = 'core_attachments.attach_id AS custom_data, core_attachments.*';
if ($group)
{
$select = 'core_attachments.attach_id AS custom_data, COUNT(attach_is_image) as cnt_images, SUM(attach_hits) as summ_attach_hits, core_attachments.*';
}
$joinsT[] = array(
'select' => $select,
'from' => 'core_attachments',
'where' => array('core_attachments.attach_is_image=1 AND core_attachments.attach_is_archived=0 AND core_attachments.attach_id=core_attachments_map.attachment_id' . $mids),
);
$joinsT[] = array( 'select' => 'core_members.member_id, core_members.member_group_id, core_members.mgroup_others, core_members.name, core_members.members_seo_name',
'from' => 'core_members',
'where' => array('core_attachments.attach_member_id=core_members.member_id' . $mids),
);
$joinsT[] = array( 'select' => 'core_permission_index.perm_id',
'from' => 'core_permission_index',
'where' => array("core_permission_index.app='forums' AND core_permission_index.perm_type='forum' AND core_permission_index.perm_type_id=forums_topics.forum_id"),
);
$groupT = $group;
$whereT[] = array(
"core_attachments_map.location_key='forums_Forums' AND " .
\IPS\Db::i()->findInSet('perm_view', array_merge(array(\IPS\Member::loggedIn()->member_group_id), array_filter(explode(',', \IPS\Member::loggedIn()->mgroup_others)))) . " OR perm_view='*'" .
$fids . $tids . $mids
);
$table = new \IPS\Helpers\Table\Db(
'core_attachments_map',
\IPS\Http\Url::internal('app=core&module=system&controller=nbattachpictures', 'front', 'nbattachpictures'),
$whereT,
$groupT
);
$table->joins = $joinsT;
$table->limit = $limit;
$table->sortBy = $order;
$table->sortDirection = $sort;
$table->rowsTemplate = array(\IPS\Theme::i()->getTemplate('plugins', 'core', 'global'), 'nbAttachmentsBlocksRows');
$table->parsers = array(
'custom_data' => function( $val, $row )
{
return array(
'topic_data' => \IPS\Http\Url::internal("app=forums&module=forums&controller=topic&id={$row['tid']}", 'front', 'forums_topic', array($row['title_seo'])),
'summ_attach_hits' => $row['summ_attach_hits'],
'jewel' => $this->attachJewel($row['summ_attach_hits']),
);
},
);
return $table;
}
I'm working on a php web application for a website, and I would like to pass some variables from one php file to another. I have tried the old fashion way with the include file but was not successful. I also tried to set the variables in global scope but still not working. The code in first.php file is:
function rc_getAvailableVehicles($pickup_timestamp, $return_timestamp, $vehicle_classes=array()) {
global
$wpdb;
$rc_currency = RC_Registry::get('rc_currency');
$where_classes = "";
if ($vehicle_classes) {
foreach($vehicle_classes as $vehicle_class) {
$where_classes[] = " v.class = '". $wpdb->escape($vehicle_class) ."'";
}
$where_classes = "AND (".implode(' OR ', $where_classes).") ";
}
$sql = "SELECT *
FROM ".$wpdb->rc_vehicles." v
WHERE v.quantity > (SELECT COUNT(*) FROM ".$wpdb->rc_bookings." b WHERE b.vehicle_id = v.vehicle_id AND ((UNIX_TIMESTAMP(b.pickup_date) >= '". (int)$pickup_timestamp ."' AND UNIX_TIMESTAMP(b.pickup_date) < '". (int)$return_timestamp ."') || (UNIX_TIMESTAMP(b.pickup_date) < '". (int)$pickup_timestamp ."' AND UNIX_TIMESTAMP(b.return_date) >= '". (int)$pickup_timestamp ."')) AND (b.status != 'new' AND b.status != 'canceled') AND b.trash = '0') ".$where_classes."AND v.status = '1' AND v.archive = '0'
ORDER BY v.rent ASC";
$results = $wpdb->get_results($sql,ARRAY_A);
$vehicles = array();
$rental_days = ceil(($return_timestamp-$pickup_timestamp)/91800);
$xfee = get_field('another_location_fee');
$xfee2 = get_field('return_to_another_location_fee_2');
if ($results) {
foreach ($results as $result) {
if ($result['image'] && file_exists(RC_UPLOADS_DIR . "vehicle_" . $result['image'])) {
$image = RC_UPLOADS_URL . 'vehicle_' . $result['image'];
$image_thumb = RC_UPLOADS_URL . 'cache/' . rc_image_resize(RC_UPLOADS_DIR . "vehicle_" . $result['image'], 220, 160);
} else {
$image = '';
$image_thumb = '';
}
$result['description'] = do_shortcode($result['description']);
$description = html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8');
global $GeneralPrice, $discount_price, $rent1, $rent5;
include_once ('file2.php');
//$GeneralPrice = $result['rent'];
$rent1 = $vehicle_meta['rent1'];
$rent2 = $vehicle_meta['rent2'];
$rent3 = $vehicle_meta['rent3'];
$rent4 = $vehicle_meta['rent4'];
$rent5 = $vehicle_meta['rent5'];
$rent6 = $vehicle_meta['rent6'];
$rent7 = $vehicle_meta['rent7'];
$rent8 = $vehicle_meta['rent8'];
$rent9 = $vehicle_meta['rent9'];
$rent10 = $vehicle_meta['rent10'];
$rent11 = $vehicle_meta['rent11'];
$rent12 = $vehicle_meta['rent12'];
$rent13 = $vehicle_meta['rent13'];
$rent14 = $vehicle_meta['rent14'];
$rent15 = $vehicle_meta['rent15'];
$rent16 = $vehicle_meta['rent16'];
$rent17 = $vehicle_meta['rent17'];
$rent18 = $vehicle_meta['rent18'];
$rent19 = $vehicle_meta['rent19'];
$rent20 = $vehicle_meta['rent20'];
$rent21 = $vehicle_meta['rent21'];
$rent22 = $vehicle_meta['rent22'];
$rent23 = $vehicle_meta['rent23'];
$rent24 = $vehicle_meta['rent24'];
$rent25 = $vehicle_meta['rent25'];
$rent26 = $vehicle_meta['rent26'];
$rent27 = $vehicle_meta['rent27'];
$rent28 = $vehicle_meta['rent28'];
$rent29 = $vehicle_meta['rent29'];
$rent30 = $vehicle_meta['rent30'];
$rent31 = $vehicle_meta['rent31'];
$rent32 = $vehicle_meta['rent32'];
$rent33 = $vehicle_meta['rent33'];
$rent34 = $vehicle_meta['rent34'];
$rent35 = $vehicle_meta['rent35'];
$rent36 = $vehicle_meta['rent36'];
$vehicle_meta = rc_getVehicleMeta($result['vehicle_id']);
$vehicles[$result['vehicle_id']] = array(
'vehicle_id' => $result['vehicle_id'],
'title' => $result['manufacturer']." ".$result['series'],
'manufacturer' => $result['manufacturer'],
'series' => $result['series'],
'year' => $result['year'],
'class' => $result['class'],
'image' => $image,
'image_thumb' => $image_thumb,
'description' => $description,
'seats' => $vehicle_meta['seats'],
'doors' => $vehicle_meta['doors'],
'baggages' => $vehicle_meta['baggages'],
'conditioning' => $vehicle_meta['conditioning'],
'transmission' => $vehicle_meta['transmission'],
'rent1' => $vehicle_meta['rent1'],
'rent2' => $vehicle_meta['rent2'],
'rent3' => $vehicle_meta['rent3'],
'rent4' => $vehicle_meta['rent4'],
'rent5' => $vehicle_meta['rent5'],
'rent6' => $vehicle_meta['rent6'],
'rent7' => $vehicle_meta['rent7'],
'rent8' => $vehicle_meta['rent8'],
'rent9' => $vehicle_meta['rent9'],
'rent10' => $vehicle_meta['rent10'],
'rent11' => $vehicle_meta['rent11'],
'rent12' => $vehicle_meta['rent12'],
'rent13' => $vehicle_meta['rent13'],
'rent14' => $vehicle_meta['rent14'],
'rent15' => $vehicle_meta['rent15'],
'rent16' => $vehicle_meta['rent16'],
'rent17' => $vehicle_meta['rent17'],
'rent18' => $vehicle_meta['rent18'],
'rent19' => $vehicle_meta['rent19'],
'rent20' => $vehicle_meta['rent20'],
'rent21' => $vehicle_meta['rent21'],
'rent22' => $vehicle_meta['rent22'],
'rent23' => $vehicle_meta['rent23'],
'rent24' => $vehicle_meta['rent24'],
'rent25' => $vehicle_meta['rent25'],
'rent26' => $vehicle_meta['rent26'],
'rent27' => $vehicle_meta['rent27'],
'rent28' => $vehicle_meta['rent28'],
'rent29' => $vehicle_meta['rent29'],
'rent30' => $vehicle_meta['rent30'],
'rent31' => $vehicle_meta['rent31'],
'rent32' => $vehicle_meta['rent32'],
'rent33' => $vehicle_meta['rent33'],
'rent34' => $vehicle_meta['rent34'],
'rent35' => $vehicle_meta['rent35'],
'rent36' => $vehicle_meta['rent36'],
'total_price' => $rc_currency->format((($rental_days*$GeneralPrice)-(($rental_days*$GeneralPrice) * ($discount_price)/100)+ $utime)),
'total_price_return_fee' => $rc_currency->format((($rental_days*$result['rent']) - ($rental_days*$result['rent']) * ($discount_price)/100)+ $xfee),
'total_price_return_fee2' => $rc_currency->format((($rental_days*$result['rent']) - ($rental_days*$result['rent'])*($discount_price)/100)+ $xfee2),
'daily_price' => $rc_currency->format((($GeneralPrice)-($GeneralPrice)*($discount_price)/100)+ ($utime / $rental_days)),
'daily_price_return_fee' => $rc_currency->format(($result['rent']-($result['rent'])* ($discount_price)/100)+ ($xfee / $rental_days)),
'daily_price_return_fee2' => $rc_currency->format(($result['rent']-($result['rent'])*($discount_price)/100) + ($xfee2 / $rental_days))
);
}
}
return $vehicles;
}
and I want to echo all the $rent variables in file2.php
I have tried the
echo $rent; without success!
You have problems with the order of the code
$vehicle_meta = rc_getVehicleMeta($result['vehicle_id']);
Should be BEFORE you populate rent variables, and
include_once ('file2.php');
Should be AFTER you populated rent variables.
You need to call a function in file1.php that exists in file2.php
ex. in file1.php you could call the function return_rent
return_rent($rent);
in file2 then you make the function
function return_rent($var){
echo $rent;
}
$pass = "anything";
include_once ('file2.php');
From file2.php you can access $pass variable.