Friday, 28 November 2014

Fetch data from database in codeigniter and convert in json.



Hey Morning fellas,

Hope you are doing well.

A quick tutorial for ajax request in codeignitor and fetching data from db in Json Format.

First we need to have the database with a "unique _id" which we will use for calling the row.


<script>                function fetchdata_4_edit(val)        {                      if (window.XMLHttpRequest)            {// code for IE7+, Firefox, Chrome, Opera, Safari            xmlhttp=new XMLHttpRequest();            }            else            {// code for IE6, IE5            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");            }            xmlhttp.onreadystatechange=function()            {            if (xmlhttp.readyState==4 && xmlhttp.status==200)                {                 //document.getElementById('group_info').style.display='none';                document.getElementById("response").innerHTML=xmlhttp.responseText;
                }            }            xmlhttp.open("GET","<?php echo base_url();?reception/fetchdata_4_edit?unique_id="+val,true);            xmlhttp.send();                                            }                                </script>

Here response is the div where we will check our json values.
Unique id is the row unique id for database.



As you can see my controller name is reception and method is fetchdata_4_edit.
so this is what we do.
        function fetchdata_4_edit()        {                        $uniq_id = $_GET['unique_id'];                                    $this->db->select('*');            $this->db->from('table_1');            $this->db->join('table_2', 'table_2.colomn_name = table_1.column_name');            $this->db->where('table_1.column_name', $uniq_id);
            $query = $this->db->get();                        foreach ($query->result() as $row)            {                print json_encode($row);            }            

               }


Thats its.Now when you use this js Function with onclick.you will see the response in Json Format like this.


{"id":"22","cust_id":"1","call_level":"1","extension":"0","action_type":"2","title":"Voice_Mail","default_sound":"","hold_sound":"","error_sound":"","vm_pre_sound":"sound1","vm_post_sound":"sound1","welcome_sound":"","no_input_sound":"","wrong_input_sound":"","call_mode":null,"dest_email":"er.shakun90@gmail.com","go_to_level":null,"use_who_call":null,"who_call_api":null,"fallback":null,"notification":null,"sortor":"2","addDate":"2014-11-28 12:48:47","updateDate":"0000-00-00 00:00:00","desc":"Vm_Desc","action_id":"74","time_slot_type":"0","slot_date":"2014-11-28","slot_day":"8","slot_time_from":"00:00:00","slot_time_to":"00:00:00"}


Thanks




Friday, 21 November 2014

How to dismiss bootstrap modal inside function.




Make another button like this

 <button type="button" class="btn btn-warning btn-lg shiny" data-dismiss="modal" aria-hidden="true">Cancel</button>

This button contains `data-dismiss="modal"` .You can hide this button if you want.

Now You can use any other function in a customized way and when you want to hide the modal you can call

 $(".btn-warning").click();

Monday, 13 October 2014

send data using ajax in codeigniter-jquery ajax


Hey everyone,

Here is quick tutorial for ajax in codeignitor.

First create a form in your view folder.
<form id="create_campaign" method="post" action="">                                                          
                                                            <div class="form-group">
                                                                <span class="input-icon icon-right">
                                                                    <input type="text" placeholder="Campaign Name" autocomplete="off" name="campaignname" required id="campaignname" class="form-control">
                                                                    <i class="glyphicon glyphicon-retweet"></i>
                                                                </span>
                                                            </div>
<div class="form-title">
                                                                Upload Message File<span id="youseletedaudio" style="float:right;"></span>
                                                            </div>
                                                           

<div class="form-group" style="text-align:center;">
<span class="input-icon icon-right">                                                                  
                                                                    <a class="btn btn-sky shiny" onClick="showdetails('<?php echo $id; ?>');" href="javascript:void(0);">Choose from sound library</a>
                                                                </span>
</div>
                                                           
<div class="form-title">
                                                                Upload Base<span id="youseleted" style="float:right;"></span>
                                                            </div>

<div class="form-group" style="text-align:center;">
<span class="input-icon icon-right">                                                                  
                                                                    <a class="btn btn-sky shiny" onClick="showgroup('<?php echo $id; ?>')" href="javascript:void(0);">Choose from address book</a>
                                                                </span>
</div>
                                                           
                                                            <!-----
                                                            <div class="form-title">
   Call Type
