function onNewEntry($workflow, $args) { $categoriesArray = explode(',', $workflow->category); $entry = $args[0]; if (!in_array($entry->cat_id, $categoriesArray)) { return false; } //Check to see if this a new Article or an old one being modified $id = JRequest::getInt('id', 0, 'post'); //Create History Entry require_once JWF_BACKEND_PATH . DS . 'models' . DS . 'history.php'; require_once JWF_BACKEND_PATH . DS . 'models' . DS . 'item.php'; $historyModel = new JWFModelHistory(); $itemModel = new JWFModelItem(); if ($id == 0) { $historyTitle = JText::_('New Item Created'); $historyMsg = new stdClass(); $historyMsg->type = 'create'; $historyMsg->title = $_POST['title']; $historyMsg->version = 0; $historyItemId = lastInsertId(); $currentStation = reset($workflow->stations); //First station } else { $historyTitle = JText::_('Item modified'); $historyMsg = new stdClass(); $historyMsg->type = 'modify'; $historyMsg->title = $_POST['title']; $historyMsg->version = $this->getLatestRevisionId($id); $historyItemId = $id; $stationId = $itemModel->getCurrentStationId($workflow->id, $id); $currentStation = $workflow->stations[$stationId]; } if ($currentStation != null) { $historyModel->add($workflow->id, $currentStation, $historyItemId, 'component.content', $historyTitle, $historyMsg); } //Done creating history entry //Exit if this is an old one if ($id != 0) { return false; } $firstStation = reset($workflow->stations); $db =& JFactory::getDBO(); $sql = "UPDATE #__aards_ads a SET a.published=0 WHERE a.id = {$id}"; $db->setQuery($sql); $db->query(); return $itemModel->enter($workflow->id, $firstStation->id, $entry->id, $entry->ad_name, 0); }
function save($workflow, $steps, $storedComments, $incomingComment) { $pManager =& getPluginManager(); $pManager->loadPlugins('acl'); $response = $pManager->invokeMethod('acl', 'getMyGroupId', array($workflow->acl), null); $myGroups = $response[$workflow->acl]; $user =& JFactory::getUser(); $isNew = intval($incomingComment['commentID']) == -1 ? true : false; $isAuthorized = false; //The HUGE Authorization routine /* Global Administrator -> Allowed to do everything Old Comment Workflow manager -> Allowed after making sure the supplied WID matches a workflow they have authority upon Normal user -> Allowed if s/he's the creator of the comment New Comment Workflow manager -> Allow if WID matches a workflow they have authority upon Normal user -> Allowed only if the item is in their station */ if (canManageWorkflows()) { $isAuthorized = true; } elseif (in_array($workflow->admin_gid, array_keys($myGroups))) { $isAuthorized = true; } else { if ($isNew) { //Allow normal users to add comments to the latest step ONLY $currentStep = searchObjectArray($steps, 'current', 1); foreach ($myGroups as $gid => $name) { if ($workflow->stations[$incomingComment['sid']]->group == $gid) { if ($currentStep->iid == $incomingComment['iid'] && $currentStep->id == $incomingComment['tid']) { $isAuthorized = true; } } } } else { $currentComment = searchObjectArray($storedComments, 'id', $incomingComment['commentID']); if ($currentComment != null && $user->get('id') == $currentComment->created_by) { $isAuthorized = true; } } } if (!$isAuthorized) { return 0; } $datenow =& JFactory::getDate(); $incomingComment['type'] = 'comments'; if (!$isNew) { $incomingComment['id'] = intval($incomingComment['commentID']); $incomingComment['modified'] = $datenow->toMySQL(); $incomingComment['modified_by'] = $user->get('id'); } else { $incomingComment['created'] = $datenow->toMySQL(); $incomingComment['modified'] = $datenow->toMySQL(); $incomingComment['created_by'] = $user->get('id'); $incomingComment['modified_by'] = $user->get('id'); } $incomingComment['value'] = base64_encode($incomingComment['text']); require_once JWF_BACKEND_PATH . DS . 'models' . DS . 'history.php'; $historyModel = new JWFModelHistory(); require_once JWF_BACKEND_PATH . DS . 'models' . DS . 'field.php'; $fieldModel = new JWFModelField(); if ($fieldModel->save($incomingComment)) { $historyObject = new stdClass(); if ($isNew) { $historyObject->type = 'create'; $historyObject->value = $incomingComment['value']; $historyModel->add($workflow->id, $workflow->stations[$incomingComment['sid']], $incomingComment['iid'], 'field.comments', JText::_('Comment Added'), $historyObject); } else { $historyObject->type = 'modify'; $historyObject->value = $incomingComment['value']; $historyModel->add($workflow->id, $workflow->stations[$incomingComment['sid']], $incomingComment['iid'], 'field.comments', JText::_('Comment Modified'), $historyObject); } return 1; } return 0; }