/admin/ajax.php
PHP | 226 lines | 181 code | 20 blank | 25 comment | 41 complexity | f6138a838905ce4e5e620544f8179722 MD5 | raw file
Possible License(s): AGPL-1.0
- <?php
- include_once '../config.php';
- include_once '../opendb.php';
- include_once 'select.php';
- if (isset($_GET['display']) && $_GET['display'] != '') {
- $offset = isset($_GET['offset'])? $_GET['offset'] : 0;
- $limit = isset($_GET['limit'])? $_GET['limit'] : 30;
- $search = isset($_GET['search'])? $_GET['search'] : '';
- $field = isset($_GET['field'])? $_GET['field'] : '';
- $total = count_daemon_stack($_GET['display'], $search, $field);
- $state = $_GET['display'];
- if (isset($_GET['from_java']))
- {
- $xml = "<?xml version='1.0'?>";
- $xml.="<daemon_stacks>";
- // null no limite, para devolver TODAS as entradas
- $daemonstacks = get_daemon_stack_for_java($state, null, 0, $search, $field);
- $i=0;
- while($row = @$daemonstacks[$i++])
- {
- $xml.="<daemon_stack>";
- $xml.="<id>".$row['id']."</id>";
- $xml.="<pub_acc>".$row['pub_acc']."</pub_acc>";
- $xml.="<author_acc>".$row['author_acc2']."</author_acc>";
- $xml.="</daemon_stack>";
- }
- $xml.="</daemon_stacks>";
- echo $xml;
- return;
- }
- $navigation_header =
- "<p>Mostrando registos $offset - ".($offset+$limit-1)." ($total total)</p>";
- $navigation =
- "<p>
- <input type='button' value='<<' title='Inэcio'
- onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value, 0, getSearchValue(), getFieldValue());' />
- <input type='button' value='<' title='Registos anteriores'
- onclick='display(\"$state\", $limit, ".($offset-$limit).", getSearchValue(), getFieldValue());' />
- <input type='button' value='Mostrar' title='Aplicar vista'
- onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value, $(\"offset\").value, getSearchValue(), getFieldValue());' />";
- $navigation .=
- "<select id='limit'>";
- for ($i=10; $i <= 100; $i+=10)
- $navigation .= '<option value="'.$i.'" '.($limit == $i? 'selected':'').'>'.$i.'</option>';
- for ($i=200; $i <= 500; $i+=100)
- $navigation .= '<option value="'.$i.'" '.($limit == $i? 'selected':'').'>'.$i.'</option>';
- for ($i=1000; $i <= 5000; $i+=1000)
- $navigation .= '<option value="'.$i.'" '.($limit == $i? 'selected':'').'>'.$i.'</option>';
- $navigation .=
- "</select>
- começando em
- <input type='text' id='offset' value='$offset' style='width: 40px;'
- onkeypress='return isNumberKey(event);' />
- <input type='button' value='>' title='Registos seguintes'
- onclick='display(\"$state\", $limit, ".($offset+$limit).", getSearchValue(), getFieldValue());' />
- <input type='button' value='>>' title='Fim'
- onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value, ";
- $_offset = @(floor($total/$limit)*$limit);
- if ($_offset >= $total)
- $_offset -= $limit;
- $navigation .=
- "$_offset, getSearchValue(), getFieldValue());' />
- </p>";
- // Opcoes para pesquisa
- $navigation_search =
- "<p>
- <input type='button' value='Procurar'
- title='Seleccione o campo que pretende procurar e indique o valor'
- onclick='display(\"$state\", $(\"limit\").options[$(\"limit\").selectedIndex].value,
- 0, getSearchValue(), getFieldValue());' />
- <select id='field' onchange='update_search(this.options[this.selectedIndex].value);'>
- <option value='team' ".($field != 'team'? '':'selected').">TEAM</option>
- <option value='author_acc' ".($field != 'author_acc'? '':'selected').">AUTHOR_ACC</option>
- <option value='pub_acc' ".($field != 'pub_acc'? '':'selected').">PUB_ACC</option>
- <option value='uri_type' ".($field != 'uri_type'? '':'selected').">URI_TYPE</option>
- <option value='date_request' ".($field != 'date_request'? '':'selected').">DATE_REQUEST</option>
- <option value='date_resolved' ".($field != 'date_resolved'? '':'selected').">DATE_RESOLVED</option>
- </select>
- <span id='search_sandbox'><input type='text' id='search' value='$search' style='width: 350px;' /></span>
- </p>";
- // $navigation_search =
- // "<p>
- // <input type="button" value="Procurar" title="Procurar 'Código' ou 'Nome'"
- // onclick="changePage($('limit').options[$('limit').selectedIndex].value, 0, $('search').value);" />
- // <input type="text" id="search" value="<php echo @$select->search; >" style="width: 350px;" />
- // </p>";
- echo $navigation_header;
- echo $navigation;
- echo $navigation_search;
- echo "<form action='admin.php' method='post' enctype='multipart/form-data'>";
- echo display($state, $limit, $offset, $search, $field);
- // submit_form (Cancelar pedidos seleccionados: Pending e Processing;
- // Para Ready a operacao nao щ para cancelar, mas para iniciar o segundo passo do processamento)
- echo "<br><input type='hidden' name='state' value='$state' >".
- "<select name='new_state'>";
- if ($state == 'standby')
- // TODO Colocar uma opcao para eliminar pedidos em standby
- // Esta opчуo NAO Щ SAFE, devido a poder existir pedidos de utilizadores
- // que poderуo estar a usar o sistema no momento em que se manda apagar.
- // Portanto, esta opчуo tem de ser usada com muito cuidado, para se apagar
- // apenas os pedidos que estуo em standby a muito tempo: (IDEIA -> ver FUTURE)
- //
- // FUTURE: Para prevenir que se apague o que nуo щ suposto, pode-se
- // colocar mais uma coluna a seguir a coluna "team" indicando se o
- // daemon_stack em questуo jс se encontra em standby por ex. a mais de 24h
- echo "<option value='pending'>Iniciar (standby -> pending)</option>";
- if ($state == 'pending')
- echo "<option value='standby'>Cancelar (pending -> standby)</option>";
- if ($state == 'processing')
- echo "<option value='standby'>Cancelar (processing -> standby)</option>
- <option value='pending'>Reiniciar (processing -> pending)</option>";
- if ($state == 'ready')
- echo "<option value='standby'>Criar publicações a partir de Scholar Raw HTML</option>";
- // if ($state == 'standby')
- // echo "<option value='delete'>Eliminar (remover do sistema)</option>";
- echo
- "</select>".
- "<input type='submit' value='Submeter'
- onclick='if(allSelected()) return window.confirm(\"Seleccionou todos os pedidos. Tem a certeza?\");' >";
- echo "</form>";
- echo $navigation;
- }
- include_once '../closedb.php';
- function display($state, $limit, $offset, $search, $field) {
- $_daemon_stack = get_daemon_stack($state, $limit, $offset, $search, $field);
- $output = '';
- $html = array();
- $header = '';
- $i=0;
- while($row = @$_daemon_stack[$i++]) {
- $html[] = "<tr><td>".
- // checkbox para formulario que permite alterar o estado dos pedidos
- // permite tambem processar pedidos de RAW HTML e criar pedidos para
- // o BIBTEX das publicaчѕes.
- ($state == 'ready' && $row['uri_type'] != 'scholar_raw'?
- "<span title='Apenas щ possэvel seleccionar pedidos do tipo ".
- "scholar_raw' style='cursor:help;'><input type='checkbox' disabled='true' ></span></td><td>" :
- "<input type='checkbox' name='cancel[]' ".
- "value='{$row['id']}|".
- substr($row['author_acc'], (strpos($row['author_acc'], ">")+1),
- strpos($row['author_acc'], '</a>')-(strpos($row['author_acc'], ">")+1)
- ).
- "|{$row['pub_acc']}|{$row['uri_type']}' >".
- "</td><td>").
- implode("</td><td>", $row).
- "</td></tr>";
- if ($header == '') {
- $header =
- // Caixa com opcoes de seleccao
- "<th class='nosort'><img src='../images/refresh_icon.png' alt='opções'
- onclick='Effect.SlideDown(\"slide_menu\");'
- style='cursor:pointer'
- title='Clique para ver as opções' />
- <div id='slide_menu' style='display:none; position: absolute; left: 70px;'>
- <fieldset id='slide_sandbox' style='position:relative; background-color: #dfdfdf; cursor: move;'
- title='Pode mover a minha posiчуo.' >
- <legend style='background-color: #3885cc; color:white;
- -moz-border-radius: 6px 6px 6px 6px;
- -webkit-border-radius: 6px 6px 6px 6px;'>
- Opчões para caixas de selecção</legend>
- <input type='button'
- title='Clique para marcar todas as ocorrências'
- onClick='selectCheckboxes(); $(\"slide_menu\").hide();'
- value='Todos' >
- <input type='button'
- title='Clique para desmarcar todas as ocorrências'
- onClick='unSelectCheckboxes(); $(\"slide_menu\").hide();'
- value='Nenhum' >
- <input type='button'
- title='Clique para esconder esta caixa'
- onClick='$(\"slide_menu\").hide();'
- value='Esconder' >
- </fieldset>
- </div>
- </th>";
- foreach ($row as $key => $value) {
- if ($key == 'id')
- $header .= "<th style='width:40px;'>$key</th>";
- else if ($key == 'uri_type')
- $header .= "<th style='width:80px;'>$key</th>";
- else if ($key == 'state' || $key == 'team')
- $header .= "<th style='width:60px;'>$key</th>";
- else
- $header .= "<th>$key</th>";
- }
- }
- }
- if (count($html) == 0) {
- $html[] =
- "<tr><td style='text-align:justify;'>No results were found. Your query:<br>".
- ($state!='standby'? "": "state= <span style='font-weight:bold; background:red; color:white;'>$state</span><br>").
- ($state!='pending'? "": "state= <span style='font-weight:bold; background:orange;'>$state</span><br>").
- ($state!='processing'? "": "state= <span style='font-weight:bold; background:yellow;'>$state</span><br>").
- ($state!='ready'? "": "state= <span style='font-weight:bold; background:green; color:white;'>$state</span><br>").
- ($field==''? "": "$field= <b>$search</b>").
- "</td></tr>";
- }
- $html = "" . implode("\r\n", $html);
- $html = "<table id='daemon_table' class='publication sortable' style='text-align:center;'>".
- "<tr>$header</tr>\n$html</table>";
- $output = $html;
- return $output;
- }
- ?>