PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/client/application/libraries/utils_helper.php

https://bitbucket.org/jerwinse/iagh-cms
PHP | 96 lines | 76 code | 13 blank | 7 comment | 20 complexity | 200010fdcf0b661b070424e2c357a112 MD5 | raw file
  1. <?php
  2. if ( ! function_exists('debug'))
  3. {
  4. function debug($str)
  5. {
  6. echo '<pre>';
  7. print_r($str);
  8. echo '</pre>';
  9. }
  10. }
  11. if ( ! function_exists('link_tag'))
  12. {
  13. function link_tag($file = '')
  14. {
  15. $link = '';
  16. if($file != '')
  17. {
  18. $type = substr($file, -3);
  19. if($type == '.js')
  20. {
  21. // JS
  22. //$link = "<script type=\"text/javascript\" src=\"" . $CI->config->slash_item('base_url') . $CI->config->slash_item('js_path') . $file . "\"></script>\n";
  23. $link = "<script type=\"text/javascript\" src=\"" . $file . "?rand=" . rand(). "\"></script>\n";
  24. }
  25. if($type == 'css')
  26. {
  27. // CSS
  28. //$link = "<link rel=\"stylesheet\" type=\"text/css\" href=\"". $CI->config->slash_item('base_url') . $CI->config->slash_item('css_path') . $file ."\" />\n";
  29. $link = "<link rel=\"stylesheet\" type=\"text/css\" href=\"". $file . "?rand=" . rand(). "\" />\n";
  30. }
  31. if ($type == 'ico')
  32. {
  33. $link = "<link rel=\"icon\" href=\"". $file ."\" />\n";
  34. }
  35. }
  36. return $link;
  37. }
  38. }
  39. if ( ! function_exists('object_to_array'))
  40. {
  41. function object_to_array($data)
  42. {
  43. if(is_array($data) || is_object($data))
  44. {
  45. $result = array();
  46. foreach($data as $key => $value)
  47. {
  48. $result[$key] = object_to_array($value);
  49. }
  50. return $result;
  51. }
  52. return $data;
  53. }
  54. }
  55. if ( ! function_exists('export_to_xls'))
  56. {
  57. function export_to_xls($report, $header, $data)
  58. {
  59. $report_data = "";
  60. for($i=0; $i<= count($header) - 1; $i++)
  61. {
  62. $report_data .= $header[$i] . "\t";
  63. if($i == count($header) - 1)
  64. $report_data = substr($report_data, 0, -1) . "\n";
  65. }
  66. foreach($data as $cell => $value)
  67. {
  68. $arr_val = array_values($value);
  69. for($i=0; $i<= count($arr_val) - 1; $i++)
  70. {
  71. $report_data .= $arr_val[$i] . "\t";
  72. if($i == count($arr_val) - 1)
  73. $report_data = substr($report_data, 0, -1) . "\n";
  74. }
  75. }
  76. //header("Content-type: application/octet-stream");
  77. //header("Content-Type: application/vnd.ms-excel");
  78. header('Content-type: application/ms-excel');
  79. //header("Content-length: " . strlen($report_data));
  80. header("Content-disposition: attachment; filename=\"" . $report . ".xls\"");
  81. echo $report_data;
  82. }
  83. }