Craig Tucker

Forum Replies Created

Viewing 13 posts - 16 through 28 (of 28 total)
  • Author
    Posts
  • in reply to: Revive deleted string #6452
    Craig Tucker
    Participant

    A better method perhaps:

    
    			$participants = fep_get_participants( $post->post_parent );
    	
    			foreach( $participants as $participant ) 
    			{
    				$query ="SELECT meta_id FROM wp_postmeta WHERE post_id = %s and <code>meta_key</code> = '_fep_delete_by_%s'";
    
    				$queryp1 = $wpdb->prepare($query, array($post->post_parent, $participant));
    				if (!empty($queryp1)) {
    					delete_post_meta($queryp1,'_fep_delete_by_' . $participant);	
    				}	
    			}
    
    in reply to: Revive deleted string #6441
    Craig Tucker
    Participant

    I said string when I should have said thread but I think you can get the idea.

    in reply to: Disable Email for One Message #6434
    Craig Tucker
    Participant

    Works great. Thanks so much.

    in reply to: Toggle Messages #6430
    Craig Tucker
    Participant

    Sounds great. I suppose I could just put it in a child theme. I should do that.

    in reply to: Toggle Messages #6414
    Craig Tucker
    Participant

    It would be nice to have this as an option in settings. I was trying to do this with a custom CSS but it is unreliable. Eg:

    div.fep-message-content.fep-message-content-2258.fep-hide-if-js{
    display: block !important;
    }

    Removing line 17 works better but will be lost on update.

    Custom CSS will last through the update but is not so good.

    in reply to: Insert Message from another application #6411
    Craig Tucker
    Participant

    Thanks. I have updated my file on github to include a new routine for multiple admins.

    in reply to: Insert Message from another application #6393
    Craig Tucker
    Participant

    I found another issue. I need to fix the method for verifying authorized admins. The variable $admin_user_login with Cartpauj PM was associated this wise:

    
    $adminOps = get_option('cartpaujPM_options');
    $admin_user_login = $adminOps['admin_user_login'];
    

    In Cartpauj PM there is only one admin so this is straightforward. But in Frontend PM you can have multiple authorized admins. So I need to develop a different procedure to verify authorized admins. I see you have a function “fep_get_option”. Can I use this to return an array of the ‘username’ entries for admins entered? If so how? With this array I can check if wp_authenticate($_REQUEST['login'] is in the array. That should work.

    in reply to: Insert Message from another application #6375
    Craig Tucker
    Participant

    Sorry I was not clear about where I needed the attachment. I do not need it with the message so my method has worked fine. So, to integrate with OpenEMR and the Sunset Patient Portal I made the following modifications to the webserve.php file:

    https://github.com/CraigT543/Sunset-Patient-Portal-with-FrontendPM/blob/master/FrontendPMmods.php

    This works to replace cartpauj-pm with Frontend PM as the messaging application for OpenEMR.

    in reply to: Insert Message from another application #6301
    Craig Tucker
    Participant

    No that was not it. I could not get the fep_action_message_after_send hook to work in this location. It would not trigger after several different approaches. My work around has been this:

    `
    function action_putmessage( $args ) {
    global $out, $admin_user_login;

    if( ! function_exists( ‘fep_send_message’ ) )
    return false;

    $sender = fep_get_userdata( $admin_user_login, ‘ID’, ‘login’ );

    if (!$sender) {
    $out[‘errmsg’] = “No such sender ‘$admin_user_login'”;
    return false;
    }
    $recipient = fep_get_userdata( $args[‘user’], ‘ID’, ‘login’ );
    if (!$recipient) {
    $out[‘errmsg’] = “No such recipient ‘{$args[‘user’]}'”;
    return false;
    }
    $message = array(
    ‘message_title’ => $args[‘title’],
    ‘message_content’ => $args[‘message’],
    ‘message_to_id’ => $recipient,
    );
    $override = array(
    ‘post_author’ => $sender,
    );
    $message_id = fep_send_message( $message, $override );

    $upload_dir = wp_upload_dir();
    $upload_dir = $upload_dir[‘basedir’];
    $subdir = ”;
    if ( get_option( ‘uploads_use_yearmonth_folders’ ) ) {
    $time = current_time( ‘mysql’ );

    $y = substr( $time, 0, 4 );
    $m = substr( $time, 5, 2 );

    $subdir = “/$y/$m”;
    }
    $upsub = ‘/front-end-pm’ . $subdir;
    $filename = $args[‘filename’];
    $newfilename = wp_unique_filename( $upload_dir, $filename );
    $pathtofile = $upload_dir . $upsub . ‘/’ . $newfilename;
    $content = isset( $args[‘contents’] ) ? base64_decode($args[‘contents’]) : ”;

    $size_limit = (int) wp_convert_hr_to_bytes(fep_get_option(‘attachment_size’,’4MB’));
    $size = strlen( $content );
    if( $size > $size_limit )
    return false;

    $mime = isset( $args[‘mimetype’] ) ? $args[‘mimetype’] : ”;
    if( !$mime || !in_array( $mime, get_allowed_mime_types() ) )
    return false;

    file_put_contents($pathtofile, $content);

    $attachment = array(
    ‘guid’ => $pathtofile,
    ‘post_mime_type’ => $args[‘mimetype’],
    ‘post_title’ => preg_replace(‘/\.[^.]+$/’, ”, basename($pathtofile)),
    ‘post_content’ => ”,
    ‘post_author’ => $sender,
    ‘post_status’ => ‘inherit’,

    );

    $attach_id = wp_insert_attachment( $attachment, $pathtofile, $message_id );

    }

    I think it includes all the necessary checks. Can you see anything wrong with working this way? Everything works as it is. Do you have any concerns?

    in reply to: Insert Message from another application #6212
    Craig Tucker
    Participant

    Thanks, I tried it out. The email and post work fine but the attachment is not found and did not download to the server and did not show up on the post. I see what you are trying to do. I will try to fish out the problem. Thanks so much for taking the time to do this.

    Craig

    in reply to: Insert Message from another application #6169
    Craig Tucker
    Participant

    Yes, sender is always admin_user_login and it is the login user name for wordpress the recipient is always $args[‘user’] and it is the login user name for wordpress. The function they are sent to is,

    
    function convertToID($login) {
      global $wpdb;
      $result = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->users} WHERE user_login = %s", $login));
      if (!empty($result)) return $result;
      return 0;
    }
    
    

    This is built for one attachment only.
    The mimetype is already defined in $args['mimetype'] . Thanks for your patience with me on this.

    Craig

    in reply to: Insert Message from another application #6151
    Craig Tucker
    Participant

    I am sorry. I am having a hard time figuring out your functions. fep_send_message() works fine but I need to do the attachments. I am not sure of email piping would be a good work around. I am trying to stay completely on the server for this so no patient data goes out over the internet. I may be misunderstanding what you were suggesting however. So to get the job done I just did this because I can understand the wordpress stuff:

    
    // Logic to process the "putmessage" action.
    // Sends a message to the designated user with an optional attachment.
    // FrontendPM version
    function action_putmessage(&$args) {
      global $wpdb, $out, $admin_user_login;
      $sender = convertToID($admin_user_login);
      if (!$sender) {
        $out['errmsg'] = "No such sender '$admin_user_login'";
        return;
      }
      $recipient = convertToID($args['user']);
      if (!$recipient) {
        $out['errmsg'] = "No such recipient '{$args['user']}'";
        return;
      }
    
    	$year = date('Y');
    	$month = date('m');
    	$timestamp = idate("U"); 
    	$upload_dir =  ABSPATH . "wp-content/uploads/front-end-pm/" . $year . "/" . $month ;
    	if (!file_exists($upload_dir)) {
    		mkdir($upload_dir, 0755, true);
    	}	
    	$filename = $args['filename'];
    	$newfilename = wp_unique_filename( $upload_dir, $filename );
    	$pathtofile = $upload_dir . '/' . $newfilename;
    	file_put_contents($pathtofile, base64_decode($args['contents']));
    	
    	$postarr = array(
    	 'post_status' => 'publish',
    	 'post_type' => 'post',
    	 'post_title' => $args['title'],
    	 'post_content' => $args['message'],
    	 'post_author' => $sender,
    	 'post_type' => 'fep_message', 
    	 );
    	 
    	$parent_post_id = wp_insert_post($postarr);
    
    	add_post_meta( $parent_post_id, '_fep_participants', $sender);	
    	add_post_meta( $parent_post_id, '_fep_participants', $recipient);	
    	add_post_meta( $parent_post_id, '_fep_parent_read_by_' .$sender , $timestamp);	
    	add_post_meta( $parent_post_id, '_fep_last_reply_time', $timestamp);	
    	add_post_meta( $parent_post_id, '_fep_last_reply_id', parent_post_id);
    	add_post_meta( $parent_post_id, '_fep_last_reply_by', $sender);
    	
    	if(!$parent_post_id) {
    		$out['errmsg'] = "Message insert failed";
    		return;
    	}
    
    	$attachment = array(
    	 'post_author' => $sender,
    	 'post_mime_type' => $args['mimetype'],
    	 'post_title' => preg_replace('/\.[^.]+$/', '', basename($pathtofile)),
    	 'post_content' => '',
    	 'post_status' => 'inherit',
    	 'guid' => $pathtofile,
    	);
    	
    	$attach_id = wp_insert_attachment( $attachment, $pathtofile, $parent_post_id );
    	
    	require_once( ABSPATH . 'wp-admin/includes/image.php' );
    	$attach_data = wp_generate_attachment_metadata( $attach_id, $pathtofile );
    	wp_update_attachment_metadata( $attach_id, $attach_data );
    		
    	if ($attach_id === false) {
    	  $out['errmsg'] = "Attachment insert failed";
    	}
    }
    
    

    This works to input the post and file. I would like to trigger an email. If you have concerns about me submitting messages and attachments this way let me know. If you have a method I may be able to add to trigger your email functions let me know that. Otherwise I will write a phpmailer thing to get the job done. With this I am about 95% done with the OpenEMR interface. I will put it out on Github when it is all done.

    in reply to: Insert Message from another application #6142
    Craig Tucker
    Participant

    I do not see how I can send attachments with fep_send_message(). Is this possible?

Viewing 13 posts - 16 through 28 (of 28 total)