示例#1
0
 public function indexAction()
 {
     $namespace = new Zend_Session_Namespace('ce');
     if ($this->getRequest()->isPost()) {
         if ($this->form->isValid($this->getRequest()->getParams())) {
             if ($this->form->getValue('Token') == $namespace->Token) {
                 $ceTable = new CalibrationExercise();
                 $data = array(CalibrationExercise::COL_NAME => $this->form->getValue(CalibrationExercise::COL_NAME), CalibrationExercise::COL_DESCRIPTION => $this->form->getValue(CalibrationExercise::COL_DESCRIPTION), CalibrationExercise::COL_WORKSHOP_ID => $this->callingWorkshopId);
                 $ceId = $ceTable->insert($data);
                 $namespace->Token = '';
                 $this->_forward("index", "edit", "ce", array("CAEX_ID" => $ceId));
             } else {
                 //form token is not equal session token
                 $this->form->reset();
                 $this->redirectTo('index');
             }
         } else {
             //not valid
         }
     } else {
         //not post
         if ($this->form->getValue('Token') == null) {
             $guid = new Ble422_Guid();
             $namespace->Token = $guid->__toString();
             $this->form->getElement('Token')->setValue($guid->__toString());
             $this->view->form = $this->form;
         }
     }
 }
示例#2
0
 public function byceAction()
 {
     $images = new Service_Image();
     $namespace = new Zend_Session_Namespace('default');
     $resultKey = new Ble422_Guid();
     $ceId = $this->getRequest()->getParam(CalibrationExercise::COL_ID);
     if ($ceId != null) {
         //get images
         $namespace->{$resultKey} = $images->getImages($ceId);
         //getCeInfo
         //set CE id
         $constCeId = CalibrationExercise::COL_ID;
         $namespace->{$constCeId} = $ceId;
         //Set CE-info result Object
         $dbadapter = Zend_Registry::get('DB_CONNECTION1');
         $select = $dbadapter->select();
         $select->from(array('caex' => CalibrationExercise::TABLE_NAME));
         $select->join(array('exp' => Expertise::TABLE_NAME), 'caex.' . CalibrationExercise::COL_EXPERTISE_ID . "=" . 'exp.' . Expertise::COL_ID);
         $select->join(array('key' => KeyTable::TABLE_NAME), 'caex.' . CalibrationExercise::COL_KEY_TABLE_ID . "=" . 'key.' . KeyTable::COL_ID);
         $select->join(array('work' => Workshop::TABLE_NAME), 'caex.' . CalibrationExercise::COL_WORKSHOP_ID . "=" . "work." . Workshop::COL_ID, array(Workshop::COL_NAME));
         $select->where('caex.' . CalibrationExercise::COL_ID . "=?", $ceId);
         $ceArray = $dbadapter->fetchAll($select);
         $namespace->ceArray = $ceArray;
     } else {
         $redirect = new Zend_Controller_Action_Helper_Redirector();
         $redirect->setGotoSimple('index', 'index', 'default');
     }
     $this->view->resultKey = $resultKey->__toString();
     $this->render('start');
 }
 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
 }
示例#5
0
 public function newselectexpAction()
 {
     $namespace = new Zend_Session_Namespace('training');
     if ($this->getRequest()->isPost()) {
         if ($this->form->isValid($this->getRequest()->getParams())) {
             if ($this->form->getValue('Token') == $namespace->Token) {
                 //insert/update
                 //get form value and set namespace
                 $this->defaultNamespace->expId = $this->form->getValue(CalibrationExercise::COL_EXPERTISE_ID);
                 $namespace->Token = $newToken;
                 $newToken = Ble422_Guid::getGuid();
                 $this->form->getElement('Token')->setValue($newToken);
                 //put validated values in GET params
                 $this->redirectTo('newselectavailablekeys', $this->form->getValues());
             } else {
                 //form token is not equal session token
                 $this->form->reset();
                 $this->redirectTo('outofdate');
             }
         } else {
             //not valid
             $this->render('form');
         }
     } else {
         //not post
         //$this->form = new Ce_Form_Search();
         //$this->form->setAction('/ce/new/newtrainselectavailablekeys/'.Workshop::COL_ID.'/TEMP');
         if ($this->form->getValue('Token') == null) {
             $guid = new Ble422_Guid();
             $namespace->Token = $guid->__toString();
             $this->form->getElement('Token')->setValue($guid->__toString());
             $this->view->form = $this->form;
             $this->render('form');
         }
     }
 }
