/** * 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'); }
/** * Registers a participant. * @param string $slug slug of the meeting * @param array $formParams * @return array $response */ public function register($slug, array $formParams = array()) { // get models $meetingsModel = new Meetings_Model_Meetings(); $meeting = $meetingsModel->getResource()->fetchRow(array('where' => array('slug = ?' => $slug))); if (empty($meeting)) { throw new Daiquiri_Exception_NotFound(); } if (!Daiquiri_Auth::getInstance()->checkPublicationRoleId($meeting['registration_publication_role_id'])) { return array('status' => 'forbidden', 'message' => $meeting['registration_message']); } // 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 Meetings_Form_Registration(array('submit' => 'Register for this meeting', 'meeting' => $meeting, 'user' => $user)); // valiadate the form if POST if (!empty($formParams)) { if ($form->isValid($formParams)) { // get the form values $values = $form->getValues(); $values['meeting_id'] = $meeting['id']; $values['details'] = array(); foreach ($meeting['participant_detail_keys'] as $keyId => $detailKey) { if (is_array($values[$detailKey['key']])) { $values['details'][$keyId] = Zend_Json::encode($values[$detailKey['key']]); } else { if ($values[$detailKey['key']] === null) { $values['details'][$keyId] = Zend_Json::encode(array()); } else { $values['details'][$keyId] = $values[$detailKey['key']]; } } unset($values[$detailKey['key']]); } $values['contributions'] = array(); foreach ($meeting['contribution_types'] as $contributionTypeId => $contributionType) { if ($values[$contributionType . '_bool'] === '1') { $values['contributions'][$contributionTypeId] = array('title' => $values[$contributionType . '_title'], 'abstract' => $values[$contributionType . '_abstract']); } else { $values['contributions'][$contributionTypeId] = false; } unset($values[$contributionType . '_bool']); unset($values[$contributionType . '_title']); unset($values[$contributionType . '_abstract']); } // get the right status $participantStatusModel = new Meetings_Model_ParticipantStatus(); if (empty(Daiquiri_Config::getInstance()->meetings->autoAccept)) { $values['status_id'] = $participantStatusModel->getResource()->fetchId(array('where' => array('`status` = "registered"'))); } else { $values['status_id'] = $participantStatusModel->getResource()->fetchId(array('where' => array('`status` = "accepted"'))); } if (Daiquiri_Config::getInstance()->meetings->validation) { $code = $this->createRandomString(32); // store the values in the database $id = $this->getResource()->insertRow(array('email' => $values['email'], 'code' => $code, 'values' => Zend_Json::encode($values), 'meeting_id' => $meeting['id'])); // prepare and send mail $link = Daiquiri_Config::getInstance()->getSiteUrl() . '/meetings/registration/validate/id/' . $id . '/code/' . $code; $this->getModelHelper('mail')->send('meetings.validate', array('to' => $values['email'], 'meeting' => $meeting['title'], 'firstname' => $values['firstname'], 'lastname' => $values['lastname'], 'link' => $link)); return array('status' => 'validate'); } else { $participantModel = new Meetings_Model_Participants(); $id = $participantModel->getResource()->insertRow($values); $participant = $participantModel->getResource()->fetchRow($id); $mailValues = array('to' => $participant['email'], 'meeting' => $meeting['title'], 'firstname' => $participant['firstname'], 'lastname' => $participant['lastname'], 'affiliation' => $participant['affiliation'], 'email' => $participant['email'], 'arrival' => $participant['arrival'], 'departure' => $participant['departure']); foreach ($meeting['participant_detail_keys'] as $d) { if (in_array(Meetings_Model_ParticipantDetailKeys::$types[$d['type_id']], array('radio', 'select'))) { $options = Zend_Json::decode($d['options']); $mailValues[$d['key']] = $options[$participant['details'][$d['key']]]; } else { if (in_array(Meetings_Model_ParticipantDetailKeys::$types[$d['type_id']], array('checkbox', 'multiselect'))) { $options = Zend_Json::decode($d['options']); $values = array(); foreach (Zend_Json::decode($participant['details'][$d['key']]) as $value_id) { $values[] = $options[$value_id]; } $mailValues[$d['key']] = implode(', ', $values); } else { $mailValues[$d['key']] = $participant['details'][$d['key']]; } } } foreach ($meeting['contribution_types'] as $contribution_type) { if (!empty($participant['contributions'][$contribution_type])) { $mailValues[$contribution_type . '_title'] = $participant['contributions'][$contribution_type]['title']; $mailValues[$contribution_type . '_abstract'] = $participant['contributions'][$contribution_type]['abstract']; } else { $mailValues[$contribution_type . '_title'] = '---'; } } $this->getModelHelper('mail')->send('meetings.register', $mailValues); return array('status' => 'ok'); } } else { return $this->getModelHelper('CRUD')->validationErrorResponse($form); } } return array('form' => $form, 'status' => 'form', 'message' => $meeting['registration_message']); }
/** * Initializes the database with the init data for the meetings module. */ public function init() { // create status entries $authStatusModel = new Auth_Model_Status(); if ($authStatusModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['status'] as $status) { $a = array('status' => $status); $r = $authStatusModel->create($a); $this->_check($r, $a); } } // create roles entries $authRoleModel = new Auth_Model_Roles(); if ($authRoleModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['roles'] as $role) { $a = array('role' => $role); $r = $authRoleModel->create($a); $this->_check($r, $a); } } // create detail keys entries $authDetailKeysModel = new Auth_Model_DetailKeys(); if ($authDetailKeysModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['detailKeys'] as &$a) { if (!isset($a['type'])) { $a['type_id'] = 0; } else { $a['type_id'] = array_search($a['type'], Auth_Model_DetailKeys::$types); unset($a['type']); } $r = $authDetailKeysModel->create($a); $this->_check($r, $a); } } // create users $authUserModel = new Auth_Model_User(); if ($authUserModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['user'] as $credentials) { // get the corresponding role_id and status_id $credentials['role_id'] = Daiquiri_Auth::getInstance()->getRoleId($credentials['role']); unset($credentials['role']); $credentials['status_id'] = Daiquiri_Auth::getInstance()->getStatusId($credentials['status']); unset($credentials['status']); // pre-process password first $credentials['new_password'] = $credentials['password']; $credentials['confirm_password'] = $credentials['password']; unset($credentials['password']); // process detail keys foreach ($this->_init->options['init']['auth']['detailKeys'] as $detailKey) { if (in_array(Auth_Model_DetailKeys::$types[$detailKey['type_id']], array('radio', 'select'))) { $options = Zend_Json::decode($detailKey['options']); $option_id = array_search($credentials[$detailKey['key']], $options); $credentials[$detailKey['key']] = $option_id; } else { if (in_array(Auth_Model_DetailKeys::$types[$detailKey['type_id']], array('checkbox', 'multiselect'))) { $options = Zend_Json::decode($detailKey['options']); $values = array(); foreach ($credentials[$detailKey['key']] as $value) { $values[] = array_search($value, $options); } $credentials[$detailKey['key']] = $values; } } } // fake request parametes to make Zend_Controller_Front::getInstance()->getRequest()->setParams($credentials); // create user $r = $authUserModel->create($credentials); // clean up request Zend_Controller_Front::getInstance()->getRequest()->setParams(array()); $this->_check($r, $credentials); } } // create apps $authAppsModel = new Auth_Model_Apps(); if ($authAppsModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['apps'] as $credentials) { // pre-process password first $credentials['new_password'] = $credentials['password']; $credentials['confirm_password'] = $credentials['password']; unset($credentials['password']); // fake request parametes to make Zend_Controller_Front::getInstance()->getRequest()->setParams($credentials); // create user $r = $authAppsModel->create($credentials); // clean up request Zend_Controller_Front::getInstance()->getRequest()->setParams(array()); $this->_check($r, $credentials); } } // create acl ressources $authResourcesModel = new Auth_Model_Resources(); if ($authResourcesModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['resources'] as $resource) { $a = array('resource' => $resource); $r = $authResourcesModel->create($a); $this->_check($r, $a); } } // create acl rules, needs to be after create apps $authRulesModel = new Auth_Model_Rules(); if ($authRulesModel->getResource()->countRows() === 0) { foreach ($this->_init->options['init']['auth']['rules'] as $role => $rule) { foreach ($rule as $resource => $permissions) { $a = array('role' => $role, 'resource' => $resource, 'permissions' => implode(',', $permissions)); $r = $authRulesModel->create($a); $this->_check($r, $a); } } } }
/** * Submits a new query query plan to the database. * @param array $formParams * @return array $response */ public function mail(array $formParams = array()) { if (Daiquiri_Config::getInstance()->query->processor->mail->enabled != true) { throw new Exception('Processor mail is disabled in config.'); } // get query, plan, tablename and queue from session $ns = new Zend_Session_Namespace('query_plan'); // get the current user $userModel = new Auth_Model_User(); $userId = Daiquiri_Auth::getInstance()->getCurrentId(); if ($userId > 0) { // get the user model for getting user details $user = $userModel->getResource()->fetchRow($userId); } else { $user = array(); } // get the form for the plan $form = new Query_Form_Mail(array('user' => $user, 'sql' => $ns->sql, 'plan' => $ns->planString)); // validate form if (!empty($formParams)) { if ($form->isValid($formParams)) { // form is valid, get values $values = $form->getValues(); // take the values from the session, NOT from the form // DANGER values are not validated in the form and should not be editable $sql = $ns->sql; $planString = $ns->planString; if (empty(Daiquiri_Config::getInstance()->query->processor->mail->admin)) { throw new Exception('No admin email addresses configured'); } else { $this->getModelHelper('mail')->send('query.plan', array('to' => Daiquiri_Config::getInstance()->query->processor->mail->admin->toArray(), 'sql' => $sql, 'plan' => $planString, 'firstname' => $values['firstname'], 'lastname' => $values['lastname'], 'email' => $values['email'], 'message' => $values['message'])); } return array('status' => 'ok'); } else { return $this->getModelHelper('CRUD')->validationErrorResponse($form); } } return array('form' => $form, 'status' => 'form'); }