Jump to content

KSI

Members
  • Posts

    19
  • Joined

  • Last visited

Recent Profile Visitors

258 profile views

KSI's Achievements

Member

Member (2/5)

0

Reputation

  1. Okay I think I got an idea what to use for this now. Currently using Codeigniter so the equivalent of this should be a flash message. Thanks.
  2. Currently I'm in my controller and I have placed a check in the controller. Basically checking if the value of a particular field is 0 or not. Now if it is 0, I want to display an alert popup via my controller. To do this I've tried the following code: public function status($status){ if($this->input->post('id')){ foreach($this->input->post('id') as $key => $id): $check_emirate = $this->listings_model->check_emirate($id); if($check_emirate->emirate == 0){ echo "<script>alert('This card was not approved.');</script>"; }else{ $data=array('status'=>$status); $updated=$this->listings_model->update($data,array(),$id); } endforeach; } return true; } Now it is entering my if condition, but it doesnt show me the popup. This is the AJAX call I'm making to enable this function: $(".status").click(function(e) { chagestatus($(this)); } function chagestatus(obj){ if($('.chkbx').is(':checked') == true){ $.ajax({ type: "post", dataType: "json", async:false, url: "<?php echo site_url('listings/status'); ?>/"+obj.data('val'), data: $(".chkbx:checked").serialize(), success: function(result) {} }); } }
  3. Currently I'm using Datatables with pagination. Now I recently added the Datatable.buttons library to use Export to Excel option. Now this functionality works fine but it only exports the first 10 rows of the page I'm currently in due to pagination. Now if I remove the limit in my model class, it will export all the entries which is what I want but it also gets rid of the pagination which decreases my site performance. The following is my current AJAX call code for getting Datatable data: $('#datatable.table').DataTable({ searching: true, paging: true, processing: true, serverSide: true, bFilter: true, dom: 'Bfrtip', async: false, 'columnDefs': [ { 'targets':[0,1,31,32,33,34,35,36,37], 'orderable': false, }], buttons: [ { text:"Export to Excel", extend: 'excelHtml5', exportOptions: { columns: ':visible', modifier:{ page:'all' } } }, ], ajax: { "url": '<?php echo site_url('listings/dtlists'); ?>', "type": "POST" }, columns: [{ data: "title", className: "column5" }, ... Now I've added page:'all' in my modifier, but it still only prints the 1st pagination page. So is there any way that I can use a different model function just for the export button where I can customize the limit manually?
  4. Currently I have a multiselect option in my edit page where at first it should display all the existing values in the database as already checked and once the user removes a selected value, it should be removed from the database and if it is already not there in the database, it should be added to the database. Currently this is my code: View class: <select name="curations[]" id="curations" multiple class="form-control multiselects" <?php echo (isset($read) ? $read:''); ?> multiple> <?php $checked = array(); foreach($get_curation as $key => $value){ $checked[]=$value['curations_id']; } if($curations){ foreach($curations as $cur){ ?> <option value="<?php echo $cur['id']; ?>" <?php echo in_array($cur['id'], $checked) ? 'selected' : 'selected'; ?>><?php echo $cur['title']; ?></option> <?php } } ?> </select> Controller Class: if ($this->input->post('curations') != '') { $curationsPost = $this->input->post('curations'); $curationsArray = array(); $c = 0; foreach($curationsPost as $cp){ if ($cp != ''){ $curationsArray[$c]['listings_id']= $id; $curationsArray[$c]['curations_id']= $cp; $c++; } } if(count($curationsArray) > 0){ $this->listings_model->update_curations($curationsArray); } } Model class: function update_curations($curationsArray){ $this->db->insert_batch("crm_property_curation",$curationsArray); } As of now by default it displays all the values as selected eventhough the values aren't present in the database and now everytime that I submit the form, it creates a duplicate entry in my database if the value was already checked. So basically what I need here is 2 things, 1 is that it shouldn't show everything initially when user enters the page and only show the selected values, and 2 is that when the form is submitted, it should insert the nonduplicate selected values and delete the unselected values. I've tried $this->db->update_batch("crm_property_curation",$curationsArray); but this does not work. As my current query is inserting all the values again, I think what my query should do is delete all the values with the particular listings_id and replace them with the incoming values if thats possible.
  5. Currently I have a table that presents a count of records next to the title of the particular product. To do this I'm using the following code: View Class: <?php $ls_arr = array(1=>'Open',8=>'Hot',2=>'Closed',3=>'Transacted',4=>'Dead',9=>'Follow Up',11=>'Working'); foreach($groupedleads as $grplead){ $statuses[] = $status = $ls_arr[$grplead["lead_status"]]; if($grplead["title"] == NULL || $grplead["title"] == '') $grplead["title"] = "Unknown"; if(isset($grplead["title"])) $titles[] = $title = $grplead["title"]; $leaddata[$status][$title] = $grplead["leadnum"]; } foreach($groupedleads_status as $grplead){ $statuses[] = $status = $ls_arr[$grplead["lead_status"]]; if($grplead["title"] == NULL || $grplead["title"] == '') $grplead["title"] = "Unknown"; if(isset($grplead["title"])) $titles[] = $title = $grplead["title"]; $leaddatastatus[$status][$title][$sub_status] = $grplead["leadnum"]; } ?> <?php if(is_array($titles)) foreach($titles as $title){ ?> <tr> <?php echo "<td>".$title."</td>"; foreach ($statuses as $status) { $num = $leaddata[$status][$title]; $contacts = $leaddatastatus[$status][$title][$sub_status]; $status_num = array_flip($ls_arr)[$status]; if($contacts != ''){ echo "<td><a target='_blank' href='" . site_url('reports/lists?source=' . $title . '&status=' . $status_num . '&sub_status=') . "'>".$num."</a> <font size= '1'><a target='_blank' href='".site_url('reports/lists?source=' . $title . '&status=' . $status_num . '&sub_status=6') . "'>". "Not Contacted - ".$contacts."</a></font></td>"; }else{ echo "<td><a target='_blank' href='" . site_url('reports/lists?source=' . $title . '&status=' . $status_num . '&sub_status=' . $sub_status) . "'>".$num."</a></td>"; } ?> </tr> <?php } ?> Now I did a var_dump on $leadstatus and it gave the following output: Now there are values that are not defined in the second array which are defined in the first. So at those places it gives me a warning message saying Undefined array key Sign Boards. So I want a way so that it displays all the titles regardless of the title being there or not and display the count for that as null.
  6. Currently I'm using codeigniter 3.0 and I have a multiple document upload tab in my add page. Here the user can write the title of the document and upload a document and they can select the add button to add more documents. But I cannot store these document in my database when I click on the save button. Here is my current code: View class: <td width="45%"><input type="text" name="doctitle[]" placeholder="Title"></td> <td><input type="file" name="documents[]"></td> <td width="1%"><a class="btn btn-success" id="addobj" href="javascript:void(0)">Add </a></td> Controller Class: if ($this->form_validation->run() == FALSE) { $main['page'] = 'crm/listings/add'; $this->load->view('crm/index', $main); }else { $maindata=array('clients_id'=>$this->session->userdata('clientsessid')); $insertid=$this->listings_model->insert_listing($maindata); if($insertid){ if ($this->input->post('documents')) { $documentPost = $this->input->post('documents'); $documentTitle = $this->input->post('doctitle'); $documentArray = array(); $c = 0; foreach($documentPost as $dp){ if($this->web_upload->do_upload('documents')) { $filedata=$this->web_upload->data(); $dp=$filedata['file_name']; } $documentArray[$c]['listings_id']= $insertid; $documentArray[$c]['title']= $documentTitle; $documentArray[$c]['document']= $dp; $documentArray[$c]['added_date']=date('Y-m-d H:i:s'); $documentArray[$c]['added_by']= $this->session->userdata('user_id'); $c++; } if(count($documentArray) > 0){ $this->listings_model->save_document($notesArray); } } redirect('listings/sales'); } Model Class: function save_document($maindata){ $this->db->insert_batch("crm_property_docs",$maindata); print_r($this->db->last_query()); die(); return $this->db->insert_id(); } function insert_listing($maindata){ $this->db->insert("crm_listings",$maindata); $prime=$this->db->insert_id(); return $prime; } Now I have added a print_r($this->db->last_query()); die(); statement in my save_document model so if it is being executed it should end the process there but it doesnt end my process, it just fills in all the data values in my database except for the documents data, which means this model is never being called and I'm not sure if I'm using the right method to upload these documents in my database.
  7. Currently I have a 2 dropdown inputs in my edit page, 1 a multi dropdown and the other is a single select dropdown. As of now when I enter the page, both of them show the values from my database. Now the multi select shows a tick on all the options that are currently there in my database. So I want it so that whenever the user unchecks anything, it deletes the entry from my database and whenever they check something, it should insert that entry in the database. Currently this is my code Controller class: function editteam($id,$return='') { if ($this->form_validation->run() == FALSE) { $main['return']=$return; $main['team']= $this->users_model->load_teams($id); $main['members']=$this->users_model->get_members(); $main['page'] = 'crm/users/editteam'; $this->load->view('crm/index', $main); } else { $maindata=array('status'=>$this->security->xss_clean($this->input->post('status')), 'can_manage'=>$this->security->xss_clean($this->input->post('manage')), 'role'=>$this->security->xss_clean($this->input->post('name'))); $loginid=$this->users_model->update_role($maindata,$id); if($loginid){redirect('users/teams/'.$return); } else { redirect('users/teams/'.$return); } } } View class: <?php $membersArray = array(); foreach($team as $t){ $membersArray[] = $t['team_user']; } ?> <div class="row card-box"><?php echo form_open('users/editteam'.$team[0]['tid'].'/'.$return); ?> <div class="form-group col-sm-12"> <label for="name">Team Name </label> <input id="name" name="name" type="text" class="form-control<?php echo $err; ?>" value="<?php echo $team[0]['team_name']; ?>" /> </div> <div class="form-group col-sm-12"> <label for="manage">Managed By <?php } ?> </label> <select class="form-control multiselects <?php echo $err; ?>" name="manage"> <option value="0">None</option> <?php foreach($members as $r){ $selected = ""; if($team[0]['managed_by'] == $r['id']){ $selected = "selected"; } echo '<option '.$selected.' value="'.$r['id'].'">'.$r['display_name'].'</option>'; } ?> </select> </div> <div> <label for="team">Team Members </label> <select multiple="multiple" class="form-control multiselects <?php echo $err; ?>" id="team" name="team[]"> <?php foreach($members as $r){ $selected = ""; if(in_array( $r['id'] , $membersArray)){ $selected = "selected"; } echo '<option '.$selected.' value="'.$r['id'].'">'.$r['display_name'].'</option>'; } ?> </select> </div> <div class="form-group col-sm-12"> <button type="submit" class="btn btn-info">Save</button> <?php echo form_close(); ?> </div> </div> <script> $(document).ready(function(){ $(".multiselects").multiselect({ enableClickableOptGroups: true, enableFiltering: true, includeSelectAllOption:true, buttonWidth: '100%', maxHeight:275, buttonClass: 'form-control text-left bggrid', nonSelectedText: 'Select', enableCaseInsensitiveFiltering: true, nonSelectedText: 'Select', selectAllText: 'Select All', templates: { ul: '<ul class="multiselect-container dropdown-menu col-sm-12"></ul>'} }); $('#team').multiselect('select',[''],true); }); </script> Model class: function get_members(){ $this->db->select("display_name,id"); $this->db->from("crm_clients_users"); $query = $this->db->get(); return $query->result_array(); } function load_teams($id) { $this->db->select("r.id AS tid , t.id as mid , r.,t."); $this->db->from("crm_clients_users_teams as r"); $this->db->where("r.id",$id); $this->db->join("crm_clients_users_teams_members as t","r.id=t.team_id","left"); $query = $this->db->get(); return $query->result_array(); } crm_clients_users_teams_members holds the members of a particular team where I want to have the insert/delete of users whenever they are selected/unselected, and crm_clients_users_teams holds the title and other related stuff to the table.
  8. Currently I have a table in my view class that is populated with data from the backend using MVC framework in codeigniter. Now I have a dropdown above each column that is filling in the same records from my database. So I want to be able to filter my records as soon as the person clicks the item in the dropdown list. To achieve this I'm using a Jquery to get the selected item and sending that value to my controller. Code: So far I have this in my view class: <table> <tr> <th width="10%">Source</th> </tr> <tr> <td width="5%"><select id="your_id_name"> <option value="">All </option> <?php if($sources) foreach($sources as $source): ?> <option value="<?php echo $source['title'] ?>"><?php echo $source['title'] ?></option> <?php endforeach;?> </select></td> <td width="10%"><select id="contact_type"> <option value="">All </option> <?php if($types) foreach($types as $type): ?> <option value="<?php echo $type['id'] ?>"><?php echo $type['title'] ?></option> <?php endforeach;?> </select></td> </tr> <tbody> <?php if(isset($records) && count($records) > 0) { foreach($records as $row ){ ?> <tr> <td><?= $row->source ?></td> <td><?= $row->title ?></td> </tr> <?php } } ?> </tbody> <script type="application/javascript"> $('#your_id_name').on('change', function() { console.log($('#your_id_name').val()); $.get('<?php echo base_url('ajax_dropdown'); ?>', { selected: $('#your_id_name').val() }, function(res) { var values = JSON.parse(res); // then do something var status = values.status; var records = values.records; var html = "" records.forEach(function(row){ html += `<tr><td>${row.source}</td> <td>${row.title }</td></tr> `; console.log(tbody_tag) }) var tbody_tag = $('tbody#table_body'); tbody_tag.html(html); }) }) $('#contact_type').on('change', function() { console.log($('#contact_type').val()); $.get('<?php echo base_url('ajax_dropdown'); ?>', { selected_contact: $('#contact_type').val() }, function(res) { var values = JSON.parse(res); // then do something var status = values.status; var records = values.records; var html = "" records.forEach(function(row){ html += `<tr><td>${row.source}</td> <td>${row.title}</td></tr> `; }) var tbody_tag = $('tbody#table_body'); tbody_tag.html(html); }) }) controller class: public function ajax_lists(){ $data = array(); // store data in here, store all data you need in data $selected_input = $this->input->get('selected'); $selected_input2 = $this->input->get('selected_contact'); $data['records'] =$this->contacts_model->get_records($selected_input,$selected_input2); echo json_encode($data); } Model Class: function get_records($selected_input = null,$selected_input2 =null){ $this->db->select("*"); $this->db->from("crm_contacts as con"); if($selected_input){ $this->db->where("con.added_by",$selected_input); } if($selected_input2){ $this->db->where("con.contact_type",$selected_input2); } $query = $this->db->get(); return $query->result(); } Here as of now I can filter all my records 1 at a time. So suppose I filter the table by source and then inside that source I want to filter the leftover data by contact_type, I cannot do it since doing so resets the 1st filter I had and filters all the data according to the new select item I have clicked.
  9. I'm trying to store my database values in a session so that whenever user logs in I can access those session variables to get their name, id, etc. To achieve this I'm using the following code: Controller Class(login): $this->load->view('crm/login/index',$main); $clientdata=$this->login_model->get_row_cond($cond); $newdata = array( 'clientsessid' => $clientdata->clients_id, 'clientsessuserid' => $clientdata->id, 'clientsesskey' => $clientdata->client_key, 'clientsesusername' => $clientdata->username, 'clientsessemail' => $clientdata->email, 'client_loginid' => $loginid, 'client_logged_in' => TRUE ); $this->session->set_userdata($newdata); redirect('dashboard'); Model class: function get_row_cond($cond) { $this->db->where($cond); $query = $this->db->get($this->table_name); return $query->row(); } View class(dashboard): <?php var_dump( $this->session->userdata('clientsesusername')) ?> But doing so returns a NULL value after the user has logged in. And I've checked the database and the username for the particular person is filled.
  10. Yea but that's not how my structure works. In my table, listsreport shows the actual view class and ajaxleadsreport shows the data for a table inside that view class. So I have to pass the GET data from listsreport to ajaxleadsreport since GET data is only able to show up in listsreport
  11. I have 2 view classes called indexreport and ajaxleadsreport. ajaxleadsreport fetches all the data and displays it. Now I have a GET variable that is being passed to indexreport which I want to be able to pass it to ajaxleadsreport to filter the current data according to the GET variable that has been passed. Controller Class: public function listsreport($slug='') { $status1 = $this->input->get('status'); print_r($status1); $main['content']=$this->load->view('crm/leads/indexreport',$content,true); } public function ajaxleadsreport($p='') { $output = array( 'html'=>$this->load->view('crm/leads/ajaxleadsreport',$content, true)); echo json_encode($output); } To put in simple words I want status1 to go to ajaxleadsreport controller
  12. In my database, I have a id and title column where each title has a specific id, for example 1 is IT, 2 is Sales, etc. Now to show this in a table format I'm using the following code: View class: <?php foreach($groupedleads as $grplead){ $statuses[] = $status = $grplead["lead_status"]; if($grplead["title"] == NULL || $grplead["title"] == '') $grplead["title"] = "Unknown"; if(isset($grplead["title"])) $titles[] = $title = $grplead["title"]; $leaddata[$status][$title] = $grplead["leadnum"]; } <table> <?php if(is_array($titles)) foreach($titles as $title){ ?> <tr> <?php echo "<td>".$title."</td>"; foreach ($statuses as $status) { $num = $leaddata[$status][$title]; echo "<td><a target='_blank' href='" . site_url('reports/viewall?source=' . $title) . "'>".$num."</a></td>"; ?> </tr> </table> Controller Class: public function leadstatus($slug='') { $content['groupedleads'] = $this->leads_model->get_statusreport(); $this->load->view('crm/reports/leadstatus',$content); } Model Class: function get_statusreport($fdate='',$tdate='') { $this->db->select("l.lead_status,crm_sources.title,crm_sources.id,count(*) as leadnum"); $this->db->from($this->table_name." as l"); $this->db->join("crm_sources ","crm_sources.id= l.lead_source","left"); $query = $this->db->get(); $results = $query->result_array(); return $results; } Now I can see the titles for each of these in my table, but as of now these items under each title are clickable and lead to a different page. I use this code to get that href='" . site_url('reports/viewall?source='.$title). Now I actually want the id to be passed instead of the string value of title. So basically it has to look up from the database for the id of the particular items title that was clicked. When I write the following code for the first forloop, it returns the ids for all the items where currently the titles are residing: foreach($groupedleads as $grplead){ $statuses[] = $status = $grplead["lead_status"]; if($grplead["id"] == NULL || $grplead["id"] == '') $grplead["id"] = "Unknown"; if(isset($grplead["id"])) $titles[] = $id= $grplead["id"]; $leaddata[$status][$id] = $grplead["leadnum"]; } But I want the display to show it as title only, but the link should be replaced with the id instead of the title which it's currently showing.
  13. I'm currently passing values in my URL that I want to GET and insert in my controller class for filtering. My current URL looks something like this: http://localhost/reports/lists?source=Product1&status=4. Now to get the value of suppose source, I'm using the following code: let searchParams = new URLSearchParams(window.location.search); var status = searchParams.get('source'); Now I want this status variable to go to my controller class so that I can use it as 1 of my parameters for my model class: Full code: View Class: <?php $postd = json_encode(array_filter($post)); ?> <table id="item-list"> <tr> <th>Ref.No#</th> <th>Source</th> </tr> </table> <script> $(document).ready(function() { function sendreq(){ setpostdatas();cleartable();getleads(); } var userrole = "<?php echo $this->session->userdata('clientrole')?>"; var slug = '<?php echo $slug?>'; var postd = '<?php echo $postd; ?>'; if( userrole > 1 && userrole != 5){ $('#item-list').DataTable({ "processing": true, "stateSave": true, "serverSide": true, "ordering": false, "createdRow": function( row, data, dataIndex){ $(row).has( "div.overdueupdate" ).css('background-color','#FFC7CE'); }, "ajax": { url: "<?php echo site_url(); ?>reports/loadLeads", data: {slug: slug, postdata: postd}, type : 'POST', "dataSrc": function ( d ) { d.myKey = "myValue"; if(d.recordsTotal == 0 || d.data == null){ $("#item-list_info").text("No records found"); $("#item-list_processing").css("display","none"); } return d.data; } }, 'columns': [ {"data": "id", "id": "id"}, {"data": "refno", "refno": "refno"}, {"data": "source", "source": "source"}, ] }); } Controller Class: public function loadLeads($p=''){ $leadsource = $this->input->get('status'); if(isset($_POST['postdata'])){ if($_POST['postdata'] != null && $_POST['postdata'] != 'null'){ $post=$_POST['postdata']; } $post = json_decode($post,true); unset($post['slug']); unset($post['page']); $sort = $post['afsort']; if($sort == "asc"){ $sortQ = 'l.updated_date asc,'; }else if ($sort == "desc"){ $sortQ = 'l.updated_date desc,'; } } $offset = (int)$_POST['start'] ; $pstdatas = explode(',', $_POST['postdata']); unset($pstdatas['item-list_length']); if($this->session->userdata('clientrole') == 1 || $this->session->userdata('clientrole') == 5 ){ $content['leads']=$this->leads_model->get_pagination($_POST['length'],$offset,$where,'',false,$sortQ?$sortQ:'l.assign_status =\'Unassigned\' desc,',$all,$leadsource); }else{ $content['leads']=$this->leads_model->get_pagination($_POST['length'],$offset,$where,'',false,$sortQ?$sortQ:'l.assigned_date desc,',$all,$leadsource); } Now here in my controller class I want that AJAX variable to be passed so that I can use it my model query.
  14. The input field lets you autocomplete because the data is large.
  15. redirect_m is the name of my model class.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.