Beispiel #1
0
 function preprocess()
 {
     global $FANNIE_OP_DB;
     $dbc = FannieDB::get($FANNIE_OP_DB);
     $json = array('error' => '');
     $model = new BatchTypeModel($dbc);
     if (FormLib::get_form_value('saveDesc') !== '') {
         $model->batchTypeID(FormLib::get('bid'));
         $model->typeDesc(FormLib::get('saveDesc'));
         if ($model->save() === false) {
             $json['error'] = 'Error saving description';
         }
         echo json_encode($json);
         return false;
         // ajax call
     }
     if (FormLib::get_form_value('saveType') !== '') {
         $model->batchTypeID(FormLib::get('bid'));
         $model->discType(FormLib::get('saveType'));
         if ($model->save() === false) {
             $json['error'] = 'Error saving sale type';
         }
         echo json_encode($json);
         return false;
         // ajax call
     }
     if (FormLib::get('saveDated') !== '') {
         $model->batchTypeID(FormLib::get('bid'));
         $model->datedSigns(FormLib::get('saveDated'));
         if ($model->save() === false) {
             $json['error'] = 'Error saving date setting';
         }
         echo json_encode($json);
         return false;
         // ajax call
     }
     if (FormLib::get('saveSO') !== '') {
         $model->batchTypeID(FormLib::get('bid'));
         $model->specialOrderEligible(FormLib::get('saveSO'));
         if ($model->save() === false) {
             $json['error'] = 'Error saving SO eligibility';
         }
         echo json_encode($json);
         return false;
         // ajax call
     }
     if (FormLib::get('saveUI') !== '') {
         $model->batchTypeID(FormLib::get('bid'));
         $model->editorUI(FormLib::get('saveUI'));
         if ($model->save() === false) {
             $json['error'] = 'Error saving UI setting';
         }
         echo json_encode($json);
         return false;
         // ajax call
     }
     if (FormLib::get_form_value('addtype') !== '') {
         $prep = $dbc->prepare_statement("SELECT MAX(batchTypeID) FROM batchType");
         $res = $dbc->exec_statement($prep);
         $tid = array_pop($dbc->fetch_row($res));
         $tid = empty($tid) ? 1 : $tid + 1;
         $ins = $dbc->prepare_statement("INSERT INTO batchType (batchTypeID,typeDesc,discType)\n                VALUES (?,'New Type',1)");
         $dbc->exec_statement($ins, array($tid));
     } elseif (FormLib::get_form_value('deltype') !== '') {
         $query = $dbc->prepare_statement("DELETE FROM batchType WHERE batchTypeID=?");
         $dbc->exec_statement($query, array(FormLib::get_form_value('bid')));
     }
     return true;
 }