function generate()
 {
     $table_name = "gu";
     $ctl = "gu";
     $tmplvar = array();
     $tmplvar["ctl"] = $ctl;
     $tmplvar["table_name"] = $table_name;
     $db = $this->fmodel($table_name);
     $tmplvar["table"] = $db->detail();
     $view = View::getObj();
     $files = array();
     $dir = dir(ROOT . "data/programetpl/crub/");
     while (($file = $dir->read()) !== false) {
         if (!preg_match("/^\\./", $file) && preg_match("/\\.tpl\$/", $file)) {
             $str = $view->fetch_html($tmplvar, ROOT . "data/programetpl/crub/{$file}");
             echo "{$file}<br><textarea cols=300 rows=20>" . e($str) . "</textarea><br>";
             if (f("go")) {
                 mkdir(ROOT . "data/programetpl/log/{$ctl}", 0700);
                 $handle = fopen(ROOT . "data/programetpl/log/{$ctl}/{$file}", 'w');
                 fwrite($handle, $str);
                 fclose($handle);
             }
         }
     }
     $dir->close();
     echo "<a href=/admin/generate/?go=1>DO</a>";
     exit;
 }
 function savetohtml($params)
 {
     $db = $this->modelu8("qiye");
     $ra = $db->peeks_sql("select * from qiye where name=? order by type", array($params[0]));
     $view = View::getObj();
     $rtnsrc = $view->fetch_html(array("list" => $ra), ROOT . 'app/view/qiye/template/a.tpl');
     $this->tocn($params[0], $rtnsrc);
     $this->jump($this->config["qiye"] . $params[0] . '.html', 1);
     exit;
 }
 function fetch_html($params)
 {
     if (isset($this->tmplvar["htmlsrc"])) {
         return $this->tmplvar["htmlsrc"];
     }
     $this->tmplvar["session"] = $_SESSION;
     $this->tmplvar["c"] = $this->config;
     $this->tmplvar["post"] = $_POST;
     $this->tmplvar["get"] = $_GET;
     $this->tmplvar["url"] = $params;
     $this->tmplvar["env"] = $_SERVER;
     $this->tmplvar["v"] = array("control" => $this->ctl, "action" => $this->action, "form_csrf" => "fdsaGJG343", "path" => "/" . $this->ctl . "/" . $this->action, "prefix" => PREFIXURL);
     if ($tmplfile = $this->get_tmplfile()) {
         $tmplfile = "app/view/{$tmplfile}.tpl";
     } else {
         $tmplfile = "app/view/" . $this->ctl . "/" . $this->action . ".tpl";
     }
     if (!file_exists(ROOT . $tmplfile)) {
         $oldtmplfile = $tmplfile;
         if (DEBUG) {
             $tmplfile = "app/view/_share/404.tpl";
         } else {
             $tmplfile = "app/view/_share/404user.tpl";
         }
         $this->tmplvar["url"] = array("{$oldtmplfile} not exist.");
     }
     $view = View::getObj();
     $rtnsrc = $view->fetch_html($this->tmplvar, ROOT . $tmplfile);
     if ($this->show_db_queries) {
         $dblogs = $this->db->logs;
         if ($dblogs) {
             $rtnsrc .= "<br><table border=1><tr><th>DB queries</th><th>Seconds</th></tr>";
             foreach ($dblogs as $i) {
                 foreach (array('left', 'join', 'on', 'as', 'desc', 'by', 'asc', 'and', 'or', 'count') as $keywordsql) {
                     $i[0] = preg_replace('/\\b' . $keywordsql . '\\b/', ' <font color=green><b>' . $keywordsql . '</b></font> ', $i[0]);
                 }
                 foreach (array('select', 'from', 'where') as $keywordsql) {
                     $i[0] = preg_replace('/\\b' . $keywordsql . '\\b/', " <br><font color=red><b>{$keywordsql}</b></font> <br>", $i[0]);
                 }
                 foreach (array('group', 'order', 'limit') as $keywordsql) {
                     $i[0] = preg_replace('/\\b' . $keywordsql . '\\b/', " <br><font color=red><b>{$keywordsql}</b></font> ", $i[0]);
                 }
                 $rtnsrc = $rtnsrc . "<tr><td>{$i['0']}</td><td>{$i['1']}</td></tr>";
             }
             $rtnsrc .= "</table>";
         }
     }
     if ($this->format == "fpdf") {
         //View::html2pdf($rtnsrc);
     }
     return $rtnsrc;
 }