/**
  * @param Zend_Controller_Request_Http $request
  */
 public function preDispatch($request)
 {
     // dont filter anything if a resident is logged in
     $session = new Zend_Session_Namespace();
     if ($session->currentResidentId) {
         $session->currentResident = Table_Residents::getInstance()->find($session->currentResidentId)->current();
         return;
     }
     // allow index and session controller to all
     if ($request->getControllerName() == 'index' || $request->getControllerName() == 'session') {
         return;
     }
     // Authenticate direct requests for non-html stuff
     if ($request->getParam('format') !== "html") {
         // The requestor provided a username
         if (isset($_SERVER['PHP_AUTH_USER'])) {
             $resident = Table_Residents::getInstance()->findResidentByEmailAndPasswordhash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
             if ($resident) {
                 $session->currentResidentId = $resident->getId();
                 $session->currentResident = $resident;
                 return;
             }
         }
         header('WWW-Authenticate: Basic realm="WG-Organizer"');
         header('HTTP/1.0 401 Unauthorized');
         die;
     }
     // else redirect to frontpage
     $request->setControllerName('index');
     $request->setActionName('index');
 }
Beispiel #2
0
 /**
  * @return Table_Residents
  */
 public function getInstance()
 {
     if (!self::$uniqueInstance) {
         self::$uniqueInstance = new Table_Residents();
     }
     return self::$uniqueInstance;
 }
 /**
  * Enter description here...
  *
  */
 public function createAction()
 {
     $this->requirePost();
     $form = $this->getNewByingsForm();
     if ($form->isValid($_POST)) {
         // do some inputting
         $buyings = array();
         for ($i = 0; $i < 10; $i++) {
             if ($form->getValue("product{$i}")) {
                 $product = $form->getValue("product{$i}");
                 $price = $form->getValue("price{$i}");
                 $buying = Table_Buyings::getInstance()->createRow();
                 $buying->setDescription($product);
                 $buying->setPriceInEuro($price);
                 $buying->setResident($this->getCurrentResident());
                 $buying->save();
                 $buyings[] = $buying;
             } else {
                 break;
             }
         }
         if (!empty($buyings)) {
             # tailor message that going to be sent to the other residents
             $message = $this->getCurrentResident()->getName();
             $message .= " hat folgende Dinge gekauft:\n";
             $buying = null;
             $summ = 0.0;
             foreach ($buyings as $buying) {
                 $message .= $buying->getDescription() . " für " . $buying->getPriceInEuro() . "€\n";
                 $summ += $buying->getPriceInEuro();
             }
             $message .= "\nGesammtwert: \t {$summ} €";
             foreach (Table_Residents::getInstance()->fetchAll() as $resident) {
                 if ($resident->getId() != $this->getCurrentResident()->getId()) {
                     # Send a message to the other residents. Telling them the current one
                     # entered a new buying.
                     $msg = Table_Messages::getInstance()->createRow();
                     $msg->setFrom('System');
                     $msg->setFor($resident);
                     $msg->setTitle('Neuer Einkauf');
                     $msg->setMessage($message);
                     $msg->save();
                 }
             }
         }
         // list byings
         $this->flash('Einkäufte eingetragen');
         $this->redirect('index');
     } else {
         $this->redirect('new');
     }
 }
