Example #1
0
/**
 * 获取模板对应的打印数据
 * @param $templateId
 * @param $chips
 * @return mixed
 */
function biz_Print_getTemplateData($templateId, $chips)
{
    $template = db_getPrintTemplate($templateId);
    $base = biz_Print_getChipsData($chips, $template['printtype']);
    $data = biz_unserializer($template, 'datamap');
    foreach ($data as $k => $v) {
        if (isset($base[$v])) {
            $data[$k] = $base[$v];
        } else {
            $data[$k] = '';
        }
    }
    return $data;
}
Example #2
0
 public function doWebTemplate()
 {
     global $_W, $_GPC;
     $op = !empty($_GPC['op']) ? $_GPC['op'] : 'list';
     $printtype = biz_getDictionary('printtype');
     if ($op == 'list') {
         $pindex = max(1, intval($_GPC['page']));
         $psize = 20;
         $table = 'printtemplate';
         $sql = "SELECT * FROM " . tablename($table) . " limit " . ($pindex - 1) * $psize . "," . $psize;
         $list = pdo_fetchall($sql);
         $total = pdo_fetchcolumn(" select count(*) from " . tablename($table));
         $pager = pagination($total, $pindex, $psize);
         include $this->template('template_list');
         exit;
     }
     if ($op == 'delete') {
         $this->CheckRight('deltemp');
         $id = $_GPC['id'];
         $template = db_getPrintTemplate($id);
         if (!empty($template)) {
             pdo_delete('printtemplate', array('id' => $template['id']));
             exit('success');
         } else {
             exit('无效数据!');
         }
     }
     if ($op == 'down') {
         $id = $_GPC['id'];
         $template = db_getPrintTemplate($id);
         header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
         header("Content-Type:application/force-download");
         header("Content-Type: application/vnd.ms-word;charset=UTF-8");
         header("Content-Type:application/octet-stream");
         header("Content-Type:application/download");
         $ua = $_SERVER["HTTP_USER_AGENT"];
         $filename = $template['title'] . ".docx";
         if (preg_match("/MSIE/", $ua)) {
             $filename = urlencode($filename);
             header('Content-Disposition: attachment; filename=' . $filename);
         } else {
             header('Content-Disposition: attachment; filename=' . $filename);
         }
         header("Content-Transfer-Encoding:binary");
         echo base64_decode($template['content']);
         exit;
     }
     load()->web('print');
     if ($op == 'post') {
         $this->CheckRight('addtemp');
         if (checksubmit()) {
             if (!empty($_FILES['wordfile']['name'])) {
                 if ($_FILES['wordfile']['error'] != 0) {
                     message('文件上传失败,请重试!', $this->createWebUrl('template', array('op' => 'post')), 'error');
                 }
             } else {
                 message('请选择要上传的模板!', $this->createWebUrl('template', array('op' => 'post')), 'warning');
             }
             $word = GetUploadFile('wordfile');
             if (empty($word)) {
                 message('上传文件失败,目录无写入权限!', $this->createWebUrl('template', array('op' => 'post')), 'error');
             }
             $tags = GetTagsOfXml($word);
             if (empty($tags)) {
                 message('无效的模板文件,无法读取标签!', $this->createWebUrl('template', array('op' => 'post')), 'error');
             }
             $data = array('id' => GUID(), 'title' => trim($_GPC['title']), 'printtype' => $_GPC['printtype'], 'tags' => iserializer($tags), 'content' => base64_encode(file_get_contents($word)), 'tagsnum' => count($tags), 'status' => '0', 'createtime' => TIMESTAMP);
             @unlink($word);
             if (empty($data['title'])) {
                 $data['title'] = $_FILES['wordfile']['name'];
             }
             if (!empty($_GPC['onlyCurr'])) {
                 $data['project'] = $_W['project']['projguid'];
             }
             pdo_insert('printtemplate', $data);
             //$test=biz_Print_getTemplateById($data['id']);
             message('保存数据成功!', $this->CreateWebUrl('template'));
         }
         include $this->template('template_post');
         exit;
     }
     if ($op == 'tags') {
         $id = $_GPC['id'];
         $template = db_getPrintTemplate($id, true);
         if (empty($template)) {
             if ($_W['isajax']) {
                 echo '无效参数,无法获取模板信息';
                 exit;
             }
         }
         $disable = !empty($template['status']);
         $url = $this->createWebUrl('template', array('op' => $op, 'id' => $id));
         $map = $template['datamap'];
         $fields = biz_Print_getDataField($template['printtype']);
         if (empty($map)) {
             $map = array();
             foreach ($template['tags'] as $t) {
                 $map[$t] = '';
             }
         }
         $json = json_encode($map);
         if ($_W['isajax']) {
             include $this->template('tagEdit');
             exit;
         }
         if ($_W['token'] == $_GPC['token']) {
             $map = json_decode(htmlspecialchars_decode($_GPC['json']));
             $map = object_to_array($map);
             if (!$disable) {
                 $update = array('datamap' => iserializer($map));
                 pdo_update('printtemplate', $update, array('id' => $id));
                 message('模板标签数据已配置', $this->createWebUrl('template'));
             } else {
                 message('模板已启用,不允许修改', $this->createWebUrl('template'));
             }
         }
     }
     if ($op == 'set') {
         $this->CheckRight('tag');
         $id = $_GPC['id'];
         $template = db_getPrintTemplate($id, true);
         if (empty($template)) {
             message('无效打印模板', $this->createWebUrl('template'), 'error');
         }
         $disable = !empty($template['status']);
         $url = $this->createWebUrl('template', array('op' => 'set', 'id' => $id));
         $map = $template['datamap'];
         $fields = biz_Print_getDataField($template['printtype']);
         if (empty($map)) {
             $map = array();
             foreach ($template['tags'] as $t) {
                 $map[$t] = '';
             }
         }
         if ($_W['token'] == $_GPC['token']) {
             if (!$disable) {
                 $update = array('datamap' => iserializer($_GPC['map']));
                 pdo_update('printtemplate', $update, array('id' => $id));
                 message('模板标签数据已配置', $this->createWebUrl('template'));
             } else {
                 message('模板已启用,不允许修改', $this->createWebUrl('template'));
             }
         }
         include $this->template('tagSet2');
     }
 }