<?php
/**
 * Phoebe pedagogic planner
 *
 * PHP version 5
 *
 * LICENSE: The GNU General Public License (GPL), version 2. See LICENSE.txt
 *
 * Copyright (c) 2006-2008 JISC/HEFCE/University of Oxford
 *
 * @author      David Balch <david.balch@conted.ox.ac.uk>
 * @license     http://opensource.org/licenses/gpl-license.php GPL2
 * @link        http://phoebe-project.conted.ox.ac.uk/
 */

/* Save the value for a property */
$content['settings'] = 'dbWrite';
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/core.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/inc/session.php');
//include_once($_SERVER['DOCUMENT_ROOT'].'/inc/utils.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/db/addFuncts.php');

// TODO: Check session for correct design

// Sanitise user data before sending to database
// Remove preceding "p"
$prop_id = substr($_POST['id'], 1);
// Remove following "_input"
$prop_id = str_replace('_input', '', $prop_id);

if(ctype_digit($prop_id)) {
    // Get Insert new property value
    $sql = 'UPDATE properties '.
           'SET value = '.$mdb2->quote($_POST['value']).' '.
           'WHERE prop_id = '.$prop_id;
    //echo $sql;

    $insert = $mdb2->queryAll($sql);
    if (PEAR::isError($insert)) {
        echo 'Error saving new value - '.$insert->getMessage();
    } else {
        echo $_POST['value'];
    }
} else {
    echo 'Error saving new value - invalid property id.';
}
?>