Friday, August 9, 2013

Php Zend Ajax

//** View Page **//

Need jquery.js

function ApprovalSearch() {
 // get the form values
 var search = $('#search').val();

 $.ajax({
   type: "POST",
   url: "/rfc/ajax/searchview/",
   data: "search=" + search,
   success: function(resp){
     // we have the response
  alert("Server said:\n '" + resp + "'");
         document.getElementById("SearchView").innerHTML = resp;
         document.getElementById("Search_head").style.visibility = 'visible';
   },
   error: function(e){
     alert('Error: ' + e);
   }
 });
}

//** controllers **//
  public function searchviewAction(){
   
                        $request = $this->getRequest();
            $registry = Zend_Registry::getInstance(); 
            $DB = $registry['DB'];
            if(isset($_POST['search'])) {
                           $search =  $_POST['search'];
            $rs = $DB->fetchAll("SELECT * FROM access_control ");
                        
          }

Php Zend Birth Date To Age Calculate



$birthDate = $request->getParam('startdate');
            $birthDate = explode("-", $birthDate); 
              $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2])); 

RESULT: 25



             

Php Zend Form Input Validation

 Special Character Validation
'LoanType' =>trim(preg_replace('/[^a-zA-Z0-9\s]/', '',$request->getParam('loanType'))),

Php Zend Session Destroy

            $auth->clearIdentity();
           
            unset($namespace->name);
            unset($namespace->username);
            unset($namespace->access);
            unset($namespace->usserGroup);
            Zend_Session::destroy(true);

Php Zend Get Session ID


$id = Zend_Session::getId();
echo $id;

Php Zend Set Session

 $namespace = new Zend_Session_Namespace(); // set session
             
            $namespace->access=$access_level;
            $namespace->usserGroup =$usserGroup;
            $namespace->ip =$_SERVER['REMOTE_ADDR'];
            $namespace->useragent = $_SERVER['HTTP_USER_AGENT'];

Php Zend Login Authenticate Check

// Nazmus Sakib

$request = $this->getRequest();
            $auth = Zend_Auth::getInstance();
            if(!$auth->hasIdentity()){
                $this->_redirect('/index/loginform');
            }

Thursday, August 1, 2013

Php HTML Browser Javascript Enable / Disable Validation

<noscript> <meta http-equiv=refresh content="0; URL=/codeigniter_mcq/index.php/javaX2/" /> </noscript>
<noscript><meta http-equiv="X-Frame-Options" content="deny"/></noscript>

Php CSV Creation

  function escape_csv_value($value) {
                $value = str_replace('"', '""', $value); // First off escape all " and make them ""
                if(preg_match('/,/', $value) or preg_match("/\n/", $value) or preg_match('/"/', $value)) { // Check if I have any commas or new lines
                        return '"'.$value.'"'; // If I have new lines or commas escape them
                } else {
                        return $value; // If no new lines or commas just return the value
                }
  }


 function csv_qstn_bank_yn()
  {

        $db = mysql_connect('localhost', 'root', ''); // Connect to the database
        $link = mysql_select_db('exam_db', $db);        // Select the database name

       $yes_no = 'YesNoQstn';

        $sql = mysql_query("SELECT q_id as Question_id,q_name as Question,ans as answer,s_name as Subject FROM bank_yn"); // Start our query of the database
        $numberFields = mysql_num_fields($sql); // Find out how many fields we are fetching

      

        if($numberFields) { // Check if we need to output anything
                for($i=0; $i<$numberFields; $i++) {
                        $keys[] = mysql_field_name($sql, $i); // Create array of the names for the loop of data below
                        $head[] = $this->escape_csv_value(mysql_field_name($sql, $i)); // Create and escape the headers for each column, this is the field name in the database
                }
                $headers = join(',', $head)."\n"; // Make our first row in the CSV

                $data = '';
                while($info = mysql_fetch_object($sql)) {
                        foreach($keys as $fieldName) { // Loop through the array of headers as we fetch the data
                                $row[] = $this->escape_csv_value($info->$fieldName);
                        } // End loop
                        $data .= join(',', $row)."\n"; // Create a new row of data and append it to the last row
                        $row = ''; // Clear the contents of the $row variable to start a new row
                }
                // Start our output of the CSV
                header("Content-type: application/x-msdownload");
                header("Content-Disposition: attachment; filename=$yes_no.csv");
                header("Pragma: no-cache");
                header("Expires: 0");
                echo $headers.$data;
        } else {
                // Nothing needed to be output. Put an error message here or something.
                echo 'No data available for this CSV.';
        }
    }
 

Php Codeigniter Cookie Set & Get

$cookie = array(
                    'name'   => 'submit',
                    'value'  => $this->userid,
                    'expire' => '30800',
                    'path'   => '/',
                    'prefix' => 'smx_',
                   );
              
