<?php

/**
 *
 * INDEXU
 * Copyright(C), Nicecoder, 2000-2006, All Rights Reserved.
 *
 * INDEXU(tm) is protected by Indonesia and International copyright laws.
 * Unauthorized use or distribution of INDEXU(tm) is strictly prohibited,
 * violators will be prosecuted. To obtain a license for using INDEXU(tm),
 * please register at Nicecoder home page at http://www.nicecoder.com
 *
 * Author:
 *    Dody Rachmat Wicaksono (dody@nicecoder.com)
 *    M. Zuber (zubby@nicecoder.com)
 *
 */

  /*===================================================
    DeleteLink()
  ===================================================*/

  function DeleteLink() {

    // vars global configuration
    global $dbConn, $theme_path;

    // vars url & form
    global $num_rows, $op;

    // vars messages
    global $msg;

    // vars template
    global $message;

    $tpl = new Template();

    $links_obj = new clsLink;
    $links_obj->table_name          = "idx_link";
    $links_obj->category_table_name = "idx_category";
    $links_obj->editor_table_name   = "idx_editor";
    $links_obj->user_table_name     = "idx_users";
    $links_obj->bad_link_table_name = "idx_bad_link";

    $i                              = 1;

    while ($i <= $num_rows) {
      $var = "chkbox_$i";
      $id  = $GLOBALS["$var"];

      if (!empty($id)) {
        if ($op == "Delete Report")
          $op = "delete_report";
        elseif ($op == "Delete Link")
          $op = "delete_link";

        // get link id
        $query         = "select link_id from idx_bad_link where bad_link_id = '$id'";
        $result        = $dbConn->Execute($query);
        $lid           = $result->Fields("link_id");
        $title         = $links_obj->GetLinkTitle($lid);
        $delete_result = $links_obj->DeleteBadLinkReport($op, $id);

        if ($delete_result == 0)
          $message .= $msg["20181"];

        $tpl->assign('title', $title);

        $message = $tpl->fetch('var:' . $message);
      }

      $i++;
    }

    if (empty($message))
      $message = $msg["20182"];

    DisplayTemplate($theme_path . "cp/editor_link_bad_delete.html", "\$message");
  }


  /*===================================================
    main
  ===================================================*/

  include "../application.php";

  AddFilter('validate_editor');
  RunPreFilter(__FILE__);

  DeleteLink();

  RunPostFilter(__FILE__);

?>