Пример #1
0
 public function post_save_client_request()
 {
     // -- Get Post Data
     // ----------------
     $clientID = \Input::post('client_id');
     $companyID = \Input::post('company_id');
     $field = str_replace("-", "_", \Input::post('field'));
     $newValue = \Input::post('new_value');
     $requestID = \Input::post('request_id');
     $address = array();
     $newAddress = array();
     $address = \Input::post('address');
     $message = '';
     // -- This list is check against the posted field. For security
     // ------------------------------------------------------------
     $fieldsList = array('Title', 'Forename', 'Surname', 'Address', 'StreetAndNumber', 'Area', 'District', 'Town', 'County', 'Postcode', 'Tel_Home', 'Tel_Work', 'Tel_Mobile', 'Email', 'Date_Of_Birth');
     // -- Check for a valid field
     // --------------------------
     if (in_array($field, $fieldsList)) {
         if ($field == 'Date_Of_Birth') {
             $field = 'DateOfBirth';
             $newValue = date("Y-m-d 00:00:00", strtotime($newValue));
         }
         if ($field == 'Address') {
             if (count($address) > 0) {
                 foreach ($address as $name => $value) {
                     if (in_array($name, $fieldsList)) {
                         $newAddress[$name] = $value;
                     }
                 }
             }
         }
         // -- Title is in the allowed array list
         // -------------------------------------
         $data = array('newValue' => $newValue, 'field' => $field, 'newAddress' => $newAddress);
         // -- Setup the Database
         //----------------------
         Model_ClientArea::forge((int) $companyID, (int) $clientID);
         // -- Save request into Debtsolv
         // -----------------------------
         if (Model_ClientArea::saveNewDetailsRequest($data)) {
             // -- Debtsolv has been updated. Now mark the request as approved in the Intranet
             // ------------------------------------------------------------------------------
             Model_ClientArea::setDetailRequestApproved($requestID);
             $status = 'success';
         } else {
             $status = 'failed';
         }
     } else {
         $status = 'failed';
         $message = 'Field not in list';
     }
     $this->response(array('status' => $status, 'message' => $message, 'data' => ''));
 }