Friday, December 3, 2021

Any autocomplete box with select dropdown

 Any autocomplete dropdown, use this code

$(document).ready(function () {

    var orgid = "0";

    getSeverityList(orgid);

    var $advAutoComplete = $('#addForm87 input[name="orgs_id"]');

    $advAutoComplete.each(function()

    {

      var $el = $(this);

      $el.on( "autocompletechange", function( event, ui )

      {

          orgid = $(event.target).attr('data-selectedid');

          getSeverityList(orgid);

      });

    });

 });


Html is like this

<div style="" class="mui-textfield ui-front mui-col-md-6">
                                    <input name="orgs_id" class="autoCompCollAdv mui--is-empty ui-autocomplete-input mui--is-dirty" type="text" data-returnpropname="orgs_id" data-coll="12" data-alias="o" data-columns="{'ValueProperty':'_id', 'DisplayProperties':['_id','name'], 'FilterDBCols':['_id','name'], 'RunOnFocus':'true', 'Functions':{'Focus':'FocusFunc','Type':'TypeFunc'}, 'PermDBFilters':[] }" value="" data-modalid="addModel87" required="" data-dirty="0" data-selectedid="" autocomplete="off" data-oldval="">
                                    <label class="">Customer ID</label>
  </div>




run any ajax oj js function when bootstrap modal open

For any bootstrap modal open, these are by default class. These classes are not mention but this is worked.   

bs modal

These are default class.

js code for call when modal is open.

$(document).ready(function () {

$( '#editModel87' ).on('show.bs.modal', function(){

  //alert("I want this to appear after the modal has opened!");

  setTimeout(

    function() {

      var orgsid = $('#editForm87 input[name="orgs_id"]').attr('data-selectedid');

      var ticketId = $('#editForm87 input[name="key_id"]').val();

      getSeverityListEdit(orgsid,ticketId);

    }, 3000); // run after 3 seconds

  });

});


Tuesday, November 30, 2021

Marge more than two array (marge by datetime) and display it

 Hello

Here I display how to marge more than two array according to datetime and display it bind together.


public function getTicketChatData($ticketID) {
$noteList = $this->customersupportmodel->getUserTicketNotes($ticketID);
$notes = json_decode($noteList)->Data[0]->Results;
$notesCount = count($notes);

$docList = $this->customersupportmodel->getUserTicketDocs($ticketID);
$docs = json_decode($docList)->Data[0]->Results;
$docsCount = count($docs);

// get job_workflow_history data 
$flowList = $this->customersupportmodel->getJobWorkflowHistory($ticketID);
$flowSteps = json_decode($flowList)->Data[0]->Results;
$flowCount = count($flowSteps);
//end jwh
//echo " c:".$flowCount;

$doc_data = $note_data = $chatData = $flowData = $chatData1 = $chatData2 = [];
if ( $notesCount > 0) {
foreach($notes as $n) {
$note_data[] = [
'type' => 1,
'date' => date('Y-m-d H:i:s', strtotime($n->key_update_date)),
'data' => $n
];
}
}
if ($docsCount > 0 ) {
foreach($docs as $d) {
$doc_data[] = [
'type' => 2,
'date' => date('Y-m-d H:i:s', strtotime($d->key_update_date)),
'data' => $d
];
}
}
if ($flowCount > 0 ) {
foreach($flowSteps as $f) {
$flowData[] = [
'type' => 3,
'date' => date('Y-m-d H:i:s', strtotime($f->key_update_date)),
'data' => $f
];
}
}

//echo "<pre>";print_r($flowData);

$chatData1 = array_merge($note_data, $doc_data);
uasort($chatData1, function ($a, $b) {
    return $a['date'] <=> $b['date'];
});

$chatData = array_merge($chatData1, $flowData);
uasort($chatData, function ($a, $b) {
    return $a['date'] <=> $b['date'];
});

return $chatData;
}


//now display it in view file



