Tuesday, May 15, 2012

Smarty php add multiple forms into single page and submit via javascript

Smarty is a web template system. It facilitates a manageable way to separate application logic and content from its presentation. Few times ago i have work with smarty web application. When i work on this i face few problem. One of the major one is when i try to add multiple HTML forms into same web page and then submit on one form, other form also try to submit. i think there are few possible way to slove above problem. i just go though the following way.

multipleforms.html


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>External Seller | Control Panel</title>
</head>
<script language="JavaScript" type="text/javascript">
{literal}
function submitform(){
   document.form1.submit();
}

function submitform2(){
   document.form2.submit();
}
{/literal}
</script>
<body>
<form action="form1.php" name ="form1" id="form1" method="post">
    <input name="txt1" type="text"  id="txt1" value="{$server_obj->getValue()}"  size="50" />
    <input type="button" onclick="javascript: submitform()" id="submit1" value="Update First" class="button" />
</form>

    <br>
   
<form action="form2.php" name ="form2" id="form2" method="post">
    <input name="txt2" type="text"  id="txt2" value="{$server_obj2->getValue2()}"  size="50" />
    <input type="button" onclick="javascript: submitform2()" id="submit2" value="Update Second" class="button" />
</form>      
</body>
</html>

In the above example, i have use normal button instead of using submit button. On the button onclick event i have call JavaScript and submit form via that JavaScript. very Simple ;)

Wednesday, May 9, 2012

eKomi Frontend Integration

This Post show eKomi Fronted Integration with zend application.
In this example i have create ItemreviewServise file for connect eKomi API get reviews and store those reviews on local database. For performance reasons eKomi recommend to store the reviews in local database.

class Itemreview_Service_ItemreviewService  extends Base_Model_Service {

public function ekomiItemreview($language)
        {
                $ekomicertificate = '';
                $errorlang = "";

                if($language == "english"){
                    $interfaceid = $configItem->ekomiInterfaceId;
                    $ekomipassword = $configItem->ekomiPassword;
                    $errorlang = "English";
                }
           
           
        try
        {

                   
                        $Url = $config->ekomiProFeedbakUrl;
                        $Service = new Itemreview_Service_ClassAPIwebService($Url, "GET", "ISO-8859-1");

                        $Params["interface_id"]   = $interfaceid;           
                        $Params["interface_pw"] = $ekomipassword;             
                        $Params["type"] = "csv";


                        $Params["range"] = $config->ekomiRange;
                        flush();
                        $Response = $Service->SendRequest($Params);
                        $CSVBODY = $Response["Body"];


                        $ItemreviewServicearray = new Itemreview_Service_ItemreviewService();                  
                        $retunval = $ItemreviewServicearray->csv_to_array($CSVBODY);                     
                        foreach ($retunval as $key => $arrParam) {
                           
                               try
                                {
                                        $ItemreviewService = new Itemreview_Service_ItemreviewService();
                                        $Itemreviwentity = new Itemreview_Entity_Itemreview();
                                        $Itemreviwentity->setItm_id($arrParam['product_id']);
                                        $Itemreviwentity->setLang_id(66);
                                        $Itemreviwentity->set_auther("eKomi");
                                        $Itemreviwentity->setRe_text($arrParam['feedback']);
                                        $Itemreviwentity->setRe_text($replasequote);
                                       
                                        $Itemreviwentity->set_rating($arrParam['star_rating']);
                                        $Itemreviwentity->set_reviewlink("$ekomicertificate");
                                        $Itemreviwentity->setRe_isenable(1);
                                        $Itemreviwentity->set_unixtime($arrParam['UNIXTIME']);
                                        $Itemreviwentity->set_orderid($arrParam['order_id']);
                   
                                        $ItemreviewDAO = new Itemreview_Dao_ItemreviewDao();
                                        $ItemreviewDAO->addEkomireview($Itemreviwentity);
                                }
                                catch ( Exception $e)
                                {
                                        print_r("error ...!!");

                                }                    
                        }

        }
        catch ( Exception $e)
        {
                        print_r("record fail-$errorlang ---!!!");
        }  
        }
       
