TemplateTag.php 4.3 KB

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