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) {
return $form;
}
function clientside_validation_settings_form($form, $form_state, $cvsid = NULL, $type = 'default') {
$settings = clientside_validation_settings_load($cvsid, $type);
function clientside_validation_settings_form($form, $form_state, $cvs_formid = NULL, $cvs_type = 'default') {
$settings = clientside_validation_settings_load($cvs_type, $cvs_formid);
$form['new'] = array(
'#type' => 'value',
'#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();
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(
'#type' => 'value',
'#value' => TRUE,
);
}
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.
......@@ -113,13 +113,13 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL,
}
$form['#tree'] = TRUE;
$form['cvsid'] = array(
$form['cvs_formid'] = array(
'#type' => 'value',
'#value' => $cvsid,
'#value' => $cvs_formid,
);
$form['cvstype'] = array(
$form['cvs_type'] = array(
'#type' => 'value',
'#value' => $type,
'#value' => $cvs_type,
);
//Validate options
......@@ -359,7 +359,7 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL,
fields (e.g. conditional fields), those will be validated too.'),
'#weight' => 3,
);
if ($type == 'default') {
if ($cvs_type == 'default') {
$form['include_hidden']['include_hidden'] = array(
'#type' => 'textarea',
'#default_value' => $settings['include_hidden']['include_hidden'],
......@@ -405,8 +405,8 @@ function clientside_validation_settings_form($form, $form_state, $cvsid = NULL,
function clientside_validation_settings_form_submit($form, &$form_state) {
$values = $form_state['values'];
$type = $values['cvstype'];
$cvsid = $values['cvsid'];
$cvs_type = $values['cvs_type'];
$cvs_formid = $values['cvs_formid'];
$new = $values['new'];
unset($values['submit']);
......@@ -414,11 +414,11 @@ function clientside_validation_settings_form_submit($form, &$form_state) {
unset($values['form_token']);
unset($values['form_id']);
unset($values['op']);
unset($values['cvstype']);
unset($values['cvsid']);
unset($values['cvs_type']);
unset($values['cvs_formid']);
unset($values['new']);
if ($type == 'default') {
if ($cvs_type == 'default') {
variable_set('clientside_validation_default_settings', $values);
}
else {
......@@ -429,10 +429,10 @@ function clientside_validation_settings_form_submit($form, &$form_state) {
}
}
if (!$new) {
clientside_validation_settings_update($cvsid, $values);
clientside_validation_settings_update($cvs_type, $cvs_formid, $values);
}
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) {
return t('Disabled');
}
function clientside_validation_settings_overview($form, $form_state, $type) {
function clientside_validation_settings_overview($form, $form_state, $cvs_type) {
$form = array();
$settings = clientside_validation_settings_load(NULL, $type);
$settings = clientside_validation_settings_load($cvs_type);
switch ($type) {
switch ($cvs_type) {
case 'content-types':
$destination = array('destination' => '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) {
'label' => $customform->form_id,
);
}
$form['cvstype'] = array(
$form['cvs_type'] = array(
'#type' => 'value',
'#value' => $type,
'#value' => $cvs_type,
);
$form['add_formid'] = array(
'#type' => 'fieldset',
......@@ -508,7 +508,7 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
'#title' => t('Add a new custom form'),
'#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'),
'#type' => 'textfield',
);
......@@ -526,22 +526,22 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
$row = array();
$row[] = $definedform['label'];
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);
$actions = array(
'edit' => array(
'title' => t('edit'),
'href' => $settinguri . $cvsid . '/edit',
'href' => $settinguri . $cvs_formid . '/edit',
'query' => $destination,
),
'disable' => array(
'title' => t('disable'),
'href' => $settinguri . $cvsid . '/disable',
'href' => $settinguri . $cvs_formid . '/disable',
'query' => $destination,
),
'delete' => array(
'title' => t('delete'),
'href' => $settinguri . $cvsid . '/delete',
'href' => $settinguri . $cvs_formid . '/delete',
'query' => $destination,
),
);
......@@ -549,21 +549,21 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
else {
$row[] = _cv_setting_status(FALSE);
if (isset($settings[$definedform['id']])) {
$cvsid = $settings[$definedform['id']]->cvsid;
$cvs_formid = check_plain($definedform['id']);
$actions = array(
'edit' => array(
'title' => t('edit'),
'href' => $settinguri . $cvsid . '/edit',
'href' => $settinguri . $cvs_formid . '/edit',
'query' => $destination,
),
'enable' => array(
'title' => t('enable'),
'href' => $settinguri . $cvsid . '/enable',
'href' => $settinguri . $cvs_formid . '/enable',
'query' => $destination,
),
'delete' => array(
'title' => t('delete'),
'href' => $settinguri . $cvsid . '/delete',
'href' => $settinguri . $cvs_formid . '/delete',
'query' => $destination,
),
);
......@@ -607,16 +607,15 @@ function clientside_validation_settings_overview($form, $form_state, $type) {
function clientside_validation_settings_overview_submit($form, &$form_state) {
$values = $form_state['values'];
$type = $values['cvstype'];
$cvsid = $values['cvsid'];
clientside_validation_settings_add($type, $cvsid);
$cvs_type = $values['cvs_type'];
$cvs_formid = $values['cvs_formid'];
clientside_validation_settings_add($cvs_type, $cvs_formid);
}
function clientside_validation_settings_confirmation_form($form, &$form_state, $cvsid, $type, $action) {
$settings = clientside_validation_settings_load();
$form['#cvaction'] = $action;
$form['#cvtype'] = $type;
$form['#cvsid'] = $cvsid;
function clientside_validation_settings_confirmation_form($form, &$form_state, $cvs_formid, $cvs_type, $action) {
$form['#cvs_action'] = $action;
$form['#cvs_type'] = $cvs_type;
$form['#cvs_formid'] = $cvs_formid;
switch ($action) {
case 'delete':
......@@ -645,18 +644,21 @@ function clientside_validation_settings_confirmation_form($form, &$form_state, $
function clientside_validation_settings_confirmation_form_submit($form, &$form_state) {
if ($form_state['values']['confirm']) {
$action = $form['#cvaction'];
$type = $form['#cvtype'];
$cvsid = $form['#cvsid'];
$action = $form['#cvs_action'];
$cvs_type = $form['#cvs_type'];
$cvs_formid = $form['#cvs_formid'];
switch ($action) {
case 'delete':
clientside_validation_settings_delete($cvsid);
clientside_validation_settings_delete($cvs_type, $cvs_formid);
break;
case 'enable':
clientside_validation_settings_enable($cvsid);
clientside_validation_settings_enable($cvs_type, $cvs_formid);
break;
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) {
}
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);
if (isset($form['actions']['previous'])) {
$form['actions']['previous']['#attributes']['class'][] = 'cancel';
......@@ -197,10 +197,10 @@ function clientside_validation_form_alter(&$form, &$form_state, $form_id) {
}
else {
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 {
$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);
if (isset($form['actions']['delete'])) {
......@@ -1097,35 +1097,38 @@ function theme_clientside_error($variables) {
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')
->condition('cvsid', $cvsid)
->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute();
}
function clientside_validation_settings_enable($cvsid) {
function clientside_validation_settings_enable($cvs_type, $cvs_formid) {
db_update('clientside_validation_settings')
->fields(array(
'status' => 1,
'status' => 7,
))
->condition('cvsid', $cvsid)
->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute();
}
function clientside_validation_settings_disable($cvsid) {
function clientside_validation_settings_disable($cvs_type, $cvs_formid) {
db_update('clientside_validation_settings')
->fields(array(
'status' => 0,
))
->condition('cvsid', $cvsid)
->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->execute();
}
function clientside_validation_settings_add($type, $cvsid, $settings = array(), $enable = FALSE) {
return db_merge('clientside_validation_settings')
function clientside_validation_settings_add($cvs_type, $cvs_formid, $settings = array(), $enable = FALSE) {
db_merge('clientside_validation_settings')
->key(array(
'type' => $type,
'form_id' => $cvsid,
'type' => $cvs_type,
'form_id' => $cvs_formid,
))
->fields(array(
'status' => $enable ? 1 : 0,
......@@ -1134,40 +1137,40 @@ function clientside_validation_settings_add($type, $cvsid, $settings = array(),
->execute();
}
function clientside_validation_settings_update($cvsid, $settings) {
function clientside_validation_settings_update($cvs_type, $cvs_formid, $settings) {
db_update('clientside_validation_settings')
->fields(array(
'settings' => serialize($settings),
))
->condition('cvsid', $cvsid)
->condition('type', $cvs_type)
->condition('form_id', $cvs_formid)
->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';
if (!$edit) {
$title = 'Create settings for %formid';
}
switch ($type) {
switch ($cvs_type) {
case 'content-types':
$content_types = node_type_get_types();
if (isset($content_types[$form_id])) {
return t($title, array('%formid' => t($content_types[$form_id]->name)));
if (isset($content_types[$cvs_formid])) {
return t($title, array('%formid' => t($content_types[$cvs_formid]->name)));
}
break;
case 'webforms':
dpm($form_id, $type);
$node = node_load($form_id);
$node = node_load($cvs_formid);
if ($node) {
return t($title, array('%formid' => $node->title));
}
break;
case 'custom-forms':
return t($title, array('%formid' => $form_id));
return t($title, array('%formid' => $cvs_formid));
break;
}
return t($title, array('%formid' => $type));
return t($title, array('%formid' => $cvs_type));
}
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() {
static $defaults;
if (!$defaults) {
$defaults = clientside_validation_settings_load(NULL, 'default');
$defaults = clientside_validation_settings_load('default');
}
return $defaults;
}
function clientside_validation_settings_load($cvsid = NULL, $type = NULL, $form_id = NULL) {
if ($type == 'default') {
function clientside_validation_settings_load($cvs_type = NULL, $cvs_formid = NULL) {
if ($cvs_type == 'default') {
$default_settings = array(
'validate_options' => array(
'disable_html5' => 1,
......@@ -1222,20 +1225,17 @@ function clientside_validation_settings_load($cvsid = NULL, $type = NULL, $form_
}
$query = db_select('clientside_validation_settings')
->fields('clientside_validation_settings');
if (!empty($cvsid)) {
$query->condition('cvsid', $cvsid);
if (!empty($cvs_type)) {
$query->condition('type', $cvs_type);
}
if (!empty($type)) {
$query->condition('type', $type);
}
if (!empty($form_id)) {
$query->condition('form_id', $form_id);
if (!empty($cvs_formid)) {
$query->condition('form_id', $cvs_formid);
}
$result = $query->execute();
// 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();
if ($res) {
$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