Edit Button

10 posts by 3 authors in: Forums > CMS Builder
Last Post: May 19, 2016   (RSS)

By tCote - May 13, 2016

Wondering how hard it would be to create a function that would show an edit button that would display in a product listing. When clicked it would take you to that particular item you are viewing for editing. This would only display if a person were logged in to the CMS admin area and not show to normal users. 

I am replacing a database of products with over 10,000 listings and from time to time some products need to be updated. This is a function that was present in the old program that we used and really was a time saver. 

By ross - May 17, 2016

Hi there.

Thanks for posting.

There are going to be options for an "edit" link on your product listing pages.  What you need to do is log into CMS Builder, and click to modify a record. 

You should end up with a URL like this:

http://www.yoursite.com/cmsAdmin/admin.php?menu=news&action=edit&num=1234

You just need to take that URL and replace the number at the end with something like this:

http://www.yoursite.com/cmsAdmin/admin.php?menu=news&action=edit&num=<?php echo $recrod['num']; ?>

Does that make sense?

If you have multiple listing pages that link to different sections in CMS Builder, you'll also need to change the "menu=news" part in that URL so it points at the right table/section.

Let me know any questions.

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By tCote - May 17, 2016 - edited: May 17, 2016

Am I too assume that I create a link from that url and insert it in the template file using link tag?  Doing so I get the following error when trying to access a record.

This is the code for link. http://www.siteaddress.com/dataAdmin/admin.php?menu=listings&action=edit&num=<?php echo $recrod['num']; ?>

Security Warning: A link from an external source has been detected and automatically disabled.
For security links are only accepted from: http://www.siteaddress.com/dataAdmin/admin.php
Your browser indicated that it linked from: http://www.siteaddress.com/listingDetail2.php?Chevrolet-43

By Damon - May 18, 2016

Hi,

Here are some steps to make the Edit link only available if you have logged into CMS Builder in another browser tab.

In the file, add this code in the PHP block at the top of the page:

$CURRENT_USER = getCurrentUserFromCMS();


This will get the user login status so we can check if the user is logged in.

Next, to test, add this code to your page to display your logged in status:

<?php if(!$CURRENT_USER) : ?>
You are NOT logged in. <br />
<?php endif; ?>

<?php if($CURRENT_USER) : ?>
You are ARE logged in. <br />
<?php endif; ?>


If the message "You are NOT logged in" appears, open another browser and log into CMS Builder. Then refresh this page to see the "You are ARE logged in" message.

For your edit links, add code like this:

<?php if($CURRENT_USER) : ?>
<a href="http://www.siteaddress.com/dataAdmin/admin.php?menu=listings&action=edit&num=<?php echo $record['num'] ?>" style="font-size: 10px; color: red;"><strong>EDIT</strong></a><br />
<?php endif; ?>


Now, when you are logged into CMS Builder in another browser tab, on this page you will see EDIT links that will take you into that record in CMS Builder to edit. Change color/style as needed.

To prevent the security warning message from appearing, log into CMS Builder and go to Admin > General Settings. Scroll down to the Security Settings and uncheck the Check Referer checkbox.

That should be in. Give this a try and let me know if you have any questions.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By tCote - May 19, 2016 - edited: May 19, 2016

Checking login using provided code when not logged in I get Not logged in as it should and also after logging in I get you are logged in and edit code shows correctly. However when hitting the edit button it takes me to the admin panel and blank record but first presents the login screen

In the developer log I get the following error. 

E_NOTICE: Undefined variable: record
/home/siteaddress(without.com)/public_html/listingDetail.php (line 316)
http://siteaddress.com/listingDetail.php?Ford-54

By Damon - May 19, 2016

Hi,

The code was based on you using $record['num']. 

From the error, it sounds like you are using a different name than record.

Can you post the full foreach loop code?

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By tCote - May 19, 2016

Only for each loop is within the uploads section and rest of the page is php echo. This is setup using the basic car template you sell. 

<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block to the TOP of your page BEFORE anything else. */
require_once "init.php";

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'listings',
'joinTable' => 'homepages',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$listing = @$listingRecords[0];


if (!$listing) { print "listingsRecord not found!"; exit; }

?>
<?php include "include_header.php"; ?>


<div class="subheader">View : <?php echo $listing['vehicle'] ?></div><br/>

<table border="0" cellspacing="0" cellpadding="2" width="590">
<tr>
<td rowspan="20" valign="top" align="center" width="165">

PHOTOS<br/>
<b>Click photo to enlarge</b><br/><br/>

<?php foreach ($listing['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" title="<?php echo $upload['info1'] ?>" alt="<?php echo $upload['info2'] ?>" /></a><br/>
<?php echo $upload['info3'] ?><br/>
<?php endif ?>
<?php endforeach ?>

<?php if (!$listing['uploads']): /* if no uploads show this: */ ?>
<table cellspacing="0" cellpadding="0" width="150" class="noPhoto" style="height: 100px">
<tr><td bgcolor="#EEEEEE" align="center"><b>Photo<br/>Not<br/>Available</b></td></tr>
</table>
<?php endif; ?>


</td>
<td valign="top">
<div class="separatorBar" style="padding: 3px 3px 3px 3px;">
<div style="float: right;"><b>Price</b> $<?php echo number_format($listing['price']); ?></div>
<div><strong>Details</strong></div>
</div> 

<?php foreach ($listing['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $upload['urlPath'] ?>" rel="lightbox['gallery']" title="<?php echo $upload['info2'] ?>"><img src="<?php echo $upload['thumbUrlPath'] ?> " width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="1" title="<?php echo $upload['info1'] ?>" alt="<?php echo $upload['info2'] ?>" /></a><br/>
<?php echo $upload['info3'] ?><br/>
<?php endif ?>
<?php endforeach ?>

<?php if (!$listing['uploads']): /* if no uploads show this: */ ?>


<table cellspacing="0" cellpadding="0" width="125" class="noPhoto" style="height: 100px">
<tr><td bgcolor="#EEEEEE" align="center"><b>Photo<br/>Not<br/>Available</b></td></tr>
</table>
<?php endif; ?>

<b><u>Photos Courtesy of</u></b><br/> <?php echo $listing['photos_courtesy_of'] ?>
</td>
<td valign="top">
<div class="separatorBar"><b><u>Profile Details:</b> - <b><?php echo $listing['year'] ?></b> <b><?php echo $listing['vehicle'] ?> <?php echo $listing['model'] ?></b></u></div></div></div>

And so on

By Damon - May 19, 2016

Try this for adding an edit button to a detailed page:

<?php if($CURRENT_USER) : ?>
<a href="http://www.siteaddress.com/dataAdmin/admin.php?menu=listings&action=edit&num=<?php echo $listing['num'] ?>" style="font-size: 10px; color: red;"><strong>EDIT</strong></a><br />
<?php endif; ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By Damon - May 19, 2016

Thanks for the update. Glad to hear it is working now!

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/