public function isConditionValid(CRM_Civirules_EventData_EventData $eventData)
 {
     $contactId = $eventData->getContactId();
     $entityData = $eventData->getEntityData('ContributionSoft');
     $contacts = array();
     $query = $this->conditionParams['smart_group_query'];
     if (!empty($query)) {
         $subQueries = explode(';', $query);
         // To run only first and select statement in query string
         if (!empty($subQueries) && !preg_match('/^(insert|update|delete|create|drop|replace)/i', $subQueries[0])) {
             CRM_Core_Error::debug_var('CiviRules::Custom Query Contact Condition Query', $subQueries[0]);
             CRM_Core_Error::debug_var('CiviRules::Custom Query Contact Condition Param Contribution', $entityData['contribution_id']);
             $dao = CRM_Core_DAO::executeQuery('SELECT ' . $subQueries[0], array(1 => array($entityData['contribution_id'], 'Int')));
             while ($dao->fetch()) {
                 $contacts[] = $dao->contact_id;
             }
         }
     }
     CRM_Core_Error::debug_var('CiviRules::Custom Query Contact Condition Contacts', $contacts);
     if (!empty($contacts)) {
         $eventData->setConditionOutputData('ContributionSoft', $contacts);
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * This function is called prior to building and submitting the form
  */
 function preProcess()
 {
     // check contact_id
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if (empty($this->_contactId)) {
         CRM_Core_Error::statusBounce(ts('Could not get a contact id.'), NULL, ts('Lidmaatschap Wijziging - Contact'));
         // this also redirects to the default civicrm page
     }
     // check for permissions
     $session = CRM_Core_Session::singleton();
     if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
         CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'), NULL, ts('Lidmaatschap Wijziging - Contact'));
         // this also redirects to the default civicrm page
     }
     // get request
     $this->_request = CRM_Utils_Request::retrieve('request', 'String', $this, FALSE, 'choose');
     // get session
     $session = CRM_Core_Session::singleton();
     // get values
     $this->_configRelationship = CRM_Lidmaatschapwijziging_ConfigRelationship::singleton($this->_contactId);
     $this->_values = $this->_configRelationship->getContact();
     // set contact id
     $this->_values['contact_id'] = $this->_contactId;
     // set display name
     $this->_display_name = $this->_values['display_name'];
     // set request
     $this->_values['request'] = $this->_request;
     // set title
     CRM_Utils_System::setTitle('LidmaatschapWijziging - Relatie - ' . $this->_values['display_name']);
     // request
     if ('empty' == $this->_request) {
     }
     if ('choose' == $this->_request) {
         // if there is no relatiosnhips then the options are empty, we
         // show a message that there are no memebrships and a submit butten to
         // go to the relationship, first we redirect them to request empty
         $relationships = $this->_configRelationship->getRelationships();
         if (empty($relationships)) {
             // redirect user
             $url = CRM_Utils_System::url('civicrm/lidmaatschapwijziging/relationship', 'reset=1&request=empty&cid=' . $this->_contactId);
             CRM_Utils_System::redirect($url);
         }
     }
     if ('update' == $this->_request) {
         // get relationship id
         $this->_relationshipId = CRM_Utils_Request::retrieve('relationship_id', 'Positive', $this);
         $this->_values['relationship_id'] = $this->_relationshipId;
         // get relationship
         $this->_values = array_merge($this->_values, $this->_configRelationship->getRelationship($this->_relationshipId));
         if (!empty($this->_values['contact_a']['display_name'])) {
             $this->assign('sort_name_a', $this->_values['contact_a']['display_name']);
         }
         if (!empty($this->_values['contact_b']['display_name'])) {
             $this->assign('sort_name_b', $this->_values['contact_b']['display_name']);
         }
         // note
         $this->_values['note_id'] = $this->_values['notes']['id'];
         $this->_values['note'] = $this->_values['notes']['note'];
     }
 }
Example #3
0
/**
 */
function smarty_function_crmAPI($params, &$smarty)
{
    if (!array_key_exists('action', $params)) {
        $params['action'] = "get";
    }
    if (!array_key_exists('sequential', $params)) {
        $params['sequential'] = 1;
    }
    if (!array_key_exists('entity', $params)) {
        $smarty->trigger_error("assign: missing 'entity' parameter");
        return "crmAPI: missing 'entity' parameter";
    }
    CRM_Core_Error::setCallback(array('CRM_Utils_REST', 'fatal'));
    $action = $params['action'];
    $entity = $params['entity'];
    unset($params['entity']);
    unset($params['method']);
    unset($params['assign']);
    $params['version'] = 3;
    require_once 'api/api.php';
    $result = civicrm_api($entity, $action, $params);
    CRM_Core_Error::setCallback();
    if ($result === FALSE) {
        $smarty->trigger_error("Unkown error");
        return;
    }
    if (!array_key_exists('var', $params)) {
        return json_encode($result);
    }
    if (!empty($params['json'])) {
        $smarty->assign($params["var"], json_encode($result));
    } else {
        $smarty->assign($params["var"], $result);
    }
}
Example #4
0
 /**
  * Check if our logfile is directly accessible.
  *
  * Per CiviCRM default the logfile sits in a folder which is
  * web-accessible, and is protected by a default .htaccess
  * configuration. If server config causes the .htaccess not to
  * function as intended, there may be information disclosure.
  *
  * The debug log may be jam-packed with sensitive data, we don't
  * want that.
  *
  * Being able to be retrieved directly doesn't mean the logfile
  * is browseable or visible to search engines; it means it can be
  * requested directly.
  *
  * @return array
  *   Array of messages
  * @see CRM-14091
  */
 public function checkLogFileIsNotAccessible()
 {
     $messages = array();
     $config = CRM_Core_Config::singleton();
     $log = CRM_Core_Error::createDebugLogger();
     $log_filename = str_replace('\\', '/', $log->_filename);
     $filePathMarker = $this->getFilePathMarker();
     // Hazard a guess at the URL of the logfile, based on common
     // CiviCRM layouts.
     if ($upload_url = explode($filePathMarker, $config->imageUploadURL)) {
         $url[] = $upload_url[0];
         if ($log_path = explode($filePathMarker, $log_filename)) {
             // CRM-17149: check if debug log path includes $filePathMarker
             if (count($log_path) > 1) {
                 $url[] = $log_path[1];
                 $log_url = implode($filePathMarker, $url);
                 $headers = @get_headers($log_url);
                 if (stripos($headers[0], '200')) {
                     $docs_url = $this->createDocUrl('checkLogFileIsNotAccessible');
                     $msg = 'The <a href="%1">CiviCRM debug log</a> should not be downloadable.' . '<br />' . '<a href="%2">Read more about this warning</a>';
                     $messages[] = new CRM_Utils_Check_Message(__FUNCTION__, ts($msg, array(1 => $log_url, 2 => $docs_url)), ts('Security Warning'), \Psr\Log\LogLevel::WARNING, 'fa-lock');
                 }
             }
         }
     }
     return $messages;
 }
 /**
  * For pre-processing
  *
  * @return void
  */
 public function preProcess()
 {
     parent::preProcess();
     $this->_key = CRM_Utils_Request::retrieve('key', 'String', $this, FALSE, 0);
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
     $session->pushUserContext($url);
     $this->assign('id', $this->_id);
     $this->assign('key', $this->_key);
     switch ($this->_action) {
         case CRM_Core_Action::ADD:
         case CRM_Core_Action::DELETE:
         case CRM_Core_Action::ENABLE:
         case CRM_Core_Action::DISABLE:
             $info = CRM_Extension_System::singleton()->getMapper()->keyToInfo($this->_key);
             $extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
             $this->assign('extension', $extInfo);
             break;
         case CRM_Core_Action::UPDATE:
             if (!CRM_Extension_System::singleton()->getBrowser()->isEnabled()) {
                 CRM_Core_Error::fatal(ts('The system administrator has disabled this feature.'));
             }
             $info = CRM_Extension_System::singleton()->getBrowser()->getExtension($this->_key);
             $extInfo = CRM_Admin_Page_Extensions::createExtendedInfo($info);
             $this->assign('extension', $extInfo);
             break;
         default:
             CRM_Core_Error::fatal(ts('Unsupported action'));
     }
 }
 function __construct()
 {
     $this->initialize();
     CRM_Utils_System::authenticateScript(TRUE);
     //log the execution of script
     CRM_Core_Error::debug_log_message('CiviReportMail.php');
 }
 public function preProcess()
 {
     $this->_type = 'unsubscribe';
     $this->_job_id = $job_id = CRM_Utils_Request::retrieve('jid', 'Integer', $this);
     $this->_queue_id = $queue_id = CRM_Utils_Request::retrieve('qid', 'Integer', $this);
     $this->_hash = $hash = CRM_Utils_Request::retrieve('h', 'String', $this);
     if (!$job_id || !$queue_id || !$hash) {
         CRM_Core_Error::fatal(ts("Missing Parameters"));
     }
     // verify that the three numbers above match
     $q = CRM_Mailing_Event_BAO_Queue::verify($job_id, $queue_id, $hash);
     if (!$q) {
         CRM_Core_Error::fatal(ts("There was an error in your request"));
     }
     list($displayName, $email) = CRM_Mailing_Event_BAO_Queue::getContactInfo($queue_id);
     $this->assign('display_name', $displayName);
     $emailMasked = CRM_Utils_String::maskEmail($email);
     $this->assign('email_masked', $emailMasked);
     $this->assign('email', $email);
     $this->_email = $email;
     $groups = CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_mailing($job_id, $queue_id, $hash, TRUE);
     $this->assign('groups', $groups);
     $groupExist = NULL;
     foreach ($groups as $key => $value) {
         if ($value) {
             $groupExist = TRUE;
         }
     }
     if (!$groupExist) {
         $statusMsg = ts('Email: %1 has been successfully unsubscribed from this Mailing List/Group.', array(1 => $email));
         CRM_Core_Session::setStatus($statusMsg, '', 'fail');
     }
     $this->assign('groupExist', $groupExist);
 }
 static function preProcess(&$form)
 {
     if (!$form->get('page_id')) {
         CRM_Core_Error::fatal(ts("Can't determine pcp id."));
     }
     $form->assign('component_page_id', $form->get('component_page_id'));
 }
Example #9
0
 /**
  * Perform an upgrade without using the web-frontend
  *
  * @param bool $enablePrint
  *
  * @throws Exception
  * @return array, with keys:
  *   - message: string, HTML-ish blob
  */
 public function run($enablePrint = TRUE)
 {
     // lets get around the time limit issue if possible for upgrades
     if (!ini_get('safe_mode')) {
         set_time_limit(0);
     }
     $upgrade = new CRM_Upgrade_Form();
     list($currentVer, $latestVer) = $upgrade->getUpgradeVersions();
     if ($error = $upgrade->checkUpgradeableVersion($currentVer, $latestVer)) {
         throw new Exception($error);
     }
     // Disable our SQL triggers
     CRM_Core_DAO::dropTriggers();
     // CRM-11156
     $preUpgradeMessage = NULL;
     $upgrade->setPreUpgradeMessage($preUpgradeMessage, $currentVer, $latestVer);
     $postUpgradeMessageFile = CRM_Utils_File::tempnam('civicrm-post-upgrade');
     $queueRunner = new CRM_Queue_Runner(array('title' => ts('CiviCRM Upgrade Tasks'), 'queue' => CRM_Upgrade_Form::buildQueue($currentVer, $latestVer, $postUpgradeMessageFile)));
     $queueResult = $queueRunner->runAll();
     if ($queueResult !== TRUE) {
         $errorMessage = CRM_Core_Error::formatTextException($queueResult['exception']);
         CRM_Core_Error::debug_log_message($errorMessage);
         if ($enablePrint) {
             print $errorMessage;
         }
         throw $queueResult['exception'];
         // FIXME test
     }
     CRM_Upgrade_Form::doFinish();
     $message = file_get_contents($postUpgradeMessageFile);
     return array('latestVer' => $latestVer, 'message' => $message, 'text' => CRM_Utils_String::htmlToText($message));
 }
 /**
  * @param $formValues
  *
  * @throws Exception
  */
 public function __construct(&$formValues)
 {
     parent::__construct($formValues);
     // unset search profile and other search params if set
     unset($this->_formValues['uf_group_id']);
     unset($this->_formValues['component_mode']);
     unset($this->_formValues['operator']);
     if (!empty($this->_formValues)) {
         // add the country and state
         if (!empty($this->_formValues['country_id'])) {
             $this->_formValues['country'] = CRM_Core_PseudoConstant::country($this->_formValues['country_id']);
         }
         if (!empty($this->_formValues['state_province_id'])) {
             $this->_formValues['state_province'] = CRM_Core_PseudoConstant::stateProvince($this->_formValues['state_province_id']);
         }
         // use the address to get the latitude and longitude
         CRM_Utils_Geocode_Google::format($this->_formValues);
         if (!is_numeric(CRM_Utils_Array::value('geo_code_1', $this->_formValues)) || !is_numeric(CRM_Utils_Array::value('geo_code_2', $this->_formValues)) || !isset($this->_formValues['distance'])) {
             CRM_Core_Error::fatal(ts('Could not geocode input'));
         }
         $this->_latitude = $this->_formValues['geo_code_1'];
         $this->_longitude = $this->_formValues['geo_code_2'];
         if ($this->_formValues['prox_distance_unit'] == "miles") {
             $conversionFactor = 1609.344;
         } else {
             $conversionFactor = 1000;
         }
         $this->_distance = $this->_formValues['distance'] * $conversionFactor;
     }
     $this->_group = CRM_Utils_Array::value('group', $this->_formValues);
     $this->_tag = CRM_Utils_Array::value('tag', $this->_formValues);
     $this->_columns = array(ts('Name') => 'sort_name', ts('Street Address') => 'street_address', ts('City') => 'city', ts('Postal Code') => 'postal_code', ts('State') => 'state_province', ts('Country') => 'country');
 }
 /**
  * Download the remote zipfile.
  *
  * @param string $remoteFile URL of a .zip file
  * @param string $localFile path at which to store the .zip file
  * @return STATUS_OK|STATUS_WRITE_ERROR|STATUS_DL_ERROR
  */
 public function fetch($remoteFile, $localFile)
 {
     // Download extension zip file ...
     if (!function_exists('curl_init')) {
         CRM_Core_Error::fatal('Cannot install this extension - curl is not installed!');
     }
     list($ch, $caConfig) = $this->createCurl($remoteFile);
     if (preg_match('/^https:/', $remoteFile) && !$caConfig->isEnableSSL()) {
         CRM_Core_Error::fatal('Cannot install this extension - does not support SSL');
     }
     $fp = @fopen($localFile, "w");
     if (!$fp) {
         CRM_Core_Session::setStatus(ts('Unable to write to %1.<br />Is the location writable?', array(1 => $localFile)), ts('Write Error'), 'error');
         return self::STATUS_WRITE_ERROR;
     }
     curl_setopt($ch, CURLOPT_FILE, $fp);
     curl_exec($ch);
     if (curl_errno($ch)) {
         CRM_Core_Session::setStatus(ts('Unable to download extension from %1. Error Message: %2', array(1 => $remoteFile, 2 => curl_error($ch))), ts('Download Error'), 'error');
         return self::STATUS_DL_ERROR;
     } else {
         curl_close($ch);
     }
     fclose($fp);
     return self::STATUS_OK;
 }
Example #12
0
 /**
  * @param object $controller
  * @param const|int $action
  */
 public function __construct($controller, $action = CRM_Core_Action::NONE)
 {
     parent::__construct($controller, $action);
     $cart = CRM_Event_Cart_BAO_Cart::find_or_create_for_current_session();
     $cart->load_associations();
     if ($cart->is_empty()) {
         CRM_Core_Error::statusBounce(ts("You don't have any events in you cart. Please add some events."), CRM_Utils_System::url('civicrm/event'));
     }
     $pages = array();
     $is_monetary = FALSE;
     $is_conference = FALSE;
     foreach ($cart->events_in_carts as $event_in_cart) {
         if ($event_in_cart->event->is_monetary) {
             $is_monetary = TRUE;
         }
     }
     $pages["CRM_Event_Cart_Form_Checkout_ParticipantsAndPrices"] = NULL;
     foreach ($cart->events_in_carts as $event_in_cart) {
         if ($event_in_cart->is_parent_event()) {
             foreach ($event_in_cart->participants as $participant) {
                 $pages["CRM_Event_Cart_Form_Checkout_ConferenceEvents_{$event_in_cart->event_id}_{$participant->id}"] = array('className' => 'CRM_Event_Cart_Form_Checkout_ConferenceEvents', 'title' => "Select {$event_in_cart->event->title} Events For {$participant->email}");
             }
         }
     }
     $pages["CRM_Event_Cart_Form_Checkout_Payment"] = NULL;
     $pages["CRM_Event_Cart_Form_Checkout_ThankYou"] = NULL;
     $this->addSequentialPages($pages, $action);
 }
 /**
  * Build all the data structures needed to build the form.
  */
 public function preProcess()
 {
     // reset action from the session
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update');
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
     $rcid = CRM_Utils_Request::retrieve('rcid', 'Positive', $this);
     $rcid = $rcid ? "&id={$rcid}" : '';
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url('civicrm/user', "reset=1{$rcid}"));
     if ($this->_contactId) {
         $contact = new CRM_Contact_DAO_Contact();
         $contact->id = $this->_contactId;
         if (!$contact->find(TRUE)) {
             CRM_Core_Error::statusBounce(ts('contact does not exist: %1', array(1 => $this->_contactId)));
         }
         $this->_contactType = $contact->contact_type;
         // check for permissions
         if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
             CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'));
         }
         list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_contactId);
         CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName);
     } else {
         CRM_Core_Error::statusBounce(ts('Could not get a contact_id and/or contact_type'));
     }
 }
 /**
  * TODO: How many checks do we need to do? Should we check to make sure the
  * activity is the right type? That the cid and aid are associated? Seems like
  * if you are messing with URL params you are kind of asking for trouble...
  */
 function preProcess()
 {
     $this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this, FALSE);
     $this->_cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
     $this->_vid = CRM_Utils_Request::retrieve('vid', 'Positive', $this, FALSE);
     if (!CRM_Volunteer_Permission::checkProjectPerms(CRM_Core_Action::UPDATE, $this->_vid)) {
         CRM_Utils_System::permissionDenied();
     }
     if (!$this->_aid && !($this->_cid && $this->_vid)) {
         CRM_Core_Error::fatal("Form expects an activity ID or both a contact and a volunteer project ID.");
     }
     $check = array('Activity' => $this->_aid, 'Contact' => $this->_cid, 'VolunteerProject' => $this->_vid);
     $errors = array();
     foreach ($check as $entityType => $entityID) {
         if (!$this->entityExists($entityType, $entityID)) {
             $errors[] = "No {$entityType} with ID {$entityID} exists.";
         }
     }
     if (count($errors)) {
         CRM_Core_Error::fatal("Invalid parameter(s) passed to commendation form: " . implode(' ', $errors));
     }
     $contact_display_name = civicrm_api3('Contact', 'getvalue', array('id' => $this->_cid, 'return' => 'display_name'));
     CRM_Utils_System::setTitle(ts('Commend %1', array(1 => $contact_display_name, 'domain' => 'org.civicrm.volunteer')));
     parent::preProcess();
 }