$noteHtml = '';
$loggedUserId = $this->session->userdata('UserID');
//echo $countDocNote = count($Notes);
$isDocStart = false;
$countDocNote = count($chatData);
    if ($countDocNote > 0) {
      foreach ($chatData as $key => $notesDocsData) {
        //echo "<pre>"; print_r($notesDocsData);
        $newUser = $notesDocsData['data']->userID;
        $create_by = $notesDocsData['data']->create_by;
        $type = $notesDocsData['type'];

        //$userFirstLetter = strtoupper($notesDocsData['data']->username[0]);

        if($type == 1){
          //echo "notes-"; // for notes
          if ($isDocStart) {
            $noteHtml.= "</div></div>";
            $isDocStart = false;
          }
          $note = $notesDocsData['data']->Note;
          $noteID = $notesDocsData['data']->NoteId;
          $notesCreateDate = $notesDocsData['data']->create_date;
          $notesdate =  date("M j, Y",strtotime($notesCreateDate)); 
          //$created_by_date = date("j M Y",strtotime($notesCreateDate)); 
          $newTimeForNote = new DateTime($notesCreateDate);
          $noteTime = $newTimeForNote->format("h:i a");
          $taskdate =  date("M j, Y",strtotime($notesCreateDate)); 
          //$newTime = new DateTime($taskdate);
          //$taskTime = $newTime->format("h:i a");
          //start display_name
          $fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          $displayName = $notesDocsData['data']->display_name;
          if ($displayName == "") {
            $display_name = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          }elseif ($notesDocsData['data']->name_first == "" && $notesDocsData['data']->name_last == "") {
            $display_name = $notesDocsData['data']->username;
          }else{
            $display_name = $notesDocsData['data']->display_name;
          }
          $userFirstLetter = strtoupper($display_name[0]);
          //end dsiplay_name

          //if(empty($notesDocsData['data']->org_id)){
          //if($notesDocsData['data']->org_id == 0){ // customer right side support left side
          if($loggedUserId == $create_by) { // logged user chat is right side
            $chatClass = "bsit_chat_user";
          }else{
            $chatClass = "bsit_chat_support";
          }
          $noteHtml.= "<div class='$chatClass'> <div class='bsit_chat_section' id='div_$noteID' >";
            $noteHtml.= "<div class='bsit_chat_user_name'><span>".$userFirstLetter."</span>".$display_name."</div>";
            $noteHtml.= "<div class='bsit_chat_detail'> ".$note." <span class='bsit_chat_time'>".$taskdate." | ".$noteTime."</span></div>";
            //echo "<div class='bsit_chat_attachment'><img src='".base_url()."assets/core/images/attachment_chat.png'>(static)GoogleCloudPrinting.png</div>";
          $noteHtml.= "</div></div>";

        }elseif($type == 2){
          //echo "doc-";// display documents/ attachment
          //$fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          //start display_name
          $fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          $displayName = $notesDocsData['data']->display_name;
          if ($displayName == "") {
            $display_name = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          }elseif ($notesDocsData['data']->name_first == "" && $notesDocsData['data']->name_last == "") {
            $display_name = $notesDocsData['data']->username;
          }else{
            $display_name = $notesDocsData['data']->display_name;
          }
          $userFirstLetter = strtoupper($display_name[0]);
          //end dsiplay_name

          $notesCreateDate = $notesDocsData['data']->create_date;
          $newTimeForNote = new DateTime($notesCreateDate);
          //$notesdate =  date("M j, Y",strtotime($notesCreateDate)); 
          $noteTime = $newTimeForNote->format("h:i a");
          $taskdate =  date("M j, Y",strtotime($notesCreateDate));
          $a_id = $notesDocsData['data']->_id;
          $file_name = $notesDocsData['data']->file_name;
          $file_location = $notesDocsData['data']->file_location;
          $file_update_date = $notesDocsData['data']->key_update_date;
          //if(empty($notesDocsData['data']->org_id)){
          if($loggedUserId == $create_by) { // logged user chat is right side
            $chatClass = "bsit_chat_user";
          }else{
            $chatClass = "bsit_chat_support";
          }
          $documentDownloalLink = base_url()."page/downloadDocument?docid=".$a_id;
          if ($isDocStart && $newUser != $oldUser) {
            $noteHtml.= "</div></div>";
            $isDocStart = false;
          }
          if ($isDocStart == false) {
            $isDocStart = true;
            $noteHtml.= "<div class='$chatClass'> <div class='bsit_chat_section' id='div_$a_id' >";
            $noteHtml.= "<div class='bsit_chat_user_name'><span>".$userFirstLetter."</span>".$display_name."</div>";
          }
          
          $noteHtml.= "<div class='bsit_chat_attachment'><div class='attchment'><a href='".$documentDownloalLink."' title='Attachment' target='_blank'> <img src='".base_url()."assets/core/images/attachment_chat.png'>$file_name</a> </div><span class='bsit_chat_time'>".$taskdate." | ".$noteTime."</span></div>"; 
        }elseif($type == 3){
          //$fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          //start display_name
          $fullname = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          $displayName = $notesDocsData['data']->display_name;
          if ($displayName == "") {
            $display_name = $notesDocsData['data']->name_first." ".$notesDocsData['data']->name_last;
          }elseif ($notesDocsData['data']->name_first == "" && $notesDocsData['data']->name_last == "") {
            $display_name = $notesDocsData['data']->username;
          }else{
            $display_name = $notesDocsData['data']->display_name;
          }
          $userFirstLetter = strtoupper($display_name[0]);
          //end dsiplay_name

          $notesCreateDate = $notesDocsData['data']->create_date;
          $newTimeForNote = new DateTime($notesCreateDate);
          //$notesdate =  date("M j, Y",strtotime($notesCreateDate)); 
          $noteTime = $newTimeForNote->format("h:i a");
          $taskdate =  date("j M Y",strtotime($notesCreateDate));
          $file_update_date = $notesDocsData['data']->key_update_date;
          $status_title = $notesDocsData['data']->status_title;
          if($status_title == 'Complete'){
            $noteHtml.="<div class='bsit_ticket_close_chat ticketComplete'><span>This ticket is closed by $display_name on $taskdate</span></div>";
          }elseif ($status_title == 'reopen') {
            $noteHtml.="<div class='bsit_ticket_status_chat ticketReOpen'><span>Reopen by $display_name on $taskdate</span></div>";
          }elseif ($status_title == 'Assigned'){
            $noteHtml.="<div class='bsit_ticket_status_chat ticketAccepted'><span>Assigned to $display_name on $taskdate</span></div>";
          }else{
            $noteHtml.="<div class='bsit_ticket_status_chat ticketNormal'><span>$status_title to $display_name on $taskdate</span></div>";
          }
          
        }
        $oldUser = $newUser;
      }
      if ($isDocStart) {
        $noteHtml.= "</div></div>";
        $isDocStart = false;
      }       
      
    }else{
      $noteHtml.= "<div class='noAnyNotesMainDiv'><span>This Ticket has no any notes or attachment!!!</span></div>";
    }
