iFrame empty in CJuidialog in YII - yii

Im using iframe inside CJuiDialog, iframe contains renderPartial to render some fields.In button click im opening dialog but dialog is empty!!! not showing fields rendered through renderPartial
My View Code:
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'RefList-New',
'options'=>array(
'title'=>'Ref List Value',
'autoOpen'=>false,
'modal'=>true,
'width'=>550,
'height'=>350,
'close'=>'js:function(){
}',
),
));
?>
<iframe id="cru-frame-RefNew" width="100%" height="100%" frameBorder="0" scrolling="no" >
<?php $this->renderPartial('reflist_New', array('model'=>$model,'base'=>$base)); ?>
</iframe>
<?php $this->endWidget();?>
<?php echo CHtml::imageButton(Yii::app()->request->baseUrl.'/images/new.jpg',array('id'=>'reflist-button','style'=>'display:inline-block'));?>
Yii script part:
<?php
Yii::app()->clientScript->registerScript('uploaddfsfd', "
$('#reflist-button').click(function() {
$('#RefList-New').dialog('open'); return false;
});
");
?>
when i open Dialog it is empty!!! why renderPartial part not executed? How to populate Dialog ??

Try like this,
<iframe id="cru-frame-RefNew"src=""width="100%" height="100%" frameBorder="0" scrolling="yes" ></iframe>
In your script
<?php
Yii::app()->clientScript->registerScript('uploaddfsfd', "
$('#reflist-button').click(function() {
$('#RefList-New').dialog('open');
$('#cru-frame-RefNew').attr('src','".CController::createUrl('yourAction',array('id'=>$model->id))."');
return false;
});
");
?>
In yor action
public function actionYourAction()
{
//renderPartial here
}
If you want to add one more iframe to the same dialogue box, add like,
$('#cru-frame-RefNew').attr('src','".CController::createUrl('yourAction',array('id'=>$model->id))."');
return false;
});

1st, make iframe with src
<iframe id="cru-frame-RefNew"
width="100%" height="100%" frameBorder="0" scrolling="no"
src="<?php echo $this->createUrl('reflist') ?>" >
2nd, add action to controller
function actionReflist() {
// fill $model and $base
// add special layout for display it in popups dialogs
$this->layout = "layouts/special_layouts_for_popup_dialogs.php";
$this->render('reflist_New', array('model'=>$model,'base'=>$base));
}

Related

run time watermark generate on pdf file Yii framework