Example #15
0
 function __construct(&$formValues)
 {
     parent::__construct($formValues);
     $this->_earthFlattening = 1.0 / 298.257223563;
     $this->_earthRadiusSemiMajor = 6378137.0;
     $this->_earthRadiusSemiMinor = $this->_earthRadiusSemiMajor * (1.0 - $this->_earthFlattening);
     $this->_earthEccentricitySQ = 2 * $this->_earthFlattening - pow($this->_earthFlattening, 2);
     // unset search profile if set
     unset($this->_formValues['uf_group_id']);
     if (!empty($this->_formValues)) {
         // add the country and state
         if (CRM_Utils_Array::value('country_id', $this->_formValues)) {
             $this->_formValues['country'] = CRM_Core_PseudoConstant::country($this->_formValues['country_id']);
         }
         if (CRM_Utils_Array::value('state_province_id', $this->_formValues)) {
             $this->_formValues['state_province'] = CRM_Core_PseudoConstant::stateProvince($this->_formValues['state_province_id']);
         }
         // use the address to get the latitude and longitude
         require_once 'CRM/Utils/Geocode/Google.php';
         CRM_Utils_Geocode_Google::format($this->_formValues);
         if (!isset($this->_formValues['geo_code_1']) || !isset($this->_formValues['geo_code_2']) || !isset($this->_formValues['distance'])) {
             CRM_Core_Error::fatal(ts('Could not geocode input'));
         }
         $this->_latitude = $this->_formValues['geo_code_1'];
         $this->_longitude = $this->_formValues['geo_code_2'];
         $this->_distance = $this->_formValues['distance'] * 1000;
     }
     $this->_earthDistanceSQL = $this->earthDistanceSQL($this->_latitude, $this->_longitude);
     $this->_tag = CRM_Utils_Array::value('tag', $this->_formValues);
     $this->_columns = array(ts('Name') => 'sort_name', ts('Street Address') => 'street_address', ts('City') => 'city', ts('Postal Code') => 'postal_code', ts('State') => 'state_province', ts('Country') => 'country');
 }
 /**
  * create or update a Volunteer Commendation
  *
  * This function is invoked from within the web form layer
  *
  * @param array $params An assoc array of name/value pairs
  *  - aid: activity id of an existing commendation to update
  *  - cid: id of contact to be commended
  *  - vid: id of project for which contact is to be commended
  *  - details: text about the contact's exceptional volunteerism
  * @see self::requiredParamsArePresent for rules re required params
  * @return array Result of api.activity.create
  * @access public
  * @static
  */
 public static function create(array $params)
 {
     // check required params
     if (!self::requiredParamsArePresent($params)) {
         CRM_Core_Error::fatal('Not enough data to create commendation object.');
     }
     $activity_statuses = CRM_Activity_BAO_Activity::buildOptions('status_id', 'create');
     $api_params = array('activity_type_id' => self::getActivityTypeId(), 'status_id' => CRM_Utils_Array::key('Completed', $activity_statuses));
     $aid = CRM_Utils_Array::value('aid', $params);
     if ($aid) {
         $api_params['id'] = $aid;
     }
     $cid = CRM_Utils_Array::value('cid', $params);
     if ($cid) {
         $api_params['target_contact_id'] = $cid;
     }
     $vid = CRM_Utils_Array::value('vid', $params);
     if ($vid) {
         $project = CRM_Volunteer_BAO_Project::retrieveByID($vid);
         $api_params['subject'] = ts('Volunteer Commendation for %1', array('1' => $project->title, 'domain' => 'org.civicrm.volunteer'));
         $customFieldSpec = self::getCustomFields();
         $volunteer_project_id_field_name = $customFieldSpec['volunteer_project_id']['custom_n'];
         $api_params[$volunteer_project_id_field_name] = $vid;
     }
     if (array_key_exists('details', $params)) {
         $api_params['details'] = CRM_Utils_Array::value('details', $params);
     }
     return civicrm_api3('Activity', 'create', $api_params);
 }
