示例#1
0
             if (isset($_POST['rm_attach_' . $image_id])) {
                 @unlink(CONTACTS_DIR_ATTACHMENTS . 'contacts_' . $cInfo->id . '_' . $image_id . '.zip');
                 unset($attachments[$image_id]);
             }
             $image_id++;
         }
         if (is_uploaded_file($_FILES['file_name']['tmp_name'])) {
             // find an image slot to use
             $image_id = 0;
             while (true) {
                 if (!file_exists(CONTACTS_DIR_ATTACHMENTS . 'contacts_' . $cInfo->id . '_' . $image_id . '.zip')) {
                     break;
                 }
                 $image_id++;
             }
             saveUploadZip('file_name', CONTACTS_DIR_ATTACHMENTS, 'contacts_' . $cInfo->id . '_' . $image_id . '.zip');
             $attachments[$image_id] = $_FILES['file_name']['name'];
         }
         $sql_data_array = array('attachments' => sizeof($attachments) > 0 ? serialize($attachments) : '');
         db_perform(TABLE_CONTACTS, $sql_data_array, 'update', 'id = ' . $cInfo->id);
         // check for crm notes
         if ($_POST['crm_action'] != '' || $_POST['crm_note'] != '') {
             $sql_data_array = array('contact_id' => $cInfo->id, 'log_date' => $_POST['crm_date'], 'entered_by' => $_POST['crm_rep_id'], 'action' => $_POST['crm_action'], 'notes' => db_prepare_input($_POST['crm_note']));
             db_perform(TABLE_CONTACTS_LOG, $sql_data_array, 'insert');
         }
         $_REQUEST['action'] = 'main';
         break;
     }
     $_REQUEST['action'] = 'edit';
     break;
 case 'edit':
     if (isset($_POST['rm_attach_' . $image_id])) {
         @unlink(RMA_DIR_ATTACHMENTS . 'rma_' . $id . '_' . $image_id . '.zip');
         unset($attachments[$image_id]);
     }
     $image_id++;
 }
 if (is_uploaded_file($_FILES['file_name']['tmp_name'])) {
     // find an image slot to use
     $image_id = 0;
     while (true) {
         if (!file_exists(RMA_DIR_ATTACHMENTS . 'rma_' . $id . '_' . $image_id . '.zip')) {
             break;
         }
         $image_id++;
     }
     saveUploadZip('file_name', RMA_DIR_ATTACHMENTS, 'rma_' . $id . '_' . $image_id . '.zip');
     $attachments[$image_id] = $_FILES['file_name']['name'];
 }
 // check for errors, process
 if ($status == 99 && $closed_date == '') {
     $closed_date = date('Y-m-d');
 }
 // write the data
 if (!$error) {
     $sql_data_array = array('status' => $status, 'entered_by' => $entered_by, 'caller_name' => $caller_name, 'caller_telephone1' => $caller_telephone1, 'caller_email' => $caller_email, 'contact_id' => $contact_id, 'contact_name' => $contact_name, 'purchase_invoice_id' => $purchase_invoice_id, 'purch_order_id' => $purch_order_id, 'return_code' => $return_code, 'caller_notes' => $caller_notes, 'received_by' => $received_by, 'receive_carrier' => $receive_carrier, 'receive_tracking' => $receive_tracking, 'receive_notes' => $receive_notes, 'receive_details' => serialize($receive_details), 'close_notes' => $close_notes, 'close_details' => serialize($close_details), 'creation_date' => $creation_date, 'invoice_date' => $invoice_date, 'closed_date' => $closed_date, 'receive_date' => $receive_date, 'attachments' => sizeof($attachments) > 0 ? serialize($attachments) : '');
     if ($id) {
         $success = db_perform(TABLE_RMA, $sql_data_array, 'update', 'id = ' . $id);
         if ($success) {
             gen_add_audit_log(RMA_LOG_USER_UPDATE . $rma_num);
         } else {
             $error = true;
示例#3
0
 function save()
 {
     global $db, $currencies, $fields, $messageStack;
     $sql_data_array = $fields->what_to_save();
     // handle the checkboxes
     $sql_data_array['inactive'] = isset($_POST['inactive']) ? $_POST['inactive'] : '0';
     // else unchecked
     foreach (array('quantity_on_hand', 'quantity_on_order', 'quantity_on_sales_order', 'quantity_on_allocation', 'creation_date', 'last_update', 'last_journal_date') as $key) {
         unset($sql_data_array[$key]);
     }
     $sql_data_array['last_update'] = date('Y-m-d H-i-s');
     if ($_SESSION['admin_security'][SECURITY_ID_PURCHASE_INVENTORY] > 1) {
         $sql_data_array['item_cost'] = $this->store_purchase_array();
         $sql_data_array['vendor_id'] = $this->min_vendor_id;
     } else {
         if (isset($sql_data_array['item_cost'])) {
             unset($sql_data_array['item_cost']);
         }
     }
     $file_path = DIR_FS_MY_FILES . $_SESSION['company'] . '/inventory/images';
     if ($this->remove_image == '1') {
         // update the image with relative path
         if ($this->image_with_path && file_exists($file_path . '/' . $this->image_with_path)) {
             unlink($file_path . '/' . $this->image_with_path);
         }
         $this->image_with_path = '';
         $sql_data_array['image_with_path'] = '';
         unset($this->remove_image);
         // this is not a db field, just an action
     }
     if (is_uploaded_file($_FILES['inventory_image']['tmp_name'])) {
         if ($this->image_with_path && file_exists($file_path . '/' . $this->image_with_path)) {
             unlink($file_path . '/' . $this->image_with_path);
         }
         $this->inventory_path = str_replace('\\', '/', $this->inventory_path);
         // strip beginning and trailing slashes if present
         if (substr($this->inventory_path, 0, 1) == '/') {
             $this->inventory_path = substr($this->inventory_path, 1);
         }
         // remove leading '/' if there
         if (substr($this->inventory_path, -1, 1) == '/') {
             $this->inventory_path = substr($this->inventory_path, 0, -1);
         }
         // remove trailing '/' if there
         if ($this->inventory_path) {
             $file_path .= '/' . $this->inventory_path;
         }
         $temp_file_name = $_FILES['inventory_image']['tmp_name'];
         $file_name = $_FILES['inventory_image']['name'];
         if (!validate_path($file_path)) {
             $messageStack->add(INV_IMAGE_PATH_ERROR, 'error');
             return false;
         } elseif (!validate_upload('inventory_image', 'image', 'jpg')) {
             $messageStack->add(INV_IMAGE_FILE_TYPE_ERROR, 'error');
             return false;
         } else {
             // passed all test, write file
             $result = $db->Execute("select * from " . TABLE_INVENTORY . " where image_with_path = '" . ($this->inventory_path ? $this->inventory_path . '/' : '') . $file_name . "'");
             if ($result->RecordCount() != 0) {
                 $messageStack->add(INV_IMAGE_DUPLICATE_NAME, 'error');
                 return false;
             }
             if (!copy($temp_file_name, $file_path . '/' . $file_name)) {
                 $messageStack->add(INV_IMAGE_FILE_WRITE_ERROR, 'error');
                 return false;
             } else {
                 $this->image_with_path = ($this->inventory_path ? $this->inventory_path . '/' : '') . $file_name;
                 $sql_data_array['image_with_path'] = $this->image_with_path;
                 // update the image with relative path
             }
         }
     }
     if ($this->id != '') {
         $result = $db->Execute("select attachments from " . TABLE_INVENTORY . " where id = {$this->id}");
         $this->attachments = $result->fields['attachments'] ? unserialize($result->fields['attachments']) : array();
         $image_id = 0;
         while ($image_id < 100) {
             // up to 100 images
             if (isset($_POST['rm_attach_' . $image_id])) {
                 @unlink(INVENTORY_DIR_ATTACHMENTS . "inventory_{$this->id}_{$image_id}.zip");
                 unset($this->attachments[$image_id]);
             }
             $image_id++;
         }
         if (is_uploaded_file($_FILES['file_name']['tmp_name'])) {
             // find an image slot to use
             $image_id = 0;
             while (true) {
                 if (!file_exists(INVENTORY_DIR_ATTACHMENTS . 'inventory_' . $this->id . '_' . $image_id . '.zip')) {
                     break;
                 }
                 $image_id++;
             }
             saveUploadZip('file_name', INVENTORY_DIR_ATTACHMENTS, 'inventory_' . $this->id . '_' . $image_id . '.zip');
             $this->attachments[$image_id] = $_FILES['file_name']['name'];
         }
         $sql_data_array['attachments'] = sizeof($this->attachments) > 0 ? serialize($this->attachments) : '';
     }
     unset($sql_data_array['last_journal_date]']);
     if ($this->id != '') {
         if ($this->price_sheet == '') {
             $db->Execute("DELETE FROM " . TABLE_INVENTORY_SPECIAL_PRICES . " WHERE inventory_id = {$this->id} and price_sheet_id IN ( SELECT id FROM " . TABLE_PRICE_SHEETS . " WHERE type = 'c' )");
         }
         unset($sql_data_array['creation_date]']);
         db_perform(TABLE_INVENTORY, $sql_data_array, 'update', "id = " . $this->id);
         gen_add_audit_log(INV_LOG_INVENTORY . TEXT_UPDATE, $this->sku . ' - ' . $sql_data_array['description_short']);
     } else {
         db_perform(TABLE_INVENTORY, $sql_data_array, 'insert');
         $this->id = db_insert_id();
         $result = $db->Execute("select price_sheet_id, price_levels from " . TABLE_INVENTORY_SPECIAL_PRICES . " where inventory_id = " . $this->id);
         while (!$result->EOF) {
             $output_array = array('inventory_id' => $this->id, 'price_sheet_id' => $result->fields['price_sheet_id'], 'price_levels' => $result->fields['price_levels']);
             db_perform(TABLE_INVENTORY_SPECIAL_PRICES, $output_array, 'insert');
             $result->MoveNext();
         }
         gen_add_audit_log(INV_LOG_INVENTORY . TEXT_COPY, " id " . $this->id . ' new sku = ' . $this->sku);
     }
     return $sql_data_array;
 }
示例#4
0
         if (!$glEntry->validate_purchase_invoice_id()) {
             $error = true;
         } else {
             if (!$glEntry->Post($glEntry->id ? 'edit' : 'insert')) {
                 $error = true;
             }
         }
     }
     if (!$error) {
         $db->transCommit();
         if ($glEntry->rm_attach) {
             @unlink(PHREEBOOKS_DIR_MY_ORDERS . 'order_' . $glEntry->id . '.zip');
         }
         if (is_uploaded_file($_FILES['file_name']['tmp_name'])) {
             $messageStack->debug('Saving file to: ' . PHREEBOOKS_DIR_MY_ORDERS . 'order_' . $glEntry->id . '.zip');
             saveUploadZip('file_name', PHREEBOOKS_DIR_MY_ORDERS, 'order_' . $glEntry->id . '.zip');
         }
         if (DEBUG) {
             $messageStack->write_debug();
         }
         gen_add_audit_log(GL_LOG_ADD_JOURNAL . ($glEntry->id ? TEXT_EDIT : TEXT_ADD), $glEntry->purchase_invoice_id);
         gen_redirect(html_href_link(FILENAME_DEFAULT, gen_get_all_get_params(array('action')), 'SSL'));
     }
     // *************** END TRANSACTION *************************
 }
 $db->transRollback();
 $messageStack->add(GL_ERROR_NO_POST, 'error');
 if (DEBUG) {
     $messageStack->write_debug();
 }
 $cInfo = new objectInfo($_POST);
     if (isset($_POST['rm_attach_' . $image_id])) {
         @unlink(ASSETS_DIR_ATTACHMENTS . 'assets_' . $id . '_' . $image_id . '.zip');
         unset($attachments[$image_id]);
     }
     $image_id++;
 }
 if (is_uploaded_file($_FILES['file_name']['tmp_name'])) {
     // find an image slot to use
     $image_id = 0;
     while (true) {
         if (!file_exists(ASSETS_DIR_ATTACHMENTS . 'assets_' . $id . '_' . $image_id . '.zip')) {
             break;
         }
         $image_id++;
     }
     saveUploadZip('file_name', ASSETS_DIR_ATTACHMENTS, 'assets_' . $id . '_' . $image_id . '.zip');
     $attachments[$image_id] = $_FILES['file_name']['name'];
 }
 $sql_data_array['attachments'] = sizeof($attachments) > 0 ? serialize($attachments) : '';
 if ($remove_image) {
     // update the image with relative path
     $_POST['image_with_path'] = '';
     $sql_data_array['image_with_path'] = '';
 }
 if (!$error && is_uploaded_file($_FILES['asset_image']['tmp_name'])) {
     $file_path = DIR_FS_MY_FILES . $_SESSION['company'] . '/assets/images';
     $asset_path = str_replace('\\', '/', $asset_path);
     // strip beginning and trailing slashes if present
     if (substr($asset_path, -1, 1) == '/') {
         $asset_path = substr($asset_path, 0, -1);
     }