Concrete5 User attributes - php

I figured out how to du this seperatly
Display the user attribute:
<?php
//Create a User object (of the current User)
$u = new User();
//Creat a UserInfo object with the user ID
$ui = UserInfo::getByID($u->getUserID());
//Get the Value of your user Attribute
$value = $ui->getAttribute('name');
//Print it out
echo $value;
?>
Display page owner:
<?php
$ownerID = $cobj->getCollectionUserID();
$uia = UserInfo::getByID($ownerID);
$ownerName = $uia->getUserName();
echo $ownerName
?>
But i cannot figure out how to put them together so it displays the attribute('name'); of the page owner
Can you guys please help
Thanks

After moving a little bit more around with the codes.
i figured out that i just needed to move the
$cobj->getCollectionUserID();
into
$ui = UserInfo::getByID($u->getUserID());
So the finished code:
<?php
//Creat a UserInfo object with the Owner
$ui = UserInfo::getByID($cobj->getCollectionUserID() );
//Get the Value of your user Attribute
$value = $ui->getAttribute('name');
//Print it out
echo $value;
?>

Related

PHP Database search display

To give you an understanding of what I'm working on. I'm working on a project where on my school campus you can navigate around. For example a room can be called J2626 or J2617 etc... The thing is that when a user Is using my website I only want it to type in the exact name of the room to be able to display anything. Right now it doesn't work like I want it to.
For example: if you only type in J in the search field, it will display all rooms that start with J.
Here is my code right now:
<?php
$fileName = dirname(dirname(__FILE__)) . "../../db/bth_nav.sqlite";
if (isset($_GET['page'])) {
$argument = $_GET['page'];
$argument = "%" . $argument . "%";
$db = new PDO("sqlite:$fileName");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$stmt = $db->prepare('SELECT * FROM bth_nav WHERE name LIKE (:nameOwner) OR owner LIKE (:nameOwner);');
$stmt->execute(array($argument));
$res = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($res)) {
header("Location: " . "http://" . $_SERVER['index.php']);
}
?>
<div class = "formObjectSearch">
<?php foreach ($res as $val) { ?>
<div class = "infoTab">
<h2><?= $val['name']; ?></h2>
<p>Guidance: <?= $val['info']; ?></p>
<p>Whos sitting here?: <?= $val['owner']; ?>
</div>
<img class = "buildingImage" src = "img/<?= $val['image']; ?>"
<?php
}
}
?>
</div>
I've tried making diffrent if statements but with no success. So what I need help with is that I only want the user to be able to search for a correct room name and not be able to only search for J and display everything.
Update
Here is my index.php:
I used this link, because Code sample didn't want to work: index.php code
Here is my building.php:
Samer here: building.php code
And the the new search.php with help:
Same here: search.php code
I get these errors right now:
Notice: Undefined index: index.php in /path/incl/files/search.php on line 19
Warning: Cannot modify header information - headers already sent by (output started at /path/incl/header.php:7) in /path/incl/files/search.php on line 19
My header.php code:
Same here: header.php code
My config.php code:
Same here: config.php code
My footer.php code:
Same here: footer.php code
If i understanded you correctly and if you want to search for all rooms with starting letter J, you need to change your arguments.
Explanation:
'%J%' - searches for selected field, where is J letter.
'%J' - searches for selected field, where J is the last letter.
'J%' - searches for selected field, where J is the first letter.
Try to change your argument like that:
$argument = $argument . "%";
UPDATE
Fixing your if statement:
if (empty($res) OR $res == null) {
header('Location: http://'.$_SERVER['index.php']);
}
else {
echo '<div class = "formObjectSearch">';
foreach ($res as $val) {
echo '<div class = "infoTab">';
echo '<h2>'.$val["name"].'</h2>';
echo '<p>Guidance:'.$val["info"].'</p>';
echo '<p>Whos sitting here?:'.$val["owner"].'</p>';
echo '</div>';
echo '<img class="buildingImage" src="img/'.$val['image'].'" />';
}
echo '</div>';
}
OR
You can try to replace empty, with:
if ($res->rowCount() > 0) {
// if founded
} else {
// header('Location: http://'.$_SERVER['index.php']);
}

How can I send url where I use sessions?

