/source/gl/ajax/xajax_Form.php

http://prosporous.googlecode.com/ · PHP · 229 lines · 195 code · 6 blank · 28 comment · 14 complexity · 7f82543a73b575b092586a34ce81bd00 MD5 · raw file

  1. <?php
  2. /**??????UTF-8???.
  3. * Created on 2010-5-17
  4. *
  5. * @author EXT <isrn@qq.com>
  6. *
  7. */
  8. require_once '../../includes/global.php';
  9. function loadUrl($title,$url,$width,$height,$mask,$id=''){
  10. $objResponse = new xajaxResponse();
  11. $id=$id==''?'addWindow':$id;
  12. $str2=" var addwin = new Ext.Window({
  13. id :'".$id."',
  14. title :'".$title."',
  15. iconCls:'plugin_edit',
  16. closable:true,
  17. closeAction :'close',
  18. plain:true,
  19. width:".$width.",
  20. height:".$height.",
  21. html:'<iframe scrolling=\"auto\" id=\"adel1828\" name=\"adel1828\" frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"".$url."\"></iframe>'
  22. });
  23. addwin.show();
  24. ";
  25. $str2=str_replace("\r","",$str2);
  26. $str2=str_replace("\n","",$str2);
  27. $str2=str_replace("\t","",$str2);
  28. $objResponse->script($str2);
  29. return $objResponse;
  30. }
  31. /*function loadUrl($title,$url,$width,$height,$mask,$id=''){
  32. $objResponse = new xajaxResponse();
  33. $id=$id==''?'addWindow':$id;
  34. $str2=" var addwin = new Ext.Window({
  35. id :'".$id."',
  36. title :'".$title."',
  37. iconCls:'plugin_edit',
  38. closable:true,
  39. closeAction :'close',
  40. plain:true,
  41. width:".$width.",
  42. height:".$height.",
  43. autoLoad:{url:'".$url."',nocache:true,scripts:true}
  44. });
  45. addwin.show();
  46. ";
  47. $str2=str_replace("\r","",$str2);
  48. $str2=str_replace("\n","",$str2);
  49. $str2=str_replace("\t","",$str2);
  50. $objResponse->script($str2);
  51. return $objResponse;
  52. }*/
  53. function items_config($tree_id,$field,$add=false){
  54. $objResponse = new xajaxResponse();
  55. $action = $add?'add':'save';
  56. $dbcfg=Sys::Gp(array('dbcfg','sevenel'));
  57. $p_id = "p_id:$tree_id";
  58. if(!$add){
  59. $field_data=Dgd(array(
  60. 'db'=>'d_sevenel',
  61. 'cd'=>"parent_tree = $tree_id and field_name ='$field' and is_shield = 0",
  62. 'tn'=>"fieldmod",
  63. 'limit'=>'1'
  64. ));
  65. $config = json_decode($field_data['config'],true);
  66. $c_id = "{$field_data['id']}";
  67. $type = $field_data['type'];
  68. }else{
  69. $c_id = '0';
  70. $type = $field;
  71. $tree=Dgd(array(
  72. 'db'=>'d_sevenel',
  73. 'cd'=>"id = $tree_id",
  74. 'tn'=>"tree",
  75. 'limit'=>'1'
  76. ));
  77. $tabname = gettabname($tree['table'],$dbcfg['prefix']);
  78. $field_=Dgd(array(
  79. 'db'=>'d_sevenel',
  80. 'cd'=>"parent_tree = $tree_id",
  81. 'tn'=>"fieldmod",
  82. 'column'=>'field_name'
  83. ));
  84. $fullfields = Dgd(array(
  85. 'db'=>'d_sevenel',
  86. 'sql'=>"SHOW FULL FIELDS FROM ".$tabname
  87. ));
  88. $doNotCreate=array('id','del','lg','gid','sortid','cataid');
  89. $existfields = array();
  90. if($field_ !=''){
  91. foreach ($field_ as $key=>$value){
  92. $existfields[] = $value['field_name'];
  93. }
  94. }
  95. foreach($fullfields as $arrow=>$data){
  96. if(!in_array($data['Field'],$existfields)&&!in_array($data['Field'],$doNotCreate)){
  97. $store_[]= "['{$data['Field']}']";
  98. }
  99. }
  100. if($store_==''){
  101. $str = "Ext.Msg.alert('??','????????!')";
  102. $objResponse->script($str);
  103. return $objResponse;
  104. }
  105. foreach($store_ as $array=>$f){
  106. $store .= $f;
  107. if($array < count($store_)-1){
  108. $store .= ',';
  109. }
  110. }
  111. $heigh = '+100';
  112. $items = "{
  113. xtype:'combo',
  114. id : 'combobox',
  115. name : 'field',
  116. width:130,
  117. fieldLabel:'????',
  118. store:new Ext.data.SimpleStore({
  119. fields:['value'],
  120. data:[$store]
  121. }),
  122. mode:'local',
  123. displayField:'value',
  124. triggerAction:'all'
  125. },
  126. ";
  127. $p_id=$tree_id;
  128. $type_="type:'$type',";
  129. }
  130. require_once '../form/items_config.php';
  131. foreach($type_array as $arrow => $value){
  132. if($value['name'] == $type){
  133. $elment = $value;
  134. }
  135. }
  136. switch($type){
  137. case 'checkboxgroup':
  138. case 'radiogroup':
  139. case 'combo':
  140. $str=" var addwin = new Ext.Window({
  141. id :'elment_config',
  142. title :'????',
  143. iconCls:'add',
  144. closable:true,
  145. closeAction :'close',
  146. plain:true,
  147. width:{$elment['width']},
  148. height:{$elment['height']},
  149. html:'<iframe scrolling=\"auto\" frameborder=\"0\" width=\"100%\" height=\"100%\" src=\"form/form_config.php?op=form_component&component=$type&c_id=$c_id&p_id=$p_id\"></iframe>'
  150. });
  151. addwin.show();
  152. ";
  153. break;
  154. default:
  155. if($elment['config'] != ''){
  156. foreach($elment['config'] as $key_ => $value_){
  157. $config!=''&&$v="value:'{$config[$value_['name']]}',";
  158. if($type == 'password'&&$config[$value_['name']]=='on'){
  159. $v = '"checked":true,';
  160. }
  161. $items.="{xtype:'{$value_['type']}',
  162. name:'{$value_['name']}',
  163. ".$v."
  164. fieldLabel:'{$value_['lable']}'}";
  165. $el_config .= $value_['name'];
  166. if($key<count($elment['config'])-1){
  167. $items.=',';
  168. $el_config.=',';
  169. }
  170. }
  171. }
  172. $el_config = ",param:'".$el_config."'";
  173. $bbar = ",bbar:['->',{xtype:'button',text:'??',handler:function(){
  174. Ext.getCmp('elment_form').form.doAction('submit',{
  175. url:'form/form_config.php',
  176. method:'POST',
  177. params:{require:'items_config_$action','pid':{$p_id},{$type_}id:'$c_id'$el_config},
  178. waitMsg:'????....',
  179. success:function(form,action){
  180. if (action.result.msg=='ok') {
  181. Ext.Msg.alert('????','???');
  182. addwin.close();
  183. } else {
  184. Ext.Msg.alert('????',action.result.msg);
  185. }
  186. }
  187. ,
  188. failure:function(){
  189. Ext.Msg.alert('??','???????');
  190. }
  191. });
  192. }}]";
  193. $str="var addwin = new Ext.Window({
  194. id :'elment_config',
  195. title :'????',
  196. closable:true,
  197. closeAction :'close',
  198. width:{$elment['width']},
  199. height:{$elment['height']}$heigh,
  200. items:[{
  201. xtype:'form',
  202. id:'elment_form',
  203. border:false,
  204. frame:true,
  205. style:'padding:10px',
  206. items:[".$items."]
  207. }]
  208. ".$bbar."
  209. });
  210. addwin.show();
  211. ";
  212. }
  213. $str=str_replace("\r","",$str);
  214. $str=str_replace("\n","",$str);
  215. $str=str_replace("\t","",$str);
  216. $objResponse->script($str);
  217. return $objResponse;
  218. }
  219. $xajax = new xajax();
  220. $xajax->registerFunction("loadUrl");
  221. $xajax->registerFunction("items_config");
  222. $xajax->processRequest();
  223. ?>