tag:blogger.com,1999:blog-13541811220949252162024-03-08T00:59:36.581-08:00Eazi Webeaziweb is a simple blog where a web developer/computer professional will find the solution for his day to day problem.eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.comBlogger63125tag:blogger.com,1999:blog-1354181122094925216.post-73522113362234841772013-11-27T10:31:00.000-08:002013-11-28T07:45:05.678-08:00URL Rewriting apache<div dir="ltr" style="text-align: left;" trbidi="on"><div class="comment-content"><br />
<p>I have a better solution. I’ve decided to go a bit in details for those who need it. Take a look and read on.</p><pre># Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Add trailing slash to url
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$
RewriteRule ^(.*)$ $1/</pre><a href="http://ecarobar.com/url-rewriting-apache/">Read more</a> </div></div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-91430606125942341562013-10-02T10:04:00.000-07:002013-10-02T10:04:08.457-07:00Magento – Can’t Retrieve Entity Config Solution<div id="post-1779" class="post-1779 post type-post status-publish format-standard hentry category-magento tag-dynamic-websites tag-web-design tag-website-designer"> <br />
<div class="entry"> <br />
<p>After a recent update of MAMP on my system, I was no longer able to load Magento sites on my localhost. The problem seems to be a PHP compatibilty issue and the solution is pretty simple.</p><p><span id="more-1779"></span></p><p>Loading up Magento sites on my local development server, I found myself greeted with a page saying:<br><br />
<strong>Can’t retrieve entity config: core/store_group</strong>, followed by a long trace: message and </p><p>I found the solution online here: <a target="_blank" title="Magento can't retrieve entity solution" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://dltr.org']);" href="http://dltr.org/blog/magento/175/Cant-retrieve-entity-config-corestore_group">dltr.org</a> and I’m posting it on my blog to make it easier for me to find later on!</p><p>Download a new copy of Magento from the <a target="_blank" title="Download Magento" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','http://www.magentocommerce.com']);" href="http://www.magentocommerce.com/download/">Magento Commerce site</a> and unzip the file.</p><p>Open <strong>Magento > lib > Varien</strong> and copy the <strong>Simplexml</strong> directory, then navigate through your sites on your localhost to the same location and replace the directory by pasting and overwriting. </p><p>Restart MAMP (or XAMP, LAMP, WAMP etc) and reload your sites.</p><p>Thanks to Damodar Bashyal for this!</p><span style="clear:both;display:none;"><img width="0" height="0" style="border-style:none;width:0px;height:0px;display:none;" alt="" src="http://haizdesign.com/blog/wp-content/plugins/wp-spamfree/img/wpsf-img.php"></span> <br />
<div class="clear"></div><br />
<br />
<p class="tags">Tags: <a rel="tag" href="http://haizdesign.com/blog/tag/dynamic-websites/">Dynamic websites</a>, <a rel="tag" href="http://haizdesign.com/blog/tag/web-design/">Web design</a>, <a rel="tag" href="http://haizdesign.com/blog/tag/website-designer/">Website designer</a></p> <br />
<p> </p> <br />
<!-- AddThis Button BEGIN --><br />
<div class="addthis_toolbox addthis_default_style "> <a fb:like:layout="button_count" class="addthis_button_facebook_like at300b"><div data-ref=".UkxQyxoxFxk.like" class="fb-like fb_edge_widget_with_comment fb_iframe_widget" data-layout="button_count" data-show_faces="false" data-action="like" data-width="90" data-font="arial" data-href="http://haizdesign.com/blog/magento/magento-cant-retrieve-entity-config-solution/" data-send="false" fb-xfbml-state="rendered"><span style="height: 20px; width: 72px;"><iframe scrolling="no" id="f2c33c586d54768" name="f10ffdda3e175d2" style="border: medium none; overflow: hidden; height: 20px; width: 72px;" title="Like this content on Facebook." class="fb_ltr" src="http://www.facebook.com/plugins/like.php?action=like&api_key=172525162793917&channel_url=http%3A%2F%2Fstatic.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D27%23cb%3Df3186165f6b26f8%26domain%3Dhaizdesign.com%26origin%3Dhttp%253A%252F%252Fhaizdesign.com%252Ff35a2cbe552802c%26relation%3Dparent.parent&colorscheme=light&extended_social_context=false&font=arial&href=http%3A%2F%2Fhaizdesign.com%2Fblog%2Fmagento%2Fmagento-cant-retrieve-entity-config-solution%2F&layout=button_count&locale=en_US&node_type=link&ref=.UkxQyxoxFxk.like&sdk=joey&send=false&show_faces=false&width=90"></iframe></span></div></a><br />
<a class="addthis_button_tweet at300b"><iframe scrolling="no" frameborder="0" allowtransparency="true" src="http://platform.twitter.com/widgets/tweet_button.1380566451.html#_=1380733140445&count=horizontal&counturl=http%3A%2F%2Fhaizdesign.com%2Fblog%2Fmagento%2Fmagento-cant-retrieve-entity-config-solution%2F&id=twitter-widget-2&lang=en&original_referer=http%3A%2F%2Fhaizdesign.com%2Fblog%2Fmagento%2Fmagento-cant-retrieve-entity-config-solution%2F&size=m&text=Magento%20-%20Can't%20Retrieve%20Entity%20Config%20Solution%20%7C%20Haiz%20Design%20Note%20Pad%3A&url=http%3A%2F%2Fhaizdesign.com%2Fblog%2Fmagento%2Fmagento-cant-retrieve-entity-config-solution%2F%23.UkxQy9fAqrc.twitter" class="twitter-share-button twitter-count-horizontal" style="width: 109px; height: 20px;" title="Twitter Tweet Button" data-twttr-rendered="true"></iframe></a><br />
<a g:plusone:size="medium" class="addthis_button_google_plusone at300b"><div style="text-indent: 0px; margin: 0px; padding: 0px; background: none repeat scroll 0% 0% transparent; border-style: none; float: none; line-height: normal; font-size: 1px; vertical-align: baseline; display: inline-block; width: 90px; height: 20px;" id="___plusone_0"><iframe width="100%" scrolling="no" frameborder="0" hspace="0" marginheight="0" marginwidth="0" style="position: static; top: 0px; width: 90px; margin: 0px; border-style: none; left: 0px; visibility: visible; height: 20px;" tabindex="0" vspace="0" id="I0_1380733144561" name="I0_1380733144561" src="https://apis.google.com/u/0/_/+1/fastbutton?bsv=o&usegapi=1&size=medium&hl=en-US&origin=http%3A%2F%2Fhaizdesign.com&url=http%3A%2F%2Fhaizdesign.com%2Fblog%2Fmagento%2Fmagento-cant-retrieve-entity-config-solution%2F&gsrc=3p&ic=1&jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en_GB.Oox7lIn1U94.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Frs%3DAItRSTMqcLhMrYhOQ6-ayEcOvkV1u8wF3w#_methods=onPlusOne%2C_ready%2C_close%2C_open%2C_resizeMe%2C_renderstart%2Concircled%2Cdrefresh%2Cerefresh&id=I0_1380733144561&parent=http%3A%2F%2Fhaizdesign.com&pfname=&rpctoken=87280279" data-gapiattached="true" title="+1"></iframe></div></a><br />
<a class="addthis_counter addthis_pill_style" style="display: block;" href="#"><a class="atc_s addthis_button_compact"><span></span></a><a class="addthis_button_expanded" target="_blank" title="View more services" href="#"></a></a><br />
<div class="atclear"></div></div> <script src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4e8736e0663d5cfe" type="text/javascript"></script><div style="visibility: hidden; height: 1px; width: 1px; position: absolute; z-index: 100000;" id="_atssh"><iframe id="_atssh835" title="AddThis utility frame" style="height: 1px; width: 1px; position: absolute; z-index: 100000; border: 0px none; left: 0px; top: 0px;" src="//ct1.addthis.com/static/r07/sh138.html#"></iframe></div><script type="text/javascript" src="http://ct1.addthis.com/static/r07/core102.js"></script><br />
<!-- AddThis Button END --><br />
<br />
</div> <br />
<div id="related-posts"><!-- related posts --><br />
Related Posts: <a title="Permanent Link to Add A Back To Page Link For NextGEN Gallery Created Pages" rel="bookmark" href="http://haizdesign.com/blog/jquery/back-to-page-link-for-nextgen-gallery/">Add A Back To Page Link For NextGEN Gallery Created Pages • </a><br />
<br />
<a title="Permanent Link to Massage In Mind Website" rel="bookmark" href="http://haizdesign.com/blog/portfolio/massage-in-mind-website/">Massage In Mind Website • </a><br />
<br />
<a title="Permanent Link to How to Exclude a Category From Your WordPress Home Page" rel="bookmark" href="http://haizdesign.com/blog/wordpress/how-to-exclude-a-category-from-your-wordpress-home-page/">How to Exclude a Category From Your WordPress Home Page • </a><br />
<br />
<a title="Permanent Link to Hobarts Estate Agents Website Makeover" rel="bookmark" href="http://haizdesign.com/blog/portfolio/hobarts-estate-agents-website-makeover/">Hobarts Estate Agents Website Makeover • </a><br />
<br />
<a title="Permanent Link to Error Establishing a Database Connection" rel="bookmark" href="http://haizdesign.com/blog/wordpress/error-establishing-a-database-connection/">Error Establishing a Database Connection • </a><br />
<br />
</div><br />
<br />
<br />
</div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-27895740456805528912013-09-04T13:14:00.001-07:002013-11-06T10:58:39.092-08:00Wordpress Plugins<style>
.main-inner .widget .post-body ul{
list-style: decimal;
}
.main-inner .widget .post-body ul li ul{
list-style: lower-roman outside none;
}
</style><br />
Some Important Wordpress plugin:<br />
<ul> <li><h3>User Management</h3> <ul> <li>User Access Manager</li>
<li>Capability Manager Enhanced</li>
<li>Role Scoper (best combination to use with Capability Manager Enhanced)</li>
</ul> </li>
<li><h3>Excerpt</h3> <ul> <li>Advanced Excerpt</li>
</ul> </li>
<li><h3>Security</h3> <ul> <li>Better WP Security</li>
<li>Really Simple CAPTCHA</li>
</ul> </li>
<li><h3>PDF</h3> <ul> <li>BSK PDF Manager</li>
<li>Print Friendly and PDF</li>
</ul> </li>
<li><h3>Custom Post</h3> <ul> <li>Custom Post Type UI</li>
<li>Post Types Order</li>
<li>Simple add pages or posts => http://wordpress.org/plugins/simple-add-pages-or-posts/</li>
</ul> </li>
<li><h3>Forms</h3> <ul> <li>Contact Form 7</li>
<li>Ninja form</li>
<li>Front End Login Form => http://wordpress.org/plugins/front-end-login-form/</li>
</ul> </li>
<li><h3>Site Down/Maintenance</h3> <ul> <li>Maintenance Mode</li>
</ul> </li>
<li><h3>Cross Platform/Cross CMS</h3> <ul> <li>Joomla/Mambo to WP Migrator</li>
</ul> </li>
<li><h3>Social Media</h3> <ul> <li>Recent Tweets Widget</li>
</ul> </li>
<li><h3>Slider/Carousel/Lightbox</h3> <ul> <li>Revolution Slider(Best known)</li>
<li>FlexSlider</li>
<li>WP Video Lightbox => http://wordpress.org/plugins/wp-video-lightbox/<br />
Description : youtube and vimeo videos in lightbox<br />
</li>
</ul> </li>
</ul>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com2tag:blogger.com,1999:blog-1354181122094925216.post-73086429962654120272013-08-30T07:58:00.000-07:002013-11-28T07:30:42.671-08:00Increase Max Upload File Size in WordPress<div dir="ltr" style="text-align: left;" trbidi="on"><br />
Sometimes, you need to upload a large file to your site, and the default 8mb limit in WordPress isn’t enough. I attempted to change my limit directly on my server, then in the .htaccess file and then in wp-config.php but neither change worked for me. Then I came across this little snippet by Word Impressed which actually worked and allowed me to increase my max upload file size limit...<br />
<a href="http://ecarobar.com/increase-max-upload-file-size-in-wordpress/"> Read more</a><br />
</div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-90651170679142431102013-06-13T11:02:00.001-07:002013-06-13T11:02:14.898-07:00First Wordpress plugin<div dir="ltr" style="text-align: left;" trbidi="on">
<div>
First Wordpress plugin</div>
<div>
<br /></div>
<div>
<blockquote>
/* Plugin Name: crud operation<br /> * Plugin URI: www.datum.com<br /> * description: a plugin for performing basic crud operations<br /> * Vesion: 1.0<br /> * Author URI: www.datum.com<br /> * license: GP2<br /> */<br />function crud_setUserCaps($param) {<br /> $editor = get_role(strtolower($param));<br /> $editor->add_cap('edit_download_item');<br /> $editor->add_cap('read_download_item');<br /> $editor->add_cap('delete_download_item');<br /> $editor->add_cap('edit_download_items');<br /> $editor->add_cap('delete_download_items');<br /> $editor->add_cap('read_download_items');<br />}<br />function crud_unsetUserCaps($param) {<br /> $editor = get_role(strtolower($param));<br /> $editor->remove_cap('edit_download_item');<br /> $editor->remove_cap('read_download_item');<br /> $editor->remove_cap('delete_download_item');<br /> $editor->remove_cap('edit_download_items');<br /> $editor->remove_cap('delete_download_items');<br /> $editor->remove_cap('read_download_items');<br />}<br />function set_caps() {<br /> //author,subscriber,contributor<br /> crud_setUserCaps('editor');<br /> crud_setUserCaps('administrator');<br />}<br />function crud_activationFun($param) {<br /> set_caps();<br /> crud_createDBTable();<br /> crud_installData();<br /> // Then flush them <br /> flush_rewrite_rules();<br />}<br />register_activation_hook(__FILE__, 'crud_activationFun');<br />function crud_deactivationFun($param) {<br /> crud_dropTable();<br /> crud_unsetUserCaps('editor');<br /> crud_unsetUserCaps('administrator');<br /> flush_rewrite_rules();<br />}<br />register_deactivation_hook(__FILE__, 'crud_deactivation_fun');<br />add_action('wp_enqueue_scripts', 'crud_loadScripts');<br />function crud_loadScripts($param) {<br /> wp_enqueue_script('jquery');<br /> wp_register_script('docready', plugins_url('js/docready.js', __FILE__));<br /> wp_enqueue_script('docready');<br />}<br />add_action('wp_enques_styles', 'crud_loadStyles');<br />function crud_loadStyles($param) {<br /> wp_register_style('baseStyle', plugins_url('css/style.css', __FILE__));<br /> wp_enqueue_style('baseStyle');<br />}<br />add_action('init', 'crud_addRewriteRules');<br />function crud_addRewriteRules() {<br /> add_rewrite_rule("download_items/^([^/]*)/?", 'index.php?post_type=download_items=$matches[1]', 'top');<br />}<br />add_action('init', 'crud_registerDownloadItems');<br />function crud_registerDownloadItems() {<br /> $labels = array(<br /> 'menu_name' => _x('download_items', 'Download Items'),<br /> 'name' => 'Download Items',<br /> 'singular_name' => 'Download Item',<br /> 'add_new' => 'Add New',<br /> 'add_new_item' => 'Add New Download Item',<br /> 'edit_item' => 'Edit Download Item',<br /> 'new_item' => 'New Download Item',<br /> 'all_items' => 'All Download Items',<br /> 'view_item' => 'View Download Item',<br /> 'search_items' => 'Search Download Items',<br /> 'not_found' => 'No Download Items found',<br /> 'not_found_in_trash' => 'No Download Items found in Trash',<br /> 'parent_item_colon' => '',<br /> 'menu_name' => 'Download Items'<br /> );<br /> $args = array(<br /> 'labels' => $labels,<br /> 'hierarchical' => true,<br /> 'description' => 'Slideshows',<br /> 'supports' => array('title', 'editor'),<br /> 'public' => true,<br /> 'show_ui' => true,<br /> 'show_in_menu' => true,<br /> 'show_in_nav_menus' => true,<br /> 'publicly_queryable' => true,<br /> 'exclude_from_search' => false,<br /> 'has_archive' => true,<br /> 'query_var' => true,<br /> 'can_export' => true,<br /> 'rewrite' => array(<br /> 'slug' => 'download_items',<br /> 'with_front' => false,<br /> 'feed' => true,<br /> 'pages' => true<br /> ),<br /> 'capabilities' => array(<br /> // Meta capabilities <br /> 'edit_post' => 'edit_download_item',<br /> 'read_post' => 'read_download_item',<br /> 'delete_post' => 'delete_download_item',<br /> // Primitive capabilities <br /> 'edit_posts' => 'edit_download_items',<br /> 'delete_post' => 'delete_download_items',<br /> 'read_posts' => 'read_download_items',<br /> ),<br /> 'capability_type' => 'post'<br /> );<br /> register_post_type('download_items', $args);<br />}<br /><br />add_action('add_meta_boxes', 'crud_addMetaBoxes');<br />function crud_addMetaBoxes() {<br /> //add_meta_box($id, $title, $callback, $page, $context, $priority);<br /> add_meta_box("crud_custom_fields", "Other Information", 'crud_viewFields', "download_items", "normal");<br />}<br />function crud_viewFields() {<br /> global $post, $wpdb;<br /> $table_name = $wpdb->prefix . "categories";<br /> $checked_status = '';<br /> $download_price = get_post_meta($post->ID, 'download_price');<br /> $crud_category = get_post_meta($post->ID, 'crud_category');<br /> $myrows = $wpdb->get_results( "SELECT category_name, category_Label FROM {$table_name}" );<br /> <br /> $html = '<input name="crud_custom_fields_nonce" type="hidden" value="' . wp_create_nonce(basename(__FILE__)) . '" />';<br /> $html .= '<table class="form-table">';<br /> $html .= "
<tr><br /> <th><label for="Download price">Download price</label></th><br /> <td><input id="crud_download_price" name="crud_download_price" nbsp="" type="text" value="" . $download_price[0] . "" /></td><br /> </tr>
<br />
<tr><br /> <th><label for="Categories">Categories</label></th><br /> <td>";<br /> $html .= '<ul class="checkbox_list checkbox">';<br /> <br /> foreach ($myrows as $key => $value) {<br /> if (stristr($crud_category[0], $value->category_name) == true) {<br /> $checked_status = ' checked="checked" ';<br /> $html .= '
<li><br /> <label><input checked="checked" class="checkbox" id="crud_category" name="crud_category[]" type="checkbox" value="' . $value->category_name . '" />' . $value->category_Label . '</label><br /> </li>
';<br /> } else {<br /> $html .= '
<li><br /> <label><input class="checkbox" id="crud_category" name="crud_category[]" type="checkbox" value="' . $value->category_name . '" />' . $value->category_Label . '</label><br /> </li>
';<br /> }<br /> }<br /><br /> $html .= "</ul>
</td><br /> </tr>
<br /> </table>
";<br /> echo $html;<br />}<br />/* Save Slider Options to database */<br />add_action('save_post', 'crud_saveDownloadInfo');<br />function crud_saveDownloadInfo($post_id) {<br /><br /> // verify nonce<br /> if (!wp_verify_nonce($_POST['crud_custom_fields_nonce'], basename(__FILE__))) {<br /> return $post_id;<br /> }<br /> // check autosave<br /> if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {<br /> return $post_id;<br /> }<br /> // check permissions<br /> if ('download_items' == $_POST['post_type'] && current_user_can('edit_download_items', $post_id)) {<br /> $download_price = (isset($_POST['crud_download_price']) ? $_POST['crud_download_price'] : '');<br /> $categories = (isset($_POST['crud_category']) ? $_POST['crud_category'] : '');<br /> $categories = strip_tags(json_encode($categories));<br /> update_post_meta($post_id, "download_price", $download_price);<br /> update_post_meta($post_id, "crud_category", $categories);<br /> } else {<br /> return $post_id;<br /> }<br />}<br />// Callback function to show fields in meta box<br />add_filter('map_meta_cap', 'crud_downloadItemMetaCap', 10, 4);<br />function crud_downloadItemMetaCap($primitive_caps, $meta_cap, $user_id, $args) {<br /> // If meta-capability is not download_item based do nothing.<br /> if (!in_array($meta_cap, array('edit_download_item', 'delete_download_item', 'read_download_item'))) {<br /> return $primitive_caps;<br /> }<br /> // Check post is of post type.<br /> $post = get_post($args[0]);<br /> $post_type = get_post_type_object($post->post_type);<br /> if ('download_items' != $post_type) {<br /> return $primitive_caps;<br /> }<br /> $primitive_caps = array();<br /> switch ($meta_cap):<br /> case 'edit_download_item':<br /> if ($post->post_author == $user_id) {<br /> // User is post author<br /> if ('publish' == $post->post_status) {<br /> // download_item is published: require 'edit_published_download_items' capability<br /> $primitive_caps[] = $post_type->cap->edit_published_posts;<br /> } elseif ('trash' == $post->post_status) {<br /> if ('publish' == get_post_meta($post->ID, '_wp_trash_meta_status', true)) {<br /> // download_item is a trashed published post require 'edit_published_download_items' capability<br /> $primitive_caps[] = $post_type->cap->edit_published_posts;<br /> }<br /> } else {<br /> $primitive_caps[] = $post_type->cap->edit_posts;<br /> }<br /> } else {<br /> // The user is trying to edit a post belonging to someone else.<br /> $primitive_caps[] = $post_type->cap->edit_others_posts;<br /> // If the post is published or private, extra caps are required.<br /> if ('publish' == $post->post_status) {<br /> $primitive_caps[] = $post_type->cap->edit_published_posts;<br /> } elseif ('private' == $post->post_status) {<br /> $primitive_caps[] = $post_type->cap->edit_private_posts;<br /> }<br /> }<br /> break;<br /> case 'read_download_item':<br /> if ('private' != $post->post_status) {<br /> // If the post is not private, just require read capability<br /> $primitive_caps[] = $post_type->cap->read;<br /> } elseif ($post->post_author == $user_id) {<br /> // Post is private, but current user is author<br /> $primitive_caps[] = $post_type->cap->read;<br /> } else {<br /> // Post is private, and current user is not the author<br /> $primitive_caps[] = $post_type->cap->read_private_post;<br /> }<br /> break;<br /> case 'delete_download_item':<br /> if ($post->post_author == $user_id) {<br /> // Current user is author, require delete_download_items capability<br /> $primitive_caps[] = $post_type->cap->delete_posts;<br /> } else {<br /> // Current user is no the author, require delete_others_download_items capability<br /> $primitive_caps[] = $post_type->cap->delete_others_posts;<br /> }<br /> // If post is published, require delete_published_posts capability too<br /> if ('publish' == $post->post_status) {<br /> $primitive_caps[] = $post_type->cap->delete_published_posts;<br /> }<br /> break;<br /> endswitch;<br /> return $primitive_caps;<br />}<br />function crud_frontendDeleteLink() {<br /> if (!current_user_can('delete_download_items')) {<br /> echo ' ';<br /> return;<br /> }<br /> $url = add_query_arg(<br /> array(<br /> 'action' => 'frontend_delete',<br /> 'post' => get_the_ID()<br /> )<br /> );<br /> echo "<a href="http://draft.blogger.com/%7B$url%7D">Delete</a>";<br />}<br />if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'frontend_delete') {<br /> add_action('init', 'crud_FrontendDeletePost');<br />}<br />function crud_FrontendDeletePost() {<br /> if (!current_user_can('delete_download_items'))<br /> return;<br /> $post_id = (isset($_REQUEST['post']) ? (int) $_REQUEST['post'] : 0);<br /> if (empty($post_id))<br /> return;<br /> wp_trash_post($post_id);<br />}<br />add_shortcode('downloadItem', crud_downloadItemFun);<br />function crud_downloadItemFun() {<br /> set_caps();<br /> global $post ;<br /> $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;<br /> $args = array(<br /> 'posts_per_page' => 10,<br /> 'post_type' => 'download_items',<br /> 'paged' => $paged<br /> );<br /> $newsObj = new WP_Query($args);<br /> if ($newsObj->have_posts()): ?><br /> <table border="1"><br />
<tr style="font-weight: bold;"><br /> <td>Title</td><br /> <td>Categories</td><br /> <td>Price</td><br /> <td>Edit</td><br /> <td>Delete</td><br /> </tr>
<br /> <br /> while ($newsObj->have_posts()): $newsObj->the_post();<br /> $curr_id = get_the_ID();<br /> $meta = get_post_meta( $curr_id,'crud_category' );<br /> $meta = preg_replace('/[^a-zA-Z0-9\,]/', '', $meta);<br /> $download_price = get_post_meta( $curr_id,'download_price' );<br /> ?><br />
<tr><br /> <td><a href="http://draft.blogger.com/%3C?php%20the_permalink();%20?%3E"></a></td><br /> <td>0 ) {echo $meta[0] ;} ?></td><br /> <td>0 ) echo implode(',', $download_price); ?></td><br /> <td><a action="edit" amp="" href="http://draft.blogger.com/%3C?php%20echo%20get_admin_url()." post.php="" post=".$curr_id.">">Edit</a></td><br /> <td></td><br /> </tr>
<br /> endwhile;?><br /> </table>
<br /> endif;<br /> wp_reset_query();<br />}<br />add_action('admin_menu','crud_pluginSetting');<br />function crud_pluginSetting() {<br /> add_menu_page('Crud Plugin Settings', 'Crud Settings', 'administrator', 'crud_settings', 'crud_settingFunction');<br />}<br />if (isset($_REQUEST['category_label']) && (!empty ($_REQUEST['category_label']) || '' != 'frontend_delete')) {<br /> crud_installData($_REQUEST['category_name'], $_REQUEST['category_label']);<br />}<br />function crud_settingFunction() {<br /> $category_label = (get_option('category_label') != '') ? get_option('category_label') : 'category_label100';<br /> $category_name = (get_option('category_name') != '') ? get_option('category_name') : 'category_name100';<br /> $html = '</blockquote>
</div>
</div>
<br /> <div class="wrap">
<form method="post" name="options">
<br /> <h2>
Select Your Settings</h2>
<br /> ' . wp_nonce_field('update-options') . '<br /> <table cellpadding="10" class="form-table" style="width: 100%px;"><br /> <tbody><br />
<tr><br /> <td align="left" scope="row"><br /> <label>Category Label</label><input name="category_label" type="text" value="'.$category_label.'" /><br /> </td><br /> </tr>
<br />
<tr><br /> <td align="left" scope="row"><br /> <label>Category Name</label><input name="category_name" type="text" value="'.$category_name.'" /><br /> </td><br /> </tr>
<br /> </tbody><br /> </table>
<br /> <input name="Submit" type="submit" value="Add" /><br /> </form>
</div>
<br /> <pre>';
echo $html;
}
function crud_createDBTable() {
global $wpdb;
$table_name = $wpdb->prefix . "categories";
$sql = "CREATE TABLE $table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT,
category_name text NOT NULL,
category_label text NOT NULL,
UNIQUE KEY id (id)
);";
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
dbDelta($sql);
}
function crud_dropTable() {
global $wpdb;
$table_name = $wpdb->prefix . "categories";
$sql = "DROP TABLE $table_name";
}
function crud_installData($category_name = "News",$category_Label = "News") {
global $wpdb;
$table_name = $wpdb->prefix . "categories";
//$category_name = "News";
//$category_Label = "News";
$rows_affected = $wpdb->insert( $table_name, array( 'category_name' => $category_name, 'category_Label' => $category_Label) );
}
//Debug Errors if there are any
add_action('activated_plugin','save_error');
function save_error(){
file_put_contents(ABSPATH. 'wp-content/uploads/2013/error_activation.html', ob_get_contents());
}
?></pre>
<div>
<br /></div>
<div>
<br /></div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-50030440324764724972013-05-31T12:22:00.000-07:002013-05-31T12:22:24.042-07:00PHP N-tier: Introduction N-Tier Strategy<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div class="MsoNormal">
<b><span style="font-family: "Times New Roman","serif"; font-size: 24.0pt; mso-fareast-font-family: "Times New Roman"; mso-font-kerning: 18.0pt;">PHP N-tier: Introduction N-Tier Strategy<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">PHP N-Tier Strategy Step By Step
Tutorial - Part 1: May be you face complicated situation in your client's
architecture. They use many technology for solve their complicated business
process. If it happen, n-tier may be possible one solution you can choice. It
this post, we begin to understanding possible N-Tier architecture. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">General principle that we must
consider if wants to build N-tier application:<o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Every layer must be independent physically. It doesn't
mean every layer have to exist in separated computer. But, every layer can
be distributed every where (separated computer or not). <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Each layer must transfer information only to/from
previous/next layer. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">You can change technology used in every layer without
change entire system. Example, - you want to change database layer- from
mySql to PostgreSQL. <o:p></o:p></span></li>
</ul>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Following sample architecture design
use 5-tier:<o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Presentation GUI, do parse HTML, XHTML, WML. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Presentation Logic do rendering process HTML, XHTML to
send using HTTP to browser. It accepts data from business logic and tie to
HTML. This process run at php at web server. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Business Logic, manipulate and transform data. Simple,
task of this layer is fetch data from data access tier and prepare before
send to presentation logic. This process run at server that utilize XML. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Data access tier have task to connect and retrieve data
from database. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Data tier is aplication database such as mySQL,
PostGreSQL, and others. <o:p></o:p></span></li>
</ul>
<h1>
PHP N-tier: Possible n-tier Application Use PHP<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">PHP N-Tier Strategy Step By Step
Tutorial - Part 2: In this post, we will try to design n-tier application use
PHP. This is my 5-tier design: <o:p></o:p></span></div>
<ul type="disc">
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Presentation GUI: Using smarty template to generate
HTML. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Presentation Logic: PHP. <o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Business Logic: Use </span><a href="http://www.phpeveryday.com/articles/Web-Services-How-PHP-Kiss-VB-NET-Part-1--P105.html"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">NuSOAP</span></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">.
<o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Data Access Tier: Using </span><a href="http://www.phpeveryday.com/pack/PHP-ADOdb-Step-By-Step-Tutorial"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">ADOdb</span></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">.
<o:p></o:p></span></li>
<li class="MsoNormal"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Data tier: Using </span><a href="http://www.phpeveryday.com/pack/PHP-MySQL-Basic-Step-By-Step-Tutorial"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">mySQL</span></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">.
<o:p></o:p></span></li>
</ul>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; line-height: 115%; mso-fareast-font-family: "Times New Roman";">We ever
talked about nusoap, adodb, and mysql. If you still understand about them,
please read posts about them. <o:p></o:p></span></div>
<h1>
PHP N-tier: Database Layer Using MySQL<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">PHP N-Tier Strategy Step By Step
Tutorial - Part 3: For practice, we will build simple application to show
5-tier design. We will begin from database layer. At the database layer, we use
MySQL. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Create a database, for example
"test". Then create table. This is the query:<o:p></o:p></span></div>
<blockquote class="tr_bq">
“CREATE TABLE `books` (<br /><span style="font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";">`id`
INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";">`title`
VARCHAR( 255 ) NOT NULL ,</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";">`author`
VARCHAR( 60 ) NOT NULL</span><span style="font-family: "Courier New"; font-size: 10.0pt; mso-fareast-font-family: "Times New Roman";">)
ENGINE = MYISAM ;</span>”</blockquote>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
Next, try to insert sample data, such as:<o:p></o:p></div>
<blockquote class="tr_bq">
“INSERT INTO `test`.`books` (<br />`id` ,<br />`title` ,<br />`author`<br />)<br />VALUES (<br />NULL , 'PHP Undercover', 'Wiwit Siswoutomo'<br />), (<br />NULL , 'PHP Enterprise', 'Wiwit Siswoutomo'<br />);<br />”</blockquote>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
<o:p></o:p></div>
<div class="MsoNormal">
Ok, next post we will try how to connect database use PHP
ADOdb as data access tier.<o:p></o:p></div>
<h1>
PHP N-tier: Data Access Tier Using PHP ADOdb<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">PHP N-Tier Strategy Step By Step
Tutorial - Part 4: In this post, we will build data access tier. We use PHP
Adodb. About PHP Adodb, you can read at </span><a href="http://www.phpeveryday.com/pack/PHP-ADOdb-Step-By-Step-Tutorial"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">here</span></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">For this practice, create a folder
named "ntier" within www/test. Place your all PHP ADOdb folder at
here. Thus, you have www/test/ntier/adodb.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Then create a file named
"dataaccess.php" within www/test/ntier. Enter following code<o:p></o:p></span></div>
<blockquote class="tr_bq">
include('adodb/adodb.inc.php');<br /> <o:p> </o:p>$databasetype = 'mysql';<br />$server = 'localhost';<br />$user = 'root';<br />$password = 'admin';<br />$database = 'test';<br /><o:p> </o:p>$db = ADONewConnection($databasetype);<br /> $db->debug = false;<br /> $db->Connect($server, $user, $password, $database);<br /> <o:p> </o:p>$recordSet = &$db->Execute('select * from books');<br /> <o:p> </o:p>if (!$recordSet)<br /> print $conn->ErrorMsg();<br /> else<br /> while (!$recordSet->EOF) {<br /> print $recordSet->fields[0].' '.$recordSet->fields[1].' '.$recordSet->fields[2].'<br />';<br /> $recordSet->MoveNext(); <br /> } <br /> <o:p> </o:p>$recordSet->Close(); # optional<br /> <br /> $db->Close();<br /><o:p> </o:p>?></blockquote>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Test it. Open your browser. point to
http://localhost/test/ntier/dataacces.php.<o:p></o:p></span></div>
<h1>
PHP N-tier: Building Business Logic<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">PHP N-Tier Strategy Step By Step
Tutorial - Part 5: After create connection to database at </span><a href="http://www.phpeveryday.com/articles/PHP-N-tier-Data-Access-Tier-Using-PHP-ADOdb-P319.html" title="PHP N-tier: Data Access Tier Using PHP ADOdb"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">this
post</span></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">, we will process this data. We
prepare this data in order to can to send using webservices. We named this:
business logic layer. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">This practice only work well for php
4. In php 5, we will talk next serial post. Because there is embedded function
in php 5. First, copy library of nusoap within www/test/ntier/lib. If you don't
understant to place nusoap, please read </span><a href="http://www.phpeveryday.com/articles/Web-Services-How-PHP-Kiss-VB-NET-Part-1--P68.html" title="Web Services: How PHP Kiss VB.NET? (Part 1)"><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">this
post</span></a><span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Open again file dataacces.php within
www/test/ntier. Update like following:<o:p></o:p></span></div>
<blockquote class="tr_bq">
// call library<br />require_once ( './lib/nusoap.php' ); //nusoap<br />require_once ('adodb/adodb.inc.php');//adodb<br /><o:p> </o:p>// create instance<br />$server = new soap_server();<br /><o:p> </o:p>// initialize WSDL support<br />$server->configureWSDL( 'hello' , 'urn:hellowsdl' );<br /><o:p> </o:p>// place schema at namespace with prefix tns<br />$server->wsdl->schemaTargetNamespace = 'urn:hellowsdl';<br /><o:p> </o:p>// register method<br />$server->register('books', // method name<br />array(), // input parameter<br />array('return'=>'xsd:array'),<br />'urn:hellowsdl' , // namespace<br />'urn:hellowsdl#hello', // soapaction<br />'rpc', // style<br />'encoded', // use<br />'Load list of book to the caller' // documentation<br />);<br /> <o:p> </o:p>// configuration database<br />define(__databasetype__,'mysql');<br />define(__server__,'localhost');<br />define(__user__,'root');<br />define(__password__,'admin');<br />define(__database__,'test');<br /><o:p> </o:p><o:p> </o:p>// method<br />function books(){<br /> $db = ADONewConnection(__databasetype__);<br /> $db->debug = false;<br /> $db->Connect(__server__, __user__, __password__, __database__);<br /> <o:p> </o:p> $recordSet = &$db->Execute('select * from books');<br /> <o:p> </o:p> if (!$recordSet){<br /> return new soap_fault('Server','',$conn->ErrorMsg());<br /> } else {<br /> while (!$recordSet->EOF) {<br /> $books[] = array('id'=>$recordSet->fields[0],<br /> 'title'=>$recordSet->fields[1],<br /> 'author'=>$recordSet->fields[2]<br /> );<br /> $recordSet->MoveNext(); <br /> } <br /> <o:p> </o:p> $recordSet->Close(); #optional <br /> $db->Close();<br /> }<br /><br /> // return value to client<br /> $obj = new soapval('return','array',$books);<br /> return $obj->serialize();<br /> <br />}<br /><o:p> </o:p><o:p> </o:p>$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';<br />$server->service($HTTP_RAW_POST_DATA);<br />?></blockquote>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
Then, test it. Open your browser. Point to
http://localhost/test/ntier/dataacces.php. You will get like this:<o:p></o:p></div>
<div class="MsoNormal">
<a href="http://farm4.static.flickr.com/3236/2334152835_ba5d06a9b1.jpg?v=0">http://farm4.static.flickr.com/3236/2334152835_ba5d06a9b1.jpg?v=0</a><o:p></o:p></div>
<h1>
PHP N-tier: Building Presentation Logic<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";"><br />
PHP N-Tier Strategy Step By Step Tutorial - Part 6: After create business
logic, now we try to catch the data. We called this: presentation logic layer.
We still use nusoap to do this job. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Just for practice, we will create
client same folder/location with server function. Create a file named
"client_book.php" within www/test/ntier. Enter following code:<o:p></o:p></span></div>
<blockquote class="tr_bq">
require_once ('lib/nusoap.php');<br /><o:p> </o:p>$client = new soapclient('http://localhost/test/ntier/dataacces.php');<br /><o:p> </o:p>$response = $client->call('books');<br /><o:p> </o:p>if($client->fault)<br />{<br /> echo "FAULT: Code: (".$client->faultcode.")<br />
";<br /> echo "String: ".$client->faultstring;<br />}<br />else<br />{<br /> $r = $response[0];<br /> $count = count($r);<br />?><br /> <table border="1"><br />
<tr><br /> <th>Id</th><br /> <th>Title</th> <br /> <th>Author</th><br /> </tr>
<br /> for($i=0;$i<=$count-1;$i++){<br /> ?><br />
<tr><br /> <td></td><br /> <td></td><br /> <td></td><br /> </tr>
<br /> }<br /> ?><br /> </table>
<br /> }<br />?></blockquote>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
Now, open your browser and point to <a href="http://localhost/test/ntier/client_book.php">http://localhost/test/ntier/client_book.php</a>.<o:p></o:p></div>
<h1>
PHP N-tier: Building Presentation GUI<o:p></o:p></h1>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">PHP N-Tier Strategy Step By Step
Tutorial - Part 7: We have grabbed data from server at presentation logic. And
we tie data to html at previous post. It will give us more flexible if we you
template system. So, we can change any layout without change all. for this job,
we use smarty template. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Exactly, what is smarty template? I
rewrite from their readme: Smarty is a template engine for PHP. Many other
template engines for PHP provide basic variable substitution and dynamic block
functionality. Smarty takes a step further to be a "smart" template
engine, adding features such as configuration files, template functions, and
variable modifiers, and making all of this functionality as easy as possible to
use for both programmers and template designers.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">First, please download smarty
template at smarty.php.net. Extract compressed file to www/test/ntier. You will
get folder named like "smarty-2.6.xx". Rename, for simply, become:
"smarty".<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Then, create folders named
"templates" and "templates_c" within www/test/ntier.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Open again your client_book.php,
rewrite with this code:<o:p></o:p></span></div>
<blockquote class="tr_bq">
// call library<br />require_once ('./lib/nusoap.php');<br />require_once ('./smarty/libs/smarty.class.php');<br /><o:p> </o:p>// retrieve data from server<br />// use webservice by nusoap<br />$client = new soapclient('http://localhost:8048/test/ntier/dataacces.php');<br />$response = $client->call('books');<br /><o:p> </o:p>if($client->fault)<br />{<br /> echo "FAULT: Code: (".$client->faultcode.")<br />
";<br /> echo "String: ".$client->faultstring;<br /> die();<br />}<br />else<br />{<br /> // start using smarty<br /> $smarty = new Smarty;<br /><br /> // assign parameters<br /> $smarty->assign("title","Books Collection");<br /> $smarty->assign("books",$response[0]);<br /><br /> //load template<br /> $smarty->display('template.tpl');<br />}<br />?></blockquote>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Now, you can see. Your code be more
clean. No html tag over there. All html tag will be place at template.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: "Times New Roman","serif"; font-size: 12.0pt; mso-fareast-font-family: "Times New Roman";">Create a file named
"template.tpl" within www/test/ntier/templates. Then enter following
code:<o:p></o:p></span></div>
<blockquote class="tr_bq">
<html><br /><head><br /><title>{$title}</title></head><br /><body><br /> <table border="1"><br />
<tr><br /> <th>Id</th><br /> <th>Title</th> <br /> <th>Author</th><br /> </tr>
<br />{foreach key=key item=item from=$books}<br />
<tr><br /> {foreach key=key item=item from=$item}<br /> <td>{$item}</td><br /> {/foreach}<br /> </tr>
<br />{/foreach}<br /> </table>
</body></html></blockquote>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<pre><o:p></o:p></pre>
<div class="MsoNormal">
Congrat! you have understand how to build 5-tier use php.
You can expand this tutorial as you need.<o:p></o:p></div>
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-77848310461639924762013-05-17T07:10:00.002-07:002013-05-17T07:37:53.297-07:00Regex in PHP<div dir="ltr" style="text-align: left;" trbidi="on">1. 1 Character 1 number and string length<br />
<blockquote class="tr_bq">^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$</blockquote><br />
<ul><li><code>^</code>: anchored to beginning of string</li>
<li><code>\S*</code>: any set of characters</li>
<li><code>(?=\S{8,})</code>: of at least length 8</li>
<li><code>(?=\S*[a-z])</code>: containing at least one lowercase letter</li>
<li><code>(?=\S*[A-Z])</code>: and at least one uppercase letter</li>
<li><code>(?=\S*[\d])</code>: and at least one number</li>
<li><code>$</code>: anchored to the end of the string</li>
</ul>To include special characters, just add <code>(?=\S*[\W])</code>, which is non-word characters<br />
<br />
OR<br />
<br />
<blockquote class="tr_bq"><code><span class="pun">(?=^.{</span><span class="lit">8</span><span class="pun">,}</span><span class="pln">$</span><span class="pun">)((?=.*</span><span class="pln">\d</span><span class="pun">)|(?=.*</span><span class="pln">\W</span><span class="pun">+))(?![.</span><span class="pln">\n</span><span class="pun">])(?=.*[</span><span class="pln">A</span><span class="pun">-</span><span class="pln">Z</span><span class="pun">])(?=.*[</span><span class="pln">a</span><span class="pun">-</span><span class="pln">z</span><span class="pun">]).*</span><span class="pln">$</span></code></blockquote><pre class="lang-php prettyprint prettyprinted"><code><span class="pln"><span class="pln"></span><span class="pun"> *</span><span class="pln"> contain at least </span><span class="pun">(</span><span class="lit">1</span><span class="pun">)</span><span class="pln"> upper </span><span class="kwd">case</span><span class="pln"> letter
</span><span class="pun">*</span><span class="pln"> contain at least </span><span class="pun">(</span><span class="lit">1</span><span class="pun">)</span><span class="pln"> lower </span><span class="kwd">case</span><span class="pln"> letter
</span><span class="pun">*</span><span class="pln"> contain at least </span><span class="pun">(</span><span class="lit">1</span><span class="pun">)</span><span class="pln"> number </span><span class="kwd">or</span><span class="pln"> special character
</span><span class="pun">*</span><span class="pln"> contain at least </span><span class="pun">(</span><span class="lit">8</span><span class="pun">)</span><span class="pln"> characters </span><span class="kwd">in</span><span class="pln"> length</span></span></code></pre><br />
</div><br />
<br />
<strong>References </strong><br />
1. http://www.autohotkey.com/docs/misc/RegEx-QuickRef.htm<br />
2. http://www.regular-expressions.info/index.htmleaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-57435810787719491322013-05-17T06:30:00.003-07:002013-05-17T07:14:19.013-07:00Zend perks<div dir="ltr" style="text-align: left;" trbidi="on">Zend perks<br />
<br />
1. <strong>StringLength Validator in Form</strong><br />
<blockquote><pre>$this->addElement('text', 'password', array(
'label' => 'Password:',
'required' => true,
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(8,20))
)
));
</pre></blockquote>Another way doing the same thing<br />
<blockquote><pre>$this->addElement('textarea', 'comment', array(
'label' => 'Please Comment:',
'required' => true,
'validators' => array(
array('validator' => 'StringLength', 'options' => array(0, 20))
)
));
</pre></blockquote>2. <strong>Regular expression</strong><br />
<br />
To use a regular expression in zend you regex mus b enclosed in (/) like /regex/<br />
<blockquote><pre>$this->addElement('text', 'password', array(
'label' => 'Password:',
'required' => true,
//'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(8,20)),
array('regex', false, array('pattern' => '/^\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])\S*$/'))
)
));
</pre></blockquote><br />
<br />
</div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-4603793264306078262013-05-16T07:04:00.003-07:002013-05-16T07:22:29.275-07:00little things BIG time saving (Some important php Functions)<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<br />
1. <strong>array_filter()</strong> <br />simply remove null/empty values froma an array.<br />
<div> <blockquote class="tr_bq"> $entry = array(<br />
0 => 'foo',<br />
1 => false,<br />
2 => -1,<br />
3 => null,<br />
4 => ''<br />
);<br />
print_r(array_filter($entry));</blockquote> </div> <b>OutPUT</b><br />
<blockquote class="tr_bq"> <pre>Array
(
[0] => foo
[2] => -1
)</pre> </blockquote> <br />
2. <strong>readCSV</strong><br />this function simply takes csv filename(with path) and return an array<br />
<div> <blockquote class="tr_bq"> <pre>function readCSV($csvFile) {
$file_handle = fopen($csvFile, 'r');
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 1024);
}
fclose($file_handle);
return array_filter($line_of_text);
}
</pre> </blockquote> </div></div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-44193754986534935602013-05-07T10:47:00.001-07:002013-05-07T10:47:38.025-07:00Zend Resources<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<ul style="text-align: left;">
<li>Zend Ajax</li>
<ul>
<li>http://blog.jtclark.ca/2010/03/zend-framework-and-ajax/</li>
</ul>
<li>Chained dropdowns </li>
<ul>
<li>http://www.codeassembly.com/Simple-chained-combobox-plugin-for-jQuery/</li>
</ul>
</ul>
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-6734377342841398812013-05-05T12:28:00.002-07:002013-05-05T12:28:59.609-07:00<div dir="ltr" style="text-align: left;" trbidi="on">
On Sunday 5-5-2013=><br />
1.Add the form to the page index.php,<br />
<ul style="text-align: left;">
<li>i have done this by drag and drop form into body of index.php</li>
<li>then drag and drop button from html component.</li>
</ul>
2.Transfer the data to the next php file and named it wishlist.php.<br />
<br />
<ul style="text-align: left;">
<li>use $_GET method for transfering of data from one form to other </li>
</ul>
3.Create a web page wishlist.php<br />
<br />
4.Establish the connection,</div>
Anonymoushttp://www.blogger.com/profile/08029100147460544916noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-80355155065748434642013-05-04T09:50:00.002-07:002013-05-05T12:08:32.676-07:002013 may 05 : starting to learn php<div dir="ltr" style="text-align: left;" trbidi="on">
<b>8:00 PM</b> => I started learning php from a tutorial of netbeans.link of the tutorial is https://netbeans.org/kb/docs/php/wish-list-lesson2.html.<br />
here i learnt the following<br />
<ol style="text-align: left;">
<li>downloaded netbean</li>
<li>downloaded jdk and installed</li>
<li>downloaded wamp and installed</li>
</ol>
<b>9:00 PM => started database connectivity through mysql jdbc in netbeans </b>.<br />
<ol style="text-align: left;">
<li>created table of wishers</li>
<li>created table of wishes</li>
<li>inserted data in tables</li>
<li>created simple form and posted its value on next page</li>
</ol>
<b>ERROR : I had the following errors</b><br />
<br />
CREATE TABLE wishes2(<br />
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,<br />
wisher_id INT NOT NULL,<br />
description CHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,<br />
due_date DATE,<br />
FOREIGN KEY (wisher_id) REFERENCES wishers2(id)<br />
)<b> </b><br />
<ol style="text-align: left;">
<li>Error code 1005, SQL state HY000: Can't create table 'saqi.wishes2' (errno: 150)<br />Line 1, column 1</li>
</ol>
<ul style="text-align: left;">
<li>Solution : error was becuase i did not create the parent table for which i was creating a foreign key and wishers2 table</li>
</ul>
<b>10:00 PM</b> </div>
Anonymoushttp://www.blogger.com/profile/08029100147460544916noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-43110628779079503082013-03-26T04:30:00.002-07:002013-03-26T04:34:02.707-07:00cell padding and cell spacing in HTML<div dir="ltr" style="text-align: left;" trbidi="on">
We can beutify our page by simple cellspacing and cell padding.<br />
just have a look at code and output at the bottom.<br />
<blockquote class="tr_bq">
<html><br />
<head><br />
<title>cell Padding</title><br />
<style><br />
div.pageoverflow {<br />
clear: left;<br />
padding-top: 1px;<br />
width: 350px;<br />
overflow: hidden;<br />
<br />
}<br />
<br />
div.pagecontainer {<br />
background-color: #ececec;<br />
margin: 10px;<br />
padding: 5px;<br />
border: solid 1px #666;<br />
}<br />
p.pagetext {<br />
color: #384654;<br />
float: left;<br />
padding-top: 5px;<br />
padding-right: 5px;<br />
width: 30em;<br />
margin-bottom: 0.5em;<br />
font:Arial, Helvetica, sans-serif;<br />
font-size:12px;<br />
}<br />
<br />
</style><br />
</head><br />
<body><br />
<table width="100%" style="background-color: #FFFFFF;"><br />
<tbody><tr><br />
<td><br />
<table width="100%" cellspacing="2" cellpadding="7"><br />
<tbody><tr style="background-color:#ECECEC"><td><strong>Date</strong></td><td><strong>Count</strong></td></tr><br />
<tr style="background-color:#ECECEC"><td>2013-03-20</td><td>2113812</td></tr><tr style="background-color:#ECECEC"><td>2013-03-25</td><td>1042</td></tr> <br />
<br />
</tbody></table><br />
</td><br />
</tr><br />
</tbody></table><br />
</body></html></blockquote>
<br />
<br />
<blockquote class="tr_bq">
<html><br />
<head><br />
<title>cell Padding</title><br />
<style>
div.pageoverflow {
clear: left;
padding-top: 1px;
width: 350px;
overflow: hidden;
}
div.pagecontainer {
background-color: #ececec;
margin: 10px;
padding: 5px;
border: solid 1px #666;
}
p.pagetext {
color: #384654;
float: left;
padding-top: 5px;
padding-right: 5px;
width: 30em;
margin-bottom: 0.5em;
font:Arial, Helvetica, sans-serif;
font-size:12px;
}
</style><br />
</head><br />
<body><br />
<table style="background-color: white; width: 100%px;"><tbody>
<tr> <td><br />
<table cellpadding="7" cellspacing="2" style="width: 100%px;"><tbody>
<tr style="background-color: #ececec;"><td><strong>Date</strong></td><td><strong>Count</strong></td></tr>
<tr style="background-color: #ececec;"><td>2013-03-20</td><td>2113812</td></tr>
<tr style="background-color: #ececec;"><td>2013-03-25</td><td>1042</td></tr>
</tbody></table>
</td> </tr>
</tbody></table>
</body></html></blockquote>
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-64621501854216033832012-12-12T23:41:00.001-08:002012-12-12T23:41:17.039-08:00Simple Jquery Ajax and getjson call<div dir="ltr" style="text-align: left;" trbidi="on">
get some Json Data through a remote API<br />
<blockquote class="tr_bq">
$(document).ready(function(){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$.ajax({<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>type: "GET",<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>url: 'http://ecarobar.com/xyz/api.php',<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>data: { method: "get", name: "jab", format: "json" },<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>async: false,<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>dataType: "json",<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>beforeSend: function(x) {alert('Not Yet Sent')},<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>success: function(data){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alert ("AjAx Call"+data.responseBody.id+" "+data.responseBody.views); //further debug<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$('#showdata').html("<p>item1="+data.responseBody.id+" item2="+data.responseBody.views+" </p>");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>});</blockquote>
<br />
<blockquote class="tr_bq">
<span class="Apple-tab-span" style="white-space: pre;"> </span>$.getJSON(<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>"http://ecarobar.com/xyz/api.php",<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{method: "get", name: "jab", format: "json" },<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>function(data) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//alert("JSON Data: " + json.users[3].name);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>alert ("JSON Call"+data.responseBody.id+" "+data.responseBody.views); //further debug<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$('#showdata').html("<p>item1="+data.responseBody.id+" item2="+data.responseBody.views+" </p>");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>});<br />
});</blockquote>
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-69821220399196361492012-11-27T04:20:00.000-08:002012-11-27T04:20:04.397-08:00Compare two files using linux comm command<div dir="ltr" style="text-align: left;" trbidi="on">
Comm Command: (to use this command file must b first sorted like cat file|sort > file1)<br />
<blockquote class="tr_bq">
for Common : comm -1 -2 file1 file2</blockquote>
<table border="1" style="width: 435px;"> <tbody>
<tr>
<td width="65">Ignore</td>
<td width="354"></td>
</tr>
<tr>
<td>-1</td>
<td>Ignore File1</td>
</tr>
<tr>
<td>-2</td>
<td>Ignore File1</td>
</tr>
<tr>
<td>-3</td>
<td>Ignore common data</td>
</tr>
</tbody></table>
<strong>Example:</strong><br />
File1<br />
1<br />
2<br />
3<br />
4<br />
5<br />
<br />
File2<br />
3<br />
4<br />
5<br />
6<br />
7<br />
<br />
<br />
<blockquote class="tr_bq">
comm -1 -2 file1 file2 => 3,4,5</blockquote>
<br />
<br />
<blockquote class="tr_bq">
comm -1 -3 file1 file2 => 6,7</blockquote>
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-28899812169603174932012-11-02T04:46:00.000-07:002012-11-02T04:46:38.451-07:00pregmatch for shell script<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<blockquote class="tr_bq">
* matches any string of zero or more characters<br />? matches any single character<br />[ ] matches any single character within the set<br />[! ] matches any single character not in the set</blockquote>
<br />
<br />
These can be combined together to form more advanced patterns:<br />
[Yy]* Matches any string starting with an upper or lower case y.<br />
<br />
Use quotes or escape/back-slash the special characters if you wish to pattern match them specifically.<br />
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-70557931983480553822012-10-22T05:30:00.000-07:002012-10-22T05:31:45.870-07:00memcached using php and perl<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Memcached is an in-memory key-value store for small chunks of arbitrary data (strings, objects) from results of database calls, API calls, or page rendering.<br />
The system uses a client–server architecture. The servers maintain a key–value associative array; the clients populate this array and query it. Keys are up to 250 bytes long and values can be at most 1 megabyte in size.<br />
Clients use client side libraries to contact the servers which, by default, expose their service at port 11211. Each client knows all servers; the servers do not communicate with each other. If a client wishes to set or read the value corresponding to a certain key, the client's library first computes a hash of the key to determine the server that will be used. Then it contacts that server. The server will compute a second hash of the key to determine where to store or read the corresponding value.<br />
Perl script for fetching a Memcached result.<br />
<br />
<br />
<blockquote>
use Cache::Memcached;<br />
use Digest::MD5;<br />
use Digest::MD5 qw(md5 md5_hex md5_base64);<br />
my $memcli = new Cache::Memcached {<br />
'servers' => [ "192.168.0.27:11211" ],<br />
'debug' => 0<br />
};<br />
my $serviceID=$ARGV[0];<br />
print "Service ID__".$serviceID." **_\n";<br />
my $perlKey='perl_'.$serviceID;<br />
my $result = $memcli->get($perlKey);<br />
#print "already : ___".$result."________\n";<br />
if($result eq "")<br />
{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>#hit a php page to set memcache values if this key does not exist.<br />
use LWP::UserAgent;<br />
#my $serviceID = 12;<br />
my $url= "http://192.168.0.27/chargerequest/perlcache.php";<br />
my $ua = LWP::UserAgent->new();<br />
my $response = $ua->post( $url, { 'id' => $serviceID } );<br />
my $content = $response->decoded_content();<br />
$result = $memcli->get($perlKey);<br />
}<br />
else {<br />
print "\n cached result \n ".$result;<br />
}</blockquote>
<br />
<br />
Now the php page<br />
<div>
<br /></div>
<div>
<blockquote class="tr_bq">
include("db.php");<br />
$dbOBJ = new DB();<br />
$conn = $dbOBJ->connectDB();<br />
if ($conn){<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$serviceid=$_REQUEST['id'];<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$qry='select id, abc, def, ghi, jkl, mno, pqr from table where id='.$id;<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>$memcache = new Memcache;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$memcache->connect('localhost', 11211) or die ("Could not connect");<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$perlKey='perl_'.$serviceid;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$cache_result = array();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>//$memcache->set($perlKey, $perlString, 0, 1);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$cache_result = $memcache->get($perlKey); // Memcached object<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if($cache_result)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// Second User Request<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo "<br />
caching<br />
";<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$dbOBJ->print_rr($cache_result);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$demos_result=$cache_result;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$curser = OCIParse($conn,$qry);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OCIExecute($curser);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>OCIFetchInto($curser , $values);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$demos_result[]=$values; // Results storing in array<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>$memcache->set($key, $demos_result, 0, 100);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$val1=$demos_result[0][0]; <br />
$val2=$demos_result[0][1];<br />
$val3=$demos_result[0][2]; <br />
$val4=$demos_result[0][3]; <br />
$val5=$demos_result[0][4]; <br />
$val6=$demos_result[0][5];<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$perlString = $val1.','. $val2.','. $val3.','. $val4.','. $val5.','. $val6;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>$memcache->set($perlKey, $perlString, 0, 10);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>echo $errorMessage='Other error';<br />
?></blockquote>
</div>
<div>
<br /></div>
<br />
<br />
<br /></div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-1798464889889396402012-10-04T01:07:00.001-07:002012-10-04T01:12:49.960-07:00Fetch files from remote server automatically in PHP using Curl<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="background-color: white; color: #111111; font-family: Georgia, serif; font-size: 14px; line-height: 21.75px;">PHP provides multiple ways to download and upload files to remote servers, such as fopen, fsockopen, cURL library, and other methods. fopen is the simplest but not the best. A while ago I wrote a function to fetch remote file by using fsockopen. However, I found a lot of problems when I use it. Then I read the PHP Cookbook and decided to try cURL library. After I implemented it in the independent class, it works like a charm. The following is the class source code.</span><br />
<span style="background-color: white; color: #111111; font-family: Georgia, serif; font-size: 14px; line-height: 21.75px;"><br />
</span> <br />
<pre style="background-color: #ecf0d9; border: 1px solid rgb(192, 195, 172); color: #223333; font-family: 'courier new'; font-size: 14px; margin: 10px 10px 20px; overflow: auto; padding: 10px;">// I adopt cURL library to download files
// It is reliable and fast, less hassle than fopen/fsockopen etc.
// this following three lines include testing code
// $file = new Remotefile("http://downloads.pcworld.com/pub/new/patches___drivers/utilities/framxpro.zip");
// $file->save2file("");
class Remotefile
{
// the url components
private $url = "";
// data get back from server
private $header = array();
private $content = "";
private $extension = "";
function __construct($url)
{
$this->initialize($url);
}
private function curl_url()
{
$c = curl_init($this->url);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($c, CURLOPT_HEADER, 1);
$buffer = curl_exec($c);
curl_close($c);
// process data
$rnrn = "\r\n\r\n";
$pos = strpos($buffer,$rnrn);
if($pos === false)
{
// string $rnrn NOT found in $buffer
echo "Something is not correct!
";
}
else
{
// string $rnrn found in $buffer
$this->content = substr($buffer, $pos+4);
$header = substr($buffer, 0, $pos);
$this->processHeader($header);
}
}
private function initialize($url)
{
// initialize all variables
$this->url = $url;
// fetch the remote file
$this->curl_url();
}
private function processHeader($header)
{
$lines = explode("\r\n", $header);
$this->header["status"] = $lines[0];
foreach($lines as $line)
{
$data = explode(": ",$line);
if ($data[1] != "")
{
$this->header[$data[0]] = $data[1];
}
//echo "$data[0] |===| $data[1]
";
}
}
private function redirectedURL()
{
return $this->header["Location"];
}
private function getMIMEtype()
{
// check redirection url
$rdurl = $this->redirectedURL();
if ($rdurl)
{
$ext = ereg_replace("^.+\\.([^.]+)$", "\\1", $rdurl);
$this->extension = $ext;
}
else
{
$mtype = $this->header["Content-Type"];
$temps1 = split("/",$mtype);
$temps2 = split(";",$temps1[1]);
$ext1 = $temps2[0];
$this->extension = $ext1;
if (($temps1[0] == "application"))
{
$ext2 = ereg_replace("^.+\\.([^.]+)$", "\\1", $this->url);
if ($ext2)
{
$this->extension = $ext2;
}
}
}
$this->extension = trim($this->extension);
//echo "file extension = ".$this->extension."
";
}
function getHeader()
{
return $this->header;
}
function getContent()
{
return $this->content;
}
function save2file($folder)
{
// write to file
$this->getMIMEtype();
$filename = date('YmdHis').".".$this->extension;
$target_path = getcwd();
if ($folder)
{
$target_path .= "/$folder";
}
$target_path .= "/".$filename;
$Handle = fopen($target_path, 'w');
fwrite($Handle, $this->content);
fclose($Handle);
return $filename;
}
}
?></pre>
<pre style="background-color: #ecf0d9; border: 1px solid rgb(192, 195, 172); color: #223333; font-family: 'courier new'; font-size: 14px; margin: 10px 10px 20px; overflow: auto; padding: 10px;"><div style="color: #111111; font-family: Georgia, serif; line-height: 21.75px; margin-bottom: 20px; margin-top: 10px; padding: 0px; white-space: normal;">
I adopt cURL library to download files. It is reliable and fast, less hassle than fopen/fsockopen etc. To use the above class, at Ubuntu yot have to install libcurl and php5-curl by the following command:</div>
<div style="color: #111111; font-family: Georgia, serif; line-height: 21.75px; margin-bottom: 20px; margin-top: 10px; padding: 0px; white-space: normal;">
<code style="font-family: 'courier new'; font-size: 1em; line-height: normal;">apt-get install curl libcurl3 libcurl3-dev php5-curl</code></div>
<div style="color: #111111; font-family: Georgia, serif; line-height: 21.75px; margin-bottom: 20px; margin-top: 10px; padding: 0px; white-space: normal;">
After this is done, just restart apache2 server by</div>
<div style="color: #111111; font-family: Georgia, serif; line-height: 21.75px; margin-bottom: 20px; margin-top: 10px; padding: 0px; white-space: normal;">
<code style="font-family: 'courier new'; font-size: 1em; line-height: normal;">/etc/init.d/apache2 restart</code></div>
</pre>
</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-89194843584907211372012-09-07T04:54:00.000-07:002012-09-07T04:56:52.334-07:00Simple XML parsing<div dir="ltr" style="text-align: left;" trbidi="on">
<b><u>Xml File</u></b><br />
"<br />
<pre id="line1"><span id="line2"></span><<span class="start-tag">methodResponse</span>>
<span id="line3"></span><<span class="start-tag">params</span>>
<span id="line4"></span><<span class="start-tag">param</span>>
<span id="line5"></span><<span class="start-tag">value</span>>
<span id="line6"></span><<span class="start-tag">struct</span>>
<span id="line7"></span><<span class="start-tag">member</span>>
<span id="line8"></span><<span class="start-tag">name</span>>originTransactionID</<span class="end-tag">name</span>>
<span id="line9"></span><<span class="start-tag">value</span>><<span class="start-tag">string</span>>102511650088881951</<span class="end-tag">string</span>></<span class="end-tag">value</span>>
<span id="line10"></span></<span class="end-tag">member</span>>
<span id="line11"></span><<span class="start-tag">member</span>>
<span id="line12"></span><<span class="start-tag">name</span>>responseCode</<span class="end-tag">name</span>>
<span id="line13"></span><<span class="start-tag">value</span>><<span class="start-tag">i4</span>>100</<span class="end-tag">i4</span>></<span class="end-tag">value</span>>
<span id="line14"></span></<span class="end-tag">member</span>>
<span id="line15"></span></<span class="end-tag">struct</span>>
<span id="line16"></span></<span class="end-tag">value</span>>
<span id="line17"></span><span class="error" title="Stray end tag “param”."></<span class="end-tag">param</span>></span>
<span id="line18"></span></<span class="end-tag">params</span>>
</pre>
</<span class="end-tag">methodResponse</span>>"<br />
<br />
<b><u>PHP :</u></b><br />
"<span class="Apple-tab-span" style="white-space: pre;"> </span>$xml = new SimpleXMLElement($xml);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$items = $xml->xpath('/methodResponse/fault/value/struct/member/name');<br />
$firstArr=$this->objectsIntoArray($items[0]);//convert XML Object to Php Array<br />
<br />
<br />
function objectsIntoArray($arrObjData, $arrSkipIndices = array())<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>{<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$arrData = array();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>// if input is object, convert into array<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (is_object($arrObjData)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$arrObjData = get_object_vars($arrObjData);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (is_array($arrObjData)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>foreach ($arrObjData as $index => $value) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (is_object($value) || is_array($value)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$value = objectsIntoArray($value, $arrSkipIndices); // recursive call<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if (in_array($index, $arrSkipIndices)) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>continue;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>$arrData[$index] = $value;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>return $arrData;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
"</div>
eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-12100367916379336302012-07-09T22:14:00.000-07:002012-07-09T22:31:23.430-07:00Auto highlight text inside pre tags using jQuery<div dir="ltr" style="text-align: left;" trbidi="on">We use pre tags to display the embed codes and short URLs. We use pre tags because it formats the text inside the tags as we insert it, which is ideal for displaying code in particular. The thing is, people like to copy this code and they have to go to the awful bother of selecting all the text manually if they wish to copy the code or URL.<br />
<br />
jQuery hack to auto select all the text inside the pre tags. The only complication with this appears to be a cross platform solution as each browser appears to have their own way of selecting text.<br />
<br />
<div style="border: 0px; color: #373737; font-family: museo-sans-1, Arial, sans-serif; font-size: 15px; line-height: 24px; margin-bottom: 1.625em; outline: 0px; padding: 0px; text-align: -webkit-auto; vertical-align: baseline;"><strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Internet Explorer</strong> uses <a href="http://msdn.microsoft.com/en-us/library/ms536401%28VS.85%29.aspx" style="border: 0px; color: #1982d1; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank">createTextRange</a>.<br />
<strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Opera</strong> and <strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Firefox</strong> use <a href="http://www.wrox.com/WileyCDA/Section/JavaScript-DOM-Ranges.id-292301.html" style="border: 0px; color: #1982d1; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank">createRange</a>.<br />
<strong style="border: 0px; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; vertical-align: baseline;">Safari</strong> uses <a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/WebKitDOMRef/DOMSelection_idl/Classes/DOMSelection/index.html" style="border: 0px; color: #1982d1; font-family: inherit; font-style: inherit; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;" target="_blank">DOMSelection</a>.</div><div style="border: 0px; color: #373737; font-family: museo-sans-1, Arial, sans-serif; font-size: 15px; line-height: 24px; margin-bottom: 1.625em; outline: 0px; padding: 0px; text-align: -webkit-auto; vertical-align: baseline;">So with a pre tag like (just click anywhere in the code)…</div><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript">
</script><br />
<script>
jQuery( document ).ready(function() {
jQuery( 'pre.code' ).click( function() {
var refNode = $( this )[0];
if ( $.browser.msie ) {
var range = document.body.createTextRange();
range.moveToElementText( refNode );
range.select();
} else if ( $.browser.mozilla || $.browser.opera ) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents( refNode );
selection.removeAllRanges();
selection.addRange( range );
} else if ( $.browser.safari ) {
var selection = window.getSelection();
selection.setBaseAndExtent( refNode, 0, refNode, 1 );
}
} );
} );
</script><br />
<pre class="code">jQuery( document ).ready(function() {
jQuery( 'pre.code' ).click( function() {
var refNode = $( this )[0];
if ( $.browser.msie ) {
var range = document.body.createTextRange();
range.moveToElementText( refNode );
range.select();
} else if ( $.browser.mozilla || $.browser.opera ) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents( refNode );
selection.removeAllRanges();
selection.addRange( range );
} else if ( $.browser.safari ) {
var selection = window.getSelection();
selection.setBaseAndExtent( refNode, 0, refNode, 1 );
}
} );
} );
</pre><br />
<div dir="ltr" style="text-align: left;" trbidi="on"><br />
<b>here goes the code :</b><br />
<blockquote><br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>Untitled Document</title><br />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script><br />
<script><br />
jQuery( document ).ready(function() {<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>jQuery( 'pre.code' ).click( function() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var refNode = $( this )[0];<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if ( $.browser.msie ) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var range = document.body.createTextRange();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>range.moveToElementText( refNode );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>range.select();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else if ( $.browser.mozilla || $.browser.opera ) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var selection = window.getSelection();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var range = document.createRange();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>range.selectNodeContents( refNode );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>selection.removeAllRanges();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>selection.addRange( range );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else if ( $.browser.safari ) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var selection = window.getSelection();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>selection.setBaseAndExtent( refNode, 0, refNode, 1 );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} );<br />
</script><br />
</head><br />
<body><br />
<pre class='code'>jQuery( document ).ready(function() {<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>jQuery( 'pre.code' ).click( function() {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var refNode = $( this )[0];<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>if ( $.browser.msie ) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var range = document.body.createTextRange();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>range.moveToElementText( refNode );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>range.select();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else if ( $.browser.mozilla || $.browser.opera ) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var selection = window.getSelection();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var range = document.createRange();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>range.selectNodeContents( refNode );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>selection.removeAllRanges();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>selection.addRange( range );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} else if ( $.browser.safari ) {<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>var selection = window.getSelection();<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>selection.setBaseAndExtent( refNode, 0, refNode, 1 );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>}<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} );<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>} );<br />
</pre><br />
</body><br />
</html></blockquote><br />
</div></div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-76953985449052144642012-07-04T00:53:00.000-07:002012-07-04T00:59:56.656-07:00post a file using PHP to remote server without ftp<div dir="ltr" style="text-align: left;" trbidi="on"><br />
Recently I was working for a product where i have to post a file to a remote server where remote server dont allow outbout FTP.<br />
And in this process i found a couple of methods to post file to server;<br />
<br />
my required file was in Xml and have to post that xml to remote server where I can fetch that data<br />
Its quite simple and easy method.<br />
<br />
here are my findings<br />
<br />
local file name : postfile.php<br />
remote file name : receivexml.php<br />
<div><br />
</div><div>code for <span style="">postfile.php</span></div><div><span style=""><br />
</span></div><div><span style=""></span><br />
<blockquote class="tr_bq"><span style=""><span style="">$thistext="</span></span><span style=""><?xml version="1.0"?></span><br />
<SERVICES><br />
<serv1234><br />
<short>1234</short><br />
<isuser>0</isuser><br />
<keyword>keyword</keyword><br />
<table>wltable</table><br />
<expiry><br />
<expiry_status>1</expiry_status><br />
<expiry_startdate>04-JUL-12</expiry_startdate><br />
<expiry_enddate>27-JUL-12</expiry_enddate><br />
<expiry_message>Expiry Message</expiry_message><br />
</expiry><br />
<br />
</serv1234><br />
<span style=""><span style=""> </SERVICES></span>";</span></blockquote><span style=""> </span><br />
<div><span style=""><br />
</span></div><span style=""> </span></div><div><br />
<blockquote class="tr_bq"><span ><span class="Apple-tab-span" style="white-space: pre;"> </span>$ch = curl_init('http://rem.ote.server.ip/receivexml.php');</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>curl_setopt($ch, CURLOPT_POSTFIELDS, $thistext);</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>curl_setopt($ch, CURLOPT_HTTPHEADER, array(</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>'Content-Type: application/xml',</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>'Content-Length: ' . strlen($thistext))<span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>); </span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span><span class="Apple-tab-span" style="white-space: pre;"> </span>$result = curl_exec($ch);</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>print_r($result);</span><br />
<span ><span class="Apple-tab-span" style="white-space: pre;"> </span>curl_close($ch);</span></blockquote><span > </span><br />
<div><span >code for receivexml.php</span></div><span ><br />
<div><br />
<blockquote><span >echo "test xml";</span><br />
<span >if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){</span><br />
<span > $postText = file_get_contents('php://input');</span><br />
<span >}</span><br />
<span >//print_r($postText);</span><br />
<span >$shortcode='';</span><br />
<span >$xml = new SimpleXMLElement($postText);</span><br />
<span >$result = $xml->xpath('/SERVICES/ serv1234/short');</span><br />
<span >while(list( , $node) = each($result)) {</span><br />
<span > echo $short=$node;</span><br />
<span >}</span><br />
<span >$myFile = "/directory/path/to/xml/".$short.".xml";</span><br />
<span >$fh = fopen($myFile, 'w') or die("can't open file");</span><br />
<span >$stringData=$postText;</span><br />
<span >fwrite($fh, $stringData);</span><br />
<span >fclose($fh);</span><br />
<span >?></span></blockquote><span > </span><br />
<div><span >in receivexml.php</span></div><span > <div><ol style="text-align: left;"><li><span >received the file and stored in </span> $postText</li>
<li>parsed the xml data with xpath</li>
<li>set the file name to a tag value in this case "short"</li>
<li>write data to file.</li>
</ol></div><div><br />
</div><div><br />
</div></span></div></span></div></div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com3tag:blogger.com,1999:blog-1354181122094925216.post-78909299770120030132012-06-27T03:13:00.001-07:002012-06-27T03:13:51.003-07:00how to get the return code of a command<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<b>how to get the return code of a command??</b><br />
<br />
you can get the retun code of a command using $? operator.Make sure to save the returncode in a variable just after the command completed.otherwise this will hold the code of the next command executed after your desired.<br />
have a look<br />
<blockquote class="tr_bq">
ncftpput -u user-name -p P@sswORD 192.168.168.9 / $filename<br />
RET=$?<br />
echo $RET</blockquote>
<br />
<div>
<br /></div>
</div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-36872434508298741772012-06-21T02:59:00.001-07:002012-06-21T02:59:14.446-07:00Linux BASH - Comparison Operators<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<h3 style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 12pt;">
Linux BASH - Comparison Operators</h3>
<span style="background-color: #fff3ab; font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;"> </span><b style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;">Integer Comparison Operators</b><br style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;" /><table style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; margin: 0px auto; text-align: left; z-index: 10;"><tbody>
<tr bgcolor="ffcc00" style="font-size: 10pt;"><td style="font-size: 10pt;" width="75"><b>Operator</b></td><td style="font-size: 10pt;" width="250"><b>Description</b></td><td style="font-size: 10pt;" width="400"><b>Example</b></td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">-eq</td><td style="font-size: 10pt;">Is Equal To</td><td style="font-size: 10pt;">if [ $1 -eq 200 ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">-ne</td><td style="font-size: 10pt;">Is Not Equal To</td><td style="font-size: 10pt;">if [ $1 -ne 1 ]</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">-gt</td><td style="font-size: 10pt;">Is Greater Than</td><td style="font-size: 10pt;">if [ $1 -gt 15 ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">-ge</td><td style="font-size: 10pt;">Is Greater Than Or Equal To</td><td style="font-size: 10pt;">if [ $1 -ge 10 ]</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">-lt</td><td style="font-size: 10pt;">Is Less Than</td><td style="font-size: 10pt;">if [ $1 -lt 5 ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">-le</td><td style="font-size: 10pt;">Is Less Than Or Equal To</td><td style="font-size: 10pt;">if [ $1 -le 0 ]</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">==</td><td style="font-size: 10pt;">Is Equal To</td><td style="font-size: 10pt;">if (( $1 == $2 )) [Note: Used within double parentheses]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">!=</td><td style="font-size: 10pt;">Is Not Equal To</td><td style="font-size: 10pt;">if (( $1 != $2 ))</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;"><</td><td style="font-size: 10pt;">Is Less Than</td><td style="font-size: 10pt;">if (( $1 < $2 ))</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;"><=</td><td style="font-size: 10pt;">Is Less Than Or Equal To</td><td style="font-size: 10pt;">if (( $1 <= $2 ))</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">></td><td style="font-size: 10pt;">Is Greater Than</td><td style="font-size: 10pt;">if (( $1 > $2 ))</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">>=</td><td style="font-size: 10pt;">Is Greater Than Or Equal To</td><td style="font-size: 10pt;">if (( $1 >= $2 ))</td></tr>
</tbody></table>
<br style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;" /><span style="background-color: #fff3ab; font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;"> </span><b style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;">String Comparison Operators</b><br style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; font-size: 13px;" /><table style="font-family: Verdana, Arial, Helvetica, 'Sans Serif'; margin: 0px auto; text-align: left; z-index: 10;"><tbody>
<tr bgcolor="ffcc00" style="font-size: 10pt;"><td style="font-size: 10pt;" width="75"><b>Operator</b></td><td style="font-size: 10pt;" width="250"><b>Description</b></td><td style="font-size: 10pt;" width="400"><b>Example</b></td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">= or ==</td><td style="font-size: 10pt;">Is Equal To</td><td style="font-size: 10pt;">if [ "$1" == "$2" ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">!=</td><td style="font-size: 10pt;">Is Not Equal To</td><td style="font-size: 10pt;">if [ "$1" != "$2" ]</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">></td><td style="font-size: 10pt;">Is Greater Than (ASCII comparison)</td><td style="font-size: 10pt;">if [ "$1" > "$2" ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">>=</td><td style="font-size: 10pt;">Is Greater Than Or Equal To</td><td style="font-size: 10pt;">if [ "$1" >= "$2" ]</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;"><</td><td style="font-size: 10pt;">Is Less Than</td><td style="font-size: 10pt;">if [ "$1" < "$2" ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;"><=</td><td style="font-size: 10pt;">Is Less Than Or Equal To</td><td style="font-size: 10pt;">if [ "$1" <= "$2" ]</td></tr>
<tr bgcolor="ccff99" style="font-size: 10pt;"><td style="font-size: 10pt;">-n</td><td style="font-size: 10pt;">Is Not Null</td><td style="font-size: 10pt;">if [ -n "$1" ]</td></tr>
<tr bgcolor="ffff66" style="font-size: 10pt;"><td style="font-size: 10pt;">-z</td><td style="font-size: 10pt;">Is Null (Zero Length String)</td><td style="font-size: 10pt;">if [ -z "$1"]</td></tr>
</tbody></table>
<br class="Apple-interchange-newline" /></div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0tag:blogger.com,1999:blog-1354181122094925216.post-5283816410033122822012-06-14T02:15:00.000-07:002012-06-15T03:30:57.214-07:00Shell Script for updating an Oracle table through a file (from a remote Server)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
a simple Script for updating an Oracle table through a file (from a remote Server)<br />
we will b using a shell script for all this<br />
process is described step by step as<br />
<blockquote class="tr_bq">
1. first Of all create a virtual directory and external table use this page <a hre="http://eaziweb.blogspot.com/2012/03/oracle-create-external-table.html" href="http://draft.blogger.com/blogger.g?blogID=1354181122094925216">http://eaziweb.blogspot.com/2012/03/oracle-create-external-table.html</a><br />
2. get file from remote server using ncftpget<br />
3. create Oracle Procedure for data insertions<br />
4. Oracle Procedure uses UTL_FILE utility for logging different file events like success and failure</blockquote>
<br />
<b><u>Summary</u></b><br />
<blockquote class="tr_bq">
Serrver<span class="Apple-tab-span" style="white-space: pre;"> </span>: server IP like 192.168.168.0<br />
directory Object Name<span class="Apple-tab-span" style="white-space: pre;"> </span>: DIR_3352<br />
directory Object Path<span class="Apple-tab-span" style="white-space: pre;"> </span>: /home/xyz/3352<br />
External File<span class="Apple-tab-span" style="white-space: pre;"> </span>: xtern_3352.txt<br />
Upload File Name Format<span class="Apple-tab-span" style="white-space: pre;"> </span>: add_20120612.csv<br />
Upload File Format<span class="Apple-tab-span" style="white-space: pre;"> </span>: 03007236317,09-MAR-12,C2676M0749<br />
External Table<span class="Apple-tab-span" style="white-space: pre;"> </span>:<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>create table xtern_3352 ( mobile varchar2(100),dateCol varchar2(20),id varchar2(20))<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>organization external (<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>type oracle_loader<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>default directory DIR_3352<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>access parameters (<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>records delimited by newline<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>FIELDS TERMINATED BY ','<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>location ('xtern_3352.txt')<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>)<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>reject limit unlimited;<br />
Procedure<span class="Apple-tab-span" style="white-space: pre;"> </span>: TEST_PARAMETER</blockquote>
<br />
<br />
<b><u>Shell Script :</u></b><br />
<blockquote class="tr_bq">
######################################################################<br />
## USAGE ##<br />
## call it as 3355.sh action-parameter ##<br />
## eg. source 3355.sh add ##<br />
## current action parameters are ##<br />
## 1.add ##<br />
## 2.delete ##<br />
######################################################################<br />
#!/bin/sh<br />
action=$1<br />
day=1<br />
date_var=`date -d "-$day days" +%Y-%m-%d`<br />
#backup old files<br />
mv -f /home/xyz/3352/xtern_3352.txt /home/xyz/3352/xtern_3352_`echo $date_var`.txt<br />
#get the file from remote Server and put in /path/to/local/dir/ directory<br />
ncftpget -u ftp-user-name -p paSSword rem.ote.Ser.ver.IP /path/to/local/dir/ /file`echo $date_var`_sub.csv<br />
mv -f /home/xyz/file`echo $date_var`_sub.csv /home/xyz/new.txt<br />
cat /home/xyz/new.txt | cut -d ' ' -f1> /home/xyz/xtern_3352.txt<br />
source /file_validation_script.sh 3352/xtern_3352.txt<br />
ORACLE_HOME=/Oracle/app/oracle/product/11.2.0/dbhome_1<br />
export ORACLE_HOME<br />
ORACLE_SID=orcl<br />
export ORACLE_SID<br />
/Oracle/app/oracle/product/11.2.0/dbhome_1/bin/sqlplus /NOLOG << EOF<br />
<br />
connect db_user/db_pwd<br />
set serveroutput on<br />
exec TEST_PARAMETER('`echo $action`');<br />
EXIT;<br />
echo "Now making file"<br />
EOF</blockquote>
<br />
<b>Oracle Procedure : TEST_PARAMETER</b><br />
<br />
<blockquote>
( action IN varchar2 )<br />
AS CURSOR C_CONTENT IS SELECT * from xtern_3352 ;<br />
--============================================================<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>--<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>Initialization<span class="Apple-tab-span" style="white-space: pre;"> </span>--<br />
--===========================================================--<br />
datecheck number;<br />
v_message varchar2(100);<br />
ERROR_mobile_FORMAT exception;<br />
ERROR_mobile_VALUE exception;<br />
ERROR_DATE_VALUE exception;<br />
ERROR_DUPLICATE_mobile exception;<br />
ERROR_NO_mobile_FOUND exception;<br />
v_file UTL_FILE.FILE_TYPE;<br />
s_file UTL_FILE.FILE_TYPE;<br />
cur_date varchar2(100);<br />
file_Name varchar2(100);<br />
success_File_Name varchar2(100);<br />
var_query varchar2(100);<br />
--=============================================================--<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>--<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>
<span style="white-space: pre;"> </span> Start of Logic<span class="Apple-tab-span" style="white-space: pre;"> </span>--<span style="white-space: pre;"> </span>-- <span class="Apple-tab-span" style="white-space: pre;"> </span>--<br />
--=============================================================--<br />
BEGIN<br />
<br />
-------------------------------------------------------------------------------------------<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span> File details <span class="Apple-tab-span" style="white-space: pre;"> </span> --<br />
-------------------------------------------------------------------------------------------<br />
SELECT to_char(sysdate, 'DDMonYYYY_HH24MISS') into cur_date from dual;<br />
file_Name := '' ;<br />
success_File_Name := '' ;<br />
if ( action = 'add') then<br />
dbms_output.put_line('add Action');<br />
file_Name := 'add_error_'||cur_date||'.txt' ;<br />
success_File_Name := 'add_success_'||cur_date||'.txt' ;<br />
--var_query := 'insert into WHITE_LIST_auto values('||wl_DATA.mobile||','||wl_DATA.dateCol||','||wl_DATA.ID||')' ;<br />
var_query := 'insert into WHITE_LIST_auto values(wl_DATA.mobile,wl_DATA.dateCol,wl_DATA.ID)' ;<br />
else if ( action = 'delete') then<br />
dbms_output.put_line('delete Action');<br />
file_Name := 'delete_error_'||cur_date||'.txt' ;<br />
success_File_Name := 'delete_success_'||cur_date||'.txt' ;<br />
var_query := 'delete from WHITE_LIST_auto where mobile=wl_DATA.mobile' ;<br />
else<br />
dbms_output.put_line('What do u want to do ??? Please Select an action (add or delete)');<br />
return;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <br />
dbms_output.put_line('else Action');<br />
--return 'Please Select an action (add or delete)';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> end if;<br />
end if;<br />
<br />
SELECT to_char(sysdate, 'DDMonYYYY_HH24MISS') into cur_date from dual;<br />
--file_Name := 'error_'||cur_date||'.txt' ;<br />
dbms_output.put_line('error is '|| file_Name);<br />
v_file := UTL_FILE.FOPEN(location => 'dir_3352',<br />
filename => file_Name,<br />
open_mode => 'w',<br />
max_linesize => 32767);<br />
--success_File_Name := 'success_'||cur_date||'.txt' ;<br />
dbms_output.put_line('success_File_Name is '|| success_File_Name);<br />
s_file := UTL_FILE.FOPEN(location => 'dir_3352',<br />
filename => success_File_Name,<br />
open_mode => 'w',<br />
max_linesize => 32767);<br />
<br />
FOR wl_DATA in C_CONTENT<br />
LOOP<br />
begin<br />
begin<br />
-------------------------------------------------------------------------------------------<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>Error Validations <span class="Apple-tab-span" style="white-space: pre;"> </span> --<br />
-------------------------------------------------------------------------------------------<br />
if length(wl_DATA.mobile) <> 11 or substr(wl_DATA.mobile,0,2) <> '03' then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> raise ERROR_mobile_FORMAT;<br />
else if ( (LENGTH(TRIM(TRANSLATE(wl_DATA.mobile, '+0123456789',' '))) is not null) ) then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>raise ERROR_mobile_VALUE;<br />
else if (is_date(wl_DATA.dateCol, 'dd-mon-yy') = 0) then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>raise ERROR_DATE_VALUE;<br />
else if (CHECK_WHITELIST(wl_DATA.mobile) = 1 and action = 'add') then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>raise ERROR_DUPLICATE_mobile;<br />
else if (CHECK_WHITELIST(wl_DATA.mobile) = 0 and action = 'delete') then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>raise ERROR_NO_mobile_FOUND;<br />
else<br />
-----------------------------------------------------------------------------<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> --<span class="Apple-tab-span" style="white-space: pre;"> </span>Dumping Valid Data <span class="Apple-tab-span" style="white-space: pre;"> </span> --<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> -----------------------------------------------------------------------------<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> if ( action = 'add') then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> insert into WHITE_LIST_auto values(wl_DATA.mobile,wl_DATA.dateCol,wl_DATA.ID);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> else if ( action = 'delete') then<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> delete from WHITE_LIST_auto where mobile=wl_DATA.mobile;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> else<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> dbms_output.put_line('else Action');<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> return;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> --return 'Please Select an action (add or delete)';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> end if;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> end if;<br />
<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>--dbms_output.put_line(var_query);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>--execute immediate var_query ;<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>--insert into WHITE_LIST_auto values(wl_DATA.mobile,wl_DATA.dateCol,wl_DATA.ID);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>UTL_FILE.PUT_LINE(s_file,wl_DATA.mobile|| ',' ||wl_DATA.dateCol|| ',' ||wl_DATA.ID);<br />
end if;<br />
end if;<br />
end if;<br />
end if;<br />
end if;<br />
exception<br />
-----------------------------------------------------------------------------<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> --<span class="Apple-tab-span" style="white-space: pre;"> </span>Exception Handling <span class="Apple-tab-span" style="white-space: pre;"> </span> --<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> -----------------------------------------------------------------------------<br />
when ERROR_mobile_FORMAT then<br />
v_message:='Mobile number Format is invalid';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> UTL_FILE.PUT_LINE(v_file,wl_DATA.mobile|| ',' ||wl_DATA.dateCol|| ',' ||wl_DATA.ID|| ',' ||v_message);<br />
when ERROR_mobile_VALUE then<br />
v_message:='Mobile number is invalid';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> UTL_FILE.PUT_LINE(v_file,wl_DATA.mobile|| ',' ||wl_DATA.dateCol|| ',' ||wl_DATA.ID|| ',' ||v_message);<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span>when ERROR_DATE_VALUE then<br />
v_message:='date is invalid';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> UTL_FILE.PUT_LINE(v_file,wl_DATA.mobile|| ',' ||wl_DATA.dateCol|| ',' ||wl_DATA.ID|| ',' ||v_message);<br />
when ERROR_DUPLICATE_mobile then<br />
v_message:='Duplictae mobile';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> UTL_FILE.PUT_LINE(v_file,wl_DATA.mobile|| ',' ||wl_DATA.dateCol|| ',' ||wl_DATA.ID|| ',' ||v_message);<br />
when ERROR_NO_mobile_FOUND then<br />
v_message:='No mobile Found';<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> UTL_FILE.PUT_LINE(v_file,wl_DATA.mobile|| ',' ||wl_DATA.dateCol|| ',' ||wl_DATA.ID|| ',' ||v_message);<br />
end;<br />
end;<br />
END LOOP;<br />
UTL_FILE.FCLOSE(v_file); <br />
UTL_FILE.FCLOSE(s_file); <br />
commit;<br />
<br />
END;<br />
--=============================================================<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>--<br />
--<span class="Apple-tab-span" style="white-space: pre;"> </span>End of Logic<span class="Apple-tab-span" style="white-space: pre;"> </span>--<br />
-- =============================================================</blockquote>
</div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com1tag:blogger.com,1999:blog-1354181122094925216.post-71235002275737240512012-06-11T22:53:00.000-07:002012-06-12T02:21:27.839-07:00oracle procedure : number validation<div dir="ltr" style="text-align: left;" trbidi="on">
<blockquote class="tr_bq">
if ( (LENGTH(TRIM(TRANSLATE(contentcode, ‘+0123456789′,’ ‘))) is not
null) or (LENGTH(TRIM(TRANSLATE(otherfield, ‘+0123456789′,’ ‘))) is not
null)) then<br />dbms_output.put_line(‘contentcode or otherfield is invalid’); </blockquote>
</div>eaziwebhttp://www.blogger.com/profile/04275969026435209869noreply@blogger.com0