Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
ajax_valuelist_append.php
Go to the documentation of this file.
1 <?php
2 import('Dataface/JSON.php');
3 import('Dataface/ValuelistTool.php');
4 
6 
7  function handle(&$params){
9 
10  if ( !@$_POST['-valuelist'] ){
11  echo JSON::error("No valuelist specified.");
12  exit;
13  }
14 
15  $valuelist = $_POST['-valuelist'];
16  $query =& $app->getQuery();
17 
18  $table =& Dataface_Table::loadTable($query['-table']);
19 
20 
21  if ( !@$_POST['-value'] ){
22  echo JSON::error("No value was provided to be appended to the valuelist.");
23  exit;
24  }
25 
26  $value = $_POST['-value'];
27  if ( @$_POST['-key'] ){
28  $key = $_POST['-key'];
29  } else {
30  $key = null;
31  }
32 
34  $res = $vt->addValueToValuelist($table, $valuelist, $value, $key, true);
35  if ( PEAR::isError($res) ){
36  echo JSON::error($res->getMessage());
37  exit;
38  }
39  echo JSON::json(array(
40  'success'=>1,
41  'value'=>array('key'=>$res['key'], 'value'=>$res['value'])
42  )
43  );
44  exit;
45 
46 
47  }
48 
49 }
50 
51 ?>