Esempio n. 1
0
 function save()
 {
     $errors = $this->validate();
     if (count($errors)) {
         return $errors;
     }
     //
     // Update
     //
     $fl = " date_start = '" . $this->getDataString('date_start') . "',\n\t\t\t\tdate_end   = '" . $this->getDataString('date_end') . "',\n\t\t\t\ttype       = '" . $this->getDataString('type') . "',\n\t\t\t\tsumbilled  = " . $this->getDataFloat('sumbilled', 0.0);
     if ($this->getDataString('type') == 'stage_change') {
         // [ML] To be honest, we should "assert" most of the
         // following values, but "new_stage" is the most important.
         lcm_assert_value($this->getDataString('new_stage', '__ASSERT__'));
         $desc = array('description' => $this->getDataString('description'), 'result' => $this->getDataString('result'), 'conclusion' => $this->getDataString('conclusion'), 'sentence' => $this->getDataString('sentence'), 'sentence_val' => $this->getDataString('sentence_val'), 'new_stage' => $this->getDataString('new_stage'));
         $fl .= ", description = '" . serialize($desc) . "'";
     } elseif (is_status_change($this->getDataString('type'))) {
         $desc = array('description' => $this->getDataString('description'), 'result' => $this->getDataString('result'), 'conclusion' => $this->getDataString('conclusion'), 'sentence' => $this->getDataString('sentence'), 'sentence_val' => $this->getDataString('sentence_val'));
         $fl .= ", description = '" . serialize($desc) . "'";
     } else {
         $fl .= ", description  = '" . $this->getDataString('description') . "'";
     }
     if ($this->getDataInt('id_followup') > 0) {
         // Edit of existing follow-up
         $id_followup = $this->getDataInt('id_followup');
         if (!allowed($this->getDataInt('id_case'), 'e')) {
             lcm_panic("You don't have permission to modify this case's information. (" . $this->getDataInt('id_case') . ")");
         }
         // TODO: check if hiding this FU is allowed
         if (allowed($this->getDataInt('id_case'), 'a') && !(is_status_change($this->getDataString('type')) || $this->getDataString('type') == 'assignment' || $this->getDataString('type') == 'unassignment')) {
             if ($this->getDataString('delete')) {
                 $fl .= ", hidden = 'Y'";
             } else {
                 $fl .= ", hidden = 'N'";
             }
         } else {
             $fl .= ", hidden = 'N'";
         }
         $q = "UPDATE lcm_followup SET {$fl} WHERE id_followup = {$id_followup}";
         $result = lcm_query($q);
         // Get stage of the follow-up entry
         $q = "SELECT id_stage, case_stage FROM lcm_followup WHERE id_followup = {$id_followup}";
         $result = lcm_query($q);
         if ($row = lcm_fetch_array($result)) {
             $case_stage = lcm_assert_value($row['case_stage']);
         } else {
             lcm_panic("There is no such follow-up (" . $id_followup . ")");
         }
         // Update the related lcm_stage entry
         $q = "UPDATE lcm_stage SET\n\t\t\t\t\tdate_conclusion = '" . $this->getDataString('date_end') . "',\n\t\t\t\t\tkw_result = '" . $this->getDataString('result') . "',\n\t\t\t\t\tkw_conclusion = '" . $this->getDataString('conclusion') . "',\n\t\t\t\t\tkw_sentence = '" . $this->getDataString('sentence') . "',\n\t\t\t\t\tsentence_val = '" . $this->getDataString('sentence_val') . "',\n\t\t\t\t\tdate_agreement = '" . $this->getDataString('date_end') . "'\n\t\t\t\tWHERE id_case = " . $this->getDataInt('id_case') . "\n\t\t\t\t  AND kw_case_stage = '" . $case_stage . "'";
         lcm_query($q);
     } else {
         // New follow-up
         if (!allowed($this->getDataInt('id_case'), 'w')) {
             lcm_panic("You don't have permission to add information to this case. (" . $this->getDataInt('id_case') . ")");
         }
         // Get the current case stage
         $q = "SELECT id_stage, stage FROM lcm_case WHERE id_case=" . $this->getDataInt('id_case', '__ASSERT__');
         $result = lcm_query($q);
         if ($row = lcm_fetch_array($result)) {
             $case_stage = lcm_assert_value($row['stage']);
             $case_stage_id = lcm_assert_value($row['id_stage']);
         } else {
             lcm_panic("There is no such case (" . $this->getDataInt('id_case') . ")");
         }
         // Add the new follow-up
         $q = "INSERT INTO lcm_followup\n\t\t\t\t\tSET id_case=" . $this->getDataInt('id_case') . ",\n\t\t\t\t\t\tid_author=" . $GLOBALS['author_session']['id_author'] . ",\n\t\t\t\t\t\t{$fl},\n\t\t\t\t\t\tid_stage = {$case_stage_id},\n\t\t\t\t\t\tcase_stage='{$case_stage}'";
         lcm_query($q);
         $this->data['id_followup'] = lcm_insert_id('lcm_followup', 'id_followup');
         // Set relation to the parent appointment, if any
         if ($this->getDataInt('id_app')) {
             $q = "INSERT INTO lcm_app_fu \n\t\t\t\t\t\tSET id_app=" . $this->getDataInt('id_app') . ",\n\t\t\t\t\t\t\tid_followup=" . $this->getDataInt('id_followup', '__ASSERT__') . ",\n\t\t\t\t\t\t\trelation='child'";
             $result = lcm_query($q);
         }
         // Update case status
         $status = '';
         $stage = '';
         switch ($this->getDataString('type')) {
             case 'conclusion':
                 $status = 'closed';
                 break;
             case 'suspension':
                 $status = 'suspended';
                 break;
             case 'opening':
             case 'resumption':
             case 'reopening':
                 $status = 'open';
                 break;
             case 'merge':
                 $status = 'merged';
                 break;
             case 'deletion':
                 $status = 'deleted';
                 break;
             case 'stage_change':
                 $stage = lcm_assert_value($this->getDataString('new_stage'));
                 break;
         }
         if ($status || $stage) {
             $q = "UPDATE lcm_case\n\t\t\t\t\t\tSET " . ($status ? "status='{$status}'" : '') . ($status && $stage ? ',' : '') . ($stage ? "stage='{$stage}'" : '') . "\n\t\t\t\t\t\tWHERE id_case=" . $this->getDataInt('id_case');
             lcm_query($q);
             // Close the lcm_stage
             // XXX for now, date_agreement is not used
             if ($status == 'open') {
                 // case is being re-opened, so erase previously entered info
                 $q = "UPDATE lcm_stage\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tdate_conclusion = '0000-00-00 00:00:00',\n\t\t\t\t\t\t\t\tid_fu_conclusion = 0,\n\t\t\t\t\t\t\t\tkw_result = '',\n\t\t\t\t\t\t\t\tkw_conclusion = '',\n\t\t\t\t\t\t\t\tkw_sentence = '',\n\t\t\t\t\t\t\t\tsentence_val = '',\n\t\t\t\t\t\t\t\tdate_agreement = '0000-00-00 00:00:0'\n\t\t\t\t\t\t\tWHERE id_case = " . $this->getDataInt('id_case') . "\n\t\t\t\t\t\t\t  AND kw_case_stage = '" . $case_stage . "'";
             } else {
                 $q = "UPDATE lcm_stage\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\tdate_conclusion = '" . $this->getDataString('date_end') . "',\n\t\t\t\t\t\t\t\tid_fu_conclusion = " . $this->getDataInt('id_followup') . ",\n\t\t\t\t\t\t\t\tkw_result = '" . $this->getDataString('result') . "',\n\t\t\t\t\t\t\t\tkw_conclusion = '" . $this->getDataString('conclusion') . "',\n\t\t\t\t\t\t\t\tkw_sentence = '" . $this->getDataString('sentence') . "',\n\t\t\t\t\t\t\t\tsentence_val = '" . $this->getDataString('sentence_val') . "',\n\t\t\t\t\t\t\t\tdate_agreement = '" . $this->getDataString('date_end') . "'\n\t\t\t\t\t\t\tWHERE id_case = " . $this->getDataInt('id_case', '__ASSERT__') . "\n\t\t\t\t\t\t\t  AND kw_case_stage = '" . $case_stage . "'";
             }
             lcm_query($q);
         }
         // If creating a new case stage, make new lcm_stage entry
         if ($stage) {
             $q = "INSERT INTO lcm_stage SET\n\t\t\t\t\t\t\tid_case = " . $this->getDataInt('id_case', '__ASSERT__') . ",\n\t\t\t\t\t\t\tkw_case_stage = '" . lcm_assert_value($stage) . "',\n\t\t\t\t\t\t\tdate_creation = NOW(),\n\t\t\t\t\t\t\tid_fu_creation = " . $this->getDataInt('id_followup');
             lcm_query($q);
         }
     }
     // Keywords
     update_keywords_request('followup', $this->getDataInt('id_followup'));
     return $errors;
 }