        public static function csv_to_array($csv, $delimiter = ',', $enclosure = '"', $escape = '\\', $terminator = "\n") {
                                $r = array();
                                $filecsv = APPLICATION_PATH."/xml/eKomiresponce.csv";
                                if(file_exists($filecsv)){
                                    unlink($filecsv);
                                }                               
                                $fp = fopen($filecsv, 'w');
                                fwrite($fp, $csv);
                                fclose($fp);
                               
                                $name_columns = array("UNIXTIME", "order_id", "product_id", "star_rating", "feedback");
                                $handle = fopen ($filecsv, 'r');
                                                while (($data = fgetcsv($handle, 1000, ',', '"')) !== FALSE)
                                                {
                                                      $r[] = array_combine($name_columns,$data);
                                                }             
                                return $r;
                              
                        }     






Following Class , i use to connect eKomi web service and get reviews




class Itemreview_Service_ClassApiwebService
{
    const TIME_OUT = 10;

    private $UserAgent;
    private $Method;
    private $CharSet;
    private $Url;
   
   
    public function __construct($ServerUrl, $Method, $CharSet, $UserAgent="")
    {

        error_reporting(E_ERROR | E_WARNING | E_PARSE);

        if (function_exists(domxml_open_mem))
            throw new Exception("Please comment out the line 'extension=php_domxml.dll' in Apache/bin/php.ini and restart the server!");
       
        if (empty($UserAgent)) $UserAgent = "PHP WebService Client";
       
        $this->Url       = parse_url($ServerUrl);
        $this->UserAgent = $UserAgent;
        $this->Method    = strtoupper($Method);
        $this->CharSet   = $CharSet;
       
        if (empty($this->Url["path"])) $this->Url["path"] = "/";
    }
   
    public function SendRequest($Data, $SoapAction="")
    {
        if (is_array($Data))
        {
            $Params = array();
            foreach ($Data as $Key => $Value)
            {
                $Encode = str_replace('%7E', '~', rawurlencode($Value));
                $Params[] = "$Key=$Encode";
            }
            $Query = implode('&', $Params);
        }
        else $DispParams = $Data;
       
        switch ($this->Method)
        {
        case "GET":
            $SendData  = "GET ".$this->Url["path"]."?$Query HTTP/1.0\r\n";
            $SendData .= "Host: " . $this->Url['host'] . "\r\n";
            $SendData .= "User-Agent: " . $this->UserAgent . "\r\n";
            $SendData .= "\r\n";
            break;

        case "POST":
            $SendData  = "POST ".$this->Url["path"]." HTTP/1.0\r\n";
            $SendData .= "Host: " . $this->Url['host'] . "\r\n";
            $SendData .= "Content-Type: application/x-www-form-urlencoded; charset=".$this->CharSet."\r\n";
            $SendData .= "Content-Length: " . strlen($Query) . "\r\n";
            $SendData .= "User-Agent: " . $this->UserAgent . "\r\n";
            $SendData .= "\r\n";
            $SendData .= $Query;
            break;

        default:
            throw new Exception("Invalid Method: ".$this->Method);   
        }
       

        $Port = array_key_exists('port',$this->Url) ? $this->Url['port'] : null;

        switch ($this->Url['scheme'])
        {
            case 'https':
                if (!function_exists(openssl_verify))
                    throw new Exception("Please remove the comment in the line ';extension=php_openssl.dll' in Apache/bin/php.ini and restart the server!");

                $Scheme = 'ssl://';
                $Port = ($Port === null) ? 443 : $Port;
                break;

            case 'http':
                $Scheme = '';
                $Port = ($Port === null) ? 80 : $Port;
                break;
               
            default:
                throw new Exception("Invalid protocol in: ".$this->ServerUrl);
        }
    
        $Socket = @fsockopen($Scheme . $this->Url['host'], $Port, $ErrNo, $ErrStr, 10);
        if (!$Socket)
            throw new Exception ("Unable to establish connection to host " . $this->Url['host'] . " $ErrStr");
       
        fwrite($Socket, $SendData);

        $Response = "";
        while (!feof($Socket))
        {

            $Response .= fgets($Socket, 1000);
        }
        fclose($Socket);
        // Between Header and ResponseBody there are two empty lines
        list($Header, $ResponseBody) = explode("\r\n\r\n", $Response, 2);
       
        $Split = preg_split("/\r\n|\n|\r/", $Header);

        list($Protocol, $StatusCode, $StatusText) = explode(' ', trim(array_shift($Split)), 3);
       
        $RetArray["Status"] = $StatusCode;
        $RetArray["Body"]   = $ResponseBody;
       
        return $RetArray;
    }
}

Hope this will help :)