</div>
<div class="control-group">
                                                                <div class="radio">
                                                                    <label>
                                                                    <input type="radio" name="calltype" checked="checked" value="Trans" name="form-field-radio">
                                                                    <span class="text">Transactional</span>
                                                                    </label>
                                                                </div>
                                                                <div class="radio">
                                                                    <label>
                                                                    <input type="radio" name="calltype" class="checked" value="Promo" name="form-field-radio">
                                                                    <span class="text">Promotional</span>
                                                                    </label>
                                                                </div>
                                                            </div>
----->
                                                           
                                                            <div class="form-group">
                                                           
<div class="form-title">
   Campaign Start Time
</div>
<div class="col-lg-6 col-sm-6">
<div class="input-group">
                                                            <input class="form-control date-picker" autocomplete="off" required name="campstartdate" id="id-date-picker-1" type="text" data-date-format="dd-mm-yyyy">
                                                            <span class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                            </span>
                                                            </div>
</div>
<div class="col-lg-6 col-sm-6">
<div class="input-group">
<input class="form-control" id="timepicker1" autocomplete="off" required name="campstarttime" type="text">
<span class="input-group-addon">
<i class="fa fa-clock-o"></i>
</span>
</div>
</div>
                                                           
                                                            </div>
                         
                                                            <div class="form-group">
                                                            <div class="form-title">
   Campaign End Time
</div>
<div class="col-lg-6 col-sm-6">
<div class="input-group">
                                                            <input class="form-control date-picker2" autocomplete="off" required id="id-date-picker-2" name="campenddate" type="text" data-date-format="dd-mm-yyyy">
                                                            <span class="input-group-addon">
                                                            <i class="fa fa-calendar"></i>
                                                            </span>
                                                            </div>
</div>
<div class="col-lg-6 col-sm-6">
<div class="input-group">
<input class="form-control" id="timepicker2" autocomplete="off" required name="campendtime" type="text">
<span class="input-group-addon">
<i class="fa fa-clock-o"></i>
</span>
</div>
</div>
                                                        </div>  

<input type="hidden" value="<?php echo $id; ?>" id="userid" name="userid">                                                   <input type="hidden" value="<?php echo $parent_id; ?>" id="parentid" name="parentid">
                                                           
                                                           
                                                           
                                                            <div class="form-group" style="text-align:center;margin-top: 85px;">
                                                           
                                                            <span class="input-icon icon-right">                                                                  
                                                                    <button class="btn btn-blue btn-lg shiny" type="submit">Submit</button>
                                                                </span>
                                                           
                                                            </div>
                                                           
                                                                                                                       
                                                           
                                                        </form>





Than below that page add this script.


<script>
// JavaScript Document
    $(document).ready(function(){
    $('#create_campaign').submit(function(e) {

//alert("hello");

//campaign name

    var campaignname = $('#campaignname').val();

// campaign name


//Most important

var audiotrack = $('#sound').val();
var groupname = $('#group').val();

//Most important

//Time travel

    var startdate = $('#id-date-picker-1').val();
var starttime = $('#timepicker1').val();

var enddate = $('#id-date-picker-2').val();
var endtime = $('#timepicker2').val();

//Time Travel

var userid = $('#userid').val();
var parentid = $('#parentid').val();



   
    var editpostData = {
    'campaignname' : campaignname,
    'audiotrack' : audiotrack,
'groupname' : groupname,
'startdate' : startdate,
'starttime' : starttime,
'enddate' : enddate,
'endtime' : endtime,
'userid' : userid,
'parentid' : parentid
    };
   
//alert(editpostData);


    var data1 = JSON.stringify(editpostData);
   
    e.preventDefault();
   
    $.ajax({
    type: "POST",
    data: {value1:data1},
    url: "<?php echo base_url(); ?>campaign/addcampaign",
    success: function() {
   
    alert("Campaign Created sucessfully") ;

    window.location = "<?php echo base_url(); ?>campaign/viewcampaign";
   
    }
    });
    });
    });

</script>






In your controller.add this to get data.

