public function delete() { if (empty($this->_data['SOrderLine']['id'])) { $this->dataError(); sendBack(); } $flash = Flash::Instance(); $sorderline = $this->_uses[$this->modeltype]; $sorderline->load($this->_data['SOrderLine']['id']); if ($sorderline->isLoaded() && $sorderline->delete()) { $flash->addMessage($sorderline->header->getFormatted('type') . ' Line Deleted'); if (isset($this->_data['dialog'])) { $link = array('modules' => $this->_modules, 'controller' => 'sorders', 'action' => 'view', 'other' => array('id' => $sorderline->order_id)); $flash->save(); echo parent::returnJSONResponse(TRUE, array('redirect' => '/?' . setParamsString($link))); exit; } else { sendTo('sorders', 'view', $this->_modules, array('id' => $sorderline->order_id)); } } $flash->addError('Error deleting ' . $sorderline->header->getFormatted('type') . ' Line'); $this->_data['id'] = $this->_data['SOrderLine']['id']; $this->_data['order_id'] = $this->_data['SOrderLine']['order_id']; $this->refresh(); }
private function getMenuLinks($tree, $pid, $level = 1) { $menu = array(); foreach ($tree[$pid] as $item) { $item['link'] += array('pid' => $item['id']); switch ($item['type']) { case 'm': $permission = $item['link']['module']; break; case 'c': $permission = $item['link']['controller']; break; case 'a': $permission = $item['link']['action']; break; } $menu[$item['id']]['main'] = new MenuLink('?' . setParamsString($item['link']), $level, $item['type'], $item['title'], $this->getIcons($item['type'], $permission)); if (isset($tree[$item['id']])) { $menu[$item['id']]['sub'] = $this->getMenuLinks($tree, $item['id'], $level + 1); } } return $menu; }
public function save() { $db = DB::Instance(); $flash = Flash::Instance(); $errors = array(); $data = $this->_data[$this->modeltype]; if (empty($data['order_id'])) { $errors[] = 'Order header not defined'; } else { $porder = DataObjectFactory::Factory('POrder'); if (!$porder->load($data['order_id'])) { $errors[] = 'Cannot find order header'; } } $db->StartTrans(); if ($porder->isLoaded() && $porder->isLatest($this->_data['POrder'], $errors)) { if (isset($data['cancel_line'])) { $data['status'] = $this->_templateobject->cancelStatus(); if ($this->_templateobject->update($data['id'], array('status', 'glaccount_centre_id'), array($this->_templateobject->cancelStatus(), 'null')) && $porder->save()) { $flash->addMessage($porder->getFormatted('type') . ' Line cancelled'); } else { $errors[] = 'Failed to cancel ' . $porder->getFormatted('type') . ' Line'; } } elseif (isset($data['complete_line'])) { $porderline = $this->_uses[$this->modeltype]; $porderline->load($data['id']); $poreceivedline = DataObjectFactory::Factory('POReceivedLine'); if ($porderline->del_qty == $poreceivedline->invoicedQty($data['id'])) { $fields = array('status', 'glaccount_centre_id'); $values = array($this->_templateobject->invoiceStatus(), 'null'); } else { $fields = array('status'); $values = array($this->_templateobject->receivedStatus()); } $fields[] = 'os_qty'; $values[] = 0; if ($this->_templateobject->update($data['id'], $fields, $values) && $porder->save()) { $flash->addMessage($porder->getFormatted('type') . ' Line completed'); } else { $errors[] = 'Failed to complete ' . $porder->getFormatted('type') . ' Line'; } } elseif ($data['status'] == $this->_templateobject->newStatus() || $data['status'] == $this->_templateobject->awaitingDeliveryStatus() || $data['status'] == $this->_templateobject->partReceivedStatus() || $data['status'] == $this->_templateobject->receivedStatus()) { $porderline = POrderLine::Factory($porder, $data, $errors); if ($porderline && count($errors) == 0) { if ($porder->due_date < $porderline->due_delivery_date) { $porder->due_date = $porderline->due_delivery_date; } if (!$porderline->save($porder, $errors)) { $errors[] = 'Failed to save ' . $porder->getFormatted('type') . ' Line'; } else { $flash->addMessage($porder->getFormatted('type') . ' Line Saved'); } } } } if (count($errors) == 0) { $db->CompleteTrans(); if (isset($this->_data['saveAnother'])) { $other = array('order_id' => $data['order_id']); if (isset($this->_data['dialog'])) { $other += array('dialog' => ''); } if (isset($this->_data['ajax'])) { $other += array('ajax' => ''); } sendTo($this->name, 'new', $this->_modules, $other); } else { $action = 'view'; $controller = 'porders'; $other = array('id' => $data['order_id']); } if (isset($this->_data['dialog'])) { $link = array('modules' => $this->_modules, 'controller' => $controller, 'action' => $action, 'other' => $other); $flash->save(); echo parent::returnJSONResponse(TRUE, array('redirect' => '/?' . setParamsString($link))); exit; } else { sendTo($controller, $action, $this->_modules, $other); } } else { $db->FailTrans(); $db->CompleteTrans(); $flash->addErrors($errors); $this->_data['id'] = $this->_data[$this->modeltype]['id']; $this->_data['order_id'] = $this->_data[$this->modeltype]['order_id']; $this->refresh(); } }
public function save() { $flash = Flash::Instance(); $errors = array(); $data = $this->_data['SInvoiceLine']; if (empty($data['invoice_id'])) { $errors[] = 'invoice header not defined'; } else { $sinvoice = DataObjectFactory::Factory('SInvoice'); if (!$sinvoice->load($data['invoice_id'])) { $errors[] = 'Cannot find invoice header'; } elseif ($sinvoice->isLatest($this->_data['SInvoice'], $errors)) { $sinvoiceline = SInvoiceLine::Factory($sinvoice, $data, $errors); if ($sinvoiceline && count($errors) == 0) { if (!$sinvoiceline->save($sinvoice)) { $errors[] = 'Failed to save Sales ' . $sinvoice->getFormatted('transaction_type') . ' line'; } } } } if (count($errors) == 0) { $flash->addMessage('Sales ' . $sinvoice->getFormatted('transaction_type') . ' Line Saved'); if (isset($this->_data['saveAnother'])) { $other = array('invoice_id' => $sinvoiceline->invoice_id); if (isset($this->_data['dialog'])) { $other += array('dialog' => ''); } if (isset($this->_data['ajax'])) { $other += array('ajax' => ''); } sendTo($this->name, 'new', $this->_modules, $other); } else { $action = 'view'; $controller = 'sinvoices'; $other = array('id' => $sinvoiceline->invoice_id); } if (isset($this->_data['dialog'])) { $link = array('modules' => $this->_modules, 'controller' => $controller, 'action' => $action, 'other' => $other); $flash->save(); echo parent::returnJSONResponse(TRUE, array('redirect' => '/?' . setParamsString($link))); exit; } else { sendTo($controller, $action, $this->_modules, $other); } } else { $flash->addErrors($errors); $this->_data['id'] = $this->_data['SInvoiceLine']['id']; $this->_data['invoice_id'] = $this->_data['SInvoiceLine']['invoice_id']; $this->refresh(); } }
function setRefererPage() { // Backwards compatibility if (isset($_SESSION['referer'])) { $referer = setParamsString(getParamsArray()); if (isset($_SESSION['referer'][$referer])) { $_SESSION['refererPage'] = getParamsArray($_SESSION['referer'][$referer]); } else { $_SESSION['refererPage'] = getParamsArray(''); $_SESSION['refererPage']['action'] = ''; } } else { $_SESSION['refererPage'] = getParamsArray(''); } // echo 'lib::setRefererPage $referer='.$referer.'<br>'; // echo 'lib::setRefererPage <pre>'.print_r($_SESSION['referer'], TRUE).'</pre><br>'; // echo 'lib::setRefererPage<pre>'.print_r($_SESSION['refererPage'], TRUE).'</pre><br>'; }
private function getAttachments() { $attachments = new EntityAttachmentCollection(); $sh = new SearchHandler($attachments, FALSE); $sh->addConstraint(new Constraint('data_model', '=', 'modulecomponent')); $sh->addConstraint(new Constraint('entity_id', '=', ModuleComponent::getComponentId($this->_modules['module'], strtolower(get_class($this))))); $sh->addConstraint(new Constraint('createdby', '=', EGS_USERNAME)); $files = $attachments->load($sh, null, RETURN_ROWS); $dirobjs = array(); if (count($files) > 0) { foreach ($files as $attachment) { $link = '/?' . setParamsString(array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'view_file', 'other' => array(file_id => $attachment['file_id']))); $details = array('name' => $attachment['file'], 'link' => $link, 'type' => 'attachment', 'delete' => array('modules' => $this->_modules, 'controller' => 'attachments', 'action' => 'delete', 'id' => $attachment['id']), 'size' => sizify($attachment['size']), 'mtime' => un_fix_date($attachment['lastupdated'])); $dirobjs['file'][] = $details; } } return $dirobjs; }
public function display() { $start = gettimeofday(TRUE); // ATTN: check system always returns true? if (!$this->check_system()) { $this->login_required = FALSE; // if (!defined('SETUP')) // { // define('SETUP', TRUE); // } if (!defined('MODULE')) { define('MODULE', 'system_admin'); } if (!defined('CONTROLLER')) { define('CONTROLLER', 'SystemsController'); } } $this->load_essential(); debug('system::display session data:' . print_r($_SESSION, TRUE)); $this->user = FALSE; if (isLoggedIn()) { // Sets the global constants EGS_USERNAME and EGS_COMPANY_ID setupLoggedInUser(); $this->user = getCurrentUser(); $this->access = AccessObject::Instance($_SESSION['username']); } else { define('EGS_COMPANY_ID', -1); define('EGS_USERNAME', $_SESSION['username']); $this->access = AccessObject::Instance(); } $this->setView(); $this->view->set("accessTree", $this->access->tree); $this->view->set('access', $this->access); $this->setController(); $this->setTemplates(); $this->setAction(); $csrf = new \Riimu\Kit\CSRF\CSRFHandler(); // check that the csrf token is valid if (!$this->csrfValid()) { sendBack(); } $csrf_token = $csrf->getToken(); // make csrf token available to smarty templates $this->view->set('csrf_token', $csrf_token); if (isLoggedIn()) { $this->checkPermission(); } // output standard arrays to smarty $this->view->set("module_css", $this->get_css()); $this->view->set("module_js", $this->get_js()); $this->view->set('current_user', $this->user); $action = $this->action; $controller = $this->controller; $theme = ''; if (defined('EGS_COMPANY_ID') && EGS_COMPANY_ID !== 'null' && EGS_COMPANY_ID > 0) { $sc = DataObjectFactory::Factory('Systemcompany'); $sc->load(EGS_COMPANY_ID); if ($sc->isLoaded()) { define('SYSTEM_COMPANY', $sc->company); define('COMPANY_ID', $sc->company_id); $theme = $sc->theme; $this->available = $sc->access_enabled == 'NONE' ? FALSE : TRUE; $this->audit = $sc->audit_enabled == 't' ? TRUE : FALSE; $this->debug = $sc->debug_enabled == 't' ? TRUE : FALSE; $this->view->set('info_message', $sc->info_message); $this->view->set('systemcompany', $sc); } } $policy = DataObjectFactory::Factory('SystemObjectPolicy'); if ($policy->getCount() > 0) { define('SYSTEM_POLICIES_ENABLED', TRUE); } else { define('SYSTEM_POLICIES_ENABLED', FALSE); } if (!defined('SYSTEM_COMPANY')) { define('SYSTEM_COMPANY', ''); } if (!defined('COMPANY_ID')) { define('COMPANY_ID', ''); } // Set auditing/debugging for logged in user if ($this->user) { $this->audit = $this->audit ? $this->audit : ($this->user->audit_enabled == 't' ? TRUE : FALSE); $this->debug = $this->debug ? $this->debug : ($this->user->debug_enabled == 't' ? TRUE : FALSE); $this->available = $this->available ? $this->user->access_enabled == 't' ? TRUE : FALSE : $this->available; } if (!$this->available && isLoggedIn()) { $_SESSION['loggedin'] = FALSE; $_SESSION['username'] = null; $flash = Flash::Instance(); $flash->addError('The system is unavailable at present'); $flash->save(); sendto(''); } define('AUDIT', $this->audit); define('DEBUG', $this->debug); $db = DB::Instance(); $db->debug(DEBUG); if (defined('LOGIN_PAGE_THEME') && $this->modules['module'] == 'login') { $theme = LOGIN_PAGE_THEME; } if (!empty($theme)) { define('THEME', $theme); } else { define('THEME', 'default'); } $this->view->set('theme', THEME); if (!defined('EGS_CURRENCY')) { define('EGS_CURRENCY', 'GBP'); } if (class_exists('Currency')) { $currency = DataObjectFactory::Factory('Currency'); $currency->loadBy('currency', EGS_CURRENCY); if ($currency) { define('EGS_CURRENCY_SYMBOL', utf8_decode($currency->symbol)); } } if (!defined('EGS_CURRENCY_SYMBOL')) { define('EGS_CURRENCY_SYMBOL', utf8_decode('£')); } /** * *BEGIN CACHE CHECK***** */ if (!defined('EGS_COMPANY_ID')) { define('EGS_COMPANY_ID', ''); } if (DEBUG) { $this->writeDebug(); } $cache_key = md5($_SERVER['REQUEST_URI'] . EGS_COMPANY_ID . EGS_USERNAME); if (TRUE || !$smarty->isCached('index.tpl', $cache_key)) { $flash = Flash::Instance(); $config = Config::Instance(); // output all the variables to smarty // this replaces $smarty.const.setting_name $this->view->assign('config', $config->get_all()); setRefererPage(); debug('system::display Calling function ' . get_class($controller) . '::' . $action); // echo 'system::display (1),'.microtime(TRUE).'<br>'; $controller->checkRequest($this->request, $action)->{$action}(); // echo 'system::display (2),'.microtime(TRUE).'<br>'; $flash->save(); // Save any flash messages for audit purposes $this->flash['errors'] = $flash->getMessages('errors'); $this->flash['warnings'] = $flash->getMessages('warnings'); $this->flash['messages'] = $flash->getMessages('messages'); if (isLoggedIn()) { $this->access->save(); } // assign stuff to smarty $controller->assignModels(); // this code fires $controller->index() if (perhaps) getPrintActions doesn't exist, // thus overwriting the sidebar. Only fire if subclass of printController if (is_subclass_of($controller, 'printController') && $action != 'printDialog') { $this->view->assign('printaction', $controller->getPrintActions()); } $controllername = str_replace('Controller', '', get_class($controller)); $this->pid = $this->access->getPermission($this->modules, $controllername, $action); $self = array(); if (!empty($this->pid)) { $self['pid'] = $this->pid; } $self['modules'] = $this->modules; // $self['controller']=$controllername; // $self['action']=$action; $qstring = $_GET; foreach ($qstring as $qname => $qvalue) { if (!in_array($qname, array('orderby', 'page'))) { $self[$qname] = $qvalue; } } $this->view->assign('self', $self); if (isset($this->user)) { $this->view->assign('current_user', $this->user); } // Session timed out on input form so save the form data while the user logs back in // See system::setController for where the form data is read after logging back in if ($this->modules['module'] == 'login' && !empty($_POST)) { $_SESSION['data'] = $_POST; } $echo = $controller->view->get('echo'); if (($this->ajax || $this->json) && $echo !== FALSE) { echo $controller->view->get('echo'); exit; } elseif ($this->modules['module'] == 'login') { $current = getParamsArray($_SERVER['QUERY_STRING']); $referer['modules'] = $current['modules']; $referer['controller'] = 'Index'; $referer['action'] = 'index'; unset($referer['other']); $_SESSION['referer'][setParamsString($current)] = setParamsString($referer); } elseif (!isset($_GET['ajax'])) { $referer = ''; if (!empty($_POST)) { // This is a save form so set the referer to be the referer's referer! $referer = isset($_SESSION['refererPage']) ? $_SESSION['refererPage'] : ''; } setReferer($referer); $current = getParamsArray($_SERVER['QUERY_STRING']); $flash = Flash::Instance(); $current += array('messages' => $flash->getMessages('messages'), 'warnings' => $flash->getMessages('warnings'), 'errors' => $flash->getMessages('errors')); $_SESSION['submit_token']['current'] = $current; } } showtime('pre-display'); // echo 'System::display end '.(gettimeofday(TRUE)-$start).'<br>'; // echo 'system::display (3),'.microtime(TRUE).'<br>'; $this->view->display('index_page.tpl', $cache_key); // echo 'system::display (4),'.microtime(TRUE).'<br>'; showtime('post-display'); }