function ZimAPI_setPresetSetting($id_preset, $array_input, &$error_parameter, $name_preset = NULL, $overwrite = FALSE) { // $name_preset is NULL when creating preset from an old id $ret_val = 0; $array_setting = array(); $preset_path = NULL; $system_preset = FALSE; // $rewrite_json = FALSE; $CI =& get_instance(); if (!is_array($array_input)) { return ERROR_INTERNAL; } // check if we have same name, and define preset path if ($name_preset != NULL) { $old_path = NULL; $ret_val = ZimAPI_checkPreset(ZimAPI_codePresetHash($name_preset), $old_path, $system_preset); if ($ret_val == TRUE) { $CI->load->helper('printerlog'); if ($system_preset == TRUE) { PrinterLog_logMessage('system can not modify default preset'); return ERROR_WRONG_PRM; } else { if ($overwrite == FALSE) { PrinterLog_logMessage('system has already the same preset name: ' . $name_preset); return ERROR_FULL_PRTLST; // just use another error code } else { PrinterLog_logMessage('system detects a same preset name, and will overwrite it: ' . $name_preset); } } } $preset_path = $CI->config->item('presetlist') . ZimAPI_codePresetHash($name_preset) . '/'; } else { $ret_val = ZimAPI_checkPreset($id_preset, $preset_path, $system_preset); if ($ret_val == FALSE) { $CI->load->helper('printerlog'); PrinterLog_logError('system can not find preset: ' . $id_preset); return ERROR_WRONG_PRM; // just use another error code } if ($system_preset == TRUE) { $CI->load->helper('printerlog'); PrinterLog_logMessage('system can not modify default preset'); return ERROR_WRONG_PRM; } $preset_path .= '/' . $id_preset . '/'; } $ret_val = ZimAPI_checkPresetSetting($array_input, $error_parameter); if ($ret_val != TRUE) { $CI->load->helper('printerlog'); PrinterLog_logError('user input preset setting has wrong parameter'); return ERROR_WRONG_PRM; } $ret_val = ZimAPI_getPresetSettingAsArray($id_preset, $array_setting); if ($ret_val != ERROR_OK) { return $ret_val; } if (!ZimAPI_fixPresetSetting($array_setting)) { return ERROR_INTERNAL; } // check if 4 parameters are changed in same preset name saving (preset json is forced generated in different preset name saving) if ($name_preset == NULL) { foreach (array(ZIMAPI_TITLE_PRESET_INFILL, ZIMAPI_TITLE_PRESET_SKIRT, ZIMAPI_TITLE_PRESET_RAFT, ZIMAPI_TITLE_PRESET_SUPPORT) as $key) { if ($array_setting[$key] != $array_input[$key]) { $json_data = array(); if (ERROR_OK == ZimAPI_getPresetInfoAsArray($id_preset, $json_data)) { $name_preset = $json_data[ZIMAPI_TITLE_PRESET_NAME]; // assign preset name as the case in same name overwrite case } else { $CI->load->helper('printerlog'); PrinterLog_logError('read preset info error in reassignment of 4 parameters', __FILE__, __LINE__); return ERROR_INTERNAL; } // $rewrite_json = TRUE; } } } // assign new setting foreach ($array_input as $key => $value) { $array_setting[$key] = $value; } // save preset if (!file_exists($preset_path)) { mkdir($preset_path); } if ($name_preset != NULL) { // || $rewrite_json == TRUE $json_data = array(ZIMAPI_TITLE_PRESET_ID => ZimAPI_codePresetHash($name_preset), ZIMAPI_TITLE_PRESET_NAME => $name_preset, ZIMAPI_TITLE_PRESET_INFILL => $array_setting[ZIMAPI_TITLE_PRESET_INFILL], ZIMAPI_TITLE_PRESET_SKIRT => (int) $array_setting[ZIMAPI_TITLE_PRESET_SKIRT], ZIMAPI_TITLE_PRESET_RAFT => (int) $array_setting[ZIMAPI_TITLE_PRESET_RAFT], ZIMAPI_TITLE_PRESET_SUPPORT => (int) $array_setting[ZIMAPI_TITLE_PRESET_SUPPORT]); $CI->load->helper('json'); //write model json info try { $fp = fopen($preset_path . ZIMAPI_FILE_PRESET_JSON, 'w'); if ($fp) { fwrite($fp, json_encode_unicode($json_data)); fclose($fp); } else { return ERROR_INTERNAL; } } catch (Exception $e) { return ERROR_INTERNAL; } } //write config ini file try { $fp = fopen($preset_path . ZIMAPI_FILE_PRESET_INI, 'w'); if ($fp) { foreach ($array_setting as $key => $value) { fwrite($fp, $key . " = " . $value . "\r\n"); } fclose($fp); } else { return ERROR_INTERNAL; } } catch (Exception $e) { return ERROR_INTERNAL; } return ERROR_OK; }
public function check_exist_ajax() { $name_preset = $this->input->post('name'); $ret_val = ZimAPI_checkPreset(ZimAPI_codePresetHash($name_preset)); $this->output->set_status_header($ret_val ? 403 : 200); return; }