Edit breadcrumble for EditUser - moodle

I created a Moodle plugin based on the edit user admin page moodle/admin/user.php.
Everything works, except the breadcrumble from the top navigation is still pointing to the edit user admin page.
This is the starting script of the plugin that creates the invalid breadcrumble:
<?php
require('../../config.php');
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->dirroot.'/report/log/locallib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->dirroot.'/lib/tablelib.php');
require_once($CFG->dirroot.'/user/filters/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
// Check if user is allowed to browse users
admin_externalpage_setup('editusers');
$sort = optional_param('sort', 'name', PARAM_ALPHANUM);
$dir = optional_param('dir', 'ASC', PARAM_ALPHA);
$page = optional_param('page', 0, PARAM_INT);
$perpage = optional_param('perpage', 30, PARAM_INT);
$returnurl = new moodle_url('/report/gnppoints/index.php', array('sort' => $sort, 'dir' => $dir, 'perpage' => $perpage, 'page'=>$page));
$sitecontext = context_system::instance();
$site = get_site();
$strshowallusers = get_string('showallusers');
$ufiltering = new user_filtering();
echo $OUTPUT->header();
I don't know where the breadcrumble is created. Any suggestions?

First add this in settings.php:
$ADMIN->add('reports',
new admin_externalpage('reportgnp', get_string('pluginname','report_gnppoints'),
$url
));
Then replace
admin_externalpage_setup('editusers');
by
admin_externalpage_setup('reportgnp');

Related

How to upload a PDF file and send via email in TYPO3?

I'm Having a form with the following fields.
Name
Address
Contact
PDF (File Attachment)
This PDF is to be uploaded from the system and send these details together with the uploaded PDF via email. I want these details to be in the custom email template using standalone view and send.
I'm using TYPO3 v7.6.23
I'm new to TYPO3. How to do This?
I'm adding my code here
$addJobsInfo = GeneralUtility::makeInstance('MNU\\MnuJobs\\Domain\\Model\\Jobs');
$addJobsInfo->setName($arguments['name']);
$addJobsInfo->setAddress($arguments['address']);
$addJobsInfo->setContact($arguments['contact']);
$this->jobsRepository->add($addJobsInfo);
$persistenceManager = $this->objectManager->get('TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager');
$persistenceManager->persistAll();
$lastID = $addJobsInfo->getUid();
$getPDF = $_FILES;
if(!empty($getPDF)){
$pdfName = $getPDF['tx_mnujobs_mnujobs']['name']['jobsDOC'];
$pdfTemp = $getPDF['tx_mnujobs_mnujobs']['tmp_name']['jobsDOC'];
$resourceFactory = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance();
$storage = $resourceFactory->getDefaultStorage();
$folder = $storage->getFolder('user_upload');
$pdfFinalName = 'Jobs_'.time().'_'.$pdfName;
$uploadPDF = $storage->addFile($pdfTemp, $folder, $pdfFinalName);
if($lastID){
$newId = 'NEW'.$lastID;
$data = array();
$data['sys_file_reference'][$newId] = array(
'table_local' => 'sys_file',
'uid_local' => $uploadPDF->getUid(),
'tablenames' => 'tx_mnujobs_domain_model_jobs',
'uid_foreign' => $lastID,
'fieldname' => 'pdfattachment',
'pid' => $this->settings['pageUid']
);
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->start($data, array());
$dataHandler->process_datamap();
}
}
//E-mail Sending
$mail = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
$mail->setSubject('Contact Details');
$mail->setTo('sample#gmail.com']);
$mail->setBody('Hi, This is a sample. Please Find the Attachment', 'text/html');
$attachment = Swift_Attachment::fromPath($folder->getIdentifier().$pdfFinalName);
$attachment->setFilename('Document.pdf');
$mail->attach($attachment);
$sendMail = $mail->send();
I'm getting this Exception
Unable to open file for reading
[/user_upload/Jobs_1525757243_sample.pdf]
So I've replaced this
$attachment = Swift_Attachment::newInstance($folder->getIdentifier().$pdfFinalName, 'Document.pdf', 'application/pdf');
$mail->attach($attachment);
Both are not working, Where I've gone wrong?
What worked for me was adding fileadmin in front of the identifier:
$filePath = 'fileadmin' . $file->getOriginalResource()->getIdentifier();
$attachment = \Swift_Attachment::fromPath($filePath);
$mail->attach($attachment);
Use ext:powermail, it is feature rich, actively maintained and very well documented

