function getBackendURI()
 {
     $backendURI = NULL;
     $path = CRM_Utils_System::currentPath();
     if (false !== strpos($path, '..')) {
         die("SECURITY FATAL: the url can't contain '..'. Please report the issue on the forum at civicrm.org");
     }
     $path = split('/', $path);
     if (!CRM_Utils_Array::value(3, $path)) {
         die("BACKEND ERROR: No backend found in request");
     } else {
         $backend = CRM_Utils_Array::value(3, $path);
         if ("facebook" == $backend) {
             $enabled = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'enable_facebook'));
             if ($enabled) {
                 $facebook_client_id = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'facebook_app_id'));
                 $backendURI = "https://www.facebook.com/dialog/oauth?";
                 $backendURI .= "client_id=" . $facebook_client_id;
                 $backendURI .= "&redirect_uri=" . $this->getRedirectURI("facebook");
             }
         } else {
             if ("googleplus" == $backend) {
                 $enabled = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'enable_googleplus'));
                 if ($enabled) {
                     $googleplus_client_id = civicrm_api3('setting', 'getvalue', array('group' => 'CiviSocial Account Credentials', 'name' => 'google_plus_key'));
                     $backendURI = "https://accounts.google.com/o/oauth2/auth?scope=email%20profile&response_type=code&";
                     $backendURI .= "client_id=" . $googleplus_client_id;
                     $backendURI .= "&redirect_uri=" . $this->getRedirectURI("googleplus");
                 }
             }
         }
     }
     return $backendURI;
 }
