<?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)
 *
 */

  /*===================================================
    ViewPendingReview()
  ===================================================*/

  function ViewPendingReview() {

    // vars global configuration
    global $dbConn, $category_separator, $admin_template_path;

    // vars url & form
    global $pg_which;

    // vars messages
    global $msg;

    // vars template
    global $review, $pagination, $chk_box, $num_rows, $param;
    
    
    $links_obj = new clsLink;

    $links_obj->table_name = "idx_link";
    $links_obj->category_table_name = "idx_category";
    $links_obj->date_format = $msg["20144"];

    $links_obj->paging = true;
    $links_obj->pg_size = 15;
    $links_obj->href = "review_validate.php";
    $links_obj->more_param = "";
    $links_obj->category_file = "../browse.php";
    $links_obj->category_separator = $category_separator;

    $param = "pg_which=$pg_which";

    //$links_obj->rev_rating_image_path = $admin_template_path . "images/review/";
    $links_obj->rev_rating_image_path = "../admin_tpl/images/review/";
    $links_obj->template_file = $admin_template_path . "review_validate_rows.html";
    $query = "select * from idx_review where status = 0";
    $review = $links_obj->DisplayReview($id,$query,true);

    $pagination = $links_obj->pagination;
    $num_rows = $links_obj->num_rows;

    DisplayTemplate($admin_template_path . "review_validate.html",
      "\$num_rows,\$pagination,\$review,\$param");
  }


  /*===================================================
    ApproveReview()
  ===================================================*/

  function ApproveReview() {

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

    // vars url & form
    global $num_rows;

    // vars messages
    global $msg;

    // vars template
    global $message, $title, $back;
    
    $tpl = new Template();

    $links_obj = new clsLink;
    $links_obj->table_name = "idx_link";
    $links_obj->review_table_name = "idx_review";

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

      if(!empty($id)) {

        $query = "select link_id from idx_review where review_id = '$id'";
        $result = $dbConn->Execute($query);
        $lid = $result->Fields("link_id");

        $query = "select title from idx_link where link_id = '$lid'";
        $result = $dbConn->Execute($query);
        $title = $result->Fields("title");

        $links_obj->ApproveReview($id);
        
        $message .= $msg["20141"];
        $tpl->assign('title', $title);
        $message = $tpl->fetch('var:' . $message);

        // recalculate avg_review
        $links_obj->UpdateAvgReview($id);
      }
      $i++;
    }

    if(empty($message)) $message = $msg["20142"];
    
    $back = "<a href=review_validate.php>Back</a>";

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


  /*===================================================
    RejectReview()
  ===================================================*/

  function RejectReview() {

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

    // vars url & form
    global $num_rows;

    // vars messages
    global $msg;

    // vars template
    global $message, $back, $link_id, $title, $url, $description, $contact_name, $email, $bid, $category, $category_id;
    
    $tpl = new Template();

    $links_obj = new clsLink;
    $links_obj->table_name = "idx_link";
    $links_obj->review_table_name = "idx_review";

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

      if(!empty($id)) {

        $query = "select link_id from idx_review where review_id = '$id'";
        $result = $dbConn->Execute($query);
        $lid = $result->Fields("link_id");

        $query = "select title from idx_link where link_id = '$lid'";
        $result = $dbConn->Execute($query);
        $title = $result->Fields("title");

        $links_obj->RejectReview($id);

        $message .= $msg["20143"];
        $tpl->assign('title', $title);
        $message = $tpl->fetch('var:' . $message);
      }
      $i++;
    }

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

    $back = "<a href=review_validate.php>Back</a>";

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


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

  include "../application.php";

  RunPreFilter(__FILE__);

  DisplayTemplate($admin_template_path . "header.html");
  if (empty($pflag)) {
    ViewPendingReview();
  }
  elseif ($pflag == 'approve') {
    ApproveReview();
  }
  elseif ($pflag == 'reject') {
    RejectReview();
  }
  DisplayTemplate($admin_template_path . "footer.html");

  RunPostFilter(__FILE__);

?>