column.class.php 21 KB

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