function addcampaign()
{

$dataString1 = $_POST['value1'];

        $json1 = json_decode($dataString1, true);

$game_date = $json1['startdate'];
$game_time = $json1['starttime'];
$game_date1 = $json1['enddate'];
$game_time1 = $json1['endtime'];


$combined_date_and_time = $game_date . ' ' . $game_time;
$combined_date_and_time1 = $game_date1 . ' ' . $game_time1;


$dt = strtotime($combined_date_and_time);

$dt1 = strtotime($combined_date_and_time1);

$st_date= date("Y-m-d H:i:s", $dt);

$en_date= date("Y-m-d H:i:s", $dt1);

$campaignid=random_string('alnum', 16);

$session_data = $this->session->userdata('logged_in');

$channels=$session_data['channels'];

$this->files_model->insert_campaign($json1['campaignname'],$json1['audiotrack'],$json1['groupname'],$st_date,$en_date,$json1['userid'],$json1['parent_id'],$campaignid,$channels);  

//calling model above
 


}


Than in your model.

public function insert_campaign($campaignname,$audiotrack,$groupname,$startdate,$enddate,$userid,$parentid,$campaignid,$channels)
    {  
         
        $data = array(
   'user_id'  => $userid,
'parent_id'=> $parentid,
   'campaign_name'  => $campaignname,
'campaign_type' => 'PlayFile',
            'campaign_id'  => $campaignid,
'prompt_file_id'  => $audiotrack,
'group_id'  => $groupname,
'call_type'  => 'Promo',
'channel'  => $channels,
'start_time'  => $startdate,
'end_time'  => $enddate,
'curr_status'  => 'Active'          
        );

        $this->db->insert('obd_campaign', $data);
        return $this->db->insert_id();
    }



Here i have inserted two files together into database.One csv and one mp3 file.


That's it.

If you have any question.please mention in comment.

Thanks

Friday, 8 August 2014

Buddypress show member avatar



Use this loop to print image with names in any page of your theme.

<?php if ( bp_has_members( bp_ajax_querystring( 'members' ) ) ) : ?>
      <?php while ( bp_members() ) : bp_the_member(); ?>
      <div class="item-avatar">
                <?php bp_member_avatar('type=full&width=150&height=170'); ?>
                <?php bp_member_name(); ?>
    </div>
 <?php endwhile; ?>
 <?php endif; ?>   

Friday, 23 May 2014

city drop down list india for contact form 7




[select india-cities include_blank "Ahmedabad" "Bengaluru/Bangalore" "Chandigarh" "Chennai" "Delhi" "Gurgaon" "Hyderabad/Secunderabad" "Kolkatta" "Mumbai" "Noida" "Pune" "Anantapur" "Guntakal" "Guntur" "kakinada" "kurnool" "Nellore" "Nizamabad" "Rajahmundry" "Tirupati" "Vijayawada" "Visakhapatnam" "Warangal" "Itanagar" "Guwahati" "Silchar" "Bhagalpur" "Patna" "Bhillai" "Bilaspur" "Raipur" "Belgaum" "Bellary" "Bidar" "Dharwad" "Gulbarga" "Hubli" "Kolar" "Mangalore" "Mysoru/Mysore" "Calicut" "Cochin" "Ernakulam" "Kannur" "Kochi" "Kollam" "Kottayam" "Kozhikode" "Palakkad" "Palghat" "Thrissur" "Trivandrum" "Bhopal" "Gwalior" "Indore" "Jabalpur" "Ujjain" "Ahmednagar" "Aurangabad" "Jalgaon" "Kolhapur" "Mumbai" "Mumbai Suburbs" "Nagpur" "Nasik" "Navi Mumbai" "Pune" "Solapur" "Imphal" "Shillong" "Aizawal" "Dimapur" "Bhubaneshwar" "Cuttak" "Paradeep" "Puri" "Rourkela" "Amritsar" "Bathinda" "Chandigarh" "Jalandhar" "Ludhiana" "Mohali" "Pathankot" "Patiala" "Ajmer" "Jaipur" "Jaisalmer" "Jodhpur" "Udaipur" "Gangtok" "Chennai" "Coimbatore" "Cuddalore" "Erode" "Hosur" "Madurai" "Nagerkoil" "Ooty" "Salem" "Thanjavur" "Tirunalveli" "Trichy" "Tuticorin" "Vellore" "Agartala" "Chandigarh" "Dadra & Nagar Haveli-Silvass" "Daman & Diu" "Pondichery" "Agra" "Aligarh" "Allahabad" "Bareilly" "Faizabad" "Ghaziabad" "Gorakhpur" "Kanpur" "Lucknow" "Mathura" "Meerut" "Moradabad" "Noida" "Varanasi/Banaras" "Dehradun" "Roorkee" "Asansol" "Durgapur" "Haldia" "Kharagpur" "Kolkatta" "Siliguri" "Panjim/Panaj" "Vasco Da Gama" "Ahmedabad" "Anand" "Ankleshwar" "Bharuch" "Bhavnagar" "Bhuj" "Gandhinagar" "Gir" "Jamnagar" "Kandla" "Porbandar" "Rajkot" "Surat" "Vadodara/Baroda" "Valsad" "Vapi" "Ambala" "Chandigarh" "Faridabad" "Hisar" "Karnal" "Kurukshetra" "Panipat" "Rohtak" "Dalhousie" "Dharmasala" "Kulu/Manali" "Shimla" "Jammu" "Srinagar" "Bokaro" "Dhanbad" "Jamshedpur" "Ranchi" "other"]

