public function createAction()
 {
     $this->view->page_heading = 'Create New Template';
     $form = new Admin_Form_CreateTemplate();
     $this->view->form = $form;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($form->isValid($this->getRequest()->getPost())) {
         $template = new App_Model_Template();
         $template->setName($form->name->getValue());
         $template->setDescription($form->description->getValue());
         if (!$form->content->receive()) {
             $form->content->addError('There was an error processing the file');
             return;
         }
         $template->setContent(file_get_contents($form->content->getFileName()));
         unlink($form->content->getFileName());
         try {
             $this->getDb()->persist($template);
             $this->getDb()->flush();
         } catch (PDOException $e) {
             $dbException = new App_Model_DBExceptionDecorator($e);
             if ($dbException->isDuplicateKeyViolation()) {
                 $form->name->addError('A template with this name already exists');
                 return;
             }
         }
         $this->addFlashMessageSuccess('Your new template has been created successfully');
         $this->_redirect($this->getUrl(array(), 'admin_view_templates'));
     }
 }
 public function createAction()
 {
     $folder = $this->getFolderFromParams();
     if (!$folder) {
         return $this->folderNotFound();
     }
     $this->view->page_heading = 'Create A New Folder In ' . $folder->getName();
     $form = new Admin_Form_CreateFolder();
     $this->view->form = $form;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($form->isValid($this->getRequest()->getPost())) {
         $new_folder = new App_Model_Folder();
         $new_folder->setName($form->name->getValue());
         $new_folder->setParent($folder);
         try {
             $this->getDb()->persist($new_folder);
             $this->getDb()->flush();
         } catch (PDOException $e) {
             $dbException = new App_Model_DBExceptionDecorator($e);
             if ($dbException->isDuplicateKeyViolation()) {
                 $form->name->addError('A folder with this name already exists within the parent folder');
                 return;
             }
         }
         $this->addFlashMessageSuccess('Your new folder has been created successfully');
         $this->_redirect($this->getUrl(array('folder_id' => $folder->getId()), 'admin_view_folder'));
     }
 }
 public function createAction()
 {
     $folder = $this->getDb()->getRepository('App_Model_Folder')->find($this->getRequest()->getParam('folder_id'));
     if (!$folder) {
         $this->addFlashMessageError('Folder not found');
         $this->_redirect($this->getUrl(array(), 'admin_index'));
     }
     $this->view->page_heading = 'Create New Media File';
     $form = new Admin_Form_CreateFile();
     $this->view->form = $form;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($form->isValid($this->getRequest()->getPost())) {
         $file = new App_Model_File();
         $file->setName($form->name->getValue());
         $file->setFolder($folder);
         if (!$form->file->receive()) {
             $form->file->addError('There was an error processing the file');
             return;
         }
         $path_parts = pathinfo($form->file->getFileName());
         $file->setExtension($path_parts['extension']);
         try {
             $this->getDb()->persist($file);
             $this->getDb()->flush();
             if (!@rename($form->file->getFileName(), $file->getFullPath(Zend_Registry::get('media_path')))) {
                 throw new App_Model_FileMoveException();
             }
             $this->addFlashMessageSuccess('Your new media has been created successfully');
             $this->_redirect($this->getUrl(array('folder_id' => $folder->getId()), 'admin_view_folder'));
         } catch (PDOException $e) {
             $dbException = new App_Model_DBExceptionDecorator($e);
             if ($dbException->isDuplicateKeyViolation()) {
                 $form->name->addError('A file with this name already exists in this folder');
             } else {
                 throw $e;
             }
         } catch (App_Model_FileMoveException $e) {
             $this->getDb()->remove($file);
             $this->getDb()->flush();
             $form->file->addError('There was an error processing the file');
         }
     }
 }
 public function createAction()
 {
     $folder = $this->getDb()->getRepository('App_Model_Folder')->find($this->getRequest()->getParam('folder_id'));
     if (!$folder) {
         $this->addFlashMessageError('Folder not found');
         $this->_redirect($this->getUrl(array(), 'admin_index'));
     }
     $templates = $this->getDb()->getRepository('App_Model_Template')->findAll();
     if (!$templates) {
         $this->addFlashError('There are currently no templates available. You must create at least one template before creating a webpage');
         $this->_redirect($this->getUrl(array('folder_id' => $folder->getId()), 'admin_create_template'));
     }
     $this->view->templates = $templates;
     $this->view->page_heading = 'Create New Webpage';
     $form = new Admin_Form_CreatePage($templates);
     $this->view->form = $form;
     if (!$this->getRequest()->isPost()) {
         return;
     }
     if ($form->isValid($this->getRequest()->getPost())) {
         $template = $this->getDb()->getRepository('App_Model_Template')->find($form->template->getValue());
         if (!$template) {
             $this->form->template->addError('You must select a template');
         }
         $page = new App_Model_Page();
         $page->setName($form->name->getValue());
         $page->setFolder($folder);
         $page->setTemplate($template);
         $template_parser = new App_Model_TemplateParser($template);
         $page->setSections($template_parser->generateSections());
         try {
             $this->getDb()->persist($page);
             $this->getDb()->flush();
             $this->addFlashMessageSuccess('Your new webpage has been created successfully');
             $this->_redirect($this->getUrl(array('folder_id' => $folder->getId()), 'admin_view_folder'));
         } catch (PDOException $e) {
             $dbException = new App_Model_DBExceptionDecorator($e);
             if ($dbException->isDuplicateKeyViolation()) {
                 $form->name->addError('A webpage with this name already exists in this folder');
             } else {
                 throw $e;
             }
         }
     }
 }
 public function editAction()
 {
     $this->view->page_heading = 'Edit User';
     $form = new Admin_Form_EditUser();
     $this->view->form = $form;
     $user = $this->getDb()->getRepository('App_Model_User')->find($this->getRequest()->getParam('user_id'));
     if (!$user) {
         $this->addFlashMessageError('User does not exist');
         $this->_redirect($this->getUrl(array(), 'admin_view_users'));
     }
     $form->email->setValue($user->getEmail());
     if (!$this->getRequest()->isPost()) {
         return;
     }
     $is_form_valid = $form->isValid($this->getRequest()->getPost());
     if ($form->new_password->getValue() != $form->new_password_confirm->getValue()) {
         $form->new_password_confirm->addError('This does not match the other password given');
         $is_form_valid = false;
     }
     if (!$user->doesPasswordEqual($form->current_password->getValue())) {
         $form->current_password->addError('Incorrect password');
         $is_form_valid = false;
     }
     if ($is_form_valid) {
         $user->setEmail($form->email->getValue());
         $user->setPassword($form->new_password->getValue());
         $user->setIsSuperAdmin(false);
         try {
             $this->getDb()->persist($user);
             $this->getDb()->flush();
             $this->addFlashMessageSuccess('User has been updated successfully');
             $this->_redirect($this->getUrl(array(), 'admin_view_users'));
         } catch (PDOException $e) {
             $dbException = new App_Model_DBExceptionDecorator($e);
             if ($dbException->isDuplicateKeyViolation()) {
                 $form->email->addError('A user with that email address already exists');
             } else {
                 throw $e;
             }
         }
     }
 }