public function quantum_category_form()
{
global $aidlink;
$this->locale = fusion_get_locale();
$this->debug = FALSE;
add_to_jquery("\n\t\t\$('#field_parent').val() == '0' ? \$('#page_settings').show() : \$('#page_settings').hide()\n\t\t\$('#field_parent').bind('change', function() {\n\t\t\$(this).val() == '0' ? \$('#page_settings').show() : \$('#page_settings').hide()\n\t\t});\n\t\t");
if (isset($_GET['action']) && $_GET['action'] == 'cat_edit' && isset($_GET['cat_id']) && self::validate_fieldCat($_GET['cat_id'])) {
$result = dbquery("SELECT * FROM " . $this->category_db . " WHERE field_cat_id='" . $_GET['cat_id'] . "'");
if (dbrows($result) > 0) {
$this->field_cat_data = dbarray($result);
} else {
if (!$this->debug) {
addNotice('warning', $this->locale['field_0206']);
redirect(FUSION_SELF . $aidlink);
}
}
}
if (isset($_POST['save_cat'])) {
$this->field_cat_data = array('field_cat_id' => form_sanitizer($_POST['field_cat_id'], '', 'field_cat_id'), 'field_cat_name' => self::fusion_getlocale($this->field_cat_data, 'field_cat_name'), 'field_parent' => form_sanitizer($_POST['field_parent'], '', 'field_parent'), 'field_cat_order' => form_sanitizer($_POST['field_cat_order'], '', 'field_cat_order'));
// only if root then need to sanitize
$old_data = array("field_cat_db" => "users");
$result = dbquery("SELECT * FROM " . $this->category_db . " WHERE field_cat_id='" . $this->field_cat_data['field_cat_id'] . "'");
if (dbrows($result) > 0) {
$old_data = dbarray($result);
}
if ($this->field_cat_data['field_parent'] == 0) {
$this->field_cat_data['field_cat_db'] = form_sanitizer($_POST['field_cat_db'], 'users', 'field_cat_db');
$this->field_cat_data['field_cat_index'] = form_sanitizer($_POST['field_cat_index'], '', 'field_cat_index');
$this->field_cat_data['field_cat_class'] = form_sanitizer($_POST['field_cat_class'], '', 'field_cat_class');
}
if ($this->field_cat_data['field_cat_order'] == 0) {
$this->field_cat_data['field_cat_order'] = dbresult(dbquery("SELECT MAX(field_cat_order)\n FROM " . $this->category_db . "\n WHERE field_parent='" . $this->field_cat_data['field_parent'] . "'"), 0) + 1;
}
// shuffle between save and update
if (self::validate_fieldCat($this->field_cat_data['field_cat_id'])) {
dbquery_order($this->category_db, $this->field_cat_data['field_cat_order'], 'field_cat_order', $this->field_cat_data['field_cat_id'], 'field_cat_id', $this->field_cat_data['field_parent'], 'field_parent', FALSE, FALSE, 'update');
if (!$this->debug) {
if (\defender::safe()) {
if (empty($old_data['field_cat_db']) or $old_data['field_cat_db'] !== "users") {
if (!empty($old_data['field_cat_db']) && !empty($old_data['field_cat_index'])) {
// CONDITION: HAVE A PREVIOUS TABLE SET
if ($this->field_cat_data['field_cat_db']) {
// new demands a table insertion, checks if same or not.. if different.
if ($this->field_cat_data['field_cat_db'] !== $old_data['field_cat_db']) {
// But the current table is different than the previous one
// - build the new one, move the column, drop the old one.
self::build_table($this->field_cat_data['field_cat_db'], $this->field_cat_data['field_cat_index']);
self::transfer_table($old_data['field_cat_db'], $this->field_cat_data['field_cat_db']);
self::drop_table($old_data['field_cat_db']);
} else {
if ($old_data['field_cat_index'] !== $this->field_cat_data['field_cat_index']) {
self::rename_column($this->field_cat_data['field_cat_db'], $old_data['field_cat_index'], $this->field_cat_data['field_cat_index'], "MEDIUMINT(8) NOT NULL DEFAULT '0'");
}
}
} elseif (empty($this->field_cat_data['field_cat_db'])) {
self::drop_table($this->field_cat_data['field_cat_db']);
}
} elseif (!empty($this->field_cat_data['field_cat_index']) && !empty($this->field_cat_data['field_cat_db'])) {
self::build_table($this->field_cat_data['field_cat_db'], $this->field_cat_data['field_cat_index']);
}
dbquery_insert($this->category_db, $this->field_cat_data, 'update');
addNotice('success', $this->locale['field_0207']);
}
redirect(FUSION_SELF . $aidlink);
}
} else {
print_p('Update Mode');
print_p($this->field_cat_data);
}
} else {
dbquery_order($this->category_db, $this->field_cat_data['field_cat_order'], 'field_cat_order', $this->field_cat_data['field_cat_id'], 'field_cat_id', $this->field_cat_data['field_parent'], 'field_parent', TRUE, 'field_cat_name', 'save');
if (!$this->debug && \defender::safe()) {
if (!empty($this->field_cat_data['field_cat_index']) && !empty($this->field_cat_data['field_cat_db']) && $this->field_cat_data['field_cat_db'] !== 'users') {
self::build_table($this->field_cat_data['field_cat_db'], $this->field_cat_data['field_cat_index']);
}
dbquery_insert($this->category_db, $this->field_cat_data, 'save');
addNotice('success', $this->locale['field_0208']);
redirect(FUSION_SELF . $aidlink);
} else {
if ($this->debug) {
print_p('Save Mode');
print_p($this->field_cat_data);
}
}
}
}
// exclusion list - unselectable
$cat_list = array();
if (!empty($this->cat_list)) {
foreach ($this->cat_list as $id => $value) {
$cat_list[] = $id;
}
}
$html = openform('cat_form', 'post', FUSION_SELF . $aidlink, array('max_tokens' => 1));
$html .= form_button('save_cat', $this->locale['fields_0318'], 'save_cat', array('input_id' => 'save_cat2', 'class' => 'm-b-20 btn-primary'));
$html .= self::quantum_multilocale_fields('field_cat_name', $this->locale['fields_0430'], $this->field_cat_data['field_cat_name'], array('required' => 1));
$html .= form_select_tree('field_parent', $this->locale['fields_0431'], $this->field_cat_data['field_parent'], array('parent_value' => $this->locale['fields_0432'], 'disable_opts' => $cat_list), $this->category_db, 'field_cat_name', 'field_cat_id', 'field_parent');
$html .= form_text('field_cat_order', $this->locale['fields_0433'], $this->field_cat_data['field_cat_order'], array('number' => 1));
$html .= form_hidden('field_cat_id', '', $this->field_cat_data['field_cat_id'], array('number' => 1));
$html .= form_hidden('add_cat', '', 'add_cat');
// root settings
$html .= "<div id='page_settings' class='list-group-item m-t-20'>\n";
$html .= "<div class='text-smaller m-b-10'>" . $this->locale['fields_0111'] . "</div>\n";
$html .= form_text('field_cat_db', sprintf($this->locale['fields_0434'], " db_prefix_ "), $this->field_cat_data['field_cat_db'], array('placeholder' => 'Table Name', "required" => TRUE, "inline" => FALSE, "deactivate" => $this->field_cat_data['field_cat_db'] ? TRUE : FALSE));
$html .= "<div class='text-smaller m-b-10'>" . $this->locale['fields_0112'] . "</div>\n";
$html .= form_text('field_cat_index', $this->locale['fields_0435'], $this->field_cat_data['field_cat_index'], array('placeholder' => 'user_id', "required" => TRUE, "inline" => FALSE));
$html .= "<div class='text-smaller m-b-10'>" . $this->locale['fields_0113'] . "</div>\n";
$html .= form_text('field_cat_class', $this->locale['fields_0436'], $this->field_cat_data['field_cat_class'], array('placeholder' => 'icon for tabs', "inline" => FALSE));
$html .= form_hidden('add_cat', '', 'add_cat');
$html .= "</div>\n";
$html .= form_button('save_cat', $this->locale['fields_0318'], 'save_cat', array('class' => 'm-t-20 btn-primary'));
$html .= closeform();
return $html;
}