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 __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; } }