示例#6
0
 public function indexAction()
 {
     $addFish = false;
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         if ($this->form->isValid($params)) {
             //TODO wenn fishsamplecode noch nicht in der datenbank,
             //dann lege fisch an mit diesem samplecode (erledigt)
             //und SPRINGE IN Fish_CreateController (am Ende des Controllers)
             //TODO mit getElement und Konstanten arbeiten
             $fishSampleCode = $this->form->getValue(Fish::COL_SAMPLE_CODE);
             $fishTable = new Fish();
             $row = $fishTable->fetchRow($fishTable->select()->where(Fish::COL_SAMPLE_CODE . '= ?', $fishSampleCode));
             if (is_null($row)) {
                 //echo 'Warnung: Fish Sample Code nicht vorhanden.';
                 $fishId = $fishTable->insert(array(Fish::COL_SAMPLE_CODE => $fishSampleCode));
                 $addFish = true;
                 $constFishId = Fish::COL_ID;
                 $fishId->{$constFishId} = $fishId;
             } else {
                 $addFish = false;
                 $fishId = $row->FISH_ID;
             }
             //TODO dateinamen mit leerzeichen
             //könnte ein problem bei der weiterverarbeitung in linux sein
             //klären,
             //ggf. akzeptieren und umwandeln oder verweigern?
             //don't call $form->getValues() - causes physical upload immediately
             //look ZFDoc 19.1.3
             //note: if using Zend_Form_Element_File (in view) you can't use new instance of Zend_File_Transfer_Adapter_Http in controller!
             // http://www.zfforums.com/zend-framework-forum-8/general-talks-12/file_transfer-illegal-uploaded-possible-attack-1737.html
             // http://www.nabble.com/Zend_File_Transfer-td19024470.html
             //solution:
             //getTransferAdapter()
             $upload = $this->form->uploadElement->getTransferAdapter();
             // Returns all known internal file informations
             $files = $upload->getFileInfo();
             $imageTable = new Image();
             $medimTable = new MetaDataImage();
             //look ZFDoc 19.3.3
             //iterates over all file elemens
             $numberImagesUploaded = 0;
             $userId = AuthQuery::getUserId();
             foreach ($files as $file => $info) {
                 /*handle only uploaded files, skip blank file elements
                 	 store original file in certain path
                 	 file is saved without excplicit temp directory with Zend Filter
                 	 image import uses temp directory instead
                 	 */
                 if (!$upload->isUploaded($file)) {
                     continue;
                 }
                 $creator_guid = new Ble422_Guid();
                 $guid = $creator_guid->__toString();
                 $fileName = $info['name'];
                 $path_parts = pathinfo($fileName);
                 $originalFileName = $path_parts['basename'];
                 //used later to create Image dataset
                 $newFileNameWithGuid = $guid . '.' . strtolower($path_parts['extension']);
                 //save extension in lower-case
                 //relative path with new filename, prefix dot&slash required
                 $completeTarget = './' . Image::RELATIVE_UPLOAD_PATH . '/' . $newFileNameWithGuid;
                 //apply filter only for uploaded file $fileName
                 $upload->addFilter('Rename', array('target' => $completeTarget, 'overwrite' => false), $fileName);
                 $upload->receive($file);
                 //TODO write protect files
                 $upload->clearFilters();
                 try {
                     $ratio = $this->form->getValue(Image::COL_RATIO_EXTERNAL);
                     $tn_ratio = $imageTable->processImage($completeTarget);
                     //ratio is filled from form
                     $imageId = $imageTable->insertImageDataset($completeTarget, $originalFileName, $fishId, $guid, $userId, $ratio, $tn_ratio);
                     $imageTable->updateImageAndMetadata($this->form, $imageId);
                     $numberImagesUploaded++;
                 } catch (Exception $e) {
                     echo "Exception: " . $e->getMessage();
                 }
             }
             Zend_Registry::set('MESSAGE', $numberImagesUploaded . ' image(s) successfully inserted');
             if ($addFish) {
                 $next = array('nextAction' => 'index', 'nextController' => 'upload', 'nextModul' => 'image');
                 $namespace = new Zend_Session_Namespace('default');
                 $namespace->next = $next;
                 $redirect = new Zend_Controller_Action_Helper_Redirector();
                 $redirect->setGotoSimple('update', 'edit', 'fish', array(Fish::COL_ID => $fishId));
             }
         } else {
             //form isn't valid
             $this->form->populate($params);
             $this->view->form = $this->form;
         }
     }
     //$this->view->form = $form;
 }