Tuesday, 13 May 2014

Update One column value in another column in Mysql




Hi,


For updating Value from one column to another use this


update Table_name set Column_name1 = Column_name2


But if  you want to copy specified character from a column then 



update Table_name set Column_name1 =
(
   SELECT LEFT(
Column_name2,INSTR(Column_name2,",")-1) 

)



SELECT LEFT(Column_name2,INSTR(Column_name2,",")-1) 

This query will select only characters before ,(Comma).


You can modify it as per your requirement.You can use slash or any other character...

Thanks
Shakun

Saturday, 11 January 2014

Add thumbnail in pages - PyroCMS



For adding thumbnail in Pyrocms page....

Simple add a img tag in every page content page body

ex:

<img src="URL OF YOUR IMAGE" id="headerimg" style="display:none;" class="" alt="" title=""/>



Now add this javascript in your default.html under addons > themes > layout.

<script>
(function(){
   
var headerimage = document.getElementById("headerimg").src;
window.onload = function() {
       //when the document is finished loading, replace everything
       //between the <a ...> </a> tags with the value of splitText
   document.getElementById("myLink").src=headerimage;
}

})();

</script>



And finally add an image tag where you want to display your banner image.i used it in main.html under addons > themes > partials.

like this :
<img id="myLink" src="">

For demo

Thanks






How to add active class in Navigation-pyrocms


=== Goodafternoon friends ===

 

For adding active class in navigation for pyrocms,

<div class="content">
<div class="menu-block-2 menu-name-primary-links parent-mlid-0 menu-level-2">
<ul class="menu">
{{ pages:children id="11" limit="12" }}
<li {{ if {url:segments segment="2"} ==  slug  }} class="active" {{ endif }}>
<a href="{{ url }}">{{ title }}</a>
</li>
{{ /pages:children }}
</ul>
</div>
</div>

For working example,click here

I hope this helps.Thanks

Friday, 10 January 2014

How to Upload images in codeignitor and save file path in database ?



Here i am using twitter bootstrap theme  

Controller to open form name dashboard.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Dashboard extends CI_Controller {

public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('newcategory');
}
public function category()
{
$data['category'] = $this->newcategory->showcategorydetails();
$this->load->view('template/header',$data);
$this->load->view('template/sidebar');
$this->load->view('category', array('error' => ' ' ));
$this->load->view('template/footer');
}
}

?>




In view- file name category.php

<div id="content">

<div class="outer">

