<?php

/**
 * [BEGIN_COT_EXT]
 * Hooks=market.add.add.done
 * [END_COT_EXT]
 */
defined('COT_CODE') or die('Wrong URL.');

global $db_users, $usr;
require_once cot_incfile('notify', 'plug');
require_once cot_langfile('notifyMarket', 'plug', "ru");

$groups = explode(",", $cfg["plugin"]["notifyMarket"]["groups"]);
$where["user_maingrp"] = "";
$i = 0;
foreach ($groups as $goup) {
    if ($i != 0)
        $prefix = " OR ";
    $where["user_maingrp"] .= $prefix . "user_maingrp='{$goup}'";
    $i++;
}

$users = $db->query(" SELECT * FROM `{$db_users}` WHERE {$where["user_maingrp"]} ")->fetchAll();

if ($_POST["rnotify"] == 1) {
    foreach ($users as $user) {
        $subscriptions = explode(",", $user['user_notifymarket']);
        $ms = array_search($item["item_cat"], array_merge(array(0), $subscriptions), 1);
        if ($ms) {
            notify_send("market", "add", cot_url("market", "c={$ritem["item_cat"]}&al={$ritem["item_alias"]}"), $cfg["plugin"]["notifyMarket"]["title"], "{$L['eventeshop_user']} {$usr["name"]} {$L['eventeshop_added_item']} \"{$ritem["item_title"]}\" ", $user["user_id"], $usr["id"]);
        }
    }
}
