Ejemplo n.º 1
0
 static function registerInterview()
 {
     $fields = array('result', 'voter_id', 'survey_id', 'activity_id', 'surveyTitle', 'interviewer_id', 'activity_type_id');
     $params = array();
     foreach ($fields as $fld) {
         $params[$fld] = CRM_Utils_Array::value($fld, $_POST);
     }
     $params['details'] = CRM_Utils_Array::value('note', $_POST);
     $voterId = $params['voter_id'];
     $activityId = $params['activity_id'];
     $customKey = "field_{$voterId}_custom";
     foreach ($_POST as $key => $value) {
         if (strpos($key, $customKey) !== FALSE) {
             $customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key);
             $params[$customFieldKey] = $value;
         }
     }
     if (isset($_POST['field']) && !empty($_POST['field'][$voterId]) && is_array($_POST['field'][$voterId])) {
         foreach ($_POST['field'][$voterId] as $fieldKey => $value) {
             $params[$fieldKey] = $value;
         }
     }
     //lets pickup contat related fields.
     foreach ($_POST as $key => $value) {
         if (strpos($key, "field_{$voterId}_") !== FALSE && strpos($key, "field_{$voterId}_custom") === FALSE) {
             $key = substr($key, strlen("field_{$voterId}_"));
             $params[$key] = $value;
         }
     }
     $result = array('status' => 'fail', 'voter_id' => $voterId, 'activity_id' => $params['interviewer_id']);
     //time to validate custom data.
     $errors = CRM_Core_BAO_CustomField::validateCustomData($params);
     if (is_array($errors) && !empty($errors)) {
         $result['errors'] = $errors;
         echo json_encode($result);
         CRM_Utils_System::civiExit();
     }
     //process the response/interview data.
     $activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params);
     if ($activityId) {
         $result['status'] = 'success';
     }
     echo json_encode($result);
     CRM_Utils_System::civiExit();
 }
Ejemplo n.º 2
0
 static function registerInterview()
 {
     $fields = array('result', 'voter_id', 'ufGroupId', 'activity_id', 'surveyTitle', 'interviewer_id', 'activity_type_id');
     $params = array();
     foreach ($fields as $fld) {
         $params[$fld] = CRM_Utils_Array::value($fld, $_POST);
     }
     $params['details'] = CRM_Utils_Array::value('note', $_POST);
     $voterId = $params['voter_id'];
     $activityId = $params['activity_id'];
     $customKey = "field_{$voterId}_custom";
     foreach ($_POST as $key => $value) {
         if (strpos($key, $customKey) !== false) {
             $customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key);
             $params[$customFieldKey] = $value;
         }
     }
     if (isset($_POST['field']) && CRM_Utils_Array::value($voterId, $_POST['field']) && is_array($_POST['field'][$voterId])) {
         foreach ($_POST['field'][$voterId] as $fieldKey => $value) {
             $params[$fieldKey] = $value;
         }
     }
     require_once "CRM/Utils/JSON.php";
     $result = array('status' => 'fail', 'voter_id' => $voterId, 'activity_id' => $params['interviewer_id']);
     //time to validate custom data.
     require_once 'CRM/Core/BAO/CustomField.php';
     $errors = CRM_Core_BAO_CustomField::validateCustomData($params);
     if (is_array($errors) && !empty($errors)) {
         $result['errors'] = $errors;
         echo json_encode($result);
         CRM_Utils_System::civiExit();
     }
     //process the response/interview data.
     require_once 'CRM/Campaign/Form/Task/Interview.php';
     $activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params);
     if ($activityId) {
         $result['status'] = 'success';
     }
     require_once "CRM/Utils/JSON.php";
     echo json_encode($result);
     CRM_Utils_System::civiExit();
 }