function action_insert_item($input) { $processedFields = array(); $trackerId = $input->trackerId->int(); if (!$trackerId) { return ['FORWARD' => ['controller' => 'tracker', 'action' => 'select_tracker']]; } $trackerName = $this->trackerName($trackerId); $definition = Tracker_Definition::get($trackerId); if (!$definition) { throw new Services_Exception_NotFound(); } $itemObject = Tracker_Item::newItem($trackerId); if (!$itemObject->canModify()) { throw new Services_Exception_Denied(); } $fields = $input->fields->none(); $forced = $input->forced->none(); if (empty($fields)) { $toRemove = array(); $processedFields = $itemObject->prepareInput($input); $fields = array(); foreach ($processedFields as $k => $f) { $permName = $f['permName']; $fields[$permName] = $f['value']; if (isset($forced[$permName])) { $toRemove[$permName] = $k; } } foreach ($toRemove as $permName => $key) { unset($fields[$permName]); unset($processedFields[$key]); } } else { $out = array(); foreach ($fields as $key => $value) { if ($itemObject->canModifyField($key)) { $out[$key] = $value; } } $fields = $out; } global $prefs; if ($prefs['feature_jquery_validation'] === 'y') { $validationjs = TikiLib::lib('validators')->generateTrackerValidateJS($definition->getFields()); TikiLib::lib('header')->add_jq_onready('$("#insertItemForm' . $trackerId . '").validate({' . $validationjs . $this->get_validation_options()); } $itemId = 0; if (!empty($fields) && $_SERVER['REQUEST_METHOD'] == 'POST') { foreach ($forced as $key => $value) { if ($itemObject->canModifyField($key)) { $fields[$key] = $value; } } // test if one item per user if ($definition->getConfiguration('oneUserItem', 'n') == 'y') { $tmp = TikiLib::lib('trk')->get_user_item($trackerId, $definition->getInformation()); if ($tmp > 0) { throw new Services_Exception(tr('Item could not be created. Only one item per user is allowed.'), 400); } } $itemId = $this->utilities->insertItem($definition, array('status' => $input->status->word(), 'fields' => $fields)); if ($itemId) { TikiLib::lib('unifiedsearch')->processUpdateQueue(); TikiLib::events()->trigger('tiki.process.redirect'); // wait for indexing to complete before loading of next request to ensure updated info shown if ($next = $input->next->url()) { $access = TikiLib::lib('access'); $access->redirect($next, tr('Item created')); } $item = $this->utilities->getItem($trackerId, $itemId); $item['itemTitle'] = $this->utilities->getTitle($definition, $item); return $item; } else { throw new Services_Exception(tr('Item could not be created.'), 400); } } $editableFields = $input->editable->none(); if (empty($editableFields)) { //if editable fields, show all fields in the form (except the ones from forced which have been removed). $displayedFields = $processedFields; } else { // if editableFields is set, only add the field if found in the editableFields array $displayedFields = array(); foreach ($processedFields as $k => $f) { $permName = $f['permName']; if (in_array($permName, $editableFields)) { $displayedFields[] = $f; } } } $status = $input->status->word(); if ($status === null) { // '=== null' means status was not set. if status is set to "", it skips the status and uses the default $status = $itemObject->getDisplayedStatus(); } else { $status = $input->status->word(); } $title = $input->title->none(); if (empty($title)) { // '=== null' means status was not set. if status is set to "", it skips the status and uses the default $title = tr('Create Item'); } else { $title = $title; } return array('title' => $title, 'trackerId' => $trackerId, 'trackerName' => $trackerName, 'itemId' => $itemId, 'fields' => $displayedFields, 'forced' => $forced, 'trackerLogo' => $definition->getConfiguration('logo'), 'modal' => $input->modal->int(), 'status' => $status, 'format' => $input->format->word()); }