I use sessions in the products site. My problem is how can I send the single products datasheet site's url.
In the product datasheet site, I fill up the sessions when I click on a product's image in the index site:
<?php session_start(); include "connection.php";
$sql = mysql_query("SELECT * FROM products WHERE img = '".$_COOKIE['image_src']."'");
while ($f = mysql_fetch_array($sql))
{
$_SESSION['fid'] = $f['id']; //product id
$_SESSION['fimg'] = $f['image']; //product image
$_SESSION['fname'] = $f['name']; //product name
$_SESSION['fdecription'] = $f['decription']; //product description
$_SESSION['fcategory'] = $f['category']; //product category
}
?>
Than the same site I write out the sessions (the product infos):
e.g:
<?php session_start(); print ($_SESSION[fname]);
echo "<img src='".$_SESSION['fimg']."' height='350' width='250'>";?>
But this way always the last clicked products infos will be in the sessions.
And I can't open more than one product's datasheet at the same time.
You just need to create another "level" to your session array:
<?php
session_start();
include "connection.php";
$sql = mysql_query("SELECT * FROM products WHERE img = '".$_COOKIE['image_src']."'");
# Create a counter variable
$counter = 0;
while ($f = mysql_fetch_array($sql))
{
$_SESSION[$counter]['fid'] = $f['id']; //product id
$_SESSION[$counter]['fimg'] = $f['image']; //product image
$_SESSION[$counter]['fname'] = $f['name']; //product name
$_SESSION[$counter]['fdecription'] = $f['decription']; //product description
$_SESSION[$counter]['fcategory'] = $f['category']; //product category
# Increment the counter
$counter++;
}
?>
Then on the page which you want to view the images, just loop that array:
<?php
for( $i=0; $i<count($_SESSION); $i++ )
{
...
echo '<img src="'.$_SESSION[$i]["fimg"].'">';
...
}
?>
Multi-dimensional Arrays
PHP Docs - Arrays
I solve the problem:
Firstly I have to call the page this way: index.php?image_src=XY
Then I need to use $_GET insted of $_COOKIE.
Finally with this way the sessions are unnecessary.
<?php include "connection.php";
$sql = mysql_query("SELECT * FROM products WHERE img = '".$_GET['image_src']."'");
while ($f = mysql_fetch_array($sql))
{
$fid = $f['id']; //product id
$fimg = $f['image']; //product image
$fname = $f['name']; //product name
$fdecription = $f['decription']; //product description
$fcategory = $f['category']; //product category
}
?>
And I can write out the datas:
<?php echo "<img src='".$fimg."' height='350' width='250'>";
echo "$fdecription";
?>

Tinypass dynamic data

I am using Tinypass.com for a paywall and would like to show data from a database table inside the tags.
I want to replace below where: 'ECHO DATA FORM DB TO GO HERE'
So far I have:
<?php
/* Include TinyPass - make sure to use the correct path */
include_once "lib/TinyPass.php";
// configure Tinypass
TinyPass::$SANDBOX = true;
# Chanage these values with your TinyPass applicatin's settings
TinyPass::$AID = "76JigADEH5";
TinyPass::$PRIVATE_KEY = "aj43agFz9ZGxq8yPlZN4PHn01Xiy0bnezWmpEirC";
/*
If you want to integrate this system with logged in user then RID should be [ObjectName-UserID]
*/
$rid = "Content-1"; #unique_resource_id
$store = new TPAccessTokenStore();
$store->loadTokensFromCookie($_COOKIE);
$token = $store->getAccessToken($rid);
# If anonymous user has rights to see content
if($token->isAccessGranted()) {
//Access granted! Display requested resource to the user
echo '<div class="vendor"><iframe src="http://player.vimeo.com/video/25708134?title=0&byline=0&portrait=0" width="500" height="281" frameborder="0"></iframe></div>'; } else {
echo '<div style="background-color:#D3768D; width:100%; height:281px;"></div><div style="padding:15px;" >
ECHO DATA FORM DB TO GO HERE
<br> ';
$resource = new TPResource("$rid", "Paid Content");
//Create 3 price options
$po1 = new TPPriceOption("5.00", "24 hours");
$po2 = new TPPriceOption("10.00", "72 hours");
$po3 = new TPPriceOption("20.00", "30 days");
$offer = new TPOffer($resource, $po1);
$offer->addPriceOption($po2);
$offer->addPriceOption($po3);
$ticketoptions = array();
$ticketoptions["btn.size"] = "2";
$purchaseRequest = new TPPurchaseRequest($offer, $ticketoptions);
$buttonHTML = $purchaseRequest->generateTag();
//output button HTML in the place where Tinypass button is supposed to be rendered
echo $buttonHTML;
}
?>
Normally I would use:
<?php echo $row_tutorial['text_after']; ?>
But obviously that would not work with in another tag. Any ideas
So what you want is a concatenated string:
echo '<div style="background-color:#D3768D; width:100%; height:281px;"></div><div style="padding:15px;" >' . $row_tutorial['text_after']. '<br> ';