echo $noteHtml;

Friday, November 26, 2021

php pass variable to one page to another

 There are many ways for pass variable value to another page.


1 : GET and POST

You can pass variable value with url. 

header("Location: ../signup.php?newpwd=passwordupdated");
login.php?id=123&username=user

You can add the variable in the link to the next page:

<a href="page2.php?varname=<?php echo $var_value ?>">Page2</a>

This will create a GET variable.

Another way is to include a hidden field in a form that submits to page two:

<form method="get" action="page2.php">
    <input type="hidden" name="varname" value="var_value">
    <input type="submit">
</form>

And then on page two:

//Using GET
$var_value = $_GET['varname'];

//Using POST
$var_value = $_POST['varname'];

//Using GET, POST or COOKIE.
$var_value = $_REQUEST['varname'];

Just change the method for the form to post if you want to do it via post. Both are equally insecure, although GET is easier to hack.

The fact that each new request is, except for session data, a totally new instance of the script caught me when I first started coding in PHP. Once you get used to it, it's quite simple though.

2 : Session:

//On page 1
$_SESSION['varname'] = $var_value;

//On page 2
$var_value = $_SESSION['varname'];

Remember to run the session_start(); statement on both these pages before you try to access the $_SESSION array, and also before any output is sent to the browser.


3 : Cookie:

//One page 1
$_COOKIE['varname'] = $var_value;

//On page 2
$var_value = $_COOKIE['varname'];

The big difference between sessions and cookies is that the value of the variable will be stored on the server if you're using sessions, and on the client if you're using cookies. I can't think of any good reason to use cookies instead of sessions, except if you want data to persist between sessions, but even then it's perhaps better to store it in a DB, and retrieve it based on a username or id.


4 : In MVC (Like Codeigniter):

In mvc, you can pass value in easy way.


<?php $this->load->view('jobs_notes_list', ['activity_history' => $activity_history , 'job_id' => $job_id]);?>

Thursday, August 26, 2021

Fetch data from array using index key name

 After a long time I write a post.

See this array :-

$data = array (

    "key 1" => "a bc",

    "key 2" => array ("sub 1" => "ab c", "sub 2" => "def"),

    "key 3" => "gh i"

);

key name is with some space. So you can not use it directly by its key name.

One solution:-

foreach ($load_data as $key=>$value) {

                $fname = $value->{"First Name"};

$lname = $value->{"Last Name"};

}

you can use curly brackets {} with "" double quote.

Second method:-

function fixArrayKey(&$arr)

{

    $arr = array_combine(

        array_map(

            function ($str) {

                return str_replace(" ", "_", $str);

            },

            array_keys($arr)

        ),

        array_values($arr)

    );


    foreach ($arr as $key => $val) {

        if (is_array($val)) {

            fixArrayKey($arr[$key]);

        }

    }

}


$data = array (

    "key 1" => "a bc",

    "key 2" => array ("sub 1" => "ab c", "sub 2" => "def"),

    "key 3" => "gh i"

);

echo "<pre>";print_r($data);echo "</pre>";

echo "<hr>";


fixArrayKey($data); 


echo "<pre>";print_r($data); echo "</pre>";