Exemplo n.º 1
0
 function run()
 {
     if (array_key_exists("action", $_GET)) {
         switch ($_GET['action']) {
             case 'enable':
                 CRM_Workflow_BAO_Workflow::setIsActive($_GET['wid'], true);
                 break;
             case 'disable':
                 CRM_Workflow_BAO_Workflow::setIsActive($_GET['wid'], false);
                 break;
             case 'delete':
                 CRM_Workflow_BAO_Workflow::del($_GET['wid']);
                 break;
             case 'copy':
                 CRM_Workflow_BAO_Workflow::copy($_GET['wid']);
                 break;
         }
     }
     CRM_Utils_System::setTitle(ts('Workflows'));
     $this->assign('rows', CRM_Workflow_BAO_Workflow::getWorkflows());
     parent::run();
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 function postProcess()
 {
     $params = $this->controller->exportValues('Workflow');
     $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_wid;
     }
     $wf = CRM_Workflow_BAO_Workflow::add($params);
     CRM_Core_Session::setStatus(ts('The workflow \'%1\' has been saved.', array(1 => $wf->name)), "Saved", "success");
     //die(var_dump($tmp));
     parent::postProcess();
     return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/workflows'));
 }
Exemplo n.º 4
0
/**
 * 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)));
                }
            }
        }
    }
}
Exemplo n.º 5
0
 static function copy($wid)
 {
     $sql = "SELECT * FROM civicrm_workflow WHERE id = {$wid}";
     $dao =& CRM_Core_DAO::executeQuery($sql);
     if ($dao->fetch()) {
         $workflow = (array) $dao;
         $workflow['id'] = null;
         $new_workflow = CRM_Workflow_BAO_Workflow::add($workflow);
         $sql2 = "SELECT * FROM civicrm_workflow_detail WHERE workflow_id = {$wid}";
         $dao2 =& CRM_Core_DAO::executeQuery($sql2);
         $nsql = "INSERT INTO civicrm_workflow_detail (id, workflow_id, entity_table, entity_id, `order`, breadcrumb) VALUES ";
         $nid = $new_workflow->id;
         while ($dao2->fetch()) {
             $did = 0;
             $eid = $dao2->entity_id;
             $e_type = $dao2->entity_table;
             $order = $dao2->order;
             $breadcrumb = $dao2->breadcrumb;
             $nsql .= "({$did}, {$nid}, '{$e_type}', {$eid}, {$order}, '{$breadcrumb}'),";
         }
         $nsql = substr($nsql, 0, -1);
         $dao =& CRM_Core_DAO::executeQuery($nsql);
     }
 }