How to save data to session

When the user clicks the "Select" link, I would like whatever is selected to be saved to the session. Then another view will display all of the items stored in the session.
How can I do this? Or is there better solution or approach to use with this application?
Here is my current code:
<?php
foreach($query as $row){
echo $row ->firstname;
echo $row ->lastname;
echo "<a href=".base_url()."index.php/controller/function/$row->username /> Select </a>"
}
?>
This should be in your controller:
function my_function($username) {
$users = json_decode($this->session->userdata('users'), true);
$users[] = $username;
$this->session->set_userdata('users', json_encode($users));
print_r($this->session->userdata('users'));
}
Make sure the session library is loaded. Autoload suggested.
For example, on the top of your page:
<?PHP
session_start();
if (isset($_SESSION['yourvar']))
echo $_SESSION['yourvar'];
else
$_SESSION['yourvar'] = 10;
?>

Facebook fb:request-form not working

I just tried using the example given on developers.facebook.com to open a request form and invite friends, so I changed everything accordingly but nothing happens, do I need to launch it in some way?
<?php
$api_key = '...';
$secret = '...';
require_once 'facebook.php';
// Names and links
$app_name = "...";
$app_url = "http://apps.facebook.com/.../"; // Assumes application is at http://apps.facebook.com/app-url/
$invite_href = "invite.php"; // Rename this as needed
$facebook->require_frame();
$user2 = $facebook->require_login();
if(isset($_POST["ids"])) {
echo "<center>Thank you for inviting ".sizeof($_POST["ids"])." of your friends on <b>".$app_name."</b>.<br><br>\n";
echo "<h2>Click here to return to ".$app_name.".</h2></center>";
} else {
// Retrieve array of friends who've already authorized the app.
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user2.') AND is_app_user = 1';
$_friends = $facebook->api_client->fql_query($fql);
// Extract the user ID's returned in the FQL request into a new array.
$friends = array();
if (is_array($_friends) && count($_friends)) {
foreach ($_friends as $friend) {
$friends[] = $friend['uid'];
}
}
// Convert the array of friends into a comma-delimeted string.
$friends = implode(',', $friends);
// Prepare the invitation text that all invited users will receive.
$content =
"<fb:name uid=\"".$user2."\" firstnameonly=\"true\" shownetwork=\"false\"/> has started using ".$app_name." and thought it's so cool even you should try it out!\n".
"<fb:req-choice url=\"".$facebook->get_add_url()."\" label=\"Put ".$app_name." on your profile\"/>";
?>
<fb:request-form
action="<? echo $invite_href; ?>"
method="post"
type="<? echo $app_name; ?>"
content="<? echo htmlentities($content,ENT_COMPAT,'UTF-8'); ?>">
<fb:multi-friend-selector
actiontext="Here are your friends who don't have <? echo $app_name; ?> yet. Invite whoever you want -it's free!"
exclude_ids="<? echo $friends; ?>" />
</fb:request-form>
<?php
}
?>
hello the following code works for me
<fb:serverFbml width="760px">
<script type="text/fbml">
<fb:fbml>
<fb:request-form
action='http://apps.facebook.com/yoursite/'
method='POST'
type='photo fun'
content="Let's fun with facebook
<fb:req-choice url='http://www.yoursite.com' label='Register'/>"
<fb:multi-friend-selector actiontext="Select your friends."></fb:multi-friend-selector>
</fb:request-form>
</fb:fbml>
</script>
</fb:serverFbml>

Categories