<?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 $admin_template_path;

    // vars url & form
    global $num_rows;

    // vars messages
    global $msg;

    // vars template
    global $message, $back;

    $links_obj = new clsLink;
    $links_obj->table_name = "idx_link";
    $links_obj->category_table_name = "idx_category";

    $tpl = new Template;

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

      if(!empty($id)) {
        $title = $links_obj->GetLinkTitle($id);
        $delete_result = $links_obj->Delete($id);

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

        $tpl->assign('title', $title);
        $message = $tpl->fetch('var:' . $message);
        $deleted++;
      }
      $i++;
    }

    if($deleted!=0) {
      $category_obj = new clsCategory;
        $category_obj->table_name = "idx_category";
      $category_obj->link_table_name = "idx_link";

      //$category_obj->UpdateNumberOfLinksInAllCategories();
    }

    if(empty($message)) $message = $msg["20092"];
    else $message .= $msg["30015"];

    $back = "<a href=$back>Back</a>";

    DisplayTemplate($admin_template_path . "message.html", "\$message,\$back");
  }


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

  include "../application.php";
  
  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  DeleteLink();
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>