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