column.class.php 20 KB

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