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

  /*===================================================
    ProcessSubscribe()
  ===================================================*/

  function ProcessSubscribe() {

    // vars global configuration
    global $theme_path;

    // vars url & form
    global $theme, $cat;

    // vars messages
    global $msg;

    // vars template
    global $error_msg;

    global $dbConn;
   
    // check if already exist
    $query    = "select username from idx_notification where
                 username = '$_COOKIE[COOKIE_USERNAME]' AND
                 category_id = '$cat'";
    $result   = @$dbConn->Execute($query);
    $username = $result->Fields("username");
    
    if(!empty($username)) {
      DisplayTemplate($theme_path . "cp/subscribe_error.html");
      RunPostFilter(__FILE__);
    }
    
    // add notification
    $query = "insert into idx_notification(username, category_id) values
              ('$_COOKIE[COOKIE_USERNAME]', '$cat')";
    $result = @$dbConn->Execute($query);

    // ignore error
    DisplayTemplate($theme_path . "cp/subscribe_ok.html");
  }


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

  include "../application.php";

  RunPreFilter(__FILE__);

  ProcessSubscribe();

  RunPostFilter(__FILE__);

?>