/** * In this function, most actions of the module are carried out * and the page generation is started, distibuted and rendered. * @return void * @see solidbase/lib/Page#run() */ function run() { global $Templates, $USER, $CONFIG, $Controller, $DB; if (!$this->may($USER, READ | EDIT)) { errorPage('401'); return false; } /** * User input types */ $_REQUEST->setType('esave', 'any'); $_REQUEST->setType('view', 'string'); $_REQUEST->setType('edit', array('numeric', '#new#')); $_REQUEST->setType('del', 'numeric'); $_REQUEST->setType('lang', 'string'); $_POST->setType('einscal', 'any'); $_POST->setType('etitle', 'string'); $_POST->setType('activated', 'any'); $_POST->setType('eimg', 'numeric'); $_POST->setType('etxt', 'any'); $_POST->setType('eupdate', 'any'); $_POST->setType('flows', 'string', true); if ($_REQUEST['del']) { if ($Controller->{$_REQUEST['del']} && $Controller->{$_REQUEST['del']}->delete()) { Flash::create(__('Item removed'), 'confirmation'); } } /** * Save item */ do { $start = $stop = 0; $item = false; if ($_REQUEST['edit'] && $_REQUEST['esave']) { if (is_numeric($_REQUEST['edit'])) { $item = new NewsItem($_REQUEST['edit'], $_REQUEST['lang']); if (!$item || !is_a($item, 'FlowItem') || !$item->mayI(EDIT)) { Flash::create(__('Invalid item'), 'warning'); break; } } //FIXME: Further validation? if ($_POST['einscal']) { if (($start = Short::parseDateAndTime('cstart')) === false) { Flash::create(__('Invalid starttime'), 'warning'); break; } if (($stop = Short::parseDateAndTime('cend')) === false) { $stop = $start += 3600; } } if (!$_POST['etitle']) { Flash::create(__('Please enter a title')); break; } if (!$_POST['etxt']) { Flash::create(__('Please enter a text')); break; } if ($_REQUEST['edit'] === 'new') { $item = $Controller->newObj('FlowItem', $_REQUEST['lang']); $_REQUEST['edit'] = $item->ID; } if ($item) { $item->Name = $_POST['etitle']; $item->Image = $_POST['eimg']; $item->setActive(Short::parseDateAndTime('estart'), Short::parseDateAndTime('eend')); $item->Activated = isset($_POST['activated']); $item->saveContent(array('Text' => $_POST['etxt'])); if ($_POST['einscal']) { if ($item->Cal) { Calendar::editEvent($item->Cal, $_POST['etitle'], $_POST['etxt'], false, $start, $stop); } else { $item->Cal = Calendar::newEvent($_POST['etitle'], $_POST['etxt'], false, $start, $stop, 'News'); } } if (!$_POST['eupdate']) { foreach ($_POST['flows'] as $flow) { Flow::touch($item->ID, $flow); } } $Controller->forceReload($item); Flash::create(__('Your data was saved'), 'confirmation'); $_REQUEST->clear('edit'); $_POST->clear('einscal', 'etitle', 'etxt', 'cstart', 'cend', 'estart', 'eend', 'flows'); } else { Flash::create(__('Unexpected error'), 'warning'); break; } } } while (false); /** * Here, the page request and permissions decide what should be shown to the user */ if (is_numeric($_REQUEST['edit'])) { $this->editView($_REQUEST['edit'], $_REQUEST['lang']); } else { $this->content = array('header' => __('Flows'), 'main' => $this->mainView()); } $Templates->admin->render(); }