<div class="inner">
<div class="row">
  <div class="col-lg-12">
    <div class="box">
      <header>
        <div class="icons"> <i class="fa fa-table"></i> </div>
        <h5>Dynamic Table</h5>
      </header>
      <div id="collapse4" class="body">
        <table id="dataTable" class="table table-bordered table-condensed table-hover table-striped">
          <thead>
            <tr>
              <th>Image</th>
              <th>Name</th>
              <th>Description</th>
              <th>Slug</th>
              <th>Posts</th>
              <th>Parent</th>
              <th>Status</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
          <?php foreach ($category as $cat) { ?>
            <tr>
              <td><img src="<?php echo base_url(); ?>uploads/<?php echo $cat['img_name']; ?>" class="category-image" alt="category-image"></td>
              <td><?php echo $cat['name']; ?></td>
              <td><?php echo $cat['description']; ?></td>
              <td><?php echo $cat['slug']; ?></td>
              <td>Empty</td>
              <td>
 <?php if($cat['parent']=='0')
 {
echo '-N/A-';
 } else {
 
 $query=$this->db->query("select parent_cat_name from app_category_parent where id=".$cat['parent']);
 $cat_name = $query->result_array();
 foreach ($cat_name as $category) {
 echo $category['parent_cat_name'];
 }}
 ?></td>
              <td><?php if($cat['status']=='1'){ echo 'Active';} else { echo 'Inactive'; } ?></td>
              <td>            
              <a href="<?php echo base_url(); ?>index.php/newentry/deactivate_Category/<?php echo $cat['id']; ?>" class="customClick btn btn-warning btn-xs btn-line" data-str="0">De-activate</a>
              <a href="<?php echo base_url(); ?>index.php/newentry/delete_Category/<?php echo $cat['id']; ?>" class="deleteClick btn btn-danger btn-xs btn-line" data-str="0">Delete</a>
              </td>
            </tr>
          <?php } ?>
          </tbody>
        </table>      
      </div>
    </div>
  </div>
</div>
<div class="row">
  <div class="col-lg-6">
    <div class="box dark">
      <header>
        <div class="icons">
          <h5>Add New Category</h5>
          <div class="toolbar">
            <ul class="nav">
              <li> <a class="minimize-box" href="#div-1" data-toggle="collapse"> <i class="fa fa-chevron-up"></i> </a> </li>
            </ul>
          </div>
        </div>
      </header>
      <div id="div-1" class="accordion-body collapse in body">
        <?php echo form_open_multipart('newentry/newcategory') ?>

// for saving data from this form into database-newentry is my controller and newcategory is the function.


          <div class="form-group">
            <label class="control-label col-lg-4" for="text1">Name</label>
            <div class="col-lg-8">
              <input id="cat_title" class="form-control" name="cat_title" type="text" required="required" onblur="getslug();">
              <p>The name is how it appears on your site.</p>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-lg-4" for="text1">Slug</label>
            <div class="col-lg-8">
              <input id="cat_slug" class="form-control" name="cat_slug" type="text" required="required">
              <p>The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.</p>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-lg-4">Parent</label>
            <div class="col-lg-8">
              <select name="cat_parent" onchange="selected();" id="cat_parent" data-placeholder="Choose a Country..." class="form-control chzn-select" tabindex="2">
              <option value="">None</option>
              <?
 $query=$this->db->query("select app_category.*,app_category_detail.* FROM app_category LEFT JOIN app_category_detail ON app_category.cat_id=app_category_detail.cat_id where status=1");
 $cat_name = $query->result_array();
 foreach ($cat_name as $category) { ?>
           
 <option value="<?php echo $category['cat_id'];?>"><?php echo $category['name'];?></option>
           
 <? } ?>            
              </select>            
              <input type="hidden" id="cat_parent_id" name="cat_parent_id" />
              <p>Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.</p>
            </div>
          </div>
          <div class="form-group">
            <label class="control-label col-lg-4" for="autosize">Description</label>
            <div class="col-lg-8">
              <textarea id="autosize" name="cat_description" class="form-control" style="overflow: hidden; word-wrap: break-word; resize: horizontal; height: 134px;"></textarea>
              <p>The description is not prominent by default; however, some themes may show it.</p>
            </div>
          </div>  
       
 <div class="form-group">
                        <label class="control-label col-lg-4">Category Image</label>
                        <div class="col-lg-8">
                          <div class="fileinput fileinput-new" data-provides="fileinput">
                            <div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
                              <img data-src="holder.js/100%x100%" alt="...">
                            </div>
                            <div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
                            <div>
                              <span class="btn btn-default btn-file"><span class="fileinput-new">Select image</span><span class="fileinput-exists">Change</span>
                              <input type="file" name="userfile" size="20" />
                              </span>
                              <a href="#" class="btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
                            </div>
                          </div>
                        </div>
                      </div>
           
 
          <p class="submit">
            <input id="submit" class="btn btn-primary" type="submit" value="Add New Category" name="submit">
          </p>
        </form>
     
      </div>
    </div>
  </div>
</div>
</div>
</div>
</div>
<script>
function getslug() {
var str = document.getElementById('cat_title').value;
var res = str.replace(/\s+/g, '-').toLowerCase(); document.getElementById('cat_slug').value = res; }
</script>
<script>
function selected()
{
var id = document.getElementById('cat_parent').value; document.getElementById('cat_parent_id').value=id;
}
</script>