Can't Relate Contact and Opportunity in SuiteCRM / SugarCRM CE

I'm working on a script to import data into SuiteCRM / SugarCRM CE. I need to create a Contact and an Opportunity. I then need to relate the two.
I have a many to many relationship between Contacts and Opportunities. Each contact should be able to create multiple opportunities. Each opportunity should be able to be assigned to multiple contacts.
When I run the code it says "1 Relationship(s) created", but when I check Suite there's nothing listed under the contact or opportunity subpanels.
FYI, I renamed the Opportunities module "Gigs" and am using this API Wrapper: github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class
Here's the code:
<?php
// Load Composer Dependencies for Sugar API Wrapper
require_once('vendor/autoload.php');
// Create Sugar Object
$sugar = new \Asakusuma\SugarWrapper\Rest;
// Set Sugar Connection Items
$sugar->setUrl('https://example.com/suitecrm/service/v2/rest.php');
$sugar->setUsername('User');
$sugar->setPassword('Pass');
// Connect to Sugar
$sugar->connect();
// Did something go wrong with the connection? Report it.
$error = $sugar->get_error();
if($error !== FALSE) {
return $error['name'];
}
// Ok... We're going to try and create a test entry in Sugar/Suite
// Create a Contact
$modules = 'Contacts';
// Set Values
$values = array(
'contact_type_c' => 'Prospect',
'lead_source' => 'Website',
'first_name' => 'Test',
'last_name' => 'Contact',
'phone_mobile' => '(123) 456-7890',
'email1' => 'test#test.com'
);
// Put it in Suite
$result = $sugar->set($modules, $values);
$contactID = $result['id'];
// Ok, now let's create a Opportunity
$modules = "Opportunities";
$values = array(
'name' => 'My Test Gig',
'sales_stage' => 'New Inquiry',
'amount' => '400'
);
$result = $sugar->set($modules, $values);
$gigID = $result['id'];
// Lastly, let's relate the two - HERE'S WHERE I HAVE PROBLEMS!
// Set Relationship
$moduleName = 'Contacts';
$moduleID = $contactID;
$linkFieldName = 'opportunities';
$relatedIDs = array($gigID);
$nameValueList = array(); // Passing empty array because we don't have any fields that need it
$delete = 0;
$result = $sugar->set_relationship($moduleName, $moduleID, $linkFieldName, $relatedIDs, $nameValueList, $delete);
echo $result['created'] . " relationship(s) made";
?>
The Contact and Opportunity are created just fine. It's the relationship that's not happening.
Ugh... Ok, I get it.
I looked at the API documentation and was passing $relatedIDs back as an array. What I didn't realize is that the API was doing this as well. So what got passed into Suite was a multidimensional array instead of a single array.

Phalcon Paginator error: Syntax error, unexpected EOF

my problem is, every time I click in the paginator link in the view, the controller returns me this error:
Syntax error, unexpected EOF
What is this? EOF?
My controller:
$domicilios = Domicilios::find();
$paginator = new \Phalcon\Paginator\Adapter\Model(
array(
"data" => $domicilios,
"limit"=> 5,
"page" => $currentPage
)
);
$pagina = $paginator->getPaginate();
$this->view->setVar("estado", $estado);
$this->view->setVar("pagina", $pagina);
The content in the model Domicilios is returning right, but why the paginator keeps returning this error?
Thanks in advance!
EOF is end of file. there might be several issues. 1stly if you upload this file to server, there might be problems with upload process and file is not fully uploaded and you have broken end of file (EOF).
try converting your php file to utf8. you can do it with notepad++ and many other programs.
here are my working pagination:
$page = $this->request->get('page', 'int', 1);
$this->view->page = $page;
if ($page < 1) {
$page = 1;
}
$user = $this->session->get('auth');
$questions = Model_UserQuestion::find(array(
'user_id=:user_id:',
'bind' => array('user_id' => $user['id']),
"order" => "id DESC",
));
// Create a Model paginator, show 10 rows by page starting from $currentPage
$paginator = new \Phalcon\Paginator\Adapter\Model(
array(
"data" => $questions,
"limit" => $this->config->application->itemsPerPage,
"page" => $page
)
);
$page = $paginator->getPaginate();
$this->view->questions = $page->items;
notice that to get items you have to use this:
$page->items

