6 $query =
$app->getQuery();
10 if ( @$query[
'--id'] ){
13 if ( @$query[
'-relationship'] ){
20 $rec = df_get_record_by_id($query[
'--id']);
22 throw new Exception(
"Record could not be found");
24 if (
PEAR::isError($rec) )
throw new Exception($rec->getMessage());
27 if ( !$rec->checkPermission(
'edit') ){
28 throw new Exception(
"Failed to get edit form for record. Permission denied");
31 $tableObj = $rec->_table;
34 if ( @$query[
'--fields'] ){
35 $fields = explode(
',', $query[
'--fields']);
39 $temp = $tableObj->fields(
false,
false,
true);
52 }
else if ( @$query[
'-table'] ){
57 $tablePerms = $tableObj->getPermissions();
59 if ( !@$tablePerms[
'new'] ){
60 throw new Exception(
"Failed to build form data because you do not have permission to create new records on this table.");
68 if ( @$query[
'--fields'] ){
69 $fields = explode(
',', $query[
'--fields']);
72 $temp = $tableObj->fields(
false,
false,
true);
79 $valuelists = array();
82 throw new Exception(
"No fields were specified for the form.");
87 $perms = $tableObj->getPermissions(array(
'field'=>$f));
88 if ( !@$perms[
'new']){
93 $data = $tableObj->getField($f);
96 'widget'=>$data[
'widget']
99 $defaults[
$f] = $tableObj->getDefaultValue($f);
101 if ( @$data[
'vocabulary'] ){
102 $form[
$f][
'vocabulary'] = $data[
'vocabulary'];
103 if ( !isset($valuelists[$data[
'vocabulary']]) ){
104 $valuelists[$data[
'vocabulary']] = $tableObj->getValuelist($data[
'vocabulary']);
109 if ( @$data[
'validators'] ){
110 $form[
$f][
'validators'] = $data[
'validators'];
117 'message'=>
'Form successfully created',
119 'defaults'=>$defaults,
120 'valuelists'=>$valuelists
129 throw new Exception(
"Invalid parameters for rest_form");
132 }
catch (Exception $ex){
135 'code' => $ex->getCode(),
136 'message' => $ex->getMessage()
145 echo json_encode($params);