Commit 844c9524 authored by Peter Droogmans's avatar Peter Droogmans
Browse files

renamed variables

parent b31abd6d
...@@ -88,23 +88,23 @@ function clientside_validation_general_settings_form($form_id, $form_state) { ...@@ -88,23 +88,23 @@ function clientside_validation_general_settings_form($form_id, $form_state) {
return $form; return $form;
} }
function clientside_validation_settings_form($form, $form_state, $cvsid = NULL, $type = 'default') { function clientside_validation_settings_form($form, $form_state, $cvs_formid = NULL, $cvs_type = 'default') {
$settings = clientside_validation_settings_load($cvsid, $type); $settings = clientside_validation_settings_load($cvs_type, $cvs_formid);
$form['new'] = array( $form['new'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => FALSE, '#value' => FALSE,
); );
if (!$settings || $settings['settings'] === FALSE || ($type != 'default' && empty($settings['form_id']))) { if (!$settings || $settings['settings'] === FALSE || ($cvs_type != 'default' && empty($settings['form_id']))) {
$settings = clientside_validation_settings_load_defaults(); $settings = clientside_validation_settings_load_defaults();
drupal_set_title(clientside_validation_settings_title($type, $cvsid, FALSE), PASS_THROUGH); drupal_set_title(clientside_validation_settings_title($cvs_type, $cvs_formid, FALSE), PASS_THROUGH);
$form['new'] = array( $form['new'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => TRUE, '#value' => TRUE,
); );
} }
else { else {
drupal_set_title(clientside_validation_settings_title($type, $settings['form_id'], TRUE), PASS_THROUGH); drupal_set_title(clientside_validation_settings_title($cvs_type, $cvs_formid, TRUE), PASS_THROUGH);
} }
// Make sure settings aren't nested. // Make sure settings aren't nested.
...@@ -113,13 +113,13 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL, ...@@ -113,13 +113,13 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL,
} }
$form['#tree'] = TRUE; $form['#tree'] = TRUE;
$form['cvsid'] = array( $form['cvs_formid'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $cvsid, '#value' => $cvs_formid,
); );
$form['cvstype'] = array( $form['cvs_type'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $type, '#value' => $cvs_type,
); );
//Validate options //Validate options
...@@ -359,7 +359,7 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL, ...@@ -359,7 +359,7 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL,
fields (e.g. conditional fields), those will be validated too.'), fields (e.g. conditional fields), those will be validated too.'),
'#weight' => 3, '#weight' => 3,
); );
if ($type == 'default') { if ($cvs_type == 'default') {
$form['include_hidden']['include_hidden'] = array( $form['include_hidden']['include_hidden'] = array(
'#type' => 'textarea', '#type' => 'textarea',
'#default_value' => $settings['include_hidden']['include_hidden'], '#default_value' => $settings['include_hidden']['include_hidden'],
...@@ -405,8 +405,8 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL, ...@@ -405,8 +405,8 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL,
function clientside_validation_settings_form_submit($form, &$form_state) { function clientside_validation_settings_form_submit($form, &$form_state) {
$values = $form_state['values']; $values = $form_state['values'];
$type = $values['cvstype']; $cvs_type = $values['cvs_type'];
$cvsid = $values['cvsid']; $cvs_formid = $values['cvs_formid'];
$new = $values['new']; $new = $values['new'];
unset($values['submit']); unset($values['submit']);
...@@ -414,11 +414,11 @@ function clientside_validation_settings_form_submit($form, &$form_state) { ...@@ -414,11 +414,11 @@ function clientside_validation_settings_form_submit($form, &$form_state) {
unset($values['form_token']); unset($values['form_token']);
unset($values['form_id']); unset($values['form_id']);
unset($values['op']); unset($values['op']);
unset($values['cvstype']); unset($values['cvs_type']);
unset($values['cvsid']); unset($values['cvs_formid']);
unset($values['new']); unset($values['new']);
if ($type == 'default') { if ($cvs_type == 'default') {
variable_set('clientside_validation_default_settings', $values); variable_set('clientside_validation_default_settings', $values);
} }
else { else {
...@@ -429,10 +429,10 @@ function clientside_validation_settings_form_submit($form, &$form_state) { ...@@ -429,10 +429,10 @@ function clientside_validation_settings_form_submit($form, &$form_state) {
} }
} }
if (!$new) { if (!$new) {
clientside_validation_settings_update($cvsid, $values); clientside_validation_settings_update($cvs_type, $cvs_formid, $values);
} }
else { else {
clientside_validation_settings_add($type, $cvsid, $values); clientside_validation_settings_add($cvs_type, $cvs_formid, $values);
} }
} }
} }
...@@ -444,11 +444,11 @@ function _cv_setting_status($status) { ...@@ -444,11 +444,11 @@ function _cv_setting_status($status) {
return t('Disabled'); return t('Disabled');
} }
function clientside_validation_settings_overview($form, $form_state, $type) { function clientside_validation_settings_overview($form, $form_state, $cvs_type) {
$form = array(); $form = array();
$settings = clientside_validation_settings_load(NULL, $type); $settings = clientside_validation_settings_load($cvs_type);
switch ($type) { switch ($cvs_type) {
case 'content-types': case 'content-types':
$destination = array('destination' => 'admin/config/validation/clientside_validation/content-types'); $destination = array('destination' => 'admin/config/validation/clientside_validation/content-types');
$settinguri = 'admin/config/validation/clientside_validation/content-types/'; $settinguri = 'admin/config/validation/clientside_validation/content-types/';
...@@ -497,9 +497,9 @@ function clientside_validation_settings_overview($form, $form_state, $type) { ...@@ -497,9 +497,9 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
'label' => $customform->form_id, 'label' => $customform->form_id,
); );
} }
$form['cvstype'] = array( $form['cvs_type'] = array(
'#type' => 'value', '#type' => 'value',
'#value' => $type, '#value' => $cvs_type,
); );
$form['add_formid'] = array( $form['add_formid'] = array(
'#type' => 'fieldset', '#type' => 'fieldset',
...@@ -508,7 +508,7 @@ function clientside_validation_settings_overview($form, $form_state, $type) { ...@@ -508,7 +508,7 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
'#title' => t('Add a new custom form'), '#title' => t('Add a new custom form'),
'#description' => t('Enter the formid of the form you want to override.'), '#description' => t('Enter the formid of the form you want to override.'),
); );
$form['add_formid']['cvsid'] = array( $form['add_formid']['cvs_formid'] = array(
'#title' => t('Form Id'), '#title' => t('Form Id'),
'#type' => 'textfield', '#type' => 'textfield',
); );
...@@ -526,22 +526,22 @@ function clientside_validation_settings_overview($form, $form_state, $type) { ...@@ -526,22 +526,22 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
$row = array(); $row = array();
$row[] = $definedform['label']; $row[] = $definedform['label'];
if (isset($settings[$definedform['id']]) && $settings[$definedform['id']]->status) { if (isset($settings[$definedform['id']]) && $settings[$definedform['id']]->status) {
$cvsid = $settings[$definedform['id']]->cvsid; $cvs_formid = check_plain($definedform['id']);
$row[] = _cv_setting_status(TRUE); $row[] = _cv_setting_status(TRUE);
$actions = array( $actions = array(
'edit' => array( 'edit' => array(
'title' => t('edit'), 'title' => t('edit'),
'href' => $settinguri . $cvsid . '/edit', 'href' => $settinguri . $cvs_formid . '/edit',
'query' => $destination, 'query' => $destination,
), ),
'disable' => array( 'disable' => array(
'title' => t('disable'), 'title' => t('disable'),
'href' => $settinguri . $cvsid . '/disable', 'href' => $settinguri . $cvs_formid . '/disable',
'query' => $destination, 'query' => $destination,
), ),
'delete' => array( 'delete' => array(
'title' => t('delete'), 'title' => t('delete'),
'href' => $settinguri . $cvsid . '/delete', 'href' => $settinguri . $cvs_formid . '/delete',
'query' => $destination, 'query' => $destination,
), ),
); );
...@@ -549,21 +549,21 @@ function clientside_validation_settings_overview($form, $form_state, $type) { ...@@ -549,21 +549,21 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
else { else {
$row[] = _cv_setting_status(FALSE); $row[] = _cv_setting_status(FALSE);
if (isset($settings[$definedform['id']])) { if (isset($settings[$definedform['id']])) {
$cvsid = $settings[$definedform['id']]->cvsid; $cvs_formid = check_plain($definedform['id']);
$actions = array( $actions = array(
'edit' => array( 'edit' => array(
'title' => t('edit'), 'title' => t('edit'),
'href' => $settinguri . $cvsid . '/edit', 'href' => $settinguri . $cvs_formid . '/edit',
'query' => $destination, 'query' => $destination,
), ),
'enable' => array( 'enable' => array(
'title' => t('enable'), 'title' => t('enable'),
'href' => $settinguri . $cvsid . '/enable', 'href' => $settinguri . $cvs_formid . '/enable',
'query' => $destination, 'query' => $destination,
), ),
'delete' => array( 'delete' => array(
'title' => t('delete'), 'title' => t('delete'),
'href' => $settinguri . $cvsid . '/delete', 'href' => $settinguri . $cvs_formid . '/delete',
'query' => $destination, 'query' => $destination,
), ),
); );
...@@ -607,16 +607,15 @@ function clientside_validation_settings_overview($form, $form_state, $type) { ...@@ -607,16 +607,15 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
function clientside_validation_settings_overview_submit($form, &$form_state) { function clientside_validation_settings_overview_submit($form, &$form_state) {
$values = $form_state['values']; $values = $form_state['values'];
$type = $values['cvstype']; $cvs_type = $values['cvs_type'];
$cvsid = $values['cvsid']; $cvs_formid = $values['cvs_formid'];
clientside_validation_settings_add($type, $cvsid); clientside_validation_settings_add($cvs_type, $cvs_formid);
} }
function clientside_validation_settings_confirmation_form($form, &$form_state, $cvsid, $type, $action) { function clientside_validation_settings_confirmation_form($form, &$form_state, $cvs_formid, $cvs_type, $action) {
$settings = clientside_validation_settings_load(); $form['#cvs_action'] = $action;
$form['#cvaction'] = $action; $form['#cvs_type'] = $cvs_type;
$form['#cvtype'] = $type; $form['#cvs_formid'] = $cvs_formid;
$form['#cvsid'] = $cvsid;
switch ($action) { switch ($action) {
case 'delete': case 'delete':
...@@ -645,18 +644,21 @@ function clientside_validation_settings_confirmation_form($form, &$form_state, $ ...@@ -645,18 +644,21 @@ function clientside_validation_settings_confirmation_form($form, &$form_state, $
function clientside_validation_settings_confirmation_form_submit($form, &$form_state) { function clientside_validation_settings_confirmation_form_submit($form, &$form_state) {
if ($form_state['values']['confirm']) { if ($form_state['values']['confirm']) {
$action = $form['#cvaction']; $action = $form['#cvs_action'];
$type = $form['#cvtype']; $cvs_type = $form['#cvs_type'];
$cvsid = $form['#cvsid']; $cvs_formid = $form['#cvs_formid'];
switch ($action) { switch ($action) {
case 'delete': case 'delete':
clientside_validation_settings_delete($cvsid); clientside_validation_settings_delete($cvs_type, $cvs_formid);
break;
case 'enable': case 'enable':
clientside_validation_settings_enable($cvsid); clientside_validation_settings_enable($cvs_type, $cvs_formid);
break;
case 'disable': case 'disable':
//clientside_validation_settings_disable($cvsid); clientside_validation_settings_disable($cvs_type, $cvs_formid);
break;
} }
$form_state['redirect'] = 'admin/config/validation/clientside_validation/' . $type; $form_state['redirect'] = 'admin/config/validation/clientside_validation/' . $cvs_type;
} }
} }
...@@ -188,7 +188,7 @@ function clientside_validation_form_alter(&$form, &$form_state, $form_id) { ...@@ -188,7 +188,7 @@ function clientside_validation_form_alter(&$form, &$form_state, $form_id) {
} }
if (strpos($form_id, 'webform_client_form') !== FALSE) { if (strpos($form_id, 'webform_client_form') !== FALSE) {
$definedsettings = clientside_validation_settings_load(NULL, 'webforms', $form['#node']->nid); $definedsettings = clientside_validation_settings_load('webforms', $form['#node']->nid);
clientside_validation_settings_current_form($definedsettings); clientside_validation_settings_current_form($definedsettings);
if (isset($form['actions']['previous'])) { if (isset($form['actions']['previous'])) {
$form['actions']['previous']['#attributes']['class'][] = 'cancel'; $form['actions']['previous']['#attributes']['class'][] = 'cancel';
...@@ -197,10 +197,10 @@ function clientside_validation_form_alter(&$form, &$form_state, $form_id) { ...@@ -197,10 +197,10 @@ function clientside_validation_form_alter(&$form, &$form_state, $form_id) {
} }
else { else {
if (isset($form['#node_edit_form']) && $form['#node_edit_form']) { if (isset($form['#node_edit_form']) && $form['#node_edit_form']) {
$definedsettings = clientside_validation_settings_load(NULL, 'content-types', $form['#node']->type); $definedsettings = clientside_validation_settings_load('content-types', $form['#node']->type);
} }
else { else {
$definedsettings = clientside_validation_settings_load(NULL, 'content-types', $form_id); $definedsettings = clientside_validation_settings_load('content-types', $form_id);
} }
clientside_validation_settings_current_form($definedsettings); clientside_validation_settings_current_form($definedsettings);
if (isset($form['actions']['delete'])) { if (isset($form['actions']['delete'])) {
...@@ -1097,35 +1097,38 @@ function theme_clientside_error($variables) { ...@@ -1097,35 +1097,38 @@ function theme_clientside_error($variables) {
return t($variables['message'], $variables['placeholders']); return t($variables['message'], $variables['placeholders']);
} }
function clientside_validation_settings_delete($cvsid) { function clientside_validation_settings_delete($cvs_type, $cvs_formid) {
db_delete('clientside_validation_settings') db_delete('clientside_validation_settings')
->condition('cvsid', $cvsid) ->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute(); ->execute();
} }
function clientside_validation_settings_enable($cvsid) { function clientside_validation_settings_enable($cvs_type, $cvs_formid) {
db_update('clientside_validation_settings') db_update('clientside_validation_settings')
->fields(array( ->fields(array(
'status' => 1, 'status' => 7,
)) ))
->condition('cvsid', $cvsid) ->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute(); ->execute();
} }
function clientside_validation_settings_disable($cvsid) { function clientside_validation_settings_disable($cvs_type, $cvs_formid) {
db_update('clientside_validation_settings') db_update('clientside_validation_settings')
->fields(array( ->fields(array(
'status' => 0, 'status' => 0,
)) ))
->condition('cvsid', $cvsid) ->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute(); ->execute();
} }
function clientside_validation_settings_add($type, $cvsid, $settings = array(), $enable = FALSE) { function clientside_validation_settings_add($cvs_type, $cvs_formid, $settings = array(), $enable = FALSE) {
return db_merge('clientside_validation_settings') db_merge('clientside_validation_settings')
->key(array( ->key(array(
'type' => $type, 'type' => $cvs_type,
'form_id' => $cvsid, 'form_id' => $cvs_formid,
)) ))
->fields(array( ->fields(array(
'status' => $enable ? 1 : 0, 'status' => $enable ? 1 : 0,
...@@ -1134,40 +1137,40 @@ function clientside_validation_settings_add($type, $cvsid, $settings = array(), ...@@ -1134,40 +1137,40 @@ function clientside_validation_settings_add($type, $cvsid, $settings = array(),
->execute(); ->execute();
} }
function clientside_validation_settings_update($cvsid, $settings) { function clientside_validation_settings_update($cvs_type, $cvs_formid, $settings) {
db_update('clientside_validation_settings') db_update('clientside_validation_settings')
->fields(array( ->fields(array(
'settings' => serialize($settings), 'settings' => serialize($settings),
)) ))
->condition('cvsid', $cvsid) ->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute(); ->execute();
} }
function clientside_validation_settings_title($type, $form_id, $edit = TRUE) { function clientside_validation_settings_title($cvs_type, $cvs_formid, $edit = TRUE) {
$title = 'Edit settings of %formid'; $title = 'Edit settings of %formid';
if (!$edit) { if (!$edit) {
$title = 'Create settings for %formid'; $title = 'Create settings for %formid';
} }
switch ($type) { switch ($cvs_type) {
case 'content-types': case 'content-types':
$content_types = node_type_get_types(); $content_types = node_type_get_types();
if (isset($content_types[$form_id])) { if (isset($content_types[$cvs_formid])) {
return t($title, array('%formid' => t($content_types[$form_id]->name))); return t($title, array('%formid' => t($content_types[$cvs_formid]->name)));
} }
break; break;
case 'webforms': case 'webforms':
dpm($form_id, $type); $node = node_load($cvs_formid);
$node = node_load($form_id);
if ($node) { if ($node) {
return t($title, array('%formid' => $node->title)); return t($title, array('%formid' => $node->title));
} }
break; break;
case 'custom-forms': case 'custom-forms':
return t($title, array('%formid' => $form_id)); return t($title, array('%formid' => $cvs_formid));
break; break;
} }
return t($title, array('%formid' => $type)); return t($title, array('%formid' => $cvs_type));
} }
function clientside_validation_settings_current_form($settings = NULL) { function clientside_validation_settings_current_form($settings = NULL) {
...@@ -1184,13 +1187,13 @@ function clientside_validation_settings_current_form($settings = NULL) { ...@@ -1184,13 +1187,13 @@ function clientside_validation_settings_current_form($settings = NULL) {
function clientside_validation_settings_load_defaults() { function clientside_validation_settings_load_defaults() {
static $defaults; static $defaults;
if (!$defaults) { if (!$defaults) {
$defaults = clientside_validation_settings_load(NULL, 'default'); $defaults = clientside_validation_settings_load('default');
} }
return $defaults; return $defaults;
} }
function clientside_validation_settings_load($cvsid = NULL, $type = NULL, $form_id = NULL) { function clientside_validation_settings_load($cvs_type = NULL, $cvs_formid = NULL) {
if ($type == 'default') { if ($cvs_type == 'default') {
$default_settings = array( $default_settings = array(
'validate_options' => array( 'validate_options' => array(
'disable_html5' => 1, 'disable_html5' => 1,
...@@ -1222,20 +1225,17 @@ function clientside_validation_settings_load($cvsid = NULL, $type = NULL, $form_ ...@@ -1222,20 +1225,17 @@ function clientside_validation_settings_load($cvsid = NULL, $type = NULL, $form_
} }
$query = db_select('clientside_validation_settings') $query = db_select('clientside_validation_settings')
->fields('clientside_validation_settings'); ->fields('clientside_validation_settings');
if (!empty($cvsid)) { if (!empty($cvs_type)) {
$query->condition('cvsid', $cvsid); $query->condition('type', $cvs_type);
} }
if (!empty($type)) { if (!empty($cvs_formid)) {
$query->condition('type', $type); $query->condition('form_id', $cvs_formid);
}
if (!empty($form_id)) {
$query->condition('form_id', $form_id);
} }
$result = $query->execute(); $result = $query->execute();
// a single id was given -> one result, so only return one row // a single id was given -> one result, so only return one row
if (is_numeric($cvsid) || isset($form_id)) { if (isset($cvs_formid)) {
$res = $result->fetchAssoc(); $res = $result->fetchAssoc();
if ($res) { if ($res) {
$res['settings'] = unserialize($res['settings']); $res['settings'] = unserialize($res['settings']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment