Exemplo n.º 1
0
 /**
  * Removes a company and all associated records from the system.
  *
  * @param integer Company ID
  * @return void
  */
 public function delete($companyID)
 {
     /* Delete the company. */
     $sql = sprintf("DELETE FROM\n                company\n            WHERE\n                company_id = %s\n            AND\n                site_id = %s", $companyID, $this->_siteID);
     $this->_db->query($sql);
     $history = new History($this->_siteID);
     $history->storeHistoryDeleted(DATA_ITEM_COMPANY, $companyID);
     /* Find associated contacts. */
     $sql = sprintf("SELECT\n                contact_id AS contactID\n            FROM\n                contact\n            WHERE\n                company_id = %s\n            AND\n                site_id = %s", $companyID, $this->_siteID);
     $contactsRS = $this->_db->getAllAssoc($sql);
     /* Find associated job orders. */
     $sql = sprintf("SELECT\n                joborder_id AS jobOrderID\n            FROM\n                joborder\n            WHERE\n                company_id = %s\n            AND\n                site_id = %s", $companyID, $this->_siteID);
     $jobOrdersRS = $this->_db->getAllAssoc($sql);
     /* Find associated attachments. */
     $attachments = new Attachments($this->_siteID);
     $attachmentsRS = $attachments->getAll(DATA_ITEM_COMPANY, $companyID);
     /* Delete associated contacts. */
     $contacts = new Contacts($this->_siteID);
     foreach ($contactsRS as $rowIndex => $row) {
         $contacts->delete($row['contactID']);
     }
     /* Delete associated job orders. */
     $jobOrders = new JobOrders($this->_siteID);
     foreach ($jobOrdersRS as $rowIndex => $row) {
         $jobOrders->delete($row['jobOrderID']);
     }
     /* Delete associated attachments. */
     foreach ($attachmentsRS as $rowNumber => $row) {
         $attachments->delete($row['attachmentID']);
     }
     /* Delete from saved lists. */
     $sql = sprintf("DELETE FROM\n                saved_list_entry\n            WHERE\n                data_item_id = %s\n            AND\n                site_id = %s\n            AND\n                data_item_type = %s", $this->_db->makeQueryInteger($companyID), $this->_siteID, DATA_ITEM_COMPANY);
     $this->_db->query($sql);
     /* Delete extra fields. */
     $this->extraFields->deleteValueByDataItemID($companyID);
 }
Exemplo n.º 2
0
 private function onDelete()
 {
     if ($this->_accessLevel < ACCESS_LEVEL_DELETE) {
         CommonErrors::fatal(COMMONERROR_PERMISSION, $this, 'Invalid user level for action.');
     }
     /* Bail out if we don't have a valid job order ID. */
     if (!$this->isRequiredIDValid('jobOrderID', $_GET)) {
         CommonErrors::fatal(COMMONERROR_BADINDEX, $this, 'Invalid job order ID.');
     }
     $jobOrderID = $_GET['jobOrderID'];
     if (!eval(Hooks::get('JO_ON_DELETE_PRE'))) {
         return;
     }
     $joborders = new JobOrders($this->_siteID);
     $joborders->delete($jobOrderID);
     /* Delete the MRU entry if present. */
     $_SESSION['CATS']->getMRU()->removeEntry(DATA_ITEM_JOBORDER, $jobOrderID);
     if (!eval(Hooks::get('JO_ON_DELETE_POST'))) {
         return;
     }
     CATSUtility::transferRelativeURI('m=joborders&a=listByView');
 }