In My controller - name - newentry.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


class Newentry extends CI_Controller {


public function __construct()

{

parent::__construct();

$this->load->helper('url');

$this->load->model('newcategory');

}

public function newcategory()

{

$this->newcategory->newcategory_partone();

$id = $this->db->insert_id();

$this->newcategory->newcategory_parttwo($id);

$cid=$this->input->post('cat_parent_id');

if ($cid !='') {

$this->newcategory->newcategory_partthree();

}

redirect('dashboard/category', 'refresh');

}

public function deactivate_Category(){

$id=$this->uri->segment(3);

$this->newcategory->deactivate_category($id);

redirect('dashboard/category', 'refresh');

}

public function delete_Category(){

$id=$this->uri->segment(3);

$this->newcategory->delete_category($id);

redirect('dashboard/category', 'refresh');

}

}






And in my model - name- newcategory.php



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Newcategory extends CI_Controller {

public function __construct()
{
parent::__construct();
}
public function lastregistration_id()
{
return $this->db->insert_id();
public function newcategory_partone()
{
$this->load->helper('url');
$this->load->helper('form');
$this->load->helper('date');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width']  = '1024';
$config['max_height']  = '768';

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload())
{
redirect('dashboard/category', 'refresh');
}
else
{
$data = array('upload_data' => $this->upload->data());
            foreach ($data as $item){
$img_path= $item['full_path']; 
$img_name= $item['file_name']; 
}
$cat = array(
'name' => $this->input->post('cat_title'),
'slug'=>$this->input->post('cat_slug'),
'date_created' => date('Y-m-d H:i:s'),
'system_ip'=> $_SERVER['REMOTE_ADDR'],
'img_name' =>$img_name,
'img_path'=>$img_path,
);
return $this->db->insert('app_category', $cat);
}
}
public function newcategory_parttwo($cat_id)
{
$this->load->helper('url');
$this->load->helper('date');
$cat_second = array(
    'cat_id' =>$cat_id,
'name'=>$this->input->post('cat_title'),
'description'=>$this->input->post('cat_description'),
'parent'=>$this->input->post('cat_parent'),
);
return $this->db->insert('app_category_detail', $cat_second);
}
public function newcategory_partthree()
{
$this->load->helper('url');
$this->load->helper('date');
$id=$this->input->post('cat_parent_id');
$query=$this->db->query("select * from app_category where cat_id=$id");
$cat_name = $query->result_array();
foreach ($cat_name as $category) { 
        $name=$category['name'];
        }
$cat_third = array(
   
'parent_cat_name'=>$name,
'status' =>1,
);
return $this->db->insert('app_category_parent', $cat_third);
}
public function showcategorydetails()
{
$query=$this->db->query("select app_category.*,app_category_detail.* FROM app_category LEFT JOIN app_category_detail ON app_category.cat_id=app_category_detail.cat_id where status=1");  
    return $query->result_array();
}
public function deactivate_category() {
$id=$this->uri->segment(3);
$data = array(
              'status '=>0
            );

$this->db->where('id', $id);
$this->db->update('app_category_detail', $data); 
}
public function delete_category() {
$id=$this->uri->segment(3);
$data = array(
             'status '=>2 
            );

$this->db->where('id', $id);
$this->db->update('app_category_detail', $data); 
}
}


That's it.Enjoy.


Sunday, 5 January 2014

Style last post in loop differently?



How to add different class in last child of loop in wordpress.



