public function CreateFile($data) { $format = $data["format"] == "excel" || $data["format"] == "csv" ? $data["format"] : "csv"; $PHPExcel = "PHPExcel"; if (!class_exists($PHPExcel)) { include_once plugin_dir_path(__FILE__) . 'extlibs/PHPExcel/PHPExcel.php'; } include_once plugin_dir_path(__FILE__) . 'extlibs/PHPExcel/PHPExcel/Writer/Excel2007.php'; $fields = Fields::Get($data["swichdatatype"]); $obj = new \PHPExcel(); $objProperties = $obj->getProperties(); $objActiveSheet = $obj->getActiveSheet(); $objProperties->setCreator("MakeRise"); $objProperties->setTitle("Data Exported List"); $products_with_variations = isset($data["products_with_variations"]) ? $data["products_with_variations"] : 'Off'; $orders_with_fancy = isset($data["orders_with_fancy"]) ? $data["orders_with_fancy"] : 'Off'; $filter = array("recordsstatus" => $data["recordsstatus"], "recordsauthor" => $data["recordsauthor"], "date-from" => $data["date-from"], "date-to" => $data["date-to"], "datatype" => $data["swichdatatype"], "products_with_variations" => $products_with_variations, "orders_with_fancy" => $orders_with_fancy, "order" => "ID" . " ASC"); if (isset($data["prod-cats"])) { $filter["prod-cats"] = $data["prod-cats"]; } $wpdatas = $this->GetData($filter); $obj->setActiveSheetIndex(0); $i = 0; if ($data["cols"]) { foreach ($data["cols"] as $value) { if (!in_array($value, $data["fields"])) { continue; } $a = Fields::GetAlphas($i); $f = strip_tags($fields[$value][0]); $f = str_replace("Variations: ", "", $f); $objActiveSheet->SetCellValue($a . "1", $f); $ColumnDimension = $objActiveSheet->getColumnDimension($a); $ColumnDimension->setAutoSize(true); $Style = $objActiveSheet->getStyle($a . "1"); $StyleFont = $Style->getFont(); $StyleFont->setBold(true); $r = 2; foreach ($wpdatas as $wpdata) { if (isset($wpdata[$value])) { $objActiveSheet->SetCellValue($a . $r, $wpdata[$value]); } $r++; } $i++; } } $objActiveSheet->setTitle('List'); $filetype = $format == "csv" ? ".csv" : ".xls"; $dt = new \DateTime("now"); $fname = "Data_" . $dt->format("Y-m-d_h-i-s") . "__" . uniqid() . $filetype; if ($format == "csv") { $objw = new \PHPExcel_Writer_CSV($obj); $objw->setDelimiter(';'); $objw->setEnclosure('"'); } else { $objw = new \PHPExcel_Writer_Excel2007($obj); } $files = glob(plugin_dir_path(__FILE__) . "tmp/*"); foreach ($files as $file) { $dt = new \DateTime(date("F d Y H:i:s.", filemtime($file))); $dt->modify("+1 day"); $dt_now = new \DateTime("now"); if ($dt_now > $dt && is_file($file)) { unlink($file); } } $objw->save(plugin_dir_path(__FILE__) . "tmp/" . $fname); return array("fileurl" => plugin_dir_url(__FILE__) . "tmp/" . $fname, "filename" => $fname); }
private function Preview() { $products_with_variations = isset($this->data["products_with_variations"]) ? $this->data["products_with_variations"] : 'Off'; $orders_with_fancy = isset($this->data["orders_with_fancy"]) ? $this->data["orders_with_fancy"] : 'Off'; $filter = array("recordsstatus" => $this->data["recordsstatus"], "recordsauthor" => $this->data["recordsauthor"], "date-from" => $this->data["date-from"], "date-to" => $this->data["date-to"], "datatype" => $this->data["datatype"], "products_with_variations" => $products_with_variations, "orders_with_fancy" => $orders_with_fancy, "order" => "ID" . " ASC", "limit" => 500); if (isset($this->data["prod-cats"])) { $filter["prod-cats"] = $this->data["prod-cats"]; } $view = new View("views/datatable"); $view->setArray(array("fields" => Fields::Get($this->data["datatype"]), "data" => $this->core->GetData($filter), "totalfound" => $this->core->totalfound, "datatype" => $this->data["datatype"])); echo json_encode(array("success" => true, "datatable" => $view->render(false))); }