Location: PHPKode > projects > QuickTalk Forum > quicktalk/qtf_adm_change.php
<?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.

*

* @package    QuickTalk

* @author     Philippe Vandenberghe <hide@address.com>

* @copyright  2008-2012 The PHP Group

* @version    2.5 build:20100924

*/



session_start();

require_once('bin/qtf_init.php');

include(Translate('qtf_adm.php'));



if ( $oVIP->role!='A' ) die($L['E_admin']);

if ( !isset($_GET['a'])) die('Wrong action');



include('bin/qtf_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  = 'qtf_adm_change.php';

$oVIP->selfname = 'QuickTalk command';



// --------

// EXECUTE COMMAND

// --------



switch($a)

{



// --------------

case 'deletedomain':

// --------------



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



  $oVIP->selfname = $L['Domain_del'];

  $oVIP->exiturl = 'qtf_adm_sections.php';

  $oVIP->exitname = '&laquo; '.$L['Sections'];



  // ask destination

  if ( !isset($_GET['ok']) )

  {

    $arrDomains = GetDomains();

    $strTitle = $arrDomains[$d];

    $arrSections = QTarrget(GetSections($oVIP->role,$d));



    // list the domain content

    if ( count($arrSections)==0 )

    {

      $strCont = '<span class="small">0 '.$L['Section'].'</span>';

    }

    else

    {

      $strCont = '';

      foreach($arrSections as $intKey=>$strValue)

      {

      $strCont .= '<span class="small">'.$L['Section'].': '.$strValue.'</span><br/>';

      }

    }



    // list of domain destination



    if ( count($arrSections)>0 )

    {

      $arrDest = array(); // array_diff_key() not supported in php<5.1      

      foreach($arrDomains as $intKey=>$strValue) { if ( $intKey!=$d ) $arrDest[$intKey] = $strValue; }

      

      $strDest = '<tr class="tr">

      <td class="colhd colhdfirst">'.$L['Sections'].'</td>

      <td class="colct">

      <select name="t" size="1" class="small">'.QTasTag($arrDest,'',array('format'=>$L['Move_to'].': %s')).'</select>

      </td>

      </tr>';

    }    

    else

    {

      $strDest = '';

    }



    // form

    $oVIP->EndMessage

    (

    NULL,

    '<form method="get" action="'.$oVIP->selfurl.'">

    <table class="data_o" cellspacing="0" summary="settings">

    <tr class="tr_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">'.$strCont.'</td>

    </tr>'.N.$strDest.'

    <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/qtf_class_dom.php');

  if ( $t>=0 ) cDomain::MoveSections($d,$t);

  cDomain::Delete($d);



  // exit

  HtmlRedirect($oVIP->exiturl);

  break;



// --------------

case 'deletesection':

// --------------



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



  $oVIP->selfname = $L['Section_del'];

  $oVIP->exiturl  = 'qtf_adm_sections.php';

  $oVIP->exitname = '&laquo; '.$L['Sections'];



  $voidSEC = new cSection(); $voidSEC->id=$s;



  // ask confirmation

  if ( !isset($_GET['ok']) )

  {  

    $intTopics = $voidSEC->Count('topics');

    $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">'.$_SESSION[QT]['sys_sections'][$s].'</td>

    </tr>

    <tr class="data_o">

    <td class="colhd colhdfirst">'.$L['Containing'].'</td>

    <td class="colct">'.LangS('Topic',$intTopics).', '.LangS('Reply',$voidSEC->Count('replies')).'</td>

    </tr>

    '.( $intTopics>0 ? '<tr class="data_o"><td class="colhd colhdfirst">&nbsp;</td><td class="colct"><i><b>'.$L['H_Topics_delete'].'</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="s" value="'.$s.'"/>

    <input type="submit" name="ok" value="'.$L['Delete'].'"/>'.( $intTopics>0 ? '&nbsp;&nbsp;<a href="qtf_adm_change.php?a=topicmoveall&amp;s='.$s.'&amp;d=10">'.$L['Adm_topics_move'].' &raquo;</a>' : '').'</td>

    </tr>

    </table>

    </form>',

    'admin',

    0,

    '600px'

    );

    exit;

  }



  $voidSEC->Delete();



  $_SESSION['L'] = array();

  if ( isset($_SESSION[QT]['sys_sections']) ) unset($_SESSION[QT]['sys_sections']);



  // exit

  HtmlRedirect($oVIP->exiturl);

  break;





// --------------

case 'topicdeleteall':

// --------------



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



  $oVIP->selfname = $L['Adm_topics_delete'];

  $oVIP->exiturl  = 'qtf_adm_topic.php?d='.$d;

  $oVIP->exitname = '&laquo; '.$L['Topics'];



  $voidSEC = new cSection(); $voidSEC->id=$s;

  $t = $voidSEC->Count('topics'); // number of topics before the action (stored as 't')



  // ask confirmation

  if ( empty($ok) )

  {

    $intReplies = $voidSEC->Count('replies');

    $intClosed = $voidSEC->Count('topicsZ');

    $intNews= $voidSEC->Count('news');

    $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">'.$_SESSION[QT]['sys_sections'][$s].'</td>

    </tr>

    <tr>

    <td class="colhd colhdfirst">'.$L['Containing'].'</td>

    <td class="colct">'.LangS('Topic',$t).' ('.LangS('News',$intNews).', '.LangS('Reply',$intReplies).')</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="t" value="'.$t.'"/>

    <input type="hidden" name="d" value="'.$d.'"/>

    <input type="submit" name="ok" value="'.$L['Delete'].'"/> <span class="small">('.$t.')</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)

  $voidSEC->DeleteTopics($ok==$L['Delete_closed']);

  $t = $t - $voidSEC->Count('topics');



  // exit

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

  exit;

  break;



// --------------

case 'topicdeleteyear':

// --------------



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



  $oVIP->selfname = $L['Adm_topics_delete'];

  $oVIP->exiturl  = 'qtf_adm_topic.php?d='.$d;

  $oVIP->exitname = '&laquo; '.$L['Topics'];



  $voidSEC = new cSection(); $voidSEC->id=$s;

  

  // Recompute stats

  

  $intCount = $voidSEC->Count('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',$voidSEC->Count('topics',10,$strKey)).' ('.LangS('Closed',$voidSEC->Count('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">'.$_SESSION[QT]['sys_sections'][$s].'</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)

  $voidSEC->DeleteTopics($ok==$L['Delete_closed'],$v);

  $intCount = $intCount - $voidSEC->Count('topics');



  // 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  = 'qtf_adm_topic.php?d='.$d;

  $oVIP->exitname = '&laquo; '.$L['Topics'];



  $voidSEC = new cSection(); $voidSEC->id=$s;

  

  // Recompute stats



  $intCount = $voidSEC->Count('topics'); // number of topics before the action

  $intClosed = $voidSEC->Count('topicsZ');

  $intNews = $voidSEC->Count('news');



  // 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">'.$_SESSION[QT]['sys_sections'][$s].'</td>

    </tr>

    <tr>

    <td class="colhd colhdfirst">'.$L['Containing'].'</td>

    <td class="colct">'.LangS('Topic',$intCount).' ('.LangS('News',$intNews).') , '.LangS('Reply',$voidSEC->Count('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">('.$intCount.')</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

  $voidSEC->MoveTopics($t,$p,-1,$ok==$L['Move_closed']);

  $intCount = $intCount - $voidSEC->Count('topics');



  // 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  = 'qtf_adm_topic.php?d='.$d;

  $oVIP->exitname = '&laquo; '.$L['Topics'];



  $voidSEC = new cSection(); $voidSEC->id=$s;

  $intCount = $voidSEC->Count('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',$voidSEC->Count('topics',10,$strKey)).' ('.LangS('Closed',$voidSEC->Count('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">'.$_SESSION[QT]['sys_sections'][$s].'</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

  $voidSEC->MoveTopics($t,$p,-1,$ok==$L['Move_closed'],$v);

  $intCount = $intCount - $voidSEC->Count('topics');



  // 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);

  $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'];



  $voidSEC = new cSection(); $voidSEC->id=$s;

  $intU = $voidSEC->Count('unreplied',$d);

  $intUN = $voidSEC->Count('unrepliednews',$d);



  $oVIP->selfname = $L['Adm_topics_prune'];

  $oVIP->exiturl = 'qtf_adm_topic.php?d='.$d;

  $oVIP->exitname = '&laquo;'.S.$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="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',$intU).' ('.LangS('News',$intUN).')</td>

    </tr>

    <tr class="data_o">

    <td class="colhd colhdfirst">'.$L['Delete'].'</td>

    <td class="colct">

    <input type="checkbox" id="tt" name="tt" value="'.$intU.'"'.($intU==0 ? QDIS : '').'/>&nbsp;<label for="t">'.LangS('Topic',$intU).'</label><br/>

    <input type="checkbox" id="ta" name="ta" value="'.$intUN.'"'.($intUN==0 ? QDIS : '').'/>&nbsp;<label for="a">'.LangS('News',$intUN).'</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><br/>'.$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.')' );

    }

  }



  // count topics in this section

  

  $voidSEC->UpdateLastPostDate();

  $voidSEC->UpdateReplies();



  // 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: QuickTalk Forum