Image link in jqgrid column - asp.net-mvc

I want to display image link in a column in jqgrid with image name as querystring.The link should contain following path "Home\ShowImage?imageName=vlaue".

function jqGridFormatter(cell, options, row) {
return "Image";
}
Then you need to specify this formatter in colModel options for jqGrid, see http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter.

You can move the image through xml or json in your url parameter like this:
$image = "<a href='#'><img src='folders/images/arrow.jpg' border='0' valign='middle' title='Edit something'><a>";
echo "<?xml version='1.0' encoding='iso-8859-1'?$et\n";
echo "<rows>"; echo "<page>".$page."</page>";
echo "<total>".$total_pages."</total>";
echo "<records>".$count."</records>"; // be sure to put text data in CDATA
echo "<row id='". $id."'>";
echo "<cell>". $image."</cell>";
echo "</row>";
}
echo "</rows>";
Please note that should be written as <a>

Related

Get code between tags and generate youtube embed

I have some tekst and in the middle of article I put {youtube}IPtv14q9ZDg{/youtube}. How to make code which is between {youtube} generated in youtube embed
I use PHP, but there might be other options.
I filter the text for the key-words. Then take the 11 digit code and wrap it in a link tag. Works best in a "for loop".
This is one I use to find url's in my text and make them live. But you can modify it to do what you want by changing the "preg_match" setting.
function make_clickable($string) {
$string = preg_replace("/[\n\r]/"," <br /> ",$string);
$arr = explode(' ', $string);
foreach($arr as $key => $value){
if(preg_match('#((^https?|http|ftp)://(\S*?\.\S*?))([\s)\[\]{},;"\':<]|\.\s|$)#i', $value)){
$arr[$key] = "<a class=\"custome\" href='". $value ."' target=\"_blank\" class='link'>$value</a> ";
}
}
$string = implode(' ', $arr);
return $string;
}

Is it possible to prevent perforce submit without filename?

My usual way to submit a file is:
p4 submit –d “some description” filename
I could do:
p4 submit
and use the editor, but I always have many files open, so that method is inconvenient
Several times, I have mistakenly typed
p4 submit –d "some description"
(forgot the filename)
This submitted dozens of open files to production, with unintended consequences.
Time to panic and spend the afternoon doing damage control.
I would like to prevent p4 -d when the filename is not specified.
If you are using Linux you can define function in your .bashrs file that validates number of arguments and won't let you submit if you miss4th parameter.
function p4()
{
# validate what parameters are passed and if they are correct
# pass them to /opt/perforce/p4 ...
}
Thanks #pitseeker
I created a Perl wrapper "p4s" which checks the arguments and forwards the call to the real "p4 submit".
#!/usr/bin/perl
use warnings;
use strict;
use Capture::Tiny 'capture_merged';
die "Description and file is required!\n" if #ARGV < 2;
my ($description, #files) = #ARGV;
if ( -f $description ) {
die "It looks like you forgot the description before the filenames";
}
my $cmd;
my %summary;
print `date`;
for my $file (#files) {
if ( ! -f $file ) {
$summary{$file} = "File $file not found!";
next;
}
my $pwd = `pwd`;
chomp $pwd;
# print p4 filelog to screen
print `ls -l $file`;
$cmd = "p4 filelog $file | head -n 2";
$cmd = "p4 fstat -T 'headRev' $file";
print $cmd . "\n";
my $filelog = `$cmd`;
print "$filelog" . "\n";
$cmd = "p4 diff -sa $file";
my ($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
if ( ! $merged ) {
$summary{$file} = "Skipped since the local file does not differ from p4";
next;
}
# p4 submit
$cmd = "p4 submit -r -d \"$description\" $file";
print $cmd . "\n";
($merged, $status) = Capture::Tiny::capture_merged {system($cmd)};
chomp $merged;
print $merged . "\n";
if ( $merged =~ /No files to submit from the default changelist/ ) {
$summary{$file} = "$merged (You may need to 'p4 add' or 'p4 edit' this file)";
next;
}
$summary{$file} = "Success";
}
if ( scalar #files > 0 ) {
print "\nSummary:\n";
for my $file (#files) {
printf "%s %s\n", $file, $summary{$file};
}
}

Remove a specific character of plaintext with simple dom html

I have this code to retrieve some products on a website:
foreach($page1->find('.link_category') as $produit1)
echo $produit1->plaintext . '<br />';
I retrieve product with double quote ", i would like to replace it (the double quote)by nothing
thanks for help
foreach($page1->find('.link_category') as $produit1) {
$product = str_replace('"','',$produit1->plaintext);
echo $product;
}
I hope it works :)

How to convert unorder list in to select option for this

Hi I am trying to add child category selection list and I found one nice code here and works fine but I want to use it as a dropdown selectoin and not un order list. Can anyone help me to do that.
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<h3>Products</h3>';
echo '<ul>'.$this_category.'</ul>';
}
}
?>
I have tried to use foreach but it didnt work may be I am wrong somewhere as not master in php
<?php
if (is_category()) {
$cat = get_query_var('cat');
$this_category = get_category($cat);
$this_category = wp_list_categories('hide_empty=0&hierarchical=true&orderby=id&show_count=0&title_li=&use_desc_for_title=1&child_of='.$this_category->cat_ID."&echo=0");
if($this_category !='<li>No categories</li>')
{
echo '<h3>Products</h3>';
echo '<select>';
foreach($this_category as $list) {
echo '<option>'.$list.'</option>';
}
echo '</select>';
}
}
?>
So your code doesn't appear to enter the foreach loop. The variable $this_category seems to be a string, not an array that you can iterate over.
Do a string replace to switch the <li> tags with <option> and then echo it:
$this_category = str_replace('<li>', '<option>', $this_category);
$this_category = str_replace('</li>', '</option>', $this_category);
echo '<select>'.$this_category.'</select>';

