Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. <?php
  2.  
  3. class ACMS_GET_Admin_Form_Index extends ACMS_GET_Admin_Module
  4. {
  5. function get()
  6. {
  7. if ( 'form_index' <> ADMIN && 'form2-edit' <> ADMIN ) return '';
  8. if ( 0
  9. || ( !roleAvailableUser() && !sessionWithAdministration() )
  10. || ( roleAvailableUser() && !roleAuthorization('form_view', BID) && !roleAuthorization('form_edit', BID) )
  11. ) {
  12. return '';
  13. }
  14.  
  15. $Tpl = new Template($this->tpl, new ACMS_Corrector());
  16. $Vars = array();
  17.  
  18. //---------
  19. // refresh
  20. if ( !$this->Post->isNull() ) {
  21. $Tpl->add('refresh');
  22. $Vars['notice_mess'] = 'show';
  23. }
  24.  
  25. //-------
  26. // order
  27. $order = ORDER ? ORDER : 'id-asc';
  28. $Vars['order:selected#'.$order] = config('attr_selected');
  29.  
  30. //--------
  31. // limit
  32. $limits = configArray('admin_limit_option');
  33. $limit = $this->Q->get('limit', $limits[config('admin_limit_default')]);
  34. foreach ( $limits as $val ) {
  35. $_vars = array('value' => $val);
  36. if ( $limit == $val ) $_vars['selected'] = config('attr_selected');
  37. $Tpl->add('limit:loop', $_vars);
  38. }
  39.  
  40. $DB = DB::singleton(dsn());
  41.  
  42. $SQL = SQL::newSelect('form');
  43. $SQL->addSelect('log_form_datetime', 'log_form_datetime', null, 'MAX');
  44. $SQL->addSelect('log_form_form_id');
  45. $SQL->addLeftJoin('blog', 'blog_id', 'form_blog_id');
  46. ACMS_Filter::blogTree($SQL, BID, 'ancestor-or-self');
  47.  
  48. $Where = SQL::newWhere();
  49. $Where->addWhereOpr('form_blog_id', BID, '=', 'OR');
  50. $Where->addWhereOpr('form_scope', 'global', '=', 'OR');
  51. $SQL->addWhere($Where);
  52.  
  53. $Amount = new SQL_Select($SQL);
  54. $Amount->setSelect('*', 'form_amount', null, 'count');
  55. if ( !$pageAmount = $DB->query($Amount->get(dsn()), 'one') ) {
  56. $Tpl->add('index#notFound');
  57. $Vars['notice_mess'] = 'show';
  58. $Tpl->add(null, $Vars);
  59. return $Tpl->get();
  60. }
  61. $Vars += $this->buildPager(PAGE, $limit, $pageAmount
  62. , config('admin_pager_delta'), config('admin_pager_cur_attr'), $Tpl, array(), array('admin' => ADMIN)
  63. );
  64.  
  65. $Log = SQL::newSelect('log_form');
  66. $Log->setOrder('log_form_datetime', 'DESC');
  67. $SQL->addLeftJoin($Log, 'log_form_form_id', 'form_id', 'log_form_ordered');
  68. $SQL->addSelect('form_id');
  69. $SQL->addSelect('form_code');
  70. $SQL->addSelect('form_name');
  71. $SQL->addSelect('form_scope');
  72. $SQL->addSelect('form_blog_id');
  73. $SQL->addSelect('log_form_datetime', 'form_log_amount', null, 'count');
  74. $Case = SQL::newCase();
  75. $Case->add(SQL::newOpr('log_form_datetime'), '1000-01-01 00:00:00');
  76. $Case->setElse(SQL::newField('log_form_datetime'));
  77. $SQL->addSelect($Case, 'form_last_datetime');
  78.  
  79. //-------
  80. // order
  81. $base_order = explode('-', $order);
  82. $base = $base_order[0];
  83. $ord = $base_order[1];
  84. $ord = ('asc' == $ord) ? 'ASC' : 'DESC';
  85. if ( 'code' == $base ) {
  86. $SQL->setOrder('form_code', $ord);
  87. } else if ( 'amount' == $base ) {
  88. $SQL->setOrder('form_log_amount', $ord);
  89. } else if ( 'datetime' == $base ) {
  90. $SQL->setOrder('form_last_datetime', $ord);
  91. } else {
  92. $SQL->setOrder('form_id', $ord);
  93. }
  94.  
  95. $SQL->setGroup('form_id');
  96. $SQL->setLimit($limit, (PAGE - 1) * $limit);
  97.  
  98. $q = $SQL->get(dsn());
  99. $DB->query($q, 'fetch');
  100.  
  101. $editAction = false;
  102. $logAction = false;
  103.  
  104. while ( $row = $DB->fetch($q) ) {
  105. $fmid = intval($row['form_id']);
  106. $fmbid = intval($row['form_blog_id']);
  107.  
  108. if ( 0
  109. || ( !roleAvailableUser() && sessionWithAdministration($fmbid) )
  110. || ( roleAvailableUser() && roleAuthorization('form_edit', $fmbid) )
  111. ) {
  112. $editAction = true;
  113. }
  114. if ( 0
  115. || ( !roleAvailableUser() && sessionWithAdministration(BID) )
  116. || ( roleAvailableUser() && roleAuthorization('form_view', BID) )
  117. ) {
  118. $logAction = true;
  119. }
  120.  
  121. if ( $editAction ) {
  122. $Tpl->add(array('editAction', 'form:loop'), array(
  123. 'itemUrl' => acmsLink(array(
  124. 'bid' => $fmbid,
  125. 'admin' => 'form_edit',
  126. 'query' => array(
  127. 'fmid' => $fmid,
  128. ),
  129. )),
  130. ));
  131. }
  132. if ( $logAction ) {
  133. $Tpl->add(array('logAction', 'form:loop'), array(
  134. 'logUrl' => acmsLink(array(
  135. 'bid' => BID,
  136. 'admin' => 'form_log',
  137. 'query' => array(
  138. 'fmid' => $fmid,
  139. ),
  140. )),
  141. ));
  142. }
  143. $Tpl->add('form:loop', array(
  144. 'code' => $row['form_code'],
  145. 'name' => $row['form_name'],
  146. 'datetime' => $row['form_last_datetime'],
  147. 'amount' => $row['form_log_amount'],
  148. 'scope' => $row['form_scope'],
  149. ));
  150. }
  151.  
  152. $Tpl->add(null, $Vars);
  153. return $Tpl->get();
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement