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


PHP Sum of mysql results calculated in real time dynamically


EDIT No working answer ...

I have a table with product price model cost stock etc, to make it easier I calculate the total customer pay for for each product like this

<?php echo number_format($show['quantity'] * $show['product_price'],0,',','.'); ?>

But now I need to show the total sum of this calculation but as you can see they are calculared in PHP real time. Is there a way to do it?

Here is the complete code

<?php
$result=mysqli_query($database,"SELECT * FROM `products` order by `category` ASC");
$rows=mysqli_num_rows($result);
if(mysqli_num_rows($result)>0){
?>

<table class="sales">

<tr>
<td>Quantity</td>
<td>Product Cost</td>
<td>Customer Pays</td>
</tr>        

<?php if($rows){$i=0;while($show=mysqli_fetch_assoc($result)){?>

<tr>
<td><?php echo number_format($show['quantity'],0,',','.'); ?></td>
<td><?php echo number_format($show['product_cost'],0,',','.'); ?></td>
<td><?php echo number_format($show['quantity'] * $show['product_cost'],0,',','.'); ?></td>
</tr>

<?php }}?>
</table>

TOTAL CUSTOMER PAY FOR ALL PRODUCTS = EXAMPLE $10.234

<?php }else{?> 

No products to show

<?php }?>


Online javascript editor like inDesign


For a project we're currently trying to create an online WYSIWYG editor which should have the same basic functionality as Adobe's InDesign:

  • Adding text frames, and linking text frames together
  • Master Pages (with baseline, margins, columns and gutter)
  • Basic formatting (font size and styles, alignment)

We're trying to enable users to create simple documents using articles on their news-website as a source. Trough a drag'n'drop interface they should be able to quickly build a simple news-paper-like document. The user's creation should get converted to PDF (trough FPDF library). Therefore the editor should create some sort of html with data-attributes containing properties like width, height, etc. so this data can be converted to a json object to be extracted in PHP and loaded into FDPF. The progress in simple steps:

  1. Html WYSIWYG generates preview + html attributes with measurements;
  2. Post html attributes trough ajax to server sided;
  3. PHP server side extracts json and converts it to FPDF object;
  4. User is offered PDF file for download.

I've tried looking at iCloud's Pages, which uses SproutCore (or Ember?) as far as I can see, but I think it would be overkill to use that framework, possibly it won't even have the basic functionality I'm looking for.

Has anybody got any idea's how to get started? What JavaScript framework to use (I've used Prototype, Mootools and jQuery in the past) and where to look for possible examples / similar projects?


Mamp/PHP: how to disable PHP warnings messages about deprecated functions


In my web app my boss wants me to use msql_* php functions but I can't even login because of PHP messages about these deprecated functions. How can I disable them in MAMP? Looking in this forum I've found the following rules to write inside php.ini

error_reporting  = E_ALL & ~E_DEPRECATED
display_errors = On
disable_functions = "list of mysqli_* functions"

but this doesn't work. I've written this to all file php.ini of each php version contained in MAMP. The only thing that works is to put

display_errors = Off

but I can't use it like that otherwisw I won't even be able to see my programming/syntax error of other problems.

Here is my php.ini of php 5.6.10 inside /Applications/MAMP/bin/php/php5.6.10/conf/

Do you have any ideas? I know I should use new functions and not deprecated ones but it's not up to me and I can't disable all error messages...


Angular does not updated loop due to implementation $mdDialog (Material Design)


Based on my previous post: Angular loop is not updating, i updated the code slightly to add a dialog box to the button a a user.

the only change in my app.js file is the directive to add a $mdDialog box. so the complete code for my app.js file is:

var app = angular.module('AddUser', ['ngMaterial']);

app.controller('AppCtrl', function($scope, $http, $mdDialog){
$scope.userInfo =  [];

/** function to add details for a user in mysql referecing php **/
$scope.save_user = function() {
    $http.post('db.php?action=add_user', 
        {
            'user_name'  : $scope.user_name, 
            'user_email' : $scope.user_email
        }
    )

    .success(function (data, status, headers, config) {
        $scope.userInfo.push(data);
        $scope.get_user(); //this will fetch latest record from DB
        console.log("The user has been added successfully to the DB");
        console.log(data);
    })

    .error(function(data, status, headers, config) {
        console.log("Failed to add the user to DB");
    });
}

/** function to get info of user added in mysql referencing php **/
$scope.get_user = function() {
    $http.get('db.php?action=get_user').success(function(data)
    { 
        $scope.userInfo = data;   
        console.log("You were succesfull in showing user info"); 
        //$scope.get_user(); //this will fetch latest record from DB
    })
}

/** function to delete a user from list referencing php **/
$scope.delete_user = function(index) {  
    $http.post('db.php?action=delete_user', 
        {
            'user_index' : index
        }
    )      
    .success(function (data, status, headers, config) {    
        $scope.get_user();//this will fetch latest record from DB
        console.log('Deletion was succesfull');
    })

    .error(function(data, status, headers, config) {
       console.log("You were NOT succesfull in deleting a user"); 
    });
}

$scope.showPopUp= function(ev) {
    $mdDialog.show({
      controller: DialogController,
      templateUrl: 'popup.tmpl.html',
      parent: angular.element(document.body),
      targetEvent: ev,
    })
};

function DialogController($scope, $mdDialog) {
    $scope.closeDialog = function() {
      $mdDialog.hide();
    }

    $scope.save_user = function() {
        $mdDialog.hide();
    }
}

});