Example #17
0
 /** 
  * Function to set variables up before form is built 
  *                                                           
  * @return void 
  * @access public
  */
 public function preProcess()
 {
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('action', $this->_action);
     $this->assign('context', $this->_context);
     //check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviGrant', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $this->_noteId = null;
     if ($this->_id) {
         require_once 'CRM/Core/BAO/Note.php';
         $noteDAO = new CRM_Core_BAO_Note();
         $noteDAO->entity_table = 'civicrm_grant';
         $noteDAO->entity_id = $this->_id;
         if ($noteDAO->find(true)) {
             $this->_noteId = $noteDAO->id;
         }
     }
     //build custom data
     CRM_Custom_Form_Customdata::preProcess($this, null, null, 1, 'Grant', $this->_id);
 }
Example #18
0
 /**
  * Process the form submission.
  *
  * @return void
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         $errors = CRM_Financial_BAO_FinancialType::del($this->_id);
         if (!empty($errors)) {
             CRM_Core_Error::statusBounce($errors['error_message'], CRM_Utils_System::url('civicrm/admin/financial/financialType', "reset=1&action=browse"), ts('Cannot Delete'));
         }
         CRM_Core_Session::setStatus(ts('Selected financial type has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $params = $ids = array();
         // store the submitted values in an array
         $params = $this->exportValues();
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $ids['financialType'] = $this->_id;
         }
         $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids);
         if ($this->_action & CRM_Core_Action::UPDATE) {
             $url = CRM_Utils_System::url('civicrm/admin/financial/financialType', 'reset=1&action=browse');
             CRM_Core_Session::setStatus(ts('The financial type "%1" has been updated.', array(1 => $financialType->name)), ts('Saved'), 'success');
         } else {
             $url = CRM_Utils_System::url('civicrm/admin/financial/financialType/accounts', 'reset=1&action=browse&aid=' . $financialType->id);
             $statusArray = array(1 => $financialType->name, 2 => $financialType->name, 3 => CRM_Utils_Array::value(0, $financialType->titles), 4 => CRM_Utils_Array::value(1, $financialType->titles), 5 => CRM_Utils_Array::value(2, $financialType->titles));
             if (empty($financialType->titles)) {
                 $text = ts('Your Financial "%1" Type has been created and assigned to an existing financial account with the same title. You should review the assigned account and determine whether additional account relationships are needed.', $statusArray);
             } else {
                 $text = ts('Your Financial "%1" Type has been created, along with a corresponding income account "%2". That income account, along with standard financial accounts "%3", "%4" and "%5" have been linked to the financial type. You may edit or replace those relationships here.', $statusArray);
             }
             CRM_Core_Session::setStatus($text, ts('Saved'), 'success', array('expires' => 0));
         }
         $session = CRM_Core_Session::singleton();
         $session->replaceUserContext($url);
     }
 }
Example #19
0
 public function preProcess()
 {
     $this->set('searchFormName', 'Custom');
     $this->set('context', 'custom');
     $csID = CRM_Utils_Request::retrieve('csid', 'Integer', $this);
     $ssID = CRM_Utils_Request::retrieve('ssID', 'Integer', $this);
     $gID = CRM_Utils_Request::retrieve('gid', 'Integer', $this);
     list($this->_customSearchID, $this->_customSearchClass, $formValues) = CRM_Contact_BAO_SearchCustom::details($csID, $ssID, $gID);
     if (!$this->_customSearchID) {
         CRM_Core_Error::fatal('Could not get details for custom search.');
     }
     // stash this as a hidden element so we can potentially go there if the session
     // is reset but this is available in the POST
     $this->addElement('hidden', 'csid', $csID);
     if (!empty($formValues)) {
         $this->_formValues = $formValues;
     }
     // set breadcrumb to return to Custom Search listings page
     $breadCrumb = array(array('title' => ts('Custom Searches'), 'url' => CRM_Utils_System::url('civicrm/contact/search/custom/list', 'reset=1')));
     CRM_Utils_System::appendBreadCrumb($breadCrumb);
     // use the custom selector
     self::$_selectorName = 'CRM_Contact_Selector_Custom';
     $this->set('customSearchID', $this->_customSearchID);
     $this->set('customSearchClass', $this->_customSearchClass);
     parent::preProcess();
     // instantiate the new class
     $this->_customClass = new $this->_customSearchClass($this->_formValues);
     // CRM-12747
     if (isset($this->_customClass->_permissionedComponent) && !self::isPermissioned($this->_customClass->_permissionedComponent)) {
         CRM_Utils_System::permissionDenied();
     }
 }
Example #20
0
 public function preProcess()
 {
     require_once 'CRM/Contact/BAO/SearchCustom.php';
     $csID = CRM_Utils_Request::retrieve('csid', 'Integer', $this);
     $ssID = CRM_Utils_Request::retrieve('ssID', 'Integer', $this);
     $gID = CRM_Utils_Request::retrieve('gid', 'Integer', $this);
     list($this->_customSearchID, $this->_customSearchClass, $formValues) = CRM_Contact_BAO_SearchCustom::details($csID, $ssID, $gID);
     if (!$this->_customSearchID) {
         CRM_Core_Error::fatal('Could not get details for custom search.');
     }
     if (!empty($formValues)) {
         $this->_formValues = $formValues;
     }
     // set breadcrumb to return to Custom Search listings page
     $breadCrumb = array(array('title' => ts('Custom Searches'), 'url' => CRM_Utils_System::url('civicrm/contact/search/custom/list', 'reset=1')));
     CRM_Utils_System::appendBreadCrumb($breadCrumb);
     // use the custom selector
     require_once 'CRM/Contact/Selector/Custom.php';
     $this->_selectorName = 'CRM_Contact_Selector_Custom';
     $this->set('customSearchID', $this->_customSearchID);
     $this->set('customSearchClass', $this->_customSearchClass);
     parent::preProcess();
     // instantiate the new class
     eval('$this->_customClass = new ' . $this->_customSearchClass . '( $this->_formValues );');
 }
Example #21
0
 public function run()
 {
     $eid = CRM_Utils_Request::retrieve('eid', 'Positive', $this, TRUE);
     $fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
     $quest = CRM_Utils_Request::retrieve('quest', 'String', $this);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this);
     list($path, $mimeType) = CRM_Core_BAO_File::path($id, $eid, NULL, $quest);
     if (!$path) {
         CRM_Core_Error::statusBounce('Could not retrieve the file');
     }
     $buffer = file_get_contents($path);
     if (!$buffer) {
         CRM_Core_Error::statusBounce('The file is either empty or you do not have permission to retrieve the file');
     }
     if ($action & CRM_Core_Action::DELETE) {
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', CRM_Core_DAO::$_nullObject)) {
             CRM_Core_BAO_File::deleteFileReferences($id, $eid, $fid);
             CRM_Core_Session::setStatus(ts('The attached file has been deleted.'), ts('Complete'), 'success');
             $session = CRM_Core_Session::singleton();
             $toUrl = $session->popUserContext();
             CRM_Utils_System::redirect($toUrl);
         }
     } else {
         CRM_Utils_System::download(CRM_Utils_File::cleanFileName(basename($path)), $mimeType, $buffer);
     }
 }
Example #22
0
 /**
  * run this page (figure out the action needed and perform it).
  *
  * @return void
  */
 function run()
 {
     $instanceId = CRM_Report_Utils_Report::getInstanceID();
     $action = CRM_Utils_Request::retrieve('action', 'String', $this);
     $optionVal = CRM_Report_Utils_Report::getValueFromUrl($instanceId);
     $reportUrl = CRM_Utils_System::url('civicrm/report/list', "reset=1");
     if ($action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('administer Reports')) {
             $statusMessage = ts('Your do not have permission to Delete Report.');
             CRM_Core_Error::statusBounce($statusMessage, $reportUrl);
         }
         CRM_Report_BAO_Instance::delete($instanceId);
         CRM_Core_Session::setStatus(ts('Selected Instance has been deleted.'));
     } else {
         require_once 'CRM/Core/OptionGroup.php';
         $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value');
         if (strstr($templateInfo['name'], '_Form')) {
             $instanceInfo = array();
             CRM_Report_BAO_Instance::retrieve(array('id' => $instanceId), $instanceInfo);
             if (!empty($instanceInfo['title'])) {
                 CRM_Utils_System::setTitle($instanceInfo['title']);
                 $this->assign('reportTitle', $instanceInfo['title']);
             } else {
                 CRM_Utils_System::setTitle($templateInfo['label']);
                 $this->assign('reportTitle', $templateInfo['label']);
             }
             $wrapper =& new CRM_Utils_Wrapper();
             return $wrapper->run($templateInfo['name'], null, null);
         }
         CRM_Core_Session::setStatus(ts('Could not find template for the instance.'));
     }
     return CRM_Utils_System::redirect($reportUrl);
 }
