PageRenderTime 50ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/admin/ajax.php

https://code.google.com/
PHP | 226 lines | 181 code | 20 blank | 25 comment | 41 complexity | f6138a838905ce4e5e620544f8179722 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. include_once '../config.php';
  3. include_once '../opendb.php';
  4. include_once 'select.php';
  5. if (isset($_GET['display']) && $_GET['display'] != '') {
  6. $offset = isset($_GET['offset'])? $_GET['offset'] : 0;
  7. $limit = isset($_GET['limit'])? $_GET['limit'] : 30;
  8. $search = isset($_GET['search'])? $_GET['search'] : '';
  9. $field = isset($_GET['field'])? $_GET['field'] : '';
  10. $total = count_daemon_stack($_GET['display'], $search, $field);
  11. $state = $_GET['display'];
  12. if (isset($_GET['from_java']))
  13. {
  14. $xml = "<?xml version='1.0'?>";
  15. $xml.="<daemon_stacks>";
  16. // null no limite, para devolver TODAS as entradas
  17. $daemonstacks = get_daemon_stack_for_java($state, null, 0, $search, $field);
  18. $i=0;
  19. while($row = @$daemonstacks[$i++])
  20. {
  21. $xml.="<daemon_stack>";
  22. $xml.="<id>".$row['id']."</id>";
  23. $xml.="<pub_acc>".$row['pub_acc']."</pub_acc>";
  24. $xml.="<author_acc>".$row['author_acc2']."</author_acc>";
  25. $xml.="</daemon_stack>";
  26. }
  27. $xml.="</daemon_stacks>";
  28. echo $xml;
  29. return;
  30. }
  31. $navigation_header =
  32. "<p>Mostrando registos $offset - ".($offset+$limit-1)." ($total total)</p>";
  33. $navigation =
  34. "<p>
  35. <input type='button' value='<<' title='Inэcio'
  36. onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value, 0, getSearchValue(), getFieldValue());' />
  37. <input type='button' value='<' title='Registos anteriores'
  38. onclick='display(\"$state\", $limit, ".($offset-$limit).", getSearchValue(), getFieldValue());' />
  39. <input type='button' value='Mostrar' title='Aplicar vista'
  40. onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value, $(\"offset\").value, getSearchValue(), getFieldValue());' />";
  41. $navigation .=
  42. "<select id='limit'>";
  43. for ($i=10; $i <= 100; $i+=10)
  44. $navigation .= '<option value="'.$i.'" '.($limit == $i? 'selected':'').'>'.$i.'</option>';
  45. for ($i=200; $i <= 500; $i+=100)
  46. $navigation .= '<option value="'.$i.'" '.($limit == $i? 'selected':'').'>'.$i.'</option>';
  47. for ($i=1000; $i <= 5000; $i+=1000)
  48. $navigation .= '<option value="'.$i.'" '.($limit == $i? 'selected':'').'>'.$i.'</option>';
  49. $navigation .=
  50. "</select>
  51. come&ccedil;ando em
  52. <input type='text' id='offset' value='$offset' style='width: 40px;'
  53. onkeypress='return isNumberKey(event);' />
  54. <input type='button' value='>' title='Registos seguintes'
  55. onclick='display(\"$state\", $limit, ".($offset+$limit).", getSearchValue(), getFieldValue());' />
  56. <input type='button' value='>>' title='Fim'
  57. onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value, ";
  58. $_offset = @(floor($total/$limit)*$limit);
  59. if ($_offset >= $total)
  60. $_offset -= $limit;
  61. $navigation .=
  62. "$_offset, getSearchValue(), getFieldValue());' />
  63. </p>";
  64. // Opcoes para pesquisa
  65. $navigation_search =
  66. "<p>
  67. <input type='button' value='Procurar'
  68. title='Seleccione o campo que pretende procurar e indique o valor'
  69. onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value,
  70. 0, getSearchValue(), getFieldValue());' />
  71. <select id='field' onchange='update_search(this.options[this.selectedIndex].value);'>
  72. <option value='team' ".($field != 'team'? '':'selected').">TEAM</option>
  73. <option value='author_acc' ".($field != 'author_acc'? '':'selected').">AUTHOR_ACC</option>
  74. <option value='pub_acc' ".($field != 'pub_acc'? '':'selected').">PUB_ACC</option>
  75. <option value='uri_type' ".($field != 'uri_type'? '':'selected').">URI_TYPE</option>
  76. <option value='date_request' ".($field != 'date_request'? '':'selected').">DATE_REQUEST</option>
  77. <option value='date_resolved' ".($field != 'date_resolved'? '':'selected').">DATE_RESOLVED</option>
  78. </select>
  79. <span id='search_sandbox'><input type='text' id='search' value='$search' style='width: 350px;' /></span>
  80. </p>";
  81. // $navigation_search =
  82. // "<p>
  83. // <input type="button" value="Procurar" title="Procurar 'C&oacute;digo' ou 'Nome'"
  84. // onclick="changePage($('limit').options[$('limit').selectedIndex].value, 0, $('search').value);" />
  85. // <input type="text" id="search" value="<php echo @$select->search; >" style="width: 350px;" />
  86. // </p>";
  87. echo $navigation_header;
  88. echo $navigation;
  89. echo $navigation_search;
  90. echo "<form action='admin.php' method='post' enctype='multipart/form-data'>";
  91. echo display($state, $limit, $offset, $search, $field);
  92. // submit_form (Cancelar pedidos seleccionados: Pending e Processing;
  93. // Para Ready a operacao nao щ para cancelar, mas para iniciar o segundo passo do processamento)
  94. echo "<br><input type='hidden' name='state' value='$state' >".
  95. "<select name='new_state'>";
  96. if ($state == 'standby')
  97. // TODO Colocar uma opcao para eliminar pedidos em standby
  98. // Esta opчуo NAO Щ SAFE, devido a poder existir pedidos de utilizadores
  99. // que poderуo estar a usar o sistema no momento em que se manda apagar.
  100. // Portanto, esta opчуo tem de ser usada com muito cuidado, para se apagar
  101. // apenas os pedidos que estуo em standby a muito tempo: (IDEIA -> ver FUTURE)
  102. //
  103. // FUTURE: Para prevenir que se apague o que nуo щ suposto, pode-se
  104. // colocar mais uma coluna a seguir a coluna "team" indicando se o
  105. // daemon_stack em questуo jс se encontra em standby por ex. a mais de 24h
  106. echo "<option value='pending'>Iniciar (standby -> pending)</option>";
  107. if ($state == 'pending')
  108. echo "<option value='standby'>Cancelar (pending -> standby)</option>";
  109. if ($state == 'processing')
  110. echo "<option value='standby'>Cancelar (processing -> standby)</option>
  111. <option value='pending'>Reiniciar (processing -> pending)</option>";
  112. if ($state == 'ready')
  113. echo "<option value='standby'>Criar publica&ccedil;&otilde;es a partir de Scholar Raw HTML</option>";
  114. // if ($state == 'standby')
  115. // echo "<option value='delete'>Eliminar (remover do sistema)</option>";
  116. echo
  117. "</select>".
  118. "<input type='submit' value='Submeter'
  119. onclick='if(allSelected()) return window.confirm(\"Seleccionou todos os pedidos. Tem a certeza?\");' >";
  120. echo "</form>";
  121. echo $navigation;
  122. }
  123. include_once '../closedb.php';
  124. function display($state, $limit, $offset, $search, $field) {
  125. $_daemon_stack = get_daemon_stack($state, $limit, $offset, $search, $field);
  126. $output = '';
  127. $html = array();
  128. $header = '';
  129. $i=0;
  130. while($row = @$_daemon_stack[$i++]) {
  131. $html[] = "<tr><td>".
  132. // checkbox para formulario que permite alterar o estado dos pedidos
  133. // permite tambem processar pedidos de RAW HTML e criar pedidos para
  134. // o BIBTEX das publicaчѕes.
  135. ($state == 'ready' && $row['uri_type'] != 'scholar_raw'?
  136. "<span title='Apenas щ possэvel seleccionar pedidos do tipo ".
  137. "scholar_raw' style='cursor:help;'><input type='checkbox' disabled='true' ></span></td><td>" :
  138. "<input type='checkbox' name='cancel[]' ".
  139. "value='{$row['id']}|".
  140. substr($row['author_acc'], (strpos($row['author_acc'], ">")+1),
  141. strpos($row['author_acc'], '</a>')-(strpos($row['author_acc'], ">")+1)
  142. ).
  143. "|{$row['pub_acc']}|{$row['uri_type']}' >".
  144. "</td><td>").
  145. implode("</td><td>", $row).
  146. "</td></tr>";
  147. if ($header == '') {
  148. $header =
  149. // Caixa com opcoes de seleccao
  150. "<th class='nosort'><img src='../images/refresh_icon.png' alt='op&ccedil;&otilde;es'
  151. onclick='Effect.SlideDown(\"slide_menu\");'
  152. style='cursor:pointer'
  153. title='Clique para ver as op&ccedil;&otilde;es' />
  154. <div id='slide_menu' style='display:none; position: absolute; left: 70px;'>
  155. <fieldset id='slide_sandbox' style='position:relative; background-color: #dfdfdf; cursor: move;'
  156. title='Pode mover a minha posiчуo.' >
  157. <legend style='background-color: #3885cc; color:white;
  158. -moz-border-radius: 6px 6px 6px 6px;
  159. -webkit-border-radius: 6px 6px 6px 6px;'>
  160. Opч&otilde;es para caixas de selec&ccedil;&atilde;o</legend>
  161. <input type='button'
  162. title='Clique para marcar todas as ocorr&ecirc;ncias'
  163. onClick='selectCheckboxes(); $(\"slide_menu\").hide();'
  164. value='Todos' >
  165. <input type='button'
  166. title='Clique para desmarcar todas as ocorr&ecirc;ncias'
  167. onClick='unSelectCheckboxes(); $(\"slide_menu\").hide();'
  168. value='Nenhum' >
  169. <input type='button'
  170. title='Clique para esconder esta caixa'
  171. onClick='$(\"slide_menu\").hide();'
  172. value='Esconder' >
  173. </fieldset>
  174. </div>
  175. </th>";
  176. foreach ($row as $key => $value) {
  177. if ($key == 'id')
  178. $header .= "<th style='width:40px;'>$key</th>";
  179. else if ($key == 'uri_type')
  180. $header .= "<th style='width:80px;'>$key</th>";
  181. else if ($key == 'state' || $key == 'team')
  182. $header .= "<th style='width:60px;'>$key</th>";
  183. else
  184. $header .= "<th>$key</th>";
  185. }
  186. }
  187. }
  188. if (count($html) == 0) {
  189. $html[] =
  190. "<tr><td style='text-align:justify;'>No results were found. Your query:<br>".
  191. ($state!='standby'? "": "state= <span style='font-weight:bold; background:red; color:white;'>$state</span><br>").
  192. ($state!='pending'? "": "state= <span style='font-weight:bold; background:orange;'>$state</span><br>").
  193. ($state!='processing'? "": "state= <span style='font-weight:bold; background:yellow;'>$state</span><br>").
  194. ($state!='ready'? "": "state= <span style='font-weight:bold; background:green; color:white;'>$state</span><br>").
  195. ($field==''? "": "$field= <b>$search</b>").
  196. "</td></tr>";
  197. }
  198. $html = "" . implode("\r\n", $html);
  199. $html = "<table id='daemon_table' class='publication sortable' style='text-align:center;'>".
  200. "<tr>$header</tr>\n$html</table>";
  201. $output = $html;
  202. return $output;
  203. }
  204. ?>