i had to comment out the following code in the get_user function ($scope.get_user();) otherwise i could not preform a delete but then on the other hand the loop did not update. so either i comment out $scope.get_user() in de get_user function and then i can delete a user or i don't comment it out and the loop will update when i add a new user but then the delete function does not work ...

my html code is:

<body ng-controller="AppCtrl">
  <div>
    <ul ng-init="get_user()">
      <li ng-repeat="user in userInfo ">{{user.user_name}}<a href="#" ng- 
      click="delete_user(user.id)"> --> Delete</a></li>
    </ul>
  </div>

 <md-button class="md-primary md-raised" ng-click="showPopUp($event)" flex 
 flex-md="100">Add a user</md-button>
</body>

and the code for the dialog box (popup.tmpl.html) is the following:

<md-dialog aria-label="Add or invite a user" ng-app="AddUser">
<form ng-controller="AppCtrl">
      <md-toolbar>
       <div class="md-toolbar-tools">
         <h2>Add or invite a user</h2>
         <span flex></span>
         <md-button class="md-icon-button" ng-click="closeDialog()">
              <md-icon md-svg-src="images/ic_close_24px.svg" aria-label="Close 
              dialog"></md-icon>
         </md-button>
       </div>
      </md-toolbar>
      <md-dialog-content>
        <div>
          <div layout="" layout-sm="column">
            <md-input-container flex="">
            <label>Enter a name</label>
            <input name="user_email" ng-model="user_name">
            </md-input-container>
        </div>
        <div layout="" layout-sm="column">
          <md-input-container flex="">
          <label>Enter an e-mail</label>
          <input name="user_name" ng-model="user_email">
          </md-input-container>
       </div>
      </div>
     </md-dial
     <div class="md-actions" layout="row">
       <md-button ng-click="closeDialog()" class="md-primary">Cancel</md-     
        button>
       <md-button ng-click="save_user()" name="add_user" class="md-
       primary">Add</md-button>
     </div>
    </form>
   </md-dialog>


TYPO3: Backend login redirects to index.php


Recently I have been having some problems with my typo3 installation on my webhosting. One of those problems is, that whenever I login to backend I get redirected to index.php and not the backend. The admin panel is shown on the index.php indicating that the it logs in successfully but then why can't I go to the backend interface.

I have tried several things, like clearing the be_sessions table in the database, clearing the browser cookies, deleting the cache, testing on other web browsers etc. but still no luck.

I am using TYPO3 4.6. Any help will be highly appreciated. Thanks :)


CAKEPHP SELECT OPTION CLASS


Does someone know how to add class to a select option in a view file ?

I have at the moment:

echo $this->Form->input(
                'shelf_id',
                array(
                    'options' => $Shelves,
                    'label'=> 'Etagère :',
                    'default' => $Place['Place']['shelf_id'],
                    'class'=>'form-control')
            );

All my options element are like this :

<option value="1">Element</option>

But I want them to be like this :

<option value="1" class="myClass">Etagere 1</option>

Tks


How do you scrape .asp or .php pages?


Can you explain a bit of the intuition behind it?

I'm using mechanize in python and I only get the server script, etc , where I believe the server script was supposed to put the table with the data I want in it.

I just want to load the page like I see it on the browser and save it to a text file.


show only parent class properties in child class using $this in parent class


I have the following two classes. Class BMW extends class Car.

class Car{

    public $doors;
    public $wheels;
    public $color;
    public $size;

    public function print_this(){
        print_r($this);
    }

}

class BMW extends Car{
    public $company;
    public $modal;

    public function __construct(){
        print_r(parent::print_this());
    }
}

$bmw = new BMW();
$bmw->print_this();

In above code when I access parent class method from constructor using parent::print_this() and inside print_this() method I have print_r($this) which prints all properties(parent and child class properties) Now what I want print_r(parent::print_this()); should output only parent class properties in child class? Can anyone help me on this?


How to log out a banned user in Symfony?


Symfony provides a simple way of preventing users from logging in using the isEnabled property if the user class implements AdvancedUserInterface.

