column.class.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <?php
  2. if (!defined('IN_ONLINE')) {
  3. exit('Access Denied');
  4. }
  5. class column {
  6. private static $_column;
  7. public static function getInstance() {
  8. if (!self::$_column) {
  9. $c = __CLASS__;
  10. self::$_column = new $c;
  11. }
  12. return self::$_column;
  13. }
  14. public function settingDisplayForVIPReport() {
  15. $data = array();
  16. //判断是否重置
  17. $level = common::check_input($_REQUEST['level']);
  18. $serial_no = common::check_input($_REQUEST['serial_no']);
  19. $defualt = common::check_input($_REQUEST['defualt']);
  20. if($level == "Shipment level"){
  21. $levelSQlWhere = "level = 'Shipment level'";
  22. $rightSqlwhere = " and shipment_level_default = true order by shipment_level_default_order";
  23. $leftSqlwhere = " and coalesce(shipment_level_default,false) = false";
  24. }elseif($level == "Container Level"){
  25. $levelSQlWhere = "level in ('Shipment level','Container Level')";
  26. $rightSqlwhere = " and ctnr_level_default = true order by ctnr_level_default_order";
  27. $leftSqlwhere = " and coalesce(ctnr_level_default,false) = false";
  28. }else {
  29. $levelSQlWhere = " 1=1 ";
  30. $rightSqlwhere = " and item_level_default = true order by item_level_default_order";
  31. $leftSqlwhere = " and coalesce(item_level_default,false) = false";
  32. }
  33. $kln_report_field_str = " id as ids,
  34. code as \"fieldBb\",
  35. display_name as field,
  36. display_name as label,
  37. level as \"fieldLevel\",
  38. 'System' as \"fieldType\",
  39. data_type as \"dataType\",
  40. group_name as \"groupName\" ";
  41. $kln_report_field_config = " field_id as ids,
  42. field_db as \"fieldBb\",
  43. field_display_name as field,
  44. field_display_name as label,
  45. field_level as \"fieldLevel\",
  46. field_type as \"fieldType\",
  47. data_type as \"dataType\",
  48. field_group_name as \"groupName\" ";
  49. $allData = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." order by id");
  50. if(empty($serial_no) || $defualt == 'true'){
  51. //代表第一次添加或者用户恢复默认顺序
  52. $groupSetting = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." ".$rightSqlwhere);
  53. $dataLeft = common::excuteListSql("select ".$kln_report_field_str." from public.kln_report_field where ".$levelSQlWhere." ".$leftSqlwhere." order by id");
  54. }else{
  55. $groupSetting = common::excuteListSql("select ".$kln_report_field_config." from public.kln_report_field_config
  56. where template_serial_no = '$serial_no' and field_type = 'System' order by id");
  57. $dataLeft = common::excuteListSql("select ".$kln_report_field_str."from public.kln_report_field
  58. where level = '$level' and id != ALL(select field_ids from public.kln_report_template where serial_no = '$serial_no' and field_type = 'System')
  59. order by id");
  60. }
  61. $children['All'] = array();
  62. $children['Reference No.'] = array();
  63. $children['General'] = array();
  64. $children['Parties'] = array();
  65. $children['Packing'] = array();
  66. $children['Time'] = array();
  67. $children['Places'] = array();
  68. $children['Transportation'] = array();
  69. $children['Milestone'] = array();
  70. $children['Container info'] = array();
  71. $children['Container Status'] = array();
  72. $children['Item info'] = array();
  73. $children['Others'] = array();
  74. $groupColumns_all = $this->allGroupVipReprotColumns($allData,$children);
  75. //总分组的检索要去掉右边的已经选中的部分
  76. $groupColumns_left = $this->allGroupVipReprotColumns($dataLeft,$children);
  77. $data['GroupColumnsAll'] = $groupColumns_all;
  78. $data['GroupColumnsLeft'] = $groupColumns_left;
  79. $data['GroupColumnsRight'] = $groupSetting;
  80. common::echo_json_encode(200,$data);
  81. exit;
  82. }
  83. public function settingDisplay($model_name, $url, $type = null) {
  84. $data = array();
  85. //判断是否重置
  86. if(!empty($_REQUEST['reset']) && $_REQUEST['reset'] == "yes"){
  87. // common::excuteUpdateSql("update ra_online_search_display_config_cso set ids = ''
  88. // where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'");
  89. }
  90. if (empty($type)) {
  91. if($model_name <> 'destination_delivery_shipment_search'){
  92. //预先初始化,空的也要保留
  93. $children['All'] = array();
  94. $children['Reference No.'] = array();
  95. $children['General'] = array();
  96. $children['Parties'] = array();
  97. $children['Packing'] = array();
  98. $children['Time'] = array();
  99. $children['Places'] = array();
  100. $children['Transportation'] = array();
  101. $children['Others'] = array();
  102. }else{
  103. //预先初始化,空的也要保留.只需要ALL
  104. $children['All'] = array();
  105. }
  106. $allData = $this->getDisplayColumnAllReomveDefault($model_name);
  107. $groupColumns_all = $this->allGroupColumns($allData,$children);
  108. //总分组的检索要去掉右边的已经选中的部分
  109. $dataLeft = $this->getDisplayColumn($model_name,false);
  110. $groupColumns_left = $this->allGroupColumns($dataLeft,$children);
  111. $setting = $this->getDisplayColumn($model_name);
  112. $groupSetting = $this->groupColumnsSetting($setting);
  113. $data['GroupColumnsAll'] = $groupColumns_all;
  114. $data['GroupColumnsLeft'] = $groupColumns_left;
  115. $data['GroupColumnsRight'] = $groupSetting;
  116. }
  117. //search目前页面没有
  118. //$data['search_setting'] = search::getInstance()->getDisplayColumn($model_name);
  119. //$data['search_diff'] = search::getInstance()->getDisplayColumn($model_name, FALSE);
  120. $data['model_name'] = $model_name;
  121. $data['url'] = $url;
  122. common::echo_json_encode(200,$data);
  123. exit;
  124. }
  125. //改为从新的配置表和配置信息,与旧的分开
  126. public function getDisplayColumn($model_name, $isin = true) {
  127. //测试服务器,改为UAT字段
  128. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  129. $model_name = "UAT_".$model_name;
  130. }
  131. $rs = null;
  132. $sql = "select ids from public.ra_online_search_display_config_cso where lower(login_name)='" . strtolower(_getLoginName()) . "' and lower(model_name) = '" . strtolower($model_name) . "'";
  133. $rs = common::excuteOneSql($sql);
  134. if(!empty($_REQUEST['reset']) && $_REQUEST['reset'] == "yes"){
  135. $rs = array();
  136. }
  137. if (empty($rs)) {
  138. $sql = "select array_to_string(array(select id from public.ra_online_search_display_cso where active = true and default_display = true and lower(model_name) = '" . strtolower($model_name) . "'";
  139. if (_isCustomerLogin())
  140. $sql .= " and customer_display = true";
  141. $sql .= " order by default_order asc), ',')";
  142. $rs = common::excuteOneSql($sql);
  143. }
  144. if ($isin) {
  145. $sql = $this->_getSql($rs);
  146. $rss = common::excuteListSql($sql);
  147. } else {
  148. $sql = "SELECT id, display_name as name, database_column_name, column_width,group_name FROM public.ra_online_search_display_cso WHERE active = true and lower(model_name) = '" . strtolower($model_name) . "' and id not in ($rs)";
  149. if (_isCustomerLogin())
  150. $sql .= ' and customer_display=true';
  151. $rss = common::excuteListSql($sql);
  152. }
  153. //旧版本去除新加__字段
  154. $action = strtolower($_REQUEST['action']);
  155. if (Soure == 'TopOcean' && empty(common::isNewVersion())
  156. && ($action =="ocean_order" || $action == "ocean_booking" || $action == "containers")){
  157. $rss = common::removeTopOceanOldVersionSpecialField($rss);
  158. }
  159. return $rss;
  160. }
  161. public function _getSql($ids) {
  162. $ids_arr = explode(',', $ids);
  163. $sql = "";
  164. foreach ($ids_arr as $value) {
  165. if (!empty($value)) {
  166. if (empty($sql)) {
  167. $sql .= 'SELECT id, display_name as name, database_column_name,column_width,group_name FROM public.ra_online_search_display_cso where active=true and id = ' . $value;
  168. if (_isCustomerLogin())
  169. $sql .= ' and CUSTOMER_DISPLAY = true';
  170. } else {
  171. $sql .= ' union all SELECT id, display_name as name, database_column_name,column_width,group_name FROM public.ra_online_search_display_cso where active=true and id = ' . $value;
  172. if (_isCustomerLogin())
  173. $sql .= ' and CUSTOMER_DISPLAY = true';
  174. }
  175. }
  176. }
  177. return $sql;
  178. }
  179. public function saveSettingDisplay($newid, $search_id, $model_name) {
  180. //测试服务器,改为UAT字段
  181. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  182. $model_name = "UAT_".$model_name;
  183. }
  184. global $db;
  185. $login_name = _getLoginName();
  186. $db->StartTrans();
  187. if ($this->checkUserDisplaySetting($model_name) === TRUE) {
  188. $sql = "UPDATE public.ra_online_search_display_config_cso SET ids = '" . common::check_input($newid) . "' WHERE lower(model_name) = '" . common::check_input(strtolower($model_name)) . "' AND lower(login_name) = '" . common::check_input(strtolower($login_name)) . "'";
  189. } else {
  190. $sql = "INSERT INTO public.ra_online_search_display_config_cso (LOGIN_NAME, MODEL_NAME, ids) VALUES ('" . common::check_input($login_name) . "', '" . common::check_input($model_name) . "', '" . common::check_input($newid) . "')";
  191. }
  192. //search 部分的数据不做查询
  193. //search::getInstance()->saveSettingDisplay($search_id, $model_name);
  194. common::excuteUpdateSql($sql);
  195. $db->CompleteTrans();
  196. }
  197. /*
  198. * check user had setting display
  199. */
  200. public function checkUserDisplaySetting($model_name) {
  201. $login_name = _getLoginName();
  202. $sql = "select ids from public.ra_online_search_display_config_cso where lower(login_name)='" . strtolower($login_name) . "' and lower(model_name) = '" . strtolower($model_name) . "'"; //check login_name is setting
  203. $rs = common::excuteObjectSql($sql);
  204. if (!empty($rs)) {
  205. return TRUE;
  206. }
  207. return FALSE;
  208. }
  209. public function getSearchSql($model_name) {
  210. //测试服务器,改为UAT字段
  211. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  212. $model_name = "UAT_".$model_name;
  213. }
  214. $sql = "";
  215. $ss = "SELECT database_column_name, display_name FROM public.ra_online_search_display_cso WHERE lower(model_name) = '" . strtolower($model_name) . "'";
  216. if (_isCustomerLogin())
  217. $ss .= ' and customer_display=true';
  218. $rss = common::excuteListSql($ss);
  219. //旧版本去除新加__字段
  220. $action = strtolower($_REQUEST['action']);
  221. $rss = common::removeTopOceanOldVersionSpecialField($rss);
  222. //不和以前重命名有冲突,改为database_column_name,display 显示由固定配置设置
  223. foreach ($rss as $v) {
  224. if ($sql == '')
  225. $sql .= $v['database_column_name'];
  226. else
  227. $sql .= ',' . $v['database_column_name'];
  228. }
  229. return ' ' . $sql . ' ';
  230. }
  231. //search 查询
  232. public function getSearchSqlForDisplay($model_name) {
  233. //测试服务器,改为UAT字段
  234. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  235. $model_name = "UAT_".$model_name;
  236. }
  237. $sql = "";
  238. $ss = "SELECT database_column_name, display_name FROM public.ra_online_search_display_cso WHERE lower(model_name) = '" . strtolower($model_name) . "'";
  239. if (_isCustomerLogin())
  240. $ss .= ' and customer_display=true';
  241. $rss = common::excuteListSql($ss);
  242. //旧版本去除新加__字段
  243. $action = strtolower($_REQUEST['action']);
  244. $rss = common::removeTopOceanOldVersionSpecialField($rss);
  245. foreach ($rss as $v) {
  246. if($v['database_column_name'] == "other_refenrence_no" && $model_name = "Ocean_Search"){
  247. continue;
  248. }
  249. if (empty($v['database_column_name'])) {
  250. if ($sql == '')
  251. $sql .= '\'' . $v['display_name'] . '\'';
  252. else
  253. $sql .= ', \'' . $v['display_name'] . '\'';
  254. }else {
  255. if ($sql == '')
  256. $sql .= $v['database_column_name'] . ' as "' . $v['display_name'] . '"';
  257. else
  258. $sql .= ', ' . $v['database_column_name'] . ' as "' . $v['display_name'] . '"';
  259. }
  260. }
  261. return ' ' . $sql . ' ';
  262. }
  263. public function getDisplayColumnAll($model_name) {
  264. $sql = "SELECT id, display_name as name, database_column_name as db,database_column_name, column_width,group_name FROM public.ra_online_search_display_cso WHERE default_display = true and active=true and lower(model_name) = '" . strtolower($model_name) . "'";
  265. if (_isCustomerLogin())
  266. $sql .= ' and customer_display=true';
  267. $sql .= " order by order_by,display_name";
  268. $rss = common::excuteListSql($sql);
  269. return $rss;
  270. }
  271. public function getDisplayColumnAllReomveDefault($model_name) {
  272. //测试服务器,改为UAT字段
  273. if(utils::startWith($_SERVER["HTTP_HOST"],"online-beta.kln.com")){
  274. $model_name = "UAT_".$model_name;
  275. }
  276. $sql = "SELECT id, display_name as name, database_column_name as db,database_column_name, column_width,group_name FROM public.ra_online_search_display_cso WHERE active=true and lower(model_name) = '" . strtolower($model_name) . "'";
  277. if (_isCustomerLogin())
  278. $sql .= ' and customer_display=true';
  279. $sql .= " order by order_by";
  280. $rss = common::excuteListSql($sql);
  281. return $rss;
  282. }
  283. public function tableColumns($type,$column){
  284. $tableColumns = array();
  285. foreach ($column as $key => $rs) {
  286. $temp = array();
  287. $temp['field'] = $rs['database_column_name'];
  288. $temp['title'] = $rs['name'];
  289. $spconfig = $this->specialTableConfig($type);
  290. if (!empty($spconfig[$rs['database_column_name']]['type'])){
  291. $temp['type'] = $spconfig[$rs['database_column_name']]['type'];
  292. }else{
  293. $temp['type'] = "normal";
  294. }
  295. //formatter
  296. if (!empty($spconfig[$rs['database_column_name']]['formatter'])){
  297. $temp['formatter'] = $spconfig[$rs['database_column_name']]['formatter'];
  298. if($temp['formatter'] == "number"){
  299. $temp['digits'] = $spconfig[$rs['database_column_name']]['digits'];
  300. }
  301. }else{
  302. $temp['formatter'] = "";
  303. }
  304. //这两个的field 不用as display
  305. if(!($type == "Destination_Delivery_Search" || $type == "destination_delivery_shipment_search")){
  306. $temp['field'] = $rs['name'];
  307. }
  308. $tableColumns[] = $temp;
  309. }
  310. return $tableColumns;
  311. }
  312. public function groupColumnsSetting($column){
  313. $groupSetting = array();
  314. foreach ($column as $key => $rs) {
  315. $temp = array();
  316. $temp['ids'] = $rs['id'];
  317. $temp['field'] = $rs['database_column_name'];
  318. $temp['label'] = $rs['name'];
  319. $groupSetting[] = $temp;
  320. }
  321. return $groupSetting;
  322. }
  323. public function specialTableConfig($type){
  324. if ($type == "Booking_Search"){
  325. return array("booking_no" =>array("type" =>"link"),
  326. "h_bol" =>array("type" =>"link"),
  327. "mode" =>array("type" =>"mode"),
  328. "transport_mode" =>array("type" =>"mode"),
  329. "status" =>array("type" =>"status"),
  330. "created_time" =>array("formatter" =>"dateTime"),
  331. "confirmation_time" =>array("formatter" =>"dateTime"),
  332. "f_etd" =>array("formatter" =>"date"),
  333. "m_eta" =>array("formatter" =>"date"),
  334. "qty" =>array("formatter" =>"number","digits"=>0),
  335. "piece_count" =>array("formatter" =>"number","digits"=>3),
  336. "weight" =>array("formatter" =>"number","digits"=>3));
  337. }
  338. if ($type == "Ocean_Search"){
  339. return array("booking_no" =>array("type" =>"link"),
  340. "h_bol" =>array("type" =>"link"),
  341. "mode" =>array("type" =>"mode"),
  342. "transport_mode" =>array("type" =>"mode"),
  343. "status" =>array("type" =>"status"),
  344. "created_time" =>array("formatter" =>"dateTime"),
  345. "etd" =>array("formatter" =>"date"),
  346. "eta" =>array("formatter" =>"date"),
  347. "qty" =>array("formatter" =>"number","digits"=>0),
  348. "piece_count" =>array("formatter" =>"number","digits"=>3),
  349. "weight" =>array("formatter" =>"number","digits"=>3),
  350. "cbm" =>array("formatter" =>"number","digits"=>3));
  351. }
  352. if ($type == "Operation_Search"){
  353. return array("operation_time" =>array("formatter" =>"dateTime"));
  354. }
  355. if ($type == "Robot_Chat_Search"){
  356. return array("request_time" =>array("formatter" =>"dateTime"),
  357. "response_time" =>array("formatter" =>"dateTime"));
  358. }
  359. if ($type == "Robot_API_Search"){
  360. return array("request_time" =>array("formatter" =>"dateTime"),
  361. "response_time" =>array("formatter" =>"dateTime"),
  362. "request_id" =>array("type" =>"link"));
  363. }
  364. if ($type == "Destination_Delivery_Search"){
  365. return array("delivery_date" =>array("formatter" =>"date"),
  366. "created_time" =>array("formatter" =>"date"),
  367. "status" =>array("type" =>"status"),
  368. "h_bol" =>array("type" =>"multiple_link"),
  369. "date_range" =>array("formatter" =>"range"));
  370. }
  371. if ($type == "destination_delivery_shipment_search"){
  372. return array("eta" =>array("formatter" =>"date"),
  373. "ata" =>array("formatter" =>"date"),
  374. "date_range" =>array("type" =>"recommend"),
  375. "packing_list" =>array("type" =>"download"),
  376. "commercial_invoice" =>array("type" =>"download"));
  377. }
  378. }
  379. /**
  380. * 通用返回setting 分组数据
  381. */
  382. public function allGroupColumns($allData,$children){
  383. foreach ($allData as $key => $data) {
  384. //固定ALl的分组
  385. if (array_key_exists("All", $children)) {
  386. $temp = $children['All'];
  387. $temp[] = array("ids"=>$data['id'],"label"=>$data['name'],"field"=>$data['database_column_name']);
  388. $children['All'] = $temp;
  389. }
  390. if (array_key_exists($data['group_name'], $children)) {
  391. $temp = $children[$data['group_name']];
  392. $temp[] = array("ids"=>$data['id'],"label"=>$data['name'],"field"=>$data['database_column_name']);
  393. $children[$data['group_name']] = $temp;
  394. }
  395. }
  396. $groupColumns = array();
  397. foreach ($children as $k => $ch) {
  398. $groupColumns[] = array("name"=>$k,"children" =>$ch);
  399. }
  400. return $groupColumns;
  401. }
  402. /**
  403. * 通用返回setting vip_reprot 分组数据
  404. */
  405. public function allGroupVipReprotColumns($allData,$children){
  406. foreach ($allData as $key => $data) {
  407. //固定ALl的分组
  408. if (array_key_exists("All", $children)) {
  409. $temp = $children['All'];
  410. $temp[] = $data;
  411. $children['All'] = $temp;
  412. }
  413. if (array_key_exists($data['groupName'], $children)) {
  414. $temp = $children[$data['groupName']];
  415. $temp[] = $data;
  416. $children[$data['groupName']] = $temp;
  417. }
  418. }
  419. $groupColumns = array();
  420. foreach ($children as $k => $ch) {
  421. $groupColumns[] = array("name"=>$k,"children" =>$ch);
  422. }
  423. return $groupColumns;
  424. }
  425. }
  426. ?>