<?php
require_once('include/MVC/View/views/view.edit.php');
require_once('modules/Iframeapp/Forms.php');
require_once('modules/Iframeapp/Iframeapp.php');

class IframeappViewEdit extends ViewEdit {

  // remove the payload from preDisplay() to ensure nothing from a normal edit
  // view is rendered
  public function preDisplay() {}

  public function display() {

    // load current values or defaults
    global $sugar_config;
    $iframe_src = Iframeapp::get_config_url();
    $iframe_height = Iframeapp::get_config_height();

    $this->ss->assign('IFRAME_HEIGHT', $iframe_height);

    if($iframe_src != '') {
      $iframe_src .= Iframeapp::get_url_ts();
      $iframe_src .= Iframeapp::get_module_version();
      $iframe_src .= '&suid=' . $GLOBALS['current_user']->id;
      if(isset($_REQUEST['i25pg'])) {

        // mapping Campaign Wizard URLs to INBOX25 iframe paths
        $inbox25_urls = array(
          'wizardtype_inbox25_email_blast' => 'send1.php',
          'wizardtype_inbox25_drip_campaign' => 'drip_campaigns.php#new',
          'wizardtype_inbox25_social_campaign' => 'social_connect.php#new',
          'wizardtype_inbox25_automated_journey' => 'automation_manager.php',
          'report_ma_outbound_emails.php' => 'report_ma_outbound_emails.php?filter1=m-0',
          'report_ma_traffic_sources.php' => 'report_ma_traffic_sources.php?filter1=m-0',
        );
        if(isset($_REQUEST['i25pg']) && isset($inbox25_urls[$_REQUEST['i25pg']])) {
          $i25pg = $inbox25_urls[$_REQUEST['i25pg']];
        }
        else {
          $i25pg = $_REQUEST['i25pg'];
        }

        $iframe_src .= '&i25pg=' . $i25pg;
      }
      $this->ss->assign('IFRAME_SRC', $iframe_src);
    }
    else {
      $this->ss->assign('IFRAME_SRC', 'https://app.inbox25.com/inbox25_module.php');
    }

    echo $this->getModuleTitle();
    $this->ss->display('modules/Iframeapp/tpls/EditView.tpl');
  }
}
