public function changeAdminUsername($old_account_identifier, $account_identifier, $account_id) { $select = $this->select()->from($this, array('user_name'))->where('account_id = ?', $account_id); $usernames = $this->fetchAll($select)->toArray(); foreach ($usernames as $username) { $data = preg_replace('/' . $old_account_identifier . '/', $account_identifier, $username, 1); parent::update($data, array('user_name = ?' => $username)); } $accountModel = new User_Model_DbTable_Account(); $accountModel->updateUsername($account_identifier, $account_id); }
public function init() { $this->setName('create_organisation_group'); $form = array(); $form['group_name'] = new Zend_Form_Element_Text('group_name'); $form['group_name']->setLabel('Group Name')->setRequired()->setAttrib('class', 'form-text'); $form['group_organisations'] = new Zend_Form_Element_Select('group_organisations'); $form['group_organisations']->setLabel('Organisations')->setRequired()->setRegisterInArrayValidator(false)->setAttrib('multiple', 'true')->setAttrib('class', 'form-select'); $form['first_name'] = new Zend_Form_Element_Text('first_name'); $form['first_name']->setLabel('First Name')->setAttrib('class', 'form-text')->setRequired(); $form['middle_name'] = new Zend_Form_Element_Text('middle_name'); $form['middle_name']->setLabel('Middle Name')->setAttrib('class', 'form-text'); $form['last_name'] = new Zend_Form_Element_Text('last_name'); $form['last_name']->setLabel('Last Name')->setAttrib('class', 'form-text')->setRequired(); $form['group_identifier'] = new Zend_Form_Element_Text('group_identifier'); $form['group_identifier']->setLabel('Group Identifier')->setAttrib('class', 'form-text')->setDescription("Your group identifier will be used as a prefix for your organisation group. \n\t \t\t\t\t\t We recommend that you use a short abbreviation that uniquely identifies \n\t \t\t\t\t\t your organisation group. If your group identifier is 'abc' the username \n\t \t\t\t\t\t for the group created with this registration will be 'abc_group'.")->setRequired(); $form['user_name'] = new Zend_Form_Element_Text('user_name'); $form['user_name']->setLabel('User Name')->addValidator('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'user_name', 'messages' => array(Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND => 'Username already in use. Please change your Group Identifier.')))->setAttrib('class', 'form-text')->setAttrib('readonly', 'true')->setDescription("User Name is a combination of Group Identifier and '_group'.\n You may only change Group Identifier portion of the username.")->setRequired(); $passwordConfirmation = new App_PasswordConfirmation(); $form['password'] = new Zend_Form_Element_Password('password'); $form['password']->setLabel('Password')->setRequired()->setAttrib('class', 'form-text')->addValidator($passwordConfirmation); $form['confirmpassword'] = new Zend_Form_Element_Password('confirmpassword'); $form['confirmpassword']->setLabel('Confirm Password')->setAttrib('class', 'form-text confirmpassword')->setRequired()->addValidator($passwordConfirmation); $form['email'] = new Zend_Form_Element_Text('email'); $form['email']->setLabel('Email')->addValidator('emailAddress', false)->addValidator('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'messages' => array(Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND => 'Email address already in use.')))->addFilter('stringTrim')->setAttrib('class', 'form-text')->setRequired(); $account_model = new User_Model_DbTable_Account(); $organisations = $account_model->getAllOrganisationNameWithId(); foreach ($organisations as $organisation) { $form['group_organisations']->addMultiOption($organisation['id'], $organisation['name']); } $create_group = new Zend_Form_Element_Submit('create_group'); $create_group->setLabel('Create Group')->setAttrib('id', 'Submit'); $this->addElements($form); // add clearfix div for all form items foreach ($form as $element) { $element->addDecorators(array(array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix form-item')))); } $this->addDisplayGroup(array('user_info', 'group_name', 'group_organisations', 'group_identifier'), 'create_organisation_group', array('legend' => 'New Organisation Group')); $this->addDisplayGroup(array('first_name', 'middle_name', 'last_name', 'user_name', 'password', 'confirmpassword', 'email'), 'group_admin_information', array('legend' => 'Group Admin Information')); $group = $this->getDisplayGroups(); foreach ($this->getDisplayGroups() as $group) { $group->setDecorators(array('FormElements', 'Fieldset', array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'default-activity-list')))); } $this->addElement($create_group); $this->setMethod('post'); }
public function sendTweet() { $identity = Zend_Auth::getInstance()->getIdentity(); $accountId = $identity->account_id; $regInfoModel = new Model_RegistryInfo(); $regInfo = $regInfoModel->getOrgRegistryInfo($accountId); $registryUrl = "/publisher/" . $regInfo->publisher_id; $model = new User_Model_DbTable_Account(); $row = $model->getAccountRowById($accountId); // If twitter screen name is present $twitter = $this->verifyCredentials(); if (is_object($twitter)) { if (strlen($row['twitter']) != 0) { $status = $row['name'] . ' ' . $row['twitter'] . ' has published their #IATIData. View the data here: http://iatiregistry.org' . $registryUrl . ' #AidStream'; } else { $status = $row['name'] . ' has published their #IATIData. View the data here: http://iatiregistry.org' . $registryUrl . ' #AidStream'; } $twitter->statuses->update($status); } else { return false; } }
public function masqueradeAction() { $accountAuth = Zend_Auth::getInstance(); if ($accountAuth->hasIdentity()) { $identity = $accountAuth->getIdentity(); if ($identity->role == 'superadmin' || $identity->role == 'groupadmin') { $identity_role = $identity->role; $account_id = $this->_getParam('org_id'); $user_id = $this->_getParam('user_id'); if (!$account_id || !$user_id) { $this->_helper->FlashMessenger->addMessage(array('error' => 'Could not masquerade. User information missing')); $this->_redirect('/wep/dashboard'); } $adminIdentity = $identity; $authAdapter = new Zend_Auth_Adapter_DbTable(Zend_Db_Table::getDefaultAdapter()); $authAdapter->setTableName('user')->setIdentityColumn('user_id')->setCredentialColumn('account_id'); $authAdapter->setIdentity($user_id)->setCredential($account_id); $accountAuth->authenticate($authAdapter); $identity = $authAdapter->getResultRowObject(null, 'password'); $rolevalue = new User_Model_DbTable_Role(); $role = $rolevalue->getRoleById($identity->role_id); $std = new stdClass(); $std->role = $role['role']; $identity = (object) array_merge((array) $identity, (array) $std); $accountAuth->getStorage()->write($identity); $accModel = new User_Model_DbTable_Account(); $account = $accModel->getAccountRowByUserName('account', 'id', $identity->account_id); $simplified = new Zend_Session_Namespace('simplified'); $simplified->simplified = $account->simplified; if ($identity_role == 'superadmin') { $session = new Zend_Session_Namespace('superadmin'); $session->identity = serialize($adminIdentity); } elseif ($identity_role == 'groupadmin') { $session = new Zend_Session_Namespace('groupadmin'); $session->identity = serialize($adminIdentity); } $this->_redirect('/wep/dashboard'); } else { $this->_helper->FlashMessenger->addMessage(array('error' => 'You are not authorised to masquerade.')); $this->_redirect('/wep/dashboard'); } } }
public function organisationAction() { if ($_GET['reporting_org']) { $reportingOrg = $this->_request->getParam('reporting_org'); } else { $this->_redirect('organisation?reporting_org=all'); } !$reportingOrg ? $handler = new Iati_Snapshot_Lib_DataHandler() : ($handler = new Iati_Snapshot_Lib_DataHandler($reportingOrg)); $accountModel = new User_Model_DbTable_Account(); $userModel = new Model_User(); $publishModel = new Model_Published(); $wepModel = new Model_Wep(); $regInfoModel = new Model_RegistryInfo(); $result = $accountModel->getAccountByOrganisation($reportingOrg); if (count($result)) { // Get Account Id $accountId = $result['id']; $user = $userModel->getUserByAccountId($accountId); $regInfo = $regInfoModel->getOrgRegistryInfo($accountId); // Get Organisation Info $organisation_array['name'] = $result['name']; $organisation_array['image'] = $result['file_name']; $organisation_array['address'] = $result['address']; $organisation_array['email'] = $user['email']; $organisation_array['telephone'] = $result['telephone'] ? $result['telephone'] : 'Not Available'; $organisation_array['website'] = $result['url'] ? $result['url'] : 'Not Available'; $organisation_array['twitter'] = $result['twitter'] ? $result['twitter'] : 'Not Available'; $organisation_array['prefix'] = $result['username']; $organisation_array['disqus_comments'] = $result['disqus_comments']; $this->view->organisation_array = $organisation_array; $this->view->publisher_id = $regInfo->publisher_id; } else { // For all organisations: snapshot if ($reportingOrg == 'all' || $reportingOrg == '') { $activityModel = new Model_Activity(); $orgData = $activityModel->allOrganisationsActivityStates(); foreach ($orgData as $key => $row) { $total['activities'] += array_sum($row['states']); $total['published'] += $row['registry_published_count']; } $accountModel = new User_Model_DbTable_Account(); $count = $accountModel->getAccountCount(); $total['organisations'] = $count['total']; $this->view->total = $total; } else { $this->_redirect('organisation?reporting_org=all'); } } // end if $this->view->handler = $handler; }
public function init() { $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); $auth = Zend_Auth::getInstance()->getIdentity(); $user_id = $auth->user_id; $roleName = $auth->role; $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $clause = $db->quoteInto('user_id != ?', $user_id); $accountObj = new User_Model_DbTable_Account(); $userName = strtok($auth->user_name, '_'); $account = $accountObj->getAccountRowByUserName('account', 'username', $userName); $usernameClause = $db->quoteInto('username != ?', $userName); $this->setName('Edit Account'); $form = array(); $form['first_name'] = new Zend_Form_Element_Text('first_name'); $form['first_name']->setLabel('First Name')->setRequired()->setAttrib('class', 'form-text'); $form['middle_name'] = new Zend_Form_Element_Text('middle_name'); $form['middle_name']->setLabel('Middle Name')->setAttrib('class', 'form-text'); $form['last_name'] = new Zend_Form_Element_Text('last_name'); $form['last_name']->setLabel('Last Name')->setRequired()->setAttrib('class', 'form-text'); $form['email'] = new Zend_Form_Element_Text('email'); $form['email']->setLabel('Email')->setRequired()->addValidator('emailAddress', false)->setAttrib('class', 'form-text')->addValidator('Db_NoRecordExists', false, array('table' => 'user', 'field' => 'email', 'exclude' => $clause, 'messages' => array(Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND => 'Email Address already exists.'))); if ($roleName != 'superadmin' && $roleName != 'groupadmin') { $form['name'] = new Zend_Form_Element_Text('name'); $form['name']->setLabel('Organisation Name')->setRequired()->setAttrib('class', 'form-text'); $form['address'] = new Zend_Form_Element_Textarea('address'); $form['address']->setLabel('Organisation Address')->setRequired()->setAttrib('rows', '4')->setAttrib('class', 'form-text'); $form['url'] = new Zend_Form_Element_Text('url'); $form['url']->setLabel('Organisation Url')->addValidator(new App_Validate_Url())->setAttrib('class', 'form-text'); $form['telephone'] = new Zend_Form_Element_Text('telephone'); $form['telephone']->setLabel('Organisaton Telephone')->addValidator(regex, false, array('pattern' => '/^[\\d -]+$/', 'messages' => 'Invalid telephone number.'))->setAttrib('class', 'form-text'); } if ($roleName == 'admin') { $twitterUsernameValidator = new App_Validate_TwitterUsername(); $form['twitter'] = new Zend_Form_Element_Text('twitter'); $form['twitter']->setLabel('Organisaton Twitter')->setAttrib('class', 'form-text')->setDescription("Please insert a valid twitter username. Example: '@oxfam' or 'oxfam'")->addValidator($twitterUsernameValidator)->addValidator('Db_NoRecordExists', false, array('table' => 'account', 'field' => 'twitter', 'exclude' => $usernameClause, 'messages' => array(Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND => 'Twitter handle already in use.'))); $filePath = $baseUrl . '/uploads/image/' . $account['file_name']; $remove = $baseUrl . '/user/user/remove/user_id/'; if ($account['file_name']) { $form['image'] = new Zend_Form_Element_Image('image'); $form['image']->setImage($filePath)->setLabel('Organisation Logo')->setDescription('<a href="' . $remove . $user_id . '/user_name/' . $userName . '" class ="remove-logo" title = "Remove Logo" >Remove</a>')->setDecorators(array('ViewHelper', array('Description', array('escape' => false, 'tag' => false)), array('HtmlTag', array('tag' => 'dd')), array('Label', array('tag' => 'dt')), 'Errors')); } $form['file'] = new Zend_Form_Element_File('file'); $form['file']->setLabel('Change')->addValidator('Extension', false, 'jpg,jpeg,png,gif')->setDescription('Please use jpg/jpeg/png/gif format and 150x150 dimensions image.')->getValidator('Extension')->setMessage('Please use jpg/jpeg/png/gif format image.'); if (!$account['file_name']) { $form['file']->setLabel('Upload Logo'); } $form['disqus_comments'] = new Zend_Form_Element_Checkbox('disqus_comments'); $form['disqus_comments']->setLabel('Disqus Comments')->setDescription('Enable/disable comments on your <a href="/organisation?reporting_org=' . rawurlencode($account->name) . '" target="_blank"> organization page</a>.'); $form['disqus_comments']->getDecorator('Description')->setOption('escape', false); } if ($roleName == 'user') { $form['address']->setAttrib('readonly', 'true'); $form['name']->setAttrib('readonly', 'true'); } foreach ($form as $element) { $element->addDecorators(array(array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix form-item')))); } $this->addElements($form); $this->addDisplayGroup(array_keys($form), 'edit-user-form', array('legend' => 'Edit Profile')); $editUser = $this->getDisplayGroup('edit-user-form'); $editUser->addDecorators(array(array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'default-activity-list')))); $save = new Zend_Form_Element_Submit('Save'); $save->setValue('save')->setAttrib('class', 'form-submit'); $this->addElement($save); }
public function generatePublishedXmlFilesAction() { $this->_helper->viewRenderer->setNoRender(true); $this->_helper->layout()->disableLayout(); $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); $xmlPath = $config->public_folder . $config->xml_folder; $xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><iati-publishers><!-- Generated By AidStream --></iati-publishers>'); $registryPublishedModel = new Model_RegistryPublishedData(); $organisationRegistryPublishedModel = new Model_OrganisationRegistryPublishedData(); $accountModel = new User_Model_DbTable_Account(); $organisationRegistryPublishedData = $organisationRegistryPublishedModel->getAllOrganisationRegistryPublishedData(); $registryPublishedData = $registryPublishedModel->getAllRegistryPublishedData(); // For Activity $index = 1; foreach ($registryPublishedData as $registryData) { $orgName = $accountModel->getOrganisationNameById($registryData->publisher_org_id); $orgName = preg_replace('/&/', '&', $orgName); if ($index == 1) { $registry[$orgName]['publisherId'] = substr($registryData->filename, 0, strrpos($registryData->filename, '-')); } $registry[$orgName]['activity'][] = $registryData->filename; } // For Organisation Data foreach ($organisationRegistryPublishedData as $registryData) { $orgName = $accountModel->getOrganisationNameById($registryData->publisher_org_id); $orgName = preg_replace('/&/', '&', $orgName); if ($index == 1) { $registry[$orgName]['publisherId'] = substr($registryData->filename, 0, strrpos($registryData->filename, '-')); } $registry[$orgName]['organisation'][] = $registryData->filename; } ksort($registry); foreach ($registry as $publisherName => $information) { $iatiPublisher = $xml->addChild('iati-publisher'); $iatiPublisher->addChild('name', $publisherName); $iatiPublisher->addChild('registry-publisher-id', $information['publisherId']); $iatiFiles = $iatiPublisher->addChild('iati-files'); if (isset($information['activity'])) { foreach ($information['activity'] as $iatiActivity) { $fileUrl = 'http://aidstream.org/files/xml/' . trim($iatiActivity) . '.xml'; $iatiFile = $iatiFiles->addChild('iati-activity', $fileUrl); } } if (isset($information['organisation'])) { foreach ($information['organisation'] as $iatiOrganisation) { $fileUrl = 'http://aidstream.org/files/xml/' . trim($iatiOrganisation) . '.xml'; $iatiFile = $iatiFiles->addChild('iati-organisation', $fileUrl); } } } $fileName = "published-files.xml"; $fp = fopen($xmlPath . $fileName, 'w'); fwrite($fp, $xml->asXML()); fclose($fp); if (file_exists($xmlPath . $fileName)) { $this->_redirect('/files/xml/' . $fileName); } }