<?php
/**
* PHP versions 4 and 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.3 build:20091102
*/
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
$s = -1; // section
$t = -1; // topic (or move target)
$p = -1; // post
$v = ''; // value
QThttpvar('a s t p v','str int int int str');
$oVIP->selfurl = 'qti_adm_cmd.php';
$oVIP->selfname = 'QuickTicket command';
// --------
// EXECUTE COMMAND
// --------
switch($a)
{
// --------------
case 'deletedomain':
// --------------
if ( $s<1 ) die('Wrong id '.$s);
$oVIP->selfname = $L['Domain_del'];
$oVIP->exiturl = 'qti_adm_sections.php';
$oVIP->exitname = '« '.$L['Sections'];
// ask destination
if ( !isset($_GET['ok']) )
{
$arrDomains = GetDomains();
$strTitle = $arrDomains[$s];
$arrSections = QTarrget(GetSections($oVIP->role,$s));
// 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!=$s ) $arrDdest[$intKey]=$strValue; }
$strDdest = '<tr class="data_o">
<td class="th_o th_o_first">'.$L['Sections'].'</td>
<td class="td_o">
<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="th_o th_o_first" style="width:150px">'.$L['Title'].'</td>
<td class="td_o"><b>'.$strTitle.'</b></td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first">'.$L['Containing'].'</td>
<td class="td_o">'.$strDcont.'</td>
</tr>'.N.$strDdest.'
<tr class="data_o">
<td class="th_o th_o_first"> </td>
<td class="td_o"><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 domain
require_once('bin/qti_class_dom.php');
if ( $t>=0 ) cDomain::MoveSections($s,$t);
cDomain::Delete($s);
// 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 = '« '.$L['Sections'];
$oSEC = new cSection($s);
// ask confirmation
if ( !isset($_GET['ok']) )
{
// list topics
if ( $oSEC->topics>0 )
{
$strList = '<tr class="data_o"><td class="th_o"> </td><td class="td_o"><i><b>'.$L['H_Topics_delete'].'</b></i> <a href="qti_adm_cmd.php?a=topicmoveall&s='.$s.'&d=10">'.$L['Adm_topics_move'].' »</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="th_o th_o_first" style="width:150px">'.$L['Section'].'</td>
<td class="td_o">'.$oSEC->name.'</td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first">'.$L['Containing'].'</td>
<td class="td_o">'.LangS('Topic',$oSEC->topics).', '.LangS('Reply',$oSEC->replies).'</td>
</tr>
'.$strList.'
<tr class="data_o">
<td class="th_o th_o_first"> </td>
<td class="td_o"><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 forum
$oSEC->DeleteTopics($s);
$oDB->Query('DELETE FROM '.TABSECTION.' WHERE id='.$s);
$oVIP->LangDel('sec','s'.$s);
$oVIP->LangDel('secdesc','s'.$s);
Unset($_SESSION[QT]['sys_topics']);
Unset($_SESSION[QT]['sys_replies']);
Unset($_SESSION['qtiSec']);
// 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['Status_del'];
$oVIP->exiturl = 'qti_adm_statuses.php';
$oVIP->exitname = '« '.$L['Statuses'];
// ask confirmation
if ( !isset($_GET['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="th_o th_o_first" style="width:150px;">'.$L['Status'].'</td>
<td class="td_o"><b>'.$v.' '.AsImg($_SESSION[QT]['skin_dir'].'/'.$oVIP->statuses[$v]['icon'],'-',$oVIP->statuses[$v]['statusname'],'ico ico_status').' '.$oVIP->statuses[$v]['name'].'</b></td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Description'].'</td>
<td class="td_o">'.$oVIP->statuses[$v]['statusdesc'].'</td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Move'].'</td>
<td class="td_o">'.$L['H_Status_move'].' <select name="to" size="1" class="small">'.$strSdest.'</select></td>
</tr>
<tr>
<td class="th_o th_o_first"> </td>
<td class="td_o">
<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);
$days = $_GET['d'];
$oVIP->selfname = $L['Adm_topics_delete'];
$oVIP->exiturl = 'qti_adm_topic.php?d='.$days;
$oVIP->exitname = '« '.$L['Topics'];
$oSEC = new cSection($s);
$intClosed = $oSEC->Count('closed');
$intNews= $oSEC->Count('news');
// ask confirmation
if ( !isset($_GET['ok']) )
{
$oVIP->EndMessage
(
NULL,
'<p><span class="bold">'.$L['All'].'</span> · <a href="'.$oVIP->selfurl.'?a=topicdeleteyear&s='.$s.'&d='.$days.'">'.$L['By'].' '.strtolower($L['Year']).'</a></p>
<form method="get" action="'.$oVIP->selfurl.'">
<table cellspacing="0" class="data_o">
<tr>
<td class="th_o th_o_first" style="width:150px;">'.$L['Section'].'</td>
<td class="td_o">'.$oSEC->name.'</td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Containing'].'</td>
<td class="td_o">'.LangS('Topic',$oSEC->topics).' ('.LangS('News',$intNews).', '.LangS('Reply',$oSEC->replies).')</td>
</tr>
<tr>
<td class="th_o th_o_first"> </td>
<td class="td_o"><i><b>'.$L['H_Topics_delete'].'</b></i></td>
</tr>
<tr>
<td class="th_o th_o_first"> </td>
<td class="td_o">
<input type="hidden" name="a" value="'.$a.'"/>
<input type="hidden" name="s" value="'.$s.'"/>
<input type="hidden" name="d" value="'.$days.'"/>
<input type="submit" name="ok" value="'.$L['Delete'].'"/> <span class="small">('.$oSEC->topics.')</span> '.( $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($s,$_GET['ok']==$L['Delete_closed']);
// exit
$oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
exit;
break;
// --------------
case 'topicdeleteyear':
// --------------
if ( $s<0 ) die('Wrong id '.$s);
$days = $_GET['d'];
$oVIP->selfname = $L['Adm_topics_delete'];
$oVIP->exiturl = 'qti_adm_topic.php?d='.$days;
$oVIP->exitname = '« '.$L['Topics'];
$oSEC = new cSection($s);
$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',$oSEC->Count('topics',$s,10,$strKey)).' ('.LangS('Closed',$oSEC->Count('closed',$s,10,$strKey)).')');
// ask confirmation and ask year
if ( !isset($_GET['ok']) || empty($_GET['v']) )
{
$oVIP->EndMessage
(
NULL,
'<p><a href="'.$oVIP->selfurl.'?a=topicdeleteall&s='.$s.'&d='.$days.'">'.$L['All'].'</a> · <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="th_o th_o_first" style="width:150px;">'.$L['Section'].'</td>
<td class="td_o">'.$oSEC->name.'</td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Year'].'</td>
<td class="td_o"><select id="v" name="v">'.QTasTag($arrYears).'</select></td>
</tr>
<tr>
<td class="th_o th_o_first"> </td>
<td class="td_o"><i><b>'.$L['H_Topics_delete'].'</b></i></td>
</tr>
<tr>
<td class="th_o th_o_first"> </td>
<td class="td_o">
<input type="hidden" name="a" value="'.$a.'"/>
<input type="hidden" name="s" value="'.$s.'"/>
<input type="hidden" name="d" value="'.$days.'"/>
<input type="submit" name="ok" value="'.$L['Delete'].'"/> <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($s,$_GET['ok']==$L['Delete_closed'],$v);
// exit
$oVIP->EndMessage(NULL,$L['S_delete'],'admin',2);
exit;
break;
// --------------
case 'topicmoveall':
// --------------
if ( $s<0 ) die('Wrong id '.$s);
$days = $_GET['d'];
$oVIP->selfname = $L['Adm_topics_move'];
$oVIP->exiturl = 'qti_adm_topic.php?d='.$days;
$oVIP->exitname = '« '.$L['Topics'];
$oSEC = new cSection($s);
$intClosed = $oSEC->Count('closed');
$intNews = $oSEC->Count('news');
$arrSections = QTarrget(GetSections($oVIP->role,-1,$s));
// ask confirmation
if ( !isset($_GET['ok']) || $t<0 )
{
// list destinations
$strFdest = QTasTag($arrSections);
// form
$oVIP->EndMessage
(
NULL,
'<p><span class="bold">'.$L['All'].'</span> · <a href="'.$oVIP->selfurl.'?a=topicmoveyear&s='.$s.'&d='.$days.'">'.$L['By'].' '.strtolower($L['Year']).'</a></p>
<form method="get" action="'.$oVIP->selfurl.'">
<table cellspacing="0" class="data_o">
<tr>
<td class="th_o th_o_first" style="width:150px;">'.$L['Section'].'</td>
<td class="td_o">'.$oSEC->name.'</td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Containing'].'</td>
<td class="td_o">'.LangS('Topic',$oSEC->topics).' ('.LangS('News',$intNews).', '.LangS('Reply',$oSEC->replies).')</td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Move_to'].'</td>
<td class="td_o"><select name="t" size="1">'.$strFdest.'</select></td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first">'.$L['Ref'].'</td>
<td class="td_o"><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="th_o th_o_first"> </td>
<td class="td_o"><input type="hidden" name="a" value="'.$a.'"/>
<input type="hidden" name="s" value="'.$s.'"/>
<input type="hidden" name="d" value="'.$days.'"/>
<input type="submit" name="ok" value="'.$L['Move'].'"/> <span class="small">('.$oSEC->topics.')</span> '.( $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($s,$t,$p,-1,$_GET['ok']==$L['Move_closed']);
// exit
$oVIP->EndMessage(NULL,$L['S_update'],'admin',2);
exit;
break;
// --------------
case 'topicmoveyear':
// --------------
if ( $s<0 ) die('Wrong id '.$s);
$days = $_GET['d'];
$oVIP->selfname = $L['Adm_topics_move'];
$oVIP->exiturl = 'qti_adm_topic.php?d='.$days;
$oVIP->exitname = '« '.$L['Topics'];
$oSEC = new cSection($s);
$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',$oSEC->Count('topics',$s,10,$strKey)).' ('.LangS('Closed',$oSEC->Count('closed',$s,10,$strKey)).')');
$arrSections = QTarrget(GetSections($oVIP->role,-1,$s));
// ask confirmation and ask year
if ( !isset($_GET['ok']) || empty($_GET['v']) || $t<0 )
{
// list destinations
$strFdest = QTasTag($arrSections);
// form
$oVIP->EndMessage
(
NULL,
'<p><a href="'.$oVIP->selfurl.'?a=topicmoveall&s='.$s.'&d='.$days.'">'.$L['All'].'</a> · <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="th_o th_o_first" style="width:150px;">'.$L['Section'].'</td>
<td class="td_o">'.$oSEC->name.'</td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Year'].'</td>
<td class="td_o"><select id="v" name="v">'.QTasTag($arrYears).'</select></td>
</tr>
<tr>
<td class="th_o th_o_first">'.$L['Move_to'].'</td>
<td class="td_o"><select name="t" size="1">'.$strFdest.'</select></td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first">'.$L['Ref'].'</td>
<td class="td_o"><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="th_o th_o_first"> </td>
<td class="td_o"><input type="hidden" name="a" value="'.$a.'"/>
<input type="hidden" name="s" value="'.$s.'"/>
<input type="hidden" name="d" value="'.$days.'"/>
<input type="submit" name="ok" value="'.$L['Move'].'"/> <input type="submit" name="ok" value="'.$L['Move_closed'].'"/></td>
</tr>
</table>
</form><br/>',
'admin',
0,
'600px'
);
exit;
}
// move topics
$oSEC->MoveTopics($s,$t,$p,-1,$_GET['ok']==$L['Move_closed'],$v);
// exit
$oVIP->EndMessage(NULL,$L['S_update'],'admin',2);
exit;
break;
// --------------
case 'topicprune':
// --------------
if ( $s<0 ) die('Wrong id '.$s);
$d = 10; if ( isset($_GET['d']) ) $d = intval($_GET['d']);
if ( $d<1 ) die('Wrong day '.$d);
$intTopics = 0;
$intNews = 0;
if ( isset($_GET['tt']) ) $intTopics = $_GET['tt'];
if ( isset($_GET['ta']) ) $intNews = $_GET['ta'];
$intU = cSection::Count('unreplied',$s,$d);
$intUN = cSection::Count('unrepliednews',$s,$d);
$oVIP->selfname = $L['Adm_topics_prune'];
$oVIP->exiturl = 'qti_adm_topic.php?d='.$d;
$oVIP->exitname = '« '.$L['Topics'];
// ask confirmation
if ( !isset($_GET['ok']) || ($intTopics+$intNews)==0 )
{
if ( isset($_GET['ok']) )
{
$error = '<span class="error">'.$L['E_nothing_selected'].'</span><br/>';
}
else
{
$error = '';
}
$oVIP->EndMessage
(
NULL,
'<form method="get" action="'.$oVIP->selfurl.'"><table class="data_o" cellspacing="0">
<tr class="data_o">
<td class="th_o th_o_first" style="width:150px;">'.$L['Section'].'</td>
<td class="td_o"><b>'.ObjTrans('sec',$s,"Section $s").'</b></td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first">'.$L['Containing'].'</td>
<td class="td_o">'.LangS('Unreplied_topic',$intU).' ('.LangS('News',$intUN).')</td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first">'.$L['Delete'].'</td>
<td class="td_o">
<input type="checkbox" id="tt" name="tt" value="'.$intU.'"'.($intU==0 ? QDIS : '').'/> <label for="t">'.LangS('Topic',$intU).'</label><br/>
<input type="checkbox" id="ta" name="ta" value="'.$intUN.'"'.($intUN==0 ? QDIS : '').'/> <label for="a">'.LangS('News',$intUN).'</label></td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first"> </td>
<td class="td_o"><i><b>'.sprintf($L['H_Topics_prune'],$d).'</b></i></td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first"> </td>
<td class="td_o">
<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;
}
// dflt topics
if ( $intTopics>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.')' );
}
}
// news topics
if ( $intNews>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.')' );
}
}
// update section stats
UpdateSectionStats($s);
// 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 = '« '.$L['Tags'];
// Ask confirmation
if ( !isset($_GET['ok']) )
{
$oVIP->EndMessage
(
NULL,
'<form method="get" action="'.$oVIP->selfurl.'">
<table class="data_o" cellspacing="0">
<tr class="data_o">
<td class="th_o th_o_first" style="width:150px">File</td>
<td class="td_o">'.$v.'</td>
</tr>
<tr class="data_o">
<td class="th_o th_o_first"> </td>
<td class="td_o"><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);
?>