TYPO3 6.1 - how can I login a fe_user via code?

I am using TYPO3 6.1 and try to login a FE user via Code (included via PHP and USER_INT).
This code does not work for me. :( Any ideas why?
// try to login the user now
$loginData = array(
'uname' => trim($postData['username']), //usernmae
'uident' => trim($postData['password']), //password
'status' => 'login'
);
// $GLOBALS['TSFE']->fe_user-checkPid=0; //do not use a particular pid
$GLOBALS['TSFE']->fe_user->checkPid = $this->feUserPid; // ''; //do not use a particular pid
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
//
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord(
$info['db_user'], $loginData['uname']
);
$ok = $GLOBALS['TSFE']->fe_user->compareUident($user, $loginData);
//
if($ok)
{
// login successfull
$GLOBALS['TSFE']->fe_user->createUserSession($user);
//
$content = '<h3 class="green">LOGIN OK!</h3>';
$content .= '<p>Sie sind eingeloggt als ' . $feUsername . ' und wurden nun weitergeleitet...</p>';
}
else
{
// login failed
$content = '<h3 class="red">LOGIN FAILED!</h3>';
}
Thanks for any hint!
Starting with TYPO3 4.7, you must use $loginData['uident_text'] instead of $loginData['uident'] for the password.
If the problem persists, please give more information what exactly is going wrong, what your log says etc.
Does compareUident() return TRUE for you?
I, fx have a case, where I automatically log in user that has just created themselves. And compareUident() didn't work for me for some reason, but as I know this same website visitor just created the user, I skip that function and continue on initiating all the session variables. The following is a working code on TYPO3 6.1:
$loginData = array(
'uname' => $postdata['username'],
'uident' => $postdata['password'],
'status' => 'login',
);
$GLOBALS['TSFE']->fe_user->checkPid = 0;
$info = $GLOBALS['TSFE']->fe_user->getAuthInfoArray();
$user = $GLOBALS['TSFE']->fe_user->fetchUserRecord($info['db_user'], $loginData['uname']);
//if($GLOBALS['TSFE']->fe_user->compareUident($user, $loginData)) {
$GLOBALS['TSFE']->fe_user->user = $GLOBALS['TSFE']->fe_user->fetchUserSession();
$GLOBALS['TSFE']->loginUser = 1;
$GLOBALS['TSFE']->fe_user->fetchGroupData();
$GLOBALS['TSFE']->fe_user->start();
$GLOBALS['TSFE']->fe_user->createUserSession($user);
$GLOBALS['TSFE']->fe_user->loginSessionStarted = TRUE;
//}
Inspired by:
https://stackoverflow.com/a/7738383/445364
https://typo3.org/extensions/repository/view/dix_easylogin

silverstripe dataobject searchable

I´m trying to have certain DataObjects (News) displayed in the default SearchResult Page. So the result should display normal Pages and News.
Is there an easy way to accomplish that in Silverstripe 3?
Or is it recommended to code it completely custom - I mean a custom controller/action which handles the search request and creates a result list, which I display then in a custom template?
I found this, but obviously search is disabled right now:
https://github.com/arambalakjian/DataObjects-as-Pages
Thx and regards,
Florian
I usually but together a custom search function after enabling FulltextSearchable. So in _config.php I would have
FulltextSearchable::enable();
Object::add_extension('NewsStory', "FulltextSearchable('Name,Content')");
replacing Name and Content with whatever DBField you want to be searchable. And each searchable DataObject have this in their class to enable search indexes (pretty sure this needs to be added and run dev/build before enabling the extension, and only works on MySQL DB).
static $create_table_options = array(
'MySQLDatabase' => 'ENGINE=MyISAM'
);
then in my PageController I have my custom searchForm and results functions.
Here is the search function that returns the search form, called with $search in the template:
public function search()
{
if($this->request && $this->request->requestVar('Search')) {
$searchText = $this->request->requestVar('Search');
}else{
$searchText = 'Search';
}
$f = new TextField('Search', false, $searchText);
$fields = new FieldList(
$f
);
$actions = new FieldList(
new FormAction('results', 'Go')
);
$form = new Form(
$this,
'search',
$fields,
$actions
);
//$form->disableSecurityToken();
$form->setFormMethod('GET');
$form->setTemplate('SearchForm');
return $form;
}
and here the custom results function to handle the queries...
function results($data, $form, $request)
{
$keyword = trim($request->requestVar('Search'));
$keyword = Convert::raw2sql($keyword);
$keywordHTML = htmlentities($keyword, ENT_NOQUOTES, 'UTF-8');
$pages = new ArrayList();
$news = new ArrayList();
$mode = ' IN BOOLEAN MODE';
//$mode = ' WITH QUERY EXPANSION';
//$mode = '';
$siteTreeClasses = array('Page');
$siteTreeMatch = "MATCH( Title, MenuTitle, Content, MetaTitle, MetaDescription, MetaKeywords ) AGAINST ('$keyword'$mode)
+ MATCH( Title, MenuTitle, Content, MetaTitle, MetaDescription, MetaKeywords ) AGAINST ('$keywordHTML'$mode)";
$newsItemMatch = "MATCH( Name, Content ) AGAINST ('$keyword'$mode)
+ MATCH( Name, Content ) AGAINST ('$keywordHTML'$mode)";
//Standard pages
foreach ( $siteTreeClasses as $c )
{
$query = DataList::create($c)
->where($siteTreeMatch);
$query = $query->dataQuery()->query();
$query->addSelect(array('Relevance' => $siteTreeMatch));
$records = DB::query($query->sql());
$objects = array();
foreach( $records as $record )
{
if ( in_array($record['ClassName'], $siteTreeClasses) )
$objects[] = new $record['ClassName']($record);
}
$pages->merge($objects);
}
//news
$query = DataList::create('NewsStory')->where($newsItemMatch);
$query = $query->dataQuery()->query();
$query->addSelect(array('Relevance' => $newsItemMatch));
$records = DB::query($query->sql());
$objects = array();
foreach( $records as $record ) $objects[] = new $record['ClassName']($record);
$news->merge($objects);
//sorting results
$pages->sort(array(
'Relevance' => 'DESC',
'Title' => 'ASC'
));
$news->sort(array(
'Relevance' => 'DESC',
'Date' => 'DESC'
));
//output
$data = array(
'Pages' => $pages,
'News' => $news,
'Query' => $keyword
);
return $this->customise($data)->renderWith(array('Search','Page'));
}
I add all the Page classes I want to be searched and that extend SiteTree in the $siteTreeClasses array, and the News parts can be pretty much copied for any other DataObjectI need searchable.
I am not saying this is the best solution and this can definitely be improved on, but it works for me and this might be a good stating point.
I have adapted #colymba's solution into a silverstripe module: https://github.com/burnbright/silverstripe-pagesearch
It allows setting the pagetype in the url.
You'll need to substantially overwrite SearchForm->getResults().
It uses Database->searchEngine(), but those are tailored towards SiteTree and Page classes.
The "proper" solution is to feed the data into a search engine like Solr or Sphinx.
We have the SS3-compatible "fulltextsearch" module for this purpose:
https://github.com/silverstripe-labs/silverstripe-fulltextsearch
It's going to take some upfront setup, and is only feasible if you can either host Solr yourself, or are prepared to pay for a SaaS provider. Once you've got it running though, the possibilities are endless, its a great tool!