function display()
 {
     global $mod_strings, $timedate, $app_strings;
     include_once 'modules/Reports/schedule/save_schedule.php';
     $smarty = new Sugar_Smarty();
     $smarty->assign('MOD', $mod_strings);
     $smarty->assign('APP', $app_strings);
     $smarty->assign('PAGE_TITLE', getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_SCHEDULE_EMAIL']), false));
     $smarty->assign('STYLESHEET', SugarThemeRegistry::current()->getCSS());
     $smarty->assign("CALENDAR_LANG", substr($GLOBALS['current_language'], 0, 2));
     $smarty->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
     $smarty->assign("PRINT_URL", "index.php?" . $GLOBALS['request_string']);
     $smarty->assign("RECORD", $_REQUEST['id']);
     $cache_dir = !empty($GLOBALS['sugar_config']['cache_dir']) ? rtrim($GLOBALS['sugar_config']['cache_dir'], '/\\') : 'cache';
     $smarty->assign('CACHE_DIR', $cache_dir);
     $refreshPage = isset($_REQUEST['refreshPage']) ? $_REQUEST['refreshPage'] : "true";
     $smarty->assign("REFRESH_PAGE", $refreshPage);
     $time_interval_select = translate('DROPDOWN_SCHEDULE_INTERVALS', 'Reports');
     $time_format = $timedate->get_user_time_format();
     $smarty->assign("TIME_FORMAT", $time_format);
     $smarty->assign("TIMEDATE_JS", self::getJavascriptValidation());
     require_once 'modules/Reports/schedule/ReportSchedule.php';
     $rs = new ReportSchedule();
     $schedule = $rs->get_report_schedule_for_user($_REQUEST['id']);
     if ($schedule) {
         $smarty->assign('SCHEDULE_ID', $schedule['id']);
         $smarty->assign('DATE_START', $timedate->to_display_date_time($schedule['date_start'], true));
         if ($schedule['active']) {
             $smarty->assign('SCHEDULE_ACTIVE_CHECKED', 'checked');
         }
         $smarty->assign('NEXT_RUN', $timedate->to_display_date_time($schedule['next_run']));
         $smarty->assign('TIME_INTERVAL_SELECT', get_select_options_with_id($time_interval_select, $schedule['time_interval']));
         $smarty->assign('SCHEDULE_TYPE', $schedule['schedule_type']);
     } else {
         $smarty->assign('NEXT_RUN', $mod_strings['LBL_NONE']);
         $smarty->assign('TIME_INTERVAL_SELECT', get_select_options_with_id($time_interval_select, ''));
         if (isset($_REQUEST['schedule_type']) && $_REQUEST['schedule_type'] != "") {
             $smarty->assign('SCHEDULE_TYPE', $_REQUEST['schedule_type']);
         }
     }
     $smarty->assign('CURRENT_LANGUAGE', $GLOBALS['current_language']);
     $smarty->assign('JS_VERSION', $GLOBALS['js_version_key']);
     $smarty->assign('JS_CUSTOM_VERSION', $GLOBALS['sugar_config']['js_custom_version']);
     $smarty->assign('JS_LANGUAGE_VERSION', $GLOBALS['sugar_config']['js_lang_version']);
     //$this->_displayJavascript();
     $html = $smarty->fetch('modules/Reports/tpls/AddSchedule.tpl');
     echo $html;
 }
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
$modListHeader = array();
require_once 'modules/Reports/schedule/ReportSchedule.php';
require_once 'modules/Reports/utils.php';
require_once 'include/modules.php';
require_once 'config.php';
/** @var Localization $locale */
global $sugar_config, $current_language, $app_list_strings, $app_strings, $locale, $timedate;
$language = $sugar_config['default_language'];
// here we'd better use English, because pdf coding problem.
$app_list_strings = return_app_list_strings_language($language);
$app_strings = return_application_language($language);
$reportSchedule = new ReportSchedule();
$reportSchedule->handleFailedReports();
$reportsToEmail = $reportSchedule->get_reports_to_email();
//Process Enterprise Schedule reports via CSV
//bug: 23934 - enable Advanced reports
require_once 'modules/ReportMaker/process_scheduled.php';
global $report_modules, $modListHeader, $current_user;
$queue = new SugarJobQueue();
foreach ($reportsToEmail as $scheduleInfo) {
    $job = BeanFactory::getBean('SchedulersJobs');
    $job->name = 'Send Scheduled Report ' . $scheduleInfo['report_id'];
    $job->assigned_user_id = $scheduleInfo['user_id'];
    $job->target = 'class::SugarJobSendScheduledReport';
    $job->data = $scheduleInfo['id'];
    $job->job_group = $scheduleInfo['report_id'];
    $queue->submitJob($job);
    die('Not A Valid Entry Point');
}
/*
 * Your installation or use of this SugarCRM file is subject to the applicable
 * terms available at
 * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
if (!empty($_REQUEST['save_schedule_msi'])) {
    global $current_user, $timedate, $app_strings;
    require_once 'modules/Reports/schedule/ReportSchedule.php';
    $rs = new ReportSchedule();
    global $timedate;
    if (!empty($_REQUEST['schedule_id'])) {
        $id = $_REQUEST['schedule_id'];
    } else {
        $id = '';
    }
    if (!empty($_REQUEST['date_start'])) {
        $date_start = $timedate->to_db($_REQUEST['date_start'], true);
    } else {
        $date_start = '';
    }
    if (!empty($_REQUEST['schedule_active'])) {
        $active = 1;
    } else {
        $active = 0;
function template_reports_saved(&$args)
{
    global $current_user, $modules_report, $mod_strings, $modListHeader, $my_report_titles, $published_report_titles, $app_list_strings;
    $module_value = '';
    // grab information for tab access to show only reports relative to modules a user has access to
    if (isset($current_user)) {
        require_once 'modules/MySettings/TabController.php';
        $tabs = new TabController();
        $tabArray = $tabs->get_user_tabs($current_user);
    }
    if ($args['type'] == 'my') {
        $title = $mod_strings['LBL_MY_SAVED_REPORTS'];
        $query_arr = array('assigned_user_id' => $current_user->id, 'is_published' => 'no');
        $order_by = 'module,report_type,name';
        if (isset($args['module']) && $args['module'] != 'All') {
            $module_value = 'value="' . $modules_report[$args['module']] . '"';
            $title = $my_report_titles[$args['module']];
            $query_arr['module'] = $args['module'];
        }
    } else {
        $title = $mod_strings['LBL_ALL_PUBLISHED_REPORTS'];
        $query_arr = array('is_published' => 'yes');
        $order_by = '';
        if (isset($args['module']) && $args['module'] != 'All') {
            $module_value = 'value="' . $modules_report[$args['module']] . '"';
            $title = $published_report_titles[$args['module']];
            $query_arr['module'] = $args['module'];
        }
    }
    if (isset($args['show_button']) && $args['show_button']) {
        $button_form = '<form action="index.php"><input type=hidden name="module" value="Reports"/><input type=hidden name="report_module" ' . $module_value . '/><input type=hidden name="action" value="index"/><input type=hidden name="page" value="report"/><input type=submit class=button name=\'Create Custom Report\' value=\'' . $mod_strings['LBL_CREATE_CUSTOM_REPORT'] . '\'></form>';
    } else {
        $button_form = '';
    }
    echo get_form_header($title, $button_form, false);
    ?>

<script>
function schedulePOPUP(id){
			window.open("index.php?module=Reports&action=add_schedule&to_pdf=true&id=" + id ,"test","width=400,height=120,resizable=1,scrollbars=1")
}
</script>
<p>
<table width="100%" border="0" cellspacing=0 cellpadding="0" class="list view">
<tr height="20">
	<td width="40%"  NOWRAP><?php 
    echo $mod_strings['LBL_REPORT_NAME'];
    ?>
</td>
	<td width="20%"  NOWRAP><?php 
    echo $mod_strings['LBL_MODULE_NAME_SAVED'];
    ?>
</td>
	<td width="20%"  NOWRAP><?php 
    echo $mod_strings['LBL_REPORT_TYPE'];
    ?>
</td>
	<td width="5%"  NOWRAP><?php 
    echo $mod_strings['LBL_SCHEDULE_REPORT'];
    ?>
</td>
	<td width="5%"  NOWRAP>&nbsp;</td>
	<td width="5%"  NOWRAP>&nbsp;</td>
	<td width="5%"  NOWRAP>&nbsp;</td>
</tr>

<?php 
    $saved_reports_seed = BeanFactory::getBean('Reports');
    $custom_reports_arr = $saved_reports_seed->retrieve_all_by_string_fields($query_arr, $order_by);
    $shownRows = false;
    $displayedNone = true;
    if (count($custom_reports_arr)) {
        $oddRow = true;
        foreach ($custom_reports_arr as $report) {
            $report->content;
            if ($report->deleted == 1) {
                continue;
            }
            if ($oddRow) {
                $row_class = 'oddListRowS1';
            } else {
                $row_class = 'evenListRowS1';
            }
            if (!isset($app_list_strings['dom_report_types'][$report->report_type])) {
                $report_type = '';
            } else {
                $report_type = $app_list_strings['dom_report_types'][$report->report_type];
            }
            $rs = new ReportSchedule();
            $schedule = $rs->get_users_schedule();
            global $timedate;
            $subModuleCheck = 0;
            $subModuleCheckArray = array("Tasks", "Calls", "Meetings", "Notes");
            $subModuleProjectArray = array("ProjectTask");
            if (in_array($report->module, $subModuleCheckArray) && (array_key_exists("Calendar", $tabArray) || array_key_exists("Activities", $tabArray))) {
                $subModuleCheck = 1;
            }
            if (in_array($report->module, $subModuleProjectArray) && array_key_exists("Project", $tabArray)) {
                $subModuleCheck = 1;
            }
            if (array_key_exists($report->module, $tabArray) || $subModuleCheck) {
                // actually display the row if the user has access to the tab/module
                $oddRow = !$oddRow;
                $shownRows = true;
                ?>
<tr class="<?php 
                echo $row_class;
                ?>
" height="20"  onmouseover="setPointer(this, '<?php 
                echo $report->id;
                ?>
', 'over', '<?php 
                echo $bg_color;
                ?>
', '<?php 
                echo $hilite_bg;
                ?>
', '<?php 
                echo $click_bg;
                ?>
');" onmouseout="setPointer(this, '{<?php 
                echo $report->id;
                ?>
}', 'out', '<?php 
                echo $bg_color;
                ?>
', '<?php 
                echo $hilite_bg;
                ?>
', '<?php 
                echo $click_bg;
                ?>
');" onmousedown="setPointer(this, '{<?php 
                echo $report->id;
                ?>
}', 'click', '<?php 
                echo $bg_color;
                ?>
', '<?php 
                echo $hilite_bg;
                ?>
', '<?php 
                echo $click_bg;
                ?>
');">

<td nowrap="nowrap"><a href="index.php?module=Reports&action=index&page=report&id=<?php 
                echo $report->id;
                ?>
"  ><?php 
                echo $report->name;
                ?>
</a></td>
<td nowrap="nowrap"><?php 
                echo $app_list_strings['moduleList'][$report->module];
                ?>
</a></td>
<td nowrap="nowrap"><?php 
                echo $report_type;
                ?>
</a></td>
<?php 
                if (isset($schedule[$report->id]) && $schedule[$report->id]['active'] == 1) {
                    ?>
<td nowrap="nowrap"><a  href="#" onclick="schedulePOPUP('<?php 
                    echo $report->id;
                    ?>
')"  class="listViewTdToolsS1"><?php 
                    echo SugarThemeRegistry::current()->getImage('scheduled_inline', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_SCHEDULE_EMAIL']);
                    ?>
&nbsp;<?php 
                    echo $timedate->to_display_date_time($schedule[$report->id]['next_run']);
                    ?>
</a></td>
<?php 
                } else {
                    ?>
<td nowrap="nowrap"><a  href="#" onclick="schedulePOPUP('<?php 
                    echo $report->id;
                    ?>
')"  class="listViewTdToolsS1"><?php 
                    echo SugarThemeRegistry::current()->getImage('unscheduled_inline', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_SCHEDULE_EMAIL']);
                    ?>
&nbsp;<?php 
                    echo $mod_strings['LBL_NONE'];
                    ?>
</a></td>
<?php 
                }
                ?>
<td nowrap="nowrap"><a href="index.php?module=Reports&action=index&page=report&id=<?php 
                echo $report->id;
                ?>
"  class="listViewTdToolsS1"><?php 
                echo SugarThemeRegistry::current()->getImage('view_inline', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_VIEW']);
                ?>
</a>&nbsp;<a href="index.php?module=Reports&action=index&page=report&id=<?php 
                echo $report->id;
                ?>
"  class="listViewTdToolsS1"><?php 
                echo $mod_strings['LBL_VIEW'];
                ?>
</a></td>
<?php 
                if ($args['type'] == 'published' && is_admin($current_user) || $args['type'] == 'my') {
                    ?>
<td nowrap="nowrap"><a href="index.php?module=Reports&action=index&view=<?php 
                    echo $args['view'];
                    ?>
&delete_report_id=<?php 
                    echo $report->id;
                    ?>
" class="listViewTdToolsS1"><?php 
                    echo SugarThemeRegistry::current()->getImage('delete_inline', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_DELETE']);
                    ?>
</a>&nbsp;<a href="index.php?module=Reports&action=index&view=<?php 
                    echo $args['view'];
                    ?>
&delete_report_id=<?php 
                    echo $report->id;
                    ?>
" class="listViewTdToolsS1"><?php 
                    echo $mod_strings['LBL_DELETE'];
                    ?>
</a></td>
<?php 
                } else {
                    ?>
<td><?php 
                    echo SugarThemeRegistry::current()->getImage(blank, "", 1, 1, ".gif", "");
                    ?>
</td>
<?php 
                }
                if (is_admin($current_user) && $args['type'] == 'published') {
                    ?>
<td><nobr><a href="index.php?module=Reports&action=index&view=<?php 
                    echo $args['view'];
                    ?>
&publish=no&publish_report_id=<?php 
                    echo $report->id;
                    ?>
" class="listViewTdToolsS1"><?php 
                    echo SugarThemeRegistry::current()->getImage('unpublish_inline', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_UN_PUBLISH']);
                    ?>
</a>&nbsp;<a href="index.php?module=Reports&action=index&view=<?php 
                    echo $args['view'];
                    ?>
&publish=no&publish_report_id=<?php 
                    echo $report->id;
                    ?>
" class="listViewTdToolsS1"><?php 
                    echo $mod_strings['LBL_UN_PUBLISH'];
                    ?>
</a></nobr></td>
<?php 
                } else {
                    if (is_admin($current_user) && $args['type'] == 'my') {
                        ?>
<td><nobr><a href="index.php?module=Reports&action=index&view=<?php 
                        echo $args['view'];
                        ?>
&publish=yes&publish_report_id=<?php 
                        echo $report->id;
                        ?>
" class="listViewTdToolsS1"><?php 
                        echo SugarThemeRegistry::current()->getImage('publish_inline', 'border="0" align="absmiddle"', null, null, '.gif', $mod_strings['LBL_PUBLISH']);
                        ?>
</a>&nbsp;<a href="index.php?module=Reports&action=index&view=<?php 
                        echo $args['view'];
                        ?>
&publish=yes&publish_report_id=<?php 
                        echo $report->id;
                        ?>
" class="listViewTdToolsS1"><?php 
                        echo $mod_strings['LBL_PUBLISH'];
                        ?>
</a></nobr></td>
<?php 
                    } else {
                        ?>
<td><?php 
                        echo SugarThemeRegistry::current()->getImage(blank, "", 1, 1, ".gif", "");
                        ?>
</td>
<?php 
                    }
                }
                ?>
</tr>
<?php 
            }
        }
    } else {
        $displayedNone = true;
        if ($args['type'] == 'my') {
            ?>
<tr class="oddListRowS1"><td colspan="10"><?php 
            echo $mod_strings['LBL_YOU_HAVE_NO_SAVED_REPORTS.'];
            ?>
</td></tr>
<?php 
        } else {
            ?>
<tr class="oddListRowS1"><td colspan="10"><?php 
            echo $mod_strings['LBL_THERE_ARE_NO_REPORTS_OF_THIS_TYPE'];
            ?>
</td></tr>
<?php 
        }
    }
    if (!$shownRows && !$displayedNone) {
        if ($args['type'] == 'my') {
            ?>
<tr class="oddListRowS1"><td colspan="10"><?php 
            echo $mod_strings['LBL_YOU_HAVE_NO_SAVED_REPORTS.'];
            ?>
</td></tr>
<?php 
        } else {
            ?>
<tr class="oddListRowS1"><td colspan="10"><?php 
            echo $mod_strings['LBL_THERE_ARE_NO_REPORTS_OF_THIS_TYPE'];
            ?>
</td></tr>
<?php 
        }
    }
    ?>


</table>
</p>
<?php 
}
 * If you do not agree to all of the applicable terms or do not have the
 * authority to bind the entity as an authorized representative, then do not
 * install or use this SugarCRM file.
 *
 * Copyright (C) SugarCRM Inc. All rights reserved.
 */
$modListHeader = array();
require_once 'modules/Reports/schedule/ReportSchedule.php';
require_once 'modules/Reports/templates/templates_pdf.php';
require_once "modules/Mailer/MailerFactory.php";
// imports all of the Mailer classes that are needed
global $sugar_config;
$language = $sugar_config['default_language'];
$app_list_strings = return_app_list_strings_language($language);
$app_strings = return_application_language($language);
$reportSchedule = new ReportSchedule();
// Process Enterprise Schedule reports via CSV
$reportsToEmailEnt = $reportSchedule->get_ent_reports_to_email("", "ent");
global $report_modules, $modListHeader, $locale;
foreach ($reportsToEmailEnt as $scheduleId => $scheduleInfo) {
    $user = BeanFactory::getBean('Users', $scheduleInfo['user_id']);
    $current_user = $user;
    // should this be the global $current_user? global $current_user isn't referenced
    $modListHeader = query_module_access_list($current_user);
    $report_modules = getAllowedReportModules($modListHeader);
    // Acquire the enterprise report to be sent
    $reportMaker = new ReportMaker();
    $reportMaker->retrieve($scheduleInfo['report_id']);
    $mod_strings = return_module_language($language, 'Reports');
    // Process data sets into CSV files
    // loop through data sets;
Exemple #6
0
 function mark_deleted($id)
 {
     require_once 'modules/Reports/schedule/ReportSchedule.php';
     $report_schedule = new ReportSchedule();
     $scheduled_reports = $report_schedule->get_report_schedule($id);
     foreach ($scheduled_reports as $rs_row) {
         $report_schedule->mark_deleted($rs_row['id']);
     }
     parent::mark_deleted($id);
 }
 /**
  * @param $data
  * @return bool
  */
 public function run($data)
 {
     global $current_user;
     global $current_language;
     global $locale;
     $this->job->runnable_ran = true;
     $this->job->runnable_data = $data;
     $report_schedule_id = $data;
     require_once 'modules/Reports/schedule/ReportSchedule.php';
     $reportSchedule = new ReportSchedule();
     $scheduleInfo = $reportSchedule->getInfo($report_schedule_id);
     $GLOBALS["log"]->debug("-----> in Reports foreach() loop");
     $savedReport = BeanFactory::getBean('Reports', $scheduleInfo['report_id']);
     $GLOBALS["log"]->debug("-----> Generating Reporter");
     require_once 'modules/Reports/Report.php';
     $reporter = new Report(from_html($savedReport->content));
     $reporter->is_saved_report = true;
     $reporter->saved_report = $savedReport;
     $reporter->saved_report_id = $savedReport->id;
     $mod_strings = return_module_language($current_language, 'Reports');
     // prevent invalid report from being processed
     if (!$reporter->is_definition_valid()) {
         $invalidFields = $reporter->get_invalid_fields();
         $args = array($scheduleInfo['report_id'], implode(', ', $invalidFields));
         $message = string_format($mod_strings['ERR_REPORT_INVALID'], $args);
         $GLOBALS["log"]->fatal("-----> {$message}");
         $reportOwner = BeanFactory::retrieveBean('Users', $savedReport->assigned_user_id);
         if ($reportOwner) {
             require_once 'modules/Reports/utils.php';
             $reportsUtils = new ReportsUtilities();
             try {
                 $reportsUtils->sendNotificationOfInvalidReport($reportOwner, $message);
             } catch (MailerException $me) {
                 //@todo consider logging the error at the very least
             }
         }
         $this->job->failJob('Report field definition is invalid');
         return false;
     } else {
         $GLOBALS["log"]->debug("-----> Reporter settings attributes");
         $reporter->layout_manager->setAttribute("no_sort", 1);
         $GLOBALS["log"]->debug("-----> Reporter Handling PDF output");
         require_once 'modules/Reports/templates/templates_tcpdf.php';
         $reportFilename = template_handle_pdf($reporter, false);
         // get the recipient's data...
         // first get all email addresses known for this recipient
         $recipientEmailAddresses = array($current_user->email1, $current_user->email2);
         $recipientEmailAddresses = array_filter($recipientEmailAddresses);
         // then retrieve first non-empty email address
         $recipientEmailAddress = array_shift($recipientEmailAddresses);
         // get the recipient name that accompanies the email address
         $recipientName = $locale->formatName($current_user);
         $result = false;
         try {
             $GLOBALS["log"]->debug("-----> Generating Mailer");
             $mailer = MailerFactory::getSystemDefaultMailer();
             // set the subject of the email
             $subject = empty($savedReport->name) ? "Report" : $savedReport->name;
             $mailer->setSubject($subject);
             // add the recipient
             $mailer->addRecipientsTo(new EmailIdentity($recipientEmailAddress, $recipientName));
             // attach the report, using the subject as the name of the attachment
             $charsToRemove = array("\r", "\n");
             // remove these characters from the attachment name
             $attachmentName = str_replace($charsToRemove, "", $subject);
             // replace spaces with the underscores
             $attachmentName = str_replace(" ", "_", "{$attachmentName}.pdf");
             $attachment = new Attachment($reportFilename, $attachmentName, Encoding::Base64, "application/pdf");
             $mailer->addAttachment($attachment);
             // set the body of the email
             $body = $mod_strings["LBL_HELLO"];
             if ($recipientName != "") {
                 $body .= " {$recipientName}";
             }
             $body .= ",\n\n" . $mod_strings["LBL_SCHEDULED_REPORT_MSG_INTRO"] . $savedReport->date_entered . $mod_strings["LBL_SCHEDULED_REPORT_MSG_BODY1"] . $savedReport->name . $mod_strings["LBL_SCHEDULED_REPORT_MSG_BODY2"];
             $textOnly = EmailFormatter::isTextOnly($body);
             if ($textOnly) {
                 $mailer->setTextBody($body);
             } else {
                 $textBody = strip_tags(br2nl($body));
                 // need to create the plain-text part
                 $mailer->setTextBody($textBody);
                 $mailer->setHtmlBody($body);
             }
             $GLOBALS["log"]->debug("-----> Sending PDF via Email to [ {$recipientEmailAddress} ]");
             $mailer->send();
             $result = true;
             $GLOBALS["log"]->debug("-----> Send successful");
             $reportSchedule->update_next_run_time($report_schedule_id, $scheduleInfo["next_run"], $scheduleInfo["time_interval"]);
         } catch (MailerException $me) {
             switch ($me->getCode()) {
                 case MailerException::InvalidEmailAddress:
                     $GLOBALS["log"]->info("No email address for {$recipientName}");
                     break;
                 default:
                     $GLOBALS["log"]->fatal("Mail error: " . $me->getMessage());
                     break;
             }
         }
         $GLOBALS["log"]->debug("-----> Removing temporary PDF file");
         unlink($reportFilename);
         if ($result) {
             $this->job->succeedJob();
         }
         return $result;
     }
 }