Goto URL on clicking Link in CAutoComplete [Yii] - yii

I am using CAutoComplete in Yii application.
I am trying to return links based on search query. I am able to return that also.
Now if I will click that link whole link is copied to the search bar. Is it possible to goto url on clicking the link?
Code :
Controller -
$products = Product::model()->findAll();
foreach($products as $product) {
$return[] = CHtml::link($product->name,array('product/view','id'=>$product->id));
}
echo implode("\n",$return);
View -
$this->widget('CAutoComplete', array(
'name'=>'search',
'value'=>CHtml::encode(Yii::app()->request->getParam('search')),
'url'=>array('ajax/suggestProducts'),
'multiple'=>false,
'selectFirst'=>false,
'htmlOptions'=>array('placeholder'=>Yii::t('main','Search Products'),'id'=>'searchbar')
));

Related

Display string in xml format in browser either using view or controller

I have a string in my model.The string is actually XML content. I have a link on my page, when clicked it opens a new tab and displays the text as XML.
The result should be the same as when I right click on an xml file and open with Internet Explorer. The difference is that this is no file, its text that I need to display as XML in a new tab.
Anyone have an idea how to achieve this without creating a file and without giving a path to a file.
You could have a controller that will serve this XML and set the proper content type header:
public class MyXMLController: Controller
{
public ActionResult Index()
{
MyModel model = GetModelFromSomewhere(...);
return Content(model.StringPropertyContainingXML, "text/xml");
}
}
now all that's left is to write an anchor link pointing to /myxml/index:
#Html.ActionLink("Click to open XML", "index", "myxml", null, new { _target = "blank" })

How to migrate a cs-cart layout programmatically?

On a cs-cart project, I am looking for a clean way to automate the migration of the current theme in a fully automatic manner.
Migrating the theme files is easy since each theme is located in a dedicated directory.
Nevertheless, some pages are created using the layouts WYSIWIG editor from the backend. This editor as a nice feature that allows to generate an XML file that describes all the layouts and can be imported back into another environment. This requires manual operation (logging into the backend, clicking the button...) and I would like to fully automate this.
So far, the only solution I was able to find is to migrate the data directly from the database, by generating a dump of the layout related-tables and importing it into the target environment. This solution seems to work but is a bit risky in my opinion.
Does cs-cart provide a command-line interface to export and import the current layouts?
I wrote a small script for this task:
<?php
use Tygh\BlockManager\Layout;
use Tygh\BlockManager\Exim;
if ($mode == "do") {
$location_ids = array();
$default_layout_data = Layout::instance()->getDefault();
$layout_id = $default_layout_data['layout_id'];
$content = Exim::instance()->export($layout_id, $location_ids);
header("Content-Type: text/xml");
header("Content-Length: " . strlen($content));
header('Content-Disposition: attachment; filename=layouts.xml');
header('Expires: 0');
print $content;
exit();
}
if you put this code to a controller file (for example into your /app/addons/my_changes/controllers/backend/layout_export.php) and call this via url (in my case: /youradmin.php?dispatch=layout_export.do), it will download the default theme's main layout structure.
Please note, that I'm working with version 4.3.3. However I think this code will work any type of CS-Cart from version 4.x
Full solution (with my_changes add-on)
/app/addons/my_changes/schemas/permissions/trusted_controllers.post.php
<?php
$schema['layout_exim']['allow']['export'] = true;
$schema['layout_exim']['allow']['import'] = true;
return $schema;
/app/addons/my_changes/controllers/backend/layout_exim.php
<?php
use Tygh\BlockManager\Layout;
use Tygh\BlockManager\Exim;
if ($mode == "export") {
$location_ids = array();
$default_layout_data = Layout::instance()->getDefault();
$layout_id = $default_layout_data['layout_id'];
$content = Exim::instance()->export($layout_id, $location_ids);
header("Content-Type: text/xml");
header("Content-Length: " . strlen($content));
header('Content-Disposition: attachment; filename=layouts.xml');
header('Expires: 0');
print $content;
exit();
} elseif ($mode == "import") {
$result = Exim::instance()->importFromFile($_REQUEST['filepath']);
if ($result) {
print "true";
} else {
print "false";
}
exit();
}
After it, please clear your cache. If you do everything right, you will be able to call these 2 controllers without authentication (however I suggest you to set passwords in the get parameters, because right now, this is very unsafe!)
To call the controllers via URL:
http://path-to-your-admin.com/admin.php?dispatch=layout_exim.import&filepath=path/to/file
http://path-to-your-admin.com/admin.php?dispatch=layout_exim.export

Closing nested CjuiDialog popup - Yii Framework