<ul class="categories_list cat_main">
<?php  
$args=array('posts_per_page' => 6,'post_type' => 'post','orderby' => 'meta_value', 'meta_key' => 'views','order'=> 'DESC', 'post_status' => 'publish');
$the_query = new WP_Query($args);
$counter=1;
while ($the_query->have_posts()) : $the_query->the_post();?>  
      <li <?php if($counter==6){echo "class='last'";}?>>
      <div id="normal">
      <a href="<?php the_permalink(); ?>">
      <?php $values = get_post_custom_values("Featured Image");  ?>
      <img src="<?php echo $values[0];?>" /></a>
      </div>
      <?php /*?><div id="mob">
      <?php $values_m = get_post_custom_values("mobile Link");  ?><a href="<?php echo $values_m[0];?>">
      <?php $values = get_post_custom_values("Featured Image");  ?>
      <img src="<?php echo $values[0];?>" /></a>
      </div><?php */?>
      <p class="title"><a href="<?php the_permalink(); ?>">
        <?php the_title(); ?>
        </a></p>
      <?php /*?><p class="mob_title"><?php $values_m = get_post_custom_values("mobile Link");  ?><a href="<?php echo $values_m[0];?>">
        <?php the_title(); ?>
        </a></p><?php */?>
      <p>
        <?php $values1 = get_post_custom_values("views");?>
        <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?>
        |
        <?php if(function_exists('the_views')) { the_views(); } ?>
      </p>
    </li>
    <?php $counter++; ?>
     <?php endwhile; ?>
    <?php wp_reset_query(); ?>
  </ul>



Thanks.

Tuesday, 3 December 2013

Rss Fetcher Wordpress and PHP



One of the most important topic that consumed my whole night to build a RSS Fetcher.This code will guide you to convert rss feed into Wordpress Posts.There are lots of plugins which provide this facility but none of them does their job completely.

Here is a sample rss feed from clipsyndicate.

<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:syndi="http://clipsyndicate.com/rss/extension/mobileplayer"version="2.0">


<channel>


<title>Entertainment</title>


<description/>


<category>ns_entertainment</category>


<link>http://chic.clipsyndicate.com/rss/feed/12235</link>


<atom:link type="application/rss+xml" href="http://chic.clipsyndicate.com/rss/feed/12235" rel="self"/>


<item>


<guid>
http://eplayer.clipsyndicate.com/view/12235/4780626
</guid>


<title>Video: Locals React to Paul Walker's Death</title>


<description>
<table border="0" cellpadding="0" cellspacing="0"><tr valign="top"><td><a href="http://chic.clipsyndicate.com/video/playlist/12235/4780626?cpt=8&wpid=6474"><img src="http://video-static.clipsyndicate.com/zStorage/clipsyndicate/247/2013/12/02/02/29/yllttxabgqohbybsuhpo.jpg" width="120" height="90" border="0" /></a></td><td style="padding:5px;">Walker's neighbors placed flowers on the front porch of his Mesa home as a tribute.</td></tr></table>
</description>


<link>
http://chic.clipsyndicate.com/video/playlist/12235/4780626?cpt=8&wpid=6474
</link>


<pubDate>Mon, 02 Dec 2013 01:59:52 +0000</pubDate>


<media:thumbnail url="http://video-static.clipsyndicate.com/zStorage/clipsyndicate/247/2013/12/02/02/29/yllttxabgqohbybsuhpo.jpg" height="90" width="120"/>


<media:title>Locals React to Paul Walker's Death</media:title>


<media:description>
Walker's neighbors placed flowers on the front porch of his Mesa home as a tribute.
</media:description>


<media>
http://chic.clipsyndicate.com/video/playlist/12235/4780626?cpt=8&wpid=6474
</media>


<media:credit>KEYT Santa Barbara, CA</media:credit>


