lundi 29 juin 2015

Implementing Jquery Pagination to Opencart Admin page


I am trying to add jquery pagination plugin to opencart Admin page(Catalog > Options > Option value)( /admin/view/template/catalog/option_form.tpl ).

When you click on edit option it loads option values. I have lots of those that is why I am trying to implement paging.

I tried many jquery plugins but to no avail as the plugins have no effect.

Is there any way I can implement paging using jquery or is there any other method i can use?

Thanks.

[Edit]

Whatever i know i tried in php and it is not working.

  EDIT:

I tried one more thing: in admin/controller/catalog/product/option.php

in the method: public function edit() {

I added this code:

<code>

    $pagination = new Pagination();
    $pagination->total = $option_value_total;
    $pagination->page = $page;
    $pagination->limit = $this->config->get('config_limit_admin');
    $pagination->url = $this->url->link('catalog/option/edit', 'token='     . $this->session->data['token'] . $url . '&page={page}', 'SSL');

    $data['pagination'] = $pagination->render();

    $data['results'] = sprintf($this->language->get('text_pagination'), ($option_value_total) ? (($page - 1) 
                        * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) 
                        * $this->config->get('config_limit_admin')) > ($option_total - $this->config->get('config_limit_admin'))) ? $option_value_total : ((($page - 1) 
                        * $this->config->get('config_limit_admin')) 
                        + $this->config->get('config_limit_admin')), $option_value_total, ceil($option_value_total / $this->config->get('config_limit_admin')));

</code>
In Option_form.tpl
<code> 

    <div class="row">
        <div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
        <div class="col-sm-6 text-right"><?php echo $results; ?></div>
    </div>

</code>
In admin/model option.php

