function __construct() { parent::__construct(); $this->load->helper(array('form', 'url', 'json', 'errorcode', 'corestatus')); $status_current = ''; if (CoreStatus_checkInInitialization() || CoreStatus_checkInConnection() || CoreStatus_checkInUSB()) { // let no block REST web service go for setting network if (CoreStatus_checkCallNoBlockRESTInConnection()) { return; } // we haven't finished initialization or connection yet $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER); } else { if (!CoreStatus_checkInIdle($status_current)) { // check if the status is changed $ret_val = 0; $this->load->helper('printerstate'); switch ($status_current) { case CORESTATUS_VALUE_SLICE: if (CoreStatus_checkCallNoBlockRESTInSlice()) { // do not block some special REST for action in slicing return; } $ret_val = PrinterState_checkBusyStatus($status_current); if ($ret_val == FALSE) { // still in slicing break; } else { if ($status_current == CORESTATUS_VALUE_IDLE) { // encounted some errors break; } else { // CORESTATUS_VALUE_PRINT $this->load->helper('printerlog'); PrinterLog_logMessage('call rest when we are in slicing, but finished really', __FILE__, __LINE__); } } // we treat canceling as printing // we treat canceling as printing case CORESTATUS_VALUE_PRINT: // do not block some special REST for action in printing if (CoreStatus_checkCallNoBlockRESTInPrint()) { return; } case CORESTATUS_VALUE_CANCEL: //TODO test here for canceling $ret_val = PrinterState_checkInPrint(); if ($ret_val == FALSE) { $ret_val = CoreStatus_setInIdle(); if ($ret_val == TRUE) { $this->load->helper('printerlog'); PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__); return; // continue to generate if we are now in idle } $this->load->helper('printerlog'); PrinterLog_logError('can not set status in idle', __FILE__, __LINE__); } break; default: $ret_val = PrinterState_checkBusyStatus($status_current); if ($ret_val == TRUE) { $this->load->helper('printerlog'); PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__); return; // status has changed to idle } break; } // do not block some special REST if (CoreStatus_checkCallNoBlockREST()) { return; } // return that printer is busy $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER); } } }
public function signup() { $body_page = NULL; $template_data = array(); $data = array(); $data['error'] = ""; $this->load->library('parser'); $this->lang->load('signup', $this->config->item('language')); $this->load->helper(array('url', 'corestatus')); // check network if (@file_get_contents("https://sso.zeepro.com/login.ashx") === FALSE) { if (CoreStatus_checkInConnection()) { $this->output->set_header('Location: /activation/wizard_confirm/fail'); } else { $body_page = $this->parser->parse('template/activation/network_error', array(), TRUE); $this->lang->load('activation/network_error', $this->config->item('language')); $template_data = array('lang' => $this->config->item('language_abbr'), 'headers' => '<title>' . t('ZeePro Personal Printer 21 - Home') . '</title>', 'contents' => $body_page, 'back' => t('back'), 'network_err_msg' => t('network_err_msg')); $this->parser->parse('basetemplate', $template_data); } return; } if ($this->input->server('REQUEST_METHOD') == 'POST') { $this->load->library('form_validation'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'required|matches[confirm]'); $this->form_validation->set_rules('confirm', 'Password confirmation', 'required'); if ($this->form_validation->run()) { extract($_POST); $data = array('email' => $email, 'password' => $password, 'optin' => (int) $this->input->post('optin') == 1 ? 'on' : 'off'); $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($data))); $context = stream_context_create($options); @file_get_contents('https://sso.zeepro.com/createaccount.ashx', false, $context); $result = substr($http_response_header[0], 9, 3); if ($result == 200) { $this->session->set_userdata($data); redirect('/account/signup_confirmation'); } else { if ($result == 437) { $data['error'] = t('account_exists') . '<br />'; } else { if ($result == 432) { $data['error'] = t('missing_parameter') . '<br />'; } } } } else { if ($_POST['password'] != $_POST['confirm']) { $data['error'] = t("wrong_pass") . '<br />'; } else { $data['error'] = t('missing_parameter') . '<br />'; } } } // add skip button if in wizard if (CoreStatus_checkInConnection()) { $data['back_or_already'] = t('already'); // $data['has_skip'] = "block"; $data['btn_url'] = '/account/signin'; } else { $data['back_or_already'] = t('back'); // $data['has_skip'] = "none"; $data['btn_url'] = '/activation/'; } $data['has_skip'] = "none"; $data['confcode_hint'] = t('confcode_hint'); $data['signup_title'] = t('signup_title'); $data['signup_text'] = t('signup_text'); $data['skip_title'] = t('button_skip'); $data['confirm_skip_text'] = t('confirm_skip_text'); $data['still_skip'] = t('still_skip'); $data['back'] = t('back'); $data['show_password'] = t('show_password'); $data['privacy_policy_link'] = t('privacy_policy_link'); $data['optin_title'] = t('optin_title'); $body_page = $this->parser->parse('template/account/signup', $data, TRUE); // parse all page $template_data = array('lang' => $this->config->item('language_abbr'), 'headers' => '<title>' . t('ZeePro Personal Printer 21 - Home') . '</title>', 'contents' => $body_page); $this->parser->parse('basetemplate', $template_data); return; }
public function __construct() { global $CFG; parent::__construct(); // $this->load->helper(array('corestatus', 'url')); $this->load->helper(array('corestatus', 'printerlog')); // set proper error handler set_error_handler(array($this, 'errorToSSO')); // add header to disable cache (IE need these headers) $this->output->set_header('Pragma: no-cache'); $this->output->set_header('Cache-Control: no-cache'); // initialisation status files if (!CoreStatus_initialFile()) { $this->load->helper('printerlog'); PrinterLog_logError('status files initialisation error when MY_Controller started', __FILE__, __LINE__); // let request failed $this->_exitWithError500('file initialisation error'); } // check tromboning autorisation if (CoreStatus_checkTromboning(FALSE)) { $this->load->helper(array('printerlog', 'errorcode')); PrinterLog_logMessage('detected and refused tromboning connection', __FILE__, __LINE__); // let request failed $this->_exitWithError500(ERROR_REMOTE_REFUSE . ' ' . MyERRMSG(ERROR_REMOTE_REFUSE), ERROR_REMOTE_REFUSE); } // Workflow management if (CoreStatus_checkCallREST()) { // we place the control for REST web service in his own class // because there are the special error codes for REST web service // and we do not need them in normal condition return; } else { $status_current = ''; $url_redirect = ''; $array_status = array(); // stats info (do not stats rest, app can initialize cookies in each request) $this->load->library('session'); if (FALSE === $this->input->cookie('stats_browserLog')) { $this->input->set_cookie('stats_browserLog', 'ok', 2592000); // 30 days for browser stats PrinterLog_statsWebAgent(); } // check initialization issue if (CoreStatus_checkInInitialization()) { if (CoreStatus_checkCallInitialization($url_redirect)) { return; // we are calling the right page } } else { if (CoreStatus_checkCallInitialization()) { $url_redirect = '/'; } else { if (CoreStatus_checkInUSB()) { if (CoreStatus_checkCallUSB($url_redirect)) { return; // we are calling the right page } } else { if (CoreStatus_checkCallUSB()) { $url_redirect = '/'; } else { if (CoreStatus_checkCallDebug()) { // we always let these interfaces go for debug return; } else { if (CoreStatus_checkInConnection()) { if (CoreStatus_checkCallNoBlockPageInConnection()) { return; // we are calling set hostname, activation or account page } if (CoreStatus_checkCallConnection($url_redirect)) { return; // we are calling the right page } } else { if (CoreStatus_checkCallConnection()) { $url_redirect = '/'; } else { if (!CoreStatus_checkInIdle($status_current, $array_status)) { switch ($status_current) { case CORESTATUS_VALUE_RECOVERY: //TODO finish and test me if (CoreStatus_checkCallRecovery($url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_PRINT: if (CoreStatus_checkCallPrinting($array_status, $url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_CANCEL: if (CoreStatus_checkCallCanceling($url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_LOAD_FILA_L: case CORESTATUS_VALUE_LOAD_FILA_R: if (CoreStatus_checkCallloading($url_redirect)) { return; // we are calling the right page } // return; // we do not block users when charging filament break; case CORESTATUS_VALUE_UNLOAD_FILA_L: case CORESTATUS_VALUE_UNLOAD_FILA_R: //FIXME finish here to block users if (CoreStatus_checkCallUnloading($url_redirect)) { return; // we are calling the right page } break; case CORESTATUS_VALUE_SLICE: if (CoreStatus_checkCallSlicing($url_redirect)) { return; } break; default: $url_redirect = '/'; // internal error, never reach here normally break; } } else { if (CoreStatus_checkCallPrintingAjax() || CoreStatus_checkCallCancelingAjax()) { // let ajax request failed when we finishing printing / canceling $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0'; header($protocol . ' 403'); header('Content-type: text/plain; charset=UTF-8'); echo 'Not in printing / canceling'; exit; } else { if (CoreStatus_checkCallPrinting() || CoreStatus_checkCallCanceling()) { $url_redirect = '/'; } else { if (CoreStatus_checkInPrinted()) { if (CoreStatus_checkCallEndPrinting($url_redirect) || CoreStatus_checkCallEndPrintingPlus()) { return; } } else { if (CoreStatus_checkCallEndPrinting()) { $url_redirect = '/'; // redirect to homepage when we have no timelapse } } } } if ($url_redirect) { header('Location: ' . $url_redirect); exit; } return; // continue to generate the current page } } } } } } } } // log error if we have no redirect url when reaching here if (is_null($url_redirect)) { $this->load->helper('printerlog'); PrinterLog_logError('no redirect place when MY_Controller finished', __FILE__, __LINE__); } header('Location: ' . $url_redirect); exit; } }
function PrinterState_checkStatusAsArray($extra_info = TRUE) { $command = ''; $output = array(); $ret_val = 0; $data_json = array(); $temp_data[PRINTERSTATE_TITLE_LASTERROR] = array(); $time_start = NULL; $status_current = ''; // if we need duration, the function that get duration by id is necessary // and we must stock print list id somewhere in json file $CI =& get_instance(); $CI->load->helper('corestatus'); if (CoreStatus_checkInUSB()) { $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_USB; return $data_json; } else { if (CoreStatus_checkInConnection()) { $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_WAIT_CONNECT; return $data_json; } } $ret_val = CoreStatus_checkInIdle($status_current, $status_json); if ($ret_val == TRUE) { $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_IDLE; //TODO think about if we need to display last error as 200 (error_ok) or not if (array_key_exists(CORESTATUS_TITLE_LASTERROR, $status_json) && !is_null($status_json[CORESTATUS_TITLE_LASTERROR]) && $status_json[CORESTATUS_TITLE_LASTERROR] != ERROR_OK) { // $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_LASTERROR] = $status_json[CORESTATUS_TITLE_LASTERROR]; // $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_DETAILMSG] = $status_json[CORESTATUS_TITLE_MESSAGE]; $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_SLICE_ERR] = $status_json[CORESTATUS_TITLE_LASTERROR] . ' ' . $status_json[CORESTATUS_TITLE_MESSAGE]; } } else { if ($ret_val == FALSE) { $temp_data = array(); $status_old = $status_current; PrinterState_checkBusyStatus($status_current, $temp_data); if (in_array($status_current, array(CORESTATUS_VALUE_SLICE, CORESTATUS_VALUE_PRINT))) { $data_json[PRINTERSTATE_TITLE_PERCENT] = $temp_data[PRINTERSTATE_TITLE_PERCENT]; } $data_json[PRINTERSTATE_TITLE_STATUS] = $status_current; // return error code in the first time when we have error from slicing=>idle if ($status_old == CORESTATUS_VALUE_SLICE && $status_current == CORESTATUS_VALUE_IDLE && array_key_exists(PRINTERSTATE_TITLE_LASTERROR, $temp_data)) { // $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_LASTERROR] = $temp_data[PRINTERSTATE_TITLE_LASTERROR]; // $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_DETAILMSG] = $temp_data[PRINTERSTATE_TITLE_DETAILMSG]; $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_SLICE_ERR] = $temp_data[PRINTERSTATE_TITLE_LASTERROR] . ' ' . $temp_data[PRINTERSTATE_TITLE_DETAILMSG]; } else { if ($status_current == CORESTATUS_VALUE_PRINT) { $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_PRINT; $array_status = array(); // add temperature if ($extra_info == TRUE && $data_json[PRINTERSTATE_TITLE_PERCENT] != 100) { $data_temperature = PrinterState_getExtruderTemperaturesAsArray(); if (!is_array($data_temperature)) { // log internal error $CI->load->helper('printerlog'); PrinterLog_logError('API error when getting temperatures in printing', __FILE__, __LINE__); } else { $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_L] = array_key_exists(PRINTERSTATE_LEFT_EXTRUD, $data_temperature) ? $data_temperature[PRINTERSTATE_LEFT_EXTRUD] : 0; $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_R] = array_key_exists(PRINTERSTATE_RIGHT_EXTRUD, $data_temperature) ? $data_temperature[PRINTERSTATE_RIGHT_EXTRUD] : 0; $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_B] = array_key_exists(PRINTERSTATE_HEAT_BED, $data_temperature) ? $data_temperature[PRINTERSTATE_HEAT_BED] : 0; } } // try to calculate time remained when percentage is passed offset $ret_val = CoreStatus_getStatusArray($array_status); if ($ret_val == TRUE && isset($array_status[CORESTATUS_TITLE_STARTTIME]) && isset($array_status[CORESTATUS_TITLE_ESTIMATE_T])) { $time_pass = time() - $array_status[CORESTATUS_TITLE_STARTTIME]; $data_json[PRINTERSTATE_TITLE_PASSTIME] = $time_pass; if (isset($data_json[PRINTERSTATE_TITLE_PERCENT]) && ($time_pass >= PRINTERSTATE_VALUE_OFST_TO_CAL_TIME || $data_json[PRINTERSTATE_TITLE_PERCENT] >= PRINTERSTATE_VALUE_OFST_TO_CAL_PCT)) { // rest time = total time - passed time // total time = estimate time (by filament) * (1 - percentage ^ 0.5) + estimate time (by time) * percentage ^ 0.5 // estimate time (by time) = passed time / percentage // $percentage_finish = $data_json[PRINTERSTATE_TITLE_PERCENT] / 100; $calculate_factor = sqrt($data_json[PRINTERSTATE_TITLE_PERCENT] / 100); $time_estimation = $array_status[CORESTATUS_TITLE_ESTIMATE_T]; $data_json[PRINTERSTATE_TITLE_DURATION] = (int) ($time_estimation * (1 - $calculate_factor) + $time_pass * (1 / $calculate_factor - 1)); } } // check operation if (file_exists(PRINTERSTATE_FILE_PRINT_HEAT)) { $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_HEAT; } else { if ($data_json[PRINTERSTATE_TITLE_PERCENT] == 100) { $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_END; } } $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_OPER] = $print_operation; } } } } if ($extra_info == TRUE && $status_current == CORESTATUS_VALUE_IDLE) { // check if we need to change idle into sliced or not PrinterState_checkSlicedCondition($data_json); //TODO add timelapse checking PrinterState_checkTimelapseCondition($data_json); } return $data_json; }