function save() { $mainframe = JFactory::getApplication(); include_once JPATH_COMPONENT_SITE . "/lib/csv.io.class.php"; $ie_id = JRequest::getInt("ie_id"); if (!$ie_id) { $ie_id = $this->get('ie_id'); } $_importexport = JTable::getInstance('ImportExport', 'jshop'); $_importexport->load($ie_id); $alias = $_importexport->get('alias'); $_importexport->set('endstart', time()); $params = JRequest::getVar("params"); if (is_array($params)) { $paramsstr = parseArrayToParams($params); $_importexport->set('params', $paramsstr); } $_importexport->store(); $ie_params_str = $_importexport->get('params'); $ie_params = parseParamsToArray($ie_params_str); $jshopConfig = JSFactory::getConfig(); $lang = JSFactory::getLang(); $db = JFactory::getDBO(); $query = "SELECT prod.product_id, prod.product_ean, prod.product_quantity, prod.product_date_added, prod.product_price, tax.tax_value as tax, prod.`" . $lang->get('name') . "` as name, prod.`" . $lang->get('short_description') . "` as short_description, prod.`" . $lang->get('description') . "` as description, cat.`" . $lang->get('name') . "` as cat_name\n FROM `#__jshopping_products` AS prod\n LEFT JOIN `#__jshopping_products_to_categories` AS categ USING (product_id)\n LEFT JOIN `#__jshopping_categories` as cat on cat.category_id=categ.category_id\n LEFT JOIN `#__jshopping_taxes` AS tax ON tax.tax_id = prod.product_tax_id \n GROUP BY prod.product_id"; $db->setQuery($query); $products = $db->loadObjectList(); $data = array(); $head = array("product_id", "ean", "qty", "date", "price", "tax", "category", "name", "short_description", "description"); $data[] = $head; foreach ($products as $prod) { $row = array(); $row[] = $prod->product_id; $row[] = $prod->product_ean; $row[] = $prod->product_quantity; $row[] = $prod->product_date_added; $row[] = $prod->product_price; $row[] = $prod->tax; $row[] = utf8_decode($prod->cat_name); $row[] = utf8_decode($prod->name); $row[] = utf8_decode($prod->short_description); $row[] = utf8_decode($prod->description); $data[] = $row; } $filename = $jshopConfig->importexport_path . $alias . "/" . $ie_params['filename'] . ".csv"; $csv = new csv(); $csv->write($filename, $data); if (!JRequest::getInt("noredirect")) { $mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=" . $ie_id, _JSHOP_COMPLETED); } }
public function parse_csv($csv, $dir = NULL) { if (!is_null($dir)) { $this->picdir = $dir; } $products = array(); $csvArr = csv::decode($csv); foreach ($csvArr as $lc => $l) { if ($this->is_empty($l)) { continue; } //表头 if ($lc === 0) { continue; } $product = $this->set_product($l); } return array('errors' => $this->errors); }
function save() { $mainframe = JFactory::getApplication(); $jshopConfig = JSFactory::getConfig(); require_once JPATH_COMPONENT_SITE . '/lib/uploadfile.class.php'; require_once JPATH_COMPONENT_SITE . "/lib/csv.io.class.php"; $ie_id = JRequest::getInt("ie_id"); if (!$ie_id) { $ie_id = $this->get('ie_id'); } $lang = JSFactory::getLang(); $db = JFactory::getDBO(); $_importexport = JSFactory::getTable('ImportExport', 'jshop'); $_importexport->load($ie_id); $alias = $_importexport->get('alias'); $_importexport->set('endstart', time()); $_importexport->store(); //get list tax $query = "SELECT tax_id, tax_value FROM `#__jshopping_taxes`"; $db->setQuery($query); $rows = $db->loadObjectList(); $listTax = array(); foreach ($rows as $row) { $listTax[intval($row->tax_value)] = $row->tax_id; } //get list category $query = "SELECT category_id as id, `" . $lang->get("name") . "` as name FROM `#__jshopping_categories`"; $db->setQuery($query); $rows = $db->loadObjectList(); $listCat = array(); foreach ($rows as $row) { $listCat[$row->name] = $row->id; } $_products = JSFactory::getModel('products', 'JshoppingModel'); $dir = $jshopConfig->importexport_path . $alias . "/"; $upload = new UploadFile($_FILES['file']); $upload->setAllowFile(array('csv')); $upload->setDir($dir); if ($upload->upload()) { $filename = $dir . "/" . $upload->getName(); @chmod($filename, 0777); $csv = new csv(); $data = $csv->read($filename); if (is_array($data)) { foreach ($data as $k => $row) { if (count($row) < 2 || $k == 0) { continue; } $tax_value = intval($row[5]); if (!isset($listTax[$tax_value])) { $tax = JSFactory::getTable('tax', 'jshop'); $tax->set('tax_name', $tax_value); $tax->set('tax_value', $tax_value); $tax->store(); $listTax[$tax_value] = $tax->get("tax_id"); } $category_name = $row['6']; if (!isset($listCat[$category_name]) && $category_name != "") { $cat = JSFactory::getTable("category", "jshop"); $query = "SELECT max(ordering) FROM `#__jshopping_categories`"; $db->setQuery($query); $ordering = $db->loadResult() + 1; $cat->set($lang->get("name"), $category_name); $cat->set("category_ordertype", 1); $cat->set("products_page", $jshopConfig->count_products_to_page); $cat->set("products_row", $jshopConfig->count_products_to_row); $cat->set("category_publish", 0); $cat->set("ordering", $ordering); $cat->store(); $listCat[$category_name] = $cat->get("category_id"); } $product = JSFactory::getTable('product', 'jshop'); $product->set("product_ean", $row[1]); $product->set("product_quantity", $row[2]); $product->set("product_date_added", $row[3]); $product->set("product_price", $row[4]); $product->set("min_price", $row[4]); $product->set("product_tax_id", $listTax[$tax_value]); $product->set("currency_id", $jshopConfig->mainCurrency); $product->set($lang->get("name"), utf8_encode($row[7])); $product->set($lang->get("short_description"), utf8_encode($row[8])); $product->set($lang->get("description"), utf8_encode($row[9])); $product->store(); $product_id = $product->get("product_id"); $category_id = $listCat[$category_name]; if ($category_name != "" && $category_id) { $_products->setCategoryToProduct($product_id, array($category_id)); } unset($product); } } @unlink($filename); } else { JError::raiseWarning("", _JSHOP_ERROR_UPLOADING); } if (!JRequest::getInt("noredirect")) { $mainframe->redirect("index.php?option=com_jshopping&controller=importexport&task=view&ie_id=" . $ie_id, _JSHOP_COMPLETED); } }
break; case "dot": $separator = "."; break; case "colon": $separator = ":"; break; case "semicolon": $separator = ";"; break; case "other": $separator = stripslashes($arr_in["otherseparator"]); break; default: $separator = stripslashes($arr_in["separator"]); break; } $csv = new csv("../uploads/" . $arr_in["filename"], $separator, stripslashes($arr_in["enclosure"]), $charset); $_SESSION["filename"] = $arr_in["filename"]; $_SESSION["separator"] = $separator; $_SESSION["enclosure"] = stripslashes($arr_in["enclosure"]); $_SESSION["csvdata"] = $retstr = json_encode($csv->getArrCsv()); /* if (count($csv) == 0) { //csv file is empty $_SESSION["total_num_columns_in_csv"] = 0; } else { $_SESSION["total_num_columns_in_csv"] = count($csv[0]); //row 0 are the title. } */ //$_SESSION["test"] = $csv->getArrCsv(); echo $retstr;
private function existeSolapamientocsv($data, $file, $numFila) { $solapamientos = false; $csv = new csv(); //estado del evento?? (solapamientos) $idLugar = $data['ID_LUGAR']; $fechaDesde = sgrDate::dateCSVtoSpanish($data['F_DESDE_HORARIO1']); //d-m-Y $fechaHasta = sgrDate::dateCSVtoSpanish($data['F_HASTA_HORARIO1']); //d-m-Y $horaInicio = $data['INI']; $horaFin = $data['FIN']; $diaSemana = $data['COD_DIA_SEMANA']; $f = fopen($file, "r"); $contadorfila = 1; while (($fila = fgetcsv($f, 0, ';', '"')) !== false && !$solapamientos) { $datosfila = $csv->filterFila($fila); if ($datosfila['ID_LUGAR'] == $idLugar && $datosfila['COD_DIA_SEMANA'] == $diaSemana && $contadorfila != $numFila) { //posible solapamiento $filafechaDesde = sgrDate::dateCSVtoSpanish($datosfila['F_DESDE_HORARIO1']); //d-m-Y $filafechaHasta = sgrDate::dateCSVtoSpanish($datosfila['F_HASTA_HORARIO1']); //d-m-Y $filahoraInicio = $datosfila['INI']; $filahoraFin = $datosfila['FIN']; if (strtotime(sgrDate::parsedatetime($fechaDesde, 'd-m-Y', 'Y-m-d')) <= strtotime(sgrDate::parsedatetime($filafechaHasta, 'd-m-Y', 'Y-m-d')) && strtotime(sgrDate::parsedatetime($fechaHasta, 'd-m-Y', 'Y-m-d')) >= strtotime(sgrDate::parsedatetime($filafechaDesde, 'd-m-Y', 'Y-m-d'))) { //posible solapamiento if (strtotime($horaInicio) < strtotime($filahoraFin) && strtotime($horaFin) > strtotime($filahoraInicio)) { //hay solapamiento $solapamientos = true; } //tercer if } //segundo if } //primer if $contadorfila++; } //fin del while fclose($f); return $solapamientos; }
public function report() { $startTime = $this->_get('stime', ''); //开始时间 $endTime = $this->_get('etime', ''); //结束时间 $serviceId = $this->_getid('service_id', 0); //服务社 $isOutput = $this->_getid('is_output', 0); //是否导出数据 $cateId = $this->_getid('cid', 0); //类目 $cateList = array(275 => '半成品菜', 273 => '预定下午茶'); if (!isset($cateList[$cateId])) { showError('抱歉,该类目不允许查看'); } if (!parent::_checkIsAdmin()) { if ($cateId != 275 || steadmin::$adminInfo['user_id'] != 291) { //半成品菜店长 showError('抱歉,暂无权限'); } } //取类目及所有子类目 $cateAllList = M('ste_goods_cate')->where(array('city_id' => steadmin::$adminInfo['city_id'], 'is_del' => 0))->order('sort DESC')->select('id'); $tidList = D('tree')->getSubs($cateAllList, $cateId, true); $cateId = $tidList['list'] ? implode(',', $tidList['list']) : $cateId; //默认报表时间为今天 $today = mktime(0, 0, 0, date('m'), date('d'), date('Y')); $stime = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')); if (!$startTime) { $startTime = date('Y-m-d', $stime); } if (!$endTime) { $endTime = date('Y-m-d', $stime); } if ($startTime && $endTime) { $startTime = inTime($startTime); $endTime = inTime($endTime) + 60 * 60 * 24 - 1; } if ($serviceId) { $where = ' AND a.service_id=' . $serviceId; $sWhere = ' AND service_id=' . $serviceId; } else { $where = ''; $sWhere = ''; } if ($startTime < $today) { $statusList = '1,3,4,5,6,7,8,9,10,11'; } else { $statusList = '1,3,4,5,6,7,8,9,10,11'; //搜索状态:已支付、已审核、正在配货 } //根据类目搜索所有的商品gid $where = ''; $rs = M('ste_order')->query('SELECT a.order_id,a.order_sn,a.order_type,a.service_id,a.village_id,a.uid,a.address,a.phone,a.username,' . 'a.desc,a.arrive_date,a.arrive_time,a.order_source,a.status,a.order_time,a.goods_counts AS goods_total,b.gid,b.shop_id,b.goods_name,b.goods_counts,b.goods_price' . ' FROM __TABLE__ AS a LEFT JOIN __PRE__ste_order_goods AS b ON a.order_id=b.order_id WHERE a.arrive_date>=' . $startTime . ' AND a.arrive_date<=' . $endTime . ' AND a.status IN (' . $statusList . ') AND b.gid IN ( SELECT gid FROM __PRE__ste_goods WHERE cate_id IN (' . $cateId . ') ' . $sWhere . ' )' . $where . ' ORDER BY service_id ASC'); // z(M('ste_order')->getAllSql()); // z($rs); $orderList = array(); $orderTotal = array(); $serviceList = array(); if ($rs) { foreach ($rs as $val) { //统计各个菜的数量 $goodsName = md5($val['goods_name']); if (!isset($orderTotal[$goodsName])) { $orderTotal[$goodsName] = array('name' => $val['goods_name'], 'counts' => $val['goods_counts'], 'item' => array()); } else { $orderTotal[$goodsName]['counts'] += $val['goods_counts']; } if (!isset($orderTotal[$goodsName]['item'][$val['service_id']])) { $orderTotal[$goodsName]['item'][$val['service_id']] = array('name' => $this->serviceData[$val['service_id']]['stitle'], 'counts' => $val['goods_counts']); } else { $orderTotal[$goodsName]['item'][$val['service_id']]['counts'] += $val['goods_counts']; } //按服务社统计菜单 if (!isset($serviceList[$val['service_id']])) { $serviceList[$val['service_id']] = array('service_name' => $this->serviceData[$val['service_id']]['stitle'], 'counts' => $val['goods_counts'], 'item' => array()); } else { $serviceList[$val['service_id']]['counts'] += $val['goods_counts']; } if (!isset($serviceList[$val['service_id']]['item'][$val['gid']])) { $serviceList[$val['service_id']]['item'][$val['gid']] = array('name' => $val['goods_name'], 'counts' => $val['goods_counts']); } else { $serviceList[$val['service_id']]['item'][$val['gid']]['counts'] += $val['goods_counts']; } //按订单号归类商品 if (!isset($orderList[$val['order_id']])) { $orderList[$val['order_id']] = array('order_id' => $val['order_id'], 'order_sn' => $val['order_sn'], 'order_type' => $val['order_type'], 'service_id' => $val['service_id'], 'service_name' => $this->serviceData[$val['service_id']]['stitle'], 'village_id' => $val['village_id'], 'village_name' => parent::getVillageName($val['village_id']), 'address' => $val['address'], 'phone' => $val['phone'], 'username' => $val['username'], 'desc' => $val['desc'], 'arrive_date' => $val['arrive_date'], 'arrive_time' => $val['arrive_time'], 'order_source' => $val['order_source'], 'status' => $val['status'], 'order_time' => $val['order_time'], 'goods_total' => $val['goods_total'], 'select_goods_total' => 0, 'list' => array()); } $orderList[$val['order_id']]['list'][] = array('goods_name' => $val['goods_name'], 'goods_counts' => $val['goods_counts'], 'goods_price' => $val['goods_price']); $orderList[$val['order_id']]['select_goods_total'] += $val['goods_counts']; } } // z($orderTotal); // z($serviceList); if ($isOutput) { $dataList = array(); $title = array('订单号', '收货人', '手机', '地址', '配送时间', '商品列表', '留言', '混合订单'); foreach ($orderList as $val) { $list = array(); foreach ($val['list'] as $v) { $list[] = $v['goods_name'] . ' (x ' . $v['goods_counts'] . ')'; } $dataList[] = array($val['order_sn'], $val['username'], $val['phone'], $val['address'], outTime($val['arrive_date'], 2) . ' ' . $val['arrive_time'], implode("\r\n", $list), $val['desc'], $val['goods_total'] == $val['select_goods_total'] ? '否' : '是'); } if (isset($this->serviceData[$serviceId])) { $tname = $this->serviceData[$serviceId]['stitle']; } else { $tname = '全部'; } $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('品类', '详细', '数量', '', '', '', '', ''); //将统计信息附加到报表中 foreach ($orderTotal as $val) { $list = array(); foreach ($val['item'] as $v) { $list[] = $v['name'] . ' (' . $v['counts'] . '份)'; } $dataList[] = array($val['name'], implode('、', $list), $val['counts'], '', '', '', '', ''); } $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('', '', '', '', '', '', '', ''); $dataList[] = array('服务社', '详细', '数量', '', '', '', '', ''); //将统计信息附加到报表中 foreach ($serviceList as $val) { $list = array(); foreach ($val['item'] as $v) { $list[] = $v['name'] . ' (' . $v['counts'] . '份)'; } $dataList[] = array($val['service_name'], implode("\r\n", $list), $val['counts'], '', '', '', '', ''); } load('csv'); $csv = new csv(); $csv->write($title, $dataList, $cateList[$cateId] . '订单_' . $tname . date('Y-m-d H/i/s')); } else { $this->assign(array('rs' => $orderList, 'orderTotal' => $orderTotal, 'cid' => $cateId, 'service_id' => $serviceId, 'startTime' => $startTime, 'endTime' => $endTime, 'serviceList' => $serviceList, 'service' => $this->serviceData, 'setting' => $this->steSetting)); $this->display(); } }
public function export() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); if (empty($request_data['classify_id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $classify_id = $request_data['classify_id']; if ($classify_id > 0) { $classify = ClassifyService::get_instance()->get($request_data['classify_id']); } else { $classify_id = 0; } $export = ExportService::get_instance()->get_titlebar($classify_id); $csv = csv::encode(array($export)); header('Cache-control: private'); header('Content-Disposition: attachment; filename=import.csv'); header('Content-type: text/csv; charset=GBK'); echo iconv('UTF-8', 'GBK//IGNORE', $csv); exit; //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = 'Success'; $return_struct['content'] = $return_data; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { // html 输出 $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
function run() { $fd = false; if (file_exists($this->file_name)) { $fd = fopen($this->file_name, 'r'); } if ($fd !== false) { $csv = new csv(); while ($str = fgets($fd)) { if ($this->encoding != 'utf-8') { $str = iconv($this->encoding, 'utf-8', $str); } $values = $csv->split(trim($str)); if (isset($this->_2d_mode)) { if (!is_array($this->horizontal)) { $this->horizontal = $values; } else { $_2d_count = 0; $hor_ptr = 0; unset($tmp); foreach ($values as $v) { if ($_2d_count < $this->_2d_mode) { $tmp['col' . $_2d_count] = $v; $_2d_count++; $hor_ptr++; } else { $tmp['col' . $_2d_count] = $this->horizontal[$hor_ptr]; $hor_ptr++; $tmp['col' . ($_2d_count + 1)] = $v; if (($this->mode == 'rows' || $this->mode == 'all') && $v != '') { if ($this->row_method == '') { die("\$this->row_method==''"); } $method = $this->row_method; if ($this->row_object != '') { $this->stop = !$this->row_object->{$method}($tmp); } else { $this->stop = !$method($tmp); } } } if ($this->stop) { return false; } } } } else { if (!is_array($this->table_columns) || count($this->table_columns) == 0) { $this->column_count = count($values); $this->first_pass = true; foreach ($values as $i => $v) { $this->table_columns['col' . $i] = array('Field' => 'col' . $i); } } else { if ($this->column_count != count($values)) { $this->stop = true; return false; } } if ($this->mode == 'rows' || $this->mode == 'all') { if ($this->row_method == '') { die("\$this->row_method==''"); } $cnt = 0; foreach ($this->table_columns as $c => $v) { $out[$c] = $values[$cnt++]; } $method = $this->row_method; if ($this->row_object != '') { $this->stop = !$this->row_object->{$method}($out); } else { $this->stop = !$method($out); } unset($out); } } if ($this->stop) { break; } } fclose($fd); } else { return false; } return true; }
<?php raintpl::$tpl_dir = ROOT_DIR . '/root/template/ajax/'; require_once ENGINE_DIR . '/classes/export-csv.class.php'; /* Windows 1251 if windows office default charset windows 1251 , else utf8*/ header('Content-Type: text/html; charset=windows-1251'); if ($_GET['full'] == 1) { $filename = 'Cosmos_Hostel_full'; // The file name you want any resulting file to be called. } else { $filename = 'Cosmos_Hostel'; } $csv = new csv(); $header[] = "Договор"; $header[] = "Договор"; $header[] = "Фамилия"; $header[] = "Имя"; $header[] = "Отчество"; if ($_GET['full'] == 1) { $header[] = "Включен"; $header[] = "Фиксация"; $header[] = "Последняя фиксация"; $header[] = "Активен"; $header[] = "Факультет"; $header[] = "Группа"; $header[] = "Телефон"; $header[] = "Контракт"; $header[] = "Заметки"; $header[] = "Админ"; $header[] = "s_net"; $header[] = "s_ip";
<?php $csv = new csv(); $fetch_csv = $csv->csv_to_array('csv/transactions.csv', ','); echo "<pre>"; print_r($fetch_csv); echo "</pre>";
function file_contents_out($fd) { global $sql; $csv = new csv(); while ($str = fgets($fd)) { $values = $csv->split(trim($str)); $this->args['o_name'] = $values[0]; $this->args['count'] = $values[1]; $this->keys['name'] = $values[0]; foreach ($this->editors as $e) { $e->bootstrap(); } $rs = $sql->fetch1($sql->query("SELECT id FROM barcodes_raw WHERE isown=0 AND name = '" . $sql->esc($values[0]) . "'")); if ($rs == '') { $rs = $sql->fetch1($sql->query("SELECT id FROM barcodes_mapping WHERE name = '" . $sql->esc($values[0]) . "'")); if ($rs == '') { $this->editors['m_del']->css_style['display'] = 'none'; } else { $this->editors['m_del']->css_style['display'] = 'inline'; } } else { $this->editors['m_del']->css_style['display'] = 'none'; } $oc = $sql->fetch1($sql->query("SELECT `count` FROM barcodes_print WHERE id = '" . $sql->esc($rs) . "' AND task=" . intval($this->args['task']))); if ($oc == $values[1]) { $this->count_td->css_style['background'] = 'green'; } if ($oc != $values[1]) { $this->count_td->css_style['background'] = 'red'; } if ($oc == 0) { $this->count_td->css_style['background'] = 'yellow'; } $this->args['m_id'] = $rs; $this->xdiv->html(); $this->xdiv->id_alloc(); } }
public function index() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); try { //$profiler = new Profiler; //* 初始化返回数据 */ $return_data = array(); //* 收集请求数据 ==根据业务逻辑定制== */ $request_data = $this->input->get(); $query_struct = array('where' => array('status' => ProductService::PRODUCT_STATUS_PUBLISH), 'orderby' => array(), 'limit' => array()); switch (trim($request_data['type'])) { case 'category': $query_struct['orderby']['id'] = 'ASC'; if (!isset($request_data['id']) or !preg_match('/^\\d+$/', $request_data['id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $category = CategoryService::get_instance()->get($request_data['id']); $category['sub_ids'] = trim($category['sub_ids']); if (empty($category['sub_ids'])) { $query_struct['where']['category_id'] = $category['id']; } else { $sub_ids = explode(',', $category['sub_ids']); array_push($sub_ids, $category['id']); $query_struct['where']['category_id'] = $sub_ids; } break; case 'classify': $query_struct['orderby']['id'] = 'ASC'; if (!isset($request_data['id']) or !preg_match('/^\\d+$/', $request_data['id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $categorys = CategoryService::get_instance()->query_assoc(array('where' => array('classify_id' => $request_data['id']))); if (empty($categorys)) { throw new MyRuntimeException(Kohana::lang('o_product.export_pdt_not_found')); } $query_struct['where']['category_id'] = array(); foreach ($categorys as $category) { $query_struct['where']['category_id'][] = $category['id']; } break; default: if (!empty($request_data['product_id'])) { $request_data['product_id'] = explode('-', $request_data['product_id']); foreach ($request_data['product_id'] as $item) { if (!preg_match('/^\\d+$/', $item)) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } } $query_struct['where']['id'] = $request_data['product_id']; } if (isset($request_data['category_id'])) { if (!preg_match('/^\\d+$/', $request_data['category_id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $query_struct['where']['category_id'] = $request_data['category_id']; } if (isset($request_data['brand_id'])) { if (!preg_match('/^\\d+$/', $request_data['brand_id'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $query_struct['where']['brand_id'] = $request_data['brand_id']; } if (!empty($request_data['title'])) { $query_struct['where']['title'] = trim($request_data['title']); } if (!empty($request_data['name_manage'])) { $query_struct['where']['name_manage'] = trim($request_data['name_manage']); } if (!empty($request_data['sku'])) { $query_struct['where']['sku'] = trim($request_data['sku']); } if (isset($request_data['orderby'])) { if (!is_array($request_data['orderby'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } foreach ($request_data['orderby'] as $item) { $item = explode('-', $item); if (count($item) != 2) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $query_struct['orderby'][$item[0]] = $item[1] === '0' ? 'ASC' : 'DESC'; } } if (isset($request_data['page'])) { if (!preg_match('/^\\d+$/', $request_data['page'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $query_struct['limit']['page'] = $request_data['page']; if (!isset($request_data['per_page']) or !preg_match('/^\\d+$/', $request_data['per_page'])) { throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400); } $query_struct['limit']['per_page'] = $request_data['per_page']; } } $products = ProductService::get_instance()->query_assoc($query_struct); if (empty($products)) { throw new MyRuntimeException(Kohana::lang('o_product.export_pdt_not_found')); } $csv = ExportService::get_instance()->run($products); $csv = csv::encode($csv); $csv = iconv('UTF-8', 'GBK//IGNORE', $csv); if ($this->is_ajax_request()) { $fid = uniqid(); $dir = Kohana::config('product.export_tmp_dir'); $dir = rtrim(trim($dir), '/'); if (!is_dir($dir) && !@mkdir($dir, 0777, TRUE)) { throw new MyRuntimeException(Kohana::lang('o_product.export_cte_tmpdir_failed')); } $filename = $dir . '/' . $fid . '.csv'; if (!@file_put_contents($filename, $csv)) { throw new MyRuntimeException(Kohana::lang('o_product.export_wte_tmp_failed')); } } else { @header('Cache-control: private'); @header('Content-Disposition: attachment; filename=' . 'export-' . date('Ymd', time()) . '.csv'); @header('Content-type: text/csv; charset=GBK'); echo $csv; exit; } //* 补充&修改返回结构体 */ $return_struct['status'] = 1; $return_struct['code'] = 200; $return_struct['msg'] = ''; $return_struct['content'] = url::base() . 'product/export/download?fid=' . $fid; //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 //exit('Not Implemented'); $this->template->content = $return_struct; } else { // html 输出 //* 模板输出 */ $content = new View($this->package . '/' . $this->class_name . '/' . __FUNCTION__); //* 变量绑定 */ $this->template->title = Kohana::config('site.name'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; //:: 当前应用专用数据 $this->template->content->site_id = $site_id; $this->template->content->sites = $sites; $this->template->content->classifies_html = $html; } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); //TODO 异常处理 //throw $ex; if ($this->is_ajax_request()) { $this->template->content = $return_struct; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; //* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; //* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }
public function _writeToString($csvFeed, $settings = array()) { return csv::writeToString($csvFeed, $settings); }
<?php /** * * Created by blond. * File: readCSV.php * Date: 16/07/15 - 00:56 * Proj: veganet * */ $csv = $path = $resu = $data_csv = $fichier = $element = $psDossier = $array_IDOption = null; require_once "class.csv.php"; $csv = new csv(); $path = $csv->getPath(); if (file_exists($path)) { $element = $csv->getFileForRead(); if (count($element) > '0') { foreach ($element as $key => $fichier) { if ($fichier != '.' && $fichier != '..') { // $csv->getPrint($fichier); $data_csv = $csv->getDataFromCSV($fichier); if (isset($data_csv[1][0]) && $data_csv[1][0] != '') { $psDossier = "'" . $data_csv[1][0] . "'"; } if (isset($psDossier) && $psDossier != null) { // $csv->getPrint($psDossier); $data = $csv->getVerifDossierExist($psDossier); //__ SI DOSSIER EXISTE PAS DEJA if (!isset($data)) { // var_dump($psDossier); if (isset($data_csv[2]) && $data_csv[2][0] > '0') {
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <?php header('Content-type: text/html; charset=UTF-8'); $indicator = explode("_//_", $_POST['indicator']); $func = explode("_//_", $_POST['functional']); $mode = explode("_//_", $_POST['mode']); if (substr($func[1], 0, 3) == "POT") { $funclabel = "Amount of "; } if (substr($func[1], 0, 3) == "ACC") { $funclabel = "Accessibility to "; } $csvname = $indicator[1] . "_" . $mode[1] . "_" . $func[1] . ".csv"; if (substr($func[1], 0, 3) == "POT") { $maptitle = ucfirst(strtolower($funclabel . $indicator[0] . " reachable in " . $func[0] . " (" . $mode[0] . ")")); $units = $indicator[3]; } if (substr($func[1], 0, 3) == "ACC") { $maptitle = ucfirst(strtolower($funclabel . $func[0] . " of the " . $indicator[0] . " (" . $mode[0] . ")")); $units = "hours"; } require '../classes/csv.class.php'; $mycsv = new csv($csvname); echo $mycsv->gettop10($maptitle, $units);
<?php session_start(); require_once "../class/db.class.php"; require_once "../class/csv.class.php"; $arr_in = json_decode(file_get_contents('php://input'), true); if (!isset($_SESSION["csvdata"])) { $csv = new csv("../uploads/" . $_SESSION["filename"], $_SESSION["separator"], $_SESSION["enclosure"], "ISO-8859-1"); $arr_csv = $csv->getArrCsv(); } else { $arr_csv = json_decode($_SESSION["csvdata"]); } $db = new db(); $issue = $db->insert($_SESSION["tablename"], $_SESSION["dbcolumnslist"], $arr_in, $arr_csv); echo json_encode($issue); function debug($string) { ob_start(); $var = func_get_args(); call_user_func_array('var_dump', $var); $string = ob_get_clean(); if ($fp = fopen("../debug.txt", "w")) { fwrite($fp, $string . "\n"); fclose($fp); } }
function handle_event($ev) { switch ($ev->rem_name) { case 'fn': $file_name = $_POST['val']; $this->unix_fd = fopen('../uploads/utf8.vcf', "w"); $this->win_fd = fopen('../uploads/cp1251.vcf', "w"); $csv = new csv(); $in = file_get_contents('../uploads/' . $file_name); $r = explode("\n", $in); foreach ($r as $line) { if ($line != '') { $row = $csv->split($line); $vc->email = $row[0]; $vc->name = $row[1]; $vc->surname = $row[2]; $this->write2("BEGIN:VCARD"); $this->write2("VERSION:3.0"); $this->write2("REV:2008-06-24T15:18:51Z"); $this->write2("EMAIL;TYPE=OTHER:" . $vc->email); $this->write2("X-EVOLUTION-FILE-AS:" . $vc->surname . "\\, " . $vc->name); $this->write2("N:" . $vc->surname . ";" . $vc->name . ";;;"); $this->write2("FN:" . $vc->name . " " . $vc->surname); $this->write2("END:VCARD"); $this->write2(""); } } fclose($this->unix_fd); fclose($this->win_fd); print "\$i('" . js_escape($ev->context[$ev->parent_name]['res_id']) . "').innerHTML='" . js_escape("<div>" . htmlspecialchars($in) . "</div>" . "<a href='../uploads/utf8.vcf'>utf-8</a> " . "<a href='../uploads/cp1251.vcf'>cp1251</a> ") . "';"; break; case 'do': break; } editor_generic::handle_event($ev); }
} } } } } break; case "selectfields": // show the form include ("./modules/mod_csv/class.csv.php"); $error = false; $templateinclude = "importcsv2"; // prepare the select $selectlist = new csv($_REQUEST["type"], $_REQUEST["number"]); $template->assign('type', $_REQUEST["type"]); $template->assign('selectnumber', $_REQUEST["number"]); // assign the select to the template $template->assign('select', $selectlist->selectArray()); break; default: $template->assign('type', $_REQUEST["type"]); $templateinclude = "importcsv1";
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <?php header('Content-type: text/html; charset=UTF-8'); $func = explode("_//_", $_POST['functional']); $indicator = explode("_//_", $_POST['indicator']); $units = $indicator[3]; $mode = explode("_//_", $_POST['mode']); $year = $indicator[2]; require '../classes/csv.class.php'; $csvfilename = $indicator[1] . "_" . $mode[1] . "_" . $func[1] . ".csv"; $mycsv = new csv($csvfilename); $top = explode("_//_", $mycsv->gettop()); $topname = $top[0]; $topval = $top[1]; if ($topval < 0) { $precision = 2; } if ($topval >= 0) { $precision = 0; } if ($topval > 1000) { $precision = -1; } if ($topval > 10000) { $precision = -2; } if ($topval > 100000) { $precision = -3; } # POT if (substr($func[1], 0, 3) == "POT") {
public function out() { parent::_checkLogin(); parent::_authUser(array(1)); $maxRead = 1000; //单次读出最大的数据量 $serviceId = $this->_getid('service_id', 0); //类别 $shopId = $this->_getid('shop_id', 0); //店铺 $where = array('status' => array(0, 1)); if ($serviceId) { $where['service_id'] = $serviceId; } if ($shopId) { $where['shop_id'] = $shopId; } $count = M('ste_goods')->where($where)->count(); $pages = ceil($count / $maxRead); $rs = array(); if ($pages) { for ($i = 1; $i <= $pages; $i += 1) { $list = M('ste_goods')->where($where)->order('shop_id DESC')->limit(($i - 1) * $maxRead . ',' . $maxRead)->findAll(false); if ($list) { $rs = array_merge($rs, $list); } } } load('csv'); $myCsv = new csv(); $list = array(); foreach ($rs as $val) { $cateList = $this->getCateTree($val['cate_id']); if ($cateList) { $cateName = implode('->', $cateList) . '->' . parent::_getCateName($val['cate_id']); } else { $cateName = parent::_getCateName($val['cate_id']); } $list[] = array($val['gid'], "\t" . $val['goods_sn'], parent::_getShopName($val['shop_id']), $cateName, parent::_getAdminName($val['user_id']), $val['goods_name'], $val['goods_subtitle'], $val['goods_spec'], getImgUrl($val['goods_pic']), "\t" . $val['original_price'], $val['price_pre'], "\t" . $val['price'], "\t" . $val['purc_price'], "\t" . $val['goods_number'], "\t" . $val['bar_code'], strip_tags($val['goods_desc']), $val['order_counts'], $val['sale_counts'], $val['storage_counts'], "\t" . outTime($val['start_times']), "\t" . outTime($val['end_times']), $val['is_limited'] ? '是' : '否', $val['limit_counts'], strip_tags($this->getStatus($val['start_times'], $val['end_times'], $val['status']))); } unset($rs); $myCsv->write(array('编号', '商品货号', '店铺', '类别', '帐号', '商品名称', '副标题', '规格', '图片', '原价', '价格前缀', '售价', '进价', '商家货号', '条形码', '描述', '下单量', '销售量', '库存', '上架时间', '下架时间', '是否特价', '限购数量', '销售状态'), $list, 'goods_' . date('y-m-d')); }