I am trying to develop the screen with nested popup (Popup inside another popup), Now am facing issues to close the inner popup and make visible the outer popup without redirecting to any page. how to achieve this ?
First popup has one grid and one new button, clicking on new button opens one more popup , here am uploading files and storing the details in DB while submitting the upload button, it should close the inner popup and focus should be in outer popup with updated grid details.
Please give any idea to achieve this ?
My 2nd Popup View Code,
<?php
echo CHtml::form('','post',array('enctype'=>'multipart/form-data'));
echo CHtml::activeFileField($model, 'name');
echo CHtml::button( 'Submit',array('submit' => array('baseContact/SaveAttachDocuments')));
echo CHtml::endForm();?>
Controller Action for 2nd Popup,
public function actionSaveAttachDocuments()
{
$model=new DocumentAttachmentModel();
$filename =CUploadedFile::getInstance($model,'name');
$model->type =pathinfo($filename, PATHINFO_EXTENSION);
$model->name =pathinfo($filename,PATHINFO_FILENAME);
$model->save();
/** Here i have to close the 2nd popup and update the grid in 1st popup **/
}
I guess you should close the inner popup by javascript (after client side validation), and then call the controller action for the outer popup again from the actionSaveAttachDocuments() method.

Safari 5.1 extension development error -> event.userInfo returns null when it try to get selected text

I am trying to create a simple safari extension. My current version of Safari is 5.1.7 running in Snow Leopard.
I have 2 documents :
global.html
<!DOCTYPE HTML>
<script>
safari.application.addEventListener("command", performCommand, false);
function performCommand(event) {
if (event.command === "traducir") {
var query = event.userInfo;
alert(query);
query = query.replace(/\s+/g,"+");
var newTab = safari.application.activeBrowserWindow.openTab();
newTab.url = "http://translate.google.es/#en/es/" + query ;
}
}
</script>
and the injected script : injected.js
document.addEventListener("contextmenu", handleMessage, false);
function handleMessage(msgEvent) {
var sel = '';
sel = window.parent.getSelection()+'';
sel = sel.replace(/^\s+|\s+$/g,"");
safari.self.tab.setContextMenuEventUserInfo(msgEvent, sel);
}
The extension is very simple :
1- When the user selects one text or word, click right-button and select the item of the contextual menu that raise the function.
2- The injected file gets the value of the selected text and it shared with the global.html through the userInfo.
3- The global.html script open a new tab with the url of google translate.
The problem is that event.userInfo is always NULL. I was searching in Google and all the examples are like this and I donĀ“t know where the problem is and why it returns always NULL.
This could possibly be due to a too strict setting for "Access Level" in the Extension Builder. Try setting the dropdown menu to "All", and tick the "Include Secure Pages" checkbox.

Prestashop - customer registration management module - slight modification

I am struggling with modifying some code in Customer registration management module. Instant checkout is not working the way it should. When the Customer registration management module is disabled, the Instant Checkout is working fine, on submit and with no errors we go to the next step/screen. When Customer registration module is enabled, once we click on submit button under Instant checkout, we do not go to the next step/screen, instead we come back to the same screens, forms empty, and in url we have this: authentication?back=order.php%3Fstep%3D1
I managed to identify a piece a code which is preventing a customer from going to the following screen from Instant checkout form. It is the code in function hookCreateAccount($params)
function hookCreateAccount($params)
{
require_once (dirname(__FILE__).'/ApprovedCustomer.php');
global $cookie, $back;
$registration_code = pSQL(Tools::getValue('registration_code'));
if ($registration_code != '' AND $registration_code == $this->_registrationCode) {
$customer = $params['newCustomer'];
$customer->cleanGroups();
$customer->addGroups ($this->_defaultGroups);
}
$cookie->logged = $this->_isCustomerRegistredByDefault;
$cust = $params['newCustomer'];
$approval = new ApprovedCustomer($cust->id);
$approval->is_approved = $this->_isCustomerRegistredByDefault;
$approval->privilege_request = intval(Tools::getValue('privilege_request'),0);
$approval->privilege_message = pSQL(Tools::getValue('privilege_message'), '');;
if (! $approval->save())
Tools::D('Unable to save approval information');
if ($this->_sendAdminMail)
$this->sendMail('pending_registration', array('customer' => $cust, 'approval'=>$approval));
if (! $approval->is_approved) {
$back = 'modules/'.basename(__FILE__, '.php').'/messages.php?msg=noconnect&back=my-account.php';
$cookie->logged = 0;
$cookie->id_customer = 0;
}
elseif ($back == '')
$back = 'my-account.php';
}
Anybody has any ideas what in this code is causing this? any help would be really appreciated.
exactly what happens: once the user fill in Instant checkout form and clicks on submit, the form is redirected to the same page: ... /authentication?back=order.php%3Fstep%3D1
but it should go to: /order?step=2
the Instant Checkout form action:
<form action="{$link->getPageLink('authentication.php', true)}?back={$back}" method="post" id="new_account_form" class="std">
so, should I change the action part then? how does this work? could somebody point me to the right direction? any help would be really appreciated.
I suspect that the conflict occurs because by definition your customer isn't registering as part of the One Page Checkout functionality (I assume this is what you mean by Instant Checkout).
You could try refactoring the first block of code as:
global $cookie, $back;
$customer = $params['newCustomer'];
if ($customer->is_guest)
return;
require_once (dirname(__FILE__).'/ApprovedCustomer.php');
$registration_code = pSQL(Tools::getValue('registration_code'));
if ($registration_code != '' AND $registration_code == $this->_registrationCode) {
$customer->cleanGroups();
$customer->addGroups ($this->_defaultGroups);
}