Xataface  2.0alpha2
Xataface Application Framework
 All Data Structures Namespaces Files Functions Variables Groups Pages
update_grid.php
Go to the documentation of this file.
1 <?php
2 import('Dataface/dhtmlxGrid/activegrid.php');
3 
20 
21  function handle(&$params){
22  if ( isset($_POST['--cleargrids']) and $_POST['--cleargrids'] == 1) Dataface_dhtmlXGrid_activegrid::clearGrids();
23  $cells = @$_REQUEST['cells'];
24 
25 
26 
27 
28  $gridid = @$_REQUEST['-gridid'];
29  $rowid = @$_REQUEST['-rowid'];
30 
31 
32  $grid = Dataface_dhtmlXGrid_activegrid::getGrid($gridid);
33  if ( !is_object($grid) ){
34 
35  echo $this->error('Could not find grid with id "'.$gridid.'"');
36  exit;
37  }
38 
39  if ( !is_array($cells) ){
40  echo $this->notice('No cells were submitted to be updated.');
41  exit;
42  }
43  //$cells = array_map('trim',$cells);
44  foreach (array_keys($cells) as $key){
45  $cells[$key] = trim($cells[$key], "\x7f..\xff\x0..\x1f");
46  }
47  print_r($cells);
48 
49  $res = $grid->setRowValues($rowid, $cells);
50  if ( PEAR::isError($res) ){
51  echo $this->error($res->getMessage());
52  }
53  $grid->update();
54  $grid2 = Dataface_dhtmlXGrid_activegrid::getGrid($gridid);
55  echo $this->json(array('success'=>1));
56  exit;
57 
58 
59  }
60 
61  function notice($msg){
62  return $this->json(array('notice'=>$msg, 'success'=>0));
63  }
64 
65  function warning($msg){
66  return $this->json(array('warning'=>$msg, 'success'=>0));
67  }
68 
69  function error($msg){
70  return $this->json(array('error'=>$msg, 'success'=>0));
71  }
72 
73  function json($arr){
74  if ( is_array($arr) ){
75  $out = array();
76  foreach ( $arr as $key=>$val){
77  $out[] = "'".addslashes($key)."': {$this->json($val)}";
78  }
79  return "{".implode(', ', $out)."}";
80  } else if ( is_int($arr) || is_float($arr) ){
81  return $arr;
82  } else if ( is_bool($arr) ){
83  return ( $arr?'1':'0');
84  } else {
85  return "'".addslashes($arr)."'";
86  }
87  }
88 
89 }
90 
91 ?>