我想从我的目录中打开pdf文件。如果文件存在,它将从我的目录打开它,它的工作原理。但是,如果pdf文件不存在,我希望它返回测试,就像在我的代码中,它仍然无法正常工作。请帮我。谢谢
代码视图如下:
<?php
if ($this->pos != 1) {
if (!$id) {
?>
<tr>
<td colspan="2" >
<label><input type="checkbox" name="use_form" value="1"/>make a quotation form after save this transaction</label>
</td>
</tr>
<?php } else { ?>
<?php if (!$quotation) { ?>
<tr>
<td colspan="5">
<a href="javascript:show_popUp('<?php echo base_url(); ?>index.php/service_tracking/trans_service/quotation/<?php echo $id; ?>')"> Create Quotation</a>
</td>
</tr>
<?php } else { ?>
<?php $file = base_url()."quotation/".$quotation.".pdf"; ?>
<?php if(file_exists($file)) {
$file = $file;
}
else {
$file = "test";
} ?>
<tr>
<td colspan="2">
<a target="_blank" href="<?php echo base_url(); ?>quotation/<?php echo $quotation;?>.pdf">View Quotation </a>
</td>
<td colspan="3">
<a href="javascript:show_popUp('<?php echo base_url(); ?>index.php/service_tracking/trans_service/edit_quotation/<?php echo $id; ?>')"> Revised Quotation</a>
</td>
</tr>
<?php
}
}
} ?>
控制器代码如下 `
protected $active_user;
function __construct() {
parent::Controller();
$this->utility->cek_session();
$this->active_user = $this->session->userdata('active_user');
$this->load->library('form');
$this->load->model('service_tracking/trans_service_model');
$this->load->library('table_generator');
$this->load->model('service_tracking/service_status_model');
$this->load->model('service_tracking/quotation_model');
}
function index() {
$data['content'] = "template/frm_filter";
$data['control_panel'] = base_url() . "index.php/service_tracking/trans_service/control_panel/";
$data['title'] = "Service Tracking System > <a href='manage_trans'>Manage Trans</a> > In House Service Transaction";
$data['controller'] = base_url() . "index.php/service_tracking/trans_service/";
$data['form'] = "service_tracking/trans_service/form/";
$data['table'] = $data['controller'] . "table";
$data['report'] = true;
$this->load->view('template/main_service', $data);
}
function pending() {
$data['content'] = "template/frm_filter";
$data['control_panel'] = base_url() . "index.php/service_tracking/trans_service/control_panel/";
$data['title'] = "Service Tracking System > <a href='../manage_trans'>Manage Trans</a> > (Pending) In House Service Transaction";
$data['controller'] = base_url() . "index.php/service_tracking/trans_service/";
$data['form'] = "service_tracking/trans_service/form/";
$data['table'] = $data['controller'] . "table/pending";
$data['report'] = true;
$this->load->view('template/main_service', $data);
}
function form($fill = '', $java = '') {
$data['action'] = base_url() . "index.php/service_tracking/trans_service/save";
if (!empty($fill)) {
$fill = $this->trans_service_model->fill_data($fill);
$data['action'] = base_url() . "index.php/service_tracking/trans_service/edit";
$data['id'] = $fill['id'];
}
if ($java == 'add') {
$data['java'] = "<script type='text/javascript'>window.opener.do_filter();</script>";
$data['java'] .= "<script type='text/javascript'>window.close();</script>";
}
if ($java == 'use_form') {
$data['java'] = "<script type='text/javascript'>window.opener.do_filter();</script>";
$data['java'] = "<script type='text/javascript'>window.opener.show_quotation('" . $fill['id'] . "');</script>";
$data['java'] .= "<script type='text/javascript'>window.close();</script>";
}
$pos = $this->session->userdata('active_user');
$rule = $this->service_status_model->get_rule($pos['id_position']);
$data['serial_no'] = $this->form->choose('serial_no', $fill['id_ticket_detail'], $fill['no_serial']);
$data['quotation'] = base_url() . "index.php/service_tracking/trans_service/quotation";
$data['content'] = "service_tracking/trans_service";
$data['controller'] = base_url() . "index.php/service_tracking/trans_service/";
$data['title'] = "IN HOUSE TRANSACTION FORM";
$radio = array(
array(
'value' => 'waranty',
'name' => 'Waranty'
),
array(
'value' => 'no_waranty',
'name' => 'No Waranty'
),
array(
'value' => 'under_contract',
'name' => 'Under Contract'
)
);
$data['service_desc'] = $this->form->radio('service_desc', $radio, $fill['service_desc']);
$data['use_new'] = false;
$setting = array(
'db' => 'st_service_status',
'id' => 'id',
'value' => 'status_name',
'menu_id' => '1'
);
$tekhnisi = array(
'db' => 'st_tekhnisi',
'id' => 'id',
'value' => 'name');
$data['id_status'] = $this->form->drop_down_db1('id_status', $fill['id_status_service'], $setting);
$data['id_tekhnisi'] = $this->form->drop_down_db('id_tekhnisi', $fill['id_tekhnisi'], $tekhnisi);
$data['RMA_date'] = $this->form->calendar('RMA_date', $fill['RMA_date']);
$data['RMA_return_date'] = $this->form->calendar('RMA_return_date', $fill['RMA_return_date']);
$data['RMA_number'] = $this->form->text_box('RMA_number', $fill['RMA_number']);
$data['action_in'] = $this->form->text_box('action_in', $fill['action_in']);
$data['customer_return_date'] = $this->form->calendar('customer_return_date', $fill['customer_return_date']);
$data['sparepart_memo'] = $this->form->text_area('sparepart_memo', $fill['sparepart_memo'], 50, 5);
$data['quotation'] = $this->quotation_model->cek_form($fill['id']);
$data['id_ticket'] = $fill['id_ticket_detail'];
$data['id'] = $fill['id'];
$data['unique_id'] = $this->form->hidden('unique_id', $this->utility->session_id());
$rule = array(
array(
'id' => 'serial_no',
'name' => 'SERIAL NUMBER'
),
array(
'id' => 'id_status',
'name' => 'SERVICE STATUS'
)
);
$data['cek'] = $this->form->form_rule($rule);
$data['width'] = 600;
$this->load->view('template/form', $data);
}
function cancel() {
$this->form();
}
function table($param = null) {
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$page = $sort = $dir = '';
$setting = array();
if($param)
$param = true;
if (isset($_POST['page']))
$page = $_POST['page'];
if (isset($_POST['sort']))
$sort = $_POST['sort'];
if (isset($_POST['dir']))
$dir = $_POST['dir'];
if (isset($_POST['limit']))
$limit = $_POST['limit'];
if (isset($_POST['setting'])) {
$setting = $_POST['setting'];
$limit = $_POST['limit'] = 'all';
}
$table_setting = array(
array(
'name' => 'unique_id',
'type' => 'none'
),
array(
'name' => 'customer_name',
'type' => 'none'
),
array(
'name' => 'product_name',
'type' => 'none'
),
array(
'name' => 'no_serial',
'type' => 'none'
),
array(
'name' => 'ticket_date',
'type' => 'none'
),
array(
'name' => 'status_name',
'type' => 'none'
),
array(
'name' => 'standard_date',
'type' => 'none'
),
array(
'name' => 'name',
'type' => 'none'
),
array(
'name' => 'customer_return_date',
'type' => 'none'
),
array(
'name' => 'update_date',
'type' => 'none'
),
array(
'name' => 'is_quoted',
'type' => 'check'
)
);
$list = $table_setting;
$header = array('Ticket No.', 'Company Name', 'Product Name', 'No. Serial', 'Date In', 'Status', 'Estimated Finish Day(s)', 'Engineer', 'Customer Return Date', 'Update Date', 'Quoted');
$total = $this->trans_service_model->totalData($setting, $param);
if (!$_POST['is_report']) {
$return = $this->trans_service_model->all_data($page, $sort, $dir, $limit, $setting, $param);
$return = $this->table_generator->tableGenerator($return, $list, $header, $total, 'no_serial');
$_POST['setting'] = "";
echo $return;
} else {
$_SESSION['setting'] = $setting;
$_SESSION['sort'] = $sort;
$_SESSION['dir'] = $dir;
$_SESSION['list'] = $list;
$_SESSION['header'] = $header;
$_SESSION['total'] = $total;
$year = "any";
$period = "any";
$month = "any";
if ($setting['year'])
$year = $setting['year'];
if ($setting['period']) {
if ($setting['period'] == 1)
$add = "st";
else if ($setting['period'] == 2)
$add = "nd";
else if ($setting['period'] == 3)
$add = "rd";
else
$add = "th";
$period = $setting['period'] . "<sup>" . $add . "</sup>";
$month = "-";
}
if ($setting['month']) {
$month_array = array('January', 'Febuary', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
$month = $month_array[($setting['month'] - 1)];
$period = "-";
}
$title = "<table cellpadding='3' border='1' cellspacing = '-1' width='100%'>
<tr>
<td colspan='2' valign='middle' align='center'>
<div style='font-size : 25px'><b>Service Transaction Report</b></div>
</td>
</tr>
<tr>
<td width='10%'>Year</td>
<td width='90%'>" . $year . "</td>
</tr>
<tr>
<td>Month</td>
<td>" . $month . "</td>
</tr>
<tr>
<td>Period</td>
<td>" . $period . "</td>
</tr>
</table>";
$_SESSION['title'] = $title;
if ($_POST['is_report'] == "pdf")
$type = "index/trans_service";
else if ($_POST['is_report'] == "excel")
$type = "excel/trans_service";
echo "<script type='text/javascript'>"
. "$('#frame_executor').attr('src', base_url + 'index.php/report/general/" . $type . "');"
. "</script>";
}
}
function control_panel() {
$merk_setting = array(
'db' => 'st_merk',
'id' => 'id',
'value' => 'merk_name'
);
$type_setting = array(
'db' => 'st_product_type',
'id' => 'id',
'value' => 'type_name'
);
$status_setting = array(
'db' => 'st_service_status',
'id' => 'id',
'value' => 'status_name'
);
$date_start = array(
'db' => 'st_trans_service',
'id' => 'id',
'value' => 'entry_date'
);
$date_end = array(
'db' => 'st_trans_service',
'id' => 'id',
'value' => 'service_date'
);
$tekhnisi_setting = array(
'db' => 'st_tekhnisi',
'id' => 'id',
'value' => 'tekhnisi_name'
);
$id_merk = $this->form->drop_down_db('id_merk', '', $merk_setting, "onchange='do_filter()'");
$id_product_type = $this->form->drop_down_db('id_product_type', '', $type_setting, "onchange='do_filter()'");
$id_status = $this->form->drop_down_db('id_status', '', $status_setting, "onchange='do_filter()'");
$start = $this->form->calendar('entry_date', '', $date_start, "onchange='do_filter()'");
$end = $this->form->calendar('service_date', '', $date_end, "onchange='do_filter()'");
$id_tekhnisi = $this->form->drop_down_db('id_tekhnisi', '', $tekhnisi_setting, "onchange='do_filter()'");
$filter = array(
array(
'title' => 'Year',
'content' => $this->form->tahun('year', '', "onchange='do_filter()'")
),
array(
'title' => 'Month',
'content' => $this->form->bulan('month', '', "onchange='do_filter()'")
),
array(
'title' => 'Period',
'content' => $this->form->period('period', "onchange='do_filter()'")
),
array(
'title' => 'Product Type',
'content' => $id_product_type
),
array(
'title' => 'Brand',
'content' => $id_merk
),
array(
'title' => 'Product Name',
'content' => $this->form->text_box('product_name', '', '35', " onkeyup='do_filter()' ")
),
array(
'title' => 'Customer',
'content' => $this->form->text_box('customer_name', '', '35', " onkeyup='do_filter()' ")
),
array(
'title' => 'Status',
'content' => $id_status
),
array(
'title' => 'Date Start',
'content' => $start
),
array(
'title' => 'Date End',
'content' => $end
),
array(
'title' => 'Serial No.',
'content' => $this->form->text_box('no_serial', '', '30', " onkeyup='do_filter()' ")
),
array(
'title' => 'Ticket No.',
'content' => $this->form->text_box('unique_id', '', '30', " onkeyup='do_filter()' ")
),
array(
'title' => 'Engineer Name',
'content' => $id_tekhnisi
),
);
$data['filter'] = $this->form->generate_filter($filter);
$data['data_management'] = true;
$this->load->view('template/platform', $data);
}
function delete() {
$id = $_POST['id'];
foreach ($id as $id_a)
$this->trans_service_model->delete_data($id_a);
echo "<script type='text/javascript'>do_filter();</script>";
}
function edit() {
$id_status = $_POST["id_status"];
$id_ticket_detail = $_POST["serial_no"];
$service_desc = $_POST['service_desc'];
$RMA_date = $_POST['RMA_date'];
$RMA_return_date = $_POST['RMA_return_date'];
$RMA_number = $_POST['RMA_number'];
$customer_return_date = $_POST['customer_return_date'];
$action_in = $_POST['action_in'];
$sparepart_memo = $_POST['sparepart_memo'];
$id = $_POST['id'];
$id_tekhnisi = $_POST['id_tekhnisi'];
$array = array(
$id_ticket_detail,
$id_status,
$service_desc,
$RMA_date,
$RMA_return_date,
$RMA_number,
$customer_return_date,
$action_in,
$sparepart_memo,
$id
);
$update_tekhnisi = array(
$id_tekhnisi, $id_ticket_detail
);
$sess = $this->session->userdata('active_user');
$this->pos = $sess['id_position'];
$this->trans_service_model->edit_data($array);
if ($this->pos != 1) {
$this->trans_service_model->edit_tekhnisi($update_tekhnisi);
}
$id_detail = $this->trans_service_model->edit_data($array);
echo "<script type='text/javascript'>do_filter();close_form();</script>";
}
function save() {
$id_status = $_POST["id_status"];
$id_ticket_detail = $_POST["serial_no"];
$service_desc = $_POST['service_desc'];
$RMA_date = $_POST['RMA_date'];
$RMA_return_date = $_POST['RMA_return_date'];
$RMA_number = $_POST['RMA_number'];
$customer_return_date = $_POST['customer_return_date'];
$action_in = $_POST['action_in'];
$sparepart_memo = $_POST['sparepart_memo'];
$array = array(
$id_ticket_detail,
$this->active_user['id'],
$id_status,
date("Y-m-d"),
date("h:i:s"),
$service_desc,
$RMA_date,
$RMA_return_date,
$RMA_number,
$customer_return_date,
$action_in,
$sparepart_memo,
$_POST['unique_id']
);
$this->trans_service_model->add_data($array);
if (!isset($_POST['submit'])) {
if (!$_POST['use_form'])
echo "<script type='text/javascript'>do_filter();close_form();</script>";
else {
$id = $this->trans_service_model->get_id($_POST['unique_id']);
echo "<script type='text/javascript'>do_filter();close_form();show_quotation('" . $id . "')</script>";
}
} else
echo "<script type='text/javascript'>do_filter();close_form();</script>";
// bikin pdf
$this->send_email($id_ticket_detail, $id_status);
}
function uniq_code() {
$unique = $this->quotation_model->get_last_id();
$unique++;
if (strlen($unique) == 1)
$unique = '0' . $unique;
$unique = "Q" . date("ymd") . $unique;
return $unique;
}
function quotation($id = '', $fill = '', $java = '') {
$data['action'] = base_url() . "index.php/service_tracking/trans_service/save_quotation";
$data['form'] = "service_tracking/quotation_form";
$data['controller'] = base_url() . "index.php/service_tracking/trans_service/";
$data['title'] = "SERVICE QUOTATION FORM";
$data['use_new'] = false;
$data['no_quotation'] = $this->uniq_code();
$data['id_trans_service'] = $this->form->hidden('id_trans_service', $id);
$data['sales_code'] = $this->form->text_box('sales_code', '', 20);
$data['problem'] = $this->form->text_area('problem');
$data['note'] = $this->form->text_area('note');
$data['action_taken'] = $this->form->text_area('action_taken');
$data['service_charge'] = $this->form->number('service_charge', '', 12);
$data['part_no'] = $this->form->text_box('part_no', '', 13);
$data['desc'] = $this->form->text_box('desc', '', 35);
$data['qty'] = $this->form->number('qty', '', 5);
$data['price'] = $this->form->number('price', '', 12);
$data['discount'] = $this->form->number('discount', '', 3);
$setting = array(
array(
'name' => 'IDR',
'value' => 'IDR'
),
array(
'name' => 'USD',
'value' => 'USD'
)
);
$data['rate'] = $this->form->drop_down('rate', $setting);
$data['service_charge_rate'] = $this->form->drop_down('service_charge_rate', $setting);
$this->load->view('template/form2', $data);
}
function save_quotation() {
$detail = array();
if ($_POST['detail'])
$detail = $_POST['detail'];
$out = array(
'part_no' => $_POST['part_no'],
'desc' => $_POST['desc'],
'qty' => $_POST['qty'],
'price' => $_POST['price'],
'rate' => $_POST['rate'],
'discount' => $_POST['discount']
);
array_push($detail, $out);
$id_tekhnisi = $this->session->userdata('active_user');
$id_tekhnisi = $id_tekhnisi['id'];
$header = array(
$_POST['id_trans_service'],
$_POST['no_quotation'],
$_POST['problem'],
$_POST['action_taken'],
$_POST['remark'],
$_POST['payment'],
$_POST['service_charge'],
$_POST['service_charge_rate'],
$_POST['service_location'],
$_POST['note'],
date('Y-m-d'),
$_POST['sales_code'],
$id_tekhnisi
);
$this->quotation_model->add_header($header);
$id = $this->quotation_model->get_id($_POST['no_quotation']);
for ($i = 0; $i < count($detail); $i++) {
$detail[$i]['ammount'] = $detail[$i]['qty'] * $detail[$i]['price'];
$detail[$i]['id_header_quotation'] = $id;
$this->quotation_model->add_detail($detail[$i]);
}
echo "<script type='text/javascript'>
window.opener.create_pdf('" . $id . "');
window.opener.do_filter();
window.opener.close_form();
window.close();
</script>";
}
function sales_code() {
$unique = $this->quotation_model->get_sales_code();
return $unique;
}
function problem() {
$unique = $this->quotation_model->get_problem();
return $unique;
}
function action_taken() {
$unique = $this->quotation_model->get_action_taken();
return $unique;
}
function service_charge() {
$unique = $this->quotation_model->get_service_charge();
return $unique;
}
function note() {
$unique = $this->quotation_model->get_note();
return $unique;
}
function no_part() {
$unique = $this->quotation_model->get_no_part();
return $unique;
}
function description() {
$unique = $this->quotation_model->get_description();
return $unique;
}
function qty() {
$unique = $this->quotation_model->get_qty();
return $unique;
}
function price() {
$unique = $this->quotation_model->get_price();
return $unique;
}
function disc() {
$unique = $this->quotation_model->get_disc();
return $unique;
}
function uniq_code_rev() {
$unique = $this->quotation_model->get_last_id();
$unique++;
if (strlen($unique) == 1)
$unique = '0' . $unique;
$unique = "Q" . date("ymd") . $unique . " rev- " . $this->quotation_model->get_no_quotation();
return $unique;
}
function edit_quotation($id = '', $fill = '', $java = '') {
$data['action'] = base_url() . "index.php/service_tracking/trans_service/save_quotation";
$data['form'] = "service_tracking/quotation_form_1";
$data['controller'] = base_url() . "index.php/service_tracking/trans_service/";
$data['title'] = "EDIT SERVICE QUOTATION FORM";
$data['use_new'] = false;
$data['no_quotation'] = $this->uniq_code_rev();
$data['id_trans_service'] = $this->form->hidden('id_trans_service', $id);
$data['sales_code'] = $this->sales_code();
$data['problem'] = $this->problem();
$data['note'] = $this->note();
$data['action_taken'] = $this->action_taken();
$data['service_charge'] = $this->form->number('service_charge', '', 12);
$data['part_no'] = $this->no_part();
$data['description'] = $this->description();
$data['qty'] = $this->qty();
$data['price'] = $this->price();
$data['discount'] = $this->disc();
$setting = array(
array(
'name' => 'IDR',
'value' => 'IDR'
),
array(
'name' => 'USD',
'value' => 'USD'
)
);
$data['rate'] = $this->form->drop_down('rate', $setting);
$data['service_charge_rate'] = $this->form->drop_down('service_charge_rate', $setting);
$this->load->view('template/form2', $data);
var_dump($data);
exit;
}
function send_email($id_ticket, $id_status) {
$arr_day = array('Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu');
$arr_month = array('Januari', 'Febuari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'November', 'Desember');
$this->load->library('email');
$data = $this->trans_service_model->get_emaildata($id_ticket);
$status = $this->trans_service_model->get_status($id_status);
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.push.mobi';
$config['smtp_port'] = 25;
$config['smtp_user'] = 'yani@sgp-dkp.com';
$config['smtp_pass'] = 'yaniya';
$config['priority'] = 1;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('yani@sgp-dkp.com', 'Duta Kalingga Pratama');
$this->email->to(array($data['customer_email'], $data['PIC_email']));
$this->email->subject('Service Status Update');
$message = "
Dear Customer, <br/><br/>
Berikut ini kami informasikan status dari <b>"
. $data['type_name'] . " " . $data['merk_name'] . "
" . $data['product_name'] . " </b> : <br/><br/>" .
"Ticket No : " . $data['unique_id'] . " <br/>
Serial No : " . $data['no_serial'] . " <br/>
Tgl masuk : " . $data['entry_date'] . "<br/>
<br/><br/>
Status pada hari ini " . $arr_day[date("w")] . ", " . date("d") . " " . $arr_month[(date("n") - 1)] . " " . date("Y") . " adalah : " . $status . " <br/>
untuk informasi lebih lanjut hubungi kami di nomor +62 21 641 0730, atau via email di helpdesk@sgp-dkp.com.";
$this->email->message($message);
$this->email->send();
}
function send_email_engineer($id_ticket, $id_status) {
$arr_day = array('Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu');
$arr_month = array('Januari', 'Febuari', 'Maret', 'April', 'Mei', 'Juni', 'Juli', 'Agustus', 'September', 'November', 'Desember');
$this->load->library('email');
$data = $this->trans_service_model->get_emaildata_test($id_ticket);
$status = $this->trans_service_model->get_status($id_status);
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'smtp.push.mobi';
$config['smtp_port'] = 25;
$config['smtp_user'] = 'yani@sgp-dkp.com';
$config['smtp_pass'] = 'yaniya';
$config['priority'] = 1;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$this->email->initialize($config);
$this->email->set_newline("\r\n");
$this->email->from('yani@sgp-dkp.com', 'Duta Kalingga Pratama');
$this->email->to(array($data['email']));
$this->email->subject('In House Repair');
$message = "
Dear " . $data['name'] . ", <br/><br/>
Anda memiliki tanggung jawab untuk melakukan In House Repair, <br/>
berikut detailnya : <br/><br/>
Nama Customer : <b>" . $data['customer_name'] . "</b><br/>
Nama Barang : <b>" . $data['type_name'] . " " . $data['merk_name'] . "
" . $data['product_name'] . "</b><br/>
Serial No : <b>" . $data['no_serial'] . " </b><br/>
Ticket No : <b>" . $data['unique_id'] . " </b><br/>
Remarks : <b>" . $data['id_status'] . "</b>";
$this->email->message($message);
$this->email->send();}}`
答案 0 :(得分:0)
所以你的问题确实是&#34;我如何检测文件是否存在?&#34;
在PHP中有一个内置函数,名为file_exists()
echo|set /p="foo" | minigzip > text.txt
所以你需要将它合并到你的代码中。