However, if the user is logged in nothing will prevent them from accessing the website until their session expires.

The idea would be to check the isEnabled property upon getting the user entity ($this->get('security.token_storage')->getToken()->getUser()) and to invalidate the session then. What is the preferred way of doing so?

Or is there a better way to achieve this goal?


Neo4j PHP returning results at the same order as the where


I have nodes with the label "Campaign". I'm getting them each time in a different order.

So after I query to the DB, I have an array with Campaigns objects.

After that, I'm sending them into another function in the db.

MATCH (campaign:Campaign)
                 where campaign.id="1433855846340" or campaign.id="1433855948013" or campaign.id="1433856017523" or campaign.id="1433856146618" or campaign.id="1433856170282" or campaign.id="1433856364138" or campaign.id="1433856901298" or campaign.id="1433857169469" or campaign.id="1433857216853" or campaign.id="1433873093289" or campaign.id="1433873178949" or campaign.id="1433926766014"
                with campaign optional match campaign<-[:TAKEN_IN]-(picture:Picture) with campaign, collect(picture) as pictures
                with pictures[toInt(rand()*size(pictures))] as picture,campaign
                optional match picture-[:UPLOADED_TO]->(facebookPicture:FacebookPicture)
                RETURN picture.source as coverPicture,campaign.id

Basically all I need, is to return the results at the same order as the where clause. How can I do that without knowing if the campaigns were got from the DB, in

DESC

, for example/


What means prefix "preg" in php PCRE functions? [duplicate]


This question already has an answer here:

I know that PCRE is for Perl-Compatible Regular Expressions. But what means PREG? Php REGex? Perl REGex?


Check if the index exists or not Elasticsearch


I want to check in elasticsearch if the index exists or not. If it not exists it should create the index and do other functionality. I try to find out a solution for that, but did not find any perfect solution for that. Can anyone have any solution to solve this problem.

I am using Elasticsearch library.

**$client = new Elasticsearch\Client();**


post multideminsional array in multideminsional array


We need to post products here.

The product will have more than one color, while each color have different image.

I have created a form. in this form when user click add more color, it will create them a block div to pick up multiple images for that color, and so on for the next color.

Here is the sketch or input that I will create dynamically with js

<input type="text" name="color[red]" value="red" /> 
    <input name="color[red][image1]" /> 
    <input name="color[red][image2]" /> 
    <input name="color[red][image3]" /> 
    <input name="color[red][image4]" /> 

<input type="text" name="color[blue]" value="blue" />
    <input name="color[blue][image1]" /> 
    <input name="color[blue][image2]" /> 
    <input name="color[blue][image3]" /> 
    <input name="color[blue][image4]" /> 


    And so on...

I need a help how to post the inputs above with php, so that the output array would be like this:

array
    (
        [0] => array
                (
                    name => one
                    id => 1
                    color => array
                                (
                                    [0] => array 
                                                (
                                                    name =>red
                                                    image => array 
                                                                (
                                                                    [0] =>oneRed1.jpg
                                                                    [1] =>oneRed2.jpg
                                                                    [2] =>oneRed3.jpg
                                                                )   
                                                )   
                                    [1] => array 
                                                (
                                                    name =>blue
                                                    image => array 
                                                                (
                                                                    [0] =>oneBlue1.jpg
                                                                    [1] =>oneBlue2.jpg
                                                                    [2] =>oneBlue3.jpg
                                                                )   
                                                )   
                                    [2] => array 
                                                (
                                                    name =>purple
                                                    image => array 
                                                                (
                                                                    [0] =>onePurple1.jpg
                                                                    [1] =>onePurple2.jpg
                                                                    [2] =>onePurple3.jpg
                                                                )   
                                                )   
                                )
                )
        [1] => array
                (
                    name => two
                    id => 2
                    color => array
                                (
                                    [0] => array 
                                                (
                                                    name =>red
                                                    image => array 
                                                                (
                                                                    [0] =>twoRed1.jpg
                                                                    [1] =>twoRed2.jpg
                                                                    [2] =>twoRed3.jpg
                                                                )   
                                                )   
                                    [1] => array 
                                                (
                                                    name =>blue
                                                    image => array 
                                                                (
                                                                    [0] =>twoBlue1.jpg
                                                                    [1] =>twoBlue2.jpg
                                                                    [2] =>twoBlue3.jpg
                                                                )   
                                                )   
                                    [2] => array 
                                                (
                                                    name =>purple
                                                    image => array 
                                                                (
                                                                    [0] =>twoPurple1.jpg
                                                                    [1] =>twoPurple2.jpg
                                                                    [2] =>twoPurple3.jpg
                                                                )   
                                                )   
                                )
                )
    )

Thank you very much in advance for any help.