Esempio n. 2
0
 function save()
 {
     $errors = $this->validate();
     if (count($errors)) {
         return $errors;
     }
     //
     // Update record in database
     //
     $cl = "name_first = '" . clean_input($this->getDataString('name_first')) . "',\n\t\t\t   name_middle = '" . clean_input($this->getDataString('name_middle')) . "',\n\t\t\t   name_last = '" . clean_input($this->getDataString('name_last')) . "',\n\t\t\t   gender = '" . clean_input($this->getDataString('gender')) . "',\n\t\t\t   notes = '" . clean_input($this->getDataString('notes')) . "'";
     // ,
     if ($this->getDataString('date_birth')) {
         $cl .= ", date_birth = '" . $this->getDataString('date_birth') . "'";
     }
     $cl .= ", citizen_number = '" . clean_input($this->getDataString('citizen_number')) . "'";
     $cl .= ", civil_status = '" . clean_input($this->getDataString('civil_status')) . "'";
     $cl .= ", income = '" . clean_input($this->getDataString('income')) . "'";
     if ($this->getDataInt('id_client') > 0) {
         $q = "UPDATE lcm_client\n\t\t\t\tSET date_update = NOW(), \n\t\t\t\t\t{$cl} \n\t\t\t\tWHERE id_client = " . $this->getDataInt('id_client', '__ASSERT__');
         lcm_query($q);
     } else {
         $q = "INSERT INTO lcm_client\n\t\t\t\t\tSET date_creation = NOW(),\n\t\t\t\t\t\tdate_update = NOW(),\n\t\t\t\t\t\t{$cl}";
         $result = lcm_query($q);
         $this->data['id_client'] = lcm_insert_id('lcm_client', 'id_client');
     }
     // Keywords
     update_keywords_request('client', $this->getDataInt('id_client'));
     if ($_SESSION['errors']) {
         $errors = array_merge($_SESSION['errors'], $errors);
     }
     // Insert/update client contacts
     include_lcm('inc_contacts');
     update_contacts_request('client', $this->getDataInt('id_client'));
     if ($_SESSION['errors']) {
         $errors = array_merge($_SESSION['errors'], $errors);
     }
     return $errors;
 }
