function ajax_callbacks($action) { global $FANNIE_OP_DB; $json = array('error' => 0); switch ($action) { case 'createCat': $json = $this->createVendorDepartment(FormLib::get_form_value('vid'), FormLib::get_form_value('deptID'), FormLib::get_form_value('name')); echo json_encode($json); break; case 'deleteCat': $dbc = FannieDB::get($FANNIE_OP_DB); $q = $dbc->prepare_statement("DELETE FROM vendorDepartments\n WHERE vendorID=? AND deptID=?"); $gone = $dbc->exec_statement($q, array(FormLib::get_form_value('vid'), FormLib::get_form_value('deptID'))); if (!$gone) { $json['error'] = 'Error deleting #' + FormLib::get('deptID'); } echo json_encode($json); break; case 'updateCat': $dbc = FannieDB::get($FANNIE_OP_DB); $dept = new VendorDepartmentsModel($dbc); $dept->vendorID(FormLib::get('vid')); $dept->deptID(FormLib::get('deptID')); $dept->name(FormLib::get('name')); $dept->margin(trim(FormLib::get('margin', 0), '%') / 100.0); $dept->posDeptID(FormLib::get('pos')); $saved = $dept->save(); if ($saved === false) { $json['error'] = 'Error saving #' . FormLib::get('deptID'); } echo json_encode($json); break; default: echo 'bad request'; break; } }