Example #2
0
 /**
  * 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();
 }
Example #3
0
 /**
  * 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();
 }
Example #4
0
  function getTemplateFileName () {
    $request = CRM_Utils_System::currentPath();
    if (false !== strpos($request, '..')) {
      die ("SECURITY FATAL: the url can't contain '..'. Please report the issue on the forum at civicrm.org");
    }

    $request = split ('/',$request);
    $tplfile = NULL;
    $smarty= CRM_Core_Smarty::singleton( );
    $smarty->assign("options",array());
    if (CRM_Utils_Array::value(2, $request)) {
      $tplfile = _civicrm_api_get_camel_name($request[2]);
      $tplfile = explode('?', $tplfile);
      $tpl = 'dataviz/'.$tplfile[0].'.tpl';
    }
    if (CRM_Utils_Array::value(3, $request)) {
      $r3 = _civicrm_api_get_camel_name($request[3]);
      $smarty->assign("id",$r3);
    }
    if (!$tplfile) {
      $tpl = "CRM/Civizualise/Page/Main.tpl";
    }
    if( !$smarty->template_exists($tpl) ){
      header("Status: 404 Not Found");
      die ("Can't find the requested template file templates/$tpl");
    }
    return $tpl;
  }
Example #5
0
 /**  
  * The pager constructor. Takes a few values, and then assigns a lot of defaults
  * to the PEAR pager class
  * We have embedded some html in this class. Need to figure out how to export this
  * to the top level at some point in time
  *
  * @param int     total        the total count of items to be displayed
  * @param int     currentPage  the page currently being displayed
  * @param string  status       the status message to be displayed. It embeds a token
  *                             %%statusMessage%% that will be replaced with which items
  *                             are currently being displayed
  * @param string  csvString    the title of the link to be displayed for the export
  * @param int     perPage      the number of items displayed per page
  *
  * @return object              the newly created and initialized pager object
  *
  * @access public
  *
  */
 function __construct($params)
 {
     if ($params['status'] === null) {
         $params['status'] = ts('Contacts %%StatusMessage%%');
     }
     $params['path'] = CRM_Utils_System::makeURL(CRM_Utils_System::currentPath());
     $this->initialize($params);
     $this->Pager_Sliding($params);
     list($offset, $limit) = $this->getOffsetAndRowCount();
     $start = $offset + 1;
     $end = $offset + $limit;
     if ($end > $params['total']) {
         $end = $params['total'];
     }
     if ($params['total'] == 0) {
         $statusMessage = '';
     } else {
         $statusMessage = ts('%1 - %2 of %3', array(1 => $start, 2 => $end, 3 => $params['total']));
     }
     $params['status'] = str_replace('%%StatusMessage%%', $statusMessage, $params['status']);
     $this->_response = array('first' => $this->_printFirstPage(), 'back' => str_replace(' ', '', $this->_getBackLink()), 'next' => str_replace(' ', '', $this->_getNextLink()), 'last' => $this->_printLastPage(), 'currentPage' => $this->getCurrentPageID(), 'numPages' => $this->numPages(), 'csvString' => CRM_Utils_Array::value('csvString', $params), 'status' => CRM_Utils_Array::value('status', $params), 'buttonTop' => CRM_Utils_Array::value('buttonTop', $params), 'buttonBottom' => CRM_Utils_Array::value('buttonBottom', $params), 'twentyfive' => $this->getPerPageLink(25), 'fifty' => $this->getPerPageLink(50), 'onehundred' => $this->getPerPageLink(100));
     /**
      * A page cannot have two variables with the same form name. Hence in the 
      * pager display, we have a form submission at the top with the normal
      * page variable, but a different form element for one at the bottom
      *
      */
     $this->_response['titleTop'] = ts('Page %1 of %2', array(1 => '<input size="2" maxlength="3" name="' . self::PAGE_ID . '" type="text" value="' . $this->_response['currentPage'] . '" />', 2 => $this->_response['numPages']));
     $this->_response['titleBottom'] = ts('Page %1 of %2', array(1 => '<input size="2" maxlength="3" name="' . self::PAGE_ID_BOTTOM . '" type="text" value="' . $this->_response['currentPage'] . '" />', 2 => $this->_response['numPages']));
 }
 function &actionLinks()
 {
     // check if variable _actionsLinks is populated
     if (!isset(self::$_actionLinks)) {
         // helper variable for nicer formatting
         $deleteExtra = ts('Are you sure you want to delete this Widget?');
         self::$_actionLinks = array(CRM_Core_Action::UPDATE => array('name' => ts('View and Edit'), 'url' => CRM_Utils_System::currentPath(), 'qs' => 'action=update&reset=1&id=%%id%%', 'title' => ts('Update')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => CRM_Utils_System::currentPath(), 'qs' => 'action=delete&reset=1&id=%%id%%', 'title' => ts('Delete Custom Field'), 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"'));
     }
     return self::$_actionLinks;
 }
Example #7
0
 /**
  * Get the action links for this page.
  *
  * @param null
  *
  * @return  array   array of action links that we need to display for the browse screen
  * @access public
  */
 static function &actionLinks()
 {
     // check if variable _actionsLinks is populated
     if (!isset(self::$_actionLinks)) {
         // helper variable for nicer formatting
         $deleteExtra = ts('Are you sure you want to delete this workflow?');
         $copyExtra = ts('Are you sure you want to make a copy of this workflow?');
         self::$_actionLinks = array(CRM_Core_Action::BROWSE => array('name' => ts('View and Edit Steps'), 'url' => 'civicrm/workflows/profiles', 'qs' => 'reset=1&action=browse&wid=%%wid%%', 'title' => ts('View and Edit Steps')), CRM_Core_Action::UPDATE => array('name' => ts('Settings'), 'url' => 'civicrm/workflows/update', 'qs' => 'action=update&reset=1&wid=%%wid%%', 'title' => ts('Edit Workflow Settings')), CRM_Core_Action::VIEW => array('name' => ts('Workflow Link'), 'url' => 'civicrm/workflow', 'qs' => 'wid=%%wid%%&reset=1', 'title' => ts('Link to the Workflow page')), CRM_Core_Action::DISABLE => array('name' => ts('Disable'), 'url' => CRM_Utils_System::currentPath(), 'qs' => 'action=disable&wid=%%wid%%&reset=1', 'title' => ts('Disable Workflow')), CRM_Core_Action::ENABLE => array('name' => ts('Enable'), 'url' => CRM_Utils_System::currentPath(), 'qs' => 'action=enable&wid=%%wid%%&reset=1', 'title' => ts('Enable Workflow')), CRM_Core_Action::DELETE => array('name' => ts('Delete'), 'url' => CRM_Utils_System::currentPath(), 'qs' => 'action=delete&reset=1&wid=%%wid%%', 'title' => ts('Delete Workflow'), 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"'), CRM_Core_Action::COPY => array('name' => ts('Clone Workflow'), 'url' => CRM_Utils_System::currentPath(), 'qs' => 'action=copy&reset=1&wid=%%wid%%', 'title' => ts('Make a Copy of this workflow'), 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"'));
     }
     return self::$_actionLinks;
 }
 /**
  * Process the uploaded file.
  *
  * @return void
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     $exportParams = $this->controller->exportValues('Select');
     $currentPath = CRM_Utils_System::currentPath();
     $urlParams = NULL;
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     if (CRM_Utils_Rule::qfKey($qfKey)) {
         $urlParams = "&qfKey={$qfKey}";
     }
     //get the button name
     $buttonName = $this->controller->getButtonName('done');
     $buttonName1 = $this->controller->getButtonName('next');
     if ($buttonName == '_qf_Map_done') {
         $this->set('exportColumnCount', NULL);
         $this->controller->resetPage($this->_name);
         return CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, 'force=1' . $urlParams));
     }
     if ($this->controller->exportValue($this->_name, 'addMore')) {
         $this->set('exportColumnCount', $this->_exportColumnCount);
         return;
     }
     $mapperKeys = $params['mapper'][1];
     $checkEmpty = 0;
     foreach ($mapperKeys as $value) {
         if ($value[0]) {
             $checkEmpty++;
         }
     }
     if (!$checkEmpty) {
         $this->set('mappingId', NULL);
         CRM_Utils_System::redirect(CRM_Utils_System::url($currentPath, '_qf_Map_display=true' . $urlParams));
     }
     if ($buttonName1 == '_qf_Map_next') {
         if (!empty($params['updateMapping'])) {
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $params['mappingId']);
         }
         if (!empty($params['saveMapping'])) {
             $mappingParams = array('name' => $params['saveMappingName'], 'description' => $params['saveMappingDesc'], 'mapping_type_id' => $this->get('mappingTypeId'));
             $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
             //save mapping fields
             CRM_Core_BAO_Mapping::saveMappingFields($params, $saveMapping->id);
         }
     }
     //get the csv file
     CRM_Export_BAO_Export_Relationship::exportComponents($this->get('selectAll'), $this->get('componentIds'), $this->get('queryParams'), $this->get(CRM_Utils_Sort::SORT_ORDER), $mapperKeys, $this->get('returnProperties'), $this->get('exportMode'), $this->get('componentClause'), $this->get('componentTable'), $this->get('mergeSameAddress'), $this->get('mergeSameHousehold'), $exportParams);
 }
Example #9
0
 function run()
 {
     $session = CRM_Core_Session::singleton();
     if (!CRM_Core_Permission::check(array(array('view Applicants', 'manage Applicants', 'evaluate Applicants', 'administer Vacancy', 'administer CiviCRM')))) {
         $session->pushUserContext(CRM_Utils_System::url('civicrm'));
         CRM_Core_Error::statusBounce(ts('You do not have the necessary permission to perform this action.'));
     }
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     $searchParams = array();
     foreach (array('position', 'status_id', 'location') as $searchField) {
         $searchValue = $this->get($searchField);
         if (!empty($searchValue)) {
             $searchParams[$searchField] = $searchValue;
         }
     }
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, 0, 'REQUEST');
     $this->_isTemplate = (bool) CRM_Utils_Request::retrieve('template', 'Integer', $this);
     if (isset($this->_isTemplate)) {
         $this->assign('isTemplate', $this->_isTemplate);
     }
     // what action to take ?
     if ($action & CRM_Core_Action::DELETE) {
         $session = CRM_Core_Session::singleton();
         $pathCancel = $this->_isTemplate ? "reset=1&action=browse&template={$this->_isTemplate}" : "reset=1&action=browse";
         $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $pathCancel));
         $controller = new CRM_Core_Controller_Simple('CRM_HRRecruitment_Form_Search_Delete', 'Delete Vacancy', $action);
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     }
     if ($action & CRM_Core_Action::UPDATE) {
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url('civicrm/vacancy', 'reset=1&action=browse'));
         $controller = new CRM_Core_Controller_Simple('CRM_HRRecruitment_Form_HRVacancy', 'Edit Vacancy', $action);
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     } elseif ($action & CRM_Core_Action::COPY) {
         $this->copy();
     }
     // finally browse the custom groups
     $this->browse($action, $searchParams);
     // parent run
     return parent::run();
 }
 /**
  * Generate the config js file based on posted data.
  *
  * @param array $params
  */
 public function save($params)
 {
     $config = "/**\n" . " * CKEditor config file auto-generated by CiviCRM.\n" . " *\n" . " * Note: This file will be overwritten if settings are modified at:\n" . " * @link " . CRM_Utils_System::url(CRM_Utils_System::currentPath(), NULL, TRUE, NULL, FALSE) . "\n" . " */\n\n" . preg_replace('~\\R~u', "\n", $params['config']);
     // Use defaultSettings as a whitelist so we don't just insert any old junk into the file
     foreach ($this->defaultSettings as $key => $default) {
         if (isset($params[$key]) && strlen($params[$key])) {
             $pos = strrpos($config, '};');
             $setting = "\n\tconfig.{$key} = '{$params[$key]}';\n";
             $config = substr_replace($config, $setting, $pos, 0);
         }
     }
     self::saveConfigFile($config);
     if (!empty($params['save'])) {
         CRM_Core_Session::setStatus(ts("You may need to clear your browser's cache to see the changes in CiviCRM."), ts('CKEditor Saved'), 'success');
     }
 }
Example #11
0
 function alterStateProvinceID($value, &$row, $selectedfield, $criteriaFieldName)
 {
     $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), "reset=1&force=1&{$criteriaFieldName}_op=in&{$criteriaFieldName}_value={$value}", $this->_absoluteUrl);
     $row[$selectedfield . '_link'] = $url;
     $row[$selectedfield . '_hover'] = ts("%1 for this state.", array(1 => $value));
     $states = CRM_Core_PseudoConstant::stateProvince($value, FALSE);
     if (!is_array($states)) {
         return $states;
     }
 }
Example #12
0
 /**
  * This function is to make a copy of a price set, including
  * all the fields in the page
  *
  * @return void
  * @access public
  */
 function copy()
 {
     $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, true, 0, 'GET');
     require_once 'CRM/Price/BAO/Set.php';
     CRM_Price_BAO_Set::copy($id);
     CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
 }
Example #13
0
 /**
  * Browse all event templates.
  */
 public function browse()
 {
     //get all event templates.
     $allEventTemplates = array();
     $eventTemplate = new CRM_Event_DAO_Event();
     $eventTypes = CRM_Event_PseudoConstant::eventType();
     $participantRoles = CRM_Event_PseudoConstant::participantRole();
     $participantListings = CRM_Event_PseudoConstant::participantListing();
     //find all event templates.
     $eventTemplate->is_template = TRUE;
     $eventTemplate->find();
     while ($eventTemplate->fetch()) {
         CRM_Core_DAO::storeValues($eventTemplate, $allEventTemplates[$eventTemplate->id]);
         //get listing types.
         if ($eventTemplate->participant_listing_id) {
             $allEventTemplates[$eventTemplate->id]['participant_listing'] = $participantListings[$eventTemplate->participant_listing_id];
         }
         //get participant role
         if ($eventTemplate->default_role_id) {
             $allEventTemplates[$eventTemplate->id]['participant_role'] = $participantRoles[$eventTemplate->default_role_id];
         }
         //get event type.
         if (isset($eventTypes[$eventTemplate->event_type_id])) {
             $allEventTemplates[$eventTemplate->id]['event_type'] = $eventTypes[$eventTemplate->event_type_id];
         }
         //form all action links
         $action = array_sum(array_keys($this->links()));
         //add action links.
         $allEventTemplates[$eventTemplate->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $eventTemplate->id), ts('more'), FALSE, 'eventTemplate.manage.action', 'Event', $eventTemplate->id);
     }
     $this->assign('rows', $allEventTemplates);
     $session = CRM_Core_Session::singleton();
     $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=browse'));
 }
