home2/isose750/public_html/ajuda/admin/custom_fields.php 0000644 00000162722 14673125103 0017177 0 ustar 00 = 50 && $action !== 'edit_cf')
{
hesk_show_info($hesklang['cf_limit']);
}
$hesk_settings['datepicker']['#dmin']['position'] = 'left top';
$hesk_settings['datepicker']['#dmax']['position'] = 'left bottom';
?>
|
|
|
|
|
|
|
|
$cf) {
if ($cf['place']) {
$num_after++;
} else {
$num_before++;
}
}
$k = 1;
$first_before_custom_field = true;
$first_after_custom_field = true;
$hide_up = false;
foreach ($hesk_settings['custom_fields'] as $tmp_id => $cf) {
$tmp_id = intval(str_replace('custom', '', $tmp_id));
if ($hide_up)
{
$hide_up = false;
}
if ($first_before_custom_field && $cf['place'] == 0) {
?>
|
|
>
|
|
|
|
|
|
1)
{
if (($num_before == 1 && $cf['place'] == 0) || ($num_after == 1 && $cf['place'] == 1))
{
// Only 1 custom fields in this place, don't print anything
?>
|
$error\n";
}
$hesk_error_buffer = $tmp;
$hesk_error_buffer = $hesklang['rfm'].'
';
hesk_process_messages($hesk_error_buffer,'custom_fields.php');
}
// Add custom field data into database
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET
`use` = '{$cf['use']}',
`place` = '{$cf['place']}',
`type` = '{$cf['type']}',
`req` = '{$cf['req']}',
`category` = ".(count($cf['categories']) ? "'".json_encode($cf['categories'])."'" : 'NULL').",
`name` = '".hesk_dbEscape($cf['names'])."',
`value` = ".(strlen($cf['value']) ? "'".hesk_dbEscape($cf['value'])."'" : 'NULL')."
WHERE `id`={$id}");
// Clear cache
hesk_purge_cache('cf');
// Show success
$_SESSION['cford'] = $id;
hesk_process_messages($hesklang['cf_mdf'],'custom_fields.php','SUCCESS');
} // End save_cf()
function edit_cf()
{
global $hesk_settings, $hesklang;
// Get custom field ID
$id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']);
// Get details from the database
$res = hesk_dbQuery("SELECT * FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `id`={$id} LIMIT 1");
if ( hesk_dbNumRows($res) != 1 )
{
hesk_error($hesklang['cf_not_found']);
}
$cf = hesk_dbFetchAssoc($res);
$cf['names'] = json_decode($cf['name'], true);
unset($cf['name']);
if (isset($cf['category']) && strlen($cf['category']))
{
$cf['categories'] = json_decode($cf['category'], true);
$cf['category'] = 1;
}
else
{
$cf['categories'] = array();
$cf['category'] = 0;
}
$_SESSION['new_cf'] = $cf;
$_SESSION['edit_cf'] = true;
} // End edit_cf()
function order_cf()
{
global $hesk_settings, $hesklang;
// A security check
hesk_token_check();
// Get ID and move parameters
$id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']);
$move = intval( hesk_GET('move') );
$_SESSION['cford'] = $id;
// Update article details
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=`order`+".intval($move)." WHERE `id`={$id}");
// Update order of all custom fields
update_cf_order();
// Clear cache
hesk_purge_cache('cf');
// Finish
header('Location: custom_fields.php');
exit();
} // End order_cf()
function update_cf_order()
{
global $hesk_settings, $hesklang;
// Get list of current custom fields
$res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `use` IN ('1','2') ORDER BY `place` ASC, `order` ASC");
// Update database
$i = 10;
while ( $cf = hesk_dbFetchAssoc($res) )
{
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=".intval($i)." WHERE `id`='".intval($cf['id'])."'");
$i += 10;
}
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `order`=1000 WHERE `use`='0'");
return true;
} // END update_cf_order()
function remove_cf()
{
global $hesk_settings, $hesklang;
// A security check
hesk_token_check();
// Get ID
$id = intval( hesk_GET('id') ) or hesk_error($hesklang['cf_e_id']);
// Reset the custom field
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET `use`='0', `place`='0', `type`='text', `req`='0', `category`=NULL, `name`='', `value`=NULL, `order`=1000 WHERE `id`={$id}");
// Were we successful?
if ( hesk_dbAffectedRows() == 1 )
{
// Update order
update_cf_order();
// Clear cache
hesk_purge_cache('cf');
// Delete custom field data from tickets
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."tickets` SET `custom{$id}`='', `lastchange`=`lastchange` WHERE `custom{$id}`!=''");
// Show success message
hesk_process_messages($hesklang['cf_deleted'],'./custom_fields.php','SUCCESS');
}
else
{
hesk_process_messages($hesklang['cf_not_found'],'./custom_fields.php');
}
} // End remove_cf()
function cf_validate()
{
global $hesk_settings, $hesklang;
global $hesk_error_buffer;
$hesk_error_buffer = array();
$errors = array();
// Get names
$cf['names'] = hesk_POST_array('name');
// Make sure only valid names pass
foreach ($cf['names'] as $key => $name)
{
if ( ! isset($hesk_settings['languages'][$key]))
{
unset($cf['names'][$key]);
}
else
{
$name = is_array($name) ? '' : hesk_input($name, 0, 0, HESK_SLASH);
if (strlen($name) < 1)
{
unset($cf['names'][$key]);
}
else
{
$cf['names'][$key] = stripslashes($name);
}
}
}
// No name entered?
if ( ! count($cf['names']))
{
$hesk_error_buffer[] = $hesklang['err_custname'];
$errors[] = 'name';
}
// Get type and values
$cf['type'] = hesk_POST('type');
switch ($cf['type'])
{
case 'textarea':
$cf['rows'] = hesk_checkMinMax(intval(hesk_POST('rows')), 1, 100, 12);
$cf['cols'] = hesk_checkMinMax(intval(hesk_POST('cols')), 1, 500, 60);
$cf['value'] = array('rows' => $cf['rows'], 'cols' => $cf['cols']);
break;
case 'radio':
$cf['radio_options'] = stripslashes(hesk_input(hesk_POST('radio_options'), 0, 0, HESK_SLASH));
$options = preg_split("/\\r\\n|\\r|\\n/", $cf['radio_options']);
$no_default = hesk_POST('no_default') ? 1 : 0;
$cf['value'] = array('radio_options' => $options, 'no_default' => $no_default);
if (count($options) < 2)
{
$hesk_error_buffer[] = $hesklang['atl2'];
$errors[] = 'radio_options';
}
break;
case 'select':
$cf['select_options'] = stripslashes(hesk_input(hesk_POST('select_options'), 0, 0, HESK_SLASH));
$options = preg_split("/\\r\\n|\\r|\\n/", $cf['select_options']);
$show_select = hesk_POST('show_select') ? 1 : 0;
$cf['value'] = array('show_select' => $show_select, 'select_options' => $options);
if (count($options) < 2)
{
$hesk_error_buffer[] = $hesklang['atl2'];
$errors[] = 'select_options';
}
break;
case 'checkbox':
$cf['checkbox_options'] = stripslashes(hesk_input(hesk_POST('checkbox_options'), 0, 0, HESK_SLASH));
$options = preg_split("/\\r\\n|\\r|\\n/", $cf['checkbox_options']);
$cf['value'] = array('checkbox_options' => $options);
if ( ! isset($options[0]) || strlen($options[0]) < 1)
{
$hesk_error_buffer[] = $hesklang['atl1'];
$errors[] = 'checkbox_options';
}
break;
case 'date':
$cf['dmin'] = '';
$cf['dmax'] = '';
// Minimum date
$dmin_rf = hesk_POST('dmin_rf');
if ($dmin_rf == 1)
{
$dmin = hesk_POST('dmin');
if ($date = hesk_datepicker_get_date($dmin))
{
$dmin = $date->format('m/d/Y');
$cf['dmin'] = $dmin;
}
}
elseif ($dmin_rf == 2)
{
$dmin_pm = hesk_POST('dmin_pm') == '+' ? '+' : '-';
$dmin_num = intval(hesk_POST('dmin_num', 0));
$dmin_type = hesk_POST('dmin_type');
if ( ! in_array($dmin_type, array('day', 'week', 'month', 'year')))
{
$dmin_type = 'day';
}
$cf['dmin'] = $dmin_pm . $dmin_num . ' ' . $dmin_type;
}
// Maximum date
$dmax_rf = hesk_POST('dmax_rf');
if ($dmax_rf == 1)
{
$dmax = hesk_POST('dmax');
if ($date = hesk_datepicker_get_date($dmax))
{
$dmax = $date->format('m/d/Y');
$cf['dmax'] = $dmax;
}
}
elseif ($dmax_rf == 2)
{
$dmax_pm = hesk_POST('dmax_pm') == '+' ? '+' : '-';
$dmax_num = intval(hesk_POST('dmax_num', 0));
$dmax_type = hesk_POST('dmax_type');
if ( ! in_array($dmax_type, array('day', 'week', 'month', 'year')))
{
$dmax_type = 'day';
}
$cf['dmax'] = $dmax_pm . $dmax_num . ' ' . $dmax_type;
}
// Minimum date should not be higher than maximum date
if (strlen($cf['dmin']) && strlen($cf['dmax']))
{
if (strtotime($cf['dmin']) > strtotime($cf['dmax']))
{
$hesk_error_buffer[] = $hesklang['d_mm'];
$errors[] = 'date_range';
}
}
// Date format
$date_format = hesk_POST('date_format');
if ($date_format == 'custom')
{
$date_format = hesk_POST('date_format_custom');
}
$cf['date_format'] = preg_replace('/[^a-zA-Z0-9 \/\.\_+\-,;:#(){}\[\]\'@*]/', '', $date_format);
$cf['value'] = array('dmin' => $cf['dmin'], 'dmax' => $cf['dmax'], 'date_format' => $cf['date_format']);
break;
case 'email':
$cf['email_multi'] = hesk_POST('email_multi') ? 1 : 0;
$cf['value'] = array('multiple' => $cf['email_multi']);
break;
case 'hidden':
$cf['hidden_max_length'] = hesk_checkMinMax(intval(hesk_POST('hidden_max_length')), 1, 10000, 255);
$cf['hidden_default_value'] = stripslashes(hesk_input(hesk_POST('hidden_default_value'), 0, 0, HESK_SLASH));
$cf['value'] = array('max_length' => $cf['hidden_max_length'], 'default_value' => $cf['hidden_default_value']);
break;
default:
$cf['type'] = 'text';
$cf['max_length'] = hesk_checkMinMax(intval(hesk_POST('max_length')), 1, 10000, 255);
$cf['default_value'] = stripslashes(hesk_input(hesk_POST('default_value'), 0, 0, HESK_SLASH));
$cf['value'] = array('max_length' => $cf['max_length'], 'default_value' => $cf['default_value']);
}
// Enable
$cf['use'] = hesk_POST('use') == 2 ? 2 : 1;
// req
$cf['req'] = hesk_POST('req');
$cf['req'] = $cf['req'] == 2 ? 2 : ($cf['req'] == 1 ? 1 : 0);
// Private fields cannot be req for customers
if ($cf['use'] == 2 && $cf['req'] == 1)
{
$cf['req'] = 0;
}
// Located above or below "Message"?
$cf['place'] = hesk_POST('place') ? 1 : 0;
// Get allowed categories
if (hesk_POST('category'))
{
$cf['category'] = 1;
$cf['categories'] = hesk_POST_array('categories');
foreach ($cf['categories'] as $key => $cat_id)
{
if ( ! isset($hesk_settings['categories'][$cat_id]) )
{
unset($cf['categories'][$key]);
}
}
if ( ! count($cf['categories']))
{
$hesk_error_buffer[] = $hesklang['cf_nocat'];
$errors[] = 'categories';
}
}
else
{
$cf['category'] = 0;
$cf['categories'] = array();
}
// Any errors?
if (count($hesk_error_buffer))
{
$_SESSION['new_cf'] = $cf;
$_SESSION['new_cf']['errors'] = $errors;
return false;
}
$cf['names'] = addslashes(json_encode($cf['names']));
$cf['value'] = $cf['type'] == 'date' ? json_encode($cf['value']) : addslashes(json_encode($cf['value']));
return $cf;
} // END cf_validate()
function new_cf()
{
global $hesk_settings, $hesklang;
global $hesk_error_buffer;
// A security check
# hesk_token_check('POST');
// Validate inputs
if (($cf = cf_validate()) == false)
{
$tmp = '';
foreach ($hesk_error_buffer as $error)
{
$tmp .= "$error\n";
}
$hesk_error_buffer = $tmp;
$hesk_error_buffer = $hesklang['rfm'].'
';
hesk_process_messages($hesk_error_buffer,'custom_fields.php');
}
// Get the lowest available custom field ID
$res = hesk_dbQuery("SELECT `id` FROM `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` WHERE `use`='0' ORDER BY `id` ASC LIMIT 1");
$row = hesk_dbFetchRow($res);
$_SESSION['cford'] = intval($row[0]);
// Insert custom field into database
hesk_dbQuery("UPDATE `".hesk_dbEscape($hesk_settings['db_pfix'])."custom_fields` SET
`use` = '{$cf['use']}',
`place` = '{$cf['place']}',
`type` = '{$cf['type']}',
`req` = '{$cf['req']}',
`category` = ".(count($cf['categories']) ? "'".json_encode($cf['categories'])."'" : 'NULL').",
`name` = '".hesk_dbEscape($cf['names'])."',
`value` = ".(strlen($cf['value']) ? "'".hesk_dbEscape($cf['value'])."'" : 'NULL').",
`order` = 990
WHERE `id`={$_SESSION['cford']}");
// Update order
update_cf_order();
// Clear cache
hesk_purge_cache('cf');
// Show success
hesk_process_messages($hesklang['cf_added'],'custom_fields.php','SUCCESS');
} // End new_cf()