1
0

inputChajian.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <?php
  2. /**
  3. * 系统表单插件
  4. */
  5. class inputChajian extends Chajian
  6. {
  7. public $fieldarr = array();
  8. public $flow = null;
  9. public $ismobile = 0;
  10. public $urs = array();
  11. public $mid = 0;
  12. public $date,$now,$option;
  13. protected function initChajian()
  14. {
  15. $this->date = $this->rock->date;
  16. $this->now = $this->rock->now;
  17. $this->option = m('option');
  18. }
  19. public function initUser($uid)
  20. {
  21. $this->adminid = $uid;
  22. $this->urs = m('admin')->getone($uid, '`name`,`deptname`');
  23. $this->adminname= $this->urs['name'];
  24. }
  25. public function initFields($stwhe='')
  26. {
  27. $fieldarr = m('flow_element')->getrows($stwhe,'*','`sort`');
  28. foreach($fieldarr as $k=>$rs){
  29. $this->fieldarr[$rs['fields']] = $rs;
  30. }
  31. return $fieldarr;
  32. }
  33. /**
  34. * 读取表单样式(有默认值的)
  35. */
  36. public function getfieldcontval($fid, $val=false, $objs=null)
  37. {
  38. return $this->getfieldcont($fid, $objs,'',0, $val);
  39. }
  40. /**
  41. * 读取表单样式
  42. */
  43. public function getfieldcont($fid, $objs=null, $leox='', $iszb=0, $deval=false)
  44. {
  45. $fida= explode(',', $fid);$xu0='0';
  46. $ism = $this->ismobile;
  47. $fid = $fida[0];
  48. $str = $val ='';
  49. if(isset($fida[1]))$xu0=$fida[1];
  50. if($fid=='base_name'){
  51. $str = '<input class="inputs" style="border:none;background:none" name="base_name" value="'.$this->adminname.'" readonly>';
  52. }
  53. if($fid=='base_deptname'){
  54. $str = '<input class="inputs" style="border:none;background:none" name="base_deptname" value="'.$this->urs['deptname'].'" readonly>';
  55. }
  56. if($fid=='base_sericnum'){
  57. $str = '<input class="inputs" style="border:none;background:none" name="base_sericnum" value="'.$this->flow->createnum().'" readonly>';
  58. }
  59. if($fid=='file_content'){
  60. $str = '<input name="fileid" type="hidden" id="fileidview-inputEl"><div id="view_fileidview" style="width:98%;height:auto;min-height:60px;border:1px #cccccc solid; background:white;overflow:auto"></div><div id="fileupaddbtn"><a href="javascript:;" class="blue" onclick="c.upload()"><u>+添加文件</u></a></div>';
  61. }
  62. if($fid=='删'){
  63. $str='<a href="javascript:;" onclick="c.delrow(this,'.$xu0.')">删</a>';
  64. }
  65. if($fid=='新增'){
  66. $str='<a href="javascript:;" onclick="c.addrow(this,'.$xu0.')">+新增</a>';
  67. }
  68. if($str!='')return $str;
  69. if(!isset($this->fieldarr[$fid]))return '';
  70. $isasm = 1;
  71. $a = $this->fieldarr[$fid];
  72. $fname = $fid.$leox;
  73. $type = $a['fieldstype'];
  74. $placeholder = arrvalue($a, 'placeholder');
  75. $isbt = arrvalue($a, 'isbt');
  76. $data = $a['data'];
  77. $val = $a['dev'];
  78. if(isset($a['value']))$val=$a['value'];
  79. $attr = $a['attr'];
  80. $lens = (int)arrvalue($a, 'lens','0');
  81. $styles = '';
  82. $style = '';
  83. if(contain($attr,',')){
  84. $attra = explode(',', $a['attr']);
  85. $style = $attra[1];
  86. $attr = $attra[0];
  87. }
  88. if(!isempt($style))$styles=' style="'.$style.'"';
  89. $fnams = $this->rock->arrvalue($a,'name');$fieldname = $fnams;
  90. if($isbt==1)$fnams='*'.$fnams.'';
  91. $val = $this->rock->get('def_'.$fname.'', $val);
  92. if(isempt($val))$val='';
  93. if($deval !== false)$val = $deval; //设置默认值
  94. if(isempt($attr))$attr='';
  95. if($val!='' && contain($val,'{')){
  96. $val = m('base')->strreplace($val, $this->adminid, 1);
  97. if($val=='{sericnum}' && $this->flow!=null)$val = $this->flow->createnum();
  98. }
  99. if($type=='num'){
  100. if($this->flow != null){
  101. $val = $this->flow->createinputnum($data, $fid);
  102. }
  103. }
  104. //读默认值
  105. if($objs != null && method_exists($objs, 'inputfieldsval')){
  106. $_vals = $objs->inputfieldsval($fname, $a);
  107. if(!isempt($_vals))$val = $_vals;
  108. }
  109. if(!isempt($placeholder))$attr.=' placeholder="'.$placeholder.'"';
  110. if($type=='email' || $type=='tel' || $type=='mobile' || $type=='url'){
  111. $attr.=' inputtype="'.$type.'"';
  112. }
  113. $lenstr = '';
  114. if($lens>0)$lenstr=' maxlength="'.$lens.'"';
  115. $onblue = ' onblur="c.inputblur(this, '.$iszb.')"';
  116. $iszhang= false;
  117. if($type=='text' && !isempt($data)){
  118. $attr.=' onkeyup="c.autocomplete(this,\''.$data.'\','.$a['id'].', '.$iszb.',event)" onclick="this.onkeyup()"';
  119. }
  120. $str = '<input class="inputs" type="text" value="'.$val.'" '.$attr.''.$onblue.''.$styles.''.$lenstr.' name="'.$fname.'">';
  121. if($type=='fixed'||$type=='hidden'){
  122. $str = '<input value="'.$val.'" '.$attr.' type="hidden" name="'.$fname.'">';
  123. $isasm=0;
  124. }
  125. if($type=='textarea'){
  126. $iszhang= false;
  127. $str = '<textarea class="textarea" onblur="js.changdu(this)" style="height:80px;'.$style.'" '.$attr.''.$lenstr.' name="'.$fname.'">'.$val.'</textarea>';
  128. }
  129. if($type=='rockcombo' || $type=='select' || $type=='checkboxall' || $type=='radio'){
  130. $attr.=' onchange="c.inputblur(this, '.$iszb.')"';
  131. $str ='<select style="width:99%;'.$style.'" '.$attr.' name="'.$fname.'" class="inputs">';
  132. $str.='<option value="">-请选择-</option>';
  133. $str1= '';
  134. $str2= '';
  135. $datanum = $data;
  136. $fopt = $this->getdatastore($type, $objs, $datanum, $fid);
  137. $optgroup = '';
  138. if($fopt)foreach($fopt as $k=>$rs){
  139. $_val= arrvalue($rs,'value', $rs['name']);
  140. $sel = ($_val==$val)?'selected':'';
  141. $sel2 = ($_val==$val)?'checked':'';
  142. $ocn = '';
  143. if($type=='select')foreach($rs as $k1=>$v1)if($k1!='id'&&$k1!='value'&&$k1!='name')$ocn.=' '.$k1.'="'.$v1.'"';
  144. if($type=='select' && isset($rs['optgroup']) && !isempt($rs['optgroup'])){
  145. if($optgroup!=$rs['optgroup']){
  146. if($optgroup!='')$str.='</optgroup>';
  147. $str.='<optgroup label="'.$rs['optgroup'].'">';
  148. }
  149. $optgroup = $rs['optgroup'];
  150. }
  151. $str.='<option'.$ocn.' value="'.$_val.'" '.$sel.'>'.$rs['name'].'</option>';
  152. $str1.='<label><input name="'.$fname.'[]" value="'.$_val.'" type="checkbox">'.$rs['name'].'</label>&nbsp;&nbsp;';
  153. $str2.='<label><input'.$ocn.' name="'.$fname.'" '.$sel2.' value="'.$_val.'" type="radio">'.$rs['name'].'</label>&nbsp;&nbsp;';
  154. }
  155. if($type=='select' && $optgroup!='')$str.='</optgroup>';
  156. $str.='</select>';
  157. if($type=='checkboxall')$str = $str1;
  158. if($type=='radio')$str = $str2;
  159. }
  160. if($type=='datetime'||$type=='date'||$type=='time'||$type=='month'){
  161. $str = '<input onclick="js.datechange(this,\''.$type.'\')" value="'.$val.'" '.$attr.''.$onblue.''.$styles.' class="inputs datesss" inputtype="'.$type.'" readonly name="'.$fname.'">';
  162. }
  163. //数字类型
  164. if($type=='number'){
  165. $xiaoshu= arrvalue($a,'xiaoshu','0');
  166. $str = '<input class="inputs" xiaoshu="'.$xiaoshu.'" '.$attr.''.$styles.' value="'.$val.'" type="number" onfocus="js.focusval=this.value" '.$lenstr.' onblur="js.number(this);c.inputblur(this,'.$iszb.')" name="'.$fname.'">';
  167. }
  168. if($type=='xuhao'){
  169. $str = '<input class="inputs xuhao" '.$attr.' type="text" value="'.$val.'" name="'.$fname.'">';
  170. $str.= '<input value="0" type="hidden" name="'.$a['fieldss'].$leox.'">';
  171. }
  172. if($type=='changeusercheck'||$type=='changeuser'||$type=='changedept'||$type=='changedeptcheck'||$type=='changedeptusercheck'){
  173. $zbnae = $data;
  174. if($iszb>0)$zbnae = $data.''.($iszb-1).''.$leox.'';
  175. $str = $this->inputchangeuser(array(
  176. 'name' => $fname,
  177. 'id' => $zbnae,
  178. 'value' => $val,
  179. 'type' => $type,
  180. 'title' => $fieldname,
  181. 'changerange' => arrvalue($a, 'gongsi'),
  182. 'placeholder' => $placeholder,
  183. 'attr' => $onblue,
  184. 'style' => '',
  185. ));
  186. }
  187. if($type=='selectdatafalse' || $type=='selectdatatrue'){
  188. $str = '<table width="98%" cellpadding="0" border="0"><tr><td width="100%"><input '.$attr.''.$onblue.''.$styles.' class="inputs" style="width:99%" value="'.$val.'" readonly type="text" name="'.$fname.'"></td>';
  189. $str .= '<td nowrap>';
  190. if($isbt=='0')$str .= '<button onclick="c.selectdataclear(\''.$fname.'\',\''.$data.'\','.$iszb.')" class="webbtn" type="button">x</button>';
  191. $str .= '<button type="button" onclick="c.selectdata(\''.$data.'\','.substr($type,10).',\''.$fname.'\',\''.$fieldname.'\','.$iszb.')" class="webbtn">选</button></td></tr></table>';
  192. }
  193. if($type=='ditumap'){
  194. $zbnae = $data;
  195. if($iszb>0)$zbnae = ''.($iszb-1).''.$leox.'';
  196. $str = '<table width="99%" cellpadding="0" border="0"><tr><td width="100%"><input '.$attr.''.$onblue.''.$styles.''.$lenstr.' class="inputs" style="width:99%" value="'.$val.'" type="text" name="'.$fname.'"></td>';
  197. $str .= '<td nowrap>';
  198. if($isbt=='0')$str .= '<button onclick="c.selectmapclear(\''.$fname.'\',\''.$zbnae.'\','.$iszb.')" class="webbtn" type="button">x</button>';
  199. $str .= '<button type="button" onclick="c.selectmap(\''.$fname.'\',\''.$zbnae.'\',\''.$fieldname.'\','.$iszb.')" class="webbtn">选</button></td></tr></table>';
  200. }
  201. if($type=='htmlediter'){
  202. $iszhang= false;
  203. $str = '<textarea class="textarea" style="height:130px;'.$style.'" '.$attr.' name="'.$fname.'">'.$val.'</textarea>';
  204. }
  205. if($type=='checkbox'){
  206. $chk = '';
  207. if($val=='1'||$val=='true')$chk='checked';
  208. $str = '<input name="'.$fname.'" '.$chk.' '.$attr.''.$styles.' type="checkbox" value="1"> ';
  209. }
  210. if($type=='uploadimg'){
  211. $str1= '<a href="javascript:;" onclick="c.uploadfileis(\''.$fname.'\',1)">库中选</a>&nbsp;';
  212. if(M=='login' || $this->adminid==0 || $a['attr']=='onlychange')$str1='';
  213. $str = '<input name="'.$fname.'" value="'.$val.'" type="hidden">';
  214. $str.= '<img src="images/noimg.jpg" onclick="c.showviews(this)" id="imgview_'.$fname.'" height="100">';
  215. $str.= '<div style="display:" tsye="img" tnam="'.$fname.'" id="filed_'.$fname.'"><a href="javascript:;" onclick="c.uploadimgclear(\''.$fname.'\')">删</a>&nbsp;'.$str1.'<input onclick="c.initupss(\''.$fname.'\');" type="file" style="width:120px" accept="image/jpg,image/jpeg,image/png" id="filed_'.$fname.'_inp"></div>';
  216. }
  217. if($type=='uploadfile'){
  218. $str = '<input name="'.$fname.'" value="'.$val.'" type="hidden">';
  219. $str.= '<div style="display:inline-block" id="fileview_'.$fname.'"><div onclick="c.uploadfilei(\''.$fname.'\',\''.$a['attr'].'\')" style="display:;border:dashed 1px #cccccc" id="'.$fname.'_divadd" class="upload_items"><img class="imgs" src="images/jia.png"></div></div>';
  220. $str.= '<div style="display:none" tsye="file" tnam="'.$fname.'" tdata="'.$data.'" id="filed_'.$fname.'"><input type="file" style="width:120px" multiple="multiple" id="filed_'.$fname.'_inp"></div>';
  221. }
  222. if($type=='graph'){
  223. $str = '<input name="'.$fname.'" value="'.$val.'" type="hidden">';
  224. $str.= '<div id="graphview_'.$fname.'" >';
  225. $str.= '<button type="button" onclick="c.autograph(\''.$fname.'\',0)" class="webbtn">手写</button><button type="button" onclick="c.autograph(\''.$fname.'\',1)" class="webbtn">引入</button><button onclick="c.autograph(\''.$fname.'\',2)" class="webbtn" type="button">x</button></div>';
  226. }
  227. if($type=='auto'){
  228. $datanum = $data;
  229. if(!isempt($datanum)){
  230. if($objs!=null && method_exists($objs, $datanum)){
  231. $str = $objs->$datanum($this->mid, $this->flow);
  232. }
  233. }
  234. }
  235. if($iszb>0)return $str;
  236. if($isasm==1){
  237. $lx = 'span';if($ism==1)$lx='div';
  238. $str = '<'.$lx.' id="div_'.$fname.'" class="divinput">'.$str.'</'.$lx.'>';
  239. if($ism==1 && $iszb==0){
  240. if($iszhang){
  241. $str = '<tr class="lumtr"><td colspan="2"><div style="padding-left:10px;padding-top:10px">'.$fnams.'</div>'.$str.'</td></tr>';
  242. }else{
  243. $str = '<tr class="lumtr"><td class="lurim" nowrap>'.str_replace(' ','<br>', $fnams).'</td><td width="90%">'.$str.'</td></tr>';
  244. }
  245. }
  246. }
  247. return $str;
  248. }
  249. /**
  250. * 输出选择人员html
  251. */
  252. public function inputchangeuser($arr=array())
  253. {
  254. $oarr = array(
  255. 'name'=>'',
  256. 'id'=>'',
  257. 'type'=>'changeuser',
  258. 'value'=> '',
  259. 'valueid'=> '',
  260. 'title' => '',
  261. 'changerange' => '',
  262. 'placeholder' => '',
  263. 'attr' => '',
  264. );
  265. foreach($arr as $k=>$v)$oarr[$k]=$v;
  266. $fname = $oarr['name'];
  267. $zbnae = $oarr['id'];
  268. $type = $oarr['type'];
  269. $valea = explode('|', $oarr['value']);
  270. $_vals0 = $valea[0];
  271. $_vals1 = arrvalue($valea,1, $oarr['valueid']);
  272. $str = '<table width="99%" cellpadding="0" border="0"><tr><td width="100%"><input class="inputs" style="width:99%" '.$oarr['attr'].' placeholder="'.$oarr['placeholder'].'" id="change'.$fname.'" value="'.$_vals0.'" readonly type="text" name="'.$fname.'"><input name="'.$zbnae.'" value="'.$_vals1.'" id="change'.$fname.'_id" type="hidden"></td>';
  273. $str .= '<td nowrap><button onclick="js.changeclear(\'change'.$fname.'\')" class="webbtn" type="button">x</button><button id="btnchange_'.$fname.'" onclick="js.changeuser(\'change'.$fname.'\',\''.$type.'\',\''.$oarr['title'].'\' ,{changerange:\''.$oarr['changerange'].'\'})" type="button" class="webbtn">选</button></td></tr></table>';
  274. return $str;
  275. }
  276. private function issql($str)
  277. {
  278. $bo = false;
  279. $str = strtoupper($str);
  280. if(contain($str,' FROM '))$bo=true;
  281. return $bo;
  282. }
  283. public function getdatastore($type, $objs, $datanum, $fid='')
  284. {
  285. $fopt = array();
  286. $tyepa = explode(',','rockcombo,select,checkboxall,radio');
  287. if(!in_array($type, $tyepa) || isempt($datanum))return $fopt;
  288. //判断是不是SQL([SQL] name,value from [Q]abc)
  289. if($this->issql($datanum)){
  290. $sql = str_replace('[SQL]','select ', $datanum);
  291. $sql = m('base')->strreplace($sql);
  292. $rows = $this->db->getall($sql);
  293. if($rows)foreach($rows as $k=>$rs){
  294. $nam = arrvalue($rs,'name');
  295. $val = $nam;
  296. if(isset($rs['id']))$val = $rs['id'];
  297. if(isset($rs['value']))$val = $rs['value'];
  298. $fopt[] = array(
  299. 'name' => $nam,
  300. 'value' => $val,
  301. );
  302. }
  303. }
  304. //2021-02-26新增新的数据源,开头
  305. if(substr($datanum,0,1)==','){
  306. return $this->sqlstore($datanum);
  307. }
  308. //用:读取model上的数据
  309. if(!$fopt && !isempt($datanum) && contain($datanum,':')){
  310. $tata = explode(',', $datanum);
  311. $acta = explode(':', $tata[0]);
  312. $objs = m($acta[0]);
  313. $tacs = $acta[1];
  314. $cshu1= arrvalue($tata, 1);
  315. if(method_exists($objs, $tacs)){
  316. $fopt = $objs->$tacs($cshu1);
  317. if(is_array($fopt)){
  318. return $fopt;
  319. }
  320. }
  321. }
  322. //自定义方法读取数据源
  323. if(!$fopt && $objs!=null && method_exists($objs, $datanum)){
  324. $fopt = $objs->$datanum($fid,$this->mid);
  325. if(is_array($fopt)){
  326. return $fopt;
  327. }
  328. }
  329. //从flow上读取
  330. if(!$fopt && $this->flow!=null && method_exists($this->flow, $datanum)){
  331. $fopt = $this->flow->$datanum($fid,$this->mid);
  332. if(is_array($fopt)){
  333. return $fopt;
  334. }
  335. }
  336. if(!$fopt && ($type=='rockcombo' || $type=='checkboxall' || $type=='radio')){
  337. $_ars = explode(',', $datanum);
  338. $fopt = $this->option->getselectdata($_ars[0], isset($_ars[2]));
  339. $fvad = 'name';
  340. if(isset($_ars[1])&&($_ars[1]=='value'||$_ars[1]=='id'||$_ars[1]=='num'))$fvad=$_ars[1];
  341. if($fopt){
  342. foreach($fopt as $k=>$rs){
  343. $fopt[$k]['value'] = $rs[$fvad];
  344. }
  345. if($type=='rockcombo' && $fvad=='name' && M=='input'){
  346. //$fopt[] = array('name' => '其它..','value' => $_ars[0],);
  347. }
  348. }
  349. }
  350. if(!$fopt && ($type=='select' || $type=='checkboxall' || $type=='radio')){
  351. $fopt = c('array')->strtoarray($datanum);
  352. $barr = array();
  353. foreach($fopt as $k=>$rs){
  354. $barr[] = array(
  355. 'name' => $rs[1],
  356. 'value' => $rs[0],
  357. );
  358. }
  359. $fopt = $barr;
  360. }
  361. return $fopt;
  362. }
  363. /**
  364. * 新的获取数据源方法
  365. */
  366. public function sqlstore($actstr1)
  367. {
  368. $rows = array();
  369. $acta = explode(',', $actstr1);
  370. if(count($acta)>=3){
  371. if($acta[1]){
  372. $cats = explode(','.$acta[1].',', $actstr1);
  373. $sqlw = $cats[1];
  374. }else{
  375. $sqlw = substr($actstr1,2);
  376. }
  377. $sqla = explode('|', $sqlw);
  378. $wher = arrvalue($sqla,2,'1=1');
  379. if(contain($wher,'{'))$wher = m('where')->getstrwhere($wher,$this->adminid);
  380. $wher = str_replace('$','"', $wher);
  381. $rowa = m($sqla[0])->getall($wher,$sqla[1]);
  382. $ndf = 'name';
  383. $vdf = 'id';
  384. if($rowa)foreach($rowa as $k=>$rs1){
  385. if($k==0){
  386. if(!isset($rs1[$ndf])){
  387. foreach($rs1 as $k1=>$v1){$ndf = $k1;break;}
  388. }
  389. if(!isset($rs1[$vdf])){
  390. $xus = 0;
  391. foreach($rs1 as $k1=>$v1){
  392. $xus++;
  393. $vdf = $k1;
  394. if($xus>=2)break;
  395. }
  396. }
  397. }
  398. $rs1['name'] = $rs1[$ndf];
  399. $rs1['value'] = $rs1[$vdf];
  400. $rows[] = $rs1;
  401. }
  402. }
  403. return $rows;
  404. }
  405. /**
  406. * 创建签名图片生成的
  407. */
  408. public function createqianming($_val)
  409. {
  410. if(isempt($_val))return '';
  411. if(substr($_val,0,10)=='data:image'){
  412. $_vlu = ''.UPDIR.'/'.date('Y-m').'/qmimg'.time().''.rand(10,99).'.png';
  413. $bar= explode(',', $_val);
  414. $bo = $this->rock->createtxt($_vlu, base64_decode($bar[1]));
  415. if($bo)$_val = $_vlu;
  416. }
  417. return $_val;
  418. }
  419. }
粤ICP备19079148号