Example #14
0
 /**
  * Make a copy of a contribution page, including all the fields in the page.
  */
 public function copy()
 {
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, TRUE, 0, 'GET');
     CRM_Contribute_BAO_ContributionPage::copy($gid);
     CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
 }
Example #15
0
 /**
  * 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');
     // default to 'browse'
     // assign vars to templates
     $this->assign('action', $action);
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0);
     // figure out whether we’re handling an event or an event template
     if ($id) {
         $this->_isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $id, 'is_template');
     } elseif ($action & CRM_Core_Action::ADD) {
         $this->_isTemplate = CRM_Utils_Request::retrieve('is_template', 'Boolean', $this);
     }
     if (!$this->_isTemplate && $id) {
         $breadCrumb = array(array('title' => ts('Manage Events'), 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')));
         CRM_Utils_System::appendBreadCrumb($breadCrumb);
     }
     // what action to take ?
     if ($action & CRM_Core_Action::ADD || $action & CRM_Core_Action::UPDATE) {
         require_once 'CRM/Event/Page/ManageEventEdit.php';
         $page = new CRM_Event_Page_ManageEventEdit();
         return $page->run();
     } else {
         if ($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_Event_Form_ManageEvent_Delete', 'Delete Event', $action);
             $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0);
             $controller->set('id', $id);
             $controller->process();
             return $controller->run();
         } else {
             if ($action & CRM_Core_Action::COPY) {
                 $this->copy();
             }
         }
     }
     // finally browse the custom groups
     $this->browse();
     // parent run
     parent::run();
 }
Example #16
0
 function setContext($id, $action)
 {
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     //we need to differentiate context for update and preview profile.
     if (!$context && !($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::PREVIEW))) {
         $context = 'group';
     }
     switch ($context) {
         case 'group':
             $url = CRM_Utils_System::url('civicrm/admin/uf/group', 'reset=1&action=browse');
             // as there is no argument after group in the url, and the context is different,
             // breadcrumb doesn't get set. And therefore setting it here -
             $breadCrumb = array(array('title' => ts('CiviCRM Profile'), 'url' => CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1')));
             CRM_Utils_System::appendBreadCrumb($breadCrumb);
             break;
         case 'field':
             $url = CRM_Utils_System::url('civicrm/admin/uf/group/field', "reset=1&action=browse&gid={$id}");
             break;
     }
     $session =& CRM_Core_Session::singleton();
     $session->pushUserContext($url);
 }
Example #17
0
 /**
  * Process the form
  *
  * @return void
  * @access public
  */
 public function postProcess()
 {
     // get the submitted form values.
     $params = $this->controller->exportValues($this->_name);
     $pageID = CRM_Utils_Request::retrieve('id', 'Positive', $this, false, 0);
     if ($this->_action & CRM_Core_Action::PREVIEW) {
         $session =& CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=update&id=' . $this->_id . '&subPage=Premium');
         $single = $session->get('singleForm');
         CRM_Utils_System::redirect($url);
         return;
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         $session =& CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=update&id=' . $this->_id . '&subPage=Premium');
         require_once 'CRM/Contribute/DAO/PremiumsProduct.php';
         $dao =& new CRM_Contribute_DAO_PremiumsProduct();
         $dao->id = $this->_pid;
         $dao->delete();
         CRM_Core_Session::setStatus(ts('Selected Premium Product has been removed from this Contribution Page.'));
         CRM_Utils_System::redirect($url);
     } else {
         $session =& CRM_Core_Session::singleton();
         $url = CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1&action=update&id=' . $this->_id . '&subPage=Premium');
         if ($this->_pid) {
             $params['id'] = $this->_pid;
         }
         require_once 'CRM/Contribute/DAO/Premium.php';
         $dao =& new CRM_Contribute_DAO_Premium();
         $dao->entity_table = 'civicrm_contribution_page';
         $dao->entity_id = $pageID;
         $dao->find(true);
         $premiumID = $dao->id;
         $params['premiums_id'] = $premiumID;
         require_once 'CRM/Contribute/DAO/PremiumsProduct.php';
         $dao =& new CRM_Contribute_DAO_PremiumsProduct();
         $dao->copyValues($params);
         $dao->save();
         CRM_Utils_System::redirect($url);
     }
 }