示例#7
0
 /**
  *
  * @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;
 }
示例#8
0
 public function updateAction()
 {
     $table = new Workshop();
     $request = $this->getRequest();
     $updateValues = $request->getParams();
     $wsNamespace = new Zend_Session_Namespace('workshop');
     //$this->view->WORK_ID = $updateValues[Workshop::COL_ID];
     $workId = intval($this->getRequest()->getParam(Workshop::COL_ID));
     $this->view->WORK_ID = $workId;
     //if user is not actual workshop manager, redirect
     if (!AuthQuery::getUserId() == Default_SimpleQuery::getWsManagerUserId($workId)) {
         $this->redirectTo('list', 'search', 'workshop');
         return;
     }
     if ($request->isPost()) {
         if ($this->getRequest()->getParam('save') != null) {
             //save Button clicked
             if ($this->form->isValid($updateValues)) {
                 if ($this->form->getValue('Token') == $wsNamespace->Token) {
                     $data = array(Workshop::COL_NAME => $this->form->getValue(Workshop::COL_NAME), Workshop::COL_LOCATION => $this->form->getValue(Workshop::COL_LOCATION), Workshop::COL_START_DATE => $this->form->getValue(Workshop::COL_START_DATE), Workshop::COL_END_DATE => $this->form->getValue(Workshop::COL_END_DATE), Workshop::COL_HOST_ORGANISATION => $this->form->getValue(Workshop::COL_HOST_ORGANISATION), Workshop::COL_USER_ID => $this->form->getValue(Workshop::COL_USER_ID));
                     $table->update($data, Workshop::COL_ID . " = '" . $this->form->getValue(Workshop::COL_ID) . "'");
                     $wsNamespace->unsetAll();
                     $this->redirectTo();
                 } else {
                     $this->form->reset();
                     $this->render('outOfDate');
                 }
             }
         } else {
             if ($this->getRequest()->getParam('setManager') != null) {
                 // new ws manager button clicked
                 $wsNamespace->formValues = $this->getRequest()->getParams();
                 $defaultNamespace = new Zend_Session_Namespace('default');
                 $defaultNamespace->callingAction = 'workshop/edit/update';
                 $defaultNamespace->callingActionId = $request->getParam(Workshop::COL_ID);
                 $this->redirectTo('index', 'search', 'user');
             } else {
                 // new ws manager has choosen and is loading
                 $userTable = new User();
                 $userResult = $userTable->find($this->getRequest()->getParam(Workshop::COL_USER_ID))->current();
                 if ($userResult != null) {
                     $userArray = $userResult->toArray();
                 } else {
                     $userArray = array(Workshop::COL_USER_ID => null, User::COL_USERNAME => 'not valid');
                 }
                 $valueArray = $wsNamespace->formValues;
                 $valueArray[Workshop::COL_USER_ID] = $userArray[Workshop::COL_USER_ID];
                 $valueArray[User::COL_USERNAME] = $userArray[User::COL_USERNAME];
                 $this->form->isValid($valueArray);
                 if ($this->form->getValue('Token') == null) {
                     $guid = new Ble422_guid();
                     $wsNamespace->Token = $guid->__toString();
                     $this->form->getElement('Token')->setValue($guid->__toString());
                 }
             }
         }
     } else {
         // first call load form with default values
         $rowset = $table->find($request->getParam(Workshop::COL_ID))->current();
         if ($rowset != null) {
             $this->form->setValues($rowset->toArray());
         }
         $this->form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . "/workshop/edit/update");
         // Get part_id and part_role
         $userTable = new User();
         $userResult = $userTable->find($this->form->getValue(Workshop::COL_USER_ID))->current();
         if ($userResult != null) {
             $userArray = $userResult->toArray();
         } else {
             $userArray = array(Workshop::COL_USER_ID => null, User::COL_USERNAME => 'not valid');
         }
         $this->form->isValidPartial(array(Workshop::COL_USER_ID => $userArray[User::COL_ID], User::COL_USERNAME => $userArray[User::COL_USERNAME]));
         $guid = new Ble422_Guid();
         $wsNamespace->Token = $guid->__toString();
         $this->form->getElement('Token')->setValue($guid->__toString());
     }
 }
示例#9
0
 public function indexAction()
 {
     if ($this->callingCeId == NULL) {
         $this->_forward("index", "index");
     }
     $dbAdapter = Zend_Registry::get('DB_CONNECTION1');
     $namespace = new Zend_Session_Namespace('ce');
     if ($this->getRequest()->isPost()) {
         if ($this->form->isValid($this->getRequest()->getParams())) {
             if ($this->form->getValue('Token') == $namespace->Token) {
                 //insert/update
                 $ceTable = new CalibrationExercise();
                 $data = array(CalibrationExercise::COL_NAME => $this->form->getValue(CalibrationExercise::COL_NAME), CalibrationExercise::COL_DESCRIPTION => $this->form->getValue(CalibrationExercise::COL_DESCRIPTION), CalibrationExercise::COL_COMPAREABLE => $this->form->getValue(CalibrationExercise::COL_COMPAREABLE), CalibrationExercise::COL_RANDOMIZED => $this->form->getValue(CalibrationExercise::COL_RANDOMIZED), CalibrationExercise::COL_WORKSHOP_ID => $this->form->getValue(CalibrationExercise::COL_WORKSHOP_ID), CalibrationExercise::COL_KEY_TABLE_ID => $this->form->getValue(CalibrationExercise::COL_KEY_TABLE_ID), CalibrationExercise::COL_EXPERTISE_ID => $this->form->getValue(CalibrationExercise::COL_EXPERTISE_ID));
                 $where = $ceTable->getAdapter()->quoteInto(CalibrationExercise::COL_ID . ' = ?', $this->form->getValue(CalibrationExercise::COL_ID));
                 $ceTable->update($data, $where);
                 $newToken = Ble422_Guid::getGuid();
                 $this->form->getElement('Token')->setValue($newToken);
                 $namespace->Token = $newToken;
             } else {
                 //form token is not equal session token
                 $this->form->reset();
                 $this->redirectTo('outofdate');
             }
         } else {
             //not valid
         }
     } else {
         //not post
         $this->form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/ce/edit/index');
         if ($this->form->getValue('Token') == null) {
             $guid = new Ble422_Guid();
             $namespace->Token = $guid->__toString();
             $this->form->getElement('Token')->setValue($guid->__toString());
         }
         /**
          * get all set values for calibration exercise
          */
         //use Left Join to get the CE without assigned KeyTable/Expertise, too
         //use left join for workshop to get training ce's too
         $select = $dbAdapter->select();
         $select->from(array('ce' => CalibrationExercise::TABLE_NAME));
         $select->joinLeft(array('ws' => Workshop::TABLE_NAME), $dbAdapter->quoteIdentifier('ce.' . CalibrationExercise::COL_WORKSHOP_ID) . '=' . $dbAdapter->quoteIdentifier('ws.' . Workshop::COL_ID));
         $select->joinLeft(array('kt' => KeyTable::TABLE_NAME), $dbAdapter->quoteIdentifier('ce.' . CalibrationExercise::COL_KEY_TABLE_ID) . '=' . $dbAdapter->quoteIdentifier('kt.' . KeyTable::COL_ID));
         $select->joinLeft(array('exp' => Expertise::TABLE_NAME), $dbAdapter->quoteIdentifier('ce.' . CalibrationExercise::COL_EXPERTISE_ID) . '=' . $dbAdapter->quoteIdentifier('exp.' . Expertise::COL_ID));
         $select->where($dbAdapter->quoteIdentifier('ce.' . CalibrationExercise::COL_ID) . ' = ?', $this->callingCeId);
         $resultArray = $dbAdapter->fetchAll($select);
         //fill form with values
         $this->form->setValues($resultArray[0]);
     }
     $this->view->isStopped = $this->form->getValue(CalibrationExercise::COL_IS_STOPPED);
     if (isset($this->defaultNamespace->returningAction) && isset($this->defaultNamespace->returningActionId)) {
         switch ($this->defaultNamespace->returningAction) {
             case 'ce/editkeytable/index':
                 $this->form->getElement(CalibrationExercise::COL_KEY_TABLE_ID)->setValue($this->defaultNamespace->returningActionId);
                 break;
             case 'ce/editexpertise/index':
                 $this->form->getElement(CalibrationExercise::COL_EXPERTISE_ID)->setValue($this->defaultNamespace->returningActionId);
                 break;
             default:
                 $this->defaultNamespace->returningAction = NULL;
                 $this->defaultNamespace->returningActionId = NULL;
                 throw new Zend_Exception();
                 break;
         }
     }
     $this->defaultNamespace->returningAction = NULL;
     $this->defaultNamespace->returningActionId = NULL;
     /**
      * get Shown Attributes List
      */
     $selectShownAttr = $dbAdapter->select();
     $selectShownAttr->from(CeHasAttributeDescriptor::TABLE_NAME);
     $selectShownAttr->join(AttributeDescriptor::TABLE_NAME, CeHasAttributeDescriptor::TABLE_NAME . '.ATDE_ID = ' . AttributeDescriptor::TABLE_NAME . '.ATDE_ID', array(AttributeDescriptor::COL_NAME));
     $selectShownAttr->where(CeHasAttributeDescriptor::COL_CAEX_ID . " = ?", $this->callingCeId);
     $resultShownAttr = $dbAdapter->fetchAll($selectShownAttr);
     $this->view->resultShownAttr = $resultShownAttr;
     //remove already used attributes from selectbox
     $elem = $this->formAttrSelCon->getElement('attr');
     foreach ($resultShownAttr as $row) {
         $elem->removeMultiOption($row[AttributeDescriptor::COL_ID]);
     }
     unset($elem);
     //info/actions about participants
     $this->view->numOfParti = $this->countParticipants();
     $this->defaultNamespace->callingAction = 'ce/edit/index';
     $this->defaultNamespace->callingActionId = $this->callingCeId;
     $this->view->form = $this->form;
     $this->formAttrSelCon->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/ce/edit/addattribute');
     $this->view->formAttrSelCon = $this->formAttrSelCon;
     /**
      * imageset attributes fish and image
      */
     //---get Attributes List
     $selectAttr = $dbAdapter->select();
     $selectAttr->from(ImagesetAttributes::TABLE_NAME);
     $selectAttr->join(AttributeDescriptor::TABLE_NAME, ImagesetAttributes::TABLE_NAME . '.ATDE_ID = ' . AttributeDescriptor::TABLE_NAME . '.ATDE_ID');
     $selectAttr->joinLeft(ValueList::TABLE_NAME, AttributeDescriptor::TABLE_NAME . '.' . AttributeDescriptor::COL_UNIT . '=' . ValueList::TABLE_NAME . '.' . ValueList::COL_ID, array('UNIT' => ValueList::COL_VALUE));
     $selectAttr->where(ImagesetAttributes::COL_CE_ID . " = ?", $this->callingCeId);
     //show only FISH-group & IMAGE-group attributes
     $selectAttr->where('(' . AttributeDescriptor::COL_GROUP . " = ?", 'FISH');
     $selectAttr->orWhere(AttributeDescriptor::COL_GROUP . " = ?)", 'IMAGE');
     $resultAttr = $dbAdapter->fetchAll($selectAttr);
     //remove already used attributes from selectbox
     $elem = $this->formAttrSelConFish->getElement('attr');
     foreach ($resultAttr as $row) {
         $elem->removeMultiOption($row[AttributeDescriptor::COL_ID]);
     }
     unset($elem);
     //remove already used attributes from selectbox
     $elem = $this->formAttrSelConImage->getElement('attr');
     foreach ($resultAttr as $row) {
         $elem->removeMultiOption($row[AttributeDescriptor::COL_ID]);
     }
     unset($elem);
     //set add form
     $this->formAttrSelConFish->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/ce/edit/addimagesetattribute');
     $this->view->formAttrSelConFish = $this->formAttrSelConFish;
     $this->imageSetForm->addDynamicElements($resultAttr, true, true);
     if (Default_SimpleQuery::isCeStopped($this->callingCeId)) {
         $this->imageSetForm->addElement('submit', 'submit', array('label' => 'save'));
     } else {
         //set description to remove the "remove attribute"-link from form
         foreach ($this->imageSetForm->getElements() as $elem) {
             $elem->setDescription(NULL);
         }
     }
     //set dynamic values
     $this->imageSetForm->dynPopulate($resultAttr, ImagesetAttributes::COL_VALUE, array(CalibrationExercise::COL_ID => $this->callingCeId));
     if (count($resultAttr) == 0) {
         $this->view->noImageset = true;
     } else {
         $this->view->noImageset = false;
     }
     /**
      * get already defined imagelist
      */
     $selectImages = $dbAdapter->select();
     $selectImages->from(array('cehim' => CeHasImage::TABLE_NAME));
     $selectImages->join(array('im' => Image::TABLE_NAME), 'cehim.' . CeHasImage::COL_IMAGE_ID . '=' . 'im.' . Image::COL_ID);
     $selectImages->where(CalibrationExercise::COL_ID . '=?', $this->callingCeId);
     $this->view->imageArray = $dbAdapter->fetchAll($selectImages);
     $this->view->ceId = $this->callingCeId;
     $this->view->imageSetForm = $this->imageSetForm;
     //set add form
     $this->formAttrSelConImage->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . '/ce/edit/addimagesetattribute');
     $this->view->formAttrSelConImage = $this->formAttrSelConImage;
     if ($this->form->getElement(CalibrationExercise::COL_RANDOMIZED)->getValue() == 1) {
         $this->view->isRandom = TRUE;
     }
     $this->defaultNamespace->message = NULL;
 }