public static function uninstall()
 {
     //loading data lib
     require_once self::get_base_path() . "/data.php";
     if (!GFZapier::has_access("gravityforms_zapier_uninstall")) {
         die(__("You don't have adequate permission to uninstall the Zapier Add-On.", "gravityformszapier"));
     }
     //droping all tables
     GFZapierData::drop_tables();
     //removing options
     delete_option("gf_zapier_settings");
     delete_option("gf_zapier_version");
     //Deactivating plugin
     $plugin = "gravityformszapier/zapier.php";
     deactivate_plugins($plugin);
     update_option('recently_activated', array($plugin => time()) + (array) get_option('recently_activated'));
 }
 private function addGFEntry($leadUserInfo, $gFormId)
 {
     // add entry
     $entry = array("form_id" => $gFormId);
     foreach ($leadUserInfo['field_data'] as $leadField) {
         if (null != ($mappedFieldId = $this->getMappedFieldId($leadField['name'], $gFormId))) {
             $entry[$mappedFieldId] = $leadField['values'][0];
         }
     }
     // Adding hidden fields with default values presented
     $gfForm = GFAPI::get_form($gFormId);
     if (!empty($gfForm['fields'])) {
         foreach ($gfForm['fields'] as $field) {
             if ($field->type == 'hidden' && $field->defaultValue != '') {
                 $entry[$field->id] = $field->defaultValue;
             }
         }
     }
     $entryId = GFAPI::add_entry($entry);
     // Force trigger MailChimp plugin
     if (class_exists('GFMailChimp')) {
         $mailchimp = GFMailChimp::get_instance();
         $gfForm = GFAPI::get_form($gFormId);
         $mailchimp->maybe_process_feed($entry, $gfForm);
     }
     // Force trigger Zapier plugin
     if (class_exists('GFZapier')) {
         $gfForm = GFAPI::get_form($gFormId);
         GFZapier::send_form_data_to_zapier($entry, $gfForm);
     }
     // send notifications
     $this->sendNotifications($gFormId, $entryId);
 }
 function process_feed($feed)
 {
     $form = $this->get_form();
     $entry = $this->get_entry();
     GFZapier::send_form_data_to_zapier($entry, $form);
 }
 function process_add_on_feed($feed_add_on, $feed)
 {
     $form = $this->get_form();
     $entry = $this->get_entry();
     if (is_subclass_of($feed_add_on['class'], 'GFFeedAddOn')) {
         $add_on = call_user_func(array($feed_add_on['class'], 'get_instance'));
         $add_on->process_feed($feed, $entry, $form);
     } else {
         // Legacy add-ons
         switch ($feed_add_on['slug']) {
             case 'gravityformszapier':
                 if (class_exists('GFZapier')) {
                     GFZapier::send_form_data_to_zapier($entry, $form);
                 }
                 break;
             case 'gravityformsuserregistration':
                 if (class_exists('GFUser')) {
                     GFUser::gf_create_user($entry, $form);
                 }
                 break;
         }
     }
 }
    function entry_detail_approval_box($form, $entry)
    {
        global $current_user;
        if (!isset($entry['approval_status'])) {
            return;
        }
        if (isset($_POST['gf_approvals_status']) && check_admin_referer('gf_approvals')) {
            $new_status = $_POST['gf_approvals_status'];
            gform_update_meta($entry['id'], 'approval_status_' . $current_user->ID, $new_status);
            $entry['approval_status_' . $current_user->ID] = $new_status;
            $entry_approved = true;
            $entry_rejected = false;
            foreach ($this->get_feeds($form['id']) as $feed) {
                if ($feed['is_active'] && $this->is_feed_condition_met($feed, $form, $entry)) {
                    $approver = $feed['meta']['approver'];
                    if (!empty($entry['approval_status_' . $approver])) {
                        if ($entry['approval_status_' . $approver] != 'approved') {
                            $entry_approved = false;
                        }
                        if ($new_status == 'rejected') {
                            $entry_rejected = true;
                        }
                    }
                }
            }
            if ($entry_rejected) {
                gform_update_meta($entry['id'], 'approval_status', 'rejected');
                $entry['approval_status'] = 'rejected';
                do_action('gform_approvals_entry_rejected', $entry, $form);
            } elseif ($entry_approved) {
                gform_update_meta($entry['id'], 'approval_status', 'approved');
                $entry['approval_status'] = 'approved';
                // Integration with the User Registration Add-On
                if (class_exists('GFUser')) {
                    GFUser::gf_create_user($entry, $form);
                }
                // Integration with the Zapier Add-On
                if (class_exists('GFZapier')) {
                    GFZapier::send_form_data_to_zapier($entry, $form);
                }
                do_action('gform_approvals_entry_approved', $entry, $form);
            }
            $notifications_to_send = GFCommon::get_notifications_to_send('form_approval', $form, $entry);
            foreach ($notifications_to_send as $notification) {
                GFCommon::send_notification($notification, $form, $entry);
            }
        }
        $status = __('Pending Approval', 'gravityformsapprovals');
        $approve_icon = '<i class="fa fa-check" style="color:green"></i>';
        $reject_icon = '<i class="fa fa-times" style="color:red"></i>';
        if ($entry['approval_status'] == 'approved') {
            $status = $approve_icon . ' ' . __('Approved', 'gravityformsapprovals');
        } elseif ($entry['approval_status'] == 'rejected') {
            $status = $reject_icon . ' ' . __('Rejected', 'gravityformsapprovals');
        }
        ?>
		<div class="postbox">
			<h3><?php 
        echo $status;
        ?>
</h3>

			<div style="padding:10px;">
				<ul>
					<?php 
        $has_been_approved = false;
        $current_user_is_approver = false;
        foreach ($this->get_feeds($form['id']) as $feed) {
            if ($feed['is_active']) {
                $approver = $feed['meta']['approver'];
                if ($feed['is_active'] && $this->is_feed_condition_met($feed, $form, $entry)) {
                    $user_info = get_user_by('id', $approver);
                    $status = $entry['approval_status_' . $approver];
                    if ($status === false) {
                        $status = 'pending';
                    } elseif ($status != 'pending') {
                        $has_been_approved = true;
                    }
                    if ($status === false || $status == 'pending') {
                        if ($current_user->ID == $approver) {
                            $current_user_is_approver = true;
                        }
                    }
                    echo '<li>' . $user_info->display_name . ': ' . $status . '</li>';
                }
            }
        }
        if ($has_been_approved) {
            add_action('gform_entrydetail_update_button', array($this, 'remove_entrydetail_update_button'), 10);
        }
        ?>
				</ul>
				<div>
					<?php 
        if ($current_user_is_approver) {
            ?>
						<form method="post" id="sidebar_form" enctype='multipart/form-data'>
							<?php 
            wp_nonce_field('gf_approvals');
            ?>
							<button name="gf_approvals_status" value="approved" type="submit" class="button">
								<?php 
            echo $approve_icon;
            ?>
 <?php 
            _e('Approve', 'gravityformsapprovals');
            ?>
							</button>
							<button name="gf_approvals_status" value="rejected" type="submit" class="button">
								<?php 
            echo $reject_icon;
            ?>
 <?php 
            _e('Reject', 'gravityformsapprovals');
            ?>
							</button>
						</form>
					<?php 
        }
        ?>
				</div>
			</div>
		</div>
	<?php 
    }
 public function trigger_workflow_complete($form, $entry)
 {
     // Integration with the User Registration Add-On
     if (class_exists('GFUser')) {
         GFUser::gf_create_user($entry, $form);
     }
     // Integration with the Zapier Add-On
     if (class_exists('GFZapier')) {
         GFZapier::send_form_data_to_zapier($entry, $form);
     }
     GFAPI::send_notifications($form, $entry, 'workflow_complete');
 }