Example #18
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $participantStatuses = CRM_Event_PseudoConstant::participantStatus();
     $partiallyPaidStatusId = array_search('Partially paid', $participantStatuses);
     $this->assign('partiallyPaidStatusId', $partiallyPaidStatusId);
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign('additionalParticipant', $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single && $this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $eventFieldParams = array('entity' => 'event', 'select' => array('minimumInputLength' => 0), 'api' => array('extra' => array('campaign_id', 'default_role_id', 'event_type_id')));
     if ($this->_mode) {
         // exclude events which are not monetary when credit card registration is used
         $eventFieldParams['api']['params']['is_monetary'] = 1;
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
     }
     $element = $this->addEntityRef('event_id', ts('Event'), $eventFieldParams, TRUE);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
     }
     if (!$campaignId) {
         $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($eventId) {
             $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $this->addSelect('role_id', array('multiple' => TRUE, 'class' => 'huge'), TRUE);
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = NULL;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     // get the participant status names to build special status array which is used to show notification
     // checkbox below participant status select
     $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
     $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired');
     // get the required status and then implode only ids
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
     $this->_participantStatuses = $statusOptions = CRM_Event_BAO_Participant::buildOptions('status_id', 'create');
     // Only show refund status when editing
     if ($this->_action & CRM_Core_Action::ADD) {
         $pendingRefundStatusId = array_search('Pending refund', $participantStatusName);
         if ($pendingRefundStatusId) {
             unset($statusOptions[$pendingRefundStatusId]);
         }
     }
     $this->addSelect('status_id', $checkCancelledJs + array('options' => $statusOptions, 'option_url' => 'civicrm/admin/participant_status'), TRUE);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS);
     $path = CRM_Utils_System::currentPath();
     $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search');
     if (!in_array($path, $excludeForPaths)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS);
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Example #19
0
 /**
  * Get user context.
  *
  * @param null $mode
  *
  * @return string
  *   user context.
  */
 public function userContext($mode = NULL)
 {
     return CRM_Utils_System::currentPath();
 }
Example #20
0
 /**
  * Build the form object.
  */
 public function preProcess()
 {
     CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     $this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
     $this->assign('atypefile', FALSE);
     if ($this->_atypefile) {
         $this->assign('atypefile', TRUE);
     }
     $session = CRM_Core_Session::singleton();
     $this->_currentUserId = $session->get('userID');
     $this->_currentlyViewedContactId = $this->get('contactId');
     if (!$this->_currentlyViewedContactId) {
         $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     }
     $this->assign('contactId', $this->_currentlyViewedContactId);
     // Give the context.
     if (!isset($this->_context)) {
         $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
         if (CRM_Contact_Form_Search::isSearchContext($this->_context)) {
             $this->_context = 'search';
         } elseif (!in_array($this->_context, array('dashlet', 'dashletFullscreen')) && $this->_currentlyViewedContactId) {
             $this->_context = 'activity';
         }
         $this->_compContext = CRM_Utils_Request::retrieve('compContext', 'String', $this);
     }
     $this->assign('context', $this->_context);
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
     if ($this->_action & CRM_Core_Action::DELETE) {
         if (!CRM_Core_Permission::check('delete activities')) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     // CRM-6957
     // When we come from contact search, activity id never comes.
     // So don't try to get from object, it might gives you wrong one.
     // if we're not adding new one, there must be an id to
     // an activity we're trying to work on.
     if ($this->_action != CRM_Core_Action::ADD && get_class($this->controller) != 'CRM_Contact_Controller_Search') {
         $this->_activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     }
     $this->_activityTypeId = CRM_Utils_Request::retrieve('atype', 'Positive', $this);
     $this->assign('atype', $this->_activityTypeId);
     $this->assign('activityId', $this->_activityId);
     // Check for required permissions, CRM-6264.
     if ($this->_activityId && in_array($this->_action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW)) && !CRM_Activity_BAO_Activity::checkPermission($this->_activityId, $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     if ($this->_action & CRM_Core_Action::VIEW && CRM_Activity_BAO_Activity::checkPermission($this->_activityId, CRM_Core_Action::UPDATE)) {
         $this->assign('permission', 'edit');
     }
     if (!$this->_activityTypeId && $this->_activityId) {
         $this->_activityTypeId = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId, 'activity_type_id');
     }
     // Assigning Activity type name.
     if ($this->_activityTypeId) {
         $activityTName = CRM_Core_OptionGroup::values('activity_type', FALSE, FALSE, FALSE, 'AND v.value = ' . $this->_activityTypeId, 'label');
         if ($activityTName[$this->_activityTypeId]) {
             $this->_activityTypeName = $activityTName[$this->_activityTypeId];
             $this->assign('activityTName', $activityTName[$this->_activityTypeId]);
         }
     }
     // Set title.
     if (isset($activityTName)) {
         $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
         $this->assign('pageTitle', ts('%1 Activity', array(1 => $activityName)));
         if ($this->_currentlyViewedContactId) {
             $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
             // Check if this is default domain contact CRM-10482.
             if (CRM_Contact_BAO_Contact::checkDomainContact($this->_currentlyViewedContactId)) {
                 $displayName .= ' (' . ts('default organization') . ')';
             }
             CRM_Utils_System::setTitle($displayName . ' - ' . $activityName);
         } else {
             CRM_Utils_System::setTitle(ts('%1 Activity', array(1 => $activityName)));
         }
     }
     // Check the mode when this form is called either single or as
     // search task action.
     if ($this->_activityTypeId || $this->_context == 'standalone' || $this->_currentlyViewedContactId) {
         $this->_single = TRUE;
         $this->assign('urlPath', 'civicrm/activity');
     } else {
         // Set the appropriate action.
         $url = CRM_Utils_System::currentPath();
         $urlArray = explode('/', $url);
         $searchPath = array_pop($urlArray);
         $searchType = 'basic';
         $this->_action = CRM_Core_Action::BASIC;
         switch ($searchPath) {
             case 'basic':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::BASIC;
                 break;
             case 'advanced':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::ADVANCED;
                 break;
             case 'builder':
                 $searchType = $searchPath;
                 $this->_action = CRM_Core_Action::PROFILE;
                 break;
             case 'custom':
                 $this->_action = CRM_Core_Action::COPY;
                 $searchType = $searchPath;
                 break;
         }
         parent::preProcess();
         $this->_single = FALSE;
         $this->assign('urlPath', "civicrm/contact/search/{$searchType}");
         $this->assign('urlPathVar', "_qf_Activity_display=true&qfKey={$this->controller->_key}");
     }
     $this->assign('single', $this->_single);
     $this->assign('action', $this->_action);
     if ($this->_action & CRM_Core_Action::VIEW) {
         // Get the tree of custom fields.
         $this->_groupTree =& CRM_Core_BAO_CustomGroup::getTree('Activity', $this, $this->_activityId, 0, $this->_activityTypeId);
     }
     if ($this->_activityTypeId) {
         // Set activity type name and description to template.
         list($this->_activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($this->_activityTypeId);
         $this->assign('activityTypeName', $this->_activityTypeName);
         $this->assign('activityTypeDescription', $activityTypeDescription);
     }
     // set user context
     $urlParams = $urlString = NULL;
     $qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
     if (!$qfKey) {
         $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     }
     // Validate the qfKey.
     if (!CRM_Utils_Rule::qfKey($qfKey)) {
         $qfKey = NULL;
     }
     if ($this->_context == 'fulltext') {
         $keyName = '&qfKey';
         $urlParams = 'force=1';
         $urlString = 'civicrm/contact/search/custom';
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $keyName = '&key';
             $urlParams .= '&context=fulltext&action=view';
             $urlString = 'civicrm/contact/view/activity';
         }
         if ($qfKey) {
             $urlParams .= "{$keyName}={$qfKey}";
         }
         $this->assign('searchKey', $qfKey);
     } elseif (in_array($this->_context, array('standalone', 'home', 'dashlet', 'dashletFullscreen'))) {
         $urlParams = 'reset=1';
         $urlString = 'civicrm/dashboard';
     } elseif ($this->_context == 'search') {
         $urlParams = 'force=1';
         if ($qfKey) {
             $urlParams .= "&qfKey={$qfKey}";
         }
         $path = CRM_Utils_System::currentPath();
         if ($this->_compContext == 'advanced') {
             $urlString = 'civicrm/contact/search/advanced';
         } elseif ($path == 'civicrm/group/search' || $path == 'civicrm/contact/search' || $path == 'civicrm/contact/search/advanced' || $path == 'civicrm/contact/search/custom' || $path == 'civicrm/group/search') {
             $urlString = $path;
         } else {
             $urlString = 'civicrm/activity/search';
         }
         $this->assign('searchKey', $qfKey);
     } elseif ($this->_context != 'caseActivity') {
         $urlParams = "action=browse&reset=1&cid={$this->_currentlyViewedContactId}&selectedChild=activity";
         $urlString = 'civicrm/contact/view';
     }
     if ($urlString) {
         $session->pushUserContext(CRM_Utils_System::url($urlString, $urlParams));
     }
     // hack to retrieve activity type id from post variables
     if (!$this->_activityTypeId) {
         $this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
     }
     // when custom data is included in this page
     if (!empty($_POST['hidden_custom'])) {
         // We need to set it in the session for the code below to work.
         // CRM-3014
         // Need to assign custom data subtype to the template.
         $this->set('type', 'Activity');
         $this->set('subType', $this->_activityTypeId);
         $this->set('entityId', $this->_activityId);
         CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity', $this->_activityId);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     // add attachments part
     CRM_Core_BAO_File::buildAttachment($this, 'civicrm_activity', $this->_activityId, NULL, TRUE);
     // figure out the file name for activity type, if any
     if ($this->_activityTypeId && ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, $this->_crmDir))) {
         $this->assign('activityTypeFile', $this->_activityTypeFile);
         $this->assign('crmDir', $this->_crmDir);
     }
     $this->setFields();
     if ($this->_activityTypeFile) {
         $className = "CRM_{$this->_crmDir}_Form_Activity_{$this->_activityTypeFile}";
         $className::preProcess($this);
     }
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_activityId) && $this->_activityId) {
             $params = array('id' => $this->_activityId);
             CRM_Activity_BAO_Activity::retrieve($params, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
     }
 }
