public function indexAction() { //TODO: Überprüfung auf Passwort und unique E-Mail auch in EditController $namespace = new Zend_Session_Namespace('user'); if ($this->getRequest()->isPost() and $this->form->isValid($this->getRequest()->getParams())) { if ($this->form->getValue('Token') == $namespace->Token) { //get parameters for test of unique username $userTable = new User(); $tableRow = User::COL_USERNAME; $value = $this->getRequest()->getParam(User::COL_USERNAME); if ($this->getRequest()->getParam(User::COL_PASSWORD) != $this->getRequest()->getParam(User_Form_Edit::PASSWORD_CLONE)) { $element = $this->form->getElement(User_Form_Edit::PASSWORD_CLONE); $element->addError("Error: Your password and the repeating don't match."); $this->form->markAsError(); return $this->render('index'); } elseif (Default_SimpleQuery::isValueInTableColumn($value, $userTable, $tableRow, 'string')) { $element = $this->form->getElement(User::COL_USERNAME); $element->addError("Error: This username is already used."); $this->form->markAsError(); return $this->render('index'); } else { try { //values checked, insert $guid = Ble422_Guid::getGuid(); $userTable = new User(); $userTable->getAdapter()->beginTransaction(); $userId = $userTable->insert(array(User::COL_USERNAME => $this->form->getValue(User::COL_USERNAME), User::COL_FIRSTNAME => $this->form->getValue(User::COL_FIRSTNAME), User::COL_LASTNAME => $this->form->getValue(User::COL_LASTNAME), User::COL_PASSWORD => "{SHA}" . base64_encode(pack("H*", sha1($this->form->getValue(User::COL_PASSWORD)))), User::COL_EMAIL => $this->form->getValue(User::COL_USERNAME), User::COL_INSTITUTION => $this->form->getValue(User::COL_INSTITUTION), User::COL_STREET => $this->form->getValue(User::COL_STREET), User::COL_COUNTRY => $this->form->getValue(User::COL_COUNTRY), User::COL_PHONE => $this->form->getValue(User::COL_PHONE), User::COL_FAX => $this->form->getValue(User::COL_FAX), User::COL_CITY => $this->form->getValue(User::COL_CITY), User::COL_GUID => $guid, User::COL_ACTIVE => 0)); $toAdress = $this->form->getValue(User::COL_USERNAME); $bodyText = "Please click this link to confirm your new account:\r\n" . Zend_Registry::get('APP_HOST') . '/default/registeruser/confirm/' . User::COL_GUID . '/' . $guid; $mail = new Default_Mail($toAdress, 'WebGR register user message', $bodyText); $mail->send(); $userTable->getAdapter()->commit(); $namespace->Token = ''; $this->redirectTo('success'); } catch (Exception $e) { $userTable->getAdapter()->rollBack(); throw new Exception('error at register a new user: '******'success'); } } else { //no post or some element(s) not valid //$this->form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl()."/user/new"); if ($this->form->getValue('Token') == null) { $guid = new Ble422_Guid(); $namespace->Token = $guid->__toString(); $this->form->getElement('Token')->setValue($guid->__toString()); } } }
public function indexAction() { //remove all elements, only username (=e-mail) stays $this->form = new User_Form_Edit(); $elems = $this->form->getElements(); foreach ($elems as $elem) { if (!($elem->getName() == User::COL_USERNAME || $elem->getName() == 'submit')) { $this->form->removeElement($elem->getName()); } } //#####################new################################### $this->form->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'table', 'class' => 'login_form')), array('Description', array('placement' => 'prepend')), 'Form')); $this->form->setElementDecorators(array('ViewHelper', 'Errors', array('decorator' => array('td' => 'HtmlTag'), 'options' => array('tag' => 'td')), array('Label', array('tag' => 'td')), array('decorator' => array('tr' => 'HtmlTag'), 'options' => array('tag' => 'tr')))); //########################################################### if ($this->getRequest()->isPost()) { if ($this->form->isValid($this->getRequest()->getParams())) { //lookup if e-mail exists and send mail $e_mail = $this->form->getValue(User::COL_USERNAME); if (Default_SimpleQuery::isValueInTableColumn($e_mail, new User(), User::COL_USERNAME, 'string')) { $user = new User(); $select = $user->select(); $where = $user->getAdapter()->quoteInto(User::COL_USERNAME . ' = ?', $e_mail, 'string'); $select->where($where); $rowset = $user->fetchAll($select); if ($rowset->count() == 1) { $newGuid = Ble422_Guid::getGuid(); $data = array(User::COL_GUID => $newGuid); $user->update($data, $where); $toAdress = $this->form->getValue(User::COL_USERNAME); $host = Zend_Registry::get('APP_HOST'); $bodyText = 'Please click this link to reset your password:'******'/default/forgotpassword/myresetpassword/' . User::COL_GUID . '/' . $newGuid; $mail = new Default_Mail($toAdress, 'WebGR forgot password message', $bodyText); $mail->send(); } } //show message anyway, not depending on success Zend_Registry::set('MESSAGE', 'if you are known to the system, the message was sent'); $this->view->message = 'if you are known to the system, the message was sent'; $this->render('message'); } else { //not valid $this->view->form = $this->form; } } else { //not post $this->view->form = $this->form; } //prevent robots and abuser to: //- send e-mail to all possible e-mail adresses //- send massive multiple e-mails to known adress //- e-mail server dos //lookup if e-mail exists and send mail //show message anyway, not depending on success }
/** * * @param $key the subdirectory for csv and image files * @return unknown_type importImages/importFishes arrays with the IDs as key to see where dataimport eventually went wrong */ public function beginImport($key) { $this->key = $key; $this->logger = new Ble422_ArrayLogger(self::RELATIVE_PATH_IMPORT_LOGS . $this->key . '_import_log.txt'); $this->loadFromNamespace(); // foreach ($this->rowHasUniqueUploadedFile as $key => $value) { $preparedDatasets[$key] = $this->preparedDatasets[$key]; } // $importedFishes = array(); $importedImages = array(); $i = 0; $j = 0; $fishForm = new Fish_Form_Edit(); $fish = new Fish(); $imageForm = new Image_Form_Edit(); $image = new Image(); $numberCopiedFiles = 0; $dbAdapter = $fish->getAdapter(); $dbAdapter->beginTransaction(); try { //changed to local preparedDatasets to filter datasets with uploaded files used in other datasets of import foreach ($preparedDatasets as $rowNo => $dataset) { if (Default_SimpleQuery::isValueInTableColumn($dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], $fish, Fish::COL_SAMPLE_CODE, 'string')) { //get id from already existing fish dataset and go on if ($values = Default_SimpleQuery::getValuesFromTableColumnWhere($fish, Fish::COL_ID, Fish::COL_SAMPLE_CODE, $dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], 'string')) { //test for amount of values, must be 1 if (count($values) == 1) { $fishId = $values[0]; } else { throw new Zend_Exception('Error: more/less than 1 id found for fish sample code'); } } } else { //create new fish dataset $fishBaseData = array(Fish::COL_SAMPLE_CODE => $dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], Fish::COL_USER_ID => $this->userId); $fishMetaData = $dataset['fishFormDataset']; //unset($fishMetaData[Fish::COL_SAMPLE_CODE]); $fishForm->populate($fishMetaData); //insert fish $fishId = $fish->insert($fishBaseData); //now update fish with fish meta data $fish->updateFishAndMetadata($fishForm, $fishId, $fishBaseData); $importedFishes[$i][Fish::COL_ID] = $fishId; $importedFishes[$i]['sourceCsvRow'] = $rowNo; $i++; } // check wether a image shall be imported ------------------------ $qu = new Default_ReferenceQuery(); $filenames = $qu->getImageNames($dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE]); //case non-sensitive foreach ($filenames as &$file) { $file = strtolower($file); } $importImageFile = false; if (!empty($filenames)) { //case non-sensitive if (in_array(strtolower($dataset['imageFormDataset'][Image::COL_ORIGINAL_FILENAME]), $filenames) != FALSE) { // Image is already in database $importImageFile = false; } else { $importImageFile = true; } } else { $importImageFile = true; } // end check ------------------------------------------------------ // import the images if ($importImageFile) { //copy file to new path and rename $completeSource = self::RELATIVE_PATH_UPLOAD_CACHE . $this->key . '/' . $dataset['imageFormDataset'][Image::COL_ORIGINAL_FILENAME]; $creator_guid = new Ble422_Guid(); $guid = $creator_guid->__toString(); $path_parts = pathinfo($completeSource); $originalFileName = $path_parts['basename']; //used later to create Image dataset $newFileNameWithGuid = $guid . '.' . strtolower($path_parts['extension']); //save extension in lower-case, needed for further processing in flex //relative path with new filename, prefix dot&slash required $completeDestination = './' . Image::RELATIVE_UPLOAD_PATH . '/' . $newFileNameWithGuid; if (!copy($completeSource, $completeDestination)) { throw new Zend_Exception("Error: copy fails, source: {$fileName}, destination: {$completeDestination}"); } $ratio = $dataset['imageFormDataset'][Image::COL_RATIO_EXTERNAL]; $this->logger->log(array('received original file' => $completeSource)); $this->logger->log(array('copied uploaded file' => $completeDestination)); $numberCopiedFiles++; //TODO write protect files //create other image files $tn_ratio = $image->processImage($completeDestination); //case sensibility: original file name is saved like spelled in CSV file $imageId = $image->insertImageDataset($completeDestination, $originalFileName, $fishId, $guid, $this->userId, $ratio, $tn_ratio); //create image base and meta datasets $imageMetaData = $dataset['imageFormDataset']; $imageForm->populate($imageMetaData); //$imageId = $image->insert($imageBaseData); $image->updateImageAndMetadata($imageForm, $imageId); $importedImages[$j]['sourceCsvRow'] = $rowNo; $importedImages[$j][Image::COL_ID] = $imageId; $importedImages[$j][Image::COL_FISH_ID] = $fishId; $importedImages[$j][Image::COL_ORIGINAL_FILENAME] = $originalFileName; $importedImages[$j]['completeDestination'] = $completeDestination; $relativePathAndFileNameWorkingCopy = './' . Image::RELATIVE_PATH_IMAGE_SHRINKED_WORKING_COPIES . '/' . $guid . '.jpg'; $relativePathAndFileNameThumbnail = './' . Image::RELATIVE_PATH_IMAGE_THUMBNAILS . '/' . $guid . '.jpg'; $importedImages[$j]['completeWorkingCopy'] = $relativePathAndFileNameWorkingCopy; $importedImages[$j]['completeThumbnail'] = $relativePathAndFileNameThumbnail; $j++; } } $dbAdapter->commit(); $this->logger->log(array('datasets committed, number of copied files into system' => $numberCopiedFiles)); $returnCode = 'success'; //delete upload cache dir Ble422_FileHelper::delete_directory(self::RELATIVE_PATH_UPLOAD_CACHE . $this->key); } catch (Exception $e) { $returnCode = 'error'; $dbAdapter->rollBack(); //delete copied/created files, else there will be orphaned files foreach ($importedImages as $image) { unlink($image['completeDestination']); unlink($image['completeWorkingCopy']); unlink($image['completeThumbnail']); } $this->logger->log(array('Error exception' => $e->getMessage()), 'ERROR, roll back of imported datasets and unsetting of files, see below'); $this->logger->log(array('Roll back of importedFishes' => $importedFishes)); $this->logger->log(array('Roll back of importedImages' => $importedImages)); //delete upload cache dir Ble422_FileHelper::delete_directory(self::RELATIVE_PATH_UPLOAD_CACHE . $this->key); echo $e->getMessage(); } $returnArray = array('returnCode' => $returnCode, 'importFishes' => $importedFishes, 'importImages' => $importedImages, 'numberCopiedFiles' => $numberCopiedFiles); $this->logger->log(array('data import' => $returnArray)); return $returnArray; }
public function deleteAction() { //check if workshop has exercises if not then //delete workshop files //delete workshop //delete ws info //delete ce //delete imageset attributes -> DB on delete cascade //delete ce has image -> DB on delete cascade //delete ce has attribute desc. -> DB on delete cascade //delete participants -> DB on delete cascade //delete annotations -> DB on delete cascade //delete dots -> DB on delete cascade $request = $this->getRequest(); $workId = intval($this->getRequest()->getParam(Workshop::COL_ID)); if (AuthQuery::getUserRole() == 'admin') { if (Default_SimpleQuery::isValueInTableColumn($workId, new CalibrationExercise(), CalibrationExercise::COL_WORKSHOP_ID)) { $request = $this->getRequest(); $workshop = new Workshop(); $rowset = $workshop->find($workId); if (count($rowset) == 1) { $table = new WorkshopInfo(); //$tableAdapter = $table->getAdapter(); $select = $table->select(); //$select->from(WorkshopInfo::TABLE_NAME); $select->where(WorkshopInfo::COL_WORKSHOP_ID . ' = ?', $workId, 'int'); echo $select; $rowset = $table->fetchAll($select); if (count($rowset) >= 1) { $rowsetArray = $rowset->toArray(); $RELATIVE_WORKSHOP_FILES_PATH = 'infoFiles'; //without pre- and post-slash! foreach ($rowsetArray as $row) { try { $filename = $row[WorkshopInfo::COL_FILE]; if ($filename != NULL) { $myFile = $RELATIVE_WORKSHOP_FILES_PATH . '/' . $filename; $fh = fopen($myFile, 'w'); fclose($fh); unlink($myFile); } } catch (Exception $e) { throw new Zend_Exception('Error: can not open file'); } } } //note: delete of workshop_info is executed from db $workshop->delete($workshop->getAdapter()->quoteInto(Workshop::COL_ID . ' = ?', $workId)); } } } $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->setGoto('myws', 'search', 'workshop'); }
public function removeimageAction() { //action is only clickable in view when there are no annotations //delete annotations -> done by DBMS //delete dots -> done by DBMS if (!Default_SimpleQuery::isValueInTableColumn($this->getRequest()->getParam(CeHasImage::COL_ID), new Annotations(), Annotations::COL_CE_HAS_IMAGE_ID)) { $cehimTable = new CeHasImage(); $cehimTable->delete($cehimTable->getAdapter()->quoteInto(CeHasImage::COL_ID . '=?', $this->getRequest()->getParam(CeHasImage::COL_ID))); } $this->redirectTo('index'); }