<?
/***************************************************************************
* Copyright (C) 2005 by J Randolph Smith *
* hide@address.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
$temp_sensorid = $_REQUEST['FRM_sensorid'];
$temp_varid = $_REQUEST['FRM_varid'];
if($obj_FMK->currentAction() == "activate")
{
$sql = "INSERT INTO TBL_ASSIGNMENTS ".
"( sensorid, type, itemid ) ".
"VALUES( '$temp_sensorid', 'V', '$temp_varid' )";
$result = $db->query($sql); if (DB::isError($result)) { Stop ( "[".__FILE__."][".__LINE__."] " . $result->getdebugInfo());}
}
else if($obj_FMK->currentAction() == "deactivate")
{
$sql = "DELETE FROM TBL_ASSIGNMENTS ".
"WHERE sensorid = $temp_sensorid AND type = 'V' AND itemid = $temp_varid";
$result = $db->query($sql); if (DB::isError($result)) { Stop ( "[".__FILE__."][".__LINE__."] " . $result->getdebugInfo());}
}
else if($obj_FMK->currentAction() == "deactivateall")
{
$sql = "DELETE FROM TBL_ASSIGNMENTS ".
"WHERE sensorid = $temp_sensorid AND type = 'V'";
$result = $db->query($sql); if (DB::isError($result)) { Stop ( "[".__FILE__."][".__LINE__."] " . $result->getdebugInfo());}
}
else if($obj_FMK->currentAction() == "activateall")
{
/** Clear all existing assignments **/
$sql = "DELETE FROM TBL_ASSIGNMENTS ".
"WHERE sensorid = $temp_sensorid AND type = 'V'";
$delete = $db->query($sql); if (DB::isError($delete)) { Stop ( "[".__FILE__."][".__LINE__."] " . $delete->getdebugInfo());}
/** Insert all vars **/
$sql = "SELECT id FROM TBL_VARIABLES";
$rsVars = $db->query($sql); if (DB::isError($rsVars)) { Stop ( "[".__FILE__."][".__LINE__."] " . $rsVars->getdebugInfo());}
while ($row = $rsVars->fetchRow(DB_FETCHMODE_ASSOC))
{
$sql = "INSERT INTO TBL_ASSIGNMENTS ".
"( sensorid, type, itemid ) ".
"VALUES( '$temp_sensorid', 'V', '".$row['id']."' )";
$rsInsert = $db->query($sql); if (DB::isError($rsInsert)) { Stop ( "[".__FILE__."][".__LINE__."] " . $rsInsert->getdebugInfo());}
}
}
header("location:".$_SERVER['HTTP_REFERER']);
?>