示例#1
0
 /**
  * Submits a contact message.
  * @param array $formParams
  * @return array $response
  */
 public function contact(array $formParams = array())
 {
     // get categories
     $categoriesModel = new Contact_Model_Categories();
     $categories = $categoriesModel->getResource()->fetchValues('category');
     // get user if one is logged in
     $userId = Daiquiri_Auth::getInstance()->getCurrentId();
     if ($userId > 0) {
         // get the user model for getting user details
         $userModel = new Auth_Model_User();
         $user = $userModel->getResource()->fetchRow($userId);
     } else {
         $user = array();
     }
     // create the form object
     $form = new Contact_Form_Submit(array('categories' => $categories, 'user' => $user));
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             // form is valid, get values
             $values = $form->getValues();
             unset($values['submit']);
             // set the user_id
             $values['user_id'] = $userId;
             // set timestamp
             $values['datetime'] = date("Y-m-d H:i:s");
             // set status of new message to active
             $statusModel = new Contact_Model_Status();
             $values['status_id'] = $statusModel->getResource()->fetchId(array('where' => array('`status` = "active"')));
             // store in database (if enabled)
             $this->getResource()->insertRow($values);
             // get the category
             $row = $categoriesModel->getResource()->fetchRow($values['category_id']);
             $values['category'] = $row['category'];
             // send mail to user who used the contact form
             $this->getModelHelper('mail')->send('contact.submit_user', array('to' => $values['email'], 'firstname' => $values['firstname'], 'lastname' => $values['lastname']));
             // send mail to support
             $userResource = new Auth_Model_Resource_User();
             $this->getModelHelper('mail')->send('contact.submit_support', array('to' => array_merge($userResource->fetchEmailByRole('manager'), $userResource->fetchEmailByRole('admin')), 'reply_to' => $values['email'], 'firstname' => $values['firstname'], 'lastname' => $values['lastname'], 'email' => $values['email'], 'category' => $values['category'], 'subject' => $values['subject'], 'message' => $values['message'], 'link' => Daiquiri_Config::getInstance()->getSiteUrl() . '/contact/messages'));
             return array('status' => 'ok');
         } else {
             return array('status' => 'error', 'errors' => $form->getMessages(), 'form' => $form);
         }
     }
     return array('form' => $form, 'status' => 'form');
 }
示例#2
0
 public function authenticateToken($username, $token, $path)
 {
     // first check if username, password or path are missing
     if (!$username) {
         throw new Exception('Username not given.');
     } else {
         if (!$token) {
             throw new Exception('Token not given.');
         } else {
             if (!$path) {
                 throw new Exception('Path not given.');
             }
         }
     }
     $tokenResource = new Auth_Model_Resource_Token();
     $tokenResource->cleanup();
     $result = $tokenResource->check($username, $token, $path);
     if ($result === true) {
         $userResource = new Auth_Model_Resource_User();
         $user = $userResource->fetchRow(array('where' => array('username = ?' => $username)));
         // store user table row in auth object, but suppress password
         $row = new stdClass();
         $row->id = $user['id'];
         $row->username = $username;
         $row->email = $user['email'];
         $row->status_id = $user['status_id'];
         $row->role_id = $user['role_id'];
         // get ip and user agent
         $row->ip = $this->getRemoteAddr();
         $row->userAgent = $this->getUserAgent();
         // get role and status
         $row->status = $this->getStatus($row->status_id);
         $row->role = $this->getRole($row->role_id);
         // get the auth singleton and its storage and store the row
         $storage = Zend_Auth::getInstance()->getStorage();
         $storage->write($row);
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 /**
  * Fetches one row specified by its primary key from the jobs table.
  * @param array $sqloptions
  * @return array $row
  */
 public function fetchRow($id)
 {
     // get adapter config
     $config = $this->getAdapter()->getConfig();
     // get the sql select object for the running jobs
     $selectPending = $this->select();
     $selectPending->from('qqueue_jobs', Query_Model_Resource_QQueueQuery::$_cols);
     $selectPending->where('qqueue_jobs.mysqlUserName = ?', $config['username']);
     $selectPending->where('qqueue_jobs.id = ?', $id);
     // get the sql select object for the old jobs
     $selectHistory = $this->select();
     $selectHistory->from('qqueue_history', Query_Model_Resource_QQueueQuery::$_cols);
     $selectHistory->where('qqueue_history.mysqlUserName = ?', $config['username']);
     $selectHistory->where('qqueue_history.id = ?', $id);
     $select = $this->select()->union(array($selectPending, $selectHistory));
     // get the rowset and return
     $row = $this->fetchOne($select);
     if (empty($row)) {
         return false;
     }
     // get all usernames, status, queues
     $userResource = new Auth_Model_Resource_User();
     $statusStrings = array_flip(Query_Model_Resource_QQueueQuery::$_status);
     $queues = $this->fetchQueues();
     // get username from cache
     $userRow = $userResource->fetchRow($row['user_id']);
     if (empty($userRow)) {
         $row['username'] = '******';
     } else {
         $row['username'] = $userRow['username'];
     }
     // get status from status string array
     $row['status'] = $statusStrings[$row['status_id']];
     // get queue
     $row['queue'] = $queues[$row['queue']]['name'];
     // calculate queue and query times
     if ($row['timeSubmit'] != '0000-00-00 00:00:00' && $row['timeExecute'] != '0000-00-00 00:00:00') {
         $row['timeQueue'] = strtotime($row['timeExecute']) - strtotime($row['timeSubmit']);
     }
     if ($row['timeExecute'] != '0000-00-00 00:00:00' && $row['timeFinish'] != '0000-00-00 00:00:00') {
         $row['timeQuery'] = strtotime($row['timeFinish']) - strtotime($row['timeExecute']);
     }
     // if row contains a call to spider_bg_direct_sql, the actual query run on the
     // server will be hidden from the user, since spider_bg_direct_sql needs secret
     // information that nobody should know...
     if (isset($row['actualQuery']) && strpos($row['actualQuery'], "spider_bg_direct_sql") !== false) {
         unset($row['actualQuery']);
     }
     return $row;
 }
示例#4
0
 /**
  * Responds to a contact message.
  * @param int $id id of the message
  * @param array $formParams
  * @return array $response
  */
 public function respond($id, array $formParams = array())
 {
     // get the message
     $message = $this->getResource()->fetchRow($id);
     // create the form object
     $form = new Contact_Form_Respond(array('subject' => "{$message['subject']}", 'body' => "Dear {$message['firstname']} {$message['lastname']},\n\n\n\nBest Regards"));
     if (!empty($formParams)) {
         if ($form->isValid($formParams)) {
             // form is valid, get values
             $values = $form->getValues();
             unset($values['submit']);
             // get manager
             $userResource = new Auth_Model_Resource_User();
             $manager = array_merge($userResource->fetchEmailByRole('admin'), $userResource->fetchEmailByRole('manager'));
             // send mail to user who used the contact form
             $this->getModelHelper('mail')->send('contact.respond', array('to' => $message['email'], 'bcc' => $manager, 'subject' => $values['subject'], 'body' => $values['body']));
             // set message status to closed
             $statusModel = new Contact_Model_Status();
             $status_id = $statusModel->getResource()->fetchId(array('where' => array('`status` = "closed"')));
             $this->getResource()->updateRow($id, array('status_id' => $status_id));
             return array('status' => 'ok');
         } else {
             return array('status' => 'error', 'errors' => $form->getMessages(), 'form' => $form);
         }
     }
     return array('message' => $message, 'form' => $form, 'status' => 'form');
 }