public function editElementAction() { $elementClass = $this->_getParam('className'); $id = $this->_getParam('id'); $activityId = $this->_getParam('activity_id'); $parentId = $this->_getParam('parent_id'); $isMultiple = $this->_getParam('isMultiple', 1); if (!$elementClass) { $this->_helper->FlashMessenger->addMessage(array('error' => "Could not\n fetch element.")); $this->_redirect("/wep/dashboard"); } $elementName = "Iati_Aidstream_Element_" . $elementClass; $element = new $elementName(); if ($isMultiple == '0') { $element->setIsMultiple(false); } if ($data = $this->getRequest()->getPost()) { $element->setData($data[$element->getClassName()]); $form = $element->getForm(); if ($form->validate()) { //$eleId will be null is element is deleted or in case of db error $eleId = $element->save($data[$element->getClassName()], $activityId); $activityHashModel = new Model_ActivityHash(); $updated = $activityHashModel->updateActivityHash($activityId); if (!$updated) { $type = 'message'; $message = 'No Changes Made'; } else { $oldState = Model_Activity::getActivityStatus($activityId); Model_Activity::updateActivityUpdatedInfo($activityId); $type = 'message'; $message = $element->getDisplayName() . " successfully updated."; } $this->_helper->FlashMessenger->addMessage(array($type => $message)); // In case of update notify the user about state change. if ($updated && $oldState != Iati_WEP_ActivityState::STATUS_DRAFT) { $this->_helper->FlashMessenger->addMessage(array('state-change-flash-message' => "The\n activity state is changed back to Draft.\n You must complete and verify in order\n to publish the activity.")); } if ($element->getClassName() == "Transaction" || $element->getClassName() == "Result") { $this->_redirect("activity/list-elements?classname={$elementClass}" . "&activity_id={$activityId}"); } // Check if save and view button was clicked if ($data['save_and_view'] || $data[$element->getClassName()]['save_and_view']) { $this->_redirect('activity/view-activity-info/?activity_id=' . $activityId); } //In case the eleId is not present i.e the element is deleted redirect to add page. if (!$eleId) { $this->_redirect("activity/add-element?className={$elementClass}" . "&activity_id={$activityId}"); } } else { $form->populate($data); $this->_helper->FlashMessenger->addMessage(array('error' => "You have some problem in your\n data. Please correct and save again")); } } else { //This can be used to edit element at any level by providing parent id. if ($parentId) { $data[$element->getClassName()] = $element->fetchData($parentId, true); } else { if ($id) { $data = $element->fetchData($id); } else { if ($element->getClassName() == 'Activity') { $data = $element->fetchData($activityId); } else { $data[$element->getClassName()] = $element->fetchData($activityId, true); } } } if (empty($data[$element->getClassName()])) { $this->_redirect("/activity/add-element?className={$elementClass}" . "&activity_id={$activityId}"); } $element->setData($data[$element->getClassName()]); $form = $element->getForm(); } /* @todo this part of code should be moved to base form or base element */ if (Iati_Aidstream_ElementSettings::isHandledIndividually($element->getClassName())) { $form->addElement('submit', 'save', array('class' => 'form-submit', 'label' => 'Update ' . $element->getDisplayName())); } else { $form->addSubmitButton('Save'); } $this->view->form = $form; $this->view->activityInfo = Model_Activity::getActivityInfo($activityId); $this->view->elementClass = $element->getClassName(); $this->view->displayName = $element->getDisplayName(); $this->view->blockManager()->enable('partial/activitymenu.phtml'); $this->view->blockManager()->disable('partial/primarymenu.phtml'); $this->view->blockManager()->disable('partial/add-activity-menu.phtml'); $this->view->blockManager()->disable('partial/usermgmtmenu.phtml'); $this->view->blockManager()->disable('partial/published-list.phtml'); $this->view->blockManager()->disable('partial/organisation-data.phtml'); $this->view->blockManager()->disable('partial/download-my-data.phtml'); $this->view->blockManager()->disable('partial/uploaded-docs.phtml'); }
public function uploadTransactionAction() { $activityId = $this->_getParam('activity_id'); $form = new Form_Wep_UploadTransaction(); if ($data = $this->getRequest()->getPost()) { if ($form->isValid($data)) { $uploadDir = Zend_Registry::get('config')->public_folder . "/files/csv/uploads"; $upload = new Zend_File_Transfer_Adapter_Http(); $upload->setDestination($uploadDir); $source = $upload->getFileName(); try { $upload->receive(); $csvHandler = new Model_CsvUpload(); $csvHandler->setInputFile($source); $csvHandler->readCsv(); $headerCount = $csvHandler->countHeader(); if ($headerCount == 34) { $count = $csvHandler->uploadDetailDataToTransaction($activityId); } elseif ($headerCount == 11) { $count = $csvHandler->uploadSimpleDataToTransaction($activityId); } if (!$count) { $messanger = $this->_helper->FlashMessenger; $messanger->addMessage(array('trans-error' => 'You have following errors. Please correct the errors.')); if ($csvHandler->getErrors()) { foreach ($csvHandler->getErrors() as $tranCount => $error) { $tranNo = $tranCount + 1; if (!empty($error)) { $messanger->addMessage(array('trans-error' => "<div class='tran-no'>\n Transaction no: {$tranNo}</div>")); foreach ($error as $errormessage) { $messanger->addMessage(array('trans-error' => " # " . $errormessage['message'])); } } } } else { $messanger->addMessage(array('trans-error' => "<div class='tran-no'>\n Something went wrong. Please check your csv file.</div>")); } } else { $activityHashModel = new Model_ActivityHash(); $updated = $activityHashModel->updateActivityHash($activityId); if (!$updated) { // Update hash and status $type = 'message'; $message = 'No Changes Made'; } else { $oldState = Model_Activity::getActivityStatus($activityId); Model_Activity::updateActivityUpdatedInfo($activityId); } if ($updated && $oldState != Iati_WEP_ActivityState::STATUS_DRAFT) { // In case of update notify the user about state change. $this->_helper->FlashMessenger->addMessage(array('state-change-flash-message' => "The\n activity state is changed back to Draft.\n You must complete and verify in order\n to publish the activity.")); } $this->_helper->FlashMessenger->addMessage(array('message' => "{$count['add']} transaction(s) added. {$count['update']} transaction(s) updated.")); $this->_redirect("/activity/list-elements/?activity_id=" . $activityId . "&classname=Activity_Transaction"); } } catch (Zend_File_Transfer_Exception $e) { $e->getMessage(); } } else { $form->populate($data); } } $this->view->form = $form; $this->view->activityId = $activityId; $this->view->blockManager()->enable('partial/override-activity.phtml'); $this->view->blockManager()->enable('partial/activitymenu.phtml'); $this->view->blockManager()->disable('partial/primarymenu.phtml'); $this->view->blockManager()->disable('partial/add-activity-menu.phtml'); $this->view->blockManager()->disable('partial/usermgmtmenu.phtml'); $this->view->blockManager()->disable('partial/published-list.phtml'); $this->view->blockManager()->disable('partial/organisation-data.phtml'); $this->view->blockManager()->disable('partial/uploaded-docs.phtml'); $this->view->blockManager()->disable('partial/download-my-data.phtml'); }