/** * Implementation of hook_civicrm_postProcess(). * * Called when a form comes back for processing. Basically, we want to process * the button we added in cdntaxreceipts_civicrm_buildForm(). */ function cdntaxreceipts_civicrm_postProcess($formName, &$form) { // first check whether I really need to process this form if (!is_a($form, 'CRM_Contribute_Form_ContributionView')) { return; } $types = array('issue_tax_receipt', 'view_tax_receipt'); $action = ''; foreach ($types as $type) { $post = '_qf_ContributionView_submit_' . $type; if (isset($_POST[$post])) { if ($_POST[$post] == ts('Tax Receipt', array('domain' => 'org.civicrm.cdntaxreceipts'))) { $action = $post; } } } if (empty($action)) { return; } // the tax receipt button has been pressed. redirect to the tax receipt 'view' screen, preserving context. $contributionId = $form->get('id'); $contactId = $form->get('cid'); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&id={$contributionId}&cid={$contactId}&action=view&context=contribution&selectedChild=contribute")); $urlParams = array('reset=1', 'id=' . $contributionId, 'cid=' . $contactId); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/cdntaxreceipts/view', implode('&', $urlParams))); }
/** * Simple ping function to test for liveness. * * @param string $var * The string to be echoed. * * @return string */ public static function ping($var = NULL) { $session = CRM_Core_Session::singleton(); $key = $session->get('key'); //$session->set( 'key', $var ); return self::simple(array('message' => "PONG: {$key}")); }
/** * Display daily system status alerts (admin only). */ public function showPeriodicAlerts() { if (CRM_Core_Permission::check('administer CiviCRM')) { $session = CRM_Core_Session::singleton(); if ($session->timer('check_' . __CLASS__, self::CHECK_TIMER)) { // Best attempt at re-securing folders $config = CRM_Core_Config::singleton(); $config->cleanup(0, FALSE); $statusMessages = array(); $maxSeverity = 0; foreach ($this->checkAll() as $message) { if (!$message->isVisible()) { continue; } if ($message->getLevel() >= 3) { $maxSeverity = max($maxSeverity, $message->getLevel()); $statusMessage = $message->getMessage(); $statusMessages[] = $statusTitle = $message->getTitle(); } } if ($statusMessages) { if (count($statusMessages) > 1) { $statusTitle = self::toStatusLabel($maxSeverity); $statusMessage = '<ul><li>' . implode('</li><li>', $statusMessages) . '</li></ul>'; } $statusMessage .= '<p><a href="' . CRM_Utils_System::url('civicrm/a/#/status') . '">' . ts('View details and manage alerts') . '</a></p>'; $statusType = $maxSeverity >= 4 ? 'error' : 'alert'; CRM_Core_Session::setStatus($statusMessage, $statusTitle, $statusType); } } } }
/** * 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')); } }
public function preProcess() { $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE); $this->_system = CRM_Utils_Request::retrieve('system', 'Boolean', $this, FALSE, TRUE); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'update'); if (isset($action)) { $this->assign('action', $action); } $session = CRM_Core_Session::singleton(); $this->_config = new CRM_Core_DAO(); if ($this->_system) { if (CRM_Core_Permission::check('administer CiviCRM')) { $this->_contactID = NULL; } else { CRM_Utils_System::fatal('You do not have permission to edit preferences'); } $this->_config->contact_id = NULL; } else { if (!$this->_contactID) { $this->_contactID = $session->get('userID'); if (!$this->_contactID) { CRM_Utils_System::fatal('Could not retrieve contact id'); } $this->set('cid', $this->_contactID); } $this->_config->contact_id = $this->_contactID; } $settings = Civi::settings(); foreach ($this->_varNames as $groupName => $settingNames) { foreach ($settingNames as $settingName => $options) { $this->_config->{$settingName} = $settings->get($settingName); } } $session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); }
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); } }
public function postProcess() { $values = $this->exportValues(); // check if EmailTyped matches Email address $result = CRM_Utils_String::compareStr($this->_email, $values['email_confirm'], TRUE); $job_id = $this->_job_id; $queue_id = $this->_queue_id; $hash = $this->_hash; $confirmURL = CRM_Utils_System::url("civicrm/mailing/{$this->_type}", "reset=1&jid={$job_id}&qid={$queue_id}&h={$hash}&confirm=1"); $this->assign('confirmURL', $confirmURL); $session = CRM_Core_Session::singleton(); $session->pushUserContext($confirmURL); if ($result == TRUE) { // Email address verified if (CRM_Mailing_Event_BAO_Unsubscribe::unsub_from_domain($job_id, $queue_id, $hash)) { CRM_Mailing_Event_BAO_Unsubscribe::send_unsub_response($queue_id, NULL, TRUE, $job_id); } $statusMsg = ts('Email: %1 has been successfully opted out', array(1 => $values['email_confirm'])); CRM_Core_Session::setStatus($statusMsg, '', 'success'); } elseif ($result == FALSE) { // Email address not verified $statusMsg = ts('The email address: %1 you have entered does not match the email associated with this opt out request.', array(1 => $values['email_confirm'])); CRM_Core_Session::setStatus($statusMsg, '', 'fail'); } }
/** * send the message to all the contacts and also insert a * contact activity in each contacts record * * @param array $contactIds the array of contact ids to send the email * @param string $subject the subject of the message * @param string $message the message contents * @param string $emailAddress use this 'to' email address instead of the default Primary address * * @return array (total, added, notAdded) count of emails sent * @access public * @static */ function sendEmail(&$contactIds, &$subject, &$message, $emailAddress) { $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); list($fromDisplayName, $fromEmail, $fromDoNotEmail) = CRM_Contact_BAO_Contact::getContactDetails($userID); if (!$fromEmail) { return array(count($contactIds), 0, count($contactIds)); } if (!trim($fromDisplayName)) { $fromDisplayName = $fromEmail; } $from = CRM_Utils_Mail::encodeAddressHeader($fromDisplayName, $fromEmail); // create the meta level record first $email =& new CRM_Core_BAO_EmailHistory(); $email->subject = $subject; $email->message = $message; $email->contact_id = $userID; $email->sent_date = date('Ymd'); $email->save(); $sent = $notSent = 0; foreach ($contactIds as $contactId) { if (CRM_Core_BAO_EmailHistory::sendMessage($from, $contactId, $subject, $message, $emailAddress, $email->id)) { $sent++; } else { $notSent++; } } return array(count($contactIds), $sent, $notSent); }
/** * Implementation of hook_civicrm_enable */ function normalize_civicrm_enable() { // jump to the setup screen after enabling extension $session = CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/setting/reformat')); return _normalize_civix_civicrm_enable(); }
/** * Execute "checkAll". * * @param array|NULL $messages * List of CRM_Utils_Check_Message; or NULL if the default list should be fetched. * @param array|string|callable $filter * Restrict messages using a callback filter. * By default, only show warnings and errors. * Set TRUE to show all messages. */ public function showPeriodicAlerts($messages = NULL, $filter = array(__CLASS__, 'severityMap')) { if (CRM_Core_Permission::check('administer CiviCRM') && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityAlert', NULL, TRUE)) { $session = CRM_Core_Session::singleton(); if ($session->timer('check_' . __CLASS__, self::CHECK_TIMER)) { // Best attempt at re-securing folders $config = CRM_Core_Config::singleton(); $config->cleanup(0, FALSE); if ($messages === NULL) { $messages = $this->checkAll(); } $statusMessages = array(); $statusType = 'alert'; foreach ($messages as $message) { if ($filter === TRUE || $message->getSeverity() >= 3) { $statusType = $message->getSeverity() >= 4 ? 'error' : $statusType; $statusMessage = $message->getMessage(); $statusMessages[] = $statusTitle = $message->getTitle(); } } if (count($statusMessages)) { if (count($statusMessages) > 1) { $statusTitle = ts('Multiple Alerts'); $statusMessage = '<ul><li>' . implode('</li><li>', $statusMessages) . '</li></ul>'; } // TODO: add link to status page CRM_Core_Session::setStatus($statusMessage, $statusTitle, $statusType); } } } }
function noverwrite_civicrm_buildForm($formName, &$form) { $names = array("CRM_Profile_Form_Edit", "CRM_Event_Form_Registration_Register", "CRM_Contribute_Form_Contribution_Main"); if (!in_array($formName, $names)) { return; } // Don't invoke if we're using CiviMobile, since CiviMobile depends on users being able // to edit records via profiles. $path = CRM_Utils_Array::value('HTTP_REFERER', $_SERVER); if ($formName == 'CRM_Profile_Form_Edit' && preg_match('#civicrm/mobile#', $path)) { return; } $session = CRM_Core_Session::singleton(); if (!$session->get('userID') && !array_key_exists("cs", $_GET)) { return; // anonymous user, nothing to bloc } foreach (array('first_name', 'middle_name', 'last_name') as $f) { if (!$form->elementExists($f)) { continue; } $field = $form->getElement($f); if ($field && $field->_attributes["value"]) { $form->freeze($f); } } // if you want to bloc it at the js level only, uncomment the next line and comment out the freeze // CRM_Core_Resources::singleton()->addScript(file_get_contents(dirname( __FILE__ ) ."/js/noverwrite.js")); }
function postProcess() { $session = CRM_Core_Session::singleton(); $params = $this->exportValues(); $result = civicrm_api3('OptionValue', 'create', array('value' => $params['hour_value'], 'id' => CRM_Utils_Array::key($params['hour_type_select'], $this->_id))); $session->pushUserContext(CRM_Utils_System::url('civicrm/hour/editoption', "&value={$params['hour_value']}")); }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * Finally it calls the parent's run method. * * @return void * @access public * */ function run() { // get the requested action $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse'); // assign vars to templates $this->assign('action', $action); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $this->_aid = CRM_Utils_Request::retrieve('aid', 'Positive', $this); // set breadcrumb to append to 2nd layer pages $breadCrumb = array(array('title' => ts('Manage Items'), 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'))); // what action to take ? if ($action & CRM_Core_Action::DISABLE) { require_once 'CRM/Auction/BAO/Auction.php'; CRM_Auction_BAO_Auction::setIsActive($id, 0); } elseif ($action & CRM_Core_Action::ENABLE) { require_once 'CRM/Auction/BAO/Auction.php'; CRM_Auction_BAO_Auction::setIsActive($id, 1); } elseif ($action & CRM_Core_Action::DELETE) { $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse')); $controller = new CRM_Core_Controller_Simple('CRM_Auction_Form_Auction_Delete', 'Delete Auction', $action); $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0); $controller->set('id', $id); $controller->process(); return $controller->run(); } // finally browse the auctions $this->browse(); // parent run parent::run(); }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $session =& CRM_Core_Session::singleton(); //this is done to unset searchRows variable assign during AddToHousehold and AddToOrganization $this->set('searchRows', ''); $context = $this->get('context'); if ($context == 'smog' || $context == 'amtg') { $url = CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid='); if ($this->get('context') == 'smog') { $session->replaceUserContext($url . $this->get('gid')); } else { $session->replaceUserContext($url . $this->get('amtgID')); } return; } $ssID = $this->get('ssID'); if (isset($ssID)) { if ($this->_action == CRM_CORE_ACTION_BASIC) { $fragment = 'search'; } else { $fragment = 'search/advanced'; } $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, 'reset=1&force=1&ssID=' . $ssID); $session->replaceUserContext($url); return; } }
/** * build all the data structures needed to build the form * * @return void * @access 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')); } }
public function postProcess() { $session = CRM_Core_Session::singleton(); $session->setStatus('Rule ' . $this->rule->label . ' parameters updated', 'Rule parameters updated', 'success'); $redirectUrl = CRM_Utils_System::url('civicrm/civirule/form/rule', 'action=update&id=' . $this->rule->id, TRUE); CRM_Utils_System::redirect($redirectUrl); }
/** * Takes an associative array and creates a Survey object. * * the function extract all the params it needs to initialize the create a * survey object. * * * @param array $params * * @return CRM_Survey_DAO_Survey */ public static function create(&$params) { if (empty($params)) { return FALSE; } if (!empty($params['is_default'])) { $query = "UPDATE civicrm_survey SET is_default = 0"; CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } if (!CRM_Utils_Array::value('id', $params)) { if (!CRM_Utils_Array::value('created_id', $params)) { $session = CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); } if (!CRM_Utils_Array::value('created_date', $params)) { $params['created_date'] = date('YmdHis'); } } $dao = new CRM_Campaign_DAO_Survey(); $dao->copyValues($params); $dao->save(); if (!empty($params['custom']) && is_array($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_survey', $dao->id); } return $dao; }
/** * Run dashboard. * * @return void */ public function run() { // Add dashboard js and css $resources = CRM_Core_Resources::singleton(); $resources->addScriptFile('civicrm', 'js/jquery/jquery.dashboard.js', 0, 'html-header', FALSE); $resources->addStyleFile('civicrm', 'css/dashboard.css'); $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject); CRM_Utils_System::setTitle(ts('CiviCRM Home')); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($resetCache) { CRM_Core_BAO_Dashboard::resetDashletCache($contactID); } // call hook to get html from other modules // ignored but needed to prevent warnings $contentPlacement = CRM_Utils_Hook::DASHBOARD_BELOW; $html = CRM_Utils_Hook::dashboard($contactID, $contentPlacement); if (is_array($html)) { $this->assign_by_ref('hookContent', $html); $this->assign('hookContentPlacement', $contentPlacement); } $communityMessages = CRM_Core_CommunityMessages::create(); if ($communityMessages->isEnabled()) { $message = $communityMessages->pick(); if ($message) { $this->assign('communityMessages', $communityMessages->evalMarkup($message['markup'])); } } return parent::run(); }
/** * run this page (figure out the action needed and perform it). * * @return void */ function run() { if (!CRM_Core_Permission::check('administer Reports')) { return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1')); } $optionVal = CRM_Report_Utils_Report::getValueFromUrl(); $templateInfo = CRM_Core_OptionGroup::getRowValues('report_template', "{$optionVal}", 'value', 'String', FALSE); $extKey = strpos(CRM_Utils_Array::value('name', $templateInfo), '.'); $reportClass = NULL; if ($extKey !== FALSE) { $ext = CRM_Extension_System::singleton()->getMapper(); $reportClass = $ext->keyToClass($templateInfo['name'], 'report'); $templateInfo['name'] = $reportClass; } if (strstr(CRM_Utils_Array::value('name', $templateInfo), '_Form') || !is_null($reportClass)) { CRM_Utils_System::setTitle($templateInfo['label'] . ' - Template'); $this->assign('reportTitle', $templateInfo['label']); $session = CRM_Core_Session::singleton(); $session->set('reportDescription', $templateInfo['description']); $wrapper = new CRM_Utils_Wrapper(); return $wrapper->run($templateInfo['name'], NULL, NULL); } if ($optionVal) { CRM_Core_Session::setStatus(ts('Could not find the report template. Make sure the report template is registered and / or url is correct.'), ts('Template Not Found'), 'error'); } return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/report/list', 'reset=1')); }
/** * Output navigation script tag * * @param array $params * - is_default: bool, true if this is normal/default instance of the menu (which may be subject to CIVICRM_DISABLE_DEFAULT_MENU) * @param CRM_Core_Smarty $smarty * The Smarty object. * * @return string * HTML */ function smarty_function_crmNavigationMenu($params, &$smarty) { $config = CRM_Core_Config::singleton(); //check if logged in user has access CiviCRM permission and build menu $buildNavigation = !CRM_Core_Config::isUpgradeMode() && CRM_Core_Permission::check('access CiviCRM'); if (defined('CIVICRM_DISABLE_DEFAULT_MENU') && CRM_Utils_Array::value('is_default', $params, FALSE)) { $buildNavigation = FALSE; } if ($config->userFrameworkFrontend) { $buildNavigation = FALSE; } if ($buildNavigation) { $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); if ($contactID) { // These params force the browser to refresh the js file when switching user, domain, or language // We don't put them as a query string because some browsers will refuse to cache a page with a ? in the url // @see CRM_Admin_Page_AJAX::getNavigationMenu $lang = $config->lcMessages; $domain = CRM_Core_Config::domainID(); $key = CRM_Core_BAO_Navigation::getCacheKey($contactID); $src = CRM_Utils_System::url("civicrm/ajax/menujs/{$contactID}/{$lang}/{$domain}/{$key}"); // CRM-15493 QFkey needed for quicksearch bar - must be unique on each page refresh so adding it directly to markup $qfKey = CRM_Core_Key::get('CRM_Contact_Controller_Search', TRUE); return '<script id="civicrm-navigation-menu" type="text/javascript" src="' . $src . '" data-qfkey=' . json_encode($qfKey) . '></script>'; } } return ''; }
/** * List activities as dashlet * * @return none * * @access public */ function run() { $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // a user can always view their own activity // if they have access CiviCRM permission $permission = CRM_Core_Permission::VIEW; // make the permission edit if the user has edit permission on the contact require_once 'CRM/Contact/BAO/Contact/Permission.php'; if (CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) { $permission = CRM_Core_Permission::EDIT; } $admin = CRM_Core_Permission::check('view all activities') || CRM_Core_Permission::check('administer CiviCRM'); require_once 'CRM/Core/Selector/Controller.php'; $output = CRM_Core_Selector_Controller::SESSION; require_once 'CRM/Activity/Selector/Activity.php'; $selector = new CRM_Activity_Selector_Activity($contactID, $permission, $admin, 'home'); $sortID = null; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, $output); $controller->setEmbedded(true); $controller->run(); $controller->moveFromSessionToTemplate(); return parent::run(); }
/** * Build the form object. */ public function buildQuickForm() { $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); $args = func_get_args(); $check = reset($args); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); foreach ($this->_settings as $setting => $group) { $settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting)); $props = $settingMetaData['values'][$setting]; if (isset($props['quick_form_type'])) { $add = 'add' . $props['quick_form_type']; if ($add == 'addElement') { $this->{$add}($props['html_type'], $setting, ts($props['title']), CRM_Utils_Array::value($props['html_type'] == 'select' ? 'option_values' : 'html_attributes', $props, array()), $props['html_type'] == 'select' ? CRM_Utils_Array::value('html_attributes', $props) : NULL); } else { $this->{$add}($setting, ts($props['title'])); } $this->assign("{$setting}_description", ts($props['description'])); if ($setting == 'max_attachments') { //temp hack @todo fix to get from metadata $this->addRule('max_attachments', ts('Value should be a positive number'), 'positiveInteger'); } if ($setting == 'maxFileSize') { //temp hack $this->addRule('maxFileSize', ts('Value should be a positive number'), 'positiveInteger'); } } } }
/** * Heart of the viewing process. The runner gets all the meta data for * the contact and calls the appropriate type of page to view. * * @return void * @access public * */ function preProcess() { // Make sure case types have been configured for the component require_once 'CRM/Core/OptionGroup.php'; $caseType = CRM_Core_OptionGroup::values('case_type'); if (empty($caseType)) { $this->assign('notConfigured', 1); return; } $session =& CRM_Core_Session::singleton(); $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session); CRM_Utils_System::setTitle(ts('CiviCase Dashboard')); $userID = $session->get('userID'); if (!$allCases) { $this->assign('myCases', true); } else { $this->assign('myCases', false); } $this->assign('newClient', false); if (CRM_Core_Permission::check('add contacts')) { $this->assign('newClient', true); } require_once 'CRM/Case/BAO/Case.php'; $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID); $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming'); $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent'); $this->assign('casesSummary', $summary); if (!empty($upcoming)) { $this->assign('upcomingCases', $upcoming); } if (!empty($recent)) { $this->assign('recentCases', $recent); } }
function __construct() { parent::__construct(); $check = CRM_Core_Permission::check('access Contact Dashboard'); if (!$check) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/dashboard', 'reset=1')); break; } $this->_contactId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $session =& CRM_Core_Session::singleton(); $userID = $session->get('userID'); if (!$this->_contactId) { $this->_contactId = $userID; } else { if ($this->_contactId != $userID) { require_once 'CRM/Contact/BAO/Contact/Permission.php'; if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::VIEW)) { CRM_Core_Error::fatal(ts('You do not have permission to view this contact')); } if (!CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) { $this->_edit = false; } } } }
function run() { $session = CRM_Core_Session::singleton(); $apiURL = "https://graph.facebook.com/v2.3"; $redirect_uri = rawurldecode(CRM_Utils_System::url('civicrm/civisocial/facebookcallback', NULL, TRUE)); // Retreive client_id and client_secret from settings $is_enabled = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'enable_facebook')); if (!$is_enabled) { die("Backend not enabled."); } $client_secret = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'facebook_secret')); $client_id = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'facebook_app_id')); // Facebook sends a code to the callback url, this is further used to acquire // access token from facebook, which is needed to get all the data from facebook if (array_key_exists('code', $_GET)) { $facebook_code = $_GET['code']; } else { die("FACEBOOK FATAL: the request returned without the code. Please try loging in again."); } // Get the access token from facebook for the user $access_token = ""; $access_token_response = $this->get_response($apiURL, "oauth/access_token", FALSE, array("client_id" => $client_id, "client_secret" => $client_secret, "code" => $facebook_code, "redirect_uri" => $redirect_uri)); if (array_key_exists("error", $access_token_response)) { die($access_token_response["error"]); $access_token = ""; } else { $access_token = $access_token_response["access_token"]; } $user_data_response = $this->get_response($apiURL, "me", FALSE, array("access_token" => $access_token)); $contact_id = CRM_Civisocial_BAO_CivisocialUser::handle_facebook_data($user_data_response); $this->assign('status', $contact_id); $session->set('userID', $contact_id); parent::run(); }
/** * called when action is update. * * @param int $groupId * * @return null */ public function edit($groupId = NULL) { $this->assign('edit', $this->_edit); if (!$this->_edit) { return NULL; } $action = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'browse'); if ($action == CRM_Core_Action::DELETE) { $groupContactId = CRM_Utils_Request::retrieve('gcid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE); $status = CRM_Utils_Request::retrieve('st', 'String', CRM_Core_DAO::$_nullObject, TRUE); if (is_numeric($groupContactId) && $status) { CRM_Contact_Page_View_GroupContact::del($groupContactId, $status, $this->_contactId); } $url = CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"); CRM_Utils_System::redirect($url); } $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_GroupContact', ts("Contact's Groups"), CRM_Core_Action::ADD, FALSE, FALSE, TRUE, FALSE); $controller->setEmbedded(TRUE); $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/user', "reset=1&id={$this->_contactId}"), FALSE); $controller->reset(); $controller->set('contactId', $this->_contactId); $controller->set('groupId', $groupId); $controller->set('context', 'user'); $controller->set('onlyPublicGroups', $this->_onlyPublicGroups); $controller->process(); $controller->run(); }
/** * Set default values for the form. * The default values are retrieved from the database. * * * @return void */ public function setDefaultValues() { $defaults = $this->_values; if (empty($defaults['pdf_format_id'])) { $defaults['pdf_format_id'] = 'null'; } $this->_workflow_id = CRM_Utils_Array::value('workflow_id', $defaults); $this->assign('workflow_id', $this->_workflow_id); if ($this->_action & CRM_Core_Action::ADD) { $defaults['is_active'] = 1; //set the context for redirection after form submit or cancel $session = CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=user&reset=1')); } // FIXME: we need to fix the Cancel button here as we don’t know whether it’s a workflow template in buildQuickForm() if ($this->_action & CRM_Core_Action::UPDATE) { if ($this->_workflow_id) { $selectedChild = 'workflow'; } else { $selectedChild = 'user'; } $cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', "selectedChild={$selectedChild}&reset=1"); $cancelURL = str_replace('&', '&', $cancelURL); $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'), 'js' => array('onclick' => "location.href='{$cancelURL}'; return false;")))); } return $defaults; }
/** * Get AngularJS modules and their dependencies * * @return array * list of modules; same format as CRM_Utils_Hook::angularModules(&$angularModules) * @see CRM_Utils_Hook::angularModules */ public function getAngularModules() { // load angular files only if valid permissions are granted to the user if (!CRM_Core_Permission::check('access CiviMail') && !CRM_Core_Permission::check('create mailings') && !CRM_Core_Permission::check('schedule mailings') && !CRM_Core_Permission::check('approve mailings')) { return array(); } $result = array(); $result['crmMailing'] = array('ext' => 'civicrm', 'js' => array('ang/crmMailing.js', 'ang/crmMailing/*.js'), 'css' => array('ang/crmMailing.css'), 'partials' => array('ang/crmMailing')); $result['crmMailingAB'] = array('ext' => 'civicrm', 'js' => array('ang/crmMailingAB.js', 'ang/crmMailingAB/*.js', 'ang/crmMailingAB/*/*.js'), 'css' => array('ang/crmMailingAB.css'), 'partials' => array('ang/crmMailingAB')); $result['crmD3'] = array('ext' => 'civicrm', 'js' => array('ang/crmD3.js', 'bower_components/d3/d3.min.js')); $config = CRM_Core_Config::singleton(); $session = CRM_Core_Session::singleton(); $contactID = $session->get('userID'); // Get past mailings // CRM-16155 - Limit to a reasonable number $civiMails = civicrm_api3('Mailing', 'get', array('is_completed' => 1, 'mailing_type' => array('IN' => array('standalone', 'winner')), 'return' => array('id', 'name', 'scheduled_date'), 'sequential' => 1, 'options' => array('limit' => 500, 'sort' => 'is_archived asc, scheduled_date desc'))); // Generic params $params = array('options' => array('limit' => 0), 'sequential' => 1); $groupNames = civicrm_api3('Group', 'get', $params + array('is_active' => 1, 'check_permissions' => TRUE, 'return' => array('title', 'visibility', 'group_type', 'is_hidden'))); $headerfooterList = civicrm_api3('MailingComponent', 'get', $params + array('is_active' => 1, 'return' => array('name', 'component_type', 'is_default', 'body_html', 'body_text'))); $emailAdd = civicrm_api3('Email', 'get', array('sequential' => 1, 'return' => "email", 'contact_id' => $contactID)); $mesTemplate = civicrm_api3('MessageTemplate', 'get', $params + array('sequential' => 1, 'is_active' => 1, 'return' => array("id", "msg_title"), 'workflow_id' => array('IS NULL' => ""))); $mailTokens = civicrm_api3('Mailing', 'gettokens', array('entity' => array('contact', 'mailing'), 'sequential' => 1)); $fromAddress = civicrm_api3('OptionValue', 'get', $params + array('option_group_id' => "from_email_address", 'domain_id' => CRM_Core_Config::domainID())); CRM_Core_Resources::singleton()->addSetting(array('crmMailing' => array('civiMails' => $civiMails['values'], 'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents), 'groupNames' => $groupNames['values'], 'headerfooterList' => $headerfooterList['values'], 'mesTemplate' => $mesTemplate['values'], 'emailAdd' => $emailAdd['values'], 'mailTokens' => $mailTokens['values'], 'contactid' => $contactID, 'requiredTokens' => CRM_Utils_Token::getRequiredTokens(), 'enableReplyTo' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'replyTo'), 'disableMandatoryTokensCheck' => (int) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'disable_mandatory_tokens_check'), 'fromAddress' => $fromAddress['values'], 'defaultTestEmail' => civicrm_api3('Contact', 'getvalue', array('id' => 'user_contact_id', 'return' => 'email')), 'visibility' => CRM_Utils_Array::makeNonAssociative(CRM_Core_SelectValues::groupVisibility()), 'workflowEnabled' => CRM_Mailing_Info::workflowEnabled())))->addPermissions(array('view all contacts', 'access CiviMail', 'create mailings', 'schedule mailings', 'approve mailings', 'delete in CiviMail', 'edit message templates')); return $result; }
/** * Method to build where part of query */ function where() { $clauses = array(); foreach ($this->_columns as $tableName => $table) { if (array_key_exists('filters', $table)) { foreach ($table['filters'] as $fieldName => $field) { $clause = NULL; $op = CRM_Utils_Array::value("{$fieldName}_op", $this->_params); // if user id value contains 0 for current user, replace value with current user if ($fieldName == 'account_id') { foreach ($this->_params['account_id_value'] as $paramKey => $userIdValue) { if ($userIdValue == 0) { $session = CRM_Core_Session::singleton(); $this->_params['account_id_value'][$paramKey] = $session->get('userID'); } } } $clause = $this->whereClause($field, $op, CRM_Utils_Array::value("{$fieldName}_value", $this->_params), CRM_Utils_Array::value("{$fieldName}_min", $this->_params), CRM_Utils_Array::value("{$fieldName}_max", $this->_params)); if (!empty($clause)) { $clauses[] = $clause; } } } } if (empty($clauses)) { $this->_where = ""; } else { $this->_where = "WHERE " . implode(' AND ', $clauses); } }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * Finally it calls the parent's run method. * * @return void * @access public * */ function run() { // get the requested action $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add'); // set breadcrumb to append to 2nd layer pages $breadCrumb = array(array('title' => ts('Manage Items'), 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'))); // what action to take ? if ($action & CRM_Core_Action::ADD) { $session = CRM_Core_Session::singleton(); if ($session->get('userID')) { // For logged in user directly go to add/update item page. $controller = new CRM_Core_Controller_Simple('CRM_Auction_Form_Item', 'New Item', $action); $controller->set('donorID', $session->get('userID')); } else { // For anonymous user go via account creation wizard. require_once 'CRM/Auction/Controller/Item.php'; $controller = new CRM_Auction_Controller_Item('New Item', $action); } return $controller->run(); } elseif ($action & CRM_Core_Action::UPDATE) { $session = CRM_Core_Session::singleton(); if ($session->get('userID')) { $controller = new CRM_Core_Controller_Simple('CRM_Auction_Form_Item', 'Update Item', $action); $controller->set('donorID', $session->get('userID')); return $controller->run(); } } // parent run parent::run(); }