Example #21
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_id, NULL, $this->_contactId, FALSE, TRUE)) - 1;
             if ($additionalParticipant) {
                 $deleteParticipants = array(1 => ts('Delete this participant record along with associated participant record(s).'), 2 => ts('Delete only this participant record.'));
                 $this->addRadio('delete_participant', NULL, $deleteParticipants, NULL, '<br />');
                 $this->setDefaults(array('delete_participant' => 1));
                 $this->assign('additionalParticipant', $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single) {
         $urlPath = 'civicrm/contact/view/participant';
         $urlParams = "reset=1&cid={$this->_contactId}&context=participant";
         if ($this->_context == 'standalone') {
             CRM_Contact_Form_NewContact::buildQuickForm($this);
             $urlParams = 'reset=1&context=standalone';
             $urlPath = 'civicrm/participant/add';
         }
         if ($this->_id) {
             $urlParams .= "&action=update&id={$this->_id}";
         } else {
             $urlParams .= "&action=add";
         }
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $url = CRM_Utils_System::url($urlPath, $urlParams, FALSE, NULL, FALSE);
     } else {
         $currentPath = CRM_Utils_System::currentPath();
         $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', FALSE, NULL, FALSE);
     }
     $this->assign('refreshURL', $url);
     $this->add('hidden', 'past_event');
     $events = array();
     if ($this->_eID) {
         $eventEndDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $this->_eID, 'end_date');
     }
     $this->assign('past', 0);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $events = CRM_Event_BAO_Event::getEvents(1, FALSE, FALSE);
     } elseif ($this->getElementValue('past_event') || isset($eventEndDate) && CRM_Utils_Date::currentDBDate() > CRM_Utils_Date::processDate($eventEndDate)) {
         $pastval = $this->getElementValue('past_event');
         $events = CRM_Event_BAO_Event::getEvents($pastval);
         $this->assign('past', $pastval);
     } else {
         $events = CRM_Event_BAO_Event::getEvents();
     }
     if ($this->_mode) {
         //unset the event which are not monetary when credit card
         //event registration is used
         foreach ($events as $key => $val) {
             $isPaid = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $key, 'is_monetary');
             if (!$isPaid) {
                 unset($events[$key]);
             }
         }
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, TRUE);
     }
     // build array(event -> eventType) mapper
     $query = "\nSELECT     civicrm_event.id as id, civicrm_event.event_type_id as event_type_id\nFROM       civicrm_event\nWHERE      civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0";
     $dao = CRM_Core_DAO::executeQuery($query);
     $eventAndTypeMapping = array();
     while ($dao->fetch()) {
         $eventAndTypeMapping[$dao->id] = $dao->event_type_id;
     }
     $eventAndTypeMapping = json_encode($eventAndTypeMapping);
     // building of mapping ends --
     //inherit the campaign from event.
     $eventCampaigns = array();
     $allEventIds = array_keys($events);
     if (!empty($allEventIds)) {
         CRM_Core_PseudoConstant::populate($eventCampaigns, 'CRM_Event_DAO_Event', TRUE, 'campaign_id');
     }
     $eventCampaigns = json_encode($eventCampaigns);
     $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, TRUE, array('onchange' => "buildFeeBlock( this.value ); CRM.buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} ); buildParticipantRole( this.value ); buildEventTypeCustomData( this.value, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' ); loadCampaign( this.value, {$eventCampaigns} );", 'class' => 'huge'));
     // CRM-6111
     // note that embedding JS within PHP files is quite awful, IMO
     // but we do the same for the onChange element and this form is complex
     // and i did not want to break it late in the 3.2 cycle
     $preloadJSSnippet = NULL;
     if (CRM_Utils_Array::value('reset', $_GET) && $this->_eID) {
         $preloadJSSnippet = "\ncj(function() {\ncj('#event_id').val( '{$this->_eID}' );\nbuildFeeBlock( {$this->_eID} );\nCRM.buildCustomData( 'Participant', {$this->_eID}, {$this->_eventNameCustomDataTypeID} );\nbuildEventTypeCustomData( {$this->_eID}, {$this->_eventTypeCustomDataTypeID}, '{$eventAndTypeMapping}' );\nloadCampaign( {$this->_eID}, {$eventCampaigns} );\n});\n";
     }
     $this->assign('preloadJSSnippet', $preloadJSSnippet);
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_id) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_id, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Participant', $this->_id, 'campaign_id');
     }
     if (!$campaignId) {
         $eventId = CRM_Utils_Request::retrieve('eid', 'Positive', $this);
         if ($eventId) {
             $campaignId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventId, 'campaign_id');
         }
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     $this->addDateTime('register_date', ts('Registration Date'), TRUE, array('formatType' => 'activityDateTime'));
     if ($this->_id) {
         $this->assign('entityID', $this->_id);
     }
     $roleids = CRM_Event_PseudoConstant::participantRole();
     foreach ($roleids as $rolekey => $rolevalue) {
         $roleTypes[] = $this->createElement('checkbox', $rolekey, NULL, $rolevalue, array('onclick' => "showCustomData( 'Participant', {$rolekey}, {$this->_roleCustomDataTypeID} );"));
     }
     $this->addGroup($roleTypes, 'role_id', ts('Participant Role'));
     $this->addRule('role_id', ts('Role is required'), 'required');
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     $confirmJS = NULL;
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     // get the participant status names to build special status array which is used to show notification
     // checkbox below participant status select
     $participantStatusName = CRM_Event_PseudoConstant::participantStatus();
     $notificationStatuses = array('Cancelled', 'Pending from waitlist', 'Pending from approval', 'Expired');
     // get the required status and then implode only ids
     $notificationStatusIds = implode(',', array_keys(array_intersect($participantStatusName, $notificationStatuses)));
     $this->assign('notificationStatusIds', $notificationStatusIds);
     $this->_participantStatuses = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + $this->_participantStatuses, TRUE, $checkCancelledJs);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), NULL);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $buttons[] = array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE, 'js' => $confirmJS);
     $path = CRM_Utils_System::currentPath();
     $excludeForPaths = array('civicrm/contact/search', 'civicrm/group/search');
     if (!in_array($path, $excludeForPaths)) {
         $buttons[] = array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS);
     }
     $buttons[] = array('type' => 'cancel', 'name' => ts('Cancel'));
     $this->addButtons($buttons);
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Example #22
0
 /**
  * create the links
  *
  * @param array  $query          The form values for search
  * @param string $sortByCharacter The character that we are potentially sorting on
  *
  * @return array with links
  * @access private
  * @static
  */
 static function createLinks(&$query, $sortByCharacter, $isDAO)
 {
     $AToZBar = self::getStaticCharacters();
     $dynamicAlphabets = self::getDynamicCharacters($query, $isDAO);
     if (!$dynamicAlphabets) {
         return NULL;
     }
     $AToZBar = array_merge($AToZBar, $dynamicAlphabets);
     sort($AToZBar, SORT_STRING);
     $AToZBar = array_unique($AToZBar);
     //get the current path
     $path = CRM_Utils_System::currentPath();
     $qfKey = null;
     if (isset($query->_formValues)) {
         $qfKey = CRM_Utils_Array::value('qfKey', $query->_formValues);
     }
     if (empty($qfKey)) {
         $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this, FALSE, NULL, $_REQUEST);
     }
     $aToZBar = array();
     foreach ($AToZBar as $key => $link) {
         if ($link === NULL) {
             continue;
         }
         $element = array();
         if (in_array($link, $dynamicAlphabets)) {
             $klass = '';
             if ($link == $sortByCharacter) {
                 $element['class'] = "active";
                 $klass = 'class="active"';
             }
             $url = CRM_Utils_System::url($path, "force=1&qfKey={$qfKey}&sortByCharacter=");
             // we do it this way since we want the url to be encoded but not the link character
             // since that seems to mess up drupal utf-8 encoding etc
             $url .= urlencode($link);
             $element['item'] = sprintf('<a href="%s" %s>%s</a>', $url, $klass, $link);
         } else {
             $element['item'] = $link;
         }
         $aToZBar[] = $element;
     }
     $url = sprintf('<a href="%s">%s</a>', CRM_Utils_System::url($path, "force=1&qfKey={$qfKey}&sortByCharacter=all"), ts('All'));
     $aToZBar[] = array('item' => $url);
     return $aToZBar;
 }