<media:text>
the community. 00-05 21-27 40-44 1:09-1:18 1:42-1:50 1:56-2:07 2:15-2:22trt - 2:38 nats "one of them is paul walkefrom the fast and the furious!." . it was supposed to be a quick joyride, but it ended in a fiery crash that killed actor and santa barbara resident paul walker and his friend roger rodas. nats of crash scene if any . walker and rodas were leaving a charity event justnorth of los angeles on saturday when their car wrecked. both were pronounced dead at the scene. sot jim torp/friend of walker "Paul wanted to go for a rideThat was the last that we saw of them." . rodas was behind the wheel and walker a passenger in the red porsche that apparently spun out of control and slammed into a tree and light pole. . walker's friends heard thecrash and tried desperately to put out the flames.. sot antonio HOLMES/friend There was nothing....we tried..we went thru fire extinguishers and...." . all that was left was the burned out wreckage..the carbarely recognizable... dissolve... NEWS OF HIS death spread quickly on social media and throughout santabarbara, where walker had a home. 30:56 LAUREL PEREZ he was just a very open sweet friendly guy. We'll miss him. 31:00 . walker's neighbors placed flowers on the front porch of his mesa home as a tribute. 32:05 LAUREL PEREZ it's a small token of our appreciation for himhumbleness and generosity to this community and to others." neighbors say even though walker was a celebrity, he was a part of the community.30:27 LAUREL PEREZ "He was very friendly. He really liked and engaged with the kids in the neighborhood. There are some fun stories teasing the boys as they wouldwalk the dogs past his house. 30:41 walker was often spotted AROUND TOWN. Nats bowling strike he was a regular at zodo's bowling alley in goleta. sot "steve davis/zodos" 26:0most of the people really knew who hewas.... the girls thought he was a nice looking man and went gaga over him"26:12 . THE 4 year-old's good looks made him one of hollywood's most bankablestars. . he rose to fame behind the wheels of fast cars in the blockbuster fast and furious movie franchise. nats from movie clips "Righ behind you."Universal Pictures "Fast an Furious 6" . WALKER WAS I the middle of filming the 7th installment ofthe series at the time of his death. . the l-a county coronersays because of the fiery collision, it will be awhile until he can positively identify the bodies. . sot ed winter/la county CORONER's officeIt's gonna take some time...dental and possible medical x-rays." . as the investigation into the crash continues, so does the shock over walker;s death...one that many say came WAY TOO SOON. Sot: 30:27 he was a great guy. We are all very saddened by his death. in santa barbara, alys martinez newschannel 3. . paul walker is survived byhis 15- year old daughter, meadow. . now
</media:text>


<media:playerurl="http://eplayer.clipsyndicate.com/cs_api/get_swf/3/&amp;auto_next=0&amp;auto_start=0&amp;cpt=8&amp;page_count=5&amp;pf_id=6477&amp;pl_id=12235&amp;va_id=4780626&amp;windows=1&amp;wpid=6474">
<iframe frameborder="0" scrolling="no" src="http://eplayer.clipsyndicate.com/embed/iframe?cpt=8&pf_id=6477&pl_id=12235&va_id=4780626&windows=1" width="320" height="280"></iframe>
</media:player>


<media:category label="cs_tickers"/>


<media:category label="cs_keywords">Paul Walker,Fast and Furious,Car Accident</media:category>


<media:category label="cs_categories">News,Local News,Entertainment,Movies,Celebrity</media:category>


<syndi:mobilePlayer url="http://play.syndi.tv/v1/player.html?pf_id=6477&va_id=4780626"/>
</item>


<item>



Here is the code which i used for fetching this rss and making it wordpress post


<?php
$url="http://www.clipsyndicate.com/rss/feed/27960?wpid=12780";
$rss = new DOMDocument();
$rss->load($url);
$feed = array();


foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'media' => $node->getElementsByTagNameNS("*","description")->item(0)->nodeValue,
'tags' => $node->getElementsByTagNameNS("*","category")->item(1)->nodeValue,
'video' => $node->getElementsByTagName('guid')->item(0)->nodeValue,
'image' => $node->getElementsByTagName('thumbnail')->item(0) ? $node->getElementsByTagName('thumbnail')->item(0)->getAttribute('url') : ''
        );
    array_push($feed, $item);
}
$limit =100;  <-------Set no. of post u want to make

for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
$video = $feed[$x]['video'];
$image = $feed[$x]['image'];
$excerpt = $feed[$x]['media'];
$tag = $feed[$x]['tags'];
$uri = $video;
$pieces = explode("/", $uri);
    $uri_3 = $pieces[5];
$frame= '<iframe frameborder="0" scrolling="no" src="http://eplayer.clipsyndicate.com/embed/iframe?pf_id=&show_title=0&va_id='.$uri_3.'&windows=1" width="620" height="420"></iframe>';
$videolink='http://www.clipsyndicate.com/video/playlist/12235/'.$uri_3.'?title=entertainment&wpid=12780';


if($title!='' && $uri_3!=''){ <----------------Wordpress code to insert post $post_id = wp_insert_post(array ( 'post_title' => $title, 'post_content' =>$frame, 'post_status' => 'publish', 'post_author' => 1, 'tags_input' => $tag, 'post_excerpt'=> $excerpt, 'comment_status'=>'open', 'post_category' => array(760) )); if ($post_id) { // insert post meta add_post_meta($post_id, 'Featured Image', $image); add_post_meta($post_id, 'Video Link', $videolink); } }



 
 
}

?>


Hope this helps.Thnks