TemplateTag.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. // register global/PHP functions to be used with your template files
  3. // You can move this to common.conf.php $config['TEMPLATE_GLOBAL_TAGS'] = array('isset', 'empty');
  4. // Every public static methods in TemplateTag class (or tag classes from modules) are available in templates without the need to define in TEMPLATE_GLOBAL_TAGS
  5. Doo::conf ()->TEMPLATE_GLOBAL_TAGS = array (
  6. 'upper',
  7. 'tofloat',
  8. 'sample_with_args',
  9. 'debug',
  10. 'url',
  11. 'url2',
  12. 'function_deny',
  13. 'isset',
  14. 'empty',
  15. 'make_date',
  16. 'inarray' ,
  17. 'getGlobals'
  18. );
  19. /**
  20. * Define as class (optional)
  21. * class TemplateTag { public static test(){} public static test2(){} }
  22. */
  23. function getGlobals($var) {
  24. if ($var=='NEW')
  25. getReceiptCount();
  26. elseif ($var=='NEW2')
  27. getExeCount();
  28. return $GLOBALS[$var] ;
  29. }
  30. function inarray($v1, $v2) {
  31. return in_array ( $v1, $v2 );
  32. }
  33. function make_date() {
  34. return date ( "Y-m" );
  35. }
  36. function upper($str) {
  37. return strtoupper ( $str );
  38. }
  39. function tofloat($str) {
  40. return sprintf ( "%.2f", $str );
  41. }
  42. function sample_with_args($str, $prefix) {
  43. return $str . ' with args: ' . $prefix;
  44. }
  45. function debug($var) {
  46. if (! empty ( $var )) {
  47. echo '<pre>';
  48. print_r ( $var );
  49. echo '</pre>';
  50. }
  51. }
  52. // This will be called when a function NOT Registered is used in IF or ElseIF statment
  53. function function_deny($var = null) {
  54. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  55. exit ();
  56. }
  57. // Build URL based on route id
  58. function url($id, $param = null, $addRootUrl = false) {
  59. Doo::loadHelper ( 'DooUrlBuilder' );
  60. // param pass in as string with format
  61. // 'param1=>this_is_my_value, param2=>something_here'
  62. if ($param != null) {
  63. $param = explode ( ', ', $param );
  64. $param2 = null;
  65. foreach ( $param as $p ) {
  66. $splited = explode ( '=>', $p );
  67. $param2 [$splited [0]] = $splited [1];
  68. }
  69. return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
  70. }
  71. return DooUrlBuilder::url ( $id, null, $addRootUrl );
  72. }
  73. // Build URL based on controller and method name
  74. function url2($controller, $method, $param = null, $addRootUrl = false) {
  75. Doo::loadHelper ( 'DooUrlBuilder' );
  76. // param pass in as string with format
  77. // 'param1=>this_is_my_value, param2=>something_here'
  78. if ($param != null) {
  79. $param = explode ( ', ', $param );
  80. $param2 = null;
  81. foreach ( $param as $p ) {
  82. $splited = explode ( '=>', $p );
  83. $param2 [$splited [0]] = $splited [1];
  84. }
  85. return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
  86. }
  87. return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
  88. }
  89. function getReceiptCount(){
  90. $status=2;
  91. $year=date('Y');
  92. Doo::loadModel('receipt');
  93. $receipt=new receipt();
  94. $dateCondition=" and Year(date) =".$year;
  95. $approvalCondition=' and nowStaff like "%'.$_COOKIE["staff"].'%" ';
  96. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  97. $GLOBALS['NEW']= count($receiptList);
  98. }
  99. function getExeCount(){
  100. Doo::loadModel('receipt');
  101. $receipt=new receipt();
  102. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$_COOKIE["staff"].'%\' and executeStaff NOT LIKE \'%'.$_COOKIE["staff"].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  103. $GLOBALS['NEW2']= count($receiptList);
  104. }
  105. ?>