Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
18 | /** | |
5a409b50 | 19 | * Auxiliary class to provide support for locking (and ignoring locks on) contact records. |
6a488035 TO |
20 | */ |
21 | class CRM_Contact_Form_Edit_Lock { | |
22 | ||
23 | /** | |
fe482240 | 24 | * Build the form object. |
6a488035 | 25 | * |
77c5b619 TO |
26 | * @param CRM_Core_Form $form |
27 | * Form object. | |
6a488035 TO |
28 | */ |
29 | public static function buildQuickForm(&$form) { | |
be2fb01f | 30 | $form->addField('modified_date', ['type' => 'hidden', 'id' => 'modified_date', 'label' => '']); |
6a488035 TO |
31 | } |
32 | ||
33 | /** | |
5a409b50 | 34 | * Ensure that modified_date has not changed in the underlying DB. |
6a488035 | 35 | * |
77c5b619 TO |
36 | * @param array $fields |
37 | * The input form values. | |
38 | * @param array $files | |
39 | * The uploaded files if any. | |
100fef9d | 40 | * @param int $contactID |
6c8f6e67 | 41 | * |
72b3a70c CW |
42 | * @return bool|array |
43 | * true if no errors, else array of errors | |
6a488035 | 44 | */ |
00be9182 | 45 | public static function formRule($fields, $files, $contactID = NULL) { |
be2fb01f | 46 | $errors = []; |
6a488035 TO |
47 | |
48 | $timestamps = CRM_Contact_BAO_Contact::getTimestamps($contactID); | |
49 | if ($fields['modified_date'] != $timestamps['modified_date']) { | |
50 | // Inline buttons generated via JS | |
51 | $open = sprintf("<span id='update_modified_date' data:latest_modified_date='%s'>", $timestamps['modified_date']); | |
52 | $close = "</span>"; | |
53 | $errors['modified_date'] = $open . ts('This record was modified by another user!') . $close; | |
54 | } | |
55 | ||
56 | return empty($errors) ? TRUE : $errors; | |
57 | } | |
96025800 | 58 | |
6a488035 | 59 | } |