function Save_Format($x, $y, $type, $action = null, $old_name = null, $delete = false) { if ($x <= $y) { $h = $x; $w = $y; } if ($x > $y) { $h = $y; $w = $x; } //Type check (if it`s base or child format) if ($type == 'base') { $bean = $this; $FORMAT_OPTIONS = 'BASE_FORMAT_OPTIONS'; $parse_out = 'base_format'; } if ($type == 'child') { $bean = new Childformat(); $FORMAT_OPTIONS = 'CHILD_FORMAT_OPTIONS'; $parse_out = 'child_format'; } //Duplicate check $query = ' SELECt id, x, y FROM ' . $bean->table_name . ' WHERE x=' . $h . ' AND y=' . $w . ' AND deleted=0 '; $result = $bean->db->query($query, true, " Error inserting format"); $data = $bean->db->fetchByAssoc($result); if ($data == null) { global $app_list_strings; global $app_strings; global $mod_strings; $xtpl = new XTemplate('modules/Paperformat/format_ui_elements.html'); //Save format $bean->x = $h; $bean->y = $w; $bean->name = $h . 'x' . $w; if ($type == 'child') { $query = 'SELECT id FROM ' . $this->table_name . ' WHERE name="' . $_REQUEST['parent_name'] . '" AND deleted=0 '; $result = $bean->db->query($query, true, " Error inserting format"); $data = $bean->db->fetchByAssoc($result); $bean->parent_id = $data['id']; } if ($action != null) { $query = ' SELECt id FROM ' . $bean->table_name . ' WHERE name="' . $old_name . '" AND deleted=0 '; $result = $bean->db->query($query, true, " Error inserting format"); $data = $bean->db->fetchByAssoc($result); $bean->retrieve($data['id']); $bean->x = $h; $bean->y = $w; $bean->name = $h . 'x' . $w; //echo $data['id']; } $bean->save($GLOBALS['check_notify']); //////////// $xtpl->assign('APP', $app_strings); $xtpl->assign('MOD', $mod_strings); if ($bean->object_name == 'Childformat') { $app_list_strings['format_options'] = $bean->Get_Dropdown_Data($bean->parent_id); $this->retrieve($bean->parent_id); $coef = $this->calc_coef($this, $bean); $xtpl->assign("COEF", '1:' . $coef); } else { $app_list_strings['format_options'] = $bean->Get_Dropdown_Data(); } $xtpl->assign($FORMAT_OPTIONS, get_select_options_with_id($app_list_strings['format_options'], $bean->name)); $xtpl->assign($type . '_x', $bean->x); $xtpl->assign($type . '_y', $bean->y); $xtpl->parse($parse_out); $xtpl->out($parse_out); if ($type == 'base' && $action == null) { $xtpl->parse("no_child_defined"); $xtpl->out("no_child_defined"); } } if ($delete == true) { global $app_list_strings; global $app_strings; global $mod_strings; $xtpl = new XTemplate('modules/Paperformat/format_ui_elements.html'); $bean->retrieve($data['id']); $xtpl->assign('APP', $app_strings); $xtpl->assign('MOD', $mod_strings); $paper = new Paper(); $query = 'SELECT format_id FROM ' . $paper->table_name . ' WHERE size_h=' . $bean->x . ' AND size_w=' . $bean->y . ' AND deleted=0'; echo $query; $result = $this->db->query($query, true, " Error inserting format"); $data = $this->db->fetchByAssoc($result); if ($data['format_id'] == null && empty($data)) { $x = ''; $y = ''; $bean->mark_deleted($bean->id); if ($type == 'base') { $child = new Childformat(); $child->mark_deletedByParent_id($bean->id); } } else { $xtpl->assign('LBL_FORMAT_IN_USE', $mod_strings['LBL_FORMAT_IN_USE']); $x = $bean->x; $y = $bean->y; echo '<input name="delete" id="delete" type="hidden" value="false" />'; } if ($bean->object_name == 'Childformat') { $app_list_strings['format_options'] = $bean->Get_Dropdown_Data($bean->parent_id); } else { $app_list_strings['format_options'] = $bean->Get_Dropdown_Data(); } $xtpl->assign($FORMAT_OPTIONS, get_select_options_with_id($app_list_strings['format_options'], $bean->name)); $xtpl->assign($type . '_x', $x); $xtpl->assign($type . '_y', $y); $xtpl->parse($parse_out); $xtpl->out($parse_out); } }