Ejemplo n.º 1
0
/**
 * Mandatory action, handles basic housekeeping
 */
function connect_action_basic(&$parent, &$child, $op = '', $target = 'parent')
{
    switch ($op) {
        case 'requires':
            $return = array();
            $default = connect_node_options($parent->nid, 'debug_hooks');
            $default = $default ? $default : 'no';
            $return['variables']['debug_hooks'] = array('#type' => 'radios', '#title' => t('Turn on debugging?'), '#description' => t('This option turns on a display of debugging messages that can be useful when troubleshooting connect problems. (Don\'t bother turning this on unless you are a developer.)'), '#options' => array('yes' => 'Yes', 'no' => 'No'), '#default_value' => $default, '#required' => TRUE);
            $types = connect_participant_types_options();
            $types[0] = '';
            asort($types);
            $return['variables']['participant_type'] = array('#type' => 'select', '#title' => 'Participant node type', '#options' => $types, '#default_value' => connect_node_options($parent->nid, 'participant_type'), '#required' => TRUE);
            $return['variables']['participant_title'] = array('#type' => 'textfield', '#title' => 'Title for the participants', '#default_value' => connect_node_options($parent->nid, 'participant_title'), '#required' => TRUE);
            $return['variables']['call_to_action'] = array('#type' => 'textfield', '#title' => 'Call to action', '#default_value' => connect_node_options($parent->nid, 'call_to_action'), '#required' => TRUE);
            $return['variables']['thankyou'] = array('#type' => 'textarea', '#size' => 4, '#title' => 'Thank-you message', '#default_value' => connect_node_options($parent->nid, 'thankyou'), '#required' => TRUE);
            return $return;
            break;
        case 'status':
            // display 'thank you' message
            if (isset($_SESSION['connect_action_thanks_' . $parent->nid])) {
                unset($_SESSION['connect_action_thanks_' . $parent->nid]);
                $message = connect_node_options($parent->nid, 'thankyou');
                return array('status' => $message, 'show_form' => FALSE);
            }
            break;
        case 'insert':
            if ($target != 'child') {
                break;
            }
            // create parent-child mapping
            $sql = "INSERT INTO {connect_data} (nid,pid) VALUES (%d,%d);";
            db_query($sql, $child->nid, $parent->nid);
            // record fact of current user's participation
            $_SESSION['connect_action_basic_' . $parent->nid] = TRUE;
            $_SESSION['connect_action_thanks_' . $parent->nid] = TRUE;
            break;
        case 'delete':
            if ($target != 'child') {
                break;
            }
            // delete parent-child mapping
            $sql = "DELETE FROM {connect_data} WHERE nid=%d;";
            db_query($sql, $child->nid);
            break;
    }
}
Ejemplo n.º 2
0
/**
 * Mandatory action, handles basic housekeeping
 */
function connect_action_basic(&$parent, &$child, $op = '', $target = 'parent')
{
    switch ($op) {
        case 'requires':
            $return = array();
            $default = connect_node_options($parent->nid, 'debug_hooks');
            $default = $default ? $default : 'no';
            $return['variables']['debug_hooks'] = array('#type' => 'radios', '#title' => t('Turn on debugging?'), '#description' => t('This option turns on a display of debugging messages that can be useful when troubleshooting connect problems. (Don\'t bother turning this on unless you are a developer.)'), '#options' => array('yes' => 'Yes', 'no' => 'No'), '#default_value' => $default, '#required' => TRUE);
            $types = connect_participant_types_options();
            $types[0] = '';
            asort($types);
            $return['variables']['participant_type'] = array('#type' => 'select', '#title' => 'Participant node type', '#options' => $types, '#default_value' => connect_node_options($parent->nid, 'participant_type'), '#required' => TRUE);
            $return['variables']['participant_title'] = array('#type' => 'textfield', '#title' => 'Title for the participants', '#default_value' => connect_node_options($parent->nid, 'participant_title'), '#required' => TRUE);
            $return['variables']['call_to_action'] = array('#type' => 'textfield', '#title' => 'Call to action', '#default_value' => connect_node_options($parent->nid, 'call_to_action'), '#required' => TRUE);
            $thank_you_description = t('This message will be shown when the action is complete.  You can use the following placeholders, which will be filled in from the information they fill out:');
            $child_type = connect_node_options($parent->nid, 'participant_type');
            $child_fields = _connect_get_child_fields($child_type);
            foreach ($child_fields as $field_name => $field_label) {
                if (!empty($field_name)) {
                    $thank_you_description .= " %{$field_name}% ";
                }
            }
            $return['variables']['thankyou'] = array('#type' => 'textarea', '#size' => 4, '#title' => 'Thank-you message', '#default_value' => connect_node_options($parent->nid, 'thankyou'), '#description' => $thank_you_description, '#required' => TRUE);
            return $return;
            break;
        case 'status':
            // display 'thank you' message
            if (isset($_SESSION['connect_action_thanks_' . $parent->nid])) {
                $message = $_SESSION['connect_action_thanks_' . $parent->nid];
                unset($_SESSION['connect_action_thanks_' . $parent->nid]);
                return array('status' => $message, 'show_form' => FALSE);
            }
            break;
        case 'insert':
            if ($target != 'child') {
                break;
            }
            // create parent-child mapping
            $sql = "INSERT INTO {connect_data} (nid,pid) VALUES (%d,%d);";
            db_query($sql, $child->nid, $parent->nid);
            // record fact of current user's participation
            $message = connect_node_options($parent->nid, 'thankyou');
            // @TODO - this would probably be better done with the token module.
            $child_type = connect_node_options($parent->nid, 'participant_type');
            $child_fields = _connect_get_child_fields($child_type);
            foreach ($child_fields as $fieldName => $fieldLabel) {
                if (!empty($fieldName)) {
                    $fieldPath = _connect_get_field_path($child, $fieldName);
                    eval("\$fieldValue = \$child" . $fieldPath . ";");
                    $message = str_replace('%' . $fieldName . '%', $fieldValue, $message);
                }
            }
            $_SESSION['connect_action_basic_' . $parent->nid] = TRUE;
            $_SESSION['connect_action_thanks_' . $parent->nid] = $message;
            break;
        case 'delete':
            if ($target != 'child') {
                break;
            }
            // delete parent-child mapping
            $sql = "DELETE FROM {connect_data} WHERE nid=%d;";
            db_query($sql, $child->nid);
            break;
    }
}