in <code>public function getOptionValues($option_id) {</code> I added 
<code> 

    if (isset($data['start']) || isset($data['limit'])) {
        if ($data['start'] < 0) {
        $data['start'] = 0;
        }

        if ($data['limit'] < 1) {
        $data['limit'] = 20;
        }

        $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
        }

        $query = $this->db->query($sql);

        return $query->rows;

</code>


Escaping input for WMI Query


I'm creating a PHP package for querying WMI objects, and I'm wondering if there's a need to escape strings inserted into WMI queries?

If so, how do I parametrize and escape strings in the query since I can't use things like PDO as it required a PDO connection?

For an example query:

$value = 'PC';

$query = sprintf('SELECT * FROM Win32_LogicalDisk WHERE SystemName = "%s"', $value);

$connection->ExecQuery($query);


Why is Laravel 5 removing REMOTE_ADDR from Server object?


I hope someone has seen this before, I've been searching Google and getting nowhere.

I'm trying to do something very simple, retrieve REMOTE_ADDR from $_SERVER object but it simply equates to true (1).

I am convinced this is a config issue related to laravel but have no idea where to start digging.

The contents of $_SERVER are as follows (obviously I've removed potentially sensitive paths etc.)

USER = '[REMOVED]'
HOME = '[REMOVED]'
FCGI_ROLE = 'RESPONDER'
REDIRECT_HANDLER = 'php5-fcgi'
REDIRECT_STATUS = '200'
HTTP_HOST = '[REMOVED]'
HTTP_CONNECTION = 'keep-alive'
HTTP_ACCEPT = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
HTTP_USER_AGENT = 'Mozilla/5.0 (Linux; Android 5.0.1; GT-I9505 Build/LRX22C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36'
HTTP_REFERER = '[REMOVED]'
HTTP_ACCEPT_ENCODING = 'gzip, deflate, sdch'
HTTP_ACCEPT_LANGUAGE = 'en-GB,en-US;q=0.8,en;q=0.6'
PATH = '/usr/local/bin:/usr/bin:/bin'
SERVER_SIGNATURE = 'Apache/2.2.22 (Ubuntu) Server at [REMOVED] Port 80'
SERVER_SOFTWARE = 'Apache/2.2.22 (Ubuntu)'
SERVER_NAME = '[REMOVED]'
SERVER_ADDR = '[REMOVED]'
SERVER_PORT = '80'
REMOTE_ADDR = '1'
DOCUMENT_ROOT = '[REMOVED]'
SERVER_ADMIN = '[REMOVED]'
SCRIPT_FILENAME = '[REMOVED]'
REMOTE_PORT = '48650'
REDIRECT_QUERY_STRING = '[REMOVED]'
REDIRECT_URL = '/index.php'
GATEWAY_INTERFACE = 'CGI/1.1'
SERVER_PROTOCOL = 'HTTP/1.1'
REQUEST_METHOD = 'GET'
QUERY_STRING = '[REMOVED]'
REQUEST_URI = '[REMOVED]'
SCRIPT_NAME = '/index.php'
ORIG_SCRIPT_FILENAME = '[REMOVED]'
ORIG_PATH_INFO = '/index.php'
ORIG_PATH_TRANSLATED = '[REMOVED]'
ORIG_SCRIPT_NAME = '/php5-fcgi'
PHP_SELF = '/index.php'
REQUEST_TIME = '1435331181'

Note the REMOTE_ADDR = '1'

What is going on there?

I have tried simply creating a test.php file in a /var/www/myapp/public/ as follows

<?php
print_r($_SERVER)

and it gives me the REMOTE_ADDR correctly, which is what leads me to believe it is a laravel issue.

If anyone can suggest why this is happening and what I can do about it, it would be greatly appreciated.

Relevant version numbers:

OS: Debian 7

nginx: 1.2.1

php: 5.4.39

Laravel 5


how to make a joomla plugin?


I am trying to make a joomla plugin, but I have few questions that I haven't found any answer.

What the plugin has to do: add a new field in register form(let's say Cell Number), and on form submit insert that cell number in database.

My documentation is this tutorial.

Questions:

  • How do you add a new field in register form? xml file is done, but I am not sure how to write the php code...(please help)

  • How do I get the cell number variable from that form? $jinput = JFactory::getApplication()->input; ?

Pleas help me with few tips. Thanks!


Get basic information of instagram page


I have number of instagram pages/urls of different users like http://ift.tt/1HtGUL2 etc etc etc. I want to get following information of that page

name, number of followers, description, bio,

I have searched and all showing using access token. But I am confused if I will take access token from my account, how can I get information of other pages?

Please guide me how can I do that?


Make SQL Query from button via PHP


I have my SQL query working fine in PHPMyAdmin but can't get it work with PHP. Let's say I have this query:

SELECT Login, Firstname, Lastname, Company INTO OUTFILE 'c:\\users.txt' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n'  
FROM `Users` WHERE Company = 'SID';

I would like to call my query from a web page with a click. I did 2 files fonction.php and form.php as follow. For fonction.php

<?php
function connectMaBase(){
    $base = mysql_connect ('localhost', 'root', '');  
    mysql_select_db ('CCPayment', $base) ;
}
?>

And for form.php I have this

<?php
include("fonction.php");
?>
<html>
    <head><title>Pages de requetes SQL </title></head>
    <body>
        <h1> Requete SQL </h1>
       <form name="sqlquery" method="post" action="form.php">        
        <input type="submit" name="valider" value="Go"/>
       </form>
 <?php 
    if (isset ($_POST['valider'])){
        connectMaBase();
        $sql = "SELECT Login, Firstname, Lastname, Company  INTO OUTFILE \'c:\\\\Users.txt\' FIELDS TERMINATED BY \',\' LINES TERMINATED BY \'\\r\\n\' \n"
     . "FROM `OptiOutput` WHERE Company = \'SID\'";

        mysql_query ($sql) or die ('Erreur SQL !'.$sql.'<br />'.mysql_error()); 
        mysql_close();
    }
?>
    </body>
</html>

I'm a beginner and could not find what is wrong in the code.

Thanks for your help.


SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data on my Image Uploader


Im new here and did not find out my Solution by using Google or StackOverflow.
My Problem is that i have a Multiple Image Uploader that works with JSON, AJAX and PHP... But while I am programming, i get this Message on the Firefox Console:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

Witch is related to this line:

ajax = function (data) {
    var xml = new XMLHttpRequest(), uploaded;
    xml.addEventListener("readystatechange", function() {
        if(this.readyState === 4) {
            if(this.status === 200) {
                uploaded = JSON.parse(this.response); //THIS IS THE ERROR LINE
                if(typeof o.options.finished === "function") {
                    o.options.finished(uploaded);
                }
            }else {
                if(typeof o.options.error === "function") {
                    o.options.error();
                }
            }
        }
    });

I think its because the Array in the Variable "Uploaded" is empty... But it shouldve be filled so far.. Well, here is the PHP Code:

header("Content-Type: application/json");

$uploaded = [];
$allowed = ["mp4", "jpg", "png", "jpeg", "doc", "avi"];

$files = $_FILES["file"];

$succedeed = [];
$failed = [];

if (!empty($files)) {
    foreach($files["name"] as $key => $name) {
        if($files["error"][$key] === 0) {

            $temp = $files["tmp_name"][$key];

            $ext = explode(".", $name);
            $ext = strtolower(end($ext));

            $file = $files["tmp_name"][$key] . $ext;


            if(in_array($ext, $allowed) === true && move_uploaded_file($temp, "uploads/{$file}") === true) {
                $succedeed[] = array(
                    "Original Name" => $name,
                    "MD5 Name" => $file
                );
            }else {
                $failed[] = array(
                    "Original Name" => $name
                );

            }   
        }
    }

    if(!empty($_POST["ajax"])) {
        echo json_encode(array(
            "Erfolgreich hochgeladen" => $succedeed,
            "Nicht erfolgreich hochgeladen" => $failed
        ));
    }


}

Im very Desperated because of this... :D Hope someone can Help me... ^^

Niggo