PageRenderTime 54ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/aoliz/core/admin/controller/order/ctl.delivery_printer.php

http://phpfor.googlecode.com/
PHP | 241 lines | 207 code | 34 blank | 0 comment | 26 complexity | 637906bf43aaaa6ec132b9c3932bcc04 MD5 | raw file
  1. <?php
  2. include_once('objectPage.php');
  3. define('DPGB_TMP_MODE',1);
  4. define('DPGB_HOME_MODE',2);
  5. class ctl_delivery_printer extends objectPage{
  6. var $workground = 'order';
  7. var $object='trading/dly_printer';
  8. var $finder_action_tpl = 'order/dly_printer_action.html';
  9. var $finder_default_cols = '_cmd,prt_tmpl_title,shortcut';
  10. var $filterUnable = true;
  11. function ctl_delivery_printer(){
  12. parent::objectPage();
  13. $this->pagedata['dpi'] = intval($this->system->getConf('system.clientdpi'));
  14. if(!$this->pagedata['dpi']){
  15. $this->pagedata['dpi'] = 96;
  16. }
  17. }
  18. function do_print(){
  19. $data = $_POST['order'];
  20. $data['shop_name'] = $this->system->getConf('system.shopname');
  21. $data['shop_name'] =str_replace('%','?',$data['shop_name']);
  22. $data['shop_name'] =str_replace('\'','’',$data['shop_name']);
  23. $obj_dly_center = &$this->system->loadModel('trading/dly_centers');
  24. $dly_center = $obj_dly_center->instance($_POST['dly_center']);
  25. $data['dly_name']=$dly_center['uname'];
  26. list($pkg,$regions,$region_id) = explode(':',$data['ship_area']);
  27. foreach(explode('/',$regions) as $i=>$region){
  28. $data['ship_area_'.$i]= $region;
  29. }
  30. if($dly_center['region']){
  31. list($pkg,$regions,$region_id) = explode(':',$dly_center['region']);
  32. foreach(explode('/',$regions) as $i=>$region){
  33. $data['dly_area_'.$i]= $region;
  34. }
  35. }
  36. $data['dly_address']=$dly_center['address'];
  37. $data['dly_tel']=$dly_center['phone'];
  38. $data['dly_mobile']=$dly_center['cellphone'];
  39. $data['dly_zip']=$dly_center['zip'];
  40. $t = time()+($GLOBALS['user_timezone']-SERVER_TIMEZONE)*3600;
  41. $data['date_y']=date('Y',$t);
  42. $data['date_m']=date('m',$t);
  43. $data['date_d']=date('d',$t);
  44. if(file_exists(HOME_DIR.'/upload/dly_bg_'.$_POST['dly_tmpl_id'].'.jpg')){
  45. $this->pagedata['tmpl_bg'] = 'index.php?ctl=order/delivery_printer&act=show_bg_picture&p[0]='.DPGB_HOME_MODE.'&p[1]='.$_POST['dly_tmpl_id'];
  46. }
  47. unset($data['ship_area']);
  48. $xmltool = &$this->system->loadModel('utility/xml');
  49. $data['order_print']=$data['order_id'];
  50. $this->pagedata['data'] = $xmltool->array2xml($data,'data');
  51. $this->pagedata['prt_tmpl'] = $this->model->instance($_POST['dly_tmpl_id'],'prt_tmpl_width,prt_tmpl_height,prt_tmpl_data');
  52. $this->display('order/print_dly_job.html');
  53. }
  54. function edit_tmpl($tmpl_id){
  55. if(PRINTER_FONTS){
  56. $this->pagedata['font'] = explode("|",PRINTER_FONTS);
  57. }
  58. if($this->pagedata['tmpl'] = $this->model->instance($tmpl_id)){
  59. if(file_exists(HOME_DIR.'/upload/dly_bg_'.$tmpl_id.'.jpg')){
  60. $this->pagedata['tmpl_bg'] = 'index.php?ctl=order/delivery_printer&act=show_bg_picture&p[0]='.DPGB_HOME_MODE.'&p[1]='.$tmpl_id;
  61. }
  62. $this->pagedata['elements'] = $this->model->getElements();
  63. $this->page('order/dly_printer_editor.html');
  64. }else{
  65. $this->splash('failed','index.php?ctl=order/delivery_printer&act=index',__('????????id'));
  66. }
  67. }
  68. function import(){
  69. $this->page('order/dly_printer_import.html');
  70. }
  71. function do_upload_pkg(){
  72. $this->begin('index.php?ctl=order/delivery_printer&act=import');
  73. $file = $_FILES['package'];
  74. $extname = strtolower(ext_name($file['name']));
  75. $tar = &$this->system->loadModel('utility/tar');
  76. if($extname=='.dtp'){
  77. if($tar->openTAR($file['tmp_name']) && $tar->containsFile('info')){
  78. if(!($info = unserialize($tar->getContents($tar->getFile('info'))))){
  79. trigger_error(__('????????,????????'),E_USER_ERROR);
  80. }
  81. if($tpl_id=$this->model->insert($info)){
  82. if($tar->containsFile('background.jpg')){ //?????
  83. file_put_contents(HOME_DIR.'/upload/dly_bg_'.$tpl_id.'.jpg',$tar->getContents($tar->getFile('background.jpg')));
  84. }
  85. }
  86. }else{
  87. trigger_error(__('?????,????????'),E_USER_ERROR);
  88. }
  89. }else{
  90. trigger_error(__('???shopex??????(.dtp)'),E_USER_ERROR);
  91. }
  92. $this->end(true,__('???????'),'index.php?ctl=order/delivery_printer&act=index');
  93. }
  94. function add_tmpl(){
  95. $this->pagedata['tmpl'] = array(
  96. 'prt_tmpl_title'=>'',
  97. 'prt_tmpl_width'=>240,
  98. 'prt_tmpl_height'=>135,
  99. );
  100. if(PRINTER_FONTS){
  101. $this->pagedata['font'] = explode("|",PRINTER_FONTS);
  102. }
  103. $this->pagedata['elements'] = $this->model->getElements();
  104. $this->page('order/dly_printer_editor.html');
  105. }
  106. function save(){
  107. $this->begin('index.php?ctl=order/delivery_printer&act=index');
  108. if($_POST['prt_tmpl_id']){
  109. if($this->model->update($_POST,array('prt_tmpl_id'=>$_POST['prt_tmpl_id']))){
  110. $tpl_id = $_POST['prt_tmpl_id'];
  111. }else{
  112. $tpl_id = false;
  113. }
  114. }else{
  115. $tpl_id = $this->model->insert($_POST);
  116. }
  117. $_POST['tmp_bg'] = trim($_POST['tmp_bg']);
  118. if($_POST['prt_tmpl_id']=='__none__'){
  119. }
  120. if($tpl_id && $_POST['tmp_bg']){
  121. if(file_exists(HOME_DIR.'/upload/dly_bg_'.$tpl_id.'.jpg')){
  122. unlink(HOME_DIR.'/upload/dly_bg_'.$tpl_id.'.jpg');
  123. }
  124. if(file_exists(HOME_DIR.'/tmp/'.$_POST['tmp_bg'])){
  125. file_rename(HOME_DIR.'/tmp/'.$_POST['tmp_bg'],HOME_DIR.'/upload/dly_bg_'.$tpl_id.'.jpg');
  126. }
  127. }
  128. $this->end(true,$tpl);
  129. }
  130. function add_same($tmpl_id){/*todo ???*/
  131. if($this->pagedata['tmpl'] = $this->model->instance($tmpl_id)){
  132. unset($this->pagedata['tmpl']['prt_tmpl_id']);
  133. $this->pagedata['elements'] = $this->model->getElements();
  134. $this->page('order/dly_printer_editor.html');
  135. }else{
  136. $this->splash('failed','index.php?ctl=order/delivery_printer&act=index',__('????????id'));
  137. }
  138. }
  139. function download($tmpl_id){
  140. $tmpl = $this->model->instance($tmpl_id,'prt_tmpl_title,prt_tmpl_width,prt_tmpl_height,prt_tmpl_data');
  141. $tar = &$this->system->loadModel('utility/tar');
  142. $tar->addFile('info',serialize($tmpl));
  143. if($bg = realpath(HOME_DIR.'/upload/dly_bg_'.$tmpl_id.'.jpg')){
  144. $tar->addFile('background.jpg',file_get_contents($bg));
  145. }
  146. $this->system->__session_close();
  147. $charset = &$this->system->loadModel('utility/charset');
  148. $name = $charset->utf2local($tmpl['prt_tmpl_title'],'zh');
  149. @set_time_limit(0);
  150. header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
  151. header('Content-type: application/octet-stream');
  152. header('Content-type: application/force-download');
  153. header('Content-Disposition: attachment; filename="'.$name.'.dtp"');
  154. $tar->getTar('output');
  155. }
  156. function upload_bg($printer_id){
  157. $this->pagedata['dly_printer_id'] = $printer_id;
  158. $this->display('order/dly_printer_uploadbg.html');
  159. }
  160. function do_upload_bg(){
  161. $this->begin('index.php?ctl=order/delivery_printer&act=do_upload_bg&p[0]=0');
  162. $extname = strtolower(ext_name($_FILES['background']['name']));
  163. if($extname=='.jpg' || $extname=='.jpeg'){
  164. $file = tempnam(HOME_DIR.'/tmp', 'dly_');
  165. unlink($file);
  166. $file.='.jpg';
  167. $rs = move_uploaded_file($_FILES['background']['tmp_name'],$file);
  168. }else{
  169. $this->splash('failed','index.php?ctl=order/delivery_printer&act=upload_bg',__('???.jpg???'));
  170. }
  171. $this->end($rs,__('???????????'),'index.php?ctl=order/delivery_printer&act=done_upload_bg&p[0]='.DPGB_TMP_MODE.'&p[1]='.basename($file));
  172. }
  173. function done_upload_bg($rs,$file){
  174. if($rs){
  175. $url = 'index.php?ctl=order/delivery_printer&act=show_bg_picture&p[0]='.$rs.'&p[1]='.$file;
  176. echo '<script>
  177. if($("dly_printer_bg")){
  178. $("dly_printer_bg").value = "'.$file.'";
  179. }else{
  180. new Element("input",{id:"dly_printer_bg",type:"hidden",name:"tmp_bg",value:"'.$file.'"}).inject("dly_printer_form");
  181. }
  182. window.printer_editor.dlg.close();
  183. window.printer_editor.setPicture("'.$url.'");
  184. </script>';
  185. }else{
  186. echo 'Error on upload:'.$file;
  187. }
  188. }
  189. function show_bg_picture($mode,$file){
  190. header('Content-Type: image/jpeg');
  191. if($mode==DPGB_TMP_MODE){
  192. $this->system->sfile(HOME_DIR.'/tmp/'.$file);
  193. }elseif($mode==DPGB_HOME_MODE){
  194. $this->system->sfile(HOME_DIR.'/upload/dly_bg_'.$file.'.jpg');
  195. }
  196. }
  197. function set_enable(){
  198. $this->begin('index.php?ctl=order/delivery_printer');
  199. $rs = $this->model->update(array('shortcut'=>'true'),$_POST);
  200. $this->end($rs);
  201. }
  202. function set_disabled(){
  203. $this->begin('index.php?ctl=order/delivery_printer');
  204. $rs = $this->model->update(array('shortcut'=>'false'),$_POST);
  205. $this->end($rs);
  206. }
  207. }