column.class.php 23 KB

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