Location: PHPKode > projects > QuickTicket > quickticket/qti_adm_change.php
<?php

/**
* PHP versions 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5 build:20101222
*/

session_start();
require_once('bin/qti_init.php');
if ( $oVIP->role!='A' ) die(Error(13));

include(Translate('qti_adm.php'));
if ( !isset($_GET['a'])) die('Wrong action');

include('bin/qti_fn_sql.php');

// --------
// INITIALISE
// --------

$a = ''; // mandatory action
$d = -1; // domain (or days)
$s = -1; // section
$t = -1; // topic (or move target)
$p = -1; // post
$v = ''; // value
$ok = ''; // submitted
QThttpvar('a d s t p v ok','str int int int int str str');

$oVIP->selfurl = 'qti_adm_change.php';
$oVIP->selfname = 'QuickTicket command';

// --------
// EXECUTE COMMAND
// --------

switch($a)
{

// --------------
case 'deletedomain':
// --------------

  if ( $d<1 ) die('Wrong id '.$d);

  $oVIP->selfname = $L['Domain_del'];
  $oVIP->exiturl = 'qti_adm_sections.php';
  $oVIP->exitname = '&laquo; '.$L['Sections'];

  // ask destination
  if ( empty($ok) )
  {

    $arrDomains = GetDomains();
    $strTitle = $arrDomains[$d];
    $arrSections = QTarrget(GetSections($oVIP->role,$d));

    // list the domain content
    if ( count($arrSections)==0 )
    {
      $strDcont = '<span class="small">0 '.$L['Section'].'</span>';
    }
    else
    {
      $strDcont = '';
      foreach($arrSections as $intKey=>$strValue)
      {
      $strDcont .= '<span class="small">'.$L['Section'].': '.$strValue.'</span><br />';
      }
    }

    // list of domain destination
    if ( count($arrSections)>0 )
    {
      $arrDdest = array(); // array_diff_key() not supported in php<5.1
      foreach($arrDomains as $intKey=>$strValue) { if ( $intKey!=$d ) $arrDdest[$intKey]=$strValue; }

      $strDdest = '<tr class="data_o">
      <td class="colhd colhdfirst">'.$L['Sections'].'</td>
      <td class="colct">
      <select name="t" size="1" class="small">'.QTasTag($arrDdest,'',array('format'=>$L['Move_to'].': %s')).'</select>
      </td>
      </tr>';
    }
    else
    {
      $strDdest = '';
    }

    // form
    $oVIP->EndMessage
    (
    NULL,
    '<form method="get" action="'.$oVIP->selfurl.'">
    <table class="data_o" cellspacing="0">
    <tr class="data_o">
    <td class="colhd colhdfirst" style="width:150px">'.$L['Title'].'</td>
    <td class="colct"><b>'.$strTitle.'</b></td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">'.$L['Containing'].'</td>
    <td class="colct">'.$strDcont.'</td>
    </tr>'.N.$strDdest.'
    <tr class="data_o">
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><input type="hidden" name="a" value="'.$a.'" /><input type="hidden" name="d" value="'.$d.'" /><input type="submit" name="ok" value="'.$L['Delete'].'" /></td>
    </tr>
    </table>
    </form>',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // Delete domain

  require_once('bin/qti_class_dom.php');
  if ( $t>=0 ) cDomain::MoveItems($d,$t);
  cDomain::Drop($d);

  // Exit

  $oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
  exit;
  break;

// --------------
case 'deletesection':
// --------------

  if ( $s<1 ) die('Wrong id '.$s);

  $oVIP->selfname = $L['Section_del'];
  $oVIP->exiturl = 'qti_adm_sections.php';
  $oVIP->exitname = '&laquo; '.$L['Sections'];

  $oSEC = new cSection($s);

  // ask confirmation
  if ( empty($ok) )
  {
    // list topics
    if ( $oSEC->items>0 )
    {
      $strList = '<tr class="data_o"><td class="colhd">&nbsp;</td><td class="colct"><i><b>'.$L['H_Topics_delete'].'</b></i>&nbsp;&nbsp;<a href="qti_adm_change.php?a=topicmoveall&amp;s='.$s.'&amp;d=10">'.$L['Adm_topics_move'].' &raquo;</a></td></tr>';
    }
    else
    {
      $strList = '';
    }

    $oVIP->EndMessage
    (
    NULL,
    '<form method="get" action="'.$oVIP->selfurl.'">
    <table class="data_o" cellspacing="0">
    <tr class="data_o">
    <td class="colhd colhdfirst" style="width:150px">'.$L['Section'].'</td>
    <td class="colct">'.$oSEC->name.'</td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">'.$L['Containing'].'</td>
    <td class="colct">'.LangS('Topic',$oSEC->items).', '.LangS('Reply',$oSEC->replies).'</td>
    </tr>
    '.$strList.'
    <tr class="data_o">
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><input type="hidden" name="a" value="'.$a.'" /><input type="hidden" name="s" value="'.$s.'" /><input type="submit" name="ok" value="'.$L['Delete'].'" />
    </td>
    </tr>
    </table>
    </form>',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // Delete section

  $oSEC->DeleteTopics(false,'',false); // no need to update section stats
  cSection::Drop($s);

  // exit
  $oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
  exit;
  break;

// --------------
case 'status_del':
// --------------

  if ( $v=='A' || $v=='Z' ) die('Wrong id '.$v);

  $oVIP->selfname = $L['Delete'].' '.strtolower($L['Status']);
  $oVIP->exiturl = 'qti_adm_statuses.php';
  $oVIP->exitname = '&laquo; '.$L['Statuses'];

  // ask confirmation
  if ( empty($ok) || !isset($_GET['to']) )
  {
    // list of status destination
    $strSdest = '';
    foreach($oVIP->statuses as $strKey=>$arrStatus)
    {
      if ( $strKey!=$v ) $strSdest .= '<option value="'.$strKey.'" />'.$strKey.' - '.$arrStatus['statusname'].'</option>';
    }

    $oVIP->EndMessage
    (
    NULL,
    '<form method="get" action="'.$oVIP->selfurl.'">
    <table cellspacing="0" class="data_o">
    <tr>
    <td class="colhd colhdfirst" style="width:150px;">'.$L['Status'].'</td>
    <td class="colct"><b>'.$v.'&nbsp;&nbsp;'.AsImg($_SESSION[QT]['skin_dir'].'/'.$oVIP->statuses[$v]['icon'],'-',$oVIP->statuses[$v]['statusname'],'ico ico_status').'&nbsp;&nbsp;'.$oVIP->statuses[$v]['name'].'</b></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Description'].'</td>
    <td class="colct">'.$oVIP->statuses[$v]['statusdesc'].'</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Move'].'</td>
    <td class="colct">'.$L['H_Status_move'].' <select name="to" size="1" class="small">'.$strSdest.'</select></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct">
    <input type="hidden" name="a" value="'.$a.'" />
    <input type="hidden" name="v" value="'.$v.'" />
    <input type="submit" name="ok" value="'.$L['Delete'].'" /></td>
    </tr>
    </table>
    </form><br />',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // Delete status

  $oVIP->StatusDelete($v,$_GET['to']);
  
  // Exit
  
  $oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
  exit;
  break;

// --------------
case 'topicdeleteall':
// --------------

  if ( $s<0 ) die('Wrong id '.$s);

  $oVIP->selfname = $L['Adm_topics_delete'];
  $oVIP->exiturl  = 'qti_adm_topic.php?d='.$d;
  $oVIP->exitname = '&laquo; '.$L['Topics'];

  $oSEC = new cSection($s);
  $intCount = $oSEC->items; // number of topics before the action
  $intClosed = $oSEC->itemsZ;
  $intNews= cSection::CountItems($oSEC->id,'news');

  // ask confirmation
  if ( empty($ok) )
  {
    $oVIP->EndMessage
    (
    NULL,
    '<p><span class="bold">'.$L['All'].'</span> &middot; <a href="'.Href().'?a=topicdeleteyear&s='.$s.'&d='.$d.'">'.$L['By'].' '.strtolower($L['Year']).'</a></p>
    <form method="get" action="'.$oVIP->selfurl.'">
    <table cellspacing="0" class="data_o">
    <tr>
    <td class="colhd colhdfirst" style="width:150px;">'.$L['Section'].'</td>
    <td class="colct">'.$oSEC->name.'</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Containing'].'</td>
    <td class="colct">'.LangS('Topic',$oSEC->items).' ('.LangS('News',$intNews).', '.LangS('Reply',$oSEC->replies).')</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><i><b>'.$L['H_Topics_delete'].'</b></i></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct">
    <input type="hidden" name="a" value="'.$a.'" />
    <input type="hidden" name="s" value="'.$s.'" />
    <input type="hidden" name="d" value="'.$d.'" />
    <input type="submit" name="ok" value="'.$L['Delete'].'" /> <span class="small">('.$oSEC->items.')</span>&nbsp;&nbsp;'.( $intClosed>0 ? ' <input type="submit" name="ok" value="'.$L['Delete_closed'].'" /> <span class="small">('.$intClosed.')</span>' : '').'</td>
    </tr>
    </table>
    </form><br />',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // delete topics (or closed only)
  $oSEC->DeleteTopics($ok==$L['Delete_closed']);
  $intCount = $intCount - $oSEC->items;

  // exit
  $oVIP->EndMessage(NULL,$L['S_delete'].'<p>'.$L['Topics_deleted'].': '.$intCount.'</p>','admin',2);
  exit;
  break;

// --------------
case 'topicdeleteyear':
// --------------

  if ( $s<0 ) die('Wrong id '.$s);

  $oVIP->selfname = $L['Adm_topics_delete'];
  $oVIP->exiturl  = 'qti_adm_topic.php?d='.$d;
  $oVIP->exitname = '&laquo; '.$L['Topics'];

  $oSEC = new cSection($s);
  
  // Recompute stats
  
  $intCount = cSection::CountItems($oSEC->id,'topics'); // number of topics before the action
  $intYear = intval(date('Y'));
  $arrYears = array('old'=>($intYear-4).' and older',($intYear-3)=>$intYear-3,$intYear-2,$intYear-1,$intYear);
  foreach($arrYears as $strKey=>$strValue) $arrYears[$strKey] .= strtolower(' -- '.LangS('Topic',cSection::CountItems($oSEC->id,'topics',10,$strKey)).' ('.LangS('Closed',cSection::CountItems($oSEC->id,'topicsZ',10,$strKey)).')');

  // ask confirmation and ask year
  if ( empty($ok) || empty($_GET['v']) )
  {
    $oVIP->EndMessage
    (
    NULL,
    '<p><a href="'.Href().'?a=topicdeleteall&s='.$s.'&d='.$d.'">'.$L['All'].'</a> &middot; <span class="bold">'.$L['By'].' '.strtolower($L['Year']).'</span></p>
    <form method="get" action="'.$oVIP->selfurl.'">
    <table cellspacing="0" class="data_o">
    <tr>
    <td class="colhd colhdfirst" style="width:150px;">'.$L['Section'].'</td>
    <td class="colct">'.$oSEC->name.'</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Year'].'</td>
    <td class="colct"><select id="v" name="v">'.QTasTag($arrYears).'</select></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><i><b>'.$L['H_Topics_delete'].'</b></i></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct">
    <input type="hidden" name="a" value="'.$a.'" />
    <input type="hidden" name="s" value="'.$s.'" />
    <input type="hidden" name="d" value="'.$d.'" />
    <input type="submit" name="ok" value="'.$L['Delete'].'" /> &nbsp;&nbsp; <input type="submit" name="ok" value="'.$L['Delete_closed'].'" /></td>
    </tr>
    </table>
    </form><br />',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // delete topics (or closed only)
  $oSEC->DeleteTopics($ok==$L['Delete_closed'],$v);
  $intCount = $intCount - $oSEC->items;

  // exit
  $oVIP->EndMessage(NULL,$L['S_delete'].'<p>'.$L['Topics_deleted'].': '.$intCount.'</p>','admin',2);
  exit;
  break;
  
// --------------
case 'topicmoveall':
// --------------

  if ( $s<0 ) die('Wrong id '.$s);

  $oVIP->selfname = $L['Adm_topics_move'];
  $oVIP->exiturl  = 'qti_adm_topic.php?d='.$d;
  $oVIP->exitname = '&laquo; '.$L['Topics'];

  $oSEC = new cSection($s);
  
  // Recompute stats

  $intCount = cSection::CountItems($oSEC->id,'topics'); // number of topics before the action
  $intClosed = cSection::CountItems($oSEC->id,'topicsZ');
  $intNews = cSection::CountItems($oSEC->id,'news');
  $intInspections = cSection::CountItems($oSEC->id,'inspections');

  // Ask confirmation
  if ( empty($ok) || $t<0 )
  {
    $oVIP->EndMessage
    (
    NULL,
    '<p><span class="bold">'.$L['All'].'</span> &middot; <a href="'.Href().'?a=topicmoveyear&s='.$s.'&d='.$d.'">'.$L['By'].' '.strtolower($L['Year']).'</a></p>
    <form method="get" action="'.$oVIP->selfurl.'">
    <table cellspacing="0" class="data_o">
    <tr>
    <td class="colhd colhdfirst" style="width:150px;">'.$L['Section'].'</td>
    <td class="colct">'.$oSEC->name.'</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Containing'].'</td>
    <td class="colct">'.LangS('Topic',$oSEC->items).' ('.LangS('News',$intNews).', '.LangS('Inspections',$intInspections).') , '.LangS('Reply',$oSEC->replies).'</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Move_to'].'</td>
    <td class="colct"><select name="t" size="1">'.GotoList(-1,$s).'</select></td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">'.$L['Ref'].'</td>
    <td class="colct"><select name="p" size="1">
    <option value="1">'.$L['Move_keep'].'</option>
    <option value="0">'.$L['Move_reset'].'</option>
    <option value="2">'.$L['Move_follow'].'</option>
    </select></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><input type="hidden" name="a" value="'.$a.'" />
    <input type="hidden" name="s" value="'.$s.'" />
    <input type="hidden" name="d" value="'.$d.'" />
    <input type="submit" name="ok" value="'.$L['Move'].'" /> <span class="small">('.$oSEC->items.')</span>&nbsp;&nbsp;'.( $intClosed>0 ? ' <input type="submit" name="ok" value="'.$L['Move_closed'].'" /> <span class="small">('.$intClosed.')</span>' : '').'</td>
    </tr>
    </table>
    </form><br />',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // move topics
  $oSEC->MoveTopics($t,$p,-1,$ok==$L['Move_closed']);
  $intCount = $intCount - $oSEC->items;

  // exit
  $oVIP->EndMessage(NULL,$L['S_update'].'<p>'.$L['Topics_moved'].': '.$intCount.'</p>','admin',2);
  exit;
  break;

// --------------
case 'topicmoveyear':
// --------------

  if ( $s<0 ) die('Wrong id '.$s);

  $oVIP->selfname = $L['Adm_topics_move'];
  $oVIP->exiturl  = 'qti_adm_topic.php?d='.$d;
  $oVIP->exitname = '&laquo; '.$L['Topics'];

  $oSEC = new cSection($s);
  $intCount = $oSEC->items; // number of topics before the action
  $intYear = intval(date('Y'));
  $arrYears = array('old'=>($intYear-4).' and older',($intYear-3)=>$intYear-3,$intYear-2,$intYear-1,$intYear);
  foreach($arrYears as $strKey=>$strValue) $arrYears[$strKey] .= strtolower(' -- '.LangS('Topic',cSection::CountItems($oSEC->id,'topics',10,$strKey)).' ('.LangS('Closed',cSection::CountItems($oSEC->id,'topicsZ',10,$strKey)).')');

  // ask confirmation and ask year

  if ( empty($ok) || empty($_GET['v']) || $t<0 )
  {
    $oVIP->EndMessage
    (
    NULL,
    '<p><a href="'.Href().'?a=topicmoveall&s='.$s.'&d='.$d.'">'.$L['All'].'</a> &middot; <span class="bold">'.$L['By'].' '.strtolower($L['Year']).'</span></p>
    <form method="get" action="'.$oVIP->selfurl.'">
    <table cellspacing="0" class="data_o">
    <tr>
    <td class="colhd colhdfirst" style="width:150px;">'.$L['Section'].'</td>
    <td class="colct">'.$oSEC->name.'</td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Year'].'</td>
    <td class="colct"><select id="v" name="v">'.QTasTag($arrYears).'</select></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">'.$L['Move_to'].'</td>
    <td class="colct"><select name="t" size="1">'.GotoList(-1,$s).'</select></td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">'.$L['Ref'].'</td>
    <td class="colct"><select name="p" size="1">
    <option value="1">'.$L['Move_keep'].'</option>
    <option value="0">'.$L['Move_reset'].'</option>
    <option value="2">'.$L['Move_follow'].'</option>
    </select></td>
    </tr>
    <tr>
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><input type="hidden" name="a" value="'.$a.'" />
    <input type="hidden" name="s" value="'.$s.'" />
    <input type="hidden" name="d" value="'.$d.'" />
    <input type="submit" name="ok" value="'.$L['Move'].'" /> &nbsp;&nbsp; <input type="submit" name="ok" value="'.$L['Move_closed'].'" /></td>
    </tr>
    </table>
    </form><br />',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // move topics
  $oSEC->MoveTopics($t,$p,-1,$ok==$L['Move_closed'],$v);
  $intCount = $intCount - $oSEC->items;

  // exit
  $oVIP->EndMessage(NULL,$L['S_update'].'<p>'.$L['Topics_moved'].': '.$intCount.'</p>','admin',2);
  exit;
  break;

// --------------
case 'topicprune':
// --------------

  if ( $s<0 ) die('Wrong id '.$s);
  if ( $d<1 ) die('Wrong day '.$d);
  $intT = 0;
  $intA = 0;
  $intI = 0; // only one of these 3 variables will be set (see checkbox)
  if ( isset($_GET['tt']) ) $intT = intval($_GET['tt']);
  if ( isset($_GET['ta']) ) $intA = intval($_GET['ta']);
  if ( isset($_GET['ti']) ) $intI = intval($_GET['ti']);

  $oSEC = new cSection($s);
  $intUA = cSection::CountItems($oSEC->id,'unrepliedA',$d); // only news
  $intUI = cSection::CountItems($oSEC->id,'unrepliedI',$d); // only inspections
  $intUT = cSection::CountItems($oSEC->id,'unrepliedT',$d); // only std tickets

  $oVIP->selfname = $L['Adm_topics_prune'];
  $oVIP->exiturl = 'qti_adm_topic.php?d='.$d;
  $oVIP->exitname = '&laquo; '.$oVIP->exitname;

  // Ask confirmation
  
  if ( empty($ok) || ($intT+$intA+$intI)==0 )
  {
    $error = (!empty($ok) ? '<span class="error">'.$L['E_nothing_selected'].'</span><br />' : '');

    $oVIP->EndMessage
    (
    NULL,
    '<form method="get" action="'.$oVIP->selfurl.'"><table class="data_o" cellspacing="0">
    <tr class="data_o">
    <td class="colhd colhdfirst" style="width:150px;">'.$L['Section'].'</td>
    <td class="colct"><b>'.ObjTrans('sec',$s,"Section $s").'</b></td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">'.$L['Containing'].'</td>
    <td class="colct">'.LangS('Unreplied_topic',$intUT+$intUA+$intUI).'</td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">'.$L['Delete'].'</td>
    <td class="colct">
    <input type="checkbox" id="ta" name="ta" value="'.$intUA.'"'.($intUA==0 ? QDIS : '').'/>&nbsp;<label for="ta">'.LangS('News',$intUA).'</label><br />
    <input type="checkbox" id="ti" name="ti" value="'.$intUI.'"'.($intUI==0 ? QDIS : '').'/>&nbsp;<label for="ti">'.LangS('Inspection',$intUI).'</label><br />
    <input type="checkbox" id="tt" name="tt" value="'.$intUT.'"'.($intUT==0 ? QDIS : '').'/>&nbsp;<label for="tt">'.LangS('Other',$intUT).'</label></td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><i><b>'.sprintf($L['H_Topics_prune'],$d).'</b></i></td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct">
    <input type="hidden" name="a" value="'.$a.'" />
    <input type="hidden" name="d" value="'.$d.'" />
    <input type="hidden" name="s" value="'.$s.'" />
    <input type="submit" name="ok" value="'.$L['Delete'].'" />
    </td></tr>
    </table></form>'.$error,
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // Only std topics 

  if ( $intT>0 )
  {
    $oDB->Query( 'SELECT t.id FROM '.TABTOPIC.' t WHERE t.forum='.$s.' AND t.replies=0 AND t.type="T" AND t.firstpostdate<"'.DateAdd(date('Ymd His'),-$d,'day').'"' );
    $strId = '';
    while($row=$oDB->Getrow()) $strId .= $row['id'].',';
    if ( !empty($strId) )
    {
      $strId = substr($strId,0,-1);
      // delete posts and topics
      $oDB->Query( 'DELETE FROM '.TABPOST.' WHERE topic IN ('.$strId.')' );
      $oDB->Query( 'DELETE FROM '.TABTOPIC.' WHERE id IN ('.$strId.')' );
    }
  }

  // Only news topics

  if ( $intA>0 )
  {
    $oDB->Query( 'SELECT t.id FROM '.TABTOPIC.' t WHERE t.forum='.$s.' AND t.replies=0 AND t.type="A" AND t.firstpostdate<"'.DateAdd(date('Ymd His'),-$d,'day').'"' );
    $strId = '';
    while($row=$oDB->Getrow()) $strId .= $row['id'].',';
    if ( !empty($strId) )
    {
      $strId = substr($strId,0,-1);
      // delete posts and topics
      $oDB->Query( 'DELETE FROM '.TABPOST.' WHERE topic IN ('.$strId.')' );
      $oDB->Query( 'DELETE FROM '.TABTOPIC.' WHERE id IN ('.$strId.')' );
    }
  }

  // Only inspection topics

  if ( $intI>0 )
  {
    $oDB->Query( 'SELECT t.id FROM '.TABTOPIC.' t WHERE t.forum='.$s.' AND t.replies=0 AND t.type="I" AND t.firstpostdate<"'.DateAdd(date('Ymd His'),-$d,'day').'"' );
    $strId = '';
    while($row=$oDB->Getrow()) $strId .= $row['id'].',';
    if ( !empty($strId) )
    {
      $strId = substr($strId,0,-1);
      // delete posts and topics
      $oDB->Query( 'DELETE FROM '.TABPOST.' WHERE topic IN ('.$strId.')' );
      $oDB->Query( 'DELETE FROM '.TABTOPIC.' WHERE id IN ('.$strId.')' );
    }
  }

  // Update section stats

  $oSEC->UpdateStats(array('tags'=>$oSEC->tags),true,true);

  // Exit

  $oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
  exit;
  break;

// --------------
case 'tags_del':
// --------------

  if ( isset($_GET['tt']) ) { $tt=strip_tags($_GET['tt']); } else { $tt='en'; }
  
  $oVIP->selfname = $L['Delete'].' CSV';
  $oVIP->exiturl = 'qti_adm_tags.php?tt='.$tt;
  $oVIP->exitname = '&laquo; '.$L['Tags'];

  
  // Ask confirmation

  if ( empty($ok) )
  {
    $oVIP->EndMessage
    (
    NULL,
    '<form method="get" action="'.$oVIP->selfurl.'">
    <table class="data_o" cellspacing="0">
    <tr class="data_o">
    <td class="colhd colhdfirst" style="width:150px">File</td>
    <td class="colct">'.$v.'</td>
    </tr>
    <tr class="data_o">
    <td class="colhd colhdfirst">&nbsp;</td>
    <td class="colct"><input type="hidden" name="a" value="'.$a.'" /><input type="hidden" name="tt" value="'.$tt.'" /><input type="hidden" name="v" value="'.$v.'" /><input type="submit" name="ok" value="'.$L['Delete'].'" />
    </td>
    </tr>
    </table>
    </form>',
    'admin',
    0,
    '600px'
    );
    exit;
  }

  // Delete

  if ( file_exists('upload/'.$v) ) unlink('upload/'.$v);

  // Exit

  $oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
  exit;
  break;
  
// --------------
default:
// --------------

  echo 'Unknown action';
  break;

// --------------
}

$oVIP->EndMessage('!','Command ['.$a.'] failled...',$_SESSION[QT]['skin_dir'],2);

?>
Return current item: QuickTicket