Beispiel #4
0
 /**
  * @return mixed The primary key value(s), as an associative array if the
  *     key is compound, or a scalar if the key is single-column.
  */
 protected function _doInsert()
 {
     $result = parent::_doInsert();
     $pricePerResident = $this->price / Table_Residents::getInstance()->count();
     // you get youre money back
     $youreCashAccount = $this->getResident()->getCashAccount();
     $youreCashAccount->addCents($this->price);
     $youreCashAccount->save();
     // all have to pay the same ammount (including yourself)
     foreach (Table_Cashaccounts::getInstance()->fetchAll() as $cashaccount) {
         $cashaccount->subCents($pricePerResident);
         $cashaccount->save();
     }
     return $result;
 }
 /**
  * creating the session
  *
  */
 public function createAction()
 {
     $this->requirePost();
     $form = $this->getLoginForm();
     if ($form->isValid($_POST)) {
         $resident = Table_Residents::getInstance()->findResidentByEmailAndPasswordhash($form->getValue('email'), $form->getValue('password'));
         if ($resident instanceof Resident) {
             $s = new Zend_Session_Namespace();
             $s->currentResidentId = $resident->id;
             $this->redirect('index', 'index');
         } else {
             $this->flash("Email oder Password falsch!");
             $this->redirect('new');
         }
     } else {
         $this->redirect('new');
     }
 }
 /**
  * @param Zend_Controller_Request_Http $request
  */
 public function preDispatch($request)
 {
     // dont filter anything if a resident is logged in
     $session = new Zend_Session_Namespace();
     // Sets the resident id so the next if loads the user ;)
     if ($request->getParam('appauth_key')) {
         $session->currentResidentId = Table_Residents::getInstance()->findByAppAuthKey($request->getParam('appauth_key'));
     }
     if ($session->currentResidentId) {
         $session->currentResident = Table_Residents::getInstance()->find($session->currentResidentId)->current();
         return;
     }
     // allow index and session controller to all
     if ($request->getControllerName() == 'index' || $request->getControllerName() == 'session') {
         return;
     }
     // else redirect to frontpage
     $request->setControllerName('index');
     $request->setActionName('index');
 }
 public function createdbAction()
 {
     $this->debug('createdbAction');
     $filename = APPLICATION_PATH . '/config/app.ini';
     $configuration = new Zend_Config_Ini($filename, APPLICATION_ENVIRONMENT);
     $dbAdapter = Zend_Db::factory($configuration->database);
     $dbAdapter->beginTransaction();
     try {
         $form = $this->getConfigForm();
         $form->populate($_POST);
         $this->debug('Setting Default Addapter');
         Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
         $registry = Zend_Registry::getInstance();
         $registry->configuration = $configuration;
         $registry->dbAdapter = $dbAdapter;
         $database_path = APPLICATION_PATH . DIRECTORY_SEPARATOR . ".." . DIRECTORY_SEPARATOR . "database" . DIRECTORY_SEPARATOR;
         $database_dir = new DirectoryIterator($database_path);
         $sql = file_get_contents($database_path . 'schema.sql');
         $this->debug("executing schema.sql sql= " . $sql);
         $dbAdapter->query($sql);
         foreach ($database_dir as $file) {
             if ($file->isFile() && preg_match("/\\d\\d\\d.*/", $file->getFilename())) {
                 // starts with a number
                 $sql = file_get_contents($database_path . $file->getFilename());
                 $this->debug("executing {$file} sql: " . $sql);
                 $dbAdapter->query($sql);
             }
         }
         $data = array('email' => $form->getValue('email'), 'password_hash' => md5($form->getValue('password')));
         $new_resident = Table_Residents::getInstance()->createRow($data);
         $new_resident->save();
     } catch (Exception $e) {
         $this->debug('Exception: ' . $e->getMessage() . $e->getTraceAsString());
         unlink($filename);
     }
 }
 /**
  * Enter description here...
  *
  */
 public function destroyAction()
 {
     $resident = Table_Residents::getInstance()->findById($this->getRequest()->getParam('id'));
     try {
         $resident->delete();
         $this->flash('Bewohner wurde rausgeworfen!');
     } catch (Exception_BuisnessLogic $e) {
         $this->flash('Der Rausschmiß ist nicht geglückt.');
         $this->flash($e->getMessage());
     }
     $this->redirect('index');
 }
Beispiel #9
0
 /**
  * @return Resident
  */
 public function getResident()
 {
     return Table_Residents::getInstance()->findById($this->resident_id);
 }
 /**
  * Enter description here...
  *
  */
 public function indexAction()
 {
     $this->view->residents = Table_Residents::getInstance()->fetchAll();
 }
Beispiel #11
0
 /**
  * Creates an Message to all residents.
  *
  * @param int $buyingId
  */
 protected function _createMessage($buyingId)
 {
     $buying = Table_Buyings::getInstance()->findById($buyingId);
     // create a message for each resident
     $residents = Table_Residents::getInstance()->fetchAll();
     foreach ($residents as $resident) {
         $date = array();
         $data['residend_id'] = $resident->getId();
         $data['title'] = 'Neuer Einkauf';
         $data['message'] = 'Neuer Einkauf';
         Table_Messages::getInstance()->createRow($data);
     }
 }