Example #23
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $params = $this->controller->exportValues($this->_name);
     //format params
     $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
     $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true);
     $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false);
     $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false);
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false);
     $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false);
     $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false);
     $params['id'] = $this->_id;
     //new event, so lets set the created_id
     if ($this->_action & CRM_Core_Action::ADD) {
         $session =& CRM_Core_Session::singleton();
         $params['created_id'] = $session->get('userID');
         $params['created_date'] = date('YmdHis');
     }
     $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params));
     $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event');
     require_once 'CRM/Event/BAO/Event.php';
     // copy all not explicitely set $params keys from the template (if it should be sourced)
     if (CRM_Utils_Array::value('template_id', $params)) {
         $defaults = array();
         $templateParams = array('id' => $params['template_id']);
         CRM_Event_BAO_Event::retrieve($templateParams, $defaults);
         unset($defaults['id']);
         unset($defaults['default_fee_id']);
         unset($defaults['default_discount_fee_id']);
         foreach ($defaults as $key => $value) {
             if (!isset($params[$key])) {
                 $params[$key] = $value;
             }
         }
     }
     $event = CRM_Event_BAO_Event::create($params);
     // now that we have the event’s id, do some more template-based stuff
     if (CRM_Utils_Array::value('template_id', $params)) {
         // copy event fees
         $ogParams = array('name' => "civicrm_event.amount.{$event->id}");
         $defaults = array();
         require_once 'CRM/Core/BAO/OptionGroup.php';
         if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) {
             // Copy the Main Event Fees
             CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id);
             // Copy the Discount option Group and Values
             require_once 'CRM/Core/BAO/Discount.php';
             $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event");
             foreach ($optionGroupIds as $id) {
                 $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label');
                 CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix);
             }
         }
         // copy price sets if any
         require_once 'CRM/Price/BAO/Set.php';
         $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']);
         if ($priceSetId) {
             CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId);
         }
         // link profiles if none linked
         $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         require_once 'CRM/Core/BAO/UFJoin.php';
         if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) {
             CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id));
         }
         // if no Tell-a-Friend defined, check whether there’s one for template and copy if so
         $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id);
         require_once 'CRM/Friend/BAO/Friend.php';
         if (!CRM_Friend_BAO_Friend::getValues($tafParams)) {
             $tafParams['entity_id'] = $params['template_id'];
             if (CRM_Friend_BAO_Friend::getValues($tafParams)) {
                 $tafParams['entity_id'] = $event->id;
                 CRM_Friend_BAO_Friend::addTellAFriend($tafParams);
             }
         }
     }
     $this->set('id', $event->id);
     if ($this->_action & CRM_Core_Action::ADD) {
         $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}";
         // special case for 'Save and Done' consistency.
         if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") {
             $urlParam = "action=update&reset=1&id={$event->id}";
             CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle())));
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam));
     }
     parent::endPostProcess();
 }