" i have uploaded a file on server i want when a user from my website download this file he should be a watermarked file (watermark text will be 'his email id' in pdf file) "
Controller:
public function actionDownloadFiles()
{
ignore_user_abort(true);
$path = ( Yii::app()->basePath.'/../images/prequlification_form/'.$_GET['path'] );
$fullPath = $path ;
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
header("Content-length: $fsize");
header("Cache-control: private");
while(!feof($fd)) {
$buffer = fread($fd, 2048);
echo $buffer;
}
}
fclose ($fd);
exit;
}
View:
<h3><p class="note"><span class="required">form</span> Filling is required.</p></h3>
<?php echo $form->errorSummary($model); ?>
<!--here is the user id-->
<?php //echo $id;?>
<div class="file-dwnload">
<?php
$data=prequalificationForm::model()->findByPk(1);
if(!empty($data)) {
echo '<div class="dwnload-file"><li>'.
CHtml::link( $data->file_path,array("prequalificationForm/downloadFiles","path"=>($data->file_path))).
'</li></div> <div class="dwnload-butn"><li>'.
CHtml::link('Download File',array("prequalificationForm/downloadFiles","path"=>($data->file_path)))
."</li></div> " ;
}?></div>
<div class="row">
<?php echo $form->labelEx($model,'file_path'); ?>
<?php echo $form->fileField($model,'file_path',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'file_path'); ?>
</div>
<div class="row buttons">
<?php //echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
<?php echo CHtml::submitButton($model->isNewRecord ? 'Submit' : 'Save',array('class'=>'submit-btn')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
So you want to watermark the pdf with some data from the user.
You would have some options to do that.
The easier would be if you don't do it on a uploaded file, instead you generate html content and convert html to pdf on the fly.
But if you need to do it on a uploaded file, maybe this could help you:
Writing/Drawing over a PDF template document in PHP

How can I display a warning message on textfield in Yii

I'm new to Yii framework and I need to display the validation error message as in login form "Username cannot be blank". Now, I have a text field where I updated the fields and the during validation I want a message to be displayed. How can I do this?
Controller
public function actionUpdate($id)
{
$model = $this->loadModel($id);
// set the parameters for the bizRule
$params = array('GroupzSupport'=>$model);
// now check the bizrule for this user
if (!Yii::app()->user->checkAccess('updateSelf', $params) &&
!Yii::app()->user->checkAccess('admin'))
{
throw new CHttpException(403, 'You are not authorized to perform this action');
}
else
{
if(isset($_POST['GroupzSupport']))
{
$password_current=$_POST['GroupzSupport']['password_current'];
$pass=$model->validatePassword($password_current);
$model->attributes=$_POST['GroupzSupport'];
if($pass==1)
{
$model->password = $model->hashPassword($_POST['GroupzSupport']['password_new']);
if($model->save())
$this->redirect(array('/messageTemplate/admin'));
}
else {$errors="Incorrect Current password"; print '<span style="color:red"><b>';
print '</b><b>'.$errors;
print '</b></span>';}
}
$this->render('update',array(
'model'=>$model,
));
}
}
View
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'password-recovery-reset-password-form',
'enableAjaxValidation'=>false,
)); ?>
<div class="row"><?php
echo $form->labelEx($model,'username');
echo $form->textField($model,'username',array('size'=>45,'maxlength'=>150));
echo $form->error($model,'username');
?></div>
<div class="row">
<?php echo $form->labelEx($model,'current password'); ?>
<?php echo $form->passwordField($model,'password_current',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_current'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'new password'); ?>
<?php echo $form->textField($model,'password_new',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_new'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'confirm new password'); ?>
<?php echo $form->passwordField($model,'password_repeat',array('size'=>30,'maxlength'=>30)); ?>
<?php echo $form->error($model,'password_repeat'); ?>
</div>
<div class="row buttons"><?php
echo CHtml::submitButton('Reset Your Password');
?></div><?php
$this->endWidget(); ?>
</div>
Now currently I'm displaying it at the top.
I want to display it right on the textfield as in login page. How can I do this?
Before redirect, add the message to the desired field.
In the model Validator:
$this->addError('field_name', "Message error.");
Or in Controller action:
$model->addError('field_name', "Message error.");

Yii - Pass filtered CGridView data to a PDF format

I have a web application that uses CGridView to display filtered data from the $model based on user-entered search parameters.
My goal is for the user to be able to hit a button to export the filtered data to a PDF.
In order to accomplish this I'm using the extension yii-pdf.
Do I need to pass the information stored in the CActiveDataProvider array to be used in a separate controller and view for the PDF creation?
It seems easier to use the same controller/action and render the data into a view that can then be exported to PDF. But, alas, I cannot figure out how to do this.
Thanks in advance.
_search View:
<div class="wide form">
<?php
$form = $this->beginWidget('GxActiveForm', array(
'action' => Yii::app()->createUrl($this->route),
'method' => 'get',
));
?>
<!-- Search Fields here -->
<!-- Search and Export to PDF buttons -->
<div class="row buttons">
<?php echo GxHtml::submitButton(Yii::t('app', 'Search')); ?>
<?php echo GxHtml::button(Yii::t('app', 'PDF'), array('id' => 'exportToPdf')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- search-form -->
_pdf View
<div class="pdfContainer" id="pdfPage">
<div class="pdfHeader">
<img src="images/logo.png" style="float:left; text-align: top;"></img>
<div class="pdfTitle" style="text-align: right; float: right;">
<h3>Service Report</h3>
</div>
</div><!-- header -->
<?php echo "Prepared by: ".Yii::app()->user->name."\n" ?>
<?php **//Possibly echo contents here?** ?>
<div class="clear"></div>
<div class="pdfFooter">
</div><!-- footer -->
</div><!-- page -->
</div>
controller/action
public function actionPdf(){
$this->layout='pdf';
/* mPDF */
$mPDF1 = Yii::app()->ePdf->mpdf();
/* render (full page) */
$mPDF1->WriteHTML($this->render('pdf', array(), true));
/* renderPartial (only 'view' of current controller) */
$mPDF1->WriteHTML($this->renderPartial('pdf', array(), true));
/* Outputs ready PDF */
$mPDF1->Output();
}
admin View:
<?php
Yii::app()->clientScript->registerScript('search', "
$('#exportToPdf').click(function(){
window.location = '". $this->createUrl('Weeklyservicereport/pdf') . "?' + $(this).parents('form').serialize() + '&export=true';
return false;
});
$('.search-form form').submit(function(){
$('#weeklyservicereport-grid').yiiGridView('update', {
data: $(this).serialize()
});
return false;
});
");
?>
<div class="search-form" style="display:block">
<?php $this->renderPartial('_search', array('model' => $model,)); ?>
</div> <!-- Search Form -->
/* Gridview Widget */
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id' => 'weeklyservicereport-grid',
'dataProvider' => $model->search(),
.....
.....
'columns'=>array(
/* Column names */
),
));
?>
You're pretty close of the solution, I will write here the logic that you can use.
Create a view for your PDF header;
Create a view for your PDF footer;
Create a view for your Gridview;
view: _pdf_header.php
<div class="pdfHeader">
<img src="images/logo.png" style="float:left; text-align: top;"></img>
<div class="pdfTitle" style="text-align: right; float: right;">
<h3>Service Report</h3>
</div>
</div>
view: _pdf_footer.php
<div class="pdfFooter">
<h5>Your Footer Page</h5>
</div>
view: _gridview.php
<?php $this->widget('application.components.widgets.tlbExcelView', array(
'id' => 'weeklyservicereport-grid',
'dataProvider' => $dataProvider,
'columns' => array( /*YOUR COLUMNS */ ),
));
?>
In your actionPdf, you just render partial the views, as suggested by #ineersa:
public function actionPdf(){
$this->layout = 'pdf';
$model = new Model();
$model->attributes = $_GET['Model']; /* to execute the filters (if is the case) */
$dataProvider = $model->search();
/* if yu want to ignore the pagination and retrieve all records */
$dataProvider->pagination = false;
$mPDF1 = Yii::app()->ePdf->mpdf();
$mPDF1->WriteHTML($this->renderPartial('_pdf_header', array(), true));
$mPDF1->WriteHTML($this->renderPartial('_gridview', array('dataProvider' => $dataProvider), true));
$mPDF1->WriteHTML($this->renderPartial('_pdf_footer', array(), true));
$mPDF1->Output();
}
Reference:
http://www.yiiframework.com/forum/index.php/topic/15677-printing-a-cgridview/

Instagram's geotagging API

I'm working on learning about Instagram's API as a side project. I've followed this tutorial (http://eduvoyage.com/instagram-search-app.html) to implement a search feature by hashtag. It was extremely helpful to me. One of the things I saw in the API was the location ID feature, and I was wondering how to implement that. Through a search on this site, I found that a request can be made which will return the following.
'{
"meta": {
"code": 200
},
"data": {
"attribution": null,
"tags": [],
"type": "image",
"location": {
"latitude": 48.8635,
"longitude": 2.301333333
},
"comments": {
"count": 0,
"data": []
},
..........'
I'm trying to figure out this tutorial to process that information. (http://www.ibm.com/developerworks/xml/library/x-instagram1/index.html#retrievedetails)
<html>
<head>
<style>
</head>
<body>
<h1>Instagram Image Detail</h1>
<?php
// load Zend classes
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
// define consumer key and secret
// available from Instagram API console
$CLIENT_ID = 'YOUR-CLIENT-ID';
$CLIENT_SECRET = 'YOUR-CLIENT-SECRET';
try {
// define image id
$image = '338314508721867526';
// initialize client
$client = new Zend_Http_Client('https://api.instagram.com/v1/media/' . $image);
$client->setParameterGet('client_id', $CLIENT_ID);
// get image metadata
$response = $client->request();
$result = json_decode($response->getBody());
// display image data
?>
<div id="container">
<div id="info">
<h2>Meta</h2>
<strong>Date: </strong>
<?php echo date('d M Y h:i:s', $result->data->created_time); ?>
<br/>
<strong>Creator: </strong>
<?php echo $result->data->user->username; ?>
(<?php echo !empty($result->data->user->full_name) ?
$result->data->user->full_name : 'Not specified'; ?>)
<br/>
<strong>Location: </strong>
<?php echo !is_null($result->data->location) ?
$result->data->location->latitude . ',' .
$result->data->location->longitude : 'Not specified'; ?>
<br/>
<strong>Filter: </strong>
<?php echo $result->data->filter; ?>
<br/>
<strong>Comments: </strong>
<?php echo $result->data->comments->count; ?>
<br/>
<strong>Likes: </strong>
<?php echo $result->data->likes->count; ?>
<br/>
<strong>Resolution: </strong>
<a href="<?php echo $result->data->images
->standard_resolution->url; ?>">Standard</a> |
<a href="<?php echo $result->data->images
->thumbnail->url; ?>">Thumbnail</a>
<br/>
<strong>Tags: </strong>
<?php echo implode(',', $result->data->tags); ?>
<br/>
</div>
<div id="image">
<h2>Image</h2>
<img src="<?php echo $result->data->images
->low_resolution->url; ?>" /></a>
</div>
<div id="comments">
<?php if ($result->data->comments->count > 0): ?>
<h2>Comments</h2>
<ul>
<?php foreach ($result->data->comments->data as $c): ?>
<div class="item"><img src="<?php echo $c
->from->profile_picture; ?>" class="profile" />
<?php echo $c->text; ?> <br/>
By <em> <?php echo $c->from->username; ?></em>
on <?php echo date('d M Y h:i:s', $c->created_time); ?>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<?php
} catch (Exception $e) {
echo 'ERROR: ' . $e->getMessage() . print_r($client);
exit;
}
?>
</body>
</html>
The main problem (I think) that I'm having is here:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Http_Client');
I downloaded Zend Frame 1.12.13, but I'm not sure what these line of code is asking for. In the Zend Framework folder, It goes "Zend/Loader(Folder)", but nothing called "Loader.php". Does that just load everything in the 'Loader' folder? Same for the Zend_Loader, there is a directory of Zend/Http/Client, but Client is also a folder.
tl;dr
Trying to set up a program that will search instagram (as linked in the tutorial above), be able to click on the picture results, open one tab that shows the picture and the users profile, and another tab that shows all the image metadata. Is there a simpler way to do this? Or a more noob friendly tutorial?
I ran into a similar problem when using this example. You must include the path of the Zend framework at the very top of this example. I did it in just its own php block at the top.
ini_set('include_path', 'path/to/ZendFramework/library');

image link in Yii framework

hello friends I am newbie to YII. I have an image . After calling that image in Yii its code like is this
<img class="deals_product_image" src="<?php echo MPFunctions::uploaded_image_url($data->item_display_image()->file_ufilename); ?>" alt="<?php echo $data->name; ?>" />
in general html it is doing like this
<img alt="women jackets" src="files/items/images/4db3b3b6a7c06/womens-jacket-thumb.jpg" class="deals_product_image">
Now I want that this image should be a href link like
<a href="files/items/images/4db3b3b6a7c06/womens-jacket-thumb.jpg img src="files/items/images/4db3b3b6a7c06/womens-jacket-thumb.jpg class="deals_product_image"/> </a>
so for this I used code like this
<?php echo CHtml::link('', array('items/viewslug', 'slug'=>$data->slug)); ?>
But it is not showing any link tag like <a href="">
so can any one tell me what should I do?What should I write in between '' tags?
You should simply give the html for the <img> tag as the first parameter:
$imageUrl = MPFunctions::uploaded_image_url($data->item_display_image()->file_ufilename);
$image = '<img class="deals_product_image" src="'.$imageUrl.'" alt="'.$data->name.'" />';
echo CHtml::link($image, array('items/viewslug', 'slug'=>$data->slug));
By the way, you can use CHtml::image to create the <img> tag as well:
$imageUrl = MPFunctions::uploaded_image_url($data->item_display_image()->file_ufilename);
$image = CHtml::image($imageUrl, $data->name, array('class' => 'deals_product_image'));
echo CHtml::link($image, array('items/viewslug', 'slug'=>$data->slug));