Example #23
0
 /**
  * Given the list of params in the params array, fetch the object
  * and store the values in the values array
  *
  * @param Object $block         typically a Phone|Email|IM|OpenID object
  * @param string $blockName     name of the above object
  * @param array  $params        input parameters to find object
  * @param array  $values        output values of the object
  *
  * @return array of $block objects.
  * @access public
  * @static
  */
 static function &getValues($blockName, $params)
 {
     if (empty($params)) {
         return NULL;
     }
     $BAOString = 'CRM_Core_BAO_' . $blockName;
     $block = new $BAOString();
     $blocks = array();
     if (!isset($params['entity_table'])) {
         $block->contact_id = $params['contact_id'];
         if (!$block->contact_id) {
             CRM_Core_Error::fatal();
         }
         $blocks = self::retrieveBlock($block, $blockName);
     } else {
         $blockIds = self::getBlockIds($blockName, NULL, $params);
         if (empty($blockIds)) {
             return $blocks;
         }
         $count = 1;
         foreach ($blockIds as $blockId) {
             $block = new $BAOString();
             $block->id = $blockId['id'];
             $getBlocks = self::retrieveBlock($block, $blockName);
             $blocks[$count++] = array_pop($getBlocks);
         }
     }
     return $blocks;
 }
Example #24
0
 /**
  * Return the next X messages from the mail store
  * FIXME: in CiviCRM 2.2 this always returns all the emails
  *
  * @param int $count  number of messages to fetch FIXME: ignored in CiviCRM 2.2 (assumed to be 0, i.e., fetch all)
  * @return array      array of ezcMail objects
  */
 function fetchNext($count = 0)
 {
     $mails = array();
     $path = rtrim($this->_dir, DIRECTORY_SEPARATOR);
     if ($this->_debug) {
         print "fetching {$count} messages\n";
     }
     $directory = new DirectoryIterator($path);
     foreach ($directory as $entry) {
         if ($entry->isDot()) {
             continue;
         }
         if (count($mails) >= $count) {
             break;
         }
         $file = $path . DIRECTORY_SEPARATOR . $entry->getFilename();
         if ($this->_debug) {
             print "retrieving message {$file}\n";
         }
         $set = new ezcMailFileSet(array($file));
         $parser = new ezcMailParser();
         $mail = $parser->parseMail($set);
         if (!$mail) {
             return CRM_Core_Error::createAPIError(ts('%1 could not be parsed', array(1 => $file)));
         }
         $mails[$file] = $mail[0];
     }
     if ($this->_debug && count($mails) <= 0) {
         print "No messages found\n";
     }
     return $mails;
 }