Example #24
0
 /**
  * Browse all rule groups.
  */
 public function run()
 {
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0);
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 0);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $session = CRM_Core_Session::singleton();
     $contactIds = $session->get('selectedSearchContactIds');
     if ($context == 'search' || !empty($contactIds)) {
         $context = 'search';
         $this->assign('backURL', $session->readUserContext());
     }
     if ($action & CRM_Core_Action::RENEW) {
         // empty cache
         $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
         if ($rgid) {
             $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
             $cacheKeyString = "merge {$contactType}";
             $cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
             $cacheKeyString .= $gid ? "_{$gid}" : '_0';
             CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKeyString);
         }
         $urlQry = "reset=1&action=update&rgid={$rgid}";
         if ($gid) {
             $urlQry .= "&gid={$gid}";
         }
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry));
     } elseif ($action & CRM_Core_Action::MAP) {
         // do a batch merge if requested
         $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
         $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', TRUE, 75);
         $skippedCount = CRM_Utils_Request::retrieve('skipped', 'Positive', $this, FALSE, 0);
         $skippedCount = $skippedCount + count($result['skipped']);
         $mergedCount = CRM_Utils_Request::retrieve('merged', 'Positive', $this, FALSE, 0);
         $mergedCount = $mergedCount + count($result['merged']);
         if (empty($result['merged']) && empty($result['skipped'])) {
             $message = '';
             if ($mergedCount >= 1) {
                 $message = ts("%1 pairs of duplicates were merged", array(1 => $mergedCount));
             }
             if ($skippedCount >= 1) {
                 $message = $message ? "{$message} and " : '';
                 $message .= ts("%1 pairs of duplicates were skipped due to conflict", array(1 => $skippedCount));
             }
             $message .= ts(" during the batch merge process with safe mode.");
             CRM_Core_Session::setStatus($message, ts('Merge Complete'), 'success');
             $urlQry = "reset=1&action=update&rgid={$rgid}";
             if ($gid) {
                 $urlQry .= "&gid={$gid}";
             }
             CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry));
         } else {
             $urlQry = "reset=1&action=map&rgid={$rgid}";
             if ($gid) {
                 $urlQry .= "&gid={$gid}";
             }
             $urlQry .= "&skipped={$skippedCount}&merged={$mergedCount}";
             CRM_Utils_System::jsRedirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry), ts('Batch Merge Task in progress'), ts('The batch merge task is still in progress. This page will be refreshed automatically.'));
         }
     }
     if ($action & CRM_Core_Action::UPDATE || $action & CRM_Core_Action::BROWSE) {
         $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
         $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
         $this->action = CRM_Core_Action::UPDATE;
         //calculate the $contactType
         if ($rgid) {
             $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
         }
         $sourceParams = 'snippet=4';
         if ($gid) {
             $sourceParams .= "&gid={$gid}";
         }
         if ($rgid) {
             $sourceParams .= "&rgid={$rgid}";
         }
         if ($context == 'conflicts') {
             $sourceParams .= "&selected=1";
         }
         $this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/dedupefind', $sourceParams, FALSE, NULL, FALSE));
         //reload from cache table
         $cacheKeyString = "merge {$contactType}";
         $cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
         $cacheKeyString .= $gid ? "_{$gid}" : '_0';
         $stats = CRM_Dedupe_Merger::getMergeStatsMsg($cacheKeyString);
         if ($stats) {
             CRM_Core_Session::setStatus($stats);
             // reset so we not displaying same message again
             CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
         }
         $join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND\n                                                                 pn.entity_id2 = de.contact_id2 )";
         $where = "de.id IS NULL";
         if ($context == 'conflicts') {
             $where .= " AND pn.is_selected = 1";
         }
         $this->_mainContacts = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where);
         if (empty($this->_mainContacts)) {
             if ($context == 'conflicts') {
                 // if the current screen was intended to list only selected contacts, move back to full dupe list
                 $sourceParams = 'reset=1&action=update';
                 if ($gid) {
                     $sourceParams .= "&gid={$gid}";
                 }
                 if ($rgid) {
                     $sourceParams .= "&rgid={$rgid}";
                 }
                 CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $sourceParams));
             }
             if ($gid) {
                 $foundDupes = $this->get("dedupe_dupes_{$gid}");
                 if (!$foundDupes) {
                     $foundDupes = CRM_Dedupe_Finder::dupesInGroup($rgid, $gid);
                 }
                 $this->set("dedupe_dupes_{$gid}", $foundDupes);
             } elseif (!empty($contactIds)) {
                 $foundDupes = $this->get("search_dedupe_dupes_{$gid}");
                 if (!$foundDupes) {
                     $foundDupes = CRM_Dedupe_Finder::dupes($rgid, $contactIds);
                 }
                 $this->get("search_dedupe_dupes_{$gid}", $foundDupes);
             } else {
                 $foundDupes = $this->get('dedupe_dupes');
                 if (!$foundDupes) {
                     $foundDupes = CRM_Dedupe_Finder::dupes($rgid);
                 }
                 $this->set('dedupe_dupes', $foundDupes);
             }
             if (!$foundDupes) {
                 $ruleGroup = new CRM_Dedupe_BAO_RuleGroup();
                 $ruleGroup->id = $rgid;
                 $ruleGroup->find(TRUE);
                 $session = CRM_Core_Session::singleton();
                 $session->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroup->name)), ts('None Found'), 'info');
                 $url = CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1');
                 if ($context == 'search') {
                     $url = $session->readUserContext();
                 }
                 CRM_Utils_System::redirect($url);
             } else {
                 $cids = array();
                 foreach ($foundDupes as $dupe) {
                     $cids[$dupe[0]] = 1;
                     $cids[$dupe[1]] = 1;
                 }
                 $cidString = implode(', ', array_keys($cids));
                 $sql = "SELECT id, display_name FROM civicrm_contact WHERE id IN ({$cidString}) ORDER BY sort_name";
                 $dao = new CRM_Core_DAO();
                 $dao->query($sql);
                 $displayNames = array();
                 while ($dao->fetch()) {
                     $displayNames[$dao->id] = $dao->display_name;
                 }
                 // FIXME: sort the contacts; $displayName
                 // is already sort_name-sorted, so use that
                 // (also, consider sorting by dupe count first)
                 // lobo - change the sort to by threshold value
                 // so the more likely dupes are sorted first
                 $session = CRM_Core_Session::singleton();
                 $userId = $session->get('userID');
                 $mainContacts = $permission = array();
                 foreach ($foundDupes as $dupes) {
                     $srcID = $dupes[0];
                     $dstID = $dupes[1];
                     if ($dstID == $userId) {
                         $srcID = $dupes[1];
                         $dstID = $dupes[0];
                     }
                     /***
                      * Eliminate this since it introduces 3 queries PER merge row
                      * and hence is very expensive
                      * CRM-8822
                      * if ( !array_key_exists( $srcID, $permission ) ) {
                      * $permission[$srcID] = CRM_Contact_BAO_Contact_Permission::allow( $srcID, CRM_Core_Permission::EDIT );
                      * }
                      * if ( !array_key_exists( $dstID, $permission ) ) {
                      * $permission[$dstID] = CRM_Contact_BAO_Contact_Permission::allow( $dstID, CRM_Core_Permission::EDIT );
                      * }
                      *
                      * $canMerge = ( $permission[$dstID] && $permission[$srcID] );
                      *
                      */
                     // we'll do permission checking during the merge process
                     $canMerge = TRUE;
                     $mainContacts[] = $row = array('srcID' => $srcID, 'srcName' => $displayNames[$srcID], 'dstID' => $dstID, 'dstName' => $displayNames[$dstID], 'weight' => $dupes[2], 'canMerge' => $canMerge);
                     $data = CRM_Core_DAO::escapeString(serialize($row));
                     $values[] = " ( 'civicrm_contact', {$srcID}, {$dstID}, '{$cacheKeyString}', '{$data}' ) ";
                 }
                 if ($cid) {
                     $this->_cid = $cid;
                 }
                 if ($gid) {
                     $this->_gid = $gid;
                 }
                 $this->_rgid = $rgid;
                 $this->_mainContacts = $mainContacts;
                 CRM_Core_BAO_PrevNextCache::setItem($values);
                 $session = CRM_Core_Session::singleton();
                 if ($this->_cid) {
                     $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/deduperules', "action=update&rgid={$this->_rgid}&gid={$this->_gid}&cid={$this->_cid}"));
                 } else {
                     $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind', "reset=1&action=update&rgid={$this->_rgid}"));
                 }
             }
         } else {
             if ($cid) {
                 $this->_cid = $cid;
             }
             if ($gid) {
                 $this->_gid = $gid;
             }
             $this->_rgid = $rgid;
         }
         $this->assign('action', $this->action);
         $this->browse();
     } else {
         $this->action = CRM_Core_Action::UPDATE;
         $this->edit($this->action);
         $this->assign('action', $this->action);
     }
     $this->assign('context', $context);
     // parent run
     return parent::run();
 }
Example #25
0
 /**
  * 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.
  *
  * @param
  * @return void
  * @access public
  */
 function run()
 {
     // get the requested action
     $action = CRM_Utils_Request::retrieve('action', 'String', $this, false, 'browse');
     if ($action & CRM_Core_Action::REVERT) {
         $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false);
         CRM_Contribute_BAO_PCP::setIsActive($id, 0);
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
     } elseif ($action & CRM_Core_Action::RENEW) {
         $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false);
         CRM_Contribute_BAO_PCP::setIsActive($id, 1);
         $session = CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
     } elseif ($action & CRM_Core_Action::DELETE) {
         $id = CRM_Utils_Request::retrieve('id', 'Positive', $this, false);
         $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_Contribute_Form_PCP_PCP', 'Personal Campaign Page', CRM_Core_Action::DELETE);
         //$this->setContext( $id, $action );
         $controller->set('id', $id);
         $controller->process();
         return $controller->run();
     }
     // finally browse
     $this->browse();
     // parent run
     parent::run();
 }
