コード例 #1
0
 public function genExcel(LouisCRUD $crud, array $list, $filename = null)
 {
     // PHPExcel_Shared_Font::setAutoSizeMethod(PHPExcel_Shared_Font::AUTOSIZE_METHOD_EXACT);
     $excel = new PHPExcel();
     $sheet = $excel->getActiveSheet();
     $fields = $crud->getShowFields();
     // Header
     $i = 0;
     foreach ($fields as $field) {
         $sheet->setCellValueByColumnAndRow($i, 1, $field->getDisplayName());
         $sheet->getColumnDimensionByColumn($i)->setAutoSize(true);
         $i++;
     }
     // Data
     $j = 2;
     foreach ($list as $bean) {
         $i = 0;
         foreach ($fields as $field) {
             $sheet->getCellByColumnAndRow($i, $j)->setValueExplicit(strip_tags($field->cellValue($bean)));
             $i++;
         }
         $j++;
     }
     // Save
     $objWriter = new PHPExcel_Writer_Excel2007($excel);
     //$rand = dechex(rand(0, 99999999));
     if ($filename == null) {
         $name = $crud->getTableName();
         $date = date("Y-m-d", time());
         $filename = "{$name}-{$date}.xlsx";
     }
     $headers = ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Content-Disposition' => 'attachment;filename="' . $filename . '"', 'Cache-Control' => 'max-age=0'];
     foreach ($headers as $key => $value) {
         $h = $this->headerClosure;
         $h($key, $value);
     }
     $objWriter->save("php://output");
 }
コード例 #2
0
    /**
     * SlimCRUD constructor.
     * @param string $groupName
     * @param string $apiGroupName
     * @param Slim $slim
     */
    public function __construct($groupName = "crud", $apiGroupName = "api", $slim = null)
    {
        session_start();
        parent::__construct();
        $this->groupName = $groupName;
        $this->apiGroupName = $apiGroupName;
        if ($slim == null) {
            $this->slim = new Slim();
        } else {
            $this->slim = $slim;
        }
        // Upload function
        $this->slim->post("/louislam-crud/upload/:type", function ($type) {
            $result = $this->upload();
            if (isset($_GET["fullpath"]) && $_GET["fullpath"] == "no") {
            } else {
                $result["url"] = \LouisLam\Util::fullURL($result["url"]);
            }
            if ($type == "js") {
                $url = $result["url"];
                if ($result["uploaded"]) {
                    echo <<<HTML
<script type="text/javascript">
    window.parent.CKEDITOR.tools.callFunction("0", "{$url}", "");
</script>
HTML;
                } else {
                    $msg = $result["msg"];
                    echo <<<HTML
<script type="text/javascript">
    alert("{$msg}");
</script>
HTML;
                }
            } else {
                $this->enableJSONResponse();
                echo json_encode($result);
            }
        });
        // Upload Image function
        $this->slim->post("/louislam-crud/upload-image/:type", function ($type) {
            $result = $this->uploadImage("upload", "upload/", 1000);
            if (isset($_GET["fullpath"]) && $_GET["fullpath"] == "no") {
            } else {
                $result["url"] = \LouisLam\Util::fullURL($result["url"]);
            }
            if ($type == "js") {
                $url = $result["url"];
                if ($result["uploaded"]) {
                    echo <<<HTML
<script type="text/javascript">
    window.parent.CKEDITOR.tools.callFunction("0", "{$url}", "");
</script>
HTML;
                } else {
                    $msg = $result["msg"];
                    echo <<<HTML
<script type="text/javascript">
    alert("{$msg}");
</script>
HTML;
                }
            } else {
                $this->enableJSONResponse();
                echo json_encode($result);
            }
        });
        $this->slim->get("/auth/login", function () {
            echo $this->getTemplateEngine()->render("adminlte::login");
        });
        $app = $this->slim;
        $this->slim->post("/auth/login", function () use($app) {
            $result = Auth::login($_POST["username"], $_POST["password"]);
            if ($result) {
                if (isset($_SESSION["redirect"])) {
                    $app->redirect(Util::fullURL($_SESSION["redirect"]));
                } else {
                    $app->redirect($this->getFirstPageURL());
                }
            } else {
                $_SESSION['msg'] = "Username or password invalid";
                $app->redirect(Util::fullURL("auth/login"));
            }
        });
        $this->slim->get("/auth/logout", function () use($app) {
            Auth::logout();
            $app->redirect(Util::fullURL("auth/login"));
        });
    }
コード例 #3
0
ファイル: Field.php プロジェクト: louislam/louislam-crud
 public function getBean()
 {
     return $this->crud->getBean();
 }