Example #25
0
 /**
  * Pre processing work done here.
  *
  * gets session variables for group or field id
  *
  * @return void
  */
 public function preProcess()
 {
     // get the controller vars
     $this->_groupId = $this->get('groupId');
     $this->_fieldId = $this->get('fieldId');
     if ($this->_fieldId) {
         // field preview
         $defaults = array();
         $params = array('id' => $this->_fieldId);
         $fieldDAO = new CRM_Core_DAO_CustomField();
         CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
         if (!empty($defaults['is_view'])) {
             CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
         } elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) {
             CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.'));
         }
         $groupTree = array();
         $groupTree[$this->_groupId]['id'] = 0;
         $groupTree[$this->_groupId]['fields'] = array();
         $groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults;
         $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
         $this->assign('preview_type', 'field');
     } else {
         $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId);
         $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this);
         $this->assign('preview_type', 'group');
     }
 }
Example #26
0
 /**
  * Set variables up before form is built.
  *
  *
  * @return void
  */
 public function preProcess()
 {
     // current set id
     $this->_id = $this->get('id');
     if ($this->_id && ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id'))) {
         CRM_Core_Error::fatal("You cannot edit the settings of a reserved custom field-set.");
     }
     // setting title for html page
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
         CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title)));
     } elseif ($this->_action == CRM_Core_Action::VIEW) {
         $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
         CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title)));
     } else {
         CRM_Utils_System::setTitle(ts('New Custom Field Set'));
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults);
         $subExtends = CRM_Utils_Array::value('extends_entity_column_value', $this->_defaults);
         if (!empty($subExtends)) {
             $this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1));
         }
     }
 }
 /**
  * Takes an associative array and creates a contribution object.
  *
  * the function extract all the params it needs to initialize the create a
  * contribution object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Contribute_BAO_Contribution
  * @todo move hook calls / extended logic to create - requires changing calls to call create not add
  */
 public static function add(&$params)
 {
     if (!empty($params['id'])) {
         CRM_Utils_Hook::pre('edit', 'ContributionRecur', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'ContributionRecur', NULL, $params);
     }
     // make sure we're not creating a new recurring contribution with the same transaction ID
     // or invoice ID as an existing recurring contribution
     $duplicates = array();
     if (self::checkDuplicate($params, $duplicates)) {
         $error = CRM_Core_Error::singleton();
         $d = implode(', ', $duplicates);
         $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Found matching recurring contribution(s): {$d}");
         return $error;
     }
     $recurring = new CRM_Contribute_BAO_ContributionRecur();
     $recurring->copyValues($params);
     $recurring->id = CRM_Utils_Array::value('id', $params);
     // set currency for CRM-1496
     if (empty($params['id']) && !isset($recurring->currency)) {
         $config = CRM_Core_Config::singleton();
         $recurring->currency = $config->defaultCurrency;
     }
     $result = $recurring->save();
     if (!empty($params['id'])) {
         CRM_Utils_Hook::post('edit', 'ContributionRecur', $recurring->id, $recurring);
     } else {
         CRM_Utils_Hook::post('create', 'ContributionRecur', $recurring->id, $recurring);
     }
     if (!empty($params['custom']) && is_array($params['custom'])) {
         CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution_recur', $recurring->id);
     }
     return $result;
 }
 /**
  * This function is called prior to building and submitting the form
  */
 function preProcess()
 {
     // check contact_id
     $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     if (empty($this->_contactId)) {
         CRM_Core_Error::statusBounce(ts('Could not get a contact id.'), NULL, ts('Lidmaatschap Wijziging - Contact'));
         // this also redirects to the default civicrm page
     }
     // check for permissions
     $session = CRM_Core_Session::singleton();
     if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
         CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to edit this contact.'), NULL, ts('Lidmaatschap Wijziging - Contact'));
         // this also redirects to the default civicrm page
     }
     // get session
     $session = CRM_Core_Session::singleton();
     // get values
     $this->_configGroup = CRM_Lidmaatschapwijziging_ConfigGroup::singleton($this->_contactId);
     $this->_values = $this->_configGroup->getContact();
     // set display name
     $this->_display_name = $this->_values['display_name'];
     // set title
     CRM_Utils_System::setTitle('LidmaatschapWijziging - Group - ' . $this->_values['display_name']);
     // set contact id
     $this->_values['contact_id'] = $this->_contactId;
 }
