inputChajian.php 16 KB

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