Im having a problem showing the current viewed contact name in SUGARCRM
can anyone tell me how to get the current contact name, lets say i am browsing a contact in SUGARCRM called jhon i need a PHP piece of code to get this name and store it in a variable.
I already tried this:
global $current_user; echo $current_user->user_name;
but not that is what i am looking for, I am looking for something like this to be able to get the current contact name.
Try to access the full_name property. $current_user is an instance of User bean
$current_user->full_name
If not working try to retrieve user details using bean id of current user :
$user = new User(); //user object
$user->retrieve($current_user->id); //retrieve user data
$full_name = $user->full_name; // If have full name property.
If no full name property try to concatenate last name and first name
$fullname = $user->first_name .' '. $user->last_name;
If you're on a contact record, then the .tpl file needs to have the property name of what you want to show. Your question says name, so try putting this in the file where you want it:
"{$fields.first_name.value} {$fields.last_name.value}"
Related
As I couldn't find anything in the documentation I might have a general understanding issue. But what I want to achieve is getting the ID of the current Contact browsing the Site. To get user details I always have to know the ID, like documented here: https://developer.mautic.org/#contacts
$api = new MauticApi();
$contactApi = $api->newApi("contacts", $auth, $settings['baseUrl']);
$contact = $contactApi->get(3);
Is there a way to the ID of the current Contact? I want to play highly customized content on the website and an entry point to get user details.
It's a REST API, so you should get a response in any case. What's the content of the response (eg. what contains $contact)? What's the HTTP code of the response? Error messages?
However... I'm not familiar with this particular API, but the principles are always the same
https://developer.mautic.org/?php#list-contacts
Without any query parameters it should give the full list of contacts. Each of the contact records should come with an ID for the details:
https://developer.mautic.org/?php#get-contact
As said, I'm not familiar with the API, so it could be that you get a contact list only from a higher entity, like a Company or so.
I can recommend Postman (https://www.postman.com/), a neat tool to make REST API requests while having full control over all the details.
Assuming that you're trying to get the details of the current logged in user.
You can use themautic.helper.user helper to do that as shown below:
<?php
$user = $this->get('mautic.helper.user')->getUser();
$firstName = $user->getFirstname();
$lastName = $user->getLastname();
$email = $user->getEmail();
$profile = $user->getProfile();
$role = $user->getRole()->getName();
if ($role->isAdmin()) {
// do something
}
Ref: https://developer.mautic.org/#services44
In order to do what you want here I do not think you actually need the API to get the user id. Mautic has dynamic content and as long as the user has a cookie dropped on his browser you can use Dynamic Content to say "Hi {contactfield=firstname}, welcome back.
You can actually call any custom field into the dynamic content slot.
Check out dynamic content which is found under the Components section in the left menu
I'm trying to create an interface where a workshop description can be updated on the server after it has been created by a user. There is a text field and a button that brings up the workshop by the number it was assigned. (This is also the name of the directory in the submissions/workshop# on the server). When I set the variable $workshopPath using this method, I want to be able to access this global variable when a text input is filled out with the string to update the title of the workshop. The $workshopPath is registering as an empty string in the 'updateTextItems' function, so it is writing the text file to the root directory instead of to the correct workshop directory. I thought I was correctly referencing the global variable within the functions, but this isn't working. I also tried using $GLOBALS['workshopPath'], but that isn't working either. Can someone help me figure out how to pass the variable to the second function? Thanks :-)
<?php
$workshopPath;
if (isset($_POST['gotoWorkshop'])) {
if (empty($_POST['numberInput'])) {
echo "Please enter a valid workshop number";
} else { //Assign the name variable form the posted field info if one was entered.
$workshopNumber = stripslashes($_POST['numberInput']);
global $workshopPath;
$workshopPath = "submissions/" . $workshopNumber . "/";
}
}
if (isset($_POST['updateTextItems'])) {
if ($_POST['titleInput']) {
//Assign the name variable form the posted field info if one was entered.
$titleInput = stripslashes($_POST['titleInput']);
}
if ($titleInput) {
global $workshopPath;
$titleFile = fopen($workshopPath . "title.txt", "w") or die("There was an error creating the title file.");
fwrite($titleFile, $titleInput);
fclose($titleFile);
}
}
?>
Do I understood you correct? The user fill in the a form for the workshop click submit and get an othewr form for the text? My guess is you sen to requests to the server. So $GLOBAL will not work for you. It only works per request and I think most time you do not realy need it. If you want to save some values across requests, you need a session when you start your session. After you have started your session with session_start() you can use $_SESSION[] to store and get your value
I'm using the following code to get store name in a reminder email sent by admin.
$storeName = Mage::getModel('sales/order')->getStore()->getName();
However since the email is sent via the admin the store name is coming up as Admin and not Widgets.com.
How do I get it to insert the Store Name?
Try this:
$store = Mage::app()->getStore();
$storeName = $store->getName();
If you still have access to the quote (during order creation)
Mage::getSingleton('adminhtml/session_quote')->getStore()->getName();
To get the store name by order store id
Mage::app()->getStore($order->getStoreId())->getName());
I am creating a website on Joomla and want to have a private page for each individual user. If anyone knows of the best way to do this apart from giving each individual their own group, this is the way I would like to try:
I want to create a page where php will match a file name based on the user id of the logged in user. This is the code I have so far:
<?php
$user = JFactory::getUser();
$user_id = $user->id;
$profilepage = file_get_contents ("user" + $user_id +"file.txt");
echo $profilepage;
?>
This gives me the user id in a variable, and I would like for the correct profilepage to show. For example, if User594 is logged in, then I want the file to be used for $profilepage to be "user" + 594 + "file.txt"...for an actual file name of user594file.txt. Is this possible? Or is there a correct way of doing this?
Thanks for any help!
Since you probably chose not to delete your question and not hearing from you in comment in regards to a comment to you, I decided to post my comment as an answer.
You're presently wanting to use + signs. This isn't the character to use in order to concatenate.
In PHP, you need to use dots/periods:
$profilepage = file_get_contents ("user" . $user_id ."file.txt");
I have to create a database for a class and I am having trouble with one thing. In the database, a user can search for other users and choose to friend them (just like facebook). In my php scripts, I am searching my 'user' table (in MySQL) for all users that match a string entered in by the logged-in user, and providing a list of names that match the string. The logged in user can then click on the name they would like to friend, and a request is sent to that person. I am not sure how to retrieve the username and id of the name that is clicked on. For example, if the list of names that are displayed is:
Sally
Kevin
Mike
and the user clicks on Sally, how can I retrieve her username and id? In the sql query I am using, the last person is at the top of the array, so they logged in user always tries to friend Mike. Any suggestions would be great!!
The $_SESSION values are taking the last name in the array. How can I get it to take the name the logged-in user clicks on?
Or is there a better way to do this?
Here is my code so far:
$sql="SELECT uid, name FROM user WHERE name LIKE '%" . $name . "%'";
//run the query against the mysql query function
$result=mysql_query($sql);
//create while loop and loop through result set
while($row=mysql_fetch_array($result)){
$name=$row[name];
$uid=$row[uid];
//display the result of the array
echo "<ul>\n";
echo "" .$name. "";
echo "</ul>";
$_SESSION['friend_name'] = $name;
$_SESSION['friend_id'] = $uid;
}
I see you are generating the url with a name which in your case is not a key in the database. Why not send the UID itself to the friend_request.php and then use that UID to send the request to that person.
echo "" .$name. "";
Remove the $_SESSION variable, you dont need it.
In the friend_request.php, change $_SESSION['uid'] and $_SESSION['name'] to
$_GET['uid'] and $_GET['name']
You should pass the value of the friend being selected to the request that's selecting it, rather than trying to store it in session. Something like this:
echo "" .$name. "";
That way the value selected will be available to the friend_request.php script as $_GET['name'].
it depends on how you generate the persons list that user want to chose from so the list may be like :
sally
and in your php code aka makefriend.php you can get the user id and name from the db like :
$result = mysql_query("SELECT uid, name FROM user WHERE name LIKE '%" . $_get['name'] . "%'
i hope this can help .