Example #26
0
 /** 
  * Function to build the form 
  * 
  * @return None 
  * @access public 
  */
 public function buildQuickForm()
 {
     if ($this->_showFeeBlock) {
         return CRM_Event_Form_EventFees::buildQuickForm($this);
     }
     if ($this->_cdType) {
         return CRM_Custom_Form_CustomData::buildQuickForm($this);
     }
     //need to assign custom data type to the template
     $this->assign('customDataType', 'Participant');
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         if ($this->_single) {
             require_once 'CRM/Event/BAO/Event.php';
             $additionalParticipant = count(CRM_Event_BAO_Event::buildCustomProfile($this->_participantId, null, $this->_contactID, false, true)) - 1;
             if ($additionalParticipant) {
                 $this->assign("additionalParticipant", $additionalParticipant);
             }
         }
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_single) {
         $urlPath = 'civicrm/contact/view/participant';
         $urlParams = "reset=1&cid={$this->_contactID}&context=participant";
         if ($this->_context == 'standalone') {
             require_once 'CRM/Contact/Form/NewContact.php';
             CRM_Contact_Form_NewContact::buildQuickForm($this);
             $urlParams = "reset=1&context=standalone";
             $urlPath = 'civicrm/participant/add';
         }
         if ($this->_participantId) {
             $urlParams .= "&action=update&id={$this->_participantId}";
         } else {
             $urlParams .= "&action=add";
         }
         if (CRM_Utils_Request::retrieve('past', 'Boolean', $this)) {
             $urlParams .= "&past=true";
         }
         if ($this->_mode) {
             $urlParams .= "&mode={$this->_mode}";
         }
         $url = CRM_Utils_System::url($urlPath, $urlParams, false, null, false);
     } else {
         $currentPath = CRM_Utils_System::currentPath();
         $url = CRM_Utils_System::url($currentPath, '_qf_Participant_display=true', false, null, false);
     }
     $this->assign("refreshURL", $url);
     $url .= "&past=true";
     $this->assign("pastURL", $url);
     $events = array();
     $this->assign("past", false);
     require_once "CRM/Event/BAO/Event.php";
     if (CRM_Utils_Request::retrieve('past', 'Boolean', $this) || $this->_action & CRM_Core_Action::UPDATE) {
         $events = CRM_Event_BAO_Event::getEvents(true);
         $this->assign("past", true);
     } else {
         $events = CRM_Event_BAO_Event::getEvents();
     }
     if ($this->_mode) {
         //unset the event which are not monetary when credit card
         //event registration is used
         foreach ($events as $key => $val) {
             $isPaid = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Event", $key, 'is_monetary');
             if (!$isPaid) {
                 unset($events[$key]);
             }
         }
         $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, true);
     }
     $element = $this->add('select', 'event_id', ts('Event'), array('' => ts('- select -')) + $events, true, array('onchange' => "buildFeeBlock( this.value ); buildCustomData( 'Participant', this.value, {$this->_eventNameCustomDataTypeID} );", 'class' => 'huge'));
     //frozen the field fix for CRM-4171
     if ($this->_action & CRM_Core_Action::UPDATE && $this->_participantId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $this->_participantId, 'contribution_id', 'participant_id')) {
             $element->freeze();
         }
     }
     $this->addDateTime('register_date', ts('Registration Date'), true);
     if ($this->_participantId) {
         $this->assign('entityID', $this->_participantId);
     }
     $this->add('select', 'role_id', ts('Participant Role'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantRole(), true, array('onchange' => "buildCustomData( 'Participant', this.value, {$this->_roleCustomDataTypeID} );"));
     // CRM-4395
     $checkCancelledJs = array('onchange' => "return sendNotification( );");
     if ($this->_onlinePendingContributionId) {
         $cancelledparticipantStatusId = array_search('Cancelled', CRM_Event_PseudoConstant::participantStatus());
         $cancelledContributionStatusId = array_search('Cancelled', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'));
         $checkCancelledJs = array('onchange' => "checkCancelled( this.value, {$cancelledparticipantStatusId},{$cancelledContributionStatusId});");
     }
     $this->add('select', 'status_id', ts('Participant Status'), array('' => ts('- select -')) + CRM_Event_PseudoConstant::participantStatus(null, null, 'label'), true, $checkCancelledJs);
     $this->addElement('checkbox', 'is_notify', ts('Send Notification'), null);
     $this->add('text', 'source', ts('Event Source'));
     $noteAttributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_Note');
     $this->add('textarea', 'note', ts('Notes'), $noteAttributes['note']);
     $confirmJS = null;
     if ($this->_onlinePendingContributionId) {
         $participantStatusId = array_search('Pending from pay later', CRM_Event_PseudoConstant::participantStatus());
         $contributionStatusId = array_search('Completed', CRM_Contribute_PseudoConstant::contributionStatus(null, 'name'));
         $confirmJS = array('onclick' => "return confirmStatus( {$participantStatusId}, {$contributionStatusId} );");
     }
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => true, 'js' => $confirmJS), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new', 'js' => $confirmJS), array('type' => 'cancel', 'name' => ts('Cancel'))));
     if ($this->_action == CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
 /**
  * Build the form object.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildQuickForm(&$form)
 {
     if ($form->_eventId) {
         $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
         if ($form->_isPaidEvent) {
             $form->addElement('hidden', 'hidden_feeblock', 1);
         }
         // make sure this is for backoffice registration.
         if ($form->getName() == 'Participant') {
             $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
             $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
         }
     }
     if ($form->_pId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $form->_pId, 'contribution_id', 'participant_id')) {
             $form->_online = TRUE;
         }
     }
     if ($form->_isPaidEvent) {
         $params = array('id' => $form->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $event);
         //retrieve custom information
         $form->_values = array();
         CRM_Event_Form_Registration::initEventFee($form, $event['id']);
         CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
         $lineItem = array();
         $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         $totalTaxAmount = 0;
         if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
             $lineItem[] = $form->_values['line_items'];
             foreach ($form->_values['line_items'] as $key => $value) {
                 $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
             }
         }
         if ($invoicing) {
             $form->assign('totalTaxAmount', $totalTaxAmount);
         }
         $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
         $discounts = array();
         if (!empty($form->_values['discount'])) {
             foreach ($form->_values['discount'] as $key => $value) {
                 $value = current($value);
                 $discounts[$key] = $value['name'];
             }
             $element = $form->add('select', 'discount_id', ts('Discount Set'), array(0 => ts('- select -')) + $discounts, FALSE, array('class' => "crm-select2"));
             if ($form->_online) {
                 $element->freeze();
             }
         }
         if ($form->_mode) {
             CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE);
         } elseif (!$form->_mode) {
             $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"));
             $form->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::financialType());
             $form->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDate'));
             $form->add('select', 'payment_instrument_id', ts('Paid By'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
             // don't show transaction id in batch update mode
             $path = CRM_Utils_System::currentPath();
             $form->assign('showTransactionId', FALSE);
             if ($path != 'civicrm/contact/search/basic') {
                 $form->add('text', 'trxn_id', ts('Transaction ID'));
                 $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'));
                 $form->assign('showTransactionId', TRUE);
             }
             $status = CRM_Contribute_PseudoConstant::contributionStatus();
             // CRM-14417 suppressing contribution statuses that are NOT relevant to new participant registrations
             $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach (array('Cancelled', 'Failed', 'In Progress', 'Overdue', 'Refunded', 'Pending refund') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
             $form->add('select', 'contribution_status_id', ts('Payment Status'), $status);
             $form->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
             $form->add('text', 'total_amount', ts('Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount'));
         }
     } else {
         $form->add('text', 'amount', ts('Event Fee(s)'));
     }
     $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
     $form->assign('paid', $form->_isPaidEvent);
     $form->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), NULL, array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"));
     $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);
     $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
     // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
     if ($form->_context != 'standalone') {
         if ($form->_contactId) {
             list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
             $form->assign('email', $form->_contributorEmail);
         } else {
             //show email block for batch update for event
             $form->assign('batchEmail', TRUE);
         }
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $form->assign('outBound_option', $mailingInfo['outBound_option']);
     $form->assign('hasPayment', $form->_paymentId);
 }
Example #28
0
 /**
  * This function is to make a copy of a contribution page, including
  * all the fields in the page
  *
  * @return void
  * @access public
  */
 function copy()
 {
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, true, 0, 'GET');
     require_once 'CRM/Contribute/BAO/ContributionPage.php';
     CRM_Contribute_BAO_ContributionPage::copy($gid);
     CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
 }
Example #29
0
 function getLoginDestination(&$form)
 {
     $args = NULL;
     $id = $form->get('id');
     if ($id) {
         $args .= "&id={$id}";
     } else {
         $gid = $form->get('gid');
         if ($gid) {
             $args .= "&gid={$gid}";
         } else {
             // Setup Personal Campaign Page link uses pageId
             $pageId = $form->get('pageId');
             if ($pageId) {
                 $component = $form->get('component');
                 $args .= "&pageId={$pageId}&component={$component}&action=add";
             }
         }
     }
     $destination = NULL;
     if ($args) {
         // append destination so user is returned to form they came from after login
         $destination = CRM_Utils_System::currentPath() . '?reset=1' . $args;
     }
     return $destination;
 }
Example #30
0
 /**
  * Get user context.
  *
  * @return string user context.
  */
 function userContext($mode = null)
 {
     return CRM_Utils_System::currentPath();
 }