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

  /*===================================================
    ShowFormAddFavorites()
  ===================================================*/

  function ShowFormAddFavorites() {

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

    // vars url & form
    global $id;

    // vars messages
    global $msg;

    // vars template

    $tpl = new Template();

    $links_obj = new clsLink;
    $links_obj->query               = "select * from idx_link where link_id = '$id'";
    $links_obj->table_name          = "idx_link";
    $links_obj->category_table_name = "idx_category";
    $links_obj->favorite_table_name = "idx_favorites";
    $links_obj->category_separator  = $category_separator;
    $links_obj->max_rows            = 1;
    $links_obj->rating_image_path   = $theme_path . "images/";
    $links_obj->date_format         = $msg["20051"];
    $links_obj->template_file       = $theme_path . "cp/favorite_add_form.html";
    $detail                         = $links_obj->Display();
    $fav                            = $links_obj->GetFavoritesDropDown($_COOKIE['COOKIE_USERNAME']);

    $tpl->assign('favorite', $fav);
    $detail = $tpl->fetch('var:' . $detail);

    print $detail;
  }


  /*===================================================
    ProcessFormAddFavorites()
  ===================================================*/

  function ProcessFormAddFavorites() {

    // vars global configuration
    global $theme_path;

    // vars url & form
    global $theme, $link_id, $favorite;

    // vars messages
    global $msg;

    // vars template
    global $error_msg;

    $links_obj = new clsLink;
    $links_obj->table_name                 = "idx_link";
    $links_obj->favorite_table_name        = "idx_favorites";
    $links_obj->favorite_detail_table_name = "idx_favorites_detail";
    $add_result                            = $links_obj->AddToFavorite($favorite, $link_id);

    if ($add_result == 0)
      DisplayTemplate($theme_path . "cp/favorite_add_ok.html");
    elseif ($add_result == 1) {
      $error_msg = $msg["20061"];
      DisplayTemplate($theme_path . "cp/favorite_add_error.html", "\$error_msg");
    }
  }


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

  include "../application.php";

  RunPreFilter(__FILE__);

  if (empty($pflag)) {
    ShowFormAddFavorites();
  }
  elseif ($pflag == 'add') {
    ProcessFormAddFavorites();
  }

  RunPostFilter(__FILE__);

?>