Esempio n. 3
0
 function save()
 {
     $errors = $this->validate();
     if (count($errors)) {
         return $errors;
     }
     //
     // Update record in database
     //
     // Record data in database
     $ol = "name='" . clean_input($this->getDataString('name')) . "', " . "court_reg='" . clean_input($this->getDataString('court_reg')) . "', " . "tax_number='" . clean_input($this->getDataString('tax_number')) . "', " . "stat_number='" . clean_input($this->getDataString('stat_number')) . "', " . "notes='" . clean_input($this->getDataString('notes')) . "'";
     if ($this->getDataInt('id_org') > 0) {
         $q = "UPDATE lcm_org SET date_update=NOW(),{$ol} WHERE id_org = " . $this->getDataInt('id_org');
         $result = lcm_query($q);
     } else {
         $q = "INSERT INTO lcm_org SET date_update = NOW(), date_creation = NOW(), {$ol}";
         $result = lcm_query($q);
         $this->setDataInt('id_org', lcm_insert_id('lcm_org', 'id_org'));
         // Just by precaution
         $_SESSION['form_data']['id_org'] = $this->getDataInt('id_org');
         // If there is an error (ex: in contacts), we should send back to 'org_det.php?org=XX'
         // not to 'org_det.php?org=0'.
         $ref_upd_org = 'edit_org.php?org=' . $this->getDataInt('id_org');
     }
     // Keywords
     update_keywords_request('org', $this->getDataInt('id_org'));
     if ($_SESSION['errors']) {
         $errors = array_merge($_SESSION['errors'], $errors);
     }
     // Insert/update client contacts
     include_lcm('inc_contacts');
     update_contacts_request('org', $this->getDataInt('id_org'));
     if ($_SESSION['errors']) {
         $errors = array_merge($_SESSION['errors'], $errors);
     }
     return $errors;
 }