Monday, May 7, 2012

eKomi link genaration

In this post i will show , how connect The SOAP-endpoint of the eKomi APIs http://api.ekomi.de/v2/wsdl and how to get account information using getSnapshot method via PHP.



The following parameters are expected for get account information, 1) auth 2)version

 Auth parameter containt Interface-ID and Interface-Password, separated by pipe (|) Example765|kgdf143shjk468775

Description of version is Script-Version. For self- build precede with ‘cust-’
 Example
cust-1.0.0


The response is a serialized PHP-array with the following elements:


Parameter Type
info array
info[account_name]
info[ekomi_certificate]
info[ekomi_certificate_id]
info[ekomi_certificate_seo]
info[fb_count]
info[fb_avg]
info[fb_avg_detail]
info[fb_avg_room]
info[fb_avg_service]
info[fb_avg_catering]
info[fb_avg_ambience]
feedbacks
feedbacks[0-9]
feedbacks[0-9]
 [transaction_id]

feedbacks[0-9] int Star rating (1-5)
[rating]
feedbacks[0-9]
[rating_room]
feedbacks[0-9]
[rating_service]
feedbacks[0-9]
[rating_catering]
feedbacks[0-9]
[rating_ambience]
 feedbacks[0-9]
    [message] 5)
    feedbacks[0-9]
    [comment] (1-5)
    feedbacks[0-9]
    [delivered] (1-5)

Following is example of php implementation of eKomi link genaration integration.


                        try{
                            $Clientekomi = new soapClient($config->ekomiWsdl);
                            $method = "getSnapshot";
                          
                            $paramss = array( new SoapParam($interfaceid.'|'.$ekomipassword, 'auth'), new SoapParam($config->ekomiCusVertion, 'version'));
                          
                            $retunarray = $Clientekomi->__call($method, $paramss);
                            $arr = unserialize(urldecode($retunarray));
                            $ekomicertificate = $arr['info']['ekomi_certificate_seo'];                       
                        }  catch (Exception $e){
                            //print_r($e);
                            print_r("Error Ocured When try to get Ekomi certificate url - $errorlang..!! \n");
                            //die('die in url');

                        } 


hope this will help you get better idea.... cheeeears... :)

Sunday, May 6, 2012

C# Windows Form add combo box controller selected index change event

In this post i will explain how to add combo box  selectedIndexChage event. Add gridview controller to Form , then add DataGridViewComboboxColumn to gridview and DataGridviewTextboxColumn.

then Create EditingControlSowing event as follow and add following code into source


 private void testgrid_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            ComboBox cmbBox;
            if ( testgrid .CurrentCell.ColumnIndex == 0)
            {
                cmbBox = e.Control as ComboBox;
                if (cmbBox == null)
                    return;
                cmbBox.SelectedIndexChanged += cmbBox_SelectedIndexChanged;
            }
        }



        void cmbBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ComboBox cmbBox = (ComboBox)sender;

            string getvalue= ((ComboBox)sender).SelectedValue.ToString();
            string setvalue= obClass.Sampkemethod( getvalue );

           testgrid .Rows[stockadjustmentgrid.CurrentCell.RowIndex].Cells[1].Value =  setvalue ;
         
        }

in above code what happen is, gather DataGridViewEditingControlShowingEventArgs  and it assign to new combobox controller .after that we create new selectedindex chage event for our new ComboBox and assign value that gathter according ComboBox selected value and , assign it to next textbox column.