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 indexAction() { // BEGIN:FILTERS $filters = array(); //array with variables to send to pagination (filters) $type = $this->getRequest()->getParam('type'); //can be 'sent','trash' or empty (inbox) $this->view->type = $type; if (!empty($type)) { $filters['type'] = $type; } $searchTxt = $this->getRequest()->getParam('searchTxt'); if (!empty($searchTxt)) { $filters['searchTxt'] = $searchTxt; } $this->view->search = $filters; // END:FILTERS //BEGIN:SEARCH FORM $formSearch = new Default_Form_MessagesSearch(); $formSearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/messages-search.phtml')))); $this->view->formSearch = $formSearch; //END:SEARCH FORM //BEGIN:FORM ADD $replyId = $this->getRequest()->getParam('replyId'); $form = new Default_Form_Messages(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/messages.phtml')))); if (!empty($replyId)) { $model = new Default_Model_Messages(); $model->find($replyId); if ($model->getIdUserTo() == Zend_Registry::get('user')->getId()) { $form->reply($model); } } $this->view->form = $form; if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost(); if (!empty($post['action']) && $post['action'] == 'add') { //if is valid save message if ($form->isValid($this->getRequest()->getPost())) { //save message $model = new Default_Model_Messages(); $model->setOptions($form->getValues()); $model->setIdUserFrom(Zend_Registry::get('user')->getId()); $savedId = $model->save(); if ($savedId) { //BEGIN:SAVE ATTACHMENTS if (!empty($post['galleryFiles']) && is_array($post['galleryFiles'])) { foreach ($post['galleryFiles'] as $valuesGallery) { $tmpFiles = new Default_Model_TempFiles(); if ($tmpFiles->find($valuesGallery)) { $gallery = new Default_Model_UploadedFiles(); $gallery->setIdMessage($savedId); $gallery->setType($tmpFiles->getFileType()); $gallery->setIdUser(Zend_Registry::get('user')->getId()); $gallery->setModule('messages'); $gallery->setName($tmpFiles->getFileName()); $gallery->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 $this->_flashMessenger->addMessage("<div class='success canhide'><p>Your message was succesfully sent.</p><a href='javascript:;'></a></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error sending message!</p><a href='javascript:;'></a></div>"); } $this->_redirect(WEBROOT . 'messages'); } } } //END:FORM ADD //BEGIN:LISTING $model = new Default_Model_Messages(); $select = $model->getMapper()->getDbTable()->select(); if (!empty($type) && $type == 'sent') { //sent $select->from(array('u' => 'messages'), array('u.id', 'idUserFrom' => 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserFrom = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedFrom')->where('NOT u.trashedFrom'); } elseif (!empty($type) && $type == 'trash') { //trash $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where("" . "(u.idUserTo = '" . Zend_Registry::get('user')->getId() . "' AND u.trashedTo = 1 AND NOT u.deletedTo) " . "OR " . "(u.idUserFrom = '" . Zend_Registry::get('user')->getId() . "' AND u.trashedFrom = 1 AND NOT u.deletedFrom)"); } else { //inbox $select->from(array('u' => 'messages'), array('u.id', 'u.idUserFrom', 'u.idUserTo', 'u.subject', 'u.created'))->where('u.idUserTo = ?', Zend_Registry::get('user')->getId())->where('NOT u.deletedTo')->where('NOT u.trashedTo'); } if (!empty($searchTxt)) { $select->where("u.subject LIKE ('%" . $searchTxt . "%') OR u.message LIKE ('%" . $searchTxt . "%')"); } $select->order('u.created DESC')->setIntegrityCheck(false); // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->inboxNr = Needs_Messages::getInboxMessagesNumber(); $this->view->sentNr = Needs_Messages::getSentMessagesNumber(); $this->view->trashNr = Needs_Messages::getTrashMessagesNumber(); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); //END:LISTING }
public static function getTempFiles($types) { $type = (array) $types; $model = new Default_Model_TempFiles(); $select = $model->getMapper()->getDbTable()->select()->where('type IN (?)', $type)->where('userId = ?', Zend_Registry::get('user')->getId()); $result = $model->fetchAll($select); return $result; }
public function fetchAll($select) { $resultSet = $this->getDbTable()->fetchAll($select); $entries = array(); foreach ($resultSet as $row) { $role = new Default_Model_TempFiles(); $role->setOptions($row->toArray())->setMapper($this); $entries[] = $role; } return $entries; }
public function indexAction() { // BEGIN:FILTERS $filters = array(); //array with variables to send to pagination (filters) $searchTxt = $this->getRequest()->getParam('searchTxt'); if (!empty($searchTxt)) { $filters['searchTxt'] = $searchTxt; } $this->view->search = $filters; // END:FILTERS //BEGIN:SEARCH FORM $formSearch = new Default_Form_FileManagerSearch(); $formSearch->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/file-manager-search.phtml')))); $this->view->formSearch = $formSearch; //END:SEARCH FORM //BEGIN:FORM ADD $replyId = $this->getRequest()->getParam('replyId'); $form = new Default_Form_FileManager(); $form->setDecorators(array('ViewScript', array('ViewScript', array('viewScript' => 'forms/file-manager.phtml')))); $this->view->form = $form; $formshare = new Default_Form_ShareFile(); if ($this->getRequest()->isPost()) { $post = $this->getRequest()->getPost(); if (!empty($post['action']) && $post['action'] == 'add') { //if is valid save message if ($form->isValid($this->getRequest()->getPost())) { //BEGIN:SAVE ATTACHMENTS 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->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 $this->_flashMessenger->addMessage("<div class='success canhide'><p>Your file was succesfully uploaded.</p><a href='javascript:;'></a></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error uploading file!</p><a href='javascript:;'></a></div>"); } $this->_redirect(WEBROOT . 'file-manager'); } } if (!empty($post['action']) && $post['action'] == 'sharefile') { //if is valid save shared file message if ($formshare->isValid($this->getRequest()->getPost())) { $model = new Default_Model_Messages(); $model->setOptions($formshare->getValues()); $model->setIdUserFrom(Zend_Registry::get('user')->getId()); $model->save(); //BEGIN:SAVE ATTACHMENTS $shared = new Default_Model_SharedList(); $shared->setOptions($formshare->getValues()); //echo $formshare->getValue('idUserTo'); //die();//aici e ok $shared->setIdUser($formshare->getValue('idUserTo')); //aici nu seteaza $shared->save(); //END:SAVE ATTACHMENTS $this->_flashMessenger->addMessage("<div class='success canhide'><p>Your file was succesfully shared.</p><a href='javascript:;'></a></div>"); } else { $this->_flashMessenger->addMessage("<div class='failure canhide'><p>Error sharing file!</p><a href='javascript:;'></a></div>"); } $this->_redirect(WEBROOT . 'file-manager'); } } //END:FORM ADD //BEGIN:LISTING $model = new Default_Model_FileManager(); $select = $model->getMapper()->getDbTable()->select(); //if(!empty($type) && $type == 'sent'){ //sent $select->from(array('sl' => 'shared_list'), array('sl.idUser', 'sl.created'))->joinLeft(array('uf' => 'uploaded_files'), 'uf.id = sl.idFile', array('uf.id', 'uf.name', 'uf.description', 'uf.type', 'uf.size'))->where('sl.idUser = ?', Zend_Registry::get('user')->getId())->where('NOT sl.deleted'); // } if (!empty($searchTxt)) { $select->where("uf.name LIKE ('%" . $searchTxt . "%') OR uf.description LIKE ('%" . $searchTxt . "%')"); } $select->order('sl.created DESC')->setIntegrityCheck(false); // pagination $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber($this->_getParam('page')); $paginator->setPageRange(5); Zend_Paginator::setDefaultScrollingStyle('Sliding'); Zend_View_Helper_PaginationControl::setDefaultViewPartial(array('_pagination.phtml', $filters)); $this->view->result = $paginator; $this->view->itemCountPerPage = $paginator->getItemCountPerPage(); $this->view->totalItemCount = $paginator->getTotalItemCount(); //END:LISTING }
public function deleteProjectUploadAction() { $return = ''; $fileId = $this->getRequest()->getParam('fileId'); $tempFiles = new Default_Model_TempFiles(); if ($tempFiles->find($fileId)) { $return = $tempFiles->getType(); $tempFile = APPLICATION_PUBLIC_PATH . '/media/temps/' . $tempFiles->getFileName(); @unlink($tempFile); $tempFiles->delete(); } echo Zend_Json_Encoder::encode($return); }