+/* This utility function remove beginning <td> and </td> from a string
+ * generated by the above *_cell function.
+ * This is usefull to use the result of the function within a pager
+ * which already include the <td>...</td>
+ * However, for function which doesn't return a string
+ * but echo, we need to capture the output of the echo first.
+ */
+function start_extract_cell() {
+ // We need
+ ob_start();
+}
+
+function end_extract_cell() {
+ $content = ob_get_contents();
+ ob_end_clean();
+ return extract_cell($content);
+}
+
+function extract_cell($td) {
+ if(preg_match('/\s*<td>(.*)<\/td>\s*/s', $td, $matches)) {
+ return $matches[1];
+ }
+ else {
+print_r('cacou');
+ return $td;
+ }
+}
+
+
+function update_extra_order_details() {
+ if(!isset($_POST['Update']) || $_POST['Update'] != 'Update') return;
+
+begin_transaction();
+ // update in database all field
+ foreach($_POST['detail'] as $detail_id => $values) {
+ $set = array();
+ if($comment = $values['comment']) array_push($set, " comment='$comment' ");
+ if(isset($values['required_date'])) {
+ $required_date = trim($values['required_date']);
+ if($required_date == "") {
+ array_push($set," required_date = NULL");
+ } else {
+ $date = date2sql($required_date);
+ array_push($set," required_date='$date' ");
+ }
+ }
+
+ if(!empty($set)) {
+ $sql = "UPDATE ".TB_PREF."sales_order_details SET ".implode($set,', ')." WHERE id = $detail_id ";
+
+ if(!db_query($sql)) {
+ display_error('Problem while updating order details. Try again');
+ cancel_transaction();
+ return;
+ }
+ }
+
+ }
+
+ display_notification('Order details updated');
+
+}
+
+function compute_input_name($row, $field) {
+ $row_id = $row['id'];
+ return "detail[$row_id][$field]";
+}
+