Esempio n. 4
0
    $_SESSION['errors'] = array_merge($_SESSION['errors'], $errs);
}
if (count($_SESSION['errors'])) {
    lcm_header("Location: " . $_SERVER['HTTP_REFERER']);
    exit;
}
if (!$id_followup) {
    $id_followup = $fu->getDataInt('id_followup', '__ASSERT__');
}
//
// Update stage keywords
//
if (isset($_REQUEST['new_stage']) && $_REQUEST['new_stage']) {
    $stage_info = get_kw_from_name('stage', $_REQUEST['new_stage']);
    $id_stage = $stage_info['id_keyword'];
    update_keywords_request('stage', $_SESSION['form_data']['id_case'], $id_stage);
}
//
// Update lcm_case.date_update (if fu.date_start > c.date_update)
//
$q = "SELECT date_update FROM lcm_case WHERE id_case = " . $fu->getDataInt('id_case', '__ASSERT__');
$result = lcm_query($q);
if ($row = lcm_fetch_array($result)) {
    if ($fu->getDataString('date_start', '__ASSERT__') > $row['date_update']) {
        $q = "UPDATE lcm_case\n\t\t\t\tSET date_update = '" . $fu->getDatastring('date_start') . "'\n\t\t\t\tWHERE id_case = " . $fu->getDataInt('id_case', '__ASSERT__');
        lcm_query($q);
    }
} else {
    lcm_panic("Query returned no results.");
}
///////////////////////////////////////////////////////////////////////
Esempio n. 5
0
 function save()
 {
     global $author_session;
     $errors = $this->validate();
     if (count($errors)) {
         return $errors;
     }
     //
     // Create the case in the database
     //
     /* [ML] Note: the 'case_notes' field is refered to as only 'notes'
      * since the constructor of the class strips 'case_' prefixes
      */
     $fl = "title='" . $this->getDataString('title') . "',\n\t\t\t\tdate_assignment = '" . $this->getDataString('date_assignment') . "',\n\t\t\t\tlegal_reason='" . $this->getDataString('legal_reason') . "',\n\t\t\t\talledged_crime='" . $this->getDataString('alledged_crime') . "',\n\t\t\t\tnotes = '" . $this->getDataString('notes') . "',\n\t\t\t    status='" . $this->getDataString('status') . "',\n\t\t\t    stage='" . $this->getDataString('stage') . "'";
     // Put public access rights settings in a separate string
     $public_access_rights = '';
     /* 
      * [ML] Important note: the meta 'case_*_always' defines whether the user
      * has the choice of whether read/write should be allowed or not. If not,
      * we take the system default value in 'case_default_*'.
      */
     if (read_meta('case_read_always') == 'yes' && $author_session['status'] != 'admin') {
         // impose system setting
         $public_access_rights .= "public=" . (int) (read_meta('case_default_read') == 'yes');
     } else {
         // write user selection
         $public_access_rights .= "public=" . (int) ($this->getDataString('public') == 'yes');
     }
     if (read_meta('case_write_always') == 'yes' && $author_session['status'] != 'admin') {
         // impose system setting
         $public_access_rights .= ", pub_write=" . (int) (read_meta('case_default_write') == 'yes');
     } else {
         // write user selection
         $public_access_rights .= ", pub_write=" . (int) ($this->getDataString('pub_write') == 'yes');
     }
     if ($this->getDataInt('id_case') > 0) {
         // This is modification of existing case
         $id_case = $this->getDataInt('id_case');
         // Check access rights
         if (!allowed($id_case, 'e')) {
             lcm_panic("You don't have permission to change this case's information!");
         }
         // If admin access is allowed, set all fields
         if (allowed($id_case, 'a')) {
             $q = "UPDATE lcm_case SET {$fl},{$public_access_rights} WHERE id_case={$id_case}";
         } else {
             $q = "UPDATE lcm_case SET {$fl} WHERE id_case={$id_case}";
         }
         lcm_query($q);
         // Update lcm_stage entry for case creation (of first stage!)
         // [ML] This doesn't make so much sense, but better than nothing imho..
         $q = "SELECT min(id_entry) as id_entry FROM lcm_stage WHERE id_case = {$id_case}";
         $tmp_result = lcm_query($q);
         if ($tmp_row = lcm_fetch_array($tmp_result)) {
             $q = "UPDATE lcm_stage\n\t\t\t\t\tSET date_creation = '" . $this->getDataString('date_assignment') . "'\n\t\t\t\t\tWHERE id_entry = " . $tmp_row['id_entry'];
             lcm_query($q);
         }
     } else {
         // This is new case
         $q = "INSERT INTO lcm_case SET id_stage = 0, date_creation = NOW(), date_update = NOW(), {$fl},{$public_access_rights}";
         $result = lcm_query($q);
         $id_case = lcm_insert_id('lcm_case', 'id_case');
         $id_author = $author_session['id_author'];
         $this->data['id_case'] = $id_case;
         // Insert new case_author relation
         // [AG] The user creating case should always have 'admin' access right, otherwise only admin could add new user(s) to the case
         $q = "INSERT INTO lcm_case_author SET\n\t\t\t\tid_case = {$id_case},\n\t\t\t\tid_author = {$id_author},\n\t\t\t\tac_read=1,\n\t\t\t\tac_write=1,\n\t\t\t\tac_edit=" . (int) (read_meta('case_allow_modif') == 'yes') . ",\n\t\t\t\tac_admin=1";
         $result = lcm_query($q);
         // Get author information
         $q = "SELECT *\n\t\t\t\tFROM lcm_author\n\t\t\t\tWHERE id_author={$id_author}";
         $result = lcm_query($q);
         $author_data = lcm_fetch_array($result);
         // Add 'assignment' followup to the case
         $q = "INSERT INTO lcm_followup\n\t\t\t\tSET id_case = {$id_case}, \n\t\t\t\t\tid_stage = 0,\n\t\t\t\t\tid_author = {$id_author},\n\t\t\t\t\ttype = 'assignment',\n\t\t\t\t\tcase_stage = '" . $this->getDataString('stage') . "',\n\t\t\t\t\tdate_start = NOW(),\n\t\t\t\t\tdate_end = NOW(),\n\t\t\t\t\tsumbilled = 0,\n\t\t\t\t\tdescription='" . $id_author . "'";
         lcm_query($q);
         $id_followup = lcm_insert_id('lcm_followup', 'id_followup');
         // Add lcm_stage entry
         $q = "INSERT INTO lcm_stage SET\n\t\t\t\tid_case = {$id_case},\n\t\t\t\t\t\tkw_case_stage = '" . $this->getDataString('stage') . "',\n\t\t\t\t\t\tdate_creation = '" . $this->getDataString('date_assignment') . "',\n\t\t\t\t\t\tid_fu_creation = {$id_followup}";
         lcm_query($q);
         $id_stage = lcm_insert_id('lcm_stage', 'id_entry');
         // Update the id_stage entry for lcm_case
         lcm_query("UPDATE lcm_case SET id_stage = {$id_stage} WHERE id_case = {$id_case}");
         lcm_query("UPDATE lcm_followup SET id_stage = {$id_stage} WHERE id_followup = {$id_followup}");
     }
     // Keywords
     update_keywords_request('case', $this->getDataInt('id_case'));
     $stage = get_kw_from_name('stage', $this->getDataString('stage'));
     $id_stage = $stage['id_keyword'];
     update_keywords_request('stage', $id_case, $id_stage);
     return $errors;
 }