TemplateTag.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. 'isInvoiceMoldShow'
  19. );
  20. /**
  21. * 判断发票的审批权限
  22. * @param number $sid 用户ID
  23. * @param string $mold 项目类型
  24. * @return boolean
  25. */
  26. function isInvoiceMoldShow($sid = 0, $mold = '') {
  27. if (! empty ( $sid ) && ! empty ( $mold )) {
  28. Doo::loadModel ( "invoiceManage" );
  29. $invoiceManage = new invoiceManage ();
  30. $imList = $invoiceManage->getInvoiceByMold($mold);
  31. $list=array();
  32. foreach ($imList as $key=>$value){
  33. $ver=json_decode($value['staff']);
  34. foreach ($ver as $k=>$v){
  35. array_push($list, $v[0]);
  36. }
  37. }
  38. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  39. $fileInvoice = json_decode ( $fileInvoice, true );
  40. print_r($fileInvoice);
  41. } else
  42. return false;
  43. }
  44. function getGlobals($var) {
  45. if ($var == 'NEW')
  46. getReceiptCount ();
  47. elseif ($var == 'NEW2')
  48. getExeCount ();
  49. // echo $GLOBALS['NEW'].'<br/>';
  50. return $GLOBALS [$var];
  51. }
  52. function inarray($v1, $v2) {
  53. return in_array ( $v1, $v2 );
  54. }
  55. function make_date() {
  56. return date ( "Y-m" );
  57. }
  58. function upper($str) {
  59. return strtoupper ( $str );
  60. }
  61. function tofloat($str) {
  62. return sprintf ( "%.2f", $str );
  63. }
  64. function sample_with_args($str, $prefix) {
  65. return $str . ' with args: ' . $prefix;
  66. }
  67. function debug($var) {
  68. if (! empty ( $var )) {
  69. echo '<pre>';
  70. print_r ( $var );
  71. echo '</pre>';
  72. }
  73. }
  74. // This will be called when a function NOT Registered is used in IF or ElseIF statment
  75. function function_deny($var = null) {
  76. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  77. exit ();
  78. }
  79. // Build URL based on route id
  80. function url($id, $param = null, $addRootUrl = false) {
  81. Doo::loadHelper ( 'DooUrlBuilder' );
  82. // param pass in as string with format
  83. // 'param1=>this_is_my_value, param2=>something_here'
  84. if ($param != null) {
  85. $param = explode ( ', ', $param );
  86. $param2 = null;
  87. foreach ( $param as $p ) {
  88. $splited = explode ( '=>', $p );
  89. $param2 [$splited [0]] = $splited [1];
  90. }
  91. return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
  92. }
  93. return DooUrlBuilder::url ( $id, null, $addRootUrl );
  94. }
  95. // Build URL based on controller and method name
  96. function url2($controller, $method, $param = null, $addRootUrl = false) {
  97. Doo::loadHelper ( 'DooUrlBuilder' );
  98. // param pass in as string with format
  99. // 'param1=>this_is_my_value, param2=>something_here'
  100. if ($param != null) {
  101. $param = explode ( ', ', $param );
  102. $param2 = null;
  103. foreach ( $param as $p ) {
  104. $splited = explode ( '=>', $p );
  105. $param2 [$splited [0]] = $splited [1];
  106. }
  107. return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
  108. }
  109. return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
  110. }
  111. /**
  112. * 获得正在审批的费用单数量
  113. */
  114. function getReceiptCount() {
  115. $status = 2;
  116. $year = date ( 'Y' );
  117. Doo::loadModel ( 'receipt' );
  118. $receipt = new receipt ();
  119. $dateCondition = " and Year(date) =" . $year;
  120. $approvalCondition = ' and nowStaff like "%' . $_COOKIE ["staff"] . '%" ';
  121. $receiptList = $receipt->find ( array (
  122. 'where' => ' status=' . $status . $dateCondition . $approvalCondition,
  123. 'desc' => 'rid',
  124. 'asArray' => true
  125. ) );
  126. $GLOBALS ['NEW'] = count ( $receiptList );
  127. }
  128. /**
  129. * 获得执行费用的数量
  130. */
  131. function getExeCount() {
  132. Doo::loadModel ( 'receipt' );
  133. $receipt = new receipt ();
  134. $receiptList = $receipt->find ( array (
  135. 'where' => '(executeCopy like \'%["' . $_COOKIE ["staff"] . '%\' and executeStaff NOT LIKE \'%' . $_COOKIE ["staff"] . '%\' ) and (status=1 or status=6)',
  136. 'desc' => 'rid',
  137. 'asArray' => true
  138. ) );
  139. $GLOBALS ['NEW2'] = count ( $receiptList );
  140. }
  141. ?>