function run() { CRM_Utils_System::setTitle(""); $wid = CRM_Utils_Request::retrieve('wid', 'Positive', $this, false, 0); $workflow = null; $steps = array(); if ($wid) { $workflow = CRM_Workflow_BAO_Workflow::getWorkflow($wid); $steps = CRM_Workflow_BAO_Workflow::getWorkflowDetails($wid, false); $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); if ($workflow['is_active']) { //If this workflow contains a contribution page forward to it //And the page injector will take over if ($workflow['contains_page'] && ($workflow['require_login'] && $userID || !$workflow['require_login']) && !($steps[1]['entity_table'] == "Profile" && $steps[1]['entity_id'] == $workflow['login_form_id'])) { return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contribute/transact', 'reset=1&id=' . $step['entity_id'])); } //Let the page know the method we are using CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('method' => "template"))); //Add Stylesheet CRM_Core_Resources::singleton()->addStyleFile('org.botany.workflow', 'workflow_execute.css'); //Add Javascript files and settings CRM_Core_Resources::singleton()->addScriptFile('org.botany.workflow', 'workflow_execute.js'); CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('steps' => $steps))); //Set the width for the step lis $stepWidth = empty($steps) ? 98 : round(98 / sizeof($steps), 0, PHP_ROUND_HALF_DOWN); CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('breadcrumWidth' => $stepWidth))); //Assign the data so smarty can use it $this->assign('workflow', $workflow); $this->assign('steps', $steps); } else { $this->assign('error', "I'm sorry, this workflow has been disabled"); } } parent::run(); }
/** * Implementation of hook_civicrm_buildForm * * @param $formName string, the name of the form * @param $form object, a reference to the form object * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_buildForm */ function workflow_civicrm_buildForm($formName, &$form) { if ($formName == "CRM_Contribute_Form_Contribution_Main") { if (array_key_exists("workflow", $_GET) && $_GET['workflow'] == 0) { return; } $allPages = CRM_Workflow_BAO_Workflow::getWorkflowPages(true); if (array_key_exists($form->_id, $allPages)) { //We have a page to inject into so Load up the workflow $workflow = CRM_Workflow_BAO_Workflow::getWorkflow($allPages[$form->_id]); if ($workflow['is_active']) { $steps = CRM_Workflow_BAO_Workflow::getWorkflowDetails($allPages[$form->_id], false); //If we require login forward to workflow page and it will forward it back here. if ($workflow['require_login']) { //If the login form selected is also the first one in the list we can just load the page. if ($steps[1]['entity_table'] == "Profile" && $steps[1]['entity_id'] == $workflow['login_form_id']) { if ($form->_contactID) { unset($steps[1]); } } else { if (!$form->contactID) { return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/workflow', 'reset=1&wid=' . $allPages[$form->_id]['workflow_id'])); } } } //Inject the needed resources into the page //Let the page know we are injecting into a page rather than loading a template. CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('method' => "inject"))); //Add Stylesheet CRM_Core_Resources::singleton()->addStyleFile('org.botany.workflow', 'workflow_execute.css'); //Add JS Libraries if we need them for notifications. if (!CRM_Core_Permission::check('access CiviCRM')) { $notiFile = CRM_Core_Resources::singleton()->getUrl('civicrm', "packages/jquery/plugins/jquery.notify.min.js", true); CRM_Core_Resources::singleton()->addScriptUrl($notiFile, -2, 'html-header'); $blockFile = CRM_Core_Resources::singleton()->getUrl('civicrm', "packages/jquery/plugins/jquery.blockUI.min.js", true); CRM_Core_Resources::singleton()->addScriptUrl($blockFile, -1, 'html-header'); } //Add Javascript files and settings CRM_Core_Resources::singleton()->addScriptFile('org.botany.workflow', 'workflow_execute.js', 20, 'page-footer'); CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('steps' => $steps))); //Set the width for the step lis $stepWidth = empty($steps) ? 98 : round(98 / sizeof($steps), 0, PHP_ROUND_HALF_DOWN); CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('breadcrumWidth' => $stepWidth))); $jquerySteps = ""; $lastStep = 1; foreach ($steps as $step) { if ($step['entity_table'] == "jQuery") { $jquerySteps[] = $step['entity_id']; $lastStep = $step['order']; } } $jqueryTotal = $jquerySteps ? implode(",", $jquerySteps) : false; CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('allSelector' => $jqueryTotal))); CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('lastStep' => $lastStep))); //If we are returning to the form. if (!empty($form->_submitValues)) { CRM_Core_Resources::singleton()->addSetting(array('Workflow' => array('returning' => true))); } } } } }