function run()
{
    session_start();
    require_once '../civicrm.config.php';
    require_once 'CRM/Core/Config.php';
    $config = CRM_Core_Config::singleton();
    require_once 'Console/Getopt.php';
    $shortOptions = "n:p:k:pre";
    $longOptions = array('name=', 'pass='******'key=', 'prefix=');
    $getopt = new Console_Getopt();
    $args = $getopt->readPHPArgv();
    array_shift($args);
    list($valid, $dontCare) = $getopt->getopt2($args, $shortOptions, $longOptions);
    $vars = array('name' => 'n', 'pass' => 'p', 'key' => 'k', 'prefix' => 'pre');
    foreach ($vars as $var => $short) {
        ${$var} = NULL;
        foreach ($valid as $v) {
            if ($v[0] == $short || $v[0] == "--{$var}") {
                ${$var} = $v[1];
                break;
            }
        }
        if (!${$var}) {
            ${$var} = CRM_Utils_Array::value($var, $_REQUEST);
        }
        $_REQUEST[$var] = ${$var};
    }
    // this does not return on failure
    // require_once 'CRM/Utils/System.php';
    CRM_Utils_System::authenticateScript(TRUE, $name, $pass);
    //log the execution of script
    CRM_Core_Error::debug_log_message('NormalizePhone.php');
    // process all phones
    processPhones($config, $prefix);
}
Example #30
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_id = $this->get('id');
     $this->_cid = $this->get('cid');
     $params = array('id' => $this->_id);
     CRM_Booking_BAO_Booking::retrieve($params, $this->_values);
     if (empty($this->_values)) {
         CRM_Core_Error::statusBounce(ts('The requested booking record does not exist (possibly the record was deleted).'));
     }
     $params = array('option_group_name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS, 'name' => CRM_Booking_Utils_Constants::OPTION_VALUE_CANCELLED);
     $result = civicrm_api3('OptionValue', 'get', $params);
     $this->_cancelStatusId = $cancelStatus = CRM_Utils_Array::value('value', CRM_Utils_Array::value($result['id'], $result['values']));
     if ($this->_values['status_id'] == $cancelStatus & ($this->_action != CRM_Core_Action::DELETE & $this->_action != CRM_Core_Action::VIEW)) {
         $bookingPayment = civicrm_api3('BookingPayment', 'get', array('booking_id' => $this->_id));
         if ($bookingPayment['count'] > 0) {
             CRM_Core_Error::statusBounce(ts('The requested booking record has already been cancelled'));
         }
     }
     $this->_values['payment_status'] = CRM_Booking_BAO_Booking::getPaymentStatus($this->_id);
     $paymentStatus = $this->_values['payment_status'];
     $this->assign('booking', $this->_values);
     //ResoveDefault
     CRM_Booking_BAO_Booking::resolveDefaults($this->_values);
     $title = $this->_values['title'];
     CRM_Utils_System::setTitle(ts('Update Booking') . " - {$title}");
     //get contribution record
     $this->associatedContribution($this->_id);
 }