Error message: Fatal error: Can't use function return > value in write context in

I am trying to run some code from a book. There appears to be a problem with the code.
Here is the error message:
Fatal error: Can't use function return
value in write context in
/Applications/MAMP/htdocs/Eclipse-Workspace/simpleblog/test.php
on line 24
Here is the code referenced in the message (starting on line 24)
if (!empty(trim($_POST['username']))
&& !empty(trim($_POST['email']))) {
// Store escaped $_POST values in variables
$uname = htmlentities($_POST['username']);
$email = htmlentities($_POST['email']);
$_SESSION['username'] = $uname;
echo "Thanks for registering! <br />",
"Username: $uname <br />",
"Email: $email <br />";
}
I would appreciate any help. Please let me know if I need to provide any more information
Thanks a lot guys. That was very fast. The solution works great.
The problem is that the empty() function needs to be applied only to direct variables.
For future reference:
The code is from 'PHP for Absolute Beginners' by Jason Lengstorf (2009), pages 90-91, Chapter 3, $_SESSION
corrected code:
//new - Created a variable that can be passed to the empty() function
$trimusername = trim($_POST['username']);
//modified - applying the empty function correctly to the new variable
if (!empty($trimusername)
&& !empty($trimusername)) {
// Store escaped $_POST values in variables
$uname = htmlentities($_POST['username']);
$email = htmlentities($_POST['email']);
$_SESSION['username'] = $uname;
echo "Thanks for registering! <br />",
"Username: $uname <br />",
"Email: $email <br />";
}
In short: The empty() function only works directly on variables
<?php
empty($foo); // ok
empty(trim($foo)); // not ok
i'd say, for the course of getting further with that book, just use a temporary variable
so change:
if (!empty(trim($_POST['username']))
to
$username = trim($_POST['username']);
if(!empty($username)) {
//....
Exactly your example is mentioned at the manual
Note:
empty() only checks variables as anything else will result in a parse error. In other words, the following will not work: empty(trim($name)).
Use a temporary variable, or just test against "empty string"
if (trim($foo) !== '') {
// Your code
}

Resources