public function saveProductsOrderAction() { $ordersString = $this->getRequest()->getParam('order'); $idGroup = $this->getRequest()->getParam('id'); $products = explode(',', $ordersString); $arrayAll = array(); //Needs_Tools::DeleteLegaturibyGroup( $groupId ); $modelGroupAll = new Default_Model_ProductGroups(); $selectAll = $modelGroupAll->getMapper()->getDbTable()->select()->where('idGroup = ?', $idGroup); $resultsAll = $modelGroupAll->fetchAll($selectAll); foreach ($resultsAll as $value) { $arrayAll[] = $value->getIdProduct(); //all the products that are currently in the table } $resultDiff = array_diff($arrayAll, $products); foreach ($resultDiff as $deleteProd) { Needs_Tools::DeleteLegaturi($deleteProd); //here we delete the prods that were before in the table, but are not anymore in the new list of prods } foreach ($products as $key => $value) { $model = new Default_Model_ProductGroups(); $select = $model->getMapper()->getDbTable()->select()->where('idProduct = ?', $value)->where('idGroup = ?', $idGroup); $model->fetchRow($select); if ($model->getId() != NULL) { $id = $model->getId(); $model->find($id); $model->setOrder($key); $model->saveOrder(); } } }
public function editAction() { $auth = Zend_Auth::getInstance(); $authAccount = $auth->getStorage()->read(); if (null != $authAccount) { if (null != $authAccount->getId()) { $user = new Default_Model_Users(); $user->find($authAccount->getId()); } } $id = $this->getRequest()->getParam('id'); /*$hasAccess = Needs_Roles::hasAccess(Zend_Registry::get('user')->getIdRole(),'adaugare_proiect'); if(!$hasAccess) { $this->_redirect(WEBROOT.'products'); }*/ $model = new Default_Model_RecurrentExpenses(); if ($model->find($id)) { $form = new Default_Form_RecurrentExpenses(); $form->edit($model); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/recurrent-expenses/edit-expense.phtml')))); $this->view->form = $form; if ($this->getRequest()->isPost()) { if ($this->getRequest()->getPost('submit')) { if ($form->isValid($this->getRequest()->getPost())) { $oldDate = $model->getDate(); $post = $this->getRequest()->getPost(); $model->setOptions($form->getValues()); $model->setDate(date("Y-m-d", strtotime($post["date"]))); if ($oldDate != date("Y-m-d", strtotime($post["date"]))) { $model->setDatePaid(); } $model->setType('0'); if ($expenseId = $model->save()) { if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) { foreach ($post['galleryFiles'] as $valuesGallery) { $tmpFiles = new Default_Model_TempFiles(); if ($tmpFiles->find($valuesGallery)) { $post = $this->getRequest()->getPost(); $gallery = new Default_Model_FileManager(); $gallery->setOptions($form->getValues()); $gallery->setType($tmpFiles->getFileType()); $gallery->setSize($tmpFiles->getFileSize()); $gallery->setModule('sharedfiles'); $gallery->setIdMessage($expenseId); $gallery->setIdUser(1); $gallery->setName($tmpFiles->getFileName()); $savedId = $gallery->save(); if ($savedId) { $shared = new Default_Model_SharedList(); $shared->setIdUser(Zend_Registry::get('user')->getId()); $shared->setIdFile($savedId); $shared->save(); } //copy picture and crop $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tmpFiles->getFileName(); $targetFile = APPLICATION_PUBLIC_PATH . '/media/files/' . $tmpFiles->getFileName(); @copy($tempFile, $targetFile); @unlink($tempFile); $tmpFiles->delete(); } } //END:SAVE ATTACHMENTS } Needs_Tools::DeleteLegaturi($expenseId, '1'); $idGroup = $this->getRequest()->getParam('idGroup'); $modelGroup = new Default_Model_ProductGroups(); $modelGroup->setIdProduct($expenseId); $modelGroup->setIdGroup($idGroup); $modelGroup->setRepeated(1); $modelGroup->save(); $post = $this->getRequest()->getPost(); //mesaj de succes $this->_flashMessenger->addMessage("<div class='success canhide'><p>Recurrent expense was modified successfully<a href='javascript:;'></a></p></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Recurrent expense was not modified<a href='javascript:;'></a></p></div>"); } $this->_redirect(WEBROOT . 'recurrent-expenses'); } } } } }
public function deleteAction() { $userId = NULL; $auth = Zend_Auth::getInstance(); $authAccount = $auth->getStorage()->read(); if (null != $authAccount) { if (null != $authAccount->getId()) { $userId = $authAccount->getId(); } } $id = $this->getRequest()->getParam('id'); $model = new Default_Model_Expenses(); if ($model->find($id)) { if ($expenseId = $model->delete()) { Needs_Tools::DeleteLegaturi($expenseId); $this->_flashMessenger->addMessage("<div class='success canhide'><p>Expense was deleted successfully!<a href='javascript:;'></a></p></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Expense was not deleted!<a href='javascript:;'></a></p></div>"); } $this->_redirect('expenses'); } }