set_cookie($cookie);

$check = get_cookie('smx_submit');

Php Codeigniter Email Send

   $add = trim($dip->email);
                $text ="Your Exam Name : "." ".$name."\n"."Exam Date : "." ".$date."\n"."Exam Start time : "." ".$time."\n"."Exam Duration : "." ".$duration." Minutes"."\n\n\n Please Log in to:"." "."http://exam.thecitybank.com \n\n\nThis is an AUTO_GENERATED email. Please do not reply here";
                $config['protocol'] = 'smtp';
                $config['smtp_host']='smtp.thecitybank.com';
                $config['port']='25';               
                $config['charset']='utf-8';
                $config['wordwrap']='TRUE';
                $config['multitype']='html';
                $config['newline']='\n';
                $this->email->initialize($config);
                $this->email->clear();
                $this->email->from('service.quality@thecitybank.com');
                $this->email->to($add);
                $this->email->subject('Retake Exam');
                $this->email->message($text);
               
                if($this->email->send())
                {
                    echo '<br><font color="Green">Mail Sent Successfully to UserId</font>'.nbs(2).$dip->username.nbs(2).'e-mail address:'.nbs(2).$dip->email;
                }
                else
                {
                    echo '<br><font color="RED">Mail Sent Failed To UserId</font>'.nbs(2).$dip->username.nbs(2).'e-mail address:'.nbs(2).$dip->email;
                }

Php MySql Database Connection Test Script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>MySQL Connection Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
#wrapper {
    width: 600px;
    margin: 20px auto 0;
    font: 1.2em Verdana, Arial, sans-serif;
}
input {
    font-size: 1em;
}
#submit {
    padding: 4px 8px;
}
</style>
</head>

<body>

<div id="wrapper">

<?php
    $action = htmlspecialchars($_GET['action'], ENT_QUOTES);
?>

<?php if (!$action) { ?>

    <h1>MySQL connection test</h1>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>?action=test" id="mail" method="post">

    <table cellpadding="2">
        <tr>
            <td>Hostname</td>
            <td><input type="text" name="hostname" id="hostname" value="" size="30" tabindex="1" /></td>
            <td>(usually "localhost")</td>
        </tr>
        <tr>
            <td>Username</td>
            <td><input type="text" name="username" id="username" value="" size="30" tabindex="2" /></td>
            <td></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type="text" name="password" id="password" value="" size="30" tabindex="3" /></td>
            <td></td>
        </tr>
        <tr>
            <td>Database</td>
            <td><input type="text" name="database" id="database" value="" size="30" tabindex="4" /></td>
            <td>(optional)</td>
        </tr>
        <tr>
            <td></td>
            <td><input type="submit" id="submit" value="Test Connection" tabindex="5" /></td>
            <td></td>
        </tr>
    </table>

</form>

<?php } ?>

<?php if ($action == "test") {

// The variables have not been adequately sanitized to protect against SQL Injection attacks: http://us3.php.net/mysql_real_escape_string

    $hostname = trim($_POST['hostname']);
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);
    $database = trim($_POST['database']);

    $link = mysql_connect("$hostname", "$username", "$password");
        if (!$link) {
            echo "<p>Could not connect to the server '" . $hostname . "'</p>\n";
            echo mysql_error();
        }else{
            echo "<p>Successfully connected to the server '" . $hostname . "'</p>\n";
//            printf("MySQL client info: %s\n", mysql_get_client_info());
//            printf("MySQL host info: %s\n", mysql_get_host_info());
//            printf("MySQL server version: %s\n", mysql_get_server_info());
//            printf("MySQL protocol version: %s\n", mysql_get_proto_info());
        }
    if ($link && !$database) {
        echo "<p>No database name was given. Available databases:</p>\n";
        $db_list = mysql_list_dbs($link);
        echo "<pre>\n";
        while ($row = mysql_fetch_array($db_list)) {
             echo $row['Database'] . "\n";
        }
        echo "</pre>\n";
    }
    if ($database) {
    $dbcheck = mysql_select_db("$database");
        if (!$dbcheck) {
            echo mysql_error();
        }else{
            echo "<p>Successfully connected to the database '" . $database . "'</p>\n";
            // Check tables
            $sql = "SHOW TABLES FROM `$database`";
            $result = mysql_query($sql);
            if (mysql_num_rows($result) > 0) {
                echo "<p>Available tables:</p>\n";
                echo "<pre>\n";
                while ($row = mysql_fetch_row($result)) {
                    echo "{$row[0]}\n";
                }
                echo "</pre>\n";
            } else {
                echo "<p>The database '" . $database . "' contains no tables.</p>\n";
                echo mysql_error();
            }
        }
    }
}
?>

</div><!-- end #wrapper -->
</body>
</html>